高通電源管理函數的power_supply的調用關系


以msm8909為例,高通的主要文件有幾個:

  • qpnp-linear-charger.c(線性充電器)
  • qpnp-vm-bms.c(BMS管理)
  • power_supply_core.c(power_supply對外部提供對應接口)

其中,vm_bus的power_supply一般為struct power_supply *bms_psy;
而linear-charger則是struct power_supply usb_psy;
(當然這只是一個命名方式而已了)

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()函數來改變其節點屬性;

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則是獲取電池的狀態,根據各個函數來判斷;

獲取電量值:

power supply class將所有可能PSY屬性,以枚舉型變量形式抽象出來,PSY driver可以根據設備的實際情況,從中選取一些。

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,
};

根據屬性來判斷:

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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM