usb: dwc_otg_310: support vbus controlled by both gpio and pmic
[firefly-linux-kernel-4.4.55.git] / drivers / usb / dwc_otg_310 / usbdev_rk3036.c
1 #ifdef CONFIG_ARM
2 #include "usbdev_rk.h"
3 #include "usbdev_grf_regs.h"
4 #include "dwc_otg_regs.h"
5 static struct dwc_otg_control_usb *control_usb;
6
7 #ifdef CONFIG_USB20_OTG
8 static void usb20otg_hw_init(void)
9 {
10         /* other haredware init,include:
11          * DRV_VBUS GPIO init */
12         if (gpio_is_valid(control_usb->otg_gpios->gpio)) {
13                 if (gpio_get_value(control_usb->otg_gpios->gpio))
14                         gpio_set_value(control_usb->otg_gpios->gpio, 0);
15         }
16 }
17
18 static void usb20otg_phy_suspend(void *pdata, int suspend)
19 {
20         struct dwc_otg_platform_data *usbpdata = pdata;
21
22         if (suspend) {
23                 /* enable soft control */
24                 writel(UOC_HIWORD_UPDATE(0x1d1, 0x1ff, 0),
25                        RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
26                 usbpdata->phy_status = 1;
27         } else {
28                 /* exit suspend */
29                 writel(UOC_HIWORD_UPDATE(0x0, 0x1, 0),
30                        RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
31                 usbpdata->phy_status = 0;
32         }
33 }
34
35 static void usb20otg_soft_reset(void *pdata, enum rkusb_rst_flag rst_type)
36 {
37         struct dwc_otg_platform_data *usbpdata = pdata;
38         struct reset_control *rst_otg_h, *rst_otg_p, *rst_otg_c;
39
40         rst_otg_h = devm_reset_control_get(usbpdata->dev, "otg_ahb");
41         rst_otg_p = devm_reset_control_get(usbpdata->dev, "otg_phy");
42         rst_otg_c = devm_reset_control_get(usbpdata->dev, "otg_controller");
43         if (IS_ERR(rst_otg_h) || IS_ERR(rst_otg_p) || IS_ERR(rst_otg_c)) {
44                 dev_err(usbpdata->dev, "Fail to get reset control from dts\n");
45                 return;
46         }
47
48         switch(rst_type) {
49         case RST_POR:
50                 /* PHY reset */
51                 writel(UOC_HIWORD_UPDATE(0x1, 0x3, 0),
52                            RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
53                 reset_control_assert(rst_otg_p);
54                 udelay(15);
55                 writel(UOC_HIWORD_UPDATE(0x2, 0x3, 0),
56                            RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
57                 udelay(1500);
58                 reset_control_deassert(rst_otg_p);
59                 udelay(2);
60
61                 /* Controller reset */
62                 reset_control_assert(rst_otg_c);
63                 reset_control_assert(rst_otg_h);
64
65                 udelay(2);
66
67                 reset_control_deassert(rst_otg_c);
68                 reset_control_deassert(rst_otg_h);
69                 break;
70
71         default:
72                 break;
73         }
74 }
75
76 static void usb20otg_clock_init(void *pdata)
77 {
78         struct dwc_otg_platform_data *usbpdata = pdata;
79         struct clk *ahbclk, *phyclk;
80
81         ahbclk = devm_clk_get(usbpdata->dev, "hclk_usb0");
82         if (IS_ERR(ahbclk)) {
83                 dev_err(usbpdata->dev, "Failed to get hclk_usb0\n");
84                 return;
85         }
86
87         phyclk = devm_clk_get(usbpdata->dev, "clk_usbphy0");
88         if (IS_ERR(phyclk)) {
89                 dev_err(usbpdata->dev, "Failed to get clk_usbphy0\n");
90                 return;
91         }
92
93         usbpdata->phyclk = phyclk;
94         usbpdata->ahbclk = ahbclk;
95 }
96
97 static void usb20otg_clock_enable(void *pdata, int enable)
98 {
99         struct dwc_otg_platform_data *usbpdata = pdata;
100
101         if (enable) {
102                 clk_prepare_enable(usbpdata->ahbclk);
103                 clk_prepare_enable(usbpdata->phyclk);
104         } else {
105                 clk_disable_unprepare(usbpdata->ahbclk);
106                 /*
107                    clk_disable_unprepare(usbpdata->phyclk);
108                  */
109         }
110 }
111
112 static int usb20otg_get_status(int id)
113 {
114         int ret = -1;
115         u32 soc_status0 = readl(RK_GRF_VIRT + RK3036_GRF_SOC_STATUS0);
116
117         switch (id) {
118         case USB_STATUS_BVABLID:
119                 /* bvalid in grf */
120                 ret = soc_status0 & (0x1 << 8);
121                 break;
122         case USB_STATUS_DPDM:
123                 /* dpdm in grf */
124                 ret = soc_status0 & (0x3 << 9);
125                 break;
126         case USB_STATUS_ID:
127                 /* id in grf */
128                 ret = soc_status0 & (0x1 << 11);
129                 break;
130         case USB_CHIP_ID:
131                 ret = control_usb->chip_id;
132                 break;
133         case USB_REMOTE_WAKEUP:
134                 ret = control_usb->remote_wakeup;
135                 break;
136         case USB_IRQ_WAKEUP:
137                 ret = control_usb->usb_irq_wakeup;
138                 break;
139         default:
140                 break;
141         }
142         return ret;
143 }
144
145 #ifdef CONFIG_RK_USB_UART
146 /**
147  *  dwc_otg_uart_enabled - check if a usb-uart bypass func is enabled in DT
148  *
149  *  Returns true if the status property of node "usb_uart" is set to "okay"
150  *  or "ok", if this property is absent it will use the default status "ok"
151  *  0 otherwise
152  */
153 static bool dwc_otg_uart_enabled(void)
154 {
155         struct device_node *np;
156
157         np = of_find_node_by_name(NULL, "usb_uart");
158         if (np && of_device_is_available(np))
159                 return true;
160
161         return false;
162 }
163
164 static void dwc_otg_uart_mode(void *pdata, int enter_usb_uart_mode)
165 {
166         if ((1 == enter_usb_uart_mode) && dwc_otg_uart_enabled()) {
167                 /* bypass dm, enter uart mode */
168                 writel(UOC_HIWORD_UPDATE(0x3, 0x3, 12), RK_GRF_VIRT + 
169                            RK3036_GRF_UOC1_CON4);
170         } else if (0 == enter_usb_uart_mode) {
171                 /* enter usb mode */
172                 writel(UOC_HIWORD_UPDATE(0x0, 0x3, 12), RK_GRF_VIRT + 
173                            RK3036_GRF_UOC1_CON4);
174         }
175 }
176 #else
177 static void dwc_otg_uart_mode(void *pdata, int enter_usb_uart_mode)
178 {
179 }
180 #endif
181
182 static void usb20otg_power_enable(int enable)
183 {
184         if (0 == enable) {
185                 /* disable otg_drv power */
186                 if (gpio_is_valid(control_usb->otg_gpios->gpio))
187                         gpio_set_value(control_usb->otg_gpios->gpio, 0);
188
189                 rk_battery_charger_detect_cb(USB_OTG_POWER_OFF);
190         } else if (1 == enable) {
191                 /* enable otg_drv power */
192                 if (gpio_is_valid(control_usb->otg_gpios->gpio))
193                         gpio_set_value(control_usb->otg_gpios->gpio, 1);
194
195                 if (!usb20otg_get_status(USB_STATUS_BVABLID))
196                         rk_battery_charger_detect_cb(USB_OTG_POWER_ON);
197         }
198 }
199 static void usb20otg_phy_power_down(int power_down)
200 {
201         if (power_down == PHY_POWER_DOWN) {
202                 if (control_usb->linestate_wakeup) {
203                         /* enable otg0_linestate irq */
204                         writel(UOC_HIWORD_UPDATE(0x3, 0x3, 12),
205                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
206                         /* enable otg1_linestate irq */
207                         writel(UOC_HIWORD_UPDATE(0x3, 0x3, 14),
208                                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
209                 }
210         } else if (power_down == PHY_POWER_UP) {
211                 ;
212         }
213 }
214 struct dwc_otg_platform_data usb20otg_pdata_rk3036 = {
215         .phyclk = NULL,
216         .ahbclk = NULL,
217         .busclk = NULL,
218         .phy_status = 0,
219         .hw_init = usb20otg_hw_init,
220         .phy_suspend = usb20otg_phy_suspend,
221         .soft_reset = usb20otg_soft_reset,
222         .clock_init = usb20otg_clock_init,
223         .clock_enable = usb20otg_clock_enable,
224         .get_status = usb20otg_get_status,
225         .power_enable = usb20otg_power_enable,
226         .dwc_otg_uart_mode = dwc_otg_uart_mode,
227         .bc_detect_cb = rk_battery_charger_detect_cb,
228         .phy_power_down = usb20otg_phy_power_down,
229 };
230 #endif
231
232 #ifdef CONFIG_USB20_HOST
233 static void usb20host_hw_init(void)
234 {
235         /* other haredware init,include:
236          * DRV_VBUS GPIO init */
237         if (gpio_is_valid(control_usb->host_gpios->gpio)) {
238                 if (!gpio_get_value(control_usb->host_gpios->gpio))
239                         gpio_set_value(control_usb->host_gpios->gpio, 1);
240         }
241 }
242
243 static void usb20host_phy_suspend(void *pdata, int suspend)
244 {
245         struct dwc_otg_platform_data *usbpdata = pdata;
246
247         if (suspend) {
248                 /* enable soft control */
249                 writel(UOC_HIWORD_UPDATE(0x1d5, 0x1ff, 0),
250                        RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
251                 usbpdata->phy_status = 1;
252         } else {
253                 /* exit suspend */
254                 writel(UOC_HIWORD_UPDATE(0x0, 0x1, 0),
255                        RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
256                 usbpdata->phy_status = 0;
257         }
258 }
259
260 static void usb20host_soft_reset(void *pdata, enum rkusb_rst_flag rst_type)
261 {
262         struct dwc_otg_platform_data *usbpdata = pdata;
263         struct reset_control *rst_host_h, *rst_host_p, *rst_host_c;
264
265         rst_host_h = devm_reset_control_get(usbpdata->dev, "host_ahb");
266         rst_host_p = devm_reset_control_get(usbpdata->dev, "host_phy");
267         rst_host_c = devm_reset_control_get(usbpdata->dev, "host_controller");
268         if (IS_ERR(rst_host_h) || IS_ERR(rst_host_p) || IS_ERR(rst_host_c)) {
269                 dev_err(usbpdata->dev, "Fail to get reset control from dts\n");
270                 return;
271         }
272
273         switch(rst_type) {
274         case RST_POR:
275                 /* PHY reset */
276                 writel(UOC_HIWORD_UPDATE(0x1, 0x3, 0),
277                            RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
278                 reset_control_assert(rst_host_p);
279                 udelay(15);
280                 writel(UOC_HIWORD_UPDATE(0x2, 0x3, 0),
281                            RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
282
283                 udelay(1500);
284                 reset_control_deassert(rst_host_p);
285
286                 /* Controller reset */
287                 reset_control_assert(rst_host_c);
288                 reset_control_assert(rst_host_h);
289
290                 udelay(5);
291
292                 reset_control_deassert(rst_host_c);
293                 reset_control_deassert(rst_host_h);
294                 break;
295
296         default:
297                 break;
298         }
299 }
300
301 static void usb20host_clock_init(void *pdata)
302 {
303         struct dwc_otg_platform_data *usbpdata = pdata;
304         struct clk *ahbclk, *phyclk;
305
306         ahbclk = devm_clk_get(usbpdata->dev, "hclk_usb1");
307         if (IS_ERR(ahbclk)) {
308                 dev_err(usbpdata->dev, "Failed to get hclk_usb1\n");
309                 return;
310         }
311
312         phyclk = devm_clk_get(usbpdata->dev, "clk_usbphy1");
313         if (IS_ERR(phyclk)) {
314                 dev_err(usbpdata->dev, "Failed to get clk_usbphy1\n");
315                 return;
316         }
317
318         usbpdata->phyclk = phyclk;
319         usbpdata->ahbclk = ahbclk;
320 }
321
322 static void usb20host_clock_enable(void *pdata, int enable)
323 {
324         struct dwc_otg_platform_data *usbpdata = pdata;
325
326         if (enable) {
327                 clk_prepare_enable(usbpdata->ahbclk);
328                 clk_prepare_enable(usbpdata->phyclk);
329         } else {
330                 clk_disable_unprepare(usbpdata->ahbclk);
331                 clk_disable_unprepare(usbpdata->phyclk);
332         }
333 }
334
335 static int usb20host_get_status(int id)
336 {
337         int ret = -1;
338         u32 soc_status0 = readl(RK_GRF_VIRT + RK3036_GRF_SOC_STATUS0);
339
340         switch (id) {
341         case USB_STATUS_BVABLID:
342                 /* bvalid in grf */
343                 ret = soc_status0 & (0x1 << 13);
344                 break;
345         case USB_STATUS_DPDM:
346                 /* dpdm in grf */
347                 ret = soc_status0 & (0x3 << 14);
348                 break;
349         case USB_STATUS_ID:
350                 /* id in grf */
351                 ret = 0;
352                 break;
353         case USB_CHIP_ID:
354                 ret = control_usb->chip_id;
355                 break;
356         case USB_REMOTE_WAKEUP:
357                 ret = control_usb->remote_wakeup;
358                 break;
359         case USB_IRQ_WAKEUP:
360                 ret = control_usb->usb_irq_wakeup;
361                 break;
362         default:
363                 break;
364         }
365         return ret;
366 }
367
368 static void usb20host_power_enable(int enable)
369 {
370         if (0 == enable) {
371                 /* disable host_drv power */
372                 /* do not disable power in default */
373         } else if (1 == enable) {
374                 /* enable host_drv power */
375                 if (gpio_is_valid(control_usb->host_gpios->gpio))
376                         gpio_set_value(control_usb->host_gpios->gpio, 1);
377         }
378 }
379
380 struct dwc_otg_platform_data usb20host_pdata_rk3036 = {
381         .phyclk = NULL,
382         .ahbclk = NULL,
383         .busclk = NULL,
384         .phy_status = 0,
385         .hw_init = usb20host_hw_init,
386         .phy_suspend = usb20host_phy_suspend,
387         .soft_reset = usb20host_soft_reset,
388         .clock_init = usb20host_clock_init,
389         .clock_enable = usb20host_clock_enable,
390         .get_status = usb20host_get_status,
391         .power_enable = usb20host_power_enable,
392 };
393 #endif
394
395 #ifdef CONFIG_OF
396 static const struct of_device_id rk_usb_control_id_table[] = {
397         {
398          .compatible = "rockchip,rk3036-usb-control",
399          },
400         {},
401 };
402 #endif
403 /*********************************************************************
404                         rk3036 usb detections
405 *********************************************************************/
406
407 #define WAKE_LOCK_TIMEOUT (HZ * 10)
408 static inline void do_wakeup(struct work_struct *work)
409 {
410         /* wake up the system */
411         rk_send_wakeup_key();
412 }
413
414 static void usb_battery_charger_detect_work(struct work_struct *work)
415 {
416         rk_battery_charger_detect_cb(usb_battery_charger_detect(1));
417 }
418
419 /********** handler for bvalid irq **********/
420 static irqreturn_t bvalid_irq_handler(int irq, void *dev_id)
421 {
422         /* clear irq */
423         writel(UOC_HIWORD_UPDATE(0x1, 0x1, 15),
424                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
425 #ifdef CONFIG_RK_USB_UART
426         /* usb otg dp/dm switch to usb phy */
427         dwc_otg_uart_mode(NULL, PHY_USB_MODE);
428 #endif
429
430         if (control_usb->usb_irq_wakeup) {
431                 wake_lock_timeout(&control_usb->usb_wakelock,
432                                   WAKE_LOCK_TIMEOUT);
433                 schedule_delayed_work(&control_usb->usb_det_wakeup_work,
434                                       HZ / 10);
435         }
436
437         schedule_delayed_work(&control_usb->usb_charger_det_work, HZ / 10);
438
439         return IRQ_HANDLED;
440 }
441
442 /********** Handler for linestate irq **********/
443 static irqreturn_t otg0_linestate_irq_handler(int irq, void *dev_id)
444 {
445         /*
446          * Here is a chip hwrdware bug, when disable/enable
447          * linestate irq bit the state machine will not reset
448          * So here have to add a delay to wait the linestate filter
449          * timer run out (linestate filter time had been set to 100us)
450          */
451         udelay(200);
452
453         /* clear and disable irq */
454         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 12),
455                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
456
457
458         if (control_usb->usb_irq_wakeup) {
459                 wake_lock_timeout(&control_usb->usb_wakelock,
460                                   WAKE_LOCK_TIMEOUT);
461         }
462
463         return IRQ_HANDLED;
464 }
465
466 static irqreturn_t otg1_linestate_irq_handler(int irq, void *dev_id)
467 {
468         /*
469          * Here is a chip hwrdware bug, when disable/enable
470          * linestate irq bit the state machine will not reset
471          * So here have to add a delay to wait the linestate filter
472          * timer run out (linestate filter time had been set to 100us)
473          */
474         udelay(200);
475
476         /* clear and disable irq */
477         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 14),
478                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
479
480
481         if (control_usb->usb_irq_wakeup) {
482                 wake_lock_timeout(&control_usb->usb_wakelock,
483                                   WAKE_LOCK_TIMEOUT);
484         }
485
486         return IRQ_HANDLED;
487 }
488 /************* register usb detection irqs **************/
489 static int otg_irq_detect_init(struct platform_device *pdev)
490 {
491         int ret = 0;
492         int irq = 0;
493
494         if (control_usb->usb_irq_wakeup) {
495                 wake_lock_init(&control_usb->usb_wakelock, WAKE_LOCK_SUSPEND,
496                                "usb_detect");
497                 INIT_DELAYED_WORK(&control_usb->usb_det_wakeup_work, do_wakeup);
498         }
499
500         /*register otg_bvalid irq */
501         irq = platform_get_irq_byname(pdev, "otg_bvalid");
502         if ((irq > 0) && control_usb->usb_irq_wakeup) {
503                 ret = request_irq(irq, bvalid_irq_handler,
504                                   0, "otg_bvalid", NULL);
505                 if (ret < 0) {
506                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
507                 } else {
508                         /* enable bvalid irq  */
509                         writel(UOC_HIWORD_UPDATE(0x1, 0x1, 14),
510                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
511                 }
512         }
513
514         if (!control_usb->linestate_wakeup)
515                 return 0;
516
517         /* Set otg0&1_linestate_filter time to 100us */
518         writel(UOC_HIWORD_UPDATE(0x0, 0xf, 6), RK_GRF_VIRT + 0x1a0);
519
520         /* Register otg0_linestate irq */
521         irq = platform_get_irq_byname(pdev, "otg0_linestate");
522         if (irq > 0) {
523                 ret = request_irq(irq, otg0_linestate_irq_handler,
524                                   0, "otg0_linestate", NULL);
525                 if (ret < 0) {
526                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
527                 } else {
528                         /* Clear otg0_linestate irq  */
529                         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 12),
530                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
531                 }
532         }
533
534         /* Register otg1_linestate irq */
535         irq = platform_get_irq_byname(pdev, "otg1_linestate");
536         if (irq > 0) {
537                 ret = request_irq(irq, otg1_linestate_irq_handler,
538                                   0, "otg1_linestate", NULL);
539                 if (ret < 0) {
540                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
541                 } else {
542                         /* Clear otg1_linestate irq  */
543                         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 14),
544                                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
545                 }
546         }
547         return ret;
548 }
549
550 /********** end of rk3036 usb detections **********/
551 static int rk_usb_control_probe(struct platform_device *pdev)
552 {
553         int gpio, err;
554         struct device_node *np = pdev->dev.of_node;
555         int ret = 0;
556
557         control_usb =
558             devm_kzalloc(&pdev->dev, sizeof(*control_usb), GFP_KERNEL);
559         if (!control_usb) {
560                 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
561                 ret = -ENOMEM;
562                 goto out;
563         }
564
565         control_usb->chip_id = RK3036_USB_CTLR;
566         control_usb->remote_wakeup = of_property_read_bool(np,
567                                                            "rockchip,remote_wakeup");
568         control_usb->usb_irq_wakeup = of_property_read_bool(np,
569                                                             "rockchip,usb_irq_wakeup");
570         control_usb->linestate_wakeup = of_property_read_bool(np,
571                                                               "rockchip,linestate_wakeup");
572
573         INIT_DELAYED_WORK(&control_usb->usb_charger_det_work,
574                           usb_battery_charger_detect_work);
575
576         control_usb->host_gpios =
577             devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
578         if (!control_usb->host_gpios) {
579                 dev_err(&pdev->dev, "unable to alloc memory for host_gpios\n");
580                 ret = -ENOMEM;
581                 goto out;
582         }
583
584         gpio = of_get_named_gpio(np, "host_drv_gpio", 0);
585         control_usb->host_gpios->gpio = gpio;
586
587         if (!gpio_is_valid(gpio)) {
588                 dev_err(&pdev->dev, "invalid host gpio%d\n", gpio);
589         } else {
590                 err = devm_gpio_request(&pdev->dev, gpio, "host_drv_gpio");
591                 if (err) {
592                         dev_err(&pdev->dev,
593                                 "failed to request GPIO%d for host_drv\n",
594                                 gpio);
595                         ret = err;
596                         goto out;
597                 }
598                 gpio_direction_output(control_usb->host_gpios->gpio, 1);
599         }
600
601         control_usb->otg_gpios =
602             devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
603         if (!control_usb->otg_gpios) {
604                 dev_err(&pdev->dev, "unable to alloc memory for otg_gpios\n");
605                 ret = -ENOMEM;
606                 goto out;
607         }
608
609         gpio = of_get_named_gpio(np, "otg_drv_gpio", 0);
610         control_usb->otg_gpios->gpio = gpio;
611
612         if (!gpio_is_valid(gpio)) {
613                 dev_err(&pdev->dev, "invalid otg gpio%d\n", gpio);
614         } else {
615                 err = devm_gpio_request(&pdev->dev, gpio, "otg_drv_gpio");
616                 if (err) {
617                         dev_err(&pdev->dev,
618                                 "failed to request GPIO%d for otg_drv\n", gpio);
619                         ret = err;
620                         goto out;
621                 }
622                 gpio_direction_output(control_usb->otg_gpios->gpio, 0);
623         }
624
625 out:
626         return ret;
627 }
628
629 static int rk_usb_control_remove(struct platform_device *pdev)
630 {
631         return 0;
632 }
633
634 static struct platform_driver rk_usb_control_driver = {
635         .probe = rk_usb_control_probe,
636         .remove = rk_usb_control_remove,
637         .driver = {
638                    .name = "rk3036-usb-control",
639                    .owner = THIS_MODULE,
640                    .of_match_table = of_match_ptr(rk_usb_control_id_table),
641                    },
642 };
643
644 #ifdef CONFIG_OF
645
646 static const struct of_device_id dwc_otg_control_usb_id_table[] = {
647         {
648          .compatible = "rockchip,rk3036-dwc-control-usb",
649          },
650         {},
651 };
652
653 #endif
654 static int dwc_otg_control_usb_probe(struct platform_device *pdev)
655 {
656         struct clk *hclk_usb_peri;
657         int ret = 0;
658
659         if (!control_usb) {
660                 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
661                 ret = -ENOMEM;
662                 goto err1;
663         }
664
665         hclk_usb_peri = devm_clk_get(&pdev->dev, "hclk_usb_peri");
666         if (IS_ERR(hclk_usb_peri)) {
667                 dev_err(&pdev->dev, "Failed to get hclk_usb_peri\n");
668                 ret = -EINVAL;
669                 goto err1;
670         }
671
672         control_usb->hclk_usb_peri = hclk_usb_peri;
673         clk_prepare_enable(hclk_usb_peri);
674
675 #ifdef CONFIG_USB20_OTG
676         if (usb20otg_get_status(USB_STATUS_BVABLID))
677                 schedule_delayed_work(&control_usb->usb_charger_det_work,
678                                       HZ / 10);
679 #endif
680
681         ret = otg_irq_detect_init(pdev);
682         if (ret < 0)
683                 goto err2;
684
685         return 0;
686
687 err2:
688         clk_disable_unprepare(hclk_usb_peri);
689 err1:
690         return ret;
691 }
692
693 static int dwc_otg_control_usb_remove(struct platform_device *pdev)
694 {
695         clk_disable_unprepare(control_usb->hclk_usb_peri);
696         return 0;
697 }
698
699 static struct platform_driver dwc_otg_control_usb_driver = {
700         .probe = dwc_otg_control_usb_probe,
701         .remove = dwc_otg_control_usb_remove,
702         .driver = {
703                    .name = "rk3036-dwc-control-usb",
704                    .owner = THIS_MODULE,
705                    .of_match_table = of_match_ptr(dwc_otg_control_usb_id_table),
706                    },
707 };
708
709 static int __init dwc_otg_control_usb_init(void)
710 {
711         int retval = 0;
712
713         retval |= platform_driver_register(&rk_usb_control_driver);
714         retval |= platform_driver_register(&dwc_otg_control_usb_driver);
715         return retval;
716 }
717
718 subsys_initcall(dwc_otg_control_usb_init);
719
720 static void __exit dwc_otg_control_usb_exit(void)
721 {
722         platform_driver_unregister(&rk_usb_control_driver);
723         platform_driver_unregister(&dwc_otg_control_usb_driver);
724 }
725
726 module_exit(dwc_otg_control_usb_exit);
727 MODULE_ALIAS("platform: dwc_control_usb");
728 MODULE_AUTHOR("RockChip Inc.");
729 MODULE_DESCRIPTION("RockChip Control Module USB Driver");
730 MODULE_LICENSE("GPL v2");
731 #endif