Skip to contentSkip to conversation

staging: Emma Mobile USB driver and KZM9D board code

PATCH Superseded Magnus Damm 4 participants 11 messages May 22, 2014 – May 23, 2014

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover staging: Emma Mobile USB driver and KZM9D board code

Emma Mobile USB driver and KZM9D board code

[PATCH 01/03] staging: emxx_udc: Add Emma Mobile USB Gadget driver [PATCH 02/03] staging: emxx_udc: I/O memory and IRQ resource support [PATCH 03/03] staging: board: kzm9d: Board staging support for emxx_udc

This patch series contains an old USB Gadget driver for Emma Mobile that gets slightly adjusted to make use of the platform device interface which in turn is used to add USB Gadget support to the KZM9D board.

Two separate staging components are included in this series:
1) the emxx_udc driver - from out-of-tree Android 2.6.35.7
2) board staging support for KZM9D - platform device for DT-only KZM9D

The two components above will be used to continously improve the driver and board integration code until the driver can be moved out of staging and/or DT bindings are available so the board staging platform device code can be replaced with a DT node.

Olof, patch 3/3 contains some board staging code for KZM9D. As it is today the EMEV2 SoC is DT-only and we neither have defconfig nor Kconfig definitions for the KZM9D board (emev2-kzm9d.dts). Instead of again adding board code to the ARM subarchitecture I hereby propose that we use staging to integrate non-DT drivers while they are improved to get DT support.

Greg, please let me know your opinions. I'd be happy to rework the code.

---

Written against renesas-devel-v3.15-rc5-20140521

 drivers/staging/Kconfig             |    4 
 drivers/staging/Makefile            |    2 
 drivers/staging/board/Kconfig       |    7 
 drivers/staging/board/Makefile      |    1 
 drivers/staging/board/board.h       |   17 
 drivers/staging/board/kzm9d.c       |   18 
 drivers/staging/emxx_udc/Kconfig    |   10 
 drivers/staging/emxx_udc/Makefile   |    1 
 drivers/staging/emxx_udc/emxx_udc.c | 3616 ++++++++++++++++++++++++++++++++++-
 drivers/staging/emxx_udc/emxx_udc.h |  671 ++++++
 10 files changed, 4299 insertions(+), 48 deletions(-)
#1 lore raw

PATCH 1/3 staging: emxx_udc: Add Emma Mobile USB Gadget driver

From: Magnus Damm <[email protected]>

Add the emxx_udc driver to staging based on an old linux-2.6.35.7 android tree. The driver has been brushed up slightly to complile but it is still in great need of cleanup.

At this point DT bindings are clearly lacking and I doubt that the driver even can run with multiple instances (global variables, hurray!).

---

 drivers/staging/Kconfig             |    2 
 drivers/staging/Makefile            |    1 
 drivers/staging/emxx_udc/Kconfig    |   10 
 drivers/staging/emxx_udc/Makefile   |    1 
 drivers/staging/emxx_udc/emxx_udc.c | 3559 +++++++++++++++++++++++++++++++++++
 drivers/staging/emxx_udc/emxx_udc.h |  662 ++++++
 6 files changed, 4235 insertions(+)
drivers/staging/Kconfig +2 -0
@@ -92,6 +92,8 @@ source "drivers/staging/quickstart/Kconf
 
 source "drivers/staging/sbe-2t3e3/Kconfig"
 
+source "drivers/staging/emxx_udc/Kconfig"
+
 source "drivers/staging/keucr/Kconfig"
 
 source "drivers/staging/bcm/Kconfig"
drivers/staging/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_FB_XGI)		+= xgifb/
 obj-$(CONFIG_TIDSPBRIDGE)	+= tidspbridge/
 obj-$(CONFIG_ACPI_QUICKSTART)	+= quickstart/
 obj-$(CONFIG_SBE_2T3E3)		+= sbe-2t3e3/
+obj-$(CONFIG_USB_EMXX)		+= emxx_udc/
 obj-$(CONFIG_USB_ENESTORAGE)	+= keucr/
 obj-$(CONFIG_BCM_WIMAX)		+= bcm/
 obj-$(CONFIG_FT1000)		+= ft1000/
drivers/staging/emxx_udc/Kconfig new file +10 -0
@@ -0,0 +1,10 @@
+config USB_EMXX
+	boolean "EMXX USB Function Device Controller"
+ 	depends on USB_GADGET && (ARCH_SHMOBILE || (ARM && COMPILE_TEST))
+	help
+	   The Emma Mobile series of SoCs from Renesas Electronics and
+	   former NEC Electronics include USB Function hardware.
+
+	   Say "y" to link the driver statically, or "m" to build a
+	   dynamically linked module called "emxx_udc" and force all
+	   gadget drivers to also be dynamically linked.
drivers/staging/emxx_udc/Makefile new file +1 -0
@@ -0,0 +1 @@
+obj-$(CONFIG_USB_EMXX)	:= emxx_udc.o
drivers/staging/emxx_udc/emxx_udc.c new file +3559 -0

2,974 lines not on this page · raw message

drivers/staging/emxx_udc/emxx_udc.h new file +662 -0

662 lines not on this page · raw message

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

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

#2 lore raw

PATCH 2/3 staging: emxx_udc: I/O memory and IRQ resource support

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

Adjust the emxx_udc driver to make use of the standard driver model to pass I/O memory and IRQ as resources instead of hard coding those things in the driver.

Needs more work - the VBUS signal is yet not handled.

---

 drivers/staging/emxx_udc/emxx_udc.c |   57 +++++++++++------------------------
 drivers/staging/emxx_udc/emxx_udc.h |    9 -----
 2 files changed, 18 insertions(+), 48 deletions(-)
drivers/staging/emxx_udc/emxx_udc.c +18 -39
@@ -3356,37 +3356,38 @@ static int nbu2ss_drv_probe(struct platf
 {
 	int	status = -ENODEV;
 	struct nbu2ss_udc	*udc;
+	struct resource *r;
+	int irq;
+	void __iomem *mmio_base;
 
 	udc = &udc_controller;
 	memset(udc, 0, sizeof(struct nbu2ss_udc));
 
 	platform_set_drvdata(pdev, udc);
 
-	/* IO Memory Region */
-	if (!request_mem_region(USB_BASE_ADDRESS, USB_BASE_SIZE
-				, driver_name)) {
+	/* require I/O memory and IRQ to be provided as resources */
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	mmio_base = devm_request_and_ioremap(&pdev->dev, r);
+	if (IS_ERR(mmio_base)) {
+		dev_err(&pdev->dev, "failed to map I/O memory\n");
+		return PTR_ERR(mmio_base);
+	}
 
-		ERR("request_mem_region failed\n");
-		return -EBUSY;
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "failed to get IRQ\n");
+		return irq;
 	}
+	status = devm_request_irq(&pdev->dev, irq, _nbu2ss_udc_irq,
+				  0, driver_name, udc);
 
 	/* IO Memory */
-	udc->p_regs = (PT_FC_REGS)ioremap(USB_BASE_ADDRESS, USB_BASE_SIZE);
-	if (!udc->p_regs) {
-		ERR("request_io_mem failed\n");
-		goto cleanup3;
-	}
+	udc->p_regs = (PT_FC_REGS)mmio_base;
 
 	/* USB Function Controller Interrupt */
-	status = request_irq(USB_UDC_IRQ_1,
-				_nbu2ss_udc_irq,
-				IRQF_DISABLED,
-				driver_name,
-				udc);
-
 	if (status != 0) {
 		ERR("request_irq(USB_UDC_IRQ_1) failed\n");
-		goto cleanup2;
+		goto cleanup1;
 	}
 
 	/* Driver Initialization */
@@ -3412,18 +3413,6 @@ static int nbu2ss_drv_probe(struct platf
 	return status;
 
 cleanup1:
-	/* Interrupt Handler - Release */
-	free_irq(USB_UDC_IRQ_1, udc);
-
-cleanup2:
-	/* IO Memory - Release */
-	if (udc->p_regs)
-		iounmap(udc->p_regs);
-
-cleanup3:
-	/* IO Memory Region - Release */
-	release_mem_region(USB_BASE_ADDRESS, USB_BASE_SIZE);
-
 	return status;
 }
 
@@ -3456,18 +3445,8 @@ static int __exit nbu2ss_drv_remove(stru
 	}
 
 	/* Interrupt Handler - Release */
-	free_irq(USB_UDC_IRQ_1, udc);
-
-	/* Interrupt Handler - Release */
 	free_irq(INT_VBUS, udc);
 
-	/* IO Memory - Release */
-	if (udc->p_regs)
-		iounmap(udc->p_regs);
-
-	/* IO Memory Region - Release */
-	release_mem_region(USB_BASE_ADDRESS, USB_BASE_SIZE);
-
 	return 0;
 }
 
drivers/staging/emxx_udc/emxx_udc.h +0 -9
@@ -47,20 +47,11 @@
 
 
 /*------------ Board dependence(Resource) */
-#define USB_BASE_ADDRESS	EMXX_USBS1_BASE
-#define USB_BASE_SIZE		0x2000
-
-#define USB_UDC_IRQ_0		INT_USBF0
-#define USB_UDC_IRQ_1		INT_USBF1
 #define	VBUS_VALUE		GPIO_VBUS
 
 /* below hacked up for staging integration */
 #define GPIO_VBUS 0 /* GPIO_P153 on KZM9D */
 #define INT_VBUS 0 /* IRQ for GPIO_P153 */
-#define INT_USBF0 158
-#define INT_USBF1 159
-#define EMXX_USBS0_BASE 0xe2700000
-#define EMXX_USBS1_BASE 0xe2800000
 
 /*------------ Board dependence(Wait) */
 
#3 lore raw

PATCH 3/3 staging: board: kzm9d: Board staging support for emxx_udc

In reply to Magnus Damm

From: Magnus Damm <[email protected]>

Add staging board support for the KZM9D board and add an emxx_udc platform device to allow in-tree continous development of the driver on the KZM9D board.

When DT bindings are ready for the emxx_udc driver then the platform device in the KZM9D staging board code can easily be removed. Until then we use platform devices to continously improve the driver and integration code.

---

 drivers/staging/Kconfig        |    2 ++
 drivers/staging/Makefile       |    1 +
 drivers/staging/board/Kconfig  |    7 +++++++
 drivers/staging/board/Makefile |    1 +
 drivers/staging/board/board.h  |   17 +++++++++++++++++
 drivers/staging/board/kzm9d.c  |   18 ++++++++++++++++++
 6 files changed, 46 insertions(+)
drivers/staging/Kconfig +2 -0
@@ -112,6 +112,8 @@ source "drivers/staging/media/Kconfig"
 
 source "drivers/staging/android/Kconfig"
 
+source "drivers/staging/board/Kconfig"
+
 source "drivers/staging/ozwpan/Kconfig"
 
 source "drivers/staging/gdm72xx/Kconfig"
drivers/staging/Makefile +1 -0
@@ -49,6 +49,7 @@ obj-$(CONFIG_TOUCHSCREEN_CLEARPAD_TM1217
 obj-$(CONFIG_TOUCHSCREEN_SYNAPTICS_I2C_RMI4)	+= ste_rmi4/
 obj-$(CONFIG_MFD_NVEC)		+= nvec/
 obj-$(CONFIG_ANDROID)		+= android/
+obj-$(CONFIG_STAGING_BOARD)	+= board/
 obj-$(CONFIG_USB_WPAN_HCD)	+= ozwpan/
 obj-$(CONFIG_WIMAX_GDM72XX)	+= gdm72xx/
 obj-$(CONFIG_LTE_GDM724X)	+= gdm724x/
drivers/staging/board/Kconfig new file +7 -0
@@ -0,0 +1,7 @@
+config STAGING_BOARD
+	boolean "Staging Board Support"
+	help
+	  Select to enable per-board staging support code.
+
+	  If in doubt, say N here.
+
drivers/staging/board/Makefile new file +1 -0
@@ -0,0 +1 @@
+obj-$(CONFIG_ARCH_SHMOBILE_MULTI)	+= kzm9d.o
drivers/staging/board/board.h new file +17 -0
@@ -0,0 +1,17 @@
+#ifndef __BOARD_H__
+#define __BOARD_H__
+#include <linux/init.h>
+#include <linux/of.h>
+
+#define board_staging(str, fn)			\
+static int __init runtime_board_check(void)	\
+{						\
+	if (of_machine_is_compatible(str))	\
+		fn();				\
+						\
+	return 0;				\
+}						\
+						\
+late_initcall(runtime_board_check)
+
+#endif /* __BOARD_H__ */
drivers/staging/board/kzm9d.c new file +18 -0
@@ -0,0 +1,18 @@
+/* Staging board support for KZM9D. Enable not-yet-DT-capable devices here. */
+
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include "board.h"
+
+static const struct resource usbs1_resources[] __initconst = {
+	DEFINE_RES_MEM(0xe2800000, 0x2000),
+	DEFINE_RES_IRQ(159),
+};
+
+static void __init kzm9d_init(void)
+{
+	platform_device_register_simple("emxx_udc", -1, usbs1_resources,
+					ARRAY_SIZE(usbs1_resources));
+}
+
+board_staging("renesas,kzm9d", kzm9d_init);
#4 lore raw

Re: [PATCH 03/03] staging: board: kzm9d: Board staging support for emxx_udc

Hi Magnus,

Quoted 8 lines · Magnus Damm

Add staging board support for the KZM9D board and add an emxx_udc platform device to allow in-tree continous development of the driver on the KZM9D board.

When DT bindings are ready for the emxx_udc driver then the platform device in the KZM9D staging board code can easily be removed. Until then we use platform devices to continously improve the driver and integration code.

Nice!

Quoted 7 lines
 drivers/staging/Kconfig        |    2 ++
 drivers/staging/Makefile       |    1 +
 drivers/staging/board/Kconfig  |    7 +++++++
 drivers/staging/board/Makefile |    1 +
 drivers/staging/board/board.h  |   17 +++++++++++++++++
 drivers/staging/board/kzm9d.c  |   18 ++++++++++++++++++
 6 files changed, 46 insertions(+)

As you're adding infrastructure and a first user, I think this should be split in two patches:
- Introduction of drivers/staging/board infrastructure,
- Addition of kzm9d board support.

drivers/staging/board/Kconfig 2014-05-22 15:31:58.000000000 +0900 line 7

Quoted 10 lines
drivers/staging/board/Kconfig 2014-05-22 15:31:58.000000000 +0900 new file +7 -0
@@ -0,0 +1,7 @@
+config STAGING_BOARD
+       boolean "Staging Board Support"
+       help
+         Select to enable per-board staging support code.
+
+         If in doubt, say N here.
+

No board-specific Kconfig symbols, so the actual individual board support itself is
always compiled-in (but see below)?

drivers/staging/board/Makefile 2014-05-22 15:31:58.000000000 +0900 line 1

Quoted 4 lines
drivers/staging/board/Makefile 2014-05-22 15:31:58.000000000 +0900 new file +1 -0
@@ -0,0 +1 @@
+obj-$(CONFIG_ARCH_SHMOBILE_MULTI)      += kzm9d.o

Ah, it's included in all shmobile multi-platform kernels.

What about testing for CONFIG_ARCH_EMEV2 instead of CONFIG_ARCH_SHMOBILE_MULTI?
Or adding a KZM9D-specific Kconfig symbol to .../board/Kconfig?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#5 lore raw

Re: [PATCH 03/03] staging: board: kzm9d: Board staging support for emxx_udc

Hi Geert,

Quoted 7 lines · Geert Uytterhoeven

Hi Magnus,

Quoted 4 lines · Magnus Damm

Add staging board support for the KZM9D board and add an emxx_udc platform device to allow in-tree continous development of the driver on the KZM9D board.

Quoted 6 lines
Quoted 4 lines

When DT bindings are ready for the emxx_udc driver then the platform device in the KZM9D staging board code can easily be removed. Until then we use platform devices to continously improve the driver and integration code.

Nice!

Thanks, I hope it can turn into something useful!

Quoted 8 lines
Quoted 7 lines
 drivers/staging/Kconfig        |    2 ++
 drivers/staging/Makefile       |    1 +
 drivers/staging/board/Kconfig  |    7 +++++++
 drivers/staging/board/Makefile |    1 +
 drivers/staging/board/board.h  |   17 +++++++++++++++++
 drivers/staging/board/kzm9d.c  |   18 ++++++++++++++++++
 6 files changed, 46 insertions(+)
Quoted 4 lines

As you're adding infrastructure and a first user, I think this should be split in two patches:
- Introduction of drivers/staging/board infrastructure,
- Addition of kzm9d board support.

I agree!

Quoted 6 lines
Quoted 6 lines
drivers/staging/board/Kconfig 2014-05-22 15:31:58.000000000 +0900 new file +3 -0
@@ -0,0 +1,7 @@
+config STAGING_BOARD
+       boolean "Staging Board Support"
+       help
Quoted 8 lines

drivers/staging/board/Kconfig 2014-05-22 15:31:58.000000000 +0900 line 7

Quoted 4 lines
drivers/staging/board/Kconfig 2014-05-22 15:31:58.000000000 +0900 new file +4 -0
+         Select to enable per-board staging support code.
+
+         If in doubt, say N here.
+

No board-specific Kconfig symbols, so the actual individual board support itself is
always compiled-in (but see below)?

Yes, the user has a single switch to flip at this point.

Quoted 6 lines

drivers/staging/board/Makefile 2014-05-22 15:31:58.000000000 +0900 line 1

Quoted 4 lines
drivers/staging/board/Makefile 2014-05-22 15:31:58.000000000 +0900 new file +1 -0
@@ -0,0 +1 @@
+obj-$(CONFIG_ARCH_SHMOBILE_MULTI)      += kzm9d.o

Ah, it's included in all shmobile multi-platform kernels.

Correct!

Quoted 2 lines

What about testing for CONFIG_ARCH_EMEV2 instead of CONFIG_ARCH_SHMOBILE_MULTI?

That is quite fine with me.

Quoted 1 line

Or adding a KZM9D-specific Kconfig symbol to .../board/Kconfig?

Yeah, we could do that but my gut feeling is that it is better and easier to just keep it simple. I'm happy to adjust in any direction here though, so whatever makes people happy...!

Thanks for your feedback!

/ magnus

#6 lore raw
In reply to Magnus Damm

Generally we take things as is into staging so there is no need for a re-work if you don't want to. But we do need a TODO file. Read the TODO files for other staging drivers.

regards,
dan carpenter

#7 lore raw

Hi Dan,

Quoted 3 lines · Dan Carpenter

Generally we take things as is into staging so there is no need for a re-work if you don't want to. But we do need a TODO file. Read the TODO files for other staging drivers.

Thanks for pointing that out, my apologies for being random and skipping that! I will add a TODO file to v2!

Cheers,

/ magnus

Quoted 7 lines · Dan Carpenter

Generally we take things as is into staging so there is no need for a re-work if you don't want to. But we do need a TODO file. Read the TODO files for other staging drivers.

regards,
dan carpenter

maintainer
#8 lore raw
Quoted 9 lines · Magnus Damm

Hi Dan,

Quoted 3 lines · Dan Carpenter

Generally we take things as is into staging so there is no need for a re-work if you don't want to. But we do need a TODO file. Read the TODO files for other staging drivers.

Thanks for pointing that out, my apologies for being random and skipping that! I will add a TODO file to v2!

Other than the missing TODO file, the idea looks good, I don't have any objections to taking this.

thanks,

greg k-h

#9 lore raw
In reply to Magnus Damm

Hi Magnus,

Thanks for your series! This looks like a good solution for interim board support.

Quoted 3 lines · Magnus Damm

Olof, patch 3/3 contains some board staging code for KZM9D. As it is today the EMEV2 SoC is DT-only and we neither have defconfig nor Kconfig definitions for the KZM9D board (emev2-kzm9d.dts).

Although there's no KZM9D-specific defconfig anymore, support for it is included in shmobile_defconfig, right?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#10 lore raw

Hi Geert,

Quoted 4 lines · Geert Uytterhoeven

Hi Magnus,

Thanks for your series! This looks like a good solution for interim board support.

Thanks!

Quoted 7 lines · Magnus Damm
Quoted 3 lines

Olof, patch 3/3 contains some board staging code for KZM9D. As it is today the EMEV2 SoC is DT-only and we neither have defconfig nor Kconfig definitions for the KZM9D board (emev2-kzm9d.dts).

Although there's no KZM9D-specific defconfig anymore, support for it is included in shmobile_defconfig, right?

Correct, I forgot to mention that.

Thanks,

/ magnus