From bb00a015d624f683c66c9e30341f93b678d03d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Fri, 23 Nov 2018 14:37:52 +0100 Subject: [PATCH 01/27] usb: gadget: f_sdp: Provide filesize env variable for downloaded images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently it's not possible to get filesize of downloaded images and it's impossible to automate some tasks in scripts. So this patch adds `filesize` environment variable with size (as hex number in bytes) of the last successfully downloaded file via `sdp` command. Cc: Lukasz Majewski Cc: Marek Vasut Cc: Stefan Agner Signed-off-by: Petr Štetiar Reviewed-by: Stefan Agner --- drivers/usb/gadget/f_sdp.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index 00a9f88a41..ae97ab2b49 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -100,6 +100,7 @@ struct f_sdp { enum sdp_state state; enum sdp_state next_state; u32 dnl_address; + u32 dnl_bytes; u32 dnl_bytes_remaining; u32 jmp_address; bool always_send_status; @@ -276,6 +277,7 @@ static void sdp_rx_command_complete(struct usb_ep *ep, struct usb_request *req) sdp->state = SDP_STATE_RX_FILE_DATA; sdp->dnl_address = be32_to_cpu(cmd->addr); sdp->dnl_bytes_remaining = be32_to_cpu(cmd->cnt); + sdp->dnl_bytes = sdp->dnl_bytes_remaining; sdp->next_state = SDP_STATE_IDLE; printf("Downloading file of size %d to 0x%08x... ", @@ -355,6 +357,9 @@ static void sdp_rx_data_complete(struct usb_ep *ep, struct usb_request *req) if (sdp->dnl_bytes_remaining) return; +#ifndef CONFIG_SPL_BUILD + env_set_hex("filesize", sdp->dnl_bytes); +#endif printf("done\n"); switch (sdp->state) { From 916fa097997a5e1b70768ce944de28e038d4bebf Mon Sep 17 00:00:00 2001 From: Lukasz Majewski Date: Fri, 23 Nov 2018 17:36:19 +0100 Subject: [PATCH 02/27] usb: composite: Move bitmap related operations to ./include/linux/bitmap.h The BITMAP related operations can now be moved to ./include/linux/bitmap.h file to mimic the Linux kernel directory tree. This change also allows to remove the lin_gadget_compat.h header file (which is a legacy code only for composite U-boot layer). It was also possible to remove #includes from several USB gadget drivers. Signed-off-by: Lukasz Majewski Reviewed-by: Stefan Agner --- drivers/usb/dwc3/gadget.c | 1 - drivers/usb/dwc3/ti_usb_phy.c | 1 - drivers/usb/eth/r8152.c | 1 - drivers/usb/gadget/at91_udc.c | 1 - drivers/usb/gadget/atmel_usba_udc.c | 1 - drivers/usb/gadget/dwc2_udc_otg.c | 1 - drivers/usb/gadget/dwc2_udc_otg_phy.c | 1 - drivers/usb/gadget/dwc2_udc_otg_priv.h | 1 - drivers/usb/gadget/f_mass_storage.c | 2 +- drivers/usb/gadget/pxa25x_udc.c | 1 - include/linux/bitmap.h | 23 +++++++++++++++++ include/linux/types.h | 3 +++ include/linux/usb/composite.h | 2 +- include/usb/lin_gadget_compat.h | 35 -------------------------- 14 files changed, 28 insertions(+), 46 deletions(-) create mode 100644 include/linux/bitmap.h delete mode 100644 include/usb/lin_gadget_compat.h diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index e340cb268f..085f7b8968 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include diff --git a/drivers/usb/dwc3/ti_usb_phy.c b/drivers/usb/dwc3/ti_usb_phy.c index d168e868e3..e7ea12c163 100644 --- a/drivers/usb/dwc3/ti_usb_phy.c +++ b/drivers/usb/dwc3/ti_usb_phy.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/usb/eth/r8152.c b/drivers/usb/eth/r8152.c index 941158abdd..e5f73e3d4c 100644 --- a/drivers/usb/eth/r8152.c +++ b/drivers/usb/eth/r8152.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include "usb_ether.h" diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c index 39ea87005c..2a6626b443 100644 --- a/drivers/usb/gadget/at91_udc.c +++ b/drivers/usb/gadget/at91_udc.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "at91_udc.h" diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c index c9d483318f..dffa5117f9 100644 --- a/drivers/usb/gadget/atmel_usba_udc.c +++ b/drivers/usb/gadget/atmel_usba_udc.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "atmel_usba_udc.h" diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c index e3edd10e29..3c7ad033e3 100644 --- a/drivers/usb/gadget/dwc2_udc_otg.c +++ b/drivers/usb/gadget/dwc2_udc_otg.c @@ -33,7 +33,6 @@ #include "dwc2_udc_otg_regs.h" #include "dwc2_udc_otg_priv.h" -#include /***********************************************************/ diff --git a/drivers/usb/gadget/dwc2_udc_otg_phy.c b/drivers/usb/gadget/dwc2_udc_otg_phy.c index 47aa78ae94..c4338af0d7 100644 --- a/drivers/usb/gadget/dwc2_udc_otg_phy.c +++ b/drivers/usb/gadget/dwc2_udc_otg_phy.c @@ -33,7 +33,6 @@ #include "dwc2_udc_otg_regs.h" #include "dwc2_udc_otg_priv.h" -#include #include diff --git a/drivers/usb/gadget/dwc2_udc_otg_priv.h b/drivers/usb/gadget/dwc2_udc_otg_priv.h index b64e222b6d..aaa90187fb 100644 --- a/drivers/usb/gadget/dwc2_udc_otg_priv.h +++ b/drivers/usb/gadget/dwc2_udc_otg_priv.h @@ -12,7 +12,6 @@ #include #include #include -#include #include /*-------------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c index a3101afa0d..45c7b58eed 100644 --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -256,7 +256,7 @@ #include #include #include -#include +#include #include /*------------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/pxa25x_udc.c b/drivers/usb/gadget/pxa25x_udc.c index 44092df25b..09c0a30b2b 100644 --- a/drivers/usb/gadget/pxa25x_udc.c +++ b/drivers/usb/gadget/pxa25x_udc.c @@ -29,7 +29,6 @@ #include #include -#include #include #include "pxa25x_udc.h" diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h new file mode 100644 index 0000000000..4a54ae0509 --- /dev/null +++ b/include/linux/bitmap.h @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +#ifndef __LINUX_BITMAP_H +#define __LINUX_BITMAP_H + +#include +#include +#include + +#define small_const_nbits(nbits) \ + (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) + +static inline void bitmap_zero(unsigned long *dst, int nbits) +{ + if (small_const_nbits(nbits)) { + *dst = 0UL; + } else { + int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + + memset(dst, 0, len); + } +} + +#endif /* __LINUX_BITMAP_H */ diff --git a/include/linux/types.h b/include/linux/types.h index 1f3cd63b8f..cc6f7cb39e 100644 --- a/include/linux/types.h +++ b/include/linux/types.h @@ -158,4 +158,7 @@ struct ustat { char f_fpack[6]; }; +#define DECLARE_BITMAP(name, bits) \ + unsigned long name[BITS_TO_LONGS(bits)] + #endif /* _LINUX_TYPES_H */ diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h index 30c464ce39..a49a66f2f8 100644 --- a/include/linux/usb/composite.h +++ b/include/linux/usb/composite.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include /* * USB function drivers should return USB_GADGET_DELAYED_STATUS if they diff --git a/include/usb/lin_gadget_compat.h b/include/usb/lin_gadget_compat.h deleted file mode 100644 index e5dba473b7..0000000000 --- a/include/usb/lin_gadget_compat.h +++ /dev/null @@ -1,35 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * Copyright (c) 2011 Samsung Electronics - * Lukasz Majewski - * - * This is a Linux kernel compatibility layer for USB Gadget - */ - -#ifndef __LIN_COMPAT_H__ -#define __LIN_COMPAT_H__ - -#include -#include - -/* common */ -#define DECLARE_BITMAP(name, bits) \ - unsigned long name[BITS_TO_LONGS(bits)] - -#define small_const_nbits(nbits) \ - (__builtin_constant_p(nbits) && (nbits) <= BITS_PER_LONG) - -static inline void bitmap_zero(unsigned long *dst, int nbits) -{ - if (small_const_nbits(nbits)) - *dst = 0UL; - else { - int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); - memset(dst, 0, len); - } -} - -#define dma_cache_maint(addr, size, mode) cache_flush() -void cache_flush(void); - -#endif /* __LIN_COMPAT_H__ */ From 16ecb295b3834d8017d922ae46eedbbf6fd6c99b Mon Sep 17 00:00:00 2001 From: Martyn Welch Date: Mon, 10 Dec 2018 11:05:16 +0000 Subject: [PATCH 03/27] usb: Don't enable CONFIG_SPL_DM_USB for non-DM SPL When CONFIG_SPL_DM_USB was added, it was added defaulted on without protection to ensure it didn't get set for non-DM SPL builds. This leads to unexpected and confusing failures when building a DM based U-Boot but with a non-DM SPL, as the defconfig is unlikely to have CONFIG_SPL_DM_USB actively disabled. Tweak the Kconfig to not enable this setting unless CONFIG_SPL_DM is set. Signed-off-by: Martyn Welch --- drivers/usb/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig index 98f83433be..3b53bf2c58 100644 --- a/drivers/usb/Kconfig +++ b/drivers/usb/Kconfig @@ -49,7 +49,7 @@ config DM_USB config SPL_DM_USB bool "Enable driver model for USB in SPL" - depends on DM_USB + depends on SPL_DM && DM_USB default y config DM_USB_GADGET From 66c65f0a9178a2f044d9e65759f0d9498da279b1 Mon Sep 17 00:00:00 2001 From: Adam Ford Date: Wed, 12 Dec 2018 08:17:22 -0600 Subject: [PATCH 04/27] usb: musb: Remove Legacy CONFIG_USB_DAVINCI This patch removes CONFIG_USB_DAVINCI. It's a legacy option that isn't defined anywhere, and there is a newer MUSB driver. Signed-off-by: Adam Ford Reviewed-by: Jean-Jacques Hiblot --- drivers/usb/musb/Kconfig | 3 - drivers/usb/musb/Makefile | 1 - drivers/usb/musb/davinci.c | 123 ------------------------------------ drivers/usb/musb/davinci.h | 73 --------------------- drivers/usb/musb/musb_udc.c | 2 - 5 files changed, 202 deletions(-) delete mode 100644 drivers/usb/musb/davinci.c delete mode 100644 drivers/usb/musb/davinci.h diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index dd42f69a6b..7e6be03f4a 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig @@ -11,9 +11,6 @@ config USB_MUSB_HCD config USB_MUSB_UDC bool "Legacy USB Device Controller" -config USB_DAVINCI - bool "Legacy MUSB DaVinci" - config USB_OMAP3 bool "Legacy MUSB OMAP3 / OMAP4" depends on ARCH_OMAP2PLUS diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile index bdb3cd87f6..1242ce1c8c 100644 --- a/drivers/usb/musb/Makefile +++ b/drivers/usb/musb/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_USB_MUSB_HCD) += musb_hcd.o musb_core.o obj-$(CONFIG_USB_MUSB_UDC) += musb_udc.o musb_core.o -obj-$(CONFIG_USB_DAVINCI) += davinci.o obj-$(CONFIG_USB_OMAP3) += omap3.o obj-$(CONFIG_USB_DA8XX) += da8xx.o obj-$(CONFIG_USB_AM35X) += am35x.o diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c deleted file mode 100644 index 46cdb5ad1f..0000000000 --- a/drivers/usb/musb/davinci.c +++ /dev/null @@ -1,123 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * TI's Davinci platform specific USB wrapper functions. - * - * Copyright (c) 2008 Texas Instruments - * - * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments - */ - -#include -#include -#include "davinci.h" -#include - -#if !defined(CONFIG_DV_USBPHY_CTL) -#define CONFIG_DV_USBPHY_CTL (USBPHY_SESNDEN | USBPHY_VBDTCTEN) -#endif - -/* MUSB platform configuration */ -struct musb_config musb_cfg = { - .regs = (struct musb_regs *)MENTOR_USB0_BASE, - .timeout = DAVINCI_USB_TIMEOUT, - .musb_speed = 0, -}; - -/* MUSB module register overlay */ -struct davinci_usb_regs *dregs; - -/* - * Enable the USB phy - */ -static u8 phy_on(void) -{ - u32 timeout; -#ifdef DAVINCI_DM365EVM - u32 val; -#endif - /* Wait until the USB phy is turned on */ -#ifdef DAVINCI_DM365EVM - writel(USBPHY_PHY24MHZ | USBPHY_SESNDEN | - USBPHY_VBDTCTEN, USBPHY_CTL_PADDR); -#else - writel(CONFIG_DV_USBPHY_CTL, USBPHY_CTL_PADDR); -#endif - timeout = musb_cfg.timeout; - -#ifdef DAVINCI_DM365EVM - /* Set the ownership of GIO33 to USB */ - val = readl(PINMUX4); - val &= ~(PINMUX4_USBDRVBUS_BITCLEAR); - val |= PINMUX4_USBDRVBUS_BITSET; - writel(val, PINMUX4); -#endif - while (timeout--) - if (readl(USBPHY_CTL_PADDR) & USBPHY_PHYCLKGD) - return 1; - - /* USB phy was not turned on */ - return 0; -} - -/* - * Disable the USB phy - */ -static void phy_off(void) -{ - /* powerdown the on-chip PHY and its oscillator */ - writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, USBPHY_CTL_PADDR); -} - -void __enable_vbus(void) -{ - /* - * nothing to do, vbus is handled through the cpu. - * Define this function in board code, if it is - * different on your board. - */ -} -void enable_vbus(void) - __attribute__((weak, alias("__enable_vbus"))); - -/* - * This function performs Davinci platform specific initialization for usb0. - */ -int musb_platform_init(void) -{ - u32 revision; - - /* enable USB VBUS */ - enable_vbus(); - - /* start the on-chip USB phy and its pll */ - if (!phy_on()) - return -1; - - /* reset the controller */ - dregs = (struct davinci_usb_regs *)DAVINCI_USB0_BASE; - writel(1, &dregs->ctrlr); - udelay(5000); - - /* Returns zero if e.g. not clocked */ - revision = readl(&dregs->version); - if (!revision) - return -1; - - /* Disable all interrupts */ - writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_RXINT_MASK | - DAVINCI_USB_TXINT_MASK , &dregs->intmsksetr); - return 0; -} - -/* - * This function performs Davinci platform specific deinitialization for usb0. - */ -void musb_platform_deinit(void) -{ - /* Turn of the phy */ - phy_off(); - - /* flush any interrupts */ - writel(DAVINCI_USB_USBINT_MASK | DAVINCI_USB_TXINT_MASK | - DAVINCI_USB_RXINT_MASK , &dregs->intclrr); -} diff --git a/drivers/usb/musb/davinci.h b/drivers/usb/musb/davinci.h deleted file mode 100644 index 29bb08c307..0000000000 --- a/drivers/usb/musb/davinci.h +++ /dev/null @@ -1,73 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * TI's Davinci platform specific USB wrapper functions. - * - * Copyright (c) 2008 Texas Instruments - * - * Author: Thomas Abraham t-abraham@ti.com, Texas Instruments - */ - -#ifndef __DAVINCI_USB_H__ -#define __DAVINCI_USB_H__ - -#include -#include "musb_core.h" - -/* Base address of DAVINCI usb0 wrapper */ -#define DAVINCI_USB0_BASE 0x01C64000 - -/* Base address of DAVINCI musb core */ -#define MENTOR_USB0_BASE (DAVINCI_USB0_BASE+0x400) - -/* - * Davinci platform USB wrapper register overlay. Note: Only the required - * registers are included in this structure. It can be expanded as required. - */ -struct davinci_usb_regs { - u32 version; - u32 ctrlr; - u32 reserved[0x20]; - u32 intclrr; - u32 intmskr; - u32 intmsksetr; -}; - -#define DAVINCI_USB_TX_ENDPTS_MASK 0x1f /* ep0 + 4 tx */ -#define DAVINCI_USB_RX_ENDPTS_MASK 0x1e /* 4 rx */ -#define DAVINCI_USB_USBINT_SHIFT 16 -#define DAVINCI_USB_TXINT_SHIFT 0 -#define DAVINCI_USB_RXINT_SHIFT 8 -#define DAVINCI_INTR_DRVVBUS 0x0100 - -#define DAVINCI_USB_USBINT_MASK 0x01ff0000 /* 8 Mentor, DRVVBUS */ -#define DAVINCI_USB_TXINT_MASK \ - (DAVINCI_USB_TX_ENDPTS_MASK << DAVINCI_USB_TXINT_SHIFT) -#define DAVINCI_USB_RXINT_MASK \ - (DAVINCI_USB_RX_ENDPTS_MASK << DAVINCI_USB_RXINT_SHIFT) -#define MGC_BUSCTL_OFFSET(_bEnd, _bOffset) \ - (0x80 + (8*(_bEnd)) + (_bOffset)) - -/* Integrated highspeed/otg PHY */ -#define USBPHY_CTL_PADDR (DAVINCI_SYSTEM_MODULE_BASE + 0x34) -#define USBPHY_PHY24MHZ (1 << 13) -#define USBPHY_PHYCLKGD (1 << 8) -#define USBPHY_SESNDEN (1 << 7) /* v(sess_end) comparator */ -#define USBPHY_VBDTCTEN (1 << 6) /* v(bus) comparator */ -#define USBPHY_PHYPLLON (1 << 4) /* override pll suspend */ -#define USBPHY_CLKO1SEL (1 << 3) -#define USBPHY_OSCPDWN (1 << 2) -#define USBPHY_PHYPDWN (1 << 0) - -/* Timeout for Davinci USB module */ -#define DAVINCI_USB_TIMEOUT 0x3FFFFFF - -/* IO Expander I2C address and VBUS enable mask */ -#define IOEXP_I2C_ADDR 0x3A -#define IOEXP_VBUSEN_MASK 1 - -/* extern functions */ -extern void lpsc_on(unsigned int id); -extern int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len); -extern int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len); -extern void enable_vbus(void); -#endif /* __DAVINCI_USB_H__ */ diff --git a/drivers/usb/musb/musb_udc.c b/drivers/usb/musb/musb_udc.c index f1d6d85862..7620114bec 100644 --- a/drivers/usb/musb/musb_udc.c +++ b/drivers/usb/musb/musb_udc.c @@ -46,8 +46,6 @@ #include "omap3.h" #elif defined(CONFIG_USB_AM35X) #include "am35x.h" -#elif defined(CONFIG_USB_DAVINCI) -#include "davinci.h" #endif /* Define MUSB_DEBUG for debugging */ From f187ace80ee2f6e1ac150a1320473e41dca65555 Mon Sep 17 00:00:00 2001 From: Adam Ford Date: Wed, 12 Dec 2018 08:17:41 -0600 Subject: [PATCH 05/27] usb: musb: Remove legacy CONFIG_USB_DA8XX There don't appear to be any boards enabling CONFIG_USB_DA8XX, and there is a newer version of the MUSB driver, so let's remove the legacy version of it. Signed-off-by: Adam Ford Reviewed-by: Jean-Jacques Hiblot --- drivers/usb/musb/Kconfig | 4 -- drivers/usb/musb/Makefile | 1 - drivers/usb/musb/da8xx.c | 127 -------------------------------------- 3 files changed, 132 deletions(-) delete mode 100644 drivers/usb/musb/da8xx.c diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig index 7e6be03f4a..2508b6ed0d 100644 --- a/drivers/usb/musb/Kconfig +++ b/drivers/usb/musb/Kconfig @@ -15,10 +15,6 @@ config USB_OMAP3 bool "Legacy MUSB OMAP3 / OMAP4" depends on ARCH_OMAP2PLUS -config USB_DA8XX - bool "Legacy MUSB DA8xx/OMAP-L1x" - depends on ARCH_DAVINCI - config USB_AM35X bool"Legacy MUSB AM35x" depends on ARCH_OMAP2PLUS && !USB_OMAP3 diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile index 1242ce1c8c..744f2cfaa2 100644 --- a/drivers/usb/musb/Makefile +++ b/drivers/usb/musb/Makefile @@ -6,5 +6,4 @@ obj-$(CONFIG_USB_MUSB_HCD) += musb_hcd.o musb_core.o obj-$(CONFIG_USB_MUSB_UDC) += musb_udc.o musb_core.o obj-$(CONFIG_USB_OMAP3) += omap3.o -obj-$(CONFIG_USB_DA8XX) += da8xx.o obj-$(CONFIG_USB_AM35X) += am35x.o diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c deleted file mode 100644 index a652a7c3c1..0000000000 --- a/drivers/usb/musb/da8xx.c +++ /dev/null @@ -1,127 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * da8xx.c - TI's DA8xx platform specific usb wrapper functions. - * - * Author: Ajay Kumar Gupta - * - * Based on drivers/usb/musb/davinci.c - * - * Copyright (C) 2009 Texas Instruments Incorporated - */ -#include - -#include "musb_core.h" -#include - -/* MUSB platform configuration */ -struct musb_config musb_cfg = { - .regs = (struct musb_regs *)DA8XX_USB_OTG_CORE_BASE, - .timeout = DA8XX_USB_OTG_TIMEOUT, - .musb_speed = 0, -}; - -/* - * This function enables VBUS by driving the GPIO Bank4 Pin 15 high. - */ -static void enable_vbus(void) -{ - u32 value; - - /* configure GPIO bank4 pin 15 in output direction */ - value = readl(&davinci_gpio_bank45->dir); - writel((value & (~DA8XX_USB_VBUS_GPIO)), &davinci_gpio_bank45->dir); - - /* set GPIO bank4 pin 15 high to drive VBUS */ - value = readl(&davinci_gpio_bank45->set_data); - writel((value | DA8XX_USB_VBUS_GPIO), &davinci_gpio_bank45->set_data); -} - -/* - * Enable the usb0 phy. This initialization procedure is explained in - * the DA8xx USB user guide document. - */ -static u8 phy_on(void) -{ - u32 timeout; - u32 cfgchip2; - - cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2); - - cfgchip2 &= ~(CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN | - CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ); - cfgchip2 |= CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN | CFGCHIP2_PHY_PLLON | - CFGCHIP2_REFFREQ_24MHZ; - - writel(cfgchip2, &davinci_syscfg_regs->cfgchip2); - - /* wait until the usb phy pll locks */ - timeout = musb_cfg.timeout; - while (timeout--) - if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD) - return 1; - - /* USB phy was not turned on */ - return 0; -} - -/* - * Disable the usb phy - */ -static void phy_off(void) -{ - u32 cfgchip2; - - /* - * Power down the on-chip PHY. - */ - cfgchip2 = readl(&davinci_syscfg_regs->cfgchip2); - cfgchip2 &= ~CFGCHIP2_PHY_PLLON; - cfgchip2 |= CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN; - writel(cfgchip2, &davinci_syscfg_regs->cfgchip2); -} - -/* - * This function performs DA8xx platform specific initialization for usb0. - */ -int musb_platform_init(void) -{ - u32 revision; - - /* enable psc for usb2.0 */ - lpsc_on(33); - - /* enable usb vbus */ - enable_vbus(); - - /* reset the controller */ - writel(0x1, &da8xx_usb_regs->control); - udelay(5000); - - /* start the on-chip usb phy and its pll */ - if (phy_on() == 0) - return -1; - - /* Returns zero if e.g. not clocked */ - revision = readl(&da8xx_usb_regs->revision); - if (revision == 0) - return -1; - - /* Disable all interrupts */ - writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK | - DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_set); - return 0; -} - -/* - * This function performs DA8xx platform specific deinitialization for usb0. - */ -void musb_platform_deinit(void) -{ - /* Turn of the phy */ - phy_off(); - - /* flush any interrupts */ - writel((DA8XX_USB_USBINT_MASK | DA8XX_USB_TXINT_MASK | - DA8XX_USB_RXINT_MASK), &da8xx_usb_regs->intmsk_clr); - writel(0, &da8xx_usb_regs->eoi); -} From 1c03ade328dd08603fa717076c5888557f1a9fa7 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:12:56 +0100 Subject: [PATCH 06/27] usb: dwc3-generic: make it compatible with "ti, keystone-dwc3" Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/usb/dwc3/dwc3-generic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index bc6bba198e..0c189b81ff 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -342,6 +342,7 @@ static int dwc3_glue_remove(struct udevice *dev) static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "xlnx,zynqmp-dwc3" }, + { .compatible = "ti,keystone-dwc3"}, { .compatible = "ti,dwc3", .data = (ulong)&ti_ops }, { } }; From c9d52206939f7489e719c3c1c429c912d622fc42 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:12:57 +0100 Subject: [PATCH 07/27] board: ks2_evm: Enable the USB clocks if DM_USB is used Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- board/ti/ks2_evm/board.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/board/ti/ks2_evm/board.c b/board/ti/ks2_evm/board.c index 3e06800608..eed62e9cac 100644 --- a/board/ti/ks2_evm/board.c +++ b/board/ti/ks2_evm/board.c @@ -66,6 +66,18 @@ struct image_header *spl_get_load_buffer(ssize_t offset, size_t size) int board_init(void) { +#if CONFIG_IS_ENABLED(DM_USB) + int rc = psc_enable_module(KS2_LPSC_USB); + + if (rc) + puts("Cannot enable USB0 module"); +#ifdef KS2_LPSC_USB_1 + rc = psc_enable_module(KS2_LPSC_USB_1); + if (rc) + puts("Cannot enable USB1 module"); +#endif +#endif + gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; return 0; From d53653f3f9a15eca6249e951ea77eddc514541a3 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:12:58 +0100 Subject: [PATCH 08/27] ARM: dts: k2g-evm: enable USB0 and USB1 Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- arch/arm/dts/keystone-k2g-evm.dts | 28 ++++++++++++++++ arch/arm/dts/keystone-k2g.dtsi | 56 +++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/arch/arm/dts/keystone-k2g-evm.dts b/arch/arm/dts/keystone-k2g-evm.dts index ad746c7311..6c9de25b94 100644 --- a/arch/arm/dts/keystone-k2g-evm.dts +++ b/arch/arm/dts/keystone-k2g-evm.dts @@ -33,6 +33,34 @@ }; }; +&keystone_usb0 { + status = "okay"; +}; + +&usb0_phy { + status = "okay"; + compatible = "nop-phy"; +}; + +&usb0 { + dr_mode = "host"; + status = "okay"; +}; + +&keystone_usb1 { + status = "okay"; +}; + +&usb1_phy { + compatible = "nop-phy"; + status = "okay"; +}; + +&usb1 { + dr_mode = "peripheral"; + status = "okay"; +}; + &gbe0 { phy-handle = <ðphy0>; }; diff --git a/arch/arm/dts/keystone-k2g.dtsi b/arch/arm/dts/keystone-k2g.dtsi index bbbb9874c8..ede7118120 100644 --- a/arch/arm/dts/keystone-k2g.dtsi +++ b/arch/arm/dts/keystone-k2g.dtsi @@ -201,5 +201,61 @@ status = "disabled"; clock-names = "fck"; }; + + usb0_phy: usb-phy@0 { + compatible = "usb-nop-xceiv"; + status = "disabled"; + }; + + keystone_usb0: keystone-dwc3@2680000 { + compatible = "ti,keystone-dwc3"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x2680000 0x10000>; + interrupts = ; + ranges; + dma-coherent; + dma-ranges; + status = "disabled"; + /*power-domains = <&k2g_pds 0x0016>;*/ + + usb0: usb@2690000 { + compatible = "snps,dwc3"; + reg = <0x2690000 0x10000>; + interrupts = ; + maximum-speed = "high-speed"; + dr_mode = "otg"; + /*usb-phy = <&usb0_phy>;*/ + status = "disabled"; + }; + }; + + usb1_phy: usb-phy@1 { + compatible = "usb-nop-xceiv"; + status = "disabled"; + }; + + keystone_usb1: keystone-dwc3@2580000 { + compatible = "ti,keystone-dwc3"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x2580000 0x10000>; + interrupts = ; + ranges; + dma-coherent; + dma-ranges; + status = "disabled"; + /*power-domains = <&k2g_pds 0x0017>;*/ + + usb1: usb@2590000 { + compatible = "snps,dwc3"; + reg = <0x2590000 0x10000>; + interrupts = ; + maximum-speed = "high-speed"; + dr_mode = "otg"; + /*usb-phy = <&usb1_phy>;*/ + status = "disabled"; + }; + }; }; }; From 4b12783c8e011859e70ba5811654a21ee1a22237 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:12:59 +0100 Subject: [PATCH 09/27] PHY: Add phy driver for the keystone USB PHY Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/phy/Kconfig | 10 +++ drivers/phy/Makefile | 1 + drivers/phy/keystone-usb-phy.c | 109 +++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 drivers/phy/keystone-usb-phy.c diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig index 3921e39d7b..825ee7c3be 100644 --- a/drivers/phy/Kconfig +++ b/drivers/phy/Kconfig @@ -164,4 +164,14 @@ config OMAP_USB2_PHY This PHY is found on OMAP devices supporting USB2. + +config KEYSTONE_USB_PHY + bool "Support TI Keystone USB PHY" + depends on PHY + depends on ARCH_KEYSTONE + help + Support for the USB PHY found on some Keystone (k2) processors + + This PHY is found on some Keystone (K2) devices supporting USB. + endmenu diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile index 53dd5bd0f7..099551d693 100644 --- a/drivers/phy/Makefile +++ b/drivers/phy/Makefile @@ -18,3 +18,4 @@ obj-$(CONFIG_PHY_STM32_USBPHYC) += phy-stm32-usbphyc.o obj-$(CONFIG_MESON_GXL_USB_PHY) += meson-gxl-usb2.o meson-gxl-usb3.o obj-$(CONFIG_MSM8916_USB_PHY) += msm8916-usbh-phy.o obj-$(CONFIG_OMAP_USB2_PHY) += omap-usb2-phy.o +obj-$(CONFIG_KEYSTONE_USB_PHY) += keystone-usb-phy.o diff --git a/drivers/phy/keystone-usb-phy.c b/drivers/phy/keystone-usb-phy.c new file mode 100644 index 0000000000..e8146cabfa --- /dev/null +++ b/drivers/phy/keystone-usb-phy.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/ + * Written by Jean-Jacques Hiblot + */ + +#include +#include +#include +#include +#include + +/* USB PHY control register offsets */ +#define USB_PHY_CTL_UTMI 0x0000 +#define USB_PHY_CTL_PIPE 0x0004 +#define USB_PHY_CTL_PARAM_1 0x0008 +#define USB_PHY_CTL_PARAM_2 0x000c +#define USB_PHY_CTL_CLOCK 0x0010 +#define USB_PHY_CTL_PLL 0x0014 + +#define PHY_OTG_VBUSVLDECTSEL BIT(16) +#define PHY_REF_SSP_EN BIT(29) + +struct keystone_usb_phy { + void __iomem *reg; +}; + +static int keystone_usb_init(struct phy *phy) +{ + u32 val; + struct udevice *dev = phy->dev; + struct keystone_usb_phy *keystone = dev_get_priv(dev); + + /* + * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't. + * It should always be cleared because our USB PHY has an onchip VBUS + * analog comparator. + */ + val = readl(keystone->reg + USB_PHY_CTL_CLOCK); + /* quit selecting the vbusvldextsel by default! */ + val &= ~PHY_OTG_VBUSVLDECTSEL; + writel(val, keystone->reg + USB_PHY_CTL_CLOCK); + + return 0; +} + +static int keystone_usb_power_on(struct phy *phy) +{ + u32 val; + struct udevice *dev = phy->dev; + struct keystone_usb_phy *keystone = dev_get_priv(dev); + + val = readl(keystone->reg + USB_PHY_CTL_CLOCK); + val |= PHY_REF_SSP_EN; + writel(val, keystone->reg + USB_PHY_CTL_CLOCK); + + return 0; +} + +static int keystone_usb_power_off(struct phy *phy) +{ + u32 val; + struct udevice *dev = phy->dev; + struct keystone_usb_phy *keystone = dev_get_priv(dev); + + val = readl(keystone->reg + USB_PHY_CTL_CLOCK); + val &= ~PHY_REF_SSP_EN; + writel(val, keystone->reg + USB_PHY_CTL_CLOCK); + + return 0; +} + +static int keystone_usb_exit(struct phy *phy) +{ + return 0; +} + +static int keystone_usb_phy_probe(struct udevice *dev) +{ + struct keystone_usb_phy *keystone = dev_get_priv(dev); + + keystone->reg = dev_remap_addr_index(dev, 0); + if (!keystone->reg) { + pr_err("unable to remap usb phy\n"); + return -EINVAL; + } + return 0; +} + +static const struct udevice_id keystone_usb_phy_ids[] = { + { .compatible = "ti,keystone-usbphy" }, + { } +}; + +static struct phy_ops keystone_usb_phy_ops = { + .init = keystone_usb_init, + .power_on = keystone_usb_power_on, + .power_off = keystone_usb_power_off, + .exit = keystone_usb_exit, +}; + +U_BOOT_DRIVER(keystone_usb_phy) = { + .name = "keystone_usb_phy", + .id = UCLASS_PHY, + .of_match = keystone_usb_phy_ids, + .ops = &keystone_usb_phy_ops, + .probe = keystone_usb_phy_probe, + .priv_auto_alloc_size = sizeof(struct keystone_usb_phy), +}; From 4dd76d0f96ab18a2bda622ec4dac822e908dd069 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:13:00 +0100 Subject: [PATCH 10/27] usb: host: replace xhci-keystone driver by the generic dwc3 driver The keystone platforms can use the generic DC3 driver. Removing the keystone-spcecific xchi driver and add the configuration options to enable the generic DWC3 driver on all K2 platforms. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- configs/k2e_evm_defconfig | 7 + configs/k2e_hs_evm_defconfig | 7 + configs/k2g_evm_defconfig | 6 + configs/k2g_hs_evm_defconfig | 6 + configs/k2hk_evm_defconfig | 7 + configs/k2hk_hs_evm_defconfig | 7 + configs/k2l_evm_defconfig | 7 + configs/k2l_hs_evm_defconfig | 7 + drivers/usb/host/Makefile | 1 - drivers/usb/host/xhci-keystone.c | 240 --------------------------- include/configs/ti_armv7_keystone2.h | 7 - 11 files changed, 54 insertions(+), 248 deletions(-) delete mode 100644 drivers/usb/host/xhci-keystone.c diff --git a/configs/k2e_evm_defconfig b/configs/k2e_evm_defconfig index 67b1f30c8e..03a1ceb268 100644 --- a/configs/k2e_evm_defconfig +++ b/configs/k2e_evm_defconfig @@ -37,6 +37,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -47,13 +48,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2e_hs_evm_defconfig b/configs/k2e_hs_evm_defconfig index 1abda846a1..bb7b31417e 100644 --- a/configs/k2e_hs_evm_defconfig +++ b/configs/k2e_hs_evm_defconfig @@ -30,6 +30,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -40,13 +41,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2g_evm_defconfig b/configs/k2g_evm_defconfig index bc4b92b491..95c835abd9 100644 --- a/configs/k2g_evm_defconfig +++ b/configs/k2g_evm_defconfig @@ -36,6 +36,7 @@ CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y # CONFIG_BLK is not set CONFIG_SYS_I2C_DAVINCI=y +CONFIG_MISC=y CONFIG_DM_MMC=y CONFIG_MMC_OMAP_HS=y CONFIG_NAND=y @@ -50,6 +51,8 @@ CONFIG_PHY_MARVELL=y CONFIG_PHY_MICREL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y CONFIG_REMOTEPROC_TI_POWER=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y @@ -57,7 +60,10 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2g_hs_evm_defconfig b/configs/k2g_hs_evm_defconfig index 66d8220aeb..47c30a6fa0 100644 --- a/configs/k2g_hs_evm_defconfig +++ b/configs/k2g_hs_evm_defconfig @@ -29,6 +29,7 @@ CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y # CONFIG_BLK is not set CONFIG_SYS_I2C_DAVINCI=y +CONFIG_MISC=y CONFIG_DM_MMC=y CONFIG_MMC_OMAP_HS=y CONFIG_NAND=y @@ -43,6 +44,8 @@ CONFIG_PHY_MARVELL=y CONFIG_PHY_MICREL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y CONFIG_REMOTEPROC_TI_POWER=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y @@ -50,7 +53,10 @@ CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2hk_evm_defconfig b/configs/k2hk_evm_defconfig index f66d922bf1..700fafd5a3 100644 --- a/configs/k2hk_evm_defconfig +++ b/configs/k2hk_evm_defconfig @@ -37,6 +37,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -47,13 +48,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2hk_hs_evm_defconfig b/configs/k2hk_hs_evm_defconfig index dd91a51414..a6caccce7b 100644 --- a/configs/k2hk_hs_evm_defconfig +++ b/configs/k2hk_hs_evm_defconfig @@ -30,6 +30,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -40,13 +41,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2l_evm_defconfig b/configs/k2l_evm_defconfig index 4f04caa1a3..cb638082da 100644 --- a/configs/k2l_evm_defconfig +++ b/configs/k2l_evm_defconfig @@ -37,6 +37,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -47,13 +48,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/configs/k2l_hs_evm_defconfig b/configs/k2l_hs_evm_defconfig index 9ce23dec93..4ce7801e4e 100644 --- a/configs/k2l_hs_evm_defconfig +++ b/configs/k2l_hs_evm_defconfig @@ -29,6 +29,7 @@ CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_TI_AEMIF=y +CONFIG_MISC=y # CONFIG_MMC is not set CONFIG_NAND=y CONFIG_NAND_DAVINCI=y @@ -39,13 +40,19 @@ CONFIG_PHYLIB=y CONFIG_PHY_MARVELL=y CONFIG_DM_ETH=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_NOP_PHY=y +CONFIG_KEYSTONE_USB_PHY=y CONFIG_DM_SERIAL=y CONFIG_SYS_NS16550=y CONFIG_SPI=y CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y +CONFIG_DM_USB=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile index 285c20ae86..948683a52b 100644 --- a/drivers/usb/host/Makefile +++ b/drivers/usb/host/Makefile @@ -50,7 +50,6 @@ obj-$(CONFIG_USB_XHCI_DWC3) += xhci-dwc3.o obj-$(CONFIG_USB_XHCI_DWC3_OF_SIMPLE) += dwc3-of-simple.o obj-$(CONFIG_USB_XHCI_ROCKCHIP) += xhci-rockchip.o obj-$(CONFIG_USB_XHCI_ZYNQMP) += xhci-zynqmp.o -obj-$(CONFIG_USB_XHCI_KEYSTONE) += xhci-keystone.o obj-$(CONFIG_USB_XHCI_EXYNOS) += xhci-exynos5.o obj-$(CONFIG_USB_XHCI_FSL) += xhci-fsl.o obj-$(CONFIG_USB_XHCI_MVEBU) += xhci-mvebu.o diff --git a/drivers/usb/host/xhci-keystone.c b/drivers/usb/host/xhci-keystone.c deleted file mode 100644 index 200b3f0e10..0000000000 --- a/drivers/usb/host/xhci-keystone.c +++ /dev/null @@ -1,240 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * USB 3.0 DRD Controller - * - * (C) Copyright 2012-2014 - * Texas Instruments Incorporated, - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "xhci.h" - -struct kdwc3_irq_regs { - u32 revision; /* 0x000 */ - u32 rsvd0[3]; - u32 sysconfig; /* 0x010 */ - u32 rsvd1[1]; - u32 irq_eoi; - u32 rsvd2[1]; - struct { - u32 raw_status; - u32 status; - u32 enable_set; - u32 enable_clr; - } irqs[16]; -}; - -struct keystone_xhci { - struct xhci_hccr *hcd; - struct dwc3 *dwc3_reg; - struct xhci_hcor *hcor; - struct kdwc3_irq_regs *usbss; - struct keystone_xhci_phy *phy; -}; - -struct keystone_xhci keystone; - -static void keystone_xhci_phy_set(struct keystone_xhci_phy *phy) -{ - u32 val; - - /* - * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't. - * It should always be cleared because our USB PHY has an onchip VBUS - * analog comparator. - */ - val = readl(&phy->phy_clock); - /* quit selecting the vbusvldextsel by default! */ - val &= ~USB3_PHY_OTG_VBUSVLDECTSEL; - writel(val, &phy->phy_clock); -} - -static void keystone_xhci_phy_unset(struct keystone_xhci_phy *phy) -{ - u32 val; - - /* Disable the PHY REFCLK clock gate */ - val = readl(&phy->phy_clock); - val &= ~USB3_PHY_REF_SSP_EN; - writel(val, &phy->phy_clock); -} - -static int keystone_xhci_core_init(struct dwc3 *dwc3_reg) -{ - int ret; - - ret = dwc3_core_init(dwc3_reg); - if (ret) { - debug("failed to initialize core\n"); - return -EINVAL; - } - - /* We are hard-coding DWC3 core to Host Mode */ - dwc3_set_mode(dwc3_reg, DWC3_GCTL_PRTCAP_HOST); - - return 0; -} - -int xhci_hcd_init(int index, - struct xhci_hccr **ret_hccr, struct xhci_hcor **ret_hcor) -{ - u32 val; - int ret; - struct xhci_hccr *hcd; - struct xhci_hcor *hcor; - struct kdwc3_irq_regs *usbss; - struct keystone_xhci_phy *phy; - - usbss = (struct kdwc3_irq_regs *)CONFIG_USB_SS_BASE; - phy = (struct keystone_xhci_phy *)CONFIG_DEV_USB_PHY_BASE; - - /* Enable the PHY REFCLK clock gate with phy_ref_ssp_en = 1 */ - val = readl(&(phy->phy_clock)); - val |= USB3_PHY_REF_SSP_EN; - writel(val, &phy->phy_clock); - - mdelay(100); - - /* Release USB from reset */ - ret = psc_enable_module(KS2_LPSC_USB); - if (ret) { - puts("Cannot enable USB module"); - return -1; - } - - mdelay(100); - - /* Initialize usb phy */ - keystone_xhci_phy_set(phy); - - /* soft reset usbss */ - writel(1, &usbss->sysconfig); - while (readl(&usbss->sysconfig) & 1) - ; - - val = readl(&usbss->revision); - debug("usbss revision %x\n", val); - - /* Initialize usb core */ - hcd = (struct xhci_hccr *)CONFIG_USB_HOST_XHCI_BASE; - keystone.dwc3_reg = (struct dwc3 *)(CONFIG_USB_HOST_XHCI_BASE + - DWC3_REG_OFFSET); - - keystone_xhci_core_init(keystone.dwc3_reg); - - /* set register addresses */ - hcor = (struct xhci_hcor *)((uint32_t)hcd + - HC_LENGTH(readl(&hcd->cr_capbase))); - - debug("Keystone2-xhci: init hccr %08x and hcor %08x hc_length %d\n", - (u32)hcd, (u32)hcor, - (u32)HC_LENGTH(xhci_readl(&hcd->cr_capbase))); - - keystone.usbss = usbss; - keystone.phy = phy; - keystone.hcd = hcd; - keystone.hcor = hcor; - - *ret_hccr = hcd; - *ret_hcor = hcor; - - return 0; -} - -static int keystone_xhci_phy_suspend(void) -{ - int loop_cnt = 0; - struct xhci_hcor *hcor; - uint32_t *portsc_1 = NULL; - uint32_t *portsc_2 = NULL; - u32 val, usb2_pls, usb3_pls, event_q; - struct dwc3 *dwc3_reg = keystone.dwc3_reg; - - /* set register addresses */ - hcor = keystone.hcor; - - /* Bypass Scrambling and Set Shorter Training sequence for simulation */ - val = DWC3_GCTL_PWRDNSCALE(0x4b0) | DWC3_GCTL_PRTCAPDIR(0x2); - writel(val, &dwc3_reg->g_ctl); - - /* GUSB2PHYCFG */ - val = readl(&dwc3_reg->g_usb2phycfg[0]); - - /* assert bit 6 (SusPhy) */ - val |= DWC3_GUSB2PHYCFG_SUSPHY; - writel(val, &dwc3_reg->g_usb2phycfg[0]); - - /* GUSB3PIPECTL */ - val = readl(&dwc3_reg->g_usb3pipectl[0]); - - /* - * assert bit 29 to allow PHY to go to suspend when idle - * and cause the USB3 SS PHY to enter suspend mode - */ - val |= (BIT(29) | DWC3_GUSB3PIPECTL_SUSPHY); - writel(val, &dwc3_reg->g_usb3pipectl[0]); - - /* - * Steps necessary to allow controller to suspend even when - * VBUS is HIGH: - * - Init DCFG[2:0] (DevSpd) to: 1=FS - * - Init GEVNTADR0 to point to an eventQ - * - Init GEVNTSIZ0 to 0x0100 to specify the size of the eventQ - * - Init DCTL::Run_nStop = 1 - */ - writel(0x00020001, &dwc3_reg->d_cfg); - /* TODO: local2global( (Uint32) eventQ )? */ - writel((u32)&event_q, &dwc3_reg->g_evnt_buf[0].g_evntadrlo); - writel(0, &dwc3_reg->g_evnt_buf[0].g_evntadrhi); - writel(0x4, &dwc3_reg->g_evnt_buf[0].g_evntsiz); - /* Run */ - writel(DWC3_DCTL_RUN_STOP, &dwc3_reg->d_ctl); - - mdelay(100); - - /* Wait for USB2 & USB3 PORTSC::PortLinkState to indicate suspend */ - portsc_1 = (uint32_t *)(&hcor->portregs[0].or_portsc); - portsc_2 = (uint32_t *)(&hcor->portregs[1].or_portsc); - usb2_pls = 0; - usb3_pls = 0; - do { - ++loop_cnt; - usb2_pls = (readl(portsc_1) & PORT_PLS_MASK) >> 5; - usb3_pls = (readl(portsc_2) & PORT_PLS_MASK) >> 5; - } while (((usb2_pls != 0x4) || (usb3_pls != 0x4)) && loop_cnt < 1000); - - if (usb2_pls != 0x4 || usb3_pls != 0x4) { - debug("USB suspend failed - PLS USB2=%02x, USB3=%02x\n", - usb2_pls, usb3_pls); - return -1; - } - - debug("USB2 and USB3 PLS - Disabled, loop_cnt=%d\n", loop_cnt); - return 0; -} - -void xhci_hcd_stop(int index) -{ - /* Disable USB */ - if (keystone_xhci_phy_suspend()) - return; - - if (psc_disable_module(KS2_LPSC_USB)) { - debug("PSC disable module USB failed!\n"); - return; - } - - /* Disable PHY */ - keystone_xhci_phy_unset(keystone.phy); - -/* memset(&keystone, 0, sizeof(struct keystone_xhci)); */ - debug("xhci_hcd_stop OK.\n"); -} diff --git a/include/configs/ti_armv7_keystone2.h b/include/configs/ti_armv7_keystone2.h index 5e504f6d3d..fae72e7c8a 100644 --- a/include/configs/ti_armv7_keystone2.h +++ b/include/configs/ti_armv7_keystone2.h @@ -169,13 +169,6 @@ #define CONFIG_SYS_NAND_MAX_CHIPS 1 #define CONFIG_SYS_NAND_NO_SUBPAGE_WRITE -/* USB Configuration */ -#define CONFIG_USB_XHCI_KEYSTONE -#define CONFIG_USB_SS_BASE KS2_USB_SS_BASE -#define CONFIG_USB_HOST_XHCI_BASE KS2_USB_HOST_XHCI_BASE -#define CONFIG_DEV_USB_PHY_BASE KS2_DEV_USB_PHY_BASE -#define CONFIG_USB_PHY_CFG_BASE KS2_USB_PHY_CFG_BASE - /* U-Boot general configuration */ #define CONFIG_MX_CYCLIC #define CONFIG_TIMESTAMP From 7ff0528a7395384d281128ecfcebbc5d903c26f3 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:13:01 +0100 Subject: [PATCH 11/27] configs: k2g_evm: Enable DFU on K2G EVM The K2G evm uses the generic DWC3 driver. DFU can thus be enabled. Enabling DFU for easier firmware update. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- configs/k2g_evm_defconfig | 6 ++++++ configs/k2g_hs_evm_defconfig | 6 ++++++ include/configs/ti_armv7_keystone2.h | 12 ++++++++++++ 3 files changed, 24 insertions(+) diff --git a/configs/k2g_evm_defconfig b/configs/k2g_evm_defconfig index 95c835abd9..8a07039696 100644 --- a/configs/k2g_evm_defconfig +++ b/configs/k2g_evm_defconfig @@ -35,6 +35,7 @@ CONFIG_MULTI_DTB_FIT=y CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y # CONFIG_BLK is not set +CONFIG_DFU_MMC=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_MISC=y CONFIG_DM_MMC=y @@ -61,9 +62,14 @@ CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y CONFIG_DM_USB=y +CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GADGET=y CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_USB_FUNCTION_SDP=y diff --git a/configs/k2g_hs_evm_defconfig b/configs/k2g_hs_evm_defconfig index 47c30a6fa0..5f91f11d36 100644 --- a/configs/k2g_hs_evm_defconfig +++ b/configs/k2g_hs_evm_defconfig @@ -28,6 +28,7 @@ CONFIG_MULTI_DTB_FIT=y CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y # CONFIG_BLK is not set +CONFIG_DFU_MMC=y CONFIG_SYS_I2C_DAVINCI=y CONFIG_MISC=y CONFIG_DM_MMC=y @@ -54,9 +55,14 @@ CONFIG_DM_SPI=y CONFIG_DAVINCI_SPI=y CONFIG_USB=y CONFIG_DM_USB=y +CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GADGET=y CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_STORAGE=y CONFIG_DRIVER_TI_KEYSTONE_NET=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_USB_FUNCTION_SDP=y diff --git a/include/configs/ti_armv7_keystone2.h b/include/configs/ti_armv7_keystone2.h index fae72e7c8a..0c7d664868 100644 --- a/include/configs/ti_armv7_keystone2.h +++ b/include/configs/ti_armv7_keystone2.h @@ -169,6 +169,17 @@ #define CONFIG_SYS_NAND_MAX_CHIPS 1 #define CONFIG_SYS_NAND_NO_SUBPAGE_WRITE +#define DFU_ALT_INFO_MMC \ + "dfu_alt_info_mmc=" \ + "MLO fat 0 1;" \ + "u-boot.img fat 0 1;" \ + "uEnv.txt fat 0 1\0" + +/* DFU settings */ +#define DFUARGS \ + "dfu_bufsiz=0x10000\0" \ + DFU_ALT_INFO_MMC \ + /* U-Boot general configuration */ #define CONFIG_MX_CYCLIC #define CONFIG_TIMESTAMP @@ -207,6 +218,7 @@ #define CONFIG_EXTRA_ENV_SETTINGS \ DEFAULT_LINUX_BOOT_ENV \ CONFIG_EXTRA_ENV_KS2_BOARD_SETTINGS \ + DFUARGS \ "bootdir=/boot\0" \ "tftp_root=/\0" \ "nfs_root=/export\0" \ From 9a1dde58f5ed4a929971b37b7436040947ec732a Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:47 +0100 Subject: [PATCH 12/27] spl: drivers: Link usb common library to SPL if USB gadget is enabled Some drivers might need to access common USB functions such as usb_get_maximum_speed() or usb_get_dr_mode(). Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/Makefile b/drivers/Makefile index 752caeae4e..5e3b122769 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_SPL_ETH_SUPPORT) += net/phy/ obj-$(CONFIG_SPL_USB_ETHER) += net/phy/ obj-$(CONFIG_SPL_MUSB_NEW_SUPPORT) += usb/musb-new/ obj-$(CONFIG_SPL_USB_GADGET_SUPPORT) += usb/gadget/ +obj-$(CONFIG_SPL_USB_GADGET_SUPPORT) += usb/common/ obj-$(CONFIG_SPL_USB_GADGET_SUPPORT) += usb/gadget/udc/ obj-$(CONFIG_SPL_DFU_SUPPORT) += dfu/ obj-$(CONFIG_SPL_WATCHDOG_SUPPORT) += watchdog/ From 0f46fb58a2355edf631c19797ad5c1f5f9403236 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:48 +0100 Subject: [PATCH 13/27] spl: net: dm: usb: bind the gadget before attempting to load the image If DM_USB_GADGET is used, the usb ethernet gadget driver must be bound to a controller before the image can be downloaded over the network. In u-boot this can be done with the bind command. In SPL it must be done programmatically. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- common/spl/spl_net.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/spl/spl_net.c b/common/spl/spl_net.c index b6967ff69e..c91ad2b6dd 100644 --- a/common/spl/spl_net.c +++ b/common/spl/spl_net.c @@ -85,7 +85,9 @@ int spl_net_load_image_usb(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { bootdev->boot_device_name = "usb_ether"; - +#if CONFIG_IS_ENABLED(DM_USB_GADGET) + usb_ether_init(); +#endif return spl_net_load_image(spl_image, bootdev); } SPL_LOAD_IMAGE_METHOD("USB eth", 0, BOOT_DEVICE_USBETH, spl_net_load_image_usb); From 512a84c4447707439da48297b2062dcfc8be61a1 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:49 +0100 Subject: [PATCH 14/27] phy: omap_usb2: Add support for am437x Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/phy/omap-usb2-phy.c | 45 ++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/drivers/phy/omap-usb2-phy.c b/drivers/phy/omap-usb2-phy.c index fd20e8c168..be3bb0d367 100644 --- a/drivers/phy/omap-usb2-phy.c +++ b/drivers/phy/omap-usb2-phy.c @@ -19,6 +19,11 @@ #define OMAP_DEV_PHY_PD BIT(0) #define OMAP_USB2_PHY_PD BIT(28) +#define AM437X_USB2_PHY_PD BIT(0) +#define AM437X_USB2_OTG_PD BIT(1) +#define AM437X_USB2_OTGVDET_EN BIT(19) +#define AM437X_USB2_OTGSESSEND_EN BIT(20) + #define USB2PHY_DISCON_BYP_LATCH BIT(31) #define USB2PHY_ANA_CONFIG1 (0x4c) @@ -60,6 +65,15 @@ static const struct usb_phy_data dra7x_usb2_phy2_data = { .power_off = OMAP_USB2_PHY_PD, }; +static const struct usb_phy_data am437x_usb2_data = { + .label = "am437x_usb2", + .flags = 0, + .mask = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD | + AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, + .power_on = AM437X_USB2_OTGVDET_EN | AM437X_USB2_OTGSESSEND_EN, + .power_off = AM437X_USB2_PHY_PD | AM437X_USB2_OTG_PD, +}; + static const struct udevice_id omap_usb2_id_table[] = { { .compatible = "ti,omap5-usb2", @@ -73,6 +87,10 @@ static const struct udevice_id omap_usb2_id_table[] = { .compatible = "ti,dra7x-usb2-phy2", .data = (ulong)&dra7x_usb2_phy2_data, }, + { + .compatible = "ti,am437x-usb2", + .data = (ulong)&am437x_usb2_data, + }, {}, }; @@ -170,20 +188,25 @@ int omap_usb2_phy_probe(struct udevice *dev) } regmap = syscon_regmap_lookup_by_phandle(dev, "syscon-phy-power"); - if (IS_ERR(regmap)) { - printf("can't get regmap (err %ld)\n", PTR_ERR(regmap)); - return PTR_ERR(regmap); + if (!IS_ERR(regmap)) { + priv->pwr_regmap = regmap; + rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2); + if (rc) { + printf("couldn't get power reg. offset (err %d)\n", rc); + return rc; + } + priv->pwr_reg_offset = tmp[1]; + return 0; } - priv->pwr_regmap = regmap; - - rc = dev_read_u32_array(dev, "syscon-phy-power", tmp, 2); - if (rc) { - printf("couldn't get power reg. offset (err %d)\n", rc); - return rc; + regmap = syscon_regmap_lookup_by_phandle(dev, "ctrl-module"); + if (!IS_ERR(regmap)) { + priv->pwr_regmap = regmap; + priv->pwr_reg_offset = 0; + return 0; } - priv->pwr_reg_offset = tmp[1]; - return 0; + printf("can't get regmap (err %ld)\n", PTR_ERR(regmap)); + return PTR_ERR(regmap); } U_BOOT_DRIVER(omap_usb2_phy) = { From 1ce5f1f933b6b3e0994b4b7d198afe0198442888 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:50 +0100 Subject: [PATCH 15/27] dwc3-generic: Add support for the am437x Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/usb/dwc3/dwc3-generic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c index 0c189b81ff..3e6c494dc6 100644 --- a/drivers/usb/dwc3/dwc3-generic.c +++ b/drivers/usb/dwc3/dwc3-generic.c @@ -344,6 +344,7 @@ static const struct udevice_id dwc3_glue_ids[] = { { .compatible = "xlnx,zynqmp-dwc3" }, { .compatible = "ti,keystone-dwc3"}, { .compatible = "ti,dwc3", .data = (ulong)&ti_ops }, + { .compatible = "ti,am437x-dwc3", .data = (ulong)&ti_ops }, { } }; From 347631bcddbfb3041b84e9b3a1812b4874c66b2d Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:51 +0100 Subject: [PATCH 16/27] board: ti: am43xx: turn on USB clocks Enable USB clocks in late init stage to support ports under DM_USB. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- board/ti/am43xx/board.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c index 31bc0f49a4..536c5b88ed 100644 --- a/board/ti/am43xx/board.c +++ b/board/ti/am43xx/board.c @@ -705,6 +705,19 @@ int board_init(void) } #ifdef CONFIG_BOARD_LATE_INIT +#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL) +static int device_okay(const char *path) +{ + int node; + + node = fdt_path_offset(gd->fdt_blob, path); + if (node < 0) + return 0; + + return fdtdec_get_is_enabled(gd->fdt_blob, node); +} +#endif + int board_late_init(void) { #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG @@ -717,10 +730,18 @@ int board_late_init(void) if (get_device_type() == HS_DEVICE) env_set("boot_fit", "1"); #endif + +#if CONFIG_IS_ENABLED(DM_USB) && CONFIG_IS_ENABLED(OF_CONTROL) + if (device_okay("/ocp/omap_dwc3@48380000")) + enable_usb_clocks(0); + if (device_okay("/ocp/omap_dwc3@483c0000")) + enable_usb_clocks(1); +#endif return 0; } #endif +#if !CONFIG_IS_ENABLED(DM_USB_GADGET) #ifdef CONFIG_USB_DWC3 static struct dwc3_device usb_otg_ss1 = { .maximum_speed = USB_SPEED_HIGH, @@ -823,6 +844,7 @@ int board_usb_cleanup(int index, enum usb_init_type init) return 0; } #endif /* defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_OMAP) */ +#endif /* !CONFIG_IS_ENABLED(DM_USB_GADGET) */ #ifdef CONFIG_DRIVER_TI_CPSW From 894f002f20be6b5354a76014ad9d4b68fcbad5aa Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:52 +0100 Subject: [PATCH 17/27] dts: Add a u-boot specific dtsi file for the am4372 This file is used to override the values found in am4372.dtsi Use it to fix the "compatible" options for the controllers used to support the USB (parent bus and syscons). Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- arch/arm/dts/am4372-generic-u-boot.dtsi | 2 ++ arch/arm/dts/am4372-u-boot.dtsi | 20 ++++++++++++++++++++ arch/arm/dts/am437x-gp-evm-u-boot.dtsi | 2 ++ arch/arm/dts/am437x-idk-evm-u-boot.dtsi | 2 ++ arch/arm/dts/am437x-sk-evm-u-boot.dtsi | 2 ++ 5 files changed, 28 insertions(+) create mode 100644 arch/arm/dts/am4372-u-boot.dtsi diff --git a/arch/arm/dts/am4372-generic-u-boot.dtsi b/arch/arm/dts/am4372-generic-u-boot.dtsi index d485679de4..6ba5c16492 100644 --- a/arch/arm/dts/am4372-generic-u-boot.dtsi +++ b/arch/arm/dts/am4372-generic-u-boot.dtsi @@ -3,6 +3,8 @@ * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ */ +#include "am4372-u-boot.dtsi" + /{ ocp { u-boot,dm-pre-reloc; diff --git a/arch/arm/dts/am4372-u-boot.dtsi b/arch/arm/dts/am4372-u-boot.dtsi new file mode 100644 index 0000000000..cda42144f0 --- /dev/null +++ b/arch/arm/dts/am4372-u-boot.dtsi @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ + */ + +&am43xx_control_usb2phy1 { + compatible = "ti,control-phy-usb2-am437", "syscon"; +}; + +&am43xx_control_usb2phy2 { + compatible = "ti,control-phy-usb2-am437", "syscon"; +}; + +&ocp2scp0 { + compatible = "ti,am437x-ocp2scp", "ti,omap-ocp2scp", "simple-bus"; +}; + +&ocp2scp1 { + compatible = "ti,am437x-ocp2scp", "ti,omap-ocp2scp", "simple-bus"; +}; diff --git a/arch/arm/dts/am437x-gp-evm-u-boot.dtsi b/arch/arm/dts/am437x-gp-evm-u-boot.dtsi index 03a1c1dd39..d950d32f17 100644 --- a/arch/arm/dts/am437x-gp-evm-u-boot.dtsi +++ b/arch/arm/dts/am437x-gp-evm-u-boot.dtsi @@ -7,6 +7,8 @@ * Based on "dra7.dtsi" */ +#include "am4372-u-boot.dtsi" + /{ ocp { u-boot,dm-spl; diff --git a/arch/arm/dts/am437x-idk-evm-u-boot.dtsi b/arch/arm/dts/am437x-idk-evm-u-boot.dtsi index 0a3d79a372..3aa9195e44 100644 --- a/arch/arm/dts/am437x-idk-evm-u-boot.dtsi +++ b/arch/arm/dts/am437x-idk-evm-u-boot.dtsi @@ -3,6 +3,8 @@ * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ */ +#include "am4372-u-boot.dtsi" + /{ ocp { u-boot,dm-spl; diff --git a/arch/arm/dts/am437x-sk-evm-u-boot.dtsi b/arch/arm/dts/am437x-sk-evm-u-boot.dtsi index 0a3d79a372..3aa9195e44 100644 --- a/arch/arm/dts/am437x-sk-evm-u-boot.dtsi +++ b/arch/arm/dts/am437x-sk-evm-u-boot.dtsi @@ -3,6 +3,8 @@ * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ */ +#include "am4372-u-boot.dtsi" + /{ ocp { u-boot,dm-spl; From 4ea07111048efc5bd7f5b3a4ffd0271042f1f448 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:53 +0100 Subject: [PATCH 18/27] dts: am4372: Enable USB1 in SPL USB1 can be used by the romboot on all am4372 platforms to download a firmware (SPL in our case). It makes sense to enable USB1 in the SPL to download u-boot. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- arch/arm/dts/am4372-u-boot.dtsi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm/dts/am4372-u-boot.dtsi b/arch/arm/dts/am4372-u-boot.dtsi index cda42144f0..99922ca030 100644 --- a/arch/arm/dts/am4372-u-boot.dtsi +++ b/arch/arm/dts/am4372-u-boot.dtsi @@ -18,3 +18,23 @@ &ocp2scp1 { compatible = "ti,am437x-ocp2scp", "ti,omap-ocp2scp", "simple-bus"; }; + +&dwc3_1 { + u-boot,dm-spl; +}; + +&usb1 { + u-boot,dm-spl; +}; + +&usb2_phy1 { + u-boot,dm-spl; +}; + +&am43xx_control_usb2phy1 { + u-boot,dm-spl; +}; + +&ocp2scp0 { + u-boot,dm-spl; +}; From 3293e87ba641693d67508dfc566256d421649005 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:54 +0100 Subject: [PATCH 19/27] configs: am43xx_evm: Enable DM_USB and DM_USB_GADGET Enable DM_USB and DM_USB_GADGET for AM43xx EVM boards. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- configs/am43xx_evm_defconfig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/configs/am43xx_evm_defconfig b/configs/am43xx_evm_defconfig index 7601263be4..aeecdc27fa 100644 --- a/configs/am43xx_evm_defconfig +++ b/configs/am43xx_evm_defconfig @@ -27,11 +27,14 @@ CONFIG_DEFAULT_DEVICE_TREE="am437x-gp-evm" CONFIG_OF_LIST="am437x-gp-evm am437x-sk-evm am43x-epos-evm am437x-idk-evm" CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y +CONFIG_REGMAP=y +CONFIG_SYSCON=y # CONFIG_BLK is not set CONFIG_DFU_MMC=y CONFIG_DFU_RAM=y CONFIG_DFU_SF=y CONFIG_DM_GPIO=y +CONFIG_MISC=y CONFIG_DM_MMC=y CONFIG_MMC_OMAP_HS=y CONFIG_NAND=y @@ -40,17 +43,22 @@ CONFIG_SPI_FLASH_MACRONIX=y CONFIG_DRIVER_TI_CPSW=y CONFIG_PHY_GIGE=y CONFIG_MII=y +CONFIG_PHY=y +CONFIG_OMAP_USB2_PHY=y CONFIG_DM_SERIAL=y CONFIG_SPI=y CONFIG_TI_QSPI=y CONFIG_TIMER=y CONFIG_OMAP_TIMER=y CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y CONFIG_USB_DWC3_GADGET=y CONFIG_USB_DWC3_OMAP=y +CONFIG_USB_DWC3_GENERIC=y CONFIG_USB_DWC3_PHY_OMAP=y CONFIG_OMAP_USB_PHY=y CONFIG_USB_STORAGE=y From 2f829af946fae52854bf796f307e686c1efff6aa Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:55 +0100 Subject: [PATCH 20/27] configs: am43xx: Enable RNDIS support in SPL The AM43xx SOCs have the ability to download the SPl through USB (RNDIS). Adding support for RNDIS in SPL allows to also download u-boot through USB. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- configs/am43xx_evm_defconfig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configs/am43xx_evm_defconfig b/configs/am43xx_evm_defconfig index aeecdc27fa..9bbda434ee 100644 --- a/configs/am43xx_evm_defconfig +++ b/configs/am43xx_evm_defconfig @@ -3,6 +3,7 @@ CONFIG_ARCH_OMAP2PLUS=y CONFIG_TI_COMMON_CMD_OPTIONS=y CONFIG_SYS_MALLOC_F_LEN=0x2000 CONFIG_AM43XX=y +CONFIG_SPL_DRIVERS_MISC_SUPPORT=y CONFIG_SPL=y CONFIG_DISTRO_DEFAULTS=y CONFIG_SPL_LOAD_FIT=y @@ -12,7 +13,11 @@ CONFIG_SYS_CONSOLE_INFO_QUIET=y # CONFIG_MISC_INIT_R is not set CONFIG_VERSION_VARIABLE=y CONFIG_SPL_MTD_SUPPORT=y +CONFIG_SPL_NET_SUPPORT=y +CONFIG_SPL_NET_VCI_STRING="AM43xx U-Boot SPL" CONFIG_SPL_OS_BOOT=y +CONFIG_SPL_USB_GADGET_SUPPORT=y +CONFIG_SPL_USB_ETHER=y CONFIG_CMD_SPL=y CONFIG_CMD_SPL_NAND_OFS=0x00100000 CONFIG_CMD_SPL_WRITE_SIZE=0x40000 @@ -28,7 +33,9 @@ CONFIG_OF_LIST="am437x-gp-evm am437x-sk-evm am43x-epos-evm am437x-idk-evm" CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG=y CONFIG_DM=y CONFIG_REGMAP=y +CONFIG_SPL_REGMAP=y CONFIG_SYSCON=y +CONFIG_SPL_SYSCON=y # CONFIG_BLK is not set CONFIG_DFU_MMC=y CONFIG_DFU_RAM=y @@ -44,6 +51,7 @@ CONFIG_DRIVER_TI_CPSW=y CONFIG_PHY_GIGE=y CONFIG_MII=y CONFIG_PHY=y +CONFIG_SPL_PHY=y CONFIG_OMAP_USB2_PHY=y CONFIG_DM_SERIAL=y CONFIG_SPI=y @@ -52,7 +60,9 @@ CONFIG_TIMER=y CONFIG_OMAP_TIMER=y CONFIG_USB=y CONFIG_DM_USB=y +CONFIG_SPL_DM_USB=y CONFIG_DM_USB_GADGET=y +CONFIG_SPL_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_XHCI_DWC3=y CONFIG_USB_DWC3=y @@ -67,3 +77,4 @@ CONFIG_USB_GADGET_MANUFACTURER="Texas Instruments" CONFIG_USB_GADGET_VENDOR_NUM=0x0403 CONFIG_USB_GADGET_PRODUCT_NUM=0xbd00 CONFIG_USB_GADGET_DOWNLOAD=y +CONFIG_USB_ETHER=y From 1594c75b3e285cac2ed19f958a0918ee677e4286 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:56 +0100 Subject: [PATCH 21/27] usb: musb-new: Allow the diver not to use the set_phy_power() callback The set_phy_power() callback is part of struct omap_musb_board_data. This structure is part of the platform data passed to the musb-new driver. This does not really fit with the Driver Model, so allow not to use struct omap_musb_board_data to turn the phy on or off. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- drivers/usb/musb-new/am35x.c | 8 ++++---- drivers/usb/musb-new/musb_dsps.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/usb/musb-new/am35x.c b/drivers/usb/musb-new/am35x.c index 251b4e9969..bda099c63f 100644 --- a/drivers/usb/musb-new/am35x.c +++ b/drivers/usb/musb-new/am35x.c @@ -406,7 +406,7 @@ static int am35x_musb_init(struct musb *musb) musb_writel(reg_base, USB_CTRL_REG, AM35X_SOFT_RESET_MASK); /* Start the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 1); msleep(5); @@ -437,7 +437,7 @@ static int am35x_musb_exit(struct musb *musb) #endif /* Shutdown the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 0); #ifndef __UBOOT__ @@ -628,7 +628,7 @@ static int am35x_suspend(struct device *dev) struct omap_musb_board_data *data = plat->board_data; /* Shutdown the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 0); clk_disable(glue->phy_clk); @@ -645,7 +645,7 @@ static int am35x_resume(struct device *dev) int ret; /* Start the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 1); ret = clk_enable(glue->phy_clk); diff --git a/drivers/usb/musb-new/musb_dsps.c b/drivers/usb/musb-new/musb_dsps.c index 9b814f4cd4..0c794b310a 100644 --- a/drivers/usb/musb-new/musb_dsps.c +++ b/drivers/usb/musb-new/musb_dsps.c @@ -450,7 +450,7 @@ 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. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 1); musb->isr = dsps_interrupt; @@ -491,7 +491,7 @@ static int dsps_musb_exit(struct musb *musb) #endif /* Shutdown the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 0); #ifndef __UBOOT__ @@ -691,7 +691,7 @@ static int dsps_suspend(struct device *dev) struct omap_musb_board_data *data = plat->board_data; /* Shutdown the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 0); return 0; @@ -703,7 +703,7 @@ static int dsps_resume(struct device *dev) struct omap_musb_board_data *data = plat->board_data; /* Start the on-chip PHY and its PLL. */ - if (data->set_phy_power) + if (data && data->set_phy_power) data->set_phy_power(data->dev, 1); return 0; From 7d98dbcc3dc8f1b93676d0953f3bee0db3796eb0 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:57 +0100 Subject: [PATCH 22/27] usb: musb-new: Add support for DM_USB Enable DM for USB peripheral in the musb-new driver. Also make sure that the driver can be used in the SPL. This implies that: * the driver must work with and without the OF_CONTROL option. That in turn, implies that the platform data can be passed in a struct ti_musb_platdata or be read from the dtb * usb.o is linked in the SPL if host support is enabled Another change is that the driver does not fail to bind (and stop the boot process) if one of the child driver does not bind. Reporting the error is enough. This kind of error would appear if the port is configured in the DTS but the driver is not activated in the config. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- arch/arm/include/asm/omap_musb.h | 8 ++ common/Makefile | 3 + drivers/usb/musb-new/musb_gadget.c | 11 ++ drivers/usb/musb-new/musb_uboot.c | 4 +- drivers/usb/musb-new/ti-musb.c | 181 +++++++++++++++++++++-------- 5 files changed, 159 insertions(+), 48 deletions(-) diff --git a/arch/arm/include/asm/omap_musb.h b/arch/arm/include/asm/omap_musb.h index 875f1002af..b40ea005be 100644 --- a/arch/arm/include/asm/omap_musb.h +++ b/arch/arm/include/asm/omap_musb.h @@ -7,6 +7,7 @@ #ifndef __ASM_ARM_OMAP_MUSB_H #define __ASM_ARM_OMAP_MUSB_H +#include extern struct musb_platform_ops musb_dsps_ops; extern const struct musb_platform_ops am35x_ops; @@ -21,4 +22,11 @@ struct omap_musb_board_data { }; enum musb_interface {MUSB_INTERFACE_ULPI, MUSB_INTERFACE_UTMI}; + +struct ti_musb_platdata { + void *base; + void *ctrl_mod_base; + struct musb_hdrc_platform_data plat; +}; + #endif /* __ASM_ARM_OMAP_MUSB_H */ diff --git a/common/Makefile b/common/Makefile index 65d89dc62d..0de60b3ced 100644 --- a/common/Makefile +++ b/common/Makefile @@ -74,9 +74,12 @@ obj-$(CONFIG_SPL_YMODEM_SUPPORT) += xyzModem.o obj-$(CONFIG_SPL_LOAD_FIT) += common_fit.o obj-$(CONFIG_SPL_NET_SUPPORT) += miiphyutil.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += fdt_support.o + ifdef CONFIG_SPL_USB_HOST_SUPPORT obj-$(CONFIG_SPL_USB_SUPPORT) += usb.o usb_hub.o obj-$(CONFIG_USB_STORAGE) += usb_storage.o +else +obj-$(CONFIG_USB_MUSB_HOST) += usb.o endif endif # CONFIG_SPL_BUILD diff --git a/drivers/usb/musb-new/musb_gadget.c b/drivers/usb/musb-new/musb_gadget.c index 8b6cec192f..b35d33ffed 100644 --- a/drivers/usb/musb-new/musb_gadget.c +++ b/drivers/usb/musb-new/musb_gadget.c @@ -1775,6 +1775,14 @@ static int musb_gadget_start(struct usb_gadget *g, struct usb_gadget_driver *driver); static int musb_gadget_stop(struct usb_gadget *g, struct usb_gadget_driver *driver); +#else +static int musb_gadget_stop(struct usb_gadget *g) +{ + struct musb *musb = gadget_to_musb(g); + + musb_stop(musb); + return 0; +} #endif static const struct usb_gadget_ops musb_gadget_operations = { @@ -1787,6 +1795,9 @@ static const struct usb_gadget_ops musb_gadget_operations = { #ifndef __UBOOT__ .udc_start = musb_gadget_start, .udc_stop = musb_gadget_stop, +#else + .udc_start = musb_gadget_start, + .udc_stop = musb_gadget_stop, #endif }; diff --git a/drivers/usb/musb-new/musb_uboot.c b/drivers/usb/musb-new/musb_uboot.c index d40772b1aa..9c8cc6e584 100644 --- a/drivers/usb/musb-new/musb_uboot.c +++ b/drivers/usb/musb-new/musb_uboot.c @@ -367,7 +367,7 @@ struct dm_usb_ops musb_usb_ops = { #endif /* CONFIG_IS_ENABLED(DM_USB) */ #endif /* CONFIG_USB_MUSB_HOST */ -#ifdef CONFIG_USB_MUSB_GADGET +#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET) static struct musb *gadget; int usb_gadget_handle_interrupts(int index) @@ -430,7 +430,7 @@ struct musb *musb_register(struct musb_hdrc_platform_data *plat, void *bdata, musbp = &musb_host.host; break; #endif -#ifdef CONFIG_USB_MUSB_GADGET +#if defined(CONFIG_USB_MUSB_GADGET) && !CONFIG_IS_ENABLED(DM_USB_GADGET) case MUSB_PERIPHERAL: musbp = &gadget; break; diff --git a/drivers/usb/musb-new/ti-musb.c b/drivers/usb/musb-new/ti-musb.c index ee0960704a..20ca2731b4 100644 --- a/drivers/usb/musb-new/ti-musb.c +++ b/drivers/usb/musb-new/ti-musb.c @@ -20,22 +20,33 @@ DECLARE_GLOBAL_DATA_PTR; #if CONFIG_IS_ENABLED(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_USB0_CTRL 0x0 #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 void ti_musb_set_phy_power(struct udevice *dev, u8 on) +{ + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + + if (!platdata->ctrl_mod_base) + return; + + 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); + } +} + +#if CONFIG_IS_ENABLED(OF_CONTROL) static int ti_musb_get_usb_index(int node) { @@ -64,20 +75,6 @@ static int ti_musb_get_usb_index(int node) 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); @@ -86,6 +83,7 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) int phys; int ctrl_mod; int usb_index; + struct musb_hdrc_config *musb_config; platdata->base = (void *)devfdt_get_addr_index(dev, 1); @@ -96,38 +94,41 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) switch (usb_index) { case 1: platdata->ctrl_mod_base += AM335X_USB1_CTRL; + break; case 0: + platdata->ctrl_mod_base += AM335X_USB0_CTRL; + break; default: break; } - platdata->musb_config.multipoint = fdtdec_get_int(fdt, node, - "mentor,multipoint", - -1); - if (platdata->musb_config.multipoint < 0) { + musb_config = malloc(sizeof(struct musb_hdrc_config)); + memset(musb_config, 0, sizeof(struct musb_hdrc_config)); + + musb_config->multipoint = fdtdec_get_int(fdt, node, + "mentor,multipoint", -1); + if (musb_config->multipoint < 0) { pr_err("MUSB multipoint DT entry missing\n"); return -ENOENT; } - platdata->musb_config.dyn_fifo = 1; + 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) { + musb_config->num_eps = fdtdec_get_int(fdt, node, "mentor,num-eps", + -1); + if (musb_config->num_eps < 0) { pr_err("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) { + musb_config->ram_bits = fdtdec_get_int(fdt, node, "mentor,ram-bits", + -1); + if (musb_config->ram_bits < 0) { pr_err("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.config = musb_config; platdata->plat.power = fdtdec_get_int(fdt, node, "mentor,power", -1); if (platdata->plat.power < 0) { @@ -136,29 +137,27 @@ static int ti_musb_ofdata_to_platdata(struct udevice *dev) } platdata->plat.platform_ops = &musb_dsps_ops; - platdata->plat.board_data = &platdata->otg_board_data; return 0; } +#endif 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, + NULL, platdata->base); if (!host->host) return -EIO; + ti_musb_set_phy_power(dev, 1); ret = musb_lowlevel_init(host); return ret; @@ -169,10 +168,12 @@ static int ti_musb_host_remove(struct udevice *dev) struct musb_host_data *host = dev_get_priv(dev); musb_stop(host->host); + ti_musb_set_phy_power(dev, 0); return 0; } +#if CONFIG_IS_ENABLED(OF_CONTROL) static int ti_musb_host_ofdata_to_platdata(struct udevice *dev) { struct ti_musb_platdata *platdata = dev_get_platdata(dev); @@ -190,11 +191,14 @@ static int ti_musb_host_ofdata_to_platdata(struct udevice *dev) return 0; } +#endif U_BOOT_DRIVER(ti_musb_host) = { .name = "ti-musb-host", .id = UCLASS_USB, +#if CONFIG_IS_ENABLED(OF_CONTROL) .ofdata_to_platdata = ti_musb_host_ofdata_to_platdata, +#endif .probe = ti_musb_host_probe, .remove = ti_musb_host_remove, .ops = &musb_usb_ops, @@ -202,6 +206,82 @@ U_BOOT_DRIVER(ti_musb_host) = { .priv_auto_alloc_size = sizeof(struct musb_host_data), }; +#if CONFIG_IS_ENABLED(DM_USB_GADGET) +struct ti_musb_peripheral { + struct musb *periph; +}; + +#if CONFIG_IS_ENABLED(OF_CONTROL) +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(dev); + int ret; + + ret = ti_musb_ofdata_to_platdata(dev); + if (ret) { + pr_err("platdata dt parse error\n"); + return ret; + } + platdata->plat.mode = MUSB_PERIPHERAL; + + return 0; +} +#endif + +int dm_usb_gadget_handle_interrupts(struct udevice *dev) +{ + struct ti_musb_peripheral *priv = dev_get_priv(dev); + + priv->periph->isr(0, priv->periph); + + return 0; +} + +static int ti_musb_peripheral_probe(struct udevice *dev) +{ + struct ti_musb_peripheral *priv = dev_get_priv(dev); + struct ti_musb_platdata *platdata = dev_get_platdata(dev); + int ret; + + priv->periph = musb_init_controller(&platdata->plat, + NULL, + platdata->base); + if (!priv->periph) + return -EIO; + + ti_musb_set_phy_power(dev, 1); + musb_gadget_setup(priv->periph); + return usb_add_gadget_udc((struct device *)dev, &priv->periph->g); +} + +static int ti_musb_peripheral_remove(struct udevice *dev) +{ + struct ti_musb_peripheral *priv = dev_get_priv(dev); + + usb_del_gadget_udc(&priv->periph->g); + ti_musb_set_phy_power(dev, 0); + + return 0; +} + +U_BOOT_DRIVER(ti_musb_peripheral) = { + .name = "ti-musb-peripheral", + .id = UCLASS_USB_GADGET_GENERIC, +#if CONFIG_IS_ENABLED(OF_CONTROL) + .ofdata_to_platdata = ti_musb_peripheral_ofdata_to_platdata, +#endif + .probe = ti_musb_peripheral_probe, + .remove = ti_musb_peripheral_remove, + .ops = &musb_usb_ops, + .platdata_auto_alloc_size = sizeof(struct ti_musb_platdata), + .priv_auto_alloc_size = sizeof(struct ti_musb_peripheral), + .flags = DM_FLAG_PRE_RELOC, +}; +#endif + +#if CONFIG_IS_ENABLED(OF_CONTROL) static int ti_musb_wrapper_bind(struct udevice *parent) { const void *fdt = gd->fdt_blob; @@ -222,15 +302,23 @@ static int ti_musb_wrapper_bind(struct udevice *parent) switch (dr_mode) { case USB_DR_MODE_PERIPHERAL: /* Bind MUSB device */ + ret = device_bind_driver_to_node(parent, + "ti-musb-peripheral", + name, + offset_to_ofnode(node), + &dev); + if (ret) + pr_err("musb - not able to bind usb peripheral node\n"); break; case USB_DR_MODE_HOST: /* Bind MUSB host */ - ret = device_bind_driver_to_node(parent, "ti-musb-host", - name, offset_to_ofnode(node), &dev); - if (ret) { + ret = device_bind_driver_to_node(parent, + "ti-musb-host", + name, + offset_to_ofnode(node), + &dev); + if (ret) pr_err("musb - not able to bind usb host node\n"); - return ret; - } break; default: break; @@ -250,5 +338,6 @@ U_BOOT_DRIVER(ti_musb_wrapper) = { .of_match = ti_musb_ids, .bind = ti_musb_wrapper_bind, }; +#endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ #endif /* CONFIG_IS_ENABLED(DM_USB) */ From 7a43dd7aa6a9f8650de240c1796ca2caa8eb8737 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:58 +0100 Subject: [PATCH 23/27] arm: am33xx: Register USB controllers if DM_USB is used but not OF_CONTROL When DM_USB is used, either the USB controllers are bound when the DTB is parsed (when OF_CONTROL is enabled) or they are bound using the U_BOOT_DEVICES() macro. In the later case, the platform data is passed in a struct ti_musb_platdata because it cannot be read from the DTB. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- arch/arm/mach-omap2/am33xx/board.c | 58 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-omap2/am33xx/board.c b/arch/arm/mach-omap2/am33xx/board.c index 2fc364d112..62158a9592 100644 --- a/arch/arm/mach-omap2/am33xx/board.c +++ b/arch/arm/mach-omap2/am33xx/board.c @@ -174,7 +174,55 @@ 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_DM_USB)) + (!CONFIG_IS_ENABLED(DM_USB) || !CONFIG_IS_ENABLED(OF_CONTROL)) && \ + (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_MUSB_NEW_SUPPORT)) + +static struct musb_hdrc_config musb_config = { + .multipoint = 1, + .dyn_fifo = 1, + .num_eps = 16, + .ram_bits = 12, +}; + +#if CONFIG_IS_ENABLED(DM_USB) && !CONFIG_IS_ENABLED(OF_CONTROL) +static struct ti_musb_platdata usb0 = { + .base = (void *)USB0_OTG_BASE, + .ctrl_mod_base = &((struct ctrl_dev *)CTRL_DEVICE_BASE)->usb_ctrl0, + .plat = { + .config = &musb_config, + .power = 50, + .platform_ops = &musb_dsps_ops, + }, +}; + +static struct ti_musb_platdata usb1 = { + .base = (void *)USB1_OTG_BASE, + .ctrl_mod_base = &((struct ctrl_dev *)CTRL_DEVICE_BASE)->usb_ctrl1, + .plat = { + .config = &musb_config, + .power = 50, + .platform_ops = &musb_dsps_ops, + }, +}; + +U_BOOT_DEVICES(am33xx_usbs) = { +#if CONFIG_AM335X_USB0_MODE == MUSB_PERIPHERAL + { "ti-musb-peripheral", &usb0 }, +#elif CONFIG_AM335X_USB0_MODE == MUSB_HOST + { "ti-musb-host", &usb0 }, +#endif +#if CONFIG_AM335X_USB1_MODE == MUSB_PERIPHERAL + { "ti-musb-peripheral", &usb1 }, +#elif CONFIG_AM335X_USB1_MODE == MUSB_HOST + { "ti-musb-host", &usb1 }, +#endif +}; + +int arch_misc_init(void) +{ + return 0; +} +#else static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; /* USB 2.0 PHY Control */ @@ -193,13 +241,6 @@ static void am33xx_usb_set_phy_power(u8 on, u32 *reg_addr) } } -static struct musb_hdrc_config musb_config = { - .multipoint = 1, - .dyn_fifo = 1, - .num_eps = 16, - .ram_bits = 12, -}; - #ifdef CONFIG_AM335X_USB0 static void am33xx_otg0_set_phy_power(struct udevice *dev, u8 on) { @@ -250,6 +291,7 @@ int arch_misc_init(void) #endif return 0; } +#endif #else /* CONFIG_USB_MUSB_* && CONFIG_AM335X_USB* && !CONFIG_DM_USB */ From 61602eaca2a50890e069fd009eeaafe9701e6b46 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:30:59 +0100 Subject: [PATCH 24/27] configs: am335x_evm: Do not disable DM_USB in SPL DM_USB is now supported in the SPL. Do not undef it Besides to support DM_USB in SPL, one now has to use SPL_DM_USB Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- include/configs/am335x_evm.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/configs/am335x_evm.h b/include/configs/am335x_evm.h index 5d5b09bbd1..3bd96b921b 100644 --- a/include/configs/am335x_evm.h +++ b/include/configs/am335x_evm.h @@ -253,7 +253,6 @@ #ifdef CONFIG_SPL_BUILD #undef CONFIG_DM_MMC #undef CONFIG_TIMER -#undef CONFIG_DM_USB #endif #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_USB_ETHER) From 5d060ec0dc02258608c8796a18d3f7bc45ff4494 Mon Sep 17 00:00:00 2001 From: Jean-Jacques Hiblot Date: Tue, 4 Dec 2018 11:31:00 +0100 Subject: [PATCH 25/27] configs: am335x_boneblack_vboot: enable DM_USB and RNDIS boot in SPl Enable DM_USB and DM_USB_GADGET for this platform. Also enable RNDIS boot support (SPL load u-boot over USB RNDIS). This is an example of how to use DM_USB on a am335x-based board. A subsequent series will take this a step further and modify more defconfigs. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Tom Rini --- configs/am335x_boneblack_vboot_defconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configs/am335x_boneblack_vboot_defconfig b/configs/am335x_boneblack_vboot_defconfig index d625599461..be04424375 100644 --- a/configs/am335x_boneblack_vboot_defconfig +++ b/configs/am335x_boneblack_vboot_defconfig @@ -13,7 +13,11 @@ CONFIG_VERSION_VARIABLE=y CONFIG_ARCH_MISC_INIT=y CONFIG_SPL_MUSB_NEW_SUPPORT=y # CONFIG_SPL_NAND_SUPPORT is not set +CONFIG_SPL_NET_SUPPORT=y +CONFIG_SPL_NET_VCI_STRING="AM33xx U-Boot SPL" CONFIG_SPL_OS_BOOT=y +CONFIG_SPL_USB_GADGET_SUPPORT=y +CONFIG_SPL_USB_ETHER=y CONFIG_AUTOBOOT_KEYED=y CONFIG_AUTOBOOT_PROMPT="Press SPACE to abort autoboot in %d seconds\n" CONFIG_AUTOBOOT_DELAY_STR="d" @@ -31,6 +35,7 @@ CONFIG_DFU_MMC=y CONFIG_DFU_RAM=y CONFIG_USB_FUNCTION_FASTBOOT=y CONFIG_DM_I2C=y +CONFIG_MISC=y CONFIG_DM_MMC=y CONFIG_MMC_OMAP_HS=y CONFIG_SPI_FLASH=y @@ -44,8 +49,13 @@ CONFIG_OMAP3_SPI=y CONFIG_TIMER=y CONFIG_OMAP_TIMER=y CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_SPL_DM_USB=y +CONFIG_DM_USB_GADGET=y +CONFIG_SPL_DM_USB_GADGET=y CONFIG_USB_MUSB_HOST=y CONFIG_USB_MUSB_GADGET=y +CONFIG_USB_MUSB_TI=y CONFIG_USB_MUSB_DSPS=y CONFIG_USB_STORAGE=y CONFIG_USB_GADGET=y From 771e76515ed5abe7eff73a54ccb0c9ae55f34388 Mon Sep 17 00:00:00 2001 From: Siva Durga Prasad Paladugu Date: Thu, 13 Dec 2018 15:16:36 +0530 Subject: [PATCH 26/27] usb: composite: Fix max packet size for USB3.0 For USB3.0, the max packetsize for GET_DESCRIPTOR should be sent as exponent value for 2. This means for 512, max packet size should be filled with 9(2^9=512). Also, fill the USB version field with 3.0 if speed is negotiated to Superspeed. This fixes the issue of DFU gadget download failure with superspeed. Without this patch, the max packet size is overflowed to zero as the bMaxPacketsize is of u8 and hence host is not able to detect this device. Signed-off-by: Siva Durga Prasad Paladugu Reviewed-by: Bin Meng --- drivers/usb/gadget/composite.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index 5106cc56cb..c7e7623747 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -735,8 +735,21 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) case USB_DT_DEVICE: cdev->desc.bNumConfigurations = count_configs(cdev, USB_DT_DEVICE); - cdev->desc.bMaxPacketSize0 = - cdev->gadget->ep0->maxpacket; + + /* + * If the speed is Super speed, then the supported + * max packet size is 512 and it should be sent as + * exponent of 2. So, 9(2^9=512) should be filled in + * bMaxPacketSize0. Also fill USB version as 3.0 + * if speed is Super speed. + */ + if (cdev->gadget->speed == USB_SPEED_SUPER) { + cdev->desc.bMaxPacketSize0 = 9; + cdev->desc.bcdUSB = cpu_to_le16(0x0300); + } else { + cdev->desc.bMaxPacketSize0 = + cdev->gadget->ep0->maxpacket; + } value = min(w_length, (u16) sizeof cdev->desc); memcpy(req->buf, &cdev->desc, value); break; From 46a3f276549f3e5720b6e80278cda354c7fa859f Mon Sep 17 00:00:00 2001 From: Stefan Mavrodiev Date: Wed, 5 Dec 2018 14:49:44 +0200 Subject: [PATCH 27/27] usb: musb-new: sunxi: Fix null pointer access When the device is in peripheral mode there is no struct usb_bus_priv allocated pointer, as the uclass driver ("usb_dev_generic") doesn't call per_device_auto_alloc_size. This results in writing to the internal SDRAM at priv->desc_before_addr = true; Signed-off-by: Stefan Mavrodiev --- drivers/usb/musb-new/sunxi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/musb-new/sunxi.c b/drivers/usb/musb-new/sunxi.c index d7170a3078..f542a181fa 100644 --- a/drivers/usb/musb-new/sunxi.c +++ b/drivers/usb/musb-new/sunxi.c @@ -435,11 +435,14 @@ static int musb_usb_probe(struct udevice *dev) { struct sunxi_glue *glue = dev_get_priv(dev); struct musb_host_data *host = &glue->mdata; - struct usb_bus_priv *priv = dev_get_uclass_priv(dev); struct musb_hdrc_platform_data pdata; void *base = dev_read_addr_ptr(dev); int ret; +#ifdef CONFIG_USB_MUSB_HOST + struct usb_bus_priv *priv = dev_get_uclass_priv(dev); +#endif + if (!base) return -EINVAL; @@ -459,7 +462,6 @@ static int musb_usb_probe(struct udevice *dev) return ret; } - priv->desc_before_addr = true; memset(&pdata, 0, sizeof(pdata)); pdata.power = 250; @@ -467,6 +469,8 @@ static int musb_usb_probe(struct udevice *dev) pdata.config = glue->cfg->config; #ifdef CONFIG_USB_MUSB_HOST + priv->desc_before_addr = true; + pdata.mode = MUSB_HOST; host->host = musb_init_controller(&pdata, &glue->dev, base); if (!host->host)