Skip to contentSkip to conversation

usb: musb: make sure the register layout is packed

PATCH New Mike Frysinger 2 participants 11 messages Dec 17, 2009 – Dec 22, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/5 usb: musb: make sure the register layout is packed

---
 drivers/usb/musb/musb_core.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/usb/musb/musb_core.h +1 -1
index f9da3f0..5e01b98 100644
@@ -97,7 +97,7 @@ struct musb_regs {
 		u8	rxhubaddr;
 		u8	rxhubport;
 	} tar[16];
-} __attribute__((aligned(32)));
+} __attribute__((packed, aligned(32)));
 
 /*
  * MUSB Register bits
Signature · 1 line
1.6.5.5
#1 lore raw

PATCH 2/5 usb: musb: make fifo support configurable

From: Bryan Wu <[email protected]>

The dynamic FIFO handling under MUSB is optional, and some parts (like the Blackfin processor) do not implement support for it.

Due to this, the FIFO reading/writing steps need special handling, so mark the common versions weak so drivers can override.

---
 drivers/usb/musb/musb_core.c |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)
drivers/usb/musb/musb_core.c +16 -4
index ec57fc8..2bad610 100644
@@ -48,6 +48,16 @@ void musb_start(void)
 #endif
 }
 
+#ifdef MUSB_NO_DYNAMIC_FIFO
+# define config_fifo(dir, idx, addr)
+#else
+# define config_fifo(dir, idx, addr) \
+	do { \
+		writeb(idx, &musbr->dir##fifosz); \
+		writew(fifoaddr >> 3, &musbr->dir##fifoadd); \
+	} while (0)
+#endif
+
 /*
  * This function configures the endpoint configuration. The musb hcd or musb
  * device implementation can use this function to configure the endpoints
@@ -72,8 +82,8 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
 		writeb(epinfo->epnum, &musbr->index);
 		if (epinfo->epdir) {
 			/* Configure fifo size and fifo base address */
-			writeb(idx, &musbr->txfifosz);
-			writew(fifoaddr >> 3, &musbr->txfifoadd);
+			config_fifo(tx, idx, fifoaddr);
+
 #if defined(CONFIG_MUSB_HCD)
 			/* clear the data toggle bit */
 			csr = readw(&musbr->txcsr);
@@ -85,8 +95,8 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
 					&musbr->txcsr);
 		} else {
 			/* Configure fifo size and fifo base address */
-			writeb(idx, &musbr->rxfifosz);
-			writew(fifoaddr >> 3, &musbr->rxfifoadd);
+			config_fifo(rx, idx, fifoaddr);
+
 #if defined(CONFIG_MUSB_HCD)
 			/* clear the data toggle bit */
 			csr = readw(&musbr->rxcsr);
@@ -109,6 +119,7 @@ void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt)
  * length	- number of bytes to write to FIFO
  * fifo_data	- Pointer to data buffer that contains the data to write
  */
+__attribute__((weak))
 void write_fifo(u8 ep, u32 length, void *fifo_data)
 {
 	u8  *data = (u8 *)fifo_data;
@@ -128,6 +139,7 @@ void write_fifo(u8 ep, u32 length, void *fifo_data)
  * length       - number of bytes to read from FIFO
  * fifo_data    - pointer to data buffer into which data is read
  */
+__attribute__((weak))
 void read_fifo(u8 ep, u32 length, void *fifo_data)
 {
 	u8  *data = (u8 *)fifo_data;
Signature · 1 line
1.6.5.5
#2 lore raw

PATCH 2/5 usb: musb: make fifo support configurable

Hi,

2009/12/17 Mike Frysinger <[email protected]>:

Quoted 5 lines

From: Bryan Wu <[email protected]>

The dynamic FIFO handling under MUSB is optional, and some parts (like the Blackfin processor) do not implement support for it.

Quoted 7 lines

Due to this, the FIFO reading/writing steps need special handling, so mark the common versions weak so drivers can override.

---

Applied to u-boot-usb with merge conflicts, please review the merge changes at:
http://git.denx.de/?p=u-boot/u-boot-usb.git;a=commitdiff;h=07255d98dc1c55d12c0ad728db8a7436da7b53ea

Thanks.

Remy

#3 lore raw

PATCH 3/5 usb: musb: make multipoint optional

In reply to Mike Frysinger

From: Bryan Wu <[email protected]>

The multipoint handling under MUSB is optional, and some parts (like the Blackfin processor) do not implement support for it.

---
 drivers/usb/musb/musb_hcd.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
drivers/usb/musb/musb_hcd.c +20 -0
index 4ca94cb..8d94aea 100644
@@ -402,11 +402,13 @@ static void config_hub_port(struct usb_device *dev, u8 ep)
 		if (dev->parent->children[chid] == dev)
 			break;
 
+#ifndef MUSB_NO_MULTIPOINT
 	/* configure the hub address and the port address */
 	writeb(hub, &musbr->tar[ep].txhubaddr);
 	writeb((chid + 1), &musbr->tar[ep].txhubport);
 	writeb(hub, &musbr->tar[ep].rxhubaddr);
 	writeb((chid + 1), &musbr->tar[ep].rxhubport);
+#endif
 }
 
 /*
@@ -415,7 +417,9 @@ static void config_hub_port(struct usb_device *dev, u8 ep)
 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 			int len, struct devrequest *setup)
 {
+#ifndef MUSB_NO_MULTIPOINT
 	int devnum = usb_pipedevice(pipe);
+#endif
 	u16 csr;
 	u8  devspeed;
 
@@ -423,9 +427,11 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 	writeb(MUSB_CONTROL_EP, &musbr->index);
 	csr = readw(&musbr->txcsr);
 
+#ifndef MUSB_NO_MULTIPOINT
 	/* target addr and (for multipoint) hub addr/port */
 	writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].txfuncaddr);
 	writeb(devnum, &musbr->tar[MUSB_CONTROL_EP].rxfuncaddr);
+#endif
 
 	/* configure the hub address and the port number as required */
 	devspeed = get_dev_speed(dev);
@@ -435,10 +441,12 @@ int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
 		writeb(devspeed << 6, &musbr->txtype);
 	} else {
 		writeb(musb_cfg.musb_speed << 6, &musbr->txtype);
+#ifndef MUSB_NO_MULTIPOINT
 		writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubaddr);
 		writeb(0, &musbr->tar[MUSB_CONTROL_EP].txhubport);
 		writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubaddr);
 		writeb(0, &musbr->tar[MUSB_CONTROL_EP].rxhubport);
+#endif
 	}
 
 	/* Control transfer setup phase */
@@ -497,7 +505,9 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 {
 	int dir_out = usb_pipeout(pipe);
 	int ep = usb_pipeendpoint(pipe);
+#ifndef MUSB_NO_MULTIPOINT
 	int devnum = usb_pipedevice(pipe);
+#endif
 	u8  type;
 	u16 csr;
 	u32 txlen = 0;
@@ -507,11 +517,13 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 	/* select bulk endpoint */
 	writeb(MUSB_BULK_EP, &musbr->index);
 
+#ifndef MUSB_NO_MULTIPOINT
 	/* write the address of the device */
 	if (dir_out)
 		writeb(devnum, &musbr->tar[MUSB_BULK_EP].txfuncaddr);
 	else
 		writeb(devnum, &musbr->tar[MUSB_BULK_EP].rxfuncaddr);
+#endif
 
 	/* configure the hub address and the port number as required */
 	devspeed = get_dev_speed(dev);
@@ -524,6 +536,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 		 */
 		config_hub_port(dev, MUSB_BULK_EP);
 	} else {
+#ifndef MUSB_NO_MULTIPOINT
 		if (dir_out) {
 			writeb(0, &musbr->tar[MUSB_BULK_EP].txhubaddr);
 			writeb(0, &musbr->tar[MUSB_BULK_EP].txhubport);
@@ -531,6 +544,7 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 			writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubaddr);
 			writeb(0, &musbr->tar[MUSB_BULK_EP].rxhubport);
 		}
+#endif
 		devspeed = musb_cfg.musb_speed;
 	}
 
@@ -696,7 +710,9 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 {
 	int dir_out = usb_pipeout(pipe);
 	int ep = usb_pipeendpoint(pipe);
+#ifndef MUSB_NO_MULTIPOINT
 	int devnum = usb_pipedevice(pipe);
+#endif
 	u8  type;
 	u16 csr;
 	u32 txlen = 0;
@@ -706,11 +722,13 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 	/* select interrupt endpoint */
 	writeb(MUSB_INTR_EP, &musbr->index);
 
+#ifndef MUSB_NO_MULTIPOINT
 	/* write the address of the device */
 	if (dir_out)
 		writeb(devnum, &musbr->tar[MUSB_INTR_EP].txfuncaddr);
 	else
 		writeb(devnum, &musbr->tar[MUSB_INTR_EP].rxfuncaddr);
+#endif
 
 	/* configure the hub address and the port number as required */
 	devspeed = get_dev_speed(dev);
@@ -723,6 +741,7 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 		 */
 		config_hub_port(dev, MUSB_INTR_EP);
 	} else {
+#ifndef MUSB_NO_MULTIPOINT
 		if (dir_out) {
 			writeb(0, &musbr->tar[MUSB_INTR_EP].txhubaddr);
 			writeb(0, &musbr->tar[MUSB_INTR_EP].txhubport);
@@ -730,6 +749,7 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 			writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubaddr);
 			writeb(0, &musbr->tar[MUSB_INTR_EP].rxhubport);
 		}
+#endif
 		devspeed = musb_cfg.musb_speed;
 	}
 
Signature · 1 line
1.6.5.5
#4 lore raw

PATCH 3/5 usb: musb: make multipoint optional

Hi,

2009/12/17 Mike Frysinger <[email protected]>:

Quoted 11 lines

From: Bryan Wu <[email protected]>

The multipoint handling under MUSB is optional, and some parts (like the Blackfin processor) do not implement support for it.

---
?drivers/usb/musb/musb_hcd.c | ? 20 ++++++++++++++++++++ ?1 files changed, 20 insertions(+), 0 deletions(-)

Applied to u-boot-usb

Thanks.

Remy

#5 lore raw

PATCH 4/5 usb: musb: change rxcsr register from write to read/modify/write

In reply to Mike Frysinger

From: Bryan Wu <[email protected]>

The RX Control/Status register has bits that we want to preserve, so don't just write out a single bit. Preserve the others bits in the process.

The original code posted to the u-boot list had this behavior, but looks like it was lost somewhere along the way to merging.

---
 drivers/usb/musb/musb_hcd.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/usb/musb/musb_hcd.c +4 -2
index 8d94aea..281fc70 100644
@@ -604,7 +604,8 @@ int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
 					(len-txlen) : dev->epmaxpacketin[ep];
 
 			/* Set the ReqPkt bit */
-			writew(MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
+			csr = readw(&musbr->rxcsr);
+			writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
 
 			/* Wait until the RxPktRdy bit is set */
 			if (!wait_until_rxep_ready(dev, MUSB_BULK_EP)) {
@@ -775,7 +776,8 @@ int submit_int_msg(struct usb_device *dev, unsigned long pipe,
 					(len-txlen) : dev->epmaxpacketin[ep];
 
 			/* Set the ReqPkt bit */
-			writew(MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
+			csr = readw(&musbr->rxcsr);
+			writew(csr | MUSB_RXCSR_H_REQPKT, &musbr->rxcsr);
 
 			/* Wait until the RxPktRdy bit is set */
 			if (!wait_until_rxep_ready(dev, MUSB_INTR_EP)) {
Signature · 1 line
1.6.5.5
#6 lore raw

PATCH 4/5 usb: musb: change rxcsr register from write to read/modify/write

Hi,

2009/12/17 Mike Frysinger <[email protected]>:

Quoted 8 lines

From: Bryan Wu <[email protected]>

The RX Control/Status register has bits that we want to preserve, so don't just write out a single bit. ?Preserve the others bits in the process.

The original code posted to the u-boot list had this behavior, but looks like it was lost somewhere along the way to merging.

Quoted 6 lines

---
?drivers/usb/musb/musb_hcd.c | ? ?6 ++++--
?1 files changed, 4 insertions(+), 2 deletions(-)

Applied to u-boot-usb
Thanks.

Remy

#7 lore raw

PATCH 5/5 usb: musb: add support for Blackfin MUSB

In reply to Mike Frysinger

From: Bryan Wu <[email protected]>

---
 drivers/usb/musb/Makefile                   |    1 +
 drivers/usb/musb/blackfin_usb.c             |  143 +++++++++++++++
 drivers/usb/musb/blackfin_usb.h             |   99 ++++++++++
 drivers/usb/musb/musb_core.h                |   16 ++
 drivers/usb/musb/musb_hcd.h                 |    4 +-
 include/asm-blackfin/mach-common/bits/usb.h |  264 +++++++++++++++++++++++++++
 include/usb.h                               |    3 +-
 7 files changed, 528 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/musb/blackfin_usb.c
 create mode 100644 drivers/usb/musb/blackfin_usb.h
 create mode 100644 include/asm-blackfin/mach-common/bits/usb.h
drivers/usb/musb/Makefile +1 -0
index 09e0a5f..40caf9b 100644
@@ -26,6 +26,7 @@ include $(TOPDIR)/config.mk
 LIB	:= $(obj)libusb_musb.a
 
 COBJS-$(CONFIG_MUSB_HCD) += musb_hcd.o musb_core.o
+COBJS-$(CONFIG_USB_BLACKFIN) += blackfin_usb.o
 COBJS-$(CONFIG_USB_DAVINCI) += davinci.o
 
 COBJS	:= $(COBJS-y)
drivers/usb/musb/blackfin_usb.c new file +143 -0

143 lines not on this page · raw message

drivers/usb/musb/blackfin_usb.h new file +99 -0

99 lines not on this page · raw message

drivers/usb/musb/musb_core.h +16 -0
index 5e01b98..e006a3c 100644
@@ -38,9 +38,14 @@
 #include <usb_defs.h>
 #include <asm/io.h>
 
+#ifdef CONFIG_USB_BLACKFIN
+# include "blackfin_usb.h"
+#endif
+
 #define MUSB_EP0_FIFOSIZE	64	/* This is non-configurable */
 
 /* Mentor USB core register overlay structure */
+#ifndef musb_regs
 struct musb_regs {
 	/* common registers */
 	u8	faddr;
@@ -98,6 +103,7 @@ struct musb_regs {
 		u8	rxhubport;
 	} tar[16];
 } __attribute__((packed, aligned(32)));
+#endif
 
 /*
  * MUSB Register bits
@@ -307,4 +313,14 @@ extern void musb_configure_ep(struct musb_epinfo *epinfo, u8 cnt);
 extern void write_fifo(u8 ep, u32 length, void *fifo_data);
 extern void read_fifo(u8 ep, u32 length, void *fifo_data);
 
+#if defined(CONFIG_USB_BLACKFIN)
+/* Every USB register is accessed as a 16-bit even if the value itself
+ * is only 8-bits in size.  Fun stuff.
+ */
+# undef  readb
+# define readb(addr)     (u8)bfin_read16(addr)
+# undef  writeb
+# define writeb(b, addr) bfin_write16(addr, b)
+#endif
+
 #endif	/* __MUSB_HDRC_DEFS_H__ */
drivers/usb/musb/musb_hcd.h +3 -1
index 17e9091..a437985 100644
@@ -38,7 +38,9 @@ extern unsigned char new[];
 #define MUSB_CONTROL_EP 0
 
 /* This defines the endpoint number used for bulk transfer */
-#define MUSB_BULK_EP 1
+#ifndef MUSB_BULK_EP
+# define MUSB_BULK_EP 1
+#endif
 
 /* This defines the endpoint number used for interrupt transfer */
 #define MUSB_INTR_EP 2
include/asm-blackfin/mach-common/bits/usb.h new file +264 -0

264 lines not on this page · raw message

include/usb.h +2 -1
index 7c47098..b398cc0 100644
@@ -183,7 +183,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_BLACKFIN)
 
 int usb_lowlevel_init(void);
 int usb_lowlevel_stop(void);
Signature · 1 line
1.6.5.5
#8 lore raw

PATCH 5/5 usb: musb: add support for Blackfin MUSB

Hi,

2009/12/17 Mike Frysinger <[email protected]>:

Quoted 13 lines

From: Bryan Wu <[email protected]>

---

?drivers/usb/musb/Makefile ? ? ? ? ? ? ? ? ? | ? ?1 +
?drivers/usb/musb/blackfin_usb.c ? ? ? ? ? ? | ?143 +++++++++++++++
?drivers/usb/musb/blackfin_usb.h ? ? ? ? ? ? | ? 99 ++++++++++
?drivers/usb/musb/musb_core.h ? ? ? ? ? ? ? ?| ? 16 ++
?drivers/usb/musb/musb_hcd.h ? ? ? ? ? ? ? ? | ? ?4 +-
?include/asm-blackfin/mach-common/bits/usb.h | ?264 +++++++++++++++++++++++++++
?include/usb.h ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | ? ?3 +-
Quoted 4 lines

?7 files changed, 528 insertions(+), 2 deletions(-) ?create mode 100644 drivers/usb/musb/blackfin_usb.c ?create mode 100644 drivers/usb/musb/blackfin_usb.h ?create mode 100644 include/asm-blackfin/mach-common/bits/usb.h

Applied to u-boot-usb with merge conflicts, please review the merge changes at:
http://git.denx.de/?p=u-boot/u-boot-usb.git;a=commitdiff;h=2804707e37bcb8d165698e83c4b1be0aa934b482

Thanks.

Remy

#9 lore raw

PATCH 1/5 usb: musb: make sure the register layout is packed

In reply to Mike Frysinger

Hi,

2009/12/17 Mike Frysinger <[email protected]>:

Quoted 16 lines

---
?drivers/usb/musb/musb_core.h | ? ?2 +-
?1 files changed, 1 insertions(+), 1 deletions(-)

drivers/usb/musb/musb_core.h +1 -1
index f9da3f0..5e01b98 100644
@@ -97,7 +97,7 @@ struct musb_regs {
 ? ? ? ? ? ? ? ?u8 ? ? ?rxhubaddr;
 ? ? ? ? ? ? ? ?u8 ? ? ?rxhubport;
 ? ? ? ?} tar[16];
-} __attribute__((aligned(32)));
+} __attribute__((packed, aligned(32)));
 
Quoted 4 lines

?/*
?* MUSB Register bits
--
1.6.5.5

Applied to u-boot-usb with merge conflicts, please review the merge changes at:
http://git.denx.de/?p=u-boot/u-boot-usb.git;a=commitdiff;h=b2178ae3c6770cb3313b10e4be2df91230b5b3c4

Thanks.

Remy

#10 lore raw

PATCH 1/5 usb: musb: make sure the register layout is packed

Quoted 4 lines · On Tuesday 22 December 2009 14:29:13 Remy Bohmer wrote:

Applied to u-boot-usb with merge conflicts, please review the merge changes
at:
http://git.denx.de/?p=u-boot/u-boot-usb.git;a=commitdiff;h=b2178ae3c6770cb
3313b10e4be2df91230b5b3c4

after a quick look at each of the merged patches, i didnt notice any issues -mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20091222/fe70c3fa/attachment.pgp