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