Skip to contentSkip to conversation

Integrate USB gadget layer and USB CDC driver layer

PATCH New Remy Bohmer 3 participants 14 messages Aug 12, 2010 – Aug 13, 2010

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

PATCH 1/3 Integrate USB gadget layer and USB CDC driver layer

Derived from Linux kernel 2.6.27

---
 drivers/usb/gadget/Makefile       |    3 +
 drivers/usb/gadget/config.c       |  119 +++
 drivers/usb/gadget/epautoconf.c   |  306 ++++++
 drivers/usb/gadget/ether.c        | 1947 +++++++++++++++++++++++++++++++++++++
 drivers/usb/gadget/gadget_chips.h |  219 +++++
 drivers/usb/gadget/usbstring.c    |  134 +++
 include/linux/usb/cdc.h           |  224 +++++
 include/linux/usb/ch9.h           |  587 +++++++++++
 include/linux/usb/gadget.h        |  871 +++++++++++++++++
 include/net.h                     |   17 +-
 10 files changed, 4425 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/gadget/config.c
 create mode 100644 drivers/usb/gadget/epautoconf.c
 create mode 100644 drivers/usb/gadget/ether.c
 create mode 100644 drivers/usb/gadget/gadget_chips.h
 create mode 100644 drivers/usb/gadget/usbstring.c
 create mode 100644 include/linux/usb/cdc.h
 create mode 100644 include/linux/usb/ch9.h
 create mode 100644 include/linux/usb/gadget.h
drivers/usb/gadget/Makefile +3 -0
index 1d7362d..9b1b55b 100644
@@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk
 
 LIB	:= $(obj)libusb_gadget.a
 
+# Devices not related to the new gadget layer depend on CONFIG_USB_DEVICE
 ifdef CONFIG_USB_DEVICE
 COBJS-y += core.o
 COBJS-y += ep0.o
@@ -34,6 +35,8 @@ COBJS-$(CONFIG_MPC885_FAMILY) += mpc8xx_udc.o
 COBJS-$(CONFIG_PXA27X) += pxa27x_udc.o
 COBJS-$(CONFIG_SPEARUDC) += spr_udc.o
 endif
+# new USB gadget layer dependencies
+COBJS-$(CONFIG_USB_ETHER) += ether.o epautoconf.o config.o usbstring.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/usb/gadget/config.c new file +119 -0

119 lines not on this page · raw message

drivers/usb/gadget/epautoconf.c new file +306 -0

306 lines not on this page · raw message

drivers/usb/gadget/ether.c new file +1947 -0

1,947 lines not on this page · raw message

drivers/usb/gadget/gadget_chips.h new file +219 -0

219 lines not on this page · raw message

drivers/usb/gadget/usbstring.c new file +134 -0

134 lines not on this page · raw message

include/linux/usb/cdc.h new file +224 -0

224 lines not on this page · raw message

include/linux/usb/ch9.h new file +587 -0

36 lines not on this page · raw message

include/linux/usb/gadget.h new file +871 -0

871 lines not on this page · raw message

include/net.h +15 -2
index ab571eb..a29dafc 100644

Lines of this file are not shown. View the raw message.

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

Signature · 1 line
1.7.0.4

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

#1 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

This patch implements the low-level part of the USB CDC layer for AT91 Other boards can use this patch as an example to connect their own.

It does not enable the use of CDC ethernet for any of the AT91 boards. Separate patches are required for that.
It works in combination with CONFIG_NET_MULTI.

---
 arch/arm/include/asm/arch-at91/at91_dbgu.h |   69 ++
 arch/arm/include/asm/arch-at91/cpu.h       |   99 ++
 drivers/usb/gadget/Makefile                |    1 +
 drivers/usb/gadget/at91_udc.c              | 1553 ++++++++++++++++++++++++++++
 include/usb/at91_udc.h                     |  209 ++++
 5 files changed, 1931 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-at91/at91_dbgu.h
 create mode 100644 arch/arm/include/asm/arch-at91/cpu.h
 create mode 100644 drivers/usb/gadget/at91_udc.c
 create mode 100644 include/usb/at91_udc.h
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +69 -0
new file mode 100644
index 0000000..55210da
@@ -0,0 +1,69 @@
+/*
+ * include/asm-arm/arch-at91/at91_dbgu.h
+ *
+ * Copyright (C) 2005 Ivan Kokshaysky
+ * Copyright (C) SAN People
+ *
+ * Debug Unit (DBGU) - System peripherals registers.
+ * Based on AT91RM9200 datasheet revision E.
+ *
+ * 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.
+ */
+
+#ifndef AT91_DBGU_H
+#define AT91_DBGU_H
+
+#ifdef AT91_DBGU
+#define AT91_DBGU_CR		(AT91_DBGU + 0x00) /* Control Register */
+#define AT91_DBGU_MR		(AT91_DBGU + 0x04) /* Mode Register */
+#define AT91_DBGU_IER		(AT91_DBGU + 0x08) /* Interrupt Enable */
+#define		AT91_DBGU_TXRDY		(1 << 1)   /* Transmitter Ready */
+#define		AT91_DBGU_TXEMPTY	(1 << 9)   /* Transmitter Empty */
+#define AT91_DBGU_IDR		(AT91_DBGU + 0x0c) /* Interrupt Disable */
+#define AT91_DBGU_IMR		(AT91_DBGU + 0x10) /* Interrupt Mask */
+#define AT91_DBGU_SR		(AT91_DBGU + 0x14) /* Status Register */
+#define AT91_DBGU_RHR		(AT91_DBGU + 0x18) /* Receiver Holding */
+#define AT91_DBGU_THR		(AT91_DBGU + 0x1c) /* Transmitter Holding */
+#define AT91_DBGU_BRGR		(AT91_DBGU + 0x20) /* Baud Rate Generator */
+
+#define AT91_DBGU_CIDR		(AT91_DBGU + 0x40) /* Chip ID Register */
+#define AT91_DBGU_EXID		(AT91_DBGU + 0x44) /* Chip ID Extension */
+#define AT91_DBGU_FNR		(AT91_DBGU + 0x48) /* Force NTRST [SAM9 only] */
+#define		AT91_DBGU_FNTRST	(1 << 0)   /* Force NTRST */
+
+#endif /* AT91_DBGU */
+
+/*
+ * Some AT91 parts that don't have full DEBUG units still support the ID
+ * and extensions register.
+ */
+#define		AT91_CIDR_VERSION	(0x1f << 0) /* Version of the Device */
+#define		AT91_CIDR_EPROC		(7    << 5) /* Embedded Processor */
+#define		AT91_CIDR_NVPSIZ	(0xf  << 8) /* Nonvolatile Program
+						       Memory Size */
+#define		AT91_CIDR_NVPSIZ2	(0xf  << 12) /* Second Nonvolatile
+							Program Memory Size */
+#define		AT91_CIDR_SRAMSIZ	(0xf  << 16)	/* Internal SRAM Size */
+#define			AT91_CIDR_SRAMSIZ_1K	(1 << 16)
+#define			AT91_CIDR_SRAMSIZ_2K	(2 << 16)
+#define			AT91_CIDR_SRAMSIZ_112K	(4 << 16)
+#define			AT91_CIDR_SRAMSIZ_4K	(5 << 16)
+#define			AT91_CIDR_SRAMSIZ_80K	(6 << 16)
+#define			AT91_CIDR_SRAMSIZ_160K	(7 << 16)
+#define			AT91_CIDR_SRAMSIZ_8K	(8 << 16)
+#define			AT91_CIDR_SRAMSIZ_16K	(9 << 16)
+#define			AT91_CIDR_SRAMSIZ_32K	(10 << 16)
+#define			AT91_CIDR_SRAMSIZ_64K	(11 << 16)
+#define			AT91_CIDR_SRAMSIZ_128K	(12 << 16)
+#define			AT91_CIDR_SRAMSIZ_256K	(13 << 16)
+#define			AT91_CIDR_SRAMSIZ_96K	(14 << 16)
+#define			AT91_CIDR_SRAMSIZ_512K	(15 << 16)
+#define		AT91_CIDR_ARCH		(0xff << 20) /* Architecture Id */
+#define		AT91_CIDR_NVPTYP	(7    << 28) /* Nonvolatile Program
+							Memory Type */
+#define		AT91_CIDR_EXT		(1    << 31)	/* Extension Flag */
+
+#endif
arch/arm/include/asm/arch-at91/cpu.h new file +99 -0

99 lines not on this page · raw message

drivers/usb/gadget/Makefile +1 -0
index 9b1b55b..27e7f40 100644
@@ -37,6 +37,7 @@ COBJS-$(CONFIG_SPEARUDC) += spr_udc.o
 endif
 # new USB gadget layer dependencies
 COBJS-$(CONFIG_USB_ETHER) += ether.o epautoconf.o config.o usbstring.o
+COBJS-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
 
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
drivers/usb/gadget/at91_udc.c new file +1553 -0

1,553 lines not on this page · raw message

include/usb/at91_udc.h new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

arch/arm/include/asm/arch-at91/at91_dbgu.h

Quoted 4 lines

This patch implements the low-level part of the USB CDC layer for AT91 Other boards can use this patch as an example to connect their own.

arch/arm/include/asm/arch-at91/at91_dbgu.h new file +0 -0
new file mode 100644

Please see my patch introducing at91_dbgu.h (4/5.July 2010)

arch/arm/include/asm/arch-at91/at91_dbgu.h line 22

Quoted 3 lines
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +3 -0
+#define AT91_DBGU_CR		(AT91_DBGU + 0x00) /* Control Register */
+#define AT91_DBGU_MR		(AT91_DBGU + 0x04) /* Mode Register */
+#define AT91_DBGU_IER		(AT91_DBGU + 0x08) /* Interrupt Enable */

Use struct access for SoC registers. Offset adressing is depreciated. See the struct in my at91_dbgu.h. Use readl/writel to access the hardware.

arch/arm/include/asm/arch-at91/at91_dbgu.h line 24

Quoted 2 lines
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +2 -0
+#define		AT91_DBGU_TXRDY		(1 << 1)   /* Transmitter Ready */
+#define		AT91_DBGU_TXEMPTY	(1 << 9)   /* Transmitter Empty */

Don't define this here, UART handling is in drivers/serial/atmel_usart.? The first 9 registers in the DBGU are identical to the normal USARTS.

arch/arm/include/asm/arch-at91/at91_dbgu.h line 54

Quoted 5 lines
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +5 -0
+#define			AT91_CIDR_SRAMSIZ_1K	(1 << 16)
+#define			AT91_CIDR_SRAMSIZ_2K	(2 << 16)
+#define			AT91_CIDR_SRAMSIZ_112K	(4 << 16)
+#define			AT91_CIDR_SRAMSIZ_4K	(5 << 16)
+#define			AT91_CIDR_SRAMSIZ_80K	(6 << 16)

I think we should not define stuff that is nowhere used, and if one space or tab will do.

Quoted 2 lines
arch/arm/include/asm/arch-at91/cpu.h new file +0 -0
new file mode 100644

<snip>

arch/arm/include/asm/arch-at91/cpu.h line 18

Quoted 3 lines
arch/arm/include/asm/arch-at91/cpu.h new file +3 -0
+#include <asm/hardware.h>
+#include <asm/arch/at91_dbgu.h>
+#include <asm/arch/io.h>

Don't include other header files at this point. If a c source requires both DBGU and CPU headers, it shall include both.

<snip>

arch/arm/include/asm/arch-at91/cpu.h line 26

Quoted 6 lines
arch/arm/include/asm/arch-at91/cpu.h new file +6 -0
+#define ARCH_ID_AT91RM9200	0x09290780
+#define ARCH_ID_AT91SAM9260	0x019803a0
+#define ARCH_ID_AT91SAM9261	0x019703a0
+#define ARCH_ID_AT91SAM9263	0x019607a0
+#define ARCH_ID_AT91SAM9RL64	0x019b03a0
+#define ARCH_ID_AT91CAP9	0x039A03A0

Nice to have, but determining at runtime which variant we are on makes only sense to me for pin-compatible variants, e.g. 9260, 9xe, 9g20. Then you will notice that their hardware is not different much, if at all.
Non pin-compatible variants are #defined in their board specific header file. Use #ifdef in the source to handle necessary variant specific stuff...

<snip>

arch/arm/include/asm/arch-at91/cpu.h

Quoted 3 lines
arch/arm/include/asm/arch-at91/cpu.h new file +3 -0
+//#define DEBUG 1
+//#define VERBOSE 1
+//#define PACKET_TRACE 1

NO C++ comments allowed. And no commented away defines in general. Maybe say it like this:
/*
* to switch on debug output define any of those:
* DEBUG - general debug
* VERBOSE - more debug
* PACKET_TRACE - also print packets
*/
wherever possible use the debug() macro defines in common.h

Quoted 3 lines

+ * This driver expects the board has been wired with two GPIOs suppporting
+ * a VBUS sensing IRQ, and a D+ pullup. (They may be omitted, but the
+ * testing hasn't covered such cases.)

It should. Besides AT91 currently cannot handle IRQs. Also I think it should read D- pullup.

<snip>

arch/arm/include/asm/arch-at91/cpu.h

Quoted 1 line
arch/arm/include/asm/arch-at91/cpu.h new file +1 -0
+		hang();

Does this mean the system is dead and would need a watchdog or reset button to come alive again?

<snip>

arch/arm/include/asm/arch-at91/cpu.h

Quoted 1 line
arch/arm/include/asm/arch-at91/cpu.h new file +1 -0
+	// terminer chaque requete dans la queue

C++ comment in unknown language ;)?

<snip>

Quoted 3 lines

+/* TODO:
+ * BUG_ON(!list_empty(&req->queue));
+ * kfree(req); */

Wrong multi line comment.

<snip>

Quoted 1 line

+static void pullup(struct at91_udc *udc, int is_on)

<snip>

I suggest to define and use a weak function to dummy on/off the pullup.
Board specific source can implement a function then to really switch on/off a pullup in whatever way the hardware has provided that. That need not necessarily be a GPIO pin...

arch/arm/include/asm/arch-at91/cpu.h

Quoted 13 lines
arch/arm/include/asm/arch-at91/cpu.h new file +13 -0
+		if (cpu_is_at91rm9200())
+			at91_set_gpio_value(udc->board.pullup_pin, 1);
+		else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
+			u32	txvc = at91_udp_read(udc, AT91_UDP_TXVC);
+
+			txvc |= AT91_UDP_TXVC_PUON;
+			at91_udp_write(udc, AT91_UDP_TXVC, txvc);
+		} else if (cpu_is_at91sam9261()) {
+			u32	usbpucr;
+
+			usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
+			usbpucr |= AT91_MATRIX_USBPUCR_PUON;
+			at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);

Using a board specific function will rid you of that cascade as well.

arch/arm/include/asm/arch-at91/cpu.h

Quoted 2 lines
arch/arm/include/asm/arch-at91/cpu.h new file +2 -0
+	u32 __iomem	*creg = ep->creg;
+	u8 __iomem	*dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));

Always use readl/writel to access hardware.

There are more coding style problems in the source, but for source pulled from the kernel that might be ok (Wolfgang?)

Best Regards,
Reinhard Meyer

#3 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Hi,

2010/8/12 Reinhard Meyer <[email protected]>:

Quoted 9 lines

Dear Remy Bohmer,

arch/arm/include/asm/arch-at91/at91_dbgu.h

Quoted 6 lines

This patch implements the low-level part of the USB CDC layer for AT91 Other boards can use this patch as an example to connect their own.

arch/arm/include/asm/arch-at91/at91_dbgu.h new file +0 -0
new file mode 100644

Please see my patch introducing at91_dbgu.h (4/5.July 2010)

Hmm, this one does not seem to be in mainline yet. If it was, I probably would have used that one ;-)

Quoted 7 lines

arch/arm/include/asm/arch-at91/at91_dbgu.h

Quoted 3 lines
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +3 -0
+#define AT91_DBGU_CR ? ? ? ? ? (AT91_DBGU + 0x00) /* Control Register */
+#define AT91_DBGU_MR ? ? ? ? ? (AT91_DBGU + 0x04) /* Mode Register */
+#define AT91_DBGU_IER ? ? ? ? ?(AT91_DBGU + 0x08) /* Interrupt Enable */

Use struct access for SoC registers. Offset adressing is depreciated. See the
struct in my at91_dbgu.h. Use readl/writel to access the hardware.

Most of the code is copied from Linux. Do you really think we should rewrite it all?

Quoted 7 lines
Quoted 4 lines

+#define ? ? ? ? ? ? ? ?AT91_DBGU_TXRDY ? ? ? ? (1 << 1) ? /* Transmitter Ready */
+#define ? ? ? ? ? ? ? ?AT91_DBGU_TXEMPTY ? ? ? (1 << 9) ? /* Transmitter Empty */

Don't define this here, UART handling is in drivers/serial/atmel_usart.? The first 9 registers in the DBGU are identical to the normal USARTS.

Indeed, but again, it is copied from Linux...

Quoted 8 lines

arch/arm/include/asm/arch-at91/at91_dbgu.h

Quoted 5 lines
arch/arm/include/asm/arch-at91/at91_dbgu.h new file +5 -0
+#define ? ? ? ? ? ? ? ? ? ? ? ?AT91_CIDR_SRAMSIZ_1K ? ?(1 << 16)
+#define ? ? ? ? ? ? ? ? ? ? ? ?AT91_CIDR_SRAMSIZ_2K ? ?(2 << 16)
+#define ? ? ? ? ? ? ? ? ? ? ? ?AT91_CIDR_SRAMSIZ_112K ?(4 << 16)
+#define ? ? ? ? ? ? ? ? ? ? ? ?AT91_CIDR_SRAMSIZ_4K ? ?(5 << 16)
+#define ? ? ? ? ? ? ? ? ? ? ? ?AT91_CIDR_SRAMSIZ_80K ? (6 << 16)

I think we should not define stuff that is nowhere used, and if one space or tab will do.

Except for easy synching with Linux code?

Quoted 6 lines
Quoted 3 lines
arch/arm/include/asm/arch-at91/cpu.h new file +0 -0
new file mode 100644

<snip>

Quoted 1 line
Quoted 6 lines

arch/arm/include/asm/arch-at91/cpu.h line 18

Quoted 3 lines
arch/arm/include/asm/arch-at91/cpu.h new file +3 -0
+#include <asm/hardware.h>
+#include <asm/arch/at91_dbgu.h>
+#include <asm/arch/io.h>

Don't include other header files at this point. If a c source requires both DBGU and CPU headers, it shall include both.

This is how the file looks like in Linux...

Quoted 7 lines

arch/arm/include/asm/arch-at91/cpu.h

Quoted 6 lines
arch/arm/include/asm/arch-at91/cpu.h new file +6 -0
+#define ARCH_ID_AT91RM9200 ? ? 0x09290780
+#define ARCH_ID_AT91SAM9260 ? ?0x019803a0
+#define ARCH_ID_AT91SAM9261 ? ?0x019703a0
+#define ARCH_ID_AT91SAM9263 ? ?0x019607a0
+#define ARCH_ID_AT91SAM9RL64 ? 0x019b03a0
+#define ARCH_ID_AT91CAP9 ? ? ? 0x039A03A0
Quoted 7 lines

Nice to have, but determining at runtime which variant we are on makes only sense to me for pin-compatible variants, e.g. 9260, 9xe, 9g20. Then you will notice that their hardware is not different much, if at all.
Non pin-compatible variants are #defined in their board specific header file. Use #ifdef in the source to handle necessary variant specific stuff...

See Linux...

Quoted 15 lines

<snip>

arch/arm/include/asm/arch-at91/cpu.h

Quoted 4 lines
arch/arm/include/asm/arch-at91/cpu.h new file +3 -0
+//#define DEBUG 1
+//#define VERBOSE 1
+//#define PACKET_TRACE 1

NO C++ comments allowed. And no commented away defines in general. Maybe say it like this:
/*
?* to switch on debug output define any of those:
?* DEBUG - general debug
?* VERBOSE - more debug
?* PACKET_TRACE - also print packets
?*/

OK. This is a left-over that I do not seem to have cleaned up. I usually use // during development, then I can easily find what to clean up later...

Quoted 1 line

wherever possible use the debug() macro defines in common.h

Even in code with Linux as origin?

Quoted 7 lines
Quoted 4 lines

+ * This driver expects the board has been wired with two GPIOs suppporting
+ * a VBUS sensing IRQ, and a D+ pullup. ?(They may be omitted, but the
+ * testing hasn't covered such cases.)

It should. Besides AT91 currently cannot handle IRQs. Also I think it should read D- pullup.

This file is copied from Linux. That was the goal of this port; to be able to integrate new devices and fixes easier in the future. It was not our goal to make it nicer compared to Linux. If the comments are wrong, I would suggest to fix it in Linux first after which we integrate it in U-boot.

Quoted 6 lines

<snip>

Quoted 2 lines

+ ? ? ? ? ? ? ? hang();

Does this mean the system is dead and would need a watchdog or reset button to come alive again?

Yep, if that happens things are really broken...

Quoted 6 lines

<snip>

Quoted 1 line

+ ? ? ? // terminer chaque requete dans la queue

C++ comment in unknown language ;)?

Linux code...

Quoted 8 lines

<snip>

Quoted 3 lines

+/* TODO:
+ * ? ? BUG_ON(!list_empty(&req->queue));
+ * ? ? kfree(req); */

Wrong multi line comment.

OK

Quoted 5 lines

<snip>

Quoted 1 line

+static void pullup(struct at91_udc *udc, int is_on)

Quoted 7 lines

<snip>

I suggest to define and use a weak function to dummy on/off the pullup.
Board specific source can implement a function then to really switch on/off a pullup in whatever way the hardware has provided that. That need not necessarily be a GPIO pin...

That is doing things differently compared to Linux...

Quoted 7 lines
Quoted 7 lines

+ ? ? ? ? ? ? ? if (cpu_is_at91rm9200())
+ ? ? ? ? ? ? ? ? ? ? ? at91_set_gpio_value(udc->board.pullup_pin, 1);
+ ? ? ? ? ? ? ? else if (cpu_is_at91sam9260() || cpu_is_at91sam9263()) {
+ ? ? ? ? ? ? ? ? ? ? ? u32 ? ? txvc = at91_udp_read(udc, AT91_UDP_TXVC); +
+ ? ? ? ? ? ? ? ? ? ? ? txvc |= AT91_UDP_TXVC_PUON;
+ ? ? ? ? ? ? ? ? ? ? ? at91_udp_write(udc, AT91_UDP_TXVC, txvc);

Quoted 8 lines
Quoted 6 lines

+ ? ? ? ? ? ? ? } else if (cpu_is_at91sam9261()) {
+ ? ? ? ? ? ? ? ? ? ? ? u32 ? ? usbpucr;
+
+ ? ? ? ? ? ? ? ? ? ? ? usbpucr = at91_sys_read(AT91_MATRIX_USBPUCR);
+ ? ? ? ? ? ? ? ? ? ? ? usbpucr |= AT91_MATRIX_USBPUCR_PUON;
+ ? ? ? ? ? ? ? ? ? ? ? at91_sys_write(AT91_MATRIX_USBPUCR, usbpucr);

Using a board specific function will rid you of that cascade as well.

Agree, but that means doing things differently compared to Linux... (the origin of this code)

Quoted 5 lines
Quoted 3 lines

+ ? ? ? u32 __iomem ? ? *creg = ep->creg;
+ ? ? ? u8 __iomem ? ? ?*dreg = ep->creg + (AT91_UDP_FDR(0) - AT91_UDP_CSR(0));

Always use readl/writel to access hardware.

See Linux

Quoted 3 lines

There are more coding style problems in the source, but for source pulled from the kernel that might be ok (Wolfgang?)

I understand your remarks, and for new written code they are 100% valid to me (I would even not have posted it at all like this), however, most of this code comes from Linux. It is a port to U-boot. True, things can be done differently, but that would make future syncing and integration of new drivers much more difficult.

Kind regards,

Remy

#4 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

Quoted 7 lines · In message <[email protected]> you…
Quoted 4 lines

Use struct access for SoC registers. Offset adressing is depreciated. See the
struct in my at91_dbgu.h. Use readl/writel to access the hardware.

Most of the code is copied from Linux. Do you really think we should rewrite it all?

Indeed. Using I/O accessors is mandatory in U-Boot.

Quoted 4 lines
Quoted 2 lines

Don't define this here, UART handling is in drivers/serial/atmel_usart.? The first 9 registers in the DBGU are identical to the normal USARTS.

Indeed, but again, it is copied from Linux...

Maybe we can do it better?

Quoted 4 lines
Quoted 2 lines

Don't include other header files at this point. If a c source requires both DBGU and CPU headers, it shall include both.

This is how the file looks like in Linux...

You got me here. Of course allowing for easy updates from Linux is important, but then, we will have bigger differences anyway, for example for the I/O accessors.

Quoted 1 line

See Linux...

This is not a general purpose, answers-all-questions/kills-them-all argument. Don't over-use it. Linux is great, but there is bad code in Linux like everywhere else. Blindly copying for no better reason that that Linux is doing that ways is NOT a good idea.

Quoted 5 lines

This file is copied from Linux. That was the goal of this port; to be able to integrate new devices and fixes easier in the future. It was not our goal to make it nicer compared to Linux. If the comments are wrong, I would suggest to fix it in Linux first after which we integrate it in U-boot.

Come on. Here a bit statistics:

-> diff -u linux/drivers/usb/gadget/at91_udc.c u-boot/drivers/usb/gadget/at91_udc.c | wc -l 1057
-> wc -l linux/drivers/usb/gadget/at91_udc.c u_boot/drivers/usb/gadget/at91_udc.c
1908 linux/drivers/usb/gadget/at91_udc.c
1553 u-boot/drivers/usb/gadget/at91_udc.c

There are so many lines changed already in the code that claoming "This file is copied from Linux." does not make much sense any more.

And many of the code changes are to the worse actually.

For example:

- ep->is_in = usb_endpoint_dir_in(desc);
+ ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0;

It is NOT the Linux code that is using CamelCase identifiers, for example.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

+ hang();

Does this mean the system is dead and would need a watchdog or reset button to come alive again?

Yep, if that happens things are really broken...

So broken that you cannot get back to the command line interpreter? Really?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ // terminer chaque requete dans la queue

C++ comment in unknown language ;)?

Linux code...

And that justifies it all.

Quoted 8 lines
Quoted 2 lines

There are more coding style problems in the source, but for source pulled from the kernel that might be ok (Wolfgang?)

I understand your remarks, and for new written code they are 100% valid to me (I would even not have posted it at all like this), however, most of this code comes from Linux. It is a port to U-boot. True, things can be done differently, but that would make future syncing and integration of new drivers much more difficult.

Face it: the code as is can already be synced only manually. It is way too different already.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
I am not now, nor have I ever been, a member of the demigodic party.
                                                   -- Dennis Ritchie
#5 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

just some more observations:

1. The USB device port hardware in AT91SAM9* is called "UDP". So files that are AT91 specific should have "udp" in their names, not "udc". I know LinuX did do it wrong already...

2. At one part the header file for at9sam9261 is unconditionally included, and none for the other at91 variants. Have you verified that this is OK for all at91 variants? Besides that if so, the common parts used should probably be moved to an extra at91_*.h file.

3. I did not follow the whole USB patches, my concern is what touches AT91, but please explain to me what for we need a board under u-boot to be a USB device. Since u-boot per se is not multitasking how is the traffic handled while at the command prompt?

Which leads to:
4. Which hardware did you test that on, and what device functionality?

Best Regards,
Reinhard

#6 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Hi,

Quoted 5 lines

3. I did not follow the whole USB patches, my concern is what touches AT91, but please explain to me what for we need a board under u-boot to be a USB device. Since u-boot per se is not multitasking how is the traffic handled while at the command prompt?

There is no traffic handled while at the command prompt. It behaves just like any other 'normal' network adapter.
So, it brings up a USB connection once you start a network action like a ping or tftp command. Once that completes the link is brought down again.

Quoted 3 lines

Which leads to:
4. Which hardware did you test that on, and what device functionality?

Within the series you can see that it was created for the Atmel at91sam9261-ek kit.

Kind regards,

Remy

#7 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

Quoted 11 lines
Quoted 5 lines

3. I did not follow the whole USB patches, my concern is what touches AT91, but please explain to me what for we need a board under u-boot to be a USB device. Since u-boot per se is not multitasking how is the traffic handled while at the command prompt?

There is no traffic handled while at the command prompt. It behaves just like any other 'normal' network adapter.
So, it brings up a USB connection once you start a network action like a ping or tftp command. Once that completes the link is brought down again.

If I understand the procedure correctly now, its as follows:

Any client network command on u-boot's command prompt like ping, dhcp, tftp etc. will 'up' the USB Device...
The host to which it is connected to will happily discover and enumerate a network adapter with MAC and IP addresses...
And the host will be the server for that command...

Best Regards,
Reinhard

#8 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Hi,

2010/8/13 Reinhard Meyer <[email protected]>:

Quoted 14 lines

Dear Remy Bohmer,

Quoted 7 lines
Quoted 6 lines

3. I did not follow the whole USB patches, my concern is what touches AT91, but please explain to me what for we need a board under u-boot to be a USB device. Since u-boot per se is not multitasking how is the traffic handled while at the command prompt?

Quoted 5 lines

There is no traffic handled while at the command prompt. It behaves just like any other 'normal' network adapter.
So, it brings up a USB connection once you start a network action like a ping or tftp command. Once that completes the link is brought down again.

Quoted 6 lines

If I understand the procedure correctly now, its as follows:

Any client network command on u-boot's command prompt like ping, dhcp, tftp etc. will 'up' the USB Device...
The host to which it is connected to will happily discover and enumerate a network adapter with MAC and IP addresses...

Correct.

Quoted 1 line

And the host will be the server for that command...

The procedure is initiated by U-boot, since that one is pulling the D+ resistor up and down.
Network traffic is of course bidirectional, so U-boot can initiate a TFTP transfer when it is up.

Kind regards,

Remy

#9 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

In reply to Wolfgang Denk

Hi Wolfgang,

2010/8/12 Wolfgang Denk <[email protected]>:

Quoted 4 lines

Dear Remy Bohmer,

Quoted 1 line · In message <[email protected]> you…
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Use struct access for SoC registers. Offset adressing is depreciated. See the
struct in my at91_dbgu.h. Use readl/writel to access the hardware.

Most of the code is copied from Linux. Do you really think we should rewrite it all?

Indeed. Using I/O accessors is mandatory in U-Boot.

Ok, but here ends the goal for easy synching with the kernel. In that case we can write our own USB gadget layer

Quoted 3 lines
Quoted 1 line

Indeed, but again, it is copied from Linux...

Maybe we can do it better?

As mentioned: we can, but I did not want to at the time of writing that code.

Quoted 8 lines
Quoted 5 lines

This file is copied from Linux. That was the goal of this port; to be able to integrate new devices and fixes easier in the future. It was not our goal to make it nicer compared to Linux. If the comments are wrong, I would suggest to fix it in Linux first after which we integrate it in U-boot.

Come on. ?Here a bit statistics:

Quoted 8 lines

-> diff -u linux/drivers/usb/gadget/at91_udc.c u-boot/drivers/usb/gadget/at91_udc.c | wc -l 1057
-> wc -l linux/drivers/usb/gadget/at91_udc.c u_boot/drivers/usb/gadget/at91_udc.c ?1908 linux/drivers/usb/gadget/at91_udc.c
?1553 u-boot/drivers/usb/gadget/at91_udc.c

There are so many lines changed already in the code that claoming "This file is copied from Linux." does not make much sense any more.

Well, it is derived from 2.6.27, not latest git.
True, there are differences, but mostly it is a strip down of the original code( /proc support is removed for example)
And I also noticed that the file can be synced to Linux more than it currently is...

Quoted 6 lines

And many of the code changes are to the worse actually.

For example:

? ? ? ?- ? ? ? ep->is_in = usb_endpoint_dir_in(desc);
? ? ? ?+ ? ? ? ep->is_in = (desc->bEndpointAddress & USB_DIR_IN) != 0;

This was NOT the case in 2.6.27. So, it is not worse compared to 2.6.27...

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Does this mean the system is dead and would need a watchdog or reset button to come alive again?

Yep, if that happens things are really broken...

So broken that you cannot get back to the command line interpreter? Really?

If malloc is broken, I consider that reason enough for hang/reboot...

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+ ? ? ? // terminer chaque requete dans la queue

C++ comment in unknown language ;)?

Linux code...

And that justifies it all.

No, but please look at the overall goal here. It was the goal to use the Linux code as much as-is, and to allow easy merging new driver code in the future. Everything can be made better, but in that case I would prefer to first make the origin better, and port that back to U-boot.

Further, I am not planning to rewrite the code to the struct based register access _right now_, since the struct based access mechanism is somehow work in progress that is not finalised yet (CONFIG_AT91_LEGACY is still defined for at91sam9261ek). I am not going to shoot on a moving duck. Also because you mention that at91_dbgu.h patches float around that are not in mainline yet. I will probably clean it up later when things are stabilised.

So, if you prefer I can drop patch 2/3 and 3/3 from the series, since those are only needed to prove that patch 1/3 works and to have at least 1 board in U-boot that make use of the USB-CDC-ECM gadget layer... I expect that there will be other boards soon that will use it, since others are working on it right now.

Kind regards,

Remy

#10 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

Quoted 9 lines · In message <[email protected]> you…
Quoted 3 lines

There are so many lines changed already in the code that claoming "This file is copied from Linux." does not make much sense any more.

Well, it is derived from 2.6.27, not latest git.
True, there are differences, but mostly it is a strip down of the original code( /proc support is removed for example)
And I also noticed that the file can be synced to Linux more than it currently is...

Well, if your argument is true that the current code can easily be kept in sync with Linux, then why is it already 8 kernel releases old?

How about syncing it with Linux, before adding it to U-Boot?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yep, if that happens things are really broken...

So broken that you cannot get back to the command line interpreter? Really?

If malloc is broken, I consider that reason enough for hang/reboot...

That's not a good idea. Please fix.

Quoted 7 lines
Quoted 1 line

And that justifies it all.

No, but please look at the overall goal here. It was the goal to use the Linux code as much as-is, and to allow easy merging new driver code in the future. Everything can be made better, but in that case I would prefer to first make the origin better, and port that back to U-boot.

Well, the origin has improved by 8 kernel releases since.

Would it make sense to update?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
A witty saying proves nothing, but saying  something  pointless  gets
people's attention.
#11 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Hi Wolfgang,

2010/8/13 Wolfgang Denk <[email protected]>:

Quoted 4 lines

Dear Remy Bohmer,

Well, if your argument is true that the current code can easily be kept in sync with Linux, then why is it already 8 kernel releases old?

Because it lives already for a real long time in the u-boot-usb tree with no requests on the ML about this subject.
Nobody ever showed interest on the ML, so that did not convince me to put any effort in it to push it further. (Why put a lot of time in something if nobody wants it?) Recently there finally seems to be interest, so now it is time to do something useful with it.

Quoted 1 line

How about syncing it with Linux, before adding it to U-Boot?

Can be done, but first collect the review comments to figure out how much time it will take to make it U-boot suitable and find out if we need to fork anyway... From functional point of view I see no reason yet to upgrade.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yep, if that happens things are really broken...

So broken that you cannot get back to the command line interpreter? Really?

If malloc is broken, I consider that reason enough for hang/reboot...

That's not a good idea. ?Please fix.

Fix what?
If runtime a condition is detected that should _never_ _ever_ happen (like malloc does not work properly for some reason), which would even make Linux OOPS or panic may not result in a hang() on U-boot? In that case I can remove the hang() and consider if it never happened. Maybe even the code will reach the prompt, but there will be no guarantees...
I personally consider that worse compared to tell the user that something serious has gone wrong...

Kind regards,

Remy

#12 lore raw

PATCH 2/3 Connect the AT91 UDC to USB CDC-ethernet support

Dear Remy Bohmer,

Quoted 4 lines · In message <[email protected]> you…
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

So broken that you cannot get back to the command line interpreter? Really?

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

If malloc is broken, I consider that reason enough for hang/reboot...

That's not a good idea. =A0Please fix.

Fix what?
If runtime a condition is detected that should _never_ _ever_ happen (like malloc does not work properly for some reason), which would even make Linux OOPS or panic may not result in a hang() on U-boot?

malloc() is not broken, it just has not enough resources to fulfil your request. That does not mean that the rest of the system (which does not make any such requests) would not be able to continue.

Quoted 3 lines

In that case I can remove the hang() and consider if it never happened. Maybe even the code will reach the prompt, but there will be no guarantees...

Fail the running command with appropriate error message and returen code, but do not decide for the user if he is able and willing to continue.

Quoted 2 lines

I personally consider that worse compared to tell the user that something serious has gone wrong...

Of course we have to issue appropriate error messages and return codes, but there is no need to halt the system.

You stop your car, but you don't (usually) take it to a knacker's yard when there is a flat tire.

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Respect is a rational process
	-- McCoy, "The Galileo Seven", stardate 2822.3
#13 lore raw

PATCH 3/3 Enable the use of Ethernet over USB (CDC) for the AT91SAM9261EK board.

In reply to Remy Bohmer
---
 board/atmel/at91sam9261ek/at91sam9261ek.c |   43 +++++++++++++++++++++++++++-
 include/configs/at91sam9261ek.h           |   17 +++++++++++
 2 files changed, 58 insertions(+), 2 deletions(-)
board/atmel/at91sam9261ek/at91sam9261ek.c +41 -2
index de5cfae..1a27e53 100644
@@ -33,14 +33,29 @@
 #include <asm/arch/gpio.h>
 #include <asm/arch/io.h>
 #include <lcd.h>
+#include <usb/at91_udc.h>
 #include <atmel_lcdc.h>
 #if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_DRIVER_DM9000)
 #include <net.h>
 #include <netdev.h>
 #endif
 
+#if defined(CONFIG_USB_GADGET_AT91) && !defined(CONFIG_USB_GADGET)
+#error "Need CONFIG_USB_GADGET when CONFIG_USB_GADGET_AT91 enabled"
+#endif
+
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifdef CONFIG_USB_GADGET_AT91
+struct platform_data brd = {
+	.board = {
+		.vbus_pin   = AT91_PIN_PB29,
+		.pullup_pin = 0,
+	},
+	.udc_clk = AT91SAM9261_ID_UDP,
+};
+#endif
+
 /* ------------------------------------------------------------------------- */
 /*
  * Miscelaneous platform dependent initialisations
@@ -141,6 +156,16 @@ static void at91sam9261ek_dm9000_hw_init(void)
 }
 #endif
 
+#ifdef CONFIG_USB_GADGET_AT91
+static void at91sam9261ek_usbd_hw_init(void)
+{
+	/* PLLB is already enabled by the bootstrap loader... */
+	at91_sys_write(AT91_PMC_SCER, AT91SAM926x_PMC_UDP);
+	at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9261_ID_PIOB);
+	at91_set_gpio_input(brd.board.vbus_pin, 0);
+}
+#endif
+
 #ifdef CONFIG_LCD
 vidinfo_t panel_info = {
 	vl_col:		240,
@@ -255,6 +280,9 @@ int board_init(void)
 #ifdef CONFIG_HAS_DATAFLASH
 	at91_spi0_hw_init(1 << 0);
 #endif
+#ifdef CONFIG_USB_GADGET_AT91
+	at91sam9261ek_usbd_hw_init();
+#endif
 #ifdef CONFIG_DRIVER_DM9000
 	at91sam9261ek_dm9000_hw_init();
 #endif
@@ -264,10 +292,21 @@ int board_init(void)
 	return 0;
 }
 
-#ifdef CONFIG_DRIVER_DM9000
+#if defined(CONFIG_DRIVER_DM9000) || defined(CONFIG_USB_GADGET_AT91)
 int board_eth_init(bd_t *bis)
 {
-	return dm9000_initialize(bis);
+	int res = -1;
+
+#if defined(CONFIG_DRIVER_DM9000)
+	res = dm9000_initialize(bis);
+#endif
+#if defined(CONFIG_USB_GADGET_AT91)
+	at91udc_probe(&brd);
+
+	if (usb_eth_initialize(bis) >= 0)
+		res = 0;
+#endif
+	return res;
 }
 #endif
 
include/configs/at91sam9261ek.h +17 -0
index df8181b..8749b51 100644
@@ -151,6 +151,23 @@
 #define CONFIG_DM9000_NO_SROM		1
 #define CONFIG_NET_RETRY_COUNT		20
 #define CONFIG_RESET_PHY_R		1
+#define CONFIG_NET_DO_NOT_TRY_ANOTHER	1
+
+/* Configure Ethernet over USB */
+#define CONFIG_USB_GADGET		1
+#define CONFIG_USB_GADGET_AT91		1
+#define CONFIG_USB_ETHER		1
+#ifdef CONFIG_USB_GADGET
+#define CFG_USBD_REGS_BASE		AT91SAM9261_BASE_UDP
+#endif
+#define CONFIG_USBNET_MANUFACTURER      "Atmel AT91SAM9261-EK"
+/* ethaddr settings can be overruled via environment settings */
+#define CONFIG_USBNET_DEV_ADDR		"8e:28:0f:fa:3c:39"
+#define CONFIG_USBNET_HOST_ADDR		"0a:fa:63:8b:e8:0a"
+#define CONFIG_USB_CDC_VENDOR_ID        0x0525
+#define CONFIG_USB_CDC_PRODUCT_ID       0xa4a1
+#define CONFIG_USB_RNDIS_VENDOR_ID      0x0525
+#define CONFIG_USB_RNDIS_PRODUCT_ID     0xa4a2
 
 /* USB */
 #define CONFIG_USB_ATMEL
Signature · 1 line
1.7.0.4