USB Consolidate descriptor definitions
Subsystems (5)
PATCH 1/8 USB Consolidate descriptor definitions
The header files usb.h and usbdescriptors.h have the same or similarly named structure definitions for
usb_device_descriptorusb_string_descriptorusb_endpoint_descriptorusb_config_descriptor vs usb_configuration_descriptor usb_interface_descriptor
There should only be one definition of these structures. Some of these structures are element-wise duplicates, one has unused elements that can be reduced to a duplicate, and some of the the structures have additional elements.
These are the element-wise duplicates in usb.h
usb_device_descriptorusb_string_descriptor
For these, the usb.h definition will be removed.
This definition in usb.h has extra unused elements
usb_endpoint_descriptor
unsigned char bRefresh unsigned char bSynchAddress;
The definition of usb_endpoint_descriptor in usb.h will be removed.
These definitions in usb.h have extra elements at the end of the usb 2.0 specified descriptor:
usb_config_descriptorusb_interface_descriptor
These structures will have their name shorted by removing the '_descriptor' suffix.
So
usb_config_descriptor -> usb_configusb_interface_descriptor -> usb_interface
The common descriptor elements are now defined by the macros
USB_CONFIG_DESCRIPTOR_DEFINITIONUSB_INTERFACE_DESCRIPTOR_DEFINITION
This has been compile tested on MAKEALL arm, ppc and mips.
--- common/cmd_usb.c | 12 ++++---- common/usb.c | 8 ++-- common/usb_kbd.c | 4 +- common/usb_storage.c | 2 +- cpu/ppc4xx/usbdev.c | 4 +- drivers/usb/host/ehci-hcd.c | 2 +- drivers/usb/musb/musb_hcd.c | 2 +- include/usb.h | 70 +++++------------------------------------- include/usbdescriptors.h | 40 ++++++++++++++---------- 9 files changed, 49 insertions(+), 95 deletions(-)
common/cmd_usb.c +6 -6
@@ -187,14 +187,14 @@ void usb_display_desc(struct usb_device *dev) } -void usb_display_conf_desc (struct usb_config_descriptor *config, +void usb_display_conf_desc (struct usb_config *config,struct usb_device *dev) {printf (" Configuration: %d\n" , config->bConfigurationValue);printf (" - Interfaces: %d %s%s%dmA\n" , config->bNumInterfaces, (config->bmAttributes &0x40 ) ?"Self Powered " :"Bus Powered " , (config->bmAttributes &0x20 ) ?"Remote Wakeup " :"" , - config->MaxPower*2 ); + config->bMaxPower*2 );if (config->iConfiguration) {printf (" - " );usb_display_string (dev, config->iConfiguration);
@@ -202,7 +202,7 @@ void usb_display_conf_desc(struct usb_config_descriptor *config, } } -void usb_display_if_desc (struct usb_interface_descriptor *ifdesc, +void usb_display_if_desc (struct usb_interface *ifdesc,struct usb_device *dev) {printf (" Interface: %d\n" , ifdesc->bInterfaceNumber);
@@ -246,8 +246,8 @@ void usb_display_ep_desc(struct usb_endpoint_descriptor *epdesc)/* main routine to diasplay the configs, interfaces and endpoints */ void usb_display_config (struct usb_device *dev) { -struct usb_config_descriptor *config; -struct usb_interface_descriptor *ifdesc; +struct usb_config *config; +struct usb_interface *ifdesc;struct usb_endpoint_descriptor *epdesc;int i, ii;
@@ -321,7 +321,7 @@ void usb_show_tree_graph(struct usb_device *dev, char *pre)printf (" %s (%s, %dmA)\n" ,usb_get_class_desc ( dev->config.if_desc[0 ].bInterfaceClass),portspeed (dev->speed), - dev->config.MaxPower *2 ); + dev->config.bMaxPower *2 );if (strlen (dev->mf) ||strlen (dev->prod) ||strlen (dev->serial))printf (" %s %s %s %s\n" , pre, dev->mf, dev->prod, dev->serial);printf (" %s\n" , pre);
common/usb.c +4 -4
@@ -440,10 +440,10 @@ int usb_get_configuration_no(struct usb_device *dev, {int result;unsigned int tmp; -struct usb_config_descriptor *config; +struct usb_config *config; - config = (struct usb_config_descriptor *)&buffer[0 ]; + config = (struct usb_config *)&buffer[0 ]; result =usb_get_descriptor (dev,USB_DT_CONFIG , cfgno, buffer,9 );if (result <9 ) {if (result <0 )
@@ -489,7 +489,7 @@ int usb_set_address(struct usb_device *dev)*/ int usb_set_interface (struct usb_device *dev,int interface,int alternate) { -struct usb_interface_descriptor *if_face =NULL ; +struct usb_interface *if_face =NULL ;int ret, i;for (i =0 ; i < dev->config.bNumInterfaces; i++) {
@@ -1347,7 +1347,7 @@ int usb_hub_configure(struct usb_device *dev)int usb_hub_probe (struct usb_device *dev,int ifnum) { -struct usb_interface_descriptor *iface; +struct usb_interface *iface;struct usb_endpoint_descriptor *ep;int ret;
common/usb_kbd.c +2 -2
@@ -229,7 +229,7 @@ int usb_kbd_deregister(void)static void usb_kbd_setled (struct usb_device *dev) { -struct usb_interface_descriptor *iface; +struct usb_interface *iface; iface = &dev->config.if_desc[0 ]; leds=0 ;if (scroll_lock!=0 )
@@ -348,7 +348,7 @@ static int usb_kbd_irq(struct usb_device *dev)/* probes the USB device dev for keyboard type */ static int usb_kbd_probe (struct usb_device *dev,unsigned int ifnum) { -struct usb_interface_descriptor *iface; +struct usb_interface *iface;struct usb_endpoint_descriptor *ep;int pipe,maxp;
common/usb_storage.c +1 -1
@@ -1070,7 +1070,7 @@ retry_it:int usb_storage_probe (struct usb_device *dev,unsigned int ifnum,struct us_data *ss) { -struct usb_interface_descriptor *iface; +struct usb_interface *iface;int i;unsigned int flags =0 ;
cpu/ppc4xx/usbdev.c +2 -2
@@ -21,7 +21,7 @@ void process_endpoints(unsigned short usb2d0_intrin) {/*will hold the packet received */ struct usb_device_descriptor usb_device_packet; -struct usb_config_descriptor usb_config_packet; +struct usb_configuration_descriptor usb_config_packet;struct usb_string_descriptor usb_string_packet;struct devrequest setup_packet;unsigned int *setup_packet_pt;
@@ -99,7 +99,7 @@ void process_endpoints(unsigned short usb2d0_intrin) usb_config_packet.bConfigurationValue =1 ; usb_config_packet.iConfiguration =0 ; usb_config_packet.bmAttributes =0x40 ; - usb_config_packet.MaxPower =0 ; + usb_config_packet.bMaxPower =0 ;/*put packet in fifo */ packet_pt = (unsigned char *)&usb_config_packet;
drivers/usb/host/ehci-hcd.c +1 -1
@@ -96,7 +96,7 @@ static struct descriptor {* UE_DIR_IN | EHCI_INTR_ENDPT */ 3, /* bmAttributes: UE_INTERRUPT */ - 8, 0, /* wMaxPacketSize */ + 8, /* wMaxPacketSize */255 /* bInterval */ }, };
drivers/usb/musb/musb_hcd.c +1 -1
@@ -803,7 +803,7 @@ void usb_event_poll() {struct stdio_dev *dev;struct usb_device *usb_kbd_dev; -struct usb_interface_descriptor *iface; +struct usb_interface *iface;struct usb_endpoint_descriptor *ep;int pipe;int maxp;
include/usb.h +9 -61
102 lines not on this page · raw message
include/usbdescriptors.h +23 -17
@@ -201,27 +201,33 @@ struct usb_endpoint_descriptor {u8 bInterval; } __attribute__ ((packed)); +#define USB_INTERFACE_DESCRIPTOR_DEFINITION \ + u8 bLength; \ + u8 bDescriptorType; /* 0x04 */ \ + u8 bInterfaceNumber; \ + u8 bAlternateSetting; \ + u8 bNumEndpoints; \ + u8 bInterfaceClass; \ + u8 bInterfaceSubClass; \ + u8 bInterfaceProtocol; \ + u8 iInterface +struct usb_interface_descriptor { -u8 bLength; -u8 bDescriptorType;/* 0x04 */ -u8 bInterfaceNumber; -u8 bAlternateSetting; -u8 bNumEndpoints; -u8 bInterfaceClass; -u8 bInterfaceSubClass; -u8 bInterfaceProtocol; -u8 iInterface; +USB_INTERFACE_DESCRIPTOR_DEFINITION ; } __attribute__ ((packed)); +#define USB_CONFIG_DESCRIPTOR_DEFINITION \ + u8 bLength; \ + u8 bDescriptorType; /* 0x2 */ \ + u16 wTotalLength; \ + u8 bNumInterfaces; \ + u8 bConfigurationValue; \ + u8 iConfiguration; \ + u8 bmAttributes; \ + u8 bMaxPower +struct usb_configuration_descriptor { -u8 bLength; -u8 bDescriptorType;/* 0x2 */ -u16 wTotalLength; -u8 bNumInterfaces; -u8 bConfigurationValue; -u8 iConfiguration; -u8 bmAttributes; -u8 bMaxPower; +USB_CONFIG_DESCRIPTOR_DEFINITION ; } __attribute__ ((packed));struct usb_device_descriptor {
Signature · 1 line
1.6.0.4
PATCH 2/8 USB add macros for debugging usb device setup.
When developing usb device features, it is useful to print out common usb structures.
--- include/usbdescriptors.h | 31 +++++++++++++ include/usbdevice.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 0 deletions(-)
include/usbdescriptors.h +31 -0
@@ -510,4 +510,35 @@ struct usb_class_descriptor { } __attribute__ ((packed)); +#ifdef DEBUG +#define PRINT_DEVICE_DESCRIPTOR (d) \ +do { \ + serial_printf("usb device descriptor \n"); \ + serial_printf("\tbLength %2.2x\n", (d)->bLength); \ + serial_printf("\tbDescriptorType %2.2x\n", \ + (d)->bDescriptorType); \ + serial_printf("\tbcdUSB %4.4x\n", (d)->bcdUSB); \ + serial_printf("\tbDeviceClass %2.2x\n", (d)->bDeviceClass); \ + serial_printf("\tbDeviceSubClass %2.2x\n", \ + (d)->bDeviceSubClass); \ + serial_printf("\tbDeviceProtocol %2.2x\n", \ + (d)->bDeviceProtocol); \ + serial_printf("\tbMaxPacketSize0 %2.2x\n", \ + (d)->bMaxPacketSize0); \ + serial_printf("\tidVendor %4.4x\n", (d)->idVendor); \ + serial_printf("\tidProduct %4.4x\n", (d)->idProduct); \ + serial_printf("\tbcdDevice %4.4x\n", (d)->bcdDevice); \ + serial_printf("\tiManufacturer %2.2x\n", (d)->iManufacturer); \ + serial_printf("\tiProduct %2.2x\n", (d)->iProduct); \ + serial_printf("\tiSerialNumber %2.2x\n", (d)->iSerialNumber); \ + serial_printf("\tbNumConfigurations %2.2x\n", \ + (d)->bNumConfigurations); \ +} while (0) + +#else + +/* stubs */ +#define PRINT_DEVICE_DESCRIPTOR (d) + +#endif /* DEBUG */ #endif
include/usbdevice.h +105 -0
109 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 3/8 TWL4030 Add usb PHY support
The twl4030 provides a PHY device for connecting a link device, like musb, to physical connection.
This change adds the twl4030 usb registers and functions for initializing the PHY as required by omap3.
--- Makefile | 1 + drivers/usb/phy/Makefile | 44 +++++++++++ drivers/usb/phy/twl4030.c | 184 +++++++++++++++++++++++++++++++++++++++++++++ include/twl4030.h | 143 +++++++++++++++++++++++++++++++---- 4 files changed, 357 insertions(+), 15 deletions(-) create mode 100644 drivers/usb/phy/Makefile create mode 100644 drivers/usb/phy/twl4030.c
Makefile +1 -0
@@ -241,6 +241,7 @@ LIBS += drivers/twserial/libtws.a LIBS += drivers/usb/gadget/libusb_gadget.a LIBS += drivers/usb/host/libusb_host.a LIBS += drivers/usb/musb/libusb_musb.a +LIBS += drivers/usb/phy/libusb_phy.a LIBS += drivers/video/libvideo.a LIBS += drivers/watchdog/libwatchdog.a LIBS += common/libcommon.a
drivers/usb/phy/Makefile new file +44 -0
44 lines not on this page · raw message
drivers/usb/phy/twl4030.c new file +184 -0
184 lines not on this page · raw message
include/twl4030.h +128 -15
153 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 4/8 OMAP3 Add usb device support
This change adds the usb device support for musb.
Omap3 platform support added at the same level as davinci.
The interface for usbtty to use the musb device support was added.
Verified on omap3 beagle, zoom1 and zoom2.
--- drivers/serial/usbtty.h | 2 + drivers/usb/musb/Makefile | 2 + drivers/usb/musb/musb_core.c | 8 +- drivers/usb/musb/musb_core.h | 40 ++ drivers/usb/musb/musb_debug.h | 240 ++++++++++++ drivers/usb/musb/musb_udc.c | 823 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/musb/omap3.c | 129 +++++++ drivers/usb/musb/omap3.h | 48 +++ include/usb.h | 3 +- include/usb/musb_udc.h | 54 +++ 10 files changed, 1346 insertions(+), 3 deletions(-) create mode 100644 drivers/usb/musb/musb_debug.h create mode 100644 drivers/usb/musb/musb_udc.c create mode 100644 drivers/usb/musb/omap3.c create mode 100644 drivers/usb/musb/omap3.h create mode 100644 include/usb/musb_udc.h
drivers/serial/usbtty.h +2 -0
@@ -29,6 +29,8 @@#include <usb/mpc8xx_udc.h> #elif defined(CONFIG_OMAP1510 )#include <usb/omap1510_udc.h> +#elif defined(CONFIG_MUSB_UDC ) +#include <usb/musb_udc.h> #elif defined(CONFIG_PXA27X )#include <usb/pxa27x_udc.h> #endif
drivers/usb/musb/Makefile +2 -0
@@ -26,7 +26,9 @@ include $(TOPDIR)/config.mk LIB := $(obj)libusb_musb.a COBJS-$(CONFIG_MUSB_HCD) += musb_hcd.o musb_core.o +COBJS-$(CONFIG_MUSB_UDC) += musb_udc.o musb_core.o COBJS-$(CONFIG_USB_DAVINCI) += davinci.o +COBJS-$(CONFIG_USB_OMAP3) += omap3.o COBJS := $(COBJS-y) SRCS := $(COBJS:.o=.c)
drivers/usb/musb/musb_core.c +6 -2
@@ -32,7 +32,9 @@ struct musb_regs *musbr;*/ void musb_start (void ) { +#if defined(CONFIG_MUSB_HCD )u8 devctl; +#endif /* disable all interrupts */ writew (0 , &musbr->intrtxe);
@@ -74,9 +76,10 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)/* Configure fifo size and fifo base address */ writeb (idx, &musbr->txfifosz);writew (fifoaddr >>3 , &musbr->txfifoadd); + + csr =readw (&musbr->txcsr);#if defined(CONFIG_MUSB_HCD )/* clear the data toggle bit */ - csr =readw (&musbr->txcsr);writew (csr |MUSB_TXCSR_CLRDATATOG , &musbr->txcsr);#endif /* Flush fifo if required */
@@ -87,9 +90,10 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)/* Configure fifo size and fifo base address */ writeb (idx, &musbr->rxfifosz);writew (fifoaddr >>3 , &musbr->rxfifoadd); + + csr =readw (&musbr->rxcsr);#if defined(CONFIG_MUSB_HCD )/* clear the data toggle bit */ - csr =readw (&musbr->rxcsr);writew (csr |MUSB_RXCSR_CLRDATATOG , &musbr->rxcsr);#endif /* Flush fifo if required */
drivers/usb/musb/musb_core.h +40 -0
@@ -40,6 +40,36 @@#define MUSB_EP0_FIFOSIZE 64/* This is non-configurable */ +/* EP0 */ +struct musb_ep0_regs { +u16 reserved4; +u16 csr0; +u16 reserved5; +u16 reserved6; +u16 count0; +u8 host_type0; +u8 host_naklimit0; +u8 reserved7; +u8 reserved8; +u8 reserved9; +u8 configdata; +}; + +/* EP 1-15 */ +struct musb_epN_regs { +u16 txmaxp; +u16 txcsr; +u16 rxmaxp; +u16 rxcsr; +u16 rxcount; +u8 txtype; +u8 txinterval; +u8 rxtype; +u8 rxinterval; +u8 reserved0; +u8 fifosize; +}; +/* Mentor USB core register overlay structure */ struct musb_regs {/* common registers */
@@ -97,6 +127,16 @@ struct musb_regs {u8 rxhubaddr;u8 rxhubport; } tar[16 ]; +/* +* end point registers +* ep0 elements are valid when array index is 0 +* otherwise epN is valid +*/ +union musb_ep_regs { +struct musb_ep0_regs ep0; +struct musb_epN_regs epN; + } ep[16 ]; + } __attribute__((aligned(32)));/*
drivers/usb/musb/musb_debug.h new file +240 -0
240 lines not on this page · raw message
drivers/usb/musb/musb_udc.c new file +823 -0
823 lines not on this page · raw message
drivers/usb/musb/omap3.c new file +129 -0
129 lines not on this page · raw message
drivers/usb/musb/omap3.h new file +48 -0
48 lines not on this page · raw message
include/usb.h +2 -1
@@ -131,7 +131,8 @@ struct usb_device {#if defined(CONFIG_USB_UHCI ) || defined(CONFIG_USB_OHCI ) || \ defined(CONFIG_USB_EHCI ) || defined(CONFIG_USB_OHCI_NEW ) || \ defined(CONFIG_USB_SL811HS ) || defined(CONFIG_USB_ISP116X_HCD ) || \ - defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) + defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) || \ + defined(CONFIG_USB_OMAP3 )int usb_lowlevel_init (void );int usb_lowlevel_stop (void );
include/usb/musb_udc.h new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 5/8 OMAP3 zoom1 Add usbtty configuration
The primary console of zoom1 is the serial out from the jumpers accessed by removing the back panel.
A secondary console is to use the usbtty. The user can set this manually by doing
setenv stdout usbtty; setenv stdin usbtty; setenv stderr usbtty saveenv
usbtty will be usable by accessing the /dev/ttyACM0 on a linux host.
--- include/configs/omap3_zoom1.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
include/configs/omap3_zoom1.h +16 -0
@@ -99,6 +99,21 @@#define CONFIG_OMAP3_MMC 1#define CONFIG_DOS_PARTITION 1 +/* USB */ +#define CONFIG_MUSB_UDC 1 +#define CONFIG_USB_OMAP3 1 +#define CONFIG_TWL4030_USB 1 + +/* USB device configuration */ +#define CONFIG_USB_DEVICE 1 +#define CONFIG_USB_TTY 1 +#define CONFIG_SYS_CONSOLE_IS_IN_ENV 1 +/* Change these to suit your needs */ +#define CONFIG_USBD_VENDORID 0x0451 +#define CONFIG_USBD_PRODUCTID 0x5678 +#define CONFIG_USBD_MANUFACTURER "Texas Instruments" +#define CONFIG_USBD_PRODUCT_NAME "Zoom1" +/* commands to include */ #include <config_cmd_default.h>
@@ -160,6 +175,7 @@#define CONFIG_EXTRA_ENV_SETTINGS \ "loadaddr=0x82000000\0" \ + "usbtty=cdc_acm\0" \ "console=ttyS2,115200n8\0" \ "videomode=1024x768 at 60,vxres=1024,vyres=768\0" \ "videospec=omapfb:vram:2M,vram:4M\0" \
Signature · 1 line
1.6.0.4
PATCH 6/8 OMAP3 beagle Add usbtty configuration
The primary console of beagle is the serial header.
A secondary console is to use the usbtty. The user can set this manually by doing
setenv stdout usbtty; setenv stdin usbtty; setenv stderr usbtty saveenv
usbtty will be usable by accessing the /dev/ttyACM0 on a linux host.
--- include/configs/omap3_beagle.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
include/configs/omap3_beagle.h +16 -0
@@ -98,6 +98,21 @@#define CONFIG_OMAP3_MMC 1#define CONFIG_DOS_PARTITION 1 +/* USB */ +#define CONFIG_MUSB_UDC 1 +#define CONFIG_USB_OMAP3 1 +#define CONFIG_TWL4030_USB 1 + +/* USB device configuration */ +#define CONFIG_USB_DEVICE 1 +#define CONFIG_USB_TTY 1 +#define CONFIG_SYS_CONSOLE_IS_IN_ENV 1 +/* Change these to suit your needs */ +#define CONFIG_USBD_VENDORID 0x0451 +#define CONFIG_USBD_PRODUCTID 0x5678 +#define CONFIG_USBD_MANUFACTURER "Texas Instruments" +#define CONFIG_USBD_PRODUCT_NAME "Beagle" +/* commands to include */ #include <config_cmd_default.h>
@@ -163,6 +178,7 @@#define CONFIG_EXTRA_ENV_SETTINGS \ "loadaddr=0x82000000\0" \ + "usbtty=cdc_acm\0" \ "console=ttyS2,115200n8\0" \ "videomode=1024x768 at 60,vxres=1024,vyres=768\0" \ "videospec=omapfb:vram:2M,vram:4M\0" \
Signature · 1 line
1.6.0.4
PATCH 7/8 USBTTY make some function declarations easier to use.
Zoom2 needs to use these declarations and the include directory is a better place from them than in the middle of the driver directory. It did not make sense to create a new file for just a couple of lines so they were appended to the serial.h
--- include/serial.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/serial.h +6 -0
@@ -59,4 +59,10 @@ extern void serial_stdio_init(void);extern int serial_assign (char * name);extern void serial_reinit_all (void ); +/* For usbtty */ +extern int usbtty_getc (void ); +extern void usbtty_putc (const char c); +extern void usbtty_puts (const char *str); +extern int usbtty_tstc (void ); +#endif
Signature · 1 line
1.6.0.4
PATCH 8/8 OMAP3 zoom2 Use usbtty if the debug board is not connected.
The preferred serial output comes from the debug board. When the debug board is disconnected, fall back on using usbtty from the usb connector on the Zoom2 board.
This shows up as /dev/ttyACM0 in a linux host.
--- board/omap3/zoom2/zoom2_serial.c | 16 ++++++++++++++++ include/configs/omap3_zoom2.h | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)
board/omap3/zoom2/zoom2_serial.c +16 -0
@@ -87,6 +87,10 @@ void quad_putc_dev (unsigned long base, const char c)NS16550_putc ((NS16550_t ) base, c); } +#ifdef CONFIG_USB_TTY + else +usbtty_putc (c ); +#endif }void quad_puts_dev (unsigned long base,const char *s)
@@ -95,6 +99,10 @@ void quad_puts_dev (unsigned long base, const char *s)while ((s !=NULL ) && (*s !='\0' ))quad_putc_dev (base, *s++); } +#ifdef CONFIG_USB_TTY + else +usbtty_puts (s ); +#endif }int quad_getc_dev (unsigned long base)
@@ -102,7 +110,11 @@ int quad_getc_dev (unsigned long base)if (zoom2_debug_board_connected ())return NS16550_getc ((NS16550_t ) base); else +#ifdef CONFIG_USB_TTY +return usbtty_getc (); +#else return 0 ; +#endif }int quad_tstc_dev (unsigned long base)
@@ -110,7 +122,11 @@ int quad_tstc_dev (unsigned long base)if (zoom2_debug_board_connected ())return NS16550_tstc ((NS16550_t ) base); else +#ifdef CONFIG_USB_TTY +return usbtty_tstc (); +#else return 0 ; +#endif }void quad_setbrg_dev (unsigned long base)
include/configs/omap3_zoom2.h +17 -0
@@ -123,6 +123,20 @@#define CONFIG_OMAP3_GPIO_3 /* board revision */ #define CONFIG_OMAP3_GPIO_5 /* debug board detection, ZOOM2_LED_BLUE */ +/* USB */ +#define CONFIG_MUSB_UDC 1 +#define CONFIG_USB_OMAP3 1 +#define CONFIG_TWL4030_USB 1 + +/* USB device configuration */ +#define CONFIG_USB_DEVICE 1 +#define CONFIG_USB_TTY 1 +/* Change these to suit your needs */ +#define CONFIG_USBD_VENDORID 0x0451 +#define CONFIG_USBD_PRODUCTID 0x5678 +#define CONFIG_USBD_MANUFACTURER "Texas Instruments" +#define CONFIG_USBD_PRODUCT_NAME "Zoom2" +/* commands to include */ #include <config_cmd_default.h>
@@ -169,6 +183,9 @@/* Environment information */ #define CONFIG_BOOTDELAY 10 +#define CONFIG_EXTRA_ENV_SETTINGS \ + "usbtty=cdc_acm\0" \ +/* * Miscellaneous configurable options */
Signature · 1 line
1.6.0.4
PATCH 8/8 OMAP3 zoom2 Use usbtty if the debug board is not connected.
Quoted 17 lines · Tom Rix
The preferred serial output comes from the debug board. When the debug board is disconnected, fall back on using usbtty from the usb connector on the Zoom2 board.
This shows up as
/dev/ttyACM0in a linux host.Signed-off-by Tom Rix <[email protected]>--- board/omap3/zoom2/zoom2_serial.c | 16 ++++++++++++++++ include/configs/omap3_zoom2.h | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)board/omap3/zoom2/zoom2_serial.c +0
-0
board/omap3/zoom2/zoom2_serial.c void quad_putc_dev (unsigned long base, const char c) · line 90
Quoted 4 lines
board/omap3/zoom2/zoom2_serial.c +1
-0@@ -87,6 +87,10 @@ void quad_putc_dev (unsigned long base, const char c)NS16550_putc ((NS16550_t ) base, c); } +#ifdef CONFIG_USB_TTY
why not do this
#ifndef CONFIG_USB_TTY
#define usbtty_putc(c)
#define usbtty_puts(s)
#define usbtty_getc() 0
#define usbtty_tstc() 0
#endif
and then avoid the ifdef
Best Regards,
J.
PATCH 8/8 OMAP3 zoom2 Use usbtty if the debug board is not connected.
Quoted 32 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 17 lines · Tom Rix
The preferred serial output comes from the debug board. When the debug board is disconnected, fall back on using usbtty from the usb connector on the Zoom2 board.
This shows up as
/dev/ttyACM0in a linux host.Signed-off-by Tom Rix <[email protected]>--- board/omap3/zoom2/zoom2_serial.c | 16 ++++++++++++++++ include/configs/omap3_zoom2.h | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 0 deletions(-)board/omap3/zoom2/zoom2_serial.c +0
-0board/omap3/zoom2/zoom2_serial.c void quad_putc_dev (unsigned long base, const char c) · line 91
Quoted 5 lines
board/omap3/zoom2/zoom2_serial.c +1
-0@@ -87,6 +87,10 @@ void quad_putc_dev (unsigned long base, const char c)NS16550_putc ((NS16550_t ) base, c); } +#ifdef CONFIG_USB_TTY why not do this
#ifndefCONFIG_USB_TTY
#defineusbtty_putc(c)
#defineusbtty_puts(s)
#defineusbtty_getc()0
#defineusbtty_tstc()0
#endif
Quoted 3 lines
and then avoid the ifdef
Yes I agree.
I will add stubs to the declarations in serial.h
Tom
Quoted 3 lines
Best Regards,
J.
PATCH 6/8 OMAP3 beagle Add usbtty configuration
In reply to Tom RixQuoted 8 lines · Tom Rix
The primary console of beagle is the serial header.
A secondary console is to use the usbtty. The user can set this manually by doing
setenv stdout usbtty; setenv stdin usbtty; setenv stderr usbtty saveenv
Quoted 6 lines
usbtty will be usable by accessing the
/dev/ttyACM0on a linux host.Signed-off-by Tom Rix <[email protected]>--- include/configs/omap3_beagle.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
Best Regards,
J.
PATCH 5/8 OMAP3 zoom1 Add usbtty configuration
In reply to Tom RixQuoted 9 lines · Tom Rix
The primary console of zoom1 is the serial out from the jumpers accessed by removing the back panel.
A secondary console is to use the usbtty. The user can set this manually by doing
setenv stdout usbtty; setenv stdin usbtty; setenv stderr usbtty saveenv
Quoted 6 lines
usbtty will be usable by accessing the
/dev/ttyACM0on a linux host.Signed-off-by Tom Rix <[email protected]>--- include/configs/omap3_zoom1.h | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
Best Regards,
J.
PATCH 4/8 OMAP3 Add usb device support
In reply to Tom RixHi,
please be carefull you have a lot's of ligne which exceed 80 chars limit
drivers/usb/musb/musb_debug.h line 24
Quoted 5 lines
drivers/usb/musb/musb_debug.h new file +5
-0+ +/* Define MUSB_DEBUG before including this file to get debug macros */ +#ifdef MUSB_DEBUG + +static inline void MUSB_PRINT_PWR (u8 b)
please lowercase
drivers/usb/musb/musb_debug.h line 26
Quoted 2 lines
drivers/usb/musb/musb_debug.h new file +2
-0+{ +serial_printf ("\tpower 0x%2.2x\n" , b);
maybe a macro will simplify the code
#define MUSB_FLAGS_PRINT(x, y) \
if (b & MUSB_##x_##y) \
serial_printf("\t\t"#y"\n");static inline void musb_print_pwr(u8 b)
{
serial_printf("\tpower 0x%2.2x\n", b);
MUSB_FLAGS_PRINT(POWER, ISOUPDATE);
MUSB_FLAGS_PRINT(POWER, SOFTCONN);
MUSB_FLAGS_PRINT(POWER, HSENAB);
MUSB_FLAGS_PRINT(POWER, HSMODE);
MUSB_FLAGS_PRINT(POWER, RESET);
MUSB_FLAGS_PRINT(POWER, RESUME);
MUSB_FLAGS_PRINT(POWER, SUSPENDM);
MUSB_FLAGS_PRINT(POWER, ENSUSPEND);
}and so on
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static inline void MUSB_PRINT_CSR0(u16 w)
please lowercase and so on
Quoted 15 lines
drivers/usb/musb/musb_debug.h new file +15
-0+{ +serial_printf ("\tcsr0 0x%4.4x\n" , w); +if (w &MUSB_CSR0_FLUSHFIFO ) +serial_printf ("\t\tFLUSHFIFO\n" ); +if (w &MUSB_CSR0_P_SVDSETUPEND ) +serial_printf ("\t\tSERV_SETUPEND\n" ); +if (w &MUSB_CSR0_P_SVDRXPKTRDY ) +serial_printf ("\t\tSERV_RXPKTRDY\n" ); +if (w &MUSB_CSR0_P_SENDSTALL ) +serial_printf ("\t\tSENDSTALL\n" ); +if (w &MUSB_CSR0_P_SETUPEND ) +serial_printf ("\t\tSETUPEND\n" ); +if (w &MUSB_CSR0_P_DATAEND ) +serial_printf ("\t\tDATAEND\n" ); +if (w &MUSB_CSR0_P_SENTSTALL )
drivers/usb/musb/musb_debug.h
Quoted 10 lines
drivers/usb/musb/musb_debug.h new file +9
-0+serial_printf ("\t\tSENTSTALL\n" ); +if (w &MUSB_CSR0_TXPKTRDY ) +serial_printf ("\t\tTXPKTRDY\n" ); +if (w &MUSB_CSR0_RXPKTRDY ) +serial_printf ("\t\tRXPKTRDY\n" ); +} + + +#define MAX_ENDPOINT 15
maybe we can put it configurable
drivers/usb/musb/musb_udc.c line 78
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ +#define GET_ENDPOINT (dev,ep) \ +(((struct usb_device_instance *)(dev))->bus->endpoint_array + ep) + +#define SET_EP0_STATE (s) \ +do { \ + if ((0 <= (s)) && (SET_ADDRESS >= (s))) { \ + if ((s) != ep0_state) { \ + if ((debug_setup) && (debug_level > 1)) \ + serial_printf("INFO : Changing state from %s to %s in %s at line %d\n", ep0_state_strings[ep0_state], ep0_state_strings[s], __PRETTY_FUNCTION__, __LINE__); \
too long please split
drivers/usb/musb/musb_udc.c line 83
Quoted 5 lines
drivers/usb/musb/musb_udc.c new file +5
-0+ ep0_state = s; \ + } \ + }else { \ +if (debug_level >0 ) \ +serial_printf ("Error at %s %d with setting state %d is invalid\n" , __PRETTY_FUNCTION__, __LINE__, s); \
too long please split
drivers/usb/musb/musb_udc.c line 91
Quoted 8 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ } \ +}while (0 ) + +/* static implies these initialized to 0 or NULL */ +static int debug_setup; +static int debug_level; +static struct musb_epinfo epinfo[MAX_ENDPOINT *2 ]; +static enum ep0_state_enum {IDLE =0 ,TX ,RX ,SET_ADDRESS } ep0_state =IDLE ;
this will be better
static enum ep0_state_enum {
IDLE = 0,
TX,
RX,
SET_ADDRESS
} ep0_state = IDLE;Quoted 62 lines
drivers/usb/musb/musb_udc.c new file +62
-0+static char *ep0_state_strings[4 ] = { +"IDLE" , +"TX" , +"RX" , +"SET_ADDRESS" , +}; + +static struct urb *ep0_urb; +struct usb_endpoint_instance *ep0_endpoint; +static struct usb_device_instance *udc_device; +static int enabled; + +#ifdef MUSB_DEBUG +static void musb_db_regs (void ) +{ +u8 b; +u16 w; + + b =readb (&musbr->faddr); +serial_printf ("\tfaddr 0x%2.2x\n" , b); + + b =readb (&musbr->power); +MUSB_PRINT_PWR (b); + + w =readw (&musbr->ep[0 ].ep0.csr0); +MUSB_PRINT_CSR0 (w); + + b =readb (&musbr->devctl); +MUSB_PRINT_DEVCTL (b); + + b =readb (&musbr->ep[0 ].ep0.configdata); +MUSB_PRINT_CONFIG (b); + + w =readw (&musbr->frame); +serial_printf ("\tframe 0x%4.4x\n" , w); + + b =readb (&musbr->index); +serial_printf ("\tindex 0x%2.2x\n" , b); + + w =readw (&musbr->ep[1 ].epN.rxmaxp); +MUSB_PRINT_RXMAXP (w); + + w =readw (&musbr->ep[1 ].epN.rxcsr); +MUSB_PRINT_RXCSR (w); + + w =readw (&musbr->ep[1 ].epN.txmaxp); +MUSB_PRINT_TXMAXP (w); + + w =readw (&musbr->ep[1 ].epN.txcsr); +MUSB_PRINT_TXCSR (w); +} +#else +#define musb_db_regs () +#endif /* DEBUG_MUSB */ + +static void musb_peri_softconnect (void ) +{ +u8 power, devctl; +u8 intrusb; +u16 intrrx, intrtx; + +/* Power off MUSB */
drivers/usb/musb/musb_udc.c line 163
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ power =readb (&musbr->power); + power &= ~MUSB_POWER_SOFTCONN ; +writeb (power, &musbr->power); + +/* Read intr to clear */ + intrusb =readb (&musbr->intrusb); + intrrx =readw (&musbr->intrrx); + intrtx =readw (&musbr->intrtx); + +udelay (2 *500000 );/* 1 sec */
why not udelay(1000 * 1000) as other place?
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +7
-0+ +/* Power on MUSB */ + power =readb (&musbr->power); + power |=MUSB_POWER_SOFTCONN ; +/* +* The usb device interface is usb 1.1 +* Disable 2.0 high speed by clearring the hsenable bit.
drivers/usb/musb/musb_udc.c line 180
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+*/ + power &= ~MUSB_POWER_HSENAB ; +writeb (power, &musbr->power); + +/* Check if device is in b-peripheral mode */ + devctl =readb (&musbr->devctl); +if (!(devctl &MUSB_DEVCTL_BDEVICE ) || + (devctl &MUSB_DEVCTL_HM )) { +serial_printf ("ERROR : Unsupport USB mode\n" ); +serial_printf ("Check that mini-B USB cable is attached to the device\n" );
evenif it's too long it's better for search
drivers/usb/musb/musb_udc.c line 190
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ } + +if (debug_setup && (debug_level >1 )) +musb_db_regs (); +} + +static void musb_peri_reset (void ) +{ +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s reset\n" , __PRETTY_FUNCTION__);
what do you mean y __PRETTY_FUNCTION__?
Quoted 6 lines
drivers/usb/musb/musb_udc.c new file +6
-0+ +/* the device address is reset by the event */ +usbd_device_event_irq (udc_device,DEVICE_RESET ,0 ); +SET_EP0_STATE (IDLE ); +if (ep0_endpoint) + ep0_endpoint->endpoint_address =0xff ;
drivers/usb/musb/musb_udc.c line 206
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+} + +static void musb_peri_resume (void ) +{ +/* noop */ +} + +static void musb_peri_ep0_stall (void ) +{ +u16 csr0;
please add an empty line
drivers/usb/musb/musb_udc.c line 216
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_SENDSTALL ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s stall\n" , __PRETTY_FUNCTION__); +} + +static void musb_peri_ep0_ack_req (void ) +{ +u16 csr0;
please add an empty line
drivers/usb/musb/musb_udc.c line 224
Quoted 8 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_SVDRXPKTRDY ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +} + +static void musb_ep0_tx_ready (void ) +{ +u16 csr0;
please add an empty line
drivers/usb/musb/musb_udc.c line 232
Quoted 8 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_TXPKTRDY ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +} + +static void musb_peri_ep0_last (void ) +{ +u16 csr0;
please add an empty line
drivers/usb/musb/musb_udc.c line 236
Quoted 4 lines
drivers/usb/musb/musb_udc.c new file +4
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_DATAEND ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +}
is it not possible to create a single function which take MUSB_CSR0_P_DATAEND, MUSB_CSR0_TXPKTRDY, MUSB_CSR0_P_SVDRXPKTRDY, MUSB_CSR0_P_SENDSTALL etc... as paramter?
Quoted 32 lines
drivers/usb/musb/musb_udc.c new file +32
-0+ +static void musb_peri_ep0_set_address (void ) +{ +writeb (udc_device->address, &musbr->faddr); +SET_EP0_STATE (IDLE ); +usbd_device_event_irq (udc_device,DEVICE_ADDRESS_ASSIGNED ,0 ); +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s Address set to %d\n" , __PRETTY_FUNCTION__, udc_device->address); +} + +static void musb_peri_rx_ack (unsigned int ep) +{ +u16 peri_rxcsr; + peri_rxcsr =readw (&musbr->ep[ep].epN.rxcsr); + peri_rxcsr &= ~MUSB_RXCSR_RXPKTRDY ; +writew (peri_rxcsr, &musbr->ep[ep].epN.rxcsr); +} + +static void musb_peri_tx_ready (unsigned int ep) +{ +u16 peri_txcsr; + peri_txcsr =readw (&musbr->ep[ep].epN.txcsr); + peri_txcsr |=MUSB_TXCSR_TXPKTRDY ; +writew (peri_txcsr, &musbr->ep[ep].epN.txcsr); +} + +static void musb_peri_ep0_zero_data_request (int err) +{ +musb_peri_ep0_ack_req (); + +if (err) { +musb_peri_ep0_stall ();
drivers/usb/musb/musb_udc.c line 278
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+SET_EP0_STATE (IDLE ); + }else { + +musb_peri_ep0_last (); + +/* USBD state */ +switch (ep0_urb->device_request.bRequest) { +case USB_REQ_SET_ADDRESS : +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s received set address\n" , __PRETTY_FUNCTION__);
maybe you can define a debug macro to reduce the code length and avoid the if everywhere
Quoted 69 lines
drivers/usb/musb/musb_udc.c new file +69
-0+break ; + +case USB_REQ_SET_CONFIGURATION : +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s Configured\n" , __PRETTY_FUNCTION__); +usbd_device_event_irq (udc_device,DEVICE_CONFIGURED ,0 ); +break ; + } + +/* EP0 state */ +if (USB_REQ_SET_ADDRESS == ep0_urb->device_request.bRequest) { +SET_EP0_STATE (SET_ADDRESS ); + }else { +SET_EP0_STATE (IDLE ); + } + } +} + +static void musb_peri_ep0_rx_data_request (void ) +{ +/* +* This is the completion of the data OUT / RX +* +* Host is sending data to ep0 that is not +* part of setup. This comes from the cdc_recv_setup +* op that is device specific. +* +*/ +musb_peri_ep0_ack_req (); + + ep0_endpoint->rcv_urb = ep0_urb; + ep0_urb->actual_length =0 ; +SET_EP0_STATE (RX ); +} + +static void musb_peri_ep0_tx_data_request (int err) +{ +if (err) { +musb_peri_ep0_stall (); +SET_EP0_STATE (IDLE ); + }else { +musb_peri_ep0_ack_req (); + + ep0_endpoint->tx_urb = ep0_urb; + ep0_endpoint->sent =0 ; +SET_EP0_STATE (TX ); + } +} + +static void musb_peri_ep0_idle (void ) +{ +u16 count0; +int err; +u16 csr0; + + csr0 =readw (&musbr->ep[0 ].ep0.csr0); + +if (!(MUSB_CSR0_RXPKTRDY & csr0)) + goto end; + + count0 =readw (&musbr->ep[0 ].ep0.count0); +if (count0 ==0 ) + goto end; + +if (count0 !=8 ) { +if ((debug_setup) && (debug_level >1 )) +serial_printf ("WARN : %s SETUP incorrect size %d\n" , + __PRETTY_FUNCTION__, count0); +musb_peri_ep0_stall ();
drivers/usb/musb/musb_udc.c line 357
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ goto end; + } + +read_fifo (0 , count0, &ep0_urb->device_request); + +if (debug_level >2 ) { +PRINT_USB_DEVICE_REQUEST (&ep0_urb->device_request); + } + +if (0 == ep0_urb->device_request.wLength) {
please invert the test
drivers/usb/musb/musb_udc.c line 364
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +7
-0+ err =ep0_recv_setup (ep0_urb); + +/* Zero data request */ +musb_peri_ep0_zero_data_request (err); + }else { +/* Is data coming or going ? */ +u8 reqType = ep0_urb->device_request.bmRequestType;
please add an empty line
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +7
-0+if (USB_REQ_DEVICE2HOST == (reqType &USB_REQ_DIRECTION_MASK )) { + err =ep0_recv_setup (ep0_urb); +/* Device to host */ +musb_peri_ep0_tx_data_request (err); + }else { +/* +* Host to device
drivers/usb/musb/musb_udc.c line 381
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+* +* The RX routine will call ep0_recv_setup +* when the data packet has arrived. +*/ +musb_peri_ep0_rx_data_request (); + } + } + +end: +return ;
why? will not be usefull to have an error return?
Quoted 8 lines
drivers/usb/musb/musb_debug.h new file +3
-0+} + +include/usb.h +0
-0
include/usb.h struct usb_device { · line 135
Quoted 6 lines
include/usb.h +2
-1@@ -131,7 +131,8 @@ struct usb_device {#if defined(CONFIG_USB_UHCI ) || defined(CONFIG_USB_OHCI ) || \ defined(CONFIG_USB_EHCI ) || defined(CONFIG_USB_OHCI_NEW ) || \ defined(CONFIG_USB_SL811HS ) || defined(CONFIG_USB_ISP116X_HCD ) || \ - defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) + defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) || \ + defined(CONFIG_USB_OMAP3 )
a simple CONFIG will be better
include/usb.h struct usb_device { · line 138
Quoted 3 lines
include/usb.h +0
-0int usb_lowlevel_init (void );int usb_lowlevel_stop (void );
Best Regards,
J.
PATCH 4/8 OMAP3 Add usb device support
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Hi,
please be carefull you have a lot's of ligne which exceed 80 chars limit
Yes I saw these from check_patch.
I will try to reduce these.
Quoted 8 lines
drivers/usb/musb/musb_debug.h line 24
Quoted 6 lines
drivers/usb/musb/musb_debug.h new file +5
-0+ +/* Define MUSB_DEBUG before including this file to get debug macros */ +#ifdef MUSB_DEBUG + +static inline void MUSB_PRINT_PWR (u8 b)please lowercase
OK
Quoted 20 lines
drivers/usb/musb/musb_debug.h line 26
Quoted 3 lines
drivers/usb/musb/musb_debug.h new file +2
-0+{ +serial_printf ("\tpower 0x%2.2x\n" , b);maybe a macro will simplify the code
#define MUSB_FLAGS_PRINT(x, y) \ if (b & MUSB_##x_##y) \ serial_printf("\t\t"#y"\n");static inline void
musb_print_pwr(u8 b){ serial_printf("\tpower 0x%2.2x\n", b); MUSB_FLAGS_PRINT(POWER, ISOUPDATE); MUSB_FLAGS_PRINT(POWER, SOFTCONN); MUSB_FLAGS_PRINT(POWER, HSENAB); MUSB_FLAGS_PRINT(POWER, HSMODE); MUSB_FLAGS_PRINT(POWER, RESET); MUSB_FLAGS_PRINT(POWER, RESUME); MUSB_FLAGS_PRINT(POWER, SUSPENDM); MUSB_FLAGS_PRINT(POWER, ENSUSPEND); }
Quoted 2 lines
and so on
Thanks.
I will give this a try.
Quoted 30 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +static inline void MUSB_PRINT_CSR0(u16 w)please lowercase and so on
Quoted 23 lines
drivers/usb/musb/musb_debug.h new file +22
-0+{ +serial_printf ("\tcsr0 0x%4.4x\n" , w); +if (w &MUSB_CSR0_FLUSHFIFO ) +serial_printf ("\t\tFLUSHFIFO\n" ); +if (w &MUSB_CSR0_P_SVDSETUPEND ) +serial_printf ("\t\tSERV_SETUPEND\n" ); +if (w &MUSB_CSR0_P_SVDRXPKTRDY ) +serial_printf ("\t\tSERV_RXPKTRDY\n" ); +if (w &MUSB_CSR0_P_SENDSTALL ) +serial_printf ("\t\tSENDSTALL\n" ); +if (w &MUSB_CSR0_P_SETUPEND ) +serial_printf ("\t\tSETUPEND\n" ); +if (w &MUSB_CSR0_P_DATAEND ) +serial_printf ("\t\tDATAEND\n" ); +if (w &MUSB_CSR0_P_SENTSTALL ) +serial_printf ("\t\tSENTSTALL\n" ); +if (w &MUSB_CSR0_TXPKTRDY ) +serial_printf ("\t\tTXPKTRDY\n" ); +if (w &MUSB_CSR0_RXPKTRDY ) +serial_printf ("\t\tRXPKTRDY\n" ); +} +
Quoted 5 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ +#define MAX_ENDPOINT 15maybe we can put it configurable
mmmm I will see
Quoted 13 lines
drivers/usb/musb/musb_udc.c line 78
Quoted 11 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ +#define GET_ENDPOINT (dev,ep) \ +(((struct usb_device_instance *)(dev))->bus->endpoint_array + ep) + +#define SET_EP0_STATE (s) \ +do { \ + if ((0 <= (s)) && (SET_ADDRESS >= (s))) { \ + if ((s) != ep0_state) { \ + if ((debug_setup) && (debug_level > 1)) \ + serial_printf("INFO : Changing state from %s to %s in %s at line %d\n", ep0_state_strings[ep0_state], ep0_state_strings[s], __PRETTY_FUNCTION__, __LINE__); \too long please split
Quoted 8 lines
drivers/usb/musb/musb_udc.c line 83
Quoted 6 lines
drivers/usb/musb/musb_udc.c new file +5
-0+ ep0_state = s; \ + } \ + }else { \ +if (debug_level >0 ) \ +serial_printf ("Error at %s %d with setting state %d is invalid\n" , __PRETTY_FUNCTION__, __LINE__, s); \too long please split
Ok.
Quoted 10 lines
drivers/usb/musb/musb_udc.c line 91
Quoted 9 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ } \ +}while (0 ) + +/* static implies these initialized to 0 or NULL */ +static int debug_setup; +static int debug_level; +static struct musb_epinfo epinfo[MAX_ENDPOINT *2 ]; +static enum ep0_state_enum {IDLE =0 ,TX ,RX ,SET_ADDRESS } ep0_state =IDLE ;this will be better
Quoted 7 lines
static enum ep0_state_enum {
IDLE = 0,
TX,
RX,
SET_ADDRESS
} ep0_state = IDLE;ok
Quoted 66 lines
Quoted 66 lines
drivers/usb/musb/musb_udc.c new file +66
-0+static char *ep0_state_strings[4 ] = { +"IDLE" , +"TX" , +"RX" , +"SET_ADDRESS" , +}; + +static struct urb *ep0_urb; +struct usb_endpoint_instance *ep0_endpoint; +static struct usb_device_instance *udc_device; +static int enabled; + +#ifdef MUSB_DEBUG +static void musb_db_regs (void ) +{ +u8 b; +u16 w; + + b =readb (&musbr->faddr); +serial_printf ("\tfaddr 0x%2.2x\n" , b); + + b =readb (&musbr->power); +MUSB_PRINT_PWR (b); + + w =readw (&musbr->ep[0 ].ep0.csr0); +MUSB_PRINT_CSR0 (w); + + b =readb (&musbr->devctl); +MUSB_PRINT_DEVCTL (b); + + b =readb (&musbr->ep[0 ].ep0.configdata); +MUSB_PRINT_CONFIG (b); + + w =readw (&musbr->frame); +serial_printf ("\tframe 0x%4.4x\n" , w); + + b =readb (&musbr->index); +serial_printf ("\tindex 0x%2.2x\n" , b); + + w =readw (&musbr->ep[1 ].epN.rxmaxp); +MUSB_PRINT_RXMAXP (w); + + w =readw (&musbr->ep[1 ].epN.rxcsr); +MUSB_PRINT_RXCSR (w); + + w =readw (&musbr->ep[1 ].epN.txmaxp); +MUSB_PRINT_TXMAXP (w); + + w =readw (&musbr->ep[1 ].epN.txcsr); +MUSB_PRINT_TXCSR (w); +} +#else +#define musb_db_regs () +#endif /* DEBUG_MUSB */ + +static void musb_peri_softconnect (void ) +{ +u8 power, devctl; +u8 intrusb; +u16 intrrx, intrtx; + +/* Power off MUSB */ + power =readb (&musbr->power); + power &= ~MUSB_POWER_SOFTCONN ; +writeb (power, &musbr->power); +
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 163
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +6
-0+/* Read intr to clear */ + intrusb =readb (&musbr->intrusb); + intrrx =readw (&musbr->intrrx); + intrtx =readw (&musbr->intrtx); + +udelay (2 *500000 );/* 1 sec */ why not
udelay(1000 * 1000)as other place?
cruft begone!
ok. i will clean this up.
Quoted 20 lines
Quoted 8 lines
drivers/usb/musb/musb_udc.c new file +7
-0+ +/* Power on MUSB */ + power =readb (&musbr->power); + power |=MUSB_POWER_SOFTCONN ; +/* +* The usb device interface is usb 1.1 +* Disable 2.0 high speed by clearring the hsenable bit. drivers/usb/musb/musb_udc.c line 180
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+*/ + power &= ~MUSB_POWER_HSENAB ; +writeb (power, &musbr->power); + +/* Check if device is in b-peripheral mode */ + devctl =readb (&musbr->devctl); +if (!(devctl &MUSB_DEVCTL_BDEVICE ) || + (devctl &MUSB_DEVCTL_HM )) { +serial_printf ("ERROR : Unsupport USB mode\n" ); +serial_printf ("Check that mini-B USB cable is attached to the device\n" );evenif it's too long it's better for search
Quoted 13 lines
drivers/usb/musb/musb_udc.c line 190
Quoted 11 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ } + +if (debug_setup && (debug_level >1 )) +musb_db_regs (); +} + +static void musb_peri_reset (void ) +{ +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s reset\n" , __PRETTY_FUNCTION__);what do you mean y
__PRETTY_FUNCTION__?
This a gcc compiler macro for printing out the function of the calling routine. It is useful in the macro's like the state machine changer to show which function did the change instead of the usual __LINE__ + __FILE__ + eyeball time. It is a non-standard cpp macro and would bite us when compiling without gcc. Does u-boot build with non-gcc ?
Quoted 10 lines
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ +/* the device address is reset by the event */ +usbd_device_event_irq (udc_device,DEVICE_RESET ,0 ); +SET_EP0_STATE (IDLE ); +if (ep0_endpoint) + ep0_endpoint->endpoint_address =0xff ; +} + +static void musb_peri_resume (void ) +{
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 206
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +6
-0+/* noop */ +} + +static void musb_peri_ep0_stall (void ) +{ +u16 csr0;please add an empty line
ok
Quoted 4 lines
Quoted 4 lines
drivers/usb/musb/musb_udc.c new file +4
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_SENDSTALL ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +if ((debug_setup) && (debug_level >1 ))
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 216
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +6
-0+serial_printf ("INFO : %s stall\n" , __PRETTY_FUNCTION__); +} + +static void musb_peri_ep0_ack_req (void ) +{ +u16 csr0;please add an empty line
ok,
Quoted 11 lines
drivers/usb/musb/musb_udc.c line 224
Quoted 9 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_SVDRXPKTRDY ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +} + +static void musb_ep0_tx_ready (void ) +{ +u16 csr0;please add an empty line
ok
Quoted 11 lines
drivers/usb/musb/musb_udc.c line 232
Quoted 9 lines
drivers/usb/musb/musb_udc.c new file +8
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_TXPKTRDY ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +} + +static void musb_peri_ep0_last (void ) +{ +u16 csr0;please add an empty line
empty lines for everyone!
Quoted 46 lines
drivers/usb/musb/musb_udc.c line 236
Quoted 5 lines
drivers/usb/musb/musb_udc.c new file +4
-0+ csr0 =readw (&musbr->ep[0 ].ep0.csr0); + csr0 |=MUSB_CSR0_P_DATAEND ; +writew (csr0, &musbr->ep[0 ].ep0.csr0); +}is it not possible to create a single function which take
MUSB_CSR0_P_DATAEND,MUSB_CSR0_TXPKTRDY,MUSB_CSR0_P_SVDRXPKTRDY,MUSB_CSR0_P_SENDSTALLetc... as paramter?Quoted 37 lines
drivers/usb/musb/musb_udc.c new file +37
-0+ +static void musb_peri_ep0_set_address (void ) +{ +writeb (udc_device->address, &musbr->faddr); +SET_EP0_STATE (IDLE ); +usbd_device_event_irq (udc_device,DEVICE_ADDRESS_ASSIGNED ,0 ); +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s Address set to %d\n" , __PRETTY_FUNCTION__, udc_device->address); +} + +static void musb_peri_rx_ack (unsigned int ep) +{ +u16 peri_rxcsr; + peri_rxcsr =readw (&musbr->ep[ep].epN.rxcsr); + peri_rxcsr &= ~MUSB_RXCSR_RXPKTRDY ; +writew (peri_rxcsr, &musbr->ep[ep].epN.rxcsr); +} + +static void musb_peri_tx_ready (unsigned int ep) +{ +u16 peri_txcsr; + peri_txcsr =readw (&musbr->ep[ep].epN.txcsr); + peri_txcsr |=MUSB_TXCSR_TXPKTRDY ; +writew (peri_txcsr, &musbr->ep[ep].epN.txcsr); +} + +static void musb_peri_ep0_zero_data_request (int err) +{ +musb_peri_ep0_ack_req (); + +if (err) { +musb_peri_ep0_stall (); +SET_EP0_STATE (IDLE ); + }else { + +musb_peri_ep0_last (); +
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 278
Quoted 6 lines
drivers/usb/musb/musb_udc.c new file +5
-0+/* USBD state */ +switch (ep0_urb->device_request.bRequest) { +case USB_REQ_SET_ADDRESS : +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s received set address\n" , __PRETTY_FUNCTION__);maybe you can define a debug macro to reduce the code length and avoid the if everywhere
ok i will look into it.
Quoted 73 lines
Quoted 73 lines
drivers/usb/musb/musb_udc.c new file +73
-0+break ; + +case USB_REQ_SET_CONFIGURATION : +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s Configured\n" , __PRETTY_FUNCTION__); +usbd_device_event_irq (udc_device,DEVICE_CONFIGURED ,0 ); +break ; + } + +/* EP0 state */ +if (USB_REQ_SET_ADDRESS == ep0_urb->device_request.bRequest) { +SET_EP0_STATE (SET_ADDRESS ); + }else { +SET_EP0_STATE (IDLE ); + } + } +} + +static void musb_peri_ep0_rx_data_request (void ) +{ +/* +* This is the completion of the data OUT / RX +* +* Host is sending data to ep0 that is not +* part of setup. This comes from the cdc_recv_setup +* op that is device specific. +* +*/ +musb_peri_ep0_ack_req (); + + ep0_endpoint->rcv_urb = ep0_urb; + ep0_urb->actual_length =0 ; +SET_EP0_STATE (RX ); +} + +static void musb_peri_ep0_tx_data_request (int err) +{ +if (err) { +musb_peri_ep0_stall (); +SET_EP0_STATE (IDLE ); + }else { +musb_peri_ep0_ack_req (); + + ep0_endpoint->tx_urb = ep0_urb; + ep0_endpoint->sent =0 ; +SET_EP0_STATE (TX ); + } +} + +static void musb_peri_ep0_idle (void ) +{ +u16 count0; +int err; +u16 csr0; + + csr0 =readw (&musbr->ep[0 ].ep0.csr0); + +if (!(MUSB_CSR0_RXPKTRDY & csr0)) + goto end; + + count0 =readw (&musbr->ep[0 ].ep0.count0); +if (count0 ==0 ) + goto end; + +if (count0 !=8 ) { +if ((debug_setup) && (debug_level >1 )) +serial_printf ("WARN : %s SETUP incorrect size %d\n" , + __PRETTY_FUNCTION__, count0); +musb_peri_ep0_stall (); + goto end; + } + +read_fifo (0 , count0, &ep0_urb->device_request);
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 357
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +6
-0+ +if (debug_level >2 ) { +PRINT_USB_DEVICE_REQUEST (&ep0_urb->device_request); + } + +if (0 == ep0_urb->device_request.wLength) {please invert the test
ok
Quoted 21 lines
drivers/usb/musb/musb_udc.c line 364
Quoted 8 lines
drivers/usb/musb/musb_udc.c new file +7
-0+ err =ep0_recv_setup (ep0_urb); + +/* Zero data request */ +musb_peri_ep0_zero_data_request (err); + }else { +/* Is data coming or going ? */ +u8 reqType = ep0_urb->device_request.bmRequestType;please add an empty line
Quoted 11 lines
drivers/usb/musb/musb_udc.c new file +11
-0+if (USB_REQ_DEVICE2HOST == (reqType &USB_REQ_DIRECTION_MASK )) { + err =ep0_recv_setup (ep0_urb); +/* Device to host */ +musb_peri_ep0_tx_data_request (err); + }else { +/* +* Host to device +* +* The RX routine will call ep0_recv_setup +* when the data packet has arrived. +*/
Quoted 9 lines
drivers/usb/musb/musb_udc.c line 381
Quoted 7 lines
drivers/usb/musb/musb_udc.c new file +6
-0+musb_peri_ep0_rx_data_request (); + } + } + +end: +return ;why? will not be usefull to have an error return?
I am not sure it needs an error.
I will check.
Quoted 8 lines
Quoted 8 lines
drivers/usb/musb/musb_debug.h new file +3
-0+} + +include/usb.h +0
-0@@ -131,7 +131,8 @@ struct usb_device {
Quoted 9 lines
include/usb.h struct usb_device { · line 136
Quoted 7 lines
include/usb.h +2
-1#if defined(CONFIG_USB_UHCI ) || defined(CONFIG_USB_OHCI ) || \ defined(CONFIG_USB_EHCI ) || defined(CONFIG_USB_OHCI_NEW ) || \ defined(CONFIG_USB_SL811HS ) || defined(CONFIG_USB_ISP116X_HCD ) || \ - defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) + defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) || \ + defined(CONFIG_USB_OMAP3 )a simple CONFIG will be better
Can this be a follow-on ?
Tom
Quoted 8 lines
include/usb.h struct usb_device { · line 138
Quoted 4 lines
include/usb.h +0
-0int usb_lowlevel_init (void );int usb_lowlevel_stop (void );Best Regards,
J.
PATCH 4/8 OMAP3 Add usb device support
Quoted 11 lines
Quoted 11 lines
drivers/usb/musb/musb_udc.c line 190
Quoted 10 lines
drivers/usb/musb/musb_udc.c new file +10
-0+ } + +if (debug_setup && (debug_level >1 )) +musb_db_regs (); +} + +static void musb_peri_reset (void ) +{ +if ((debug_setup) && (debug_level >1 )) +serial_printf ("INFO : %s reset\n" , __PRETTY_FUNCTION__);what do you mean y
__PRETTY_FUNCTION__?
Quoted 6 lines
This a gcc compiler macro for printing out the function of the calling routine. It is useful in the macro's like the state machine changer to show which function did the change instead of the usual
__LINE__+__FILE__+ eyeball time. It is a non-standard cpp macro and would bite us when compiling without gcc. Does u-boot build with non-gcc ?
no only gcc but I think it will not be impossible to use an other toolchains but ok
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
drivers/usb/musb/musb_udc.c new file +2
-0+ +/* the device address is reset by the event */ include/usb.h +0
-0Quoted 8 lines
include/usb.h struct usb_device { · line 135
Quoted 7 lines
include/usb.h +2
-1@@ -131,7 +131,8 @@ struct usb_device {#if defined(CONFIG_USB_UHCI ) || defined(CONFIG_USB_OHCI ) || \ defined(CONFIG_USB_EHCI ) || defined(CONFIG_USB_OHCI_NEW ) || \ defined(CONFIG_USB_SL811HS ) || defined(CONFIG_USB_ISP116X_HCD ) || \ - defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) + defined(CONFIG_USB_R8A66597_HCD ) || defined(CONFIG_USB_DAVINCI ) || \ + defined(CONFIG_USB_OMAP3 )a simple CONFIG will be better
Quoted 1 line
Can this be a follow-on ?
ofcource
Best Regards,
J.
PATCH 3/8 TWL4030 Add usb PHY support
In reply to Tom RixQuoted 129 lines · Tom Rix
The twl4030 provides a PHY device for connecting a link device, like musb, to physical connection.
This change adds the twl4030 usb registers and functions for initializing the PHY as required by omap3.
Signed-off-by Tom Rix <[email protected]>--- Makefile | 1 + drivers/usb/phy/Makefile | 44 +++++++++++ drivers/usb/phy/twl4030.c | 184 +++++++++++++++++++++++++++++++++++++++++++++ include/twl4030.h | 143 +++++++++++++++++++++++++++++++---- 4 files changed, 357 insertions(+), 15 deletions(-) create mode 100644 drivers/usb/phy/Makefile create mode 100644 drivers/usb/phy/twl4030.cMakefile +1
-0@@ -241,6 +241,7 @@ LIBS += drivers/twserial/libtws.a LIBS += drivers/usb/gadget/libusb_gadget.a LIBS += drivers/usb/host/libusb_host.a LIBS += drivers/usb/musb/libusb_musb.a +LIBS += drivers/usb/phy/libusb_phy.a LIBS += drivers/video/libvideo.a LIBS += drivers/watchdog/libwatchdog.a LIBS += common/libcommon.adrivers/usb/phy/Makefile new file +44
-0@@ -0,0 +1,44 @@ +# +# Copyright (c) 2009 Wind River Systems, Inc. +# Tom Rix <[email protected]> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# + +include $(TOPDIR)/config.mk + +LIB := $(obj)libusb_phy.a + +COBJS-$(CONFIG_TWL4030_USB) += twl4030.o +COBJS-y := twl4030.o + +COBJS := $(COBJS-y) +SRCS := $(COBJS:.o=.c) +OBJS := $(addprefix $(obj),$(COBJS)) + +all: $(LIB) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +#########################################################################drivers/usb/phy/twl4030.c new file +45
-0@@ -0,0 +1,184 @@ +/* +* Copyright (c) 2009 Wind River Systems, Inc. +* Tom Rix <[email protected]> +* +* This is file is based on +* repository git.gitorious.org/u-boot-omap3/mainline.git, +* branch omap3-dev-usb, file drivers/usb/gadget/twl4030_usb.c +* +* This is the unique part of its copyright : +* +* ------------------------------------------------------------------------ +* +* * (C) Copyright 2009 Atin Malaviya (atin.malaviya at gmail.com) +* +* Based on: twl4030_usb.c in linux 2.6 (drivers/i2c/chips/twl4030_usb.c) +* Copyright (C) 2004-2007 Texas Instruments +* Copyright (C) 2008 Nokia Corporation +* Contact: Felipe Balbi <[email protected]> +* +* Author: Atin Malaviya (atin.malaviya at gmail.com) +* +* ------------------------------------------------------------------------ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + +#include <twl4030.h> + +/* Defines for bits in registers */ +#define OPMODE_MASK (3 << 3) +#define XCVRSELECT_MASK (3 << 0) +#define CARKITMODE (1 << 2)
drivers/usb/phy/twl4030.c line 55
Quoted 10 lines
drivers/usb/phy/twl4030.c new file +10
-0+#define OTG_ENAB (1 << 5) +#define PHYPWD (1 << 0) +#define CLOCKGATING_EN (1 << 2) +#define CLK32K_EN (1 << 1) +#define REQ_PHY_DPLL_CLK (1 << 0) +#define PHY_DPLL_CLK (1 << 0) + +static int twl4030_usb_write (u8 address,u8 data) +{ +int ret;
please add an empty line
drivers/usb/phy/twl4030.c line 66
Quoted 11 lines
drivers/usb/phy/twl4030.c new file +11
-0+ ret =twl4030_i2c_write_u8 (TWL4030_CHIP_USB , data, address); +if (ret !=0 ) +printf ("TWL4030:USB:Write[0x%x] Error %d\n" , address, ret); + +return ret; +} + +static int twl4030_usb_read (u8 address) +{ +u8 data; +int ret;
please add an empty line
drivers/usb/phy/twl4030.c line 73
Quoted 8 lines
drivers/usb/phy/twl4030.c new file +7
-0+ ret =twl4030_i2c_read_u8 (TWL4030_CHIP_USB , &data, address); +if (ret ==0 ) + ret = data; +else +printf ("TWL4030:USB:Read[0x%x] Error %d\n" , address, ret); + +return ret;
why not this and avoid the copy of data
if (ret != 0) {
printf("TWL4030:USB:Read[0x%x] Error %d\n", address, ret);
return ret;
}
return data;
}drivers/usb/phy/twl4030.c line 117
Quoted 4 lines
drivers/usb/phy/twl4030.c new file +4
-0+ +static void twl4030_phy_power (void ) +{ +u8 pwr, clk;
please add an empty line
drivers/usb/phy/twl4030.c line 121
Quoted 4 lines
drivers/usb/phy/twl4030.c new file +4
-0+/* Power the PHY */ + pwr =twl4030_usb_read (TWL4030_USB_PHY_PWR_CTRL ); + pwr &= ~PHYPWD ; +twl4030_usb_write (TWL4030_USB_PHY_PWR_CTRL , pwr);
please add an empty line to make it more readable
Quoted 25 lines
drivers/usb/phy/twl4030.c new file +25
-0+/* Enable clocks */ + clk =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL ); + clk |=CLOCKGATING_EN |CLK32K_EN ; +twl4030_usb_write (TWL4030_USB_PHY_CLK_CTRL , clk); +} + +/* +* Initiaze the ULPI interface +* ULPI : Universal Transceiver Macrocell Low Pin Interface +* An interface between the USB link controller like musb and the +* the PHY or transceiver that drives the actual bus. +*/ +int twl4030_usb_ulpi_init (void ) +{ +long timeout =1000 *1000 ;/* 1 sec */ ; +u8 clk, sts, pwr; + +/* twl4030 ldo init */ +twl4030_usb_ldo_init (); + +/* Enable the twl4030 phy */ +twl4030_phy_power (); + +/* Enable DPLL to access PHY registers over I2C */ + clk =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL );
drivers/usb/phy/twl4030.c line 156
Quoted 10 lines
drivers/usb/phy/twl4030.c new file +10
-0+ clk |=REQ_PHY_DPLL_CLK ; +twl4030_usb_write (TWL4030_USB_PHY_CLK_CTRL , clk); + +/* Check if the PHY DPLL is locked */ + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); +while (!(sts &PHY_DPLL_CLK ) &&0 < timeout) { +udelay (10 ); + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); + timeout -=10 ; + }
why not set time to 100 * 1000
and just decrease by 1
Quoted 6 lines
drivers/usb/phy/twl4030.c new file +6
-0+ +/* Final check */ + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); +if (!(sts &PHY_DPLL_CLK )) { +printf ("Error:TWL4030:USB Timeout setting PHY DPLL clock\n" ); +return -1 ;
drivers/usb/phy/twl4030.c line 172
Quoted 10 lines
drivers/usb/phy/twl4030.c new file +10
-0+ } + +/* +* There are two circuit blocks attached to the PHY, +* Carkit and USB OTG. Disable Carkit and enable USB OTG +*/ +twl4030_usb_write (TWL4030_USB_IFC_CTRL_CLR ,CARKITMODE ); + pwr =twl4030_usb_read (TWL4030_USB_POWER_CTRL ); + pwr |=OTG_ENAB ; +twl4030_usb_write (TWL4030_USB_POWER_CTRL_SET , pwr);
please add an empty line to make it more readable
drivers/usb/phy/twl4030.c line 174
Quoted 2 lines
drivers/usb/phy/twl4030.c new file +2
-0+/* Clear the opmode bits to ensure normal encode */ +twl4030_usb_write (TWL4030_USB_FUNC_CTRL_CLR ,OPMODE_MASK );
please add an empty line to make it more readable
Quoted 23 lines
drivers/usb/phy/twl4030.c new file +10
-0+/* Clear the xcvrselect bits to enable the high speed transeiver */ +twl4030_usb_write (TWL4030_USB_FUNC_CTRL_CLR ,XCVRSELECT_MASK ); + +/* Let ULPI control the DPLL clock */ + clk =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL ); + clk &= ~REQ_PHY_DPLL_CLK ; +twl4030_usb_write (TWL4030_USB_PHY_CLK_CTRL , clk); + +return 0 ; +}include/twl4030.h +0
-5@@ -342,21 +342,129 @@#define TWL4030_KEYPAD_CTRL_SOFT_NRST (1 << 0)/* USB */ -#define TWL4030_USB_FUNC_CTRL (0x04) -#define TWL4030_USB_OPMODE_MASK (3 << 3) -#define TWL4030_USB_XCVRSELECT_MASK (3 << 0) -#define TWL4030_USB_IFC_CTRL (0x07) -#define TWL4030_USB_CARKITMODE (1 << 2)
include/twl4030.h line 359
Quoted 10 lines
include/twl4030.h +0
-10-#define TWL4030_USB_POWER_CTRL (0xAC) -#define TWL4030_USB_OTG_ENAB (1 << 5) -#define TWL4030_USB_PHY_PWR_CTRL (0xFD) -#define TWL4030_USB_PHYPWD (1 << 0) -#define TWL4030_USB_PHY_CLK_CTRL (0xFE) -#define TWL4030_USB_CLOCKGATING_EN (1 << 2) -#define TWL4030_USB_CLK32K_EN (1 << 1) -#define TWL4030_USB_REQ_PHY_DPLL_CLK (1 << 0) -#define TWL4030_USB_PHY_CLK_CTRL_STS (0xFF) -#define TWL4030_USB_PHY_DPLL_CLK (1 << 0)
make some enums by group of function will be better as it simplify the code
Quoted 35 lines
include/twl4030.h +35
-0+#define TWL4030_USB_VENDOR_ID_LO 0x00 +#define TWL4030_USB_VENDOR_ID_HI 0x01 +#define TWL4030_USB_PRODUCT_ID_LO 0x02 +#define TWL4030_USB_PRODUCT_ID_HI 0x03 +#define TWL4030_USB_FUNC_CTRL 0x04 +#define TWL4030_USB_FUNC_CTRL_SET 0x05 +#define TWL4030_USB_FUNC_CTRL_CLR 0x06 +#define TWL4030_USB_IFC_CTRL 0x07 +#define TWL4030_USB_IFC_CTRL_SET 0x08 +#define TWL4030_USB_IFC_CTRL_CLR 0x09 +#define TWL4030_USB_OTG_CTRL 0x0A +#define TWL4030_USB_OTG_CTRL_SET 0x0B +#define TWL4030_USB_OTG_CTRL_CLR 0x0C +#define TWL4030_USB_USB_INT_EN_RISE 0x0D +#define TWL4030_USB_USB_INT_EN_RISE_SET 0x0E +#define TWL4030_USB_USB_INT_EN_RISE_CLR 0x0F +#define TWL4030_USB_USB_INT_EN_FALL 0x10 +#define TWL4030_USB_USB_INT_EN_FALL_SET 0x11 +#define TWL4030_USB_USB_INT_EN_FALL_CLR 0x12 +#define TWL4030_USB_USB_INT_STS 0x13 +#define TWL4030_USB_USB_INT_LATCH 0x14 +#define TWL4030_USB_DEBUG 0x15 +#define TWL4030_USB_SCRATCH_REG 0x16 +#define TWL4030_USB_SCRATCH_REG_SET 0x17 +#define TWL4030_USB_SCRATCH_REG_CLR 0x18 +#define TWL4030_USB_CARKIT_CTRL 0x19 +#define TWL4030_USB_CARKIT_CTRL_SET 0x1A +#define TWL4030_USB_CARKIT_CTRL_CLR 0x1B +#define TWL4030_USB_CARKIT_INT_DELAY 0x1C +#define TWL4030_USB_CARKIT_INT_EN 0x1D +#define TWL4030_USB_CARKIT_INT_EN_SET 0x1E +#define TWL4030_USB_CARKIT_INT_EN_CLR 0x1F +#define TWL4030_USB_CARKIT_INT_STS 0x20 +#define TWL4030_USB_CARKIT_INT_LATCH 0x21 +#define TWL4030_USB_CARKIT_PLS_CTRL 0x22
include/twl4030.h line 389
Quoted 10 lines
include/twl4030.h +10
-0+#define TWL4030_USB_CARKIT_PLS_CTRL_SET 0x23 +#define TWL4030_USB_CARKIT_PLS_CTRL_CLR 0x24 +#define TWL4030_USB_TRANS_POS_WIDTH 0x25 +#define TWL4030_USB_TRANS_NEG_WIDTH 0x26 +#define TWL4030_USB_RCV_PLTY_RECOVERY 0x27 +#define TWL4030_USB_MCPC_CTRL 0x30 +#define TWL4030_USB_MCPC_CTRL_SET 0x31 +#define TWL4030_USB_MCPC_CTRL_CLR 0x32 +#define TWL4030_USB_MCPC_IO_CTRL 0x33 +#define TWL4030_USB_MCPC_IO_CTRL_SET 0x34
Best Regards,
J.
PATCH 3/8 TWL4030 Add usb PHY support
Quoted 2 lines · Jean-Christophe PLAGNIOL-VILLARD
On 15:12 Fri 04 Sep , Tom Rix wrote:
<snip>
Quoted 3 lines
Quoted 1 line
please add an empty line
I will take care of all the empty lines.
Quoted 8 lines
drivers/usb/phy/twl4030.c line 73
Quoted 7 lines
drivers/usb/phy/twl4030.c new file +6
-0+if (ret ==0 ) + ret = data; +else +printf ("TWL4030:USB:Read[0x%x] Error %d\n" , address, ret); + +return ret;why not this and avoid the copy of data
Quoted 9 lines
if (ret != 0) {
printf("TWL4030:USB:Read[0x%x] Error %d\n", address, ret);
return ret;
}
return data;
}In general I rather have only one exit point from a function. This makes tracing execution easier.
Quoted 11 lines
drivers/usb/phy/twl4030.c line 156
Quoted 8 lines
drivers/usb/phy/twl4030.c new file +7
-0+/* Check if the PHY DPLL is locked */ + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); +while (!(sts &PHY_DPLL_CLK ) &&0 < timeout) { +udelay (10 ); + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); + timeout -=10 ; + }why not set time to 100 * 1000
and just decrease by 1
Yes.
Quoted 5 lines
make some enums by group of function will be better as it simplify the code
include/twl4030.h line 346
Quoted 3 lines
include/twl4030.h +2
-0+#define TWL4030_USB_VENDOR_ID_LO 0x00 +#define TWL4030_USB_VENDOR_ID_HI 0x01
I see your point, but this is how they are defined in a twl4030 spec. This way makes it easy to look up #define in the spec. Just remove the prefix.
Quoted 3 lines
include/twl4030.h line 348
Quoted 3 lines
include/twl4030.h +2
-0+#define TWL4030_USB_PRODUCT_ID_LO 0x02 +#define TWL4030_USB_PRODUCT_ID_HI 0x03
Tom
Quoted 4 lines
Best Regards,
J.
PATCH 3/8 TWL4030 Add usb PHY support
Quoted 18 lines · Tom
Quoted 1 line · Jean-Christophe PLAGNIOL-VILLARD
On 15:12 Fri 04 Sep , Tom Rix wrote:
<snip>
Quoted 1 line
please add an empty line
I will take care of all the empty lines.
Quoted 12 lines
drivers/usb/phy/twl4030.c line 73
Quoted 6 lines
drivers/usb/phy/twl4030.c new file +6
-0+if (ret ==0 ) + ret = data; +else +printf ("TWL4030:USB:Read[0x%x] Error %d\n" , address, ret); + +return ret;why not this and avoid the copy of data
if (ret != 0) { printf("TWL4030:USB:Read[0x%x] Error %d\n", address, ret); return ret; }
Quoted 5 lines
Quoted 3 lines
return data; }In general I rather have only one exit point from a function. This makes tracing execution easier.
ok
Quoted 12 lines
Quoted 10 lines
drivers/usb/phy/twl4030.c line 156
Quoted 8 lines
drivers/usb/phy/twl4030.c new file +7
-0+/* Check if the PHY DPLL is locked */ + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); +while (!(sts &PHY_DPLL_CLK ) &&0 < timeout) { +udelay (10 ); + sts =twl4030_usb_read (TWL4030_USB_PHY_CLK_CTRL_STS ); + timeout -=10 ; + }why not set time to 100 * 1000
and just decrease by 1Yes.
Quoted 8 lines
Quoted 3 lines
make some enums by group of function will be better as it simplify the code
include/twl4030.h line 346
Quoted 2 lines
include/twl4030.h +2
-0+#define TWL4030_USB_VENDOR_ID_LO 0x00 +#define TWL4030_USB_VENDOR_ID_HI 0x01I see your point, but this is how they are defined in a twl4030 spec. This way makes it easy to look up #define in the spec. Just remove the prefix.
Quoted 2 lines
include/twl4030.h line 348
Quoted 2 lines
include/twl4030.h +2
-0+#define TWL4030_USB_PRODUCT_ID_LO 0x02 +#define TWL4030_USB_PRODUCT_ID_HI 0x03
ok fine
Best Regards,
J.
PATCH 2/8 USB add macros for debugging usb device setup.
In reply to Tom RixQuoted 14 lines · Tom Rix
When developing usb device features, it is useful to print out common usb structures.
Signed-off-by Tom Rix <[email protected]>--- include/usbdescriptors.h | 31 +++++++++++++ include/usbdevice.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 0 deletions(-)include/usbdescriptors.h +0
-0
include/usbdescriptors.h struct usb_class_descriptor { · line 514
Quoted 5 lines
include/usbdescriptors.h +2
-0@@ -510,4 +510,35 @@ struct usb_class_descriptor { } __attribute__ ((packed)); +#ifdef DEBUG +#define PRINT_DEVICE_DESCRIPTOR (d) \
inline will be better
Quoted 12 lines
include/usbdescriptors.h +12
-0+do { \ + serial_printf("usb device descriptor \n"); \ + serial_printf("\tbLength %2.2x\n", (d)->bLength); \ + serial_printf("\tbDescriptorType %2.2x\n", \ + (d)->bDescriptorType); \ + serial_printf("\tbcdUSB %4.4x\n", (d)->bcdUSB); \ + serial_printf("\tbDeviceClass %2.2x\n", (d)->bDeviceClass); \ + serial_printf("\tbDeviceSubClass %2.2x\n", \ + (d)->bDeviceSubClass); \ + serial_printf("\tbDeviceProtocol %2.2x\n", \ + (d)->bDeviceProtocol); \ + serial_printf("\tbMaxPacketSize0 %2.2x\n", \
include/usbdescriptors.h struct usb_class_descriptor { · line 536
Quoted 10 lines
include/usbdescriptors.h +10
-0+ (d)->bMaxPacketSize0); \ +serial_printf ("\tidVendor %4.4x\n" , (d)->idVendor); \ +serial_printf ("\tidProduct %4.4x\n" , (d)->idProduct); \ +serial_printf ("\tbcdDevice %4.4x\n" , (d)->bcdDevice); \ +serial_printf ("\tiManufacturer %2.2x\n" , (d)->iManufacturer); \ +serial_printf ("\tiProduct %2.2x\n" , (d)->iProduct); \ +serial_printf ("\tiSerialNumber %2.2x\n" , (d)->iSerialNumber); \ +serial_printf ("\tbNumConfigurations %2.2x\n" , \ + (d)->bNumConfigurations); \ +}while (0 )
Best Regards,
J.
PATCH 2/8 USB add macros for debugging usb device setup.
Quoted 17 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 15 lines · Tom Rix
When developing usb device features, it is useful to print out common usb structures.
Signed-off-by Tom Rix <[email protected]>--- include/usbdescriptors.h | 31 +++++++++++++ include/usbdevice.h | 105 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 0 deletions(-)include/usbdescriptors.h +0
-0@@ -510,4 +510,35 @@ struct usb_class_descriptor {
Quoted 7 lines
include/usbdescriptors.h struct usb_class_descriptor {
Quoted 5 lines
include/usbdescriptors.h +2
-0} __attribute__ ((packed)); +#ifdef DEBUG +#define PRINT_DEVICE_DESCRIPTOR (d) \inline will be better
Yes. I agree.
Tom
Quoted 3 lines
Best Regards,
J.