Skip to contentSkip to conversation

Correction and clean-up

PATCH New Adam YH Lee 2 participants 5 messages Aug 4, 2015 – Aug 31, 2015 IIO

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 Correction and clean-up

The V4 of this patch addresses issues raised by Jonathan [1].

"iio_device_register" call should be the last call in the probe. All regulators should be configured before that call.

Remove devm_regulator_put as it is not necessary. "devm_allocators" (devm_regulator_get, in this case) does device removal as well as error handling.

[1] http://www.spinics.net/lists/linux-omap/msg120871.html

Adam YH Lee (1):
[TWL4030 MADC] Fix ADC[3:6] readings

 drivers/iio/adc/twl4030-madc.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
Signature · 1 line
2.1.4
#1 lore raw

PATCH v4 1/1 Fix ADC[3:6] readings

MADC[3:6] reads incorrect values without these two following changes:

- enable the 3v1 bias regulator for ADC[3:6]
- configure ADC[3:6] lines as input, not as USB

---
 drivers/iio/adc/twl4030-madc.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/iio/adc/twl4030-madc.c +34 -0
index 94c5f05..8c58498 100644
@@ -45,13 +45,18 @@
 #include <linux/types.h>
 #include <linux/gfp.h>
 #include <linux/err.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/iio/iio.h>
 
+#define TWL4030_USB_SEL_MADC_MCPC	(1<<3)
+#define TWL4030_USB_CARKIT_ANA_CTRL	0xBB
+
 /**
  * struct twl4030_madc_data - a container for madc info
  * @dev:		Pointer to device structure for madc
  * @lock:		Mutex protecting this data structure
+ * @regulator:		Pointer to bias regulator for madc
  * @requests:		Array of request struct corresponding to SW1, SW2 and RT
  * @use_second_irq:	IRQ selection (main or co-processor)
  * @imr:		Interrupt mask register of MADC
@@ -60,6 +65,7 @@
 struct twl4030_madc_data {
 	struct device *dev;
 	struct mutex lock;	/* mutex protecting this data structure */
+	struct regulator *usb3v1;
 	struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
 	bool use_second_irq;
 	u8 imr;
@@ -842,6 +848,32 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	}
 	twl4030_madc = madc;
 
+	/* Configure MADC[3:6] */
+	ret = twl_i2c_read_u8(TWL_MODULE_USB, &regval,
+			TWL4030_USB_CARKIT_ANA_CTRL);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to read reg CARKIT_ANA_CTRL  0x%X\n",
+				TWL4030_USB_CARKIT_ANA_CTRL);
+		goto err_i2c;
+	}
+	regval |= TWL4030_USB_SEL_MADC_MCPC;
+	ret = twl_i2c_write_u8(TWL_MODULE_USB, regval,
+				 TWL4030_USB_CARKIT_ANA_CTRL);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to write reg CARKIT_ANA_CTRL 0x%X\n",
+				TWL4030_USB_CARKIT_ANA_CTRL);
+		goto err_i2c;
+	}
+
+	/* Enable 3v1 bias regulator for MADC[3:6] */
+	madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
+	if (IS_ERR(madc->usb3v1))
+		return -ENODEV;
+
+	ret = regulator_enable(madc->usb3v1);
+	if (ret)
+		dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
+
 	ret = iio_device_register(iio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio device\n");
@@ -867,6 +899,8 @@ static int twl4030_madc_remove(struct platform_device *pdev)
 	twl4030_madc_set_current_generator(madc, 0, 0);
 	twl4030_madc_set_power(madc, 0);
 
+	regulator_disable(madc->usb3v1);
+
 	return 0;
 }
 
Signature · 1 line
2.1.4
maintainer
#2 lore raw

PATCH v4 1/1 Fix ADC[3:6] readings

Quoted 6 lines · Adam YH Lee

MADC[3:6] reads incorrect values without these two following changes:

- enable the 3v1 bias regulator for ADC[3:6]
- configure ADC[3:6] lines as input, not as USB

I'd ideally like an ack from the driver author or Sebastian as this isn't a driver I'm particular familiar with.

Also, for future reference, patches should be titled something like [Patch v4] iio: twl4030 madc: Fix ADC[3:6] readings. (the patch bit is standard, the rest is iio convention)

Jonathan

Quoted 78 lines
---
 drivers/iio/adc/twl4030-madc.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
drivers/iio/adc/twl4030-madc.c +34 -0
index 94c5f05..8c58498 100644
@@ -45,13 +45,18 @@
 #include <linux/types.h>
 #include <linux/gfp.h>
 #include <linux/err.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/iio/iio.h>
 
+#define TWL4030_USB_SEL_MADC_MCPC	(1<<3)
+#define TWL4030_USB_CARKIT_ANA_CTRL	0xBB
+
 /**
  * struct twl4030_madc_data - a container for madc info
  * @dev:		Pointer to device structure for madc
  * @lock:		Mutex protecting this data structure
+ * @regulator:		Pointer to bias regulator for madc
  * @requests:		Array of request struct corresponding to SW1, SW2 and RT
  * @use_second_irq:	IRQ selection (main or co-processor)
  * @imr:		Interrupt mask register of MADC
@@ -60,6 +65,7 @@
 struct twl4030_madc_data {
 	struct device *dev;
 	struct mutex lock;	/* mutex protecting this data structure */
+	struct regulator *usb3v1;
 	struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
 	bool use_second_irq;
 	u8 imr;
@@ -842,6 +848,32 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	}
 	twl4030_madc = madc;
 
+	/* Configure MADC[3:6] */
+	ret = twl_i2c_read_u8(TWL_MODULE_USB, &regval,
+			TWL4030_USB_CARKIT_ANA_CTRL);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to read reg CARKIT_ANA_CTRL  0x%X\n",
+				TWL4030_USB_CARKIT_ANA_CTRL);
+		goto err_i2c;
+	}
+	regval |= TWL4030_USB_SEL_MADC_MCPC;
+	ret = twl_i2c_write_u8(TWL_MODULE_USB, regval,
+				 TWL4030_USB_CARKIT_ANA_CTRL);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to write reg CARKIT_ANA_CTRL 0x%X\n",
+				TWL4030_USB_CARKIT_ANA_CTRL);
+		goto err_i2c;
+	}
+
+	/* Enable 3v1 bias regulator for MADC[3:6] */
+	madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
+	if (IS_ERR(madc->usb3v1))
+		return -ENODEV;
+
+	ret = regulator_enable(madc->usb3v1);
+	if (ret)
+		dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
+
 	ret = iio_device_register(iio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio device\n");
@@ -867,6 +899,8 @@ static int twl4030_madc_remove(struct platform_device *pdev)
 	twl4030_madc_set_current_generator(madc, 0, 0);
 	twl4030_madc_set_power(madc, 0);
 
+	regulator_disable(madc->usb3v1);
+
 	return 0;
 }
 
author
#3 lore raw

Re: [V4] [TWL4030 MADC] Fix ADC[3:6] readings

Yes I will do a better job in following the patch submission conventions. Thanks for your comment Jonathan.

@Sebastian, let me know if you have any concerns with the patch.

Quoted 103 lines · Jonathan Cameron
Quoted 6 lines · Adam YH Lee

MADC[3:6] reads incorrect values without these two following changes:

- enable the 3v1 bias regulator for ADC[3:6]
- configure ADC[3:6] lines as input, not as USB

I'd ideally like an ack from the driver author or Sebastian as this isn't a driver I'm particular familiar with.

Also, for future reference, patches should be titled something like [Patch v4] iio: twl4030 madc: Fix ADC[3:6] readings. (the patch bit is standard, the rest is iio convention)

Jonathan

Review

Quoted 5 lines
---
 drivers/iio/adc/twl4030-madc.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/adc/twl4030-madc.c

Quoted 10 lines

index 94c5f05..8c58498 100644

drivers/iio/adc/twl4030-madc.c +1 -0
@@ -45,13 +45,18 @@
 #include <linux/types.h>
 #include <linux/gfp.h>
 #include <linux/err.h>
+#include <linux/regulator/consumer.h>
 
 #include <linux/iio/iio.h>

drivers/iio/adc/twl4030-madc.c line 60

Quoted 10 lines
drivers/iio/adc/twl4030-madc.c +4 -0
 
+#define TWL4030_USB_SEL_MADC_MCPC    (1<<3)
+#define TWL4030_USB_CARKIT_ANA_CTRL  0xBB
+
 /**
  * struct twl4030_madc_data - a container for madc info
  * @dev:             Pointer to device structure for madc
  * @lock:            Mutex protecting this data structure
+ * @regulator:               Pointer to bias regulator for madc
  * @requests:                Array of request struct corresponding to

SW1, SW2 and RT

drivers/iio/adc/twl4030-madc.c static int twl4030_madc_probe(struct

Quoted 11 lines
drivers/iio/adc/twl4030-madc.c +1 -0
  * @use_second_irq:  IRQ selection (main or co-processor)
  * @imr:             Interrupt mask register of MADC
@@ -60,6 +65,7 @@
 struct twl4030_madc_data {
      struct device *dev;
      struct mutex lock;      /* mutex protecting this data structure */
+     struct regulator *usb3v1;
      struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
      bool use_second_irq;
      u8 imr;
@@ -842,6 +848,32 @@ static int twl4030_madc_probe(struct

platform_device *pdev)

drivers/iio/adc/twl4030-madc.c static int twl4030_madc_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/iio/adc/twl4030-madc.c +5 -0
      }
      twl4030_madc = madc;
 
+     /* Configure MADC[3:6] */
+     ret = twl_i2c_read_u8(TWL_MODULE_USB, &regval,
+                     TWL4030_USB_CARKIT_ANA_CTRL);
+     if (ret) {
+             dev_err(&pdev->dev, "unable to read reg CARKIT_ANA_CTRL

0x%X\n",

drivers/iio/adc/twl4030-madc.c static int twl4030_madc_probe(struct platform_device *pdev)

Quoted 8 lines
drivers/iio/adc/twl4030-madc.c +8 -0
+                             TWL4030_USB_CARKIT_ANA_CTRL);
+             goto err_i2c;
+     }
+     regval |= TWL4030_USB_SEL_MADC_MCPC;
+     ret = twl_i2c_write_u8(TWL_MODULE_USB, regval,
+                              TWL4030_USB_CARKIT_ANA_CTRL);
+     if (ret) {
+             dev_err(&pdev->dev, "unable to write reg CARKIT_ANA_CTRL

0x%X\n",

drivers/iio/adc/twl4030-madc.c static int twl4030_madc_probe(struct platform_device *pdev)

Quoted 12 lines
drivers/iio/adc/twl4030-madc.c +12 -0
+                             TWL4030_USB_CARKIT_ANA_CTRL);
+             goto err_i2c;
+     }
+
+     /* Enable 3v1 bias regulator for MADC[3:6] */
+     madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
+     if (IS_ERR(madc->usb3v1))
+             return -ENODEV;
+
+     ret = regulator_enable(madc->usb3v1);
+     if (ret)
+             dev_err(madc->dev, "could not enable 3v1 bias

regulator\n");

drivers/iio/adc/twl4030-madc.c static int twl4030_madc_remove(struct

Quoted 5 lines
drivers/iio/adc/twl4030-madc.c +1 -0
+
      ret = iio_device_register(iio_dev);
      if (ret) {
              dev_err(&pdev->dev, "could not register iio device\n");
@@ -867,6 +899,8 @@ static int twl4030_madc_remove(struct

platform_device *pdev)

Quoted 9 lines
drivers/iio/adc/twl4030-madc.c +2 -0
      twl4030_madc_set_current_generator(madc, 0, 0);
      twl4030_madc_set_power(madc, 0);
 
+     regulator_disable(madc->usb3v1);
+
      return 0;
 }
 
maintainer
#4 lore raw

PATCH v4 1/1 Fix ADC[3:6] readings

Quoted 4 lines · Adam Lee

Yes I will do a better job in following the patch submission conventions. Thanks for your comment Jonathan.

@Sebastian, let me know if you have any concerns with the patch.

This has been sat around for long enough that I suspect Sebastian isn't going to reply. As such I've just applied it as is to the fixes-togreg branch of iio.git (with some editing of the patch description!)

Thanks,

Jonathan

Quoted 100 lines · On Sat, Aug 8, 2015 at 8:15 AM Jonathan Cameron <jic23 at kernel.org…
    On 04/08/15 19:15, Adam YH Lee wrote:
    > MADC[3:6] reads incorrect values without these two following changes:
    >
    > - enable the 3v1 bias regulator for ADC[3:6]
    > - configure ADC[3:6] lines as input, not as USB
    >
    > Signed-off-by: Adam YH Lee <adam.yh.lee at gmail.com <mailto:[email protected]>>
    I'd ideally like an ack from the driver author or Sebastian as this isn't
    a driver I'm particular familiar with.

    Also, for future reference, patches should be titled something like
    [Patch v4] iio: twl4030 madc: Fix ADC[3:6] readings.
    (the patch bit is standard, the rest is iio convention)

    Jonathan

    > ---
    >  drivers/iio/adc/twl4030-madc.c | 34 ++++++++++++++++++++++++++++++++++
    >  1 file changed, 34 insertions(+)
    >
    > diff --git a/drivers/iio/adc/twl4030-madc.c b/drivers/iio/adc/twl4030-madc.c
    > index 94c5f05..8c58498 100644
    > --- a/drivers/iio/adc/twl4030-madc.c
    > +++ b/drivers/iio/adc/twl4030-madc.c
    > @@ -45,13 +45,18 @@
    >  #include <linux/types.h>
    >  #include <linux/gfp.h>
    >  #include <linux/err.h>
    > +#include <linux/regulator/consumer.h>
    >
    >  #include <linux/iio/iio.h>
    >
    > +#define TWL4030_USB_SEL_MADC_MCPC    (1<<3)
    > +#define TWL4030_USB_CARKIT_ANA_CTRL  0xBB
    > +
    >  /**
    >   * struct twl4030_madc_data - a container for madc info
    >   * @dev:             Pointer to device structure for madc
    >   * @lock:            Mutex protecting this data structure
    > + * @regulator:               Pointer to bias regulator for madc
    >   * @requests:                Array of request struct corresponding to SW1, SW2 and RT
    >   * @use_second_irq:  IRQ selection (main or co-processor)
    >   * @imr:             Interrupt mask register of MADC
    > @@ -60,6 +65,7 @@
    >  struct twl4030_madc_data {
    >       struct device *dev;
    >       struct mutex lock;      /* mutex protecting this data structure */
    > +     struct regulator *usb3v1;
    >       struct twl4030_madc_request requests[TWL4030_MADC_NUM_METHODS];
    >       bool use_second_irq;
    >       u8 imr;
    > @@ -842,6 +848,32 @@ static int twl4030_madc_probe(struct platform_device *pdev)
    >       }
    >       twl4030_madc = madc;
    >
    > +     /* Configure MADC[3:6] */
    > +     ret = twl_i2c_read_u8(TWL_MODULE_USB, &regval,
    > +                     TWL4030_USB_CARKIT_ANA_CTRL);
    > +     if (ret) {
    > +             dev_err(&pdev->dev, "unable to read reg CARKIT_ANA_CTRL  0x%X\n",
    > +                             TWL4030_USB_CARKIT_ANA_CTRL);
    > +             goto err_i2c;
    > +     }
    > +     regval |= TWL4030_USB_SEL_MADC_MCPC;
    > +     ret = twl_i2c_write_u8(TWL_MODULE_USB, regval,
    > +                              TWL4030_USB_CARKIT_ANA_CTRL);
    > +     if (ret) {
    > +             dev_err(&pdev->dev, "unable to write reg CARKIT_ANA_CTRL 0x%X\n",
    > +                             TWL4030_USB_CARKIT_ANA_CTRL);
    > +             goto err_i2c;
    > +     }
    > +
    > +     /* Enable 3v1 bias regulator for MADC[3:6] */
    > +     madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
    > +     if (IS_ERR(madc->usb3v1))
    > +             return -ENODEV;
    > +
    > +     ret = regulator_enable(madc->usb3v1);
    > +     if (ret)
    > +             dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
    > +
    >       ret = iio_device_register(iio_dev);
    >       if (ret) {
    >               dev_err(&pdev->dev, "could not register iio device\n");
    > @@ -867,6 +899,8 @@ static int twl4030_madc_remove(struct platform_device *pdev)
    >       twl4030_madc_set_current_generator(madc, 0, 0);
    >       twl4030_madc_set_power(madc, 0);
    >
    > +     regulator_disable(madc->usb3v1);
    > +
    >       return 0;
    >  }
    >
    >