arm64: meson: Add support for USB on Amlogic G12A
Subsystems (6)
PATCH 1/8 dt-bindings: phy: Add Amlogic G12A USB2 PHY Bindings
In reply to Neil ArmstrongAdd the Amlogic G12A Family USB2 OTG PHY Bindings
--- .../bindings/phy/meson-g12a-usb2-phy.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt
Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt new file +22 -0
@@ -0,0 +1,22 @@ +* Amlogic G12A USB2 PHY binding + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb2-phy" +- reg: The base address and length of the registers +- #phys-cells: must be 0 (see phy-bindings.txt in this directory) +- clocks: a phandle to the clock of this PHY +- clock-names: must be "xtal" +- resets: a phandle to the reset line of this PHY +- reset-names: must be "phy" +- phy-supply: see phy-bindings.txt in this directory + +Example: + usb2_phy0: phy@36000 { + compatible = "amlogic,g12a-usb2-phy"; + reg = <0x0 0x36000 0x0 0x2000>; + clocks = <&xtal>; + clock-names = "xtal"; + resets = <&reset RESET_USB_PHY21>; + reset-names = "phy"; + #phy-cells = <0>; + };
Signature · 1 line
2.20.1
PATCH 2/8 dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
In reply to Neil ArmstrongAdd the Amlogic G12A Family USB3 + PCIE Combo PHY Bindings.
This PHY can provide exclusively USB3 or PCIE support on shared I/Os.
--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +25 -0
@@ -0,0 +1,25 @@ +* Amlogic G12A USB3 + PCIE Combo PHY binding + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb3-pcie-phy" +- #phys-cells: must be 1. The cell number is used to select the phy mode + as defined in <dt-bindings/phy/phy.h> between PHY_TYPE_USB3 and PHY_TYPE_PCIE +- reg: The base address and length of the registers +- clocks: a phandle to the 100MHz reference clock of this PHY +- clock-names: must be "ref_clk" +- resets: phandle to the reset lines for: + - the PHY control + - the USB3+PCIE PHY + - the PHY registers + +Example: + usb3_pcie_phy: phy@46000 { + compatible = "amlogic,g12a-usb3-pcie-phy"; + reg = <0x0 0x46000 0x0 0x2000>; + clocks = <&clkc CLKID_PCIE_PLL>; + clock-names = "ref_clk"; + resets = <&reset RESET_PCIE_CTRL_A>, + <&reset RESET_PCIE_PHY>, + <&reset RESET_PCIE_APB>; + #phy-cells = <1>; + };
Signature · 1 line
2.20.1
PATCH 3/8 dt-bindings: usb: dwc2: Add Amlogic G12A DWC2 Compatible
In reply to Neil ArmstrongAdds the specific compatible string for the DWC2 IP found in the Amlogic G12A SoC Family.
--- Documentation/devicetree/bindings/usb/dwc2.txt | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/usb/dwc2.txt +1 -0
@@ -14,6 +14,7 @@ Required properties: - "amlogic,meson8-usb": The DWC2 USB controller instance in Amlogic Meson8 SoCs; - "amlogic,meson8b-usb": The DWC2 USB controller instance in Amlogic Meson8b SoCs; - "amlogic,meson-gxbb-usb": The DWC2 USB controller instance in Amlogic S905 SoCs; + - "amlogic,meson-g12a-usb": The DWC2 USB controller instance in Amlogic G12A SoCs; - "amcc,dwc-otg": The DWC2 USB controller instance in AMCC Canyonlands 460EX SoCs; - snps,dwc2: A generic DWC2 USB controller with default parameters. - "st,stm32f4x9-fsotg": The DWC2 USB FS/HS controller instance in STM32F4x9 SoCs
Signature · 1 line
2.20.1
PATCH 4/8 dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
In reply to Neil ArmstrongAdds the bindings for the Amlogic G12A USB 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.
The PHYs are children of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
The PHY interconnect is handled into ports subnodes, which eases describing which PHY is enabled (like the USB3 shared PHY) and futures layouts on derivatives of the G12A Family.
--- .../devicetree/bindings/usb/amlogic,dwc3.txt | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+)
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +109 -0
@@ -40,3 +40,112 @@ Example device nodes: phy-names = "usb2-phy", "usb3-phy"; }; }; + +Amlogic Meson G12A DWC3 USB SoC Controller Glue + +The Amlogic G12A embeds a DWC3 USB IP Core configured for USB2 and USB3 +in host-only mode, and a DWC2 IP Core configured for USB2 peripheral mode +only. + +A glue connects the DWC3 core to USB2 PHYs and optionnaly to an USB3 PHY. + +One of the USB2 PHY can be re-routed in peripheral mode to a DWC2 USB IP. + +The DWC3 Glue controls the PHY routing and power, an interrupt line is +connected to the Glue to serve as OTG ID change detection. + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb-ctrl" +- clocks: a handle for the "USB" clock +- clock-names: must be "usb" +- resets: a handle for the shared "USB" reset line +- reset-names: must be "usb" +- reg: The base address and length of the registers +- interrupts: the interrupt specifier for the OTG detection + +Required child nodes: + +USB Ports are described as child 'port' nodes grouped under a 'ports' node, +with #address-cells, #size-cells specified. + +Each 'port' sub-node identifies a possible USB Port served by an USB PHY +identified by the 'phy' property as decribed in ../phy/phy-bindings.txt + +Each 'port' is identified by a reg property to number the port. + +The following table lists for each supported model the port number +corresponding to each PHY serving a physical USB Port. + + Family Port 0 Port 1 Port 2 Port 3 Port 4 +--------------------------------------------------------------- + G12A USBHOST_A USBOTG_B Reserved Reserved USB3_0 + +A child node must exist to represent the core DWC3 IP block. The name of +the node is not important. The content of the node is defined in dwc3.txt. + +A child node must exist to represent the core DWC2 IP block. The name of +the node is not important. The content of the node is defined in dwc2.txt. + +PHY documentation is provided in the following places: +- Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt +- Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt + + +Example device nodes: + usb: usb@ffe09000 { + compatible = "amlogic,meson-g12a-usb-ctrl"; + reg = <0x0 0xffe09000 0x0 0xa0>; + interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + clocks = <&clkc CLKID_USB>; + clock-names = "usb"; + resets = <&reset RESET_USB>; + reset-names = "usb"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB2 Port 0 */ + usb20: port@0 { + reg = <0>; + phys = <&usb2_phy0>; + }; + + /* USB2 Port 1 */ + usb21: port@1 { + reg = <1>; + phys = <&usb2_phy1>; + }; + + /* USB3 Port 0 */ + usb3: port@4 { + reg = <4>; + phys = <&usb3_pcie_phy PHY_TYPE_USB3>; + }; + }; + + dwc2: usb@ff400000 { + compatible = "amlogic,meson-g12a-usb", "snps,dwc2"; + reg = <0x0 0xff400000 0x0 0x40000>; + interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc CLKID_USB1_DDR_BRIDGE>; + clock-names = "ddr"; + dr_mode = "peripheral"; + g-rx-fifo-size = <192>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128 128 16 16 16>; + }; + + dwc3: dwc3@ff500000 { + compatible = "snps,dwc3"; + reg = <0x0 0xff500000 0x0 0x100000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + dr_mode = "host"; + snps,dis_u2_susphy_quirk; + snps,quirk-frame-length-adjustment; + }; + };
Signature · 1 line
2.20.1
PATCH 5/8 phy: amlogic: add Amlogic G12A USB2 PHY Driver
In reply to Neil ArmstrongThis adds support for the USB2 PHY found in the Amlogic G12A SoC Family.
It 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.
--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 191 ++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.c
drivers/phy/amlogic/Kconfig +12 -0
@@ -36,3 +36,15 @@ config PHY_MESON_GXL_USB3 Enable this to support the Meson USB3 PHY and OTG detection IP block found in Meson GXL and GXM SoCs. If unsure, say N. + +config PHY_MESON_G12A_USB2 + tristate "Meson G12A USB2 PHY drivers" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + depends on USB_SUPPORT + select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB2 PHYs found in Meson + G12A SoCs. + If unsure, say N.
drivers/phy/amlogic/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o +obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +191 -0
191 lines not on this page · raw message
PATCH 6/8 phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
In reply to Neil ArmstrongThis adds support for the shared USB3 + PCIE PHY found in the Amlogic G12A SoC Family.
It 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/amlogic/Kconfig | 12 + drivers/phy/amlogic/Makefile | 1 + .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 414 ++++++++++++++++++ 3 files changed, 427 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c
drivers/phy/amlogic/Kconfig +12 -0
@@ -48,3 +48,15 @@ config PHY_MESON_G12A_USB2 Enable this to support the Meson USB2 PHYs found in Meson G12A SoCs. If unsure, say N. + +config PHY_MESON_G12A_USB3_PCIE + tristate "Meson G12A USB3+PCIE Combo PHY drivers" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + depends on USB_SUPPORT + select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB3 + PCIE Combi PHY found + in Meson G12A SoCs. + If unsure, say N.
drivers/phy/amlogic/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o +obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.o
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +414 -0
414 lines not on this page · raw message
PATCH 7/8 usb: dwc2: Add Amlogic G12A DWC2 Params
In reply to Neil ArmstrongThis patchs sets the params for the DWC2 Controller found in the Amlogic G12A SoC family.
It mainly sets the settings reported incorrect by the driver, leaving the remaining detected automatically by the driver and provided by the DT node.
--- drivers/usb/dwc2/params.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/usb/dwc2/params.c +12 -0
@@ -121,6 +121,16 @@ static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg) p->power_down =DWC2_POWER_DOWN_PARAM_NONE ; } +static void dwc2_set_amlogic_g12a_params (struct dwc2_hsotg *hsotg) +{ +struct dwc2_core_params *p = &hsotg->params; + + p->lpm = false; + p->lpm_clock_gating = false; + p->besl = false; + p->hird_threshold_en = false; +} +static void dwc2_set_amcc_params (struct dwc2_hsotg *hsotg) {struct dwc2_core_params *p = &hsotg->params;
@@ -167,6 +177,8 @@ const struct of_device_id dwc2_of_match_table[] = { .data = dwc2_set_amlogic_params }, { .compatible = "amlogic,meson-gxbb-usb", .data = dwc2_set_amlogic_params }, + { .compatible = "amlogic,meson-g12a-usb", + .data = dwc2_set_amlogic_g12a_params }, { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params }, { .compatible = "st,stm32f4x9-fsotg", .data = dwc2_set_stm32f4x9_fsotg_params },
PATCH 8/8 usb: dwc3: Add Amlogic G12A DWC3 glue
In reply to Neil ArmstrongAdds 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.
The PHYs are childen of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
The drivers collects the mode of each PHY and determine which PHY is to be routed between the DWC2 and DWC3 controllers.
This drivers supports the on-probe setup of the OTG mode, and manually via a debugfs interface. The IRQ mode change detect is yet to be added in a future patchset, mainly due to lack of hardware to validate on.
--- drivers/usb/dwc3/Kconfig | 9 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 650 +++++++++++++++++++++++++++++ 3 files changed, 660 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.c
drivers/usb/dwc3/Kconfig +9 -0
@@ -93,6 +93,15 @@ config USB_DWC3_KEYSTONE Support of USB2/3 functionality in TI Keystone2 platforms. Say 'Y' or 'M' here if you have one such device +config USB_DWC3_MESON_G12A + tristate "Amlogic Meson G12A Platforms" + depends on OF && COMMON_CLK + depends on ARCH_MESON || COMPILE_TEST + default USB_DWC3 + help + Support USB2/3 functionality in Amlogic G12A platforms. + Say 'Y' or 'M' if you have one such device. + config USB_DWC3_OF_SIMPLE tristate "Generic OF Simple Glue Layer" depends on OF && COMMON_CLK
drivers/usb/dwc3/Makefile +1 -0
@@ -47,6 +47,7 @@ obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o obj-$(CONFIG_USB_DWC3_HAPS) += dwc3-haps.o obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o +obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.o
drivers/usb/dwc3/dwc3-meson-g12a.c new file +650 -0
650 lines not on this page · raw message
cover arm64: meson: Add support for USB on Amlogic G12A
This patchset adds support for USB on Amlogic G12A SoCs.
This patchset is composed with :
- bindings of the PHYs
- bindings of the USB Control Glue
- PHY Drivers
- USB Control Glue driver
Device Tree nodes will be added in a separate patchset.
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.
The PHYs are children of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
The PHY interconnect is handled into ports subnodes, which eases describing which PHY is enabled (like the USB3 shared PHY) and futures layouts on derivatives of the G12A Family.
This drivers supports the on-probe setup of the OTG mode, and manually via a debugfs interface. The IRQ mode change detect is yet to be added in a future patchset, mainly due to lack of hardware to validate on.
Neil Armstrong (8):
dt-bindings: phy: Add Amlogic G12A USB2 PHY Bindings
dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
dt-bindings: usb: dwc2: Add Amlogic G12A DWC2 Compatible
dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
phy: amlogic: add Amlogic G12A USB2 PHY Driver
phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
usb: dwc2: Add Amlogic G12A DWC2 Params
usb: dwc3: Add Amlogic G12A DWC3 glue
.../bindings/phy/meson-g12a-usb2-phy.txt | 22 + .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 25 + .../devicetree/bindings/usb/amlogic,dwc3.txt | 109 +++ .../devicetree/bindings/usb/dwc2.txt | 1 + drivers/phy/amlogic/Kconfig | 24 + drivers/phy/amlogic/Makefile | 2 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 191 +++++ .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 414 +++++++++++ drivers/usb/dwc2/params.c | 12 + drivers/usb/dwc3/Kconfig | 9 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 650 ++++++++++++++++++ 12 files changed, 1460 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.c create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.c
Signature · 1 line
2.20.1
Re: [PATCH 1/8] dt-bindings: phy: Add Amlogic G12A USB2 PHY Bindings
In reply to Neil ArmstrongQuoted 2 lines · Neil Armstrong
Add the Amlogic G12A Family USB2 OTG PHY Bindings
nit-pick: if you want to keep "OTG" in there then please add a short description how OTG works on this PHY.
I would describe this as: "Add the Amlogic G12A Family USB2 PHY Bindings. The PHY works for host or peripheral modes. Configuration of the mode is part of the USBCTRL registers which are outside of the PHY registers."
Quoted 1 line
Signed-off-by Neil Armstrong <[email protected]>
with the patch description nit-pick addressed:
Regards
Martin
Re: [PATCH 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
In reply to Neil ArmstrongQuoted 6 lines · Neil Armstrong
Add the Amlogic G12A Family USB3 + PCIE Combo PHY Bindings.
This PHY can provide exclusively USB3 or PCIE support on shared I/Os.
Signed-off-by Neil Armstrong <[email protected]>
one nit-pick below, but apart from that:
Quoted 14 lines
--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txtDocumentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +3
-0@@ -0,0 +1,25 @@ +* Amlogic G12A USB3 + PCIE Combo PHY binding + +Required properties:
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt line 13
Quoted 10 lines
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +10
-0+- compatible: Should be "amlogic,meson-g12a-usb3-pcie-phy" +- #phys-cells: must be 1. The cell number is used to select the phy mode + as defined in <dt-bindings/phy/phy.h> between PHY_TYPE_USB3 and PHY_TYPE_PCIE +- reg: The base address and length of the registers +- clocks: a phandle to the 100MHz reference clock of this PHY +- clock-names: must be "ref_clk" +- resets: phandle to the reset lines for: + - the PHY control + - the USB3+PCIE PHY + - the PHY registers
no reset-names (like in the G12A USB2 PHY bindings) here? even if you don't use them in the driver I suggest you add them for consistency (and maybe to make it easier to compare the bindings with the datasheet. I don't have access to the datasheet so I'm not sure if having the reset-names is relevant for this case)
Regards
Martin
Re: [PATCH 3/8] dt-bindings: usb: dwc2: Add Amlogic G12A DWC2 Compatible
In reply to Neil ArmstrongHi Neil,
Quoted 5 lines · Neil Armstrong
Adds the specific compatible string for the DWC2 IP found in the Amlogic G12A SoC Family.
Signed-off-by Neil Armstrong <[email protected]>
Documentation/devicetree/bindings/usb/dwc2.txt Required properties: · line 17
Quoted 13 lines
--- Documentation/devicetree/bindings/usb/dwc2.txt | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/usb/dwc2.txt +1
-0@@ -14,6 +14,7 @@ Required properties: - "amlogic,meson8-usb": The DWC2 USB controller instance in Amlogic Meson8 SoCs; - "amlogic,meson8b-usb": The DWC2 USB controller instance in Amlogic Meson8b SoCs; - "amlogic,meson-gxbb-usb": The DWC2 USB controller instance in Amlogic S905 SoCs; + - "amlogic,meson-g12a-usb": The DWC2 USB controller instance in Amlogic G12A SoCs;
if anyone is curious: starting with GXL (not supported by the dwc2 driver yet) the dwc2 core is "peripheral mode" only while previous SoCs had one host-only dwc2 instance and another OTG capable dwc2 instance
I also discussed the compatible string with Neil off-list because I was not sure if we have unique compatible names for the dwc2 controller and the "USB control" registers.
The "USB control" registers are named "USBCTRL" according to Neil (I assume he got this information from the datasheet to which I don't have access). Thus the compatible string for the "USB control" device will be "amlogic,meson-g12a-usb-ctrl" - so we don't have any naming conflict.
Regards
Martin
Martin Blumenstingl
reviewerRe: [PATCH 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver
In reply to Neil ArmstrongHi Neil,
Quoted 20 lines · Neil Armstrong
This adds support for the USB2 PHY found in the Amlogic G12A SoC Family.
It 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.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 191 ++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.cdrivers/phy/amlogic/Kconfig +0
-0
drivers/phy/amlogic/Kconfig config PHY_MESON_GXL_USB3 · line 41
Quoted 6 lines
drivers/phy/amlogic/Kconfig +3
-0@@ -36,3 +36,15 @@ config PHY_MESON_GXL_USB3 Enable this to support the Meson USB3 PHY and OTG detection IP block found in Meson GXL and GXM SoCs. If unsure, say N. + +config PHY_MESON_G12A_USB2 + tristate "Meson G12A USB2 PHY drivers"
aw, there's a typo in the GXL driver names (from which this new Kconfig entry may have been copied): it should be "driver" instead of "drivers"
drivers/phy/amlogic/Kconfig config PHY_MESON_GXL_USB3 · line 44
Quoted 3 lines
drivers/phy/amlogic/Kconfig +3
-0+ default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + depends on USB_SUPPORT
I don't think you need USB_SUPPORT (neither does PHY_MESON_GXL_USB2, but it seems that I accidentally left it in from an early development iteration), see below
Quoted 28 lines
drivers/phy/amlogic/Kconfig +6
-0+ select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB2 PHYs found in Meson + G12A SoCs. + If unsure, say N.drivers/phy/amlogic/Makefile +1
-0@@ -1,3 +1,4 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o +obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.odrivers/phy/amlogic/phy-meson-g12a-usb2.c new file +7
-0@@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Meson G12A USB2 PHY driver +* +* Copyright (C) 2017 Martin Blumenstingl <[email protected]> +* Copyright (C) 2017 Amlogic, Inc. All rights reserved +* Copyright (C) 2019 BayLibre, SAS
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 17
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0+* Author: Neil Armstrong <[email protected]> +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/regmap.h> +#include <linux/mfd/syscon.h>
I don't see any syscon usage in the driver so you can drop this
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 20
Quoted 3 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +3
-0+#include <linux/reset.h> +#include <linux/phy/phy.h> +#include <linux/usb/otg.h>
do you need this? if you drop "depends on USB_SUPPORT" from Kconfig then you want to get rid of this as well
Quoted 47 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +47
-0+#include <linux/platform_device.h> + +#define PHY_CTRL_R0 0x0 +#define PHY_CTRL_R1 0x4 +#define PHY_CTRL_R2 0x8 +#define PHY_CTRL_R3 0xc +#define PHY_CTRL_R4 0x10 +#define PHY_CTRL_R5 0x14 +#define PHY_CTRL_R6 0x18 +#define PHY_CTRL_R7 0x1c +#define PHY_CTRL_R8 0x20 +#define PHY_CTRL_R9 0x24 +#define PHY_CTRL_R10 0x28 +#define PHY_CTRL_R11 0x2c +#define PHY_CTRL_R12 0x30 +#define PHY_CTRL_R13 0x34 +#define PHY_CTRL_R14 0x38 +#define PHY_CTRL_R15 0x3c +#define PHY_CTRL_R16 0x40 +#define PHY_CTRL_R17 0x44 +#define PHY_CTRL_R18 0x48 +#define PHY_CTRL_R19 0x4c +#define PHY_CTRL_R20 0x50 +#define PHY_CTRL_R21 0x54 +#define PHY_CTRL_R22 0x58 +#define PHY_CTRL_R23 0x5c + +#define RESET_COMPLETE_TIME 1000 +#define PLL_RESET_COMPLETE_TIME 100 + +struct phy_meson_g12a_usb2_priv { +struct device *dev; +struct regmap *regmap; +struct clk *clk; +struct reset_control *reset; +}; + +static const struct regmap_config phy_meson_g12a_usb2_regmap_conf = { + .reg_bits =8 , + .val_bits =32 , + .reg_stride =4 , + .max_register =PHY_CTRL_R23 , +}; + +static int phy_meson_g12a_usb2_init (struct phy *phy) +{ +struct phy_meson_g12a_usb2_priv *priv =phy_get_drvdata (phy);
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 77
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0+int ret; + + ret =reset_control_reset (priv->reset); +if (ret) +return ret; + +udelay (RESET_COMPLETE_TIME ); + +/* usb2_otg_aca_en == 0 */ +regmap_update_bits (priv->regmap,PHY_CTRL_R21 ,BIT (2 ),0 );
do you have the name of the other register bits as well? having #defines would make the code easier to read
Quoted 20 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +20
-0+ +/* PLL Setup : 24MHz * 20 / 1 = 480MHz */ +regmap_write (priv->regmap,PHY_CTRL_R16 ,0x39400414 ); +regmap_write (priv->regmap,PHY_CTRL_R17 ,0x927e0000 ); +regmap_write (priv->regmap,PHY_CTRL_R18 ,0xac5f49e5 ); + +udelay (PLL_RESET_COMPLETE_TIME ); + +/* UnReset PLL */ +regmap_write (priv->regmap,PHY_CTRL_R16 ,0x19400414 ); + +/* PHY Tuning */ +regmap_write (priv->regmap,PHY_CTRL_R20 ,0xfe18 ); +regmap_write (priv->regmap,PHY_CTRL_R4 ,0x8000fff ); + +/* Tuning Disconnect Threshold */ +regmap_write (priv->regmap,PHY_CTRL_R3 ,0x34 ); + +/* Analog Settings */ +regmap_write (priv->regmap,PHY_CTRL_R14 ,0 );
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 107
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0+regmap_write (priv->regmap,PHY_CTRL_R13 ,0x78000 ); + +return 0 ; +} + +static int phy_meson_g12a_usb2_exit (struct phy *phy) +{ +struct phy_meson_g12a_usb2_priv *priv =phy_get_drvdata (phy); + +return reset_control_reset (priv->reset);
do you have information on whether we should reset_control_assert here instead of reset_control_reset?
Quoted 35 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +35
-0+} + +/* set_mode is not needed, mode setting is handled via the UTMI bus */ +static const struct phy_ops phy_meson_g12a_usb2_ops = { + .init = phy_meson_g12a_usb2_init, + .exit = phy_meson_g12a_usb2_exit, + .owner =THIS_MODULE , +}; + +static int phy_meson_g12a_usb2_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *res; +struct phy_meson_g12a_usb2_priv *priv; +struct phy *phy; +void __iomem *base; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->dev = dev; +platform_set_drvdata (pdev, priv); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + priv->regmap =devm_regmap_init_mmio (dev, base, + &phy_meson_g12a_usb2_regmap_conf); +if (IS_ERR (priv->regmap)) +return PTR_ERR (priv->regmap);
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 152
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0+ + priv->clk =devm_clk_get (dev,"xtal" ); +if (IS_ERR (priv->clk)) +return PTR_ERR (priv->clk); + + priv->reset =devm_reset_control_get (dev,"phy" ); +if (IS_ERR (priv->reset)) +return PTR_ERR (priv->reset); + + ret =reset_control_deassert (priv->reset);
should we move this to phy_meson_g12a_usb2_init (which currently uses reset_control_reset)?
then we could also use reset_control_assert in phy_meson_g12a_usb2_exit
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 160
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +8
-0+if (ret) +return ret; + + phy =devm_phy_create (dev,NULL , &phy_meson_g12a_usb2_ops); +if (IS_ERR (phy)) { + ret =PTR_ERR (phy); +if (ret != -EPROBE_DEFER ) +dev_err (dev,"failed to create PHY\n" );
phy-core only returns EPROBE_DEFER in case the phy-supply is not ready yet. we won't need a phy-supply (at least as far as I know, if we do then please document this in the dt-bindings patch). for USB VBUS dwc2 support the "vbus-supply" property which we should use instead. I leave it up to you to decide whether the check makes sense
Quoted 17 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +17
-0+return ret; + } + +phy_set_bus_width (phy,8 ); +phy_set_drvdata (phy, priv); + + phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); + +return PTR_ERR_OR_ZERO (phy_provider); +} + +static const struct of_device_id phy_meson_g12a_usb2_of_match[] = { + { .compatible ="amlogic,g12a-usb2-phy" , }, + { }, +}; +MODULE_DEVICE_TABLE (of, phy_meson_g12a_usb2_of_match); +
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 188
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0+static struct platform_driver phy_meson_g12a_usb2_driver = { + .probe = phy_meson_g12a_usb2_probe, + .driver = { + .name ="phy-meson-g12a-usb2" , + .of_match_table = phy_meson_g12a_usb2_of_match, + }, +}; +module_platform_driver (phy_meson_g12a_usb2_driver); + +MODULE_AUTHOR ("Martin Blumenstingl <[email protected]>" );
I haven't contributed any of the relevant code to this driver (I assume you took one of our existing Amlogic PHY drivers as skeleton?). it's up to you whether you want to keep me in here
Regards
Martin
Re: [PATCH 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
In reply to Martin BlumenstinglQuoted 31 lines · Martin Blumenstingl
Quoted 6 lines · Neil Armstrong
Add the Amlogic G12A Family USB3 + PCIE Combo PHY Bindings.
This PHY can provide exclusively USB3 or PCIE support on shared I/Os.
Signed-off-by Neil Armstrong <[email protected]>one nit-pick below, but apart from that:
Reviewed-by Martin Blumenstingl <[email protected]>Quoted 21 lines
--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txtDocumentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +10
-0@@ -0,0 +1,25 @@ +* Amlogic G12A USB3 + PCIE Combo PHY binding + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb3-pcie-phy" +- #phys-cells: must be 1. The cell number is used to select the phy mode + as defined in <dt-bindings/phy/phy.h> between PHY_TYPE_USB3 and PHY_TYPE_PCIE +- reg: The base address and length of the registers +- clocks: a phandle to the 100MHz reference clock of this PHY +- clock-names: must be "ref_clk" +- resets: phandle to the reset lines for:
Quoted 8 lines
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt line 13
Quoted 3 lines
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +3
-0+ - the PHY control + - the USB3+PCIE PHY + - the PHY registersno reset-names (like in the G12A USB2 PHY bindings) here? even if you don't use them in the driver I suggest you add them for consistency (and maybe to make it easier to compare the bindings with the datasheet. I don't have access to the datasheet so I'm not sure if having the reset-names is relevant for this case)
You're right, it's better to have names here !
Neil
Quoted 5 lines
Regards
Martin
Re: [PATCH 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver
In reply to Martin BlumenstinglHi Martin,
Quoted 18 lines · Martin Blumenstingl
Hi Neil,
Quoted 15 lines · Neil Armstrong
This adds support for the USB2 PHY found in the Amlogic G12A SoC Family.
It 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.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 ++ drivers/phy/amlogic/Makefile | 1 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 191 ++++++++++++++++++++++ 3 files changed, 204 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.c
Quoted 14 lines
drivers/phy/amlogic/Kconfig config PHY_MESON_GXL_USB3 · line 41
Quoted 11 lines
drivers/phy/amlogic/Kconfig +3
-0@@ -36,3 +36,15 @@ config PHY_MESON_GXL_USB3 Enable this to support the Meson USB3 PHY and OTG detection IP block found in Meson GXL and GXM SoCs. If unsure, say N. + +config PHY_MESON_G12A_USB2 + tristate "Meson G12A USB2 PHY drivers"aw, there's a typo in the GXL driver names (from which this new
Kconfigentry may have been copied): it should be "driver" instead of "drivers"
Will fix...
Quoted 7 lines
drivers/phy/amlogic/Kconfig config PHY_MESON_GXL_USB3 · line 44
Quoted 4 lines
drivers/phy/amlogic/Kconfig +3
-0+ default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + depends on USB_SUPPORTI don't think you need
USB_SUPPORT(neither doesPHY_MESON_GXL_USB2, but it seems that I accidentally left it in from an early development iteration), see below
Indeed, thanks for pointing this
Quoted 32 lines
Quoted 32 lines
drivers/phy/amlogic/Kconfig +6
-0+ select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB2 PHYs found in Meson + G12A SoCs. + If unsure, say N.drivers/phy/amlogic/Makefile +1
-0@@ -1,3 +1,4 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o +obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.odrivers/phy/amlogic/phy-meson-g12a-usb2.c new file +10
-0@@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Meson G12A USB2 PHY driver +* +* Copyright (C) 2017 Martin Blumenstingl <[email protected]> +* Copyright (C) 2017 Amlogic, Inc. All rights reserved +* Copyright (C) 2019 BayLibre, SAS +* Author: Neil Armstrong <[email protected]> +*/ +
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 17
Quoted 7 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +7
-0+#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/regmap.h> +#include <linux/mfd/syscon.h> I don't see any syscon usage in the driver so you can drop this
Forgot to remove it
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 20
Quoted 4 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +3
-0+#include <linux/reset.h> +#include <linux/phy/phy.h> +#include <linux/usb/otg.h> do you need this? if you drop "depends on
USB_SUPPORT" fromKconfigthen you want to get rid of this as well
Indeed, no need to this
Quoted 52 lines
Quoted 52 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +51
-0+#include <linux/platform_device.h> + +#define PHY_CTRL_R0 0x0 +#define PHY_CTRL_R1 0x4 +#define PHY_CTRL_R2 0x8 +#define PHY_CTRL_R3 0xc +#define PHY_CTRL_R4 0x10 +#define PHY_CTRL_R5 0x14 +#define PHY_CTRL_R6 0x18 +#define PHY_CTRL_R7 0x1c +#define PHY_CTRL_R8 0x20 +#define PHY_CTRL_R9 0x24 +#define PHY_CTRL_R10 0x28 +#define PHY_CTRL_R11 0x2c +#define PHY_CTRL_R12 0x30 +#define PHY_CTRL_R13 0x34 +#define PHY_CTRL_R14 0x38 +#define PHY_CTRL_R15 0x3c +#define PHY_CTRL_R16 0x40 +#define PHY_CTRL_R17 0x44 +#define PHY_CTRL_R18 0x48 +#define PHY_CTRL_R19 0x4c +#define PHY_CTRL_R20 0x50 +#define PHY_CTRL_R21 0x54 +#define PHY_CTRL_R22 0x58 +#define PHY_CTRL_R23 0x5c + +#define RESET_COMPLETE_TIME 1000 +#define PLL_RESET_COMPLETE_TIME 100 + +struct phy_meson_g12a_usb2_priv { +struct device *dev; +struct regmap *regmap; +struct clk *clk; +struct reset_control *reset; +}; + +static const struct regmap_config phy_meson_g12a_usb2_regmap_conf = { + .reg_bits =8 , + .val_bits =32 , + .reg_stride =4 , + .max_register =PHY_CTRL_R23 , +}; + +static int phy_meson_g12a_usb2_init (struct phy *phy) +{ +struct phy_meson_g12a_usb2_priv *priv =phy_get_drvdata (phy); +int ret; + + ret =reset_control_reset (priv->reset); +if (ret)
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 77
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +6
-0+return ret; + +udelay (RESET_COMPLETE_TIME ); + +/* usb2_otg_aca_en == 0 */ +regmap_update_bits (priv->regmap,PHY_CTRL_R21 ,BIT (2 ),0 );do you have the name of the other register bits as well? having #defines would make the code easier to read
It's on my TODO list...
Quoted 25 lines
Quoted 25 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +24
-0+ +/* PLL Setup : 24MHz * 20 / 1 = 480MHz */ +regmap_write (priv->regmap,PHY_CTRL_R16 ,0x39400414 ); +regmap_write (priv->regmap,PHY_CTRL_R17 ,0x927e0000 ); +regmap_write (priv->regmap,PHY_CTRL_R18 ,0xac5f49e5 ); + +udelay (PLL_RESET_COMPLETE_TIME ); + +/* UnReset PLL */ +regmap_write (priv->regmap,PHY_CTRL_R16 ,0x19400414 ); + +/* PHY Tuning */ +regmap_write (priv->regmap,PHY_CTRL_R20 ,0xfe18 ); +regmap_write (priv->regmap,PHY_CTRL_R4 ,0x8000fff ); + +/* Tuning Disconnect Threshold */ +regmap_write (priv->regmap,PHY_CTRL_R3 ,0x34 ); + +/* Analog Settings */ +regmap_write (priv->regmap,PHY_CTRL_R14 ,0 ); +regmap_write (priv->regmap,PHY_CTRL_R13 ,0x78000 ); + +return 0 ; +}
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 107
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +6
-0+ +static int phy_meson_g12a_usb2_exit (struct phy *phy) +{ +struct phy_meson_g12a_usb2_priv *priv =phy_get_drvdata (phy); + +return reset_control_reset (priv->reset);do you have information on whether we should
reset_control_asserthere instead ofreset_control_reset?
No, I don't have it, I haven't fully validated the remove/suspend path yet, but this should at least put the PHY in an unconfigured mode.
Quoted 41 lines
Quoted 41 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +40
-0+} + +/* set_mode is not needed, mode setting is handled via the UTMI bus */ +static const struct phy_ops phy_meson_g12a_usb2_ops = { + .init = phy_meson_g12a_usb2_init, + .exit = phy_meson_g12a_usb2_exit, + .owner =THIS_MODULE , +}; + +static int phy_meson_g12a_usb2_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct phy_provider *phy_provider; +struct resource *res; +struct phy_meson_g12a_usb2_priv *priv; +struct phy *phy; +void __iomem *base; +int ret; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + priv->dev = dev; +platform_set_drvdata (pdev, priv); + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + priv->regmap =devm_regmap_init_mmio (dev, base, + &phy_meson_g12a_usb2_regmap_conf); +if (IS_ERR (priv->regmap)) +return PTR_ERR (priv->regmap); + + priv->clk =devm_clk_get (dev,"xtal" ); +if (IS_ERR (priv->clk)) +return PTR_ERR (priv->clk); +
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 152
Quoted 5 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +5
-0+ priv->reset =devm_reset_control_get (dev,"phy" ); +if (IS_ERR (priv->reset)) +return PTR_ERR (priv->reset); + + ret =reset_control_deassert (priv->reset);should we move this to
phy_meson_g12a_usb2_init(which currently usesreset_control_reset)?
then we could also usereset_control_assertinphy_meson_g12a_usb2_exit
Maybe it would be better, indeed.
Quoted 9 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 160
Quoted 9 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +8
-0+if (ret) +return ret; + + phy =devm_phy_create (dev,NULL , &phy_meson_g12a_usb2_ops); +if (IS_ERR (phy)) { + ret =PTR_ERR (phy); +if (ret != -EPROBE_DEFER ) +dev_err (dev,"failed to create PHY\n" );
Quoted 5 lines
phy-core only returns
EPROBE_DEFERin case the phy-supply is not ready yet. we won't need a phy-supply (at least as far as I know, if we do then please document this in the dt-bindings patch). for USB VBUS dwc2 support the "vbus-supply" property which we should use instead. I leave it up to you to decide whether the check makes sense
It's always better to handle these return cases, better to leave it.
Quoted 23 lines
Quoted 23 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +22
-0+return ret; + } + +phy_set_bus_width (phy,8 ); +phy_set_drvdata (phy, priv); + + phy_provider =devm_of_phy_provider_register (dev, of_phy_simple_xlate); + +return PTR_ERR_OR_ZERO (phy_provider); +} + +static const struct of_device_id phy_meson_g12a_usb2_of_match[] = { + { .compatible ="amlogic,g12a-usb2-phy" , }, + { }, +}; +MODULE_DEVICE_TABLE (of, phy_meson_g12a_usb2_of_match); + +static struct platform_driver phy_meson_g12a_usb2_driver = { + .probe = phy_meson_g12a_usb2_probe, + .driver = { + .name ="phy-meson-g12a-usb2" , + .of_match_table = phy_meson_g12a_usb2_of_match,
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 188
Quoted 5 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +5
-0+ }, +}; +module_platform_driver (phy_meson_g12a_usb2_driver); + +MODULE_AUTHOR ("Martin Blumenstingl <[email protected]>" );I haven't contributed any of the relevant code to this driver (I assume you took one of our existing Amlogic PHY drivers as skeleton?). it's up to you whether you want to keep me in here
Yep it's for the skeleton ! No harm to keep you in !
Quoted 5 lines
Regards
Martin
Thanks,
Neil
Martin Blumenstingl
reviewerRe: [PATCH 6/8] phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
In reply to Neil ArmstrongHi Neil,
Quoted 22 lines · Neil Armstrong
This adds support for the shared USB3 + PCIE PHY found in the Amlogic G12A SoC Family.
It 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.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/phy/amlogic/Kconfig | 12 + drivers/phy/amlogic/Makefile | 1 + .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 414 ++++++++++++++++++ 3 files changed, 427 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.cdrivers/phy/amlogic/Kconfig +0
-0
drivers/phy/amlogic/Kconfig config PHY_MESON_G12A_USB2 · line 53
Quoted 6 lines
drivers/phy/amlogic/Kconfig +3
-0@@ -48,3 +48,15 @@ config PHY_MESON_G12A_USB2 Enable this to support the Meson USB2 PHYs found in Meson G12A SoCs. If unsure, say N. + +config PHY_MESON_G12A_USB3_PCIE + tristate "Meson G12A USB3+PCIE Combo PHY drivers"
nit-pick: s/drivers/driver/
Quoted 24 lines
drivers/phy/amlogic/Kconfig +9
-0+ default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + depends on USB_SUPPORT + select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB3 + PCIE Combi PHY found + in Meson G12A SoCs. + If unsure, say N.drivers/phy/amlogic/Makefile +1
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB2) += phy-meson-gxl-usb2.o obj-$(CONFIG_PHY_MESON_G12A_USB2) += phy-meson-g12a-usb2.o obj-$(CONFIG_PHY_MESON_GXL_USB3) += phy-meson-gxl-usb3.o +obj-$(CONFIG_PHY_MESON_G12A_USB3_PCIE) += phy-meson-g12a-usb3-pcie.odrivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +0
-0@@ -0,0 +1,414 @@
[...]
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +8
-0+static int phy_g12a_usb3_init (struct phy *phy) +{ +struct phy_g12a_usb3_pcie_priv *priv =phy_get_drvdata (phy); +int data, ret; + +/* Switch PHY to USB3 */ + regmap_update_bits(priv->regmap, PHY_R0, + PHY_R0_PCIE_USB3_SWITCH,
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 211
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +10
-0+ PHY_R0_PCIE_USB3_SWITCH); + +/* +* WORKAROUND: There is SSPHY suspend bug due to +* which USB enumerates +* in HS mode instead of SS mode. Workaround it by asserting +* LANE0.TX_ALT_BLOCK.EN_ALT_BUS to enable TX to use alt bus +* mode +*/ + ret =regmap_update_bits (priv->regmap_cr,0x102d ,BIT (7 ),BIT (7 ));
does the datasheet have names for these registers / bits? it if does then it would be great if you could introduce #defines for them
Quoted 38 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +38
-0+if (ret) +return ret; + + ret =regmap_update_bits (priv->regmap_cr,0x1010 ,0xff0 ,20 ); +if (ret) +return ret; + +/* +* Fix RX Equalization setting as follows +* LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0 +* LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1 +* LANE0.RX_OVRD_IN_HI.RX_EQ set to 3 +* LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1 +*/ + ret =regmap_read (priv->regmap_cr,0x1006 , &data); +if (ret) +return ret; + + data &= ~BIT (6 ); + data |=BIT (7 ); + data &= ~(0x7 <<8 ); + data |= (0x3 <<8 ); + data |= (1 <<11 ); + ret =regmap_write (priv->regmap_cr,0x1006 , data); +if (ret) +return ret; + +/* +* Set EQ and TX launch amplitudes as follows +* LANE0.TX_OVRD_DRV_LO.PREEMPH set to 22 +* LANE0.TX_OVRD_DRV_LO.AMPLITUDE set to 127 +* LANE0.TX_OVRD_DRV_LO.EN set to 1. +*/ + ret =regmap_read (priv->regmap_cr,0x1002 , &data); +if (ret) +return ret; + + data &= ~0x3f80 ;
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 259
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +10
-0+ data |= (0x16 <<7 ); + data &= ~0x7f ; + data |= (0x7f |BIT (14 )); + ret =regmap_write (priv->regmap_cr,0x1002 , data); +if (ret) +return ret; + +/* +* MPLL_LOOP_CTL.PROP_CNTRL = 8 +*/
why a multi-line comment here? "Switch PHY to USB3" above uses a single-line comment
Quoted 22 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +22
-0+ ret =regmap_update_bits (priv->regmap_cr,0x30 ,0xf <<4 ,8 <<4 ); +if (ret) +return ret; + +regmap_update_bits (priv->regmap,PHY_R2 , +PHY_R2_PHY_TX_VBOOST_LVL , +FIELD_PREP (PHY_R2_PHY_TX_VBOOST_LVL ,0x4 )); + +regmap_update_bits (priv->regmap,PHY_R1 , +PHY_R1_PHY_LOS_BIAS |PHY_R1_PHY_LOS_LEVEL , +FIELD_PREP (PHY_R1_PHY_LOS_BIAS ,4 ) | +FIELD_PREP (PHY_R1_PHY_LOS_LEVEL ,9 )); + +return 0 ; +} + +static int phy_g12a_usb3_pcie_init (struct phy *phy) +{ +struct phy_g12a_usb3_pcie_priv *priv =phy_get_drvdata (phy); +int ret; + + ret =reset_control_reset (priv->reset);
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 291
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +10
-0+if (ret) +return ret; + +if (priv->mode ==PHY_TYPE_USB3 ) +return phy_g12a_usb3_init (phy); + +/* Power UP PCIE */ +regmap_update_bits (priv->regmap,PHY_R0 , +PHY_R0_PCIE_POWER_STATE , +FIELD_PREP (PHY_R0_PCIE_POWER_STATE ,0x1c ));
do we also need this for USB mode?
also do we need to change the PHY_R2 register values (PHY_R2_PHY_TX_VBOOST_LVL for example) for PCIe, for example if the bootloader initialized the PHY in USB3 mode while the board actually exposes a PCIe port?
Regards
Martin
Martin Blumenstingl
reviewerRe: [PATCH 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
In reply to Neil ArmstrongHi Neil,
On Tue, Feb 12, 2019 at 4:15 PM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 39 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +39
-0+ +Example device nodes: + usb: usb@ffe09000 { + compatible = "amlogic,meson-g12a-usb-ctrl"; + reg = <0x0 0xffe09000 0x0 0xa0>; + interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + clocks = <&clkc CLKID_USB>; + clock-names = "usb"; + resets = <&reset RESET_USB>; + reset-names = "usb"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB2 Port 0 */ + usb20: port@0 { + reg = <0>; + phys = <&usb2_phy0>; + }; + + /* USB2 Port 1 */ + usb21: port@1 { + reg = <1>; + phys = <&usb2_phy1>; + }; + + /* USB3 Port 0 */ + usb3: port@4 { + reg = <4>; + phys = <&usb3_pcie_phy PHY_TYPE_USB3>; + }; + }; + + dwc2: usb@ff400000 {
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 141
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ compatible = "amlogic,meson-g12a-usb", "snps,dwc2"; + reg = <0x0 0xff400000 0x0 0x40000>; + interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc CLKID_USB1_DDR_BRIDGE>; + clock-names = "ddr"; + dr_mode = "peripheral"; + g-rx-fifo-size = <192>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128 128 16 16 16>; + };
you suggested (off-list) that the OTG capable PHY should be passed to the dwc2 instance
I'm aware that this is an example - could you please still add it for consistency?
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 150
Quoted 9 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +9
-0+ + dwc3: dwc3@ff500000 { + compatible = "snps,dwc3"; + reg = <0x0 0xff500000 0x0 0x100000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + dr_mode = "host"; + snps,dis_u2_susphy_quirk; + snps,quirk-frame-length-adjustment; + };
maybe the phys should also be passed to the dwc3 instance?
Regards
Martin
Martin Blumenstingl
reviewerRe: [PATCH 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
In reply to Neil ArmstrongHi Neil,
thank you for working on this!
I have few questions and comments below, but overall it looks good :)
Quoted 10 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.
Quoted 6 lines
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.
The PHYs are childen of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
my initial impression is: "if we pass the PHYs [via device-tree] to the dwc2 and dwc3 controllers then we can simplify the suspend management here in the USBCTRL driver".
I assume there's a catch so it please add an explanation why it's not possible.
Quoted 155 lines
The drivers collects the mode of each PHY and determine which PHY is to be routed between the DWC2 and DWC3 controllers.
This drivers supports the on-probe setup of the OTG mode, and manually via a debugfs interface. The IRQ mode change detect is yet to be added in a future patchset, mainly due to lack of hardware to validate on.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/usb/dwc3/Kconfig | 9 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 650 +++++++++++++++++++++++++++++ 3 files changed, 660 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.cdrivers/usb/dwc3/Kconfig +9
-0@@ -93,6 +93,15 @@ config USB_DWC3_KEYSTONE Support of USB2/3 functionality in TI Keystone2 platforms. Say 'Y' or 'M' here if you have one such device +config USB_DWC3_MESON_G12A + tristate "Amlogic Meson G12A Platforms" + depends on OF && COMMON_CLK + depends on ARCH_MESON || COMPILE_TEST + default USB_DWC3 + help + Support USB2/3 functionality in Amlogic G12A platforms. + Say 'Y' or 'M' if you have one such device. + config USB_DWC3_OF_SIMPLE tristate "Generic OF Simple Glue Layer" depends on OF && COMMON_CLKdrivers/usb/dwc3/Makefile +1
-0@@ -47,6 +47,7 @@ obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o obj-$(CONFIG_USB_DWC3_HAPS) += dwc3-haps.o obj-$(CONFIG_USB_DWC3_KEYSTONE) += dwc3-keystone.o +obj-$(CONFIG_USB_DWC3_MESON_G12A) += dwc3-meson-g12a.o obj-$(CONFIG_USB_DWC3_OF_SIMPLE) += dwc3-of-simple.o obj-$(CONFIG_USB_DWC3_ST) += dwc3-st.o obj-$(CONFIG_USB_DWC3_QCOM) += dwc3-qcom.odrivers/usb/dwc3/dwc3-meson-g12a.c new file +102
-0@@ -0,0 +1,650 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* USB Glue for Amlogic G12A SoCs +* +* Copyright (c) 2019 BayLibre, SAS +* Author: Neil Armstrong <[email protected]> +*/ + +/* +* The USB is organized with a glue around the DWC3 Controller IP as : +* - Control registers for each USB2 Ports +* - Control registers for the USB PHY layer +* - SuperSpeed PHY can be enabled only if port is used +* +* TOFIX: +* - Add dynamic OTG switching with ID change interrupt +*/ + +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/dma-mapping.h> +#include <linux/clk.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/pm_runtime.h> +#include <linux/regmap.h> +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/reset.h> +#include <linux/of_graph.h> +#include <linux/phy/phy.h> +#include <linux/usb/otg.h> +#include <linux/debugfs.h> + +/* USB Glue Control Registers */ + +#define USB_R0 0x00 +#define USB_R0_P30_LANE0_TX2RX_LOOPBACK BIT(17) +#define USB_R0_P30_LANE0_EXT_PCLK_REQ BIT(18) +#define USB_R0_P30_PCS_RX_LOS_MASK_VAL_MASK GENMASK(28, 19) +#define USB_R0_U2D_SS_SCALEDOWN_MODE_MASK GENMASK(30, 29) +#define USB_R0_U2D_ACT BIT(31) + +#define USB_R1 0x04 +#define USB_R1_U3H_BIGENDIAN_GS BIT(0) +#define USB_R1_U3H_PME_ENABLE BIT(1) +#define USB_R1_U3H_HUB_PORT_OVERCURRENT_MASK GENMASK(4, 2) +#define USB_R1_U3H_HUB_PORT_PERM_ATTACH_MASK GENMASK(9, 7) +#define USB_R1_U3H_HOST_U2_PORT_DISABLE_MASK GENMASK(13, 12) +#define USB_R1_U3H_HOST_U3_PORT_DISABLE BIT(16) +#define USB_R1_U3H_HOST_PORT_POWER_CONTROL_PRESENT BIT(17) +#define USB_R1_U3H_HOST_MSI_ENABLE BIT(18) +#define USB_R1_U3H_FLADJ_30MHZ_REG_MASK GENMASK(24, 19) +#define USB_R1_P30_PCS_TX_SWING_FULL_MASK GENMASK(31, 25) + +#define USB_R2 0x08 +#define USB_R2_P30_PCS_TX_DEEMPH_3P5DB_MASK GENMASK(25, 20) +#define USB_R2_P30_PCS_TX_DEEMPH_6DB_MASK GENMASK(31, 26) + +#define USB_R3 0x0c +#define USB_R3_P30_SSC_ENABLE BIT(0) +#define USB_R3_P30_SSC_RANGE_MASK GENMASK(3, 1) +#define USB_R3_P30_SSC_REF_CLK_SEL_MASK GENMASK(12, 4) +#define USB_R3_P30_REF_SSP_EN BIT(13) + +#define USB_R4 0x10 +#define USB_R4_P21_PORT_RESET_0 BIT(0) +#define USB_R4_P21_SLEEP_M0 BIT(1) +#define USB_R4_MEM_PD_MASK GENMASK(3, 2) +#define USB_R4_P21_ONLY BIT(4) + +#define USB_R5 0x14 +#define USB_R5_ID_DIG_SYNC BIT(0) +#define USB_R5_ID_DIG_REG BIT(1) +#define USB_R5_ID_DIG_CFG_MASK GENMASK(3, 2) +#define USB_R5_ID_DIG_EN_0 BIT(4) +#define USB_R5_ID_DIG_EN_1 BIT(5) +#define USB_R5_ID_DIG_CURR BIT(6) +#define USB_R5_ID_DIG_IRQ BIT(7) +#define USB_R5_ID_DIG_TH_MASK GENMASK(15, 8) +#define USB_R5_ID_DIG_CNT_MASK GENMASK(23, 16) + +/* USB2 Ports Control Registers */ + +#define U2P_R0 0x0 +#define U2P_R0_HOST_DEVICE BIT(0) +#define U2P_R0_POWER_OK BIT(1) +#define U2P_R0_HAST_MODE BIT(2) +#define U2P_R0_POWER_ON_RESET BIT(3) +#define U2P_R0_ID_PULLUP BIT(4) +#define U2P_R0_DRV_VBUS BIT(5) + +#define U2P_R1 0x4 +#define U2P_R1_PHY_READY BIT(0) +#define U2P_R1_ID_DIG BIT(1) +#define U2P_R1_OTG_SESSION_VALID BIT(2) +#define U2P_R1_VBUS_VALID BIT(3) + +#define MAX_PHY 5 +
drivers/usb/dwc3/dwc3-meson-g12a.c line 112
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+#define USB2_MAX_PHY 4 +#define USB3_PHY 4 + +struct dwc3_meson_g12a { +struct device *dev; +struct regmap *regmap; +struct clk *clk; +struct reset_control *reset; +struct phy *phys[5 ]; +enum usb_dr_mode phy_modes[5 ];
use MAX_PHY instead of hardcoded 5 here
have you also considered moving the per-port values into a separate struct struct dwc3_meson_g12a_port?
(I'll get back to this below)
drivers/usb/dwc3/dwc3-meson-g12a.c line 120
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+enum phy_mode otg_phy_mode; +unsigned int usb2_ports; +unsigned int usb3_ports; +struct dentry *root; +}; + +#define U2P_REG_SIZE 0x20 +#define USB_REG_OFFSET 0x80
the USB_Rn registers are always accessed with USB_REG_OFFSET added to their offset except in dwc3_meson_g12a_usb2_init.
can we add 0x80 to all USB_Rn #defines to avoid this?
drivers/usb/dwc3/dwc3-meson-g12a.c line 131
Quoted 11 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +11
-0+ +static void dwc3_meson_g12a_usb2_set_mode (struct dwc3_meson_g12a *priv, +int i,enum usb_dr_mode mode) +{ +switch (mode) { +case USB_DR_MODE_HOST : +case USB_DR_MODE_OTG : +case USB_DR_MODE_UNKNOWN : +regmap_update_bits (priv->regmap,U2P_R0 + (U2P_REG_SIZE * i), +U2P_R0_HOST_DEVICE , +U2P_R0_HOST_DEVICE );
have you considered creating a separate regmap for each USB2 PHY configuration register space?
that separate regmap could also be part of the per-port struct (dwc3_meson_g12a_port)
the result might look like this:
regmap_update_bits(priv->ports[i].regmap, U2P_R0,
U2P_R0_HOST_DEVICE,
U2P_R0_HOST_DEVICE);Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+break ; + +case USB_DR_MODE_PERIPHERAL : +regmap_update_bits (priv->regmap,U2P_R0 + (U2P_REG_SIZE * i), +U2P_R0_HOST_DEVICE ,0 ); +break ; + }
drivers/usb/dwc3/dwc3-meson-g12a.c line 148
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+} + +static int dwc3_meson_g12a_usb2_init (struct dwc3_meson_g12a *priv) +{ +enum usb_dr_mode id_mode; +u32 val; +int i; + +/* Read ID current level */ +regmap_read (priv->regmap,USB_R5 , &val);
do we need to add USB_REG_OFFSET to USB_R5 here or do we need to read USB_R5 from the first USB2 PHY register space?
in case we need to express it as "USB_REG_OFFSET + USB_R5" then I have two suggestions to avoid this kind of issues:
- either add 0x80 to all USB_Rn #defines and to remove USB_REG_OFFSET
- assuming you create a separate regmap for each USB2 PHY
configuration: have a separate regmap for the USB_Rn registers as well
Quoted 60 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +60
-0+if (val &USB_R5_ID_DIG_CURR ) + id_mode =USB_DR_MODE_PERIPHERAL ; +else + id_mode =USB_DR_MODE_HOST ; + +dev_info (priv->dev,"ID mode %s\n" , + id_mode ==USB_DR_MODE_HOST ?"host" :"peripheral" ); + +for (i =0 ; i <USB2_MAX_PHY ; ++i) { +if (!priv->phys[i]) +continue ; + +regmap_update_bits (priv->regmap,U2P_R0 + (U2P_REG_SIZE * i), +U2P_R0_POWER_ON_RESET , +U2P_R0_POWER_ON_RESET ); + +if (priv->phy_modes[i] ==USB_DR_MODE_PERIPHERAL || + (priv->phy_modes[i] ==USB_DR_MODE_OTG && + id_mode ==USB_DR_MODE_PERIPHERAL )) { +dwc3_meson_g12a_usb2_set_mode (priv, i, +USB_DR_MODE_PERIPHERAL ); + +if (priv->phy_modes[i] ==USB_DR_MODE_OTG ) + priv->otg_phy_mode =PHY_MODE_USB_DEVICE ; + }else { +dwc3_meson_g12a_usb2_set_mode (priv, i, +USB_DR_MODE_HOST ); + +if (priv->phy_modes[i] ==USB_DR_MODE_OTG ) + priv->otg_phy_mode =PHY_MODE_USB_HOST ; + } + +regmap_update_bits (priv->regmap,U2P_R0 + (U2P_REG_SIZE * i), +U2P_R0_POWER_ON_RESET ,0 ); + } + +return 0 ; +} + +static void dwc3_meson_g12a_usb3_init (struct dwc3_meson_g12a *priv) +{ +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R3 , +USB_R3_P30_SSC_RANGE_MASK | +USB_R3_P30_REF_SSP_EN , +USB_R3_P30_SSC_ENABLE | +FIELD_PREP (USB_R3_P30_SSC_RANGE_MASK ,2 ) | +USB_R3_P30_REF_SSP_EN ); +udelay (2 ); + +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R2 , +USB_R2_P30_PCS_TX_DEEMPH_3P5DB_MASK , +FIELD_PREP (USB_R2_P30_PCS_TX_DEEMPH_3P5DB_MASK ,0x15 )); + +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R2 , +USB_R2_P30_PCS_TX_DEEMPH_6DB_MASK , +FIELD_PREP (USB_R2_P30_PCS_TX_DEEMPH_6DB_MASK ,0x20 )); + +udelay (2 ); + + regmap_update_bits(priv->regmap, USB_REG_OFFSET + USB_R1,
drivers/usb/dwc3/dwc3-meson-g12a.c line 218
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+USB_R1_U3H_HOST_PORT_POWER_CONTROL_PRESENT , + USB_R1_U3H_HOST_PORT_POWER_CONTROL_PRESENT); + +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R1 , +USB_R1_P30_PCS_TX_SWING_FULL_MASK , +FIELD_PREP (USB_R1_P30_PCS_TX_SWING_FULL_MASK ,127 )); +} + +static void dwc3_meson_g12a_usb_init_mode (struct dwc3_meson_g12a *priv, +bool is_peripheral)
can you please make this consistent with dwc3_meson_g12a_usb2_set_mode which takes enum usb_dr_mode instead of a bool?
also while reading the code the naming of dwc3_meson_g12a_usb2_set_mode and dwc3_meson_g12a_usb_init_mode confused me.
in retrospect dwc3_meson_g12a_usb2_set_mode seems good enough because it indicates that it sets the mode for one one the USB2 ports (or PHYs).dwc3_meson_g12a_usb_init_mode however is not only used for initialization but also for forcing the mode at runtime. I don't have any suggestion for a better name yet
Quoted 116 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +116
-0+{ +if (is_peripheral) { +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R0 , +USB_R0_U2D_ACT ,USB_R0_U2D_ACT ); +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R0 , +USB_R0_U2D_SS_SCALEDOWN_MODE_MASK ,0 ); +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R4 , +USB_R4_P21_SLEEP_M0 ,USB_R4_P21_SLEEP_M0 ); + }else { +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R0 , +USB_R0_U2D_ACT ,0 ); +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R4 , +USB_R4_P21_SLEEP_M0 ,0 ); + } +} + +static int dwc3_meson_g12a_usb_init (struct dwc3_meson_g12a *priv) +{ +int ret; + + ret =dwc3_meson_g12a_usb2_init (priv); +if (ret) +return ret; + +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R1 , +USB_R1_U3H_FLADJ_30MHZ_REG_MASK , +FIELD_PREP (USB_R1_U3H_FLADJ_30MHZ_REG_MASK ,0x20 )); + +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R5 , +USB_R5_ID_DIG_EN_0 , +USB_R5_ID_DIG_EN_0 ); +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R5 , +USB_R5_ID_DIG_EN_1 , +USB_R5_ID_DIG_EN_1 ); +regmap_update_bits (priv->regmap,USB_REG_OFFSET +USB_R5 , +USB_R5_ID_DIG_TH_MASK , +FIELD_PREP (USB_R5_ID_DIG_TH_MASK ,0xff )); + +/* If we have an actual SuperSpeed port, initialize it */ +if (priv->usb3_ports) +dwc3_meson_g12a_usb3_init (priv); + +dwc3_meson_g12a_usb_init_mode (priv, + (priv->otg_phy_mode ==PHY_MODE_USB_DEVICE )); + +return 0 ; +} + +static const struct regmap_config phy_meson_g12a_usb3_regmap_conf = { + .reg_bits =8 , + .val_bits =32 , + .reg_stride =4 , + .max_register =USB_REG_OFFSET +USB_R5 , +}; + +static int dwc3_meson_g12a_get_phys (struct dwc3_meson_g12a *priv) +{ +struct device_node *port, *phy_node; +struct of_phandle_args args; +enum usb_dr_mode mode; +const char *dr_mode; +struct phy *phy; +int ret, i; + +for (i =0 ; i <MAX_PHY ; ++i) { + port =of_graph_get_port_by_id (priv->dev->of_node, i); + +/* Ignore port if not defined or disabled */ +if (!of_device_is_available (port)) { +of_node_put (port); +continue ; + } + +/* Get associated PHY */ + phy =of_phy_get (port,NULL ); +if (IS_ERR (phy)) { +of_node_put (port); + ret =PTR_ERR (phy); + goto err_phy_get; + } + +of_node_put (port); + +/* Get phy dr_mode */ + ret =of_parse_phandle_with_args (port,"phys" ,"#phy-cells" , +0 , &args); +if (ret) { +of_node_put (port); + goto err_phy_get; + } + + phy_node = args.np; + + ret =of_property_read_string (phy_node,"dr_mode" , &dr_mode); +if (ret) { + dr_mode ="unknown" ; + mode =USB_DR_MODE_UNKNOWN ; + }else { +if (!strcmp (dr_mode,"host" )) + mode =USB_DR_MODE_HOST ; +else if (!strcmp (dr_mode,"otg" )) + mode =USB_DR_MODE_OTG ; +else if (!strcmp (dr_mode,"peripheral" )) + mode =USB_DR_MODE_PERIPHERAL ; +else { + mode =USB_DR_MODE_UNKNOWN ; + dr_mode ="unknown" ; + } + } + +dev_info (priv->dev,"port%d: %s mode %s\n" , + i,of_node_full_name (phy_node), dr_mode); + +of_node_put (phy_node); + + priv->phy_modes[i] = mode;
drivers/usb/dwc3/dwc3-meson-g12a.c line 344
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ priv->phys[i] = phy; + +if (i ==USB3_PHY ) + priv->usb3_ports++; +else + priv->usb2_ports++; + } + +dev_info (priv->dev,"usb2 ports: %d\n" , priv->usb2_ports); +dev_info (priv->dev,"usb3 ports: %d\n" , priv->usb3_ports);
nit-pick: USB2 and USB3 (instead of the lower-case variants)?
drivers/usb/dwc3/dwc3-meson-g12a.c line 350
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+ +return 0 ; + +err_phy_get: +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_put is NULL-safe, so you can drop this check
Quoted 46 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +46
-0+phy_put (priv->phys[i]); + +return ret; +} + +static int dwc3_meson_g12a_mode_force_get (void *data,u64 *val) +{ +struct dwc3_meson_g12a *priv = data; + +if (priv->otg_phy_mode ==PHY_MODE_USB_HOST ) + *val =1 ; +else if (priv->otg_phy_mode ==PHY_MODE_USB_DEVICE ) + *val =0 ; +else +return -EINVAL ; + +return 0 ; +} + +static int dwc3_meson_g12a_mode_force_set (void *data,u64 val) +{ +struct dwc3_meson_g12a *priv = data; +int i; + +if ((val && priv->otg_phy_mode ==PHY_MODE_USB_HOST ) || + (!val && priv->otg_phy_mode ==PHY_MODE_USB_DEVICE )) +return 0 ; + +for (i =0 ; i <USB2_MAX_PHY ; ++i) { +if (!priv->phys[i]) +continue ; + +if (priv->phy_modes[i] !=USB_DR_MODE_OTG ) +continue ; + +if (val) { +dev_info (priv->dev,"switching to Host Mode\n" ); + +dwc3_meson_g12a_usb2_set_mode (priv, i, +USB_DR_MODE_HOST ); + +dwc3_meson_g12a_usb_init_mode (priv, false); + + priv->otg_phy_mode =PHY_MODE_USB_HOST ; + }else { +dev_info (priv->dev,"switching to Device Mode\n" );
drivers/usb/dwc3/dwc3-meson-g12a.c line 406
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ +dwc3_meson_g12a_usb2_set_mode (priv, i, +USB_DR_MODE_PERIPHERAL ); + +dwc3_meson_g12a_usb_init_mode (priv, true); + + priv->otg_phy_mode =PHY_MODE_USB_DEVICE ; + } + +return phy_set_mode (priv->phys[i], priv->otg_phy_mode);
none of the G12A USB PHY drivers implements phy_ops.set_mode. do you plan to change that? if not: what's the purpose of calling phy_set_mode?
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ } + +return -EINVAL ; +} + +DEFINE_DEBUGFS_ATTRIBUTE(dwc3_meson_g12a_mode_force_fops, + dwc3_meson_g12a_mode_force_get,
drivers/usb/dwc3/dwc3-meson-g12a.c line 423
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ dwc3_meson_g12a_mode_force_set, "%llu\n"); + +static int dwc3_meson_g12a_otg_id_get (void *data,u64 *val) +{ +struct dwc3_meson_g12a *priv = data; +u32 reg; + +regmap_read (priv->regmap,USB_R5 , ®); + + *val = (reg &USB_R5_ID_DIG_CURR );
"mode_force" returns 0 or 1 while this returns either 0 or 0x40 (bit 6). can you please express it as "!!(reg & USB_R5_ID_DIG_CURR)" to make "otg_id" also return 0 or 1?
drivers/usb/dwc3/dwc3-meson-g12a.c line 431
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+ +return 0 ; +} + +DEFINE_DEBUGFS_ATTRIBUTE (dwc3_meson_g12a_otg_id_fops, + dwc3_meson_g12a_otg_id_get,NULL ,"%llu\n" ); + +/* We provide a DebugFS interface to get the ID value and force OTG switch */
at first I was curious if having one debugfs attribute for the whole USBCTL registers is enough.
my thought was that we may have to expose one attribute per port for example if G12A uses port 1 for OTG, but G12B uses port 2 (this is a theoretical case, I have no documentation that this will happen). only later I noticed that the code already supports this by looking up the PHY with USB_DR_MODE_OTG set.
so a single attribute (together with the dr_mode configuration in the .dts) covers our requirements.
Quoted 66 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +66
-0+static int dwc3_meson_g12a_debugfs_init (struct dwc3_meson_g12a *priv) +{ + priv->root =debugfs_create_dir ("dwc3-meson-g12a" ,NULL ); +if (IS_ERR (priv->root)) +return PTR_ERR (priv->root); + +debugfs_create_file ("mode_force" ,0600 , priv->root, priv, + &dwc3_meson_g12a_mode_force_fops); + +debugfs_create_file ("otg_id" ,0400 , priv->root, priv, + &dwc3_meson_g12a_otg_id_fops); + +return 0 ; +} + +static int dwc3_meson_g12a_probe (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv; +struct device *dev = &pdev->dev; +struct device_node *np = dev->of_node; +void __iomem *base; +struct resource *res; +int ret, i; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + priv->regmap =devm_regmap_init_mmio (dev, base, + &phy_meson_g12a_usb3_regmap_conf); +if (IS_ERR (priv->regmap)) +return PTR_ERR (priv->regmap); + + priv->clk =devm_clk_get (dev,"usb" ); +if (IS_ERR (priv->clk)) +return PTR_ERR (priv->clk); + + ret =clk_prepare_enable (priv->clk); +if (ret) +return ret; + +platform_set_drvdata (pdev, priv); + priv->dev = dev; + + priv->reset =devm_reset_control_get (dev,"usb" ); +if (IS_ERR (priv->reset)) { + ret =PTR_ERR (priv->reset); +dev_err (dev,"failed to get device reset, err=%d\n" , ret); +return ret; + } + + ret =reset_control_reset (priv->reset); +if (ret) +return ret; + + ret =dwc3_meson_g12a_get_phys (priv); +if (ret) +return ret; + +dwc3_meson_g12a_usb_init (priv); +
drivers/usb/dwc3/dwc3-meson-g12a.c line 507
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+/* Init PHYs */ +for (i =0 ; i <MAX_PHY ; ++i) { +if (priv->phys[i]) { + ret =phy_init (priv->phys[i]); +if (ret) + goto err_phys_put; + } + } + +/* Set OTG PHY mode */
none of this PHY drivers implements phy_ops.set_mode. dwc3_meson_g12a_usb_init() above should have taken care of initializing the mode already if I understand the code correctly can you please check if the following block is needed:
Quoted 18 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +18
-0+for (i =0 ; i <MAX_PHY ; ++i) { +if (priv->phys[i] && priv->phy_modes[i] ==USB_DR_MODE_OTG ) { + ret =phy_set_mode (priv->phys[i], priv->otg_phy_mode); +if (ret) + goto err_phys_put; + } + } + + ret =of_platform_populate (np,NULL ,NULL , dev); +if (ret) { +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + + goto err_phys_exit; + } + +pm_runtime_set_active (dev); +pm_runtime_enable (dev);
drivers/usb/dwc3/dwc3-meson-g12a.c line 535
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+pm_runtime_get_sync (dev); + +if (dwc3_meson_g12a_debugfs_init (priv)) +dev_dbg (dev,"Failed to add DebugFS interface\n" ); + +return 0 ; + +err_phys_exit: +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_exit is NULL-safe, so you can drop this check
drivers/usb/dwc3/dwc3-meson-g12a.c line 540
Quoted 5 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +5
-0+phy_exit (priv->phys[i]); + +err_phys_put: +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_put is NULL-safe so you can drop this check
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+phy_put (priv->phys[i]); + +return ret; +} + +static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{
drivers/usb/dwc3/dwc3-meson-g12a.c line 557
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int i; + +debugfs_remove_recursive (priv->root); + +of_platform_depopulate (dev); + +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_exit is NULL-safe, so you can drop this check
drivers/usb/dwc3/dwc3-meson-g12a.c line 540
Quoted 4 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +4
-0+phy_exit (priv->phys[i]); + +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_put is NULL-safe, so you can drop this check
drivers/usb/dwc3/dwc3-meson-g12a.c line 565
Quoted 4 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +4
-0+phy_put (priv->phys[i]); + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk);
the clock is obtained with devm_clk_get - doesn't that automatically call clk_put upon removal?
drivers/usb/dwc3/dwc3-meson-g12a.c line 569
Quoted 4 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +4
-0+ +pm_runtime_disable (dev); +pm_runtime_put_noidle (dev); +pm_runtime_set_suspended (dev);
(I'm new to the runtime PM logic, so the following questions might not make sense)
will this also call dwc3_meson_g12a_runtime_suspend (defined below)? if so: how do we ensure that we don't call clk_disable if we already called clk_disable_unprepare?
Quoted 16 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +16
-0+return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_runtime_suspend (struct device *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); + +clk_disable (priv->clk); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_runtime_resume (struct device *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +
drivers/usb/dwc3/dwc3-meson-g12a.c line 596
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+return clk_enable (priv->clk); +} + +static int __maybe_unused dwc3_meson_g12a_suspend (struct device *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +int i; + +for (i =0 ; i <MAX_PHY ; ++i) +if (priv->phys[i])
phy_exit is NULL-safe, so you can drop this check
Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +9
-0+phy_exit (priv->phys[i]); + +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{
drivers/usb/dwc3/dwc3-meson-g12a.c line 615
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +int i, ret; + +reset_control_deassert (priv->reset); + +dwc3_meson_g12a_usb_init (priv); + +/* Init PHYs */ +for (i =0 ; i <MAX_PHY ; ++i) { +if (priv->phys[i]) {
phy_init is NULL-safe, so you can drop this check
Quoted 39 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +35
-1+ ret =phy_init (priv->phys[i]); +if (ret) +return ret; + } + } + +return 0 ; +} + +static const struct dev_pm_ops dwc3_meson_g12a_dev_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(dwc3_meson_g12a_suspend, dwc3_meson_g12a_resume) +SET_RUNTIME_PM_OPS (dwc3_meson_g12a_runtime_suspend, + dwc3_meson_g12a_runtime_resume,NULL ) +}; + +static const struct of_device_id dwc3_meson_g12a_match[] = { + { .compatible ="amlogic,meson-g12a-usb-ctrl" }, + {/* Sentinel */ } +}; +MODULE_DEVICE_TABLE (of, dwc3_meson_g12a_match); + +static struct platform_driver dwc3_meson_g12a_driver = { + .probe = dwc3_meson_g12a_probe, + .remove = dwc3_meson_g12a_remove, + .driver = { + .name ="dwc3-meson-g12a" , + .of_match_table = dwc3_meson_g12a_match, + .pm = &dwc3_meson_g12a_dev_pm_ops, + }, +}; + +module_platform_driver (dwc3_meson_g12a_driver); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Amlogic Meson G12A USB Glue Layer" ); +MODULE_AUTHOR ("Neil Armstrong <[email protected]>" ); --2.20.1
Quoted 4 lines
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Regards
Martin
Re: [PATCH 1/8] dt-bindings: phy: Add Amlogic G12A USB2 PHY Bindings
In reply to Neil ArmstrongQuoted 8 lines · Neil Armstrong
Add the Amlogic G12A Family USB2 OTG PHY Bindings
Signed-off-by Neil Armstrong <[email protected]>--- .../bindings/phy/meson-g12a-usb2-phy.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt
Re: [PATCH 3/8] dt-bindings: usb: dwc2: Add Amlogic G12A DWC2 Compatible
In reply to Neil ArmstrongQuoted 8 lines · Neil Armstrong
Adds the specific compatible string for the DWC2 IP found in the Amlogic G12A SoC Family.
Signed-off-by Neil Armstrong <[email protected]>--- Documentation/devicetree/bindings/usb/dwc2.txt | 1 + 1 file changed, 1 insertion(+)
Rob Herring
maintainerRe: [PATCH 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
In reply to Neil ArmstrongQuoted 43 lines · Neil Armstrong
Adds the bindings for the Amlogic G12A USB 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.
The PHYs are children of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
The PHY interconnect is handled into ports subnodes, which eases describing which PHY is enabled (like the USB3 shared PHY) and futures layouts on derivatives of the G12A Family.
Signed-off-by Neil Armstrong <[email protected]>--- .../devicetree/bindings/usb/amlogic,dwc3.txt | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+)Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0@@ -40,3 +40,112 @@ Example device nodes: phy-names = "usb2-phy", "usb3-phy"; }; }; + +Amlogic Meson G12A DWC3 USB SoC Controller Glue + +The Amlogic G12A embeds a DWC3 USB IP Core configured for USB2 and USB3 +in host-only mode, and a DWC2 IP Core configured for USB2 peripheral mode +only. + +A glue connects the DWC3 core to USB2 PHYs and optionnaly to an USB3 PHY. + +One of the USB2 PHY can be re-routed in peripheral mode to a DWC2 USB IP.
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 62
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ +The DWC3 Glue controls the PHY routing and power, an interrupt line is +connected to the Glue to serve as OTG ID change detection. + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb-ctrl" +- clocks: a handle for the "USB" clock +- clock-names: must be "usb" +- resets: a handle for the shared "USB" reset line +- reset-names: must be "usb"
-name for a single entry is pointless.
Quoted 43 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +43
-0+- reg: The base address and length of the registers +- interrupts: the interrupt specifier for the OTG detection + +Required child nodes: + +USB Ports are described as child 'port' nodes grouped under a 'ports' node, +with #address-cells, #size-cells specified. + +Each 'port' sub-node identifies a possible USB Port served by an USB PHY +identified by the 'phy' property as decribed in ../phy/phy-bindings.txt + +Each 'port' is identified by a reg property to number the port. + +The following table lists for each supported model the port number +corresponding to each PHY serving a physical USB Port. + + Family Port 0 Port 1 Port 2 Port 3 Port 4 +--------------------------------------------------------------- + G12A USBHOST_A USBOTG_B Reserved Reserved USB3_0 + +A child node must exist to represent the core DWC3 IP block. The name of +the node is not important. The content of the node is defined in dwc3.txt. + +A child node must exist to represent the core DWC2 IP block. The name of +the node is not important. The content of the node is defined in dwc2.txt. + +PHY documentation is provided in the following places: +- Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt +- Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt + + +Example device nodes: + usb: usb@ffe09000 { + compatible = "amlogic,meson-g12a-usb-ctrl"; + reg = <0x0 0xffe09000 0x0 0xa0>; + interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + clocks = <&clkc CLKID_USB>; + clock-names = "usb"; + resets = <&reset RESET_USB>;
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 115
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ reset-names = "usb"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB2 Port 0 */ + usb20: port@0 { + reg = <0>; + phys = <&usb2_phy0>;
'ports' and 'port' are reserved for the graph binding. Don't use it for your own thing.
Can't you just make 'phys' a list using 0 phandle if you need to skip entries.
Quoted 18 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +18
-0+ }; + + /* USB2 Port 1 */ + usb21: port@1 { + reg = <1>; + phys = <&usb2_phy1>; + }; + + /* USB3 Port 0 */ + usb3: port@4 { + reg = <4>; + phys = <&usb3_pcie_phy PHY_TYPE_USB3>; + }; + }; + + dwc2: usb@ff400000 { + compatible = "amlogic,meson-g12a-usb", "snps,dwc2"; + reg = <0x0 0xff400000 0x0 0x40000>;
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 143
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc CLKID_USB1_DDR_BRIDGE>; + clock-names = "ddr"; + dr_mode = "peripheral"; + g-rx-fifo-size = <192>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128 128 16 16 16>; + }; + + dwc3: dwc3@ff500000 {
usb@... or usb3@...
Quoted 11 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +8
-0+ compatible = "snps,dwc3"; + reg = <0x0 0xff500000 0x0 0x100000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + dr_mode = "host"; + snps,dis_u2_susphy_quirk; + snps,quirk-frame-length-adjustment; + }; + };Signature · 1 line
2.20.1
Re: [PATCH 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
Quoted 114 lines · Rob Herring
Quoted 43 lines · Neil Armstrong
Adds the bindings for the Amlogic G12A USB 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.
The PHYs are children of the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
The PHY interconnect is handled into ports subnodes, which eases describing which PHY is enabled (like the USB3 shared PHY) and futures layouts on derivatives of the G12A Family.
Signed-off-by Neil Armstrong <[email protected]>--- .../devicetree/bindings/usb/amlogic,dwc3.txt | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+)Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0@@ -40,3 +40,112 @@ Example device nodes: phy-names = "usb2-phy", "usb3-phy"; }; }; + +Amlogic Meson G12A DWC3 USB SoC Controller Glue + +The Amlogic G12A embeds a DWC3 USB IP Core configured for USB2 and USB3 +in host-only mode, and a DWC2 IP Core configured for USB2 peripheral mode +only. + +A glue connects the DWC3 core to USB2 PHYs and optionnaly to an USB3 PHY. + +One of the USB2 PHY can be re-routed in peripheral mode to a DWC2 USB IP.Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 62
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ +The DWC3 Glue controls the PHY routing and power, an interrupt line is +connected to the Glue to serve as OTG ID change detection. + +Required properties: +- compatible: Should be "amlogic,meson-g12a-usb-ctrl" +- clocks: a handle for the "USB" clock +- clock-names: must be "usb" +- resets: a handle for the shared "USB" reset line +- reset-names: must be "usb"-name for a single entry is pointless.
Quoted 43 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +43
-0+- reg: The base address and length of the registers +- interrupts: the interrupt specifier for the OTG detection + +Required child nodes: + +USB Ports are described as child 'port' nodes grouped under a 'ports' node, +with #address-cells, #size-cells specified. + +Each 'port' sub-node identifies a possible USB Port served by an USB PHY +identified by the 'phy' property as decribed in ../phy/phy-bindings.txt + +Each 'port' is identified by a reg property to number the port. + +The following table lists for each supported model the port number +corresponding to each PHY serving a physical USB Port. + + Family Port 0 Port 1 Port 2 Port 3 Port 4 +--------------------------------------------------------------- + G12A USBHOST_A USBOTG_B Reserved Reserved USB3_0 + +A child node must exist to represent the core DWC3 IP block. The name of +the node is not important. The content of the node is defined in dwc3.txt. + +A child node must exist to represent the core DWC2 IP block. The name of +the node is not important. The content of the node is defined in dwc2.txt. + +PHY documentation is provided in the following places: +- Documentation/devicetree/bindings/phy/meson-g12a-usb2-phy.txt +- Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt + + +Example device nodes: + usb: usb@ffe09000 { + compatible = "amlogic,meson-g12a-usb-ctrl"; + reg = <0x0 0xffe09000 0x0 0xa0>; + interrupts = <GIC_SPI 16 IRQ_TYPE_LEVEL_HIGH>; + #address-cells = <2>; + #size-cells = <2>; + ranges; + + clocks = <&clkc CLKID_USB>; + clock-names = "usb"; + resets = <&reset RESET_USB>;Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 115
Quoted 10 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +10
-0+ reset-names = "usb"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB2 Port 0 */ + usb20: port@0 { + reg = <0>; + phys = <&usb2_phy0>;'ports' and 'port' are reserved for the graph binding. Don't use it for your own thing.
Quoted 2 lines
Can't you just make 'phys' a list using 0 phandle if you need to skip entries.
Yep, finally this would be simpler.
Quoted 23 lines
Quoted 23 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +22
-0+ }; + + /* USB2 Port 1 */ + usb21: port@1 { + reg = <1>; + phys = <&usb2_phy1>; + }; + + /* USB3 Port 0 */ + usb3: port@4 { + reg = <4>; + phys = <&usb3_pcie_phy PHY_TYPE_USB3>; + }; + }; + + dwc2: usb@ff400000 { + compatible = "amlogic,meson-g12a-usb", "snps,dwc2"; + reg = <0x0 0xff400000 0x0 0x40000>; + interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clkc CLKID_USB1_DDR_BRIDGE>; + clock-names = "ddr"; + dr_mode = "peripheral";
Quoted 8 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 143
Quoted 6 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +6
-0+ g-rx-fifo-size = <192>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128 128 16 16 16>; + }; + + dwc3: dwc3@ff500000 {usb@... or usb3@...
Ok
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +8
-0+ compatible = "snps,dwc3"; + reg = <0x0 0xff500000 0x0 0x100000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + dr_mode = "host"; + snps,dis_u2_susphy_quirk; + snps,quirk-frame-length-adjustment; + }; + };Signature · 1 line
2.20.1
Martin Blumenstingl
reviewerRe: [PATCH 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
In reply to Martin BlumenstinglHi Neil,
Quoted 6 lines
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+static int dwc3_meson_g12a_debugfs_init (struct dwc3_meson_g12a *priv) +{ + priv->root =debugfs_create_dir ("dwc3-meson-g12a" ,NULL ); +if (IS_ERR (priv->root)) +return PTR_ERR (priv->root); +
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 445
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+debugfs_create_file ("mode_force" ,0600 , priv->root, priv, + &dwc3_meson_g12a_mode_force_fops); + +debugfs_create_file ("otg_id" ,0400 , priv->root, priv, + &dwc3_meson_g12a_otg_id_fops); + +return 0 ; +}
I just stumbled across the "USB role switch framework", see [0] it seems to provide a userspace API as well and two in-kernel drivers are using this framework already (drivers/usb/gadget/udc/renesas_usb3.c, drivers/usb/roles/intel-xhci-usb-role-switch.c)
[0] https://elixir.bootlin.com/linux/v5.0-rc8/source/drivers/usb/roles/class.c#L246
Re: [PATCH 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
Hi,
Quoted 13 lines · Martin Blumenstingl
Hi Neil,
Quoted 11 lines
Quoted 11 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +11
-0+static int dwc3_meson_g12a_debugfs_init (struct dwc3_meson_g12a *priv) +{ + priv->root =debugfs_create_dir ("dwc3-meson-g12a" ,NULL ); +if (IS_ERR (priv->root)) +return PTR_ERR (priv->root); + +debugfs_create_file ("mode_force" ,0600 , priv->root, priv, + &dwc3_meson_g12a_mode_force_fops); + +debugfs_create_file ("otg_id" ,0400 , priv->root, priv, + &dwc3_meson_g12a_otg_id_fops);
Quoted 8 lines
Quoted 3 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 186
Quoted 3 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +3
-0+ +return 0 ; +}I just stumbled across the "USB role switch framework", see [0] it seems to provide a userspace API as well and two in-kernel drivers are using this framework already (
drivers/usb/gadget/udc/renesas_usb3.c,drivers/usb/roles/intel-xhci-usb-role-switch.c)
Just added support for it, works perfectly :-)
Neil
RE: [PATCH 7/8] usb: dwc2: Add Amlogic G12A DWC2 Params
In reply to Neil ArmstrongQuoted 5 lines
This patchs sets the params for the DWC2 Controller found in the Amlogic G12A SoC family.
It mainly sets the settings reported incorrect by the driver, leaving the remaining detected automatically by the driver and provided by the DT node.
Signed-off-by Neil Armstrong <[email protected]>
Quoted 32 lines
--- drivers/usb/dwc2/params.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/usb/dwc2/params.c +11
-1@@ -121,6 +121,16 @@ static void dwc2_set_amlogic_params(struct dwc2_hsotg *hsotg) p->power_down =DWC2_POWER_DOWN_PARAM_NONE ; } +static void dwc2_set_amlogic_g12a_params (struct dwc2_hsotg *hsotg) { +struct dwc2_core_params *p = &hsotg->params; + + p->lpm = false; + p->lpm_clock_gating = false; + p->besl = false; + p->hird_threshold_en = false; +} +static void dwc2_set_amcc_params (struct dwc2_hsotg *hsotg) { struct dwc2_core_params *p = &hsotg->params; @@ -167,6 +177,8 @@ const struct of_device_id dwc2_of_match_table[] = { .data = dwc2_set_amlogic_params }, { .compatible = "amlogic,meson-gxbb-usb", .data = dwc2_set_amlogic_params }, + { .compatible = "amlogic,meson-g12a-usb", + .data = dwc2_set_amlogic_g12a_params }, { .compatible = "amcc,dwc-otg", .data = dwc2_set_amcc_params }, { .compatible = "st,stm32f4x9-fsotg", .data = dwc2_set_stm32f4x9_fsotg_params }, --2.20.1