Lines Matching +full:charge +full:- +full:led
4 * SPDX-License-Identifier: GPL-2.0+
14 #include <led.h>
29 #include <irq-generic.h>
37 #define IMAGE_RECALC_IDX -1
38 #define IMAGE_SOC_100_IDX(n) ((n) - 2)
39 #define IMAGE_LOWPOWER_IDX(n) ((n) - 1)
70 * IF you want to use your own charge images, please:
73 * 2. You must set the failed image as last one and soc = -1 !!!
82 { .name = "battery_fail.bmp", .soc = -1, .period = 1000 },
96 list1 = dev_read_prop(dev, "regulator-on-in-mem", &size1); in regulators_parse_assigned_mem_state()
97 list2 = dev_read_prop(dev, "regulator-off-in-mem", &size2); in regulators_parse_assigned_mem_state()
101 return -EINVAL; in regulators_parse_assigned_mem_state()
103 return -EINVAL; in regulators_parse_assigned_mem_state()
108 pdata->regulators_mem = in regulators_parse_assigned_mem_state()
109 calloc(size1 + size2, sizeof(*pdata->regulators_mem)); in regulators_parse_assigned_mem_state()
110 if (!pdata->regulators_mem) in regulators_parse_assigned_mem_state()
111 return -ENOMEM; in regulators_parse_assigned_mem_state()
113 mem = pdata->regulators_mem; in regulators_parse_assigned_mem_state()
116 mem->enable = true; in regulators_parse_assigned_mem_state()
119 phandle, &mem->dev); in regulators_parse_assigned_mem_state()
124 mem->enable = false; in regulators_parse_assigned_mem_state()
127 phandle, &mem->dev); in regulators_parse_assigned_mem_state()
134 for (mem = pdata->regulators_mem; mem->dev; mem++) in regulators_parse_assigned_mem_state()
135 printf(" %20s: suspend %s\n", mem->dev->name, in regulators_parse_assigned_mem_state()
136 mem->enable ? "enabling" : "disabled"); in regulators_parse_assigned_mem_state()
147 for (mem = pdata->regulators_mem; mem->dev; mem++) { in regulators_enable_assigned_state_mem()
148 ret = regulator_set_suspend_enable(mem->dev, mem->enable); in regulators_enable_assigned_state_mem()
151 mem->dev->name, ret); in regulators_enable_assigned_state_mem()
161 if (pdata->regulators_mem) in regulators_suspend()
195 /* charge mode */ in charge_animation_ofdata_to_platdata()
196 pdata->uboot_charge = in charge_animation_ofdata_to_platdata()
197 dev_read_u32_default(dev, "rockchip,uboot-charge-on", 0); in charge_animation_ofdata_to_platdata()
198 pdata->android_charge = in charge_animation_ofdata_to_platdata()
199 dev_read_u32_default(dev, "rockchip,android-charge-on", 0); in charge_animation_ofdata_to_platdata()
201 pdata->auto_exit_charge = in charge_animation_ofdata_to_platdata()
202 dev_read_u32_default(dev, "rockchip,uboot-exit-charge-auto", 0); in charge_animation_ofdata_to_platdata()
203 pdata->exit_charge_level = in charge_animation_ofdata_to_platdata()
204 dev_read_u32_default(dev, "rockchip,uboot-exit-charge-level", 0); in charge_animation_ofdata_to_platdata()
205 pdata->exit_charge_voltage = in charge_animation_ofdata_to_platdata()
206 dev_read_u32_default(dev, "rockchip,uboot-exit-charge-voltage", 0); in charge_animation_ofdata_to_platdata()
208 pdata->low_power_voltage = in charge_animation_ofdata_to_platdata()
209 dev_read_u32_default(dev, "rockchip,uboot-low-power-voltage", 0); in charge_animation_ofdata_to_platdata()
211 pdata->screen_on_voltage = in charge_animation_ofdata_to_platdata()
212 dev_read_u32_default(dev, "rockchip,screen-on-voltage", 0); in charge_animation_ofdata_to_platdata()
213 pdata->system_suspend = in charge_animation_ofdata_to_platdata()
214 dev_read_u32_default(dev, "rockchip,system-suspend", 0); in charge_animation_ofdata_to_platdata()
216 pdata->auto_wakeup_interval = in charge_animation_ofdata_to_platdata()
217 dev_read_u32_default(dev, "rockchip,auto-wakeup-interval", 0); in charge_animation_ofdata_to_platdata()
218 pdata->auto_wakeup_screen_invert = in charge_animation_ofdata_to_platdata()
219 dev_read_u32_default(dev, "rockchip,auto-wakeup-screen-invert", 0); in charge_animation_ofdata_to_platdata()
221 pdata->auto_off_screen_interval = in charge_animation_ofdata_to_platdata()
222 dev_read_u32_default(dev, "rockchip,auto-off-screen-interval", 15); in charge_animation_ofdata_to_platdata()
224 if (pdata->screen_on_voltage > pdata->exit_charge_voltage) in charge_animation_ofdata_to_platdata()
225 pdata->screen_on_voltage = pdata->exit_charge_voltage; in charge_animation_ofdata_to_platdata()
227 if (pdata->auto_exit_charge && !pdata->auto_wakeup_interval) in charge_animation_ofdata_to_platdata()
228 pdata->auto_wakeup_interval = 10; in charge_animation_ofdata_to_platdata()
233 return -EINVAL; in charge_animation_ofdata_to_platdata()
238 pdata->uboot_charge, pdata->android_charge, in charge_animation_ofdata_to_platdata()
239 pdata->exit_charge_level, pdata->exit_charge_voltage, in charge_animation_ofdata_to_platdata()
240 pdata->low_power_voltage, pdata->screen_on_voltage); in charge_animation_ofdata_to_platdata()
252 if (priv->rtc && rtc_alarm_trigger(priv->rtc)) { in check_key_press()
266 if (pdata->auto_wakeup_interval && in check_key_press()
267 pdata->auto_wakeup_screen_invert) { in check_key_press()
268 if (priv->auto_wakeup_key_state == KEY_PRESS_DOWN) { in check_key_press()
270 priv->auto_wakeup_key_state = KEY_PRESS_NONE; in check_key_press()
276 if (!pdata->auto_wakeup_screen_invert && in check_key_press()
277 pdata->auto_off_screen_interval) { in check_key_press()
278 if (priv->auto_screen_off_timeout && in check_key_press()
279 get_timer(priv->auto_screen_off_timeout) > in check_key_press()
280 pdata->auto_off_screen_interval * 1000) { /* 1000ms */ in check_key_press()
316 if (priv->suspend_delay_timeout && in system_suspend_enter()
317 get_timer(priv->suspend_delay_timeout) <= SYSTEM_SUSPEND_DELAY_MS) in system_suspend_enter()
320 if (pdata->system_suspend && IS_ENABLED(CONFIG_ARM_SMCCC)) { in system_suspend_enter()
357 priv->suspend_delay_timeout = get_timer(0); in system_suspend_enter()
376 priv->auto_wakeup_key_state = KEY_PRESS_DOWN; in autowake_timer_handler()
426 static int old_soc = -1; in leds_update()
433 if (priv->led_charging) { in leds_update()
435 ret = led_set_state(priv->led_charging, ledst); in leds_update()
437 printf("set charging led %s failed, ret=%d\n", in leds_update()
443 if (priv->led_full) { in leds_update()
445 ret = led_set_state(priv->led_full, ledst); in leds_update()
447 printf("set charging full led %s failed, ret=%d\n", in leds_update()
464 charger = priv->charger ? : priv->fg; in fg_charger_get_chrg_online()
472 struct udevice *pmic = priv->pmic; in sys_shutdown()
473 struct udevice *fg = priv->fg; in sys_shutdown()
476 * Call the fuel/charge again to update something specific in sys_shutdown()
480 * fuel/charge need to update something before shutdown. in sys_shutdown()
500 struct udevice *fg = priv->fg; in charge_extrem_low_power()
507 return -EINVAL; in charge_extrem_low_power()
509 while (voltage < pdata->low_power_voltage + 50) { in charge_extrem_low_power()
532 * including charge current, coulometer or other. in charge_extrem_low_power()
540 /* Update led */ in charge_extrem_low_power()
544 pdata->low_power_voltage, voltage); in charge_extrem_low_power()
557 printf("Extrem low charge: exit by ctrl+c\n"); in charge_extrem_low_power()
571 const struct charge_image *image = priv->image; in charge_animation_show()
572 struct udevice *fg = priv->fg; in charge_animation_show()
574 int image_num = priv->image_num; in charge_animation_show()
580 int start_idx = 0, show_idx = -1, old_show_idx = IMAGE_RECALC_IDX; in charge_animation_show()
590 * 1. Extrem low power charge? in charge_animation_show()
593 * 4. U-Boot charge enabled by dts config? in charge_animation_show()
594 * 5. Screen off before charge? in charge_animation_show()
595 * 6. Enter charge ! in charge_animation_show()
599 printf("Exit charge: battery is not exist\n"); in charge_animation_show()
603 /* Extrem low power charge */ in charge_animation_show()
606 printf("extrem low power charge failed, ret=%d\n", ret); in charge_animation_show()
612 printf("Exit charge: due to preboot cmd '%s'\n", preboot); in charge_animation_show()
616 /* Not valid charge mode, exit */ in charge_animation_show()
621 printf("Exit charge: due to boot mode\n"); in charge_animation_show()
627 if (charging <= 0 && pdata->auto_exit_charge) { in charge_animation_show()
630 if (soc < pdata->exit_charge_level) { in charge_animation_show()
632 soc, pdata->exit_charge_level); in charge_animation_show()
635 if (voltage < pdata->exit_charge_voltage) { in charge_animation_show()
637 voltage, pdata->exit_charge_voltage); in charge_animation_show()
651 printf("Exit charge: due to charger offline\n"); in charge_animation_show()
655 /* Enter android charge, set property for kernel */ in charge_animation_show()
656 if (pdata->android_charge) { in charge_animation_show()
658 printf("Android charge mode\n"); in charge_animation_show()
661 /* Not enable U-Boot charge, exit */ in charge_animation_show()
662 if (!pdata->uboot_charge) { in charge_animation_show()
663 printf("Exit charge: due to not enable uboot charge\n"); in charge_animation_show()
670 return -EINVAL; in charge_animation_show()
674 if (voltage <= pdata->screen_on_voltage + 50) { in charge_animation_show()
681 if (pdata->auto_wakeup_interval) { in charge_animation_show()
682 printf("Auto wakeup: %dS\n", pdata->auto_wakeup_interval); in charge_animation_show()
683 autowakeup_timer_init(dev, pdata->auto_wakeup_interval); in charge_animation_show()
688 printf("Enter U-Boot charging mode\n"); in charge_animation_show()
690 printf("Enter U-Boot charging mode(IRQ)\n"); in charge_animation_show()
757 if (current == -ENOSYS) { in charge_animation_show()
765 if (pdata->auto_exit_charge) { in charge_animation_show()
767 if (pdata->exit_charge_level && in charge_animation_show()
768 soc >= pdata->exit_charge_level) { in charge_animation_show()
769 printf("soc(%d%%) exit charge animation...\n", in charge_animation_show()
773 if (pdata->exit_charge_voltage && in charge_animation_show()
774 voltage >= pdata->exit_charge_voltage) { in charge_animation_show()
775 printf("vol(%d) exit charge animation...\n", in charge_animation_show()
813 (voltage > pdata->screen_on_voltage)) { in charge_animation_show()
856 if (pdata->auto_wakeup_interval && in charge_animation_show()
857 priv->auto_wakeup_key_state == KEY_PRESS_DOWN && in charge_animation_show()
888 printf("battery FULL,exit charge animation\n"); in charge_animation_show()
908 /* Re-calculate timeout to off screen */ in charge_animation_show()
909 if (priv->auto_screen_off_timeout == 0) in charge_animation_show()
910 priv->auto_screen_off_timeout = get_timer(0); in charge_animation_show()
913 priv->auto_screen_off_timeout = 0; in charge_animation_show()
967 priv->suspend_delay_timeout = get_timer(0); in charge_animation_show()
981 if (soc < pdata->exit_charge_level) { in charge_animation_show()
983 soc, pdata->exit_charge_level); in charge_animation_show()
989 if (voltage < pdata->exit_charge_voltage) { in charge_animation_show()
991 voltage, pdata->exit_charge_voltage); in charge_animation_show()
998 printf("Exit charge animation...\n"); in charge_animation_show()
1009 if (voltage >= pdata->screen_on_voltage) in charge_animation_show()
1011 printf("Exit charge, due to ctrl+c\n"); in charge_animation_show()
1016 if (pdata->auto_wakeup_interval) in charge_animation_show()
1059 return (*fuel_gauge) ? 0 : -ENODEV; in fg_charger_get_device()
1072 ret = uclass_get_device(UCLASS_PMIC, 0, &priv->pmic); in charge_animation_probe()
1074 if (ret == -ENODEV) in charge_animation_probe()
1082 ret = fg_charger_get_device(&priv->fg, &priv->charger); in charge_animation_probe()
1084 if (ret == -ENODEV) in charge_animation_probe()
1092 ret = uclass_get_device(UCLASS_RTC, 0, &priv->rtc); in charge_animation_probe()
1094 if (ret == -ENODEV) in charge_animation_probe()
1103 return -EINVAL; in charge_animation_probe()
1106 /* Initialize charge current */ in charge_animation_probe()
1107 soc = fuel_gauge_update_get_soc(priv->fg); in charge_animation_probe()
1110 return -EINVAL; in charge_animation_probe()
1115 ret = led_get_by_label(LED_CHARGING_NAME, &priv->led_charging); in charge_animation_probe()
1117 printf("Found Charging LED\n"); in charge_animation_probe()
1118 ret = led_get_by_label(LED_CHARGING_FULL_NAME, &priv->led_full); in charge_animation_probe()
1120 printf("Found Charging-Full LED\n"); in charge_animation_probe()
1123 /* Get charge images */ in charge_animation_probe()
1124 priv->image = image; in charge_animation_probe()
1125 priv->image_num = ARRAY_SIZE(image); in charge_animation_probe()
1127 printf("Enable charge animation display\n"); in charge_animation_probe()
1133 { .compatible = "rockchip,uboot-charge" },
1138 .name = "charge-animation",