diff mbox series

[12/14] power: supply: bq25890: show VSYS as output voltage

Message ID fdd9ec41a66113264c3b233658a72e00159f65d5.1585838679.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Not Applicable, archived
Headers show
Series power: supply: bq25890: fix and extend | expand

Commit Message

Michał Mirosław April 2, 2020, 2:58 p.m. UTC
VSYS is the voltage that is provided to the rest of the system. Show
measurement OUTPUT_VOLTAGE and supplement it with VSYSMIN setting.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/power/supply/bq25890_charger.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

kernel test robot April 3, 2020, 9:41 p.m. UTC | #1
Hi "Michał,

I love your patch! Yet something to improve:

[auto build test ERROR on power-supply/for-next]
[also build test ERROR on linus/master v5.6 next-20200403]
[cannot apply to linux/master]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Micha-Miros-aw/power-supply-bq25890-fix-and-extend/20200404-010738
base:   https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next
config: parisc-allyesconfig (attached as .config)
compiler: hppa-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        GCC_VERSION=9.3.0 make.cross ARCH=parisc 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/power/supply/bq25890_charger.c: In function 'bq25890_is_adc_property':
   drivers/power/supply/bq25890_charger.c:383:7: error: 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW' undeclared (first use in this function); did you mean 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT'?
     383 |  case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW:
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |       POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
   drivers/power/supply/bq25890_charger.c:383:7: note: each undeclared identifier is reported only once for each function it appears in
   drivers/power/supply/bq25890_charger.c:384:7: error: 'POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW' undeclared (first use in this function); did you mean 'POWER_SUPPLY_PROP_VOLTAGE_NOW'?
     384 |  case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW:
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |       POWER_SUPPLY_PROP_VOLTAGE_NOW
   drivers/power/supply/bq25890_charger.c: In function 'bq25890_power_supply_get_property':
   drivers/power/supply/bq25890_charger.c:509:7: error: 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW' undeclared (first use in this function); did you mean 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT'?
     509 |  case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW:
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |       POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
   drivers/power/supply/bq25890_charger.c:527:7: error: 'POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW' undeclared (first use in this function); did you mean 'POWER_SUPPLY_PROP_VOLTAGE_NOW'?
     527 |  case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW:
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |       POWER_SUPPLY_PROP_VOLTAGE_NOW
>> drivers/power/supply/bq25890_charger.c:536:7: error: 'POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN' undeclared (first use in this function); did you mean 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT'?
     536 |  case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN:
         |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |       POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
   drivers/power/supply/bq25890_charger.c: At top level:
   drivers/power/supply/bq25890_charger.c:730:2: error: 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW' undeclared here (not in a function); did you mean 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT'?
     730 |  POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW,
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |  POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
>> drivers/power/supply/bq25890_charger.c:731:2: error: 'POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW' undeclared here (not in a function); did you mean 'POWER_SUPPLY_PROP_VOLTAGE_NOW'?
     731 |  POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW,
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |  POWER_SUPPLY_PROP_VOLTAGE_NOW
>> drivers/power/supply/bq25890_charger.c:732:2: error: 'POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN' undeclared here (not in a function); did you mean 'POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT'?
     732 |  POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN,
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         |  POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT
   drivers/power/supply/bq25890_charger.c:743:16: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     743 |  .properties = bq25890_power_supply_props,
         |                ^~~~~~~~~~~~~~~~~~~~~~~~~~

vim +536 drivers/power/supply/bq25890_charger.c

   395	
   396	static int bq25890_power_supply_get_property(struct power_supply *psy,
   397						     enum power_supply_property psp,
   398						     union power_supply_propval *val)
   399	{
   400		struct bq25890_device *bq = power_supply_get_drvdata(psy);
   401		struct bq25890_state state;
   402		bool do_adc_conv;
   403		int ret;
   404	
   405		mutex_lock(&bq->lock);
   406		/* update state in case we lost an interrupt */
   407		__bq25890_handle_irq(bq);
   408		state = bq->state;
   409		do_adc_conv = !state.online && bq25890_is_adc_property(psp);
   410		if (do_adc_conv)
   411			bq25890_field_write(bq, F_CONV_START, 1);
   412		mutex_unlock(&bq->lock);
   413	
   414		if (do_adc_conv)
   415			regmap_field_read_poll_timeout(bq->rmap_fields[F_CONV_START],
   416				ret, !ret, 25000, 1000000);
   417	
   418		switch (psp) {
   419		case POWER_SUPPLY_PROP_STATUS:
   420			if (!state.online)
   421				val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
   422			else if (state.chrg_status == STATUS_NOT_CHARGING)
   423				val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
   424			else if (state.chrg_status == STATUS_PRE_CHARGING ||
   425				 state.chrg_status == STATUS_FAST_CHARGING)
   426				val->intval = POWER_SUPPLY_STATUS_CHARGING;
   427			else if (state.chrg_status == STATUS_TERMINATION_DONE)
   428				val->intval = POWER_SUPPLY_STATUS_FULL;
   429			else
   430				val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
   431	
   432			break;
   433	
   434		case POWER_SUPPLY_PROP_CHARGE_TYPE:
   435			if (!state.online || state.chrg_status == STATUS_NOT_CHARGING ||
   436			    state.chrg_status == STATUS_TERMINATION_DONE)
   437				val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE;
   438			else if (state.chrg_status == STATUS_PRE_CHARGING)
   439				val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD;
   440			else if (state.chrg_status == STATUS_FAST_CHARGING)
   441				val->intval = POWER_SUPPLY_CHARGE_TYPE_FAST;
   442			else /* unreachable */
   443				val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN;
   444			break;
   445	
   446		case POWER_SUPPLY_PROP_MANUFACTURER:
   447			val->strval = BQ25890_MANUFACTURER;
   448			break;
   449	
   450		case POWER_SUPPLY_PROP_MODEL_NAME:
   451			val->strval = bq25890_chip_name[bq->chip_version];
   452			break;
   453	
   454		case POWER_SUPPLY_PROP_ONLINE:
   455			val->intval = state.online;
   456			break;
   457	
   458		case POWER_SUPPLY_PROP_HEALTH:
   459			if (!state.chrg_fault && !state.bat_fault && !state.boost_fault)
   460				val->intval = POWER_SUPPLY_HEALTH_GOOD;
   461			else if (state.bat_fault)
   462				val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
   463			else if (state.chrg_fault == CHRG_FAULT_TIMER_EXPIRED)
   464				val->intval = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE;
   465			else if (state.chrg_fault == CHRG_FAULT_THERMAL_SHUTDOWN)
   466				val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
   467			else
   468				val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
   469			break;
   470	
   471		case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
   472			val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
   473			break;
   474	
   475		case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
   476			if (!state.online) {
   477				val->intval = 0;
   478				break;
   479			}
   480	
   481			ret = bq25890_field_read(bq, F_BATV); /* read measured value */
   482			if (ret < 0)
   483				return ret;
   484	
   485			/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
   486			val->intval = 2304000 + ret * 20000;
   487			break;
   488	
   489		case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
   490			val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
   491			break;
   492	
   493		case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
   494			val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM);
   495			break;
   496	
   497		case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
   498			val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM);
   499			break;
   500	
   501		case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
   502			ret = bq25890_field_read(bq, F_IILIM);
   503			if (ret < 0)
   504				return ret;
   505	
   506			val->intval = bq25890_find_val(ret, TBL_IILIM);
   507			break;
   508	
   509		case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW:
   510			ret = bq25890_field_read(bq, F_VBUS_GD); /* is VBUS connected? */
   511			if (ret < 0)
   512				return ret;
   513	
   514			if (!ret) {
   515				val->intval = 0;
   516				break;
   517			}
   518	
   519			ret = bq25890_field_read(bq, F_VBUSV); /* read measured value */
   520			if (ret < 0)
   521				return ret;
   522	
   523			/* converted_val = 2.6V + ADC_val * 100mV */
   524			val->intval = 2600000 + ret * 100000;
   525			break;
   526	
   527		case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW:
   528			ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
   529			if (ret < 0)
   530				return ret;
   531	
   532			/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
   533			val->intval = 2304000 + ret * 20000;
   534			break;
   535	
 > 536		case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN:
   537			val->intval = bq25890_find_val(bq->init_data.sysvmin, TBL_SYSVMIN);
   538			break;
   539	
   540		case POWER_SUPPLY_PROP_CURRENT_NOW:
   541			ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */
   542			if (ret < 0)
   543				return ret;
   544	
   545			/* converted_val = ADC_val * 50mA (table 10.3.19) */
   546			val->intval = ret * -50000;
   547			break;
   548	
   549		default:
   550			return -EINVAL;
   551		}
   552	
   553		return 0;
   554	}
   555	
   556	static int bq25890_get_chip_state(struct bq25890_device *bq,
   557					  struct bq25890_state *state)
   558	{
   559		int i, ret;
   560	
   561		struct {
   562			enum bq25890_fields id;
   563			u8 *data;
   564		} state_fields[] = {
   565			{F_CHG_STAT,	&state->chrg_status},
   566			{F_PG_STAT,	&state->online},
   567			{F_VSYS_STAT,	&state->vsys_status},
   568			{F_BOOST_FAULT, &state->boost_fault},
   569			{F_BAT_FAULT,	&state->bat_fault},
   570			{F_CHG_FAULT,	&state->chrg_fault}
   571		};
   572	
   573		for (i = 0; i < ARRAY_SIZE(state_fields); i++) {
   574			ret = bq25890_field_read(bq, state_fields[i].id);
   575			if (ret < 0)
   576				return ret;
   577	
   578			*state_fields[i].data = ret;
   579		}
   580	
   581		dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT=%d/%d/%d\n",
   582			state->chrg_status, state->online, state->vsys_status,
   583			state->chrg_fault, state->boost_fault, state->bat_fault);
   584	
   585		return 0;
   586	}
   587	
   588	static irqreturn_t __bq25890_handle_irq(struct bq25890_device *bq)
   589	{
   590		struct bq25890_state new_state;
   591		int ret;
   592	
   593		ret = bq25890_get_chip_state(bq, &new_state);
   594		if (ret < 0)
   595			return IRQ_NONE;
   596	
   597		if (!memcmp(&bq->state, &new_state, sizeof(new_state)))
   598			return IRQ_NONE;
   599	
   600		if (!new_state.online && bq->state.online) {	    /* power removed */
   601			/* disable ADC */
   602			ret = bq25890_field_write(bq, F_CONV_START, 0);
   603			if (ret < 0)
   604				goto error;
   605		} else if (new_state.online && !bq->state.online) { /* power inserted */
   606			/* enable ADC, to have control of charge current/voltage */
   607			ret = bq25890_field_write(bq, F_CONV_START, 1);
   608			if (ret < 0)
   609				goto error;
   610		}
   611	
   612		bq->state = new_state;
   613		power_supply_changed(bq->charger);
   614	
   615		return IRQ_HANDLED;
   616	error:
   617		dev_err(bq->dev, "Error communicating with the chip: %pe\n",
   618			ERR_PTR(ret));
   619		return IRQ_HANDLED;
   620	}
   621	
   622	static irqreturn_t bq25890_irq_handler_thread(int irq, void *private)
   623	{
   624		struct bq25890_device *bq = private;
   625		irqreturn_t ret;
   626	
   627		mutex_lock(&bq->lock);
   628		ret = __bq25890_handle_irq(bq);
   629		mutex_unlock(&bq->lock);
   630	
   631		return ret;
   632	}
   633	
   634	static int bq25890_chip_reset(struct bq25890_device *bq)
   635	{
   636		int ret;
   637		int rst_check_counter = 10;
   638	
   639		ret = bq25890_field_write(bq, F_REG_RST, 1);
   640		if (ret < 0)
   641			return ret;
   642	
   643		do {
   644			ret = bq25890_field_read(bq, F_REG_RST);
   645			if (ret < 0)
   646				return ret;
   647	
   648			usleep_range(5, 10);
   649		} while (ret == 1 && --rst_check_counter);
   650	
   651		if (!rst_check_counter)
   652			return -ETIMEDOUT;
   653	
   654		return 0;
   655	}
   656	
   657	static int bq25890_hw_init(struct bq25890_device *bq)
   658	{
   659		int ret;
   660		int i;
   661	
   662		const struct {
   663			enum bq25890_fields id;
   664			u32 value;
   665		} init_data[] = {
   666			{F_ICHG,	 bq->init_data.ichg},
   667			{F_VREG,	 bq->init_data.vreg},
   668			{F_ITERM,	 bq->init_data.iterm},
   669			{F_IPRECHG,	 bq->init_data.iprechg},
   670			{F_SYSVMIN,	 bq->init_data.sysvmin},
   671			{F_BOOSTV,	 bq->init_data.boostv},
   672			{F_BOOSTI,	 bq->init_data.boosti},
   673			{F_BOOSTF,	 bq->init_data.boostf},
   674			{F_EN_ILIM,	 bq->init_data.ilim_en},
   675			{F_TREG,	 bq->init_data.treg}
   676		};
   677	
   678		ret = bq25890_chip_reset(bq);
   679		if (ret < 0) {
   680			dev_dbg(bq->dev, "Reset failed %d\n", ret);
   681			return ret;
   682		}
   683	
   684		/* disable watchdog */
   685		ret = bq25890_field_write(bq, F_WD, 0);
   686		if (ret < 0) {
   687			dev_dbg(bq->dev, "Disabling watchdog failed %d\n", ret);
   688			return ret;
   689		}
   690	
   691		/* initialize currents/voltages and other parameters */
   692		for (i = 0; i < ARRAY_SIZE(init_data); i++) {
   693			ret = bq25890_field_write(bq, init_data[i].id,
   694						  init_data[i].value);
   695			if (ret < 0) {
   696				dev_dbg(bq->dev, "Writing init data failed %d\n", ret);
   697				return ret;
   698			}
   699		}
   700	
   701		/* Configure ADC for continuous conversions when charging */
   702		ret = bq25890_field_write(bq, F_CONV_RATE, !!bq->state.online);
   703		if (ret < 0) {
   704			dev_dbg(bq->dev, "Config ADC failed %d\n", ret);
   705			return ret;
   706		}
   707	
   708		ret = bq25890_get_chip_state(bq, &bq->state);
   709		if (ret < 0) {
   710			dev_dbg(bq->dev, "Get state failed %d\n", ret);
   711			return ret;
   712		}
   713	
   714		return 0;
   715	}
   716	
   717	static const enum power_supply_property bq25890_power_supply_props[] = {
   718		POWER_SUPPLY_PROP_MANUFACTURER,
   719		POWER_SUPPLY_PROP_MODEL_NAME,
   720		POWER_SUPPLY_PROP_STATUS,
   721		POWER_SUPPLY_PROP_CHARGE_TYPE,
   722		POWER_SUPPLY_PROP_ONLINE,
   723		POWER_SUPPLY_PROP_HEALTH,
   724		POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
   725		POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
   726		POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
   727		POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
   728		POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
   729		POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
   730		POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW,
 > 731		POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW,
 > 732		POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN,
   733		POWER_SUPPLY_PROP_CURRENT_NOW,
   734	};
   735	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index d23274d13263..6c277f2dbae2 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -524,7 +524,7 @@  static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = 2600000 + ret * 100000;
 		break;
 
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+	case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW:
 		ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
 		if (ret < 0)
 			return ret;
@@ -533,6 +533,10 @@  static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = 2304000 + ret * 20000;
 		break;
 
+	case POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN:
+		val->intval = bq25890_find_val(bq->init_data.sysvmin, TBL_SYSVMIN);
+		break;
+
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */
 		if (ret < 0)
@@ -724,7 +728,8 @@  static const enum power_supply_property bq25890_power_supply_props[] = {
 	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
 	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
 	POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW,
-	POWER_SUPPLY_PROP_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_NOW,
+	POWER_SUPPLY_PROP_OUTPUT_VOLTAGE_MIN,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 };