drm/rockchip: gem: import dma_buf to gem
[firefly-linux-kernel-4.4.55.git] / drivers / power / rk29_charger_display.c
index 693684da5bb4cacbe77d82576052404d37c627a5..407486f68bf0ab257cd5070c16491423a8cd534a 100755 (executable)
@@ -4,16 +4,15 @@
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
+#include <linux/device.h>
 #include <linux/delay.h>
 #include <linux/power_supply.h>
 #include <linux/workqueue.h>
+#include <linux/reboot.h>
 #include <asm/unaligned.h>
-#include <mach/gpio.h>
-#include <mach/iomux.h>
-#include <mach/board.h>
 #include <asm/uaccess.h>
 #include <linux/power_supply.h>
-
+#include <linux/rockchip/common.h>
 
 #if 0
 #define DBG(x...)      printk(KERN_INFO x)
 #define DBG(x...)
 #endif
 
-//#define RK29_PLAY_ON_PIN RK29_PIN6_PA7
-//#define MAX_PRE_CNT 2
-//#define DET_CNT   5
-#define PWR_ON_THRESHD 5       //power on threshd of capacity
-//unsigned int   pre_cnt = 0;   //for long press counter 
-//int charge_disp_mode = 0;
-int pwr_on_thrsd = 5;          //power on capcity threshold
-
-//extern int board_boot_mode(void);
-//extern int boot_mode_init(char * s);
-
-extern void kernel_power_off(void);
+static int pwr_on_thrsd = 5;          //power on capcity threshold
 
 static int __init pwr_on_thrsd_setup(char *str)
 {
@@ -44,55 +32,88 @@ static int __init pwr_on_thrsd_setup(char *str)
 
 __setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
 
+static int usb_status;
+static int ac_status;
+static int __rk_get_system_battery_status(struct device *dev, void *data)
+{
+       union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
+       struct power_supply *psy = dev_get_drvdata(dev);
+
+       psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val_status);
+
+       if (val_status.intval != 0) {
+               if (psy->type == POWER_SUPPLY_TYPE_USB)
+                       usb_status = POWER_SUPPLY_TYPE_USB;
+               if (psy->type == POWER_SUPPLY_TYPE_MAINS)
+                       ac_status = POWER_SUPPLY_TYPE_MAINS;
+       }
+
+       return 0;
+}
+
+// POWER_SUPPLY_TYPE_BATTERY --- discharge
+// POWER_SUPPLY_TYPE_USB     --- usb_charging
+// POWER_SUPPLY_TYPE_MAINS   --- AC_charging
+int rk_get_system_battery_status(void)
+{
+       class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_status);
+
+       if (ac_status == POWER_SUPPLY_TYPE_MAINS) {
+               return POWER_SUPPLY_TYPE_MAINS;
+       } else if (usb_status == POWER_SUPPLY_TYPE_USB) {
+               return POWER_SUPPLY_TYPE_USB;
+       }
+
+       return POWER_SUPPLY_TYPE_BATTERY;
+}
+EXPORT_SYMBOL(rk_get_system_battery_status);
+
+static union power_supply_propval battery_capacity = { 100 };
+static int __rk_get_system_battery_capacity(struct device *dev, void *data)
+{
+       struct power_supply *psy = dev_get_drvdata(dev);
+
+       psy->get_property(psy, POWER_SUPPLY_PROP_CAPACITY, &battery_capacity);
+
+       return 0;
+}
 
-LIST_HEAD(rk_psy_head);  //add by yxj for charge logo display  boot_command_line
-//int charger_mode=0;          //1:charge,0:not charge
+int rk_get_system_battery_capacity(void)
+{
+       class_for_each_device(power_supply_class, NULL, NULL, __rk_get_system_battery_capacity);
+
+       return battery_capacity.intval;
+}
+EXPORT_SYMBOL(rk_get_system_battery_capacity);
+
+#ifdef CONFIG_CHARGER_DISPLAY
 static void add_bootmode_charger_to_cmdline(void)
 {
        char *pmode=" androidboot.mode=charger";
-       //int off = strlen(saved_command_line);
        char *new_command_line = kzalloc(strlen(saved_command_line) + strlen(pmode) + 1, GFP_KERNEL);
+
        sprintf(new_command_line, "%s%s", saved_command_line, pmode);
        saved_command_line = new_command_line;
-       //strcpy(saved_command_line+off,pmode);
-
-       //int off = strlen(boot_command_line);
-       //strcpy(boot_command_line+off,pmode);
 
        printk("Kernel command line: %s\n", saved_command_line);
 }
 
-//display charger logo in kernel CAPACITY
-
-
 static int  __init start_charge_logo_display(void)
 {
        union power_supply_propval val_status = {POWER_SUPPLY_STATUS_DISCHARGING};
        union power_supply_propval val_capacity ={ 100} ;
-       struct power_supply *psy;
-       int online = 0;
 
        printk("start_charge_logo_display\n");
 
-       if(board_boot_mode() == BOOT_MODE_RECOVERY)  //recovery mode
+       if(rockchip_boot_mode() == BOOT_MODE_RECOVERY)  //recovery mode
        {
                printk("recovery mode \n");
                return 0;
-
-       }
-
-       list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
-       {
-               psy->get_property(psy,POWER_SUPPLY_PROP_ONLINE,&val_status);
-               
-               online += val_status.intval;
-
-               psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity); 
        }
-
-       if(online >= 1)
+       if (rk_get_system_battery_status() != POWER_SUPPLY_TYPE_BATTERY)
                val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
 
+       val_capacity.intval = rk_get_system_battery_capacity();
        // low power   and  discharging
 #if 0
        if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
@@ -104,36 +125,17 @@ static int  __init start_charge_logo_display(void)
        }
 #endif
 
-
-       //low power and charging
-#if 0
-       if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval == POWER_SUPPLY_STATUS_CHARGING))
-       {
-               while((val_capacity.intval < pwr_on_thrsd ))
-               {
-                       list_for_each_entry(psy, &rk_psy_head, rk_psy_node)
-                       {
-                               psy->get_property(psy,POWER_SUPPLY_PROP_CAPACITY,&val_capacity); 
-                       }
-
-                       //printk("charging ... \n");
-               }
-       }
-
-#endif
-
        if(val_status.intval == POWER_SUPPLY_STATUS_CHARGING)
        {
-               if(board_boot_mode() != BOOT_MODE_REBOOT)   //do not enter power on charge mode when soft  reset
+               if (((rockchip_boot_mode() == BOOT_MODE_NORMAL) || (rockchip_boot_mode() == BOOT_MODE_CHARGE)) || (val_capacity.intval <= pwr_on_thrsd))
            {                   
                        add_bootmode_charger_to_cmdline();
-                       //boot_mode_init("charge");
-                       printk("power in charge mode\n");
-               }
+                       printk("power in charge mode %d %d  %d\n\n",rockchip_boot_mode(),val_capacity.intval,pwr_on_thrsd);
+          }
        }
 
        return 0;
 } 
 
-//subsys_initcall_sync(start_charge_logo_display);
 late_initcall(start_charge_logo_display);
+#endif