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 void wm8350_init_charger(struct wm8350 *wm8350) in wm8350_init_charger() argument
414 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, in wm8350_init_charger()
415 wm8350_charger_handler, 0, "Battery hot", wm8350); in wm8350_init_charger()
416 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, in wm8350_init_charger()
417 wm8350_charger_handler, 0, "Battery cold", wm8350); in wm8350_init_charger()
418 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, in wm8350_init_charger()
419 wm8350_charger_handler, 0, "Battery fail", wm8350); in wm8350_init_charger()
420 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_TO, in wm8350_init_charger()
422 "Charger timeout", wm8350); in wm8350_init_charger()
423 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_END, in wm8350_init_charger()
425 "Charge end", wm8350); in wm8350_init_charger()
426 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_START, in wm8350_init_charger()
428 "Charge start", wm8350); in wm8350_init_charger()
429 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, in wm8350_init_charger()
431 "Fast charge ready", wm8350); in wm8350_init_charger()
432 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, in wm8350_init_charger()
434 "Battery <3.9V", wm8350); in wm8350_init_charger()
435 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, in wm8350_init_charger()
437 "Battery <3.1V", wm8350); in wm8350_init_charger()
438 wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, in wm8350_init_charger()
440 "Battery <2.85V", wm8350); in wm8350_init_charger()
443 wm8350_register_irq(wm8350, WM8350_IRQ_EXT_USB_FB, in wm8350_init_charger()
444 wm8350_charger_handler, 0, "USB", wm8350); in wm8350_init_charger()
445 wm8350_register_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, in wm8350_init_charger()
446 wm8350_charger_handler, 0, "Wall", wm8350); in wm8350_init_charger()
447 wm8350_register_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, in wm8350_init_charger()
448 wm8350_charger_handler, 0, "Battery", wm8350); in wm8350_init_charger()
451 static void free_charger_irq(struct wm8350 *wm8350) in free_charger_irq() argument
453 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, wm8350); in free_charger_irq()
454 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, wm8350); in free_charger_irq()
455 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, wm8350); in free_charger_irq()
456 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO, wm8350); in free_charger_irq()
457 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END, wm8350); in free_charger_irq()
458 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START, wm8350); in free_charger_irq()
459 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, wm8350); in free_charger_irq()
460 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, wm8350); in free_charger_irq()
461 wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, wm8350); in free_charger_irq()
462 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB, wm8350); in free_charger_irq()
463 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, wm8350); in free_charger_irq()
464 wm8350_free_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, wm8350); in free_charger_irq()
469 struct wm8350 *wm8350 = platform_get_drvdata(pdev); in wm8350_power_probe() local
470 struct wm8350_power *power = &wm8350->power; in wm8350_power_probe()
493 dev_warn(wm8350->dev, "failed to add charge sysfs: %d\n", ret); in wm8350_power_probe()
496 wm8350_init_charger(wm8350); in wm8350_power_probe()
497 if (wm8350_charger_config(wm8350, policy) == 0) { in wm8350_power_probe()
498 wm8350_reg_unlock(wm8350); in wm8350_power_probe()
499 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CHG_ENA); in wm8350_power_probe()
500 wm8350_reg_lock(wm8350); in wm8350_power_probe()
515 struct wm8350 *wm8350 = platform_get_drvdata(pdev); in wm8350_power_remove() local
516 struct wm8350_power *power = &wm8350->power; in wm8350_power_remove()
518 free_charger_irq(wm8350); in wm8350_power_remove()