power_supply: add charger display
author许盛飞 <xsf@rock-chips.com>
Wed, 4 Jan 2012 13:28:24 +0000 (21:28 +0800)
committer许盛飞 <xsf@rock-chips.com>
Wed, 4 Jan 2012 13:28:24 +0000 (21:28 +0800)
drivers/power/Kconfig
drivers/power/Makefile
drivers/power/power_supply_core.c
drivers/power/rk29_charger_display.c [new file with mode: 0755]
include/linux/power_supply.h

index 54c3ed608409863975c3a131354d4dece6e62ab4..7342bdde79677cfec7f1a6af9fa98180bb9f4ee1 100755 (executable)
@@ -304,4 +304,7 @@ config BATTERY_RK29_AC_CHARGE
        help
          say Y to enable suspport for the AC battery charge
 
+config POWER_ON_CHARGER_DISPLAY
+       bool "Support charger display"
+
 endif # POWER_SUPPLY
index 5e24f30321ad3f1976c2f6ab35cf683265bd3102..213a799bdae4d4d4083e0db0933ed5422477178c 100644 (file)
@@ -42,3 +42,4 @@ obj-$(CONFIG_CHARGER_MAX8903) += max8903_charger.o
 obj-$(CONFIG_CHARGER_TWL4030)  += twl4030_charger.o
 obj-$(CONFIG_CHARGER_GPIO)     += gpio-charger.o
 obj-$(CONFIG_BATTERY_RK29_ADC) += rk29_adc_battery.o
+obj-$(CONFIG_POWER_ON_CHARGER_DISPLAY) += rk29_charger_display.o
index 03810ce5633faf03105d9690b4369cdf0a8950d3..f76f0bcbf60603dbe969c3f71c6090ce230b0e68 100644 (file)
@@ -19,6 +19,9 @@
 #include <linux/power_supply.h>
 #include "power_supply.h"
 
+#ifdef CONFIG_POWER_ON_CHARGER_DISPLAY 
+extern struct list_head rk_psy_head;
+#endif
 /* exported for the APM Power driver, APM emulation */
 struct class *power_supply_class;
 EXPORT_SYMBOL_GPL(power_supply_class);
@@ -181,6 +184,10 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
 
        device_initialize(dev);
 
+#ifdef CONFIG_POWER_ON_CHARGER_DISPLAY 
+       list_add(&psy->rk_psy_node, &rk_psy_head);
+#endif
+
        dev->class = power_supply_class;
        dev->type = &power_supply_dev_type;
        dev->parent = parent;
diff --git a/drivers/power/rk29_charger_display.c b/drivers/power/rk29_charger_display.c
new file mode 100755 (executable)
index 0000000..4afe3f9
--- /dev/null
@@ -0,0 +1,137 @@
+        
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/delay.h>
+#include <linux/power_supply.h>
+#include <linux/workqueue.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>
+
+
+#if 0
+#define DBG(x...)      printk(KERN_INFO x)
+#else
+#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 __init pwr_on_thrsd_setup(char *str)
+{
+
+       pwr_on_thrsd = simple_strtol(str,NULL,10);
+       printk(KERN_INFO "power on threshold:%d",pwr_on_thrsd);
+       return 0;
+}
+
+__setup("pwr_on_thrsd=", pwr_on_thrsd_setup);
+
+
+LIST_HEAD(rk_psy_head);  //add by yxj for charge logo display  boot_command_line
+//int charger_mode=0;          //1:charge,0:not charge
+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
+       {
+               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)
+               val_status.intval = POWER_SUPPLY_STATUS_CHARGING;
+
+       // low power   and  discharging
+
+       if((val_capacity.intval < pwr_on_thrsd )&&(val_status.intval != POWER_SUPPLY_STATUS_CHARGING))
+       {
+               printk("low power\n");
+               kernel_power_off();
+               while(1);
+               return 0;
+       }
+
+/*
+       //low power and charging
+       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");
+               }
+       }
+*/
+
+
+       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
+           {                   
+                       add_bootmode_charger_to_cmdline();
+                       //boot_mode_init("charge");
+                       printk("power in charge mode\n");
+               }
+       }
+
+       return 0;
+} 
+
+subsys_initcall_sync(start_charge_logo_display);
+
index 2287c3214138dc556e0c26a8686e3be35364a338..0cc26c7e57043ffced2188ab48dbdac1f05ac94a 100644 (file)
@@ -147,6 +147,10 @@ struct power_supply {
        char **supplied_to;
        size_t num_supplicants;
 
+#ifdef CONFIG_POWER_ON_CHARGER_DISPLAY
+       struct list_head rk_psy_node;
+#endif
+
        int (*get_property)(struct power_supply *psy,
                            enum power_supply_property psp,
                            union power_supply_propval *val);