From: yangkai Date: Thu, 9 Dec 2010 10:17:30 +0000 (+0800) Subject: rk29 usb 2.0 device support X-Git-Tag: firefly_0821_release~10966 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a02460155bc3eb9aeeb7b1dddfb170aa050e9ac3;p=firefly-linux-kernel-4.4.55.git rk29 usb 2.0 device support --- diff --git a/arch/arm/mach-rk29/board-rk29sdk.c b/arch/arm/mach-rk29/board-rk29sdk.c index 94db61d0edd3..041eba4f949b 100755 --- a/arch/arm/mach-rk29/board-rk29sdk.c +++ b/arch/arm/mach-rk29/board-rk29sdk.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -952,6 +953,13 @@ static struct platform_device rk29_device_keys = { }, }; #endif +/********************usb*********************/ +struct usb_mass_storage_platform_data mass_storage_pdata = { + .nluns = 1, + .vendor = "RockChip", + .product = "rk9 sdk", + .release = 0x0100, +}; static void __init rk29_board_iomux_init(void) { @@ -1068,6 +1076,13 @@ static struct platform_device *devices[] __initdata = { #endif &android_pmem_device, &rk29_vpu_mem_device, +#ifdef CONFIG_DWC_OTG + &rk29_device_dwc_otg, +#endif +#ifdef CONFIG_USB_ANDROID + &android_usb_device, + &usb_mass_storage_device, +#endif }; /***************************************************************************************** diff --git a/arch/arm/mach-rk29/devices.c b/arch/arm/mach-rk29/devices.c old mode 100644 new mode 100755 index da3e8f3a793c..d587c28238e3 --- a/arch/arm/mach-rk29/devices.c +++ b/arch/arm/mach-rk29/devices.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -539,3 +540,130 @@ struct platform_device rk29_device_iis_8ch = { .resource = rk29_iis_8ch_resource, }; #endif +#ifdef CONFIG_DWC_OTG +/*DWC_OTG*/ +static struct resource dwc_otg_resource[] = { + { + .start = IRQ_USB_OTG0, + .end = IRQ_USB_OTG0, + .flags = IORESOURCE_IRQ, + }, + { + .start = RK29_USBOTG0_PHYS, + .end = RK29_USBOTG0_PHYS + RK29_USBOTG0_SIZE - 1, + .flags = IORESOURCE_MEM, + }, + +}; + +struct platform_device rk29_device_dwc_otg = { + .name = "dwc_otg", + .id = -1, + .num_resources = ARRAY_SIZE(dwc_otg_resource), + .resource = dwc_otg_resource, +}; + +static char *usb_functions_rockchip[] = { + "usb_mass_storage", +}; + +static char *usb_functions_rockchip_adb[] = { + "usb_mass_storage", + "adb", +}; + +static char *usb_functions_rndis_rockchip[] = { + "rndis", + "usb_mass_storage", +}; + +static char *usb_functions_rndis_rockchip_adb[] = { + "rndis", + "usb_mass_storage", + "adb", +}; + +#ifdef CONFIG_USB_ANDROID_DIAG +static char *usb_functions_adb_diag[] = { + "usb_mass_storage", + "adb", + "diag", +}; +#endif + +static char *usb_functions_all[] = { +#ifdef CONFIG_USB_ANDROID_RNDIS + "rndis", +#endif + "usb_mass_storage", +#ifdef CONFIG_USB_ANDROID_ADB + "adb", +#endif +#ifdef CONFIG_USB_ANDROID_ACM + "acm", +#endif +#ifdef CONFIG_USB_ANDROID_DIAG + "diag", +#endif +}; + +static struct android_usb_product usb_products[] = { + { + .product_id = 0x2810,//0x0c02,//0x4e11, + .num_functions = ARRAY_SIZE(usb_functions_rockchip), + .functions = usb_functions_rockchip, + }, + { + .product_id = 0x4e12, + .num_functions = ARRAY_SIZE(usb_functions_rockchip_adb), + .functions = usb_functions_rockchip_adb, + }, + { + .product_id = 0x4e13, + .num_functions = ARRAY_SIZE(usb_functions_rndis_rockchip), + .functions = usb_functions_rndis_rockchip, + }, + { + .product_id = 0x4e14, + .num_functions = ARRAY_SIZE(usb_functions_rndis_rockchip_adb), + .functions = usb_functions_rndis_rockchip_adb, + }, +#ifdef CONFIG_USB_ANDROID_DIAG + { + .product_id = 0x4e17, + .num_functions = ARRAY_SIZE(usb_functions_adb_diag), + .functions = usb_functions_adb_diag, + }, +#endif +}; + +static struct android_usb_platform_data android_usb_pdata = { + .vendor_id = 0x2207,//0x0bb4,//0x18d1, + .product_id = 0x2810,//0x4e11, + .version = 0x0100, + .product_name = "rk2818 sdk", + .manufacturer_name = "RockChip", + .num_products = ARRAY_SIZE(usb_products), + .products = usb_products, + .num_functions = ARRAY_SIZE(usb_functions_all), + .functions = usb_functions_all, +}; + +//static +struct platform_device android_usb_device = { + .name = "android_usb", + .id = -1, + .dev = { + .platform_data = &android_usb_pdata, + }, +}; + +//static +struct platform_device usb_mass_storage_device = { + .name = "usb_mass_storage", + .id = -1, + .dev = { + .platform_data = &mass_storage_pdata, + }, +}; +#endif diff --git a/arch/arm/mach-rk29/devices.h b/arch/arm/mach-rk29/devices.h index 6becc8ecb8fb..d088cf136397 100755 --- a/arch/arm/mach-rk29/devices.h +++ b/arch/arm/mach-rk29/devices.h @@ -49,5 +49,9 @@ extern struct platform_device rk29_device_sdmmc1; extern struct platform_device rk29_device_adc; extern struct rk29_bl_info rk29_bl_info; extern struct platform_device rk29_device_backlight; +extern struct platform_device rk29_device_dwc_otg; +extern struct platform_device android_usb_device; +extern struct usb_mass_storage_platform_data mass_storage_pdata; +extern struct platform_device usb_mass_storage_device; #endif diff --git a/drivers/usb/dwc_otg/dwc_otg_attr.c b/drivers/usb/dwc_otg/dwc_otg_attr.c index ef77142600e4..c710d037eb7e 100755 --- a/drivers/usb/dwc_otg/dwc_otg_attr.c +++ b/drivers/usb/dwc_otg/dwc_otg_attr.c @@ -735,6 +735,29 @@ static ssize_t wr_reg_test_show( struct device *_dev, } DEVICE_ATTR(wr_reg_test, S_IRUGO|S_IWUSR, wr_reg_test_show, 0); +extern int dwc_debug(int flag); +static ssize_t debug_show( struct device *_dev, + struct device_attribute *attr, char *buf) +{ + dwc_otg_device_t *otg_dev = _dev->platform_data; + dwc_otg_dump_global_registers( otg_dev->core_if); + if (dwc_otg_is_host_mode(otg_dev->core_if)) { + dwc_otg_dump_host_registers( otg_dev->core_if); + } else { + dwc_otg_dump_dev_registers( otg_dev->core_if); + } + return sprintf( buf, "Register Dump\n" ); +} +static ssize_t debug_store( struct device *_dev, + struct device_attribute *attr, + const char *buf, size_t count ) +{ + uint32_t val = simple_strtoul(buf, NULL, 16); + dwc_debug(val); + return count; +} + +DEVICE_ATTR(step, S_IRUGO|S_IWUSR, debug_show, debug_store); /**@}*/ /** @@ -771,6 +794,7 @@ void dwc_otg_attr_create (struct device *dev) error |= device_create_file(dev, &dev_attr_hcd_frrem); error |= device_create_file(dev, &dev_attr_rd_reg_test); error |= device_create_file(dev, &dev_attr_wr_reg_test); + error |= device_create_file(dev, &dev_attr_step); if (error) pr_err("DWC_OTG: Creating some device files failed\n"); } @@ -808,4 +832,5 @@ void dwc_otg_attr_remove (struct device *dev) device_remove_file(dev, &dev_attr_hcd_frrem); device_remove_file(dev, &dev_attr_rd_reg_test); device_remove_file(dev, &dev_attr_wr_reg_test); + device_remove_file(dev, &dev_attr_step); } diff --git a/drivers/usb/dwc_otg/dwc_otg_cil.c b/drivers/usb/dwc_otg/dwc_otg_cil.c index b90b792c788a..089e1ae5687d 100755 --- a/drivers/usb/dwc_otg/dwc_otg_cil.c +++ b/drivers/usb/dwc_otg/dwc_otg_cil.c @@ -62,11 +62,9 @@ #endif #include "linux/dwc_otg_plat.h" -#include #include "dwc_otg_regs.h" #include "dwc_otg_driver.h" #include "dwc_otg_cil.h" -#define SCU_BASE_ADDR_VA RK2818_SCU_BASE static dwc_otg_core_if_t * dwc_core_if = NULL; /** * This function is called to initialize the DWC_otg CSR data @@ -723,11 +721,11 @@ void dwc_otg_core_dev_init(dwc_otg_core_if_t *_core_if) dwc_write_reg32( &_core_if->dev_if->dev_global_regs->dctl, dctl.d32 ); /* Configure data FIFO sizes */ - dwc_write_reg32( &global_regs->grxfsiz, 0x00000400 ); - dwc_write_reg32( &global_regs->gnptxfsiz, 0x00200400 ); //ep0 tx fifo - dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[0], 0x01000420 ); //ep1 tx fifo - dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[1], 0x00200520 ); //ep3 tx fifo - dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[2], 0x01800540 ); //ep5 tx fifo + dwc_write_reg32( &global_regs->grxfsiz, 0x00000210 ); + dwc_write_reg32( &global_regs->gnptxfsiz, 0x00100210 ); //ep0 tx fifo + dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[0], 0x01000220 ); //ep1 tx fifo + dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[1], 0x00100320 ); //ep3 tx fifo + dwc_write_reg32( &global_regs->dptxfsiz_dieptxf[2], 0x00800330 ); //ep5 tx fifo if(_core_if->en_multiple_tx_fifo && _core_if->dma_enable) { @@ -2894,6 +2892,7 @@ void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if) volatile grstctl_t greset = { .d32 = 0}; volatile gusbcfg_data_t usbcfg = { .d32 = 0 }; volatile gintsts_data_t gintsts = { .d32 = 0 }; + volatile dctl_data_t dctl = {.d32 = 0}; int count = 0; DWC_DEBUGPL(DBG_CILV, "%s\n", __func__); /* Wait for AHB master IDLE state. */ @@ -2909,7 +2908,7 @@ void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if) } } while (greset.b.ahbidle == 0); - +#if 1 /* Core Soft Reset */ count = 0; greset.b.csftrst = 1; @@ -2926,6 +2925,10 @@ void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if) } while (greset.b.csftrst == 1); + dctl.d32 = dwc_read_reg32( &_core_if->dev_if->dev_global_regs->dctl ); + dctl.b.sftdiscon = 1; + dwc_write_reg32( &_core_if->dev_if->dev_global_regs->dctl, dctl.d32 ); +#endif usbcfg.d32 = dwc_read_reg32( &global_regs->gusbcfg); if(_core_if->usb_mode == USB_MODE_FORCE_HOST) { @@ -2945,7 +2948,7 @@ void dwc_otg_core_reset(dwc_otg_core_if_t *_core_if) dwc_write_reg32( &global_regs->gusbcfg, usbcfg.d32 ); /* Wait for 3 PHY Clocks*/ //DWC_PRINT("100ms\n"); - mdelay(10); + mdelay(100); count = 0; if(usbcfg.b.force_hst_mode) do @@ -3299,19 +3302,17 @@ void dump_scu_regs(void) printk("SCU_CLKGATE2_CON: 0x%08x\n",regvalue); regvalue = dwc_read_reg32((uint32_t *)(SCU_BASE_ADDR_VA+0x28)); printk("SCU_SOFTRST_CON: 0x%08x\n",regvalue); - regvalue = dwc_read_reg32((uint32_t *)(RK2818_REGFILE_BASE+0x3c)); + regvalue = dwc_read_reg32((uint32_t *)(USB_GRF_CON)); printk("USB_PHY_CON1: 0x%08x\n",regvalue); } -extern void dwc_otg_dump_pcd_flags(void); void dwc_otg_dump_flags(dwc_otg_core_if_t *_core_if) { printk("_______________________dwc_otg flags_______________________________\n"); printk("core_if->op_state = %x\n",_core_if->op_state); printk("core_if->usb_mode = %x\n",_core_if->usb_mode); printk("core_if->usb_wakeup = %x\n",_core_if->usb_wakeup); - dwc_otg_dump_pcd_flags(); } -extern int rk28_msc_switch(int action); +int dwc_step = 0; int dwc_debug(int flag) { dwc_otg_core_if_t *core_if = dwc_core_if; @@ -3339,10 +3340,9 @@ int dwc_debug(int flag) break; case 7: dwc_otg_dump_flags(core_if); - rk28_msc_switch(2); break; case 8: - rk28_msc_switch(2); + dwc_step = 0; break; case 9: dwc_otg_dump_flags(core_if); diff --git a/drivers/usb/dwc_otg/dwc_otg_driver.c b/drivers/usb/dwc_otg/dwc_otg_driver.c index 8ab58fa8f00c..735d7fa57c75 100755 --- a/drivers/usb/dwc_otg/dwc_otg_driver.c +++ b/drivers/usb/dwc_otg/dwc_otg_driver.c @@ -59,7 +59,6 @@ #include #include -#include #include "linux/dwc_otg_plat.h" #include @@ -1024,11 +1023,10 @@ static __devinit int dwc_otg_driver_probe(struct platform_device *pdev) dwc_otg_device_t *dwc_otg_device; int32_t snpsid; int irq; - uint32_t otgreg; /* *Enable usb phy */ - unsigned int * otg_phy_con1 = (unsigned int*)(RK2818_REGFILE_BASE+0x3c); + unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON); *otg_phy_con1 |= (0x01<<2); *otg_phy_con1 |= (0x01<<3); // exit suspend. @@ -1064,7 +1062,7 @@ static __devinit int dwc_otg_driver_probe(struct platform_device *pdev) goto fail; dwc_otg_device->base = - ioremap(res_base->start,RK2818_USBOTG_SIZE); + ioremap(res_base->start,USBOTG_SIZE); if (dwc_otg_device->base == NULL) { dev_err(dev, "ioremap() failed\n"); @@ -1269,7 +1267,6 @@ static int dwc_otg_driver_resume(struct platform_device *_dev ) if(core_if->usb_wakeup) { core_if->usb_wakeup = 0; -// rk28_send_wakeup_key(); /* exit wake up */ } return 0; } @@ -1320,8 +1317,8 @@ static struct platform_driver dwc_otg_driver = { void rk28_host11_driver_enable(dwc_otg_core_if_t *core_if) { - unsigned int * otg_phy_con1 = (unsigned int*)(RK2818_REGFILE_BASE+0x3c); - unsigned int * scu_clkgate1_con = (unsigned int*)(RK2818_SCU_BASE+0x20); + unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON); + unsigned int * scu_clkgate1_con = (unsigned int*)(USB_CLKGATE_CON); /* * enable usb phy & clockgate host controller */ @@ -1342,8 +1339,8 @@ void rk28_host11_driver_enable(dwc_otg_core_if_t *core_if) void rk28_host11_driver_disable(dwc_otg_core_if_t *core_if) { - unsigned int * otg_phy_con1 = (unsigned int*)(RK2818_REGFILE_BASE+0x3c); - unsigned int * scu_clkgate1_con = (unsigned int*)(RK2818_SCU_BASE+0x20); + unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON); + unsigned int * scu_clkgate1_con = (unsigned int*)(USB_CLKGATE_CON); dwc_otg_disable_global_interrupts( core_if ); hub_disconnect_device(g_root_hub11); if (core_if->hcd_cb && core_if->hcd_cb->stop) { @@ -1502,7 +1499,7 @@ static __devinit int rk28_host11_driver_probe(struct platform_device *pdev) /* *Enable usb phy */ - unsigned int * otg_phy_con1 = (unsigned int*)(RK2818_REGFILE_BASE+0x3c); + unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON); *otg_phy_con1 &= ~(0x01<<31); // exit suspend. #if 0 *otg_phy_con1 |= (0x01<<2); @@ -1535,7 +1532,7 @@ static __devinit int rk28_host11_driver_probe(struct platform_device *pdev) goto fail; dwc_otg_device->base = - ioremap(res_base->start,RK2818_USBHOST_SIZE); + ioremap(res_base->start,USBOTG_SIZE); printk("%s host1.1 reg addr: 0x%x remap:0x%x\n",__func__, (unsigned)res_base->start, (unsigned)dwc_otg_device->base); if (dwc_otg_device->base == NULL) diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd.c b/drivers/usb/dwc_otg/dwc_otg_pcd.c index 4215a0ba6708..20ee3409bd06 100755 --- a/drivers/usb/dwc_otg/dwc_otg_pcd.c +++ b/drivers/usb/dwc_otg/dwc_otg_pcd.c @@ -79,8 +79,6 @@ #include #include -#include - #include "dwc_otg_driver.h" #include "dwc_otg_pcd.h" #include "dwc_otg_regs.h" @@ -1520,7 +1518,6 @@ static void dwc_otg_pcd_gadget_release(struct device *_dev) DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _dev); } -extern void rk28_send_wakeup_key( void ) ; int dwc_pcd_reset(dwc_otg_pcd_t *pcd) { dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd); @@ -1543,7 +1540,7 @@ int rk28_usb_suspend( int exitsuspend ) { dwc_otg_pcd_t *pcd = s_pcd; - unsigned int * otg_phy_con1 = (unsigned int*)(RK2818_REGFILE_BASE+0x3c); + unsigned int * otg_phy_con1 = (unsigned int*)(USB_GRF_CON); // unsigned int * usb_core_ctrl_reg = (unsigned int*)(USB_OTG_BASE_ADDR_VA); if(exitsuspend && (pcd->phy_suspend == 1)) { pcd->phy_suspend = 0; @@ -1608,7 +1605,7 @@ void dwc_otg_msc_unlock(void) android_unlock_suspend(&usb_msc_lock); #endif } - +extern int dwc_step; static void dwc_phy_reconnect(struct work_struct *work) { dwc_otg_pcd_t *pcd; @@ -1628,6 +1625,12 @@ static void dwc_phy_reconnect(struct work_struct *work) * Enable the global interrupt after all the interrupt * handlers are installed. */ + #if 0 + printk("debug while 1, please enter command to continue!\n"); + dwc_step = 1; + while(dwc_step) + mdelay(5); + #endif dctl.d32 = dwc_read_reg32( &core_if->dev_if->dev_global_regs->dctl ); dctl.b.sftdiscon = 0; dwc_write_reg32( &core_if->dev_if->dev_global_regs->dctl, dctl.d32 ); @@ -1723,12 +1726,6 @@ int dwc_vbus_status( void ) dwc_otg_pcd_t *pcd = s_pcd; return pcd->vbus_status ; } -int dwc_otg_set_vbus_status(uint8_t status) -{ - dwc_otg_pcd_t *pcd = s_pcd; - pcd->vbus_status = status; - return pcd->vbus_status; -} int dwc_otg_set_phy_status(uint8_t status) { dwc_otg_pcd_t *pcd = s_pcd; @@ -1977,25 +1974,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *_driver) return 0; } EXPORT_SYMBOL(usb_gadget_unregister_driver); -void dwc_otg_dump_pcd_flags(void) -{ - dwc_otg_pcd_t *pcd = s_pcd; - if(pcd) - { - printk("pcd->phy_suspend = %x\n",pcd->phy_suspend); - printk("pcd->vbus_status = %x\n",pcd->vbus_status); - printk("pcd->conn_status = %x\n",pcd->conn_status); - } -} -int rk28_msc_switch(int action) -{ - return 0; -} #else -int dwc_otg_set_vbus_status(int status) -{ - return 0; -} int rk28_usb_suspend( int exitsuspend ) { return 0; @@ -2008,13 +1987,5 @@ int get_msc_connect_flag( void ) { return 0; } -void dwc_otg_dump_pcd_flags(void) -{ - return; -} -int rk28_msc_switch(int action) -{ - return 0; -} #endif /* DWC_HOST_ONLY */ diff --git a/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c b/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c index bfa4850bf507..ed21e70295a5 100755 --- a/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c +++ b/drivers/usb/dwc_otg/dwc_otg_pcd_intr.c @@ -37,7 +37,7 @@ #include "dwc_otg_pcd.h" -//#define DEBUG_EP0 +#define DEBUG_EP0 /* request functions defined in "dwc_otg_pcd.c" */ extern void request_done( dwc_otg_pcd_ep_t *_ep, dwc_otg_pcd_request_t *_req, diff --git a/drivers/usb/dwc_otg/linux/dwc_otg_plat.h b/drivers/usb/dwc_otg/linux/dwc_otg_plat.h index 2dd0282034fb..74008b6a5728 100755 --- a/drivers/usb/dwc_otg/linux/dwc_otg_plat.h +++ b/drivers/usb/dwc_otg/linux/dwc_otg_plat.h @@ -40,6 +40,17 @@ #include #include +#include +#define GRF_REG_BASE RK29_GRF_BASE +#define USB20_OTG0_BASE RK29_USBOTG0_PHYS +#define USB20_OTG1_BASE RK29_USBOTG1_PHYS +#define USB11_HOST_BASE RK29_USBHOST_PHYS +#define USBOTG_SIZE RK29_USBOTG0_SIZE +#define USB_GRF_CON (GRF_REG_BASE+0X9C) +#define USB_CLKGATE_CON (RK29_CRU_BASE+0X60) +#ifndef SCU_BASE_ADDR_VA +#define SCU_BASE_ADDR_VA RK29_CRU_BASE +#endif /** * @file * diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c old mode 100644 new mode 100755 index 7987a626889f..bbb8402abfcf --- a/drivers/usb/gadget/android.c +++ b/drivers/usb/gadget/android.c @@ -55,7 +55,7 @@ static const char longname[] = "Gadget Android"; /* Default vendor and product IDs, overridden by platform data */ #define VENDOR_ID 0x2207//0x18D1 -#define PRODUCT_ID 0x2810 +#define PRODUCT_ID 0x2910 struct android_dev { struct usb_composite_dev *cdev;