Merge tag 'lsk-android-14.04' into develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / usb / dwc_otg_310 / dwc_otg_driver.c
1 /* ==========================================================================
2  * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
3  * $Revision: #94 $
4  * $Date: 2012/12/21 $
5  * $Change: 2131568 $
6  *
7  * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
8  * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
9  * otherwise expressly agreed to in writing between Synopsys and you.
10  *
11  * The Software IS NOT an item of Licensed Software or Licensed Product under
12  * any End User Software License Agreement or Agreement for Licensed Product
13  * with Synopsys or any supplement thereto. You are permitted to use and
14  * redistribute this Software in source and binary forms, with or without
15  * modification, provided that redistributions of source code must retain this
16  * notice. You may not view, use, disclose, copy or distribute this file or
17  * any information contained herein except pursuant to this license grant from
18  * Synopsys. If you do not agree with this notice, including the disclaimer
19  * below, then you are not authorized to use the Software.
20  *
21  * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
25  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
31  * DAMAGE.
32  * ========================================================================== */
33
34 /** @file
35  * The dwc_otg_driver module provides the initialization and cleanup entry
36  * points for the DWC_otg driver. This module will be dynamically installed
37  * after Linux is booted using the insmod command. When the module is
38  * installed, the dwc_otg_driver_init function is called. When the module is
39  * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
40  *
41  * This module also defines a data structure for the dwc_otg_driver, which is
42  * used in conjunction with the standard ARM lm_device structure. These
43  * structures allow the OTG driver to comply with the standard Linux driver
44  * model in which devices and drivers are registered with a bus driver. This
45  * has the benefit that Linux can expose attributes of the driver and device
46  * in its special sysfs file system. Users can then read or write files in
47  * this file system to perform diagnostics on the driver components or the
48  * device.
49  */
50
51 #include "dwc_otg_os_dep.h"
52 #include "common_port/dwc_os.h"
53 #include "dwc_otg_dbg.h"
54 #include "dwc_otg_driver.h"
55 #include "dwc_otg_attr.h"
56 #include "dwc_otg_core_if.h"
57 #include "dwc_otg_pcd_if.h"
58 #include "dwc_otg_hcd_if.h"
59 #include "dwc_otg_cil.h"
60 #include "dwc_otg_pcd.h"
61
62 #include "usbdev_rk.h"
63
64 #define DWC_DRIVER_VERSION      "3.10a 21-DEC-2012"
65 #define DWC_DRIVER_DESC         "HS OTG USB Controller driver"
66
67 static const char dwc_host20_driver_name[] = "usb20_host";
68 static const char dwc_otg20_driver_name[]  = "usb20_otg";
69
70 dwc_otg_device_t* g_otgdev = NULL;
71
72 extern int pcd_init( struct platform_device *_dev );
73 extern int otg20_hcd_init( struct platform_device *_dev );
74 extern int host20_hcd_init( struct platform_device *_dev );
75 extern int pcd_remove(     struct platform_device *_dev );
76 extern void hcd_remove(     struct platform_device *_dev);
77 extern void dwc_otg_adp_start( dwc_otg_core_if_t * core_if, uint8_t is_host);
78
79 #ifdef CONFIG_USB20_OTG
80 static struct usb20otg_pdata_id usb20otg_pdata[] = {
81         {
82                 .name = "rk3188-usb20otg",
83                 .pdata = &usb20otg_pdata_rk3188,
84         },
85         {
86                 .name = "rk3288-usb20otg",
87                 .pdata = &usb20otg_pdata_rk3288,
88         },
89         { },
90 };
91 #endif
92
93 #ifdef CONFIG_USB20_HOST
94 static struct usb20host_pdata_id usb20host_pdata[] = {
95         {
96                 .name = "rk3188-usb20host",
97                 .pdata = &usb20host_pdata_rk3188,
98         },
99         {
100                 .name = "rk3288-usb20host",
101                 .pdata = &usb20host_pdata_rk3288,
102         },
103         { },
104 };
105 #endif
106
107 #ifdef CONFIG_RK_USB_UART
108 static u32 usb_to_uart_status;
109 #endif
110 /*-------------------------------------------------------------------------*/
111 /* Encapsulate the module parameter settings */
112
113 struct dwc_otg_driver_module_params {
114         int32_t opt;
115         int32_t otg_cap;
116         int32_t dma_enable;
117         int32_t dma_desc_enable;
118         int32_t dma_burst_size;
119         int32_t speed;
120         int32_t host_support_fs_ls_low_power;
121         int32_t host_ls_low_power_phy_clk;
122         int32_t enable_dynamic_fifo;
123         int32_t data_fifo_size;
124         int32_t dev_rx_fifo_size;
125         int32_t dev_nperio_tx_fifo_size;
126         uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
127         int32_t host_rx_fifo_size;
128         int32_t host_nperio_tx_fifo_size;
129         int32_t host_perio_tx_fifo_size;
130         int32_t max_transfer_size;
131         int32_t max_packet_count;
132         int32_t host_channels;
133         int32_t dev_endpoints;
134         int32_t phy_type;
135         int32_t phy_utmi_width;
136         int32_t phy_ulpi_ddr;
137         int32_t phy_ulpi_ext_vbus;
138         int32_t i2c_enable;
139         int32_t ulpi_fs_ls;
140         int32_t ts_dline;
141         int32_t en_multiple_tx_fifo;
142         uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
143         uint32_t thr_ctl;
144         uint32_t tx_thr_length;
145         uint32_t rx_thr_length;
146         int32_t pti_enable;
147         int32_t mpi_enable;
148         int32_t lpm_enable;
149         int32_t besl_enable;
150         int32_t baseline_besl;
151         int32_t deep_besl;
152         int32_t ic_usb_cap;
153         int32_t ahb_thr_ratio;
154         int32_t power_down;
155         int32_t reload_ctl;
156         int32_t dev_out_nak;
157         int32_t cont_on_bna;
158         int32_t ahb_single;
159         int32_t otg_ver;
160         int32_t adp_enable;
161 };
162
163 static struct dwc_otg_driver_module_params dwc_otg_module_params = {
164         .opt = -1,
165         .otg_cap = DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE,
166         .dma_enable = -1,
167         .dma_desc_enable = 0,
168         .dma_burst_size = -1,
169         .speed = -1,
170         .host_support_fs_ls_low_power = -1,
171         .host_ls_low_power_phy_clk = -1,
172         .enable_dynamic_fifo = 1,
173         .data_fifo_size = -1,
174         .dev_rx_fifo_size = 0x120,
175         .dev_nperio_tx_fifo_size = 0x10,
176         .dev_perio_tx_fifo_size = {
177                                    /* dev_perio_tx_fifo_size_1 */
178                                    -1,
179                                    -1,
180                                    -1,
181                                    -1,
182                                    -1,
183                                    -1,
184                                    -1,
185                                    -1,
186                                    -1,
187                                    -1,
188                                    -1,
189                                    -1,
190                                    -1,
191                                    -1,
192                                    -1
193                                    /* 15 */
194                                    },
195         .host_rx_fifo_size = -1,
196         .host_nperio_tx_fifo_size = -1,
197         .host_perio_tx_fifo_size = -1,
198         .max_transfer_size = -1,
199         .max_packet_count = -1,
200         .host_channels = -1,
201         .dev_endpoints = -1,
202         .phy_type = -1,
203         .phy_utmi_width = -1,
204         .phy_ulpi_ddr = -1,
205         .phy_ulpi_ext_vbus = -1,
206         .i2c_enable = -1,
207         .ulpi_fs_ls = -1,
208         .ts_dline = -1,
209         .en_multiple_tx_fifo = -1,
210         .dev_tx_fifo_size = {
211                              /* dev_tx_fifo_size */
212                              0x100,
213                              0x80,
214                              0x80,
215                              0x60,
216                              0x10,
217                              0x10,
218                              -1,
219                              -1,
220                              -1,
221                              -1,
222                              -1,
223                              -1,
224                              -1,
225                              -1,
226                              -1
227                              /* 15 */
228                              },
229         .thr_ctl = -1,
230         .tx_thr_length = -1,
231         .rx_thr_length = -1,
232         .pti_enable = -1,
233         .mpi_enable = -1,
234         .lpm_enable = -1,
235         .besl_enable = -1,
236         .baseline_besl = -1,
237         .deep_besl = -1,
238         .ic_usb_cap = -1,
239         .ahb_thr_ratio = -1,
240         .power_down = -1,
241         .reload_ctl = -1,
242         .dev_out_nak = -1,
243         .cont_on_bna = -1,
244         .ahb_single = -1,
245         .otg_ver = -1,
246         .adp_enable = 0,
247 };
248
249 #ifdef CONFIG_USB20_HOST
250 static struct dwc_otg_driver_module_params dwc_host_module_params = {
251         .opt = -1,
252         .otg_cap = DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE,
253         .dma_enable = -1,
254         .dma_desc_enable = 0,
255         .dma_burst_size = -1,
256         .speed = -1,
257         .host_support_fs_ls_low_power = -1,
258         .host_ls_low_power_phy_clk = -1,
259         .enable_dynamic_fifo = -1,
260         .data_fifo_size = -1,
261         .dev_rx_fifo_size = -1,
262         .dev_nperio_tx_fifo_size = -1,
263         .dev_perio_tx_fifo_size = {
264                                    /* dev_perio_tx_fifo_size_1 */
265                                    -1,
266                                    -1,
267                                    -1,
268                                    -1,
269                                    -1,
270                                    -1,
271                                    -1,
272                                    -1,
273                                    -1,
274                                    -1,
275                                    -1,
276                                    -1,
277                                    -1,
278                                    -1,
279                                    -1
280                                    /* 15 */
281                                    },
282         .host_rx_fifo_size = -1,
283         .host_nperio_tx_fifo_size = -1,
284         .host_perio_tx_fifo_size = -1,
285         .max_transfer_size = -1,
286         .max_packet_count = -1,
287         .host_channels = -1,
288         .dev_endpoints = -1,
289         .phy_type = -1,
290         .phy_utmi_width = -1,
291         .phy_ulpi_ddr = -1,
292         .phy_ulpi_ext_vbus = -1,
293         .i2c_enable = -1,
294         .ulpi_fs_ls = -1,
295         .ts_dline = -1,
296         .en_multiple_tx_fifo = -1,
297         .dev_tx_fifo_size = {
298                              /* dev_tx_fifo_size */
299                              -1,
300                              -1,
301                              -1,
302                              -1,
303                              -1,
304                              -1,
305                              -1,
306                              -1,
307                              -1,
308                              -1,
309                              -1,
310                              -1,
311                              -1,
312                              -1,
313                              -1
314                              /* 15 */
315                              },
316         .thr_ctl = -1,
317         .tx_thr_length = -1,
318         .rx_thr_length = -1,
319         .pti_enable = -1,
320         .mpi_enable = -1,
321         .lpm_enable = -1,
322         .besl_enable = -1,
323         .baseline_besl = -1,
324         .deep_besl = -1,
325         .ic_usb_cap = -1,
326         .ahb_thr_ratio = -1,
327         .power_down = -1,
328         .reload_ctl = -1,
329         .dev_out_nak = -1,
330         .cont_on_bna = -1,
331         .ahb_single = -1,
332         .otg_ver = -1,
333         .adp_enable = 0,
334 };
335 #endif
336
337 /**
338  * This function shows the Driver Version.
339  */
340 static ssize_t version_show(struct device_driver *dev, char *buf)
341 {
342         return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
343                         DWC_DRIVER_VERSION);
344 }
345
346 static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
347
348 /**
349  * Global Debug Level Mask.
350  */
351 uint32_t g_dbg_lvl = DBG_OFF;           /* OFF */
352
353 /**
354  * This function shows the driver Debug Level.
355  */
356 static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
357 {
358         return sprintf(buf, "0x%0x\n", g_dbg_lvl);
359 }
360
361 /**
362  * This function stores the driver Debug Level.
363  */
364 static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
365                                size_t count)
366 {
367         g_dbg_lvl = simple_strtoul(buf, NULL, 16);
368         return count;
369 }
370
371 static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
372                    dbg_level_store);
373
374 extern void hcd_start(dwc_otg_core_if_t *core_if);
375 extern struct usb_hub *g_dwc_otg_root_hub20;
376 extern void dwc_otg_hub_disconnect_device(struct usb_hub *hub);
377
378 void dwc_otg_force_host(dwc_otg_core_if_t *core_if)
379 {
380         dwc_otg_device_t *otg_dev = core_if->otg_dev;
381         dctl_data_t dctl = {.d32=0};
382         unsigned long flags;
383
384         if(core_if->op_state == A_HOST)
385     {
386         printk("dwc_otg_force_host,already in A_HOST mode,everest\n");
387         return;
388     }
389         core_if->op_state = A_HOST;
390
391         cancel_delayed_work(&otg_dev->pcd->check_vbus_work);
392         dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
393         dctl.b.sftdiscon = 1;
394         DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
395         
396         local_irq_save(flags);
397         cil_pcd_stop(core_if);
398         /*
399          * Initialize the Core for Host mode.
400          */
401
402         dwc_otg_core_init(core_if);
403         dwc_otg_enable_global_interrupts(core_if);
404         cil_hcd_start(core_if);
405         local_irq_restore(flags);
406 }
407 void dwc_otg_force_device(dwc_otg_core_if_t *core_if)
408 {
409         dwc_otg_device_t *otg_dev = core_if->otg_dev;
410         unsigned long flags;
411
412         local_irq_save(flags);
413
414         if(core_if->op_state == B_PERIPHERAL) {
415                 printk("dwc_otg_force_device,already in B_PERIPHERAL,everest\n");
416                 return;
417         }
418         core_if->op_state = B_PERIPHERAL;
419         cil_hcd_stop(core_if);
420         //dwc_otg_hub_disconnect_device(g_dwc_otg_root_hub20);
421         otg_dev->pcd->phy_suspend = 1;
422         otg_dev->pcd->vbus_status = 0;
423         dwc_otg_pcd_start_check_vbus_work(otg_dev->pcd);
424         
425         /* Reset the Controller */
426         dwc_otg_core_reset( core_if );
427         
428         dwc_otg_core_init(core_if);
429         dwc_otg_disable_global_interrupts(core_if);
430         cil_pcd_start(core_if);
431
432         local_irq_restore(flags);
433 }
434 static void dwc_otg_set_force_mode(dwc_otg_core_if_t *core_if, int mode)
435 {
436         gusbcfg_data_t usbcfg = { .d32 = 0 };
437         printk("!!!dwc_otg_set_force_mode\n");
438         usbcfg.d32 = DWC_READ_REG32( &core_if->core_global_regs->gusbcfg);
439         switch(mode) {
440                 case USB_MODE_FORCE_HOST:
441                         usbcfg.b.force_host_mode = 1;
442                         usbcfg.b.force_dev_mode = 0;
443                         break;
444                 case USB_MODE_FORCE_DEVICE:
445                         usbcfg.b.force_host_mode = 0;
446                         usbcfg.b.force_dev_mode = 1;
447                         break;
448                 case USB_MODE_NORMAL:
449                         usbcfg.b.force_host_mode = 0;
450                         usbcfg.b.force_dev_mode = 0;
451                         break;
452         }
453         DWC_WRITE_REG32( &core_if->core_global_regs->gusbcfg, usbcfg.d32 );
454 }
455
456 static ssize_t force_usb_mode_show(struct device_driver *drv, char *buf)
457 {
458         dwc_otg_device_t *otg_dev = g_otgdev;
459         dwc_otg_core_if_t *core_if = otg_dev->core_if;
460
461         return sprintf(buf, "%d\n", core_if->usb_mode);
462 }
463
464 static ssize_t force_usb_mode_store(struct device_driver *drv, const char *buf,
465                                     size_t count )
466 {
467         int new_mode = simple_strtoul(buf, NULL, 16);
468         dwc_otg_device_t *otg_dev = g_otgdev;
469         dwc_otg_core_if_t *core_if;
470         struct dwc_otg_platform_data *pldata;
471
472         if(!otg_dev)
473                 return -EINVAL;
474
475         core_if = otg_dev->core_if;
476         pldata = otg_dev->pldata;
477
478         DWC_PRINTF("%s %d->%d\n",__func__, core_if->usb_mode, new_mode);
479
480         if(core_if->usb_mode == new_mode) {
481                 return count;
482         }
483
484         if(pldata->phy_status == USB_PHY_SUSPEND) {
485                 pldata->clock_enable(pldata, 1);
486                 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
487         }
488
489         switch(new_mode) {
490                 case USB_MODE_FORCE_HOST:
491                         if(USB_MODE_FORCE_DEVICE == core_if->usb_mode) {
492                                 /* device-->host */
493                                 core_if->usb_mode = new_mode;
494                                 dwc_otg_force_host(core_if);
495                         } else if(USB_MODE_NORMAL == core_if->usb_mode) {
496                                 core_if->usb_mode = new_mode;
497                                 if(dwc_otg_is_host_mode(core_if)) {
498                                         dwc_otg_set_force_mode(core_if, new_mode);
499                                 } else {
500                                         dwc_otg_force_host(core_if);
501                                 }
502                         }
503                         break;
504
505                 case USB_MODE_FORCE_DEVICE:
506                         if(USB_MODE_FORCE_HOST == core_if->usb_mode) {
507                                 core_if->usb_mode = new_mode;
508                                 dwc_otg_force_device(core_if);
509                         } else if(USB_MODE_NORMAL == core_if->usb_mode) {
510                                 core_if->usb_mode = new_mode;
511                                 if(dwc_otg_is_device_mode(core_if)) {
512                                         dwc_otg_set_force_mode(core_if, new_mode);
513                                 } else {
514                                         dwc_otg_force_device(core_if);
515                                 }
516                         }
517                         break;
518
519                 case USB_MODE_NORMAL:
520                         if(USB_MODE_FORCE_DEVICE == core_if->usb_mode) {
521                                 core_if->usb_mode = new_mode;
522                                 cancel_delayed_work(&otg_dev->pcd->check_vbus_work);
523                                 dwc_otg_set_force_mode(core_if, new_mode);
524                                 //msleep(100);
525                                 if(dwc_otg_is_host_mode(core_if)) {
526                                         dwc_otg_force_host(core_if);
527                                 } else {
528                                         dwc_otg_pcd_start_check_vbus_work(otg_dev->pcd);
529                                 }
530                         } else if(USB_MODE_FORCE_HOST == core_if->usb_mode) {
531                                 core_if->usb_mode = new_mode;
532                                 dwc_otg_set_force_mode(core_if, new_mode);
533                                 //msleep(100);
534                                 if(dwc_otg_is_device_mode(core_if)) {
535                                         dwc_otg_force_device(core_if);
536                                 }
537                         }
538                         break;
539
540                 default:
541                         break;
542         }
543         return count;
544 }
545
546 static DRIVER_ATTR(force_usb_mode, S_IRUGO | S_IWUSR, force_usb_mode_show, force_usb_mode_store);
547
548
549 static ssize_t dwc_otg_conn_en_show(struct device_driver *_drv, char *_buf)
550 {
551
552     dwc_otg_device_t *otg_dev = g_otgdev;
553     dwc_otg_pcd_t *_pcd = otg_dev->pcd;
554     return sprintf (_buf, "%d\n", _pcd->conn_en);
555
556 }
557
558 static ssize_t dwc_otg_conn_en_store(struct device_driver *_drv, const char *_buf,
559                                      size_t _count)
560 {
561     int enable = simple_strtoul(_buf, NULL, 10);
562     dwc_otg_device_t *otg_dev = g_otgdev;
563     dwc_otg_pcd_t *_pcd = otg_dev->pcd;
564     DWC_PRINTF("%s %d->%d\n",__func__, _pcd->conn_en, enable);
565     
566     _pcd->conn_en = enable;
567     return _count;
568 }
569 static DRIVER_ATTR(dwc_otg_conn_en, S_IRUGO|S_IWUSR, dwc_otg_conn_en_show, dwc_otg_conn_en_store);
570
571 static ssize_t vbus_status_show(struct device_driver *_drv, char *_buf)
572 {
573         dwc_otg_device_t *otg_dev = g_otgdev;
574         dwc_otg_pcd_t *_pcd = otg_dev->pcd;
575         return sprintf (_buf, "%d\n", _pcd->vbus_status);
576 }
577 static DRIVER_ATTR(vbus_status, S_IRUGO, vbus_status_show, NULL);
578
579 /**
580  * This function is called during module intialization
581  * to pass module parameters to the DWC_OTG CORE.
582  */
583 static int set_parameters(dwc_otg_core_if_t * core_if, struct dwc_otg_driver_module_params module_params)
584 {
585         int retval = 0;
586         int i;
587
588         if (module_params.otg_cap != -1) {
589                 retval +=
590                     dwc_otg_set_param_otg_cap(core_if,
591                                               module_params.otg_cap);
592         }
593         if (module_params.dma_enable != -1) {
594                 retval +=
595                     dwc_otg_set_param_dma_enable(core_if,
596                                                  module_params.
597                                                  dma_enable);
598         }
599         if (module_params.dma_desc_enable != -1) {
600                 retval +=
601                     dwc_otg_set_param_dma_desc_enable(core_if,
602                                                       module_params.
603                                                       dma_desc_enable);
604         }
605         if (module_params.opt != -1) {
606                 retval +=
607                     dwc_otg_set_param_opt(core_if, module_params.opt);
608         }
609         if (module_params.dma_burst_size != -1) {
610                 retval +=
611                     dwc_otg_set_param_dma_burst_size(core_if,
612                                                      module_params.
613                                                      dma_burst_size);
614         }
615         if (module_params.host_support_fs_ls_low_power != -1) {
616                 retval +=
617                     dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
618                                                                    module_params.
619                                                                    host_support_fs_ls_low_power);
620         }
621         if (module_params.enable_dynamic_fifo != -1) {
622                 retval +=
623                     dwc_otg_set_param_enable_dynamic_fifo(core_if,
624                                                           module_params.
625                                                           enable_dynamic_fifo);
626         }
627         if (module_params.data_fifo_size != -1) {
628                 retval +=
629                     dwc_otg_set_param_data_fifo_size(core_if,
630                                                      module_params.
631                                                      data_fifo_size);
632         }
633         if (module_params.dev_rx_fifo_size != -1) {
634                 retval +=
635                     dwc_otg_set_param_dev_rx_fifo_size(core_if,
636                                                        module_params.
637                                                        dev_rx_fifo_size);
638         }
639         if (module_params.dev_nperio_tx_fifo_size != -1) {
640                 retval +=
641                     dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
642                                                               module_params.
643                                                               dev_nperio_tx_fifo_size);
644         }
645         if (module_params.host_rx_fifo_size != -1) {
646                 retval +=
647                     dwc_otg_set_param_host_rx_fifo_size(core_if,
648                                                         module_params.host_rx_fifo_size);
649         }
650         if (module_params.host_nperio_tx_fifo_size != -1) {
651                 retval +=
652                     dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
653                                                                module_params.
654                                                                host_nperio_tx_fifo_size);
655         }
656         if (module_params.host_perio_tx_fifo_size != -1) {
657                 retval +=
658                     dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
659                                                               module_params.
660                                                               host_perio_tx_fifo_size);
661         }
662         if (module_params.max_transfer_size != -1) {
663                 retval +=
664                     dwc_otg_set_param_max_transfer_size(core_if,
665                                                         module_params.
666                                                         max_transfer_size);
667         }
668         if (module_params.max_packet_count != -1) {
669                 retval +=
670                     dwc_otg_set_param_max_packet_count(core_if,
671                                                        module_params.
672                                                        max_packet_count);
673         }
674         if (module_params.host_channels != -1) {
675                 retval +=
676                     dwc_otg_set_param_host_channels(core_if,
677                                                     module_params.
678                                                     host_channels);
679         }
680         if (module_params.dev_endpoints != -1) {
681                 retval +=
682                     dwc_otg_set_param_dev_endpoints(core_if,
683                                                     module_params.
684                                                     dev_endpoints);
685         }
686         if (module_params.phy_type != -1) {
687                 retval +=
688                     dwc_otg_set_param_phy_type(core_if,
689                                                module_params.phy_type);
690         }
691         if (module_params.speed != -1) {
692                 retval +=
693                     dwc_otg_set_param_speed(core_if,
694                                             module_params.speed);
695         }
696         if (module_params.host_ls_low_power_phy_clk != -1) {
697                 retval +=
698                     dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
699                                                                 module_params.
700                                                                 host_ls_low_power_phy_clk);
701         }
702         if (module_params.phy_ulpi_ddr != -1) {
703                 retval +=
704                     dwc_otg_set_param_phy_ulpi_ddr(core_if,
705                                                    module_params.
706                                                    phy_ulpi_ddr);
707         }
708         if (module_params.phy_ulpi_ext_vbus != -1) {
709                 retval +=
710                     dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
711                                                         module_params.
712                                                         phy_ulpi_ext_vbus);
713         }
714         if (module_params.phy_utmi_width != -1) {
715                 retval +=
716                     dwc_otg_set_param_phy_utmi_width(core_if,
717                                                      module_params.
718                                                      phy_utmi_width);
719         }
720         if (module_params.ulpi_fs_ls != -1) {
721                 retval +=
722                     dwc_otg_set_param_ulpi_fs_ls(core_if,
723                                                  module_params.ulpi_fs_ls);
724         }
725         if (module_params.ts_dline != -1) {
726                 retval +=
727                     dwc_otg_set_param_ts_dline(core_if,
728                                                module_params.ts_dline);
729         }
730         if (module_params.i2c_enable != -1) {
731                 retval +=
732                     dwc_otg_set_param_i2c_enable(core_if,
733                                                  module_params.
734                                                  i2c_enable);
735         }
736         if (module_params.en_multiple_tx_fifo != -1) {
737                 retval +=
738                     dwc_otg_set_param_en_multiple_tx_fifo(core_if,
739                                                           module_params.
740                                                           en_multiple_tx_fifo);
741         }
742         for (i = 0; i < 15; i++) {
743                 if (module_params.dev_perio_tx_fifo_size[i] != -1) {
744                         retval +=
745                             dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
746                                                                      module_params.
747                                                                      dev_perio_tx_fifo_size
748                                                                      [i], i);
749                 }
750         }
751
752         for (i = 0; i < 15; i++) {
753                 if (module_params.dev_tx_fifo_size[i] != -1) {
754                         retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
755                                                                      module_params.
756                                                                      dev_tx_fifo_size
757                                                                      [i], i);
758                 }
759         }
760         if (module_params.thr_ctl != -1) {
761                 retval +=
762                     dwc_otg_set_param_thr_ctl(core_if,
763                                               module_params.thr_ctl);
764         }
765         if (module_params.mpi_enable != -1) {
766                 retval +=
767                     dwc_otg_set_param_mpi_enable(core_if,
768                                                  module_params.
769                                                  mpi_enable);
770         }
771         if (module_params.pti_enable != -1) {
772                 retval +=
773                     dwc_otg_set_param_pti_enable(core_if,
774                                                  module_params.
775                                                  pti_enable);
776         }
777         if (module_params.lpm_enable != -1) {
778                 retval +=
779                     dwc_otg_set_param_lpm_enable(core_if,
780                                                  module_params.
781                                                  lpm_enable);
782         }       
783         if (module_params.besl_enable != -1) {
784                 retval +=
785                     dwc_otg_set_param_besl_enable(core_if,
786                                                  module_params.
787                                                  besl_enable);
788         }
789         if (module_params.baseline_besl != -1) {
790                 retval +=
791                     dwc_otg_set_param_baseline_besl(core_if,
792                                                  module_params.
793                                                  baseline_besl);
794         }
795         if (module_params.deep_besl != -1) {
796                 retval +=
797                     dwc_otg_set_param_deep_besl(core_if,
798                                                  module_params.
799                                                  deep_besl);
800         }               
801         if (module_params.ic_usb_cap != -1) {
802                 retval +=
803                     dwc_otg_set_param_ic_usb_cap(core_if,
804                                                  module_params.
805                                                  ic_usb_cap);
806         }
807         if (module_params.tx_thr_length != -1) {
808                 retval +=
809                     dwc_otg_set_param_tx_thr_length(core_if,
810                                                     module_params.tx_thr_length);
811         }
812         if (module_params.rx_thr_length != -1) {
813                 retval +=
814                     dwc_otg_set_param_rx_thr_length(core_if,
815                                                     module_params.
816                                                     rx_thr_length);
817         }
818         if (module_params.ahb_thr_ratio != -1) {
819                 retval +=
820                     dwc_otg_set_param_ahb_thr_ratio(core_if,
821                                                     module_params.ahb_thr_ratio);
822         }
823         if (module_params.power_down != -1) {
824                 retval +=
825                     dwc_otg_set_param_power_down(core_if,
826                                                  module_params.power_down);
827         }
828         if (module_params.reload_ctl != -1) {
829                 retval +=
830                     dwc_otg_set_param_reload_ctl(core_if,
831                                                  module_params.reload_ctl);
832         }
833
834         if (module_params.dev_out_nak != -1) {
835                 retval +=
836                         dwc_otg_set_param_dev_out_nak(core_if,
837                         module_params.dev_out_nak);
838         }
839
840         if (module_params.cont_on_bna != -1) {
841                 retval +=
842                         dwc_otg_set_param_cont_on_bna(core_if,
843                         module_params.cont_on_bna);
844         }
845
846         if (module_params.ahb_single != -1) {
847                 retval +=
848                         dwc_otg_set_param_ahb_single(core_if,
849                         module_params.ahb_single);
850         }
851
852         if (module_params.otg_ver != -1) {
853                 retval +=
854                     dwc_otg_set_param_otg_ver(core_if,
855                                               module_params.otg_ver);
856         }
857         if (module_params.adp_enable != -1) {
858                 retval +=
859                     dwc_otg_set_param_adp_enable(core_if,
860                                                  module_params.
861                                                  adp_enable);
862         }
863         return retval;
864 }
865
866 /**
867  * This function is the top level interrupt handler for the Common
868  * (Device and host modes) interrupts.
869  */
870 static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
871 {
872         int32_t retval = IRQ_NONE;
873
874         retval = dwc_otg_handle_common_intr(dev);
875         if (retval != 0) {
876                 //S3C2410X_CLEAR_EINTPEND();
877         }
878         return IRQ_RETVAL(retval);
879 }
880
881 #ifdef CONFIG_USB20_HOST
882 /**
883  * This function is called when a lm_device is unregistered with the
884  * dwc_otg_driver. This happens, for example, when the rmmod command is
885  * executed. The device may or may not be electrically present. If it is
886  * present, the driver stops device processing. Any resources used on behalf
887  * of this device are freed.
888  *
889  * @param _dev
890  */
891 static int host20_driver_remove( struct platform_device *_dev )
892 {
893
894         dwc_otg_device_t *otg_dev = dwc_get_device_platform_data(_dev);
895         DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, _dev);
896
897         if (!otg_dev) {
898                 /* Memory allocation for the dwc_otg_device failed. */
899                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
900                 return 0;
901         }
902
903 #ifndef DWC_DEVICE_ONLY
904         if (otg_dev->hcd) {
905                 hcd_remove(_dev);
906         } else {
907                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
908                 return 0;
909         }
910 #endif
911
912 #ifndef DWC_HOST_ONLY
913         if (otg_dev->pcd) {
914                 pcd_remove(_dev);
915         } else {
916                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
917                 return 0;
918         }
919 #endif
920
921         /*
922          * Free the IRQ
923          */
924         if (otg_dev->common_irq_installed) {
925                 //free_irq(_dev->irq, otg_dev);
926                 free_irq(platform_get_irq(_dev,0), otg_dev );
927         } else {
928                 DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
929                 return 0;
930         }
931
932         if (otg_dev->core_if) {
933                 dwc_otg_cil_remove(otg_dev->core_if);
934         } else {
935                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
936                 return 0;
937         }
938
939         /*
940          * Remove the device attributes
941          */
942         dwc_otg_attr_remove(_dev);
943
944         /*
945          * Return the memory.
946          */
947         if (otg_dev->os_dep.base) {
948                 iounmap(otg_dev->os_dep.base);
949         }
950         DWC_FREE(otg_dev);
951
952         /*
953          * Clear the drvdata pointer.
954          */
955
956         dwc_set_device_platform_data(_dev, 0);
957
958         return 0;
959 }
960
961 static const struct of_device_id usb20_host_of_match[] = {
962         {
963                 .compatible = "rockchip,rk3188_usb20_host", 
964                 .data = &usb20host_pdata[RK3188_USB_CTLR],
965         },
966         {
967                 .compatible = "rockchip,rk3288_usb20_host",
968                 .data = &usb20host_pdata[RK3288_USB_CTLR],
969         },
970         { },
971 };
972 MODULE_DEVICE_TABLE(of, usb20_host_of_match);
973
974 /**
975  * This function is called when an lm_device is bound to a
976  * dwc_otg_driver. It creates the driver components required to
977  * control the device (CIL, HCD, and PCD) and it initializes the
978  * device. The driver components are stored in a dwc_otg_device
979  * structure. A reference to the dwc_otg_device is saved in the
980  * lm_device. This allows the driver to access the dwc_otg_device
981  * structure on subsequent calls to driver methods for this device.
982  *
983  * @param _dev Bus device
984  */
985 static int host20_driver_probe(struct platform_device *_dev)
986 {
987         int retval = 0;
988         int irq;
989         struct resource *res_base;
990         dwc_otg_device_t *dwc_otg_device;
991         struct device           *dev = &_dev->dev;
992         struct device_node      *node = _dev->dev.of_node;
993         struct dwc_otg_platform_data *pldata;
994         struct usb20host_pdata_id *p;
995         const struct of_device_id *match =
996                 of_match_device(of_match_ptr( usb20_host_of_match ), &_dev->dev);
997
998         if (match){
999                 p = (struct usb20host_pdata_id *)match->data;
1000         }else{
1001                 dev_err(dev, "usb20host match failed\n");
1002                 return -EINVAL;
1003         }
1004
1005         dev->platform_data = p->pdata;
1006         pldata = dev->platform_data;
1007         pldata->dev = dev;
1008
1009         if (!node) {
1010                 dev_err(dev, "device node not found\n");
1011                 return -EINVAL;
1012         }
1013
1014         if(pldata->hw_init)
1015                 pldata->hw_init();
1016
1017         if(pldata->clock_init){
1018                 pldata->clock_init(pldata);
1019                 pldata->clock_enable(pldata, 1);
1020         }
1021
1022         if(pldata->phy_suspend)
1023                 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1024
1025         if(pldata->soft_reset)
1026                 pldata->soft_reset();
1027
1028         res_base=platform_get_resource(_dev, IORESOURCE_MEM, 0);
1029
1030         dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
1031
1032         if (!dwc_otg_device) {
1033                 dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
1034                 retval = -ENOMEM;
1035                 goto clk_disable;
1036         }
1037
1038         memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
1039         dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
1040
1041         /*
1042          * Map the DWC_otg Core memory into virtual address space.
1043          */
1044
1045         dwc_otg_device->os_dep.base = devm_ioremap_resource(dev, res_base);
1046     
1047         if (!dwc_otg_device->os_dep.base) {
1048                 dev_err(&_dev->dev, "ioremap() failed\n");
1049                 DWC_FREE(dwc_otg_device);
1050                 retval = -ENOMEM;
1051                 goto clk_disable;
1052         }
1053         dev_dbg(&_dev->dev, "base=0x%08x\n",
1054                 (unsigned)dwc_otg_device->os_dep.base);
1055
1056         /*
1057          * Initialize driver data to point to the global DWC_otg
1058          * Device structure.
1059          */
1060
1061         dwc_set_device_platform_data(_dev, dwc_otg_device);
1062         pldata->privdata = dwc_otg_device;
1063         dwc_otg_device->pldata = (void *)pldata;
1064
1065         dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
1066
1067         dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
1068
1069         
1070         if (!dwc_otg_device->core_if) {
1071                 dev_err(&_dev->dev, "CIL initialization failed!\n");
1072                 retval = -ENOMEM;
1073                 goto fail;
1074         }
1075
1076         dwc_otg_device->core_if->otg_dev= dwc_otg_device;
1077
1078         /*
1079          * Attempt to ensure this device is really a DWC_otg Controller.
1080          * Read and verify the SNPSID register contents. The value should be
1081          * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
1082          * as in "OTG version 2.XX" or "OTG version 3.XX".
1083          */
1084
1085         if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) !=     0x4F542000) &&
1086                 ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
1087                 dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
1088                         dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
1089                 retval = -EINVAL;
1090                 goto fail;
1091         }
1092
1093         /*
1094          * Validate parameter values.
1095          */
1096         if (set_parameters(dwc_otg_device->core_if ,dwc_host_module_params )) {
1097                 retval = -EINVAL;
1098                 goto fail;
1099         }
1100         
1101         /*
1102          * Create Device Attributes in sysfs
1103          */
1104         dwc_otg_attr_create(_dev);
1105
1106         /*
1107          * Disable the global interrupt until all the interrupt
1108          * handlers are installed.
1109          */
1110         dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
1111
1112         /*
1113          * Install the interrupt handler for the common interrupts before
1114          * enabling common interrupts in core_init below.
1115          */
1116         irq = platform_get_irq(_dev,0);
1117         DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
1118                     irq);
1119         retval = request_irq(irq, dwc_otg_common_irq,
1120                              IRQF_SHARED , "dwc_otg",
1121                              dwc_otg_device);
1122         if (retval) {
1123                 DWC_ERROR("request of irq%d failed\n", irq);
1124                 retval = -EBUSY;
1125                 goto fail;
1126         } else {
1127                 dwc_otg_device->common_irq_installed = 1;
1128         }
1129
1130         /*
1131          * Initialize the DWC_otg core.
1132          * In order to reduce the time of initialization,
1133          * we do core soft reset after connection detected.
1134          */
1135         dwc_otg_core_init_no_reset(dwc_otg_device->core_if);
1136                 
1137         /*
1138          * Initialize the HCD
1139          */
1140         retval = host20_hcd_init(_dev);
1141         if (retval != 0) {
1142                 DWC_ERROR("hcd_init failed\n");
1143                 dwc_otg_device->hcd = NULL;
1144                 goto fail;
1145         }
1146
1147         clk_set_rate(pldata->phyclk_480m, 480000000);
1148         /*
1149          * Enable the global interrupt after all the interrupt
1150          * handlers are installed if there is no ADP support else 
1151          * perform initial actions required for Internal ADP logic.
1152          */
1153         if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if))     {
1154                 if( pldata->phy_status == USB_PHY_ENABLED ){
1155                         pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1156                         udelay(3);
1157                         pldata->clock_enable( pldata, 0);
1158                 }
1159 //              dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
1160         }
1161         else
1162                 dwc_otg_adp_start(dwc_otg_device->core_if, 
1163                                                         dwc_otg_is_host_mode(dwc_otg_device->core_if));
1164
1165         return 0;
1166
1167 fail:
1168         host20_driver_remove(_dev);
1169 clk_disable:
1170         if(pldata->clock_enable)
1171                 pldata->clock_enable(pldata, 0);
1172
1173         return retval;
1174 }
1175 #endif
1176
1177 static int dwc_otg_driver_suspend(struct platform_device *_dev , pm_message_t state )
1178 {
1179     return 0;
1180 }
1181
1182 static int dwc_otg_driver_resume(struct platform_device *_dev )
1183 {
1184     return 0;
1185 }
1186
1187 static void dwc_otg_driver_shutdown(struct platform_device *_dev )
1188 {
1189         struct device *dev = &_dev->dev;
1190         dwc_otg_device_t *otg_dev = dev->platform_data;
1191     dwc_otg_core_if_t *core_if = otg_dev->core_if;
1192     dctl_data_t dctl = {.d32=0};
1193
1194     DWC_PRINTF("%s: disconnect USB %s mode\n" , __func__ ,
1195         dwc_otg_is_host_mode(core_if) ? "host" : "device");
1196     if(dwc_otg_is_host_mode(core_if))
1197     {
1198         if (core_if->hcd_cb && core_if->hcd_cb->stop)
1199         {
1200                 core_if->hcd_cb->stop( core_if->hcd_cb_p);
1201         }
1202     }
1203     else
1204     {
1205         /* soft disconnect */
1206         dctl.d32 = DWC_READ_REG32( &core_if->dev_if->dev_global_regs->dctl );
1207         dctl.b.sftdiscon = 1;
1208         DWC_WRITE_REG32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 );
1209     }
1210     /* Clear any pending interrupts */
1211     DWC_WRITE_REG32( &core_if->core_global_regs->gintsts, 0xFFFFFFFF); 
1212
1213 }
1214
1215
1216 /**
1217  * This structure defines the methods to be called by a bus driver
1218  * during the lifecycle of a device on that bus. Both drivers and
1219  * devices are registered with a bus driver. The bus driver matches
1220  * devices to drivers based on information in the device and driver
1221  * structures.
1222  *
1223  * The probe function is called when the bus driver matches a device
1224  * to this driver. The remove function is called when a device is
1225  * unregistered with the bus driver.
1226  */
1227 #ifdef CONFIG_USB20_HOST
1228 static struct platform_driver dwc_host_driver = {
1229         .driver = {
1230                 .name = (char *)dwc_host20_driver_name,
1231                 .of_match_table = of_match_ptr(usb20_host_of_match),
1232         },
1233         .probe = host20_driver_probe,
1234         .remove = host20_driver_remove,
1235         .suspend = dwc_otg_driver_suspend,
1236         .resume = dwc_otg_driver_resume,
1237 };
1238 #endif
1239
1240 #ifdef CONFIG_USB20_OTG
1241 /**
1242  * This function is called when a lm_device is unregistered with the
1243  * dwc_otg_driver. This happens, for example, when the rmmod command is
1244  * executed. The device may or may not be electrically present. If it is
1245  * present, the driver stops device processing. Any resources used on behalf
1246  * of this device are freed.
1247  *
1248  * @param _dev
1249  */
1250 static int otg20_driver_remove( struct platform_device *_dev )
1251 {
1252
1253         dwc_otg_device_t *otg_dev = dwc_get_device_platform_data(_dev);
1254         DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, _dev);
1255
1256         if (!otg_dev) {
1257                 /* Memory allocation for the dwc_otg_device failed. */
1258                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
1259                 return 0;
1260         }
1261 #ifndef DWC_DEVICE_ONLY
1262         if (otg_dev->hcd) {
1263                 hcd_remove(_dev);
1264         } else {
1265                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
1266                 return 0;
1267         }
1268 #endif
1269
1270 #ifndef DWC_HOST_ONLY
1271         if (otg_dev->pcd) {
1272                 pcd_remove(_dev);
1273         } else {
1274                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
1275                 return 0;
1276         }
1277 #endif
1278         /*
1279          * Free the IRQ
1280          */
1281         if (otg_dev->common_irq_installed) {
1282                 //free_irq(_dev->irq, otg_dev);
1283                 free_irq(platform_get_irq(_dev,0), otg_dev );
1284         } else {
1285                 DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
1286                 return 0;
1287         }
1288
1289         if (otg_dev->core_if) {
1290                 dwc_otg_cil_remove(otg_dev->core_if);
1291         } else {
1292                 DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
1293                 return 0;
1294         }
1295
1296         /*
1297          * Remove the device attributes
1298          */
1299         dwc_otg_attr_remove(_dev);
1300
1301         /*
1302          * Return the memory.
1303          */
1304         if (otg_dev->os_dep.base) {
1305                 iounmap(otg_dev->os_dep.base);
1306         }
1307         DWC_FREE(otg_dev);
1308
1309         /*
1310          * Clear the drvdata pointer.
1311          */
1312
1313         dwc_set_device_platform_data(_dev, 0);
1314
1315         return 0;
1316 }
1317
1318 static const struct of_device_id usb20_otg_of_match[] = {
1319         {
1320                 .compatible = "rockchip,rk3188_usb20_otg",
1321                 .data = &usb20otg_pdata[RK3188_USB_CTLR],
1322         },
1323         {
1324                 .compatible = "rockchip,rk3288_usb20_otg",
1325                 .data = &usb20otg_pdata[RK3288_USB_CTLR],
1326         },
1327         {
1328         },
1329 };
1330 MODULE_DEVICE_TABLE(of, usb20_otg_of_match);
1331
1332 /**
1333  * This function is called when an lm_device is bound to a
1334  * dwc_otg_driver. It creates the driver components required to
1335  * control the device (CIL, HCD, and PCD) and it initializes the
1336  * device. The driver components are stored in a dwc_otg_device
1337  * structure. A reference to the dwc_otg_device is saved in the
1338  * lm_device. This allows the driver to access the dwc_otg_device
1339  * structure on subsequent calls to driver methods for this device.
1340  *
1341  * @param _dev Bus device
1342  */
1343 static int otg20_driver_probe(struct platform_device *_dev)
1344 {
1345         int retval = 0;
1346         int irq;
1347         uint32_t val;
1348         struct resource *res_base;
1349         dwc_otg_device_t *dwc_otg_device;
1350         struct device           *dev = &_dev->dev;
1351         struct device_node      *node = _dev->dev.of_node;
1352         struct dwc_otg_platform_data *pldata;
1353         struct usb20otg_pdata_id *p;
1354         const struct of_device_id *match =
1355                 of_match_device(of_match_ptr( usb20_otg_of_match ), &_dev->dev);
1356
1357         if (match){
1358                 p = (struct usb20otg_pdata_id *)match->data;
1359         }else{
1360                 dev_err(dev, "usb20otg match failed\n");
1361                 return -EINVAL;
1362         }
1363
1364         dev->platform_data = p->pdata;
1365 //      dev->platform_data = &usb20otg_pdata;
1366         pldata =  dev->platform_data;
1367         pldata->dev = dev;
1368
1369         if (!node) {
1370                 dev_err(dev, "device node not found\n");
1371                 return -EINVAL;
1372         }
1373         /*todo : move to usbdev_rk-XX.c*/
1374         if(pldata->hw_init)
1375                 pldata->hw_init();
1376         
1377         if(pldata->clock_init){
1378                 pldata->clock_init(pldata);
1379                 pldata->clock_enable(pldata, 1);
1380         }
1381
1382         if(pldata->phy_suspend)
1383                 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1384
1385         if(pldata->dwc_otg_uart_mode)
1386                 pldata->dwc_otg_uart_mode(pldata, PHY_USB_MODE);
1387
1388         /* do reset later, because reset need about
1389          * 100ms to ensure otg id state change.
1390          */
1391         /*
1392         if(pldata->soft_reset)
1393                 pldata->soft_reset();
1394         */
1395         /*end todo*/
1396
1397         res_base=platform_get_resource(_dev, IORESOURCE_MEM, 0);
1398
1399         dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
1400
1401         if (!dwc_otg_device) {
1402                 dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
1403                 retval = -ENOMEM;       
1404                 goto clk_disable;
1405         }
1406
1407         memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
1408         dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
1409
1410         /*
1411          * Map the DWC_otg Core memory into virtual address space.
1412          */
1413
1414         dwc_otg_device->os_dep.base = devm_ioremap_resource(dev, res_base);
1415
1416         if (!dwc_otg_device->os_dep.base) {
1417                 dev_err(&_dev->dev, "ioremap() failed\n");
1418                 DWC_FREE(dwc_otg_device);
1419                 retval = -ENOMEM;
1420                 goto clk_disable;
1421         }
1422         dev_dbg(&_dev->dev, "base=0x%08x\n",
1423                 (unsigned)dwc_otg_device->os_dep.base);
1424
1425         /*
1426          * Initialize driver data to point to the global DWC_otg
1427          * Device structure.
1428          */
1429
1430         g_otgdev = dwc_otg_device;
1431         pldata->privdata =  dwc_otg_device;
1432         dwc_otg_device->pldata = pldata;
1433
1434         dwc_set_device_platform_data(_dev, dwc_otg_device);
1435
1436         dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
1437
1438         dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
1439         if (!dwc_otg_device->core_if) {
1440                 dev_err(&_dev->dev, "CIL initialization failed!\n");
1441                 retval = -ENOMEM;
1442                 goto fail;
1443         }
1444         
1445         dwc_otg_device->core_if->otg_dev = dwc_otg_device;
1446         /*
1447          * Attempt to ensure this device is really a DWC_otg Controller.
1448          * Read and verify the SNPSID register contents. The value should be
1449          * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
1450          * as in "OTG version 2.XX" or "OTG version 3.XX".
1451          */
1452
1453         if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) !=     0x4F542000) &&
1454                 ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
1455                 dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
1456                         dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
1457                 retval = -EINVAL;
1458                 goto fail;
1459         }
1460
1461         /*
1462          * Validate parameter values.
1463          */
1464         if (set_parameters(dwc_otg_device->core_if ,dwc_otg_module_params)) {
1465                 retval = -EINVAL;
1466                 goto fail;
1467         }
1468         
1469         /*
1470          * Create Device Attributes in sysfs
1471          */
1472         dwc_otg_attr_create(_dev);
1473
1474         /*
1475          * Disable the global interrupt until all the interrupt
1476          * handlers are installed.
1477          */
1478         dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
1479
1480         /*
1481          * Install the interrupt handler for the common interrupts before
1482          * enabling common interrupts in core_init below.
1483          */
1484         irq = platform_get_irq(_dev,0);
1485         DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
1486                     irq);
1487         retval = request_irq(irq, dwc_otg_common_irq,
1488                              IRQF_SHARED , "dwc_otg",
1489                              dwc_otg_device);
1490         if (retval) {
1491                 DWC_ERROR("request of irq%d failed\n", irq);
1492                 retval = -EBUSY;
1493                 goto fail;
1494         } else {
1495                 dwc_otg_device->common_irq_installed = 1;
1496         }
1497
1498         /*
1499          * Initialize the DWC_otg core.
1500          * In order to reduce the time of initialization,
1501          * we do core soft reset after connection detected.
1502          */
1503         dwc_otg_core_init_no_reset(dwc_otg_device->core_if);
1504
1505         /* set otg mode
1506          * 0 - USB_MODE_NORMAL
1507          * 1 - USB_MODE_FORCE_HOST
1508          * 2 - USB_MODE_FORCE_DEVICE
1509          */
1510         of_property_read_u32(node, "rockchip,usb-mode", &val);
1511         dwc_otg_device->core_if->usb_mode = val;
1512
1513 #ifndef DWC_HOST_ONLY
1514         /*
1515          * Initialize the PCD
1516          */
1517         retval = pcd_init(_dev);
1518         if (retval != 0) {
1519                 DWC_ERROR("pcd_init failed\n");
1520                 dwc_otg_device->pcd = NULL;
1521                 goto fail;
1522         }       
1523 #endif
1524 #ifndef DWC_DEVICE_ONLY
1525         /*
1526          * Initialize the HCD
1527          */
1528         retval = otg20_hcd_init(_dev);
1529         if (retval != 0) {
1530                 DWC_ERROR("hcd_init failed\n");
1531                 dwc_otg_device->hcd = NULL;
1532                 goto fail;
1533         }
1534 #endif
1535         /*
1536          * Enable the global interrupt after all the interrupt
1537          * handlers are installed if there is no ADP support else 
1538          * perform initial actions required for Internal ADP logic.
1539          */
1540         if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)){
1541                 if( pldata->phy_status == USB_PHY_ENABLED ){
1542                         pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1543                         udelay(3);
1544                         pldata->clock_enable( pldata, 0);
1545                 }
1546 //              dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
1547         }
1548         else
1549                 dwc_otg_adp_start(dwc_otg_device->core_if, 
1550                                                         dwc_otg_is_host_mode(dwc_otg_device->core_if));
1551
1552         return 0;
1553
1554 fail:
1555         otg20_driver_remove(_dev);
1556
1557 clk_disable:
1558         if(pldata->clock_enable)
1559                 pldata->clock_enable(pldata, 0);
1560
1561         return retval;
1562 }
1563
1564 static struct platform_driver dwc_otg_driver = {
1565         .driver = {
1566                 .name = (char *)dwc_otg20_driver_name,
1567                 .of_match_table = of_match_ptr(usb20_otg_of_match),
1568         },
1569         .probe = otg20_driver_probe,
1570         .remove = otg20_driver_remove,
1571         .suspend = dwc_otg_driver_suspend,
1572         .resume = dwc_otg_driver_resume,
1573         .shutdown = dwc_otg_driver_shutdown,
1574 };
1575 #endif
1576
1577 void rk_usb_power_up(void)
1578 {
1579         if(cpu_is_rk3288()){
1580 #ifdef CONFIG_RK_USB_UART
1581                 /* enable USB bypass UART function  */
1582                 writel_relaxed(0x00c00000 | usb_to_uart_status, RK_GRF_VIRT + RK3288_GRF_UOC0_CON3);
1583
1584 #endif
1585         }
1586 }
1587
1588 void rk_usb_power_down(void)
1589 {
1590         if(cpu_is_rk3288()){
1591 #ifdef CONFIG_RK_USB_UART
1592                 /* disable USB bypass UART function */
1593                 usb_to_uart_status = readl_relaxed(RK_GRF_VIRT + RK3288_GRF_UOC0_CON3);
1594                 writel_relaxed(0x00c00000, RK_GRF_VIRT + RK3288_GRF_UOC0_CON3);
1595 #endif
1596         }
1597 }
1598
1599 EXPORT_SYMBOL(rk_usb_power_up);
1600 EXPORT_SYMBOL(rk_usb_power_down);
1601 /**
1602  * This function is called when the dwc_otg_driver is installed with the
1603  * insmod command. It registers the dwc_otg_driver structure with the
1604  * appropriate bus driver. This will cause the dwc_otg_driver_probe function
1605  * to be called. In addition, the bus driver will automatically expose
1606  * attributes defined for the device and driver in the special sysfs file
1607  * system.
1608  *
1609  * @return
1610  */
1611 static int __init dwc_otg_driver_init(void)
1612 {
1613         int retval = 0;
1614         int error;
1615         
1616 #ifdef CONFIG_USB20_OTG
1617         //register otg20
1618         printk(KERN_INFO "%s: version %s\n", dwc_otg20_driver_name,
1619                    DWC_DRIVER_VERSION);
1620
1621         retval = platform_driver_register(&dwc_otg_driver);
1622         if (retval < 0) {
1623                 printk(KERN_ERR "%s retval=%d\n", __func__, retval);
1624                 return retval;
1625         }
1626
1627         error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_version);
1628         error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
1629         error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_conn_en);
1630         error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_vbus_status);
1631         error = driver_create_file(&dwc_otg_driver.driver, &driver_attr_force_usb_mode);
1632                 
1633 #endif
1634         
1635         //register host20
1636 #ifdef CONFIG_USB20_HOST
1637         printk(KERN_INFO "%s: version %s\n", dwc_host20_driver_name,
1638                DWC_DRIVER_VERSION);
1639
1640         retval = platform_driver_register(&dwc_host_driver);
1641         if (retval < 0) {
1642                 printk(KERN_ERR "%s retval=%d\n", __func__, retval);
1643                 return retval;
1644         }
1645
1646         error = driver_create_file(&dwc_host_driver.driver, &driver_attr_version);
1647         error = driver_create_file(&dwc_host_driver.driver, &driver_attr_debuglevel);
1648 #endif
1649         return retval;
1650 }
1651
1652 module_init(dwc_otg_driver_init);
1653
1654 /**
1655  * This function is called when the driver is removed from the kernel
1656  * with the rmmod command. The driver unregisters itself with its bus
1657  * driver.
1658  *
1659  */
1660 static void __exit dwc_otg_driver_cleanup(void)
1661 {
1662         printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
1663
1664 #ifdef CONFIG_USB20_HOST
1665         /*for host20*/
1666         driver_remove_file(&dwc_host_driver.driver, &driver_attr_debuglevel);
1667         driver_remove_file(&dwc_host_driver.driver, &driver_attr_version);
1668         platform_driver_unregister(&dwc_host_driver);
1669         printk(KERN_INFO "%s module removed\n", dwc_host20_driver_name);
1670 #endif
1671
1672 #ifdef CONFIG_USB20_OTG
1673         /*for otg*/
1674         driver_remove_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_conn_en);
1675         driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
1676         driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
1677         driver_remove_file(&dwc_otg_driver.driver, &driver_attr_vbus_status);
1678         driver_remove_file(&dwc_otg_driver.driver, &driver_attr_force_usb_mode);
1679         platform_driver_unregister(&dwc_otg_driver);
1680         printk(KERN_INFO "%s module removed\n", dwc_otg20_driver_name);
1681 #endif
1682 }
1683
1684 module_exit(dwc_otg_driver_cleanup);
1685
1686 MODULE_DESCRIPTION(DWC_DRIVER_DESC);
1687 MODULE_AUTHOR("Synopsys Inc.");
1688 MODULE_LICENSE("GPL");
1689
1690 module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
1691 MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
1692 module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
1693 MODULE_PARM_DESC(opt, "OPT Mode");
1694 module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
1695 MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
1696
1697 module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
1698                    0444);
1699 MODULE_PARM_DESC(dma_desc_enable,
1700                  "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
1701
1702 module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
1703                    0444);
1704 MODULE_PARM_DESC(dma_burst_size,
1705                  "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
1706 module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
1707 MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
1708 module_param_named(host_support_fs_ls_low_power,
1709                    dwc_otg_module_params.host_support_fs_ls_low_power, int,
1710                    0444);
1711 MODULE_PARM_DESC(host_support_fs_ls_low_power,
1712                  "Support Low Power w/FS or LS 0=Support 1=Don't Support");
1713 module_param_named(host_ls_low_power_phy_clk,
1714                    dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
1715 MODULE_PARM_DESC(host_ls_low_power_phy_clk,
1716                  "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
1717 module_param_named(enable_dynamic_fifo,
1718                    dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
1719 MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
1720 module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
1721                    0444);
1722 MODULE_PARM_DESC(data_fifo_size,
1723                  "Total number of words in the data FIFO memory 32-32768");
1724 module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
1725                    int, 0444);
1726 MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
1727 module_param_named(dev_nperio_tx_fifo_size,
1728                    dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
1729 MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
1730                  "Number of words in the non-periodic Tx FIFO 16-32768");
1731 module_param_named(dev_perio_tx_fifo_size_1,
1732                    dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
1733 MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
1734                  "Number of words in the periodic Tx FIFO 4-768");
1735 module_param_named(dev_perio_tx_fifo_size_2,
1736                    dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
1737 MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
1738                  "Number of words in the periodic Tx FIFO 4-768");
1739 module_param_named(dev_perio_tx_fifo_size_3,
1740                    dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
1741 MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
1742                  "Number of words in the periodic Tx FIFO 4-768");
1743 module_param_named(dev_perio_tx_fifo_size_4,
1744                    dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
1745 MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
1746                  "Number of words in the periodic Tx FIFO 4-768");
1747 module_param_named(dev_perio_tx_fifo_size_5,
1748                    dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
1749 MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
1750                  "Number of words in the periodic Tx FIFO 4-768");
1751 module_param_named(dev_perio_tx_fifo_size_6,
1752                    dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
1753 MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
1754                  "Number of words in the periodic Tx FIFO 4-768");
1755 module_param_named(dev_perio_tx_fifo_size_7,
1756                    dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
1757 MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
1758                  "Number of words in the periodic Tx FIFO 4-768");
1759 module_param_named(dev_perio_tx_fifo_size_8,
1760                    dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
1761 MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
1762                  "Number of words in the periodic Tx FIFO 4-768");
1763 module_param_named(dev_perio_tx_fifo_size_9,
1764                    dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
1765 MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
1766                  "Number of words in the periodic Tx FIFO 4-768");
1767 module_param_named(dev_perio_tx_fifo_size_10,
1768                    dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
1769 MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
1770                  "Number of words in the periodic Tx FIFO 4-768");
1771 module_param_named(dev_perio_tx_fifo_size_11,
1772                    dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
1773 MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
1774                  "Number of words in the periodic Tx FIFO 4-768");
1775 module_param_named(dev_perio_tx_fifo_size_12,
1776                    dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
1777 MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
1778                  "Number of words in the periodic Tx FIFO 4-768");
1779 module_param_named(dev_perio_tx_fifo_size_13,
1780                    dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
1781 MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
1782                  "Number of words in the periodic Tx FIFO 4-768");
1783 module_param_named(dev_perio_tx_fifo_size_14,
1784                    dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
1785 MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
1786                  "Number of words in the periodic Tx FIFO 4-768");
1787 module_param_named(dev_perio_tx_fifo_size_15,
1788                    dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
1789 MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
1790                  "Number of words in the periodic Tx FIFO 4-768");
1791 module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
1792                    int, 0444);
1793 MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
1794 module_param_named(host_nperio_tx_fifo_size,
1795                    dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
1796 MODULE_PARM_DESC(host_nperio_tx_fifo_size,
1797                  "Number of words in the non-periodic Tx FIFO 16-32768");
1798 module_param_named(host_perio_tx_fifo_size,
1799                    dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
1800 MODULE_PARM_DESC(host_perio_tx_fifo_size,
1801                  "Number of words in the host periodic Tx FIFO 16-32768");
1802 module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
1803                    int, 0444);
1804 /** @todo Set the max to 512K, modify checks */
1805 MODULE_PARM_DESC(max_transfer_size,
1806                  "The maximum transfer size supported in bytes 2047-65535");
1807 module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
1808                    int, 0444);
1809 MODULE_PARM_DESC(max_packet_count,
1810                  "The maximum number of packets in a transfer 15-511");
1811 module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
1812                    0444);
1813 MODULE_PARM_DESC(host_channels,
1814                  "The number of host channel registers to use 1-16");
1815 module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
1816                    0444);
1817 MODULE_PARM_DESC(dev_endpoints,
1818                  "The number of endpoints in addition to EP0 available for device mode 1-15");
1819 module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
1820 MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
1821 module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
1822                    0444);
1823 MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
1824 module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
1825 MODULE_PARM_DESC(phy_ulpi_ddr,
1826                  "ULPI at double or single data rate 0=Single 1=Double");
1827 module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
1828                    int, 0444);
1829 MODULE_PARM_DESC(phy_ulpi_ext_vbus,
1830                  "ULPI PHY using internal or external vbus 0=Internal");
1831 module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
1832 MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
1833 module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
1834 MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
1835 module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
1836 MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
1837 module_param_named(debug, g_dbg_lvl, int, 0444);
1838 MODULE_PARM_DESC(debug, "");
1839
1840 module_param_named(en_multiple_tx_fifo,
1841                    dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
1842 MODULE_PARM_DESC(en_multiple_tx_fifo,
1843                  "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
1844 module_param_named(dev_tx_fifo_size_1,
1845                    dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
1846 MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
1847 module_param_named(dev_tx_fifo_size_2,
1848                    dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
1849 MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
1850 module_param_named(dev_tx_fifo_size_3,
1851                    dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
1852 MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
1853 module_param_named(dev_tx_fifo_size_4,
1854                    dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
1855 MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
1856 module_param_named(dev_tx_fifo_size_5,
1857                    dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
1858 MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
1859 module_param_named(dev_tx_fifo_size_6,
1860                    dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
1861 MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
1862 module_param_named(dev_tx_fifo_size_7,
1863                    dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
1864 MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
1865 module_param_named(dev_tx_fifo_size_8,
1866                    dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
1867 MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
1868 module_param_named(dev_tx_fifo_size_9,
1869                    dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
1870 MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
1871 module_param_named(dev_tx_fifo_size_10,
1872                    dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
1873 MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
1874 module_param_named(dev_tx_fifo_size_11,
1875                    dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
1876 MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
1877 module_param_named(dev_tx_fifo_size_12,
1878                    dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
1879 MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
1880 module_param_named(dev_tx_fifo_size_13,
1881                    dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
1882 MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
1883 module_param_named(dev_tx_fifo_size_14,
1884                    dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
1885 MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
1886 module_param_named(dev_tx_fifo_size_15,
1887                    dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
1888 MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
1889
1890 module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
1891 MODULE_PARM_DESC(thr_ctl,
1892                  "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
1893 module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
1894                    0444);
1895 MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
1896 module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
1897                    0444);
1898 MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
1899
1900 module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
1901 module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
1902 module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
1903 MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
1904
1905 module_param_named(besl_enable, dwc_otg_module_params.besl_enable, int, 0444);
1906 MODULE_PARM_DESC(besl_enable, "BESL Enable 0=BESL Disabled 1=BESL Enabled");
1907 module_param_named(baseline_besl, dwc_otg_module_params.baseline_besl, int, 0444);
1908 MODULE_PARM_DESC(baseline_besl, "Set the baseline besl value");
1909 module_param_named(deep_besl, dwc_otg_module_params.deep_besl, int, 0444);
1910 MODULE_PARM_DESC(deep_besl, "Set the deep besl value");
1911
1912 module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
1913 MODULE_PARM_DESC(ic_usb_cap,
1914                  "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
1915 module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
1916                    0444);
1917 MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
1918 module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
1919 MODULE_PARM_DESC(power_down, "Power Down Mode");
1920 module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
1921 MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
1922 module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
1923 MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
1924 module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
1925 MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
1926 module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
1927 MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
1928 module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
1929 MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
1930 module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
1931 MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
1932
1933 /** @page "Module Parameters"
1934  *
1935  * The following parameters may be specified when starting the module.
1936  * These parameters define how the DWC_otg controller should be
1937  * configured. Parameter values are passed to the CIL initialization
1938  * function dwc_otg_cil_init
1939  *
1940  * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
1941  *
1942
1943  <table>
1944  <tr><td>Parameter Name</td><td>Meaning</td></tr>
1945
1946  <tr>
1947  <td>otg_cap</td>
1948  <td>Specifies the OTG capabilities. The driver will automatically detect the
1949  value for this parameter if none is specified.
1950  - 0: HNP and SRP capable (default, if available)
1951  - 1: SRP Only capable
1952  - 2: No HNP/SRP capable
1953  </td></tr>
1954
1955  <tr>
1956  <td>dma_enable</td>
1957  <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
1958  The driver will automatically detect the value for this parameter if none is
1959  specified.
1960  - 0: Slave
1961  - 1: DMA (default, if available)
1962  </td></tr>
1963
1964  <tr>
1965  <td>dma_burst_size</td>
1966  <td>The DMA Burst size (applicable only for External DMA Mode).
1967  - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
1968  </td></tr>
1969
1970  <tr>
1971  <td>speed</td>
1972  <td>Specifies the maximum speed of operation in host and device mode. The
1973  actual speed depends on the speed of the attached device and the value of
1974  phy_type.
1975  - 0: High Speed (default)
1976  - 1: Full Speed
1977  </td></tr>
1978
1979  <tr>
1980  <td>host_support_fs_ls_low_power</td>
1981  <td>Specifies whether low power mode is supported when attached to a Full
1982  Speed or Low Speed device in host mode.
1983  - 0: Don't support low power mode (default)
1984  - 1: Support low power mode
1985  </td></tr>
1986
1987  <tr>
1988  <td>host_ls_low_power_phy_clk</td>
1989  <td>Specifies the PHY clock rate in low power mode when connected to a Low
1990  Speed device in host mode. This parameter is applicable only if
1991  HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
1992  - 0: 48 MHz (default)
1993  - 1: 6 MHz
1994  </td></tr>
1995
1996  <tr>
1997  <td>enable_dynamic_fifo</td>
1998  <td> Specifies whether FIFOs may be resized by the driver software.
1999  - 0: Use cC FIFO size parameters
2000  - 1: Allow dynamic FIFO sizing (default)
2001  </td></tr>
2002
2003  <tr>
2004  <td>data_fifo_size</td>
2005  <td>Total number of 4-byte words in the data FIFO memory. This memory
2006  includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
2007  - Values: 32 to 32768 (default 8192)
2008
2009  Note: The total FIFO memory depth in the FPGA configuration is 8192.
2010  </td></tr>
2011
2012  <tr>
2013  <td>dev_rx_fifo_size</td>
2014  <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
2015  FIFO sizing is enabled.
2016  - Values: 16 to 32768 (default 1064)
2017  </td></tr>
2018
2019  <tr>
2020  <td>dev_nperio_tx_fifo_size</td>
2021  <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
2022  dynamic FIFO sizing is enabled.
2023  - Values: 16 to 32768 (default 1024)
2024  </td></tr>
2025
2026  <tr>
2027  <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
2028  <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
2029  when dynamic FIFO sizing is enabled.
2030  - Values: 4 to 768 (default 256)
2031  </td></tr>
2032
2033  <tr>
2034  <td>host_rx_fifo_size</td>
2035  <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
2036  sizing is enabled.
2037  - Values: 16 to 32768 (default 1024)
2038  </td></tr>
2039
2040  <tr>
2041  <td>host_nperio_tx_fifo_size</td>
2042  <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
2043  dynamic FIFO sizing is enabled in the core.
2044  - Values: 16 to 32768 (default 1024)
2045  </td></tr>
2046
2047  <tr>
2048  <td>host_perio_tx_fifo_size</td>
2049  <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
2050  sizing is enabled.
2051  - Values: 16 to 32768 (default 1024)
2052  </td></tr>
2053
2054  <tr>
2055  <td>max_transfer_size</td>
2056  <td>The maximum transfer size supported in bytes.
2057  - Values: 2047 to 65,535 (default 65,535)
2058  </td></tr>
2059
2060  <tr>
2061  <td>max_packet_count</td>
2062  <td>The maximum number of packets in a transfer.
2063  - Values: 15 to 511 (default 511)
2064  </td></tr>
2065
2066  <tr>
2067  <td>host_channels</td>
2068  <td>The number of host channel registers to use.
2069  - Values: 1 to 16 (default 12)
2070
2071  Note: The FPGA configuration supports a maximum of 12 host channels.
2072  </td></tr>
2073
2074  <tr>
2075  <td>dev_endpoints</td>
2076  <td>The number of endpoints in addition to EP0 available for device mode
2077  operations.
2078  - Values: 1 to 15 (default 6 IN and OUT)
2079
2080  Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
2081  addition to EP0.
2082  </td></tr>
2083
2084  <tr>
2085  <td>phy_type</td>
2086  <td>Specifies the type of PHY interface to use. By default, the driver will
2087  automatically detect the phy_type.
2088  - 0: Full Speed
2089  - 1: UTMI+ (default, if available)
2090  - 2: ULPI
2091  </td></tr>
2092
2093  <tr>
2094  <td>phy_utmi_width</td>
2095  <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
2096  phy_type of UTMI+. Also, this parameter is applicable only if the
2097  OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
2098  core has been configured to work at either data path width.
2099  - Values: 8 or 16 bits (default 16)
2100  </td></tr>
2101
2102  <tr>
2103  <td>phy_ulpi_ddr</td>
2104  <td>Specifies whether the ULPI operates at double or single data rate. This
2105  parameter is only applicable if phy_type is ULPI.
2106  - 0: single data rate ULPI interface with 8 bit wide data bus (default)
2107  - 1: double data rate ULPI interface with 4 bit wide data bus
2108  </td></tr>
2109
2110  <tr>
2111  <td>i2c_enable</td>
2112  <td>Specifies whether to use the I2C interface for full speed PHY. This
2113  parameter is only applicable if PHY_TYPE is FS.
2114  - 0: Disabled (default)
2115  - 1: Enabled
2116  </td></tr>
2117
2118  <tr>
2119  <td>ulpi_fs_ls</td>
2120  <td>Specifies whether to use ULPI FS/LS mode only.
2121  - 0: Disabled (default)
2122  - 1: Enabled
2123  </td></tr>
2124
2125  <tr>
2126  <td>ts_dline</td>
2127  <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
2128  - 0: Disabled (default)
2129  - 1: Enabled
2130  </td></tr>
2131  
2132  <tr>
2133  <td>en_multiple_tx_fifo</td>
2134  <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
2135  The driver will automatically detect the value for this parameter if none is
2136  specified.
2137  - 0: Disabled
2138  - 1: Enabled (default, if available)
2139  </td></tr>
2140
2141  <tr>
2142  <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
2143  <td>Number of 4-byte words in each of the Tx FIFOs in device mode
2144  when dynamic FIFO sizing is enabled.
2145  - Values: 4 to 768 (default 256)
2146  </td></tr>
2147
2148  <tr>
2149  <td>tx_thr_length</td>
2150  <td>Transmit Threshold length in 32 bit double words
2151  - Values: 8 to 128 (default 64)
2152  </td></tr>
2153
2154  <tr>
2155  <td>rx_thr_length</td>
2156  <td>Receive Threshold length in 32 bit double words
2157  - Values: 8 to 128 (default 64)
2158  </td></tr>
2159
2160 <tr>
2161  <td>thr_ctl</td>
2162  <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of 
2163  this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
2164  Rx transfers accordingly.
2165  The driver will automatically detect the value for this parameter if none is
2166  specified.
2167  - Values: 0 to 7 (default 0)
2168  Bit values indicate:
2169  - 0: Thresholding disabled
2170  - 1: Thresholding enabled
2171  </td></tr>
2172
2173 <tr>
2174  <td>dma_desc_enable</td>
2175  <td>Specifies whether to enable Descriptor DMA mode.
2176  The driver will automatically detect the value for this parameter if none is
2177  specified.
2178  - 0: Descriptor DMA disabled
2179  - 1: Descriptor DMA (default, if available)
2180  </td></tr>
2181
2182 <tr>
2183  <td>mpi_enable</td>
2184  <td>Specifies whether to enable MPI enhancement mode.
2185  The driver will automatically detect the value for this parameter if none is
2186  specified.
2187  - 0: MPI disabled (default)
2188  - 1: MPI enable
2189  </td></tr>
2190
2191 <tr>
2192  <td>pti_enable</td>
2193  <td>Specifies whether to enable PTI enhancement support.
2194  The driver will automatically detect the value for this parameter if none is
2195  specified.
2196  - 0: PTI disabled (default)
2197  - 1: PTI enable
2198  </td></tr>
2199
2200 <tr>
2201  <td>lpm_enable</td>
2202  <td>Specifies whether to enable LPM support.
2203  The driver will automatically detect the value for this parameter if none is
2204  specified.
2205  - 0: LPM disabled
2206  - 1: LPM enable (default, if available)
2207  </td></tr>
2208   
2209  <tr>
2210  <td>besl_enable</td>
2211  <td>Specifies whether to enable LPM Errata support.
2212  The driver will automatically detect the value for this parameter if none is
2213  specified.
2214  - 0: LPM Errata disabled (default)
2215  - 1: LPM Errata enable 
2216  </td></tr>
2217  
2218   <tr>
2219  <td>baseline_besl</td>
2220  <td>Specifies the baseline besl value.
2221  - Values: 0 to 15 (default 0)
2222  </td></tr>
2223  
2224   <tr>
2225  <td>deep_besl</td>
2226  <td>Specifies the deep besl value.
2227  - Values: 0 to 15 (default 15)
2228  </td></tr>
2229
2230 <tr>
2231  <td>ic_usb_cap</td>
2232  <td>Specifies whether to enable IC_USB capability.
2233  The driver will automatically detect the value for this parameter if none is
2234  specified.
2235  - 0: IC_USB disabled (default, if available)
2236  - 1: IC_USB enable 
2237  </td></tr>
2238
2239 <tr>
2240  <td>ahb_thr_ratio</td>
2241  <td>Specifies AHB Threshold ratio.
2242  - Values: 0 to 3 (default 0)
2243  </td></tr>
2244
2245 <tr>
2246  <td>power_down</td>
2247  <td>Specifies Power Down(Hibernation) Mode.
2248  The driver will automatically detect the value for this parameter if none is
2249  specified.
2250  - 0: Power Down disabled (default)
2251  - 2: Power Down enabled
2252  </td></tr>
2253  
2254  <tr>
2255  <td>reload_ctl</td>
2256  <td>Specifies whether dynamic reloading of the HFIR register is allowed during
2257  run time. The driver will automatically detect the value for this parameter if
2258  none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
2259  the core might misbehave.
2260  - 0: Reload Control disabled (default)
2261  - 1: Reload Control enabled
2262  </td></tr>
2263
2264  <tr>
2265  <td>dev_out_nak</td>
2266  <td>Specifies whether  Device OUT NAK enhancement enabled or no.
2267  The driver will automatically detect the value for this parameter if
2268  none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1\92b1.
2269  - 0: The core does not set NAK after Bulk OUT transfer complete (default)
2270  - 1: The core sets NAK after Bulk OUT transfer complete
2271  </td></tr>
2272
2273  <tr>
2274  <td>cont_on_bna</td>
2275  <td>Specifies whether Enable Continue on BNA enabled or no. 
2276  After receiving BNA interrupt the core disables the endpoint,when the
2277  endpoint is re-enabled by the application the  
2278  - 0: Core starts processing from the DOEPDMA descriptor (default)
2279  - 1: Core starts processing from the descriptor which received the BNA.
2280  This parameter is valid only when OTG_EN_DESC_DMA == 1\92b1.
2281  </td></tr>
2282
2283  <tr>
2284  <td>ahb_single</td>
2285  <td>This bit when programmed supports SINGLE transfers for remainder data
2286  in a transfer for DMA mode of operation. 
2287  - 0: The remainder data will be sent using INCR burst size (default)
2288  - 1: The remainder data will be sent using SINGLE burst size.
2289  </td></tr>
2290
2291 <tr>
2292  <td>adp_enable</td>
2293  <td>Specifies whether ADP feature is enabled.
2294  The driver will automatically detect the value for this parameter if none is
2295  specified.
2296  - 0: ADP feature disabled (default)
2297  - 1: ADP feature enabled
2298  </td></tr>
2299
2300   <tr>
2301  <td>otg_ver</td>
2302  <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
2303  USB OTG device.
2304  - 0: OTG 2.0 support disabled (default)
2305  - 1: OTG 2.0 support enabled 
2306  </td></tr>
2307
2308 */