AB8500 battery management series upgrade
cover AB8500 battery management series upgrade
Hi Anton,
Please find the next instalment of the AB8500 Power drivers upgrade. A lot of work has taken place on the internal development track, but little effort has gone into mainlining it. At last count there were around 70+ patches which are in need of forward-porting, then upstreaming. This patch-set aims to make a good start. :)
drivers/power/Kconfig | 15 + drivers/power/Makefile | 1 + drivers/power/ab8500_bmdata.c | 18 +- drivers/power/ab8500_btemp.c | 27 +- drivers/power/ab8500_charger.c | 348 ++++++-- drivers/power/ab8500_fg.c | 336 +++++-- drivers/power/abx500_chargalg.c | 30 +- drivers/power/pm2301_charger.c | 1599 ++++++++++++++++++++++++++++++++++ include/linux/mfd/abx500.h | 6 +- include/linux/mfd/abx500/ab8500-bm.h | 10 + include/linux/mfd/abx500/ab8500.h | 5 + include/linux/pm2301_charger.h | 60 ++ 12 files changed, 2312 insertions(+), 143 deletions(-)
PATCH 1/18 power: ab8500_charger: Rename the power_loss function
From: Paer-Olof Haakansson <[email protected]>
Rename the ab8500_power_loss_handling function to a more descriptive name ab8500_enable_disable_sw_fallback
--- drivers/power/ab8500_charger.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/power/ab8500_charger.c +11 -12
@@ -270,20 +270,19 @@ static enum power_supply_property ab8500_charger_usb_props[] = { POWER_SUPPLY_PROP_CURRENT_NOW, }; -/** -* ab8500_power_loss_handling - set how we handle powerloss. -* @di: pointer to the ab8500_charger structure -* -* Magic nummbers are from STE HW department. +/* +* Function for enabling and disabling sw fallback mode +* should always be disabled when no charger is connected. */ -static void ab8500_power_loss_handling (struct ab8500_charger *di) +static void ab8500_enable_disable_sw_fallback (struct ab8500_charger *di, +bool fallback) {u8 reg;int ret; -dev_dbg (di->dev,"Autopower : %d\n" , di->autopower); +dev_dbg (di->dev,"SW Fallback: %d\n" , fallback); -/* read the autopower register */ +/* read the register containing fallback bit */ ret =abx500_get_register_interruptible (di->dev,0x15 ,0x00 , ®);if (ret) {dev_err (di->dev,"%d write failed\n" , __LINE__);
@@ -297,12 +296,12 @@ static void ab8500_power_loss_handling(struct ab8500_charger *di)return ; } -if (di->autopower) +if (fallback) reg |=0x8 ;else reg &= ~0x8 ; -/* write back the changed value to autopower reg */ +/* write back the changed fallback bit value to register */ ret =abx500_set_register_interruptible (di->dev,0x15 ,0x00 , reg);if (ret) {dev_err (di->dev,"%d write failed\n" , __LINE__);
@@ -332,12 +331,12 @@ static void ab8500_power_supply_changed(struct ab8500_charger *di, !di->ac.charger_connected && di->autopower) { di->autopower = false; -ab8500_power_loss_handling (di); +ab8500_enable_disable_sw_fallback (di, false); } else if (!di->autopower && (di->ac.charger_connected || di->usb.charger_connected)) { di->autopower = true; -ab8500_power_loss_handling (di); +ab8500_enable_disable_sw_fallback (di, true); } }power_supply_changed (psy);
Signature · 1 line
1.7.9.5
Re: [PATCH 01/18] power: ab8500_charger: Rename the power_loss function
Hi Anton,
Poke for the patch-set.
Quoted 79 lines · Lee Jones
From: Paer-Olof Haakansson <[email protected]>
Rename the
ab8500_power_loss_handlingfunction to a more descriptive nameab8500_enable_disable_sw_fallbackSigned-off-by Lee Jones <[email protected]>Signed-off-by Robert Marklund <[email protected]>Reviewed-by Par-Olof HAKANSSON <[email protected]>Reviewed-by Karl KOMIEROWSKI <[email protected]>Tested-by Par-Olof HAKANSSON <[email protected]>--- drivers/power/ab8500_charger.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)drivers/power/ab8500_charger.c +11
-12@@ -270,20 +270,19 @@ static enum power_supply_property ab8500_charger_usb_props[] = { POWER_SUPPLY_PROP_CURRENT_NOW, }; -/** -* ab8500_power_loss_handling - set how we handle powerloss. -* @di: pointer to the ab8500_charger structure -* -* Magic nummbers are from STE HW department. +/* +* Function for enabling and disabling sw fallback mode +* should always be disabled when no charger is connected. */ -static void ab8500_power_loss_handling (struct ab8500_charger *di) +static void ab8500_enable_disable_sw_fallback (struct ab8500_charger *di, +bool fallback) {u8 reg;int ret; -dev_dbg (di->dev,"Autopower : %d\n" , di->autopower); +dev_dbg (di->dev,"SW Fallback: %d\n" , fallback); -/* read the autopower register */ +/* read the register containing fallback bit */ ret =abx500_get_register_interruptible (di->dev,0x15 ,0x00 , ®);if (ret) {dev_err (di->dev,"%d write failed\n" , __LINE__);@@ -297,12 +296,12 @@ static void ab8500_power_loss_handling(struct ab8500_charger *di)return ; } -if (di->autopower) +if (fallback) reg |=0x8 ;else reg &= ~0x8 ; -/* write back the changed value to autopower reg */ +/* write back the changed fallback bit value to register */ ret =abx500_set_register_interruptible (di->dev,0x15 ,0x00 , reg);if (ret) {dev_err (di->dev,"%d write failed\n" , __LINE__);@@ -332,12 +331,12 @@ static void ab8500_power_supply_changed(struct ab8500_charger *di, !di->ac.charger_connected && di->autopower) { di->autopower = false; -ab8500_power_loss_handling (di); +ab8500_enable_disable_sw_fallback (di, false); } else if (!di->autopower && (di->ac.charger_connected || di->usb.charger_connected)) { di->autopower = true; -ab8500_power_loss_handling (di); +ab8500_enable_disable_sw_fallback (di, true); } }power_supply_changed (psy);Signature · 1 line
1.7.9.5
Signature · 4 lines
Lee Jones Linaro ST-Ericsson Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog
PATCH 2/18 power: ab8500_bm: Skip first CCEOC irq for instant current
In reply to Lee JonesFrom: Johan Bjornstedt <[email protected]>
When enabling the CCEOC irq we might get false interrupt from ab8500-driver due to the latched value will be saved and interpreted as an IRQ when enabled
--- drivers/power/ab8500_btemp.c | 11 +++--- drivers/power/ab8500_fg.c | 63 +++++++++++++++++++++++++++++----- include/linux/mfd/abx500/ab8500-bm.h | 7 ++++ 3 files changed, 66 insertions(+), 15 deletions(-)
drivers/power/ab8500_btemp.c +4 -7
@@ -374,13 +374,10 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di)return ret; } -/* -* Since there is no interrupt when current measurement is done, -* loop for over 250ms (250ms is one sample conversion time -* with 32.768 Khz RTC clock). Note that a stop time must be set -* since the ab8500_btemp_read_batctrl_voltage call can block and -* take an unknown amount of time to complete. -*/ +do { +msleep (20 ); + }while (!ab8500_fg_inst_curr_started (di->fg)); + i =0 ; do {
drivers/power/ab8500_fg.c +55 -8
178 lines not on this page · raw message
include/linux/mfd/abx500/ab8500-bm.h +7 -0
@@ -431,11 +431,18 @@ struct ab8500_fg *ab8500_fg_get(void);int ab8500_fg_inst_curr_blocking (struct ab8500_fg *dev);int ab8500_fg_inst_curr_start (struct ab8500_fg *di);int ab8500_fg_inst_curr_finalize (struct ab8500_fg *di,int *res); +int ab8500_fg_inst_curr_started (struct ab8500_fg *di);int ab8500_fg_inst_curr_done (struct ab8500_fg *di);#else +int ab8500_fg_inst_curr_started (struct ab8500_fg *di) +{ +return 0 ; +} +int ab8500_fg_inst_curr_done (struct ab8500_fg *di) { +return 0 ; }static void ab8500_fg_reinit (void ) {
Signature · 1 line
1.7.9.5
PATCH 3/18 power: ab8500_charger: Detect removed charger
In reply to Lee JonesFrom: Jonas Aaberg <[email protected]>
--- drivers/power/ab8500_charger.c | 145 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-)
drivers/power/ab8500_charger.c +144 -1
@@ -31,6 +31,7 @@#include <linux/mfd/abx500/ab8500-gpadc.h> #include <linux/mfd/abx500/ux500_chargalg.h> #include <linux/usb/otg.h> +#include <linux/mutex.h> /* Charger constants */ #define NO_PW_CONN 0
@@ -68,6 +69,11 @@#define MAIN_CH_NOK 0x01#define VBUS_DET 0x80 +#define MAIN_CH_STATUS2_MAINCHGDROP 0x80 +#define MAIN_CH_STATUS2_MAINCHARGERDETDBNC 0x40 +#define USB_CH_VBUSDROP 0x40 +#define USB_CH_VBUSDETDBNC 0x01 +/* UsbLineStatus register bit masks */ #define AB8500_USB_LINK_STATUS 0x78#define AB8500_STD_HOST_SUSP 0x18
@@ -82,6 +88,8 @@/* Step up/down delay in us */ #define STEP_UDELAY 1000 +#define CHARGER_STATUS_POLL 10/* in ms */ +/* UsbLineStatus register - usb types */ enum ab8500_charger_link_status {USB_STAT_NOT_CONFIGURED ,
@@ -203,6 +211,10 @@ struct ab8500_charger_usb_state {* @check_usbchgnotok_work: Work for checking USB charger not ok status * @kick_wd_work: Work for kicking the charger watchdog in case * of ABB rev 1.* due to the watchog logic bug +* @ac_charger_attached_work: Work for checking if AC charger is still +* connected +* @usb_charger_attached_work: Work for checking if USB charger is still +* connected * @ac_work: Work for checking AC charger connection * @detect_usb_type_work: Work for detecting the USB type connected * @usb_link_status_work: Work for checking the new USB link status
@@ -211,6 +223,7 @@ struct ab8500_charger_usb_state {* Work for checking Main thermal status * @check_usb_thermal_prot_work: * Work for checking USB thermal status +* @charger_attached_mutex: For controlling the wakelock */ struct ab8500_charger {struct device *dev;
@@ -239,6 +252,8 @@ struct ab8500_charger {struct delayed_work check_hw_failure_work;struct delayed_work check_usbchgnotok_work;struct delayed_work kick_wd_work; +struct delayed_work ac_charger_attached_work; +struct delayed_work usb_charger_attached_work;struct work_struct ac_work;struct work_struct detect_usb_type_work;struct work_struct usb_link_status_work;
@@ -247,6 +262,7 @@ struct ab8500_charger {struct work_struct check_usb_thermal_prot_work;struct usb_phy *usb_phy;struct notifier_block nb; +struct mutex charger_attached_mutex; };/* AC properties */
@@ -349,6 +365,19 @@ static void ab8500_charger_set_usb_connected(struct ab8500_charger *di,dev_dbg (di->dev,"USB connected:%i\n" , connected); di->usb.charger_connected = connected;sysfs_notify (&di->usb_chg.psy.dev->kobj,NULL ,"present" ); + +if (connected) { +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); + +queue_delayed_work (di->charger_wq, + &di->usb_charger_attached_work, +HZ ); + }else { +cancel_delayed_work_sync (&di->usb_charger_attached_work); +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); + } } }
@@ -1706,6 +1735,87 @@ static void ab8500_charger_ac_work(struct work_struct *work)sysfs_notify (&di->ac_chg.psy.dev->kobj,NULL ,"present" ); } +static void ab8500_charger_usb_attached_work (struct work_struct *work) +{ +int i; +int ret; +u8 statval; +struct ab8500_charger *di =container_of (work, + struct ab8500_charger, + usb_charger_attached_work.work); + +for (i =0 ; i <10 ; i++) { + ret =abx500_get_register_interruptible (di->dev, +AB8500_CHARGER , +AB8500_CH_USBCH_STAT1_REG , + &statval); +if (ret <0 ) { +dev_err (di->dev,"ab8500 read failed %d\n" , + __LINE__); + goto reschedule; + } +if ((statval & (USB_CH_VBUSDROP | +USB_CH_VBUSDETDBNC )) != + (USB_CH_VBUSDROP |USB_CH_VBUSDETDBNC )) + goto reschedule; + +msleep (CHARGER_STATUS_POLL ); + } + + (void )ab8500_charger_usb_en (&di->usb_chg,0 ,0 ,0 ); + +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); + +return ; +reschedule: +queue_delayed_work (di->charger_wq, + &di->usb_charger_attached_work, +HZ ); +} + +static void ab8500_charger_ac_attached_work (struct work_struct *work) +{ + +int i; +int ret; +u8 statval; +struct ab8500_charger *di =container_of (work, + struct ab8500_charger, + ac_charger_attached_work.work); + +for (i =0 ; i <10 ; i++) { + ret =abx500_get_register_interruptible (di->dev, +AB8500_CHARGER , +AB8500_CH_STATUS2_REG , + &statval); +if (ret <0 ) { +dev_err (di->dev,"ab8500 read failed %d\n" , + __LINE__); + goto reschedule; + } +if ((statval & (MAIN_CH_STATUS2_MAINCHGDROP | +MAIN_CH_STATUS2_MAINCHARGERDETDBNC )) != + (MAIN_CH_STATUS2_MAINCHGDROP | +MAIN_CH_STATUS2_MAINCHARGERDETDBNC )) + goto reschedule; + +msleep (CHARGER_STATUS_POLL ); + } + + (void )ab8500_charger_ac_en (&di->ac_chg,0 ,0 ,0 ); +queue_work (di->charger_wq, &di->ac_work); + +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); + +return ; +reschedule: +queue_delayed_work (di->charger_wq, + &di->ac_charger_attached_work, +HZ ); +} +/** * ab8500_charger_detect_usb_type_work() - work to detect USB type * @work: Pointer to the work_struct structure
@@ -1986,6 +2096,10 @@ static irqreturn_t ab8500_charger_mainchunplugdet_handler(int irq, void *_di)dev_dbg (di->dev,"Main charger unplugged\n" );queue_work (di->charger_wq, &di->ac_work); +cancel_delayed_work_sync (&di->ac_charger_attached_work); +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); +return IRQ_HANDLED ; }
@@ -2003,6 +2117,11 @@ static irqreturn_t ab8500_charger_mainchplugdet_handler(int irq, void *_di)dev_dbg (di->dev,"Main charger plugged\n" );queue_work (di->charger_wq, &di->ac_work); +mutex_lock (&di->charger_attached_mutex); +mutex_unlock (&di->charger_attached_mutex); +queue_delayed_work (di->charger_wq, + &di->ac_charger_attached_work, +HZ );return IRQ_HANDLED ; }
@@ -2637,7 +2756,7 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)struct device_node *np = pdev->dev.of_node;struct abx500_bm_data *plat = pdev->dev.platform_data;struct ab8500_charger *di; -int irq, i, charger_status, ret =0 ; +int irq, i, charger_status, ret =0 , ch_stat; di =devm_kzalloc (&pdev->dev,sizeof (*di),GFP_KERNEL );if (!di) {
@@ -2716,12 +2835,19 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)return -ENOMEM ; } +mutex_init (&di->charger_attached_mutex); +/* Init work for HW failure check */ INIT_DEFERRABLE_WORK (&di->check_hw_failure_work, ab8500_charger_check_hw_failure_work);INIT_DEFERRABLE_WORK (&di->check_usbchgnotok_work, ab8500_charger_check_usbchargernotok_work); +INIT_DELAYED_WORK (&di->ac_charger_attached_work, + ab8500_charger_ac_attached_work); +INIT_DELAYED_WORK (&di->usb_charger_attached_work, + ab8500_charger_usb_attached_work); +/* * For ABB revision 1.0 and 1.1 there is a bug in the watchdog * logic. That means we have to continously kick the charger
@@ -2835,6 +2961,23 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)platform_set_drvdata (pdev, di); +mutex_lock (&di->charger_attached_mutex); + + ch_stat =ab8500_charger_detect_chargers (di); + +if ((ch_stat &AC_PW_CONN ) ==AC_PW_CONN ) { +queue_delayed_work (di->charger_wq, + &di->ac_charger_attached_work, +HZ ); + } +if ((ch_stat &USB_PW_CONN ) ==USB_PW_CONN ) { +queue_delayed_work (di->charger_wq, + &di->usb_charger_attached_work, +HZ ); + } + +mutex_unlock (&di->charger_attached_mutex); +return ret; free_irq:
Signature · 1 line
1.7.9.5
PATCH 4/18 power: ab8500_fg: flush sync on suspend
In reply to Lee JonesFrom: Jonas Aaberg <[email protected]>
Do flush sync on the fg workqueue at suspend instead of just flushing it.
--- drivers/power/ab8500_fg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/ab8500_fg.c +1 -1
@@ -2436,7 +2436,7 @@ static int ab8500_fg_suspend(struct platform_device *pdev, {struct ab8500_fg *di =platform_get_drvdata (pdev); -flush_delayed_work (&di->fg_periodic_work); +flush_delayed_work_sync (&di->fg_periodic_work);/* * If the FG is enabled we will disable it before going to suspend
Signature · 1 line
1.7.9.5
PATCH 5/18 power: ab8500_fg: usleep_range instead of short msleep
In reply to Lee JonesFrom: Jonas Aaberg <[email protected]>
--- drivers/power/ab8500_fg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/ab8500_fg.c +1 -1
@@ -956,7 +956,7 @@ static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di)do { vbat +=ab8500_fg_bat_voltage (di); i++; -msleep (5 ); +usleep_range (5000 ,5001 ); }while (!ab8500_fg_inst_curr_done (di));ab8500_fg_inst_curr_finalize (di, &di->inst_curr);
Signature · 1 line
1.7.9.5
PATCH 6/18 power: ab8500_charger: Handle gpadc errors
In reply to Lee JonesFrom: Jonas Aaberg <[email protected]>
Gracefully handle gpadc conversion errors.
--- drivers/power/ab8500_charger.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/power/ab8500_charger.c +18 -4
@@ -160,6 +160,7 @@ struct ab8500_charger_info {int charger_voltage;int cv_active;bool wd_expired; +int charger_current; };struct ab8500_charger_event_flags {
@@ -2361,6 +2362,7 @@ static int ab8500_charger_ac_get_property(struct power_supply *psy, union power_supply_propval *val) {struct ab8500_charger *di; +int ret; di =to_ab8500_charger_ac_device_info (psy_to_ux500_charger (psy));
@@ -2382,7 +2384,10 @@ static int ab8500_charger_ac_get_property(struct power_supply *psy, val->intval = di->ac.charger_connected;break ;case POWER_SUPPLY_PROP_VOLTAGE_NOW : - di->ac.charger_voltage =ab8500_charger_get_ac_voltage (di); + ret =ab8500_charger_get_ac_voltage (di); +if (ret >=0 ) + di->ac.charger_voltage = ret; +/* On error, use previous value */ val->intval = di->ac.charger_voltage *1000 ;break ;case POWER_SUPPLY_PROP_VOLTAGE_AVG :
@@ -2394,7 +2399,10 @@ static int ab8500_charger_ac_get_property(struct power_supply *psy, val->intval = di->ac.cv_active;break ;case POWER_SUPPLY_PROP_CURRENT_NOW : - val->intval =ab8500_charger_get_ac_current (di) *1000 ; + ret =ab8500_charger_get_ac_current (di); +if (ret >=0 ) + di->ac.charger_current = ret; + val->intval = di->ac.charger_current *1000 ;break ;default :return -EINVAL ;
@@ -2421,6 +2429,7 @@ static int ab8500_charger_usb_get_property(struct power_supply *psy, union power_supply_propval *val) {struct ab8500_charger *di; +int ret; di =to_ab8500_charger_usb_device_info (psy_to_ux500_charger (psy));
@@ -2444,7 +2453,9 @@ static int ab8500_charger_usb_get_property(struct power_supply *psy, val->intval = di->usb.charger_connected;break ;case POWER_SUPPLY_PROP_VOLTAGE_NOW : - di->usb.charger_voltage =ab8500_charger_get_vbus_voltage (di); + ret =ab8500_charger_get_vbus_voltage (di); +if (ret >=0 ) + di->usb.charger_voltage = ret; val->intval = di->usb.charger_voltage *1000 ;break ;case POWER_SUPPLY_PROP_VOLTAGE_AVG :
@@ -2456,7 +2467,10 @@ static int ab8500_charger_usb_get_property(struct power_supply *psy, val->intval = di->usb.cv_active;break ;case POWER_SUPPLY_PROP_CURRENT_NOW : - val->intval =ab8500_charger_get_usb_current (di) *1000 ; + ret =ab8500_charger_get_usb_current (di); +if (ret >=0 ) + di->usb.charger_current = ret; + val->intval = di->usb.charger_current *1000 ;break ;case POWER_SUPPLY_PROP_CURRENT_AVG :/*
Signature · 1 line
1.7.9.5
PATCH 7/18 power: ab8500_bm: Recharge condition not optimal for battery
In reply to Lee JonesFrom: Marcus Cooper <[email protected]>
Today the battery recharge is determined with a voltage threshold. This voltage threshold is only valid when the battery is relaxed. In charging algorithm the voltage read is the loaded battery voltage and no compensation is done to get the relaxed voltage. When maintenance charging is not selected, this makes the recharging condition to almost immediately activate when there is a discharge present on the battery.
Depending on which vendor the battery comes from this behavior can wear out the battery much faster than normal.
The fuelgauge driver is responsible to monitor the actual battery capacity and is able to estimate the remaining capacity. It is better to use the remaining capacity as a limit to determine when battery should be recharged.
--- drivers/power/ab8500_bmdata.c | 18 +++-- drivers/power/ab8500_fg.c | 146 +++++++++++++++++++++++++++++++--- drivers/power/abx500_chargalg.c | 30 ++++--- include/linux/mfd/abx500.h | 6 +- include/linux/mfd/abx500/ab8500-bm.h | 2 + 5 files changed, 168 insertions(+), 34 deletions(-)
drivers/power/ab8500_bmdata.c +10 -8
@@ -192,7 +192,7 @@ static struct abx500_battery_type bat_type_thermistor[] = { .nominal_voltage = 3700, .termination_vol = 4050, .termination_curr = 200, - .recharge_vol = 3990, + .recharge_cap = 95, .normal_cur_lvl = 400, .normal_vol_lvl = 4100, .maint_a_cur_lvl = 400,
@@ -219,7 +219,7 @@ static struct abx500_battery_type bat_type_thermistor[] = { .nominal_voltage = 3600, .termination_vol = 4150, .termination_curr = 80, - .recharge_vol = 4130, + .recharge_cap = 95, .normal_cur_lvl = 700, .normal_vol_lvl = 4200, .maint_a_cur_lvl = 600,
@@ -247,7 +247,7 @@ static struct abx500_battery_type bat_type_thermistor[] = { .nominal_voltage = 3600, .termination_vol = 4150, .termination_curr = 80, - .recharge_vol = 4130, + .recharge_cap = 95, .normal_cur_lvl = 700, .normal_vol_lvl = 4200, .maint_a_cur_lvl = 600,
@@ -278,7 +278,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { .nominal_voltage = 3700, .termination_vol = 4050, .termination_curr = 200, - .recharge_vol = 3990, + .recharge_cap = 95, .normal_cur_lvl = 400, .normal_vol_lvl = 4100, .maint_a_cur_lvl = 400,
@@ -310,7 +310,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { .nominal_voltage = 3700, .termination_vol = 4150, .termination_curr = 100, - .recharge_vol = 4130, + .recharge_cap = 95, .normal_cur_lvl = 700, .normal_vol_lvl = 4200, .maint_a_cur_lvl = 600,
@@ -337,7 +337,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { .nominal_voltage = 3700, .termination_vol = 4150, .termination_curr = 100, - .recharge_vol = 4130, + .recharge_cap = 95, .normal_cur_lvl = 700, .normal_vol_lvl = 4200, .maint_a_cur_lvl = 600,
@@ -364,7 +364,7 @@ static struct abx500_battery_type bat_type_ext_thermistor[] = { .nominal_voltage = 3700, .termination_vol = 4150, .termination_curr = 100, - .recharge_vol = 4130, + .recharge_cap = 95, .normal_cur_lvl = 700, .normal_vol_lvl = 4200, .maint_a_cur_lvl = 600,
@@ -405,6 +405,7 @@ static const struct abx500_fg_parameters fg = { .lowbat_threshold = 3100, .battok_falling_th_sel0 = 2860, .battok_raising_th_sel1 = 2860, + .maint_thres = 95, .user_cap_limit = 15, .maint_thres = 97, };
@@ -435,6 +436,7 @@ struct abx500_bm_data ab8500_bm_data = { .bkup_bat_v = BUP_VCH_SEL_2P6V, .bkup_bat_i = BUP_ICH_SEL_150UA, .no_maintenance = false, + .capacity_scaling = false, .adc_therm = ABx500_ADC_THERM_BATCTRL, .chg_unknown_bat = false, .enable_overshoot = false,
@@ -479,7 +481,7 @@ int __devinit ab8500_bm_of_probe(struct device *dev, bm->chg_unknown_bat = true; bm->bat_type[BATTERY_UNKNOWN ].charge_full_design =2600 ; bm->bat_type[BATTERY_UNKNOWN ].termination_vol =4150 ; - bm->bat_type[BATTERY_UNKNOWN ].recharge_vol =4130 ; + bm->bat_type[BATTERY_UNKNOWN ].recharge_cap =95 ; bm->bat_type[BATTERY_UNKNOWN ].normal_cur_lvl =520 ; bm->bat_type[BATTERY_UNKNOWN ].normal_vol_lvl =4200 ; }
drivers/power/ab8500_fg.c +135 -11
213 lines not on this page · raw message
drivers/power/abx500_chargalg.c +17 -13
@@ -33,9 +33,6 @@/* End-of-charge criteria counter */ #define EOC_COND_CNT 10 -/* Recharge criteria counter */ -#define RCH_COND_CNT 3 -#define to_abx500_chargalg_device_info (x) container_of((x), \ struct abx500_chargalg, chargalg_psy);
@@ -196,7 +193,6 @@ enum maxim_ret {* @dev: pointer to the structure device * @charge_status: battery operating status * @eoc_cnt: counter used to determine end-of_charge -* @rch_cnt: counter used to determine start of recharge * @maintenance_chg: indicate if maintenance charge is active * @t_hyst_norm temperature hysteresis when the temperature has been * over or under normal limits
@@ -223,7 +219,6 @@ struct abx500_chargalg {struct device *dev;int charge_status;int eoc_cnt; -int rch_cnt;bool maintenance_chg;int t_hyst_norm;int t_hyst_lowhigh;
@@ -858,6 +853,7 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)union power_supply_propval ret;int i, j;bool psy_found = false; +bool capacity_updated = false; psy = (struct power_supply *)data; ext =dev_get_drvdata (dev);
@@ -870,6 +866,16 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data)if (!psy_found)return 0 ; +/* +* If external is not registering 'POWER_SUPPLY_PROP_CAPACITY' to its +* property because of handling that sysfs entry on its own, this is +* the place to get the battery capacity. +*/ +if (!ext->get_property (ext,POWER_SUPPLY_PROP_CAPACITY , &ret)) { + di->batt_data.percent = ret.intval; + capacity_updated = true; + } +/* Go through all properties for the psy */ for (j =0 ; j < ext->num_properties; j++) {enum power_supply_property prop;
@@ -1154,7 +1160,8 @@ static int abx500_chargalg_get_ext_psy_data(struct device *dev, void *data) }break ;case POWER_SUPPLY_PROP_CAPACITY : - di->batt_data.percent = ret.intval; +if (!capacity_updated) + di->batt_data.percent = ret.intval;break ;default :break ;
@@ -1424,16 +1431,13 @@ static void abx500_chargalg_algorithm(struct abx500_chargalg *di)case STATE_WAIT_FOR_RECHARGE_INIT :abx500_chargalg_hold_charging (di);abx500_chargalg_state_to (di,STATE_WAIT_FOR_RECHARGE ); - di->rch_cnt =RCH_COND_CNT ;/* Intentional fallthrough */ case STATE_WAIT_FOR_RECHARGE : -if (di->batt_data.volt <= - di->bm->bat_type[di->bm->batt_id].recharge_vol) { -if (di->rch_cnt-- ==0 ) -abx500_chargalg_state_to (di,STATE_NORMAL_INIT ); - }else - di->rch_cnt =RCH_COND_CNT ; +if (di->batt_data.percent <= + di->bm->bat_type[di->bm->batt_id]. + recharge_cap) +abx500_chargalg_state_to (di,STATE_NORMAL_INIT );break ;case STATE_MAINTENANCE_A_INIT :
include/linux/mfd/abx500.h +4 -2
@@ -131,7 +131,7 @@ struct abx500_maxim_parameters {* @nominal_voltage: Nominal voltage of the battery in mV * @termination_vol: max voltage upto which battery can be charged * @termination_curr battery charging termination current in mA -* @recharge_vol battery voltage limit that will trigger a new +* @recharge_cap battery capacity limit that will trigger a new * full charging cycle in the case where maintenan- * -ce charging has been disabled * @normal_cur_lvl: charger current in normal state in mA
@@ -160,7 +160,7 @@ struct abx500_battery_type {int nominal_voltage;int termination_vol;int termination_curr; -int recharge_vol; +int recharge_cap;int normal_cur_lvl;int normal_vol_lvl;int maint_a_cur_lvl;
@@ -224,6 +224,7 @@ struct abx500_bm_charger_parameters {* @bkup_bat_v voltage which we charge the backup battery with * @bkup_bat_i current which we charge the backup battery with * @no_maintenance indicates that maintenance charging is disabled +* @capacity_scaling indicates whether capacity scaling is to be used * @abx500_adc_therm placement of thermistor, batctrl or battemp adc * @chg_unknown_bat flag to enable charging of unknown batteries * @enable_overshoot flag to enable VBAT overshoot control
@@ -254,6 +255,7 @@ struct abx500_bm_data {int bkup_bat_v;int bkup_bat_i;bool no_maintenance; +bool capacity_scaling;bool chg_unknown_bat;bool enable_overshoot;bool auto_trig;
include/linux/mfd/abx500/ab8500-bm.h +2 -0
@@ -355,6 +355,7 @@ struct ab8500_bm_charger_parameters {* @bkup_bat_v voltage which we charge the backup battery with * @bkup_bat_i current which we charge the backup battery with * @no_maintenance indicates that maintenance charging is disabled +* @capacity_scaling indicates whether capacity scaling is to be used * @adc_therm placement of thermistor, batctrl or battemp adc * @chg_unknown_bat flag to enable charging of unknown batteries * @enable_overshoot flag to enable VBAT overshoot control
@@ -383,6 +384,7 @@ struct ab8500_bm_data {int bkup_bat_v;int bkup_bat_i;bool no_maintenance; +bool capacity_scaling;bool chg_unknown_bat;bool enable_overshoot;enum abx500_adc_therm adc_therm;
Signature · 1 line
1.7.9.5
PATCH 8/18 power: ab8500_fg: balance IRQ enable
In reply to Lee JonesFrom: Rickard Andersson <[email protected]>
In case of time out error IRQ needs to be disabled otherwise we will get unbalanced enable/disable pairs.
--- drivers/power/ab8500_fg.c | 1 + 1 file changed, 1 insertion(+)
drivers/power/ab8500_fg.c +1 -0
@@ -745,6 +745,7 @@ int ab8500_fg_inst_curr_blocking(struct ab8500_fg *di)dev_dbg (di->dev,"%s instant current: %d" , __func__, res);return res; fail: +disable_irq (di->irq);mutex_unlock (&di->cc_lock);return ret; }
Signature · 1 line
1.7.9.5
PATCH 9/18 power: ab8500_btemp: Ignore false btemp low interrupt
In reply to Lee JonesFrom: Hakan Berg <[email protected]>
Ignore the low btemp interrupts for ab8500 3.0 and 3.3
--- drivers/power/ab8500_btemp.c | 20 ++++++++++---------- include/linux/mfd/abx500/ab8500.h | 5 +++++ 2 files changed, 15 insertions(+), 10 deletions(-)
drivers/power/ab8500_btemp.c +10 -10
@@ -622,9 +622,9 @@ static irqreturn_t ab8500_btemp_templow_handler(int irq, void *_di) {struct ab8500_btemp *di = _di; -if (is_ab8500_2p0_or_earlier (di->parent)) { +if (is_ab8500_3p3_or_earlier (di->parent)) {dev_dbg (di->dev,"Ignore false btemp low irq" -" for ABB cut 1.0, 1.1 and 2.0\n" ); +" for ABB cut 1.0, 1.1, 2.0 and 3.3\n" ); }else {dev_crit (di->dev,"Battery temperature lower than -10deg c\n" );
@@ -738,30 +738,30 @@ static int ab8500_btemp_get_temp(struct ab8500_btemp *di)int temp =0 ;/* -* The BTEMP events are not reliabe on AB8500 cut2.0 +* The BTEMP events are not reliabe on AB8500 cut3.3 * and prior versions */ -if (is_ab8500_2p0_or_earlier (di->parent)) { +if (is_ab8500_3p3_or_earlier (di->parent)) { temp = di->bat_temp *10 ; }else {if (di->events.btemp_low) {if (temp > di->btemp_ranges.btemp_low_limit) - temp = di->btemp_ranges.btemp_low_limit; + temp = di->btemp_ranges.btemp_low_limit *10 ;else temp = di->bat_temp *10 ; }else if (di->events.btemp_high) {if (temp < di->btemp_ranges.btemp_high_limit) - temp = di->btemp_ranges.btemp_high_limit; + temp = di->btemp_ranges.btemp_high_limit *10 ;else temp = di->bat_temp *10 ; }else if (di->events.btemp_lowmed) {if (temp > di->btemp_ranges.btemp_med_limit) - temp = di->btemp_ranges.btemp_med_limit; + temp = di->btemp_ranges.btemp_med_limit *10 ;else temp = di->bat_temp *10 ; }else if (di->events.btemp_medhigh) {if (temp < di->btemp_ranges.btemp_med_limit) - temp = di->btemp_ranges.btemp_med_limit; + temp = di->btemp_ranges.btemp_med_limit *10 ;else temp = di->bat_temp *10 ; }else
@@ -1030,8 +1030,8 @@ static int __devinit ab8500_btemp_probe(struct platform_device *pdev) ab8500_btemp_periodic_work);/* Set BTEMP thermal limits. Low and Med are fixed */ - di->btemp_ranges.btemp_low_limit =BTEMP_THERMAL_LOW_LIMIT ; - di->btemp_ranges.btemp_med_limit =BTEMP_THERMAL_MED_LIMIT ; + di->btemp_ranges.btemp_low_limit =BTEMP_THERMAL_LOW_LIMIT *10 ; + di->btemp_ranges.btemp_med_limit =BTEMP_THERMAL_MED_LIMIT *10 ; ret =abx500_get_register_interruptible (di->dev,AB8500_CHARGER ,AB8500_BTEMP_HIGH_TH , &val);
include/linux/mfd/abx500/ab8500.h +5 -0
@@ -335,6 +335,11 @@ static inline int is_ab8500_2p0_or_earlier(struct ab8500 *ab)return (is_ab8500 (ab) && (ab->chip_id <=AB8500_CUT2P0 )); } +static inline int is_ab8500_3p3_or_earlier (struct ab8500 *ab) +{ +return (is_ab8500 (ab) && (ab->chip_id <=AB8500_CUT3P3 )); +} +/* exclude also ab8505, ab9540... */ static inline int is_ab8500_2p0 (struct ab8500 *ab) {
Signature · 1 line
1.7.9.5
PATCH 10/18 power: ab8500_bm: Adds support for Car/Travel Adapters
In reply to Lee JonesFrom: Hakan Berg <[email protected]>
The Travel and Carkit adapter should be handled directly by the charger driver.
--- drivers/power/ab8500_charger.c | 92 +++++++++++++++++++++++++--------- include/linux/mfd/abx500/ab8500-bm.h | 1 + 2 files changed, 69 insertions(+), 24 deletions(-)
drivers/power/ab8500_charger.c +68 -24
@@ -108,6 +108,18 @@ enum ab8500_charger_link_status {USB_STAT_HM_IDGND ,USB_STAT_RESERVED ,USB_STAT_NOT_VALID_LINK , +USB_STAT_PHY_EN , +USB_STAT_SUP_NO_IDGND_VBUS , +USB_STAT_SUP_IDGND_VBUS , +USB_STAT_CHARGER_LINE_1 , +USB_STAT_CARKIT_1 , +USB_STAT_CARKIT_2 , +USB_STAT_ACA_DOCK_CHARGER , +USB_STAT_SAMSUNG_USB_PHY_DIS , +USB_STAT_SAMSUNG_USB_PHY_ENA , +USB_STAT_SAMSUNG_UART_PHY_DIS , +USB_STAT_SAMSUNG_UART_PHY_ENA , + USB_STAT_MOTOROLA_USB_PHY_ENA, }; enum ab8500_usb_state {
@@ -586,7 +598,7 @@ static int ab8500_charger_detect_chargers(struct ab8500_charger *di)* Returns error code in case of failure else 0 on success */ static int ab8500_charger_max_usb_curr (struct ab8500_charger *di, -enum ab8500_charger_link_status link_status) +enum ab8500_charger_link_status link_status) {int ret =0 ;
@@ -595,15 +607,19 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,case USB_STAT_STD_HOST_C_NS :case USB_STAT_STD_HOST_C_S :dev_dbg (di->dev,"USB Type - Standard host is " -"detected through USB driver\n" ); +"detected through USB driver\n" ); di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P09 ;break ;case USB_STAT_HOST_CHG_HS_CHIRP : di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P5 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr);break ;case USB_STAT_HOST_CHG_HS :case USB_STAT_ACA_RID_C_HS : di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P9 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr);break ;case USB_STAT_ACA_RID_A :/*
@@ -611,6 +627,8 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,* can consume (300mA). Closest level is 1100mA */ di->max_usb_in_curr =USB_CH_IP_CUR_LVL_1P1 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr);break ;case USB_STAT_ACA_RID_B :/*
@@ -618,34 +636,50 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,* 100mA for potential accessory). Closest level is 1300mA */ di->max_usb_in_curr =USB_CH_IP_CUR_LVL_1P3 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr);break ; -case USB_STAT_DEDICATED_CHG :case USB_STAT_HOST_CHG_NM : -case USB_STAT_ACA_RID_C_HS_CHIRP : +case USB_STAT_DEDICATED_CHG :case USB_STAT_ACA_RID_C_NM : +case USB_STAT_ACA_RID_C_HS_CHIRP : di->max_usb_in_curr =USB_CH_IP_CUR_LVL_1P5 ; -break ; -case USB_STAT_RESERVED : -/* -* This state is used to indicate that VBUS has dropped below -* the detection level 4 times in a row. This is due to the -* charger output current is set to high making the charger -* voltage collapse. This have to be propagated through to -* chargalg. This is done using the property -* POWER_SUPPLY_PROP_CURRENT_AVG = 1 -*/ - di->flags.vbus_collapse = true; -dev_dbg (di->dev,"USB Type - USB_STAT_RESERVED " -"VBUS has collapsed\n" ); - ret =-1 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr);break ;case USB_STAT_HM_IDGND : -case USB_STAT_NOT_CONFIGURED :case USB_STAT_NOT_VALID_LINK : +case USB_STAT_NOT_CONFIGURED :dev_err (di->dev,"USB Type - Charging not allowed\n" ); di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P05 ; ret = -ENXIO ;break ; +case USB_STAT_RESERVED : +if (is_ab8500 (di->parent)) { + di->flags.vbus_collapse = true; +dev_err (di->dev,"USB Type - USB_STAT_RESERVED " +"VBUS has collapsed\n" ); + ret = -ENXIO ; +break ; + } +if (is_ab9540 (di->parent) ||is_ab8505 (di->parent)) { +dev_dbg (di->dev,"USB Type - Charging not allowed\n" ); + di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P05 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , + link_status, di->max_usb_in_curr); + ret = -ENXIO ; +break ; + } +break ; +case USB_STAT_CARKIT_1 : +case USB_STAT_CARKIT_2 : +case USB_STAT_ACA_DOCK_CHARGER : +case USB_STAT_CHARGER_LINE_1 : + di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P5 ; +dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, + di->max_usb_in_curr); +break ; +default :dev_err (di->dev,"USB Type - Unknown\n" ); di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P05 ;
@@ -677,8 +711,14 @@ static int ab8500_charger_read_usb_type(struct ab8500_charger *di)dev_err (di->dev,"%s ab8500 read failed\n" , __func__);return ret; } - ret =abx500_get_register_interruptible (di->dev,AB8500_USB , -AB8500_USB_LINE_STAT_REG , &val); +if (is_ab8500 (di->parent)) { + ret =abx500_get_register_interruptible (di->dev,AB8500_USB , +AB8500_USB_LINE_STAT_REG , &val); + }else { +if (is_ab9540 (di->parent) ||is_ab8505 (di->parent)) + ret =abx500_get_register_interruptible (di->dev, +AB8500_USB ,AB8500_USB_LINK1_STAT_REG , &val); + }if (ret <0 ) {dev_err (di->dev,"%s ab8500 read failed\n" , __func__);return ret;
@@ -718,8 +758,13 @@ static int ab8500_charger_detect_usb_type(struct ab8500_charger *di)dev_err (di->dev,"%s ab8500 read failed\n" , __func__);return ret; } - ret =abx500_get_register_interruptible (di->dev,AB8500_USB , -AB8500_USB_LINE_STAT_REG , &val); + +if (is_ab8500 (di->parent)) + ret =abx500_get_register_interruptible (di->dev, +AB8500_USB ,AB8500_USB_LINE_STAT_REG , &val); +else + ret =abx500_get_register_interruptible (di->dev, +AB8500_USB ,AB8500_USB_LINK1_STAT_REG , &val);if (ret <0 ) {dev_err (di->dev,"%s ab8500 read failed\n" , __func__);return ret;
@@ -2950,7 +2995,6 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev) }if (charger_status &USB_PW_CONN ) { -dev_dbg (di->dev,"VBUS Detect during startup\n" ); di->vbus_detected = true; di->vbus_detected_start = true; queue_work(di->charger_wq,
include/linux/mfd/abx500/ab8500-bm.h +1 -0
@@ -23,6 +23,7 @@* Bank : 0x5 */ #define AB8500_USB_LINE_STAT_REG 0x80 +#define AB8500_USB_LINK1_STAT_REG 0x94/* * Charger / status register offfsets
Signature · 1 line
1.7.9.5
PATCH 11/18 power: ab8500_fg: Round capacity output
In reply to Lee JonesFrom: pender01 <[email protected]>
Round the capacity values for better enduser experience.
--- drivers/power/ab8500_fg.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/power/ab8500_fg.c +15 -13
@@ -32,6 +32,7 @@#include <linux/mfd/abx500/ab8500.h> #include <linux/mfd/abx500/ab8500-bm.h> #include <linux/mfd/abx500/ab8500-gpadc.h> +#include <linux/kernel.h> #define MILLI_TO_MICRO 1000#define FG_LSB_IN_MA 1627
@@ -1158,7 +1159,7 @@ static int ab8500_fg_capacity_level(struct ab8500_fg *di) {int ret, percent; - percent = di->bat_cap.permille /10 ; + percent =DIV_ROUND_CLOSEST (di->bat_cap.permille,10 );if (percent <= di->bm->cap_levels->critical || di->flags.low_bat)
@@ -1279,6 +1280,7 @@ static void ab8500_fg_update_cap_scalers(struct ab8500_fg *di)static void ab8500_fg_check_capacity_limits (struct ab8500_fg *di,bool init) {bool changed = false; +int percent =DIV_ROUND_CLOSEST (di->bat_cap.permille,10 ); di->bat_cap.level =ab8500_fg_capacity_level (di);
@@ -1310,6 +1312,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)dev_dbg (di->dev,"Battery low, set capacity to 0\n" ); di->bat_cap.prev_percent =0 ; di->bat_cap.permille =0 ; + percent =0 ; di->bat_cap.prev_mah =0 ; di->bat_cap.mah =0 ; changed = true;
@@ -1319,7 +1322,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)* and show 100% during maintenance charging (scaling). */ if (di->flags.force_full) { - di->bat_cap.prev_percent = di->bat_cap.permille /10 ; + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true;
@@ -1332,19 +1335,18 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) di->bat_cap.prev_percent; di->bat_cap.cap_scale.disable_cap_level =100 ; } - }else if ( di->bat_cap.prev_percent != - (di->bat_cap.permille) /10 ) { + }else if (di->bat_cap.prev_percent != percent) {dev_dbg (di->dev,"battery reported full " "but capacity dropping: %d\n" , - di->bat_cap.permille /10 ); - di->bat_cap.prev_percent = di->bat_cap.permille /10 ; + percent); + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true; } - }else if (di->bat_cap.prev_percent != di->bat_cap.permille /10 ) { -if (di->bat_cap.permille /10 ==0 ) { + }else if (di->bat_cap.prev_percent != percent) { +if (percent ==0 ) {/* * We will not report 0% unless we've got * the LOW_BAT IRQ, no matter what the FG
@@ -1354,11 +1356,11 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) di->bat_cap.permille =1 ; di->bat_cap.prev_mah =1 ; di->bat_cap.mah =1 ; + percent =1 ; changed = true; }else if (!(!di->flags.charging && - (di->bat_cap.permille /10 ) > - di->bat_cap.prev_percent) || init) { + percent > di->bat_cap.prev_percent) || init) {/* * We do not allow reported capacity to go up * unless we're charging or if we're in init
@@ -1366,9 +1368,9 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)dev_dbg (di->dev,"capacity changed from %d to %d (%d)\n" , di->bat_cap.prev_percent, - di->bat_cap.permille /10 , + percent, di->bat_cap.permille); - di->bat_cap.prev_percent = di->bat_cap.permille /10 ; + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true;
@@ -1376,7 +1378,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)dev_dbg (di->dev,"capacity not allowed to go up since " "no charger is connected: %d to %d (%d)\n" , di->bat_cap.prev_percent, - di->bat_cap.permille /10 , + percent, di->bat_cap.permille); } }
Signature · 1 line
1.7.9.5
PATCH 12/18 power: ab8500_btemp: remove superfluous BTEMP thermal comp.
In reply to Lee JonesFrom: Hakan Berg <[email protected]>
BTEMP thermal compensation factor times 10 is applied in two places, probe and get_property. Removed from probe.
--- drivers/power/ab8500_btemp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/ab8500_btemp.c +2 -2
@@ -1030,8 +1030,8 @@ static int __devinit ab8500_btemp_probe(struct platform_device *pdev) ab8500_btemp_periodic_work);/* Set BTEMP thermal limits. Low and Med are fixed */ - di->btemp_ranges.btemp_low_limit =BTEMP_THERMAL_LOW_LIMIT *10 ; - di->btemp_ranges.btemp_med_limit =BTEMP_THERMAL_MED_LIMIT *10 ; + di->btemp_ranges.btemp_low_limit =BTEMP_THERMAL_LOW_LIMIT ; + di->btemp_ranges.btemp_med_limit =BTEMP_THERMAL_MED_LIMIT ; ret =abx500_get_register_interruptible (di->dev,AB8500_CHARGER ,AB8500_BTEMP_HIGH_TH , &val);
Signature · 1 line
1.7.9.5
PATCH 13/18 power: ab8500_fg: Added support for BATT_OVV
In reply to Lee JonesFrom: Hakan Berg <[email protected]>
Add support for the battery over-voltage situation
--- drivers/power/ab8500_fg.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
drivers/power/ab8500_fg.c +16 -16
@@ -1840,24 +1840,26 @@ static void ab8500_fg_check_hw_failure_work(struct work_struct *work)* If we have had a battery over-voltage situation, * check ovv-bit to see if it should be reset. */ -if (di->flags.bat_ovv) { - ret =abx500_get_register_interruptible (di->dev, -AB8500_CHARGER ,AB8500_CH_STAT_REG , - ®_value); -if (ret <0 ) { -dev_err (di->dev,"%s ab8500 read failed\n" , __func__); -return ; - } -if ((reg_value &BATT_OVV ) !=BATT_OVV ) { -dev_dbg (di->dev,"Battery recovered from OVV\n" ); - di->flags.bat_ovv = false; + ret =abx500_get_register_interruptible (di->dev, +AB8500_CHARGER ,AB8500_CH_STAT_REG , + ®_value); +if (ret <0 ) { +dev_err (di->dev,"%s ab8500 read failed\n" , __func__); +return ; + } +if ((reg_value &BATT_OVV ) ==BATT_OVV ) { +if (!di->flags.bat_ovv) { +dev_dbg (di->dev,"Battery OVV\n" ); + di->flags.bat_ovv = true;power_supply_changed (&di->fg_psy); -return ; } -/* Not yet recovered from ovv, reschedule this test */ queue_delayed_work (di->fg_wq, &di->fg_check_hw_failure_work, -round_jiffies (HZ )); +HZ ); + }else { +dev_dbg (di->dev,"Battery recovered from OVV\n" ); + di->flags.bat_ovv = false; +power_supply_changed (&di->fg_psy); } }
@@ -2037,8 +2039,6 @@ static irqreturn_t ab8500_fg_batt_ovv_handler(int irq, void *_di)struct ab8500_fg *di = _di;dev_dbg (di->dev,"Battery OVV\n" ); - di->flags.bat_ovv = true; -power_supply_changed (&di->fg_psy);/* Schedule a new HW failure check */ queue_delayed_work (di->fg_wq, &di->fg_check_hw_failure_work,0 );
Signature · 1 line
1.7.9.5
PATCH 14/18 power: pm2301: Add pm2301 charger
In reply to Lee JonesFrom: Michel JAOUEN <[email protected]>
PM2301 AC charger driver based on 9540 platform.
--- drivers/power/Kconfig | 15 + drivers/power/Makefile | 1 + drivers/power/ab8500_charger.c | 8 +- drivers/power/pm2301_charger.c | 1599 ++++++++++++++++++++++++++++++++++++++++ include/linux/pm2301_charger.h | 60 ++ 5 files changed, 1681 insertions(+), 2 deletions(-) create mode 100644 drivers/power/pm2301_charger.c create mode 100644 include/linux/pm2301_charger.h
drivers/power/Kconfig +15 -0
@@ -346,6 +346,21 @@ config AB8500_BM help Say Y to include support for AB8500 battery management. +config CHARGER_PM2301 + bool "PM2301 Battery Charger Driver" + depends on AB8500_BM + help + Say Y to include support for PM2301 charger driver. + +config PM2XXX_DEEP_DEBUG + bool "PM2XXX Deep Debug" + depends on DEEP_DEBUG && CHARGER_PM2301 + default n + help + Deep Debug interface provides an access to all registers. + It allows to read or write directly a register. + Say Y to include support for Deep Debug. + If unsure, say N. endif # POWER_SUPPLY source "drivers/power/avs/Kconfig"
drivers/power/Makefile +1 -0
@@ -46,6 +46,7 @@ obj-$(CONFIG_CHARGER_LP8727) += lp8727_charger.o obj-$(CONFIG_CHARGER_LP8788) += lp8788-charger.o obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o +obj-$(CONFIG_CHARGER_PM2301) += pm2301_charger.o obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o obj-$(CONFIG_CHARGER_BQ2415X) += bq2415x_charger.o
drivers/power/ab8500_charger.c +6 -2
@@ -2798,7 +2798,9 @@ static int __devexit ab8500_charger_remove(struct platform_device *pdev)flush_scheduled_work ();power_supply_unregister (&di->usb_chg.psy); +#if !defined(CONFIG_CHARGER_PM2301 )power_supply_unregister (&di->ac_chg.psy); +#endif platform_set_drvdata (pdev,NULL );return 0 ;
@@ -2957,14 +2959,14 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)dev_err (di->dev,"failed to initialize ABB registers\n" ); goto free_regulator; } - +#if !defined(CONFIG_CHARGER_PM2301 )/* Register AC charger class */ ret =power_supply_register (di->dev, &di->ac_chg.psy);if (ret) {dev_err (di->dev,"failed to register AC charger\n" ); goto free_regulator; } - +#endif /* Register USB charger class */ ret =power_supply_register (di->dev, &di->usb_chg.psy);if (ret) {
@@ -3051,7 +3053,9 @@ put_usb_phy: free_usb:power_supply_unregister (&di->usb_chg.psy); free_ac: +#if !defined(CONFIG_CHARGER_PM2301 )power_supply_unregister (&di->ac_chg.psy); +#endif free_regulator:regulator_put (di->regu); free_charger_wq:
drivers/power/pm2301_charger.c new file +1599 -0
1,599 lines not on this page · raw message
include/linux/pm2301_charger.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 15/18 power: ab8500_fg: Add sysfs interfaces for capacity
In reply to Lee JonesFrom: Daniel WILLERUD <[email protected]>
Switchable depending on whether capacity scaling is enabled
--- drivers/power/ab8500_fg.c | 57 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-)
drivers/power/ab8500_fg.c +56 -1
@@ -265,7 +265,6 @@ static enum power_supply_property ab8500_fg_props[] = {POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN ,POWER_SUPPLY_PROP_CHARGE_FULL ,POWER_SUPPLY_PROP_CHARGE_NOW , -POWER_SUPPLY_PROP_CAPACITY , POWER_SUPPLY_PROP_CAPACITY_LEVEL, };
@@ -2539,6 +2538,54 @@ static int ab8500_fg_sysfs_init(struct ab8500_fg *di)return ret; } + +static ssize_t ab8500_show_capacity (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct power_supply *psy =dev_get_drvdata (dev); +struct ab8500_fg *di; +int capacity; + + di =to_ab8500_fg_device_info (psy); + +if (di->bm->capacity_scaling) + capacity = di->bat_cap.cap_scale.scaled_cap; +else + capacity =DIV_ROUND_CLOSEST (di->bat_cap.permille,10 ); + +return scnprintf (buf,PAGE_SIZE ,"%d\n" , capacity); +} + +static struct device_attribute ab8500_fg_sysfs_psy_attrs[] = { +__ATTR (capacity,S_IRUGO , ab8500_show_capacity,NULL ), +}; + +static int ab8500_fg_sysfs_psy_create_attrs (struct device *dev) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ab8500_fg_sysfs_psy_attrs); i++) +if (device_create_file (dev, &ab8500_fg_sysfs_psy_attrs[i])) + goto sysfs_psy_create_attrs_failed; + +return 0 ; + +sysfs_psy_create_attrs_failed: +dev_err (dev,"Failed creating sysfs psy attrs.\n" ); +while (i--) +device_remove_file (dev, &ab8500_fg_sysfs_psy_attrs[i]); + +return -EIO ; +} + +static void ab8500_fg_sysfs_psy_remove_attrs (struct device *dev) +{ +unsigned int i; + +for (i =0 ; i <ARRAY_SIZE (ab8500_fg_sysfs_psy_attrs); i++) + (void )device_remove_file (dev, &ab8500_fg_sysfs_psy_attrs[i]); +}/* Exposure to the sysfs interface <<END>> */ #if defined(CONFIG_PM )
@@ -2595,6 +2642,7 @@ static int __devexit ab8500_fg_remove(struct platform_device *pdev)ab8500_fg_sysfs_exit (di);flush_scheduled_work (); +ab8500_fg_sysfs_psy_remove_attrs (di->fg_psy.dev);power_supply_unregister (&di->fg_psy);platform_set_drvdata (pdev,NULL );return ret;
@@ -2754,6 +2802,13 @@ static int __devinit ab8500_fg_probe(struct platform_device *pdev) goto free_irq; } + ret =ab8500_fg_sysfs_psy_create_attrs (di->fg_psy.dev); +if (ret) { +dev_err (di->dev,"failed to create FG psy\n" ); +ab8500_fg_sysfs_exit (di); + goto free_irq; + } +/* Calibrate the fg first time */ di->flags.calibrate = true; di->calib_state =AB8500_FG_CALIB_INIT ;
Signature · 1 line
1.7.9.5
PATCH 16/18 power: ab8500_charger: remove unused defines.
In reply to Lee JonesFrom: Marcus Cooper <[email protected]>
Cleanup of the ab8500_charger driver.
--- drivers/power/ab8500_charger.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/power/ab8500_charger.c +0 -5
@@ -115,11 +115,6 @@ enum ab8500_charger_link_status {USB_STAT_CARKIT_1 ,USB_STAT_CARKIT_2 , USB_STAT_ACA_DOCK_CHARGER, -USB_STAT_SAMSUNG_USB_PHY_DIS , -USB_STAT_SAMSUNG_USB_PHY_ENA , -USB_STAT_SAMSUNG_UART_PHY_DIS , -USB_STAT_SAMSUNG_UART_PHY_ENA , - USB_STAT_MOTOROLA_USB_PHY_ENA, }; enum ab8500_usb_state {
Signature · 1 line
1.7.9.5
PATCH 17/18 power: ab8500_charger: Adds support for legacy USB chargers
In reply to Lee JonesFrom: Marcus Cooper <[email protected]>
A Legacy USB charger should be handled directly by the charger driver.
--- drivers/power/ab8500_charger.c | 65 ++++++++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 9 deletions(-)
drivers/power/ab8500_charger.c +56 -9
@@ -88,6 +88,9 @@/* Step up/down delay in us */ #define STEP_UDELAY 1000 +/* Wait for enumeration before charging in ms */ +#define WAIT_FOR_USB_ENUMERATION 5 * 1000 +#define CHARGER_STATUS_POLL 10/* in ms */ /* UsbLineStatus register - usb types */
@@ -201,6 +204,7 @@ struct ab8500_charger_usb_state {* charger is enabled * @vbat Battery voltage * @old_vbat Previously measured battery voltage +* @usb_device_is_unrecognised USB device is unrecognised by the hardware * @autopower Indicate if we should have automatic pwron after pwrloss * @autopower_cfg platform specific power config support for "pwron after pwrloss" * @parent: Pointer to the struct ab8500
@@ -219,6 +223,7 @@ struct ab8500_charger_usb_state {* @check_usbchgnotok_work: Work for checking USB charger not ok status * @kick_wd_work: Work for kicking the charger watchdog in case * of ABB rev 1.* due to the watchog logic bug +* @attach_work: Work for checking the usb enumeration * @ac_charger_attached_work: Work for checking if AC charger is still * connected * @usb_charger_attached_work: Work for checking if USB charger is still
@@ -243,6 +248,7 @@ struct ab8500_charger {bool vddadc_en_usb;int vbat;int old_vbat; +bool usb_device_is_unrecognised;bool autopower;bool autopower_cfg;struct ab8500 *parent;
@@ -260,6 +266,7 @@ struct ab8500_charger {struct delayed_work check_hw_failure_work;struct delayed_work check_usbchgnotok_work;struct delayed_work kick_wd_work; +struct delayed_work attach_work;struct delayed_work ac_charger_attached_work;struct delayed_work usb_charger_attached_work;struct work_struct ac_work;
@@ -597,6 +604,8 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di, {int ret =0 ; + di->usb_device_is_unrecognised = false; +switch (link_status) {case USB_STAT_STD_HOST_NC :case USB_STAT_STD_HOST_C_NS :
@@ -642,9 +651,15 @@ static int ab8500_charger_max_usb_curr(struct ab8500_charger *di,dev_dbg (di->dev,"USB Type - 0x%02x MaxCurr: %d" , link_status, di->max_usb_in_curr);break ; +case USB_STAT_NOT_CONFIGURED : +if (di->vbus_detected) { + di->usb_device_is_unrecognised = true; +dev_dbg (di->dev,"USB Type - Legacy charger.\n" ); + di->max_usb_in_curr =USB_CH_IP_CUR_LVL_1P5 ; +break ; + }case USB_STAT_HM_IDGND :case USB_STAT_NOT_VALID_LINK : -case USB_STAT_NOT_CONFIGURED :dev_err (di->dev,"USB Type - Charging not allowed\n" ); di->max_usb_in_curr =USB_CH_IP_CUR_LVL_0P05 ; ret = -ENXIO ;
@@ -1915,6 +1930,30 @@ static void ab8500_charger_detect_usb_type_work(struct work_struct *work) }/** +* ab8500_charger_usb_link_attach_work() - delayd work to detect USB type +* @work: pointer to the work_struct structure +* +* Detect the type of USB plugged +*/ +static void ab8500_charger_usb_link_attach_work (struct work_struct *work) +{ +int ret; + +struct ab8500_charger *di =container_of (work, + struct ab8500_charger, attach_work.work); + +/* Update maximum input current if USB enumeration is not detected */ +if (!di->usb.charger_online) { + ret =ab8500_charger_set_vbus_in_curr (di, di->max_usb_in_curr); +if (ret) +return ; + } + +ab8500_charger_set_usb_connected (di, true); +ab8500_power_supply_changed (di, &di->usb_chg.psy); +} + +/** * ab8500_charger_usb_link_status_work() - work to detect USB type * @work: pointer to the work_struct structure *
@@ -1944,14 +1983,19 @@ static void ab8500_charger_usb_link_status_work(struct work_struct *work) di->vbus_detected =1 ; ret =ab8500_charger_read_usb_type (di);if (!ret) { -/* Update maximum input current */ - ret =ab8500_charger_set_vbus_in_curr (di, - di->max_usb_in_curr); -if (ret) -return ; - -ab8500_charger_set_usb_connected (di, true); -ab8500_power_supply_changed (di, &di->usb_chg.psy); +if (di->usb_device_is_unrecognised) { +dev_dbg (di->dev, +"Potential Legacy Charger device. " +"Delay work for %d msec for USB enum " +"to finish" , +WAIT_FOR_USB_ENUMERATION ); +queue_delayed_work (di->charger_wq, + &di->attach_work, +msecs_to_jiffies (WAIT_FOR_USB_ENUMERATION )); + }else { +queue_delayed_work (di->charger_wq, + &di->attach_work,0 ); + } }else if (ret == -ENXIO ) {/* No valid charger type detected */ ab8500_charger_set_usb_connected (di, false);
@@ -2919,6 +2963,9 @@ static int __devinit ab8500_charger_probe(struct platform_device *pdev)INIT_DEFERRABLE_WORK (&di->check_vbat_work, ab8500_charger_check_vbat_work); +INIT_DELAYED_WORK (&di->attach_work, + ab8500_charger_usb_link_attach_work); +/* Init work for charger detection */ INIT_WORK (&di->usb_link_status_work, ab8500_charger_usb_link_status_work);
Signature · 1 line
1.7.9.5
PATCH 18/18 Power: ab8500_fg: Overflow in current calculation
In reply to Lee JonesFrom: Paer-Olof Haakansson <[email protected]>
When calculating the average current the nominator will overflow when the charging current is high.
--- drivers/power/ab8500_fg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/power/ab8500_fg.c +4 -5
@@ -804,12 +804,9 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work)/* * Convert to unit value in mA -* Full scale input voltage is -* 66.660mV => LSB = 66.660mV/(4096*res) = 1.627mA -* Given a 250ms conversion cycle time the LSB corresponds -* to 112.9 nAh. Convert to current by dividing by the conversion +* by dividing by the conversion * time in hours (= samples / (3600 * 4)h) -* 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm +* and multiply with 1000 */ di->avg_curr = (val *QLSB_NANO_AMP_HOURS_X10 *36 ) / (1000 * di->bm->fg_res * (di->fg_samples /4 ));
@@ -820,6 +817,8 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work)queue_work (di->fg_wq, &di->fg_work); +dev_dbg (di->dev,"fg_res: %d, fg_samples: %d, gasg: %d, accu_charge: %d \n" , + di->bm->fg_res, di->fg_samples, val, di->accu_charge);return ; exit: dev_err(di->dev,
Signature · 1 line
1.7.9.5
Quoted 5 lines · Lee Jones
Please find the next instalment of the AB8500 Power drivers upgrade. A lot of work has taken place on the internal development track, but little effort has gone into mainlining it. At last count there were around 70+ patches which are in need of forward-porting, then upstreaming. This patch-set aims to make a good start. :)
Lee,
The series seem like a part of a larger 57-patches series that I reviewed in late September (it took me 3 days to review it back then :).
So, today I took a look at the first few patches, and I see that none of my comments were addressed. I guess there is some internal miscommunication between the teams, so maybe you didn't know about the previous effort of upstreaming the fixes.
So, please take a look at these comments:
http://lkml.org/lkml/2012/9/25/587
Thanks!
Anton
Hi Anton,
I hope your studies are progressing well.
Quoted 8 lines
Quoted 5 lines
Please find the next instalment of the AB8500 Power drivers upgrade. A lot of work has taken place on the internal development track, but little effort has gone into mainlining it. At last count there were around 70+ patches which are in need of forward-porting, then upstreaming. This patch-set aims to make a good start. :)
Lee,
Quoted 7 lines
The series seem like a part of a larger 57-patches series that I reviewed in late September (it took me 3 days to review it back then :).
So, today I took a look at the first few patches, and I see that none of my comments were addressed. I guess there is some internal miscommunication between the teams, so maybe you didn't know about the previous effort of upstreaming the fixes.
No, I didn't know that Mathieu had already sent patches to the list.
I will endeavour to make any changes and resubmit my patch-set.
I think I've mentioned this before, but there are 80 patches in all. :(
Signature · 4 lines
Lee Jones Linaro ST-Ericsson Landing Team Lead Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog