Skip to contentSkip to conversation

USB: atmel: add atmel usba udc driver support

PATCH New Bo Shen 2 participants 6 messages Sep 11, 2013

Subsystems (3)
lore
Share & tools
lore

Bo Shen

author
#0 lore raw

v3 cover USB: atmel: add atmel usba udc driver support

Add atmel usb udc driver support porting from Linux kernel. Using RNDIS gadget driver to test it.

Test OK on at91sam9m10g45ek, at91sam9m10g45ek, and sama5d31ek boards.

It need the patch from: Troy Kisky <[email protected]> (usb: gadget: config: fix unaligned access issues)
more information: http://patchwork.ozlabs.org/patch/264151/

Changes in v3:
- Add new (resubmit) one patch from Troy Kisky
- Move common header file along with USB device driver

Changes in v2:
- Add detail information of the orignal code
- Add a common header to hold atmel usba udc information for different SoCs

Bo Shen (3):
USB: gadget: add atmel usba udc driver
ARM: atmel: correct UDPHS name
ARM: atmel: add RNDIS gadget support

Troy Kisky (1):
usb: gadget: config: fix unaligned access issues

 arch/arm/cpu/armv7/at91/sama5d3_devices.c       |   12 +
 arch/arm/include/asm/arch-at91/at91_common.h    |    1 +
 arch/arm/include/asm/arch-at91/atmel_usba_udc.h |   64 ++
 arch/arm/include/asm/arch-at91/sama5d3.h        |    2 +-
 board/atmel/sama5d3xek/sama5d3xek.c             |   13 +
 drivers/usb/gadget/Makefile                     |    1 +
 drivers/usb/gadget/atmel_usba_udc.c             | 1305 +++++++++++++++++++++++
 drivers/usb/gadget/atmel_usba_udc.h             |  326 ++++++
 drivers/usb/gadget/config.c                     |    6 +-
 include/configs/sama5d3xek.h                    |    8 +
 include/linux/usb/atmel_usba_udc.h              |   26 +
 11 files changed, 1761 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-at91/atmel_usba_udc.h
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.h
 create mode 100644 include/linux/usb/atmel_usba_udc.h
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v3 1/4 usb: gadget: config: fix unaligned access issues

From: Troy Kisky <[email protected]>

As seen with codesourcery compiler 2010q1, the buf pointer in usb_request structure is not aligned on 4 bytes boundary causing data aborts in eth_setup -> conf_buf -> usb_gadget_config_buf. Make it as align access to fix this issue.

[voice.shen at atmel.com: add commit message]

---
Changes in v3:
- New

 drivers/usb/gadget/config.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/usb/gadget/config.c +4 -2
index f563afe..014a679 100644
@@ -10,6 +10,7 @@
  */
 
 #include <common.h>
+#include <asm/unaligned.h>
 #include <asm/errno.h>
 #include <linux/list.h>
 #include <linux/string.h>
@@ -86,7 +87,8 @@ int usb_gadget_config_buf(
 	/* config descriptor first */
 	if (length < USB_DT_CONFIG_SIZE || !desc)
 		return -EINVAL;
-	*cp = *config;
+	/* config need not be aligned */
+	memcpy(cp, config, sizeof(*cp));
 
 	/* then interface/endpoint/class/vendor/... */
 	len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8 *)buf,
@@ -100,7 +102,7 @@ int usb_gadget_config_buf(
 	/* patch up the config descriptor */
 	cp->bLength = USB_DT_CONFIG_SIZE;
 	cp->bDescriptorType = USB_DT_CONFIG;
-	cp->wTotalLength = cpu_to_le16(len);
+	put_unaligned_le16(len, &cp->wTotalLength);
 	cp->bmAttributes |= USB_CONFIG_ATT_ONE;
 	return len;
 }
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v3 2/4 USB: gadget: add atmel usba udc driver

In reply to Bo Shen

Add atmel usba udc driver support, porting from Linux kernel

The original code in Linux Kernel information is as following

commit e01ee9f509a927158f670408b41127d4166db1c7

Author: Jingoo Han <[email protected]>
Date:   Tue Jul 30 17:00:51 2013 +0900

usb: gadget: use dev_get_platdata()

Use the wrapper function for retrieving the platform data instead of accessing dev->platform_data directly.

---
Changes in v3:
- Move USB device endpoint info header file in this patch
Changes in v2:
- None

---
 arch/arm/include/asm/arch-at91/atmel_usba_udc.h |   64 ++
 drivers/usb/gadget/Makefile                     |    1 +
 drivers/usb/gadget/atmel_usba_udc.c             | 1305 +++++++++++++++++++++++
 drivers/usb/gadget/atmel_usba_udc.h             |  326 ++++++
 include/linux/usb/atmel_usba_udc.h              |   26 +
 5 files changed, 1722 insertions(+)
 create mode 100644 arch/arm/include/asm/arch-at91/atmel_usba_udc.h
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.h
 create mode 100644 include/linux/usb/atmel_usba_udc.h
arch/arm/include/asm/arch-at91/atmel_usba_udc.h new file +64 -0
new file mode 100644
index 0000000..6f540d2
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2005-2013 Atmel Corporation
+ *			   Bo Shen <[email protected]>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef __ATMEL_USBA_UDC_H__
+#define __ATMEL_USBA_UDC_H__
+
+#include <linux/usb/atmel_usba_udc.h>
+
+#define EP(nam, idx, maxpkt, maxbk, dma, isoc)		\
+	[idx] = {					\
+		.name	= nam,				\
+		.index	= idx,				\
+		.fifo_size	= maxpkt,		\
+		.nr_banks	= maxbk,		\
+		.can_dma	= dma,			\
+		.can_isoc	= isoc,			\
+	}
+
+#if defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45) || \
+	defined(CONFIG_AT91SAM9X5)
+static struct usba_ep_data usba_udc_ep[] = {
+	EP("ep0", 0, 64, 1, 0, 0),
+	EP("ep1", 1, 1024, 2, 1, 1),
+	EP("ep2", 2, 1024, 2, 1, 1),
+	EP("ep3", 3, 1024, 3, 1, 0),
+	EP("ep4", 4, 1024, 3, 1, 0),
+	EP("ep5", 5, 1024, 3, 1, 1),
+	EP("ep6", 6, 1024, 3, 1, 1),
+};
+#elif defined(CONFIG_SAMA5D3)
+static struct usba_ep_data usba_udc_ep[] = {
+	EP("ep0", 0, 64, 1, 0, 0),
+	EP("ep1", 1, 1024, 3, 1, 0),
+	EP("ep2", 2, 1024, 3, 1, 0),
+	EP("ep3", 3, 1024, 2, 1, 0),
+	EP("ep4", 4, 1024, 2, 1, 0),
+	EP("ep5", 5, 1024, 2, 1, 0),
+	EP("ep6", 6, 1024, 2, 1, 0),
+	EP("ep7", 7, 1024, 2, 1, 0),
+	EP("ep8", 8, 1024, 2, 0, 0),
+	EP("ep9", 9, 1024, 2, 0, 0),
+	EP("ep10", 10, 1024, 2, 0, 0),
+	EP("ep11", 11, 1024, 2, 0, 0),
+	EP("ep12", 12, 1024, 2, 0, 0),
+	EP("ep13", 13, 1024, 2, 0, 0),
+	EP("ep14", 14, 1024, 2, 0, 0),
+	EP("ep15", 15, 1024, 2, 0, 0),
+};
+#else
+# error "NO usba_udc_ep defined"
+#endif
+
+#undef EP
+
+struct usba_platform_data pdata = {
+	.num_ep	= ARRAY_SIZE(usba_udc_ep),
+	.ep	= usba_udc_ep,
+};
+
+#endif
drivers/usb/gadget/Makefile +1 -0
index 4c2a39a..4d51f59 100644
@@ -18,6 +18,7 @@ endif
 
 # new USB gadget layer dependencies
 ifdef CONFIG_USB_GADGET
+COBJS-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 COBJS-$(CONFIG_USB_GADGET_S3C_UDC_OTG) += s3c_udc_otg.o
 COBJS-$(CONFIG_USB_GADGET_FOTG210) += fotg210.o
 COBJS-$(CONFIG_USBDOWNLOAD_GADGET) += g_dnl.o
drivers/usb/gadget/atmel_usba_udc.c new file +1305 -0

1,305 lines not on this page · raw message

drivers/usb/gadget/atmel_usba_udc.h new file +326 -0

326 lines not on this page · raw message

include/linux/usb/atmel_usba_udc.h new file +26 -0
new file mode 100644
index 0000000..be29ef0
@@ -0,0 +1,26 @@
+/*
+ * Platform data definitions for Atmel USBA gadget driver
+ * [Original from Linux kernel: include/linux/usb/atmel_usba_udc.h]
+ *
+ * SPDX-License-Identifier:     GPL-2.0+
+ */
+#ifndef __LINUX_USB_USBA_H__
+#define __LINUX_USB_USBA_H__
+
+struct usba_ep_data {
+	char *name;
+	int index;
+	int fifo_size;
+	int nr_banks;
+	int can_dma;
+	int can_isoc;
+};
+
+struct usba_platform_data {
+	int			num_ep;
+	struct usba_ep_data	*ep;
+};
+
+extern int usba_udc_probe(struct usba_platform_data *pdata);
+
+#endif /* __LINUX_USB_USBA_H */
Signature · 1 line
1.7.9.5
author
#3 lore raw

PATCH v3 3/4 ARM: atmel: correct UDPHS name

In reply to Bo Shen

Correct the UDPHS name from UDHPS

---
Changes in v3:
- Add Acked-by from Marek Vasut
Changes in v2:
- None

 arch/arm/include/asm/arch-at91/sama5d3.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/include/asm/arch-at91/sama5d3.h +1 -1
index fefee5e..123a627 100644
@@ -120,7 +120,7 @@
 #define ATMEL_BASE_USART3	0xf8024000
 #define ATMEL_BASE_UART1	0xf8028000
 #define ATMEL_BASE_EMAC		0xf802c000
-#define ATMEL_BASE_UDHPS	0xf8030000
+#define ATMEL_BASE_UDPHS	0xf8030000
 #define ATMEL_BASE_SHA		0xf8034000
 #define ATMEL_BASE_AES		0xf8038000
 #define ATMEL_BASE_TDES		0xf803c000
Signature · 1 line
1.7.9.5
author
#4 lore raw

PATCH v3 4/4 ARM: atmel: add RNDIS gadget support

In reply to Bo Shen

Add RNDIS gadget support to test atmel usba udc driver

---
Changes in v3:
- Move this header file along with USB device driver patch
Changes in v2:
- Add a common header to hold atmel usba udc information for different SoCs

---
 arch/arm/cpu/armv7/at91/sama5d3_devices.c    |   12 ++++++++++++
 arch/arm/include/asm/arch-at91/at91_common.h |    1 +
 board/atmel/sama5d3xek/sama5d3xek.c          |   13 +++++++++++++
 include/configs/sama5d3xek.h                 |    8 ++++++++
 4 files changed, 34 insertions(+)
arch/arm/cpu/armv7/at91/sama5d3_devices.c +12 -0
index e55e1c6..51f0a6d 100644
@@ -202,3 +202,15 @@ void at91_lcd_hw_init(void)
 	at91_periph_clk_enable(ATMEL_ID_LCDC);
 }
 #endif
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+void at91_udp_hw_init(void)
+{
+	struct at91_pmc *pmc = (struct at91_pmc *)ATMEL_BASE_PMC;
+
+	/* Enable UPLL clock */
+	writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
+	/* Enable UDPHS clock */
+	at91_periph_clk_enable(ATMEL_ID_UDPHS);
+}
+#endif
arch/arm/include/asm/arch-at91/at91_common.h +1 -0
index 9f54fdd..abcb97d 100644
@@ -19,6 +19,7 @@ void at91_serial2_hw_init(void);
 void at91_seriald_hw_init(void);
 void at91_spi0_hw_init(unsigned long cs_mask);
 void at91_spi1_hw_init(unsigned long cs_mask);
+void at91_udp_hw_init(void);
 void at91_uhp_hw_init(void);
 void at91_lcd_hw_init(void);
 
board/atmel/sama5d3xek/sama5d3xek.c +13 -0
index 97caf64..b0965ef 100644
@@ -21,6 +21,10 @@
 #include <net.h>
 #include <netdev.h>
 
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+#include <asm/arch/atmel_usba_udc.h>
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
 /* ------------------------------------------------------------------------- */
@@ -170,6 +174,9 @@ int board_init(void)
 #ifdef CONFIG_CMD_USB
 	sama5d3xek_usb_hw_init();
 #endif
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+	at91_udp_hw_init();
+#endif
 #ifdef CONFIG_GENERIC_ATMEL_MCI
 	sama5d3xek_mci_hw_init();
 #endif
@@ -221,6 +228,12 @@ int board_eth_init(bd_t *bis)
 	if (has_gmac())
 		rc = macb_eth_initialize(0, (void *)ATMEL_BASE_GMAC, 0x00);
 #endif
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+	usba_udc_probe(&pdata);
+#ifdef CONFIG_USB_ETH_RNDIS
+	usb_eth_initialize(bis);
+#endif
+#endif
 
 	return rc;
 }
include/configs/sama5d3xek.h +8 -0
index 76fa500..79c0068 100644
@@ -162,6 +162,14 @@
 #define CONFIG_USB_STORAGE
 #endif
 
+/* USB device */
+#define CONFIG_USB_GADGET
+#define CONFIG_USB_GADGET_DUALSPEED
+#define CONFIG_USB_GADGET_ATMEL_USBA
+#define CONFIG_USB_ETHER
+#define CONFIG_USB_ETH_RNDIS
+#define CONFIG_USBNET_MANUFACTURER      "Atmel SAMA5D3xEK"
+
 #if defined(CONFIG_CMD_USB) || defined(CONFIG_CMD_MMC)
 #define CONFIG_CMD_FAT
 #endif
Signature · 1 line
1.7.9.5
Applied
#5 lore raw

v3 cover USB: atmel: add atmel usba udc driver support

In reply to Bo Shen

Dear Bo Shen,

Quoted 18 lines

Add atmel usb udc driver support porting from Linux kernel. Using RNDIS gadget driver to test it.

Test OK on at91sam9m10g45ek, at91sam9m10g45ek, and sama5d31ek boards.

It need the patch from: Troy Kisky <[email protected]> (usb: gadget: config: fix unaligned access issues)
more information: http://patchwork.ozlabs.org/patch/264151/

Changes in v3:
- Add new (resubmit) one patch from Troy Kisky
- Move common header file along with USB device driver

Changes in v2:
- Add detail information of the orignal code
- Add a common header to hold atmel usba udc information for different SoCs

Quoted 7 lines

Bo Shen (3):
USB: gadget: add atmel usba udc driver
ARM: atmel: correct UDPHS name
ARM: atmel: add RNDIS gadget support

Troy Kisky (1):
usb: gadget: config: fix unaligned access issues

Applied all, thanks

Best regards,
Marek Vasut