power: smb349: add callback to update charger
Chandler Zhang [Mon, 12 Mar 2012 09:05:16 +0000 (17:05 +0800)]
Add update_charger_status() function callback to fix unknown
charging status at start up issue.

Bug 951750

Change-Id: Ib264479b0a251a07d136c245afa85c3444754ee0
Signed-off-by: Chandler Zhang <chazhang@nvidia.com>
Reviewed-on: http://git-master/r/89436
Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com>

drivers/power/smb349-charger.c
include/linux/smb349-charger.h

index d6a3ef2..300f919 100644 (file)
@@ -336,6 +336,54 @@ irq_error:
        return IRQ_HANDLED;
 }
 
+int update_charger_status(void)
+{
+       struct i2c_client *client = charger->client;
+       int ret, val;
+
+       val =  smb349_read(client, SMB349_STS_REG_D);
+       if (val < 0) {
+               dev_err(&client->dev, "%s(): Failed in reading register"
+                       "0x%02x\n", __func__, SMB349_STS_REG_D);
+               goto val_error;
+       } else if (val != 0) {
+               if (val & DEDICATED_CHARGER)
+                       charger->chrg_type = AC;
+               else if (val & CHRG_DOWNSTRM_PORT)
+                       charger->chrg_type = USB;
+
+               /* configure charger */
+               ret = smb349_configure_charger(client, 1);
+               if (ret < 0) {
+                       dev_err(&client->dev, "%s() error in configuring"
+                               "charger..\n", __func__);
+                       goto ret_error;
+               }
+
+               charger->state = progress;
+       } else {
+               charger->state = stopped;
+
+               /* Disable charger */
+               ret = smb349_configure_charger(client, 0);
+               if (ret < 0) {
+                       dev_err(&client->dev, "%s() error in configuring"
+                               "charger..\n", __func__);
+                       goto ret_error;
+               }
+       }
+
+       if (charger->charger_cb)
+               charger->charger_cb(charger->state, charger->chrg_type,
+                                               charger->charger_cb_data);
+       return 0;
+val_error:
+       return val;
+ret_error:
+       return ret;
+}
+EXPORT_SYMBOL_GPL(update_charger_status);
+
 int register_callback(charging_callback_t cb, void *args)
 {
        struct smb349_charger *charger_data = charger;
index 311b2f4..ab02b88 100644 (file)
@@ -57,5 +57,6 @@ typedef void (*callback_t)(enum usb_otg_state otg_state, void *args);
  */
 extern int register_callback(charging_callback_t cb, void *args);
 extern int register_otg_callback(callback_t cb, void *args);
+extern int update_charger_status(void);
 
 #endif /*__LINUX_SMB349_CHARGER_H */