[U-Boot] [PATCH v3 00/10] driver model bring-up of musb on AM335x GP and BBB

This patch series enables musb driver to adopt driver model. This has been tested on the following evms (logs [1]) by loading kernel and dtbs from usb mass storage (host) and usb rndis mode (device). * AM335x GP evm * AM335x BBB
Also pushed a branch for testing [2]
This patch series depends on the following patch series * usb ether gadget DM conversion [4]
Changes from v2: * Removed from non-useful error logs. * Since defconfig is merged into single defconfig for all TI AM335x platforms, rebased those patches as well.
Changes from initial version: * Separated out the usb gadget driver patches from earlier musb series [3] for testing and submitting of dwc3 dm musb patches. * passed an dummy dev pointer for non-DM case as well for reducing the number of #ifdefs in musb backend driver.
[1] - http://pastebin.ubuntu.com/23489333/ [2] - git://git.ti.com/~mugunthanvnm/ti-u-boot/mugunth-ti-u-boot.git dm-musb-v3 [3] - http://lists.denx.de/pipermail/u-boot/2016-February/246827.html [4] - http://lists.denx.de/pipermail/u-boot/2016-November/273037.html
Note: ~~~~~ The following checkpatch warning can be ignore as splitting the line will break grep during debug session. WARNING: line over 80 characters #224: FILE: drivers/usb/musb-new/ti-musb.c:232: + error("musb - not able to bind usb host node\n");
total: 0 errors, 1 warnings, 0 checks, 207 lines checked
NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE PREFER_ETHER_ADDR_COPY USLEEP_RANGE
../dm-musb/patches/musb/v3.00/0006-drivers-usb-musb-add-ti-musb-host-driver-with-driver.patch has style problems, please review.
If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. WARNING: line over 80 characters #164: FILE: drivers/usb/musb-new/ti-musb.c:332: + error("musb - not able to bind usb device node\n");
total: 0 errors, 1 warnings, 0 checks, 139 lines checked
NOTE: Ignored message types: COMPLEX_MACRO CONSIDER_KSTRTO MINMAX MULTISTATEMENT_MACRO_USE_DO_WHILE NETWORKING_BLOCK_COMMENT_STYLE PREFER_ETHER_ADDR_COPY USLEEP_RANGE
../dm-musb/patches/musb/v3.00/0007-drivers-usb-musb-add-ti-musb-peripheral-driver-with-.patch has style problems, please review.
If any of these errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS. total: 0 errors, 0 warnings, 0 checks, 14 lines checked
Mugunthan V N (10): 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 am33xx: board: init usb ether gadget for rndis support am335x_evm: enable usb ether gadget as it supports DM_ETH defconfig: am335x_evm: enable usb driver model
arch/arm/cpu/armv7/am33xx/board.c | 24 ++- arch/arm/cpu/armv7/omap3/am35x_musb.c | 6 +- arch/arm/include/asm/arch-omap3/musb.h | 6 +- arch/arm/include/asm/omap_musb.h | 7 +- configs/am335x_evm_defconfig | 3 + drivers/usb/musb-new/Kconfig | 9 + drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/am35x.c | 14 +- drivers/usb/musb-new/musb_dsps.c | 8 +- drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 364 +++++++++++++++++++++++++++++++++ include/configs/am335x_evm.h | 4 +- 12 files changed, 422 insertions(+), 26 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 Reviewed-by: Tom Rini trini@konsulko.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 ec70b72970..8e62248c73 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -316,6 +316,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 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
include/configs/am335x_evm.h | 1 + 1 file changed, 1 insertion(+)
Applied to u-boot-dm, thanks!

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 --- 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 68badedd14..fd4235e526 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 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
arch/arm/cpu/armv7/am33xx/board.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Applied to u-boot-dm, thanks!

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 Reviewed-by: Tom Rini trini@konsulko.com --- drivers/usb/musb-new/Kconfig | 9 ++++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 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 c264859b6c..caba42c26f 100644 --- a/drivers/usb/musb-new/Kconfig +++ b/drivers/usb/musb-new/Kconfig @@ -14,6 +14,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 n + help + Say y here to enable support for the dual role high + speed USB controller based on the Mentor Graphics + silicon IP. + if USB_MUSB_HOST || USB_MUSB_GADGET
config USB_MUSB_PIC32 diff --git a/drivers/usb/musb-new/Makefile b/drivers/usb/musb-new/Makefile index df1c3c8a45..296f230fbf 100644 --- a/drivers/usb/musb-new/Makefile +++ b/drivers/usb/musb-new/Makefile @@ -12,6 +12,7 @@ obj-$(CONFIG_USB_MUSB_AM35X) += am35x.o obj-$(CONFIG_USB_MUSB_OMAP2PLUS) += omap2430.o obj-$(CONFIG_USB_MUSB_PIC32) += pic32.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 0000000000..cf0e296bd0 --- /dev/null +++ b/drivers/usb/musb-new/ti-musb.c @@ -0,0 +1,64 @@ +/* + * MISC driver for TI MUSB Glue. + * + * (C) Copyright 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 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); + enum usb_dr_mode dr_mode; + struct driver *drv; + + if (strncmp(name, "usb@", 4)) + continue; + + dr_mode = usb_get_dr_mode(node); + 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 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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 Reviewed-by: Tom Rini trini@konsulko.com
drivers/usb/musb-new/Kconfig | 9 ++++++ drivers/usb/musb-new/Makefile | 1 + drivers/usb/musb-new/ti-musb.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 drivers/usb/musb-new/ti-musb.c
Applied to u-boot-dm, thanks!

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 --- 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 fd4235e526..c3f50e9733 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 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
arch/arm/cpu/armv7/am33xx/board.c | 7 +++++++ 1 file changed, 7 insertions(+)
Applied to u-boot-dm, thanks!

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 can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Tom Rini trini@konsulko.com --- arch/arm/cpu/armv7/am33xx/board.c | 4 ++-- arch/arm/cpu/armv7/omap3/am35x_musb.c | 6 +++--- arch/arm/include/asm/arch-omap3/musb.h | 6 +++--- arch/arm/include/asm/omap_musb.h | 7 ++++--- drivers/usb/musb-new/am35x.c | 14 +++++++------- drivers/usb/musb-new/musb_dsps.c | 8 ++++---- 6 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/arch/arm/cpu/armv7/am33xx/board.c b/arch/arm/cpu/armv7/am33xx/board.c index c3f50e9733..245a9575ec 100644 --- a/arch/arm/cpu/armv7/am33xx/board.c +++ b/arch/arm/cpu/armv7/am33xx/board.c @@ -148,7 +148,7 @@ static struct musb_hdrc_config musb_config = { };
#ifdef CONFIG_AM335X_USB0 -static void am33xx_otg0_set_phy_power(u8 on) +static void am33xx_otg0_set_phy_power(struct udevice *dev, u8 on) { am33xx_usb_set_phy_power(on, &cdev->usb_ctrl0); } @@ -167,7 +167,7 @@ static struct musb_hdrc_platform_data otg0_plat = { #endif
#ifdef CONFIG_AM335X_USB1 -static void am33xx_otg1_set_phy_power(u8 on) +static void am33xx_otg1_set_phy_power(struct udevice *dev, u8 on) { am33xx_usb_set_phy_power(on, &cdev->usb_ctrl1); } diff --git a/arch/arm/cpu/armv7/omap3/am35x_musb.c b/arch/arm/cpu/armv7/omap3/am35x_musb.c index 74dd105eb6..d542699ab0 100644 --- a/arch/arm/cpu/armv7/omap3/am35x_musb.c +++ b/arch/arm/cpu/armv7/omap3/am35x_musb.c @@ -13,7 +13,7 @@ #include <asm/io.h> #include <asm/arch/am35x_def.h>
-void am35x_musb_reset(void) +void am35x_musb_reset(struct udevice *dev) { /* Reset the musb interface */ clrsetbits_le32(&am35x_scm_general_regs->ip_sw_reset, @@ -22,7 +22,7 @@ void am35x_musb_reset(void) USBOTGSS_SW_RST, 0); }
-void am35x_musb_phy_power(u8 on) +void am35x_musb_phy_power(struct udevice *dev, u8 on) { unsigned long start = get_timer(0);
@@ -53,7 +53,7 @@ void am35x_musb_phy_power(u8 on) } }
-void am35x_musb_clear_irq(void) +void am35x_musb_clear_irq(struct udevice *dev) { clrsetbits_le32(&am35x_scm_general_regs->lvl_intr_clr, 0, USBOTGSS_INT_CLR); diff --git a/arch/arm/include/asm/arch-omap3/musb.h b/arch/arm/include/asm/arch-omap3/musb.h index cee4ed311e..d06a758f1b 100644 --- a/arch/arm/include/asm/arch-omap3/musb.h +++ b/arch/arm/include/asm/arch-omap3/musb.h @@ -7,7 +7,7 @@
#ifndef __ASM_ARCH_OMAP3_MUSB_H #define __ASM_ARCH_OMAP3_MUSB_H -extern void am35x_musb_reset(void); -extern void am35x_musb_phy_power(u8 on); -extern void am35x_musb_clear_irq(void); +void am35x_musb_reset(struct udevice *dev); +void am35x_musb_phy_power(struct udevice *dev, u8 on); +void am35x_musb_clear_irq(struct udevice *dev); #endif diff --git a/arch/arm/include/asm/omap_musb.h b/arch/arm/include/asm/omap_musb.h index 8b9cb0eb8f..7c5fb40774 100644 --- a/arch/arm/include/asm/omap_musb.h +++ b/arch/arm/include/asm/omap_musb.h @@ -15,9 +15,10 @@ extern const struct musb_platform_ops omap2430_ops;
struct omap_musb_board_data { u8 interface_type; - void (*set_phy_power)(u8 on); - void (*clear_irq)(void); - void (*reset)(void); + struct udevice *dev; + void (*set_phy_power)(struct udevice *dev, u8 on); + void (*clear_irq)(struct udevice *dev); + void (*reset)(struct udevice *dev); };
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 b8791ddd5c..0167ea7797 100644 --- a/drivers/usb/musb-new/am35x.c +++ b/drivers/usb/musb-new/am35x.c @@ -336,7 +336,7 @@ eoi: if (ret == IRQ_HANDLED || epintr || usbintr) { /* clear level interrupt */ if (data->clear_irq) - data->clear_irq(); + data->clear_irq(data->dev); /* write EOI */ musb_writel(reg_base, USB_END_OF_INTR_REG, 0); } @@ -401,14 +401,14 @@ static int am35x_musb_init(struct musb *musb)
/* Reset the musb */ if (data->reset) - data->reset(); + data->reset(data->dev);
/* Reset the controller */ musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK);
/* Start the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(1); + data->set_phy_power(data->dev, 1);
msleep(5);
@@ -416,7 +416,7 @@ static int am35x_musb_init(struct musb *musb)
/* clear level interrupt */ if (data->clear_irq) - data->clear_irq(); + data->clear_irq(data->dev);
return 0; } @@ -439,7 +439,7 @@ static int am35x_musb_exit(struct musb *musb)
/* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(0); + data->set_phy_power(data->dev, 0);
#ifndef __UBOOT__ usb_put_phy(musb->xceiv); @@ -630,7 +630,7 @@ static int am35x_suspend(struct device *dev)
/* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(0); + data->set_phy_power(data->dev, 0);
clk_disable(glue->phy_clk); clk_disable(glue->clk); @@ -647,7 +647,7 @@ static int am35x_resume(struct device *dev)
/* Start the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(1); + data->set_phy_power(data->dev, 1);
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 a71db76d7c..399b85bbce 100644 --- a/drivers/usb/musb-new/musb_dsps.c +++ b/drivers/usb/musb-new/musb_dsps.c @@ -452,7 +452,7 @@ static int dsps_musb_init(struct musb *musb)
/* Start the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(1); + data->set_phy_power(data->dev, 1);
musb->isr = dsps_interrupt;
@@ -493,7 +493,7 @@ static int dsps_musb_exit(struct musb *musb)
/* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(0); + data->set_phy_power(data->dev, 0);
#ifndef __UBOOT__ /* NOP driver needs change if supporting dual instance */ @@ -693,7 +693,7 @@ static int dsps_suspend(struct device *dev)
/* Shutdown the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(0); + data->set_phy_power(data->dev, 0);
return 0; } @@ -705,7 +705,7 @@ static int dsps_resume(struct device *dev)
/* Start the on-chip PHY and its PLL. */ if (data->set_phy_power) - data->set_phy_power(1); + data->set_phy_power(data->dev, 1);
return 0; }

On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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 can get physical addresses from the usb driver priv/plat data.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Tom Rini trini@konsulko.com
arch/arm/cpu/armv7/am33xx/board.c | 4 ++-- arch/arm/cpu/armv7/omap3/am35x_musb.c | 6 +++--- arch/arm/include/asm/arch-omap3/musb.h | 6 +++--- arch/arm/include/asm/omap_musb.h | 7 ++++--- drivers/usb/musb-new/am35x.c | 14 +++++++------- drivers/usb/musb-new/musb_dsps.c | 8 ++++---- 6 files changed, 23 insertions(+), 22 deletions(-)
Applied to u-boot-dm, thanks!

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 Reviewed-by: Tom Rini trini@konsulko.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 cf0e296bd0..1c15aa2a42 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 int ti_musb_wrapper_bind(struct udevice *parent) { const void *fdt = gd->fdt_blob; @@ -41,6 +226,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;

On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com wrote:
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 Reviewed-by: Tom Rini trini@konsulko.com
drivers/usb/musb-new/ti-musb.c | 191 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+)
Applied to u-boot-dm, thanks!

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 Reviewed-by: Simon Glass sjg@chromium.org --- drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 109 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index ea71f75947..46e3faeeaa 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -373,6 +373,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;
@@ -453,3 +454,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 1c15aa2a42..b8abc1dc58 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,106 @@ 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) + return ret; + + ret = driver->bind(&gadget->g); + if (ret < 0) + 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); @@ -222,7 +323,15 @@ static int ti_musb_wrapper_bind(struct udevice *parent) dr_mode = usb_get_dr_mode(node); 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 */

Hi Mugunthan,
On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com wrote:
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 Reviewed-by: Simon Glass sjg@chromium.org
drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 109 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index ea71f75947..46e3faeeaa 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -373,6 +373,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;
@@ -453,3 +454,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 1c15aa2a42..b8abc1dc58 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,106 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) return 0; }
+static struct musb *gadget;
Can you please drop this static struct? We should not use this sort of thing with driver model.
Let me know if you want ideas on how.
Regards, Simon

On Sat, 2016-12-03 at 11:40 -0700, Simon Glass wrote:
Hi Mugunthan,
On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com wrote:
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.
Seems like this never landed. Seems to works fine with some trivial fixups though.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 109 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb- new/musb_uboot.c index ea71f75947..46e3faeeaa 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -373,6 +373,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;
@@ -453,3 +454,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 1c15aa2a42..b8abc1dc58 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,106 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) return 0; }
+static struct musb *gadget;
Can you please drop this static struct? We should not use this sort of thing with driver model.
Let me know if you want ideas on how.
From what i can tell; dropping that needs quite a bit refactoring of
the gadget framework such that it passes through a udevice with e.g. usb_gadget_register_driver and usb_gadget_handle_interrupts.
Was that what you were pondering, or other suggestions ;)
-- Sjoerd Simons Collabora Ltd.

Hi Sjeord,
On 25 March 2018 at 15:28, Sjoerd Simons sjoerd.simons@collabora.co.uk wrote:
On Sat, 2016-12-03 at 11:40 -0700, Simon Glass wrote:
Hi Mugunthan,
On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com wrote:
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.
Seems like this never landed. Seems to works fine with some trivial fixups though.
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com Reviewed-by: Simon Glass sjg@chromium.org
drivers/usb/musb-new/musb_uboot.c | 2 + drivers/usb/musb-new/ti-musb.c | 109 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb- new/musb_uboot.c index ea71f75947..46e3faeeaa 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -373,6 +373,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;
@@ -453,3 +454,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 1c15aa2a42..b8abc1dc58 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,106 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) return 0; }
+static struct musb *gadget;
Can you please drop this static struct? We should not use this sort of thing with driver model.
Let me know if you want ideas on how.
From what i can tell; dropping that needs quite a bit refactoring of the gadget framework such that it passes through a udevice with e.g. usb_gadget_register_driver and usb_gadget_handle_interrupts.
Was that what you were pondering, or other suggestions ;)
Well if it is just this static var, then it should be possible to move it to use device-private data, or perhaps uclass-private data if there is a uclass for the gadget (but presumably in principle we need to support multiple gadgets?).
Regards, Simon

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 --- 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 245a9575ec..48816c9809 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 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
arch/arm/cpu/armv7/am33xx/board.c | 8 ++++++++ 1 file changed, 8 insertions(+)
Applied to u-boot-dm, thanks!

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 --- 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 8e62248c73..91e02de91f 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -301,12 +301,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 */ #endif /* CONFIG_USB_MUSB_GADGET */
/*

On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
include/configs/am335x_evm.h | 3 --- 1 file changed, 3 deletions(-)
Applied to u-boot-dm, thanks!

On 01/09/2017 09:45 PM, Simon Glass wrote:
On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
include/configs/am335x_evm.h | 3 --- 1 file changed, 3 deletions(-)
Applied to u-boot-dm, thanks!
Shouldn't this go through u-boot-ti ?

On Mon, Jan 09, 2017 at 09:58:03PM +0100, Marek Vasut wrote:
On 01/09/2017 09:45 PM, Simon Glass wrote:
On 17 November 2016 at 02:08, Mugunthan V N mugunthanvnm@ti.com 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
include/configs/am335x_evm.h | 3 --- 1 file changed, 3 deletions(-)
Applied to u-boot-dm, thanks!
Shouldn't this go through u-boot-ti ?
No, I reviewed it so it can just go via the other tree. I am not a fan of breaking up a series into N maintainers, so long as the maintainers have acked/reviewed/etc the series.

enable usb driver model for am335x bbb as musb supports driver model
Signed-off-by: Mugunthan V N mugunthanvnm@ti.com --- configs/am335x_evm_defconfig | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/configs/am335x_evm_defconfig b/configs/am335x_evm_defconfig index e5a1696914..7e1cf3213e 100644 --- a/configs/am335x_evm_defconfig +++ b/configs/am335x_evm_defconfig @@ -60,3 +60,6 @@ CONFIG_G_DNL_VENDOR_NUM=0x0451 CONFIG_G_DNL_PRODUCT_NUM=0xd022 CONFIG_RSA=y CONFIG_SPL_OF_LIBFDT=y +CONFIG_MISC=y +CONFIG_DM_USB=y +CONFIG_USB_MUSB_TI=y

On Thu, Nov 17, 2016 at 02:38:15PM +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

On 21 November 2016 at 07:06, Tom Rini trini@konsulko.com wrote:
On Thu, Nov 17, 2016 at 02:38:15PM +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
Applied to u-boot-dm, thanks!
participants (5)
-
Marek Vasut
-
Mugunthan V N
-
Simon Glass
-
Sjoerd Simons
-
Tom Rini