Lines Matching refs:wm8350

20 static int wm8350_read_battery_uvolts(struct wm8350 *wm8350)  in wm8350_read_battery_uvolts()  argument
22 return wm8350_read_auxadc(wm8350, WM8350_AUXADC_BATT, 0, 0) in wm8350_read_battery_uvolts()
26 static int wm8350_read_line_uvolts(struct wm8350 *wm8350) in wm8350_read_line_uvolts() argument
28 return wm8350_read_auxadc(wm8350, WM8350_AUXADC_LINE, 0, 0) in wm8350_read_line_uvolts()
32 static int wm8350_read_usb_uvolts(struct wm8350 *wm8350) in wm8350_read_usb_uvolts() argument
34 return wm8350_read_auxadc(wm8350, WM8350_AUXADC_USB, 0, 0) in wm8350_read_usb_uvolts()
42 static inline int wm8350_charge_time_min(struct wm8350 *wm8350, int min) in wm8350_charge_time_min() argument
44 if (!wm8350->power.rev_g_coeff) in wm8350_charge_time_min()
50 static int wm8350_get_supplies(struct wm8350 *wm8350) in wm8350_get_supplies() argument
55 sm = wm8350_reg_read(wm8350, WM8350_STATE_MACHINE_STATUS); in wm8350_get_supplies()
56 ov = wm8350_reg_read(wm8350, WM8350_MISC_OVERRIDES); in wm8350_get_supplies()
57 co = wm8350_reg_read(wm8350, WM8350_COMPARATOR_OVERRIDES); in wm8350_get_supplies()
58 chrg = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2); in wm8350_get_supplies()
86 static int wm8350_charger_config(struct wm8350 *wm8350, in wm8350_charger_config() argument
92 dev_warn(wm8350->dev, in wm8350_charger_config()
99 dev_err(wm8350->dev, "USB fast charge > 500mA\n"); in wm8350_charger_config()
105 wm8350_reg_unlock(wm8350); in wm8350_charger_config()
107 reg = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1) in wm8350_charger_config()
109 wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1, in wm8350_charger_config()
115 if (wm8350_get_supplies(wm8350) & WM8350_USB_SUPPLY) { in wm8350_charger_config()
118 wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2, in wm8350_charger_config()
120 fast_limit_mA | wm8350_charge_time_min(wm8350, in wm8350_charger_config()
126 wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2, in wm8350_charger_config()
128 fast_limit_mA | wm8350_charge_time_min(wm8350, in wm8350_charger_config()
132 wm8350_reg_lock(wm8350); in wm8350_charger_config()
136 static int wm8350_batt_status(struct wm8350 *wm8350) in wm8350_batt_status() argument
140 state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2); in wm8350_batt_status()
159 struct wm8350 *wm8350 = dev_get_drvdata(dev); in charger_state_show() local
163 state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2) & in charger_state_show()
186 struct wm8350 *wm8350 = data; in wm8350_charger_handler() local
187 struct wm8350_power *power = &wm8350->power; in wm8350_charger_handler()
190 switch (irq - wm8350->irq_base) { in wm8350_charger_handler()
192 dev_err(wm8350->dev, "battery failed\n"); in wm8350_charger_handler()
195 dev_err(wm8350->dev, "charger timeout\n"); in wm8350_charger_handler()
207 dev_dbg(wm8350->dev, "fast charger ready\n"); in wm8350_charger_handler()
208 wm8350_charger_config(wm8350, policy); in wm8350_charger_handler()
209 wm8350_reg_unlock(wm8350); in wm8350_charger_handler()
210 wm8350_set_bits(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1, in wm8350_charger_handler()
212 wm8350_reg_lock(wm8350); in wm8350_charger_handler()
216 dev_warn(wm8350->dev, "battery < 3.9V\n"); in wm8350_charger_handler()
219 dev_warn(wm8350->dev, "battery < 3.1V\n"); in wm8350_charger_handler()
222 dev_warn(wm8350->dev, "battery < 2.85V\n"); in wm8350_charger_handler()
229 wm8350_charger_config(wm8350, policy); in wm8350_charger_handler()
238 dev_err(wm8350->dev, "Unknown interrupt %d\n", irq); in wm8350_charger_handler()
251 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent); in wm8350_ac_get_prop() local
256 val->intval = !!(wm8350_get_supplies(wm8350) & in wm8350_ac_get_prop()
260 val->intval = wm8350_read_line_uvolts(wm8350); in wm8350_ac_get_prop()
281 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent); in wm8350_usb_get_prop() local
286 val->intval = !!(wm8350_get_supplies(wm8350) & in wm8350_usb_get_prop()
290 val->intval = wm8350_read_usb_uvolts(wm8350); in wm8350_usb_get_prop()
308 static int wm8350_bat_check_health(struct wm8350 *wm8350) in wm8350_bat_check_health() argument
312 if (wm8350_read_battery_uvolts(wm8350) < 2850000) in wm8350_bat_check_health()
315 reg = wm8350_reg_read(wm8350, WM8350_CHARGER_OVERRIDES); in wm8350_bat_check_health()
325 static int wm8350_bat_get_charge_type(struct wm8350 *wm8350) in wm8350_bat_get_charge_type() argument
329 state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2) & in wm8350_bat_get_charge_type()
347 struct wm8350 *wm8350 = dev_get_drvdata(psy->dev.parent); in wm8350_bat_get_property() local
352 val->intval = wm8350_batt_status(wm8350); in wm8350_bat_get_property()
355 val->intval = !!(wm8350_get_supplies(wm8350) & in wm8350_bat_get_property()
359 val->intval = wm8350_read_battery_uvolts(wm8350); in wm8350_bat_get_property()
362 val->intval = wm8350_bat_check_health(wm8350); in wm8350_bat_get_property()
365 val->intval = wm8350_bat_get_charge_type(wm8350); in wm8350_bat_get_property()
411 static int wm8350_init_charger(struct wm8350 *wm8350) in wm8350_init_charger() argument
416 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, in wm8350_init_charger()
417 wm8350_charger_handler, 0, "Battery hot", wm8350); in wm8350_init_charger()
421 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, in wm8350_init_charger()
422 wm8350_charger_handler, 0, "Battery cold", wm8350); in wm8350_init_charger()
426 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, in wm8350_init_charger()
427 wm8350_charger_handler, 0, "Battery fail", wm8350); in wm8350_init_charger()
431 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_TO, in wm8350_init_charger()
433 "Charger timeout", wm8350); in wm8350_init_charger()
437 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_END, in wm8350_init_charger()
439 "Charge end", wm8350); in wm8350_init_charger()
443 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_START, in wm8350_init_charger()
445 "Charge start", wm8350); in wm8350_init_charger()
449 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, in wm8350_init_charger()
451 "Fast charge ready", wm8350); in wm8350_init_charger()
455 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, in wm8350_init_charger()
457 "Battery <3.9V", wm8350); in wm8350_init_charger()
461 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, in wm8350_init_charger()
463 "Battery <3.1V", wm8350); in wm8350_init_charger()
467 ret = wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, in wm8350_init_charger()
469 "Battery <2.85V", wm8350); in wm8350_init_charger()
474 ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_USB_FB, in wm8350_init_charger()
475 wm8350_charger_handler, 0, "USB", wm8350); in wm8350_init_charger()
479 ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, in wm8350_init_charger()
480 wm8350_charger_handler, 0, "Wall", wm8350); in wm8350_init_charger()
484 ret = wm8350_register_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, in wm8350_init_charger()
485 wm8350_charger_handler, 0, "Battery", wm8350); in wm8350_init_charger()
492 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, wm8350); in wm8350_init_charger()
494 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB, wm8350); in wm8350_init_charger()
496 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350); in wm8350_init_charger()
498 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350); in wm8350_init_charger()
500 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350); in wm8350_init_charger()
502 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, wm8350); in wm8350_init_charger()
504 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350); in wm8350_init_charger()
506 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350); in wm8350_init_charger()
508 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350); in wm8350_init_charger()
510 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, wm8350); in wm8350_init_charger()
512 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, wm8350); in wm8350_init_charger()
514 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, wm8350); in wm8350_init_charger()
519 static void free_charger_irq(struct wm8350 *wm8350) in free_charger_irq() argument
521 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, wm8350); in free_charger_irq()
522 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, wm8350); in free_charger_irq()
523 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, wm8350); in free_charger_irq()
524 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350); in free_charger_irq()
525 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350); in free_charger_irq()
526 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350); in free_charger_irq()
527 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, wm8350); in free_charger_irq()
528 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350); in free_charger_irq()
529 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350); in free_charger_irq()
530 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350); in free_charger_irq()
531 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB, wm8350); in free_charger_irq()
532 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, wm8350); in free_charger_irq()
533 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, wm8350); in free_charger_irq()
538 struct wm8350 *wm8350 = platform_get_drvdata(pdev); in wm8350_power_probe() local
539 struct wm8350_power *power = &wm8350->power; in wm8350_power_probe()
562 dev_warn(wm8350->dev, "failed to add charge sysfs: %d\n", ret); in wm8350_power_probe()
565 wm8350_init_charger(wm8350); in wm8350_power_probe()
566 if (wm8350_charger_config(wm8350, policy) == 0) { in wm8350_power_probe()
567 wm8350_reg_unlock(wm8350); in wm8350_power_probe()
568 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CHG_ENA); in wm8350_power_probe()
569 wm8350_reg_lock(wm8350); in wm8350_power_probe()
584 struct wm8350 *wm8350 = platform_get_drvdata(pdev); in wm8350_power_remove() local
585 struct wm8350_power *power = &wm8350->power; in wm8350_power_remove()
587 free_charger_irq(wm8350); in wm8350_power_remove()