diff options
author | Anton Vorontsov <anton@enomsg.org> | 2013-01-05 20:14:22 -0500 |
---|---|---|
committer | Anton Vorontsov <anton@enomsg.org> | 2013-01-05 20:14:22 -0500 |
commit | 240fbe2347f1bb58c45fe07fd7c1e5ed96e2e983 (patch) | |
tree | 8481027b056197db888e51eae47a8f95931b84cb /drivers/power/ab8500_fg.c | |
parent | 2fbb520d2079186727786b728ebc5bf20fc85520 (diff) | |
parent | 215cf5c93d2deda4df38d0c9b2429ab2e86808a5 (diff) |
Merge branch 'for-anton' of git://git.linaro.org/people/ljones/linux-3.0-ux500
Diffstat (limited to 'drivers/power/ab8500_fg.c')
-rw-r--r-- | drivers/power/ab8500_fg.c | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index b3bf178c3462..3d05c73813c8 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c | |||
@@ -173,7 +173,7 @@ struct inst_curr_result_list { | |||
173 | * @avg_cap: Average capacity filter | 173 | * @avg_cap: Average capacity filter |
174 | * @parent: Pointer to the struct ab8500 | 174 | * @parent: Pointer to the struct ab8500 |
175 | * @gpadc: Pointer to the struct gpadc | 175 | * @gpadc: Pointer to the struct gpadc |
176 | * @bat: Pointer to the abx500_bm platform data | 176 | * @bm: Platform specific battery management information |
177 | * @fg_psy: Structure that holds the FG specific battery properties | 177 | * @fg_psy: Structure that holds the FG specific battery properties |
178 | * @fg_wq: Work queue for running the FG algorithm | 178 | * @fg_wq: Work queue for running the FG algorithm |
179 | * @fg_periodic_work: Work to run the FG algorithm periodically | 179 | * @fg_periodic_work: Work to run the FG algorithm periodically |
@@ -212,7 +212,7 @@ struct ab8500_fg { | |||
212 | struct ab8500_fg_avg_cap avg_cap; | 212 | struct ab8500_fg_avg_cap avg_cap; |
213 | struct ab8500 *parent; | 213 | struct ab8500 *parent; |
214 | struct ab8500_gpadc *gpadc; | 214 | struct ab8500_gpadc *gpadc; |
215 | struct abx500_bm_data *bat; | 215 | struct abx500_bm_data *bm; |
216 | struct power_supply fg_psy; | 216 | struct power_supply fg_psy; |
217 | struct workqueue_struct *fg_wq; | 217 | struct workqueue_struct *fg_wq; |
218 | struct delayed_work fg_periodic_work; | 218 | struct delayed_work fg_periodic_work; |
@@ -355,7 +355,7 @@ static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr) | |||
355 | /* | 355 | /* |
356 | * We want to know if we're in low current mode | 356 | * We want to know if we're in low current mode |
357 | */ | 357 | */ |
358 | if (curr > -di->bat->fg_params->high_curr_threshold) | 358 | if (curr > -di->bm->fg_params->high_curr_threshold) |
359 | return true; | 359 | return true; |
360 | else | 360 | else |
361 | return false; | 361 | return false; |
@@ -484,8 +484,9 @@ static int ab8500_fg_coulomb_counter(struct ab8500_fg *di, bool enable) | |||
484 | di->flags.fg_enabled = true; | 484 | di->flags.fg_enabled = true; |
485 | } else { | 485 | } else { |
486 | /* Clear any pending read requests */ | 486 | /* Clear any pending read requests */ |
487 | ret = abx500_set_register_interruptible(di->dev, | 487 | ret = abx500_mask_and_set_register_interruptible(di->dev, |
488 | AB8500_GAS_GAUGE, AB8500_GASG_CC_CTRL_REG, 0); | 488 | AB8500_GAS_GAUGE, AB8500_GASG_CC_CTRL_REG, |
489 | (RESET_ACCU | READ_REQ), 0); | ||
489 | if (ret) | 490 | if (ret) |
490 | goto cc_err; | 491 | goto cc_err; |
491 | 492 | ||
@@ -647,7 +648,7 @@ int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res) | |||
647 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm | 648 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm |
648 | */ | 649 | */ |
649 | val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) / | 650 | val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) / |
650 | (1000 * di->bat->fg_res); | 651 | (1000 * di->bm->fg_res); |
651 | 652 | ||
652 | if (di->turn_off_fg) { | 653 | if (di->turn_off_fg) { |
653 | dev_dbg(di->dev, "%s Disable FG\n", __func__); | 654 | dev_dbg(di->dev, "%s Disable FG\n", __func__); |
@@ -750,7 +751,7 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) | |||
750 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm | 751 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm |
751 | */ | 752 | */ |
752 | di->accu_charge = (val * QLSB_NANO_AMP_HOURS_X10) / | 753 | di->accu_charge = (val * QLSB_NANO_AMP_HOURS_X10) / |
753 | (100 * di->bat->fg_res); | 754 | (100 * di->bm->fg_res); |
754 | 755 | ||
755 | /* | 756 | /* |
756 | * Convert to unit value in mA | 757 | * Convert to unit value in mA |
@@ -762,7 +763,7 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) | |||
762 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm | 763 | * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm |
763 | */ | 764 | */ |
764 | di->avg_curr = (val * QLSB_NANO_AMP_HOURS_X10 * 36) / | 765 | di->avg_curr = (val * QLSB_NANO_AMP_HOURS_X10 * 36) / |
765 | (1000 * di->bat->fg_res * (di->fg_samples / 4)); | 766 | (1000 * di->bm->fg_res * (di->fg_samples / 4)); |
766 | 767 | ||
767 | di->flags.conv_done = true; | 768 | di->flags.conv_done = true; |
768 | 769 | ||
@@ -814,8 +815,8 @@ static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage) | |||
814 | struct abx500_v_to_cap *tbl; | 815 | struct abx500_v_to_cap *tbl; |
815 | int cap = 0; | 816 | int cap = 0; |
816 | 817 | ||
817 | tbl = di->bat->bat_type[di->bat->batt_id].v_to_cap_tbl, | 818 | tbl = di->bm->bat_type[di->bm->batt_id].v_to_cap_tbl, |
818 | tbl_size = di->bat->bat_type[di->bat->batt_id].n_v_cap_tbl_elements; | 819 | tbl_size = di->bm->bat_type[di->bm->batt_id].n_v_cap_tbl_elements; |
819 | 820 | ||
820 | for (i = 0; i < tbl_size; ++i) { | 821 | for (i = 0; i < tbl_size; ++i) { |
821 | if (voltage > tbl[i].voltage) | 822 | if (voltage > tbl[i].voltage) |
@@ -866,8 +867,8 @@ static int ab8500_fg_battery_resistance(struct ab8500_fg *di) | |||
866 | struct batres_vs_temp *tbl; | 867 | struct batres_vs_temp *tbl; |
867 | int resist = 0; | 868 | int resist = 0; |
868 | 869 | ||
869 | tbl = di->bat->bat_type[di->bat->batt_id].batres_tbl; | 870 | tbl = di->bm->bat_type[di->bm->batt_id].batres_tbl; |
870 | tbl_size = di->bat->bat_type[di->bat->batt_id].n_batres_tbl_elements; | 871 | tbl_size = di->bm->bat_type[di->bm->batt_id].n_batres_tbl_elements; |
871 | 872 | ||
872 | for (i = 0; i < tbl_size; ++i) { | 873 | for (i = 0; i < tbl_size; ++i) { |
873 | if (di->bat_temp / 10 > tbl[i].temp) | 874 | if (di->bat_temp / 10 > tbl[i].temp) |
@@ -888,11 +889,11 @@ static int ab8500_fg_battery_resistance(struct ab8500_fg *di) | |||
888 | 889 | ||
889 | dev_dbg(di->dev, "%s Temp: %d battery internal resistance: %d" | 890 | dev_dbg(di->dev, "%s Temp: %d battery internal resistance: %d" |
890 | " fg resistance %d, total: %d (mOhm)\n", | 891 | " fg resistance %d, total: %d (mOhm)\n", |
891 | __func__, di->bat_temp, resist, di->bat->fg_res / 10, | 892 | __func__, di->bat_temp, resist, di->bm->fg_res / 10, |
892 | (di->bat->fg_res / 10) + resist); | 893 | (di->bm->fg_res / 10) + resist); |
893 | 894 | ||
894 | /* fg_res variable is in 0.1mOhm */ | 895 | /* fg_res variable is in 0.1mOhm */ |
895 | resist += di->bat->fg_res / 10; | 896 | resist += di->bm->fg_res / 10; |
896 | 897 | ||
897 | return resist; | 898 | return resist; |
898 | } | 899 | } |
@@ -1110,14 +1111,14 @@ static int ab8500_fg_capacity_level(struct ab8500_fg *di) | |||
1110 | 1111 | ||
1111 | percent = di->bat_cap.permille / 10; | 1112 | percent = di->bat_cap.permille / 10; |
1112 | 1113 | ||
1113 | if (percent <= di->bat->cap_levels->critical || | 1114 | if (percent <= di->bm->cap_levels->critical || |
1114 | di->flags.low_bat) | 1115 | di->flags.low_bat) |
1115 | ret = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; | 1116 | ret = POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL; |
1116 | else if (percent <= di->bat->cap_levels->low) | 1117 | else if (percent <= di->bm->cap_levels->low) |
1117 | ret = POWER_SUPPLY_CAPACITY_LEVEL_LOW; | 1118 | ret = POWER_SUPPLY_CAPACITY_LEVEL_LOW; |
1118 | else if (percent <= di->bat->cap_levels->normal) | 1119 | else if (percent <= di->bm->cap_levels->normal) |
1119 | ret = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; | 1120 | ret = POWER_SUPPLY_CAPACITY_LEVEL_NORMAL; |
1120 | else if (percent <= di->bat->cap_levels->high) | 1121 | else if (percent <= di->bm->cap_levels->high) |
1121 | ret = POWER_SUPPLY_CAPACITY_LEVEL_HIGH; | 1122 | ret = POWER_SUPPLY_CAPACITY_LEVEL_HIGH; |
1122 | else | 1123 | else |
1123 | ret = POWER_SUPPLY_CAPACITY_LEVEL_FULL; | 1124 | ret = POWER_SUPPLY_CAPACITY_LEVEL_FULL; |
@@ -1182,7 +1183,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) | |||
1182 | di->bat_cap.prev_percent != | 1183 | di->bat_cap.prev_percent != |
1183 | (di->bat_cap.permille) / 10 && | 1184 | (di->bat_cap.permille) / 10 && |
1184 | (di->bat_cap.permille / 10) < | 1185 | (di->bat_cap.permille / 10) < |
1185 | di->bat->fg_params->maint_thres) { | 1186 | di->bm->fg_params->maint_thres) { |
1186 | dev_dbg(di->dev, | 1187 | dev_dbg(di->dev, |
1187 | "battery reported full " | 1188 | "battery reported full " |
1188 | "but capacity dropping: %d\n", | 1189 | "but capacity dropping: %d\n", |
@@ -1284,7 +1285,7 @@ static void ab8500_fg_algorithm_charging(struct ab8500_fg *di) | |||
1284 | switch (di->charge_state) { | 1285 | switch (di->charge_state) { |
1285 | case AB8500_FG_CHARGE_INIT: | 1286 | case AB8500_FG_CHARGE_INIT: |
1286 | di->fg_samples = SEC_TO_SAMPLE( | 1287 | di->fg_samples = SEC_TO_SAMPLE( |
1287 | di->bat->fg_params->accu_charging); | 1288 | di->bm->fg_params->accu_charging); |
1288 | 1289 | ||
1289 | ab8500_fg_coulomb_counter(di, true); | 1290 | ab8500_fg_coulomb_counter(di, true); |
1290 | ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_READOUT); | 1291 | ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_READOUT); |
@@ -1346,8 +1347,8 @@ static bool check_sysfs_capacity(struct ab8500_fg *di) | |||
1346 | cap_permille = ab8500_fg_convert_mah_to_permille(di, | 1347 | cap_permille = ab8500_fg_convert_mah_to_permille(di, |
1347 | di->bat_cap.user_mah); | 1348 | di->bat_cap.user_mah); |
1348 | 1349 | ||
1349 | lower = di->bat_cap.permille - di->bat->fg_params->user_cap_limit * 10; | 1350 | lower = di->bat_cap.permille - di->bm->fg_params->user_cap_limit * 10; |
1350 | upper = di->bat_cap.permille + di->bat->fg_params->user_cap_limit * 10; | 1351 | upper = di->bat_cap.permille + di->bm->fg_params->user_cap_limit * 10; |
1351 | 1352 | ||
1352 | if (lower < 0) | 1353 | if (lower < 0) |
1353 | lower = 0; | 1354 | lower = 0; |
@@ -1387,7 +1388,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1387 | case AB8500_FG_DISCHARGE_INIT: | 1388 | case AB8500_FG_DISCHARGE_INIT: |
1388 | /* We use the FG IRQ to work on */ | 1389 | /* We use the FG IRQ to work on */ |
1389 | di->init_cnt = 0; | 1390 | di->init_cnt = 0; |
1390 | di->fg_samples = SEC_TO_SAMPLE(di->bat->fg_params->init_timer); | 1391 | di->fg_samples = SEC_TO_SAMPLE(di->bm->fg_params->init_timer); |
1391 | ab8500_fg_coulomb_counter(di, true); | 1392 | ab8500_fg_coulomb_counter(di, true); |
1392 | ab8500_fg_discharge_state_to(di, | 1393 | ab8500_fg_discharge_state_to(di, |
1393 | AB8500_FG_DISCHARGE_INITMEASURING); | 1394 | AB8500_FG_DISCHARGE_INITMEASURING); |
@@ -1400,18 +1401,17 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1400 | * samples to get an initial capacity. | 1401 | * samples to get an initial capacity. |
1401 | * Then go to READOUT | 1402 | * Then go to READOUT |
1402 | */ | 1403 | */ |
1403 | sleep_time = di->bat->fg_params->init_timer; | 1404 | sleep_time = di->bm->fg_params->init_timer; |
1404 | 1405 | ||
1405 | /* Discard the first [x] seconds */ | 1406 | /* Discard the first [x] seconds */ |
1406 | if (di->init_cnt > | 1407 | if (di->init_cnt > di->bm->fg_params->init_discard_time) { |
1407 | di->bat->fg_params->init_discard_time) { | ||
1408 | ab8500_fg_calc_cap_discharge_voltage(di, true); | 1408 | ab8500_fg_calc_cap_discharge_voltage(di, true); |
1409 | 1409 | ||
1410 | ab8500_fg_check_capacity_limits(di, true); | 1410 | ab8500_fg_check_capacity_limits(di, true); |
1411 | } | 1411 | } |
1412 | 1412 | ||
1413 | di->init_cnt += sleep_time; | 1413 | di->init_cnt += sleep_time; |
1414 | if (di->init_cnt > di->bat->fg_params->init_total_time) | 1414 | if (di->init_cnt > di->bm->fg_params->init_total_time) |
1415 | ab8500_fg_discharge_state_to(di, | 1415 | ab8500_fg_discharge_state_to(di, |
1416 | AB8500_FG_DISCHARGE_READOUT_INIT); | 1416 | AB8500_FG_DISCHARGE_READOUT_INIT); |
1417 | 1417 | ||
@@ -1426,7 +1426,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1426 | /* Intentional fallthrough */ | 1426 | /* Intentional fallthrough */ |
1427 | 1427 | ||
1428 | case AB8500_FG_DISCHARGE_RECOVERY: | 1428 | case AB8500_FG_DISCHARGE_RECOVERY: |
1429 | sleep_time = di->bat->fg_params->recovery_sleep_timer; | 1429 | sleep_time = di->bm->fg_params->recovery_sleep_timer; |
1430 | 1430 | ||
1431 | /* | 1431 | /* |
1432 | * We should check the power consumption | 1432 | * We should check the power consumption |
@@ -1438,9 +1438,9 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1438 | 1438 | ||
1439 | if (ab8500_fg_is_low_curr(di, di->inst_curr)) { | 1439 | if (ab8500_fg_is_low_curr(di, di->inst_curr)) { |
1440 | if (di->recovery_cnt > | 1440 | if (di->recovery_cnt > |
1441 | di->bat->fg_params->recovery_total_time) { | 1441 | di->bm->fg_params->recovery_total_time) { |
1442 | di->fg_samples = SEC_TO_SAMPLE( | 1442 | di->fg_samples = SEC_TO_SAMPLE( |
1443 | di->bat->fg_params->accu_high_curr); | 1443 | di->bm->fg_params->accu_high_curr); |
1444 | ab8500_fg_coulomb_counter(di, true); | 1444 | ab8500_fg_coulomb_counter(di, true); |
1445 | ab8500_fg_discharge_state_to(di, | 1445 | ab8500_fg_discharge_state_to(di, |
1446 | AB8500_FG_DISCHARGE_READOUT); | 1446 | AB8500_FG_DISCHARGE_READOUT); |
@@ -1453,7 +1453,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1453 | di->recovery_cnt += sleep_time; | 1453 | di->recovery_cnt += sleep_time; |
1454 | } else { | 1454 | } else { |
1455 | di->fg_samples = SEC_TO_SAMPLE( | 1455 | di->fg_samples = SEC_TO_SAMPLE( |
1456 | di->bat->fg_params->accu_high_curr); | 1456 | di->bm->fg_params->accu_high_curr); |
1457 | ab8500_fg_coulomb_counter(di, true); | 1457 | ab8500_fg_coulomb_counter(di, true); |
1458 | ab8500_fg_discharge_state_to(di, | 1458 | ab8500_fg_discharge_state_to(di, |
1459 | AB8500_FG_DISCHARGE_READOUT); | 1459 | AB8500_FG_DISCHARGE_READOUT); |
@@ -1462,7 +1462,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1462 | 1462 | ||
1463 | case AB8500_FG_DISCHARGE_READOUT_INIT: | 1463 | case AB8500_FG_DISCHARGE_READOUT_INIT: |
1464 | di->fg_samples = SEC_TO_SAMPLE( | 1464 | di->fg_samples = SEC_TO_SAMPLE( |
1465 | di->bat->fg_params->accu_high_curr); | 1465 | di->bm->fg_params->accu_high_curr); |
1466 | ab8500_fg_coulomb_counter(di, true); | 1466 | ab8500_fg_coulomb_counter(di, true); |
1467 | ab8500_fg_discharge_state_to(di, | 1467 | ab8500_fg_discharge_state_to(di, |
1468 | AB8500_FG_DISCHARGE_READOUT); | 1468 | AB8500_FG_DISCHARGE_READOUT); |
@@ -1509,9 +1509,9 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1509 | } | 1509 | } |
1510 | 1510 | ||
1511 | di->high_curr_cnt += | 1511 | di->high_curr_cnt += |
1512 | di->bat->fg_params->accu_high_curr; | 1512 | di->bm->fg_params->accu_high_curr; |
1513 | if (di->high_curr_cnt > | 1513 | if (di->high_curr_cnt > |
1514 | di->bat->fg_params->high_curr_time) | 1514 | di->bm->fg_params->high_curr_time) |
1515 | di->recovery_needed = true; | 1515 | di->recovery_needed = true; |
1516 | 1516 | ||
1517 | ab8500_fg_calc_cap_discharge_fg(di); | 1517 | ab8500_fg_calc_cap_discharge_fg(di); |
@@ -1528,7 +1528,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) | |||
1528 | ab8500_fg_calc_cap_discharge_voltage(di, true); | 1528 | ab8500_fg_calc_cap_discharge_voltage(di, true); |
1529 | 1529 | ||
1530 | di->fg_samples = SEC_TO_SAMPLE( | 1530 | di->fg_samples = SEC_TO_SAMPLE( |
1531 | di->bat->fg_params->accu_high_curr); | 1531 | di->bm->fg_params->accu_high_curr); |
1532 | ab8500_fg_coulomb_counter(di, true); | 1532 | ab8500_fg_coulomb_counter(di, true); |
1533 | ab8500_fg_discharge_state_to(di, | 1533 | ab8500_fg_discharge_state_to(di, |
1534 | AB8500_FG_DISCHARGE_READOUT); | 1534 | AB8500_FG_DISCHARGE_READOUT); |
@@ -1721,7 +1721,7 @@ static void ab8500_fg_low_bat_work(struct work_struct *work) | |||
1721 | vbat = ab8500_fg_bat_voltage(di); | 1721 | vbat = ab8500_fg_bat_voltage(di); |
1722 | 1722 | ||
1723 | /* Check if LOW_BAT still fulfilled */ | 1723 | /* Check if LOW_BAT still fulfilled */ |
1724 | if (vbat < di->bat->fg_params->lowbat_threshold) { | 1724 | if (vbat < di->bm->fg_params->lowbat_threshold) { |
1725 | di->flags.low_bat = true; | 1725 | di->flags.low_bat = true; |
1726 | dev_warn(di->dev, "Battery voltage still LOW\n"); | 1726 | dev_warn(di->dev, "Battery voltage still LOW\n"); |
1727 | 1727 | ||
@@ -1779,8 +1779,8 @@ static int ab8500_fg_battok_init_hw_register(struct ab8500_fg *di) | |||
1779 | int ret; | 1779 | int ret; |
1780 | int new_val; | 1780 | int new_val; |
1781 | 1781 | ||
1782 | sel0 = di->bat->fg_params->battok_falling_th_sel0; | 1782 | sel0 = di->bm->fg_params->battok_falling_th_sel0; |
1783 | sel1 = di->bat->fg_params->battok_raising_th_sel1; | 1783 | sel1 = di->bm->fg_params->battok_raising_th_sel1; |
1784 | 1784 | ||
1785 | cbp_sel0 = ab8500_fg_battok_calc(di, sel0); | 1785 | cbp_sel0 = ab8500_fg_battok_calc(di, sel0); |
1786 | cbp_sel1 = ab8500_fg_battok_calc(di, sel1); | 1786 | cbp_sel1 = ab8500_fg_battok_calc(di, sel1); |
@@ -1963,7 +1963,7 @@ static int ab8500_fg_get_property(struct power_supply *psy, | |||
1963 | di->bat_cap.max_mah); | 1963 | di->bat_cap.max_mah); |
1964 | break; | 1964 | break; |
1965 | case POWER_SUPPLY_PROP_ENERGY_NOW: | 1965 | case POWER_SUPPLY_PROP_ENERGY_NOW: |
1966 | if (di->flags.batt_unknown && !di->bat->chg_unknown_bat && | 1966 | if (di->flags.batt_unknown && !di->bm->chg_unknown_bat && |
1967 | di->flags.batt_id_received) | 1967 | di->flags.batt_id_received) |
1968 | val->intval = ab8500_fg_convert_mah_to_uwh(di, | 1968 | val->intval = ab8500_fg_convert_mah_to_uwh(di, |
1969 | di->bat_cap.max_mah); | 1969 | di->bat_cap.max_mah); |
@@ -1978,21 +1978,21 @@ static int ab8500_fg_get_property(struct power_supply *psy, | |||
1978 | val->intval = di->bat_cap.max_mah; | 1978 | val->intval = di->bat_cap.max_mah; |
1979 | break; | 1979 | break; |
1980 | case POWER_SUPPLY_PROP_CHARGE_NOW: | 1980 | case POWER_SUPPLY_PROP_CHARGE_NOW: |
1981 | if (di->flags.batt_unknown && !di->bat->chg_unknown_bat && | 1981 | if (di->flags.batt_unknown && !di->bm->chg_unknown_bat && |
1982 | di->flags.batt_id_received) | 1982 | di->flags.batt_id_received) |
1983 | val->intval = di->bat_cap.max_mah; | 1983 | val->intval = di->bat_cap.max_mah; |
1984 | else | 1984 | else |
1985 | val->intval = di->bat_cap.prev_mah; | 1985 | val->intval = di->bat_cap.prev_mah; |
1986 | break; | 1986 | break; |
1987 | case POWER_SUPPLY_PROP_CAPACITY: | 1987 | case POWER_SUPPLY_PROP_CAPACITY: |
1988 | if (di->flags.batt_unknown && !di->bat->chg_unknown_bat && | 1988 | if (di->flags.batt_unknown && !di->bm->chg_unknown_bat && |
1989 | di->flags.batt_id_received) | 1989 | di->flags.batt_id_received) |
1990 | val->intval = 100; | 1990 | val->intval = 100; |
1991 | else | 1991 | else |
1992 | val->intval = di->bat_cap.prev_percent; | 1992 | val->intval = di->bat_cap.prev_percent; |
1993 | break; | 1993 | break; |
1994 | case POWER_SUPPLY_PROP_CAPACITY_LEVEL: | 1994 | case POWER_SUPPLY_PROP_CAPACITY_LEVEL: |
1995 | if (di->flags.batt_unknown && !di->bat->chg_unknown_bat && | 1995 | if (di->flags.batt_unknown && !di->bm->chg_unknown_bat && |
1996 | di->flags.batt_id_received) | 1996 | di->flags.batt_id_received) |
1997 | val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; | 1997 | val->intval = POWER_SUPPLY_CAPACITY_LEVEL_UNKNOWN; |
1998 | else | 1998 | else |
@@ -2078,7 +2078,7 @@ static int ab8500_fg_get_ext_psy_data(struct device *dev, void *data) | |||
2078 | if (!di->flags.batt_id_received) { | 2078 | if (!di->flags.batt_id_received) { |
2079 | const struct abx500_battery_type *b; | 2079 | const struct abx500_battery_type *b; |
2080 | 2080 | ||
2081 | b = &(di->bat->bat_type[di->bat->batt_id]); | 2081 | b = &(di->bm->bat_type[di->bm->batt_id]); |
2082 | 2082 | ||
2083 | di->flags.batt_id_received = true; | 2083 | di->flags.batt_id_received = true; |
2084 | 2084 | ||
@@ -2155,7 +2155,7 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di) | |||
2155 | AB8500_SYS_CTRL2_BLOCK, | 2155 | AB8500_SYS_CTRL2_BLOCK, |
2156 | AB8500_LOW_BAT_REG, | 2156 | AB8500_LOW_BAT_REG, |
2157 | ab8500_volt_to_regval( | 2157 | ab8500_volt_to_regval( |
2158 | di->bat->fg_params->lowbat_threshold) << 1 | | 2158 | di->bm->fg_params->lowbat_threshold) << 1 | |
2159 | LOW_BAT_ENABLE); | 2159 | LOW_BAT_ENABLE); |
2160 | if (ret) { | 2160 | if (ret) { |
2161 | dev_err(di->dev, "%s write failed\n", __func__); | 2161 | dev_err(di->dev, "%s write failed\n", __func__); |
@@ -2448,6 +2448,7 @@ static char *supply_interface[] = { | |||
2448 | static int ab8500_fg_probe(struct platform_device *pdev) | 2448 | static int ab8500_fg_probe(struct platform_device *pdev) |
2449 | { | 2449 | { |
2450 | struct device_node *np = pdev->dev.of_node; | 2450 | struct device_node *np = pdev->dev.of_node; |
2451 | struct abx500_bm_data *plat = pdev->dev.platform_data; | ||
2451 | struct ab8500_fg *di; | 2452 | struct ab8500_fg *di; |
2452 | int i, irq; | 2453 | int i, irq; |
2453 | int ret = 0; | 2454 | int ret = 0; |
@@ -2457,21 +2458,19 @@ static int ab8500_fg_probe(struct platform_device *pdev) | |||
2457 | dev_err(&pdev->dev, "%s no mem for ab8500_fg\n", __func__); | 2458 | dev_err(&pdev->dev, "%s no mem for ab8500_fg\n", __func__); |
2458 | return -ENOMEM; | 2459 | return -ENOMEM; |
2459 | } | 2460 | } |
2460 | di->bat = pdev->mfd_cell->platform_data; | 2461 | |
2461 | if (!di->bat) { | 2462 | if (!plat) { |
2462 | if (np) { | 2463 | dev_err(&pdev->dev, "no battery management data supplied\n"); |
2463 | ret = bmdevs_of_probe(&pdev->dev, np, &di->bat); | 2464 | return -EINVAL; |
2464 | if (ret) { | 2465 | } |
2465 | dev_err(&pdev->dev, | 2466 | di->bm = plat; |
2466 | "failed to get battery information\n"); | 2467 | |
2467 | return ret; | 2468 | if (np) { |
2468 | } | 2469 | ret = ab8500_bm_of_probe(&pdev->dev, np, di->bm); |
2469 | } else { | 2470 | if (ret) { |
2470 | dev_err(&pdev->dev, "missing dt node for ab8500_fg\n"); | 2471 | dev_err(&pdev->dev, "failed to get battery information\n"); |
2471 | return -EINVAL; | 2472 | return ret; |
2472 | } | 2473 | } |
2473 | } else { | ||
2474 | dev_info(&pdev->dev, "falling back to legacy platform data\n"); | ||
2475 | } | 2474 | } |
2476 | 2475 | ||
2477 | mutex_init(&di->cc_lock); | 2476 | mutex_init(&di->cc_lock); |
@@ -2491,11 +2490,11 @@ static int ab8500_fg_probe(struct platform_device *pdev) | |||
2491 | di->fg_psy.external_power_changed = ab8500_fg_external_power_changed; | 2490 | di->fg_psy.external_power_changed = ab8500_fg_external_power_changed; |
2492 | 2491 | ||
2493 | di->bat_cap.max_mah_design = MILLI_TO_MICRO * | 2492 | di->bat_cap.max_mah_design = MILLI_TO_MICRO * |
2494 | di->bat->bat_type[di->bat->batt_id].charge_full_design; | 2493 | di->bm->bat_type[di->bm->batt_id].charge_full_design; |
2495 | 2494 | ||
2496 | di->bat_cap.max_mah = di->bat_cap.max_mah_design; | 2495 | di->bat_cap.max_mah = di->bat_cap.max_mah_design; |
2497 | 2496 | ||
2498 | di->vbat_nom = di->bat->bat_type[di->bat->batt_id].nominal_voltage; | 2497 | di->vbat_nom = di->bm->bat_type[di->bm->batt_id].nominal_voltage; |
2499 | 2498 | ||
2500 | di->init_capacity = true; | 2499 | di->init_capacity = true; |
2501 | 2500 | ||
@@ -2549,7 +2548,7 @@ static int ab8500_fg_probe(struct platform_device *pdev) | |||
2549 | goto free_inst_curr_wq; | 2548 | goto free_inst_curr_wq; |
2550 | } | 2549 | } |
2551 | 2550 | ||
2552 | di->fg_samples = SEC_TO_SAMPLE(di->bat->fg_params->init_timer); | 2551 | di->fg_samples = SEC_TO_SAMPLE(di->bm->fg_params->init_timer); |
2553 | ab8500_fg_coulomb_counter(di, true); | 2552 | ab8500_fg_coulomb_counter(di, true); |
2554 | 2553 | ||
2555 | /* Initialize completion used to notify completion of inst current */ | 2554 | /* Initialize completion used to notify completion of inst current */ |