11 #include <linux/module.h>
15 #include <linux/slab.h>
33 static int wm831x_power_check_online(
struct wm831x *
wm831x,
int supply,
50 static int wm831x_power_read_voltage(
struct wm831x *
wm831x,
66 static int wm831x_wall_get_prop(
struct power_supply *psy,
71 struct wm831x *wm831x = wm831x_power->
wm831x;
102 struct wm831x *wm831x = wm831x_power->
wm831x;
134 static struct chg_map trickle_ilims[] = {
141 static struct chg_map vsels[] = {
148 static struct chg_map fast_ilims[] = {
167 static struct chg_map eoc_iterms[] = {
178 static struct chg_map chg_times[] = {
197 static void wm831x_battey_apply_config(
struct wm831x *wm831x,
204 for (i = 0; i <
count; i++)
205 if (val == map[i].val)
212 dev_dbg(wm831x->
dev,
"Set %s of %d%s\n", name, val, units);
216 static void wm831x_config_battery(
struct wm831x *wm831x)
222 if (!wm831x_pdata || !wm831x_pdata->
battery) {
224 "No battery charger configuration\n");
234 dev_info(wm831x->
dev,
"Battery charger disabled\n");
244 wm831x_battey_apply_config(wm831x, trickle_ilims,
247 "trickle charge current limit",
"mA");
249 wm831x_battey_apply_config(wm831x, vsels,
ARRAY_SIZE(vsels),
251 "target voltage",
"mV");
253 wm831x_battey_apply_config(wm831x, fast_ilims,
ARRAY_SIZE(fast_ilims),
255 "fast charge current limit",
"mA");
257 wm831x_battey_apply_config(wm831x, eoc_iterms,
ARRAY_SIZE(eoc_iterms),
259 "end of charge current threshold",
"mA");
261 wm831x_battey_apply_config(wm831x, chg_times,
ARRAY_SIZE(chg_times),
263 "charger timeout",
"min");
267 dev_err(wm831x->
dev,
"Failed to unlock registers: %d\n", ret);
277 dev_err(wm831x->
dev,
"Failed to set charger control 1: %d\n",
288 dev_err(wm831x->
dev,
"Failed to set charger control 2: %d\n",
294 static int wm831x_bat_check_status(
struct wm831x *wm831x,
int *
status)
328 static int wm831x_bat_check_type(
struct wm831x *wm831x,
int *
type)
353 static int wm831x_bat_check_health(
struct wm831x *wm831x,
int *health)
392 static int wm831x_bat_get_prop(
struct power_supply *psy,
397 struct wm831x *wm831x = wm831x_power->
wm831x;
402 ret = wm831x_bat_check_status(wm831x, &val->
intval);
405 ret = wm831x_power_check_online(wm831x, WM831X_PWR_SRC_BATT,
412 ret = wm831x_bat_check_health(wm831x, &val->
intval);
415 ret = wm831x_bat_check_type(wm831x, &val->
intval);
433 static const char *wm831x_bat_irqs[] = {
446 struct wm831x_power *wm831x_power =
data;
447 struct wm831x *wm831x = wm831x_power->
wm831x;
449 dev_dbg(wm831x->
dev,
"Battery status changed: %d\n", irq);
464 static irqreturn_t wm831x_syslo_irq(
int irq,
void *data)
466 struct wm831x_power *wm831x_power =
data;
467 struct wm831x *wm831x = wm831x_power->
wm831x;
471 dev_crit(wm831x->
dev,
"SYSVDD under voltage\n");
476 static irqreturn_t wm831x_pwr_src_irq(
int irq,
void *data)
478 struct wm831x_power *wm831x_power =
data;
479 struct wm831x *wm831x = wm831x_power->
wm831x;
481 dev_dbg(wm831x->
dev,
"Power source changed\n");
495 struct wm831x_pdata *wm831x_pdata = wm831x->
dev->platform_data;
496 struct wm831x_power *power;
502 power = kzalloc(
sizeof(
struct wm831x_power),
GFP_KERNEL);
507 platform_set_drvdata(pdev, power);
513 if (wm831x_pdata && wm831x_pdata->
wm831x_num) {
517 "wm831x-battery.%d", wm831x_pdata->
wm831x_num);
532 wm831x_config_battery(wm831x);
573 dev_err(&pdev->
dev,
"Failed to request SYSLO IRQ %d: %d\n",
583 dev_err(&pdev->
dev,
"Failed to request PWR SRC IRQ %d: %d\n",
588 for (i = 0; i <
ARRAY_SIZE(wm831x_bat_irqs); i++) {
589 irq = wm831x_irq(wm831x,
591 wm831x_bat_irqs[i]));
598 "Failed to request %s IRQ %d: %d\n",
599 wm831x_bat_irqs[i], irq, ret);
607 for (; i >= 0; i--) {
630 struct wm831x_power *wm831x_power = platform_get_drvdata(pdev);
631 struct wm831x *wm831x = wm831x_power->
wm831x;
634 for (i = 0; i <
ARRAY_SIZE(wm831x_bat_irqs); i++) {
635 irq = wm831x_irq(wm831x,
637 wm831x_bat_irqs[i]));
656 .probe = wm831x_power_probe,
659 .name =
"wm831x-power",