power: charger-manager: Support different polling mode for sleep state.
authorJonghwa Lee <jonghwa3.lee@samsung.com>
Fri, 24 Oct 2014 05:45:02 +0000 (14:45 +0900)
committerChanho Park <chanho61.park@samsung.com>
Tue, 18 Nov 2014 03:01:06 +0000 (12:01 +0900)
Add additional polling mode for sleep state to define different mode with
normal state. With this change, charger-manager can work differently in
normal state or sleep state. e.g, polling aways for normal and polling
only when charing for sleep. If there is no defined polling mode for
sleep state it just follows the normal state's.
In addition to, polling rate is still same in sleep.

Change-Id: I787a3abd646bdc0be81dccbafbd635c22c84951c
Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
drivers/power/charger-manager.c
include/linux/power/charger-manager.h

index c739a89..7f2a57f 100644 (file)
@@ -202,7 +202,15 @@ static bool is_full_charged(struct charger_manager *cm)
  */
 static bool is_polling_required(struct charger_manager *cm)
 {
-       switch (cm->desc->polling_mode) {
+       enum polling_modes polling_mode;
+
+       if (cm_suspended
+               && cm->desc->poll_mode_sleep >= 0)
+               polling_mode = cm->desc->poll_mode_sleep;
+       else
+               polling_mode = cm->desc->poll_mode_normal;
+
+       switch (polling_mode) {
        case CM_POLL_DISABLE:
                return false;
        case CM_POLL_ALWAYS:
@@ -213,7 +221,7 @@ static bool is_polling_required(struct charger_manager *cm)
                return is_charging(cm);
        default:
                dev_warn(cm->dev, "Incorrect polling_mode (%d)\n",
-                        cm->desc->polling_mode);
+                        polling_mode);
        }
 
        return false;
@@ -1054,6 +1062,7 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
        u32 poll_mode = CM_POLL_DISABLE;
        u32 battery_stat = CM_NO_BATTERY;
        int num_chgs = 0;
+       int ret;
 
        desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
        if (!desc)
@@ -1062,7 +1071,11 @@ static struct charger_desc *of_cm_parse_desc(struct device *dev)
        of_property_read_string(np, "cm-name", &desc->psy_name);
 
        of_property_read_u32(np, "cm-poll-mode", &poll_mode);
-       desc->polling_mode = poll_mode;
+       desc->poll_mode_normal = poll_mode;
+
+       /* Polling mode in sleep state */
+       ret = of_property_read_u32(np, "cm-poll-mode-sleep", &poll_mode);
+       desc->poll_mode_sleep = (!ret) ? poll_mode : -EINVAL;
 
        of_property_read_u32(np, "cm-poll-interval",
                                &desc->polling_interval_ms);
index d380ba3..a644a28 100644 (file)
@@ -131,8 +131,10 @@ struct charger_regulator {
 /**
  * struct charger_desc
  * @psy_name: the name of power-supply-class for charger manager
- * @polling_mode:
- *     Determine which polling mode will be used
+ * @poll_mode_normal:
+ *     Determine which polling mode will be used in normal state.
+ * @poll_mode_sleep:
+ *     Determine which polling mode will be used in sleep state.
  * @fullbatt_vchkdrop_uV:
  *     Check voltage drop after the battery is fully charged.
  *     If it has dropped more than fullbatt_vchkdrop_uV
@@ -171,7 +173,8 @@ struct charger_regulator {
 struct charger_desc {
        const char *psy_name;
 
-       enum polling_modes polling_mode;
+       enum polling_modes poll_mode_normal;
+       enum polling_modes poll_mode_sleep;
        unsigned int polling_interval_ms;
 
        unsigned int fullbatt_vchkdrop_uV;