usb: dwc3: add Layerscape SoC support
Subsystems (3)
v2 cover usb: dwc3: add Layerscape SoC support
Primarily, this will add support for peripheral mode on Layerscape SoCs. For this to work, we have to backport two fixes from linux and fix the fixup code for the DWC3 controller (which enables snooping because the SoC has wrong startup defaults).
As a first user of the driver, enable it on the Kontron SL28 board, where both host and peripheral mode was tested.
OTG mode is not supported. For this to work, one would need to read the hardware status of the OTG pin in the bind() op. But it isn't allowed to access the hardware in the bind() op (if I understand Simon correctly).
changes since v1:
- added test case for the new ofnode_for_each_compatible_node()
Michael Walle (9):
dm: core: add ofnode_for_each_compatible_node()
test: dm: add test for ofnode_for_each_compatible_node()
armv8: fsl-layerscape: rework the dwc3 snooping enable code
usb: common: silence dubious errors
usb: dwc3: Add frame length adjustment quirk
usb: dwc3: Enable undefined length INCR burst type
usb: dwc3: add layerscape support
board: sl28: switch to dwc3 driver
board: sl28: enable USB periheral support and gadgets
arch/arm/cpu/armv8/fsl-layerscape/soc.c | 28 ++- configs/kontron_sl28_defconfig | 9 +- drivers/usb/common/common.c | 4 +- drivers/usb/dwc3/Kconfig | 10 ++ drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/core.c | 95 ++++++++++ drivers/usb/dwc3/core.h | 22 +++ drivers/usb/dwc3/dwc3-layerscape.c | 222 ++++++++++++++++++++++++ include/dm/ofnode.h | 24 +++ test/dm/ofnode.c | 18 ++ 10 files changed, 415 insertions(+), 18 deletions(-) create mode 100644 drivers/usb/dwc3/dwc3-layerscape.c
Signature · 1 line
2.30.2
PATCH v2 1/9 dm: core: add ofnode_for_each_compatible_node()
Add a helper to iterate over all nodes with a given compatible string.
--- include/dm/ofnode.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
include/dm/ofnode.h +24 -0
@@ -1009,6 +1009,30 @@ ofnode ofnode_by_prop_value(ofnode from, const char *propname,ofnode_valid (node); \ node = ofnode_next_subnode(node)) +/** +* ofnode_for_each_compatible_node() - iterate over all nodes with a given +* compatible string +* +* @node: child node (ofnode, lvalue) +* @compat: compatible string to match +* +* This is a wrapper around a for loop and is used like so: +* +* ofnode node; +* +* ofnode_for_each_compatible_node(node, parent, compatible) { +* Use node +* ... +* } +* +* Note that this is implemented as a macro and @node is used as +* iterator in the loop. +*/ +#define ofnode_for_each_compatible_node (node, compat) \ + for (node = ofnode_by_compatible(ofnode_null(), compat); \ + ofnode_valid(node); \ + node = ofnode_by_compatible(node, compat)) +/** * ofnode_get_child_count() - get the child count of a ofnode *
Signature · 1 line
2.30.2
PATCH v2 2/9 test: dm: add test for ofnode_for_each_compatible_node()
In reply to Michael WalleCheck that all matching nodes have the correct compatible and that there is at least one match.
--- test/dm/ofnode.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
test/dm/ofnode.c +18 -0
@@ -333,3 +333,21 @@ static int dm_test_ofnode_conf(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_ofnode_conf,0 ); + +static int dm_test_ofnode_for_each_compatible_node (struct unit_test_state *uts) +{ +const char compatible[] ="denx,u-boot-fdt-test" ; +bool found = false; +ofnode node; + +ofnode_for_each_compatible_node (node, compatible) { +ut_assert (ofnode_device_is_compatible (node, compatible)); + found = true; + } + +/* There should be at least one matching node */ +ut_assert (found); + +return 0 ; +} +DM_TEST (dm_test_ofnode_for_each_compatible_node,UT_TESTF_SCAN_FDT );
Signature · 1 line
2.30.2
Re: [PATCH v2 2/9] test: dm: add test for ofnode_for_each_compatible_node()
Quoted 9 lines · Michael Walle
Check that all matching nodes have the correct compatible and that there is at least one match.
Signed-off-by Michael Walle <[email protected]>--- test/dm/ofnode.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
PATCH v2 3/9 armv8: fsl-layerscape: rework the dwc3 snooping enable code
In reply to Michael WalleInstead of looking at all USB (host) devices, just search all DWC3 device tree nodes. This will (1) fix a panic if of_match is zero and (2) also apply the fixup if the controller is in peripheral mode. Both happen when the DWC3 USB controller driver is used.
--- arch/arm/cpu/armv8/fsl-layerscape/soc.c | 28 ++++++++++++------------- 1 file changed, 13 insertions(+), 15 deletions(-)
arch/arm/cpu/armv8/fsl-layerscape/soc.c +13 -15
@@ -919,25 +919,23 @@ __weak int fsl_board_late_init(void)#define DWC3_GSBUSCFG0_CACHETYPE (n) (((n) & 0xffff) \ << DWC3_GSBUSCFG0_CACHETYPE_SHIFT) -void enable_dwc3_snooping (void ) +static void enable_dwc3_snooping (void ) { -int ret; -u32 val; -struct udevice *bus; -struct uclass *uc; +static const char *const compatibles[] = { +"fsl,layerscape-dwc3" , +"fsl,ls1028a-dwc3" , + };fdt_addr_t dwc3_base; +ofnode node; +u32 val; +int i; - ret =uclass_get (UCLASS_USB , &uc); -if (ret) -return ; - - uclass_foreach_dev(bus, uc) { -if (!strcmp (bus->driver->of_match->compatible,"fsl,layerscape-dwc3" )) { - dwc3_base =devfdt_get_addr (bus); -if (dwc3_base ==FDT_ADDR_T_NONE ) { -dev_err (bus,"dwc3 regs missing\n" ); +for (i =0 ; i <ARRAY_SIZE (compatibles); i++) { +ofnode_for_each_compatible_node (node, compatibles[i]) { + dwc3_base =ofnode_get_addr (node); +if (dwc3_base ==FDT_ADDR_T_NONE )continue ; - } + val =in_le32 (dwc3_base +DWC3_GSBUSCFG0 ); val &= ~DWC3_GSBUSCFG0_CACHETYPE (~0 ); val |=DWC3_GSBUSCFG0_CACHETYPE (0x2222 );
Signature · 1 line
2.30.2
PATCH v2 4/9 usb: common: silence dubious errors
In reply to Michael WalleBoth dr_mode and maximum-speed properties are usually optional. Drivers will still try to fetch the properties nonetheless, which leads to error messages, although they are no errors. Change pr_err() to pr_debug().
--- drivers/usb/common/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/common/common.c +2 -2
@@ -29,7 +29,7 @@ enum usb_dr_mode usb_get_dr_mode(ofnode node) dr_mode =ofnode_read_string (node,"dr_mode" );if (!dr_mode) { -pr_err ("usb dr_mode not found\n" ); +pr_debug ("usb dr_mode not found\n" );return USB_DR_MODE_UNKNOWN ; }
@@ -64,7 +64,7 @@ enum usb_device_speed usb_get_maximum_speed(ofnode node) max_speed =ofnode_read_string (node,"maximum-speed" );if (!max_speed) { -pr_err ("usb maximum-speed not found\n" ); +pr_debug ("usb maximum-speed not found\n" );return USB_SPEED_UNKNOWN ; }
Signature · 1 line
2.30.2
Re: [PATCH v2 4/9] usb: common: silence dubious errors
Quoted 9 lines · Michael Walle
Both
dr_modeand maximum-speed properties are usually optional. Drivers will still try to fetch the properties nonetheless, which leads to error messages, although they are no errors. Changepr_err()topr_debug().Signed-off-by Michael Walle <[email protected]>--- drivers/usb/common/common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
PATCH v2 5/9 usb: dwc3: Add frame length adjustment quirk
In reply to Michael Walle[backport from linux commit db2be4e9e30c6e43e48c5749d3fc74cee0a6bbb3]
Add adjust_frame_length_quirk for writing to fladj register which adjusts (micro)frame length to value provided by "snps,quirk-frame-length-adjustment" property thus avoiding USB 2.0 devices to time-out over a longer run
--- drivers/usb/dwc3/core.c | 26 ++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 6 ++++++ 2 files changed, 32 insertions(+)
drivers/usb/dwc3/core.c +26 -0
@@ -93,6 +93,27 @@ static int dwc3_core_soft_reset(struct dwc3 *dwc)return 0 ; } +/* +* dwc3_frame_length_adjustment - Adjusts frame length if required +* @dwc3: Pointer to our controller context structure +* @fladj: Value of GFLADJ_30MHZ to adjust frame length +*/ +static void dwc3_frame_length_adjustment (struct dwc3 *dwc,u32 fladj) +{ +u32 reg; + +if (dwc->revision <DWC3_REVISION_250A ) +return ; + +if (fladj ==0 ) +return ; + + reg =dwc3_readl (dwc->regs,DWC3_GFLADJ ); + reg &= ~DWC3_GFLADJ_30MHZ_MASK ; + reg |=DWC3_GFLADJ_30MHZ_SDBND_SEL | fladj; +dwc3_writel (dwc->regs,DWC3_GFLADJ , reg); +} +/** * dwc3_free_one_event_buffer - Frees one event buffer * @dwc: Pointer to our controller context structure
@@ -569,6 +590,9 @@ static int dwc3_core_init(struct dwc3 *dwc)if (ret) goto err1; +/* Adjust Frame Length */ +dwc3_frame_length_adjustment (dwc, dwc->fladj); +return 0 ; err1:
@@ -958,6 +982,8 @@ void dwc3_of_parse(struct dwc3 *dwc) dwc->hird_threshold = hird_threshold | (dwc->is_utmi_l1_suspend <<4 ); + +dev_read_u32 (dev,"snps,quirk-frame-length-adjustment" , &dwc->fladj); }int dwc3_init (struct dwc3 *dwc)
drivers/usb/dwc3/core.h +6 -0
@@ -115,6 +115,7 @@#define DWC3_GEVNTCOUNT (n) (0xc40c + (n * 0x10))#define DWC3_GHWPARAMS8 0xc600 +#define DWC3_GFLADJ 0xc630/* Device Registers */ #define DWC3_DCFG 0xc700
@@ -233,6 +234,10 @@/* Global HWPARAMS6 Register */ #define DWC3_GHWPARAMS6_EN_FPGA (1 << 7) +/* Global Frame Length Adjustment Register */ +#define DWC3_GFLADJ_30MHZ_SDBND_SEL (1 << 7) +#define DWC3_GFLADJ_30MHZ_MASK 0x3f +/* Device Configuration Register */ #define DWC3_DCFG_DEVADDR (addr) ((addr) << 3)#define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
@@ -812,6 +817,7 @@ struct dwc3 {u8 test_mode_nr;u8 lpm_nyet_threshold;u8 hird_threshold; +u32 fladj; unsigned delayed_status:1; unsigned ep0_bounced:1;
Signature · 1 line
2.30.2
PATCH v2 6/9 usb: dwc3: Enable undefined length INCR burst type
In reply to Michael Walle[backport from linux commit d9612c2f0449e24983a8b689603210486a930c90]
Enable the undefined length INCR burst type and set INCRx. Different platform may has the different burst size type. In order to get best performance, we need to tune the burst size to one special value, instead of the default value.
--- drivers/usb/dwc3/core.c | 69 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/core.h | 16 ++++++++++ 2 files changed, 85 insertions(+)
drivers/usb/dwc3/core.c +69 -0
@@ -462,6 +462,53 @@ static void dwc3_phy_setup(struct dwc3 *dwc)mdelay (100 ); } +/* set global incr burst type configuration registers */ +static void dwc3_set_incr_burst_type (struct dwc3 *dwc) +{ +struct udevice *dev = dwc->dev; +u32 cfg; + +if (!dwc->incrx_size) +return ; + + cfg =dwc3_readl (dwc->regs,DWC3_GSBUSCFG0 ); + +/* Enable Undefined Length INCR Burst and Enable INCRx Burst */ + cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK ; +if (dwc->incrx_mode) + cfg |=DWC3_GSBUSCFG0_INCRBRSTENA ; +switch (dwc->incrx_size) { +case 256 : + cfg |=DWC3_GSBUSCFG0_INCR256BRSTENA ; +break ; +case 128 : + cfg |=DWC3_GSBUSCFG0_INCR128BRSTENA ; +break ; +case 64 : + cfg |=DWC3_GSBUSCFG0_INCR64BRSTENA ; +break ; +case 32 : + cfg |=DWC3_GSBUSCFG0_INCR32BRSTENA ; +break ; +case 16 : + cfg |=DWC3_GSBUSCFG0_INCR16BRSTENA ; +break ; +case 8 : + cfg |=DWC3_GSBUSCFG0_INCR8BRSTENA ; +break ; +case 4 : + cfg |=DWC3_GSBUSCFG0_INCR4BRSTENA ; +break ; +case 1 : +break ; +default : +dev_err (dev,"Invalid property\n" ); +break ; + } + +dwc3_writel (dwc->regs,DWC3_GSBUSCFG0 , cfg); +} +/** * dwc3_core_init - Low-level initialization of DWC3 Core * @dwc: Pointer to our controller context structure
@@ -593,6 +640,8 @@ static int dwc3_core_init(struct dwc3 *dwc)/* Adjust Frame Length */ dwc3_frame_length_adjustment (dwc, dwc->fladj); +dwc3_set_incr_burst_type (dwc); +return 0 ; err1:
@@ -916,6 +965,8 @@ void dwc3_of_parse(struct dwc3 *dwc)u8 lpm_nyet_threshold;u8 tx_de_emphasis;u8 hird_threshold; +u32 val; +int i;/* default to highest possible threshold */ lpm_nyet_threshold =0xff ;
@@ -984,6 +1035,24 @@ void dwc3_of_parse(struct dwc3 *dwc) | (dwc->is_utmi_l1_suspend << 4);dev_read_u32 (dev,"snps,quirk-frame-length-adjustment" , &dwc->fladj); + +/* +* Handle property "snps,incr-burst-type-adjustment". +* Get the number of value from this property: +* result <= 0, means this property is not supported. +* result = 1, means INCRx burst mode supported. +* result > 1, means undefined length burst mode supported. +*/ + dwc->incrx_mode =INCRX_BURST_MODE ; + dwc->incrx_size =0 ; +for (i =0 ; i <8 ; i++) { +if (dev_read_u32_index (dev,"snps,incr-burst-type-adjustment" , + i, &val)) +break ; + + dwc->incrx_mode =INCRX_UNDEF_LENGTH_BURST_MODE ; + dwc->incrx_size =max (dwc->incrx_size, val); + } }int dwc3_init (struct dwc3 *dwc)
drivers/usb/dwc3/core.h +16 -0
@@ -139,6 +139,17 @@/* Bit fields */ +/* Global SoC Bus Configuration INCRx Register 0 */ +#define DWC3_GSBUSCFG0_INCR256BRSTENA (1 << 7)/* INCR256 burst */ +#define DWC3_GSBUSCFG0_INCR128BRSTENA (1 << 6)/* INCR128 burst */ +#define DWC3_GSBUSCFG0_INCR64BRSTENA (1 << 5)/* INCR64 burst */ +#define DWC3_GSBUSCFG0_INCR32BRSTENA (1 << 4)/* INCR32 burst */ +#define DWC3_GSBUSCFG0_INCR16BRSTENA (1 << 3)/* INCR16 burst */ +#define DWC3_GSBUSCFG0_INCR8BRSTENA (1 << 2)/* INCR8 burst */ +#define DWC3_GSBUSCFG0_INCR4BRSTENA (1 << 1)/* INCR4 burst */ +#define DWC3_GSBUSCFG0_INCRBRSTENA (1 << 0)/* undefined length enable */ +#define DWC3_GSBUSCFG0_INCRBRST_MASK 0xff +/* Global Configuration Register */ #define DWC3_GCTL_PWRDNSCALE (n) ((n) << 19)#define DWC3_GCTL_U2RSTECN (1 << 16)
@@ -818,6 +829,8 @@ struct dwc3 {u8 lpm_nyet_threshold;u8 hird_threshold;u32 fladj; +u8 incrx_mode; +u32 incrx_size; unsigned delayed_status:1; unsigned ep0_bounced:1;
@@ -855,6 +868,9 @@ struct dwc3 {struct list_head list; }; +#define INCRX_BURST_MODE 0 +#define INCRX_UNDEF_LENGTH_BURST_MODE 1 +/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
Signature · 1 line
2.30.2
PATCH v2 7/9 usb: dwc3: add layerscape support
In reply to Michael WalleAdd support for the proper dwc3 device tree binding support as specified in the offical device tree spec.
Initially, add support for the LS1028A support. Other SoCs should be easy to add by just adding the corresponding compatible string. Unfortunately, the device trees of all other layerscape SoCs are not converted and uses a wrong compatible string only known in u-boot.
To maintain backwards compatibility with current u-boot device trees, add the generic "fsl,layerscape-dwc3" compatible string.
OTG mode is not supported yet. The dr_mode in the devicetree will either have to be set to peripheral or host.
--- drivers/usb/dwc3/Kconfig | 10 ++ drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-layerscape.c | 222 +++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-layerscape.c
drivers/usb/dwc3/Kconfig +10 -0
@@ -53,6 +53,16 @@ config USB_DWC3_UNIPHIER Support of USB2/3 functionality in Socionext UniPhier platforms. Say 'Y' here if you have one such device. +config USB_DWC3_LAYERSCAPE + bool "Freescale Layerscape platform support" + depends on DM_USB && USB_DWC3 + depends on !USB_XHCI_FSL + help + Select this for Freescale Layerscape Platforms. + + Host and Peripheral operation modes are supported. OTG is not + supported. + menu "PHY Subsystem" config USB_DWC3_PHY_OMAP
drivers/usb/dwc3/Makefile +1 -0
@@ -11,5 +11,6 @@ obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o obj-$(CONFIG_USB_DWC3_MESON_GXL) += dwc3-meson-gxl.o obj-$(CONFIG_USB_DWC3_GENERIC) += dwc3-generic.o obj-$(CONFIG_USB_DWC3_UNIPHIER) += dwc3-uniphier.o +obj-$(CONFIG_USB_DWC3_LAYERSCAPE) += dwc3-layerscape.o obj-$(CONFIG_USB_DWC3_PHY_OMAP) += ti_usb_phy.o obj-$(CONFIG_USB_DWC3_PHY_SAMSUNG) += samsung_usb_phy.o
drivers/usb/dwc3/dwc3-layerscape.c new file +222 -0
222 lines not on this page · raw message
Signature · 1 line
2.30.2
PATCH v2 8/9 board: sl28: switch to dwc3 driver
In reply to Michael WalleNow that the DWC3 USB driver has support for the layerscape platform, use it. This will have the benefit that peripheral mode will work.
--- configs/kontron_sl28_defconfig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
configs/kontron_sl28_defconfig +3 -1
@@ -91,6 +91,8 @@ CONFIG_NXP_FSPI=y CONFIG_USB=y # CONFIG_SPL_DM_USB is not set CONFIG_USB_XHCI_HCD=y -CONFIG_USB_XHCI_DWC3=y +# CONFIG_USB_XHCI_FSL is not set +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_LAYERSCAPE=y CONFIG_OF_LIBFDT_ASSUME_MASK=0x0 CONFIG_OF_LIBFDT_OVERLAY=y
Signature · 1 line
2.30.2
PATCH v2 9/9 board: sl28: enable USB periheral support and gadgets
In reply to Michael WalleEnable support to update the board via the DFU protocol and make it possible to export the block devices via USB mass storage protocol.
This will not work out of the box, yet. You have to change the dr_mode of the usb0 controller to peripheral manually to make it work. True, OTG support will hopefully coming soon.
--- configs/kontron_sl28_defconfig | 5 +++++ 1 file changed, 5 insertions(+)
configs/kontron_sl28_defconfig +5 -0
@@ -39,12 +39,14 @@ CONFIG_SYS_SPI_U_BOOT_OFFS=0x230000 CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_NVEDIT_EFI=y +CONFIG_CMD_DFU=y CONFIG_CMD_DM=y CONFIG_CMD_GPT=y CONFIG_CMD_I2C=y CONFIG_CMD_MMC=y CONFIG_CMD_PCI=y CONFIG_CMD_USB=y +CONFIG_CMD_USB_MASS_STORAGE=y CONFIG_CMD_CACHE=y CONFIG_CMD_EFIDEBUG=y CONFIG_CMD_RNG=y
@@ -90,9 +92,12 @@ CONFIG_FSL_DSPI=y CONFIG_NXP_FSPI=y CONFIG_USB=y # CONFIG_SPL_DM_USB is not set +CONFIG_DM_USB_GADGET=y CONFIG_USB_XHCI_HCD=y # CONFIG_USB_XHCI_FSL is not set CONFIG_USB_DWC3=y CONFIG_USB_DWC3_LAYERSCAPE=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DOWNLOAD=y CONFIG_OF_LIBFDT_ASSUME_MASK=0x0 CONFIG_OF_LIBFDT_OVERLAY=y
Signature · 1 line
2.30.2
Hi Bin,
Marek suggested to add you. Unfortunately, get_maintainer.pl doesn't mention you.
You can find the whole thread here:
https://lore.kernel.org/u-boot/[email protected]/
Am 2021-10-15 15:15, schrieb Michael Walle:
Quoted 26 lines
Primarily, this will add support for peripheral mode on Layerscape SoCs. For this to work, we have to backport two fixes from linux and fix the fixup code for the DWC3 controller (which enables snooping because the SoC has wrong startup defaults).
As a first user of the driver, enable it on the Kontron SL28 board, where both host and peripheral mode was tested.
OTG mode is not supported. For this to work, one would need to read the hardware status of the OTG pin in the
bind()op. But it isn't allowed to access the hardware in thebind()op (if I understand Simon correctly).changes since v1:
- added test case for the newofnode_for_each_compatible_node()Michael Walle (9):
dm: core: addofnode_for_each_compatible_node()
test: dm: add test forofnode_for_each_compatible_node()
armv8: fsl-layerscape: rework the dwc3 snooping enable code
usb: common: silence dubious errors
usb: dwc3: Add frame length adjustment quirk
usb: dwc3: Enable undefined length INCR burst type
usb: dwc3: add layerscape support
board: sl28: switch to dwc3 driver
board: sl28: enable USB periheral support and gadgets
Quoted 12 lines
arch/arm/cpu/armv8/fsl-layerscape/soc.c | 28 ++- configs/kontron_sl28_defconfig | 9 +- drivers/usb/common/common.c | 4 +- drivers/usb/dwc3/Kconfig | 10 ++ drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/core.c | 95 ++++++++++ drivers/usb/dwc3/core.h | 22 +++ drivers/usb/dwc3/dwc3-layerscape.c | 222 ++++++++++++++++++++++++ include/dm/ofnode.h | 24 +++ test/dm/ofnode.c | 18 ++ 10 files changed, 415 insertions(+), 18 deletions(-) create mode 100644 drivers/usb/dwc3/dwc3-layerscape.c
-michael