高通电源管理函数的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);

你可能感兴趣的:(高通电源管理函数的power_supply的调用关系)