power: rk818-charger: move irq init to the last step
authorchenjh <chenjh@rock-chips.com>
Thu, 18 May 2017 06:58:02 +0000 (14:58 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 19 May 2017 09:48:44 +0000 (17:48 +0800)
init irq later than workqueue_struct and delayed_work to
avoid NULL ponint

Change-Id: I715296a715cb07149a6dce236a3b8ccafe00622e
Signed-off-by: chenjh <chenjh@rock-chips.com>
drivers/power/rk818_charger.c

index 00146303d27ea3aed701796d5e7c480e5f457faa..3bc89d12d27682d5aa96d84707fc1d6be07955e8 100644 (file)
@@ -1379,12 +1379,6 @@ static int rk818_charger_probe(struct platform_device *pdev)
                return ret;
        }
 
-       ret = rk818_cg_init_irqs(cg);
-       if (ret != 0) {
-               dev_err(cg->dev, "init irqs failed!\n");
-               return ret;
-       }
-
        rk818_cg_init_ts2_detect(cg);
 
        ret = rk818_cg_init_dc(cg);
@@ -1407,8 +1401,49 @@ static int rk818_charger_probe(struct platform_device *pdev)
 
        rk818_cg_init_charger_state(cg);
 
+       ret = rk818_cg_init_irqs(cg);
+       if (ret) {
+               dev_err(cg->dev, "init irqs failed!\n");
+               goto irq_fail;
+       }
+
        CG_INFO("driver version: %s\n", DRIVER_VERSION);
 
+       return 0;
+
+irq_fail:
+
+       /* type-c only */
+       if (cg->pdata->extcon) {
+               cancel_delayed_work_sync(&cg->host_work);
+               cancel_delayed_work_sync(&cg->discnt_work);
+       }
+
+       cancel_delayed_work_sync(&cg->usb_work);
+       cancel_delayed_work_sync(&cg->dc_work);
+       cancel_delayed_work_sync(&cg->finish_sig_work);
+       cancel_delayed_work_sync(&cg->irq_work);
+       cancel_delayed_work_sync(&cg->ts2_vol_work);
+       destroy_workqueue(cg->ts2_wq);
+       destroy_workqueue(cg->usb_charger_wq);
+       destroy_workqueue(cg->dc_charger_wq);
+       destroy_workqueue(cg->finish_sig_wq);
+
+       if (cg->pdata->extcon) {
+               extcon_unregister_notifier(cg->cable_edev, EXTCON_CHG_USB_SDP,
+                                          &cg->cable_cg_nb);
+               extcon_unregister_notifier(cg->cable_edev, EXTCON_CHG_USB_DCP,
+                                          &cg->cable_cg_nb);
+               extcon_unregister_notifier(cg->cable_edev, EXTCON_CHG_USB_CDP,
+                                          &cg->cable_cg_nb);
+               extcon_unregister_notifier(cg->cable_edev, EXTCON_USB_VBUS_EN,
+                                          &cg->cable_host_nb);
+               extcon_unregister_notifier(cg->cable_edev, EXTCON_USB,
+                                          &cg->cable_discnt_nb);
+       } else {
+               rk_bc_detect_notifier_unregister(&cg->bc_nb);
+       }
+
        return ret;
 }