Changeset 123


Ignore:
Timestamp:
Apr 14, 2011, 4:44:11 PM (6 years ago)
Author:
bs
Message:

Battery bug fixed.

Location:
kern_2.6.32/drivers/power
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kern_2.6.32/drivers/power/power_supply_core.c

    r121 r123  
    1919#include "power_supply.h" 
    2020 
     21/* exported for the APM Power driver, APM emulation */ 
    2122struct class *power_supply_class; 
     23EXPORT_SYMBOL_GPL(power_supply_class); 
    2224 
    2325static int __power_supply_changed_work(struct device *dev, void *data) 
     
    3739static void power_supply_changed_work(struct work_struct *work) 
    3840{ 
     41        unsigned long flags; 
    3942        struct power_supply *psy = container_of(work, struct power_supply, 
    4043                                                changed_work); 
     
    4245        dev_dbg(psy->dev, "%s\n", __func__); 
    4346 
    44         class_for_each_device(power_supply_class, NULL, psy, 
    45                               __power_supply_changed_work); 
    46  
    47         power_supply_update_leds(psy); 
    48  
    49         kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); 
     47        spin_lock_irqsave(&psy->changed_lock, flags); 
     48        if (psy->changed) { 
     49                psy->changed = false; 
     50                spin_unlock_irqrestore(&psy->changed_lock, flags); 
     51 
     52                class_for_each_device(power_supply_class, NULL, psy, 
     53                                      __power_supply_changed_work); 
     54 
     55                power_supply_update_leds(psy); 
     56 
     57                kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); 
     58                spin_lock_irqsave(&psy->changed_lock, flags); 
     59        } 
     60        if (!psy->changed) 
     61                wake_unlock(&psy->work_wake_lock); 
     62        spin_unlock_irqrestore(&psy->changed_lock, flags); 
    5063} 
    5164 
    5265void power_supply_changed(struct power_supply *psy) 
    5366{ 
     67        unsigned long flags; 
     68 
    5469        dev_dbg(psy->dev, "%s\n", __func__); 
    5570 
     71        spin_lock_irqsave(&psy->changed_lock, flags); 
     72        psy->changed = true; 
     73        wake_lock(&psy->work_wake_lock); 
     74        spin_unlock_irqrestore(&psy->changed_lock, flags); 
    5675        schedule_work(&psy->changed_work); 
    5776} 
     77EXPORT_SYMBOL_GPL(power_supply_changed); 
    5878 
    5979static int __power_supply_am_i_supplied(struct device *dev, void *data) 
     
    87107        return error; 
    88108} 
     109EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); 
    89110 
    90111static int __power_supply_is_system_supplied(struct device *dev, void *data) 
     
    111132        return error; 
    112133} 
     134EXPORT_SYMBOL_GPL(power_supply_is_system_supplied); 
     135 
     136int power_supply_set_battery_charged(struct power_supply *psy) 
     137{ 
     138        if (psy->type == POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) { 
     139                psy->set_charged(psy); 
     140                return 0; 
     141        } 
     142 
     143        return -EINVAL; 
     144} 
     145EXPORT_SYMBOL_GPL(power_supply_set_battery_charged); 
     146 
     147static int power_supply_match_device_by_name(struct device *dev, void *data) 
     148{ 
     149        const char *name = data; 
     150        struct power_supply *psy = dev_get_drvdata(dev); 
     151 
     152        return strcmp(psy->name, name) == 0; 
     153} 
     154 
     155struct power_supply *power_supply_get_by_name(char *name) 
     156{ 
     157        struct device *dev = class_find_device(power_supply_class, NULL, name, 
     158                                        power_supply_match_device_by_name); 
     159 
     160        return dev ? dev_get_drvdata(dev) : NULL; 
     161} 
     162EXPORT_SYMBOL_GPL(power_supply_get_by_name); 
    113163 
    114164int power_supply_register(struct device *parent, struct power_supply *psy) 
     
    124174 
    125175        INIT_WORK(&psy->changed_work, power_supply_changed_work); 
     176        spin_lock_init(&psy->changed_lock); 
     177        wake_lock_init(&psy->work_wake_lock, WAKE_LOCK_SUSPEND, "power-supply"); 
    126178 
    127179        rc = power_supply_create_attrs(psy); 
     
    140192        power_supply_remove_attrs(psy); 
    141193create_attrs_failed: 
     194        wake_lock_destroy(&psy->work_wake_lock); 
    142195        device_unregister(psy->dev); 
    143196dev_create_failed: 
     
    145198        return rc; 
    146199} 
     200EXPORT_SYMBOL_GPL(power_supply_register); 
    147201 
    148202void power_supply_unregister(struct power_supply *psy) 
     
    151205        power_supply_remove_triggers(psy); 
    152206        power_supply_remove_attrs(psy); 
     207        wake_lock_destroy(&psy->work_wake_lock); 
    153208        device_unregister(psy->dev); 
    154209} 
     210EXPORT_SYMBOL_GPL(power_supply_unregister); 
    155211 
    156212static int __init power_supply_class_init(void) 
     
    170226        class_destroy(power_supply_class); 
    171227} 
    172  
    173 EXPORT_SYMBOL_GPL(power_supply_changed); 
    174 EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); 
    175 EXPORT_SYMBOL_GPL(power_supply_is_system_supplied); 
    176 EXPORT_SYMBOL_GPL(power_supply_register); 
    177 EXPORT_SYMBOL_GPL(power_supply_unregister); 
    178  
    179 /* exported for the APM Power driver, APM emulation */ 
    180 EXPORT_SYMBOL_GPL(power_supply_class); 
    181228 
    182229subsys_initcall(power_supply_class_init); 
  • kern_2.6.32/drivers/power/power_supply_sysfs.c

    r121 r123  
    4444                "Unknown", "Charging", "Discharging", "Not charging", "Full" 
    4545        }; 
     46        static char *charge_type[] = { 
     47                "Unknown", "N/A", "Trickle", "Fast" 
     48        }; 
    4649        static char *health_text[] = { 
    4750                "Unknown", "Good", "Overheat", "Dead", "Over voltage", 
     
    5154                "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", 
    5255                "LiMn" 
     56        }; 
     57        static char *capacity_level_text[] = { 
     58                "Unknown", "Critical", "Low", "Normal", "High", "Full" 
    5359        }; 
    5460        ssize_t ret; 
     
    6874        if (off == POWER_SUPPLY_PROP_STATUS) 
    6975                return sprintf(buf, "%s\n", status_text[value.intval]); 
     76        else if (off == POWER_SUPPLY_PROP_CHARGE_TYPE) 
     77                return sprintf(buf, "%s\n", charge_type[value.intval]); 
    7078        else if (off == POWER_SUPPLY_PROP_HEALTH) 
    7179                return sprintf(buf, "%s\n", health_text[value.intval]); 
    7280        else if (off == POWER_SUPPLY_PROP_TECHNOLOGY) 
    7381                return sprintf(buf, "%s\n", technology_text[value.intval]); 
     82        else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL) 
     83                return sprintf(buf, "%s\n", capacity_level_text[value.intval]); 
    7484        else if (off >= POWER_SUPPLY_PROP_MODEL_NAME) 
    7585                return sprintf(buf, "%s\n", value.strval); 
     
    8292        /* Properties of type `int' */ 
    8393        POWER_SUPPLY_ATTR(status), 
     94        POWER_SUPPLY_ATTR(charge_type), 
    8495        POWER_SUPPLY_ATTR(health), 
    8596        POWER_SUPPLY_ATTR(present), 
     
    110121        POWER_SUPPLY_ATTR(energy_avg), 
    111122        POWER_SUPPLY_ATTR(capacity), 
     123        POWER_SUPPLY_ATTR(capacity_level), 
    112124        POWER_SUPPLY_ATTR(temp), 
    113125        POWER_SUPPLY_ATTR(temp_ambient), 
     
    116128        POWER_SUPPLY_ATTR(time_to_full_now), 
    117129        POWER_SUPPLY_ATTR(time_to_full_avg), 
    118         /* for android <riversky> */ 
    119         POWER_SUPPLY_ATTR(batt_vol),     
    120         POWER_SUPPLY_ATTR(batt_temp), 
    121130        /* Properties of type `const char *' */ 
    122131        POWER_SUPPLY_ATTR(model_name), 
Note: See TracChangeset for help on using the changeset viewer.