power: battery-charger-gauge: Add APIs to start/stop battery thermal monitoring
Laxman Dewangan [Tue, 25 Jun 2013 07:34:40 +0000 (12:34 +0530)]
Add APIs to start and stop battery thermal monitoring. The charger
driver which is client of battery thermal monitoring will start
monitoring when charging cable connected and stop monitoring when
charging cable disconnected.

bug 1259466

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

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

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

index 92a434b..a9cc71e 100644 (file)
@@ -69,6 +69,7 @@ struct battery_charger_thermal_dev {
        struct delayed_work                     poll_temp_monitor_wq;
        int                                     polling_time_sec;
        struct thermal_zone_device              *battery_tz;
+       bool                                    start_monitoring;
 };
 
 static void battery_thermal_check_temperature(struct work_struct *work)
@@ -116,8 +117,9 @@ static void battery_thermal_check_temperature(struct work_struct *work)
                        charger_enable_state, charger_current_half,
                        battery_thersold_voltage);
 
-       schedule_delayed_work(&bct_dev->poll_temp_monitor_wq,
-               msecs_to_jiffies(bct_dev->polling_time_sec * HZ));
+       if (bct_dev->start_monitoring)
+               schedule_delayed_work(&bct_dev->poll_temp_monitor_wq,
+                       msecs_to_jiffies(bct_dev->polling_time_sec * HZ));
        return;
 }
 
@@ -176,6 +178,31 @@ void battery_charger_thermal_unregister(
 }
 EXPORT_SYMBOL_GPL(battery_charger_thermal_unregister);
 
+int battery_charger_thermal_start_monitoring(
+       struct battery_charger_thermal_dev *bct_dev)
+{
+       if (!bct_dev)
+               return -EINVAL;
+
+       bct_dev->start_monitoring = true;
+       schedule_delayed_work(&bct_dev->poll_temp_monitor_wq,
+                       msecs_to_jiffies(bct_dev->polling_time_sec * HZ));
+       return 0;
+}
+EXPORT_SYMBOL_GPL(battery_charger_thermal_start_monitoring);
+
+int battery_charger_thermal_stop_monitoring(
+       struct battery_charger_thermal_dev *bct_dev)
+{
+       if (!bct_dev)
+               return -EINVAL;
+
+       bct_dev->start_monitoring = false;
+       cancel_delayed_work(&bct_dev->poll_temp_monitor_wq);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(battery_charger_thermal_stop_monitoring);
+
 struct battery_charger_dev *battery_charger_register(struct device *dev,
        struct battery_charger_info *bci)
 {
@@ -258,7 +285,6 @@ int battery_charging_status_update(struct battery_charger_dev *bc_dev,
        enum battery_charger_status status)
 {
        struct battery_gauge_dev *node;
-       struct battery_charger_thermal_dev *nbct;
        int ret = -EINVAL;
 
        if (!bc_dev) {
@@ -275,13 +301,6 @@ int battery_charging_status_update(struct battery_charger_dev *bc_dev,
                        ret = node->ops->update_battery_status(node, status);
        }
 
-       list_for_each_entry(nbct, &charger_thermal_map_list, list) {
-               if (nbct->cell_id != bc_dev->cell_id)
-                       continue;
-               schedule_delayed_work(&nbct->poll_temp_monitor_wq,
-                       msecs_to_jiffies(nbct->polling_time_sec * HZ));
-       }
-
        mutex_unlock(&charger_gauge_list_mutex);
        return ret;
 }
index 08a42c6..6759c25 100644 (file)
@@ -75,6 +75,10 @@ struct battery_charger_thermal_dev *battery_charger_thermal_register(
        void *drv_data);
 void battery_charger_thermal_unregister(
        struct battery_charger_thermal_dev *bct_dev);
+int battery_charger_thermal_start_monitoring(
+       struct battery_charger_thermal_dev *bct_dev);
+int battery_charger_thermal_stop_monitoring(
+       struct battery_charger_thermal_dev *bct_dev);
 
 struct battery_gauge_dev *battery_gauge_register(struct device *dev,
                struct battery_gauge_info *bgi);