All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others
@ 2022-12-01 18:16 Andreas Kemnade
  2022-12-04 15:41 ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Kemnade @ 2022-12-01 18:16 UTC (permalink / raw)
  To: jic23, lars, andreas, jiasheng, paul, linux-iio, linux-kernel,
	Tony Lindgren

Some inputs need to be wired up to produce proper measurements,
without this change only near zero values are reported.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
 drivers/iio/adc/twl6030-gpadc.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
index f53e8558b560c..40438e5b49702 100644
--- a/drivers/iio/adc/twl6030-gpadc.c
+++ b/drivers/iio/adc/twl6030-gpadc.c
@@ -57,6 +57,18 @@
 #define TWL6030_GPADCS				BIT(1)
 #define TWL6030_GPADCR				BIT(0)
 
+#define USB_VBUS_CTRL_SET			0x04
+#define USB_ID_CTRL_SET				0x06
+
+#define TWL6030_MISC1				0xE4
+#define VBUS_MEAS				0x01
+#define ID_MEAS					0x01
+
+#define VAC_MEAS                0x04
+#define VBAT_MEAS               0x02
+#define BB_MEAS                 0x01
+
+
 /**
  * struct twl6030_chnl_calib - channel calibration
  * @gain:		slope coefficient for ideal curve
@@ -927,6 +939,26 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
+	if (ret < 0) {
+		dev_err(dev, "failed to wire up inputs\n");
+		return ret;
+	}
+
+	ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
+	if (ret < 0) {
+		dev_err(dev, "failed to wire up inputs\n");
+		return ret;
+	}
+
+	ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
+				VBAT_MEAS | BB_MEAS | BB_MEAS,
+				TWL6030_MISC1);
+	if (ret < 0) {
+		dev_err(dev, "failed to wire up inputs\n");
+		return ret;
+	}
+
 	indio_dev->name = DRIVER_NAME;
 	indio_dev->info = &twl6030_gpadc_iio_info;
 	indio_dev->modes = INDIO_DIRECT_MODE;
-- 
2.30.2


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

* Re: [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others
  2022-12-01 18:16 [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others Andreas Kemnade
@ 2022-12-04 15:41 ` Jonathan Cameron
  2022-12-04 20:27   ` Andreas Kemnade
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2022-12-04 15:41 UTC (permalink / raw)
  To: Andreas Kemnade
  Cc: lars, jiasheng, paul, linux-iio, linux-kernel, Tony Lindgren

On Thu,  1 Dec 2022 19:16:35 +0100
Andreas Kemnade <andreas@kemnade.info> wrote:

> Some inputs need to be wired up to produce proper measurements,
> without this change only near zero values are reported.
> 
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>

Sounds like a fix to me.  If so, Fixes tag?

Anything in here we should be turning off again if the driver is removed 
or toggling on suspend? If not, other than the space below this looks fine to me.

Jonathan

> ---
>  drivers/iio/adc/twl6030-gpadc.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/iio/adc/twl6030-gpadc.c b/drivers/iio/adc/twl6030-gpadc.c
> index f53e8558b560c..40438e5b49702 100644
> --- a/drivers/iio/adc/twl6030-gpadc.c
> +++ b/drivers/iio/adc/twl6030-gpadc.c
> @@ -57,6 +57,18 @@
>  #define TWL6030_GPADCS				BIT(1)
>  #define TWL6030_GPADCR				BIT(0)
>  
> +#define USB_VBUS_CTRL_SET			0x04
> +#define USB_ID_CTRL_SET				0x06
> +
> +#define TWL6030_MISC1				0xE4
> +#define VBUS_MEAS				0x01
> +#define ID_MEAS					0x01
> +
> +#define VAC_MEAS                0x04
> +#define VBAT_MEAS               0x02
> +#define BB_MEAS                 0x01
> +
I'm always of the view one blank line is enough! I'll tidy this up whilst applying.
> +
>  /**
>   * struct twl6030_chnl_calib - channel calibration
>   * @gain:		slope coefficient for ideal curve
> @@ -927,6 +939,26 @@ static int twl6030_gpadc_probe(struct platform_device *pdev)
>  		return ret;
>  	}
>  
> +	ret = twl_i2c_write_u8(TWL_MODULE_USB, VBUS_MEAS, USB_VBUS_CTRL_SET);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to wire up inputs\n");
> +		return ret;
> +	}
> +
> +	ret = twl_i2c_write_u8(TWL_MODULE_USB, ID_MEAS, USB_ID_CTRL_SET);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to wire up inputs\n");
> +		return ret;
> +	}
> +
> +	ret = twl_i2c_write_u8(TWL6030_MODULE_ID0,
> +				VBAT_MEAS | BB_MEAS | BB_MEAS,
> +				TWL6030_MISC1);
> +	if (ret < 0) {
> +		dev_err(dev, "failed to wire up inputs\n");
> +		return ret;
> +	}
> +
>  	indio_dev->name = DRIVER_NAME;
>  	indio_dev->info = &twl6030_gpadc_iio_info;
>  	indio_dev->modes = INDIO_DIRECT_MODE;


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

* Re: [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others
  2022-12-04 15:41 ` Jonathan Cameron
@ 2022-12-04 20:27   ` Andreas Kemnade
  2022-12-11 11:53     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Kemnade @ 2022-12-04 20:27 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: lars, jiasheng, paul, linux-iio, linux-kernel, Tony Lindgren

On Sun, 4 Dec 2022 15:41:52 +0000
Jonathan Cameron <jic23@kernel.org> wrote:

> On Thu,  1 Dec 2022 19:16:35 +0100
> Andreas Kemnade <andreas@kemnade.info> wrote:
> 
> > Some inputs need to be wired up to produce proper measurements,
> > without this change only near zero values are reported.
> > 
> > Signed-off-by: Andreas Kemnade <andreas@kemnade.info>  
> 
> Sounds like a fix to me.  If so, Fixes tag?

seems to be there since the beginning, to it would be
Fixes: 1696f36482e70 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")

I think it was just not used with the charger (which is not in mainline yet),
so it was probably ignored.

> 
> Anything in here we should be turning off again if the driver is removed 
> or toggling on suspend? If not, other than the space below this looks fine to me.
> 
I would consider that as configuration, comparing with the nearest relative twl4030,
there a similar bit is set in the probe() without disabling it in the remove().

But I think we should set TWL6030_GPADCR in remove() as we do in suspend(),
but that is another fix.

Regards,
Andreas

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

* Re: [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others
  2022-12-04 20:27   ` Andreas Kemnade
@ 2022-12-11 11:53     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2022-12-11 11:53 UTC (permalink / raw)
  To: Andreas Kemnade
  Cc: lars, jiasheng, paul, linux-iio, linux-kernel, Tony Lindgren

On Sun, 4 Dec 2022 21:27:51 +0100
Andreas Kemnade <andreas@kemnade.info> wrote:

> On Sun, 4 Dec 2022 15:41:52 +0000
> Jonathan Cameron <jic23@kernel.org> wrote:
> 
> > On Thu,  1 Dec 2022 19:16:35 +0100
> > Andreas Kemnade <andreas@kemnade.info> wrote:
> >   
> > > Some inputs need to be wired up to produce proper measurements,
> > > without this change only near zero values are reported.
> > > 
> > > Signed-off-by: Andreas Kemnade <andreas@kemnade.info>    
> > 
> > Sounds like a fix to me.  If so, Fixes tag?  
> 
> seems to be there since the beginning, to it would be
> Fixes: 1696f36482e70 ("iio: twl6030-gpadc: TWL6030, TWL6032 GPADC driver")
> 
> I think it was just not used with the charger (which is not in mainline yet),
> so it was probably ignored.
Makes sense.  I've applied it at marked it for stable on basis it wants the
fixes tag and would get picked up anyway + appears unlikely to have bad side effects.
> 
> > 
> > Anything in here we should be turning off again if the driver is removed 
> > or toggling on suspend? If not, other than the space below this looks fine to me.
> >   
> I would consider that as configuration, comparing with the nearest relative twl4030,
> there a similar bit is set in the probe() without disabling it in the remove().
> 
> But I think we should set TWL6030_GPADCR in remove() as we do in suspend(),
> but that is another fix.

There are always more fixes :)

Jonathan

> 
> Regards,
> Andreas


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

end of thread, other threads:[~2022-12-11 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 18:16 [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others Andreas Kemnade
2022-12-04 15:41 ` Jonathan Cameron
2022-12-04 20:27   ` Andreas Kemnade
2022-12-11 11:53     ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.