Skip to contentSkip to conversation

Port of MUSB driver from Linux (changes from Linux)

PATCH Superseded Ilya Yanok 2 participants 6 messages Nov 3, 2012 – Nov 4, 2012

Subsystems (9)
Arm (32-bit) USB PowerPC Kbuild +5 more subsystems

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ilya Yanok

author
#0 lore raw

v4 cover Port of MUSB driver from Linux (changes from Linux)

Current MUSB driver in U-Boot uses old UDC API while new gagdet client drivers need new gadget API. Also current MUSB driver has some significant limitations (like inability to handle tx for endpoints other than ep0). So I think port of new Linux driver is desirable.

This is initial port, performed mostly by putting DM and OTG code under #ifndef __UBOOT__ clauses. My intention was to be as close as possible to the original to ease of possible resyncs. Some warnings are suppressed via CFLAGS. There are some style problems but I'm not touching them for now for the above mentioned reason. There is obviously some room for optimisation, some structure fields are unused as well as (probably) some code.

This is not a replacement for existing MUSB driver (at least for now), cause there are still consumers of USB serial gadget which uses old API and there is no support for serial with new API for now.

OTG and DMA are not supported. Ported drivers include:
musb_dsps (should work both with TI AM33xx and TI81xx, tested only on AM33xx), am35x (tested on AM3517 EVM) and omap2plus (should work on OMAP2/3/4, tested on omap3_beagle, omap4_panda doesn't work and needs more work). Others should be easy to port too.

Virtual root hub is not implemented but this shouldn't be a big problem as the old code has virtual root hub support enabled only for Blackfin platform.

Pathes are rather big because of the original code size (and I didn't delete unused code, just disabled it). So it's probably better to look at changes as compared to Linux code. I prepared such version also, you can find it at [1]. Hopefully it will be also useful if resync with the kernel will be needed in future.

[1] https://github.com/yanok/u-boot/tree/musb-changes-from-linux-v4

Changes in v4:
- fix indent
- minor style fixes

Changes in v3:
- fix old MUSB code compilation
- bugfix: struct musb should be zeroed after alloc
- fix musb gadget_chips entry
- fix for new multi-interface usb API
- use clrsetbits_le32 for USB PHY ops

Changes in v2:
- add missing linux-compat.h header
- added host support
- glue code moved from musb_gadget_uboot.c to musb_uboot.c and cleaned up slightly.
- added check for malloc return value
- define is_{host,peripheral}_capable conditionally to support compilation with only host or gadget enabled
- added some more is_{host,peripheral}_capable guards to core code to support compilation with only host or gadget enabled
- rename backend config option to CONFIG_USB_MUSB_DSPS
- we are providing host support now so add yourself to usb.h

Ilya Yanok (13):
linux/usb/ch9.h: update with the version from Linux tree
usb: use linux/usb/ch9.h instead of usbdescriptors.h
musb-new: port of Linux musb driver
musb-new: dsps backend driver
am33xx: init OTG hardware and new musb gadget driver
am335x_evm: enable both musb gadget and host
musb-new: am35x backend driver
OMAP3: am35x_def.h: add USB defines
OMAP3: am35x: add musb functions
am3517_evm: switch to musb-new
musb-new: omap2plus backend driver
omap3_beagle: add musb-new init
omap3_beagle: use new MUSB intstead of the old one

 Makefile                                      |    1 +
 arch/arm/cpu/arm920t/s3c24x0/usb_ohci.c       |    2 +-
 arch/arm/cpu/armv7/am33xx/board.c             |  103 +-
 arch/arm/cpu/armv7/am33xx/clock.c             |    8 +
 arch/arm/cpu/armv7/omap3/Makefile             |    1 +
 arch/arm/cpu/armv7/omap3/am35x_musb.c         |   75 +
 arch/arm/include/asm/arch-am33xx/cpu.h        |   11 +-
 arch/arm/include/asm/arch-am33xx/hardware.h   |    4 +
 arch/arm/include/asm/arch-omap3/am35x_def.h   |   27 +
 arch/arm/include/asm/arch-omap3/musb.h        |   28 +
 arch/arm/include/asm/omap_musb.h              |   32 +
 arch/mips/cpu/mips32/au1x00/au1x00_usb_ohci.c |    2 +-
 arch/powerpc/cpu/mpc5xxx/usb_ohci.c           |    2 +-
 arch/powerpc/cpu/ppc4xx/usb_ohci.c            |    2 +-
 board/logicpd/am3517evm/am3517evm.c           |   74 +
 board/ti/beagle/beagle.c                      |   43 +
 common/cmd_usb.c                              |    2 +-
 common/usb.c                                  |    4 +-
 drivers/usb/gadget/config.c                   |    1 -
 drivers/usb/gadget/epautoconf.c               |    1 -
 drivers/usb/gadget/ether.c                    |    1 -
 drivers/usb/gadget/gadget_chips.h             |    4 +-
 drivers/usb/gadget/s3c_udc_otg.c              |    1 -
 drivers/usb/gadget/usbstring.c                |    1 -
 drivers/usb/host/ehci-hcd.c                   |   16 +-
 drivers/usb/host/isp116x-hcd.c                |    2 +-
 drivers/usb/host/ohci-hcd.c                   |    2 +-
 drivers/usb/host/sl811-hcd.c                  |    2 +-
 drivers/usb/musb-new/Makefile                 |   39 +
 drivers/usb/musb-new/am35x.c                  |  709 +++++++
 drivers/usb/musb-new/linux-compat.h           |  119 ++
 drivers/usb/musb-new/musb_core.c              | 2497 +++++++++++++++++++++++++
 drivers/usb/musb-new/musb_core.h              |  623 ++++++
 drivers/usb/musb-new/musb_debug.h             |   58 +
 drivers/usb/musb-new/musb_dma.h               |  186 ++
 drivers/usb/musb-new/musb_dsps.c              |  771 ++++++++
 drivers/usb/musb-new/musb_gadget.c            | 2333 +++++++++++++++++++++++
 drivers/usb/musb-new/musb_gadget.h            |  130 ++
 drivers/usb/musb-new/musb_gadget_ep0.c        | 1089 +++++++++++
 drivers/usb/musb-new/musb_host.c              | 2400 ++++++++++++++++++++++++
 drivers/usb/musb-new/musb_host.h              |  114 ++
 drivers/usb/musb-new/musb_io.h                |  146 ++
 drivers/usb/musb-new/musb_regs.h              |  645 +++++++
 drivers/usb/musb-new/musb_uboot.c             |  237 +++
 drivers/usb/musb-new/omap2430.c               |  626 +++++++
 drivers/usb/musb-new/omap2430.h               |   56 +
 drivers/usb/musb-new/usb-compat.h             |   88 +
 drivers/usb/musb/musb_core.h                  |    3 +-
 drivers/usb/musb/musb_hcd.c                   |    5 +-
 include/configs/am335x_evm.h                  |   27 +
 include/configs/am3517_evm.h                  |   37 +-
 include/configs/omap3_beagle.h                |   13 +-
 include/linux/usb/ch9.h                       |  514 ++++-
 include/linux/usb/musb.h                      |  162 ++
 include/usb.h                                 |   19 +-
 include/usb/s3c_udc.h                         |    1 -
 include/usb_defs.h                            |    6 -
 57 files changed, 14015 insertions(+), 90 deletions(-)
 create mode 100644 arch/arm/cpu/armv7/omap3/am35x_musb.c
 create mode 100644 arch/arm/include/asm/arch-omap3/musb.h
 create mode 100644 arch/arm/include/asm/omap_musb.h
 create mode 100644 drivers/usb/musb-new/Makefile
 create mode 100644 drivers/usb/musb-new/am35x.c
 create mode 100644 drivers/usb/musb-new/linux-compat.h
 create mode 100644 drivers/usb/musb-new/musb_core.c
 create mode 100644 drivers/usb/musb-new/musb_core.h
 create mode 100644 drivers/usb/musb-new/musb_debug.h
 create mode 100644 drivers/usb/musb-new/musb_dma.h
 create mode 100644 drivers/usb/musb-new/musb_dsps.c
 create mode 100644 drivers/usb/musb-new/musb_gadget.c
 create mode 100644 drivers/usb/musb-new/musb_gadget.h
 create mode 100644 drivers/usb/musb-new/musb_gadget_ep0.c
 create mode 100644 drivers/usb/musb-new/musb_host.c
 create mode 100644 drivers/usb/musb-new/musb_host.h
 create mode 100644 drivers/usb/musb-new/musb_io.h
 create mode 100644 drivers/usb/musb-new/musb_regs.h
 create mode 100644 drivers/usb/musb-new/musb_uboot.c
 create mode 100644 drivers/usb/musb-new/omap2430.c
 create mode 100644 drivers/usb/musb-new/omap2430.h
 create mode 100644 drivers/usb/musb-new/usb-compat.h
 create mode 100644 include/linux/usb/musb.h
Signature · 1 line
1.7.10.2 (Apple Git-33)
author
#1 lore raw

PATCH v4 1/13 linux/usb/ch9.h: update with the version from Linux tree

---

 drivers/usb/gadget/config.c      |    1 -
 drivers/usb/gadget/epautoconf.c  |    1 -
 drivers/usb/gadget/ether.c       |    1 -
 drivers/usb/gadget/s3c_udc_otg.c |    1 -
 drivers/usb/gadget/usbstring.c   |    1 -
 include/linux/usb/ch9.h          |  514 ++++++++++++++++++++++++++++++++++++--
 include/usb/s3c_udc.h            |    1 -
 7 files changed, 499 insertions(+), 21 deletions(-)
drivers/usb/gadget/config.c +0 -1
index f88d0c1..f9163a8 100644
@@ -27,7 +27,6 @@
 #include <linux/string.h>
 
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <linux/usb/gadget.h>
 
 
drivers/usb/gadget/epautoconf.c +0 -1
index b656c8b..5b8776e 100644
@@ -23,7 +23,6 @@
 
 #include <common.h>
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <asm/errno.h>
 #include <linux/usb/gadget.h>
 #include <asm/unaligned.h>
drivers/usb/gadget/ether.c +0 -1
index 1e187e5..c51e69c 100644
@@ -24,7 +24,6 @@
 #include <asm/errno.h>
 #include <linux/netdevice.h>
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <linux/usb/cdc.h>
 #include <linux/usb/gadget.h>
 #include <net.h>
drivers/usb/gadget/s3c_udc_otg.c +0 -1
index 3fdfdf7..f9d24e3 100644
@@ -37,7 +37,6 @@
 #include <malloc.h>
 
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <linux/usb/gadget.h>
 
 #include <asm/byteorder.h>
drivers/usb/gadget/usbstring.c +0 -1
index 4dbe060..95555cf 100644
@@ -13,7 +13,6 @@
 #include <common.h>
 #include <asm/errno.h>
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <linux/usb/gadget.h>
 
 #include <asm/unaligned.h>
include/linux/usb/ch9.h +499 -15

641 lines not on this page · raw message

include/usb/s3c_udc.h +0 -1
index 6a8fd44..7114dae 100644
@@ -24,7 +24,6 @@
 
 #include <asm/errno.h>
 #include <linux/usb/ch9.h>
-#include <usbdescriptors.h>
 #include <linux/usb/gadget.h>
 #include <linux/list.h>
 #include <usb/lin_gadget_compat.h>
Signature · 1 line
1.7.10.2 (Apple Git-33)
author
#2 lore raw

PATCH v4 2/13 usb: use linux/usb/ch9.h instead of usbdescriptors.h

In reply to Ilya Yanok

Linux usb/ch9.h seems to have all the same information (and more) as usbdescriptors.h so use the former instead of the later one.

As a consequense of this change USB_SPEED_* values don't correspond directly to EHCI speed encoding anymore, I've added necessary recoding in EHCI driver. Also there is no point to put speed into pipe anymore so it's removed and a bunch of host drivers fixed to look at usb_device->speed instead.

Old usbdescriptors.h included is not removed as it seems to be used by old USB device code.

This makes usb.h and usbdevice.h incompatible. Fortunately the only place that tries to include both are the old MUSB code and it needs usb.h only for USB_DMA_MINALIGN used in aligned attribute on musb_regs structure but this attribute seems to be unneeded (old MUSB code doesn't support any DMA at all).

---
Changes in v4:
- fix indent

Changes in v3:
- fix old MUSB code compilation

 arch/arm/cpu/arm920t/s3c24x0/usb_ohci.c       |    2 +-
 arch/mips/cpu/mips32/au1x00/au1x00_usb_ohci.c |    2 +-
 arch/powerpc/cpu/mpc5xxx/usb_ohci.c           |    2 +-
 arch/powerpc/cpu/ppc4xx/usb_ohci.c            |    2 +-
 common/cmd_usb.c                              |    2 +-
 common/usb.c                                  |    4 ++--
 drivers/usb/host/ehci-hcd.c                   |   16 ++++++++++++++--
 drivers/usb/host/isp116x-hcd.c                |    2 +-
 drivers/usb/host/ohci-hcd.c                   |    2 +-
 drivers/usb/host/sl811-hcd.c                  |    2 +-
 drivers/usb/musb/musb_core.h                  |    3 +--
 drivers/usb/musb/musb_hcd.c                   |    5 +++--
 include/usb.h                                 |   15 +++------------
 include/usb_defs.h                            |    6 ------
 14 files changed, 31 insertions(+), 34 deletions(-)
arch/arm/cpu/arm920t/s3c24x0/usb_ohci.c +1 -1
index 944bb32..3bca66a 100644
@@ -620,7 +620,7 @@ static struct ed *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe)
 			      | (usb_pipeisoc(pipe) ? 0x8000 : 0)
 			      | (usb_pipecontrol(pipe) ? 0 :
 				 (usb_pipeout(pipe) ? 0x800 : 0x1000))
-			      | usb_pipeslow(pipe) << 13 |
+			      | (usb_dev->speed == USB_SPEED_LOW) << 13 |
 			      usb_maxpacket(usb_dev, pipe) << 16);
 
 	return ed_ret;
arch/mips/cpu/mips32/au1x00/au1x00_usb_ohci.c +1 -1
index c747767..b9b0998 100644
@@ -615,7 +615,7 @@ static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
 			| usb_pipeendpoint (pipe) << 7
 			| (usb_pipeisoc (pipe)? 0x8000: 0)
 			| (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
-			| usb_pipeslow (pipe) << 13
+			| (usb_dev->speed == USB_SPEED_LOW) << 13
 			| usb_maxpacket (usb_dev, pipe) << 16);
 
 	return ed_ret;
arch/powerpc/cpu/mpc5xxx/usb_ohci.c +1 -1
index 607034b..de07343 100644
@@ -618,7 +618,7 @@ static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
 			| usb_pipeendpoint (pipe) << 7
 			| (usb_pipeisoc (pipe)? 0x8000: 0)
 			| (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
-			| usb_pipeslow (pipe) << 13
+			| (usb_dev->speed == USB_SPEED_LOW) << 13
 			| usb_maxpacket (usb_dev, pipe) << 16);
 
 	return ed_ret;
arch/powerpc/cpu/ppc4xx/usb_ohci.c +1 -1
index 4ce2726..f820c37 100644
@@ -621,7 +621,7 @@ static ed_t * ep_add_ed (struct usb_device *usb_dev, unsigned long pipe)
 			| usb_pipeendpoint (pipe) << 7
 			| (usb_pipeisoc (pipe)? 0x8000: 0)
 			| (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
-			| usb_pipeslow (pipe) << 13
+			| (usb_dev->speed == USB_SPEED_LOW) << 13
 			| usb_maxpacket (usb_dev, pipe) << 16);
 
 	return ed_ret;
common/cmd_usb.c +1 -1
index c128455..8be9952 100644
@@ -192,7 +192,7 @@ void usb_display_desc(struct usb_device *dev)
 
 }
 
-void usb_display_conf_desc(struct usb_configuration_descriptor *config,
+void usb_display_conf_desc(struct usb_config_descriptor *config,
 			   struct usb_device *dev)
 {
 	printf("   Configuration: %d\n", config->bConfigurationValue);
common/usb.c +2 -2
index 1c9763c..94b78d1 100644
@@ -492,9 +492,9 @@ int usb_get_configuration_no(struct usb_device *dev,
 {
 	int result;
 	unsigned int tmp;
-	struct usb_configuration_descriptor *config;
+	struct usb_config_descriptor *config;
 
-	config = (struct usb_configuration_descriptor *)&buffer[0];
+	config = (struct usb_config_descriptor *)&buffer[0];
 	result = usb_get_descriptor(dev, USB_DT_CONFIG, cfgno, buffer, 9);
 	if (result < 9) {
 		if (result < 0)
drivers/usb/host/ehci-hcd.c +14 -2
index d90e94d..7f98a63 100644
@@ -210,6 +210,18 @@ static int ehci_td_buffer(struct qTD *td, void *buf, size_t sz)
 	return 0;
 }
 
+static inline u8 ehci_encode_speed(enum usb_device_speed speed)
+{
+	#define QH_HIGH_SPEED	2
+	#define QH_FULL_SPEED	0
+	#define QH_LOW_SPEED	1
+	if (speed == USB_SPEED_HIGH)
+		return QH_HIGH_SPEED;
+	if (speed == USB_SPEED_LOW)
+		return QH_LOW_SPEED;
+	return QH_FULL_SPEED;
+}
+
 static int
 ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
 		   int length, struct devrequest *req)
@@ -318,12 +330,12 @@ ehci_submit_async(struct usb_device *dev, unsigned long pipe, void *buffer,
 	 * - qh_overlay.qt_altnext
 	 */
 	qh->qh_link = cpu_to_hc32((uint32_t)&ctrl->qh_list | QH_LINK_TYPE_QH);
-	c = usb_pipespeed(pipe) != USB_SPEED_HIGH && !usb_pipeendpoint(pipe);
+	c = (dev->speed != USB_SPEED_HIGH) && !usb_pipeendpoint(pipe);
 	maxpacket = usb_maxpacket(dev, pipe);
 	endpt = QH_ENDPT1_RL(8) | QH_ENDPT1_C(c) |
 		QH_ENDPT1_MAXPKTLEN(maxpacket) | QH_ENDPT1_H(0) |
 		QH_ENDPT1_DTC(QH_ENDPT1_DTC_DT_FROM_QTD) |
-		QH_ENDPT1_EPS(usb_pipespeed(pipe)) |
+		QH_ENDPT1_EPS(ehci_encode_speed(dev->speed)) |
 		QH_ENDPT1_ENDPT(usb_pipeendpoint(pipe)) | QH_ENDPT1_I(0) |
 		QH_ENDPT1_DEVADDR(usb_pipedevice(pipe));
 	qh->qh_endpt1 = cpu_to_hc32(endpt);
drivers/usb/host/isp116x-hcd.c +1 -1
index 19e16a4..289018c 100644
@@ -617,7 +617,7 @@ static int isp116x_submit_job(struct usb_device *dev, unsigned long pipe,
 	int epnum = usb_pipeendpoint(pipe);
 	int max = usb_maxpacket(dev, pipe);
 	int dir_out = usb_pipeout(pipe);
-	int speed_low = usb_pipeslow(pipe);
+	int speed_low = (dev->speed == USB_SPEED_LOW);
 	int i, done = 0, stat, timeout, cc;
 
 	/* 500 frames or 0.5s timeout when function is busy and NAKs transactions for a while */
drivers/usb/host/ohci-hcd.c +1 -1
index c2106ad..bdbe250 100644
@@ -803,7 +803,7 @@ static ed_t *ep_add_ed(struct usb_device *usb_dev, unsigned long pipe,
 			| (usb_pipeisoc(pipe)? 0x8000: 0)
 			| (usb_pipecontrol(pipe)? 0: \
 					   (usb_pipeout(pipe)? 0x800: 0x1000))
-			| usb_pipeslow(pipe) << 13
+			| (usb_dev->speed == USB_SPEED_LOW) << 13
 			| usb_maxpacket(usb_dev, pipe) << 16);
 
 	if (ed->type == PIPE_INTERRUPT && ed->state == ED_UNLINK) {
drivers/usb/host/sl811-hcd.c +1 -1
index 2830616..417f1a8 100644
@@ -234,7 +234,7 @@ static int sl811_send_packet(struct usb_device *dev, unsigned long pipe, __u8 *b
 	__u16 status = 0;
 	int err = 0, time_start = get_timer(0);
 	int need_preamble = !(rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED) &&
-		usb_pipeslow(pipe);
+		(dev->speed == USB_SPEED_LOW);
 
 	if (len > 239)
 		return -1;
drivers/usb/musb/musb_core.h +1 -2
index e914369..ec8a038 100644
@@ -34,7 +34,6 @@
 #ifndef __MUSB_HDRC_DEFS_H__
 #define __MUSB_HDRC_DEFS_H__
 
-#include <usb.h>
 #include <usb_defs.h>
 #include <asm/io.h>
 
@@ -145,7 +144,7 @@ struct musb_regs {
 		struct musb_epN_regs epN;
 	} ep[16];
 
-} __attribute__((packed, aligned(USB_DMA_MINALIGN)));
+} __attribute__((packed));
 #endif
 
 /*
drivers/usb/musb/musb_hcd.c +3 -2
index 06be38d..60e03a4 100644
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <usb.h>
 #include "musb_hcd.h"
 
 /* MSC control transfers */
@@ -485,8 +486,8 @@ static int ctrlreq_in_status_phase(struct usb_device *dev)
  */
 static u8 get_dev_speed(struct usb_device *dev)
 {
-	return (dev->speed & USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
-		((dev->speed & USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
+	return (dev->speed == USB_SPEED_HIGH) ? MUSB_TYPE_SPEED_HIGH :
+		((dev->speed == USB_SPEED_LOW) ? MUSB_TYPE_SPEED_LOW :
 						MUSB_TYPE_SPEED_FULL);
 }
 
include/usb.h +3 -12
index 9dd8791..4689db6 100644
@@ -27,7 +27,7 @@
 #define _USB_H_
 
 #include <usb_defs.h>
-#include <usbdescriptors.h>
+#include <linux/usb/ch9.h>
 
 /*
  * The EHCI spec says that we must align to at least 32 bytes.  However,
@@ -67,12 +67,6 @@ struct devrequest {
 	unsigned short	length;
 } __attribute__ ((packed));
 
-/* All standard descriptors have these 2 fields in common */
-struct usb_descriptor_header {
-	unsigned char	bLength;
-	unsigned char	bDescriptorType;
-} __attribute__ ((packed));
-
 /* Interface */
 struct usb_interface {
 	struct usb_interface_descriptor desc;
@@ -86,7 +80,7 @@ struct usb_interface {
 
 /* Configuration information.. */
 struct usb_config {
-	struct usb_configuration_descriptor desc;
+	struct usb_config_descriptor desc;
 
 	unsigned char	no_of_if;	/* number of interfaces */
 	struct usb_interface if_desc[USB_MAXINTERFACES];
@@ -285,7 +279,6 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
  *  - device:		bits 8-14
  *  - endpoint:		bits 15-18
  *  - Data0/1:		bit 19
- *  - speed:		bit 26		(0 = Full, 1 = Low Speed, 2 = High)
  *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt,
  *					 10 = control, 11 = bulk)
  *
@@ -297,7 +290,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 /* Create various pipes... */
 #define create_pipe(dev,endpoint) \
 		(((dev)->devnum << 8) | ((endpoint) << 15) | \
-		((dev)->speed << 26) | (dev)->maxpacketsize)
+		(dev)->maxpacketsize)
 #define default_pipe(dev) ((dev)->speed << 26)
 
 #define usb_sndctrlpipe(dev, endpoint)	((PIPE_CONTROL << 30) | \
@@ -348,8 +341,6 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate);
 #define usb_pipe_endpdev(pipe)	(((pipe) >> 8) & 0x7ff)
 #define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)
 #define usb_pipedata(pipe)	(((pipe) >> 19) & 1)
-#define usb_pipespeed(pipe)	(((pipe) >> 26) & 3)
-#define usb_pipeslow(pipe)	(usb_pipespeed(pipe) == USB_SPEED_LOW)
 #define usb_pipetype(pipe)	(((pipe) >> 30) & 3)
 #define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
 #define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)
include/usb_defs.h +0 -6
index 8032e57..9502544 100644
@@ -80,12 +80,6 @@
 #define USB_DIR_OUT           0
 #define USB_DIR_IN            0x80
 
-/* USB device speeds */
-#define USB_SPEED_FULL		0x0	/* 12Mbps */
-#define USB_SPEED_LOW		0x1	/* 1.5Mbps */
-#define USB_SPEED_HIGH		0x2	/* 480Mbps */
-#define USB_SPEED_RESERVED	0x3
-
 /* Descriptor types */
 #define USB_DT_DEVICE        0x01
 #define USB_DT_CONFIG        0x02
Signature · 1 line
1.7.10.2 (Apple Git-33)
author
#3 lore raw

PATCH v4 3/13 musb-new: port of Linux musb driver

In reply to Ilya Yanok

Existing U-Boot musb driver has no support for the new gadget framework and also seems to have other limitations. As gadget framework is ported from Linux it seems pretty natural to port musb gadget driver as well.

This driver supports both host and peripheral modes.

This is not a replacement for current musb driver (at least now) as there are still some consumers of the old UDC interface.

No DMA operation support included, CONFIG_MUSB_PIO_ONLY should be defined.

Virtual root hub device is not implemented.

Known problems: with no devices connected usb_lowlevel_start() fails.

---
Changes in v4:
- minor style fixes

Changes in v3:
- bugfix: struct musb should be zeroed after alloc
- fix musb gadget_chips entry
- fix for new multi-interface usb API

Changes in v2:
- add missing linux-compat.h header
- added host support
- glue code moved from musb_gadget_uboot.c to musb_uboot.c and cleaned up slightly.
- added check for malloc return value
- define is_{host,peripheral}_capable conditionally to support compilation with only host or gadget enabled
- added some more is_{host,peripheral}_capable guards to core code to support compilation with only host or gadget enabled

 Makefile                               |    1 +
 drivers/usb/gadget/gadget_chips.h      |    4 +-
 drivers/usb/musb-new/Makefile          |   36 +
 drivers/usb/musb-new/linux-compat.h    |  109 ++
 drivers/usb/musb-new/musb_core.c       | 2497 ++++++++++++++++++++++++++++++++
 drivers/usb/musb-new/musb_core.h       |  623 ++++++++
 drivers/usb/musb-new/musb_debug.h      |   58 +
 drivers/usb/musb-new/musb_dma.h        |  186 +++
 drivers/usb/musb-new/musb_gadget.c     | 2333 +++++++++++++++++++++++++++++
 drivers/usb/musb-new/musb_gadget.h     |  130 ++
 drivers/usb/musb-new/musb_gadget_ep0.c | 1089 ++++++++++++++
 drivers/usb/musb-new/musb_host.c       | 2400 ++++++++++++++++++++++++++++++
 drivers/usb/musb-new/musb_host.h       |  114 ++
 drivers/usb/musb-new/musb_io.h         |  146 ++
 drivers/usb/musb-new/musb_regs.h       |  645 +++++++++
 drivers/usb/musb-new/musb_uboot.c      |  237 +++
 drivers/usb/musb-new/usb-compat.h      |   88 ++
 include/linux/usb/musb.h               |  162 +++
 18 files changed, 10856 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/musb-new/Makefile
 create mode 100644 drivers/usb/musb-new/linux-compat.h
 create mode 100644 drivers/usb/musb-new/musb_core.c
 create mode 100644 drivers/usb/musb-new/musb_core.h
 create mode 100644 drivers/usb/musb-new/musb_debug.h
 create mode 100644 drivers/usb/musb-new/musb_dma.h
 create mode 100644 drivers/usb/musb-new/musb_gadget.c
 create mode 100644 drivers/usb/musb-new/musb_gadget.h
 create mode 100644 drivers/usb/musb-new/musb_gadget_ep0.c
 create mode 100644 drivers/usb/musb-new/musb_host.c
 create mode 100644 drivers/usb/musb-new/musb_host.h
 create mode 100644 drivers/usb/musb-new/musb_io.h
 create mode 100644 drivers/usb/musb-new/musb_regs.h
 create mode 100644 drivers/usb/musb-new/musb_uboot.c
 create mode 100644 drivers/usb/musb-new/usb-compat.h
 create mode 100644 include/linux/usb/musb.h
Makefile +1 -0
index 90e99af..f35cf6f 100644
@@ -299,6 +299,7 @@ LIBS-y += drivers/usb/eth/libusb_eth.o
 LIBS-y += drivers/usb/gadget/libusb_gadget.o
 LIBS-y += drivers/usb/host/libusb_host.o
 LIBS-y += drivers/usb/musb/libusb_musb.o
+LIBS-y += drivers/usb/musb-new/libusb_musb-new.o
 LIBS-y += drivers/usb/phy/libusb_phy.o
 LIBS-y += drivers/usb/ulpi/libusb_ulpi.o
 LIBS-y += drivers/video/libvideo.o
drivers/usb/gadget/gadget_chips.h +2 -2
index 5d7b638..2759c12 100644
@@ -131,8 +131,8 @@
 #endif
 
 /* Mentor high speed "dual role" controller, in peripheral role */
-#ifdef CONFIG_USB_GADGET_MUSB_HDRC
-#define gadget_is_musbhdrc(g)	(!strcmp("musb_hdrc", (g)->name))
+#ifdef CONFIG_MUSB_GADGET
+#define gadget_is_musbhdrc(g)	(!strcmp("musb-hdrc", (g)->name))
 #else
 #define gadget_is_musbhdrc(g)	0
 #endif
drivers/usb/musb-new/Makefile new file +36 -0
new file mode 100644
index 0000000..f01fb16
@@ -0,0 +1,36 @@
+#
+# for USB OTG silicon based on Mentor Graphics INVENTRA designs
+#
+
+include $(TOPDIR)/config.mk
+
+LIB	:= $(obj)libusb_musb-new.o
+
+COBJS-$(CONFIG_MUSB_GADGET) += musb_gadget.o musb_gadget_ep0.o musb_core.o
+COBJS-$(CONFIG_MUSB_GADGET) += musb_uboot.o
+COBJS-$(CONFIG_MUSB_HOST) += musb_host.o musb_core.o musb_uboot.o
+
+CFLAGS_NO_WARN := $(call cc-option,-Wno-unused-variable) \
+			$(call cc-option,-Wno-unused-but-set-variable) \
+			$(call cc-option,-Wno-unused-label)
+CFLAGS += $(CFLAGS_NO_WARN)
+
+COBJS	:= $(sort $(COBJS-y))
+SRCS	:= $(COBJS:.o=.c)
+OBJS	:= $(addprefix $(obj),$(COBJS))
+
+all:	$(LIB)
+
+#$(LIB):	$(OBJS)
+$(LIB):	$(obj).depend $(OBJS)
+	$(call cmd_link_o_target, $(OBJS))
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
+
drivers/usb/musb-new/linux-compat.h new file +109 -0

109 lines not on this page · raw message

drivers/usb/musb-new/musb_core.c new file +2497 -0

2,497 lines not on this page · raw message

drivers/usb/musb-new/musb_core.h new file +623 -0

341 lines not on this page · raw message

drivers/usb/musb-new/musb_debug.h new file +58 -0

58 lines not on this page · raw message

drivers/usb/musb-new/musb_dma.h new file +186 -0

186 lines not on this page · raw message

drivers/usb/musb-new/musb_gadget.c new file +2333 -0

2,333 lines not on this page · raw message

drivers/usb/musb-new/musb_gadget.h new file +130 -0

130 lines not on this page · raw message

drivers/usb/musb-new/musb_gadget_ep0.c new file +1089 -0

1,089 lines not on this page · raw message

drivers/usb/musb-new/musb_host.c new file +2400 -0

2,400 lines not on this page · raw message

drivers/usb/musb-new/musb_host.h new file +114 -0

114 lines not on this page · raw message

drivers/usb/musb-new/musb_io.h new file +146 -0

146 lines not on this page · raw message

drivers/usb/musb-new/musb_regs.h new file +645 -0

645 lines not on this page · raw message

drivers/usb/musb-new/musb_uboot.c new file +237 -0

237 lines not on this page · raw message

drivers/usb/musb-new/usb-compat.h new file +88 -0

88 lines not on this page · raw message

include/linux/usb/musb.h new file +162 -0

162 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.10.2 (Apple Git-33)

Part of the diff is not shown here. View the raw message.

author
#4 lore raw

PATCH v4 4/13 musb-new: dsps backend driver

In reply to Ilya Yanok

Backend driver for MUSB OTG controllers found on TI AM33xx and TI81xx SoCs (tested with AM33xx only).

---
Changes in v2:
- rename backend config option to CONFIG_USB_MUSB_DSPS
- we are providing host support now so add yourself to usb.h

 arch/arm/include/asm/omap_musb.h |   25 ++
 drivers/usb/musb-new/Makefile    |    1 +
 drivers/usb/musb-new/musb_dsps.c |  771 ++++++++++++++++++++++++++++++++++++++
 include/usb.h                    |    3 +-
 4 files changed, 799 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/include/asm/omap_musb.h
 create mode 100644 drivers/usb/musb-new/musb_dsps.c
arch/arm/include/asm/omap_musb.h new file +25 -0
new file mode 100644
index 0000000..0081a68
@@ -0,0 +1,25 @@
+/*
+ * Board data structure for musb gadget on OMAPs
+ *
+ * Copyright (C) 2012, Ilya Yanok <[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.
+ */
+
+#ifndef __ASM_ARM_OMAP_MUSB_H
+#define __ASM_ARM_OMAP_MUSB_H
+
+extern struct musb_platform_ops musb_dsps_ops;
+
+struct omap_musb_board_data {
+	void (*set_phy_power)(u8 on);
+};
+#endif /* __ASM_ARM_OMAP_MUSB_H */
drivers/usb/musb-new/Makefile +1 -0
index f01fb16..a753423 100644
@@ -9,6 +9,7 @@ LIB	:= $(obj)libusb_musb-new.o
 COBJS-$(CONFIG_MUSB_GADGET) += musb_gadget.o musb_gadget_ep0.o musb_core.o
 COBJS-$(CONFIG_MUSB_GADGET) += musb_uboot.o
 COBJS-$(CONFIG_MUSB_HOST) += musb_host.o musb_core.o musb_uboot.o
+COBJS-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o
 
 CFLAGS_NO_WARN := $(call cc-option,-Wno-unused-variable) \
 			$(call cc-option,-Wno-unused-but-set-variable) \
drivers/usb/musb-new/musb_dsps.c new file +771 -0

771 lines not on this page · raw message

include/usb.h +2 -1
index 4689db6..aa389e6 100644
@@ -147,7 +147,8 @@ struct usb_device {
 	defined(CONFIG_USB_SL811HS) || defined(CONFIG_USB_ISP116X_HCD) || \
 	defined(CONFIG_USB_R8A66597_HCD) || defined(CONFIG_USB_DAVINCI) || \
 	defined(CONFIG_USB_OMAP3) || defined(CONFIG_USB_DA8XX) || \
-	defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X)
+	defined(CONFIG_USB_BLACKFIN) || defined(CONFIG_USB_AM35X) || \
+	defined(CONFIG_USB_MUSB_DSPS)
 
 int usb_lowlevel_init(int index, void **controller);
 int usb_lowlevel_stop(int index);
Signature · 1 line
1.7.10.2 (Apple Git-33)
#5 lore raw

v4 cover Port of MUSB driver from Linux (changes from Linux)

In reply to Ilya Yanok

Dear Ilya Yanok,

Quoted 29 lines

Current MUSB driver in U-Boot uses old UDC API while new gagdet client drivers need new gadget API. Also current MUSB driver has some significant limitations (like inability to handle tx for endpoints other than ep0). So I think port of new Linux driver is desirable.

This is initial port, performed mostly by putting DM and OTG code under #ifndef __UBOOT__ clauses. My intention was to be as close as possible to the original to ease of possible resyncs. Some warnings are suppressed via CFLAGS. There are some style problems but I'm not touching them for now for the above mentioned reason. There is obviously some room for optimisation, some structure fields are unused as well as (probably) some code.

This is not a replacement for existing MUSB driver (at least for now), cause there are still consumers of USB serial gadget which uses old API and there is no support for serial with new API for now.

OTG and DMA are not supported. Ported drivers include:
musb_dsps (should work both with TI AM33xx and TI81xx, tested only on AM33xx), am35x (tested on AM3517 EVM) and omap2plus (should work on OMAP2/3/4, tested on omap3_beagle, omap4_panda doesn't work and needs more work). Others should be easy to port too.

Virtual root hub is not implemented but this shouldn't be a big problem as the old code has virtual root hub support enabled only for Blackfin platform.

Quoted 7 lines

Pathes are rather big because of the original code size (and I didn't delete unused code, just disabled it). So it's probably better to look at changes as compared to Linux code. I prepared such version also, you can find it at [1]. Hopefully it will be also useful if resync with the kernel will be needed in future.

[1] https://github.com/yanok/u-boot/tree/musb-changes-from-linux-v4

[...]

What is this patchset ? I received another similar one, but which is more complete ...