ARM: meson: Add G12A USB Support
Subsystems (6)
cover ARM: meson: Add G12A USB Support
This patchset adds support for USB on Amlogic G12A SoCs.
This patchset is composed with :
- PHY Drivers
- USB Control Glue driver
- G12A board setup for Device mode
Device Tree nodes will be added in a separate patchset when applied on a tagged Linux tree.
The Amlogic G12A USB Complex is composed of :
- 2 USB Controllers :
* DWC3 for USB2 and USB3 Host functionality
* DWC2 for USB2 Peripheral functionality
- 2 USB2 OTG PHYs, only a single one will be routed to either DWC2 to DWC3
- 1 USB3 PHY shared with PCIE funcionnality
- A Glue to control PHY routing, setup and OTG detection
The Glue configures the UTMI 8bit interfaces for the USB2 PHYs, including routing of the OTG PHY between the DWC3 and DWC2 controllers, and setups the on-chip OTG mode selection for this PHY.
This drivers supports the on-probe setup of the OTG mode, and manually via a setup function in the G12A common board code.
Neil Armstrong (3):
usb: dwc3: Add Meson G12A USB Glue
phy: meson: add Amlogic G12A USB2 and USB3+PCIE PHY drivers
mach-meson: g12a: add DWC2 peripheral mode support
arch/arm/include/asm/arch-meson/usb.h | 12 + arch/arm/mach-meson/board-g12a.c | 126 +++++++ drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/meson-g12a-usb2.c | 216 ++++++++++++ drivers/phy/meson-g12a-usb3-pcie.c | 345 +++++++++++++++++++ drivers/usb/dwc3/Kconfig | 8 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 456 ++++++++++++++++++++++++++ 9 files changed, 1173 insertions(+) create mode 100644 arch/arm/include/asm/arch-meson/usb.h create mode 100644 drivers/phy/meson-g12a-usb2.c create mode 100644 drivers/phy/meson-g12a-usb3-pcie.c create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.c
Signature · 1 line
2.21.0
PATCH 1/3 usb: dwc3: Add Meson G12A USB Glue
Adds support for Amlogic G12A USB Control Glue HW.
The Amlogic G12A SoC Family embeds 2 USB Controllers :
- a DWC3 IP configured as Host for USB2 and USB3
- a DWC2 IP configured as Peripheral USB2 Only
A glue connects these both controllers to 2 USB2 PHYs, and optionnally to an USB3+PCIE Combo PHY shared with the PCIE controller.
The Glue configures the UTMI 8bit interfaces for the USB2 PHYs, including routing of the OTG PHY between the DWC3 and DWC2 controllers, and setups the on-chip OTG mode selection for this PHY.
This driver sets the OTG capable port as Host mode by default, the switch to Device mode is to be done in a separate patch.
--- drivers/usb/dwc3/Kconfig | 8 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 456 +++++++++++++++++++++++++++++ 3 files changed, 465 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.c
drivers/usb/dwc3/Kconfig +8 -0
@@ -44,6 +44,14 @@ config USB_DWC3_GENERIC Select this for Xilinx ZynqMP and similar Platforms. This wrapper supports Host and Peripheral operation modes. +config USB_DWC3_MESON_G12A + bool "Amlogic Meson G12A USB wrapper" + depends on DM_USB && USB_DWC3 && ARCH_MESON + imply PHY + help + Select this for Amlogic Meson G12A Platforms. + This wrapper supports Host and Peripheral operation modes. + config USB_DWC3_UNIPHIER bool "DesignWare USB3 Host Support on UniPhier Platforms" depends on ARCH_UNIPHIER && USB_XHCI_DWC3
drivers/usb/dwc3/Makefile +1 -0
@@ -7,6 +7,7 @@ dwc3-y := core.o obj-$(CONFIG_USB_DWC3_GADGET) += gadget.o ep0.o obj-$(CONFIG_USB_DWC3_OMAP) += dwc3-omap.o +obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o obj-$(CONFIG_USB_DWC3_GENERIC) += dwc3-generic.o obj-$(CONFIG_USB_DWC3_UNIPHIER) += dwc3-uniphier.o obj-$(CONFIG_USB_DWC3_PHY_OMAP) += ti_usb_phy.o
drivers/usb/dwc3/dwc3-meson-g12a.c new file +456 -0
456 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH 1/3 usb: dwc3: Add Meson G12A USB Glue
Quoted 18 lines · Neil Armstrong
Adds support for Amlogic G12A USB Control Glue HW.
The Amlogic G12A SoC Family embeds 2 USB Controllers :
- a DWC3 IP configured as Host for USB2 and USB3
- a DWC2 IP configured as Peripheral USB2 OnlyA glue connects these both controllers to 2 USB2 PHYs, and optionnally to an USB3+PCIE Combo PHY shared with the PCIE controller.
The Glue configures the UTMI 8bit interfaces for the USB2 PHYs, including routing of the OTG PHY between the DWC3 and DWC2 controllers, and setups the on-chip OTG mode selection for this PHY.
This driver sets the OTG capable port as Host mode by default, the switch to Device mode is to be done in a separate patch.
Signed-off-by Neil Armstrong <[email protected]>---
[...]
Quoted 11 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +11
-0+static int dwc3_meson_g12a_get_phys (struct dwc3_meson_g12a *priv) +{ +int i, ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =generic_phy_get_by_name (priv->dev, phy_names[i], + &priv->phys[i]); +if (ret == -ENOENT ) +continue ; + +if (ret)
drivers/usb/dwc3/dwc3-meson-g12a.c line 315
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+return ret; + +if (i ==USB3_HOST_PHY ) + priv->usb3_ports++; +else + priv->usb2_ports++; + } + +printf ("%s: usb2 ports: %d\n" , __func__, priv->usb2_ports); +printf ("%s: usb3 ports: %d\n" , __func__, priv->usb3_ports);
Are these prints needed ?
Quoted 2 lines
(quoted diff) +2
-0+ return 0; +}
[...]
Quoted 42 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +42
-0+static int dwc3_meson_g12a_probe (struct udevice *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_platdata (dev); +int ret, i; + + priv->dev = dev; + + ret =regmap_init_mem (dev_ofnode (dev), &priv->regmap); +if (ret) +return ret; + + ret =dwc3_meson_g12a_clk_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_reset_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_get_phys (priv); +if (ret) +return ret; + +#if CONFIG_IS_ENABLED (DM_REGULATOR ) + ret =device_get_supply_regulator (dev,"vbus-supply" , + &priv->vbus_supply); +if (ret && ret != -ENOENT ) { +pr_err ("Failed to get PHY regulator\n" ); +return ret; + } + +if (priv->vbus_supply) { + ret =regulator_set_enable (priv->vbus_supply, true); +if (ret) +return ret; + } +#endif + + priv->otg_mode =usb_get_dr_mode (dev_of_offset (dev)); + + ret =dwc3_meson_g12a_usb_init (priv); +if (ret)
drivers/usb/dwc3/dwc3-meson-g12a.c line 409
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+return ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { +if (!priv->phys[i].dev) +continue ; + + ret =generic_phy_init (&priv->phys[i]); +if (ret) + goto err_phy_init; + }
Isn't there some function to init all the PHYs already ?
Signature · 2 lines
Best regards, Marek Vasut
PATCH 1/3 usb: dwc3: Add Meson G12A USB Glue
Quoted 37 lines · Marek Vasut
Quoted 18 lines · Neil Armstrong
Adds support for Amlogic G12A USB Control Glue HW.
The Amlogic G12A SoC Family embeds 2 USB Controllers :
- a DWC3 IP configured as Host for USB2 and USB3
- a DWC2 IP configured as Peripheral USB2 OnlyA glue connects these both controllers to 2 USB2 PHYs, and optionnally to an USB3+PCIE Combo PHY shared with the PCIE controller.
The Glue configures the UTMI 8bit interfaces for the USB2 PHYs, including routing of the OTG PHY between the DWC3 and DWC2 controllers, and setups the on-chip OTG mode selection for this PHY.
This driver sets the OTG capable port as Host mode by default, the switch to Device mode is to be done in a separate patch.
Signed-off-by Neil Armstrong <[email protected]>---
[...]
Quoted 15 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +15
-0+static int dwc3_meson_g12a_get_phys (struct dwc3_meson_g12a *priv) +{ +int i, ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =generic_phy_get_by_name (priv->dev, phy_names[i], + &priv->phys[i]); +if (ret == -ENOENT ) +continue ; + +if (ret) +return ret; + +if (i ==USB3_HOST_PHY ) + priv->usb3_ports++;
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 315
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+else + priv->usb2_ports++; + } + +printf ("%s: usb2 ports: %d\n" , __func__, priv->usb2_ports); +printf ("%s: usb3 ports: %d\n" , __func__, priv->usb3_ports);Are these prints needed ?
Nop, forgot to switch them to debug
Quoted 51 lines
Quoted 3 lines
(quoted diff) +2
-0+ return 0; +}[...]
Quoted 46 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +46
-0+static int dwc3_meson_g12a_probe (struct udevice *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_platdata (dev); +int ret, i; + + priv->dev = dev; + + ret =regmap_init_mem (dev_ofnode (dev), &priv->regmap); +if (ret) +return ret; + + ret =dwc3_meson_g12a_clk_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_reset_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_get_phys (priv); +if (ret) +return ret; + +#if CONFIG_IS_ENABLED (DM_REGULATOR ) + ret =device_get_supply_regulator (dev,"vbus-supply" , + &priv->vbus_supply); +if (ret && ret != -ENOENT ) { +pr_err ("Failed to get PHY regulator\n" ); +return ret; + } + +if (priv->vbus_supply) { + ret =regulator_set_enable (priv->vbus_supply, true); +if (ret) +return ret; + } +#endif + + priv->otg_mode =usb_get_dr_mode (dev_of_offset (dev)); + + ret =dwc3_meson_g12a_usb_init (priv); +if (ret) +return ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { +if (!priv->phys[i].dev)
Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 409
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+continue ; + + ret =generic_phy_init (&priv->phys[i]); +if (ret) + goto err_phy_init; + }Isn't there some function to init all the PHYs already ?
I don't see any in u-boot master !
Unlike dwc3, we need to get the phys with the names to check if the USB3 phy is enabled, so we can't get all possible phys.
Neil
PATCH 1/3 usb: dwc3: Add Meson G12A USB Glue
Quoted 110 lines · Neil Armstrong
Quoted 37 lines · Marek Vasut
Quoted 18 lines · Neil Armstrong
Adds support for Amlogic G12A USB Control Glue HW.
The Amlogic G12A SoC Family embeds 2 USB Controllers :
- a DWC3 IP configured as Host for USB2 and USB3
- a DWC2 IP configured as Peripheral USB2 OnlyA glue connects these both controllers to 2 USB2 PHYs, and optionnally to an USB3+PCIE Combo PHY shared with the PCIE controller.
The Glue configures the UTMI 8bit interfaces for the USB2 PHYs, including routing of the OTG PHY between the DWC3 and DWC2 controllers, and setups the on-chip OTG mode selection for this PHY.
This driver sets the OTG capable port as Host mode by default, the switch to Device mode is to be done in a separate patch.
Signed-off-by Neil Armstrong <[email protected]>---
[...]
Quoted 15 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +15
-0+static int dwc3_meson_g12a_get_phys (struct dwc3_meson_g12a *priv) +{ +int i, ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =generic_phy_get_by_name (priv->dev, phy_names[i], + &priv->phys[i]); +if (ret == -ENOENT ) +continue ; + +if (ret) +return ret; + +if (i ==USB3_HOST_PHY ) + priv->usb3_ports++;Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 315
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+else + priv->usb2_ports++; + } + +printf ("%s: usb2 ports: %d\n" , __func__, priv->usb2_ports); +printf ("%s: usb3 ports: %d\n" , __func__, priv->usb3_ports);Are these prints needed ?
Nop, forgot to switch them to debug
Quoted 51 lines
Quoted 3 lines
(quoted diff) +2
-0+ return 0; +}[...]
Quoted 46 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +46
-0+static int dwc3_meson_g12a_probe (struct udevice *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_platdata (dev); +int ret, i; + + priv->dev = dev; + + ret =regmap_init_mem (dev_ofnode (dev), &priv->regmap); +if (ret) +return ret; + + ret =dwc3_meson_g12a_clk_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_reset_init (priv); +if (ret) +return ret; + + ret =dwc3_meson_g12a_get_phys (priv); +if (ret) +return ret; + +#if CONFIG_IS_ENABLED (DM_REGULATOR ) + ret =device_get_supply_regulator (dev,"vbus-supply" , + &priv->vbus_supply); +if (ret && ret != -ENOENT ) { +pr_err ("Failed to get PHY regulator\n" ); +return ret; + } + +if (priv->vbus_supply) { + ret =regulator_set_enable (priv->vbus_supply, true); +if (ret) +return ret; + } +#endif + + priv->otg_mode =usb_get_dr_mode (dev_of_offset (dev)); + + ret =dwc3_meson_g12a_usb_init (priv); +if (ret) +return ret; + +for (i =0 ; i <PHY_COUNT ; ++i) { +if (!priv->phys[i].dev)Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 409
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+continue ; + + ret =generic_phy_init (&priv->phys[i]); +if (ret) + goto err_phy_init; + }Isn't there some function to init all the PHYs already ?
Quoted 3 lines
I don't see any in u-boot master !
Unlike dwc3, we need to get the phys with the names to check if the USB3 phy is enabled, so we can't get all possible phys.
I see, so thus far my only comment is about the missed debug prints. Thanks!
Signature · 2 lines
Best regards, Marek Vasut
PATCH 2/3 phy: meson: add Amlogic G12A USB2 and USB3+PCIE PHY drivers
In reply to Neil ArmstrongThis adds support for the USB PHYs found in the Amlogic G12A SoC Family.
The USB2 PHY supports Host and/or Peripheral mode, depending on it's position. The first PHY is only used as Host, but the second supports Dual modes defined by the USB Control Glue HW in front of the USB Controllers.
The second driver supports USB3 Host mode or PCIE 2.0 mode, depending on the layout of the board.
Selection is done by the #phy-cells, making the mode static and exclusive.
--- drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/meson-g12a-usb2.c | 216 ++++++++++++++++++ drivers/phy/meson-g12a-usb3-pcie.c | 345 +++++++++++++++++++++++++++++ 4 files changed, 570 insertions(+) create mode 100644 drivers/phy/meson-g12a-usb2.c create mode 100644 drivers/phy/meson-g12a-usb3-pcie.c
drivers/phy/Kconfig +8 -0
@@ -147,6 +147,14 @@ config MESON_GXL_USB_PHY This is the generic phy driver for the Amlogic Meson GXL USB2 and USB3 PHYS. +config MESON_G12A_USB_PHY + bool "Amlogic Meson G12A USB PHYs" + depends on PHY && ARCH_MESON && MESON_G12A + imply REGMAP + help + This is the generic phy driver for the Amlogic Meson G12A + USB2 and USB3 PHYS. + config MSM8916_USB_PHY bool "Qualcomm MSM8916 USB PHY support" depends on PHY
drivers/phy/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_PHY_RCAR_GEN2) += phy-rcar-gen2.o obj-$(CONFIG_PHY_RCAR_GEN3) += phy-rcar-gen3.o 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_MESON_G12A_USB_PHY) += meson-g12a-usb2.o meson-g12a-usb3-pcie.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
drivers/phy/meson-g12a-usb2.c new file +216 -0
216 lines not on this page · raw message
drivers/phy/meson-g12a-usb3-pcie.c new file +345 -0
345 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH 3/3 mach-meson: g12a: add DWC2 peripheral mode support
In reply to Neil ArmstrongAdds support for Amlogic G12A USB Device mode.
The DWC2 Controller behind the Glue can be connected to an OTG capable PHY. The Glue setups the PHY mode.
This patch implements Device mode support by adding a board_usb_init/cleanup setting up the DWC2 controller and switch the OTG capable port to Device before starting the DWC2 controller in Device mode.
--- arch/arm/include/asm/arch-meson/usb.h | 12 +++ arch/arm/mach-meson/board-g12a.c | 126 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 arch/arm/include/asm/arch-meson/usb.h
arch/arm/include/asm/arch-meson/usb.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 BayLibre, SAS +* Author: Neil Armstrong <[email protected]> +*/ + +#ifndef __MESON_USB_H__ +#define __MESON_USB_H__ + +int dwc3_meson_g12a_force_mode (struct udevice *dev,enum usb_dr_mode mode); + +#endif /* __MESON_USB_H__ */
arch/arm/mach-meson/board-g12a.c +126 -0
136 lines not on this page · raw message
Signature · 1 line
2.21.0