Skip to contentSkip to conversation

MX21 USB Host Support

PATCH New Martin Fuzzey 4 participants 10 messages Nov 8, 2009 – Nov 20, 2009

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

cover MX21 USB Host Support

This patch series adds support for the USB host controller in the Freescale i.MX21 SoC.

Only host mode (not function or OTG mode) is currently supported (the OTG port may be used in host only mode).

Power management is not yet implemented (as it has not yet been implemented for MXC).

The driver has been tested with usbtest suite and has run for several days with other simultaneous USB activity (webcam + mass storage).

The driver part is the same as that posted in June just rebased to 2.6.32-rc5

The changes to the platform resource part are:
* Clock patch dropped as now merged
* Let compiler count array indices in platform resources
* Use DMA_BIT_MASK

#1 lore raw

PATCH 1/3 MXC: Add i.MX21 specific USB host controller driver.

This driver is a Full / Low speed only USB host for the i.MX21.

---

 arch/arm/plat-mxc/include/mach/mx21-usbhost.h |   38 +
 drivers/usb/Makefile                          |    1 
 drivers/usb/host/Kconfig                      |   11 
 drivers/usb/host/Makefile                     |    2 
 drivers/usb/host/imx21-dbg.c                  |  527 +++++++
 drivers/usb/host/imx21-hcd.c                  | 1789 +++++++++++++++++++++++++
 drivers/usb/host/imx21-hcd.h                  |  436 ++++++
 7 files changed, 2804 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/plat-mxc/include/mach/mx21-usbhost.h
 create mode 100644 drivers/usb/host/imx21-dbg.c
 create mode 100644 drivers/usb/host/imx21-hcd.c
 create mode 100644 drivers/usb/host/imx21-hcd.h
arch/arm/plat-mxc/include/mach/mx21-usbhost.h new file +38 -0
new file mode 100644
index 0000000..22d0b59
@@ -0,0 +1,38 @@
+/*
+ *	Copyright (C) 2009 Martin Fuzzey <[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_ARCH_MX21_USBH
+#define __ASM_ARCH_MX21_USBH
+
+enum mx21_usbh_xcvr {
+	/* Values below as used by hardware (HWMODE register) */
+	MX21_USBXCVR_TXDIF_RXDIF = 0,
+	MX21_USBXCVR_TXDIF_RXSE = 1,
+	MX21_USBXCVR_TXSE_RXDIF = 2,
+	MX21_USBXCVR_TXSE_RXSE = 3,
+};
+
+struct mx21_usbh_platform_data {
+	enum mx21_usbh_xcvr host_xcvr; /* tranceiver mode host 1,2 ports */
+	enum mx21_usbh_xcvr otg_xcvr; /* tranceiver mode otg (as host) port */
+	u16 	enable_host1:1,
+		enable_host2:1,
+		enable_otg_host:1, /* enable "OTG" port (as host) */
+		host1_xcverless:1, /* traceiverless host1 port */
+		host1_txenoe:1, /* output enable host1 transmit enable */
+		otg_ext_xcvr:1, /* external tranceiver for OTG port */
+		unused:10;
+};
+
+#endif /* __ASM_ARCH_MX21_USBH */
drivers/usb/Makefile +1 -0
index be3c9b8..80b4008 100644
@@ -21,6 +21,7 @@ obj-$(CONFIG_USB_U132_HCD)	+= host/
 obj-$(CONFIG_USB_R8A66597_HCD)	+= host/
 obj-$(CONFIG_USB_HWA_HCD)	+= host/
 obj-$(CONFIG_USB_ISP1760_HCD)	+= host/
+obj-$(CONFIG_USB_IMX21_HCD)	+= host/
 
 obj-$(CONFIG_USB_C67X00_HCD)	+= c67x00/
 
drivers/usb/host/Kconfig +11 -0
index 9b43b22..fe2be81 100644
@@ -381,3 +381,14 @@ config USB_HWA_HCD
 
 	  To compile this driver a module, choose M here: the module
 	  will be called "hwa-hc".
+
+config USB_IMX21_HCD
+       tristate "iMX21 HCD support"
+       depends on USB && ARM && MACH_MX21
+       help
+         This driver enables support for the on-chip USB host in the
+         iMX21 processor.
+
+         To compile this driver as a module, choose M here: the
+         module will be called "imx21-hcd".
+
drivers/usb/host/Makefile +2 -0
index f58b249..4e0c67f 100644
@@ -32,3 +32,5 @@ obj-$(CONFIG_USB_U132_HCD)	+= u132-hcd.o
 obj-$(CONFIG_USB_R8A66597_HCD)	+= r8a66597-hcd.o
 obj-$(CONFIG_USB_ISP1760_HCD)	+= isp1760.o
 obj-$(CONFIG_USB_HWA_HCD)	+= hwa-hc.o
+obj-$(CONFIG_USB_IMX21_HCD)	+= imx21-hcd.o
+
drivers/usb/host/imx21-dbg.c new file +527 -0

527 lines not on this page · raw message

drivers/usb/host/imx21-hcd.c new file +1789 -0

1,789 lines not on this page · raw message

drivers/usb/host/imx21-hcd.h new file +436 -0

436 lines not on this page · raw message

#2 lore raw

PATCH 1/3 MXC: Add i.MX21 specific USB host controller driver.

Quoted 1 line · Martin Fuzzey

This driver is a Full / Low speed only USB host for the i.MX21.

I didn't notice anything objectionable here, but host controller drivers are not my speciality. If it's working for you, that is a good reason to get it in for wider testing.

thanks,

greg k-h

#3 lore raw

PATCH 1/3 MXC: Add i.MX21 specific USB host controller driver.

Quoted 4 lines · Greg KH

I didn't notice anything objectionable here, but host controller drivers are not my speciality. ?If it's working for you, that is a good reason to get it in for wider testing.

Yes it's working fine for me.

There have been no other comments on the driver part - do I need to do anything else to get it in?

If it's ok to repost just the platform resource bits with the couple of mods requested (spelling mistake and letting compiler count array indices) I'll just do that - seems stupid to repost the unmodified driver.

Cheers,

Martin

#4 lore raw

PATCH 1/3 MXC: Add i.MX21 specific USB host controller driver.

Quoted 8 lines · Martin Fuzzey
Quoted 4 lines · Greg KH

I didn't notice anything objectionable here, but host controller drivers are not my speciality. ?If it's working for you, that is a good reason to get it in for wider testing.

Yes it's working fine for me.

Quoted 7 lines

There have been no other comments on the driver part - do I need to do anything else to get it in?

If it's ok to repost just the platform resource bits with the couple of mods requested (spelling mistake and letting compiler count array indices) I'll just do that - seems stupid to repost the unmodified driver.

Please repost the whole thing, I don't have it in my queue anymore.

thanks,

greg k-h

#5 lore raw

PATCH 2/3 MXC: use DMA_BIT_MASK macro rather than hardcoded constants.

In reply to Martin Fuzzey

Also fixes tab/space issue causing checkpatch to compplain.

---

 arch/arm/mach-mx2/devices.c |   53 ++++++++++++++++++++++---------------------
 1 files changed, 27 insertions(+), 26 deletions(-)
arch/arm/mach-mx2/devices.c +27 -26
index 50199af..3522397 100644
@@ -31,6 +31,7 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/dma-mapping.h>
 
 #include <mach/irqs.h>
 #include <mach/hardware.h>
@@ -292,7 +293,7 @@ struct platform_device mxc_fb_device = {
 	.num_resources = ARRAY_SIZE(mxc_fb),
 	.resource = mxc_fb,
 	.dev = {
-		.coherent_dma_mask = 0xFFFFFFFF,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
 	},
 };
 
@@ -395,17 +396,17 @@ static struct resource mxc_sdhc1_resources[] = {
 	},
 };
 
-static u64 mxc_sdhc1_dmamask = 0xffffffffUL;
+static u64 mxc_sdhc1_dmamask = DMA_BIT_MASK(32);
 
 struct platform_device mxc_sdhc_device0 = {
-       .name           = "mxc-mmc",
-       .id             = 0,
-       .dev            = {
-               .dma_mask = &mxc_sdhc1_dmamask,
-               .coherent_dma_mask = 0xffffffff,
-       },
-       .num_resources  = ARRAY_SIZE(mxc_sdhc1_resources),
-       .resource       = mxc_sdhc1_resources,
+	.name           = "mxc-mmc",
+	.id             = 0,
+	.dev            = {
+		.dma_mask = &mxc_sdhc1_dmamask,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
+	},
+	.num_resources  = ARRAY_SIZE(mxc_sdhc1_resources),
+	.resource       = mxc_sdhc1_resources,
 };
 
 static struct resource mxc_sdhc2_resources[] = {
@@ -424,17 +425,17 @@ static struct resource mxc_sdhc2_resources[] = {
 	},
 };
 
-static u64 mxc_sdhc2_dmamask = 0xffffffffUL;
+static u64 mxc_sdhc2_dmamask = DMA_BIT_MASK(32);
 
 struct platform_device mxc_sdhc_device1 = {
-       .name           = "mxc-mmc",
-       .id             = 1,
-       .dev            = {
-               .dma_mask = &mxc_sdhc2_dmamask,
-               .coherent_dma_mask = 0xffffffff,
-       },
-       .num_resources  = ARRAY_SIZE(mxc_sdhc2_resources),
-       .resource       = mxc_sdhc2_resources,
+	.name           = "mxc-mmc",
+	.id             = 1,
+	.dev            = {
+		.dma_mask = &mxc_sdhc2_dmamask,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
+	},
+	.num_resources  = ARRAY_SIZE(mxc_sdhc2_resources),
+	.resource       = mxc_sdhc2_resources,
 };
 
 #ifdef CONFIG_MACH_MX27
@@ -450,7 +451,7 @@ static struct resource otg_resources[] = {
 	},
 };
 
-static u64 otg_dmamask = 0xffffffffUL;
+static u64 otg_dmamask = DMA_BIT_MASK(32);
 
 /* OTG gadget device */
 struct platform_device mxc_otg_udc_device = {
@@ -458,7 +459,7 @@ struct platform_device mxc_otg_udc_device = {
 	.id		= -1,
 	.dev		= {
 		.dma_mask		= &otg_dmamask,
-		.coherent_dma_mask	= 0xffffffffUL,
+		.coherent_dma_mask	= DMA_BIT_MASK(32),
 	},
 	.resource	= otg_resources,
 	.num_resources	= ARRAY_SIZE(otg_resources),
@@ -469,7 +470,7 @@ struct platform_device mxc_otg_host = {
 	.name = "mxc-ehci",
 	.id = 0,
 	.dev = {
-		.coherent_dma_mask = 0xffffffff,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
 		.dma_mask = &otg_dmamask,
 	},
 	.resource = otg_resources,
@@ -478,7 +479,7 @@ struct platform_device mxc_otg_host = {
 
 /* USB host 1 */
 
-static u64 usbh1_dmamask = 0xffffffffUL;
+static u64 usbh1_dmamask = DMA_BIT_MASK(32);
 
 static struct resource mxc_usbh1_resources[] = {
 	{
@@ -496,7 +497,7 @@ struct platform_device mxc_usbh1 = {
 	.name = "mxc-ehci",
 	.id = 1,
 	.dev = {
-		.coherent_dma_mask = 0xffffffff,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
 		.dma_mask = &usbh1_dmamask,
 	},
 	.resource = mxc_usbh1_resources,
@@ -504,7 +505,7 @@ struct platform_device mxc_usbh1 = {
 };
 
 /* USB host 2 */
-static u64 usbh2_dmamask = 0xffffffffUL;
+static u64 usbh2_dmamask = DMA_BIT_MASK(32);
 
 static struct resource mxc_usbh2_resources[] = {
 	{
@@ -522,7 +523,7 @@ struct platform_device mxc_usbh2 = {
 	.name = "mxc-ehci",
 	.id = 2,
 	.dev = {
-		.coherent_dma_mask = 0xffffffff,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
 		.dma_mask = &usbh2_dmamask,
 	},
 	.resource = mxc_usbh2_resources,
#6 lore raw

PATCH 2/3 MXC: use DMA_BIT_MASK macro rather than hardcoded constants.

Quoted 1 line · Martin Fuzzey

Also fixes tab/space issue causing checkpatch to compplain.

s/pp/p/

(Note this doesn't imply an Acked-by me when you fix it. I don't have enough expertise in this area, it's just what I noticed by a quick glimpse.)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                              | Uwe Kleine-K?nig            |
Industrial Linux Solutions                    | http://www.pengutronix.de/  |
#7 lore raw

PATCH 3/3 MXC: add platform resources for i.MX21 USB host controller.

In reply to Martin Fuzzey

---

 arch/arm/mach-mx2/devices.c |   27 +++++++++++++++++++++++++++
 arch/arm/mach-mx2/devices.h |    1 +
 2 files changed, 28 insertions(+), 0 deletions(-)
arch/arm/mach-mx2/devices.c +27 -0
index 3522397..4e6f5a0 100644
@@ -565,3 +565,30 @@ int __init mxc_register_gpios(void)
 {
 	return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
 }
+
+#ifdef CONFIG_MACH_MX21
+static struct resource mx21_usbhc_resources[] = {
+	[0] = {
+		.start	= USBOTG_BASE_ADDR,
+		.end	= USBOTG_BASE_ADDR + 0x1FFF,
+		.flags	= IORESOURCE_MEM,
+	},
+	[1] = {
+		.start		= MXC_INT_USBHOST,
+		.end		= MXC_INT_USBHOST,
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+
+struct platform_device mx21_usbhc_device = {
+	.name		= "imx21-hcd",
+	.id		= 0,
+	.dev		= {
+		.dma_mask = &mx21_usbhc_device.dev.coherent_dma_mask,
+		.coherent_dma_mask = DMA_BIT_MASK(32),
+	},
+	.num_resources	= ARRAY_SIZE(mx21_usbhc_resources),
+	.resource	= mx21_usbhc_resources,
+};
+#endif
+
arch/arm/mach-mx2/devices.h +1 -0
index d315406..f3b4d8b 100644
@@ -26,4 +26,5 @@ extern struct platform_device mxc_usbh2;
 extern struct platform_device mxc_spi_device0;
 extern struct platform_device mxc_spi_device1;
 extern struct platform_device mxc_spi_device2;
+extern struct platform_device mx21_usbhc_device;
 
#8 lore raw

PATCH 3/3 MXC: add platform resources for i.MX21 USB host controller.

Martin,

Quoted 41 lines · Martin Fuzzey

From: Martin Fuzzey <[email protected]>
Subject: [REPOST PATCH 3/3] MXC: add platform resources for i.MX21 USB host controller.
To: "Greg KH" <[email protected]>, "Sascha Hauer" <[email protected]>
Cc: linux-usb at vger.kernel.org, linux-arm-kernel at lists.infradead.org
Date: Sunday, November 8, 2009, 4:52 PM

---

arch/arm/mach-mx2/devices.c |???27
+++++++++++++++++++++++++++
arch/arm/mach-mx2/devices.h |? ? 1 +

 2 files changed, 28 insertions(+), 0 deletions(-)
arch/arm/mach-mx2/devices.c +5 -0
index 3522397..4e6f5a0 100644
@@ -565,3 +565,30 @@ int __init mxc_register_gpios(void)
 {
 ??? return mxc_gpio_init(imx_gpio_ports,
 ARRAY_SIZE(imx_gpio_ports));
 }
+
+#ifdef CONFIG_MACH_MX21
+static struct resource mx21_usbhc_resources[] = {
+??? [0] = {
+??? ???

.start??? = USBOTG_BASE_ADDR,
+??? ???
.end??? = USBOTG_BASE_ADDR + 0x1FFF,
+??? ???
.flags??? = IORESOURCE_MEM,
+??? },
+??? [1] = {
+??? ???
.start??? ??? =
MXC_INT_USBHOST,

Quoted 8 lines

+??? ???
.end??? ??? =
MXC_INT_USBHOST,
+??? ???
.flags??? ??? =
IORESOURCE_IRQ,
+??? },
+};

Shouldn't you let the compiler count the array?

Regards,

Fabio Estevam

#9 lore raw

PATCH 3/3 MXC: add platform resources for i.MX21 USB host controller.

Quoted 2 lines · Fabio Estevam

Shouldn't you let the compiler count the array?

Grr yes thank you - I had changed it then messed something up in my patch stack.

Fixed now but I'll wait for feedback on the driver part before resending.

Martin