2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/slab.h>
5 #include <linux/kernel.h>
6 #include <linux/errno.h>
7 #include <linux/device.h>
8 #include <linux/delay.h>
9 #include <linux/power_supply.h>
10 #include <linux/workqueue.h>
11 #include <linux/reboot.h>
12 #include <asm/unaligned.h>
13 #include <asm/uaccess.h>
14 #include <linux/power_supply.h>
15 #include <linux/rockchip/common.h>
18 #define DBG(x...) printk(KERN_INFO x)
23 static int pwr_on_thrsd = 5; //power on capcity threshold
25 static int __init pwr_on_thrsd_setup(char *str)
28 pwr_on_thrsd = simple_strtol(str,NULL,10);
29 printk(KERN_INFO "power on threshold:%d",pwr_on_thrsd);
33 __setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
35 static int usb_status;
37 static int __rk_get_system_battery_status(struct device *dev, void *data)
39 union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
40 struct power_supply *psy = dev_get_drvdata(dev);
42 psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val_status);
44 if (val_status.intval != 0) {
45 if (psy->type == POWER_SUPPLY_TYPE_USB)
46 usb_status = POWER_SUPPLY_TYPE_USB;
47 if (psy->type == POWER_SUPPLY_TYPE_MAINS)
48 ac_status = POWER_SUPPLY_TYPE_MAINS;
54 // POWER_SUPPLY_TYPE_BATTERY --- discharge
55 // POWER_SUPPLY_TYPE_USB --- usb_charging
56 // POWER_SUPPLY_TYPE_MAINS --- AC_charging
57 int rk_get_system_battery_status(void)
59 class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_status);
61 if (ac_status == POWER_SUPPLY_TYPE_MAINS) {
62 return POWER_SUPPLY_TYPE_MAINS;
63 } else if (usb_status == POWER_SUPPLY_TYPE_USB) {
64 return POWER_SUPPLY_TYPE_USB;
67 return POWER_SUPPLY_TYPE_BATTERY;
69 EXPORT_SYMBOL(rk_get_system_battery_status);
71 static union power_supply_propval battery_capacity = { 100 };
72 static int __rk_get_system_battery_capacity(struct device *dev, void *data)
74 struct power_supply *psy = dev_get_drvdata(dev);
76 psy->get_property(psy, POWER_SUPPLY_PROP_CAPACITY, &battery_capacity);
81 int rk_get_system_battery_capacity(void)
83 class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_capacity);
85 return battery_capacity.intval;
87 EXPORT_SYMBOL(rk_get_system_battery_capacity);
89 #ifdef CONFIG_CHARGER_DISPLAY
90 static void add_bootmode_charger_to_cmdline(void)
92 char *pmode=" androidboot.mode=charger";
93 char *new_command_line = kzalloc(strlen(saved_command_line) + strlen(pmode) + 1, GFP_KERNEL);
95 sprintf(new_command_line, "%s%s", saved_command_line, pmode);
96 saved_command_line = new_command_line;
98 printk("Kernel command line: %s\n", saved_command_line);
101 static int __init start_charge_logo_display(void)
103 union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
104 union power_supply_propval val_capacity ={ 100} ;
106 printk("start_charge_logo_display\n");
108 if(rockchip_boot_mode() == BOOT_MODE_RECOVERY) //recovery mode
110 printk("recovery mode \n");
113 if (rk_get_system_battery_status() != POWER_SUPPLY_TYPE_BATTERY)
114 val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
116 val_capacity.intval = rk_get_system_battery_capacity();
117 // low power and discharging
119 if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
121 printk("low power\n");
128 if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
130 if (((rockchip_boot_mode() == BOOT_MODE_NORMAL) || (rockchip_boot_mode() == BOOT_MODE_CHARGE)) || (val_capacity.intval <= pwr_on_thrsd))
132 add_bootmode_charger_to_cmdline();
133 printk("power in charge mode %d %d %d\n\n",rockchip_boot_mode(),val_capacity.intval,pwr_on_thrsd);
140 late_initcall(start_charge_logo_display);