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/delay.h>
8 #include <linux/power_supply.h>
9 #include <linux/workqueue.h>
10 #include <linux/reboot.h>
11 #include <asm/unaligned.h>
12 #include <mach/gpio.h>
13 #include <mach/iomux.h>
14 #include <mach/board.h>
15 #include <asm/uaccess.h>
16 #include <linux/power_supply.h>
20 #define DBG(x...) printk(KERN_INFO x)
25 //#define RK29_PLAY_ON_PIN RK29_PIN6_PA7
26 //#define MAX_PRE_CNT 2
28 #define PWR_ON_THRESHD 5 //power on threshd of capacity
29 //unsigned int pre_cnt = 0; //for long press counter
30 //int charge_disp_mode = 0;
31 static int pwr_on_thrsd = 5; //power on capcity threshold
33 //extern int boot_mode_init(char * s);
35 static int __init pwr_on_thrsd_setup(char *str)
38 pwr_on_thrsd = simple_strtol(str,NULL,10);
39 printk(KERN_INFO "power on threshold:%d",pwr_on_thrsd);
43 __setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
45 static int usb_status;
47 static int __rk_get_system_battery_status(struct device *dev, void *data)
49 union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
50 struct power_supply *psy = dev_get_drvdata(dev);
52 psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val_status);
54 if (val_status.intval != 0) {
55 if (psy->type == POWER_SUPPLY_TYPE_USB)
56 usb_status = POWER_SUPPLY_TYPE_USB;
57 if (psy->type == POWER_SUPPLY_TYPE_MAINS)
58 ac_status = POWER_SUPPLY_TYPE_MAINS;
64 // POWER_SUPPLY_TYPE_BATTERY --- discharge
65 // POWER_SUPPLY_TYPE_USB --- usb_charging
66 // POWER_SUPPLY_TYPE_MAINS --- AC_charging
67 int rk_get_system_battery_status(void)
69 class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_status);
71 if (ac_status == POWER_SUPPLY_TYPE_MAINS) {
72 return POWER_SUPPLY_TYPE_MAINS;
73 } else if (usb_status == POWER_SUPPLY_TYPE_USB) {
74 return POWER_SUPPLY_TYPE_USB;
77 return POWER_SUPPLY_TYPE_BATTERY;
79 EXPORT_SYMBOL(rk_get_system_battery_status);
81 static union power_supply_propval battery_capacity = { 100 };
82 static int __rk_get_system_battery_capacity(struct device *dev, void *data)
84 struct power_supply *psy = dev_get_drvdata(dev);
86 psy->get_property(psy, POWER_SUPPLY_PROP_CAPACITY, &battery_capacity);
91 int rk_get_system_battery_capacity(void)
93 class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_capacity);
95 return battery_capacity.intval;
97 EXPORT_SYMBOL(rk_get_system_battery_capacity);
99 #ifdef CONFIG_POWER_ON_CHARGER_DISPLAY
100 //int charger_mode=0; //1:charge,0:not charge
101 static void add_bootmode_charger_to_cmdline(void)
103 char *pmode=" androidboot.mode=charger";
104 //int off = strlen(saved_command_line);
105 char *new_command_line = kzalloc(strlen(saved_command_line) + strlen(pmode) + 1, GFP_KERNEL);
106 sprintf(new_command_line, "%s%s", saved_command_line, pmode);
107 saved_command_line = new_command_line;
108 //strcpy(saved_command_line+off,pmode);
110 //int off = strlen(boot_command_line);
111 //strcpy(boot_command_line+off,pmode);
113 printk("Kernel command line: %s\n", saved_command_line);
116 //display charger logo in kernel CAPACITY
119 static int __init start_charge_logo_display(void)
121 union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
122 union power_supply_propval val_capacity ={ 100} ;
124 printk("start_charge_logo_display\n");
126 if(board_boot_mode() == BOOT_MODE_RECOVERY) //recovery mode
128 printk("recovery mode \n");
133 if (rk_get_system_battery_status() != POWER_SUPPLY_TYPE_BATTERY)
134 val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
136 val_capacity.intval = rk_get_system_battery_capacity();
138 // low power and discharging
140 if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
142 printk("low power\n");
150 //low power and charging
152 if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval == POWER_SUPPLY_STATUS_CHARGING))
154 while((val_capacity.intval < pwr_on_thrsd ))
156 list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
158 psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity);
161 //printk("charging ... \n");
167 if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
169 if ((board_boot_mode() == BOOT_MODE_NORMAL) ||(board_boot_mode() == BOOT_MODE_CHARGE)|| (val_capacity.intval <= pwr_on_thrsd)) //do not enter power on charge mode when soft reset
171 add_bootmode_charger_to_cmdline();
172 //boot_mode_init("charge");
173 printk("power in charge mode\n");
180 //subsys_initcall_sync(start_charge_logo_display);
181 module_init(start_charge_logo_display);