Revert "Revert "MALI: midgard: support sharing regulator with other devices""
[firefly-linux-kernel-4.4.55.git] / drivers / power / bq24296_charger.c
index 528e25c7fe3231c39240f62327fb7f119b510abc..09a8d7f887350abdcbb5698f4908188984f2f4c7 100755 (executable)
@@ -505,13 +505,25 @@ static struct of_device_id bq24296_battery_of_match[] = {
 MODULE_DEVICE_TABLE(of, bq24296_battery_of_match);
 #endif
 
+static int bq24296_battery_suspend(struct i2c_client *client, pm_message_t mesg)
+{
+       cancel_delayed_work_sync(&bq24296_di->usb_detect_work);
+       return 0;
+}
+
+static int bq24296_battery_resume(struct i2c_client *client)
+{
+       schedule_delayed_work(&bq24296_di->usb_detect_work, msecs_to_jiffies(50));
+       return 0;
+}
+
 static int bq24296_battery_probe(struct i2c_client *client,const struct i2c_device_id *id)
 {
        struct bq24296_device_info *di;
        u8 retval = 0;
        struct bq24296_board *pdev;
        struct device_node *bq24296_node;
-       int ret=0,irq=0;
+       int ret = -EINVAL;
        
         DBG("%s,line=%d\n", __func__,__LINE__);
         
@@ -523,7 +535,7 @@ static int bq24296_battery_probe(struct i2c_client *client,const struct i2c_devi
        di = devm_kzalloc(&client->dev,sizeof(*di), GFP_KERNEL);
        if (!di) {
                dev_err(&client->dev, "failed to allocate device info data\n");
-               retval = -ENOMEM;
+               ret = -ENOMEM;
                goto batt_failed_2;
        }
        i2c_set_clientdata(client, di);
@@ -566,8 +578,8 @@ static int bq24296_battery_probe(struct i2c_client *client,const struct i2c_devi
 
 
        if (gpio_is_valid(pdev->chg_irq_pin)){
-               irq = gpio_to_irq(pdev->chg_irq_pin);
-               ret = request_threaded_irq(irq, NULL,chg_irq_func, IRQF_TRIGGER_FALLING| IRQF_ONESHOT, "bq24296_chg_irq", di);
+               pdev->chg_irq = gpio_to_irq(pdev->chg_irq_pin);
+               ret = request_threaded_irq(pdev->chg_irq, NULL, chg_irq_func, IRQF_TRIGGER_FALLING| IRQF_ONESHOT, "bq24296_chg_irq", di);
                if (ret) {
                        ret = -EINVAL;
                        printk("failed to request bq24296_chg_irq\n");
@@ -583,21 +595,20 @@ static int bq24296_battery_probe(struct i2c_client *client,const struct i2c_devi
 err_chgirq_failed:
        free_irq(gpio_to_irq(pdev->chg_irq_pin), NULL);
 batt_failed_2:
-       return retval;
+       return ret;
 }
 
 static void bq24296_battery_shutdown(struct i2c_client *client)
 {
+       struct bq24296_device_info *di = i2c_get_clientdata(client);
 
-       if (gpio_is_valid(bq24296_pdata->chg_irq_pin)){
-       free_irq(gpio_to_irq(bq24296_pdata->chg_irq_pin), NULL);
-       }
-       
+       if (bq24296_pdata->chg_irq)
+               free_irq(bq24296_pdata->chg_irq, di);
 }
+
 static int bq24296_battery_remove(struct i2c_client *client)
 {
-       struct bq24296_device_info *di = i2c_get_clientdata(client);
-       kfree(di);
+
        return 0;
 }
 
@@ -614,6 +625,8 @@ static struct i2c_driver bq24296_battery_driver = {
        .probe = bq24296_battery_probe,
        .remove = bq24296_battery_remove,
        .shutdown = bq24296_battery_shutdown,
+       .suspend = bq24296_battery_suspend,
+       .resume = bq24296_battery_resume,
        .id_table = bq24296_id,
 };