Skip to content

Commit db43e6c

Browse files
author
Lee Jones
committed
ab8500-bm: Add usb power path support
AB8540 supports power path function in USB charging mode for fast power up with dead and weak battery, and it could extend the battery age. When USB charging starts, if the Vbattrue is below than SW cut off voltage, power path and pre-charge should be enabled. If Vbattrue is higher than SW cut off voltage, power path and pre-charge should be disabled. This is to make sure full current to battery charge. At the end of charge, power path should be enable again to reduce charging the battery again. Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 405fea1 commit db43e6c

5 files changed

Lines changed: 160 additions & 0 deletions

File tree

‎drivers/power/ab8500_charger.c‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,67 @@ static int ab8500_charger_update_charger_current(struct ux500_charger *charger,
19251925
return ret;
19261926
}
19271927

1928+
/**
1929+
* ab8540_charger_power_path_enable() - enable usb power path mode
1930+
* @charger: pointer to the ux500_charger structure
1931+
* @enable: enable/disable flag
1932+
*
1933+
* Enable or disable the power path for usb mode
1934+
* Returns error code in case of failure else 0(on success)
1935+
*/
1936+
static int ab8540_charger_power_path_enable(struct ux500_charger *charger,
1937+
bool enable)
1938+
{
1939+
int ret;
1940+
struct ab8500_charger *di;
1941+
1942+
if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1943+
di = to_ab8500_charger_usb_device_info(charger);
1944+
else
1945+
return -ENXIO;
1946+
1947+
ret = abx500_mask_and_set_register_interruptible(di->dev,
1948+
AB8500_CHARGER, AB8540_USB_PP_MODE_REG,
1949+
BUS_POWER_PATH_MODE_ENA, enable);
1950+
if (ret) {
1951+
dev_err(di->dev, "%s write failed\n", __func__);
1952+
return ret;
1953+
}
1954+
1955+
return ret;
1956+
}
1957+
1958+
1959+
/**
1960+
* ab8540_charger_usb_pre_chg_enable() - enable usb pre change
1961+
* @charger: pointer to the ux500_charger structure
1962+
* @enable: enable/disable flag
1963+
*
1964+
* Enable or disable the pre-chage for usb mode
1965+
* Returns error code in case of failure else 0(on success)
1966+
*/
1967+
static int ab8540_charger_usb_pre_chg_enable(struct ux500_charger *charger,
1968+
bool enable)
1969+
{
1970+
int ret;
1971+
struct ab8500_charger *di;
1972+
1973+
if (charger->psy.type == POWER_SUPPLY_TYPE_USB)
1974+
di = to_ab8500_charger_usb_device_info(charger);
1975+
else
1976+
return -ENXIO;
1977+
1978+
ret = abx500_mask_and_set_register_interruptible(di->dev,
1979+
AB8500_CHARGER, AB8540_USB_PP_CHR_REG,
1980+
BUS_POWER_PATH_PRECHG_ENA, enable);
1981+
if (ret) {
1982+
dev_err(di->dev, "%s write failed\n", __func__);
1983+
return ret;
1984+
}
1985+
1986+
return ret;
1987+
}
1988+
19281989
static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data)
19291990
{
19301991
struct power_supply *psy;
@@ -3201,6 +3262,23 @@ static int ab8500_charger_init_hw_registers(struct ab8500_charger *di)
32013262
if (ret < 0)
32023263
dev_err(di->dev, "%s mask and set failed\n", __func__);
32033264

3265+
if (is_ab8540(di->parent)) {
3266+
ret = abx500_mask_and_set_register_interruptible(di->dev,
3267+
AB8500_CHARGER, AB8540_USB_PP_MODE_REG,
3268+
BUS_VSYS_VOL_SELECT_MASK, BUS_VSYS_VOL_SELECT_3P6V);
3269+
if (ret) {
3270+
dev_err(di->dev, "failed to setup usb power path vsys voltage\n");
3271+
goto out;
3272+
}
3273+
ret = abx500_mask_and_set_register_interruptible(di->dev,
3274+
AB8500_CHARGER, AB8540_USB_PP_CHR_REG,
3275+
BUS_PP_PRECHG_CURRENT_MASK, 0);
3276+
if (ret) {
3277+
dev_err(di->dev, "failed to setup usb power path prechage current\n");
3278+
goto out;
3279+
}
3280+
}
3281+
32043282
out:
32053283
return ret;
32063284
}
@@ -3484,13 +3562,16 @@ static int ab8500_charger_probe(struct platform_device *pdev)
34843562
di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable;
34853563
di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick;
34863564
di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current;
3565+
di->usb_chg.ops.pp_enable = &ab8540_charger_power_path_enable;
3566+
di->usb_chg.ops.pre_chg_enable = &ab8540_charger_usb_pre_chg_enable;
34873567
di->usb_chg.max_out_volt = ab8500_charger_voltage_map[
34883568
ARRAY_SIZE(ab8500_charger_voltage_map) - 1];
34893569
di->usb_chg.max_out_curr = ab8500_charger_current_map[
34903570
ARRAY_SIZE(ab8500_charger_current_map) - 1];
34913571
di->usb_chg.wdt_refresh = CHG_WD_INTERVAL;
34923572
di->usb_chg.enabled = di->bm->usb_enabled;
34933573
di->usb_chg.external = false;
3574+
di->usb_chg.power_path = di->bm->usb_power_path;
34943575
di->usb_state.usb_current = -1;
34953576

34963577
/* Create a work queue for the charger */

‎drivers/power/abx500_chargalg.c‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
/* End-of-charge criteria counter */
3535
#define EOC_COND_CNT 10
3636

37+
/* Plus margin for the low battery threshold */
38+
#define BAT_PLUS_MARGIN (100)
39+
3740
#define to_abx500_chargalg_device_info(x) container_of((x), \
3841
struct abx500_chargalg, chargalg_psy);
3942

@@ -83,6 +86,7 @@ enum abx500_chargalg_states {
8386
STATE_HW_TEMP_PROTECT_INIT,
8487
STATE_HW_TEMP_PROTECT,
8588
STATE_NORMAL_INIT,
89+
STATE_USB_PP_PRE_CHARGE,
8690
STATE_NORMAL,
8791
STATE_WAIT_FOR_RECHARGE_INIT,
8892
STATE_WAIT_FOR_RECHARGE,
@@ -114,6 +118,7 @@ static const char *states[] = {
114118
"HW_TEMP_PROTECT_INIT",
115119
"HW_TEMP_PROTECT",
116120
"NORMAL_INIT",
121+
"USB_PP_PRE_CHARGE",
117122
"NORMAL",
118123
"WAIT_FOR_RECHARGE_INIT",
119124
"WAIT_FOR_RECHARGE",
@@ -560,6 +565,37 @@ static int abx500_chargalg_usb_en(struct abx500_chargalg *di, int enable,
560565
return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset);
561566
}
562567

568+
/**
569+
* ab8540_chargalg_usb_pp_en() - Enable/ disable USB power path
570+
* @di: pointer to the abx500_chargalg structure
571+
* @enable: power path enable/disable
572+
*
573+
* The USB power path will be enable/ disable
574+
*/
575+
static int ab8540_chargalg_usb_pp_en(struct abx500_chargalg *di, bool enable)
576+
{
577+
if (!di->usb_chg || !di->usb_chg->ops.pp_enable)
578+
return -ENXIO;
579+
580+
return di->usb_chg->ops.pp_enable(di->usb_chg, enable);
581+
}
582+
583+
/**
584+
* ab8540_chargalg_usb_pre_chg_en() - Enable/ disable USB pre-charge
585+
* @di: pointer to the abx500_chargalg structure
586+
* @enable: USB pre-charge enable/disable
587+
*
588+
* The USB USB pre-charge will be enable/ disable
589+
*/
590+
static int ab8540_chargalg_usb_pre_chg_en(struct abx500_chargalg *di,
591+
bool enable)
592+
{
593+
if (!di->usb_chg || !di->usb_chg->ops.pre_chg_enable)
594+
return -ENXIO;
595+
596+
return di->usb_chg->ops.pre_chg_enable(di->usb_chg, enable);
597+
}
598+
563599
/**
564600
* abx500_chargalg_update_chg_curr() - Update charger current
565601
* @di: pointer to the abx500_chargalg structure
@@ -765,6 +801,9 @@ static void abx500_chargalg_end_of_charge(struct abx500_chargalg *di)
765801
di->batt_data.avg_curr > 0) {
766802
if (++di->eoc_cnt >= EOC_COND_CNT) {
767803
di->eoc_cnt = 0;
804+
if ((di->chg_info.charger_type & USB_CHG) &&
805+
(di->usb_chg->power_path))
806+
ab8540_chargalg_usb_pp_en(di, true);
768807
di->charge_status = POWER_SUPPLY_STATUS_FULL;
769808
di->maintenance_chg = true;
770809
dev_dbg(di->dev, "EOC reached!\n");
@@ -1465,6 +1504,22 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
14651504
break;
14661505

14671506
case STATE_NORMAL_INIT:
1507+
if ((di->chg_info.charger_type & USB_CHG) &&
1508+
di->usb_chg->power_path) {
1509+
if (di->batt_data.volt >
1510+
(di->bm->fg_params->lowbat_threshold +
1511+
BAT_PLUS_MARGIN)) {
1512+
ab8540_chargalg_usb_pre_chg_en(di, false);
1513+
ab8540_chargalg_usb_pp_en(di, false);
1514+
} else {
1515+
ab8540_chargalg_usb_pp_en(di, true);
1516+
ab8540_chargalg_usb_pre_chg_en(di, true);
1517+
abx500_chargalg_state_to(di,
1518+
STATE_USB_PP_PRE_CHARGE);
1519+
break;
1520+
}
1521+
}
1522+
14681523
abx500_chargalg_start_charging(di,
14691524
di->bm->bat_type[di->bm->batt_id].normal_vol_lvl,
14701525
di->bm->bat_type[di->bm->batt_id].normal_cur_lvl);
@@ -1479,6 +1534,13 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)
14791534

14801535
break;
14811536

1537+
case STATE_USB_PP_PRE_CHARGE:
1538+
if (di->batt_data.volt >
1539+
(di->bm->fg_params->lowbat_threshold +
1540+
BAT_PLUS_MARGIN))
1541+
abx500_chargalg_state_to(di, STATE_NORMAL_INIT);
1542+
break;
1543+
14821544
case STATE_NORMAL:
14831545
handle_maxim_chg_curr(di);
14841546
if (di->charge_status == POWER_SUPPLY_STATUS_FULL &&

‎include/linux/mfd/abx500.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ struct abx500_bm_data {
267267
bool autopower_cfg;
268268
bool ac_enabled;
269269
bool usb_enabled;
270+
bool usb_power_path;
270271
bool no_maintenance;
271272
bool capacity_scaling;
272273
bool chg_unknown_bat;

‎include/linux/mfd/abx500/ab8500-bm.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#define AB8500_USBCH_CTRL1_REG 0xC0
7070
#define AB8500_USBCH_CTRL2_REG 0xC1
7171
#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
72+
#define AB8540_USB_PP_MODE_REG 0xC5
73+
#define AB8540_USB_PP_CHR_REG 0xC6
7274

7375
/*
7476
* Gas Gauge register offsets
@@ -259,6 +261,16 @@ enum bup_vch_sel {
259261
#define AB8505_RTC_PCUT_RESTART_REG 0x16
260262
#define AB8505_RTC_PCUT_DEBOUNCE_REG 0x17
261263

264+
/* USB Power Path constants for ab8540 */
265+
#define BUS_VSYS_VOL_SELECT_MASK 0x06
266+
#define BUS_VSYS_VOL_SELECT_3P6V 0x00
267+
#define BUS_VSYS_VOL_SELECT_3P325V 0x02
268+
#define BUS_VSYS_VOL_SELECT_3P9V 0x04
269+
#define BUS_VSYS_VOL_SELECT_4P3V 0x06
270+
#define BUS_POWER_PATH_MODE_ENA 0x01
271+
#define BUS_PP_PRECHG_CURRENT_MASK 0x0E
272+
#define BUS_POWER_PATH_PRECHG_ENA 0x01
273+
262274
/**
263275
* struct res_to_temp - defines one point in a temp to res curve. To
264276
* be used in battery packs that combines the identification resistor with a

‎include/linux/mfd/abx500/ux500_chargalg.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct ux500_charger_ops {
2020
int (*check_enable) (struct ux500_charger *, int, int);
2121
int (*kick_wd) (struct ux500_charger *);
2222
int (*update_curr) (struct ux500_charger *, int);
23+
int (*pp_enable) (struct ux500_charger *, bool);
24+
int (*pre_chg_enable) (struct ux500_charger *, bool);
2325
};
2426

2527
/**
@@ -30,6 +32,7 @@ struct ux500_charger_ops {
3032
* @max_out_curr maximum output charger current in mA
3133
* @enabled indicates if this charger is used or not
3234
* @external external charger unit (pm2xxx)
35+
* @power_path USB power path support
3336
*/
3437
struct ux500_charger {
3538
struct power_supply psy;
@@ -39,6 +42,7 @@ struct ux500_charger {
3942
int wdt_refresh;
4043
bool enabled;
4144
bool external;
45+
bool power_path;
4246
};
4347

4448
extern struct blocking_notifier_head charger_notifier_list;

0 commit comments

Comments
 (0)