android - How to find the power supply type through a fuel gauge? -
i trying integrate bq27531 fuel gauge i.mx6 som. schematic this: schematic.png (cropped http://www.ti.com/lit/ds/slusbe7c/slusbe7c.pdf)
as shown in schematic, bq24192 charger not connected system's i2c line. registers in charger can accessed via fuel gauge if necessary. loaded bq27531 driver , battery fuel gauge shows in sysfs:
root@var_mx6:/ # ls /sys/class/power_supply/
bq27531-0
i can read related fuel gauge via sysfs, includes battery capacity, current, voltage, temperature etc. however, cannot type of power supply (battery/ac/usb/wireless). information should come charger.
in batterymonitor.cpp, found sysfs expected show /sys/class/power_supply/ac/
directory when ac power source plugged in.
void batterymonitor::init(struct healthd_config *hc) { string8 path; char pval[property_value_max]; mhealthdconfig = hc; dir* dir = opendir(power_supply_sysfs_path); if (dir == null) { klog_error(log_tag, "could not open %s\n", power_supply_sysfs_path); } else { struct dirent* entry; while ((entry = readdir(dir))) { const char* name = entry->d_name; if (!strcmp(name, ".") || !strcmp(name, "..")) continue; // "type" file in each subdirectory path.clear(); path.appendformat("%s/%s/type", power_supply_sysfs_path, name); switch(readpowersupplytype(path)) { case android_power_supply_type_ac: case android_power_supply_type_usb: case android_power_supply_type_wireless: path.clear(); path.appendformat("%s/%s/online", power_supply_sysfs_path, name); if (access(path.string(), r_ok) == 0) mchargernames.add(string8(name)); break; case android_power_supply_type_battery: mbatterydevicepresent = true; if (mhealthdconfig->batterystatuspath.isempty()) { path.clear(); path.appendformat("%s/%s/status", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterystatuspath = path; } if (mhealthdconfig->batteryhealthpath.isempty()) { path.clear(); path.appendformat("%s/%s/health", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batteryhealthpath = path; } if (mhealthdconfig->batterypresentpath.isempty()) { path.clear(); path.appendformat("%s/%s/present", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterypresentpath = path; } if (mhealthdconfig->batterycapacitypath.isempty()) { path.clear(); path.appendformat("%s/%s/capacity", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterycapacitypath = path; } if (mhealthdconfig->batteryvoltagepath.isempty()) { path.clear(); path.appendformat("%s/%s/voltage_now", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) { mhealthdconfig->batteryvoltagepath = path; } else { path.clear(); path.appendformat("%s/%s/batt_vol", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batteryvoltagepath = path; } } if (mhealthdconfig->batterycurrentnowpath.isempty()) { path.clear(); path.appendformat("%s/%s/current_now", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterycurrentnowpath = path; } if (mhealthdconfig->batterycurrentavgpath.isempty()) { path.clear(); path.appendformat("%s/%s/current_avg", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterycurrentavgpath = path; } if (mhealthdconfig->batterychargecounterpath.isempty()) { path.clear(); path.appendformat("%s/%s/charge_counter", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterychargecounterpath = path; } if (mhealthdconfig->batterytemperaturepath.isempty()) { path.clear(); path.appendformat("%s/%s/temp", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) { mhealthdconfig->batterytemperaturepath = path; } else { path.clear(); path.appendformat("%s/%s/batt_temp", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterytemperaturepath = path; } } if (mhealthdconfig->batterytechnologypath.isempty()) { path.clear(); path.appendformat("%s/%s/technology", power_supply_sysfs_path, name); if (access(path, r_ok) == 0) mhealthdconfig->batterytechnologypath = path; } break; case android_power_supply_type_unknown: break; } } closedir(dir); } // indicates there no charger driver registered. // typically case devices not have battery , // , plugged ac mains. if (!mchargernames.size()) { klog_error(log_tag, "no charger supplies found\n"); mbatteryfixedcapacity = always_plugged_capacity; mbatteryfixedtemperature = fake_battery_temperature; malwayspluggeddevice = true; } if (!mbatterydevicepresent) { klog_warning(log_tag, "no battery devices found\n"); hc->periodic_chores_interval_fast = -1; hc->periodic_chores_interval_slow = -1; } else { if (mhealthdconfig->batterystatuspath.isempty()) klog_warning(log_tag, "batterystatuspath not found\n"); if (mhealthdconfig->batteryhealthpath.isempty()) klog_warning(log_tag, "batteryhealthpath not found\n"); if (mhealthdconfig->batterypresentpath.isempty()) klog_warning(log_tag, "batterypresentpath not found\n"); if (mhealthdconfig->batterycapacitypath.isempty()) klog_warning(log_tag, "batterycapacitypath not found\n"); if (mhealthdconfig->batteryvoltagepath.isempty()) klog_warning(log_tag, "batteryvoltagepath not found\n"); if (mhealthdconfig->batterytemperaturepath.isempty()) klog_warning(log_tag, "batterytemperaturepath not found\n"); if (mhealthdconfig->batterytechnologypath.isempty()) klog_warning(log_tag, "batterytechnologypath not found\n"); } if (property_get("ro.boot.fake_battery", pval, null) > 0 && strtol(pval, null, 10) != 0) { mbatteryfixedcapacity = fake_battery_capacity; mbatteryfixedtemperature = fake_battery_temperature; } }
i not know how ac folder appear under sysfs. there no ac driver far know , cannot load driver charger (bq24192) directly not connected system's i2c bus. how can find out power supply type then? "no charger supplies found" message produced batterymonitor way.
Comments
Post a Comment