power: battery-charger: add support for restart charging
Laxman Dewangan [Tue, 2 Jul 2013 07:35:40 +0000 (12:35 +0530)]
Add API and framework support to re-start charging after sometime
once charger detected as the charging complete.

bug 1275955

Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/244204
(cherry picked from commit 9588d11f231e78261579e969747dcd7eafcee866)

Change-Id: I190fa1bc8d5ad6915f23842533ec9665e16785da
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/253364
Reviewed-by: Automatic_Commit_Validation_User

drivers/power/battery-charger-gauge-comm.c
include/linux/power/battery-charger-gauge-comm.h

index 8ce50fd..e053b3c 100644 (file)
@@ -49,6 +49,7 @@ struct battery_charger_dev {
        struct battery_charging_ops     *ops;
        struct list_head                list;
        void                            *drv_data;
+       struct delayed_work             restart_charging_wq;
 };
 
 struct battery_gauge_dev {
@@ -58,7 +59,7 @@ struct battery_gauge_dev {
        struct battery_gauge_ops        *ops;
        struct list_head                list;
        void                            *drv_data;
-       struct thermal_zone_device              *battery_tz;
+       struct thermal_zone_device      *battery_tz;
 };
 
 struct battery_charger_thermal_dev {
@@ -74,6 +75,20 @@ struct battery_charger_thermal_dev {
        bool                                    start_monitoring;
 };
 
+static void battery_charger_restart_charging_wq(struct work_struct *work)
+{
+       struct battery_charger_dev *bc_dev;
+
+       bc_dev = container_of(work, struct battery_charger_dev,
+                                       restart_charging_wq.work);
+       if (!bc_dev->ops->restart_charging) {
+               dev_err(bc_dev->parent_dev,
+                               "No callback for restart charging\n");
+               return;
+       }
+       bc_dev->ops->restart_charging(bc_dev);
+}
+
 static void battery_thermal_check_temperature(struct work_struct *work)
 {
        struct battery_charger_thermal_dev *bct_dev;
@@ -230,6 +245,9 @@ struct battery_charger_dev *battery_charger_register(struct device *dev,
        bc_dev->ops = bci->bc_ops;
        bc_dev->parent_dev = dev;
        list_add(&bc_dev->list, &charger_list);
+
+       INIT_DELAYED_WORK(&bc_dev->restart_charging_wq,
+                       battery_charger_restart_charging_wq);
        mutex_unlock(&charger_gauge_list_mutex);
        return bc_dev;
 }
@@ -244,6 +262,19 @@ void battery_charger_unregister(struct battery_charger_dev *bc_dev)
 }
 EXPORT_SYMBOL_GPL(battery_charger_unregister);
 
+int battery_charging_restart(struct battery_charger_dev *bc_dev, int after_sec)
+{
+       if (!bc_dev->ops->restart_charging) {
+               dev_err(bc_dev->parent_dev,
+                       "No callback for restart charging\n");
+               return -EINVAL;
+       }
+       schedule_delayed_work(&bc_dev->restart_charging_wq,
+                       msecs_to_jiffies(after_sec * HZ));
+       return 0;
+}
+EXPORT_SYMBOL_GPL(battery_charging_restart);
+
 int battery_gauge_get_battery_temperature(struct battery_gauge_dev *bg_dev,
        int *temp)
 {
index e72befb..481b5ca 100644 (file)
@@ -41,6 +41,7 @@ struct battery_gauge_ops {
 
 struct battery_charging_ops {
        int (*get_charging_status)(struct battery_charger_dev *bc_dev);
+       int (*restart_charging)(struct battery_charger_dev *bc_dev);
 };
 
 struct battery_charger_thermal_ops {
@@ -70,6 +71,9 @@ struct battery_gauge_info {
 struct battery_charger_dev *battery_charger_register(struct device *dev,
                struct battery_charger_info *bci);
 void battery_charger_unregister(struct battery_charger_dev *bc_dev);
+int battery_charging_status_update(struct battery_charger_dev *bc_dev,
+               enum battery_charger_status status);
+int battery_charging_restart(struct battery_charger_dev *bc_dev, int after_sec);
 
 struct battery_charger_thermal_dev *battery_charger_thermal_register(
        struct device *dev, struct battery_charger_thermal_info *bci,
@@ -87,9 +91,6 @@ struct battery_gauge_dev *battery_gauge_register(struct device *dev,
                struct battery_gauge_info *bgi);
 void battery_gauge_unregister(struct battery_gauge_dev *bg_dev);
 
-int battery_charging_status_update(struct battery_charger_dev *bc_dev,
-               enum battery_charger_status status);
-
 void *battery_charger_get_drvdata(struct battery_charger_dev *bc_dev);
 void battery_charger_set_drvdata(struct battery_charger_dev *bc_dev,
                        void *data);