Received: by 10.223.176.5 with SMTP id f5csp2653636wra; Mon, 29 Jan 2018 01:38:29 -0800 (PST) X-Google-Smtp-Source: AH8x227VMMHSwT2w4im3MSqPy5bvpDFnvxKvUgTGQSnlQv4a+S9qgM6BrtbYUtDxmamUJFGpdsgj X-Received: by 10.98.185.14 with SMTP id z14mr26257549pfe.185.1517218709040; Mon, 29 Jan 2018 01:38:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517218708; cv=none; d=google.com; s=arc-20160816; b=nif38VoHS+E7Cti9PnJj0pV6F6W+H4hBg2OSQx10ZmjZZmZ+TUrcfGTmP3fw5KFx0J 6Rn/VcA/PR+jKjsAJsqIZa1Fugp56xo4cpsAvPZvA7Ki9ThK4KrI3ZtT01+47+3RuMN9 +DwDHOL4Wq8KhvXwwbQogV37t/z04taztFVcysAbL6JZUs+eS96hRJRB56SrZW1s3Aqm y19uemHxgInk9bnkV+ZcvyKaELDudzQUVSEldijKbDiWZnyAv3XGrj2JD94/VCfY1FtH WCcEIrVjq+NB7dUVbLVEwxzxSAmb1Padkx98cPs7GCdX4+sAAwN9BD61nPHqP9iqf8J3 +IzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=G61Rwp79gxJNXN035xX0oJIZjSCf/NkZP7Xu72iDLZA=; b=cUEo01+IFTXqZGcTSRa+az+DP1wRfNjVx1STZNk+FhvdA7ObUrqUh/E80SloQV/zfR 7v7KbipHVqesDfLNLBbUCIVKqJt9RXP4fY+Kq5gPagJsJeGW0xzomBuZMS56+X/uHAep M///weS5L58EOKoGpUe3y0WEw2kE5FzdmYR05iJaR27YUPk1WgV+79LHYhAcj4JDbrz5 9YsHLMYOIKF+icbvr0CehQEglwtpTpMzVKzNB6X1EieR2OLQwMwuQiTGnu5SgRZk5PiF 58REItDljS+aEcFc2R25ijKpTwtdazlZ0V1gxmnLeA9jMXYWh+js8wC/I2oD/l082Khd q9MA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 186si11419738pfe.411.2018.01.29.01.38.14; Mon, 29 Jan 2018 01:38:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751363AbeA2Jhx (ORCPT + 99 others); Mon, 29 Jan 2018 04:37:53 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:58376 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750913AbeA2Jhu (ORCPT ); Mon, 29 Jan 2018 04:37:50 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id A1F4121992; Mon, 29 Jan 2018 10:37:48 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.free-electrons.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.0 Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 6B2BC2198F; Mon, 29 Jan 2018 10:37:38 +0100 (CET) Date: Mon, 29 Jan 2018 10:37:38 +0100 From: Maxime Ripard To: Philipp Rossak 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, davem@davemloft.net, hans.verkuil@cisco.com, mchehab@kernel.org, rask@formelder.dk, clabbe.montjoie@gmail.com, sean@mess.org, krzk@kernel.org, quentin.schulz@free-electrons.com, 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 Subject: Re: [PATCH v2 06/16] iio: adc: sun4i-gpadc-iio: rework: support multiple sensors Message-ID: <20180129093738.5edpjclcbtsoneiw@flea.lan> References: <20180128232919.12639-1-embed3d@gmail.com> <20180128232919.12639-7-embed3d@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="htifghagwui5ssmn" Content-Disposition: inline In-Reply-To: <20180128232919.12639-7-embed3d@gmail.com> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --htifghagwui5ssmn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, 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. >=20 > 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. >=20 > 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. >=20 > 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. >=20 > 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(-) >=20 > diff --git a/drivers/iio/adc/sun4i-gpadc-iio.c b/drivers/iio/adc/sun4i-gp= adc-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; > }; > =20 > static const struct gpadc_data sun4i_gpadc_data =3D { > @@ -82,9 +83,10 @@ static const struct gpadc_data sun4i_gpadc_data =3D { > .tp_adc_select =3D SUN4I_GPADC_CTRL1_TP_ADC_SELECT, > .adc_chan_select =3D &sun4i_gpadc_chan_select, > .adc_chan_mask =3D SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, > - .temp_data =3D SUN4I_GPADC_TEMP_DATA, > + .temp_data =3D {SUN4I_GPADC_TEMP_DATA, 0, 0, 0}, > .sample_start =3D sun4i_gpadc_sample_start, > .sample_end =3D sun4i_gpadc_sample_end, > + .sensor_count =3D 1, > }; > =20 > static const struct gpadc_data sun5i_gpadc_data =3D { > @@ -94,9 +96,10 @@ static const struct gpadc_data sun5i_gpadc_data =3D { > .tp_adc_select =3D SUN4I_GPADC_CTRL1_TP_ADC_SELECT, > .adc_chan_select =3D &sun4i_gpadc_chan_select, > .adc_chan_mask =3D SUN4I_GPADC_CTRL1_ADC_CHAN_MASK, > - .temp_data =3D SUN4I_GPADC_TEMP_DATA, > + .temp_data =3D {SUN4I_GPADC_TEMP_DATA, 0, 0, 0}, > .sample_start =3D sun4i_gpadc_sample_start, > .sample_end =3D sun4i_gpadc_sample_end, > + .sensor_count =3D 1, > }; > =20 > static const struct gpadc_data sun6i_gpadc_data =3D { > @@ -106,18 +109,20 @@ static const struct gpadc_data sun6i_gpadc_data =3D= { > .tp_adc_select =3D SUN6I_GPADC_CTRL1_TP_ADC_SELECT, > .adc_chan_select =3D &sun6i_gpadc_chan_select, > .adc_chan_mask =3D SUN6I_GPADC_CTRL1_ADC_CHAN_MASK, > - .temp_data =3D SUN4I_GPADC_TEMP_DATA, > + .temp_data =3D {SUN4I_GPADC_TEMP_DATA, 0, 0, 0}, > .sample_start =3D sun4i_gpadc_sample_start, > .sample_end =3D sun4i_gpadc_sample_end, > + .sensor_count =3D 1, > }; > =20 > static const struct gpadc_data sun8i_a33_gpadc_data =3D { > .temp_offset =3D -1662, > .temp_scale =3D 162, > .tp_mode_en =3D SUN8I_A33_GPADC_CTRL1_CHOP_TEMP_EN, > - .temp_data =3D SUN4I_GPADC_TEMP_DATA, > + .temp_data =3D {SUN4I_GPADC_TEMP_DATA, 0, 0, 0}, > .sample_start =3D sun4i_gpadc_sample_start, > .sample_end =3D sun4i_gpadc_sample_end, > + .sensor_count =3D 1, > }; > =20 > struct sun4i_gpadc_iio { > @@ -135,6 +140,7 @@ struct sun4i_gpadc_iio { > struct clk *bus_clk; > struct clk *mod_clk; > struct reset_control *reset; > + int sensor_id; > /* prevents concurrent reads of temperature and ADC */ > struct mutex mutex; > struct thermal_zone_device *tzd; > @@ -302,14 +308,15 @@ static int sun4i_gpadc_adc_read(struct iio_dev *ind= io_dev, int channel, > return sun4i_gpadc_read(indio_dev, channel, val, info->fifo_data_irq); > } > =20 > -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 =3D iio_priv(indio_dev); > =20 > if (info->no_irq) { > pm_runtime_get_sync(indio_dev->dev.parent); > =20 > - regmap_read(info->regmap, info->data->temp_data, val); > + regmap_read(info->regmap, info->data->temp_data[sensor], val); > =20 > pm_runtime_mark_last_busy(indio_dev->dev.parent); > pm_runtime_put_autosuspend(indio_dev->dev.parent); > @@ -356,7 +363,7 @@ static int sun4i_gpadc_read_raw(struct iio_dev *indio= _dev, > ret =3D sun4i_gpadc_adc_read(indio_dev, chan->channel, > val); > else > - ret =3D sun4i_gpadc_temp_read(indio_dev, val); > + ret =3D sun4i_gpadc_temp_read(indio_dev, val, 0); > =20 > if (ret) > return ret; > @@ -470,7 +477,7 @@ static int sun4i_gpadc_get_temp(void *data, int *temp) > struct sun4i_gpadc_iio *info =3D data; > int val, scale, offset; > =20 > - if (sun4i_gpadc_temp_read(info->indio_dev, &val)) > + if (sun4i_gpadc_temp_read(info->indio_dev, &val, info->sensor_id)) > return -ETIMEDOUT; > =20 > sun4i_gpadc_temp_scale(info->indio_dev, &scale); > @@ -712,7 +719,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; > =20 > indio_dev =3D devm_iio_device_alloc(&pdev->dev, sizeof(*info)); > if (!indio_dev) > @@ -745,9 +752,12 @@ static int sun4i_gpadc_probe(struct platform_device = *pdev) > pm_runtime_enable(&pdev->dev); > =20 > if (IS_ENABLED(CONFIG_THERMAL_OF)) { > - info->tzd =3D thermal_zone_of_sensor_register(info->sensor_device, > - 0, info, > - &sun4i_ts_tz_ops); > + for (i =3D 0; i < info->data->sensor_count; i++) { > + info->sensor_id =3D i; > + info->tzd =3D thermal_zone_of_sensor_register( > + info->sensor_device, > + i, info, &sun4i_ts_tz_ops); > + } I'm not sure how that works. Isn't the info structure shared between all the sensors? The sensor_id value would be always set to the last sensor then. Thanks! Maxime --=20 Maxime Ripard, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com --htifghagwui5ssmn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE0VqZU19dR2zEVaqr0rTAlCFNr3QFAlpu62EACgkQ0rTAlCFN r3S0KA//Z6QtY14DZGa7sO2cRE+vfDH4TtUmGpczbdQUuv03pza3YnLyBN4P7f8U 047pAo4kuwaHARM0kErGTlj2i+07qtsdtrraeFHStL6VM50+XyiqCZEmYGeWv7Th UNtsgphdv3rajd15smRNKZrkLr9fY/GBhsaiW6ICCb+/oAF7wJ2PGZvPcSmeKLlZ qDkRWKwvARBq7OKXhPAY39/UM+jYYwVtBktgH9E+RZn7OyZuIWNWw8Dn4yiggy7K hDHhj46s6ObMZCrEe2LU+CT+an4pYNScKUMtg5SszvzbRN7NqhyD1dgSaIH2/SvJ Fvc5Dl3vpzWEviJ88m4eC90T5nOzxcm59fXDQEQQkorJB11WBc7AZ6K6rab9AUha wByfmnVQ6DHvWfZDVp+Zv2Fkqp7I4pRyGI/vlCkwjhP3pvrQfqGn0BnOQPUSbev9 nbWifnugTabecLYrAP+xY7QKcurK0z9d8+HSDFFTqjgMhO2F5Bg9/e9Vr83sdP26 pX8nDFFj83lTLMJtpGsZytS0x5vQ7AGAqmQlM1Nue1He8vk7vNS9f/HXuXaZH3v2 WZiykgpar9swhk+gt1tfXepInXSehiGLXKvOMs0+2uydhWDe6Aun4u8zCRUM/VEj rsanOvFPItVrnszGMKRpeWsc7aoAwRcmxEJ2M7DYdBLhQ6fkLAg= =ody9 -----END PGP SIGNATURE----- --htifghagwui5ssmn--