arm64: dts: rk3368: fix string error for sdio
[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                 else if (usb20otg_get_status(USB_STATUS_BVABLID))
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                 else if (!usb20otg_get_status(USB_STATUS_BVABLID))
195                         rk_battery_charger_detect_cb(USB_OTG_POWER_ON);
196         }
197 }
198 static void usb20otg_phy_power_down(int power_down)
199 {
200         if (power_down == PHY_POWER_DOWN) {
201                 if (control_usb->linestate_wakeup) {
202                         /* enable otg0_linestate irq */
203                         writel(UOC_HIWORD_UPDATE(0x3, 0x3, 12),
204                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
205                         /* enable otg1_linestate irq */
206                         writel(UOC_HIWORD_UPDATE(0x3, 0x3, 14),
207                                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
208                 }
209         } else if (power_down == PHY_POWER_UP) {
210                 ;
211         }
212 }
213 struct dwc_otg_platform_data usb20otg_pdata_rk3036 = {
214         .phyclk = NULL,
215         .ahbclk = NULL,
216         .busclk = NULL,
217         .phy_status = 0,
218         .hw_init = usb20otg_hw_init,
219         .phy_suspend = usb20otg_phy_suspend,
220         .soft_reset = usb20otg_soft_reset,
221         .clock_init = usb20otg_clock_init,
222         .clock_enable = usb20otg_clock_enable,
223         .get_status = usb20otg_get_status,
224         .power_enable = usb20otg_power_enable,
225         .dwc_otg_uart_mode = dwc_otg_uart_mode,
226         .bc_detect_cb = rk_battery_charger_detect_cb,
227         .phy_power_down = usb20otg_phy_power_down,
228 };
229 #endif
230
231 #ifdef CONFIG_USB20_HOST
232 static void usb20host_hw_init(void)
233 {
234         /* other haredware init,include:
235          * DRV_VBUS GPIO init */
236         if (gpio_is_valid(control_usb->host_gpios->gpio)) {
237                 if (!gpio_get_value(control_usb->host_gpios->gpio))
238                         gpio_set_value(control_usb->host_gpios->gpio, 1);
239         }
240 }
241
242 static void usb20host_phy_suspend(void *pdata, int suspend)
243 {
244         struct dwc_otg_platform_data *usbpdata = pdata;
245
246         if (suspend) {
247                 /* enable soft control */
248                 writel(UOC_HIWORD_UPDATE(0x1d5, 0x1ff, 0),
249                        RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
250                 usbpdata->phy_status = 1;
251         } else {
252                 /* exit suspend */
253                 writel(UOC_HIWORD_UPDATE(0x0, 0x1, 0),
254                        RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
255                 usbpdata->phy_status = 0;
256         }
257 }
258
259 static void usb20host_soft_reset(void *pdata, enum rkusb_rst_flag rst_type)
260 {
261         struct dwc_otg_platform_data *usbpdata = pdata;
262         struct reset_control *rst_host_h, *rst_host_p, *rst_host_c;
263
264         rst_host_h = devm_reset_control_get(usbpdata->dev, "host_ahb");
265         rst_host_p = devm_reset_control_get(usbpdata->dev, "host_phy");
266         rst_host_c = devm_reset_control_get(usbpdata->dev, "host_controller");
267         if (IS_ERR(rst_host_h) || IS_ERR(rst_host_p) || IS_ERR(rst_host_c)) {
268                 dev_err(usbpdata->dev, "Fail to get reset control from dts\n");
269                 return;
270         }
271
272         switch(rst_type) {
273         case RST_POR:
274                 /* PHY reset */
275                 writel(UOC_HIWORD_UPDATE(0x1, 0x3, 0),
276                            RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
277                 reset_control_assert(rst_host_p);
278                 udelay(15);
279                 writel(UOC_HIWORD_UPDATE(0x2, 0x3, 0),
280                            RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
281
282                 udelay(1500);
283                 reset_control_deassert(rst_host_p);
284
285                 /* Controller reset */
286                 reset_control_assert(rst_host_c);
287                 reset_control_assert(rst_host_h);
288
289                 udelay(5);
290
291                 reset_control_deassert(rst_host_c);
292                 reset_control_deassert(rst_host_h);
293                 break;
294
295         default:
296                 break;
297         }
298 }
299
300 static void usb20host_clock_init(void *pdata)
301 {
302         struct dwc_otg_platform_data *usbpdata = pdata;
303         struct clk *ahbclk, *phyclk;
304
305         ahbclk = devm_clk_get(usbpdata->dev, "hclk_usb1");
306         if (IS_ERR(ahbclk)) {
307                 dev_err(usbpdata->dev, "Failed to get hclk_usb1\n");
308                 return;
309         }
310
311         phyclk = devm_clk_get(usbpdata->dev, "clk_usbphy1");
312         if (IS_ERR(phyclk)) {
313                 dev_err(usbpdata->dev, "Failed to get clk_usbphy1\n");
314                 return;
315         }
316
317         usbpdata->phyclk = phyclk;
318         usbpdata->ahbclk = ahbclk;
319 }
320
321 static void usb20host_clock_enable(void *pdata, int enable)
322 {
323         struct dwc_otg_platform_data *usbpdata = pdata;
324
325         if (enable) {
326                 clk_prepare_enable(usbpdata->ahbclk);
327                 clk_prepare_enable(usbpdata->phyclk);
328         } else {
329                 clk_disable_unprepare(usbpdata->ahbclk);
330                 clk_disable_unprepare(usbpdata->phyclk);
331         }
332 }
333
334 static int usb20host_get_status(int id)
335 {
336         int ret = -1;
337         u32 soc_status0 = readl(RK_GRF_VIRT + RK3036_GRF_SOC_STATUS0);
338
339         switch (id) {
340         case USB_STATUS_BVABLID:
341                 /* bvalid in grf */
342                 ret = soc_status0 & (0x1 << 13);
343                 break;
344         case USB_STATUS_DPDM:
345                 /* dpdm in grf */
346                 ret = soc_status0 & (0x3 << 14);
347                 break;
348         case USB_STATUS_ID:
349                 /* id in grf */
350                 ret = 0;
351                 break;
352         case USB_CHIP_ID:
353                 ret = control_usb->chip_id;
354                 break;
355         case USB_REMOTE_WAKEUP:
356                 ret = control_usb->remote_wakeup;
357                 break;
358         case USB_IRQ_WAKEUP:
359                 ret = control_usb->usb_irq_wakeup;
360                 break;
361         default:
362                 break;
363         }
364         return ret;
365 }
366
367 static void usb20host_power_enable(int enable)
368 {
369         if (0 == enable) {
370                 /* disable host_drv power */
371                 /* do not disable power in default */
372         } else if (1 == enable) {
373                 /* enable host_drv power */
374                 if (gpio_is_valid(control_usb->host_gpios->gpio))
375                         gpio_set_value(control_usb->host_gpios->gpio, 1);
376         }
377 }
378
379 struct dwc_otg_platform_data usb20host_pdata_rk3036 = {
380         .phyclk = NULL,
381         .ahbclk = NULL,
382         .busclk = NULL,
383         .phy_status = 0,
384         .hw_init = usb20host_hw_init,
385         .phy_suspend = usb20host_phy_suspend,
386         .soft_reset = usb20host_soft_reset,
387         .clock_init = usb20host_clock_init,
388         .clock_enable = usb20host_clock_enable,
389         .get_status = usb20host_get_status,
390         .power_enable = usb20host_power_enable,
391 };
392 #endif
393
394 #ifdef CONFIG_OF
395 static const struct of_device_id rk_usb_control_id_table[] = {
396         {
397          .compatible = "rockchip,rk3036-usb-control",
398          },
399         {},
400 };
401 #endif
402 /*********************************************************************
403                         rk3036 usb detections
404 *********************************************************************/
405
406 #define WAKE_LOCK_TIMEOUT (HZ * 10)
407 static inline void do_wakeup(struct work_struct *work)
408 {
409         /* wake up the system */
410         rk_send_wakeup_key();
411 }
412
413 static void usb_battery_charger_detect_work(struct work_struct *work)
414 {
415         rk_battery_charger_detect_cb(usb_battery_charger_detect(1));
416 }
417
418 /********** handler for bvalid irq **********/
419 static irqreturn_t bvalid_irq_handler(int irq, void *dev_id)
420 {
421         /* clear irq */
422         writel(UOC_HIWORD_UPDATE(0x1, 0x1, 15),
423                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
424 #ifdef CONFIG_RK_USB_UART
425         /* usb otg dp/dm switch to usb phy */
426         dwc_otg_uart_mode(NULL, PHY_USB_MODE);
427 #endif
428
429         if (control_usb->usb_irq_wakeup) {
430                 wake_lock_timeout(&control_usb->usb_wakelock,
431                                   WAKE_LOCK_TIMEOUT);
432                 schedule_delayed_work(&control_usb->usb_det_wakeup_work,
433                                       HZ / 10);
434         }
435
436         schedule_delayed_work(&control_usb->usb_charger_det_work, HZ / 10);
437
438         return IRQ_HANDLED;
439 }
440
441 /********** Handler for linestate irq **********/
442 static irqreturn_t otg0_linestate_irq_handler(int irq, void *dev_id)
443 {
444         /*
445          * Here is a chip hwrdware bug, when disable/enable
446          * linestate irq bit the state machine will not reset
447          * So here have to add a delay to wait the linestate filter
448          * timer run out (linestate filter time had been set to 100us)
449          */
450         udelay(200);
451
452         /* clear and disable irq */
453         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 12),
454                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
455
456
457         if (control_usb->usb_irq_wakeup) {
458                 wake_lock_timeout(&control_usb->usb_wakelock,
459                                   WAKE_LOCK_TIMEOUT);
460         }
461
462         return IRQ_HANDLED;
463 }
464
465 static irqreturn_t otg1_linestate_irq_handler(int irq, void *dev_id)
466 {
467         /*
468          * Here is a chip hwrdware bug, when disable/enable
469          * linestate irq bit the state machine will not reset
470          * So here have to add a delay to wait the linestate filter
471          * timer run out (linestate filter time had been set to 100us)
472          */
473         udelay(200);
474
475         /* clear and disable irq */
476         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 14),
477                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
478
479
480         if (control_usb->usb_irq_wakeup) {
481                 wake_lock_timeout(&control_usb->usb_wakelock,
482                                   WAKE_LOCK_TIMEOUT);
483         }
484
485         return IRQ_HANDLED;
486 }
487 /************* register usb detection irqs **************/
488 static int otg_irq_detect_init(struct platform_device *pdev)
489 {
490         int ret = 0;
491         int irq = 0;
492
493         if (control_usb->usb_irq_wakeup) {
494                 wake_lock_init(&control_usb->usb_wakelock, WAKE_LOCK_SUSPEND,
495                                "usb_detect");
496                 INIT_DELAYED_WORK(&control_usb->usb_det_wakeup_work, do_wakeup);
497         }
498
499         /*register otg_bvalid irq */
500         irq = platform_get_irq_byname(pdev, "otg_bvalid");
501         if ((irq > 0) && control_usb->usb_irq_wakeup) {
502                 ret = request_irq(irq, bvalid_irq_handler,
503                                   0, "otg_bvalid", NULL);
504                 if (ret < 0) {
505                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
506                 } else {
507                         /* enable bvalid irq  */
508                         writel(UOC_HIWORD_UPDATE(0x1, 0x1, 14),
509                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
510                 }
511         }
512
513         if (!control_usb->linestate_wakeup)
514                 return 0;
515
516         /* Set otg0&1_linestate_filter time to 100us */
517         writel(UOC_HIWORD_UPDATE(0x0, 0xf, 6), RK_GRF_VIRT + 0x1a0);
518
519         /* Register otg0_linestate irq */
520         irq = platform_get_irq_byname(pdev, "otg0_linestate");
521         if (irq > 0) {
522                 ret = request_irq(irq, otg0_linestate_irq_handler,
523                                   0, "otg0_linestate", NULL);
524                 if (ret < 0) {
525                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
526                 } else {
527                         /* Clear otg0_linestate irq  */
528                         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 12),
529                                RK_GRF_VIRT + RK3036_GRF_UOC0_CON5);
530                 }
531         }
532
533         /* Register otg1_linestate irq */
534         irq = platform_get_irq_byname(pdev, "otg1_linestate");
535         if (irq > 0) {
536                 ret = request_irq(irq, otg1_linestate_irq_handler,
537                                   0, "otg1_linestate", NULL);
538                 if (ret < 0) {
539                         dev_err(&pdev->dev, "request_irq %d failed!\n", irq);
540                 } else {
541                         /* Clear otg1_linestate irq  */
542                         writel(UOC_HIWORD_UPDATE(0x2, 0x3, 14),
543                                RK_GRF_VIRT + RK3036_GRF_UOC1_CON5);
544                 }
545         }
546         return ret;
547 }
548
549 /********** end of rk3036 usb detections **********/
550 static int rk_usb_control_probe(struct platform_device *pdev)
551 {
552         int gpio, err;
553         struct device_node *np = pdev->dev.of_node;
554         int ret = 0;
555
556         control_usb =
557             devm_kzalloc(&pdev->dev, sizeof(*control_usb), GFP_KERNEL);
558         if (!control_usb) {
559                 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
560                 ret = -ENOMEM;
561                 goto out;
562         }
563
564         control_usb->chip_id = RK3036_USB_CTLR;
565         control_usb->remote_wakeup = of_property_read_bool(np,
566                                                            "rockchip,remote_wakeup");
567         control_usb->usb_irq_wakeup = of_property_read_bool(np,
568                                                             "rockchip,usb_irq_wakeup");
569         control_usb->linestate_wakeup = of_property_read_bool(np,
570                                                               "rockchip,linestate_wakeup");
571
572         INIT_DELAYED_WORK(&control_usb->usb_charger_det_work,
573                           usb_battery_charger_detect_work);
574
575         control_usb->host_gpios =
576             devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
577         if (!control_usb->host_gpios) {
578                 dev_err(&pdev->dev, "unable to alloc memory for host_gpios\n");
579                 ret = -ENOMEM;
580                 goto out;
581         }
582
583         gpio = of_get_named_gpio(np, "host_drv_gpio", 0);
584         control_usb->host_gpios->gpio = gpio;
585
586         if (!gpio_is_valid(gpio)) {
587                 dev_err(&pdev->dev, "invalid host gpio%d\n", gpio);
588         } else {
589                 err = devm_gpio_request(&pdev->dev, gpio, "host_drv_gpio");
590                 if (err) {
591                         dev_err(&pdev->dev,
592                                 "failed to request GPIO%d for host_drv\n",
593                                 gpio);
594                         ret = err;
595                         goto out;
596                 }
597                 gpio_direction_output(control_usb->host_gpios->gpio, 1);
598         }
599
600         control_usb->otg_gpios =
601             devm_kzalloc(&pdev->dev, sizeof(struct gpio), GFP_KERNEL);
602         if (!control_usb->otg_gpios) {
603                 dev_err(&pdev->dev, "unable to alloc memory for otg_gpios\n");
604                 ret = -ENOMEM;
605                 goto out;
606         }
607
608         gpio = of_get_named_gpio(np, "otg_drv_gpio", 0);
609         control_usb->otg_gpios->gpio = gpio;
610
611         if (!gpio_is_valid(gpio)) {
612                 dev_err(&pdev->dev, "invalid otg gpio%d\n", gpio);
613         } else {
614                 err = devm_gpio_request(&pdev->dev, gpio, "otg_drv_gpio");
615                 if (err) {
616                         dev_err(&pdev->dev,
617                                 "failed to request GPIO%d for otg_drv\n", gpio);
618                         ret = err;
619                         goto out;
620                 }
621                 gpio_direction_output(control_usb->otg_gpios->gpio, 0);
622         }
623
624 out:
625         return ret;
626 }
627
628 static int rk_usb_control_remove(struct platform_device *pdev)
629 {
630         return 0;
631 }
632
633 static struct platform_driver rk_usb_control_driver = {
634         .probe = rk_usb_control_probe,
635         .remove = rk_usb_control_remove,
636         .driver = {
637                    .name = "rk3036-usb-control",
638                    .owner = THIS_MODULE,
639                    .of_match_table = of_match_ptr(rk_usb_control_id_table),
640                    },
641 };
642
643 #ifdef CONFIG_OF
644
645 static const struct of_device_id dwc_otg_control_usb_id_table[] = {
646         {
647          .compatible = "rockchip,rk3036-dwc-control-usb",
648          },
649         {},
650 };
651
652 #endif
653 static int dwc_otg_control_usb_probe(struct platform_device *pdev)
654 {
655         struct clk *hclk_usb_peri;
656         int ret = 0;
657
658         if (!control_usb) {
659                 dev_err(&pdev->dev, "unable to alloc memory for control usb\n");
660                 ret = -ENOMEM;
661                 goto err1;
662         }
663
664         hclk_usb_peri = devm_clk_get(&pdev->dev, "hclk_usb_peri");
665         if (IS_ERR(hclk_usb_peri)) {
666                 dev_err(&pdev->dev, "Failed to get hclk_usb_peri\n");
667                 ret = -EINVAL;
668                 goto err1;
669         }
670
671         control_usb->hclk_usb_peri = hclk_usb_peri;
672         clk_prepare_enable(hclk_usb_peri);
673
674 #ifdef CONFIG_USB20_OTG
675         if (usb20otg_get_status(USB_STATUS_BVABLID))
676                 schedule_delayed_work(&control_usb->usb_charger_det_work,
677                                       HZ / 10);
678 #endif
679
680         ret = otg_irq_detect_init(pdev);
681         if (ret < 0)
682                 goto err2;
683
684         return 0;
685
686 err2:
687         clk_disable_unprepare(hclk_usb_peri);
688 err1:
689         return ret;
690 }
691
692 static int dwc_otg_control_usb_remove(struct platform_device *pdev)
693 {
694         clk_disable_unprepare(control_usb->hclk_usb_peri);
695         return 0;
696 }
697
698 static struct platform_driver dwc_otg_control_usb_driver = {
699         .probe = dwc_otg_control_usb_probe,
700         .remove = dwc_otg_control_usb_remove,
701         .driver = {
702                    .name = "rk3036-dwc-control-usb",
703                    .owner = THIS_MODULE,
704                    .of_match_table = of_match_ptr(dwc_otg_control_usb_id_table),
705                    },
706 };
707
708 static int __init dwc_otg_control_usb_init(void)
709 {
710         int retval = 0;
711
712         retval |= platform_driver_register(&rk_usb_control_driver);
713         retval |= platform_driver_register(&dwc_otg_control_usb_driver);
714         return retval;
715 }
716
717 subsys_initcall(dwc_otg_control_usb_init);
718
719 static void __exit dwc_otg_control_usb_exit(void)
720 {
721         platform_driver_unregister(&rk_usb_control_driver);
722         platform_driver_unregister(&dwc_otg_control_usb_driver);
723 }
724
725 module_exit(dwc_otg_control_usb_exit);
726 MODULE_ALIAS("platform: dwc_control_usb");
727 MODULE_AUTHOR("RockChip Inc.");
728 MODULE_DESCRIPTION("RockChip Control Module USB Driver");
729 MODULE_LICENSE("GPL v2");
730 #endif