Skip to content

Commit 8891716

Browse files
author
Lee Jones
committed
ab8500-bm: Charge only mode fixes for the ab9540
Fix for charging not getting enabled in charge only mode by external charger. Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 789ca7b commit 8891716

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎drivers/power/ab8500_charger.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/device.h>
1616
#include <linux/interrupt.h>
1717
#include <linux/delay.h>
18+
#include <linux/notifier.h>
1819
#include <linux/slab.h>
1920
#include <linux/platform_device.h>
2021
#include <linux/power_supply.h>
@@ -97,6 +98,10 @@
9798
#define AB8500_SW_CONTROL_FALLBACK 0x03
9899
/* Wait for enumeration before charing in us */
99100
#define WAIT_ACA_RID_ENUMERATION (5 * 1000)
101+
/*External charger control*/
102+
#define AB8500_SYS_CHARGER_CONTROL_REG 0x52
103+
#define EXTERNAL_CHARGER_DISABLE_REG_VAL 0x03
104+
#define EXTERNAL_CHARGER_ENABLE_REG_VAL 0x07
100105

101106
/* UsbLineStatus register - usb types */
102107
enum ab8500_charger_link_status {
@@ -1678,6 +1683,29 @@ static int ab8500_charger_usb_en(struct ux500_charger *charger,
16781683
return ret;
16791684
}
16801685

1686+
static int ab8500_external_charger_prepare(struct notifier_block *charger_nb,
1687+
unsigned long event, void *data)
1688+
{
1689+
int ret;
1690+
struct device *dev = data;
1691+
/*Toggle External charger control pin*/
1692+
ret = abx500_set_register_interruptible(dev, AB8500_SYS_CTRL1_BLOCK,
1693+
AB8500_SYS_CHARGER_CONTROL_REG,
1694+
EXTERNAL_CHARGER_DISABLE_REG_VAL);
1695+
if (ret < 0) {
1696+
dev_err(dev, "write reg failed %d\n", ret);
1697+
goto out;
1698+
}
1699+
ret = abx500_set_register_interruptible(dev, AB8500_SYS_CTRL1_BLOCK,
1700+
AB8500_SYS_CHARGER_CONTROL_REG,
1701+
EXTERNAL_CHARGER_ENABLE_REG_VAL);
1702+
if (ret < 0)
1703+
dev_err(dev, "Write reg failed %d\n", ret);
1704+
1705+
out:
1706+
return ret;
1707+
}
1708+
16811709
/**
16821710
* ab8500_charger_usb_check_enable() - enable usb charging
16831711
* @charger: pointer to the ux500_charger structure
@@ -3221,6 +3249,10 @@ static int ab8500_charger_suspend(struct platform_device *pdev,
32213249
#define ab8500_charger_resume NULL
32223250
#endif
32233251

3252+
static struct notifier_block charger_nb = {
3253+
.notifier_call = ab8500_external_charger_prepare,
3254+
};
3255+
32243256
static int ab8500_charger_remove(struct platform_device *pdev)
32253257
{
32263258
struct ab8500_charger *di = platform_get_drvdata(pdev);
@@ -3250,6 +3282,11 @@ static int ab8500_charger_remove(struct platform_device *pdev)
32503282
/* Delete the work queue */
32513283
destroy_workqueue(di->charger_wq);
32523284

3285+
/* Unregister external charger enable notifier */
3286+
if (!di->ac_chg.enabled)
3287+
blocking_notifier_chain_unregister(
3288+
&charger_notifier_list, &charger_nb);
3289+
32533290
flush_scheduled_work();
32543291
if (di->usb_chg.enabled)
32553292
power_supply_unregister(&di->usb_chg.psy);
@@ -3331,6 +3368,11 @@ static int ab8500_charger_probe(struct platform_device *pdev)
33313368
di->ac_chg.enabled = di->bm->ac_enabled;
33323369
di->ac_chg.external = false;
33333370

3371+
/*notifier for external charger enabling*/
3372+
if (!di->ac_chg.enabled)
3373+
blocking_notifier_chain_register(
3374+
&charger_notifier_list, &charger_nb);
3375+
33343376
/* USB supply */
33353377
/* power_supply base class */
33363378
di->usb_chg.psy.name = "ab8500_usb";

‎drivers/power/abx500_chargalg.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/mfd/abx500.h>
2727
#include <linux/mfd/abx500/ux500_chargalg.h>
2828
#include <linux/mfd/abx500/ab8500-bm.h>
29+
#include <linux/notifier.h>
2930

3031
/* Watchdog kick interval */
3132
#define CHG_WD_INTERVAL (6 * HZ)
@@ -243,6 +244,9 @@ struct abx500_chargalg {
243244
struct kobject chargalg_kobject;
244245
};
245246

247+
/*External charger prepare notifier*/
248+
BLOCKING_NOTIFIER_HEAD(charger_notifier_list);
249+
246250
/* Main battery properties */
247251
static enum power_supply_property abx500_chargalg_props[] = {
248252
POWER_SUPPLY_PROP_STATUS,
@@ -503,6 +507,8 @@ static int abx500_chargalg_kick_watchdog(struct abx500_chargalg *di)
503507
static int abx500_chargalg_ac_en(struct abx500_chargalg *di, int enable,
504508
int vset, int iset)
505509
{
510+
static int abx500_chargalg_ex_ac_enable_toggle;
511+
506512
if (!di->ac_chg || !di->ac_chg->ops.enable)
507513
return -ENXIO;
508514

@@ -515,6 +521,14 @@ static int abx500_chargalg_ac_en(struct abx500_chargalg *di, int enable,
515521
di->chg_info.ac_iset = iset;
516522
di->chg_info.ac_vset = vset;
517523

524+
/* Enable external charger */
525+
if (enable && di->ac_chg->external &&
526+
!abx500_chargalg_ex_ac_enable_toggle) {
527+
blocking_notifier_call_chain(&charger_notifier_list,
528+
0, di->dev);
529+
abx500_chargalg_ex_ac_enable_toggle++;
530+
}
531+
518532
return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset);
519533
}
520534

‎drivers/power/pm2301_charger.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,13 @@ static int pm2xxx_wall_charger_probe(struct i2c_client *i2c_client,
10591059
ret = pm2xxx_charger_detection(pm2, &val);
10601060

10611061
if ((ret == 0) && val) {
1062+
/*
1063+
* When boot is due to AC charger plug-in,
1064+
* read interrupt registers
1065+
*/
1066+
pm2xxx_reg_read(pm2, PM2XXX_REG_INT1, &val);
1067+
pm2xxx_reg_read(pm2, PM2XXX_REG_INT2, &val);
1068+
pm2xxx_reg_read(pm2, PM2XXX_REG_INT4, &val);
10621069
pm2->ac.charger_connected = 1;
10631070
pm2->ac_conn = true;
10641071
power_supply_changed(&pm2->ac_chg.psy);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ struct ux500_charger {
4141
bool external;
4242
};
4343

44+
extern struct blocking_notifier_head charger_notifier_list;
45+
4446
#endif

0 commit comments

Comments
 (0)