Few non-critical cpcap ADC fixes
cover Few non-critical cpcap ADC fixes
Hi all,
Here are few fixes for cpcap ADC mostly to get temperature readings produce sane values. AFAIK no need for urgency with these and they can all wait for v4.13 merge window.
Regards,
Tony
Tony Lindgren (3):
iio: adc: cpcap: Fix default register values and battery temperature
iio: adc: cpcap: Fix die temperature
iio: adc: cpcap: Remove hung interrupt quirk
drivers/iio/adc/cpcap-adc.c | 101 ++++++++++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 28 deletions(-)
Signature · 1 line
2.13.0
PATCH 1/3 iio: adc: cpcap: Fix default register values and battery temperature
Looking at the register dumps from Android kernel on droid 4, I noticed the values with the mainline kernel don't match. Let's fix this by initializing the ADC registers to what Android does.
For getting correct values from the battery thermistor, we need to toggle the CPCAP_BIT_THERMBIAS_EN when measuring battery temperature to get correct battery temperatures. And looks like we also need to wait a little bit before reading the battery temperature as otherwise the results are inaccurate.
--- drivers/iio/adc/cpcap-adc.c | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-)
drivers/iio/adc/cpcap-adc.c +46 -4
@@ -52,6 +52,10 @@#define CPCAP_BIT_RAND0 BIT(1)/* Set with CAL_MODE */ #define CPCAP_BIT_ADEN BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC1_DEFAULTS (CPCAP_BIT_ADEN_AUTO_CLR | \ + CPCAP_BIT_ADC_CLK_SEL0 | \ + CPCAP_BIT_RAND1) +/* Register CPCAP_REG_ADCC2 bits */ #define CPCAP_BIT_CAL_FACTOR_ENABLE BIT(15)/* Currently unused */ #define CPCAP_BIT_BATDETB_EN BIT(14)/* Currently unused */
@@ -62,7 +66,7 @@#define CPCAP_BIT_ADC_PS_FACTOR0 BIT(9)#define CPCAP_BIT_AD4_SELECT BIT(8)/* Currently unused */ #define CPCAP_BIT_ADC_BUSY BIT(7)/* Currently unused */ -#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Currently unused */ +#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Bias for AD0_BATTDETB */ #define CPCAP_BIT_ADTRIG_DIS BIT(5)/* Disable interrupt */ #define CPCAP_BIT_LIADC BIT(4)/* Currently unused */ #define CPCAP_BIT_TS_REFEN BIT(3)/* Currently unused */
@@ -70,6 +74,13 @@#define CPCAP_BIT_TS_M1 BIT(1)/* Currently unused */ #define CPCAP_BIT_TS_M0 BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC2_DEFAULTS (CPCAP_BIT_AD4_SELECT | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_LIADC | \ + CPCAP_BIT_TS_M2 | \ + CPCAP_BIT_TS_M1) +#define CPCAP_MAX_TEMP_LVL 27#define CPCAP_FOUR_POINT_TWO_ADC 801#define ST_ADC_CAL_CHRGI_HIGH_THRESHOLD 530
@@ -124,10 +135,10 @@ struct cpcap_adc {*/ enum cpcap_adc_channel {/* Bank0 channels */ -CPCAP_ADC_AD0_BATTDETB ,/* Battery detection */ +CPCAP_ADC_AD0_BATTDETB ,/* Battery temperature */ CPCAP_ADC_BATTP ,/* Battery voltage */ CPCAP_ADC_VBUS ,/* USB VBUS voltage */ -CPCAP_ADC_AD3 ,/* Battery temperature when charging */ +CPCAP_ADC_AD3 ,/* Die temperature when charging */ CPCAP_ADC_BPLUS_AD4 ,/* Another battery or system voltage */ CPCAP_ADC_CHG_ISENSE ,/* Calibrated charge current */ CPCAP_ADC_BATTI ,/* Calibrated system current */
@@ -541,6 +552,15 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata,return ;switch (req->channel) { +case CPCAP_ADC_AD0_BATTDETB : + value2 |=CPCAP_BIT_THERMBIAS_EN ; + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +CPCAP_BIT_THERMBIAS_EN , + value2); +if (error) +return ; +usleep_range (800 ,1000 ); +break ; case CPCAP_ADC_AD8 ... CPCAP_ADC_TSY2_AD15: value1 |=CPCAP_BIT_AD_SEL1 ;break ;
@@ -583,7 +603,8 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 ,CPCAP_BIT_ATOX_PS_FACTOR |CPCAP_BIT_ADC_PS_FACTOR1 | -CPCAP_BIT_ADC_PS_FACTOR0 , +CPCAP_BIT_ADC_PS_FACTOR0 | +CPCAP_BIT_THERMBIAS_EN , value2);if (error)return ;
@@ -664,6 +685,21 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return error; } +static int cpcap_adc_stop_bank (struct cpcap_adc *ddata) +{ +int error; + + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC1 , +0xffff , +CPCAP_REG_ADCC1_DEFAULTS ); +if (error) +return error; + +return regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +0xffff , +CPCAP_REG_ADCC2_DEFAULTS ); +} +static void cpcap_adc_phase (struct cpcap_adc_request *req) {const struct cpcap_adc_conversion_tbl *conv_tbl = req->conv_tbl;
@@ -860,6 +896,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =regmap_read (ddata->reg, chan->address, val);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock);break ;case IIO_CHAN_INFO_PROCESSED :
@@ -870,6 +909,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =cpcap_adc_read_bank_scaled (ddata, &req);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock); *val = req.result;break ;
Signature · 1 line
2.13.0
PATCH 2/3 iio: adc: cpcap: Fix die temperature
In reply to Tony LindgrenIt seems that "MC13783 Power Management and Audio Ciruit User's Guide" MC1378UG.pdf documents several similar components as in the CPCAP PMIC.
Chapter "9.5.5 Die Temperature and UID" says that the die temperature value is 282 at 25C with LSB of -1.14C. Converting CPCAP PMIC channel3 values with following seems to produce values that make sense for a PMIC die:
temperature = 25000 + ((regval - 282) * 114)
As we don't have any other documentation, let's assume the die temperature is unconfigured in the Motorola mapphone Linux kernel and the current temperature conversion table should be only used for the battery thermistor and not for the die temperature.
--- drivers/iio/adc/cpcap-adc.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
drivers/iio/adc/cpcap-adc.c +28 -3
@@ -875,6 +875,22 @@ static int cpcap_adc_init_request(struct cpcap_adc_request *req,return 0 ; } +static int cpcap_adc_read_st_die_temp (struct cpcap_adc *ddata, +int addr,int *val) +{ +int error; + + error =regmap_read (ddata->reg, addr, val); +if (error) +return error; + + *val -=282 ; + *val *=114 ; + *val +=25000 ; + +return 0 ; +} +static int cpcap_adc_read (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)
@@ -906,9 +922,18 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =cpcap_adc_start_bank (ddata, &req);if (error) goto err_unlock; - error =cpcap_adc_read_bank_scaled (ddata, &req); -if (error) - goto err_unlock; +if ((ddata->vendor ==CPCAP_VENDOR_ST ) && + (chan->channel ==CPCAP_ADC_AD3 )) { + error =cpcap_adc_read_st_die_temp (ddata, + chan->address, + &req.result); +if (error) + goto err_unlock; + }else { + error =cpcap_adc_read_bank_scaled (ddata, &req); +if (error) + goto err_unlock; + } error =cpcap_adc_stop_bank (ddata);if (error) goto err_unlock;
Signature · 1 line
2.13.0
PATCH 3/3 iio: adc: cpcap: Remove hung interrupt quirk
In reply to Tony LindgrenThis is no longer needed as the real problem was interrupt flags not getting passed properly from device tree to the cpcap-core.c mfd driver. This got fixed with commit ac89473213c6 ("mfd: cpcap:
Fix interrupt to use level interrupt") So let's remove ADC interrupt specific the quirk.
--- drivers/iio/adc/cpcap-adc.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)
drivers/iio/adc/cpcap-adc.c +1 -23
@@ -89,7 +89,7 @@#define ST_ADC_CAL_BATTI_LOW_THRESHOLD 494#define ST_ADC_CALIBRATE_DIFF_THRESHOLD 3 -#define CPCAP_ADC_MAX_RETRIES 5/* Calibration and quirk */ +#define CPCAP_ADC_MAX_RETRIES 5/* Calibration */ /** * struct cpcap_adc_ato - timing settings for cpcap adc
@@ -635,27 +635,6 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, } } -/* -* Occasionally the ADC does not seem to start and there will be no -* interrupt. Let's re-init interrupt to prevent the ADC from hanging -* for the next request. It is unclear why this happens, but the next -* request will usually work after doing this. -*/ -static void cpcap_adc_quirk_reset_lost_irq (struct cpcap_adc *ddata) -{ -int error; - -dev_info (ddata->dev,"lost ADC irq, attempting to reinit\n" ); -disable_irq (ddata->irq); - error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , -CPCAP_BIT_ADTRIG_DIS , -CPCAP_BIT_ADTRIG_DIS ); -if (error) -dev_warn (ddata->dev,"%s reset failed: %i\n" , - __func__, error); -enable_irq (ddata->irq); -} -static int cpcap_adc_start_bank (struct cpcap_adc *ddata,struct cpcap_adc_request *req) {
@@ -673,7 +652,6 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return 0 ;if (error ==0 ) { -cpcap_adc_quirk_reset_lost_irq (ddata); error = -ETIMEDOUT ;continue ; }
Signature · 1 line
2.13.0
Re: [PATCH 1/3] iio: adc: cpcap: Fix default register values and battery temperature
In reply to Tony LindgrenQuoted 56 lines · Tony Lindgren
Looking at the register dumps from Android kernel on droid 4, I noticed the values with the mainline kernel don't match. Let's fix this by initializing the ADC registers to what Android does.
For getting correct values from the battery thermistor, we need to toggle the
CPCAP_BIT_THERMBIAS_ENwhen measuring battery temperature to get correct battery temperatures. And looks like we also need to wait a little bit before reading the battery temperature as otherwise the results are inaccurate.Cc Marcel Partap <[email protected]>Cc Michael Scott <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/iio/adc/cpcap-adc.c | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-)drivers/iio/adc/cpcap-adc.c +12
-1@@ -52,6 +52,10 @@#define CPCAP_BIT_RAND0 BIT(1)/* Set with CAL_MODE */ #define CPCAP_BIT_ADEN BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC1_DEFAULTS (CPCAP_BIT_ADEN_AUTO_CLR | \ + CPCAP_BIT_ADC_CLK_SEL0 | \ + CPCAP_BIT_RAND1) +/* Register CPCAP_REG_ADCC2 bits */ #define CPCAP_BIT_CAL_FACTOR_ENABLE BIT(15)/* Currently unused */ #define CPCAP_BIT_BATDETB_EN BIT(14)/* Currently unused */ @@ -62,7 +66,7 @@#define CPCAP_BIT_ADC_PS_FACTOR0 BIT(9)#define CPCAP_BIT_AD4_SELECT BIT(8)/* Currently unused */ #define CPCAP_BIT_ADC_BUSY BIT(7)/* Currently unused */ -#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Currently unused */ +#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Bias for AD0_BATTDETB */ #define CPCAP_BIT_ADTRIG_DIS BIT(5)/* Disable interrupt */ #define CPCAP_BIT_LIADC BIT(4)/* Currently unused */ #define CPCAP_BIT_TS_REFEN BIT(3)/* Currently unused */ @@ -70,6 +74,13 @@#define CPCAP_BIT_TS_M1 BIT(1)/* Currently unused */ #define CPCAP_BIT_TS_M0 BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC2_DEFAULTS (CPCAP_BIT_AD4_SELECT | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_LIADC | \ + CPCAP_BIT_TS_M2 | \ + CPCAP_BIT_TS_M1) +#define CPCAP_MAX_TEMP_LVL 27#define CPCAP_FOUR_POINT_TWO_ADC 801#define ST_ADC_CAL_CHRGI_HIGH_THRESHOLD 530
drivers/iio/adc/cpcap-adc.c struct cpcap_adc { · line 138
Quoted 5 lines
drivers/iio/adc/cpcap-adc.c +1
-1@@ -124,10 +135,10 @@ struct cpcap_adc {*/ enum cpcap_adc_channel {/* Bank0 channels */ -CPCAP_ADC_AD0_BATTDETB ,/* Battery detection */ +CPCAP_ADC_AD0_BATTDETB ,/* Battery temperature */
Since this doesn't mean battery detection anymore I'd recommend renaming to CPCAP_ADC_AD0_BATTEMP or similar.
Quoted 81 lines
drivers/iio/adc/cpcap-adc.c +33
-3CPCAP_ADC_BATTP ,/* Battery voltage */ CPCAP_ADC_VBUS ,/* USB VBUS voltage */ -CPCAP_ADC_AD3 ,/* Battery temperature when charging */ +CPCAP_ADC_AD3 ,/* Die temperature when charging */ CPCAP_ADC_BPLUS_AD4 ,/* Another battery or system voltage */ CPCAP_ADC_CHG_ISENSE ,/* Calibrated charge current */ CPCAP_ADC_BATTI, /* Calibrated system current */@@ -541,6 +552,15 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata,return ;switch (req->channel) { +case CPCAP_ADC_AD0_BATTDETB : + value2 |=CPCAP_BIT_THERMBIAS_EN ; + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +CPCAP_BIT_THERMBIAS_EN , + value2); +if (error) +return ; +usleep_range (800 ,1000 ); +break ; case CPCAP_ADC_AD8 ... CPCAP_ADC_TSY2_AD15: value1 |=CPCAP_BIT_AD_SEL1 ;break ;@@ -583,7 +603,8 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 ,CPCAP_BIT_ATOX_PS_FACTOR |CPCAP_BIT_ADC_PS_FACTOR1 | -CPCAP_BIT_ADC_PS_FACTOR0 , +CPCAP_BIT_ADC_PS_FACTOR0 | +CPCAP_BIT_THERMBIAS_EN , value2);if (error)return ;@@ -664,6 +685,21 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return error; } +static int cpcap_adc_stop_bank (struct cpcap_adc *ddata) +{ +int error; + + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC1 , +0xffff , +CPCAP_REG_ADCC1_DEFAULTS ); +if (error) +return error; + +return regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +0xffff , +CPCAP_REG_ADCC2_DEFAULTS ); +} +static void cpcap_adc_phase (struct cpcap_adc_request *req) {const struct cpcap_adc_conversion_tbl *conv_tbl = req->conv_tbl;@@ -860,6 +896,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =regmap_read (ddata->reg, chan->address, val);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock);break ;case IIO_CHAN_INFO_PROCESSED :@@ -870,6 +909,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =cpcap_adc_read_bank_scaled (ddata, &req);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock); *val = req.result;break ; --2.13.0
--
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
Re: [PATCH 3/3] iio: adc: cpcap: Remove hung interrupt quirk
In reply to Tony LindgrenHi,
Quoted 10 lines · Tony Lindgren
This is no longer needed as the real problem was interrupt flags not getting passed properly from device tree to the
cpcap-core.cmfd driver. This got fixed with commitac89473213c6("mfd: cpcap:
Fix interrupt to use level interrupt") So let's remove ADC interrupt specific the quirk.Cc Marcel Partap <[email protected]>Cc Michael Scott <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>
-- Sebastian
Quoted 54 lines
--- drivers/iio/adc/cpcap-adc.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)drivers/iio/adc/cpcap-adc.c +1
-23@@ -89,7 +89,7 @@#define ST_ADC_CAL_BATTI_LOW_THRESHOLD 494#define ST_ADC_CALIBRATE_DIFF_THRESHOLD 3 -#define CPCAP_ADC_MAX_RETRIES 5/* Calibration and quirk */ +#define CPCAP_ADC_MAX_RETRIES 5/* Calibration */ /** * struct cpcap_adc_ato - timing settings for cpcap adc @@ -635,27 +635,6 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, } } -/* -* Occasionally the ADC does not seem to start and there will be no -* interrupt. Let's re-init interrupt to prevent the ADC from hanging -* for the next request. It is unclear why this happens, but the next -* request will usually work after doing this. -*/ -static void cpcap_adc_quirk_reset_lost_irq (struct cpcap_adc *ddata) -{ -int error; - -dev_info (ddata->dev,"lost ADC irq, attempting to reinit\n" ); -disable_irq (ddata->irq); - error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , -CPCAP_BIT_ADTRIG_DIS , -CPCAP_BIT_ADTRIG_DIS ); -if (error) -dev_warn (ddata->dev,"%s reset failed: %i\n" , - __func__, error); -enable_irq (ddata->irq); -} -static int cpcap_adc_start_bank (struct cpcap_adc *ddata,struct cpcap_adc_request *req) {@@ -673,7 +652,6 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return 0 ;if (error ==0 ) { -cpcap_adc_quirk_reset_lost_irq (ddata); error = -ETIMEDOUT ;continue ; }Signature · 1 line
2.13.0
Jonathan Cameron
maintainerRe: [PATCH 1/3] iio: adc: cpcap: Fix default register values and battery temperature
In reply to Matt RanostayQuoted 11 lines · Matt Ranostay
Quoted 10 lines · Tony Lindgren
Looking at the register dumps from Android kernel on droid 4, I noticed the values with the mainline kernel don't match. Let's fix this by initializing the ADC registers to what Android does.
For getting correct values from the battery thermistor, we need to toggle the
CPCAP_BIT_THERMBIAS_ENwhen measuring battery temperature to get correct battery temperatures. And looks like we also need to wait a little bit before reading the battery temperature as otherwise the results are inaccurate.
Quoted 4 lines
Quoted 4 lines
Cc Marcel Partap <[email protected]>Cc Michael Scott <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>
Other than Matt's valid point inline, looks sensible to me...
Jonathan
Quoted 137 lines
Quoted 42 lines
--- drivers/iio/adc/cpcap-adc.c | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-)drivers/iio/adc/cpcap-adc.c +12
-1@@ -52,6 +52,10 @@#define CPCAP_BIT_RAND0 BIT(1)/* Set with CAL_MODE */ #define CPCAP_BIT_ADEN BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC1_DEFAULTS (CPCAP_BIT_ADEN_AUTO_CLR | \ + CPCAP_BIT_ADC_CLK_SEL0 | \ + CPCAP_BIT_RAND1) +/* Register CPCAP_REG_ADCC2 bits */ #define CPCAP_BIT_CAL_FACTOR_ENABLE BIT(15)/* Currently unused */ #define CPCAP_BIT_BATDETB_EN BIT(14)/* Currently unused */ @@ -62,7 +66,7 @@#define CPCAP_BIT_ADC_PS_FACTOR0 BIT(9)#define CPCAP_BIT_AD4_SELECT BIT(8)/* Currently unused */ #define CPCAP_BIT_ADC_BUSY BIT(7)/* Currently unused */ -#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Currently unused */ +#define CPCAP_BIT_THERMBIAS_EN BIT(6)/* Bias for AD0_BATTDETB */ #define CPCAP_BIT_ADTRIG_DIS BIT(5)/* Disable interrupt */ #define CPCAP_BIT_LIADC BIT(4)/* Currently unused */ #define CPCAP_BIT_TS_REFEN BIT(3)/* Currently unused */ @@ -70,6 +74,13 @@#define CPCAP_BIT_TS_M1 BIT(1)/* Currently unused */ #define CPCAP_BIT_TS_M0 BIT(0)/* Currently unused */ +#define CPCAP_REG_ADCC2_DEFAULTS (CPCAP_BIT_AD4_SELECT | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_ADTRIG_DIS | \ + CPCAP_BIT_LIADC | \ + CPCAP_BIT_TS_M2 | \ + CPCAP_BIT_TS_M1) +#define CPCAP_MAX_TEMP_LVL 27#define CPCAP_FOUR_POINT_TWO_ADC 801#define ST_ADC_CAL_CHRGI_HIGH_THRESHOLD 530drivers/iio/adc/cpcap-adc.c struct cpcap_adc { · line 138
Quoted 5 lines
drivers/iio/adc/cpcap-adc.c +1
-1@@ -124,10 +135,10 @@ struct cpcap_adc {*/ enum cpcap_adc_channel {/* Bank0 channels */ -CPCAP_ADC_AD0_BATTDETB ,/* Battery detection */ +CPCAP_ADC_AD0_BATTDETB ,/* Battery temperature */ Since this doesn't mean battery detection anymore I'd recommend renaming to
CPCAP_ADC_AD0_BATTEMPor similar.Quoted 76 lines
drivers/iio/adc/cpcap-adc.c +33
-3CPCAP_ADC_BATTP ,/* Battery voltage */ CPCAP_ADC_VBUS ,/* USB VBUS voltage */ -CPCAP_ADC_AD3 ,/* Battery temperature when charging */ +CPCAP_ADC_AD3 ,/* Die temperature when charging */ CPCAP_ADC_BPLUS_AD4 ,/* Another battery or system voltage */ CPCAP_ADC_CHG_ISENSE ,/* Calibrated charge current */ CPCAP_ADC_BATTI, /* Calibrated system current */@@ -541,6 +552,15 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata,return ;switch (req->channel) { +case CPCAP_ADC_AD0_BATTDETB : + value2 |=CPCAP_BIT_THERMBIAS_EN ; + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +CPCAP_BIT_THERMBIAS_EN , + value2); +if (error) +return ; +usleep_range (800 ,1000 ); +break ; case CPCAP_ADC_AD8 ... CPCAP_ADC_TSY2_AD15: value1 |=CPCAP_BIT_AD_SEL1 ;break ;@@ -583,7 +603,8 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 ,CPCAP_BIT_ATOX_PS_FACTOR |CPCAP_BIT_ADC_PS_FACTOR1 | -CPCAP_BIT_ADC_PS_FACTOR0 , +CPCAP_BIT_ADC_PS_FACTOR0 | +CPCAP_BIT_THERMBIAS_EN , value2);if (error)return ;@@ -664,6 +685,21 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return error; } +static int cpcap_adc_stop_bank (struct cpcap_adc *ddata) +{ +int error; + + error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC1 , +0xffff , +CPCAP_REG_ADCC1_DEFAULTS ); +if (error) +return error; + +return regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , +0xffff , +CPCAP_REG_ADCC2_DEFAULTS ); +} +static void cpcap_adc_phase (struct cpcap_adc_request *req) {const struct cpcap_adc_conversion_tbl *conv_tbl = req->conv_tbl;@@ -860,6 +896,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =regmap_read (ddata->reg, chan->address, val);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock);break ;case IIO_CHAN_INFO_PROCESSED :@@ -870,6 +909,9 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =cpcap_adc_read_bank_scaled (ddata, &req);if (error) goto err_unlock; + error =cpcap_adc_stop_bank (ddata); +if (error) + goto err_unlock;mutex_unlock (&ddata->lock); *val = req.result;break ; --Quoted 5 lines
2.13.0
--
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--
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
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: adc: cpcap: Fix die temperature
In reply to Tony LindgrenQuoted 8 lines · Tony Lindgren
It seems that "MC13783 Power Management and Audio Ciruit User's Guide" MC1378UG.pdf documents several similar components as in the CPCAP PMIC.
Chapter "9.5.5 Die Temperature and UID" says that the die temperature value is 282 at 25C with LSB of -1.14C. Converting CPCAP PMIC channel3 values with following seems to produce values that make sense for a PMIC die:
Quoted 6 lines
temperature = 25000 + ((regval - 282) * 114)
As we don't have any other documentation, let's assume the die temperature is unconfigured in the Motorola mapphone Linux kernel and the current temperature conversion table should be only used for the battery thermistor and not for the die temperature.
Is there any route we have available to confirm this? I.e. doe anyone have one where we can check plausibility?
If not such is life, but thought I'd ask.
Code is fine as far as I can see.
Jonathan
Quoted 58 lines
Cc Marcel Partap <[email protected]>Cc Michael Scott <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/iio/adc/cpcap-adc.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)drivers/iio/adc/cpcap-adc.c +28
-3@@ -875,6 +875,22 @@ static int cpcap_adc_init_request(struct cpcap_adc_request *req,return 0 ; } +static int cpcap_adc_read_st_die_temp (struct cpcap_adc *ddata, +int addr,int *val) +{ +int error; + + error =regmap_read (ddata->reg, addr, val); +if (error) +return error; + + *val -=282 ; + *val *=114 ; + *val +=25000 ; + +return 0 ; +} +static int cpcap_adc_read (struct iio_dev *indio_dev,struct iio_chan_spec const *chan,int *val,int *val2,long mask)@@ -906,9 +922,18 @@ static int cpcap_adc_read(struct iio_dev *indio_dev, error =cpcap_adc_start_bank (ddata, &req);if (error) goto err_unlock; - error =cpcap_adc_read_bank_scaled (ddata, &req); -if (error) - goto err_unlock; +if ((ddata->vendor ==CPCAP_VENDOR_ST ) && + (chan->channel ==CPCAP_ADC_AD3 )) { + error =cpcap_adc_read_st_die_temp (ddata, + chan->address, + &req.result); +if (error) + goto err_unlock; + }else { + error =cpcap_adc_read_bank_scaled (ddata, &req); +if (error) + goto err_unlock; + } error =cpcap_adc_stop_bank (ddata);if (error) goto err_unlock;
Jonathan Cameron
maintainerRe: [PATCH 3/3] iio: adc: cpcap: Remove hung interrupt quirk
In reply to Sebastian ReichelQuoted 9 lines · Sebastian Reichel
Hi,
Quoted 6 lines · Tony Lindgren
This is no longer needed as the real problem was interrupt flags not getting passed properly from device tree to the
cpcap-core.cmfd driver. This got fixed with commitac89473213c6("mfd: cpcap:
Fix interrupt to use level interrupt") So let's remove ADC interrupt specific the quirk.
Quoted 6 lines
Quoted 4 lines
Cc Marcel Partap <[email protected]>Cc Michael Scott <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>
Good. Always nice to see an odd issue like this cleaned up.
Will pick up V2 along with the previous two patches.
Thanks,
Jonathan
Quoted 57 lines
-- Sebastian
Quoted 54 lines
--- drivers/iio/adc/cpcap-adc.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-)drivers/iio/adc/cpcap-adc.c +1
-23@@ -89,7 +89,7 @@#define ST_ADC_CAL_BATTI_LOW_THRESHOLD 494#define ST_ADC_CALIBRATE_DIFF_THRESHOLD 3 -#define CPCAP_ADC_MAX_RETRIES 5/* Calibration and quirk */ +#define CPCAP_ADC_MAX_RETRIES 5/* Calibration */ /** * struct cpcap_adc_ato - timing settings for cpcap adc @@ -635,27 +635,6 @@ static void cpcap_adc_setup_bank(struct cpcap_adc *ddata, } } -/* -* Occasionally the ADC does not seem to start and there will be no -* interrupt. Let's re-init interrupt to prevent the ADC from hanging -* for the next request. It is unclear why this happens, but the next -* request will usually work after doing this. -*/ -static void cpcap_adc_quirk_reset_lost_irq (struct cpcap_adc *ddata) -{ -int error; - -dev_info (ddata->dev,"lost ADC irq, attempting to reinit\n" ); -disable_irq (ddata->irq); - error =regmap_update_bits (ddata->reg,CPCAP_REG_ADCC2 , -CPCAP_BIT_ADTRIG_DIS , -CPCAP_BIT_ADTRIG_DIS ); -if (error) -dev_warn (ddata->dev,"%s reset failed: %i\n" , - __func__, error); -enable_irq (ddata->irq); -} -static int cpcap_adc_start_bank (struct cpcap_adc *ddata,struct cpcap_adc_request *req) {@@ -673,7 +652,6 @@ static int cpcap_adc_start_bank(struct cpcap_adc *ddata,return 0 ;if (error ==0 ) { -cpcap_adc_quirk_reset_lost_irq (ddata); error = -ETIMEDOUT ;continue ; }Signature · 1 line
2.13.0
Re: [PATCH 1/3] iio: adc: cpcap: Fix default register values and battery temperature
In reply to Matt RanostayQuoted 8 lines · Matt Ranostay
drivers/iio/adc/cpcap-adc.c struct cpcap_adc { · line 138
Quoted 4 lines · Tony Lindgren
enum cpcap_adc_channel { /* Bank0 channels */drivers/iio/adc/cpcap-adc.c +1
-1- CPCAP_ADC_AD0_BATTDETB, /* Battery detection */ + CPCAP_ADC_AD0_BATTDETB, /* Battery temperature */Since this doesn't mean battery detection anymore I'd recommend renaming to
CPCAP_ADC_AD0_BATTEMPor similar.
OK I'll change it to just CPCAP_ADC_AD0 as it seems it's use has changed across revisions or products.
Regards,
Tony
Re: [PATCH 2/3] iio: adc: cpcap: Fix die temperature
In reply to Jonathan CameronQuoted 9 lines · Jonathan Cameron
Quoted 8 lines · Tony Lindgren
It seems that "MC13783 Power Management and Audio Ciruit User's Guide" MC1378UG.pdf documents several similar components as in the CPCAP PMIC.
Chapter "9.5.5 Die Temperature and UID" says that the die temperature value is 282 at 25C with LSB of -1.14C. Converting CPCAP PMIC channel3 values with following seems to produce values that make sense for a PMIC die:
Quoted 8 lines
Quoted 6 lines
temperature = 25000 + ((regval - 282) * 114)
As we don't have any other documentation, let's assume the die temperature is unconfigured in the Motorola mapphone Linux kernel and the current temperature conversion table should be only used for the battery thermistor and not for the die temperature.
Is there any route we have available to confirm this? I.e. doe anyone have one where we can check plausibility?
Well there is also a tmp105 sensor for SoC temperature on board that I used for some sanity checks :) For the Motorola kernel, it seems it's doing all the interesting ADC stuff in user space for battery estimates. So if ch3 is used, it must be using the raw values. My guess is that ch3 is only used by the PMIC firmware to automatically cut off power if it gets too hot.
The temperature values seem to make sense now when compared against the tmp105 values.. The following output is from an idle device with charger connected with reasonably full battery:
$ ./test-d4-temperature tmp105: 37187 bat ch0: 33675 die ch3: 46888 tmp105: 37187 bat ch0: 33820 die ch3: 41074 tmp105: 37187 bat ch0: 33525 die ch3: 40390 tmp105: 37125 bat ch0: 33675 die ch3: 40162 tmp105: 37125 bat ch0: 34410 die ch3: 40048 tmp105: 37125 bat ch0: 34555 die ch3: 40162 tmp105: 37125 bat ch0: 33525 die ch3: 40390 ...
Add some load with two instances of dd if=/dev/urandom of=/dev/null:
$ ./test-d4-temperature tmp105: 44250 bat ch0: 37240 die ch3: 51790 tmp105: 44250 bat ch0: 34705 die ch3: 48940 tmp105: 44250 bat ch0: 34705 die ch3: 48484 tmp105: 44250 bat ch0: 34850 die ch3: 48370 tmp105: 44312 bat ch0: 37585 die ch3: 48142 tmp105: 44312 bat ch0: 36895 die ch3: 48484 tmp105: 44375 bat ch0: 34705 die ch3: 48484 tmp105: 44375 bat ch0: 36895 die ch3: 48484 ...
So ch3 for the PMIC die temperature seems to follow the load numbers and makes sense as it provides power to all the devices. The first value of ch3 often is all over the map though, probably no way around that..
The script I'm using is:
#!/bin/sh
while [ 1 ]; do
echo -n "tmp105: $(cat /sys/class/hwmon/hwmon0/temp1_input) " echo -n "bat ch0: $(cat /sys/bus/iio/devices/iio:device0/in_temp0_input) " echo "die ch3: $(cat /sys/bus/iio/devices/iio:device0/in_temp3_input)" sleep 1
done
Regards,
Tony
Jonathan Cameron
maintainerRe: [PATCH 2/3] iio: adc: cpcap: Fix die temperature
Quoted 67 lines · Tony Lindgren
Quoted 9 lines · Jonathan Cameron
Quoted 8 lines · Tony Lindgren
It seems that "MC13783 Power Management and Audio Ciruit User's Guide" MC1378UG.pdf documents several similar components as in the CPCAP PMIC.
Chapter "9.5.5 Die Temperature and UID" says that the die temperature value is 282 at 25C with LSB of -1.14C. Converting CPCAP PMIC channel3 values with following seems to produce values that make sense for a PMIC die:
Quoted 8 lines
Quoted 6 lines
temperature = 25000 + ((regval - 282) * 114)
As we don't have any other documentation, let's assume the die temperature is unconfigured in the Motorola mapphone Linux kernel and the current temperature conversion table should be only used for the battery thermistor and not for the die temperature.
Is there any route we have available to confirm this? I.e. doe anyone have one where we can check plausibility?
Well there is also a tmp105 sensor for SoC temperature on board that I used for some sanity checks :) For the Motorola kernel, it seems it's doing all the interesting ADC stuff in user space for battery estimates. So if ch3 is used, it must be using the raw values. My guess is that ch3 is only used by the PMIC firmware to automatically cut off power if it gets too hot.
The temperature values seem to make sense now when compared against the tmp105 values.. The following output is from an idle device with charger connected with reasonably full battery:
$ ./test-d4-temperature tmp105: 37187 bat ch0: 33675 die ch3: 46888 tmp105: 37187 bat ch0: 33820 die ch3: 41074 tmp105: 37187 bat ch0: 33525 die ch3: 40390 tmp105: 37125 bat ch0: 33675 die ch3: 40162 tmp105: 37125 bat ch0: 34410 die ch3: 40048 tmp105: 37125 bat ch0: 34555 die ch3: 40162 tmp105: 37125 bat ch0: 33525 die ch3: 40390 ...Add some load with two instances of dd if=/dev/urandom of=/dev/null:
$ ./test-d4-temperature tmp105: 44250 bat ch0: 37240 die ch3: 51790 tmp105: 44250 bat ch0: 34705 die ch3: 48940 tmp105: 44250 bat ch0: 34705 die ch3: 48484 tmp105: 44250 bat ch0: 34850 die ch3: 48370 tmp105: 44312 bat ch0: 37585 die ch3: 48142 tmp105: 44312 bat ch0: 36895 die ch3: 48484 tmp105: 44375 bat ch0: 34705 die ch3: 48484 tmp105: 44375 bat ch0: 36895 die ch3: 48484 ...So ch3 for the PMIC die temperature seems to follow the load numbers and makes sense as it provides power to all the devices. The first value of ch3 often is all over the map though, probably no way around that..
The script I'm using is:
#!/bin/sh
while [ 1 ]; do
echo -n "tmp105: $(cat /sys/class/hwmon/hwmon0/temp1_input) " echo -n "bat ch0: $(cat /sys/bus/iio/devices/iio:device0/in_temp0_input) " echo "die ch3: $(cat /sys/bus/iio/devices/iio:device0/in_temp3_input)" sleep 1
Quoted 6 lines
done
Regards,
Tony
thanks for the info.
I'm happy with the it looks plausible on real hardware answer.
Jonathan