[U-Boot] [PATCH 00/17] driver model bring-up of musb on AM335x GP and BBB and usb_ether DM conversion

This patch series enables musb driver to adopt driver model. This has been tested on the following evms (logs [1]) by loading kernel and dtb from sata hard-disk. * AM335x GP evm * AM335x BBB
Also pushed a branch for testing [2]
[1] - http://pastebin.ubuntu.com/15239811/ [2] - git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git dm-musb
Mugunthan V N (17): configs: am335x: usb: do not define CONFIG_DM_USB for spl am33xx: board: do not register usb devices when CONFIG_DM_USB is defined drivers: usb: musb: add ti musb misc driver for wrapper am33xx: board: probe misc drivers to register musb devices drivers: usb: musb: adopt musb backend driver to driver model drivers: usb: musb: add ti musb host driver with driver model support drivers: usb: musb: add ti musb peripheral driver with driver model support drivers: usb: gadget: ether: adopt to usb driver model drivers: usb: gadget: ether: access network_started using local variable drivers: usb: gadget: ether: consolidate global devices to single struct drivers: usb: gadget: ether: use net device priv to pass usb ether priv drivers: usb: gadget: ether: prepare driver for driver model migration drivers: usb: gadget: ether/rndis: convert driver to adopt device driver model am33xx: board: init usb ether gadget for rndis support am335x_evm: enable usb ether gadget as it supports DM_ETH defconfig: am335x_boneblack: enable usb driver model defconfig: am335x_gp_evm: enable usb driver model
arch/arm/cpu/armv7/am33xx/board.c | 20 +- arch/arm/include/asm/omap_musb.h | 7 + configs/am335x_boneblack_vboot_defconfig | 4 + configs/am335x_gp_evm_defconfig | 4 + drivers/usb/gadget/ether.c | 314 +++++++++++++++++++----- drivers/usb/gadget/rndis.c | 13 +- drivers/usb/gadget/rndis.h | 19 +- drivers/usb/musb-new/Kconfig | 9 + drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/am35x.c | 35 +++ drivers/usb/musb-new/musb_dsps.c | 20 ++ drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 393 +++++++++++++++++++++++++++++++ include/configs/am335x_evm.h | 4 +- include/net.h | 7 + 15 files changed, 783 insertions(+), 69 deletions(-) create mode 100644 drivers/usb/musb-new/ti-musb.c

Since OMAP's spl doesn't support DM currently, do not define CONFIG_DM_USB for spl build.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- include/configs/am335x_evm.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index 6ebe0b3..d4724d5 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -358,6 +358,7 @@ #ifdef CONFIG_SPL_BUILD #undef CONFIG_DM_MMC #undef CONFIG_TIMER +#undef CONFIG_DM_USB #endif
#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_USBETH_SUPPORT)

On Mon, Feb 29, 2016 at 09:14:04AM +0530, Mugunthan V N wrote:
Since OMAP's spl doesn't support DM currently, do not define CONFIG_DM_USB for spl build.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

Do not register usb devices when CONFIG_DM_USB is define.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- arch/arm/cpu/armv7/am33xx/board.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c index e8d5be3..52e1b36 100644 --- a/arch/arm/cpu/armv7/am33xx/board.c +++ b/arch/arm/cpu/armv7/am33xx/board.c @@ -120,7 +120,8 @@ int cpu_mmc_init(bd_t *bis)
/* AM33XX has two MUSB controllers which can be host or gadget */ #if (defined(CONFIG_USB_MUSB_GADGET) || defined(CONFIG_USB_MUSB_HOST)) && \ - (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1)) + (defined(CONFIG_AM335X_USB0) || defined(CONFIG_AM335X_USB1)) && \ + (!defined(CONFIG_DM_USB)) static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
/* USB 2.0 PHY Control */ @@ -187,6 +188,7 @@ static struct musb_hdrc_platform_data otg1_plat = {
int arch_misc_init(void) { +#ifndef CONFIG_DM_USB #ifdef CONFIG_AM335X_USB0 musb_register(&otg0_plat, &otg0_board_data, (void *)USB0_OTG_BASE); @@ -195,6 +197,7 @@ int arch_misc_init(void) musb_register(&otg1_plat, &otg1_board_data, (void *)USB1_OTG_BASE); #endif +#endif return 0; }

On Mon, Feb 29, 2016 at 09:14:05AM +0530, Mugunthan V N wrote:
Do not register usb devices when CONFIG_DM_USB is define.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI + bool "Enable TI OTG USB controller" + depends on DM_USB + default y + help + Say y here to enable support for the TI OTG USB controller + used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af + asdf asdf fadsf asf s + if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/* + * MISC driver for TI MUSB Glue. + * + * (C) Copyright 2012-2016 + * Texas Instruments Incorporated, <www.ti.com> + * + * SPDX-License-Identifier: GPL-2.0+ + */ +#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h> + +DECLARE_GLOBAL_DATA_PTR; + +#ifdef CONFIG_DM_USB + +static const char *const usb_dr_modes[] = { + [USB_DR_MODE_UNKNOWN] = "", + [USB_DR_MODE_HOST] = "host", + [USB_DR_MODE_PERIPHERAL] = "peripheral", + [USB_DR_MODE_OTG] = "otg", +}; + +enum usb_dr_mode usb_get_dr_mode(const char *dr_mode) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++) + if (!strcmp(dr_mode, usb_dr_modes[i])) + return i; + + return USB_DR_MODE_UNKNOWN; +} + +static int ti_musb_wrapper_bind(struct udevice *parent) +{ + const void *fdt = gd->fdt_blob; + int node; + int ret; + + for (node = fdt_first_subnode(fdt, parent->of_offset); node > 0; + node = fdt_next_subnode(fdt, node)) { + struct udevice *dev; + const char *name = fdt_get_name(fdt, node, NULL); + const char *dr_mode_str; + enum usb_dr_mode dr_mode; + struct driver *drv; + + if (strncmp(name, "usb@", 4)) + continue; + + dr_mode_str = fdt_getprop(fdt, node, "dr_mode", NULL); + if (!dr_mode_str) { + error("usb dr_mode not found\n"); + return -ENOENT; + } + + dr_mode = usb_get_dr_mode(dr_mode_str); + switch (dr_mode) { + case USB_DR_MODE_PERIPHERAL: + /* Bind MUSB device */ + break; + case USB_DR_MODE_HOST: + /* Bind MUSB host */ + break; + default: + break; + }; + } + return 0; +} + +static const struct udevice_id ti_musb_ids[] = { + { .compatible = "ti,am33xx-usb" }, + { } +}; + +U_BOOT_DRIVER(ti_musb_wrapper) = { + .name = "ti-musb-wrapper", + .id = UCLASS_MISC, + .of_match = ti_musb_ids, + .bind = ti_musb_wrapper_bind, +}; + +#endif /* CONFIG_DM_USB */

On Monday 29 February 2016 09:14 AM, Mugunthan V N wrote:
Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI
- bool "Enable TI OTG USB controller"
- depends on DM_USB
- default y
- help
Say y here to enable support for the TI OTG USB controller
used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af
asdf asdf fadsf asf s
Oops!, This was done to fix checkpatch warning temporarily but forgot to fix it properly before submitting. Will fix in v2.
Regards Mugunthan V N
if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/*
- MISC driver for TI MUSB Glue.
- (C) Copyright 2012-2016
Texas Instruments Incorporated, <www.ti.com>
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h>
+DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB
+static const char *const usb_dr_modes[] = {
- [USB_DR_MODE_UNKNOWN] = "",
- [USB_DR_MODE_HOST] = "host",
- [USB_DR_MODE_PERIPHERAL] = "peripheral",
- [USB_DR_MODE_OTG] = "otg",
+};
+enum usb_dr_mode usb_get_dr_mode(const char *dr_mode) +{
- int i;
- for (i = 0; i < ARRAY_SIZE(usb_dr_modes); i++)
if (!strcmp(dr_mode, usb_dr_modes[i]))
return i;
- return USB_DR_MODE_UNKNOWN;
+}
+static int ti_musb_wrapper_bind(struct udevice *parent) +{
- const void *fdt = gd->fdt_blob;
- int node;
- int ret;
- for (node = fdt_first_subnode(fdt, parent->of_offset); node > 0;
node = fdt_next_subnode(fdt, node)) {
struct udevice *dev;
const char *name = fdt_get_name(fdt, node, NULL);
const char *dr_mode_str;
enum usb_dr_mode dr_mode;
struct driver *drv;
if (strncmp(name, "usb@", 4))
continue;
dr_mode_str = fdt_getprop(fdt, node, "dr_mode", NULL);
if (!dr_mode_str) {
error("usb dr_mode not found\n");
return -ENOENT;
}
dr_mode = usb_get_dr_mode(dr_mode_str);
switch (dr_mode) {
case USB_DR_MODE_PERIPHERAL:
/* Bind MUSB device */
break;
case USB_DR_MODE_HOST:
/* Bind MUSB host */
break;
default:
break;
};
- }
- return 0;
+}
+static const struct udevice_id ti_musb_ids[] = {
- { .compatible = "ti,am33xx-usb" },
- { }
+};
+U_BOOT_DRIVER(ti_musb_wrapper) = {
- .name = "ti-musb-wrapper",
- .id = UCLASS_MISC,
- .of_match = ti_musb_ids,
- .bind = ti_musb_wrapper_bind,
+};
+#endif /* CONFIG_DM_USB */

On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI
- bool "Enable TI OTG USB controller"
- depends on DM_USB
- default y
- help
Say y here to enable support for the TI OTG USB controller
used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af
asdf asdf fadsf asf s
if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/*
- MISC driver for TI MUSB Glue.
- (C) Copyright 2012-2016
Texas Instruments Incorporated, <www.ti.com>
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h>
+DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB
+static const char *const usb_dr_modes[] = {
- [USB_DR_MODE_UNKNOWN] = "",
This should probably be "unknown" and not empty string.
- [USB_DR_MODE_HOST] = "host",
- [USB_DR_MODE_PERIPHERAL] = "peripheral",
- [USB_DR_MODE_OTG] = "otg",
+};
[...]

On Monday 29 February 2016 05:32 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI
- bool "Enable TI OTG USB controller"
- depends on DM_USB
- default y
- help
Say y here to enable support for the TI OTG USB controller
used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af
asdf asdf fadsf asf s
if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/*
- MISC driver for TI MUSB Glue.
- (C) Copyright 2012-2016
Texas Instruments Incorporated, <www.ti.com>
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h>
+DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB
+static const char *const usb_dr_modes[] = {
- [USB_DR_MODE_UNKNOWN] = "",
This should probably be "unknown" and not empty string.
I just the followed the Linux way of DT parse implementation.
Regards Mugunthan V N

On Mon, Feb 29, 2016 at 06:51:32PM +0530, Mugunthan V N wrote:
On Monday 29 February 2016 05:32 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI
- bool "Enable TI OTG USB controller"
- depends on DM_USB
- default y
- help
Say y here to enable support for the TI OTG USB controller
used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af
asdf asdf fadsf asf s
if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/*
- MISC driver for TI MUSB Glue.
- (C) Copyright 2012-2016
Texas Instruments Incorporated, <www.ti.com>
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h>
+DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB
+static const char *const usb_dr_modes[] = {
- [USB_DR_MODE_UNKNOWN] = "",
This should probably be "unknown" and not empty string.
I just the followed the Linux way of DT parse implementation.
OK, that sounds like a good reason to keep it the way you did it then.

On 02/29/2016 03:42 PM, Tom Rini wrote:
On Mon, Feb 29, 2016 at 06:51:32PM +0530, Mugunthan V N wrote:
On Monday 29 February 2016 05:32 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Add a misc driver for MUSB wrapper, so that based on dr_mode the USB devices can bind to USB host or USB device drivers.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
drivers/usb/musb-new/Kconfig | 9 +++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 89 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
diff --git a/drivers/usb/musb-new/Kconfig b/drivers/usb/musb-new/Kconfig index 6a6cb93..2bcc646 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -13,6 +13,15 @@ config USB_MUSB_GADGET help Enables the MUSB USB dual-role controller in gadget mode.
+config USB_MUSB_TI
- bool "Enable TI OTG USB controller"
- depends on DM_USB
- default y
- help
Say y here to enable support for the TI OTG USB controller
used on TI SoCs. fadsf fa fad af adf adf asf adfa fad fd af
asdf asdf fadsf asf s
if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_SUNXI diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index 072d516..d137044 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_USB_MUSB_DSPS) += musb_dsps.o obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_SUNXI) += sunxi.o +obj-$(CONFIG_USB_MUSB_TI) += ti-musb.o
ccflags-y := $(call cc-option,-Wno-unused-variable) \ $(call cc-option,-Wno-unused-but-set-variable) \ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c new file mode 100644 index 0000000..c1a4952 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,89 @@ +/*
- MISC driver for TI MUSB Glue.
- (C) Copyright 2012-2016
Texas Instruments Incorporated, <www.ti.com>
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <command.h> +#include <console.h> +#include <dm.h> +#include <linux/usb/otg.h> +#include <dm/device-internal.h> +#include <dm/lists.h>
+DECLARE_GLOBAL_DATA_PTR;
+#ifdef CONFIG_DM_USB
+static const char *const usb_dr_modes[] = {
- [USB_DR_MODE_UNKNOWN] = "",
This should probably be "unknown" and not empty string.
I just the followed the Linux way of DT parse implementation.
OK, that sounds like a good reason to keep it the way you did it then.
Yeah

MUSB wrapper driver is bound as MISC device and underlying usb devices are bind to usb drivers based on dr_mode, so probing the MISC wrapper driver to register musb devices.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- arch/arm/cpu/armv7/am33xx/board.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c index 52e1b36..8211dd6 100644 --- a/arch/arm/cpu/armv7/am33xx/board.c +++ b/arch/arm/cpu/armv7/am33xx/board.c @@ -197,6 +197,13 @@ int arch_misc_init(void) musb_register(&otg1_plat, &otg1_board_data, (void *)USB1_OTG_BASE); #endif +#else + struct udevice *dev; + int ret; + + ret = uclass_first_device(UCLASS_MISC, &dev); + if (ret || !dev) + return ret; #endif return 0; }

On Mon, Feb 29, 2016 at 09:14:07AM +0530, Mugunthan V N wrote:
MUSB wrapper driver is bound as MISC device and underlying usb devices are bind to usb drivers based on dr_mode, so probing the MISC wrapper driver to register musb devices.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

Currently all backend driver ops uses hard coded physical address, so to adopt the driver to DM, add device pointer to ops call backs so that drivers that drivers can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- arch/arm/include/asm/omap_musb.h | 7 +++++++ drivers/usb/musb-new/am35x.c | 35 +++++++++++++++++++++++++++++++++++ drivers/usb/musb-new/musb_dsps.c | 20 ++++++++++++++++++++ 3 files changed, 62 insertions(+)
diff --git a/arch/arm/include/asm/omap_musb.h b/arch/arm/include/asm/omap_musb.h index 8b9cb0e..d358148 100644 --- a/arch/arm/include/asm/omap_musb.h +++ b/arch/arm/include/asm/omap_musb.h @@ -15,9 +15,16 @@ extern const struct musb_platform_ops omap2430_ops;
struct omap_musb_board_data { u8 interface_type; +#ifndef CONFIG_DM_USB void (*set_phy_power)(u8 on); void (*clear_irq)(void); void (*reset)(void); +#else + struct udevice *dev; + void (*set_phy_power)(struct udevice *dev, u8 on); + void (*clear_irq)(struct udevice *dev); + void (*reset)(struct udevice *dev); +#endif };
enum musb_interface {MUSB_INTERFACE_ULPI, MUSB_INTERFACE_UTMI}; diff --git a/drivers/usb/musb-new/am35x.c b/drivers/usb/musb-new/am35x.c index b8791dd..60c8275 100644 --- a/drivers/usb/musb-new/am35x.c +++ b/drivers/usb/musb-new/am35x.c @@ -335,8 +335,13 @@ eoi: /* EOI needs to be written for the IRQ to be re-asserted. */ if (ret == IRQ_HANDLED || epintr || usbintr) { /* clear level interrupt */ +#ifndef CONFIG_DM_USB if (data->clear_irq) data->clear_irq(); +#else + if (data->clear_irq) + data->clear_irq(data->dev); +#endif /* write EOI */ musb_writel(reg_base, USB_END_OF_INTR_REG, 0); } @@ -400,23 +405,38 @@ static int am35x_musb_init(struct musb *musb) #endif
/* Reset the musb */ +#ifndef CONFIG_DM_USB if (data->reset) data->reset(); +#else + if (data->reset) + data->reset(data->dev); +#endif
/* Reset the controller */ musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK);
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 1); +#endif
msleep(5);
musb->isr = am35x_musb_interrupt;
/* clear level interrupt */ +#ifndef CONFIG_DM_USB if (data->clear_irq) data->clear_irq(); +#else + if (data->clear_irq) + data->clear_irq(data->dev); +#endif
return 0; } @@ -437,9 +457,14 @@ static int am35x_musb_exit(struct musb *musb) del_timer_sync(&otg_workaround); #endif
+#ifndef CONFIG_DM_USB /* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) data->set_phy_power(0); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 0); +#endif
#ifndef __UBOOT__ usb_put_phy(musb->xceiv); @@ -628,9 +653,14 @@ static int am35x_suspend(struct device *dev) struct musb_hdrc_platform_data *plat = dev->platform_data; struct omap_musb_board_data *data = plat->board_data;
+#ifndef CONFIG_DM_USB /* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) data->set_phy_power(0); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 0); +#endif
clk_disable(glue->phy_clk); clk_disable(glue->clk); @@ -645,9 +675,14 @@ static int am35x_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data; int ret;
+#ifndef CONFIG_DM_USB /* Start the on-chip PHY and its PLL. */ if (data->set_phy_power) data->set_phy_power(1); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 1); +#endif
ret = clk_enable(glue->phy_clk); if (ret) { diff --git a/drivers/usb/musb-new/musb_dsps.c b/drivers/usb/musb-new/musb_dsps.c index bb7c952..69d2dd8 100644 --- a/drivers/usb/musb-new/musb_dsps.c +++ b/drivers/usb/musb-new/musb_dsps.c @@ -451,8 +451,13 @@ static int dsps_musb_init(struct musb *musb) dsps_writel(reg_base, wrp->control, (1 << wrp->reset));
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 1); +#endif
musb->isr = dsps_interrupt;
@@ -492,8 +497,13 @@ static int dsps_musb_exit(struct musb *musb) #endif
/* Shutdown the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(0); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 0); +#endif
#ifndef __UBOOT__ /* NOP driver needs change if supporting dual instance */ @@ -692,8 +702,13 @@ static int dsps_suspend(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Shutdown the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(0); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 0); +#endif
return 0; } @@ -704,8 +719,13 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else + if (data->set_phy_power) + data->set_phy_power(data->dev, 1); +#endif
return 0; }

On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Currently all backend driver ops uses hard coded physical address, so to adopt the driver to DM, add device pointer to ops call backs so that drivers that drivers can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
[...]
@@ -704,8 +719,13 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else
- if (data->set_phy_power)
data->set_phy_power(data->dev, 1);
Would it be possible to avoid adding this sea of ifdefs into the driver?
+#endif
return 0; }

On Monday 29 February 2016 05:34 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Currently all backend driver ops uses hard coded physical address, so to adopt the driver to DM, add device pointer to ops call backs so that drivers that drivers can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
[...]
@@ -704,8 +719,13 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else
- if (data->set_phy_power)
data->set_phy_power(data->dev, 1);
Would it be possible to avoid adding this sea of ifdefs into the driver?
May be introducing a void pointer and pass it back in ops callback can avoid ifdefs. For non DM mode, it will be holding NULL pointer and for DM mode it will be holding a dev pointer. If its ok, I can fix in v2.
Regards Mugunthan V N

On 02/29/2016 02:26 PM, Mugunthan V N wrote:
On Monday 29 February 2016 05:34 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Currently all backend driver ops uses hard coded physical address, so to adopt the driver to DM, add device pointer to ops call backs so that drivers that drivers can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
[...]
@@ -704,8 +719,13 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else
- if (data->set_phy_power)
data->set_phy_power(data->dev, 1);
Would it be possible to avoid adding this sea of ifdefs into the driver?
May be introducing a void pointer and pass it back in ops callback can avoid ifdefs. For non DM mode, it will be holding NULL pointer and for DM mode it will be holding a dev pointer. If its ok, I can fix in v2.
That looks a bit more sensible, yes. I am worried about problems with dereferencing the data->dev pointer though. But let's see.

On Mon, Feb 29, 2016 at 02:34:41PM +0100, Marek Vasut wrote:
On 02/29/2016 02:26 PM, Mugunthan V N wrote:
On Monday 29 February 2016 05:34 PM, Marek Vasut wrote:
On 02/29/2016 04:44 AM, Mugunthan V N wrote:
Currently all backend driver ops uses hard coded physical address, so to adopt the driver to DM, add device pointer to ops call backs so that drivers that drivers can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
[...]
@@ -704,8 +719,13 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data;
/* Start the on-chip PHY and its PLL. */ +#ifndef CONFIG_DM_USB if (data->set_phy_power) data->set_phy_power(1); +#else
- if (data->set_phy_power)
data->set_phy_power(data->dev, 1);
Would it be possible to avoid adding this sea of ifdefs into the driver?
May be introducing a void pointer and pass it back in ops callback can avoid ifdefs. For non DM mode, it will be holding NULL pointer and for DM mode it will be holding a dev pointer. If its ok, I can fix in v2.
That looks a bit more sensible, yes. I am worried about problems with dereferencing the data->dev pointer though. But let's see.
Maybe looking at how Jagan has the SPI stuff separated to allow for DM/non-DM but without a lot of ifdefs can help here too?

Add a TI MUSB host driver with driver model support and the driver will be bound by the MUSB wrapper driver based on the dr_mode device tree entry.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/musb-new/ti-musb.c | 191 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+)
diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index c1a4952..adc68e6 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -14,10 +14,195 @@ #include <dm/device-internal.h> #include <dm/lists.h>
+#include <asm/io.h> +#include <asm/omap_musb.h> +#include "musb_uboot.h" + DECLARE_GLOBAL_DATA_PTR;
#ifdef CONFIG_DM_USB
+/* USB 2.0 PHY Control */ +#define CM_PHY_PWRDN (1 << 0) +#define CM_PHY_OTG_PWRDN (1 << 1) +#define OTGVDET_EN (1 << 19) +#define OTGSESSENDEN (1 << 20) + +#define AM335X_USB1_CTRL 0x8 + +struct ti_musb_platdata { + void *base; + void *ctrl_mod_base; + struct musb_hdrc_platform_data plat; + struct musb_hdrc_config musb_config; + struct omap_musb_board_data otg_board_data; +}; + +static int ti_musb_get_usb_index(int node) +{ + const void *fdt = gd->fdt_blob; + int i = 0; + char path[64]; + const char *alias_path; + char alias[16]; + + fdt_get_path(fdt, node, path, sizeof(path)); + + do { + snprintf(alias, sizeof(alias), "usb%d", i); + alias_path = fdt_get_alias(fdt, alias); + if (alias_path == NULL) { + debug("USB index not found\n"); + return -ENOENT; + } + + if (!strcmp(path, alias_path)) + return i; + + i++; + } while (alias_path); + + return -ENOENT; +} + +static void ti_musb_set_phy_power(struct udevice *dev, u8 on) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + + if (on) { + clrsetbits_le32(platdata->ctrl_mod_base, + CM_PHY_PWRDN | CM_PHY_OTG_PWRDN, + OTGVDET_EN | OTGSESSENDEN); + } else { + clrsetbits_le32(platdata->ctrl_mod_base, 0, + CM_PHY_PWRDN | CM_PHY_OTG_PWRDN); + } +} + +static int ti_musb_ofdata_to_platdata(struct udevice *dev) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + const void *fdt = gd->fdt_blob; + int node = dev->of_offset; + int phys; + int ctrl_mod; + int usb_index; + + platdata->base = (void *)dev_get_addr_index(dev, 1); + + phys = fdtdec_lookup_phandle(fdt, node, "phys"); + ctrl_mod = fdtdec_lookup_phandle(fdt, phys, "ti,ctrl_mod"); + platdata->ctrl_mod_base = (void *)fdtdec_get_addr(fdt, ctrl_mod, "reg"); + usb_index = ti_musb_get_usb_index(node); + switch (usb_index) { + case 1: + platdata->ctrl_mod_base += AM335X_USB1_CTRL; + case 0: + default: + break; + } + + platdata->musb_config.multipoint = fdtdec_get_int(fdt, node, + "mentor,multipoint", + -1); + if (platdata->musb_config.multipoint < 0) { + error("MUSB multipoint DT entry missing\n"); + return -ENOENT; + } + + platdata->musb_config.dyn_fifo = 1; + + platdata->musb_config.num_eps = fdtdec_get_int(fdt, node, + "mentor,num-eps", -1); + if (platdata->musb_config.num_eps < 0) { + error("MUSB num-eps DT entry missing\n"); + return -ENOENT; + } + + platdata->musb_config.ram_bits = fdtdec_get_int(fdt, node, + "mentor,ram-bits", -1); + if (platdata->musb_config.ram_bits < 0) { + error("MUSB ram-bits DT entry missing\n"); + return -ENOENT; + } + + platdata->otg_board_data.set_phy_power = ti_musb_set_phy_power; + platdata->otg_board_data.dev = dev; + platdata->plat.config = &platdata->musb_config; + + platdata->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1); + if (platdata->plat.power < 0) { + error("MUSB mentor,power DT entry missing\n"); + return -ENOENT; + } + + platdata->plat.platform_ops = &musb_dsps_ops; + platdata->plat.board_data = &platdata->otg_board_data; + + return 0; +} + +static int ti_musb_host_probe(struct udevice *dev) +{ + struct musb_host_data *host = dev_get_priv(dev); + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + struct usb_bus_priv *priv = dev_get_uclass_priv(dev); + struct omap_musb_board_data *otg_board_data; + int ret; + + priv->desc_before_addr = true; + + otg_board_data = &platdata->otg_board_data; + + host->host = musb_init_controller(&platdata->plat, + (struct device *)otg_board_data, + platdata->base); + if (!host->host) + return -EIO; + + ret = musb_lowlevel_init(host); + + return ret; +} + +static int ti_musb_host_remove(struct udevice *dev) +{ + struct musb_host_data *host = dev_get_priv(dev); + + musb_stop(host->host); + + return 0; +} + +static int ti_musb_host_ofdata_to_platdata(struct udevice *dev) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + const void *fdt = gd->fdt_blob; + int node = dev->of_offset; + int ret; + + ret = ti_musb_ofdata_to_platdata(dev); + if (ret) { + error("platdata dt parse error\n"); + return ret; + } + + platdata->plat.mode = MUSB_HOST; + + return 0; +} + +U_BOOT_DRIVER(ti_musb_host) = { + .name = "ti-musb-host", + .id = UCLASS_USB, + .ofdata_to_platdata = ti_musb_host_ofdata_to_platdata, + .probe = ti_musb_host_probe, + .remove = ti_musb_host_remove, + .ops = &musb_usb_ops, + .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata), + .priv_auto_alloc_size = sizeof(struct musb_host_data), +}; + static const char *const usb_dr_modes[] = { [USB_DR_MODE_UNKNOWN] = "", [USB_DR_MODE_HOST] = "host", @@ -66,6 +251,12 @@ static int ti_musb_wrapper_bind(struct udevice *parent) break; case USB_DR_MODE_HOST: /* Bind MUSB host */ + ret = device_bind_driver_to_node(parent, "ti-musb-host", + name, node, &dev); + if (ret) { + error("musb - not able to bind usb host node\n"); + return ret; + } break; default: break;

Add a TI MUSB peripheral driver with driver model support and the driver will be bound by the MUSB wrapper driver based on the dr_mode device tree entry.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 113 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+)
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index 233a0e4..155bc3e 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -371,6 +371,7 @@ struct dm_usb_ops musb_usb_ops = { #endif /* CONFIG_DM_USB */ #endif /* CONFIG_USB_MUSB_HOST */
+#ifndef CONFIG_DM_USB #ifdef CONFIG_USB_MUSB_GADGET static struct musb *gadget;
@@ -451,3 +452,4 @@ int musb_register(struct musb_hdrc_platform_data *plat, void *bdata,
return 0; } +#endif /* CONFIG_DM_USB */ diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index adc68e6..f449a64 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -14,6 +14,7 @@ #include <dm/device-internal.h> #include <dm/lists.h>
+#include <watchdog.h> #include <asm/io.h> #include <asm/omap_musb.h> #include "musb_uboot.h" @@ -142,6 +143,110 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) return 0; }
+static struct musb *gadget; + +int usb_gadget_handle_interrupts(int index) +{ + WATCHDOG_RESET(); + if (!gadget || !gadget->isr) + return -EINVAL; + + return gadget->isr(0, gadget); +} + +int usb_gadget_register_driver(struct usb_gadget_driver *driver) +{ + int ret; + + if (!driver || driver->speed < USB_SPEED_FULL || !driver->bind || + !driver->setup) { + printf("bad parameter.\n"); + return -EINVAL; + } + + if (!gadget) { + printf("Controller uninitialized\n"); + return -ENXIO; + } + + ret = musb_gadget_start(&gadget->g, driver); + if (ret < 0) { + printf("gadget_start failed with %d\n", ret); + return ret; + } + + ret = driver->bind(&gadget->g); + if (ret < 0) { + printf("bind failed with %d\n", ret); + return ret; + } + + return 0; +} + +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) +{ + if (driver->disconnect) + driver->disconnect(&gadget->g); + if (driver->unbind) + driver->unbind(&gadget->g); + return 0; +} + +static int ti_musb_peripheral_usb_probe(struct udevice *dev) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + struct usb_bus_priv *priv = dev_get_uclass_priv(dev); + struct omap_musb_board_data *otg_board_data; + + otg_board_data = &platdata->otg_board_data; + + gadget = musb_init_controller(&platdata->plat, + (struct device *)otg_board_data, + platdata->base); + if (!gadget) { + error("gadget init failed\n"); + return -EIO; + } + + return 0; +} + +static int ti_musb_peripheral_remove(struct udevice *dev) +{ + musb_stop(gadget); + + return 0; +} + +static int ti_musb_peripheral_ofdata_to_platdata(struct udevice *dev) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + const void *fdt = gd->fdt_blob; + int node = dev->of_offset; + int ret; + + ret = ti_musb_ofdata_to_platdata(dev); + if (ret) { + error("platdata dt parse error\n"); + return ret; + } + + platdata->plat.mode = MUSB_PERIPHERAL; + + return 0; +} + +U_BOOT_DRIVER(ti_musb_peripheral) = { + .name = "ti-musb-peripheral", + .id = UCLASS_USB_DEV_GENERIC, + .ofdata_to_platdata = ti_musb_peripheral_ofdata_to_platdata, + .probe = ti_musb_peripheral_usb_probe, + .remove = ti_musb_peripheral_remove, + .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata), + .priv_auto_alloc_size = sizeof(struct musb), +}; + static int ti_musb_host_probe(struct udevice *dev) { struct musb_host_data *host = dev_get_priv(dev); @@ -247,7 +352,15 @@ static int ti_musb_wrapper_bind(struct udevice *parent) dr_mode = usb_get_dr_mode(dr_mode_str); switch (dr_mode) { case USB_DR_MODE_PERIPHERAL: + case USB_DR_MODE_OTG: /* Bind MUSB device */ + ret = device_bind_driver_to_node(parent, + "ti-musb-peripheral", + name, node, &dev); + if (ret) { + error("musb - not able to bind usb device node\n"); + return ret; + } break; case USB_DR_MODE_HOST: /* Bind MUSB host */

Convert usb ether gadget to adopt usb driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 9b06f02..ae5ffcd 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -24,6 +24,10 @@ #include "gadget_chips.h" #include "rndis.h"
+#include <dm.h> +#include <dm/uclass-internal.h> +#include <dm/device-internal.h> + #define USB_NET_NAME "usb_ether"
#define atomic_read @@ -101,6 +105,9 @@ struct eth_dev { struct usb_gadget *gadget; struct usb_request *req; /* for control responses */ struct usb_request *stat_req; /* for cdc & rndis status */ +#ifdef CONFIG_DM_USB + struct udevice *usb_udev; +#endif
u8 config; struct usb_ep *in_ep, *out_ep, *status_ep; @@ -2303,6 +2310,24 @@ fail:
/*-------------------------------------------------------------------------*/
+#ifdef CONFIG_DM_USB +int dm_usb_init(struct eth_dev *e_dev) +{ + struct udevice *dev = NULL; + int ret; + + ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &dev); + if (!dev || ret) { + error("No USB device found\n"); + return -ENODEV; + } + + e_dev->usb_udev = dev; + + return ret; +} +#endif + static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct eth_dev *dev = &l_ethdev; @@ -2315,7 +2340,14 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
+#ifdef CONFIG_DM_USB + if (dm_usb_init(dev)) { + error("USB ether not found\n"); + return -ENODEV; + } +#else board_usb_init(0, USB_INIT_DEVICE); +#endif
/* Configure default mac-addresses for the USB ethernet device */ #ifdef CONFIG_USBNET_DEV_ADDR @@ -2497,7 +2529,11 @@ void usb_eth_halt(struct eth_device *netdev) }
usb_gadget_unregister_driver(ð_driver); +#ifdef CONFIG_DM_USB + device_remove(dev->usb_udev); +#else board_usb_cleanup(0, USB_INIT_DEVICE); +#endif }
static struct usb_gadget_driver eth_driver = {

network_started of struct eth_dev can be accessed using local variable dev and no reason to access it with the global struct.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index ae5ffcd..89e5ab8 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1142,7 +1142,7 @@ static void eth_status_complete(struct usb_ep *ep, struct usb_request *req) event->bNotificationType, value); if (event->bNotificationType == USB_CDC_NOTIFY_SPEED_CHANGE) { - l_ethdev.network_started = 1; + dev->network_started = 1; printf("USB network up!\n"); } } @@ -1330,7 +1330,7 @@ eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) * that network is working. So we signalize it * here. */ - l_ethdev.network_started = 1; + dev->network_started = 1; debug("USB network up!\n"); goto done_set_intf; } @@ -1830,10 +1830,10 @@ static void rndis_control_ack_complete(struct usb_ep *ep, debug("rndis control ack complete --> %d, %d/%d\n", req->status, req->actual, req->length);
- if (!l_ethdev.network_started) { + if (!dev->network_started) { if (rndis_get_state(dev->rndis_config) == RNDIS_DATA_INITIALIZED) { - l_ethdev.network_started = 1; + dev->network_started = 1; printf("USB RNDIS network up!\n"); } } @@ -2389,7 +2389,7 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) timeout = simple_strtoul(getenv("cdc_connect_timeout"), NULL, 10) * CONFIG_SYS_HZ; ts = get_timer(0); - while (!l_ethdev.network_started) { + while (!dev->network_started) { /* Handle control-c and timeouts */ if (ctrlc() || (get_timer(ts) > timeout)) { error("The remote end did not respond in time.");

Consolidate the net device, usb eth device and gadget device struct to single struct and a single global variable so that the same can be passed as priv of ethernet driver.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 53 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 89e5ab8..b40d99a 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -141,9 +141,14 @@ struct eth_dev { */
/*-------------------------------------------------------------------------*/ -static struct eth_dev l_ethdev; -static struct eth_device l_netdev; -static struct usb_gadget_driver eth_driver; +struct ether_priv { + struct eth_dev ethdev; + struct eth_device netdev; + struct usb_gadget_driver eth_driver; +}; + +struct ether_priv eth_priv; +struct ether_priv *l_priv = ð_priv;
/*-------------------------------------------------------------------------*/
@@ -1848,7 +1853,7 @@ static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
static int rndis_control_ack(struct eth_device *net) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; int length; struct usb_request *resp = dev->stat_req;
@@ -1989,7 +1994,7 @@ static int get_ether_addr(const char *str, u8 *dev_addr)
static int eth_bind(struct usb_gadget *gadget) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; u8 cdc = 1, zlp = 1, rndis = 1; struct usb_ep *in_ep, *out_ep, *status_ep = NULL; int status = -ENOMEM; @@ -2182,7 +2187,7 @@ autoconf_fail:
/* network device setup */ - dev->net = &l_netdev; + dev->net = &l_priv->netdev;
dev->cdc = cdc; dev->zlp = zlp; @@ -2330,7 +2335,7 @@ int dm_usb_init(struct eth_dev *e_dev)
static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; struct usb_gadget *gadget; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2374,7 +2379,15 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
- if (usb_gadget_register_driver(ð_driver) < 0) + l_priv->eth_driver.speed = DEVSPEED; + l_priv->eth_driver.bind = eth_bind; + l_priv->eth_driver.unbind = eth_unbind; + l_priv->eth_driver.setup = eth_setup; + l_priv->eth_driver.reset = eth_disconnect; + l_priv->eth_driver.disconnect = eth_disconnect; + l_priv->eth_driver.suspend = eth_suspend; + l_priv->eth_driver.resume = eth_resume; + if (usb_gadget_register_driver(&l_priv->eth_driver) < 0) goto fail;
dev->network_started = 0; @@ -2409,7 +2422,7 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2476,7 +2489,7 @@ drop:
static int usb_eth_recv(struct eth_device *netdev) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev;
usb_gadget_handle_interrupts(0);
@@ -2496,7 +2509,7 @@ static int usb_eth_recv(struct eth_device *netdev)
void usb_eth_halt(struct eth_device *netdev) { - struct eth_dev *dev = &l_ethdev; + struct eth_dev *dev = &l_priv->ethdev;
if (!netdev) { error("received NULL ptr"); @@ -2528,7 +2541,7 @@ void usb_eth_halt(struct eth_device *netdev) dev->network_started = 0; }
- usb_gadget_unregister_driver(ð_driver); + usb_gadget_unregister_driver(&l_priv->eth_driver); #ifdef CONFIG_DM_USB device_remove(dev->usb_udev); #else @@ -2536,23 +2549,9 @@ void usb_eth_halt(struct eth_device *netdev) #endif }
-static struct usb_gadget_driver eth_driver = { - .speed = DEVSPEED, - - .bind = eth_bind, - .unbind = eth_unbind, - - .setup = eth_setup, - .reset = eth_disconnect, - .disconnect = eth_disconnect, - - .suspend = eth_suspend, - .resume = eth_resume, -}; - int usb_eth_initialize(bd_t *bi) { - struct eth_device *netdev = &l_netdev; + struct eth_device *netdev = &l_priv->netdev;
strlcpy(netdev->name, USB_NET_NAME, sizeof(netdev->name));

Use net device priv to pass usb ether priv and use it in net device ops callback.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index b40d99a..47071c3 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -1853,7 +1853,8 @@ static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
static int rndis_control_ack(struct eth_device *net) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)net->priv; + struct eth_dev *dev = &priv->ethdev; int length; struct usb_request *resp = dev->stat_req;
@@ -2335,16 +2336,12 @@ int dm_usb_init(struct eth_dev *e_dev)
static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; struct usb_gadget *gadget; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT;
- if (!netdev) { - error("received NULL ptr"); - goto fail; - } - #ifdef CONFIG_DM_USB if (dm_usb_init(dev)) { error("USB ether not found\n"); @@ -2379,15 +2376,15 @@ static int usb_eth_init(struct eth_device *netdev, bd_t *bd) goto fail; }
- l_priv->eth_driver.speed = DEVSPEED; - l_priv->eth_driver.bind = eth_bind; - l_priv->eth_driver.unbind = eth_unbind; - l_priv->eth_driver.setup = eth_setup; - l_priv->eth_driver.reset = eth_disconnect; - l_priv->eth_driver.disconnect = eth_disconnect; - l_priv->eth_driver.suspend = eth_suspend; - l_priv->eth_driver.resume = eth_resume; - if (usb_gadget_register_driver(&l_priv->eth_driver) < 0) + priv->eth_driver.speed = DEVSPEED; + priv->eth_driver.bind = eth_bind; + priv->eth_driver.unbind = eth_unbind; + priv->eth_driver.setup = eth_setup; + priv->eth_driver.reset = eth_disconnect; + priv->eth_driver.disconnect = eth_disconnect; + priv->eth_driver.suspend = eth_suspend; + priv->eth_driver.resume = eth_resume; + if (usb_gadget_register_driver(&priv->eth_driver) < 0) goto fail;
dev->network_started = 0; @@ -2422,7 +2419,8 @@ static int usb_eth_send(struct eth_device *netdev, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -2489,7 +2487,8 @@ drop:
static int usb_eth_recv(struct eth_device *netdev) { - struct eth_dev *dev = &l_priv->ethdev; + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev;
usb_gadget_handle_interrupts(0);
@@ -2509,12 +2508,8 @@ static int usb_eth_recv(struct eth_device *netdev)
void usb_eth_halt(struct eth_device *netdev) { - struct eth_dev *dev = &l_priv->ethdev; - - if (!netdev) { - error("received NULL ptr"); - return; - } + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev;
/* If the gadget not registered, simple return */ if (!dev->gadget) @@ -2541,7 +2536,7 @@ void usb_eth_halt(struct eth_device *netdev) dev->network_started = 0; }
- usb_gadget_unregister_driver(&l_priv->eth_driver); + usb_gadget_unregister_driver(&priv->eth_driver); #ifdef CONFIG_DM_USB device_remove(dev->usb_udev); #else @@ -2559,6 +2554,7 @@ int usb_eth_initialize(bd_t *bi) netdev->send = usb_eth_send; netdev->recv = usb_eth_recv; netdev->halt = usb_eth_halt; + netdev->priv = l_priv;
#ifdef CONFIG_MCAST_TFTP #error not supported

prepare driver for driver model migration
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 72 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 21 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 47071c3..2f70ebf 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -2334,9 +2334,8 @@ int dm_usb_init(struct eth_dev *e_dev) } #endif
-static int usb_eth_init(struct eth_device *netdev, bd_t *bd) +static int _usb_eth_init(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev; struct usb_gadget *gadget; unsigned long ts; @@ -2415,11 +2414,10 @@ fail: return -1; }
-static int usb_eth_send(struct eth_device *netdev, void *packet, int length) +static int _usb_eth_send(struct ether_priv *priv, void *packet, int length) { int retval; void *rndis_pkt = NULL; - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev; struct usb_request *req = dev->tx_req; unsigned long ts; @@ -2485,30 +2483,15 @@ drop: return -ENOMEM; }
-static int usb_eth_recv(struct eth_device *netdev) +static int _usb_eth_recv(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; - struct eth_dev *dev = &priv->ethdev; - usb_gadget_handle_interrupts(0);
- if (packet_received) { - debug("%s: packet received\n", __func__); - if (dev->rx_req) { - net_process_received_packet(net_rx_packets[0], - dev->rx_req->length); - packet_received = 0; - - rx_submit(dev, dev->rx_req, 0); - } else - error("dev->rx_req invalid"); - } return 0; }
-void usb_eth_halt(struct eth_device *netdev) +void _usb_eth_halt(struct ether_priv *priv) { - struct ether_priv *priv = (struct ether_priv *)netdev->priv; struct eth_dev *dev = &priv->ethdev;
/* If the gadget not registered, simple return */ @@ -2544,6 +2527,53 @@ void usb_eth_halt(struct eth_device *netdev) #endif }
+static int usb_eth_init(struct eth_device *netdev, bd_t *bd) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + return _usb_eth_init(priv); +} + +static int usb_eth_send(struct eth_device *netdev, void *packet, int length) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + return _usb_eth_send(priv, packet, length); +} + +static int usb_eth_recv(struct eth_device *netdev) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + struct eth_dev *dev = &priv->ethdev; + int ret; + + ret = _usb_eth_recv(priv); + if (ret) { + error("error packet receive\n"); + return ret; + } + + if (packet_received) { + if (dev->rx_req) { + net_process_received_packet(net_rx_packets[0], + dev->rx_req->length); + } else { + error("dev->rx_req invalid"); + } + packet_received = 0; + rx_submit(dev, dev->rx_req, 0); + } + + return 0; +} + +void usb_eth_halt(struct eth_device *netdev) +{ + struct ether_priv *priv = (struct ether_priv *)netdev->priv; + + _usb_eth_halt(priv); +} + int usb_eth_initialize(bd_t *bi) { struct eth_device *netdev = &l_priv->netdev;

Adopt usb ether gadget and rndis driver to adopt driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- drivers/usb/gadget/ether.c | 153 ++++++++++++++++++++++++++++++++++++++++++--- drivers/usb/gadget/rndis.c | 13 +++- drivers/usb/gadget/rndis.h | 19 ++++-- include/net.h | 7 +++ 4 files changed, 177 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 2f70ebf..c436f75 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -25,6 +25,7 @@ #include "rndis.h"
#include <dm.h> +#include <dm/lists.h> #include <dm/uclass-internal.h> #include <dm/device-internal.h>
@@ -116,7 +117,11 @@ struct eth_dev {
struct usb_request *tx_req, *rx_req;
+#ifndef CONFIG_DM_ETH struct eth_device *net; +#else + struct udevice *net; +#endif struct net_device_stats stats; unsigned int tx_qlen;
@@ -143,7 +148,11 @@ struct eth_dev { /*-------------------------------------------------------------------------*/ struct ether_priv { struct eth_dev ethdev; +#ifndef CONFIG_DM_ETH struct eth_device netdev; +#else + struct udevice *netdev; +#endif struct usb_gadget_driver eth_driver; };
@@ -1851,7 +1860,11 @@ static void rndis_control_ack_complete(struct usb_ep *ep,
static char rndis_resp_buf[8] __attribute__((aligned(sizeof(__le32))));
+#ifndef CONFIG_DM_ETH static int rndis_control_ack(struct eth_device *net) +#else +static int rndis_control_ack(struct udevice *net) +#endif { struct ether_priv *priv = (struct ether_priv *)net->priv; struct eth_dev *dev = &priv->ethdev; @@ -2001,6 +2014,9 @@ static int eth_bind(struct usb_gadget *gadget) int status = -ENOMEM; int gcnum; u8 tmp[7]; +#ifdef CONFIG_DM_ETH + struct eth_pdata *pdata = dev_get_platdata(l_priv->netdev); +#endif
/* these flags are only ever cleared; compiler take note */ #ifndef CONFIG_USB_ETH_CDC @@ -2188,7 +2204,11 @@ autoconf_fail:
/* network device setup */ +#ifndef CONFIG_DM_ETH dev->net = &l_priv->netdev; +#else + dev->net = l_priv->netdev; +#endif
dev->cdc = cdc; dev->zlp = zlp; @@ -2197,6 +2217,7 @@ autoconf_fail: dev->out_ep = out_ep; dev->status_ep = status_ep;
+ memset(tmp, 0, sizeof(tmp)); /* * Module params for these addresses should come from ID proms. * The host side address is used with CDC and RNDIS, and commonly @@ -2204,10 +2225,13 @@ autoconf_fail: * host side code for the SAFE thing cares -- its original BLAN * thing didn't, Sharp never assigned those addresses on Zaurii. */ +#ifndef CONFIG_DM_ETH get_ether_addr(dev_addr, dev->net->enetaddr); - - memset(tmp, 0, sizeof(tmp)); memcpy(tmp, dev->net->enetaddr, sizeof(dev->net->enetaddr)); +#else + get_ether_addr(dev_addr, pdata->enetaddr); + memcpy(tmp, pdata->enetaddr, sizeof(pdata->enetaddr)); +#endif
get_ether_addr(host_addr, dev->host_mac);
@@ -2268,10 +2292,11 @@ autoconf_fail: status_ep ? " STATUS " : "", status_ep ? status_ep->name : "" ); - printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", - dev->net->enetaddr[0], dev->net->enetaddr[1], - dev->net->enetaddr[2], dev->net->enetaddr[3], - dev->net->enetaddr[4], dev->net->enetaddr[5]); +#ifndef CONFIG_DM_ETH + printf("MAC %pM\n", dev->net->enetaddr); +#else + printf("MAC %pM\n", pdata->enetaddr); +#endif
if (cdc || rndis) printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n", @@ -2520,13 +2545,12 @@ void _usb_eth_halt(struct ether_priv *priv) }
usb_gadget_unregister_driver(&priv->eth_driver); -#ifdef CONFIG_DM_USB - device_remove(dev->usb_udev); -#else +#ifndef CONFIG_DM_USB board_usb_cleanup(0, USB_INIT_DEVICE); #endif }
+#ifndef CONFIG_DM_ETH static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { struct ether_priv *priv = (struct ether_priv *)netdev->priv; @@ -2592,3 +2616,114 @@ int usb_eth_initialize(bd_t *bi) eth_register(netdev); return 0; } +#else +static int usb_eth_start(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + + return _usb_eth_init(priv); +} + +static int usb_eth_send(struct udevice *dev, void *packet, int length) +{ + struct ether_priv *priv = dev_get_priv(dev); + + return _usb_eth_send(priv, packet, length); +} + +static int usb_eth_recv(struct udevice *dev, int flags, uchar **packetp) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_dev *ethdev = &priv->ethdev; + int ret; + + ret = _usb_eth_recv(priv); + if (ret) { + error("error packet receive\n"); + return ret; + } + + if (packet_received) { + if (ethdev->rx_req) { + *packetp = (uchar *)net_rx_packets[0]; + return ethdev->rx_req->length; + } else { + error("dev->rx_req invalid"); + return -EFAULT; + } + } + + return -EAGAIN; +} + +static int usb_eth_free_pkt(struct udevice *dev, uchar *packet, + int length) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_dev *ethdev = &priv->ethdev; + + packet_received = 0; + + return rx_submit(ethdev, ethdev->rx_req, 0); +} + +static void usb_eth_stop(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + + _usb_eth_halt(priv); +} + +static int usb_eth_probe(struct udevice *dev) +{ + struct ether_priv *priv = dev_get_priv(dev); + struct eth_pdata *pdata = dev_get_platdata(dev); + + priv->netdev = dev; + l_priv = priv; + + get_ether_addr("de:ad:be:ef:00:01", pdata->enetaddr); + eth_setenv_enetaddr("usbnet_devaddr", pdata->enetaddr); + + return 0; +} + +static const struct eth_ops usb_eth_ops = { + .start = usb_eth_start, + .send = usb_eth_send, + .recv = usb_eth_recv, + .free_pkt = usb_eth_free_pkt, + .stop = usb_eth_stop, +}; + +int usb_ether_init(void) +{ + struct udevice *dev; + struct udevice *usb_dev; + int ret; + + ret = uclass_first_device(UCLASS_USB_DEV_GENERIC, &usb_dev); + if (!usb_dev || ret) { + error("No USB device found\n"); + return ret; + } + + ret = device_bind_driver(usb_dev, "usb_ether", "usb_ether", &dev); + if (!dev || ret) { + error("usb - not able to bind usb_ether device\n"); + return ret; + } + + return 0; +} + +U_BOOT_DRIVER(eth_usb) = { + .name = "usb_ether", + .id = UCLASS_ETH, + .probe = usb_eth_probe, + .ops = &usb_eth_ops, + .priv_auto_alloc_size = sizeof(struct ether_priv), + .platdata_auto_alloc_size = sizeof(struct eth_pdata), + .flags = DM_FLAG_ALLOC_PRIV_DMA, +}; +#endif /* CONFIG_DM_ETH */ diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c index 48463db..e6029ec 100644 --- a/drivers/usb/gadget/rndis.c +++ b/drivers/usb/gadget/rndis.c @@ -1123,7 +1123,11 @@ int rndis_msg_parser(u8 configNr, u8 *buf) return -ENOTSUPP; }
+#ifndef CONFIG_DM_ETH int rndis_register(int (*rndis_control_ack)(struct eth_device *)) +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)) +#endif { u8 i;
@@ -1151,8 +1155,13 @@ void rndis_deregister(int configNr) return; }
-int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, - struct net_device_stats *stats, u16 *cdc_filter) +#ifndef CONFIG_DM_ETH +int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter) +#else +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter) +#endif { debug("%s: configNr = %d\n", __func__, configNr); if (!dev || !stats) diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h index 7a389a5..084af85 100644 --- a/drivers/usb/gadget/rndis.h +++ b/drivers/usb/gadget/rndis.h @@ -222,23 +222,34 @@ typedef struct rndis_params {
const u8 *host_mac; u16 *filter; - struct eth_device *dev; struct net_device_stats *stats; int mtu;
u32 vendorID; const char *vendorDescr; - int (*ack)(struct eth_device *); +#ifndef CONFIG_DM_ETH + struct eth_device *dev; + int (*ack)(struct eth_device *); +#else + struct udevice *dev; + int (*ack)(struct udevice *); +#endif struct list_head resp_queue; } rndis_params;
/* RNDIS Message parser and other useless functions */ int rndis_msg_parser(u8 configNr, u8 *buf); enum rndis_state rndis_get_state(int configNr); -int rndis_register(int (*rndis_control_ack)(struct eth_device *)); void rndis_deregister(int configNr); +#ifndef CONFIG_DM_ETH +int rndis_register(int (*rndis_control_ack)(struct eth_device *)); int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu, - struct net_device_stats *stats, u16 *cdc_filter); + struct net_device_stats *stats, u16 *cdc_filter); +#else +int rndis_register(int (*rndis_control_ack)(struct udevice *)); +int rndis_set_param_dev(u8 configNr, struct udevice *dev, int mtu, + struct net_device_stats *stats, u16 *cdc_filter); +#endif int rndis_set_param_vendor(u8 configNr, u32 vendorID, const char *vendorDescr); int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed); diff --git a/include/net.h b/include/net.h index a739f45..fea6561 100644 --- a/include/net.h +++ b/include/net.h @@ -238,6 +238,13 @@ int eth_getenv_enetaddr(const char *name, uchar *enetaddr); int eth_setenv_enetaddr(const char *name, const uchar *enetaddr);
/* + * Initialize USB ethernet device with CONFIG_DM_ETH + * Returns: + * 0 is success, non-zero is error status. + */ +int usb_ether_init(void); + +/* * Get the hardware address for an ethernet interface . * Args: * base_name - base name for device (normally "eth")

Add usb ether gadget device with usb_ether_init() when CONFIG_DM_ETH and CONFIG_USB_ETHER are defined.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- arch/arm/cpu/armv7/am33xx/board.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c index 8211dd6..a006e97 100644 --- a/arch/arm/cpu/armv7/am33xx/board.c +++ b/arch/arm/cpu/armv7/am33xx/board.c @@ -204,6 +204,14 @@ int arch_misc_init(void) ret = uclass_first_device(UCLASS_MISC, &dev); if (ret || !dev) return ret; + +#if defined(CONFIG_DM_ETH) && defined(CONFIG_USB_ETHER) + ret = usb_ether_init(); + if (ret) { + error("USB ether init failed\n"); + return ret; + } +#endif #endif return 0; }

On Mon, Feb 29, 2016 at 09:14:17AM +0530, Mugunthan V N wrote:
Add usb ether gadget device with usb_ether_init() when CONFIG_DM_ETH and CONFIG_USB_ETHER are defined.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

Since usb ether gadget have support for driver model, so enable usb ether gadget.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- include/configs/am335x_evm.h | 3 --- 1 file changed, 3 deletions(-)
diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index d4724d5..da7aa49 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -338,12 +338,9 @@ #endif
#ifdef CONFIG_USB_MUSB_GADGET -/* Removing USB gadget and can be enabled adter adding support usb DM */ -#ifndef CONFIG_DM_ETH #define CONFIG_USB_ETHER #define CONFIG_USB_ETH_RNDIS #define CONFIG_USBNET_HOST_ADDR "de:ad:be:af:00:00" -#endif /* CONFIG_DM_ETH */
/* USB TI's IDs */ #define CONFIG_G_DNL_VENDOR_NUM 0x0451

On Mon, Feb 29, 2016 at 09:14:18AM +0530, Mugunthan V N wrote:
Since usb ether gadget have support for driver model, so enable usb ether gadget.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

enable usb driver model for am335x bbb as musb supports driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- configs/am335x_boneblack_vboot_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/configs/am335x_boneblack_vboot_defconfig b/configs/am335x_boneblack_vboot_defconfig index 060aa1c..7fb0ff9 100644 --- a/configs/am335x_boneblack_vboot_defconfig +++ b/configs/am335x_boneblack_vboot_defconfig @@ -24,3 +24,7 @@ CONFIG_DM_ETH=y CONFIG_SYS_NS16550=y CONFIG_TIMER=y CONFIG_OMAP_TIMER=y +CONFIG_MISC=y +CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_USB_MUSB_TI=y

On Mon, Feb 29, 2016 at 09:14:19AM +0530, Mugunthan V N wrote:
enable usb driver model for am335x bbb as musb supports driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com

enable usb driver model for am335x gp evm as musb supports driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- configs/am335x_gp_evm_defconfig | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/configs/am335x_gp_evm_defconfig b/configs/am335x_gp_evm_defconfig index 49461e2..ff0f667 100644 --- a/configs/am335x_gp_evm_defconfig +++ b/configs/am335x_gp_evm_defconfig @@ -18,3 +18,7 @@ CONFIG_SYS_NS16550=y CONFIG_RSA=y CONFIG_TIMER=y CONFIG_OMAP_TIMER=y +CONFIG_MISC=y +CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_USB_MUSB_TI=y

On Mon, Feb 29, 2016 at 09:14:20AM +0530, Mugunthan V N wrote:
enable usb driver model for am335x gp evm as musb supports driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com
Reviewed-by: Tom Rini trini@konsulko.com
participants (3)
-
Marek Vasut
-
Mugunthan V N
-
Tom Rini