#define POWER_SUPPLY_SUBSYSTEM "power_supply"
2 底层 调用 power_supply_changed 通过event 通知上层(实际用的是 socket , kobject_uevent), healthd/ 监听 uevent ,然后再去读 power_supply sys 下的节点 /sys/class/power_supply/bq27320-AC 等。这里“bq27320-AC”名字可能区分大小写
system/core/healthd/healthd.cpp:
#define UEVENT_MSG_LEN 2048
static void uevent_event(uint32_t /*epevents*/) {char msg[UEVENT_MSG_LEN+2];
char *cp;
int n;
n = uevent_kernel_multicast_recv(uevent_fd, msg, UEVENT_MSG_LEN);
if (n <= 0)
return;
if (n >= UEVENT_MSG_LEN) /* overflow -- discard */
return;
msg[n] = '\0';
msg[n+1] = '\0';
cp = msg;
while (*cp) {
if ((!strcmp(cp, "SUBSYSTEM=" POWER_SUPPLY_SUBSYSTEM)|| strstr(cp, POWER_SUPPLY_SUBSYSTEM))
&& strstr(cp, "AC")) {
healthd_battery_update();
break;
}
/* advance to after the next \0 */
while (*cp++)
;
}
}
driver code:
static void bq27320_powersupply_init(struct bq27320_device_info *di)
{
di->bat.type = POWER_SUPPLY_TYPE_BATTERY;
di->bat.properties = bq27320_battery_props;
di->bat.num_properties = ARRAY_SIZE(bq27320_battery_props);
di->bat.get_property = bq27320_battery_get_property;
di->ac.name = "bq27320-AC";
di->ac.type = POWER_SUPPLY_TYPE_MAINS;
di->ac.properties = rk3190_ac_props;
di->ac.num_properties = ARRAY_SIZE(rk3190_ac_props);
di->ac.get_property =rk3190_ac_get_property;
}
3,内核启动的时候会一直去读电量,具体在
vim ./drivers/power/rk29_charger_display.c 中的 psy->get_property(psy, POWER_SUPPLY_PROP_CAPACITY, &battery_capacity); 由 ./drivers/cpufreq/rockchip-cpufreq.c 来调用,具体为什么待查。