Merge branch 'develop-3.0' of ssh://10.10.10.29/rk/kernel into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / power / rk29_charger_display.c
1          
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>
16
17
18 #if 0
19 #define DBG(x...)       printk(KERN_INFO x)
20 #else
21 #define DBG(x...)
22 #endif
23
24 //#define RK29_PLAY_ON_PIN RK29_PIN6_PA7
25 //#define MAX_PRE_CNT 2
26 //#define DET_CNT   5
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
31
32 //extern int board_boot_mode(void);
33 //extern int boot_mode_init(char * s);
34
35 extern void kernel_power_off(void);
36
37 static int __init pwr_on_thrsd_setup(char *str)
38 {
39
40         pwr_on_thrsd = simple_strtol(str,NULL,10);
41         printk(KERN_INFO "power on threshold:%d",pwr_on_thrsd);
42         return 0;
43 }
44
45 __setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
46
47
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)
51 {
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);
58
59         //int off = strlen(boot_command_line);
60         //strcpy(boot_command_line+off,pmode);
61
62         printk("Kernel command line: %s\n", saved_command_line);
63 }
64
65 //display charger logo in kernel CAPACITY
66
67
68 static int  __init start_charge_logo_display(void)
69 {
70         union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
71         union power_supply_propval val_capacity ={ 100} ;
72         struct power_supply *psy;
73         int online = 0;
74
75         printk("start_charge_logo_display\n");
76
77         if(board_boot_mode() == BOOT_MODE_RECOVERY)  //recovery mode
78         {
79                 printk("recovery mode \n");
80                 return 0;
81
82         }
83
84         list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
85         {
86                 psy->get_property(psy,POWER_SUPPLY_PROP_ONLINE,&val_status);
87                 
88                 online += val_status.intval;
89
90                 psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity); 
91         }
92
93         if(online >= 1)
94                 val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
95
96         // low power   and  discharging
97
98         if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
99         {
100                 printk("low power\n");
101                 kernel_power_off();
102                 while(1);
103                 return 0;
104         }
105
106 /*
107         //low power and charging
108         if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval == POWER_SUPPLY_STATUS_CHARGING))
109         {
110                 while((val_capacity.intval < pwr_on_thrsd ))
111                 {
112                         list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
113                         {
114                                 psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity); 
115                         }
116
117                         //printk("charging ... \n");
118                 }
119         }
120 */
121
122
123         if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
124         {
125                 if(board_boot_mode() != BOOT_MODE_REBOOT)   //do not enter power on charge mode when soft  reset
126             {                   
127                         add_bootmode_charger_to_cmdline();
128                         //boot_mode_init("charge");
129                         printk("power in charge mode\n");
130                 }
131         }
132
133         return 0;
134
135
136 subsys_initcall_sync(start_charge_logo_display);
137