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 <asm/unaligned.h>
11 #include <mach/gpio.h>
12 #include <mach/iomux.h>
13 #include <mach/board.h>
14 #include <asm/uaccess.h>
15 #include <linux/power_supply.h>
19 #define DBG(x...) printk(KERN_INFO x)
24 //#define RK29_PLAY_ON_PIN RK29_PIN6_PA7
25 //#define MAX_PRE_CNT 2
27 #define PWR_ON_THRESHD 5 //power on threshd of capacity
28 //unsigned int pre_cnt = 0; //for long press counter
29 //int charge_disp_mode = 0;
30 int pwr_on_thrsd = 5; //power on capcity threshold
32 //extern int board_boot_mode(void);
33 //extern int boot_mode_init(char * s);
35 extern void kernel_power_off(void);
37 static int __init pwr_on_thrsd_setup(char *str)
40 pwr_on_thrsd = simple_strtol(str,NULL,10);
41 printk(KERN_INFO "power on threshold:%d",pwr_on_thrsd);
45 __setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
48 LIST_HEAD(rk_psy_head); //add by yxj for charge logo display boot_command_line
49 //int charger_mode=0; //1:charge,0:not charge
50 static void add_bootmode_charger_to_cmdline(void)
52 char *pmode=" androidboot.mode=charger";
53 //int off = strlen(saved_command_line);
54 char *new_command_line = kzalloc(strlen(saved_command_line) + strlen(pmode) + 1, GFP_KERNEL);
55 sprintf(new_command_line, "%s%s", saved_command_line, pmode);
56 saved_command_line = new_command_line;
57 //strcpy(saved_command_line+off,pmode);
59 //int off = strlen(boot_command_line);
60 //strcpy(boot_command_line+off,pmode);
62 printk("Kernel command line: %s\n", saved_command_line);
65 //display charger logo in kernel CAPACITY
68 static int __init start_charge_logo_display(void)
70 union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
71 union power_supply_propval val_capacity ={ 100} ;
72 struct power_supply *psy;
75 printk("start_charge_logo_display\n");
77 if(board_boot_mode() == BOOT_MODE_RECOVERY) //recovery mode
79 printk("recovery mode \n");
84 list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
86 psy->get_property(psy,POWER_SUPPLY_PROP_ONLINE,&val_status);
88 online += val_status.intval;
90 psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity);
94 val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
96 // low power and discharging
98 if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
100 printk("low power\n");
108 //low power and charging
110 if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval == POWER_SUPPLY_STATUS_CHARGING))
112 while((val_capacity.intval < pwr_on_thrsd ))
114 list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
116 psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity);
119 //printk("charging ... \n");
125 if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
127 if(board_boot_mode() != BOOT_MODE_REBOOT) //do not enter power on charge mode when soft reset
129 add_bootmode_charger_to_cmdline();
130 //boot_mode_init("charge");
131 printk("power in charge mode\n");
138 //subsys_initcall_sync(start_charge_logo_display);
139 module_init(start_charge_logo_display);