Commit 4008e879 authored by Mark Brown's avatar Mark Brown Committed by Samuel Ortiz

power_supply: Add battery health reporting for WM8350

Implement support for reporting battery health in the WM8350 battery
interface. Since we are now able to report this via the classs remove
the diagnostics from the interrupt handler.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarAnton Vorontsov <cbouatmailru@gmail.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@openedhand.com>
parent 7e386e6e
...@@ -1314,7 +1314,7 @@ const struct wm8350_reg_access wm8350_reg_io_map[] = { ...@@ -1314,7 +1314,7 @@ const struct wm8350_reg_access wm8350_reg_io_map[] = {
{ 0xFFFF, 0xFFFF, 0xFFFF }, /* R223 */ { 0xFFFF, 0xFFFF, 0xFFFF }, /* R223 */
{ 0x0000, 0x0000, 0x0000 }, /* R224 */ { 0x0000, 0x0000, 0x0000 }, /* R224 */
{ 0x8F3F, 0x0000, 0xFFFF }, /* R225 - DCDC/LDO status */ { 0x8F3F, 0x0000, 0xFFFF }, /* R225 - DCDC/LDO status */
{ 0x0000, 0x0000, 0x0000 }, /* R226 */ { 0x0000, 0x0000, 0xFFFF }, /* R226 - Charger status */
{ 0x0000, 0x0000, 0xFFFF }, /* R227 */ { 0x0000, 0x0000, 0xFFFF }, /* R227 */
{ 0x0000, 0x0000, 0x0000 }, /* R228 */ { 0x0000, 0x0000, 0x0000 }, /* R228 */
{ 0x0000, 0x0000, 0x0000 }, /* R229 */ { 0x0000, 0x0000, 0x0000 }, /* R229 */
......
...@@ -190,22 +190,18 @@ static void wm8350_charger_handler(struct wm8350 *wm8350, int irq, void *data) ...@@ -190,22 +190,18 @@ static void wm8350_charger_handler(struct wm8350 *wm8350, int irq, void *data)
struct wm8350_charger_policy *policy = power->policy; struct wm8350_charger_policy *policy = power->policy;
switch (irq) { switch (irq) {
case WM8350_IRQ_CHG_BAT_HOT:
dev_err(wm8350->dev, "battery too hot\n");
break;
case WM8350_IRQ_CHG_BAT_COLD:
dev_err(wm8350->dev, "battery too cold\n");
break;
case WM8350_IRQ_CHG_BAT_FAIL: case WM8350_IRQ_CHG_BAT_FAIL:
dev_err(wm8350->dev, "battery failed\n"); dev_err(wm8350->dev, "battery failed\n");
break; break;
case WM8350_IRQ_CHG_TO: case WM8350_IRQ_CHG_TO:
dev_err(wm8350->dev, "charger timeout\n"); dev_err(wm8350->dev, "charger timeout\n");
break;
case WM8350_IRQ_CHG_END:
power_supply_changed(&power->battery); power_supply_changed(&power->battery);
break; break;
case WM8350_IRQ_CHG_BAT_HOT:
case WM8350_IRQ_CHG_BAT_COLD:
case WM8350_IRQ_CHG_START: case WM8350_IRQ_CHG_START:
case WM8350_IRQ_CHG_END:
power_supply_changed(&power->battery); power_supply_changed(&power->battery);
break; break;
...@@ -308,6 +304,23 @@ static enum power_supply_property wm8350_usb_props[] = { ...@@ -308,6 +304,23 @@ static enum power_supply_property wm8350_usb_props[] = {
* Battery properties * Battery properties
*********************************************************************/ *********************************************************************/
static int wm8350_bat_check_health(struct wm8350 *wm8350)
{
u16 reg;
if (wm8350_read_battery_uvolts(wm8350) < 2850000)
return POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
reg = wm8350_reg_read(wm8350, WM8350_CHARGER_OVERRIDES);
if (reg & WM8350_CHG_BATT_HOT_OVRDE)
return POWER_SUPPLY_HEALTH_OVERHEAT;
if (reg & WM8350_CHG_BATT_COLD_OVRDE)
return POWER_SUPPLY_HEALTH_COLD;
return POWER_SUPPLY_HEALTH_GOOD;
}
static int wm8350_bat_get_property(struct power_supply *psy, static int wm8350_bat_get_property(struct power_supply *psy,
enum power_supply_property psp, enum power_supply_property psp,
union power_supply_propval *val) union power_supply_propval *val)
...@@ -326,6 +339,9 @@ static int wm8350_bat_get_property(struct power_supply *psy, ...@@ -326,6 +339,9 @@ static int wm8350_bat_get_property(struct power_supply *psy,
case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = wm8350_read_battery_uvolts(wm8350); val->intval = wm8350_read_battery_uvolts(wm8350);
break; break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = wm8350_bat_check_health(wm8350);
break;
default: default:
ret = -EINVAL; ret = -EINVAL;
break; break;
...@@ -338,6 +354,7 @@ static enum power_supply_property wm8350_bat_props[] = { ...@@ -338,6 +354,7 @@ static enum power_supply_property wm8350_bat_props[] = {
POWER_SUPPLY_PROP_STATUS, POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_HEALTH,
}; };
/********************************************************************* /*********************************************************************
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25 #define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25
#define WM8350_GPIO_INT_STATUS_MASK 0x26 #define WM8350_GPIO_INT_STATUS_MASK 0x26
#define WM8350_COMPARATOR_INT_STATUS_MASK 0x27 #define WM8350_COMPARATOR_INT_STATUS_MASK 0x27
#define WM8350_CHARGER_OVERRIDES 0xE2
#define WM8350_MISC_OVERRIDES 0xE3 #define WM8350_MISC_OVERRIDES 0xE3
#define WM8350_COMPARATOR_OVERRIDES 0xE7 #define WM8350_COMPARATOR_OVERRIDES 0xE7
#define WM8350_STATE_MACHINE_STATUS 0xE9 #define WM8350_STATE_MACHINE_STATUS 0xE9
...@@ -532,6 +533,12 @@ ...@@ -532,6 +533,12 @@
#define WM8350_DC2_STS 0x0002 #define WM8350_DC2_STS 0x0002
#define WM8350_DC1_STS 0x0001 #define WM8350_DC1_STS 0x0001
/*
* R226 (0xE2) - Charger status
*/
#define WM8350_CHG_BATT_HOT_OVRDE 0x8000
#define WM8350_CHG_BATT_COLD_OVRDE 0x4000
/* /*
* R227 (0xE3) - Misc Overrides * R227 (0xE3) - Misc Overrides
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment