From: Maxime Ripard <maxime.ripard@bootlin.com>
To: Philipp Rossak <embed3d@gmail.com>
Cc: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com,
wens@csie.org, linux@armlinux.org.uk, jic23@kernel.org,
knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
eugen.hristev@microchip.com, rdunlap@infradead.org,
vilhelm.gray@gmail.com, clabbe.montjoie@gmail.com,
quentin.schulz@bootlin.com, geert+renesas@glider.be,
lukas@wunner.de, icenowy@aosc.io, arnd@arndb.de,
broonie@kernel.org, arnaud.pouliquen@st.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
Subject: Re: [PATCH v3 18/30] iio: adc: sun4i-gpadc-iio: rework: support multiple sensors
Date: Fri, 31 Aug 2018 11:05:56 +0200 [thread overview]
Message-ID: <20180831090556.amfyixpv2shdrrlp@flea> (raw)
In-Reply-To: <20180830154518.29507-19-embed3d@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 6865 bytes --]
On Thu, Aug 30, 2018 at 05:45:06PM +0200, 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 <embed3d@gmail.com>
> ---
> drivers/iio/adc/sun4i-gpadc-iio.c | 63 +++++++++++++++++++++++++------------
> include/linux/iio/adc/sun4i-gpadc.h | 3 ++
> 2 files changed, 46 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gpadc-iio.c
> index c12de48c4e86..18ab72e52d78 100644
> --- a/drivers/iio/adc/sun4i-gpadc-iio.c
> +++ b/drivers/iio/adc/sun4i-gpadc-iio.c
> @@ -69,6 +69,7 @@ struct gpadc_data {
> bool has_bus_rst;
> bool has_mod_clk;
> u32 temp_data_base;
> + int sensor_count;
> };
>
> static irqreturn_t sun4i_gpadc_data_irq_handler(int irq, void *dev_id);
> @@ -84,6 +85,7 @@ static const struct gpadc_data sun4i_gpadc_data = {
> .ths_irq_thread = sun4i_gpadc_data_irq_handler,
> .support_irq = true,
> .temp_data_base = SUN4I_GPADC_TEMP_DATA,
> + .sensor_count = 1,
> };
>
> static const struct gpadc_data sun5i_gpadc_data = {
> @@ -97,6 +99,7 @@ static const struct gpadc_data sun5i_gpadc_data = {
> .ths_irq_thread = sun4i_gpadc_data_irq_handler,
> .support_irq = true,
> .temp_data_base = SUN4I_GPADC_TEMP_DATA,
> + .sensor_count = 1,
> };
>
> static const struct gpadc_data sun6i_gpadc_data = {
> @@ -110,6 +113,7 @@ static const struct gpadc_data sun6i_gpadc_data = {
> .ths_irq_thread = sun4i_gpadc_data_irq_handler,
> .support_irq = true,
> .temp_data_base = SUN4I_GPADC_TEMP_DATA,
> + .sensor_count = 1,
> };
>
> static const struct gpadc_data sun8i_a33_gpadc_data = {
> @@ -117,6 +121,13 @@ static const struct gpadc_data sun8i_a33_gpadc_data = {
> .temp_scale = 162,
> .tp_mode_en = SUN8I_A33_GPADC_CTRL1_CHOP_TEMP_EN,
> .temp_data_base = SUN4I_GPADC_TEMP_DATA,
> + .sensor_count = 1,
> +};
> +
> +struct sun4i_sensor_tzd {
> + struct sun4i_gpadc_iio *info;
> + struct thermal_zone_device *tzd;
> + unsigned int sensor_id;
> };
>
> struct sun4i_gpadc_iio {
> @@ -130,7 +141,7 @@ struct sun4i_gpadc_iio {
> const struct gpadc_data *data;
> /* prevents concurrent reads of temperature and ADC */
> struct mutex mutex;
> - struct thermal_zone_device *tzd;
> + struct sun4i_sensor_tzd tzds[MAX_SENSOR_COUNT];
> struct device *sensor_device;
> struct clk *bus_clk;
> struct clk *mod_clk;
> @@ -280,7 +291,8 @@ static int sun4i_gpadc_adc_read(struct iio_dev *indio_dev, int channel,
> SUN4I_GPADC_IRQ_FIFO_DATA);
> }
>
> -static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val)
> +static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val,
> + int sensor)
> {
> struct sun4i_gpadc_iio *info = iio_priv(indio_dev);
>
> @@ -290,7 +302,8 @@ static int sun4i_gpadc_temp_read(struct iio_dev *indio_dev, int *val)
>
> pm_runtime_get_sync(indio_dev->dev.parent);
>
> - regmap_read(info->regmap, info->data->temp_data_base, val);
> + regmap_read(info->regmap, info->data->temp_data_base + 0x4 * sensor,
> + val);
>
> pm_runtime_mark_last_busy(indio_dev->dev.parent);
> pm_runtime_put_autosuspend(indio_dev->dev.parent);
> @@ -334,7 +347,7 @@ static int sun4i_gpadc_read_raw(struct iio_dev *indio_dev,
> ret = sun4i_gpadc_adc_read(indio_dev, chan->channel,
> val);
> else
> - ret = sun4i_gpadc_temp_read(indio_dev, val);
> + ret = sun4i_gpadc_temp_read(indio_dev, val, 0);
>
> if (ret)
> return ret;
> @@ -420,10 +433,11 @@ static int sun4i_gpadc_runtime_resume(struct device *dev)
>
> static int sun4i_gpadc_get_temp(void *data, int *temp)
> {
> - struct sun4i_gpadc_iio *info = data;
> + struct sun4i_sensor_tzd *tzd = data;
> + struct sun4i_gpadc_iio *info = tzd->info;
> int val, scale, offset;
>
> - if (sun4i_gpadc_temp_read(info->indio_dev, &val))
> + if (sun4i_gpadc_temp_read(info->indio_dev, &val, tzd->sensor_id))
> return -ETIMEDOUT;
>
> sun4i_gpadc_temp_scale(info->indio_dev, &scale);
> @@ -569,7 +583,7 @@ static int sun4i_gpadc_probe(struct platform_device *pdev)
> {
> struct sun4i_gpadc_iio *info;
> struct iio_dev *indio_dev;
> - int ret;
> + int ret, i;
>
> indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
> if (!indio_dev)
> @@ -603,18 +617,24 @@ static int sun4i_gpadc_probe(struct platform_device *pdev)
> pm_runtime_set_suspended(&pdev->dev);
> pm_runtime_enable(&pdev->dev);
>
> - info->tzd = thermal_zone_of_sensor_register(info->sensor_device,
> - 0, info,
> - &sun4i_ts_tz_ops);
> - /*
> - * Do not fail driver probing when failing to register in
> - * thermal because no thermal DT node is found.
> - */
> - if (IS_ERR(info->tzd) && PTR_ERR(info->tzd) != -ENODEV) {
> - dev_err(&pdev->dev,
> - "could not register thermal sensor: %ld\n",
> - PTR_ERR(info->tzd));
> - return PTR_ERR(info->tzd);
> + for (i = 0; i < info->data->sensor_count; i++) {
> + info->tzds[i].info = info;
> + info->tzds[i].sensor_id = i;
> +
> + info->tzds[i].tzd = thermal_zone_of_sensor_register(
This isn't where should wrap your line.
> + info->sensor_device,
> + i, &info->tzds[i], &sun4i_ts_tz_ops);
> + /*
> + * Do not fail driver probing when failing to register in
> + * thermal because no thermal DT node is found.
> + */
> + if (IS_ERR(info->tzds[i].tzd) && \
And you don't need the \ here.
> + PTR_ERR(info->tzds[i].tzd) != -ENODEV) {
> + dev_err(&pdev->dev,
> + "could not register thermal sensor: %ld\n",
> + PTR_ERR(info->tzds[i].tzd));
> + return PTR_ERR(info->tzds[i].tzd);
> + }
If you're failing half way through the registration, you won't free
the first sensors registered.
Maxime
--
Maxime Ripard, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-08-31 13:12 UTC|newest]
Thread overview: 86+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-30 15:44 [PATCH v3 00/30] IIO-based thermal sensor driver for Allwinner H3 and A83T SoC Philipp Rossak
2018-08-30 15:44 ` [PATCH v3 01/30] mfd: Makefile: Remove build option for MFD:sun4i-gpadc Philipp Rossak
2018-08-31 8:25 ` Maxime Ripard
2018-09-02 19:58 ` Jonathan Cameron
2018-08-30 15:44 ` [PATCH v3 02/30] mfd: Kconfig: Remove MFD_SUN4I_GPADC config option Philipp Rossak
2018-09-02 19:58 ` Jonathan Cameron
2018-08-30 15:44 ` [PATCH v3 03/30] iio: adc: Remove ID table Philipp Rossak
2018-08-30 15:44 ` [PATCH v3 04/30] iio: adc: Kconfig: Update Kconfig to new build options Philipp Rossak
2018-08-31 8:32 ` Maxime Ripard
2018-08-30 15:44 ` [PATCH v3 05/30] iio: adc: move SUN4I_GPADC_CHANNEL define to header file Philipp Rossak
2018-09-02 20:01 ` Jonathan Cameron
2018-09-03 14:24 ` Philipp Rossak
2018-09-03 17:28 ` Jonathan Cameron
2018-08-30 15:44 ` [PATCH v3 06/30] iio: adc: remove ofnode options Philipp Rossak
2018-08-30 15:44 ` [PATCH v3 07/30] iio: adc: remove mfd_probe & sunwi_irq_init function Philipp Rossak
2018-08-31 8:34 ` Maxime Ripard
2018-08-30 15:44 ` [PATCH v3 08/30] iio: adc: remove hwmon structure Philipp Rossak
2018-08-31 8:34 ` Maxime Ripard
2018-08-30 15:44 ` [PATCH v3 09/30] iio: adc: Threat A33 as thermal sensor and remove non thermal sun4i channel Philipp Rossak
2018-08-30 16:40 ` [linux-sunxi] " Ondřej Jirman
2018-08-31 8:35 ` Maxime Ripard
2018-08-30 15:44 ` [PATCH v3 10/30] iio: adc: rework irq and adc_channel handling Philipp Rossak
2018-08-31 8:44 ` Maxime Ripard
2018-08-30 15:44 ` [PATCH v3 11/30] iio: adc: add new compatibles Philipp Rossak
2018-08-31 8:46 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 12/30] mfd: Remove old mfd driver & Move sun4i-gpadc.h to iio/adc/ Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 13/30] arm: config: Enable SUN4I_GPADC in defconfig Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 14/30] dt-bindings: update the Allwinner GPADC device tree binding for H3 & A83T Philipp Rossak
2018-08-31 8:48 ` Maxime Ripard
2018-09-10 19:44 ` Rob Herring
2018-09-11 9:12 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 15/30] iio: adc: sun4i-gpadc-iio: rename A33-specified registers to contain A33 Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 16/30] iio: adc: sun4i-gpadc-iio: rework: readout temp_data Philipp Rossak
2018-08-31 8:50 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 17/30] iio: adc: sun4i-gpadc-iio: rework: support clocks and reset Philipp Rossak
2018-08-31 9:03 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 18/30] iio: adc: sun4i-gpadc-iio: rework: support multiple sensors Philipp Rossak
2018-08-31 9:05 ` Maxime Ripard [this message]
2018-09-02 20:11 ` Jonathan Cameron
2018-09-03 13:58 ` Philipp Rossak
2018-09-03 17:29 ` Jonathan Cameron
2018-08-30 15:45 ` [PATCH v3 19/30] iio: adc: sun4i-gpadc-iio: rework: support nvmem calibration data Philipp Rossak
2018-08-31 9:07 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 20/30] iio: adc: sun4i-gpadc-iio: rework: device specific suspend & resume Philipp Rossak
2018-08-31 9:09 ` Maxime Ripard
2018-08-31 12:05 ` Philipp Rossak
2018-09-03 9:44 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 21/30] iio: adc: sun4i-gpadc-iio: add support for H3 thermal sensor Philipp Rossak
2018-08-30 16:27 ` [linux-sunxi] " Ondřej Jirman
2018-08-30 20:00 ` Philipp Rossak
2018-08-30 20:46 ` Philipp Rossak
2018-08-31 9:11 ` Maxime Ripard
2018-08-31 9:51 ` Icenowy Zheng
2018-08-31 11:58 ` [linux-sunxi] " Philipp Rossak
2018-09-03 10:20 ` Maxime Ripard
2018-09-03 11:01 ` [linux-sunxi] " Icenowy Zheng
2018-09-05 14:58 ` Maxime Ripard
2018-08-31 12:01 ` Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 22/30] iio: adc: sun4i-gpadc-iio: add support for A83T " Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 23/30] ARM: dts: sunxi-h3-h5: add support for the thermal sensor in H3 and H5 Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 24/30] ARM: dts: sun8i: h3: add support for the thermal sensor in H3 Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 25/30] ARM: dts: sun8i: h3: add thermal zone to H3 Philipp Rossak
2018-08-31 9:14 ` Maxime Ripard
2018-08-30 15:45 ` [PATCH v3 26/30] ARM: dts: sun8i: h3: enable H3 sid controller Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 27/30] ARM: dts: sun8i: h3: use calibration for ths Philipp Rossak
2018-09-04 16:46 ` Emmanuel Vadot
2018-09-06 11:47 ` Philipp Rossak
2018-09-06 11:51 ` Maxime Ripard
2018-09-06 12:04 ` [linux-sunxi] " Icenowy Zheng
2018-09-06 12:18 ` Philipp Rossak
2019-02-19 7:54 ` Allwinner SID THS calibration data cell representation? Chen-Yu Tsai
2019-02-20 14:55 ` Maxime Ripard
2019-02-21 10:10 ` Emmanuel Vadot
2019-02-25 20:37 ` Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 28/30] ARM: dts: sun8i: a83t: add support for the thermal sensor in A83T Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 29/30] ARM: dts: sun8i: a83t: add thermal zone to A83T Philipp Rossak
2018-08-30 15:45 ` [PATCH v3 30/30] ARM: sun8i: a83t: full range OPP tables and CPUfreq Philipp Rossak
2018-08-30 16:38 ` [linux-sunxi] " Ondřej Jirman
2018-08-30 20:29 ` Philipp Rossak
2018-09-06 7:24 ` Quentin Schulz
2018-09-06 11:39 ` Philipp Rossak
2018-09-06 11:42 ` Maxime Ripard
2018-09-06 12:06 ` Quentin Schulz
2019-03-19 12:30 ` [PATCH v3 00/30] IIO-based thermal sensor driver for Allwinner H3 and A83T SoC Måns Rullgård
2019-03-19 12:37 ` Maxime Ripard
2019-03-19 13:04 ` [linux-sunxi] " Chen-Yu Tsai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180831090556.amfyixpv2shdrrlp@flea \
--to=maxime.ripard@bootlin.com \
--cc=arnaud.pouliquen@st.com \
--cc=arnd@arndb.de \
--cc=broonie@kernel.org \
--cc=clabbe.montjoie@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=embed3d@gmail.com \
--cc=eugen.hristev@microchip.com \
--cc=geert+renesas@glider.be \
--cc=icenowy@aosc.io \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=lee.jones@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@googlegroups.com \
--cc=linux@armlinux.org.uk \
--cc=lukas@wunner.de \
--cc=mark.rutland@arm.com \
--cc=pmeerw@pmeerw.net \
--cc=quentin.schulz@bootlin.com \
--cc=rdunlap@infradead.org \
--cc=robh+dt@kernel.org \
--cc=vilhelm.gray@gmail.com \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).