usb: gadget: bcm63xx UDC driver
PATCH v2 1/1 usb: gadget: bcm63xx UDC driver
Driver for the "USB20D" / "USBD" block on BCM6328, BCM6368, BCM6816, BCM6362, BCM3383, and others.
The hardware block was designed to support networking applications (direct connection of a home router to a PC), and the endpoint configuration is fixed.
--- drivers/usb/gadget/Kconfig | 13 + drivers/usb/gadget/Makefile | 1 + drivers/usb/gadget/bcm63xx_udc.c | 2442 +++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/gadget_chips.h | 3 + 4 files changed, 2459 insertions(+) create mode 100644 drivers/usb/gadget/bcm63xx_udc.c
V2 changes:
Rename all non-trivial symbols to bcm63xx_* or iudma_* Move most HW init/deinit into udc_start/udc_stop calls Remove debug prints from udc_start/udc_stop calls Halt the USBD clocks when stopped
Fix duplicate memory allocation in iudma_uninit() Don't use a workqueue for ep0 handling
Remove -ERANGE check in bcm63xx_ep_enable() Don't use DMA_ADDR_INVALID
Clean up IUDMA data ISR multiplexing
Quick sanity tests still pass; I will run more tests overnight.
Checkpatch warnings are only for seq_printf() long lines (and turn into "split string" warnings if I split the strings).
Do you think I should add support for the new ->reset callback now?
drivers/usb/gadget/Kconfig +13 -0
@@ -160,6 +160,19 @@ config USB_ATMEL_USBA USBA is the integrated high-speed USB Device controller on the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. +config USB_BCM63XX_UDC + tristate "Broadcom BCM63xx Peripheral Controller" + select USB_GADGET_DUALSPEED + depends on BCM63XX + help + Many Broadcom BCM63xx chipsets (such as the BCM6328) have a + high speed USB Device Port with support for four fixed endpoints + (plus endpoint zero). + + Say "y" to link the driver statically, or "m" to build a + dynamically linked module called "bcm63xx_udc" and force + all gadget drivers to also be dynamically linked. + config USB_FSL_USB2 tristate "Freescale Highspeed USB DR Peripheral Controller" depends on FSL_SOC || ARCH_MXC
drivers/usb/gadget/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_USB_OMAP) += omap_udc.o obj-$(CONFIG_USB_S3C2410) += s3c2410_udc.o obj-$(CONFIG_USB_AT91) += at91_udc.o obj-$(CONFIG_USB_ATMEL_USBA) += atmel_usba_udc.o +obj-$(CONFIG_USB_BCM63XX_UDC) += bcm63xx_udc.o obj-$(CONFIG_USB_FSL_USB2) += fsl_usb2_udc.o fsl_usb2_udc-y := fsl_udc_core.o fsl_usb2_udc-$(CONFIG_ARCH_MXC) += fsl_mxc_udc.o
drivers/usb/gadget/bcm63xx_udc.c new file +2442 -0
2,442 lines not on this page · raw message
drivers/usb/gadget/gadget_chips.h +3 -0
@@ -28,6 +28,7 @@#define gadget_is_amd5536udc (g) (!strcmp("amd5536udc", (g)->name))#define gadget_is_at91 (g) (!strcmp("at91_udc", (g)->name))#define gadget_is_atmel_usba (g) (!strcmp("atmel_usba_udc", (g)->name)) +#define gadget_is_bcm63xx (g) (!strcmp("bcm63xx_udc", (g)->name))#define gadget_is_ci13xxx_msm (g) (!strcmp("ci13xxx_msm", (g)->name))#define gadget_is_ci13xxx_pci (g) (!strcmp("ci13xxx_pci", (g)->name))#define gadget_is_dummy (g) (!strcmp("dummy_udc", (g)->name))
@@ -121,6 +122,8 @@ static inline int usb_gadget_controller_number(struct usb_gadget *gadget)return 0x32 ; else if (gadget_is_lpc32xx(gadget)) return 0x33; + else if (gadget_is_bcm63xx(gadget)) + return 0x34;return -ENOENT ; }
Signature · 1 line
1.7.11.1
Quoted 2 lines · Kevin Cernekee
Driver for the "USB20D" / "USBD" block on BCM6328, BCM6368, BCM6816, BCM6362, BCM3383, and others.
looks good btw.
Quoted 10 lines
drivers/usb/gadget/Kconfig +2
-0@@ -160,6 +160,19 @@ config USB_ATMEL_USBA USBA is the integrated high-speed USB Device controller on the AT32AP700x, some AT91SAM9 and AT91CAP9 processors from Atmel. +config USB_BCM63XX_UDC + tristate "Broadcom BCM63xx Peripheral Controller"
drivers/usb/gadget/Kconfig config USB_ATMEL_USBA · line 174
Quoted 10 lines
drivers/usb/gadget/Kconfig +10
-0+ select USB_GADGET_DUALSPEED + depends on BCM63XX + help + Many Broadcom BCM63xx chipsets (such as the BCM6328) have a + high speed USB Device Port with support for four fixed endpoints + (plus endpoint zero). + + Say "y" to link the driver statically, or "m" to build a + dynamically linked module called "bcm63xx_udc" and force + all gadget drivers to also be dynamically linked.
please drop the "force all gadget drivers to also be dynamically linked" part. We may want to change this one day :)
Quoted 12 lines
drivers/usb/gadget/Kconfig +1
-0+ config USB_FSL_USB2 tristate "Freescale Highspeed USB DR Peripheral Controller" depends on FSL_SOC || ARCH_MXCdrivers/usb/gadget/Makefile +0
-0drivers/usb/gadget/bcm63xx_udc.c new file +0
-0
...
drivers/usb/gadget/bcm63xx_udc.c line 54
Quoted 3 lines
drivers/usb/gadget/bcm63xx_udc.c new file +3
-0+static bool use_fullspeed; +module_param (use_fullspeed, bool,S_IRUGO ); +MODULE_PARM_DESC (use_fullspeed,"true for fullspeed only" );
How important is this option? Maybe this should become a generic option?
drivers/usb/gadget/bcm63xx_udc.c line 1792
Quoted 7 lines
drivers/usb/gadget/bcm63xx_udc.c new file +7
-0+static int bcm63xx_udc_start (struct usb_gadget *gadget, +struct usb_gadget_driver *driver) +{ +struct bcm63xx_udc *udc =gadget_to_udc (gadget); +unsigned long flags; + + if (!driver || driver->max_speed < USB_SPEED_HIGH ||
Hmm. But if you set use_fullspeed isn't this kinda legal?
Quoted 37 lines
drivers/usb/gadget/bcm63xx_udc.c new file +37
-0+static int __devinit bcm63xx_udc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct bcm63xx_usbd_platform_data *pd = dev->platform_data; +struct bcm63xx_udc *udc; +struct resource *res; +int rc = -ENOMEM , i, irq; + + udc =devm_kzalloc (dev,sizeof (*udc),GFP_KERNEL ); +if (!udc) { +dev_err (dev,"cannot allocate memory\n" ); +return -ENOMEM ; + } + +platform_set_drvdata (pdev, udc); + udc->dev = dev; + udc->pd = pd; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) { +dev_err (dev,"error finding USBD resource\n" ); +return -ENXIO ; + } + udc->usbd_regs =devm_request_and_ioremap (dev, res); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (!res) { +dev_err (dev,"error finding IUDMA resource\n" ); +return -ENXIO ; + } + udc->iudma_regs =devm_request_and_ioremap (dev, res); + +if (!udc->usbd_regs || !udc->iudma_regs) { +dev_err (dev,"error requesting resources\n" ); +return -ENXIO ; + } +
drivers/usb/gadget/bcm63xx_udc.c line 2356
Quoted 10 lines
drivers/usb/gadget/bcm63xx_udc.c new file +10
-0+spin_lock_init (&udc->lock); +dev_set_name (&udc->gadget.dev,"gadget" ); + + udc->gadget.ops = &bcm63xx_udc_ops; + udc->gadget.name =dev_name (dev); + udc->gadget.dev.parent = dev; + udc->gadget.dev.release = bcm63xx_udc_gadget_release; + udc->gadget.dev.dma_mask = dev->dma_mask; + +if (!pd->use_fullspeed && !use_fullspeed)
so it is a good advice to have pd not set to NULL :)
Sebastian
Quoted 2 lines · Sebastian Andrzej Siewior
please drop the "force all gadget drivers to also be dynamically linked" part. We may want to change this one day :)
Done in V3
Quoted 2 lines
Quoted 1 line
+ if (!pd->use_fullspeed && !use_fullspeed)
so it is a good advice to have pd not set to NULL :)
In V3 the probe function will call dev_err() and exit, instead of crashing. I added a comment explaining why it's mandatory: the hardware requires specifying which port is shared between the device core + host core, and if we just "assume" the wrong value, the port won't pass traffic and it won't be obvious why.
Quoted 5 lines
drivers/usb/gadget/bcm63xx_udc.c line 54
Quoted 3 lines
drivers/usb/gadget/bcm63xx_udc.c new file +3
-0+static bool use_fullspeed; +module_param (use_fullspeed, bool,S_IRUGO ); +MODULE_PARM_DESC (use_fullspeed,"true for fullspeed only" );How important is this option? Maybe this should become a generic option?
In theory, the hardware core should always be able to support USB 2.0 without any problems, and bcm63xx_udc.c should always be used with gadget drivers that can handle USB 2.0.
In practice, there are a number of boards floating around which are only reliable at USB 1.1 speeds, either due to impedance problems or noise. These fall into two categories:
1) Boards that have their own board definition in board_bcm963xx.c, and pass this ID to Linux - in this case use_fullspeed can be specified right in the platform data.
2) Products that copied the generic board name from the reference design. In this case they'll need another way of overriding use_fullspeed, because the reference board supports high speed. Some might just add "bcm63xx_udc.use_fullspeed=1" to CONFIG_CMDLINE. Others have to detect the board revision through other means (such as reading a GPIO) and then pass the appropriate option to insmod.
use_fullspeed=1 just tells the core not to negotiate USB 2.0 PHY rates. It should be roughly equivalent to plugging the device into a full speed hub.
Quoted 3 lines · Kevin Cernekee
use_fullspeed=1 just tells the core not to negotiate USB 2.0 PHY rates. It should be roughly equivalent to plugging the device into a full speed hub.
Okay, understood.
Sebastian