Re: [PATCH] iio:adc:twl6030: Enable measurements of VUSB, VBAT and others

From: Jonathan Cameron
Date: Sun Dec 04 2022 - 10:29:37 EST


On Thu, 1 Dec 2022 19:16:35 +0100
Andreas Kemnade <andreas@xxxxxxxxxxxx> 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@xxxxxxxxxxxx>

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;