19 #include <linux/module.h>
20 #include <linux/device.h>
27 #include <linux/slab.h>
32 #include <linux/time.h>
35 #define MILLI_TO_MICRO 1000
36 #define FG_LSB_IN_MA 1627
37 #define QLSB_NANO_AMP_HOURS_X10 1129
38 #define INS_CURR_TIMEOUT (3 * HZ)
40 #define SEC_TO_SAMPLE(S) (S * 4)
42 #define NBR_AVG_SAMPLES 20
44 #define LOW_BAT_CHECK_INTERVAL (2 * HZ)
46 #define VALID_CAPACITY_SEC (45 * 60)
47 #define BATT_OK_MIN 2360
48 #define BATT_OK_INCREMENT 50
49 #define BATT_OK_MAX_NR_INCREMENTS 0xE
54 #define interpolate(x, x1, y1, x2, y2) \
55 ((y1) + ((((y2) - (y1)) * ((x) - (x1))) / ((x2) - (x1))));
57 #define to_ab8500_fg_device_info(x) container_of((x), \
58 struct ab8500_fg, fg_psy);
80 static char *discharge_state[] = {
82 "DISCHARGE_INITMEASURING",
83 "DISCHARGE_INIT_RECOVERY",
85 "DISCHARGE_READOUT_INIT",
95 static char *charge_state[] = {
238 if (list_empty(&ab8500_fg_list))
264 static int ab8500_fg_lowbat_voltage_map[] = {
331 static u8 ab8500_volt_to_regval(
int voltage)
335 if (voltage < ab8500_fg_lowbat_voltage_map[0])
338 for (i = 0; i <
ARRAY_SIZE(ab8500_fg_lowbat_voltage_map); i++) {
339 if (voltage < ab8500_fg_lowbat_voltage_map[i])
344 return (
u8)
ARRAY_SIZE(ab8500_fg_lowbat_voltage_map) - 1;
354 static int ab8500_fg_is_low_curr(
struct ab8500_fg *di,
int curr)
359 if (curr > -di->
bat->fg_params->high_curr_threshold)
409 static void ab8500_fg_clear_cap_samples(
struct ab8500_fg *di)
432 static void ab8500_fg_fill_cap_sample(
struct ab8500_fg *di,
int sample)
459 static int ab8500_fg_coulomb_counter(
struct ab8500_fg *di,
bool enable)
485 di->
flags.fg_enabled =
true;
504 di->
flags.fg_enabled =
false;
507 dev_dbg(di->
dev,
" CC enabled: %d Samples: %d\n",
514 dev_err(di->
dev,
"%s Enabling coulomb counter failed\n", __func__);
606 dev_err(di->
dev,
"completion timed out [%d]\n",
637 val = (low | (high << 8) | 0xFFFFE000);
639 val = (low | (high << 8));
651 (1000 * di->
bat->fg_res);
654 dev_dbg(di->
dev,
"%s Disable FG\n", __func__);
691 dev_err(di->
dev,
"Failed to initialize fg_inst\n");
697 dev_err(di->
dev,
"Failed to finalize fg_inst\n");
743 val = (low | (med << 8) | (high << 16) | 0xFFE00000);
745 val = (low | (med << 8) | (high << 16));
754 (100 * di->
bat->fg_res);
768 di->
flags.conv_done =
true;
777 "Failed to read or write gas gauge registers\n");
788 static int ab8500_fg_bat_voltage(
struct ab8500_fg *di)
796 "%s gpadc conversion failed, using previous value\n",
812 static int ab8500_fg_volt_to_capacity(
struct ab8500_fg *di,
int voltage)
818 tbl = di->
bat->bat_type[di->
bat->batt_id].v_to_cap_tbl,
819 tbl_size = di->
bat->bat_type[di->
bat->batt_id].n_v_cap_tbl_elements;
821 for (i = 0; i < tbl_size; ++
i) {
822 if (voltage > tbl[i].voltage)
826 if ((i > 0) && (i < tbl_size)) {
831 tbl[i-1].capacity * 10);
838 dev_dbg(di->
dev,
"%s Vbat: %d, Cap: %d per mille",
839 __func__, voltage, cap);
851 static int ab8500_fg_uncomp_volt_to_capacity(
struct ab8500_fg *di)
853 di->
vbat = ab8500_fg_bat_voltage(di);
854 return ab8500_fg_volt_to_capacity(di, di->
vbat);
864 static int ab8500_fg_battery_resistance(
struct ab8500_fg *di)
870 tbl = di->
bat->bat_type[di->
bat->batt_id].batres_tbl;
871 tbl_size = di->
bat->bat_type[di->
bat->batt_id].n_batres_tbl_elements;
873 for (i = 0; i < tbl_size; ++
i) {
878 if ((i > 0) && (i < tbl_size)) {
887 resist = tbl[tbl_size - 1].
resist;
890 dev_dbg(di->
dev,
"%s Temp: %d battery internal resistance: %d"
891 " fg resistance %d, total: %d (mOhm)\n",
892 __func__, di->
bat_temp, resist, di->
bat->fg_res / 10,
893 (di->
bat->fg_res / 10) + resist);
896 resist += di->
bat->fg_res / 10;
908 static int ab8500_fg_load_comp_volt_to_capacity(
struct ab8500_fg *di)
917 vbat += ab8500_fg_bat_voltage(di);
925 res = ab8500_fg_battery_resistance(di);
930 dev_dbg(di->
dev,
"%s Measured Vbat: %dmV,Compensated Vbat %dmV, "
931 "R: %dmOhm, Current: %dmA Vbat Samples: %d\n",
934 return ab8500_fg_volt_to_capacity(di, vbat_comp);
944 static int ab8500_fg_convert_mah_to_permille(
struct ab8500_fg *di,
int cap_mah)
946 return (cap_mah * 1000) / di->
bat_cap.max_mah_design;
956 static int ab8500_fg_convert_permille_to_mah(
struct ab8500_fg *di,
int cap_pm)
958 return cap_pm * di->
bat_cap.max_mah_design / 1000;
968 static int ab8500_fg_convert_mah_to_uwh(
struct ab8500_fg *di,
int cap_mah)
974 div_rem =
do_div(div_res, 1000);
977 if (div_rem >= 1000 / 2)
980 return (
int) div_res;
990 static int ab8500_fg_calc_cap_charging(
struct ab8500_fg *di)
992 dev_dbg(di->
dev,
"%s cap_mah %d accu_charge %d\n",
1007 di->
flags.force_full) {
1011 ab8500_fg_fill_cap_sample(di, di->
bat_cap.mah);
1013 ab8500_fg_convert_mah_to_permille(di, di->
bat_cap.mah);
1016 di->
vbat = ab8500_fg_bat_voltage(di);
1031 static int ab8500_fg_calc_cap_discharge_voltage(
struct ab8500_fg *di,
bool comp)
1036 permille = ab8500_fg_load_comp_volt_to_capacity(di);
1038 permille = ab8500_fg_uncomp_volt_to_capacity(di);
1040 mah = ab8500_fg_convert_permille_to_mah(di, permille);
1042 di->
bat_cap.mah = ab8500_fg_add_cap_sample(di, mah);
1044 ab8500_fg_convert_mah_to_permille(di, di->
bat_cap.mah);
1057 static int ab8500_fg_calc_cap_discharge_fg(
struct ab8500_fg *di)
1059 int permille_volt, permille;
1061 dev_dbg(di->
dev,
"%s cap_mah %d accu_charge %d\n",
1079 permille = ab8500_fg_convert_mah_to_permille(di, di->
bat_cap.mah);
1080 permille_volt = ab8500_fg_uncomp_volt_to_capacity(di);
1082 if (permille < permille_volt) {
1083 di->
bat_cap.permille = permille_volt;
1084 di->
bat_cap.mah = ab8500_fg_convert_permille_to_mah(di,
1087 dev_dbg(di->
dev,
"%s voltage based: perm %d perm_volt %d\n",
1092 ab8500_fg_fill_cap_sample(di, di->
bat_cap.mah);
1094 ab8500_fg_fill_cap_sample(di, di->
bat_cap.mah);
1096 ab8500_fg_convert_mah_to_permille(di, di->
bat_cap.mah);
1108 static int ab8500_fg_capacity_level(
struct ab8500_fg *di)
1112 percent = di->
bat_cap.permille / 10;
1114 if (percent <= di->bat->cap_levels->critical ||
1117 else if (percent <= di->bat->cap_levels->low)
1119 else if (percent <= di->bat->cap_levels->normal)
1121 else if (percent <= di->bat->cap_levels->high)
1137 static void ab8500_fg_check_capacity_limits(
struct ab8500_fg *di,
bool init)
1141 di->
bat_cap.level = ab8500_fg_capacity_level(di);
1149 di->
bat_cap.prev_level) || init) {
1150 dev_dbg(di->
dev,
"level changed from %d to %d\n",
1156 dev_dbg(di->
dev,
"level not allowed to go up "
1157 "since no charger is connected: %d to %d\n",
1167 if (di->
flags.low_bat) {
1168 dev_dbg(di->
dev,
"Battery low, set capacity to 0\n");
1174 }
else if (di->
flags.fully_charged) {
1179 if (di->
flags.force_full) {
1182 }
else if (!di->
flags.force_full &&
1184 (di->
bat_cap.permille) / 10 &&
1186 di->
bat->fg_params->maint_thres) {
1188 "battery reported full "
1189 "but capacity dropping: %d\n",
1196 }
else if (di->
bat_cap.prev_percent != di->
bat_cap.permille / 10) {
1197 if (di->
bat_cap.permille / 10 == 0) {
1209 }
else if (!(!di->
flags.charging &&
1211 di->
bat_cap.prev_percent) || init) {
1217 "capacity changed from %d to %d (%d)\n",
1226 dev_dbg(di->
dev,
"capacity not allowed to go up since "
1227 "no charger is connected: %d to %d (%d)\n",
1236 if (di->
flags.fully_charged && di->
flags.force_full) {
1237 dev_dbg(di->
dev,
"Battery full, notifying.\n");
1238 di->
flags.force_full =
false;
1245 static void ab8500_fg_charge_state_to(
struct ab8500_fg *di,
1248 dev_dbg(di->
dev,
"Charge state from %d [%s] to %d [%s]\n",
1252 charge_state[new_state]);
1257 static void ab8500_fg_discharge_state_to(
struct ab8500_fg *di,
1260 dev_dbg(di->
dev,
"Disharge state from %d [%s] to %d [%s]\n",
1264 discharge_state[new_state]);
1275 static void ab8500_fg_algorithm_charging(
struct ab8500_fg *di)
1282 ab8500_fg_discharge_state_to(di,
1288 di->
bat->fg_params->accu_charging);
1290 ab8500_fg_coulomb_counter(di,
true);
1300 if (!di->
flags.conv_done) {
1308 di->
flags.conv_done =
false;
1311 ab8500_fg_calc_cap_charging(di);
1320 ab8500_fg_check_capacity_limits(di,
false);
1323 static void force_capacity(
struct ab8500_fg *di)
1327 ab8500_fg_clear_cap_samples(di);
1329 if (cap > di->
bat_cap.max_mah_design) {
1330 dev_dbg(di->
dev,
"Remaining cap %d can't be bigger than total"
1331 " %d\n", cap, di->
bat_cap.max_mah_design);
1332 cap = di->
bat_cap.max_mah_design;
1334 ab8500_fg_fill_cap_sample(di, di->
bat_cap.user_mah);
1335 di->
bat_cap.permille = ab8500_fg_convert_mah_to_permille(di, cap);
1337 ab8500_fg_check_capacity_limits(di,
true);
1340 static bool check_sysfs_capacity(
struct ab8500_fg *di)
1342 int cap, lower, upper;
1347 cap_permille = ab8500_fg_convert_mah_to_permille(di,
1350 lower = di->
bat_cap.permille - di->
bat->fg_params->user_cap_limit * 10;
1351 upper = di->
bat_cap.permille + di->
bat->fg_params->user_cap_limit * 10;
1360 " (Lower: %d User: %d Upper: %d) [user: %d, was: %d]\n",
1361 lower, cap_permille, upper, cap, di->
bat_cap.mah);
1364 if (cap_permille > lower && cap_permille < upper) {
1365 dev_dbg(di->
dev,
"OK! Using users cap %d uAh now\n", cap);
1369 dev_dbg(di->
dev,
"Capacity from user out of limits, ignoring");
1379 static void ab8500_fg_algorithm_discharging(
struct ab8500_fg *di)
1392 ab8500_fg_coulomb_counter(di,
true);
1393 ab8500_fg_discharge_state_to(di,
1404 sleep_time = di->
bat->fg_params->init_timer;
1408 di->
bat->fg_params->init_discard_time) {
1409 ab8500_fg_calc_cap_discharge_voltage(di,
true);
1411 ab8500_fg_check_capacity_limits(di,
true);
1415 if (di->
init_cnt > di->
bat->fg_params->init_total_time)
1416 ab8500_fg_discharge_state_to(di,
1424 ab8500_fg_discharge_state_to(di,
1430 sleep_time = di->
bat->fg_params->recovery_sleep_timer;
1440 if (ab8500_fg_is_low_curr(di, di->
inst_curr)) {
1442 di->
bat->fg_params->recovery_total_time) {
1444 di->
bat->fg_params->accu_high_curr);
1445 ab8500_fg_coulomb_counter(di,
true);
1446 ab8500_fg_discharge_state_to(di,
1457 di->
bat->fg_params->accu_high_curr);
1458 ab8500_fg_coulomb_counter(di,
true);
1459 ab8500_fg_discharge_state_to(di,
1466 di->
bat->fg_params->accu_high_curr);
1467 ab8500_fg_coulomb_counter(di,
true);
1468 ab8500_fg_discharge_state_to(di,
1475 if (ab8500_fg_is_low_curr(di, di->
inst_curr)) {
1483 ab8500_fg_discharge_state_to(di,
1492 ab8500_fg_calc_cap_discharge_voltage(di,
true);
1495 if (!di->
flags.conv_done) {
1503 di->
flags.conv_done =
false;
1513 di->
bat->fg_params->accu_high_curr;
1515 di->
bat->fg_params->high_curr_time)
1518 ab8500_fg_calc_cap_discharge_fg(di);
1521 ab8500_fg_check_capacity_limits(di,
false);
1526 ab8500_fg_coulomb_counter(di,
true);
1529 ab8500_fg_calc_cap_discharge_voltage(di,
true);
1532 di->
bat->fg_params->accu_high_curr);
1533 ab8500_fg_coulomb_counter(di,
true);
1534 ab8500_fg_discharge_state_to(di,
1537 ab8500_fg_check_capacity_limits(di,
false);
1551 static void ab8500_fg_algorithm_calibrate(
struct ab8500_fg *di)
1557 dev_dbg(di->
dev,
"Calibration ongoing...\n");
1578 di->
flags.calibrate =
false;
1590 dev_err(di->
dev,
"failed to calibrate the CC\n");
1591 di->
flags.calibrate =
false;
1602 static void ab8500_fg_algorithm(
struct ab8500_fg *di)
1604 if (di->
flags.calibrate)
1605 ab8500_fg_algorithm_calibrate(di);
1607 if (di->
flags.charging)
1608 ab8500_fg_algorithm_charging(di);
1610 ab8500_fg_algorithm_discharging(di);
1613 dev_dbg(di->
dev,
"[FG_DATA] %d %d %d %d %d %d %d %d %d "
1614 "%d %d %d %d %d %d %d\n",
1639 static void ab8500_fg_periodic_work(
struct work_struct *work)
1648 ab8500_fg_calc_cap_discharge_voltage(di,
true);
1649 ab8500_fg_check_capacity_limits(di,
true);
1653 }
else if (di->
flags.user_cap) {
1654 if (check_sysfs_capacity(di)) {
1655 ab8500_fg_check_capacity_limits(di,
true);
1656 if (di->
flags.charging)
1657 ab8500_fg_charge_state_to(di,
1660 ab8500_fg_discharge_state_to(di,
1663 di->
flags.user_cap =
false;
1666 ab8500_fg_algorithm(di);
1676 static void ab8500_fg_check_hw_failure_work(
struct work_struct *work)
1688 if (di->
flags.bat_ovv) {
1693 dev_err(di->
dev,
"%s ab8500 read failed\n", __func__);
1696 if ((reg_value &
BATT_OVV) != BATT_OVV) {
1697 dev_dbg(di->
dev,
"Battery recovered from OVV\n");
1698 di->
flags.bat_ovv =
false;
1715 static void ab8500_fg_low_bat_work(
struct work_struct *work)
1722 vbat = ab8500_fg_bat_voltage(di);
1725 if (vbat < di->
bat->fg_params->lowbat_threshold) {
1726 di->
flags.low_bat =
true;
1736 di->
flags.low_bat =
false;
1741 ab8500_fg_check_capacity_limits(di,
false);
1744 di->
flags.low_bat_delay =
false;
1773 static int ab8500_fg_battok_init_hw_register(
struct ab8500_fg *di)
1783 sel0 = di->
bat->fg_params->battok_falling_th_sel0;
1784 sel1 = di->
bat->fg_params->battok_raising_th_sel1;
1786 cbp_sel0 = ab8500_fg_battok_calc(di, sel0);
1787 cbp_sel1 = ab8500_fg_battok_calc(di, sel1);
1791 if (selected != sel0)
1792 dev_warn(di->
dev,
"Invalid voltage step:%d, using %d %d\n",
1793 sel0, selected, cbp_sel0);
1797 if (selected != sel1)
1798 dev_warn(di->
dev,
"Invalid voltage step:%d, using %d %d\n",
1799 sel1, selected, cbp_sel1);
1801 new_val = cbp_sel0 | (cbp_sel1 << 4);
1803 dev_dbg(di->
dev,
"using: %x %d %d\n", new_val, cbp_sel0, cbp_sel1);
1815 static void ab8500_fg_instant_work(
struct work_struct *work)
1819 ab8500_fg_algorithm(di);
1829 static irqreturn_t ab8500_fg_cc_data_end_handler(
int irq,
void *_di)
1843 static irqreturn_t ab8500_fg_cc_int_calib_handler(
int irq,
void *_di)
1858 static irqreturn_t ab8500_fg_cc_convend_handler(
int irq,
void *_di)
1874 static irqreturn_t ab8500_fg_batt_ovv_handler(
int irq,
void *_di)
1879 di->
flags.bat_ovv =
true;
1899 if (!di->
flags.low_bat_delay) {
1900 dev_warn(di->
dev,
"Battery voltage is below LOW threshold\n");
1901 di->
flags.low_bat_delay =
true;
1930 static int ab8500_fg_get_property(
struct power_supply *psy,
1947 if (di->
flags.bat_ovv)
1959 val->
intval = ab8500_fg_convert_mah_to_uwh(di,
1963 val->
intval = ab8500_fg_convert_mah_to_uwh(di,
1967 if (di->
flags.batt_unknown && !di->
bat->chg_unknown_bat &&
1968 di->
flags.batt_id_received)
1969 val->
intval = ab8500_fg_convert_mah_to_uwh(di,
1972 val->
intval = ab8500_fg_convert_mah_to_uwh(di,
1982 if (di->
flags.batt_unknown && !di->
bat->chg_unknown_bat &&
1983 di->
flags.batt_id_received)
1989 if (di->
flags.batt_unknown && !di->
bat->chg_unknown_bat &&
1990 di->
flags.batt_id_received)
1996 if (di->
flags.batt_unknown && !di->
bat->chg_unknown_bat &&
1997 di->
flags.batt_id_received)
2008 static int ab8500_fg_get_ext_psy_data(
struct device *
dev,
void *
data)
2015 bool psy_found =
false;
2043 switch (ext->
type) {
2045 switch (ret.intval) {
2049 if (!di->
flags.charging)
2051 di->
flags.charging =
false;
2052 di->
flags.fully_charged =
false;
2056 if (di->
flags.fully_charged)
2058 di->
flags.fully_charged =
true;
2059 di->
flags.force_full =
true;
2065 if (di->
flags.charging)
2067 di->
flags.charging =
true;
2068 di->
flags.fully_charged =
false;
2077 switch (ext->
type) {
2079 if (!di->
flags.batt_id_received) {
2082 b = &(di->
bat->bat_type[di->
bat->batt_id]);
2084 di->
flags.batt_id_received =
true;
2097 di->
flags.batt_unknown =
false;
2099 di->
flags.batt_unknown =
true;
2106 switch (ext->
type) {
2108 if (di->
flags.batt_id_received)
2128 static int ab8500_fg_init_hw_registers(
struct ab8500_fg *di)
2139 dev_err(di->
dev,
"failed to set BATT_OVV\n");
2150 dev_err(di->
dev,
"failed to enable BATT_OVV\n");
2158 ab8500_volt_to_regval(
2159 di->
bat->fg_params->lowbat_threshold) << 1 |
2162 dev_err(di->
dev,
"%s write failed\n", __func__);
2167 ret = ab8500_fg_battok_init_hw_register(di);
2169 dev_err(di->
dev,
"BattOk init write failed.\n");
2185 static void ab8500_fg_external_power_changed(
struct power_supply *psy)
2190 &di->
fg_psy, ab8500_fg_get_ext_psy_data);
2201 static void ab8500_fg_reinit_work(
struct work_struct *work)
2206 if (di->
flags.calibrate ==
false) {
2207 dev_dbg(di->
dev,
"Resetting FG state machine to init.\n");
2208 ab8500_fg_clear_cap_samples(di);
2209 ab8500_fg_calc_cap_discharge_voltage(di,
true);
2215 dev_err(di->
dev,
"Residual offset calibration ongoing "
2253 unsigned long charge_full;
2258 dev_dbg(di->
dev,
"Ret %zd charge_full %lu", ret, charge_full);
2275 unsigned long charge_now;
2280 dev_dbg(di->
dev,
"Ret %zd charge_now %lu was %d",
2281 ret, charge_now, di->
bat_cap.prev_mah);
2285 di->
flags.user_cap =
true;
2293 __ATTR(charge_full, 0644, charge_full_show, charge_full_store);
2296 __ATTR(charge_now, 0644, charge_now_show, charge_now_store);
2310 return entry->
show(di, buf);
2313 ab8500_fg_store(
struct kobject *kobj,
struct attribute *attr,
const char *buf,
2325 return entry->
store(di, buf, count);
2328 static const struct sysfs_ops ab8500_fg_sysfs_ops = {
2329 .show = ab8500_fg_show,
2330 .store = ab8500_fg_store,
2333 static struct attribute *ab8500_fg_attrs[] = {
2334 &charge_full_attr.
attr,
2335 &charge_now_attr.
attr,
2339 static struct kobj_type ab8500_fg_ktype = {
2340 .sysfs_ops = &ab8500_fg_sysfs_ops,
2341 .default_attrs = ab8500_fg_attrs,
2350 static void ab8500_fg_sysfs_exit(
struct ab8500_fg *di)
2362 static int ab8500_fg_sysfs_init(
struct ab8500_fg *di)
2370 dev_err(di->
dev,
"failed to create sysfs entry\n");
2376 #if defined(CONFIG_PM)
2379 struct ab8500_fg *di = platform_get_drvdata(pdev);
2385 if (!di->
flags.charging) {
2396 struct ab8500_fg *di = platform_get_drvdata(pdev);
2404 if (di->
flags.fg_enabled && !di->
flags.charging)
2405 ab8500_fg_coulomb_counter(di,
false);
2410 #define ab8500_fg_suspend NULL
2411 #define ab8500_fg_resume NULL
2417 struct ab8500_fg *di = platform_get_drvdata(pdev);
2422 ret = ab8500_fg_coulomb_counter(di,
false);
2424 dev_err(di->
dev,
"failed to disable coulomb counter\n");
2427 ab8500_fg_sysfs_exit(di);
2431 platform_set_drvdata(pdev,
NULL);
2438 {
"NCONV_ACCU", ab8500_fg_cc_convend_handler},
2439 {
"BATT_OVV", ab8500_fg_batt_ovv_handler},
2440 {
"LOW_BAT_F", ab8500_fg_lowbatf_handler},
2441 {
"CC_INT_CALIB", ab8500_fg_cc_int_calib_handler},
2442 {
"CCEOC", ab8500_fg_cc_data_end_handler},
2471 dev_err(di->
dev,
"no fg platform data supplied\n");
2473 goto free_device_info;
2479 dev_err(di->
dev,
"no battery platform data supplied\n");
2481 goto free_device_info;
2484 di->
fg_psy.name =
"ab8500_fg";
2486 di->
fg_psy.properties = ab8500_fg_props;
2488 di->
fg_psy.get_property = ab8500_fg_get_property;
2490 di->
fg_psy.num_supplicants = di->
pdata->num_supplicants;
2491 di->
fg_psy.external_power_changed = ab8500_fg_external_power_changed;
2494 di->
bat->bat_type[di->
bat->batt_id].charge_full_design;
2498 di->
vbat_nom = di->
bat->bat_type[di->
bat->batt_id].nominal_voltage;
2508 dev_err(di->
dev,
"failed to create work queue\n");
2510 goto free_device_info;
2521 ab8500_fg_reinit_work);
2525 ab8500_fg_periodic_work);
2529 ab8500_fg_low_bat_work);
2533 ab8500_fg_check_hw_failure_work);
2536 ret = ab8500_fg_init_hw_registers(di);
2538 dev_err(di->
dev,
"failed to initialize registers\n");
2539 goto free_inst_curr_wq;
2543 di->
flags.batt_unknown =
true;
2544 di->
flags.batt_id_received =
false;
2549 dev_err(di->
dev,
"failed to register FG psy\n");
2550 goto free_inst_curr_wq;
2554 ab8500_fg_coulomb_counter(di,
true);
2560 for (i = 0; i <
ARRAY_SIZE(ab8500_fg_irq); i++) {
2564 ab8500_fg_irq[i].
name, di);
2567 dev_err(di->
dev,
"failed to request %s IRQ %d: %d\n"
2568 , ab8500_fg_irq[i].
name, irq, ret);
2571 dev_dbg(di->
dev,
"Requested %s IRQ %d: %d\n",
2572 ab8500_fg_irq[i].
name, irq, ret);
2577 platform_set_drvdata(pdev, di);
2579 ret = ab8500_fg_sysfs_init(di);
2581 dev_err(di->
dev,
"failed to create sysfs entry\n");
2586 di->
flags.calibrate =
true;
2603 for (i = i - 1; i >= 0; i--) {
2616 .probe = ab8500_fg_probe,
2621 .name =
"ab8500-fg",
2626 static int __init ab8500_fg_init(
void)
2631 static void __exit ab8500_fg_exit(
void)