linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: Add scaling support to exynos adc driver
@ 2020-05-08 21:14 Jonathan Bakker
  2020-05-10 10:24 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Bakker @ 2020-05-08 21:14 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw, kgene, krzk
  Cc: cw00.choi, kstewart, mpe, m.szyprowski, swboyd, tglx, linux-iio,
	linux-arm-kernel, linux-samsung-soc, linux-kernel,
	Jonathan Bakker

Currently the driver only exposes the raw counts.  As we
have the regulator voltage and the maximum value (stored in
the data mask), we can trivially produce a scaling fraction
of voltage / max value.

This assumes that the regulator voltage is in fact the max
voltage, which appears to be the case for all mainline dts
and cross referenced with the public Exynos4412 and S5PV210
datasheets.

Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
---
 drivers/iio/adc/exynos_adc.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index 22131a677445..9d29b56805cd 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -531,8 +531,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
 	unsigned long timeout;
 	int ret;
 
-	if (mask != IIO_CHAN_INFO_RAW)
+	if (mask == IIO_CHAN_INFO_SCALE) {
+		ret = regulator_get_voltage(info->vdd);
+		if (ret < 0)
+			return ret;
+
+		/* Regulator voltage is in uV, but need mV */
+		*val = ret / 1000;
+		*val2 = info->data->mask;
+
+		return IIO_VAL_FRACTIONAL;
+	} else if (mask != IIO_CHAN_INFO_RAW) {
 		return -EINVAL;
+	}
 
 	mutex_lock(&indio_dev->mlock);
 	reinit_completion(&info->completion);
@@ -683,6 +694,7 @@ static const struct iio_info exynos_adc_iio_info = {
 	.channel = _index,				\
 	.address = _index,				\
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
+	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),	\
 	.datasheet_name = _id,				\
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: Add scaling support to exynos adc driver
  2020-05-08 21:14 [PATCH] iio: adc: Add scaling support to exynos adc driver Jonathan Bakker
@ 2020-05-10 10:24 ` Jonathan Cameron
  2020-05-11  7:42   ` Krzysztof Kozlowski
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2020-05-10 10:24 UTC (permalink / raw)
  To: Jonathan Bakker
  Cc: knaack.h, lars, pmeerw, kgene, krzk, cw00.choi, kstewart, mpe,
	m.szyprowski, swboyd, tglx, linux-iio, linux-arm-kernel,
	linux-samsung-soc, linux-kernel

On Fri,  8 May 2020 14:14:00 -0700
Jonathan Bakker <xc-racer2@live.ca> wrote:

> Currently the driver only exposes the raw counts.  As we
> have the regulator voltage and the maximum value (stored in
> the data mask), we can trivially produce a scaling fraction
> of voltage / max value.
> 
> This assumes that the regulator voltage is in fact the max
> voltage, which appears to be the case for all mainline dts
> and cross referenced with the public Exynos4412 and S5PV210
> datasheets.
> 
> Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>

Seems reasonable to me. I'd like an exynos Ack though before applying.

thanks,

Jonathan


> ---
>  drivers/iio/adc/exynos_adc.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index 22131a677445..9d29b56805cd 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -531,8 +531,19 @@ static int exynos_read_raw(struct iio_dev *indio_dev,
>  	unsigned long timeout;
>  	int ret;
>  
> -	if (mask != IIO_CHAN_INFO_RAW)
> +	if (mask == IIO_CHAN_INFO_SCALE) {
> +		ret = regulator_get_voltage(info->vdd);
> +		if (ret < 0)
> +			return ret;
> +
> +		/* Regulator voltage is in uV, but need mV */
> +		*val = ret / 1000;
> +		*val2 = info->data->mask;
> +
> +		return IIO_VAL_FRACTIONAL;
> +	} else if (mask != IIO_CHAN_INFO_RAW) {
>  		return -EINVAL;
> +	}
>  
>  	mutex_lock(&indio_dev->mlock);
>  	reinit_completion(&info->completion);
> @@ -683,6 +694,7 @@ static const struct iio_info exynos_adc_iio_info = {
>  	.channel = _index,				\
>  	.address = _index,				\
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
> +	.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),	\
>  	.datasheet_name = _id,				\
>  }
>  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: Add scaling support to exynos adc driver
  2020-05-10 10:24 ` Jonathan Cameron
@ 2020-05-11  7:42   ` Krzysztof Kozlowski
  2020-05-16 18:19     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2020-05-11  7:42 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Jonathan Bakker, knaack.h, lars, pmeerw, kgene, cw00.choi,
	kstewart, mpe, m.szyprowski, swboyd, tglx, linux-iio,
	linux-arm-kernel, linux-samsung-soc, linux-kernel

On Sun, May 10, 2020 at 11:24:17AM +0100, Jonathan Cameron wrote:
> On Fri,  8 May 2020 14:14:00 -0700
> Jonathan Bakker <xc-racer2@live.ca> wrote:
> 
> > Currently the driver only exposes the raw counts.  As we
> > have the regulator voltage and the maximum value (stored in
> > the data mask), we can trivially produce a scaling fraction
> > of voltage / max value.
> > 
> > This assumes that the regulator voltage is in fact the max
> > voltage, which appears to be the case for all mainline dts
> > and cross referenced with the public Exynos4412 and S5PV210
> > datasheets.
> > 
> > Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
> 
> Seems reasonable to me. I'd like an exynos Ack though before applying.


It's correct, at least with ARMv7 Exynos datasheets

The few ARMv8 Exynos chips are silent about the voltage levels. The
Exynos 7 DTS board in mainline kernel does not have regulator but it
looks clearly like mistake.

I think they behave the same, so for Exynos:
Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>

Best regards,
Krzysztof

> thanks,
> 
> Jonathan
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] iio: adc: Add scaling support to exynos adc driver
  2020-05-11  7:42   ` Krzysztof Kozlowski
@ 2020-05-16 18:19     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-05-16 18:19 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Jonathan Bakker, knaack.h, lars, pmeerw, kgene, cw00.choi,
	kstewart, mpe, m.szyprowski, swboyd, tglx, linux-iio,
	linux-arm-kernel, linux-samsung-soc, linux-kernel

On Mon, 11 May 2020 09:42:32 +0200
Krzysztof Kozlowski <krzk@kernel.org> wrote:

> On Sun, May 10, 2020 at 11:24:17AM +0100, Jonathan Cameron wrote:
> > On Fri,  8 May 2020 14:14:00 -0700
> > Jonathan Bakker <xc-racer2@live.ca> wrote:
> >   
> > > Currently the driver only exposes the raw counts.  As we
> > > have the regulator voltage and the maximum value (stored in
> > > the data mask), we can trivially produce a scaling fraction
> > > of voltage / max value.
> > > 
> > > This assumes that the regulator voltage is in fact the max
> > > voltage, which appears to be the case for all mainline dts
> > > and cross referenced with the public Exynos4412 and S5PV210
> > > datasheets.
> > > 
> > > Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>  
> > 
> > Seems reasonable to me. I'd like an exynos Ack though before applying.  
> 
> 
> It's correct, at least with ARMv7 Exynos datasheets
> 
> The few ARMv8 Exynos chips are silent about the voltage levels. The
> Exynos 7 DTS board in mainline kernel does not have regulator but it
> looks clearly like mistake.
> 
> I think they behave the same, so for Exynos:
> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>
Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to poke at it.

Thanks,

Jonathan

> 
> Best regards,
> Krzysztof
> 
> > thanks,
> > 
> > Jonathan
> > 
> >   


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-05-16 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 21:14 [PATCH] iio: adc: Add scaling support to exynos adc driver Jonathan Bakker
2020-05-10 10:24 ` Jonathan Cameron
2020-05-11  7:42   ` Krzysztof Kozlowski
2020-05-16 18:19     ` Jonathan Cameron

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).