summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorinder saluja <isaluja@broadcom.com>2014-09-11 17:52:14 +0000
committerinder saluja <isaluja@broadcom.com>2014-09-11 18:56:10 +0000
commitb78f29198ff0874ff983e89d7b3775d621dcfc0d (patch)
tree846ed432fa92506ee164cf9a9a36fe0bd8484c08
parent4eed6c9e1ca24285b43f3ff86346b5e16fce3963 (diff)
downloadbcm-b78f29198ff0874ff983e89d7b3775d621dcfc0d.tar.gz
Revert "FG: Wrong current sample fix CSP 834010"
This reverts commit 7d5d6c520e486cc7148b13964e886613afd1a536. Change-Id: I56d365ab93ada152bad4b67215e95e39a2b3c3f2
-rw-r--r--drivers/power/bcmpmu-fg.c66
1 files changed, 32 insertions, 34 deletions
diff --git a/drivers/power/bcmpmu-fg.c b/drivers/power/bcmpmu-fg.c
index b9acc25e43b..70b6a635b1f 100644
--- a/drivers/power/bcmpmu-fg.c
+++ b/drivers/power/bcmpmu-fg.c
@@ -72,9 +72,6 @@
#define CRIT_BATT_POLL_TIME_MS (2000)
#define FAKE_BATT_POLL_TIME_MS (60000)
-#define FG_SETTLING_TIME (bcmpmu_fg_sample_rate_to_time\
- (fg->sample_rate) * 5)
-
#define INTERPOLATE_LINEAR(X, Xa, Ya, Xb, Yb) \
(Ya + (((Yb - Ya) * (X - Xa))/(Xb - Xa)))
@@ -361,7 +358,6 @@ struct bcmpmu_fg_data {
int prev_cap_delta;
int max_discharge_current;
bool used_init_cap;
- int init_notifier;
/* for debugging only */
int lock_cnt;
@@ -376,8 +372,7 @@ struct bcmpmu_fg_data {
#endif
#ifdef DEBUG
-#define DEBUG_MASK (BCMPMU_PRINT_ERROR | BCMPMU_PRINT_INIT |\
- BCMPMU_PRINT_FLOW | BCMPMU_PRINT_VERBOSE)
+#define DEBUG_MASK (BCMPMU_PRINT_ERROR | BCMPMU_PRINT_INIT | BCMPMU_PRINT_FLOW)
#else
#define DEBUG_MASK (BCMPMU_PRINT_ERROR | BCMPMU_PRINT_INIT)
#endif
@@ -403,7 +398,6 @@ static int bcmpmu_fg_get_curr_inst(struct bcmpmu_fg_data *fg);
static int bcmpmu_fg_freeze_read(struct bcmpmu_fg_data *fg);
static inline int bcmpmu_fg_sample_rate_to_time(
enum bcmpmu_fg_sample_rate rate);
-static int bcmpmu_fg_register_notifiers(struct bcmpmu_fg_data *fg);
@@ -651,6 +645,11 @@ static int bcmpmu_fg_set_sample_rate(struct bcmpmu_fg_data *fg,
pr_fg(INIT, "set CIC sample rate to %d\n", rate);
+ /**
+ * since we have changed the CIC filter rate, its
+ * better to calibrate the offset for better accuracy
+ */
+ bcmpmu_fg_calibrate_offset(fg, FG_HW_CAL_MODE_FAST);
return ret;
}
@@ -715,16 +714,15 @@ static int bcmpmu_fg_reset(struct bcmpmu_fg_data *fg)
static int bcmpmu_fg_enable_coulb_counter(struct bcmpmu_fg_data *fg,
bool enable)
{
- if (fg->flags.coulb_dis == enable) {
- bcmpmu_fg_reset(fg);
- if (enable) {
- bcmpmu_fg_enable(fg, true);
- fg->flags.coulb_dis = false;
- } else {
- bcmpmu_fg_enable(fg, false);
- fg->flags.coulb_dis = true;
- }
+ bcmpmu_fg_reset(fg);
+ if (enable) {
+ bcmpmu_fg_enable(fg, true);
+ fg->flags.coulb_dis = false;
+ } else {
+ bcmpmu_fg_enable(fg, false);
+ fg->flags.coulb_dis = true;
}
+
return 0;
}
@@ -1199,8 +1197,6 @@ static int bcmpmu_fg_get_curr_inst(struct bcmpmu_fg_data *fg)
pr_fg(FLOW,
"Read time(%llu) < FG samp time(%d)\n",
t_ms, bcmpmu_fg_sample_rate_to_time(fg->sample_rate));
- pr_fg(FLOW, "%s:latch curr_sample=%d\n",
- __func__, last_curr_sample);
return last_curr_sample;
}
@@ -1222,8 +1218,6 @@ static int bcmpmu_fg_get_curr_inst(struct bcmpmu_fg_data *fg)
fg->last_curr_sample =
bcmpmu_fgsmpl_to_curr(fg, smpl_cal[1], smpl_cal[0]);
FG_UNLOCK(fg);
- pr_fg(FLOW, "%s:fg->last_curr_sample=%d\n",
- __func__, fg->last_curr_sample);
return fg->last_curr_sample;
}
@@ -2033,6 +2027,7 @@ static int bcmpmu_fg_event_handler(struct notifier_block *nb,
fg->flags.chrgr_connected = false;
if (fg->bcmpmu->flags & BCMPMU_FG_VF_CTRL)
fg->vf_zone = -1;
+ bcmpmu_fg_calibrate_offset(fg, FG_HW_CAL_MODE_FAST);
} else if (fg->chrgr_type > PMU_CHRGR_TYPE_NONE &&
fg->chrgr_type < PMU_CHRGR_TYPE_MAX) {
pr_fg(FLOW, "charger connected!!\n");
@@ -2041,6 +2036,7 @@ static int bcmpmu_fg_event_handler(struct notifier_block *nb,
bcmpmu_fg_reset_cutoff_cnts(fg);
bcmpmu_fg_enable_coulb_counter(fg, true);
clear_avg_sample_buff(fg);
+ bcmpmu_fg_calibrate_offset(fg, FG_HW_CAL_MODE_FAST);
fg->flags.prev_batt_status = fg->flags.batt_status;
fg->flags.batt_status = POWER_SUPPLY_STATUS_CHARGING;
} else
@@ -2145,7 +2141,6 @@ static void bcmpmu_fg_hw_init(struct bcmpmu_fg_data *fg)
bcmpmu_fg_set_sync_mode(fg, true);
bcmpmu_fg_enable(fg, true);
bcmpmu_fg_calibrate_offset(fg, FG_HW_CAL_MODE_FAST);
- bcmpmu_fg_reset(fg);
}
static int bcmpmu_fg_get_ocv_avg_capacity(struct bcmpmu_fg_data *fg,
@@ -2156,9 +2151,12 @@ static int bcmpmu_fg_get_ocv_avg_capacity(struct bcmpmu_fg_data *fg,
int cap_samples[50];
pr_fg(VERBOSE, "%s\n", __func__);
+ bcmpmu_fg_enable(fg, false);
+ bcmpmu_fg_set_sample_rate(fg, SAMPLE_RATE_8HZ);
+ bcmpmu_fg_enable(fg, true);
do {
- msleep(bcmpmu_fg_sample_rate_to_time(fg->sample_rate));
+ msleep(FG_INIT_CAPACITY_SAMPLE_DELAY);
cap_samples[i] = bcmpmu_fg_get_load_comp_capacity(fg, true);
i++;
} while (i < samples);
@@ -2167,6 +2165,11 @@ static int bcmpmu_fg_get_ocv_avg_capacity(struct bcmpmu_fg_data *fg,
BUG_ON((cap_percentage > 100) || (cap_percentage < 0));
+ bcmpmu_fg_enable(fg, false);
+ bcmpmu_fg_set_sample_rate(fg, SAMPLE_RATE_2HZ);
+ bcmpmu_fg_enable(fg, true);
+ bcmpmu_fg_reset(fg);
+
return cap_percentage;
}
@@ -2865,17 +2868,11 @@ static void bcmpmu_fg_periodic_work(struct work_struct *work)
struct bcmpmu_fg_status_flags flags;
enum bcmpmu_chrgr_type_t chrgr_type;
int data;
- int ret;
FG_LOCK(fg);
flags = fg->flags;
FG_UNLOCK(fg);
- if (!fg->init_notifier) {
- ret = bcmpmu_fg_register_notifiers(fg);
- WARN_ON(ret);
- }
-
/**
* No battery Case (BSI/BCL pin is not connected)
* if battery is not present (booting with power supply
@@ -3212,8 +3209,6 @@ static int bcmpmu_fg_register_notifiers(struct bcmpmu_fg_data *fg)
if (ret)
goto unreg_chrgr_current_nb;
- fg->init_notifier = 1;
-
return 0;
unreg_chrgr_current_nb:
@@ -3913,6 +3908,9 @@ static int bcmpmu_fg_probe(struct platform_device *pdev)
INIT_WORK(&fg->low_batt_irq_work, bcmpmu_fg_low_batt_irq_work);
mutex_init(&fg->mutex);
+ ret = bcmpmu_fg_register_notifiers(fg);
+ if (ret)
+ goto destroy_workq;
#ifdef CONFIG_WD_TAPPER
ret = wd_tapper_add_timeout_req(&fg->wd_tap_node, "fg",
TAPPER_DEFAULT_TIMEOUT);
@@ -3931,7 +3929,6 @@ static int bcmpmu_fg_probe(struct platform_device *pdev)
fg->flags.prev_batt_status = POWER_SUPPLY_STATUS_UNKNOWN;
fg->discharge_state = DISCHARG_STATE_HIGH_BATT;
fg->dummy_bat_cap_lmt = FG_DUMMY_BAT_CAP;
- fg->flags.coulb_dis = true;
fg->flags.init_capacity = true;
fg->crit_cutoff_cap = -1;
@@ -3944,9 +3941,10 @@ static int bcmpmu_fg_probe(struct platform_device *pdev)
} else
pr_fg(INIT, "booting with power supply\n");
- bcmpmu_fg_set_sample_rate(fg, SAMPLE_RATE_4HZ);
+ bcmpmu_fg_set_sample_rate(fg, SAMPLE_RATE_2HZ);
bcmpmu_fg_hw_init(fg);
+
if (!(bcmpmu->flags & BCMPMU_SPA_EN)) {
ret = power_supply_register(&pdev->dev, &fg->psy);
if (ret) {
@@ -4004,8 +4002,8 @@ static int bcmpmu_fg_probe(struct platform_device *pdev)
/**
* Run FG algorithm now
*/
- queue_delayed_work(fg->fg_wq, &fg->fg_periodic_work,
- msecs_to_jiffies(FG_SETTLING_TIME));
+ queue_delayed_work(fg->fg_wq, &fg->fg_periodic_work, 0);
+
#ifdef CONFIG_DEBUG_FS
bcmpmu_fg_debugfs_init(fg);
#endif