以msm8909爲例,高通的主要文件有幾個:html
其中,vm_bus的power_supply通常爲struct power_supply *bms_psy;
而linear-charger則是struct power_supply usb_psy;
(固然這只是一個命名方式而已了)node
power_supply具體參考這篇博客:架構
Linux power supply class(1)_軟件架構及API彙整【轉】函數
struct power_supply { const char *name; enum power_supply_type type; enum power_supply_property *properties; size_t num_properties; char **supplied_to; size_t num_supplicants; char **supplied_from; size_t num_supplies; #ifdef CONFIG_OF struct device_node *of_node; #endif int (*get_property)(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val); int (*set_property)(struct power_supply *psy, enum power_supply_property psp, const union power_supply_propval *val); int (*property_is_writeable)(struct power_supply *psy, enum power_supply_property psp); void (*external_power_changed)(struct power_supply *psy); void (*set_charged)(struct power_supply *psy); /* For APM emulation, think legacy userspace. */ int use_for_apm; /* private */ struct device *dev; struct work_struct changed_work; spinlock_t changed_lock; bool changed; #ifdef CONFIG_THERMAL struct thermal_zone_device *tzd; struct thermal_cooling_device *tcd; #endif #ifdef CONFIG_LEDS_TRIGGERS struct led_trigger *charging_full_trig; char *charging_full_trig_name; struct led_trigger *charging_trig; char *charging_trig_name; struct led_trigger *full_trig; char *full_trig_name; struct led_trigger *online_trig; char *online_trig_name; struct led_trigger *charging_blink_full_solid_trig; char *charging_blink_full_solid_trig_name; #endif };
在vm_bus.c中通常都有power_supply_changed()函數來改變其節點屬性;spa
power_supply_changed(&chip->bms_psy);(qpnp-vm-bms.c) --> power_supply_changed()中有一個工做隊列schedule_work(&psy->changed_work);(power_supply_core.c)--> power_supply_changed_work()工做隊列--> class_for_each_device(power_supply_class, NULL, psy,__power_supply_changed_work);對power_supply_class下的每一個設備都進行匹配 --> __power_supply_changed_work調用psy->external_power_changed中的函數--> qpnp_vm_bms_ext_power_changed是bms_psy.external_power_changed註冊的回調函數;
qpnp_vm_bms_ext_power_changed則是獲取電池的狀態,根據各個函數來判斷;code
power supply class將全部可能PSY屬性,以枚舉型變量形式抽象出來,PSY driver能夠根據設備的實際狀況,從中選取一些。htm
enum power_supply_property { /* Properties of type `int' */ POWER_SUPPLY_PROP_STATUS = 0, //該PSY的status,主要是充電狀態,包括:unknown,charging,discharging,not charging full, POWER_SUPPLY_PROP_CHARGE_TYPE,//充電類型 POWER_SUPPLY_PROP_HEALTH, //健康情況,包括:good dead over voltage等 POWER_SUPPLY_PROP_PRESENT, //電量百分比 POWER_SUPPLY_PROP_ONLINE, //是否在線 POWER_SUPPLY_PROP_AUTHENTIC, POWER_SUPPLY_PROP_TECHNOLOGY, //採用的技術 POWER_SUPPLY_PROP_CYCLE_COUNT, POWER_SUPPLY_PROP_VOLTAGE_MAX, POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, POWER_SUPPLY_PROP_VOLTAGE_NOW, POWER_SUPPLY_PROP_VOLTAGE_AVG, POWER_SUPPLY_PROP_VOLTAGE_OCV, POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_CURRENT_NOW, POWER_SUPPLY_PROP_CURRENT_AVG, POWER_SUPPLY_PROP_POWER_NOW, POWER_SUPPLY_PROP_POWER_AVG, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_EMPTY, POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_AVG, POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN, POWER_SUPPLY_PROP_ENERGY_EMPTY_DESIGN, POWER_SUPPLY_PROP_ENERGY_FULL, POWER_SUPPLY_PROP_ENERGY_EMPTY, POWER_SUPPLY_PROP_ENERGY_NOW, POWER_SUPPLY_PROP_ENERGY_AVG, POWER_SUPPLY_PROP_CAPACITY, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_ALERT_MIN, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_ALERT_MAX, /* in percents! */ POWER_SUPPLY_PROP_CAPACITY_LEVEL, //容量 POWER_SUPPLY_PROP_TEMP, POWER_SUPPLY_PROP_TEMP_ALERT_MIN, POWER_SUPPLY_PROP_TEMP_ALERT_MAX, POWER_SUPPLY_PROP_TEMP_AMBIENT, POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MIN, POWER_SUPPLY_PROP_TEMP_AMBIENT_ALERT_MAX, POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW, POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG, POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ POWER_SUPPLY_PROP_SCOPE, /* Local extensions */ POWER_SUPPLY_PROP_USB_HC, POWER_SUPPLY_PROP_USB_OTG, POWER_SUPPLY_PROP_CHARGE_ENABLED, /* Local extensions of type int64_t */ POWER_SUPPLY_PROP_CHARGE_COUNTER_EXT, /* Properties of type `const char *' */ POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_SERIAL_NUMBER, };
根據屬性來判斷:blog
qpnp-linear-charger.c中的chip->bms_psy->get_property(qpnp-linear-charger.c)————> qpnp_vm_bms_power_get_property————> get_prop_bms_capacity
以設置充電狀態爲例,POWER_SUPPLY_STATUS_CHARGING
爲其power_supply須要設置的狀態,而且使用POWER_SUPPLY_PROP_STATUS
來肯定設置的東西:接口
vm_bus只有在復充的時候會會設置充電,其餘狀況都只有linear-charge充電器中使用:隊列
ret.intval = POWER_SUPPLY_STATUS_CHARGING; rc = chip->batt_psy->set_property(chip->batt_psy, POWER_SUPPLY_PROP_STATUS, &ret);