Received: by 10.223.176.5 with SMTP id f5csp790836wra; Fri, 2 Feb 2018 06:14:20 -0800 (PST) X-Google-Smtp-Source: AH8x225HT8IX5Y5OKjcDsCkRWQefbVjiWIrDDYQeqoFHjVAltGLQd6VCx46SGa3CFl+Ms1sCdDqP X-Received: by 2002:a17:902:ba84:: with SMTP id k4-v6mr4756610pls.116.1517580860813; Fri, 02 Feb 2018 06:14:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517580860; cv=none; d=google.com; s=arc-20160816; b=o3Q7MCL54UFG/RDZLpcNdtrbrL7r3hhUgMlZfK6W6QqvWfqREj9/oBvostjv2b3z17 hvF/ay+pHnI+OmOUFan1JbCkchDZx86gF/vqP2qhxUnsmA84ey+LShOHphQQtWm44qiF vdj7gZZsdlIzNQVrD42TLAPcbPg3OyE6SpaXBctYhtGbKjsC+pIbrvJmMoVgDgxn0g8H xYLct5bLGTh9ch9yCM/hXaCu3F79LkvLBS/BFGagpt4CkT/B0BwuFh85LW6zuJC+pBpv p9pflwAPlHfobSh6rt0yQg7q283uRQTgP4nL6C0Gy0a/H7NeX2HkCRB4a0Dj4A/h+pR6 R6tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=OQwUuRUWY/j3ujvwMhCTpwCeuyYgCPBoyoolWtGgd3g=; b=alwvgSW7sPl6oQ0+fh+BEXwK4gptlWyU0dqSVqEeWgHgOgpPcfsyepgEbG5dggE1mN 9PfgoNFXZQqgqUsQhn6zlWk2mV8jx43aSkGHfVmyUCi1uvSwtDdAGwtFcWRL/L20n8l2 KD5xIfLv4L7rEaZuY9QXvdMR8AfDGlcIl/BaHL3SJwQbS5nt5aM7J+Eaex/wXX/usyV6 0ikM2ffLKB1nfW1Earoc3EfMUg03sYMAFpgtXVyL8eKjQX4h7psh/6mMMkRN9OfHgWVi VfEBuj5yvYQfdp6TgM6Hg9Ekgj+EIZZJBG1tyUmJGAhus8Wz1vUNowXFuw7WMMJqaDgT +Lcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDaYzfib; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n9si1179588pgc.36.2018.02.02.06.14.05; Fri, 02 Feb 2018 06:14:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VDaYzfib; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752060AbeBBONi (ORCPT + 99 others); Fri, 2 Feb 2018 09:13:38 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:52748 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751626AbeBBONc (ORCPT ); Fri, 2 Feb 2018 09:13:32 -0500 Received: by mail-wm0-f68.google.com with SMTP id g1so12895650wmg.2; Fri, 02 Feb 2018 06:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=OQwUuRUWY/j3ujvwMhCTpwCeuyYgCPBoyoolWtGgd3g=; b=VDaYzfib36PVBG7mIeBSLOLX6d4AUq137HjYy2o77jvgFt/z65mHd1u7MTtuh7yobN zMGb9hosdflc9CzZ1L6p866yKkLh0XkVZzh1BdLH89BaL+YVjiBB1mAqNHuMq6TJI5pe +ejfaDkHt/JvMwKucKF8RRMTC+xGHW00elQZZbndOubpSMP5eaeYPpTy2yCXfH2MUIBX UYdLqQEqSXpWOECnqS8l5aUDXb18hC0P4eLf2+U6qpkoaBVB+Zv1gCFRrBrE6JryWSeR 5bGhyTj5gEDgvwQsahfl+tUiGjRyHm4yUBW5hFxxGl/XlPjspyPXY9+W9+BlK6eMnPM8 uVqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=OQwUuRUWY/j3ujvwMhCTpwCeuyYgCPBoyoolWtGgd3g=; b=RWGHR0sLYJk78VZFKME2Aa32NxviVH2252fSVhNLD8Kt71gBgmYgKwwSlSax69Saqy HESbDPua//zc4K/2CJbxGTMD3U62ev7qf5LYeoq7iExdjEXwGLKphPmko9858aURPyRZ HTgdl9RQrAn/pYsXlGEyp6E1/RYyrym6GSt3rXYR1S/KbqdATpqRYfFgVKrUyExoivFn pV9iaixdH/VoiGUlDAL7l9JHWYxF6SxSuDd6Yb7OexOQensaCwfkHhwNFqJFK4yIQw4w ediaHvEkpZIxnr94IccnP/E3BEA1X2o+InoE0X2Jewfzb7u0VMxtDfTcj2XHOtmYYtOt SNVQ== X-Gm-Message-State: AKwxytfzUs9UD1pW2RJZgWTHdph+STQDi0bpcoUBfCH1b2OdUVVi8U8v g7y9SlOtS/ERK9imr86B03M= X-Received: by 10.80.213.218 with SMTP id g26mr66923021edj.101.1517580810441; Fri, 02 Feb 2018 06:13:30 -0800 (PST) Received: from [134.60.183.180] (eduroam183-180.wlan.uni-ulm.de. [134.60.183.180]) by smtp.gmail.com with ESMTPSA id o47sm1927100edc.10.2018.02.02.06.13.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 06:13:29 -0800 (PST) Subject: Re: [PATCH v2 06/16] iio: adc: sun4i-gpadc-iio: rework: support multiple sensors To: Quentin Schulz Cc: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, maxime.ripard@free-electrons.com, wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, davem@davemloft.net, hans.verkuil@cisco.com, mchehab@kernel.org, rask@formelder.dk, clabbe.montjoie@gmail.com, sean@mess.org, krzk@kernel.org, icenowy@aosc.io, edu.molinas@gmail.com, singhalsimran0@gmail.com, linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com References: <20180128232919.12639-1-embed3d@gmail.com> <20180128232919.12639-7-embed3d@gmail.com> <20180131184236.4yhp732l5kenhmp2@qschulz> From: Philipp Rossak Message-ID: <42632deb-077a-ad73-58e1-92d92dbd0963@gmail.com> Date: Fri, 2 Feb 2018 15:13:28 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180131184236.4yhp732l5kenhmp2@qschulz> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 31.01.2018 19:42, Quentin Schulz wrote: > Hi Philipp, > > On Mon, Jan 29, 2018 at 12:29:09AM +0100, Philipp Rossak wrote: >> For adding newer sensor some basic rework of the code is necessary. >> >> This patch reworks the driver to be able to handle more than one >> thermal sensor. Newer SoC like the A80 have 4 thermal sensors. >> Because of this the maximal sensor count value was set to 4. >> >> The sensor_id value is set during sensor registration and is for each >> registered sensor indiviual. This makes it able to differntiate the >> sensors when the value is read from the register. >> >> In function sun4i_gpadc_read_raw(), the sensor number of the ths sensor >> was directly set to 0 (sun4i_gpadc_temp_read(x,x,0)). This selects >> in the temp_read function automatically sensor 0. A check for the >> sensor_id is here not required since the old sensors only have one >> thermal sensor. In addition to that is the sun4i_gpadc_read_raw() >> function only used by the "older" sensors (before A33) where the >> thermal sensor was a cobination of an adc and a thermal sensor. >> >> Signed-off-by: Philipp Rossak >> --- >> drivers/iio/adc/sun4i-gpadc-iio.c | 36 +++++++++++++++++++++++------------- >> include/linux/mfd/sun4i-gpadc.h | 3 +++ >> 2 files changed, 26 insertions(+), 13 deletions(-) >> >> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c >> index 51ec0104d678..ac9ad2f8232f 100644 >> --- a/drivers/iio/adc/sun4i-gpadc-iio.c >> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c >> @@ -67,12 +67,13 @@ struct gpadc_data { >> unsigned int tp_adc_select; >> unsigned int (*adc_chan_select)(unsigned int chan); >> unsigned int adc_chan_mask; >> - unsigned int temp_data; >> + unsigned int temp_data[MAX_SENSOR_COUNT]; >> int (*sample_start)(struct sun4i_gpadc_iio *info); >> int (*sample_end)(struct sun4i_gpadc_iio *info); >> bool has_bus_clk; >> bool has_bus_rst; >> bool has_mod_clk; >> + int sensor_count; >> }; >> > > I've noticed that for H3, A83T, A64 (at least), if DATA reg of sensor 0 > is e.g. 0x80, DATA reg of sensor N is at 0x80 + 0x04 * N. > > Is that verified for other SoCs? Does anyone have some input on this? > > We could then just use temp_data as the DATA reg "base" and increment by > 0x4 depending on the sensor id instead of using a fixed-size array. > This sounds like a good idea! I will add this to the next version. I can verify this with a table, I created during development. I will upload it during the weekend here: [1] >> static const struct gpadc_data sun4i_gpadc_data = { >> @@ -82,9 +83,10 @@ static const struct gpadc_data sun4i_gpadc_data = { >> .tp_adc_select = SUN4I_GPADC_CTRL1_TP_ADC_SELECT, >> .adc_chan_select = &sun4i_gpadc_chan_select, >> .adc_chan_mask = SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, >> - .temp_data = SUN4I_GPADC_TEMP_DATA, >> + .temp_data = {SUN4I_GPADC_TEMP_DATA, 0, 0, 0}, >> .sample_start = sun4i_gpadc_sample_start, >> .sample_end = sun4i_gpadc_sample_end, >> + .sensor_count = 1, > > If the solution above is not desirable/possible, could we use something > like: > > unsigned int sun4i_temp_data[] = {SUN4I_GPADC_TEMP_DATA,}; > > static const struct gpadc_data sun4i_gpadc_data = { > .temp_data = &sun4i_temp_data, > .sensor_count = ARRAY_SIZE(sun4i_temp_data), > }; > > That avoids 1) inconsistencies between the array size and the array > itself, 2) does not require to pad the array with zeroes. > > [...] > >> @@ -745,9 +752,12 @@ static int sun4i_gpadc_probe(struct platform_device *pdev) >> pm_runtime_enable(&pdev->dev); >> >> if (IS_ENABLED(CONFIG_THERMAL_OF)) { >> - info->tzd = thermal_zone_of_sensor_register(info->sensor_device, >> - 0, info, >> - &sun4i_ts_tz_ops); >> + for (i = 0; i < info->data->sensor_count; i++) { >> + info->sensor_id = i; >> + info->tzd = thermal_zone_of_sensor_register( >> + info->sensor_device, >> + i, info, &sun4i_ts_tz_ops); >> + } > > As Maxime said, this does not work. > > One way would be to have a new structure being: > struct sun4i_sensor_info { > struct sun4i_gpadc_iio *info; > unsigned int sensor_id; > }; > > Or since we only use the iio_dev within the sun4i_gpadc_iio in the > .get_temp function, we may replace info by struct iio_dev *indio_dev > above. > > Quentin > I will have a closer look on this next week, when I start to work on the next version.. Thanks, Philipp [1]: http://linux-sunxi.org/Thermal_Sensor