Skip to contentSkip to conversation

iio: adc: axp288: Drop bogus AXP288_ADC_TS_PIN_CTRL register modifications

PATCH In review Hans de Goede 7 participants 11 messages Dec 14, 2016 – Jan 8, 2017 2 messages not in the archive

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: axp288: Drop bogus AXP288_ADC_TS_PIN_CTRL register modifications

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

---
 drivers/iio/adc/axp288_adc.c | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
drivers/iio/adc/axp288_adc.c +1 -31
index 7fd2494..64799ad 100644
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val, unsigned long address,
 	return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
-}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 	mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address, info->regmap);
-		if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin restore\n");
 		break;
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to function */
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
-}
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system suspend.
 	 * otherwise internal fuel gauge functionality may be affected.
 	 */
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
 	if (ret) {
 		dev_err(&pdev->dev, "unable to enable ADC device\n");
 		return ret;
Signature · 1 line
2.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 18 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

Quoted 5 lines

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

Note that I do not have hardware to test this.

maintainer
#2 lore raw
In reply to Hans de Goede
Quoted 18 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

Quoted 5 lines

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

I guess you probably have more up to date contact details than I do, but seems worth trying to cc Jacob Pan on this to see if we can find out what the original reasoning behind this was. Seems a very odd thing to do with no purpose!

If Jacob isn't contactable we'll fall back to guessing it was just an oddity of driver evolution.

Jonathan

Quoted 77 lines
---
 drivers/iio/adc/axp288_adc.c | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
drivers/iio/adc/axp288_adc.c +1 -31
index 7fd2494..64799ad 100644
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val, unsigned long address,
 	return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
-}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 	mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address, info->regmap);
-		if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin restore\n");
 		break;
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 	return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to function */
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
-}
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system suspend.
 	 * otherwise internal fuel gauge functionality may be affected.
 	 */
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
 	if (ret) {
 		dev_err(&pdev->dev, "unable to enable ADC device\n");
 		return ret;

A message that is not in the archive (sent off-list or not yet received): 1f31b2e7-90fa-0fb8-5f6e-a8ee2ddf69f7-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#4 lore raw
Quoted 9 lines · On Fri, 30 Dec 2016 16:46:03 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 8 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

It has been a while. Just looked at the datasheet, reg 84h is for ADC and TS pin control. IIRC, we had to set the TS bits in order to make ADC read to work. What is the other register?

Quoted 5 lines
Quoted 5 lines

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

Agreed, it would be better to do read-modify-write and not to touch the other bits.

Quoted 97 lines
Quoted 10 lines

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

I guess you probably have more up to date contact details than I do, but seems worth trying to cc Jacob Pan on this to see if we can find out what the original reasoning behind this was. Seems a very odd thing to do with no purpose!

If Jacob isn't contactable we'll fall back to guessing it was just an oddity of driver evolution.

Jonathan

Quoted 78 lines
---
 drivers/iio/adc/axp288_adc.c | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/adc/axp288_adc.c index 7fd2494..64799ad 100644

drivers/iio/adc/axp288_adc.c +0 -12
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val,
 unsigned long address, return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int
 mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin
 */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
-}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
drivers/iio/adc/axp288_adc.c +0 -9
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address,
 info->regmap);
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin

restore\n"); break;

drivers/iio/adc/axp288_adc.c +0 -3
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to

function */

drivers/iio/adc/axp288_adc.c +0 -1
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,

AXP288_ADC_TS_PIN_ON))

drivers/iio/adc/axp288_adc.c +0 -3
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); -}

drivers/iio/adc/axp288_adc.c +0 -1
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct
 platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system

suspend.

Quoted 9 lines
Quoted 8 lines

* otherwise internal fuel gauge functionality may be
affected. */

drivers/iio/adc/axp288_adc.c +1 -1
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); if (ret) {
dev_err(&pdev->dev, "unable to enable ADC
device\n"); return ret;

[Jacob Pan]

#5 lore raw

Hi,

Quoted 8 lines · Jacob Pan
Quoted 5 lines · On Fri, 30 Dec 2016 16:46:03 +0000 Jonathan Cameron…
Quoted 4 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

It has been a while. Just looked at the datasheet, reg 84h is for ADC and TS pin control. IIRC, we had to set the TS bits in order to make ADC read to work.

The bits the code I'm removing are manipulating are bits 0 & 1 of reg 84h which are:

1-0 Current source from TS pin on/off enable bit [1:0]

00: off
01: on when charging battery, off when not charging
10: on in ADC phase and off when out of the ADC phase, for power saving 11: always on

And they are being toggled between 10 and 11, so in both cases the current source is enabled when reading the adc value. Specifically the code this patch removes are setting these bits to 10 before reading and back to 11 after reading, which makes no sense.

And to make things even funkier, this manipulation is only done when reading the GP_ADC, which is the ADC function of GPIO0, whereas these bits control the bias current source for the TS pin, which is a completely different pin.

So all in all this entire bit of code seems to be big NOP.

Quoted 1 line

What is the other register?

The register to actually enable / disable the bias current source for GPIO0 / the GPADC pin is register 85h, where setting bit 2 enables the GPIO0 output current.

Regards,

Hans

Quoted 116 lines
Quoted 5 lines
Quoted 5 lines

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

Agreed, it would be better to do read-modify-write and not to touch the other bits.

Quoted 97 lines
Quoted 10 lines

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

I guess you probably have more up to date contact details than I do, but seems worth trying to cc Jacob Pan on this to see if we can find out what the original reasoning behind this was. Seems a very odd thing to do with no purpose!

If Jacob isn't contactable we'll fall back to guessing it was just an oddity of driver evolution.

Jonathan

Quoted 78 lines
---
 drivers/iio/adc/axp288_adc.c | 32 +-------------------------------
 1 file changed, 1 insertion(+), 31 deletions(-)
(quoted diff) +0 -0

b/drivers/iio/adc/axp288_adc.c index 7fd2494..64799ad 100644

drivers/iio/adc/axp288_adc.c +0 -12
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val,
 unsigned long address, return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int
 mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin
 */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
-}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
drivers/iio/adc/axp288_adc.c +0 -9
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address,
 info->regmap);
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin

restore\n"); break;

drivers/iio/adc/axp288_adc.c +0 -3
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to

function */

drivers/iio/adc/axp288_adc.c +0 -1
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,

AXP288_ADC_TS_PIN_ON))

drivers/iio/adc/axp288_adc.c +0 -3
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); -}

drivers/iio/adc/axp288_adc.c +0 -1
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct
 platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system

suspend.

Quoted 9 lines
Quoted 8 lines

* otherwise internal fuel gauge functionality may be
affected. */

drivers/iio/adc/axp288_adc.c +1 -1
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); if (ret) {
dev_err(&pdev->dev, "unable to enable ADC
device\n"); return ret;

[Jacob Pan]

A message that is not in the archive (sent off-list or not yet received): 054b52de-40fd-a879-7b8e-2d25fed18840-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#7 lore raw
Quoted 35 lines · On Sun, 1 Jan 2017 12:19:40 +0100 Hans de Goede <[email protected]> wrote:

Hi,

Quoted 8 lines · Jacob Pan
Quoted 5 lines · On Fri, 30 Dec 2016 16:46:03 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

It has been a while. Just looked at the datasheet, reg 84h is for ADC and TS pin control. IIRC, we had to set the TS bits in order to make ADC read to work.

The bits the code I'm removing are manipulating are bits 0 & 1 of reg 84h which are:

1-0 Current source from TS pin on/off enable bit [1:0]

00: off
01: on when charging battery, off when not charging 10: on in ADC phase and off when out of the ADC phase, for power saving 11: always on

And they are being toggled between 10 and 11, so in both cases the current source is enabled when reading the adc value. Specifically the code this patch removes are setting these bits to 10 before reading and back to 11 after reading, which makes no sense.

Quoted 7 lines

And to make things even funkier, this manipulation is only done when reading the GP_ADC, which is the ADC function of GPIO0, whereas these bits control the bias current source for the TS pin, which is a completely different pin.

So all in all this entire bit of code seems to be big NOP.

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Quoted 129 lines
Quoted 1 line

What is the other register?

The register to actually enable / disable the bias current source for GPIO0 / the GPADC pin is register 85h, where setting bit 2 enables the GPIO0 output current.

Regards,

Hans

Quoted 117 lines
Quoted 5 lines
Quoted 5 lines

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

Agreed, it would be better to do read-modify-write and not to touch the other bits.

Quoted 98 lines
Quoted 10 lines

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

I guess you probably have more up to date contact details than I do, but seems worth trying to cc Jacob Pan on this to see if we can find out what the original reasoning behind this was. Seems a very odd thing to do with no purpose!

If Jacob isn't contactable we'll fall back to guessing it was just an oddity of driver evolution.

Jonathan

Quoted 79 lines
---
 drivers/iio/adc/axp288_adc.c | 32

+------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-)

(quoted diff) +0 -0

b/drivers/iio/adc/axp288_adc.c index 7fd2494..64799ad 100644

drivers/iio/adc/axp288_adc.c +0 -20
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val,
 unsigned long address, return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int
 mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin
 */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,
 mode); -}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address,
 info->regmap);
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin

restore\n"); break;

drivers/iio/adc/axp288_adc.c +0 -3
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to

function */

drivers/iio/adc/axp288_adc.c +0 -1
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,

AXP288_ADC_TS_PIN_ON))

drivers/iio/adc/axp288_adc.c +0 -3
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); -}

drivers/iio/adc/axp288_adc.c +0 -1
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct
 platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system

suspend.

Quoted 9 lines
Quoted 8 lines

* otherwise internal fuel gauge functionality may be
affected. */

drivers/iio/adc/axp288_adc.c +1 -1
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); if (ret) {
dev_err(&pdev->dev, "unable to enable ADC
device\n"); return ret;

[Jacob Pan]

[Jacob Pan]

#8 lore raw

Hi,

Quoted 43 lines · Jacob Pan
Quoted 40 lines · On Sun, 1 Jan 2017 12:19:40 +0100 Hans de Goede <[email protected]> wrote:

Hi,

Quoted 8 lines · Jacob Pan
Quoted 5 lines · On Fri, 30 Dec 2016 16:46:03 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 4 lines · Hans de Goede

For some reason the axp288_adc driver was modifying the AXP288_ADC_TS_PIN_CTRL register, changing bits 0-1 depending on whether the GP_ADC channel or another channel was written.

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

These bits control when a bias current is send to the TS_PIN, the GP_ADC has its own pin and a separate bit in another register to control the bias current.

It has been a while. Just looked at the datasheet, reg 84h is for ADC and TS pin control. IIRC, we had to set the TS bits in order to make ADC read to work.

The bits the code I'm removing are manipulating are bits 0 & 1 of reg 84h which are:

1-0 Current source from TS pin on/off enable bit [1:0]

00: off
01: on when charging battery, off when not charging 10: on in ADC phase and off when out of the ADC phase, for power saving 11: always on

And they are being toggled between 10 and 11, so in both cases the current source is enabled when reading the adc value. Specifically the code this patch removes are setting these bits to 10 before reading and back to 11 after reading, which makes no sense.

And to make things even funkier, this manipulation is only done when reading the GP_ADC, which is the ADC function of GPIO0, whereas these bits control the bias current source for the TS pin, which is a completely different pin.

Quoted 4 lines
Quoted 2 lines

So all in all this entire bit of code seems to be big NOP.

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Yes, I've successfully tested this on 2 different models cherrytrail tablets.

Regards,

Hans

Quoted 133 lines
Quoted 130 lines
Quoted 2 lines

What is the other register?

The register to actually enable / disable the bias current source for GPIO0 / the GPADC pin is register 85h, where setting bit 2 enables the GPIO0 output current.

Regards,

Hans

Quoted 117 lines
Quoted 5 lines
Quoted 5 lines

Not only does changing when to enable the TS_PIN bias current (always or only when sampling) when reading the GP_ADC make no sense at all, the code is modifying these bits is writing the entire register, assuming that all the other bits have their default value.

Agreed, it would be better to do read-modify-write and not to touch the other bits.

Quoted 98 lines
Quoted 10 lines

So if the firmware has configured a different bias-current for either pin, then that change gets clobbered by the write, likewise if the firmware has set bit 2 to indicate that the battery has no thermal sensor, this will get clobbered by the write.

This commit fixes all this, by simply removing all writes to the AXP288_ADC_TS_PIN_CTRL register, they are not needed to read the GP_ADC pin, and can actually be harmful.

I guess you probably have more up to date contact details than I do, but seems worth trying to cc Jacob Pan on this to see if we can find out what the original reasoning behind this was. Seems a very odd thing to do with no purpose!

If Jacob isn't contactable we'll fall back to guessing it was just an oddity of driver evolution.

Jonathan

Quoted 79 lines
---
 drivers/iio/adc/axp288_adc.c | 32

+------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-)

(quoted diff) +0 -0

b/drivers/iio/adc/axp288_adc.c index 7fd2494..64799ad 100644

drivers/iio/adc/axp288_adc.c +0 -20
@@ -28,8 +28,6 @@
 #include <linux/iio/driver.h>
 
 #define AXP288_ADC_EN_MASK		0xF1
-#define AXP288_ADC_TS_PIN_GPADC		0xF2
-#define AXP288_ADC_TS_PIN_ON		0xF3
 
 enum axp288_adc_id {
 	AXP288_ADC_TS,
@@ -123,16 +121,6 @@ static int axp288_adc_read_channel(int *val,
 unsigned long address, return IIO_VAL_INT;
 }
 
-static int axp288_adc_set_ts(struct regmap *regmap, unsigned int
 mode,
-				unsigned long address)
-{
-	/* channels other than GPADC do not need to switch TS pin
 */
-	if (address != AXP288_GP_ADC_H)
-		return 0;
-
-	return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,
 mode); -}
-
 static int axp288_adc_read_raw(struct iio_dev *indio_dev,
 			struct iio_chan_spec const *chan,
 			int *val, int *val2, long mask)
@@ -143,16 +131,7 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, mutex_lock(&indio_dev->mlock);
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_GPADC,
-					chan->address)) {
-			dev_err(&indio_dev->dev, "GPADC mode\n");
-			ret = -EINVAL;
-			break;
-		}
 		ret = axp288_adc_read_channel(val, chan->address,
 info->regmap);
-		if (axp288_adc_set_ts(info->regmap,
 AXP288_ADC_TS_PIN_ON,
-						chan->address))
-			dev_err(&indio_dev->dev, "TS pin

restore\n"); break;

drivers/iio/adc/axp288_adc.c +0 -3
 	default:
 		ret = -EINVAL;
@@ -162,15 +141,6 @@ static int axp288_adc_read_raw(struct iio_dev
 *indio_dev, return ret;
 }
 
-static int axp288_adc_set_state(struct regmap *regmap)
-{
-	/* ADC should be always enabled for internal FG to

function */

drivers/iio/adc/axp288_adc.c +0 -1
-	if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,

AXP288_ADC_TS_PIN_ON))

drivers/iio/adc/axp288_adc.c +0 -3
-		return -EIO;
-
-	return regmap_write(regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); -}

drivers/iio/adc/axp288_adc.c +0 -1
-
 static const struct iio_info axp288_adc_iio_info = {
 	.read_raw = &axp288_adc_read_raw,
 	.driver_module = THIS_MODULE,
@@ -199,7 +169,7 @@ static int axp288_adc_probe(struct
 platform_device *pdev)
 	 * Set ADC to enabled state at all time, including system

suspend.

Quoted 9 lines
Quoted 8 lines

* otherwise internal fuel gauge functionality may be
affected. */

drivers/iio/adc/axp288_adc.c +1 -1
-	ret = axp288_adc_set_state(axp20x->regmap);
+	ret = regmap_write(info->regmap, AXP20X_ADC_EN1,

AXP288_ADC_EN_MASK); if (ret) {
dev_err(&pdev->dev, "unable to enable ADC
device\n"); return ret;

[Jacob Pan]

[Jacob Pan]

#9 lore raw
Quoted 5 lines · On Tue, 3 Jan 2017 23:10:57 +0100 Hans de Goede <[email protected]> wrote:
Quoted 2 lines

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Yes, I've successfully tested this on 2 different models cherrytrail tablets.

[Jacob Pan] I am ok with your change. I last tested on baytrail tablets, I don't know if you have one available to verify. That would be ideal.

Thanks,

#10 lore raw
Quoted 6 lines · Jacob Pan
Quoted 3 lines · On Tue, 3 Jan 2017 23:10:57 +0100 Hans de Goede…
Quoted 2 lines

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Quoted 7 lines
Quoted 2 lines

Yes, I've successfully tested this on 2 different models cherrytrail tablets.

[Jacob Pan] I am ok with your change. I last tested on baytrail tablets, I don't know if you have one available to verify. That would be ideal.

Stable material? As I read this it is a fairly major fix, but we aren't entirely sure there wasn't a reason on some platforms for this 'interesting' corner of code?

So basically are we sure this won't cause regressions? If so I'll take it as a fix and mark for stable.

Thanks,

Jonathan

Quoted 6 lines

Thanks,
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Hi,

Quoted 14 lines · Jonathan Cameron
Quoted 6 lines · Jacob Pan
Quoted 3 lines · On Tue, 3 Jan 2017 23:10:57 +0100 Hans de Goede <[email protected]> wrote:
Quoted 2 lines

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Quoted 7 lines
Quoted 2 lines

Yes, I've successfully tested this on 2 different models cherrytrail tablets.

[Jacob Pan] I am ok with your change. I last tested on baytrail tablets, I don't know if you have one available to verify. That would be ideal.

Quoted 6 lines

Stable material? As I read this it is a fairly major fix, but we aren't entirely sure there wasn't a reason on some platforms for this 'interesting' corner of code?

So basically are we sure this won't cause regressions? If so I'll take it as a fix and mark for stable.

The main consumer of the axp288_adc code is the axp288_fuel_gauge driver, which until now was not really functional. It depended on platform data being attached to its mfd device, and the provider of that platform data never got merged.

I've got patches queued up for 4.11 fixing this. So in practice the chance of this patch causing regressions is close to 0 as so far it had no consumers, likewise adding a Cc: stable is not really useful.

Regards,

Hans

maintainer
#12 lore raw
Quoted 24 lines · Hans de Goede

Hi,

Quoted 14 lines · Jonathan Cameron
Quoted 6 lines · Jacob Pan
Quoted 3 lines · On Tue, 3 Jan 2017 23:10:57 +0100 Hans de Goede <[email protected]> wrote:
Quoted 2 lines

It could have been a quirk we had to do on our platforms, I just cannot recall the details. Are you testing this on x86 platforms?

Quoted 7 lines
Quoted 2 lines

Yes, I've successfully tested this on 2 different models cherrytrail tablets.

[Jacob Pan] I am ok with your change. I last tested on baytrail tablets, I don't know if you have one available to verify. That would be ideal.

Quoted 6 lines

Stable material? As I read this it is a fairly major fix, but we aren't entirely sure there wasn't a reason on some platforms for this 'interesting' corner of code?

So basically are we sure this won't cause regressions? If so I'll take it as a fix and mark for stable.

Quoted 8 lines

The main consumer of the axp288_adc code is the axp288_fuel_gauge driver, which until now was not really functional. It depended on platform data being attached to its mfd device, and the provider of that platform data never got merged.

I've got patches queued up for 4.11 fixing this. So in practice the chance of this patch causing regressions is close to 0 as so far it had no consumers, likewise adding a Cc: stable is not really useful.

Cool. I'll queue it for 4.11 as well then.

Applied to the togreg branch of iio.git which will be pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 8 lines

Regards,

Hans

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html