From: Bough Chen <haibo.chen@nxp.com>
To: "Nuno Sá" <nuno.sa@analog.com>,
"linux-amlogic@lists.infradead.org"
<linux-amlogic@lists.infradead.org>,
dl-linux-imx <linux-imx@nxp.com>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-rockchip@lists.infradead.org"
<linux-rockchip@lists.infradead.org>
Cc: Heiko Stuebner <heiko@sntech.de>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Neil Armstrong <narmstrong@baylibre.com>,
Shawn Guo <shawnguo@kernel.org>,
Lars-Peter Clausen <lars@metafoo.de>,
Jyoti Bhayana <jbhayana@google.com>,
Hans de Goede <hdegoede@redhat.com>,
Andriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Cixi Geng <cixi.geng1@unisoc.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Ciprian Regus <ciprian.regus@analog.com>,
Fabio Estevam <festevam@gmail.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Alexandru Ardelean <aardelean@deviqon.com>,
Florian Boor <florian.boor@kernelconcepts.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Orson Zhai <orsonzhai@gmail.com>, Chen-Yu Tsai <wens@csie.org>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Vladimir Zapolskiy <vz@mleia.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
Jerome Brunet <jbrunet@baylibre.com>,
Kevin Hilman <khilman@baylibre.com>,
Jonathan Cameron <jic23@kernel.org>
Subject: RE: [PATCH v2 09/16] iio: adc: vf610_adc: add helper function to read samples
Date: Sun, 9 Oct 2022 02:10:10 +0000 [thread overview]
Message-ID: <DB7PR04MB4010695F5EB018F5FF95CB0290219@DB7PR04MB4010.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20221004134909.1692021-10-nuno.sa@analog.com>
> -----Original Message-----
> From: Nuno Sá <nuno.sa@analog.com>
> Sent: 2022年10月4日 21:49
> To: linux-amlogic@lists.infradead.org; dl-linux-imx <linux-imx@nxp.com>;
> linux-iio@vger.kernel.org; linux-arm-kernel@lists.infradead.org;
> linux-rockchip@lists.infradead.org
> Cc: Heiko Stuebner <heiko@sntech.de>; Martin Blumenstingl
> <martin.blumenstingl@googlemail.com>; Neil Armstrong
> <narmstrong@baylibre.com>; Shawn Guo <shawnguo@kernel.org>; Lars-Peter
> Clausen <lars@metafoo.de>; Jyoti Bhayana <jbhayana@google.com>; Hans de
> Goede <hdegoede@redhat.com>; Andriy Tryshnivskyy
> <andriy.tryshnivskyy@opensynergy.com>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Miquel Raynal <miquel.raynal@bootlin.com>; Cixi
> Geng <cixi.geng1@unisoc.com>; Baolin Wang
> <baolin.wang@linux.alibaba.com>; Ciprian Regus <ciprian.regus@analog.com>;
> Fabio Estevam <festevam@gmail.com>; Nuno Sá <nuno.sa@analog.com>;
> Sascha Hauer <s.hauer@pengutronix.de>; Alexandru Ardelean
> <aardelean@deviqon.com>; Florian Boor <florian.boor@kernelconcepts.de>;
> Michael Hennerich <Michael.Hennerich@analog.com>; Orson Zhai
> <orsonzhai@gmail.com>; Chen-Yu Tsai <wens@csie.org>; Chunyan Zhang
> <zhang.lyra@gmail.com>; Vladimir Zapolskiy <vz@mleia.com>; Andy
> Shevchenko <andy.shevchenko@gmail.com>; Jerome Brunet
> <jbrunet@baylibre.com>; Bough Chen <haibo.chen@nxp.com>; Kevin Hilman
> <khilman@baylibre.com>; Jonathan Cameron <jic23@kernel.org>
> Subject: [PATCH v2 09/16] iio: adc: vf610_adc: add helper function to read
> samples
>
> This is a precursor change to make it simpler to remove the 'mlock'
> usage. Having the code in it's own helper function, also makes it easier to read
> the error paths.
>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> drivers/iio/adc/vf610_adc.c | 94 +++++++++++++++++++++----------------
> 1 file changed, 54 insertions(+), 40 deletions(-)
>
> diff --git a/drivers/iio/adc/vf610_adc.c b/drivers/iio/adc/vf610_adc.c index
> c6b16cf6e367..a6f9182d7766 100644
> --- a/drivers/iio/adc/vf610_adc.c
> +++ b/drivers/iio/adc/vf610_adc.c
> @@ -622,6 +622,58 @@ static const struct attribute_group
> vf610_attribute_group = {
> .attrs = vf610_attributes,
> };
>
> +static int vf610_read_sample(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan, int *val) {
> + struct vf610_adc *info = iio_priv(indio_dev);
> + unsigned int hc_cfg;
> + int ret;
> +
> + mutex_lock(&indio_dev->mlock);
> + if (iio_buffer_enabled(indio_dev)) {
> + ret = -EBUSY;
> + goto out_unlock;
> + }
> +
> + reinit_completion(&info->completion);
> + hc_cfg = VF610_ADC_ADCHC(chan->channel);
> + hc_cfg |= VF610_ADC_AIEN;
> + writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
> + ret = wait_for_completion_interruptible_timeout(&info->completion,
> + VF610_ADC_TIMEOUT);
> + if (ret == 0) {
> + ret = -ETIMEDOUT;
> + goto out_unlock;
> + }
> +
> + if (ret < 0)
> + goto out_unlock;
> +
> + switch (chan->type) {
> + case IIO_VOLTAGE:
> + *val = info->value;
> + break;
> + case IIO_TEMP:
> + /*
> + * Calculate in degree Celsius times 1000
> + * Using the typical sensor slope of 1.84 mV/°C
> + * and VREFH_ADC at 3.3V, V at 25°C of 699 mV
> + */
> + *val = 25000 - ((int)info->value - VF610_VTEMP25_3V3) *
> + 1000000 / VF610_TEMP_SLOPE_COEFF;
> +
> + break;
> + default:
> + ret = -EINVAL;
> + break;
> + }
> +
> +out_unlock:
> + mutex_unlock(&indio_dev->mlock);
> +
> + return ret;
> +}
> +
> static int vf610_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val,
> @@ -629,53 +681,15 @@ static int vf610_read_raw(struct iio_dev *indio_dev,
> long mask)
> {
> struct vf610_adc *info = iio_priv(indio_dev);
> - unsigned int hc_cfg;
> long ret;
>
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> case IIO_CHAN_INFO_PROCESSED:
> - mutex_lock(&indio_dev->mlock);
> - if (iio_buffer_enabled(indio_dev)) {
> - mutex_unlock(&indio_dev->mlock);
> - return -EBUSY;
> - }
> -
> - reinit_completion(&info->completion);
> - hc_cfg = VF610_ADC_ADCHC(chan->channel);
> - hc_cfg |= VF610_ADC_AIEN;
> - writel(hc_cfg, info->regs + VF610_REG_ADC_HC0);
> - ret = wait_for_completion_interruptible_timeout
> - (&info->completion, VF610_ADC_TIMEOUT);
> - if (ret == 0) {
> - mutex_unlock(&indio_dev->mlock);
> - return -ETIMEDOUT;
> - }
> - if (ret < 0) {
> - mutex_unlock(&indio_dev->mlock);
> + ret = vf610_read_sample(indio_dev, chan, val);
> + if (ret < 0)
> return ret;
> - }
> -
> - switch (chan->type) {
> - case IIO_VOLTAGE:
> - *val = info->value;
> - break;
> - case IIO_TEMP:
> - /*
> - * Calculate in degree Celsius times 1000
> - * Using the typical sensor slope of 1.84 mV/°C
> - * and VREFH_ADC at 3.3V, V at 25°C of 699 mV
> - */
> - *val = 25000 - ((int)info->value - VF610_VTEMP25_3V3) *
> - 1000000 / VF610_TEMP_SLOPE_COEFF;
> -
> - break;
> - default:
> - mutex_unlock(&indio_dev->mlock);
> - return -EINVAL;
> - }
>
> - mutex_unlock(&indio_dev->mlock);
> return IIO_VAL_INT;
>
> case IIO_CHAN_INFO_SCALE:
> --
> 2.37.3
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
next prev parent reply other threads:[~2022-10-09 2:10 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 13:48 [PATCH v2 00/16] Make 'mlock' really private Nuno Sá
2022-10-04 13:48 ` [PATCH v2 01/16] iio: adc: ad799x: do not use internal iio_dev lock Nuno Sá
2022-10-09 11:53 ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 02/16] iio: adc: axp288_adc: " Nuno Sá
2022-10-09 11:55 ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 03/16] iio: adc: imx7d_adc: " Nuno Sá
2022-10-09 2:00 ` Bough Chen
2022-10-09 11:56 ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 04/16] iio: adc: lpc32xx_adc: " Nuno Sá
2022-10-09 11:57 ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 05/16] iio: adc: ltc2947-core: " Nuno Sá
2022-10-09 11:58 ` Jonathan Cameron
2022-10-04 13:48 ` [PATCH v2 06/16] iio: adc: meson_saradc: " Nuno Sá
2022-10-09 12:01 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 07/16] iio: adc: rockchip_saradc: " Nuno Sá
2022-10-05 7:44 ` Heiko Stübner
2022-10-09 12:03 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 08/16] iio: adc: sc27xx_adc: " Nuno Sá
2022-10-09 12:05 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 09/16] iio: adc: vf610_adc: add helper function to read samples Nuno Sá
2022-10-09 2:10 ` Bough Chen [this message]
2022-10-04 13:49 ` [PATCH v2 10/16] iio: adc: vf610_adc: vf610_adc: do not use internal iio_dev lock Nuno Sá
2022-10-09 2:10 ` Bough Chen
2022-10-04 13:49 ` [PATCH v2 11/16] iio: common: scmi_iio: " Nuno Sá
2022-10-09 12:09 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 12/16] iio: gyro: itg3200_core: " Nuno Sá
2022-10-09 12:10 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 13/16] iio: core: introduce iio_device_{claim|release}_buffer_mode() APIs Nuno Sá
2022-10-04 14:08 ` Andy Shevchenko
2022-10-05 8:37 ` Nuno Sá
2022-10-09 11:41 ` Jonathan Cameron
2022-10-10 7:03 ` Nuno Sá
2022-10-04 13:49 ` [PATCH v2 14/16] iio: health: max30100: do not use internal iio_dev lock Nuno Sá
2022-10-04 14:13 ` Andy Shevchenko
2022-10-05 8:09 ` Nuno Sá
2022-10-09 12:14 ` Jonathan Cameron
2022-10-04 13:49 ` [PATCH v2 15/16] iio: health: max30102: " Nuno Sá
2022-10-04 14:15 ` Andy Shevchenko
2022-10-05 8:17 ` Nuno Sá
2022-10-09 11:44 ` Jonathan Cameron
2022-10-09 12:16 ` Jonathan Cameron
2022-10-10 7:08 ` Nuno Sá
2022-10-04 13:49 ` [PATCH v2 16/16] iio: core: move 'mlock' to 'struct iio_dev_opaque' Nuno Sá
2022-10-04 14:21 ` Andy Shevchenko
2022-10-05 8:40 ` Nuno Sá
2022-10-09 11:48 ` Jonathan Cameron
2022-10-09 11:52 ` Jonathan Cameron
2022-10-10 8:30 ` Andy Shevchenko
2022-10-09 12:19 ` Jonathan Cameron
2022-10-10 7:11 ` Nuno Sá
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=DB7PR04MB4010695F5EB018F5FF95CB0290219@DB7PR04MB4010.eurprd04.prod.outlook.com \
--to=haibo.chen@nxp.com \
--cc=Michael.Hennerich@analog.com \
--cc=aardelean@deviqon.com \
--cc=andriy.tryshnivskyy@opensynergy.com \
--cc=andy.shevchenko@gmail.com \
--cc=baolin.wang@linux.alibaba.com \
--cc=ciprian.regus@analog.com \
--cc=cixi.geng1@unisoc.com \
--cc=festevam@gmail.com \
--cc=florian.boor@kernelconcepts.de \
--cc=hdegoede@redhat.com \
--cc=heiko@sntech.de \
--cc=jbhayana@google.com \
--cc=jbrunet@baylibre.com \
--cc=jic23@kernel.org \
--cc=kernel@pengutronix.de \
--cc=khilman@baylibre.com \
--cc=lars@metafoo.de \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-rockchip@lists.infradead.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=miquel.raynal@bootlin.com \
--cc=narmstrong@baylibre.com \
--cc=nuno.sa@analog.com \
--cc=orsonzhai@gmail.com \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=vz@mleia.com \
--cc=wens@csie.org \
--cc=zhang.lyra@gmail.com \
/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
all inboxes | Powered by JetHome®