rk: power_supply: add rk_get_system_battery_capacity and rk_get_system_battery_status api
author黄涛 <huangtao@rock-chips.com>
Fri, 22 Feb 2013 07:10:24 +0000 (15:10 +0800)
committer黄涛 <huangtao@rock-chips.com>
Fri, 22 Feb 2013 07:10:57 +0000 (15:10 +0800)
drivers/power/Makefile
drivers/power/power_supply_core.c
drivers/power/rk29_charger_display.c
include/linux/power_supply.h

index c774f10a69e24ae69c4098aa2cebb3c4208d8f98..88affea3013b17bf08f518e1a6ed5664c1990383 100644 (file)
@@ -44,5 +44,5 @@ obj-$(CONFIG_CHARGER_GPIO)    += gpio-charger.o
 obj-$(CONFIG_TWL6030_BCI_BATTERY)      += twl6030_bci_battery.o
 obj-$(CONFIG_BATTERY_RK29_ADC) += rk29_adc_battery.o
 obj-$(CONFIG_BATTERY_RK30_ADC)  += rk30_adc_battery.o
-obj-$(CONFIG_POWER_ON_CHARGER_DISPLAY) += rk29_charger_display.o
+obj-$(CONFIG_PLAT_RK)          += rk29_charger_display.o
 obj-$(CONFIG_BATTERY_RK30_ADC_FAC)  += rk30_factory_adc_battery.o
index f76f0bcbf60603dbe969c3f71c6090ce230b0e68..03810ce5633faf03105d9690b4369cdf0a8950d3 100644 (file)
@@ -19,9 +19,6 @@
 #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);
@@ -184,10 +181,6 @@ 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;
index 693684da5bb4cacbe77d82576052404d37c627a5..7d2253b29800030df750056dfc104a5d760aee7a 100755 (executable)
@@ -7,6 +7,7 @@
 #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>
 #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
+static 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)
 {
 
@@ -44,8 +42,61 @@ 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);
 
-LIST_HEAD(rk_psy_head);  //add by yxj for charge logo display  boot_command_line
+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;
+}
+
+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_POWER_ON_CHARGER_DISPLAY
 //int charger_mode=0;          //1:charge,0:not charge
 static void add_bootmode_charger_to_cmdline(void)
 {
@@ -69,8 +120,6 @@ 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");
 
@@ -81,18 +130,11 @@ static int  __init start_charge_logo_display(void)
 
        }
 
-       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))
@@ -124,7 +166,7 @@ static int  __init start_charge_logo_display(void)
 
        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 ((board_boot_mode() != BOOT_MODE_REBOOT) || (val_capacity.intval <= pwr_on_thrsd))  //do not enter power on charge mode when soft  reset
            {                   
                        add_bootmode_charger_to_cmdline();
                        //boot_mode_init("charge");
@@ -136,4 +178,5 @@ static int  __init start_charge_logo_display(void)
 } 
 
 //subsys_initcall_sync(start_charge_logo_display);
-late_initcall(start_charge_logo_display);
+module_init(start_charge_logo_display);
+#endif
index 0cc26c7e57043ffced2188ab48dbdac1f05ac94a..2287c3214138dc556e0c26a8686e3be35364a338 100644 (file)
@@ -147,10 +147,6 @@ 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);