1 /* ==========================================================================
2 * $File: //dwh/usb_iip/dev/software/otg_ipmate/linux/drivers/dwc_otg_driver.c $
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.
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.
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
32 * ========================================================================== */
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.
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
51 #include <linux/kernel.h>
52 #include <linux/module.h>
53 #include <linux/moduleparam.h>
54 #include <linux/init.h>
55 #include <linux/device.h>
56 #include <linux/errno.h>
57 #include <linux/types.h>
58 #include <linux/stat.h> /* permission constants */
61 #include <asm/sizes.h>
63 #include "linux/dwc_otg_plat.h"
64 #include <linux/platform_device.h>
65 #include "dwc_otg_attr.h"
66 #include "dwc_otg_driver.h"
67 #include "dwc_otg_cil.h"
68 #include "dwc_otg_pcd.h"
69 #include "dwc_otg_hcd.h"
71 #include "usbdev_rk.h"
72 //#define DWC_DRIVER_VERSION "2.60a 22-NOV-2006"
73 //#define DWC_DRIVER_VERSION "2.70 2009-12-31"
74 #define DWC_DRIVER_VERSION "3.00 2010-12-12 rockchip"
76 #define DWC_DRIVER_DESC "HS OTG USB Controller driver"
78 static const char dwc_driver_name[] = "usb20_otg";
80 dwc_otg_device_t* g_otgdev = NULL;
82 /*-------------------------------------------------------------------------*/
83 /* Encapsulate the module parameter settings */
85 static dwc_otg_core_params_t dwc_otg_module_params = {
91 .host_support_fs_ls_low_power = -1,
92 .host_ls_low_power_phy_clk = -1,
93 .enable_dynamic_fifo = -1,
95 .dev_rx_fifo_size = -1,
96 .dev_nperio_tx_fifo_size = -1,
97 .dev_perio_tx_fifo_size =
98 { /* dev_perio_tx_fifo_size_1 */
115 .host_rx_fifo_size = -1,
116 .host_nperio_tx_fifo_size = -1,
117 //.host_perio_tx_fifo_size = 512,
118 .host_perio_tx_fifo_size = -1,
119 .max_transfer_size = -1,
120 .max_packet_count = -1,
124 .phy_utmi_width = -1,
126 .phy_ulpi_ext_vbus = -1,
130 .en_multiple_tx_fifo = -1,
132 { /* dev_tx_fifo_size */
154 #ifdef CONFIG_USB11_HOST
156 dwc_otg_device_t* g_host11 = NULL;
158 static dwc_otg_core_params_t host11_module_params = {
162 .dma_burst_size = -1,
164 .host_support_fs_ls_low_power = 1,
165 .host_ls_low_power_phy_clk = -1,
166 .enable_dynamic_fifo = -1,
167 .data_fifo_size = -1,
168 .dev_rx_fifo_size = -1,
169 .dev_nperio_tx_fifo_size = -1,
170 .dev_perio_tx_fifo_size =
171 { /* dev_perio_tx_fifo_size_1 */
188 .host_rx_fifo_size = -1,
189 .host_nperio_tx_fifo_size = -1,
190 //.host_perio_tx_fifo_size = 512,
191 .host_perio_tx_fifo_size = -1,
192 .max_transfer_size = -1,
193 .max_packet_count = -1,
197 .phy_utmi_width = -1,
199 .phy_ulpi_ext_vbus = -1,
203 .en_multiple_tx_fifo = -1,
205 { /* dev_tx_fifo_size */
228 #ifdef CONFIG_USB20_HOST
229 dwc_otg_device_t* g_host20 = NULL;
231 static dwc_otg_core_params_t host20_module_params = {
235 .dma_burst_size = -1,
237 .host_support_fs_ls_low_power = -1,
238 .host_ls_low_power_phy_clk = -1,
239 .enable_dynamic_fifo = -1,
240 .data_fifo_size = -1,
241 .dev_rx_fifo_size = -1,
242 .dev_nperio_tx_fifo_size = -1,
243 .dev_perio_tx_fifo_size =
244 { /* dev_perio_tx_fifo_size_1 */
261 .host_rx_fifo_size = -1,
262 .host_nperio_tx_fifo_size = -1,
263 //.host_perio_tx_fifo_size = 512,
264 .host_perio_tx_fifo_size = -1,
265 .max_transfer_size = -1,
266 .max_packet_count = -1,
270 .phy_utmi_width = -1,
272 .phy_ulpi_ext_vbus = -1,
276 .en_multiple_tx_fifo = -1,
278 { /* dev_tx_fifo_size */
302 * This function shows the Driver Version.
304 static ssize_t version_show(struct device_driver *dev, char *buf)
306 return snprintf(buf, sizeof(DWC_DRIVER_VERSION)+2,"%s\n",
309 static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
312 * Global Debug Level Mask.
314 uint32_t g_dbg_lvl = DBG_OFF;//0xFFFF;//DBG_CIL|DBG_CILV|DBG_PCDV|DBG_HCDV|DBG_HCD|DBG_HCD_URB; /* OFF */
317 * This function shows the driver Debug Level.
319 static ssize_t dbg_level_show(struct device_driver *_drv, char *_buf)
321 return sprintf(_buf, "0x%0x\n", g_dbg_lvl);
324 * This function stores the driver Debug Level.
326 static ssize_t dbg_level_store(struct device_driver *_drv, const char *_buf,
329 g_dbg_lvl = simple_strtoul(_buf, NULL, 16);
332 static DRIVER_ATTR(debuglevel, S_IRUGO|S_IWUSR, dbg_level_show, dbg_level_store);
335 extern struct usb_hub *g_root_hub20;
336 #ifdef DWC_BOTH_HOST_SLAVE
337 extern void hcd_start( dwc_otg_core_if_t *_core_if );
339 extern void hub_disconnect_device(struct usb_hub *hub);
341 static ssize_t force_usb_mode_show(struct device_driver *_drv, char *_buf)
343 dwc_otg_device_t *otg_dev = g_otgdev;
344 dwc_otg_core_if_t *core_if = otg_dev->core_if;
346 return sprintf (_buf, "%d\n", core_if->usb_mode);
349 void dwc_otg_force_host(dwc_otg_core_if_t *core_if)
351 dwc_otg_device_t *otg_dev = g_otgdev;
352 dctl_data_t dctl = {.d32=0};
353 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
354 if(core_if->op_state == A_HOST)
356 printk("dwc_otg_force_host,already in A_HOST mode,everest\n");
359 del_timer(&otg_dev->pcd->check_vbus_timer);
361 /* soft disconnect */
362 dctl.d32 = dwc_read_reg32( &core_if->dev_if->dev_global_regs->dctl );
363 dctl.b.sftdiscon = 1;
364 dwc_write_reg32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 );
366 if (core_if->pcd_cb && core_if->pcd_cb->stop ) {
367 core_if->pcd_cb->stop( core_if->pcd_cb->p );
370 //core_if->op_state = A_HOST;
372 * Initialize the Core for Host mode.
374 dwc_otg_core_init(core_if);
375 dwc_otg_enable_global_interrupts(core_if);
376 hcd_start( core_if );
379 void dwc_otg_force_device(dwc_otg_core_if_t *core_if)
381 dwc_otg_device_t *otg_dev = g_otgdev;
382 dwc_otg_disable_global_interrupts( core_if );
383 if (core_if->hcd_cb && core_if->hcd_cb->stop) {
384 core_if->hcd_cb->stop( core_if->hcd_cb->p );
386 if(core_if->op_state == B_PERIPHERAL)
388 printk("dwc_otg_force_device,already in B_PERIPHERAL,everest\n");
391 hub_disconnect_device(g_root_hub20);
392 otg_dev->core_if->op_state = B_PERIPHERAL;
393 /* Reset the Controller */
394 dwc_otg_core_reset( core_if );
395 otg_dev->pcd->vbus_status = 0;
396 dwc_otg_pcd_start_vbus_timer( otg_dev->pcd );
399 static void dwc_otg_set_gusbcfg(dwc_otg_core_if_t *core_if, int mode)
401 gusbcfg_data_t usbcfg = { .d32 = 0 };
403 usbcfg.d32 = dwc_read_reg32( &core_if->core_global_regs->gusbcfg);
406 case USB_MODE_FORCE_HOST:
407 usbcfg.b.force_hst_mode = 1;
408 usbcfg.b.force_dev_mode = 0;
410 case USB_MODE_FORCE_DEVICE:
411 usbcfg.b.force_hst_mode = 0;
412 usbcfg.b.force_dev_mode = 1;
414 case USB_MODE_NORMAL:
415 usbcfg.b.force_hst_mode = 0;
416 usbcfg.b.force_dev_mode = 0;
419 dwc_write_reg32( &core_if->core_global_regs->gusbcfg, usbcfg.d32 );
422 static ssize_t force_usb_mode_store(struct device_driver *_drv, const char *_buf,
425 int new_mode = simple_strtoul(_buf, NULL, 16);
426 dwc_otg_device_t *otg_dev = g_otgdev;
427 dwc_otg_core_if_t *core_if = otg_dev->core_if;
428 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
429 DWC_PRINT("%s %d->%d\n",__func__, core_if->usb_mode, new_mode);
430 if(core_if->usb_mode == new_mode)
435 if(pldata->phy_status==USB_PHY_SUSPEND){
436 pldata->clock_enable(pldata, 1);
437 pldata->phy_suspend(pldata,USB_PHY_ENABLED);
442 case USB_MODE_FORCE_HOST:
443 if(USB_MODE_FORCE_DEVICE == core_if->usb_mode)
445 core_if->usb_mode = new_mode;
446 dwc_otg_force_host(core_if);
448 else if(USB_MODE_NORMAL == core_if->usb_mode)
450 core_if->usb_mode = new_mode;
451 if(dwc_otg_is_host_mode(core_if))
453 dwc_otg_set_gusbcfg(core_if, new_mode);
457 dwc_otg_force_host(core_if);
461 core_if->usb_mode = new_mode;
463 case USB_MODE_FORCE_DEVICE:
464 if(USB_MODE_FORCE_HOST == core_if->usb_mode)
466 core_if->usb_mode = new_mode;
467 dwc_otg_force_device(core_if);
469 else if(USB_MODE_NORMAL == core_if->usb_mode)
471 core_if->usb_mode = new_mode;
472 if(dwc_otg_is_device_mode(core_if))
474 dwc_otg_set_gusbcfg(core_if, new_mode);
478 dwc_otg_force_device(core_if);
482 case USB_MODE_NORMAL:
484 if(USB_MODE_FORCE_DEVICE == core_if->usb_mode)
486 core_if->usb_mode = new_mode;
487 del_timer(&otg_dev->pcd->check_vbus_timer);
488 dwc_otg_set_gusbcfg(core_if, new_mode);
490 if(dwc_otg_is_host_mode(core_if))
492 dwc_otg_force_host(core_if);
496 dwc_otg_pcd_start_vbus_timer( otg_dev->pcd );
499 //core_if->usb_mode = new_mode;
500 //if(!dwc_otg_connid(core_if))
501 // dwc_otg_force_host(core_if);
503 else if(USB_MODE_FORCE_HOST == core_if->usb_mode)
505 core_if->usb_mode = new_mode;
506 dwc_otg_set_gusbcfg(core_if, new_mode);
508 if(dwc_otg_is_device_mode(core_if))
510 dwc_otg_force_device(core_if);
512 //if(dwc_otg_connid(core_if))
513 // hub_disconnect_device();
514 //core_if->usb_mode = new_mode;
515 // dwc_otg_force_device(core_if);
524 static DRIVER_ATTR(force_usb_mode, 0666/*S_IRUGO|S_IWUSR*/, force_usb_mode_show, force_usb_mode_store);
526 static ssize_t dwc_otg_enable_show( struct device *_dev,
527 struct device_attribute *attr, char *buf)
529 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)_dev->platform_data));
530 return sprintf (buf, "%d\n", otg_dev->hcd->host_enabled);
533 static ssize_t dwc_otg_enable_store( struct device *_dev,
534 struct device_attribute *attr,
535 const char *buf, size_t count )
537 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)_dev->platform_data));
538 dwc_otg_core_if_t *_core_if = otg_dev->core_if;
539 struct platform_device *pdev = to_platform_device(_dev);
540 uint32_t val = simple_strtoul(buf, NULL, 16);
541 struct dwc_otg_platform_data *pldata = _dev->platform_data;
542 if(otg_dev->hcd->host_enabled == val)
545 otg_dev->hcd->host_enabled = val;
546 if(val == 0) // enable -> disable
548 DWC_PRINT("disable host controller:%s,id:%d\n",pdev->name,pdev->id);
550 if (_core_if->hcd_cb && _core_if->hcd_cb->disconnect) {
551 _core_if->hcd_cb->disconnect( _core_if->hcd_cb->p );
554 if (_core_if->hcd_cb && _core_if->hcd_cb->stop) {
555 _core_if->hcd_cb->stop( _core_if->hcd_cb->p );
557 if(pldata->phy_status==USB_PHY_ENABLED){
558 pldata->phy_suspend(pldata,USB_PHY_SUSPEND);
560 pldata->clock_enable(pldata, 0);
565 DWC_PRINT("enable host controller:%s\n",pdev->name);
566 if( pldata->phy_status == USB_PHY_SUSPEND ){
567 pldata->clock_enable( pldata, 1);
568 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
571 if (_core_if->hcd_cb && _core_if->hcd_cb->start) {
572 _core_if->hcd_cb->start( _core_if->hcd_cb->p );
578 static DEVICE_ATTR(enable, S_IRUGO|S_IWUSR, dwc_otg_enable_show, dwc_otg_enable_store);
580 static ssize_t dwc_otg_conn_en_show(struct device_driver *_drv, char *_buf)
582 #ifndef CONFIG_DWC_OTG_HOST_ONLY
583 dwc_otg_device_t *otg_dev = g_otgdev;
584 dwc_otg_pcd_t *_pcd = otg_dev->pcd;
585 return sprintf (_buf, "%d\n", _pcd->conn_en);
587 return sprintf(_buf, "0\n");
591 static ssize_t dwc_otg_conn_en_store(struct device_driver *_drv, const char *_buf,
594 #ifndef CONFIG_DWC_OTG_HOST_ONLY
595 int enable = simple_strtoul(_buf, NULL, 10);
596 dwc_otg_device_t *otg_dev = g_otgdev;
597 dwc_otg_pcd_t *_pcd = otg_dev->pcd;
598 DWC_PRINT("%s %d->%d\n",__func__, _pcd->conn_en, enable);
600 _pcd->conn_en = enable;
604 static DRIVER_ATTR(dwc_otg_conn_en, S_IRUGO|S_IWUSR, dwc_otg_conn_en_show, dwc_otg_conn_en_store);
606 #ifdef CONFIG_RK_USB_UART
608 extern int get_gadget_connect_flag(void);
609 extern int dwc_vbus_status(void);
613 write 1 to /sys/bus/platform/drivers/usb20_otg/dwc_otg_force_uart
614 can stop check_vbus_timer and force usb_phy bypass to uart mode
616 write 0 comes back to normal usb operate mode
619 static ssize_t dwc_otg_force_uart_store(struct device_driver *_drv, const char *_buf,
622 int enable = simple_strtoul(_buf, NULL, 10);
623 dwc_otg_device_t *otg_dev = g_otgdev;
624 dwc_otg_pcd_t *_pcd = otg_dev->pcd;
625 struct dwc_otg_platform_data *pldata = otg_dev->pldata;
629 if(!get_gadget_connect_flag() &&
630 dwc_otg_is_device_mode(otg_dev->core_if))
632 disable_irq(IRQ_OTG_BVALID);
633 del_timer(&_pcd->check_vbus_timer);
634 pldata->phy_suspend(pldata,USB_PHY_SUSPEND);
635 pldata->dwc_otg_uart_mode(pldata,PHY_UART_MODE);
636 _pcd->vbus_status = 2;
639 printk("mode mismatch!\n");
644 _pcd->vbus_status == 0;
645 _pcd->vbus_status = 0;
646 pldata->dwc_otg_uart_mode(pldata,PHY_USB_MODE);
647 dwc_otg_pcd_start_vbus_timer(_pcd);
648 enable_irq(IRQ_OTG_BVALID);
652 static DRIVER_ATTR(dwc_otg_force_uart, S_IRUGO|S_IWUSR, NULL, dwc_otg_force_uart_store);
654 #ifndef CONFIG_DWC_OTG_HOST_ONLY
655 static ssize_t vbus_status_show(struct device_driver *_drv, char *_buf)
657 dwc_otg_device_t *otg_dev = g_otgdev;
658 dwc_otg_pcd_t *_pcd = otg_dev->pcd;
659 return sprintf (_buf, "%d\n", _pcd->vbus_status);
661 static DRIVER_ATTR(vbus_status, S_IRUGO|S_IWUSR, vbus_status_show, NULL);
663 volatile depctl_data_t depctl_ep0 = {.d32 = 0};
664 volatile depctl_data_t depctl_ep2 = {.d32 = 0};
665 volatile depctl_data_t depctl_ep4 = {.d32 = 0};
666 void dwc_otg_epout_save(void)
668 dwc_otg_device_t *otg_dev = g_otgdev;
669 dwc_otg_dev_if_t *dev_if = otg_dev->core_if->dev_if;
670 volatile depctl_data_t depctl = {.d32 = 0};
671 volatile grstctl_t grstctl = {.d32 = 0};
672 grstctl.d32 = dwc_read_reg32(&otg_dev->core_if->core_global_regs->grstctl);
674 while(grstctl.b.ahbidle != 1)
676 grstctl.d32 = dwc_read_reg32(&otg_dev->core_if->core_global_regs->grstctl);
678 depctl_ep0.d32 = dwc_read_reg32(&dev_if->out_ep_regs[0]->doepctl);
679 depctl.d32 = depctl_ep0.d32;
683 dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, depctl.d32);
685 depctl_ep2.d32 = dwc_read_reg32(&dev_if->out_ep_regs[2]->doepctl);
686 depctl.d32 = depctl_ep2.d32;
690 dwc_write_reg32(&dev_if->out_ep_regs[2]->doepctl, depctl.d32);
692 depctl_ep4.d32 = dwc_read_reg32(&dev_if->out_ep_regs[4]->doepctl);
693 depctl.d32 = depctl_ep4.d32;
697 dwc_write_reg32(&dev_if->out_ep_regs[4]->doepctl, depctl.d32);
700 void dwc_otg_epout_restore(void)
702 dwc_otg_device_t *otg_dev = g_otgdev;
703 dwc_otg_dev_if_t *dev_if = otg_dev->core_if->dev_if;
704 dwc_write_reg32(&dev_if->out_ep_regs[0]->doepctl, depctl_ep0.d32);
705 dwc_write_reg32(&dev_if->out_ep_regs[2]->doepctl, depctl_ep2.d32);
706 dwc_write_reg32(&dev_if->out_ep_regs[4]->doepctl, depctl_ep4.d32);
710 * This function is called during module intialization to verify that
711 * the module parameters are in a valid state.
713 static int check_parameters(dwc_otg_core_if_t *core_if)
717 dwc_otg_core_params_t *core_params;
718 core_params = core_if->core_params;
719 /* Checks if the parameter is outside of its valid range of values */
720 #define DWC_OTG_PARAM_TEST(_param_,_low_,_high_) \
721 ((core_params->_param_ < (_low_)) || \
722 (core_params->_param_ > (_high_)))
724 /* If the parameter has been set by the user, check that the parameter value is
725 * within the value range of values. If not, report a module error. */
726 #define DWC_OTG_PARAM_ERR(_param_,_low_,_high_,_string_) \
728 if (core_params->_param_ != -1) { \
729 if (DWC_OTG_PARAM_TEST(_param_,(_low_),(_high_))) { \
730 DWC_ERROR("`%d' invalid for parameter `%s'\n", \
731 core_params->_param_, _string_); \
732 core_params->_param_ = dwc_param_##_param_##_default; \
738 DWC_OTG_PARAM_ERR(opt,0,1,"opt");
739 DWC_OTG_PARAM_ERR(otg_cap,0,2,"otg_cap");
740 DWC_OTG_PARAM_ERR(dma_enable,0,1,"dma_enable");
741 DWC_OTG_PARAM_ERR(speed,0,1,"speed");
742 DWC_OTG_PARAM_ERR(host_support_fs_ls_low_power,0,1,"host_support_fs_ls_low_power");
743 DWC_OTG_PARAM_ERR(host_ls_low_power_phy_clk,0,1,"host_ls_low_power_phy_clk");
744 DWC_OTG_PARAM_ERR(enable_dynamic_fifo,0,1,"enable_dynamic_fifo");
745 DWC_OTG_PARAM_ERR(data_fifo_size,32,32768,"data_fifo_size");
746 DWC_OTG_PARAM_ERR(dev_rx_fifo_size,16,32768,"dev_rx_fifo_size");
747 DWC_OTG_PARAM_ERR(dev_nperio_tx_fifo_size,16,32768,"dev_nperio_tx_fifo_size");
748 DWC_OTG_PARAM_ERR(host_rx_fifo_size,16,32768,"host_rx_fifo_size");
749 DWC_OTG_PARAM_ERR(host_nperio_tx_fifo_size,16,32768,"host_nperio_tx_fifo_size");
750 DWC_OTG_PARAM_ERR(host_perio_tx_fifo_size,16,32768,"host_perio_tx_fifo_size");
751 DWC_OTG_PARAM_ERR(max_transfer_size,2047,524288,"max_transfer_size");
752 DWC_OTG_PARAM_ERR(max_packet_count,15,511,"max_packet_count");
753 DWC_OTG_PARAM_ERR(host_channels,1,16,"host_channels");
754 DWC_OTG_PARAM_ERR(dev_endpoints,1,15,"dev_endpoints");
755 DWC_OTG_PARAM_ERR(phy_type,0,2,"phy_type");
756 DWC_OTG_PARAM_ERR(phy_ulpi_ddr,0,1,"phy_ulpi_ddr");
757 DWC_OTG_PARAM_ERR(phy_ulpi_ext_vbus,0,1,"phy_ulpi_ext_vbus");
758 DWC_OTG_PARAM_ERR(i2c_enable,0,1,"i2c_enable");
759 DWC_OTG_PARAM_ERR(ulpi_fs_ls,0,1,"ulpi_fs_ls");
760 DWC_OTG_PARAM_ERR(ts_dline,0,1,"ts_dline");
762 if (core_params->dma_burst_size != -1)
764 if (DWC_OTG_PARAM_TEST(dma_burst_size,1,1) &&
765 DWC_OTG_PARAM_TEST(dma_burst_size,4,4) &&
766 DWC_OTG_PARAM_TEST(dma_burst_size,8,8) &&
767 DWC_OTG_PARAM_TEST(dma_burst_size,16,16) &&
768 DWC_OTG_PARAM_TEST(dma_burst_size,32,32) &&
769 DWC_OTG_PARAM_TEST(dma_burst_size,64,64) &&
770 DWC_OTG_PARAM_TEST(dma_burst_size,128,128) &&
771 DWC_OTG_PARAM_TEST(dma_burst_size,256,256))
773 DWC_ERROR("`%d' invalid for parameter `dma_burst_size'\n",
774 core_params->dma_burst_size);
775 core_params->dma_burst_size = 32;
780 if (core_params->phy_utmi_width != -1)
782 if (DWC_OTG_PARAM_TEST(phy_utmi_width,8,8) &&
783 DWC_OTG_PARAM_TEST(phy_utmi_width,16,16))
785 DWC_ERROR("`%d' invalid for parameter `phy_utmi_width'\n",
786 core_params->phy_utmi_width);
787 core_params->phy_utmi_width = 16;
794 /** @todo should be like above */
795 //DWC_OTG_PARAM_ERR(dev_perio_tx_fifo_size[i],4,768,"dev_perio_tx_fifo_size");
796 if (core_params->dev_perio_tx_fifo_size[i] != -1)
798 if (DWC_OTG_PARAM_TEST(dev_perio_tx_fifo_size[i],4,768))
800 DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
801 core_params->dev_perio_tx_fifo_size[i], "dev_perio_tx_fifo_size", i);
802 core_params->dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
808 DWC_OTG_PARAM_ERR(en_multiple_tx_fifo,0,1,"en_multiple_tx_fifo");
812 /** @todo should be like above */
813 //DWC_OTG_PARAM_ERR(dev_tx_fifo_size[i],4,768,"dev_tx_fifo_size");
814 if (core_params->dev_tx_fifo_size[i] != -1)
816 if (DWC_OTG_PARAM_TEST(dev_tx_fifo_size[i],4,768))
818 DWC_ERROR("`%d' invalid for parameter `%s_%d'\n",
819 core_params->dev_tx_fifo_size[i], "dev_tx_fifo_size", i);
820 core_params->dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
826 DWC_OTG_PARAM_ERR(thr_ctl, 0, 7, "thr_ctl");
827 DWC_OTG_PARAM_ERR(tx_thr_length, 8, 128, "tx_thr_length");
828 DWC_OTG_PARAM_ERR(rx_thr_length, 8, 128, "rx_thr_length");
831 /* At this point, all module parameters that have been set by the user
832 * are valid, and those that have not are left unset. Now set their
833 * default values and/or check the parameters against the hardware
834 * configurations of the OTG core. */
838 /* This sets the parameter to the default value if it has not been set by the
840 #define DWC_OTG_PARAM_SET_DEFAULT(_param_) \
843 if (core_params->_param_ == -1) { \
845 core_params->_param_ = dwc_param_##_param_##_default; \
850 /* This checks the macro agains the hardware configuration to see if it is
851 * valid. It is possible that the default value could be invalid. In this
852 * case, it will report a module error if the user touched the parameter.
853 * Otherwise it will adjust the value without any error. */
854 #define DWC_OTG_PARAM_CHECK_VALID(_param_,_str_,_is_valid_,_set_valid_) \
856 int changed = DWC_OTG_PARAM_SET_DEFAULT(_param_); \
858 if (!(_is_valid_)) { \
860 DWC_ERROR("`%d' invalid for parameter `%s'. Check HW configuration.\n", core_params->_param_,_str_); \
863 core_params->_param_ = (_set_valid_); \
869 retval += DWC_OTG_PARAM_CHECK_VALID(otg_cap,"otg_cap",
873 switch (core_params->otg_cap) {
874 case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
875 if (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) valid = 0;
877 case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
878 if ((core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) &&
879 (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) &&
880 (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) &&
881 (core_if->hwcfg2.b.op_mode != DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST))
886 case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
892 (((core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG) ||
893 (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG) ||
894 (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE) ||
895 (core_if->hwcfg2.b.op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
896 DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
897 DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE));
899 retval += DWC_OTG_PARAM_CHECK_VALID(dma_enable,"dma_enable",
900 ((core_params->dma_enable == 1) && (core_if->hwcfg2.b.architecture == 0)) ? 0 : 1,
903 retval += DWC_OTG_PARAM_CHECK_VALID(opt,"opt",
907 DWC_OTG_PARAM_SET_DEFAULT(dma_burst_size);
909 retval += DWC_OTG_PARAM_CHECK_VALID(host_support_fs_ls_low_power,
910 "host_support_fs_ls_low_power",
913 retval += DWC_OTG_PARAM_CHECK_VALID(enable_dynamic_fifo,
914 "enable_dynamic_fifo",
915 ((core_params->enable_dynamic_fifo == 0) ||
916 (core_if->hwcfg2.b.dynamic_fifo == 1)), 0);
919 retval += DWC_OTG_PARAM_CHECK_VALID(data_fifo_size,
921 (core_params->data_fifo_size <= core_if->hwcfg3.b.dfifo_depth),
922 core_if->hwcfg3.b.dfifo_depth);
924 retval += DWC_OTG_PARAM_CHECK_VALID(dev_rx_fifo_size,
926 (core_params->dev_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
927 dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
929 retval += DWC_OTG_PARAM_CHECK_VALID(dev_nperio_tx_fifo_size,
930 "dev_nperio_tx_fifo_size",
931 (core_params->dev_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
932 (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
934 retval += DWC_OTG_PARAM_CHECK_VALID(host_rx_fifo_size,
936 (core_params->host_rx_fifo_size <= dwc_read_reg32(&core_if->core_global_regs->grxfsiz)),
937 dwc_read_reg32(&core_if->core_global_regs->grxfsiz));
940 retval += DWC_OTG_PARAM_CHECK_VALID(host_nperio_tx_fifo_size,
941 "host_nperio_tx_fifo_size",
942 (core_params->host_nperio_tx_fifo_size <= (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16)),
943 (dwc_read_reg32(&core_if->core_global_regs->gnptxfsiz) >> 16));
944 retval += DWC_OTG_PARAM_CHECK_VALID(host_perio_tx_fifo_size,
945 "host_perio_tx_fifo_size",
946 (core_params->host_perio_tx_fifo_size <= ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16))),
947 ((dwc_read_reg32(&core_if->core_global_regs->hptxfsiz) >> 16)));
949 retval += DWC_OTG_PARAM_CHECK_VALID(max_transfer_size,
951 (core_params->max_transfer_size < (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))),
952 ((1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11)) - 1));
954 retval += DWC_OTG_PARAM_CHECK_VALID(max_packet_count,
956 (core_params->max_packet_count < (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))),
957 ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1));
959 retval += DWC_OTG_PARAM_CHECK_VALID(host_channels,
961 (core_params->host_channels <= (core_if->hwcfg2.b.num_host_chan + 1)),
962 (core_if->hwcfg2.b.num_host_chan + 1));
964 retval += DWC_OTG_PARAM_CHECK_VALID(dev_endpoints,
966 (core_params->dev_endpoints <= (core_if->hwcfg2.b.num_dev_ep)),
967 core_if->hwcfg2.b.num_dev_ep);
970 * Define the following to disable the FS PHY Hardware checking. This is for
971 * internal testing only.
973 * #define NO_FS_PHY_HW_CHECKS
976 #ifdef NO_FS_PHY_HW_CHECKS
977 retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
980 retval += DWC_OTG_PARAM_CHECK_VALID(phy_type,
984 if ((core_params->phy_type == DWC_PHY_TYPE_PARAM_UTMI) &&
985 ((core_if->hwcfg2.b.hs_phy_type == 1) ||
986 (core_if->hwcfg2.b.hs_phy_type == 3)))
990 else if ((core_params->phy_type == DWC_PHY_TYPE_PARAM_ULPI) &&
991 ((core_if->hwcfg2.b.hs_phy_type == 2) ||
992 (core_if->hwcfg2.b.hs_phy_type == 3)))
996 else if ((core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
997 (core_if->hwcfg2.b.fs_phy_type == 1))
1004 int set = DWC_PHY_TYPE_PARAM_FS;
1005 if (core_if->hwcfg2.b.hs_phy_type) {
1006 if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
1007 (core_if->hwcfg2.b.hs_phy_type == 1)) {
1008 set = DWC_PHY_TYPE_PARAM_UTMI;
1011 set = DWC_PHY_TYPE_PARAM_ULPI;
1018 retval += DWC_OTG_PARAM_CHECK_VALID(speed,"speed",
1019 (core_params->speed == 0) && (core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1,
1020 core_params->phy_type == DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
1022 retval += DWC_OTG_PARAM_CHECK_VALID(host_ls_low_power_phy_clk,
1023 "host_ls_low_power_phy_clk",
1024 ((core_params->host_ls_low_power_phy_clk == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ) && (core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) ? 0 : 1),
1025 ((core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) ? DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ : DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ));
1027 DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ddr);
1028 DWC_OTG_PARAM_SET_DEFAULT(phy_ulpi_ext_vbus);
1029 DWC_OTG_PARAM_SET_DEFAULT(phy_utmi_width);
1030 DWC_OTG_PARAM_SET_DEFAULT(ulpi_fs_ls);
1031 DWC_OTG_PARAM_SET_DEFAULT(ts_dline);
1033 #ifdef NO_FS_PHY_HW_CHECKS
1034 retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
1035 "i2c_enable", 1, 0);
1037 retval += DWC_OTG_PARAM_CHECK_VALID(i2c_enable,
1039 (core_params->i2c_enable == 1) && (core_if->hwcfg3.b.i2c == 0) ? 0 : 1,
1043 for (i=0; i<15; i++)
1048 if (core_params->dev_perio_tx_fifo_size[i] == -1)
1051 core_params->dev_perio_tx_fifo_size[i] = dwc_param_dev_perio_tx_fifo_size_default;
1053 if (!(core_params->dev_perio_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]))))
1057 DWC_ERROR("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n", core_params->dev_perio_tx_fifo_size[i],i);
1060 core_params->dev_perio_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
1066 retval += DWC_OTG_PARAM_CHECK_VALID(en_multiple_tx_fifo,"en_multiple_tx_fifo",
1067 ((core_params->en_multiple_tx_fifo == 1) && (core_if->hwcfg4.b.ded_fifo_en == 0)) ? 0 : 1,
1071 for (i=0; i<15; i++)
1077 if (core_params->dev_tx_fifo_size[i] == -1)
1080 core_params->dev_tx_fifo_size[i] = dwc_param_dev_tx_fifo_size_default;
1082 if (!(core_params->dev_tx_fifo_size[i] <= (dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]))))
1086 DWC_ERROR("%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n", core_params->dev_tx_fifo_size[i],i);
1089 core_params->dev_tx_fifo_size[i] = dwc_read_reg32(&core_if->core_global_regs->dptxfsiz_dieptxf[i]);
1096 DWC_OTG_PARAM_SET_DEFAULT(thr_ctl);
1097 DWC_OTG_PARAM_SET_DEFAULT(tx_thr_length);
1098 DWC_OTG_PARAM_SET_DEFAULT(rx_thr_length);
1103 * This function is the top level interrupt handler for the Common
1104 * (Device and host modes) interrupts.
1106 static irqreturn_t dwc_otg_common_irq(int _irq, void *_dev)
1108 dwc_otg_device_t *otg_dev = _dev;
1109 int32_t retval = IRQ_NONE;
1111 retval = dwc_otg_handle_common_intr( otg_dev->core_if );
1112 return IRQ_RETVAL(retval);
1116 * This function is called when a lm_device is unregistered with the
1117 * dwc_otg_driver. This happens, for example, when the rmmod command is
1118 * executed. The device may or may not be electrically present. If it is
1119 * present, the driver stops device processing. Any resources used on behalf
1120 * of this device are freed.
1124 static int dwc_otg_driver_remove(struct platform_device *pdev)
1126 struct device *dev = &pdev->dev;
1127 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)dev->platform_data));
1128 DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, pdev);
1130 if (otg_dev == NULL)
1132 /* Memory allocation for the dwc_otg_device failed. */
1139 if (otg_dev->common_irq_installed)
1141 free_irq( platform_get_irq(to_platform_device(dev),0), otg_dev );
1144 #ifndef CONFIG_DWC_OTG_DEVICE_ONLY
1145 if (otg_dev->hcd != NULL)
1147 dwc_otg_hcd_remove(dev);
1151 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1152 if (otg_dev->pcd != NULL)
1154 dwc_otg_pcd_remove(dev);
1157 if (otg_dev->core_if != NULL)
1159 dwc_otg_cil_remove( otg_dev->core_if );
1163 * Remove the device attributes
1165 dwc_otg_attr_remove(dev);
1168 * Return the memory.
1170 if (otg_dev->base != NULL)
1172 iounmap(otg_dev->base);
1177 * Clear the drvdata pointer.
1179 // dev->platform_data = 0;
1181 #ifdef DWC_BOTH_HOST_SLAVE
1182 dwc_otg_module_params.host_rx_fifo_size = -1;
1183 dwc_otg_module_params.dev_nperio_tx_fifo_size = -1;
1184 dwc_otg_module_params.host_nperio_tx_fifo_size = -1;
1185 dwc_otg_module_params.dev_rx_fifo_size = -1;
1191 * This function is called when an lm_device is bound to a
1192 * dwc_otg_driver. It creates the driver components required to
1193 * control the device (CIL, HCD, and PCD) and it initializes the
1194 * device. The driver components are stored in a dwc_otg_device
1195 * structure. A reference to the dwc_otg_device is saved in the
1196 * lm_device. This allows the driver to access the dwc_otg_device
1197 * structure on subsequent calls to driver methods for this device.
1199 * @param[in] pdev platform_device definition
1201 static __devinit int dwc_otg_driver_probe(struct platform_device *pdev)
1204 struct resource *res_base;
1205 struct device *dev = &pdev->dev;
1206 dwc_otg_device_t *dwc_otg_device;
1209 struct dwc_otg_platform_data *pldata = dev->platform_data;
1211 // clock and hw init
1216 if(pldata->clock_init){
1217 pldata->clock_init(pldata);
1218 pldata->clock_enable(pldata, 1);
1221 if(pldata->phy_suspend)
1222 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1224 if(pldata->soft_reset)
1225 pldata->soft_reset();
1227 dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
1229 if (dwc_otg_device == 0)
1231 dev_err(dev, "kmalloc of dwc_otg_device failed\n");
1236 memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
1237 dwc_otg_device->reg_offset = 0xFFFFFFFF;
1240 * Map the DWC_otg Core memory into virtual address space.
1243 res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1247 dwc_otg_device->base = ioremap(res_base->start,res_base->end-res_base->start+1);
1248 if (dwc_otg_device->base == NULL)
1250 dev_err(dev, "ioremap() failed\n");
1255 dwc_otg_device->base = (void*)(USB_OTG_BASE_ADDR_VA);
1257 if (dwc_otg_device->base == NULL)
1259 dev_err(dev, "ioremap() failed\n");
1264 dev_dbg(dev, "base=0x%08x\n", (unsigned)dwc_otg_device->base);
1266 * Attempt to ensure this device is really a DWC_otg Controller.
1267 * Read and verify the SNPSID register contents. The value should be
1268 * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
1270 snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
1271 if ((snpsid & 0xFFFFF000) != 0x4F542000)
1273 dev_err(dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
1279 * Initialize driver data to point to the global DWC_otg
1282 //dev->platform_data = dwc_otg_device;
1283 pldata->privdata = dwc_otg_device;
1284 dwc_otg_device->pldata = (void *)pldata;
1286 dev_dbg(dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
1288 g_otgdev = dwc_otg_device;
1290 dwc_otg_device->core_if = dwc_otg_cil_init( dwc_otg_device->base,
1291 &dwc_otg_module_params);
1292 if (dwc_otg_device->core_if == 0)
1294 dev_err(dev, "CIL initialization failed!\n");
1298 dwc_otg_device->core_if->otg_dev = dwc_otg_device;
1300 * Validate parameter values.
1302 if (check_parameters(dwc_otg_device->core_if) != 0)
1309 * Create Device Attributes in sysfs
1311 dwc_otg_attr_create(dev);
1312 #ifndef CONFIG_DWC_OTG_DEVICE_ONLY
1313 retval |= device_create_file(dev, &dev_attr_enable);
1317 * Disable the global interrupt until all the interrupt
1318 * handlers are installed.
1320 dwc_otg_disable_global_interrupts( dwc_otg_device->core_if );
1322 * Install the interrupt handler for the common interrupts before
1323 * enabling common interrupts in core_init below.
1325 irq = platform_get_irq(to_platform_device(dev),0);
1326 DWC_DEBUGPL( DBG_CIL, "registering (common) handler for irq%d\n",
1328 retval = request_irq(irq, dwc_otg_common_irq,
1329 IRQF_SHARED, "dwc_otg", dwc_otg_device );
1332 DWC_ERROR("request of irq%d failed\n", irq);
1338 dwc_otg_device->common_irq_installed = 1;
1341 #ifdef CONFIG_MACH_IPMATE
1342 set_irq_type(irq, IRQT_LOW);
1345 #ifdef CONFIG_DWC_OTG_DEVICE_ONLY
1346 dwc_otg_device->core_if->usb_mode = USB_MODE_FORCE_DEVICE;
1348 #ifdef CONFIG_DWC_OTG_HOST_ONLY
1349 dwc_otg_device->core_if->usb_mode = USB_MODE_FORCE_HOST;
1352 #ifdef CONFIG_DWC_OTG_DEFAULT_HOST
1353 dwc_otg_device->core_if->usb_mode = USB_MODE_FORCE_HOST;
1355 dwc_otg_device->core_if->usb_mode = USB_MODE_NORMAL;
1356 #ifdef CONFIG_DWC_OTG_DEFAULT_DEVICE
1357 dwc_otg_device->core_if->usb_mode = USB_MODE_FORCE_DEVICE;
1365 * Initialize the DWC_otg core.
1367 dwc_otg_core_init( dwc_otg_device->core_if );
1369 /* Initialize the bus state. If the core is in Device Mode
1370 * HALT the USB bus and return. */
1371 #ifndef CONFIG_DWC_OTG_DEVICE_ONLY
1373 * Initialize the HCD
1375 retval = dwc_otg_hcd_init(dev);
1378 DWC_ERROR("dwc_otg_hcd_init failed\n");
1379 dwc_otg_device->hcd = NULL;
1383 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1385 * Initialize the PCD
1387 retval = dwc_otg_pcd_init(dev);
1390 DWC_ERROR("dwc_otg_pcd_init failed\n");
1391 dwc_otg_device->pcd = NULL;
1398 * Enable the global interrupt after all the interrupt
1399 * handlers are installed.
1401 dwc_otg_enable_global_interrupts( dwc_otg_device->core_if );
1404 devm_kfree(&pdev->dev, dwc_otg_device);
1405 DWC_PRINT("dwc_otg_driver_probe fail,everest\n");
1409 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1410 static int dwc_otg_driver_suspend(struct platform_device *_dev , pm_message_t state )
1412 struct device *dev = &_dev->dev;
1413 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)dev->platform_data));
1414 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1415 struct dwc_otg_platform_data *pldata = dev->platform_data;
1416 if(core_if->op_state == A_HOST)
1418 DWC_PRINT("%s,A_HOST mode\n", __func__);
1421 /* Clear any pending interrupts */
1422 dwc_write_reg32( &core_if->core_global_regs->gintsts, 0xFFFFFFFF);
1423 // dwc_otg_disable_global_interrupts(core_if);
1424 if( pldata->phy_status == 0 ){
1425 /* no vbus detect here , close usb phy */
1426 pldata->phy_suspend(pldata, USB_PHY_SUSPEND);
1428 pldata->clock_enable( pldata, 0);
1430 // del_timer(&otg_dev->pcd->check_vbus_timer);
1435 static int dwc_otg_driver_suspend(struct platform_device *_dev , pm_message_t state )
1441 static int dwc_otg_driver_resume(struct platform_device *_dev )
1443 struct device *dev = &_dev->dev;
1444 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)dev->platform_data));
1445 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1446 dctl_data_t dctl = {.d32=0};
1447 struct dwc_otg_platform_data *pldata = dev->platform_data;
1449 dwc_otg_core_global_regs_t *global_regs =
1450 core_if->core_global_regs;
1451 if(core_if->op_state == A_HOST)
1453 DWC_PRINT("%s,A_HOST mode\n", __func__);
1459 static void dwc_otg_driver_shutdown(struct platform_device *_dev )
1461 struct device *dev = &_dev->dev;
1462 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)dev->platform_data));
1463 dwc_otg_core_if_t *core_if = otg_dev->core_if;
1464 dctl_data_t dctl = {.d32=0};
1466 DWC_PRINT("%s:: disconnect USB\n" , __func__ );
1467 if(core_if->op_state == A_HOST)
1469 if (core_if->hcd_cb && core_if->hcd_cb->stop) {
1470 core_if->hcd_cb->stop( core_if->hcd_cb->p );
1474 /* soft disconnect */
1475 dctl.d32 = dwc_read_reg32( &core_if->dev_if->dev_global_regs->dctl );
1476 dctl.b.sftdiscon = 1;
1477 dwc_write_reg32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 );
1479 /* Clear any pending interrupts */
1480 dwc_write_reg32( &core_if->core_global_regs->gintsts, 0xFFFFFFFF);
1485 * This structure defines the methods to be called by a bus driver
1486 * during the lifecycle of a device on that bus. Both drivers and
1487 * devices are registered with a bus driver. The bus driver matches
1488 * devices to drivers based on information in the device and driver
1491 * The probe function is called when the bus driver matches a device
1492 * to this driver. The remove function is called when a device is
1493 * unregistered with the bus driver.
1495 static struct platform_driver dwc_otg_driver = {
1496 .probe = dwc_otg_driver_probe,
1497 .remove = dwc_otg_driver_remove,
1498 .suspend = dwc_otg_driver_suspend,
1499 .resume = dwc_otg_driver_resume,
1500 .shutdown = dwc_otg_driver_shutdown,
1502 .name = dwc_driver_name,
1503 .owner = THIS_MODULE},
1507 #ifdef CONFIG_USB20_HOST
1508 extern void dwc_otg_hcd_remove(struct device *dev);
1509 extern int __devinit host20_hcd_init(struct device *_dev);
1512 static int host20_driver_remove(struct platform_device *pdev)
1514 struct device *dev = &pdev->dev;
1515 dwc_otg_device_t *otg_dev = (dwc_otg_device_t *)(*((uint32_t *)dev->platform_data));
1516 DWC_DEBUGPL(DBG_ANY, "%s(%p)\n", __func__, pdev);
1518 if (otg_dev == NULL)
1520 /* Memory allocation for the dwc_otg_device failed. */
1527 if (otg_dev->common_irq_installed)
1529 free_irq( platform_get_irq(to_platform_device(dev),0), otg_dev );
1532 if (otg_dev->hcd != NULL)
1534 dwc_otg_hcd_remove(dev);
1537 if (otg_dev->core_if != NULL)
1539 dwc_otg_cil_remove( otg_dev->core_if );
1543 * Remove the device attributes
1545 //dwc_otg_attr_remove(dev);
1548 * Return the memory.
1550 if (otg_dev->base != NULL)
1552 iounmap(otg_dev->base);
1557 * Clear the drvdata pointer.
1559 // dev->platform_data = 0;
1566 * This function is called when an lm_device is bound to a
1567 * dwc_otg_driver. It creates the driver components required to
1568 * control the device (CIL, HCD, and PCD) and it initializes the
1569 * device. The driver components are stored in a dwc_otg_device
1570 * structure. A reference to the dwc_otg_device is saved in the
1571 * lm_device. This allows the driver to access the dwc_otg_device
1572 * structure on subsequent calls to driver methods for this device.
1574 * @param[in] pdev platform_device definition
1576 static __devinit int host20_driver_probe(struct platform_device *pdev)
1578 struct resource *res_base;
1580 struct device *dev = &pdev->dev;
1581 dwc_otg_device_t *dwc_otg_device;
1584 struct dwc_otg_platform_data *pldata = dev->platform_data;
1586 // clock and hw init
1590 if(pldata->clock_init){
1591 pldata->clock_init(pldata);
1592 pldata->clock_enable(pldata, 1);
1595 if(pldata->phy_suspend)
1596 pldata->phy_suspend(pldata, USB_PHY_ENABLED);
1598 if(pldata->soft_reset)
1599 pldata->soft_reset();
1605 dwc_otg_device = kmalloc(sizeof(dwc_otg_device_t), GFP_KERNEL);
1607 if (dwc_otg_device == 0)
1609 dev_err(dev, "kmalloc of dwc_otg_device failed\n");
1614 memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
1615 dwc_otg_device->reg_offset = 0xFFFFFFFF;
1618 * Map the DWC_otg Core memory into virtual address space.
1621 res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1625 dwc_otg_device->base =
1626 ioremap(res_base->start,res_base->end-res_base->start+1);
1627 DWC_PRINT("%s host2.0 reg addr: 0x%x remap:0x%x\n",__func__,
1628 (unsigned)res_base->start, (unsigned)dwc_otg_device->base);
1629 if (dwc_otg_device->base == NULL)
1631 DWC_ERROR("ioremap() failed\n");
1635 DWC_DEBUGPL( DBG_CIL, "base addr for rk29 host20:0x%x\n", (unsigned)dwc_otg_device->base);
1637 * Attempt to ensure this device is really a DWC_otg Controller.
1638 * Read and verify the SNPSID register contents. The value should be
1639 * 0x45F42XXX, which corresponds to "OT2", as in "OTG version 2.XX".
1641 snpsid = dwc_read_reg32((uint32_t *)((uint8_t *)dwc_otg_device->base + 0x40));
1642 if ((snpsid & 0xFFFFF000) != 0x4F542000)
1644 DWC_PRINT("%s::snpsid=0x%x,want 0x%x" , __func__ , snpsid , 0x4F542000 );
1645 dev_err(dev, "Bad value for SNPSID: 0x%08x\n", snpsid);
1651 * Initialize driver data to point to the global DWC_otg
1654 pldata->privdata = dwc_otg_device;
1655 dwc_otg_device->pldata = (void *)pldata;
1657 DWC_DEBUGPL(DBG_CIL, "dwc_otg_device=0x%p\n", dwc_otg_device);
1658 g_host20 = dwc_otg_device;
1660 dwc_otg_device->core_if = dwc_otg_cil_init( dwc_otg_device->base,
1661 &host20_module_params);
1662 if (dwc_otg_device->core_if == 0)
1664 dev_err(dev, "CIL initialization failed!\n");
1669 dwc_otg_device->core_if->otg_dev = dwc_otg_device;
1671 * Validate parameter values.
1673 if (check_parameters(dwc_otg_device->core_if) != 0)
1680 * Create Device Attributes in sysfs
1682 dwc_otg_attr_create(dev);
1683 retval |= device_create_file(dev, &dev_attr_enable);
1686 * Disable the global interrupt until all the interrupt
1687 * handlers are installed.
1689 dwc_otg_disable_global_interrupts( dwc_otg_device->core_if );
1691 * Install the interrupt handler for the common interrupts before
1692 * enabling common interrupts in core_init below.
1694 irq = platform_get_irq(to_platform_device(dev),0);
1695 DWC_DEBUGPL( DBG_CIL, "registering (common) handler for irq%d\n",
1697 retval = request_irq(irq, dwc_otg_common_irq,
1698 IRQF_SHARED, "dwc_otg", dwc_otg_device );
1701 DWC_ERROR("request of irq%d failed\n", irq);
1707 dwc_otg_device->common_irq_installed = 1;
1711 * Initialize the DWC_otg core.
1713 dwc_otg_core_init( dwc_otg_device->core_if );
1716 * Initialize the HCD
1718 retval = host20_hcd_init(dev);
1721 DWC_ERROR("host20_hcd_init failed\n");
1722 dwc_otg_device->hcd = NULL;
1726 * Enable the global interrupt after all the interrupt
1727 * handlers are installed.
1729 dwc_otg_enable_global_interrupts( dwc_otg_device->core_if );
1734 devm_kfree(&pdev->dev, dwc_otg_device);
1735 DWC_PRINT("host20_driver_probe fail,everest\n");
1739 static struct platform_driver host20_driver = {
1740 .probe = host20_driver_probe,
1741 .remove = host20_driver_remove,
1743 .name = "usb20_host",
1744 .owner = THIS_MODULE},
1749 * This function is called when the dwc_otg_driver is installed with the
1750 * insmod command. It registers the dwc_otg_driver structure with the
1751 * appropriate bus driver. This will cause the dwc_otg_driver_probe function
1752 * to be called. In addition, the bus driver will automatically expose
1753 * attributes defined for the device and driver in the special sysfs file
1758 static int __init dwc_otg_driver_init(void)
1762 * USB2.0 OTG controller
1764 retval = platform_driver_register(&dwc_otg_driver);
1767 DWC_ERROR("%s retval=%d\n", __func__, retval);
1770 if (driver_create_file(&dwc_otg_driver.driver, &driver_attr_version))
1771 pr_warning("DWC_OTG: Failed to create driver version file\n");
1772 if (driver_create_file(&dwc_otg_driver.driver, &driver_attr_debuglevel))
1773 pr_warning("DWC_OTG: Failed to create driver debug level file\n");
1774 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1775 if(driver_create_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_conn_en))
1776 pr_warning("DWC_OTG: Failed to create driver dwc_otg_conn_en file");
1779 #ifdef CONFIG_RK_USB_UART
1780 if(driver_create_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_force_uart))
1781 pr_warning("DWC_OTG: Failed to create driver dwc_otg_force_uart file");
1783 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1784 if(driver_create_file(&dwc_otg_driver.driver, &driver_attr_vbus_status))
1785 pr_warning("DWC_OTG: Failed to create driver vbus status file");
1787 #ifdef DWC_BOTH_HOST_SLAVE
1788 if(driver_create_file(&dwc_otg_driver.driver, &driver_attr_force_usb_mode))
1789 pr_warning("DWC_OTG: Failed to create driver force usb mode file\n");
1793 * USB2.0 host controller
1795 #ifdef CONFIG_USB20_HOST
1796 retval = platform_driver_register(&host20_driver);
1799 DWC_ERROR("%s retval=%d\n", __func__, retval);
1805 * USB1.1 host controller
1808 #ifdef CONFIG_USB11_HOST
1809 retval = platform_driver_register(&host11_driver);
1812 DWC_ERROR("%s retval=%d\n", __func__, retval);
1815 // retval = driver_create_file(&host11_driver.driver, &driver_attr_enable_usb11);
1820 module_init(dwc_otg_driver_init);
1823 * This function is called when the driver is removed from the kernel
1824 * with the rmmod command. The driver unregisters itself with its bus
1828 static void __exit dwc_otg_driver_cleanup(void)
1830 DWC_PRINT("dwc_otg_driver_cleanup()\n");
1832 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
1833 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
1835 #ifdef DWC_BOTH_HOST_SLAVE
1836 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_force_usb_mode);
1838 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1839 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_conn_en);
1842 #ifdef CONFIG_RK_USB_UART
1843 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_dwc_otg_force_uart);
1846 #ifndef CONFIG_DWC_OTG_HOST_ONLY
1847 driver_remove_file(&dwc_otg_driver.driver, &driver_attr_vbus_status);
1850 platform_driver_unregister(&dwc_otg_driver);
1852 #ifdef CONFIG_USB11_HOST
1853 platform_driver_unregister(&host11_driver);
1856 #ifdef CONFIG_USB20_HOST
1857 platform_driver_unregister(&host20_driver);
1859 DWC_PRINT("%s module removed\n", dwc_driver_name);
1861 module_exit(dwc_otg_driver_cleanup);
1863 MODULE_DESCRIPTION(DWC_DRIVER_DESC);
1864 MODULE_AUTHOR("Synopsys Inc.");
1865 MODULE_LICENSE("GPL");
1867 module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
1868 MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
1869 module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
1870 MODULE_PARM_DESC(opt, "OPT Mode");
1871 module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
1872 MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
1873 module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int, 0444);
1874 MODULE_PARM_DESC(dma_burst_size, "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
1875 module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
1876 MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
1877 module_param_named(host_support_fs_ls_low_power, dwc_otg_module_params.host_support_fs_ls_low_power, int, 0444);
1878 MODULE_PARM_DESC(host_support_fs_ls_low_power, "Support Low Power w/FS or LS 0=Support 1=Don't Support");
1879 module_param_named(host_ls_low_power_phy_clk, dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
1880 MODULE_PARM_DESC(host_ls_low_power_phy_clk, "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
1881 module_param_named(enable_dynamic_fifo, dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
1882 MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
1883 module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int, 0444);
1884 MODULE_PARM_DESC(data_fifo_size, "Total number of words in the data FIFO memory 32-32768");
1885 module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size, int, 0444);
1886 MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
1887 module_param_named(dev_nperio_tx_fifo_size, dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
1888 MODULE_PARM_DESC(dev_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
1889 module_param_named(dev_perio_tx_fifo_size_1, dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
1890 MODULE_PARM_DESC(dev_perio_tx_fifo_size_1, "Number of words in the periodic Tx FIFO 4-768");
1891 module_param_named(dev_perio_tx_fifo_size_2, dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
1892 MODULE_PARM_DESC(dev_perio_tx_fifo_size_2, "Number of words in the periodic Tx FIFO 4-768");
1893 module_param_named(dev_perio_tx_fifo_size_3, dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
1894 MODULE_PARM_DESC(dev_perio_tx_fifo_size_3, "Number of words in the periodic Tx FIFO 4-768");
1895 module_param_named(dev_perio_tx_fifo_size_4, dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
1896 MODULE_PARM_DESC(dev_perio_tx_fifo_size_4, "Number of words in the periodic Tx FIFO 4-768");
1897 module_param_named(dev_perio_tx_fifo_size_5, dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
1898 MODULE_PARM_DESC(dev_perio_tx_fifo_size_5, "Number of words in the periodic Tx FIFO 4-768");
1899 module_param_named(dev_perio_tx_fifo_size_6, dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
1900 MODULE_PARM_DESC(dev_perio_tx_fifo_size_6, "Number of words in the periodic Tx FIFO 4-768");
1901 module_param_named(dev_perio_tx_fifo_size_7, dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
1902 MODULE_PARM_DESC(dev_perio_tx_fifo_size_7, "Number of words in the periodic Tx FIFO 4-768");
1903 module_param_named(dev_perio_tx_fifo_size_8, dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
1904 MODULE_PARM_DESC(dev_perio_tx_fifo_size_8, "Number of words in the periodic Tx FIFO 4-768");
1905 module_param_named(dev_perio_tx_fifo_size_9, dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
1906 MODULE_PARM_DESC(dev_perio_tx_fifo_size_9, "Number of words in the periodic Tx FIFO 4-768");
1907 module_param_named(dev_perio_tx_fifo_size_10, dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
1908 MODULE_PARM_DESC(dev_perio_tx_fifo_size_10, "Number of words in the periodic Tx FIFO 4-768");
1909 module_param_named(dev_perio_tx_fifo_size_11, dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
1910 MODULE_PARM_DESC(dev_perio_tx_fifo_size_11, "Number of words in the periodic Tx FIFO 4-768");
1911 module_param_named(dev_perio_tx_fifo_size_12, dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
1912 MODULE_PARM_DESC(dev_perio_tx_fifo_size_12, "Number of words in the periodic Tx FIFO 4-768");
1913 module_param_named(dev_perio_tx_fifo_size_13, dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
1914 MODULE_PARM_DESC(dev_perio_tx_fifo_size_13, "Number of words in the periodic Tx FIFO 4-768");
1915 module_param_named(dev_perio_tx_fifo_size_14, dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
1916 MODULE_PARM_DESC(dev_perio_tx_fifo_size_14, "Number of words in the periodic Tx FIFO 4-768");
1917 module_param_named(dev_perio_tx_fifo_size_15, dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
1918 MODULE_PARM_DESC(dev_perio_tx_fifo_size_15, "Number of words in the periodic Tx FIFO 4-768");
1919 module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size, int, 0444);
1920 MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
1921 module_param_named(host_nperio_tx_fifo_size, dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
1922 MODULE_PARM_DESC(host_nperio_tx_fifo_size, "Number of words in the non-periodic Tx FIFO 16-32768");
1923 module_param_named(host_perio_tx_fifo_size, dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
1924 MODULE_PARM_DESC(host_perio_tx_fifo_size, "Number of words in the host periodic Tx FIFO 16-32768");
1925 module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size, int, 0444);
1926 /** @todo Set the max to 512K, modify checks */
1927 MODULE_PARM_DESC(max_transfer_size, "The maximum transfer size supported in bytes 2047-65535");
1928 module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count, int, 0444);
1929 MODULE_PARM_DESC(max_packet_count, "The maximum number of packets in a transfer 15-511");
1930 module_param_named(host_channels, dwc_otg_module_params.host_channels, int, 0444);
1931 MODULE_PARM_DESC(host_channels, "The number of host channel registers to use 1-16");
1932 module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int, 0444);
1933 MODULE_PARM_DESC(dev_endpoints, "The number of endpoints in addition to EP0 available for device mode 1-15");
1934 module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
1935 MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
1936 module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int, 0444);
1937 MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
1938 module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
1939 MODULE_PARM_DESC(phy_ulpi_ddr, "ULPI at double or single data rate 0=Single 1=Double");
1940 module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus, int, 0444);
1941 MODULE_PARM_DESC(phy_ulpi_ext_vbus, "ULPI PHY using internal or external vbus 0=Internal");
1942 module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
1943 MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
1944 module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
1945 MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
1946 module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
1947 MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
1948 module_param_named(debug, g_dbg_lvl, int, 0444);
1949 MODULE_PARM_DESC(debug, "");
1951 module_param_named(en_multiple_tx_fifo, dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
1952 MODULE_PARM_DESC(en_multiple_tx_fifo, "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
1953 module_param_named(dev_tx_fifo_size_1, dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
1954 MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
1955 module_param_named(dev_tx_fifo_size_2, dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
1956 MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
1957 module_param_named(dev_tx_fifo_size_3, dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
1958 MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
1959 module_param_named(dev_tx_fifo_size_4, dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
1960 MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
1961 module_param_named(dev_tx_fifo_size_5, dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
1962 MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
1963 module_param_named(dev_tx_fifo_size_6, dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
1964 MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
1965 module_param_named(dev_tx_fifo_size_7, dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
1966 MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
1967 module_param_named(dev_tx_fifo_size_8, dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
1968 MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
1969 module_param_named(dev_tx_fifo_size_9, dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
1970 MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
1971 module_param_named(dev_tx_fifo_size_10, dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
1972 MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
1973 module_param_named(dev_tx_fifo_size_11, dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
1974 MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
1975 module_param_named(dev_tx_fifo_size_12, dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
1976 MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
1977 module_param_named(dev_tx_fifo_size_13, dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
1978 MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
1979 module_param_named(dev_tx_fifo_size_14, dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
1980 MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
1981 module_param_named(dev_tx_fifo_size_15, dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
1982 MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
1984 module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
1985 MODULE_PARM_DESC(thr_ctl, "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
1986 module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int, 0444);
1987 MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
1988 module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int, 0444);
1989 MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
1990 /** @page "Module Parameters"
1992 * The following parameters may be specified when starting the module.
1993 * These parameters define how the DWC_otg controller should be
1994 * configured. Parameter values are passed to the CIL initialization
1995 * function dwc_otg_cil_init
1997 * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
2001 <tr><td>Parameter Name</td><td>Meaning</td></tr>
2005 <td>Specifies the OTG capabilities. The driver will automatically detect the
2006 value for this parameter if none is specified.
2007 - 0: HNP and SRP capable (default, if available)
2008 - 1: SRP Only capable
2009 - 2: No HNP/SRP capable
2014 <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
2015 The driver will automatically detect the value for this parameter if none is
2018 - 1: DMA (default, if available)
2022 <td>dma_burst_size</td>
2023 <td>The DMA Burst size (applicable only for External DMA Mode).
2024 - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
2029 <td>Specifies the maximum speed of operation in host and device mode. The
2030 actual speed depends on the speed of the attached device and the value of
2032 - 0: High Speed (default)
2037 <td>host_support_fs_ls_low_power</td>
2038 <td>Specifies whether low power mode is supported when attached to a Full
2039 Speed or Low Speed device in host mode.
2040 - 0: Don't support low power mode (default)
2041 - 1: Support low power mode
2045 <td>host_ls_low_power_phy_clk</td>
2046 <td>Specifies the PHY clock rate in low power mode when connected to a Low
2047 Speed device in host mode. This parameter is applicable only if
2048 HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
2049 - 0: 48 MHz (default)
2054 <td>enable_dynamic_fifo</td>
2055 <td> Specifies whether FIFOs may be resized by the driver software.
2056 - 0: Use cC FIFO size parameters
2057 - 1: Allow dynamic FIFO sizing (default)
2061 <td>data_fifo_size</td>
2062 <td>Total number of 4-byte words in the data FIFO memory. This memory
2063 includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
2064 - Values: 32 to 32768 (default 8192)
2066 Note: The total FIFO memory depth in the FPGA configuration is 8192.
2070 <td>dev_rx_fifo_size</td>
2071 <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
2072 FIFO sizing is enabled.
2073 - Values: 16 to 32768 (default 1064)
2077 <td>dev_nperio_tx_fifo_size</td>
2078 <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
2079 dynamic FIFO sizing is enabled.
2080 - Values: 16 to 32768 (default 1024)
2084 <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
2085 <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
2086 when dynamic FIFO sizing is enabled.
2087 - Values: 4 to 768 (default 256)
2091 <td>host_rx_fifo_size</td>
2092 <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
2094 - Values: 16 to 32768 (default 1024)
2098 <td>host_nperio_tx_fifo_size</td>
2099 <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
2100 dynamic FIFO sizing is enabled in the core.
2101 - Values: 16 to 32768 (default 1024)
2105 <td>host_perio_tx_fifo_size</td>
2106 <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
2108 - Values: 16 to 32768 (default 1024)
2112 <td>max_transfer_size</td>
2113 <td>The maximum transfer size supported in bytes.
2114 - Values: 2047 to 65,535 (default 65,535)
2118 <td>max_packet_count</td>
2119 <td>The maximum number of packets in a transfer.
2120 - Values: 15 to 511 (default 511)
2124 <td>host_channels</td>
2125 <td>The number of host channel registers to use.
2126 - Values: 1 to 16 (default 12)
2128 Note: The FPGA configuration supports a maximum of 12 host channels.
2132 <td>dev_endpoints</td>
2133 <td>The number of endpoints in addition to EP0 available for device mode
2135 - Values: 1 to 15 (default 6 IN and OUT)
2137 Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
2143 <td>Specifies the type of PHY interface to use. By default, the driver will
2144 automatically detect the phy_type.
2146 - 1: UTMI+ (default, if available)
2151 <td>phy_utmi_width</td>
2152 <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
2153 phy_type of UTMI+. Also, this parameter is applicable only if the
2154 OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
2155 core has been configured to work at either data path width.
2156 - Values: 8 or 16 bits (default 16)
2160 <td>phy_ulpi_ddr</td>
2161 <td>Specifies whether the ULPI operates at double or single data rate. This
2162 parameter is only applicable if phy_type is ULPI.
2163 - 0: single data rate ULPI interface with 8 bit wide data bus (default)
2164 - 1: double data rate ULPI interface with 4 bit wide data bus
2169 <td>Specifies whether to use the I2C interface for full speed PHY. This
2170 parameter is only applicable if PHY_TYPE is FS.
2171 - 0: Disabled (default)
2176 <td>otg_en_multiple_tx_fifo</td>
2177 <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
2178 The driver will automatically detect the value for this parameter if none is
2181 - 1: Enabled (default, if available)
2185 <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
2186 <td>Number of 4-byte words in each of the Tx FIFOs in device mode
2187 when dynamic FIFO sizing is enabled.
2188 - Values: 4 to 768 (default 256)