Skip to content

Commit 5161ec2

Browse files
Hermes Zhangsre
authored andcommitted
power: supply: bq256xx: Support to disable charger
To be able to control the charging process flexible, we need to able to disable the charger. This commit will allow to disable the charger by "echo 1 > /sys/class/power_supply/bq256xx-charger/charge_type" (1 = POWER_SUPPLY_CHARGE_TYPE_NONE) and enable the charger by set it to 2/3 (POWER_SUPPLY_CHARGE_TYPE_TRICKLE/POWER_SUPPLY_CHARGE_TYPE_FAST) Signed-off-by: Hermes Zhang <chenhuiz@axis.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 83425c8 commit 5161ec2

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

drivers/power/supply/bq256xx_charger.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
#define BQ25611D_VBATREG_THRESH_uV 4290000
7171
#define BQ25618_VBATREG_THRESH_uV 4300000
7272

73+
#define BQ256XX_CHG_CONFIG_MASK BIT(4)
74+
#define BQ256XX_CHG_CONFIG_BIT_SHIFT 4
75+
7376
#define BQ256XX_ITERM_MASK GENMASK(3, 0)
7477
#define BQ256XX_ITERM_STEP_uA 60000
7578
#define BQ256XX_ITERM_OFFSET_uA 60000
@@ -259,6 +262,7 @@ struct bq256xx_device {
259262
* @bq256xx_set_iterm: pointer to instance specific set_iterm function
260263
* @bq256xx_set_iprechg: pointer to instance specific set_iprechg function
261264
* @bq256xx_set_vindpm: pointer to instance specific set_vindpm function
265+
* @bq256xx_set_charge_type: pointer to instance specific set_charge_type function
262266
*
263267
* @bq256xx_def_ichg: default ichg value in microamps
264268
* @bq256xx_def_iindpm: default iindpm value in microamps
@@ -290,6 +294,7 @@ struct bq256xx_chip_info {
290294
int (*bq256xx_set_iterm)(struct bq256xx_device *bq, int iterm);
291295
int (*bq256xx_set_iprechg)(struct bq256xx_device *bq, int iprechg);
292296
int (*bq256xx_set_vindpm)(struct bq256xx_device *bq, int vindpm);
297+
int (*bq256xx_set_charge_type)(struct bq256xx_device *bq, int type);
293298

294299
int bq256xx_def_ichg;
295300
int bq256xx_def_iindpm;
@@ -449,6 +454,27 @@ static int bq256xx_get_state(struct bq256xx_device *bq,
449454
return 0;
450455
}
451456

457+
static int bq256xx_set_charge_type(struct bq256xx_device *bq, int type)
458+
{
459+
int chg_config = 0;
460+
461+
switch (type) {
462+
case POWER_SUPPLY_CHARGE_TYPE_NONE:
463+
chg_config = 0x0;
464+
break;
465+
case POWER_SUPPLY_CHARGE_TYPE_TRICKLE:
466+
case POWER_SUPPLY_CHARGE_TYPE_FAST:
467+
chg_config = 0x1;
468+
break;
469+
default:
470+
return -EINVAL;
471+
}
472+
473+
return regmap_update_bits(bq->regmap, BQ256XX_CHARGER_CONTROL_0,
474+
BQ256XX_CHG_CONFIG_MASK,
475+
(chg_config ? 1 : 0) << BQ256XX_CHG_CONFIG_BIT_SHIFT);
476+
}
477+
452478
static int bq256xx_get_ichg_curr(struct bq256xx_device *bq)
453479
{
454480
unsigned int charge_current_limit;
@@ -915,6 +941,12 @@ static int bq256xx_set_charger_property(struct power_supply *psy,
915941
return ret;
916942
break;
917943

944+
case POWER_SUPPLY_PROP_CHARGE_TYPE:
945+
ret = bq->chip_info->bq256xx_set_charge_type(bq, val->intval);
946+
if (ret)
947+
return ret;
948+
break;
949+
918950
default:
919951
break;
920952
}
@@ -1197,6 +1229,7 @@ static int bq256xx_property_is_writeable(struct power_supply *psy,
11971229
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
11981230
case POWER_SUPPLY_PROP_STATUS:
11991231
case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT:
1232+
case POWER_SUPPLY_PROP_CHARGE_TYPE:
12001233
return true;
12011234
default:
12021235
return false;
@@ -1286,6 +1319,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
12861319
.bq256xx_set_iterm = bq256xx_set_term_curr,
12871320
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
12881321
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1322+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
12891323

12901324
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
12911325
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1316,6 +1350,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
13161350
.bq256xx_set_iterm = bq256xx_set_term_curr,
13171351
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
13181352
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1353+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
13191354

13201355
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
13211356
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1346,6 +1381,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
13461381
.bq256xx_set_iterm = bq256xx_set_term_curr,
13471382
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
13481383
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1384+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
13491385

13501386
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
13511387
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1376,6 +1412,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
13761412
.bq256xx_set_iterm = bq256xx_set_term_curr,
13771413
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
13781414
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1415+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
13791416

13801417
.bq256xx_def_ichg = BQ2560X_ICHG_DEF_uA,
13811418
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1406,6 +1443,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
14061443
.bq256xx_set_iterm = bq256xx_set_term_curr,
14071444
.bq256xx_set_iprechg = bq256xx_set_prechrg_curr,
14081445
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1446+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
14091447

14101448
.bq256xx_def_ichg = BQ25611D_ICHG_DEF_uA,
14111449
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1436,6 +1474,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
14361474
.bq256xx_set_iterm = bq25618_619_set_term_curr,
14371475
.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
14381476
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1477+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
14391478

14401479
.bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
14411480
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,
@@ -1466,6 +1505,7 @@ static const struct bq256xx_chip_info bq256xx_chip_info_tbl[] = {
14661505
.bq256xx_set_iterm = bq25618_619_set_term_curr,
14671506
.bq256xx_set_iprechg = bq25618_619_set_prechrg_curr,
14681507
.bq256xx_set_vindpm = bq256xx_set_input_volt_lim,
1508+
.bq256xx_set_charge_type = bq256xx_set_charge_type,
14691509

14701510
.bq256xx_def_ichg = BQ25618_ICHG_DEF_uA,
14711511
.bq256xx_def_iindpm = BQ256XX_IINDPM_DEF_uA,

0 commit comments

Comments
 (0)