power: pm8921-charger: update userspace per update_time milliseconds
The userspace should be updated periodically to update it with the
charging progress.
Create a delayed_work and schedule it every update_time milliseconds
to notify the userspace that power supply changed. The userspace
is then supposed to read the power supply properties and know about
the charging progress.
CRs-Fixed: 305572
Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
diff --git a/arch/arm/mach-msm/board-msm8960.c b/arch/arm/mach-msm/board-msm8960.c
index 2ec02ef..3654c59 100644
--- a/arch/arm/mach-msm/board-msm8960.c
+++ b/arch/arm/mach-msm/board-msm8960.c
@@ -3611,7 +3611,7 @@
static struct pm8921_charger_platform_data pm8921_chg_pdata __devinitdata = {
.safety_time = 180,
- .update_time = 1,
+ .update_time = 60000,
.max_voltage = 4200,
.min_voltage = 3200,
.resume_voltage = 4100,
diff --git a/drivers/power/pm8921-charger.c b/drivers/power/pm8921-charger.c
index 62bdd58..0f871de 100644
--- a/drivers/power/pm8921-charger.c
+++ b/drivers/power/pm8921-charger.c
@@ -200,6 +200,7 @@
int vin_min;
int *thermal_mitigation;
int thermal_levels;
+ struct delayed_work update_heartbeat_work;
};
static int charging_disabled;
@@ -1417,6 +1418,23 @@
return IRQ_HANDLED;
}
+/**
+ * update_heartbeat - internal function to update userspace
+ * per update_time minutes
+ *
+ */
+static void update_heartbeat(struct work_struct *work)
+{
+ struct delayed_work *dwork = to_delayed_work(work);
+ struct pm8921_chg_chip *chip = container_of(dwork,
+ struct pm8921_chg_chip, update_heartbeat_work);
+
+ power_supply_changed(&chip->batt_psy);
+ schedule_delayed_work(&chip->update_heartbeat_work,
+ round_jiffies_relative(msecs_to_jiffies
+ (chip->update_time)));
+}
+
static void btm_configure_work(struct work_struct *work)
{
int rc;
@@ -2132,6 +2150,13 @@
/* determine what state the charger is in */
determine_initial_state(chip);
+ if (chip->update_time) {
+ INIT_DELAYED_WORK(&chip->update_heartbeat_work,
+ update_heartbeat);
+ schedule_delayed_work(&chip->update_heartbeat_work,
+ round_jiffies_relative(msecs_to_jiffies
+ (chip->update_time)));
+ }
return 0;
free_irq:
diff --git a/include/linux/mfd/pm8xxx/pm8921-charger.h b/include/linux/mfd/pm8xxx/pm8921-charger.h
index 4b74f85..613e57a 100644
--- a/include/linux/mfd/pm8xxx/pm8921-charger.h
+++ b/include/linux/mfd/pm8xxx/pm8921-charger.h
@@ -27,7 +27,7 @@
* struct pm8921_charger_platform_data -
* @safety_time: max charging time in minutes
* @ttrkl_time: max trckl charging time in minutes
- * @update_time: how often the userland be updated of the charging
+ * @update_time: how often the userland be updated of the charging (msec)
* @max_voltage: the max voltage (mV) the battery should be charged up to
* @min_voltage: the voltage (mV) where charging method switches from
* trickle to fast. This is also the minimum voltage the