arm64: meson: Add support for USB on Amlogic G12A
Subsystems (6)
v2 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.
This drivers supports the on-probe setup of the OTG mode, and manually via the USB Role interface. The IRQ mode change detect is yet to be added in a future patchset, mainly due to lack of hardware to validate on.
Changes since v1 at [0]:
- USB2 PHY Bindings: collected tags and updated commit log
- USB3/PCIE PHY Bindings: collected tag and updated reset list
- DWC2 Compatible: collected tags
- DWC3 Glue Bindings:
- removed clock-names and reset-names for single entries
- removed ports graph for PHYs and replaced by phys list with phy-names
- added dr_mode and optional vbus-supply
- fixed example
- USB2 PHY Driver: removed USB_SUPPORT and otg.h include
- USB3/PCIE PHY Driver: removed USB_SUPPORT, fixed comment and unused reg variable
- USB Glue Driver:
- Moved debugfs I/F to USB_ROLE_SWITCH framework
- Integrated USB Glue Control Registers offset
- Removed of graph parsing to use devm_phy_optional_get()
- Fixed PHY mode handling and OTG switching
- Simplified PHY calls by removing the NULL test
- Added optional vbus regulator handling
[1] https://lkml.kernel.org/r/[email protected]
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 | 22 + .../devicetree/bindings/usb/amlogic,dwc3.txt | 88 +++ .../devicetree/bindings/usb/dwc2.txt | 1 + drivers/phy/amlogic/Kconfig | 22 + drivers/phy/amlogic/Makefile | 2 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 190 ++++++ .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 411 ++++++++++++ drivers/usb/dwc2/params.c | 12 + drivers/usb/dwc3/Kconfig | 10 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 601 ++++++++++++++++++ 12 files changed, 1382 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
PATCH v2 1/8 dt-bindings: phy: Add Amlogic G12A USB2 PHY Bindings
Add the Amlogic G12A Family USB2 OTG PHY Bindings
The PHY can work in host or peripheral modes depending on it's position. Configuration of the mode is part of the USBCTRL registers which are outside of the PHY registers.
--- .../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 v2 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 | 22 +++++++++++++++++++ 1 file changed, 22 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 +22 -0
@@ -0,0 +1,22 @@ +* 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 +- reset-names: must be "phy" + +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_PHY>; + reset-names = "phy"; + #phy-cells = <1>; + };
Signature · 1 line
2.20.1
Martin Blumenstingl
reviewerRe: [PATCH v2 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
Hi Neil,
Quoted 19 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]>Reviewed-by Martin Blumenstingl <[email protected]>--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 22 +++++++++++++++++++ 1 file changed, 22 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 +1
-0@@ -0,0 +1,22 @@ +* Amlogic G12A USB3 + PCIE Combo PHY binding
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt line 11
Quoted 10 lines
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +10
-0+ +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 +- reset-names: must be "phy"
one question on the resets:
- in v1 you had three reset lines: RESET_PCIE_CTRL_A, RESET_PCIE_PHY, RESET_PCIE_APB
- in v2 you only have the "phy" reset line.
is this because the other two are connected to the PCIe controller (Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt) instead of the PHY?
Regards
Martin
Re: [PATCH v2 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
Quoted 31 lines · Martin Blumenstingl
Hi Neil,
Quoted 28 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]>Reviewed-by Martin Blumenstingl <[email protected]>--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 22 +++++++++++++++++++ 1 file changed, 22 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,22 @@ +* 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
Quoted 8 lines
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt line 11
Quoted 1 line
Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt new file +1
-0+- reset-names: must be "phy"one question on the resets:
- in v1 you had three reset lines:RESET_PCIE_CTRL_A,RESET_PCIE_PHY,RESET_PCIE_APB
- in v2 you only have the "phy" reset line.
is this because the other two are connected to the PCIe controller (Documentation/devicetree/bindings/pci/amlogic,meson-pcie.txt) instead of the PHY?
Indeed, it was wrong, only the RESET_PCIE_PHY is needed for the PHY
Neil
Quoted 5 lines
Regards
Martin
Re: [PATCH v2 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings
In reply to Neil ArmstrongQuoted 11 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]>Reviewed-by Martin Blumenstingl <[email protected]>--- .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt
PATCH v2 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 v2 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 phandles are passed to the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
--- .../devicetree/bindings/usb/amlogic,dwc3.txt | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+)
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +88 -0
@@ -40,3 +40,91 @@ 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 +- resets: a handle for the shared "USB" reset line +- reg: The base address and length of the registers +- interrupts: the interrupt specifier for the OTG detection +- phys: handle to used PHYs on the system + - a <0> phandle can be used if a PHY is not used +- phy-names: names of the used PHYs on the system : + - "usb2-phy0" for USB2 PHY0 if USBHOST_A port is used + - "usb2-phy1" for USB2 PHY1 if USBOTG_B port is used + - "usb3-phy0" for USB3 PHY if USB3_0 is used +- dr_mode: should be "host", "peripheral", or "otg" depending on + the usage and configuration of the OTG Capable port. + - "host" and "peripheral" means a fixed Host or Device only connection + - "otg" means the port can be used as both Host or Device and + be switched automatically using the OTG ID pin. + +Optional properties: +- vbus-supply: should be a phandle to the regulator controlling the VBUS + power supply when used in OTG switchable mode + +Required child nodes: + +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>; + resets = <&reset RESET_USB>; + + dr_mode = "otg"; + + phys = <&usb2_phy0>, <&usb2_phy1>, + <&usb3_pcie_phy PHY_TYPE_USB3>; + phy-names = "usb2-phy0", "usb2-phy1", "usb3-phy0"; + + 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"; + phys = <&usb2_phy1>; + dr_mode = "peripheral"; + g-rx-fifo-size = <192>; + g-np-tx-fifo-size = <128>; + g-tx-fifo-size = <128 128 16 16 16>; + }; + + dwc3: usb@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
Re: [PATCH v2 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
Hi Neil,
Quoted 10 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.
Quoted 8 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 phandles are passed to the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
Signed-off-by Neil Armstrong <[email protected]>
[...]
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 129
Quoted 8 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +8
-0+ dwc3: usb@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; + };
in v1 of the patch I asked whether we should pass the PHYs which are connected to the dwc3 controller here as well (instead of only passing them to the USBCTRL node).
we can still do this later on, the important part is: USBCTRL interfaces with the PHYs -> that is already part of the binding.
Regards
Martin
Re: [PATCH v2 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
Quoted 32 lines · Martin Blumenstingl
Hi Neil,
Quoted 10 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.Quoted 8 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 phandles are passed to the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
Signed-off-by Neil Armstrong <[email protected]>Reviewed-by Martin Blumenstingl <[email protected]>[...]
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt Example device nodes: · line 129
Quoted 8 lines
Documentation/devicetree/bindings/usb/amlogic,dwc3.txt +8
-0+ dwc3: usb@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; + };
Quoted 5 lines
in v1 of the patch I asked whether we should pass the PHYs which are connected to the dwc3 controller here as well (instead of only passing them to the USBCTRL node).
we can still do this later on, the important part is: USBCTRL interfaces with the PHYs -> that is already part of the binding.
Indeed, it's not part of this binding doc, and we can do it if needed. But since the OTG setup is not handled by DWC3, there is no real use.
Neil
Quoted 5 lines
Regards
Martin
Re: [PATCH v2 4/8] dt-bindings: usb: dwc3: Add Amlogic G12A DWC3 Glue Bindings
In reply to Neil ArmstrongQuoted 13 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.
Quoted 8 lines
The PHYs phandles are passed to the Glue node since the Glue controls the interface with the PHY, not the DWC3 controller.
Signed-off-by Neil Armstrong <[email protected]>--- .../devicetree/bindings/usb/amlogic,dwc3.txt | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+)
PATCH v2 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 | 11 ++ drivers/phy/amlogic/Makefile | 1 + drivers/phy/amlogic/phy-meson-g12a-usb2.c | 190 ++++++++++++++++++++++ 3 files changed, 202 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.c
drivers/phy/amlogic/Kconfig +11 -0
@@ -36,3 +36,14 @@ 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 driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + 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 +190 -0
190 lines not on this page · raw message
Martin Blumenstingl
reviewerRe: [PATCH v2 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver
Hi Neil,
On Mon, Mar 4, 2019 at 11:40 AM Neil Armstrong <[email protected]> wrote:
[...]
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>
there's a "regmap" include right above. this driver doesn't use syscon so this include can be dropped
[...]
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 106
Quoted 5 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +5
-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 know whether we should reset_control_assert here instead of reset_control_reset?
the probe function below already uses reset_control_deassert, so the current implementation is inconsistent. in v1 you replied with "Maybe it would be better, indeed." - if there's a reason why reset_control_assert doesn't work here then I would like to have a comment stating why
Apart from these two this is looking good!
Human readable BIT/GENMASK #defines for the register bits would be nice, but I'm not sure if you have the details to add these.
Regards
Martin
Re: [PATCH v2 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver
Quoted 4 lines · Martin Blumenstingl
Hi Neil,
On Mon, Mar 4, 2019 at 11:40 AM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 9 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> there's a "regmap" include right above. this driver doesn't use syscon so this include can be dropped
Forgot this one...
Quoted 14 lines
[...]
drivers/phy/amlogic/phy-meson-g12a-usb2.c line 106
Quoted 5 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +5
-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 know whether we should
reset_control_asserthere instead ofreset_control_reset?
the probe function below already usesreset_control_deassert, so the current implementation is inconsistent. in v1 you replied with "Maybe it would be better, indeed." - if there's a reason whyreset_control_assertdoesn't work here then I would like to have a comment stating why
It's not clear yet, I implemented it safe here since in my tests, when I left the USB2 PHYs resetted, it was kept resetted on a soft system reset and the ROM was not able to setup the PHY correctly.
So maybe it's wrong for power management, it's safer to simply to keep the PHYs unresetted when unused.
Quoted 4 lines
Apart from these two this is looking good!
Human readable BIT/GENMASK #defines for the register bits would be nice, but I'm not sure if you have the details to add these.
I have the registers set in the doc, but it's much longer than copying the registers structs from the vendor kernel, so I postponed it.
I'll try adding these, but for now it's low priority unless the PHY maintainer asks for them.
Neil
Quoted 5 lines
Regards
Martin
Re: [PATCH v2 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver
Hi Neil,
On Thu, Mar 7, 2019 at 9:41 AM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/phy/amlogic/phy-meson-g12a-usb2.c new file +4
-0+static int phy_meson_g12a_usb2_exit (struct phy *phy) +{ +struct phy_meson_g12a_usb2_priv *priv =phy_get_drvdata (phy); +Quoted 8 lines
Quoted 1 line
+ return
reset_control_reset(priv->reset);do you know whether we should
reset_control_asserthere instead ofreset_control_reset?
the probe function below already usesreset_control_deassert, so the current implementation is inconsistent. in v1 you replied with "Maybe it would be better, indeed." - if there's a reason whyreset_control_assertdoesn't work here then I would like to have a comment stating why
Quoted 3 lines
It's not clear yet, I implemented it safe here since in my tests, when I left the USB2 PHYs resetted, it was kept resetted on a soft system reset and the ROM was not able to setup the PHY correctly.
that's probably why Amlogic's kernel also uses a reset pulse
Quoted 2 lines
So maybe it's wrong for power management, it's safer to simply to keep the PHYs unresetted when unused.
if you re-send this patch anyways (to clean up the #include) can you please add a comment with the explanation from above?
Quoted 9 lines
Quoted 3 lines
Apart from these two this is looking good!
Human readable BIT/GENMASK #defines for the register bits would be nice, but I'm not sure if you have the details to add these.I have the registers set in the doc, but it's much longer than copying the registers structs from the vendor kernel, so I postponed it.
I'll try adding these, but for now it's low priority unless the PHY maintainer asks for them.
ACK, it's not high priority, so it's fine for now
with the #include changed and a comment for the reset pulse you can add my:
Regards
Martin
PATCH v2 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 | 11 + drivers/phy/amlogic/Makefile | 1 + .../phy/amlogic/phy-meson-g12a-usb3-pcie.c | 411 ++++++++++++++++++ 3 files changed, 423 insertions(+) create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c
drivers/phy/amlogic/Kconfig +11 -0
@@ -47,3 +47,14 @@ 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 driver" + default ARCH_MESON + depends on OF && (ARCH_MESON || COMPILE_TEST) + select GENERIC_PHY + select REGMAP_MMIO + help + Enable this to support the Meson USB3 + PCIE Combo 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 +411 -0
411 lines not on this page · raw message
Martin Blumenstingl
reviewerRe: [PATCH v2 6/8] phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
Hi Neil,
On Mon, Mar 4, 2019 at 11:40 AM Neil Armstrong <[email protected]> wrote:
[...]
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 202
Quoted 9 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +9
-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 , +PHY_R0_PCIE_USB3_SWITCH );
does this automatically clear PHY_R0_PCIE_POWER_STATE (in case the bootloader incorrectly set that)?
[...]
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +6
-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 289
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 ));
similar to my question above: does this automatically clear PHY_R0_PCIE_USB3_SWITCH (in case the bootloader incorrectly set that)?
Apart from these two questions this looks good to me!
Regards
Martin
Re: [PATCH v2 6/8] phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
Quoted 4 lines · Martin Blumenstingl
Hi Neil,
On Mon, Mar 4, 2019 at 11:40 AM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 11 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 202
Quoted 9 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +9
-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 , +PHY_R0_PCIE_USB3_SWITCH );does this automatically clear
PHY_R0_PCIE_POWER_STATE(in case the bootloader incorrectly set that)?
Don't forget it's a static configuration, on the board, only USB3 XOR PCIE will be available, if the bootloader sets this and the kernel uses USB3, or the reverse, one of them is wrong.
Quoted 12 lines
[...]
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +10
-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); +if (ret) +return ret; + +if (priv->mode ==PHY_TYPE_USB3 )
Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 289
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +6
-0+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 ));similar to my question above: does this automatically clear
PHY_R0_PCIE_USB3_SWITCH(in case the bootloader incorrectly set that)?
Same answer, but I'll investigate to have more details on this register.
It's more an implementation issue, we can change it when PCIe is enabled on this platform.
Quoted 2 lines
Apart from these two questions this looks good to me!
Thanks for the review !
Neil
Quoted 5 lines
Regards
Martin
Re: [PATCH v2 6/8] phy: amlogic: Add Amlogic G12A USB3 + PCIE Combo PHY Driver
Hi Neil,
Quoted 18 lines · Neil Armstrong
Quoted 4 lines · Martin Blumenstingl
Hi Neil,
On Mon, Mar 4, 2019 at 11:40 AM Neil Armstrong <[email protected]> wrote:
[...]Quoted 11 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 202
Quoted 9 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +9
-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 , +PHY_R0_PCIE_USB3_SWITCH );does this automatically clear
PHY_R0_PCIE_POWER_STATE(in case the bootloader incorrectly set that)?
Quoted 3 lines
Don't forget it's a static configuration, on the board, only USB3 XOR PCIE will be available, if the bootloader sets this and the kernel uses USB3, or the reverse, one of them is wrong.
I'm specifically asking is because we've seen various GXL/GXM boards with a bootloader which is configured for the wrong PHY interface (RGMII != RMII)
Quoted 21 lines
Quoted 12 lines
[...]
Quoted 10 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +10
-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); +if (ret) +return ret; + +if (priv->mode ==PHY_TYPE_USB3 )Quoted 8 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c line 289
Quoted 6 lines
drivers/phy/amlogic/phy-meson-g12a-usb3-pcie.c new file +6
-0+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 ));similar to my question above: does this automatically clear
PHY_R0_PCIE_USB3_SWITCH(in case the bootloader incorrectly set that)?
Quoted 4 lines
Same answer, but I'll investigate to have more details on this register.
It's more an implementation issue, we can change it when PCIe is enabled on this platform.
I'm fine with postponing this until we bring up PCIe support on this platform if you add a comment (preferably marked with "TODO") in the driver. that makes it obvious to everyone who comes across this in the PHY driver
with a TODO-comment you can add my:
Regards
Martin
PATCH v2 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 v2 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.
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 | 10 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 601 +++++++++++++++++++++++++++++ 3 files changed, 612 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.c
drivers/usb/dwc3/Kconfig +10 -0
@@ -93,6 +93,16 @@ 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 + select USB_ROLE_SWITCH + 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 +601 -0
601 lines not on this page · raw message
Re: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
Hi,
Quoted 82 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 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 | 10 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 601 +++++++++++++++++++++++++++++ 3 files changed, 612 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.cdrivers/usb/dwc3/Kconfig +10
-0@@ -93,6 +93,16 @@ 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 + select USB_ROLE_SWITCH + 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 +18
-0@@ -0,0 +1,601 @@ +// 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 +*/ +
[...]
Quoted 70 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +70
-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; +enum phy_mode otg_id; +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->vbus =devm_regulator_get_optional (dev,"vbus" ); +if (IS_ERR (priv->vbus)) { +if (PTR_ERR (priv->vbus) == -EPROBE_DEFER ) +return PTR_ERR (priv->vbus); + priv->vbus =NULL ; + } + + priv->clk =devm_clk_get (dev,NULL ); +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,NULL ); +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; + + ret =regulator_enable (priv->vbus); +if (ret) +return ret; + +/* Get dr_mode */ + priv->otg_mode =usb_get_dr_mode (dev); + +dwc3_meson_g12a_usb_init (priv); + +/* Set PHY Power */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_power_on (priv->phys[i]);
drivers/usb/dwc3/dwc3-meson-g12a.c line 446
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+if (ret) + goto err_phys_put; + } + +/* Init PHYs */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_init (priv->phys[i]); +if (ret) + goto err_phys_power; + }
usually phy_init() first
Quoted 16 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +16
-0+ + ret =of_platform_populate (np,NULL ,NULL , dev); +if (ret) { +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + + goto err_phys_exit; + } + +/* Setup OTG mode corresponding to the ID pin */ +if (priv->otg_mode ==USB_DR_MODE_OTG ) { +/* TOFIX Handle ID mode toggling via IRQ */ + otg_id =dwc3_meson_g12a_get_id (priv); +if (otg_id != priv->otg_phy_mode) { +if (dwc3_meson_g12a_otg_mode_set (priv, otg_id)) +dev_warn (dev,"Failed to switch OTG mode\n" );
drivers/usb/dwc3/dwc3-meson-g12a.c line 472
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ } + } + +/* Setup role switcher */ + priv->switch_desc.usb2_port =dwc3_meson_g12_find_child (dev, +"snps,dwc3" ); + priv->switch_desc.udc =dwc3_meson_g12_find_child (dev,"snps,dwc2" ); + priv->switch_desc.allow_userspace_control = true; + priv->switch_desc.set = dwc3_meson_g12a_role_set; + priv->switch_desc.get = dwc3_meson_g12a_role_get;
to me, use a local variable for switch_desc
Quoted 13 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +13
-0+ + priv->role_switch =usb_role_switch_register (dev, &priv->switch_desc); +if (IS_ERR (priv->role_switch)) +dev_warn (dev,"Unable to register Role Switch\n" ); + +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_get_sync (dev); + +return 0 ; + +err_phys_exit: +for (i =0 ; i <PHY_COUNT ; ++i)
drivers/usb/dwc3/dwc3-meson-g12a.c line 495
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+phy_exit (priv->phys[i]); + +err_phys_power: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_power_off (priv->phys[i]); + +err_phys_put: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_put (priv->phys[i]); +
The phys are got by devm_phy_optional_get(), no need call phy_put()
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+return ret; +} + +static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev;
drivers/usb/dwc3/dwc3-meson-g12a.c line 512
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+int i; + +usb_role_switch_unregister (priv->role_switch); + +of_platform_depopulate (dev); + +for (i =0 ; i <PHY_COUNT ; ++i) { +phy_power_off (priv->phys[i]); +phy_exit (priv->phys[i]); +phy_put (priv->phys[i]);
ditto
Quoted 89 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +89
-0+ } + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + +pm_runtime_disable (dev); +pm_runtime_put_noidle (dev); +pm_runtime_set_suspended (dev); + +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); + +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 <PHY_COUNT ; ++i) +if (priv->phys[i]) +phy_exit (priv->phys[i]); + +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{ +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 <PHY_COUNT ; ++i) { +if (priv->phys[i]) { + 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]>" );
Re: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
Quoted 158 lines · Chunfeng Yun
Hi,
Quoted 82 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 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 | 10 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 601 +++++++++++++++++++++++++++++ 3 files changed, 612 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.cdrivers/usb/dwc3/Kconfig +10
-0@@ -93,6 +93,16 @@ 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 + select USB_ROLE_SWITCH + 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 +18
-0@@ -0,0 +1,601 @@ +// 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 +*/ +[...]
Quoted 73 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +73
-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; +enum phy_mode otg_id; +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->vbus =devm_regulator_get_optional (dev,"vbus" ); +if (IS_ERR (priv->vbus)) { +if (PTR_ERR (priv->vbus) == -EPROBE_DEFER ) +return PTR_ERR (priv->vbus); + priv->vbus =NULL ; + } + + priv->clk =devm_clk_get (dev,NULL ); +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,NULL ); +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; + + ret =regulator_enable (priv->vbus); +if (ret) +return ret; + +/* Get dr_mode */ + priv->otg_mode =usb_get_dr_mode (dev); + +dwc3_meson_g12a_usb_init (priv); + +/* Set PHY Power */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_power_on (priv->phys[i]); +if (ret) + goto err_phys_put; + }
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 446
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ +/* Init PHYs */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_init (priv->phys[i]); +if (ret) + goto err_phys_power; + }usually
phy_init()first
OK, i usually saw power_on before, but I'll swap them.
Quoted 20 lines
Quoted 20 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +19
-0+ + ret =of_platform_populate (np,NULL ,NULL , dev); +if (ret) { +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + + goto err_phys_exit; + } + +/* Setup OTG mode corresponding to the ID pin */ +if (priv->otg_mode ==USB_DR_MODE_OTG ) { +/* TOFIX Handle ID mode toggling via IRQ */ + otg_id =dwc3_meson_g12a_get_id (priv); +if (otg_id != priv->otg_phy_mode) { +if (dwc3_meson_g12a_otg_mode_set (priv, otg_id)) +dev_warn (dev,"Failed to switch OTG mode\n" ); + } + } +
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 472
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+/* Setup role switcher */ + priv->switch_desc.usb2_port =dwc3_meson_g12_find_child (dev, +"snps,dwc3" ); + priv->switch_desc.udc =dwc3_meson_g12_find_child (dev,"snps,dwc2" ); + priv->switch_desc.allow_userspace_control = true; + priv->switch_desc.set = dwc3_meson_g12a_role_set; + priv->switch_desc.get = dwc3_meson_g12a_role_get;to me, use a local variable for
switch_desc
I'm never fan of changing a local global variable for a driver instance, is it strictly required ?
Quoted 17 lines
Quoted 17 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +16
-0+ + priv->role_switch =usb_role_switch_register (dev, &priv->switch_desc); +if (IS_ERR (priv->role_switch)) +dev_warn (dev,"Unable to register Role Switch\n" ); + +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_get_sync (dev); + +return 0 ; + +err_phys_exit: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_exit (priv->phys[i]); + +err_phys_power:
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 495
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+for (i =0 ; i <PHY_COUNT ; ++i) +phy_power_off (priv->phys[i]); + +err_phys_put: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_put (priv->phys[i]); +The phys are got by
devm_phy_optional_get(), no need callphy_put()
You are right, this is a leftover from v1.
Quoted 10 lines
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+return ret; +} + +static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int i; + +usb_role_switch_unregister (priv->role_switch);
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 512
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ +of_platform_depopulate (dev); + +for (i =0 ; i <PHY_COUNT ; ++i) { +phy_power_off (priv->phys[i]); +phy_exit (priv->phys[i]); +phy_put (priv->phys[i]);ditto
Thanks for the review,
Neil
Quoted 91 lines
Quoted 89 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +89
-0+ } + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + +pm_runtime_disable (dev); +pm_runtime_put_noidle (dev); +pm_runtime_set_suspended (dev); + +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); + +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 <PHY_COUNT ; ++i) +if (priv->phys[i]) +phy_exit (priv->phys[i]); + +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{ +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 <PHY_COUNT ; ++i) { +if (priv->phys[i]) { + 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]>" );
Re: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
Quoted 199 lines · Neil Armstrong
Quoted 158 lines · Chunfeng Yun
Hi,
Quoted 82 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 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 | 10 + drivers/usb/dwc3/Makefile | 1 + drivers/usb/dwc3/dwc3-meson-g12a.c | 601 +++++++++++++++++++++++++++++ 3 files changed, 612 insertions(+) create mode 100644 drivers/usb/dwc3/dwc3-meson-g12a.cdrivers/usb/dwc3/Kconfig +10
-0@@ -93,6 +93,16 @@ 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 + select USB_ROLE_SWITCH + 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 +18
-0@@ -0,0 +1,601 @@ +// 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 +*/ +[...]
Quoted 73 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +73
-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; +enum phy_mode otg_id; +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->vbus =devm_regulator_get_optional (dev,"vbus" ); +if (IS_ERR (priv->vbus)) { +if (PTR_ERR (priv->vbus) == -EPROBE_DEFER ) +return PTR_ERR (priv->vbus); + priv->vbus =NULL ; + } + + priv->clk =devm_clk_get (dev,NULL ); +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,NULL ); +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; + + ret =regulator_enable (priv->vbus); +if (ret) +return ret; + +/* Get dr_mode */ + priv->otg_mode =usb_get_dr_mode (dev); + +dwc3_meson_g12a_usb_init (priv); + +/* Set PHY Power */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_power_on (priv->phys[i]); +if (ret) + goto err_phys_put; + }Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 446
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ +/* Init PHYs */ +for (i =0 ; i <PHY_COUNT ; ++i) { + ret =phy_init (priv->phys[i]); +if (ret) + goto err_phys_power; + }usually
phy_init()firstOK, i usually saw
power_onbefore, but I'll swap them.Quoted 20 lines
Quoted 20 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +19
-0+ + ret =of_platform_populate (np,NULL ,NULL , dev); +if (ret) { +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + + goto err_phys_exit; + } + +/* Setup OTG mode corresponding to the ID pin */ +if (priv->otg_mode ==USB_DR_MODE_OTG ) { +/* TOFIX Handle ID mode toggling via IRQ */ + otg_id =dwc3_meson_g12a_get_id (priv); +if (otg_id != priv->otg_phy_mode) { +if (dwc3_meson_g12a_otg_mode_set (priv, otg_id)) +dev_warn (dev,"Failed to switch OTG mode\n" ); + } + } +Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 472
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+/* Setup role switcher */ + priv->switch_desc.usb2_port =dwc3_meson_g12_find_child (dev, +"snps,dwc3" ); + priv->switch_desc.udc =dwc3_meson_g12_find_child (dev,"snps,dwc2" ); + priv->switch_desc.allow_userspace_control = true; + priv->switch_desc.set = dwc3_meson_g12a_role_set; + priv->switch_desc.get = dwc3_meson_g12a_role_get;to me, use a local variable for
switch_desc
Quoted 2 lines
I'm never fan of changing a local global variable for a driver instance, is it strictly required ?
No :)
Quoted 143 lines
Quoted 18 lines
Quoted 18 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +16
-0+ + priv->role_switch =usb_role_switch_register (dev, &priv->switch_desc); +if (IS_ERR (priv->role_switch)) +dev_warn (dev,"Unable to register Role Switch\n" ); + +pm_runtime_set_active (dev); +pm_runtime_enable (dev); +pm_runtime_get_sync (dev); + +return 0 ; + +err_phys_exit: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_exit (priv->phys[i]); + +err_phys_power:Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 495
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+for (i =0 ; i <PHY_COUNT ; ++i) +phy_power_off (priv->phys[i]); + +err_phys_put: +for (i =0 ; i <PHY_COUNT ; ++i) +phy_put (priv->phys[i]); +The phys are got by
devm_phy_optional_get(), no need callphy_put()You are right, this is a leftover from v1.
Quoted 10 lines
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+return ret; +} + +static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int i; + +usb_role_switch_unregister (priv->role_switch);Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 512
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ +of_platform_depopulate (dev); + +for (i =0 ; i <PHY_COUNT ; ++i) { +phy_power_off (priv->phys[i]); +phy_exit (priv->phys[i]); +phy_put (priv->phys[i]);ditto
Thanks for the review,
NeilQuoted 91 lines
Quoted 89 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +89
-0+ } + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk); + +pm_runtime_disable (dev); +pm_runtime_put_noidle (dev); +pm_runtime_set_suspended (dev); + +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); + +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 <PHY_COUNT ; ++i) +if (priv->phys[i]) +phy_exit (priv->phys[i]); + +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{ +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 <PHY_COUNT ; ++i) { +if (priv->phys[i]) { + 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]>" );
Martin Blumenstingl
reviewerRe: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
In reply to Neil ArmstrongOn Thu, Mar 7, 2019 at 10:46 AM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 11 lines
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 472
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+/* Setup role switcher */ + priv->switch_desc.usb2_port =dwc3_meson_g12_find_child (dev, +"snps,dwc3" ); + priv->switch_desc.udc =dwc3_meson_g12_find_child (dev,"snps,dwc2" ); + priv->switch_desc.allow_userspace_control = true; + priv->switch_desc.set = dwc3_meson_g12a_role_set; + priv->switch_desc.get = dwc3_meson_g12a_role_get;to me, use a local variable for
switch_descI'm never fan of changing a local global variable for a driver instance, is it strictly required ?
usb_role_switch_register (which is called a few lines below this) copies all data from "struct usb_role_switch_desc" to a newly allocated "struct usb_role_switch"
in other words: you could make it a stack-variable
personally I have no preference so I leave the decision up to you
Regards
Martin
Martin Blumenstingl
reviewerRe: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
In reply to Neil ArmstrongHi Neil,
On Mon, Mar 4, 2019 at 11:41 AM Neil Armstrong <[email protected]> wrote:
[...]
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+static void dwc3_meson_g12a_usb_init_mode (struct dwc3_meson_g12a *priv) +{ +if (priv->otg_phy_mode ==PHY_MODE_USB_DEVICE ) { +regmap_update_bits (priv->regmap,USB_R0 , +USB_R0_U2D_ACT ,USB_R0_U2D_ACT ); + regmap_update_bits(priv->regmap, USB_R0,
drivers/usb/dwc3/dwc3-meson-g12a.c line 219
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ USB_R0_U2D_SS_SCALEDOWN_MODE_MASK, 0); +regmap_update_bits (priv->regmap,USB_R4 , +USB_R4_P21_SLEEP_M0 ,USB_R4_P21_SLEEP_M0 ); + }else { +regmap_update_bits (priv->regmap,USB_R0 , +USB_R0_U2D_ACT ,0 ); +regmap_update_bits (priv->regmap,USB_R4 , +USB_R4_P21_SLEEP_M0 ,0 ); + } +}
I was already confused by the name of this function in v1. do you think "dwc3_meson_g12a_usb_otg_apply_mode" is a suitable name?
[...]
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+static int dwc3_meson_g12a_otg_mode_set (struct dwc3_meson_g12a *priv, +enum phy_mode mode) +{ +int ret; + +if (!priv->phys[USB2_OTG_PHY ]) +return -EINVAL ; +
drivers/usb/dwc3/dwc3-meson-g12a.c line 312
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+if (mode ==PHY_MODE_USB_HOST ) +dev_info (priv->dev,"switching to Host Mode\n" ); +else +dev_info (priv->dev,"switching to Device Mode\n" ); + +if (priv->vbus) { +if (mode ==PHY_MODE_USB_DEVICE ) + ret =regulator_disable (priv->vbus); +else + ret =regulator_enable (priv->vbus);
do we need to track the regulator status (whether it's enabled or not)? the regulator framework WARN()s if it detects "unbalanced disables for <regulator>"
(I haven't tested this on one of my boards yet, so maybe it works because the callers of dwc3_meson_g12a_otg_mode_set() protect against this by not calling this function if the mode doesn't change)
drivers/usb/dwc3/dwc3-meson-g12a.c line 324
Quoted 12 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +12
-0+if (ret) +return ret; + } + + priv->otg_phy_mode = mode; + +dwc3_meson_g12a_usb2_set_mode (priv,USB2_OTG_PHY , mode); + +dwc3_meson_g12a_usb_init_mode (priv); + +return phy_set_mode (priv->phys[USB2_OTG_PHY ], mode); + }
this is the only place where phy_set_mode is called
I'm fine with keeping it but then it should be consistent at least for all USB2 PHYs.
I suggest to either move the phy_set_mode call to dwc3_meson_g12a_usb2_set_mode or to remove it.
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 334
Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +9
-0+static int dwc3_meson_g12a_role_set (struct device *dev,enum usb_role role) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +enum phy_mode mode; + +if (role ==USB_ROLE_NONE ) +return 0 ; + + mode = role ==USB_ROLE_HOST ?PHY_MODE_USB_HOST :PHY_MODE_USB_DEVICE ;
(without surrounding parens I find the "role == USB_ROLE_HOST" part hard to distinguish from the "mode =" operation. if more people think this way then please speak up - otherwise it's probably just my personal taste)
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 360
Quoted 11 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +11
-0+static struct device *dwc3_meson_g12_find_child (struct device *dev, +const char *compatible) +{ +struct platform_device *pdev; +struct device_node *np; + + np =of_find_compatible_node (dev->of_node,NULL , compatible); +if (!np) +return NULL ; + + pdev =of_find_device_by_node (np);
maybe switch to of_get_compatible_child() here? This was done for the MMC driver in c483a5cc9d09f4 ("mmc: meson-mx-sdio: fix OF child-node lookup"), but I'm not sure if the problem described there also applies to dwc3_meson_g12_find_child
[...]
Quoted 38 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +38
-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; +enum phy_mode otg_id; +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->vbus =devm_regulator_get_optional (dev,"vbus" ); +if (IS_ERR (priv->vbus)) { +if (PTR_ERR (priv->vbus) == -EPROBE_DEFER ) +return PTR_ERR (priv->vbus); + priv->vbus =NULL ; + } + + priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) +return PTR_ERR (priv->clk); + + ret =clk_prepare_enable (priv->clk); +if (ret) +return ret;
drivers/usb/dwc3/dwc3-meson-g12a.c line 415
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ +platform_set_drvdata (pdev, priv); + priv->dev = dev; + + priv->reset =devm_reset_control_get (dev,NULL ); +if (IS_ERR (priv->reset)) { + ret =PTR_ERR (priv->reset); +dev_err (dev,"failed to get device reset, err=%d\n" , ret); +return ret; + }
clk_prepare_enable is called a few lines above but this (and a few more) error-paths don't call clk_disable_unprepare.
Jerome suggested in the dwmac-meson8b driver that I use something like, which will even allow you to drop the clk_disable_unprepare call from dwc3_meson_g12a_remove and catch all error cases in dwc3_meson_g12a_probe at the same time:
devm_add_action_or_reset(dev, (void(*)(void
*))clk_disable_unprepare, priv->clk);
(if you go with this then you also need to remove the clk_disable_unprepare after of_platform_populate)
[...]
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int i; + +usb_role_switch_unregister (priv->role_switch); +
drivers/usb/dwc3/dwc3-meson-g12a.c line 516
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+of_platform_depopulate (dev); + +for (i =0 ; i <PHY_COUNT ; ++i) { +phy_power_off (priv->phys[i]); +phy_exit (priv->phys[i]); +phy_put (priv->phys[i]); + } + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk);
priv->clk is obtained with devm_clk_get so the common clock framework will call clk_put for us automatically
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 548
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+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 <PHY_COUNT ; ++i) +if (priv->phys[i]) +phy_exit (priv->phys[i]);
phy_init is NULL-safe, so you can drop the NULL-check above
Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +9
-0+ +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev);
drivers/usb/dwc3/dwc3-meson-g12a.c line 567
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+int i, ret; + +reset_control_deassert (priv->reset); + +dwc3_meson_g12a_usb_init (priv); + +/* Init PHYs */ +for (i =0 ; i <PHY_COUNT ; ++i) { +if (priv->phys[i]) { + ret =phy_init (priv->phys[i]);
phy_init is NULL-safe, so you can drop the NULL-check above
Regards
Martin
Re: [PATCH v2 8/8] usb: dwc3: Add Amlogic G12A DWC3 glue
Quoted 14 lines · Martin Blumenstingl
Hi Neil,
On Mon, Mar 4, 2019 at 11:41 AM Neil Armstrong <[email protected]> wrote:
[...]Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+static void dwc3_meson_g12a_usb_init_mode (struct dwc3_meson_g12a *priv) +{ +if (priv->otg_phy_mode ==PHY_MODE_USB_DEVICE ) { +regmap_update_bits (priv->regmap,USB_R0 , +USB_R0_U2D_ACT ,USB_R0_U2D_ACT ); +regmap_update_bits (priv->regmap,USB_R0 , +USB_R0_U2D_SS_SCALEDOWN_MODE_MASK ,0 ); +regmap_update_bits (priv->regmap,USB_R4 , +USB_R4_P21_SLEEP_M0 ,USB_R4_P21_SLEEP_M0 ); + }else {
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 219
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+regmap_update_bits (priv->regmap,USB_R0 , +USB_R0_U2D_ACT ,0 ); +regmap_update_bits (priv->regmap,USB_R4 , +USB_R4_P21_SLEEP_M0 ,0 ); + } +}I was already confused by the name of this function in v1. do you think "
dwc3_meson_g12a_usb_otg_apply_mode" is a suitable name?
Yep changed
Quoted 18 lines
[...]
Quoted 16 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +16
-0+static int dwc3_meson_g12a_otg_mode_set (struct dwc3_meson_g12a *priv, +enum phy_mode mode) +{ +int ret; + +if (!priv->phys[USB2_OTG_PHY ]) +return -EINVAL ; + +if (mode ==PHY_MODE_USB_HOST ) +dev_info (priv->dev,"switching to Host Mode\n" ); +else +dev_info (priv->dev,"switching to Device Mode\n" ); + +if (priv->vbus) { +if (mode ==PHY_MODE_USB_DEVICE ) + ret =regulator_disable (priv->vbus);
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ else + ret = regulator_enable(priv->vbus);do we need to track the regulator status (whether it's enabled or not)? the regulator framework WARN()s if it detects "unbalanced disables for <regulator>"
(I haven't tested this on one of my boards yet, so maybe it works because the callers ofdwc3_meson_g12a_otg_mode_set()protect against this by not calling this function if the mode doesn't change)
I handled this case by enabling the regulator _before_, as we default in Host/OTG mode in probe, then eventually switch to device.
In this case, we don't have to track the status, and further calls to dwc3_meson_g12a_otg_mode_set() will only change the regulator on mode change.
Quoted 10 lines
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +9
-0+if (ret) +return ret; + } + + priv->otg_phy_mode = mode; + +dwc3_meson_g12a_usb2_set_mode (priv,USB2_OTG_PHY , mode); + +dwc3_meson_g12a_usb_init_mode (priv);
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 324
Quoted 3 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +3
-0+ +return phy_set_mode (priv->phys[USB2_OTG_PHY ], mode); + }this is the only place where
phy_set_modeis called
I'm fine with keeping it but then it should be consistent at least for all USB2 PHYs.
I suggest to either move thephy_set_modecall todwc3_meson_g12a_usb2_set_modeor to remove it.
I will remove it, it's useless for now.
Quoted 15 lines
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 334
Quoted 9 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +9
-0+static int dwc3_meson_g12a_role_set (struct device *dev,enum usb_role role) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +enum phy_mode mode; + +if (role ==USB_ROLE_NONE ) +return 0 ; + + mode = role ==USB_ROLE_HOST ?PHY_MODE_USB_HOST :PHY_MODE_USB_DEVICE ;(without surrounding parens I find the "role ==
USB_ROLE_HOST" part hard to distinguish from the "mode =" operation. if more people think this way then please speak up - otherwise it's probably just my personal taste)
Yep, I added parenthesis and changed indentation to make it clearer.
Quoted 17 lines
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 360
Quoted 11 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +11
-0+static struct device *dwc3_meson_g12_find_child (struct device *dev, +const char *compatible) +{ +struct platform_device *pdev; +struct device_node *np; + + np =of_find_compatible_node (dev->of_node,NULL , compatible); +if (!np) +return NULL ; + + pdev =of_find_device_by_node (np);maybe switch to
of_get_compatible_child()here? This was done for the MMC driver inc483a5cc9d09f4("mmc: meson-mx-sdio: fix OF child-node lookup"), but I'm not sure if the problem described there also applies todwc3_meson_g12_find_child
of_get_compatible_child() is new to me, switching to it !
Quoted 52 lines
[...]
Quoted 38 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +38
-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; +enum phy_mode otg_id; +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->vbus =devm_regulator_get_optional (dev,"vbus" ); +if (IS_ERR (priv->vbus)) { +if (PTR_ERR (priv->vbus) == -EPROBE_DEFER ) +return PTR_ERR (priv->vbus); + priv->vbus =NULL ; + } + + priv->clk =devm_clk_get (dev,NULL ); +if (IS_ERR (priv->clk)) +return PTR_ERR (priv->clk); + + ret =clk_prepare_enable (priv->clk); +if (ret) +return ret;drivers/usb/dwc3/dwc3-meson-g12a.c line 415
Quoted 10 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +10
-0+ +platform_set_drvdata (pdev, priv); + priv->dev = dev; + + priv->reset =devm_reset_control_get (dev,NULL ); +if (IS_ERR (priv->reset)) { + ret =PTR_ERR (priv->reset); +dev_err (dev,"failed to get device reset, err=%d\n" , ret); +return ret; + }
clk_prepare_enableis called a few lines above but this (and a few more) error-paths don't callclk_disable_unprepare.
Quoted 8 lines
Jerome suggested in the dwmac-meson8b driver that I use something like, which will even allow you to drop the
clk_disable_unpreparecall fromdwc3_meson_g12a_removeand catch all error cases indwc3_meson_g12a_probeat the same time:
devm_add_action_or_reset(dev, (void(*)(void
*))clk_disable_unprepare,priv->clk);
(if you go with this then you also need to remove theclk_disable_unprepareafterof_platform_populate)
Indeed I totally forgot this, thanks !
Quoted 14 lines
[...]
Quoted 12 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +12
-0+static int dwc3_meson_g12a_remove (struct platform_device *pdev) +{ +struct dwc3_meson_g12a *priv =platform_get_drvdata (pdev); +struct device *dev = &pdev->dev; +int i; + +usb_role_switch_unregister (priv->role_switch); + +of_platform_depopulate (dev); + +for (i =0 ; i <PHY_COUNT ; ++i) { +phy_power_off (priv->phys[i]);
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 516
Quoted 6 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +6
-0+phy_exit (priv->phys[i]); +phy_put (priv->phys[i]); + } + +clk_disable_unprepare (priv->clk); +clk_put (priv->clk);
priv->clkis obtained withdevm_clk_getso the common clock framework will callclk_putfor us automatically
Right
Quoted 11 lines
[...]
drivers/usb/dwc3/dwc3-meson-g12a.c line 548
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +8
-0+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 <PHY_COUNT ; ++i) +if (priv->phys[i]) +phy_exit (priv->phys[i]);
phy_initis NULL-safe, so you can drop the NULL-check above
Forgot this one
Quoted 13 lines
Quoted 13 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +12
-0+ +reset_control_assert (priv->reset); + +return 0 ; +} + +static int __maybe_unused dwc3_meson_g12a_resume (struct device *dev) +{ +struct dwc3_meson_g12a *priv =dev_get_drvdata (dev); +int i, ret; + +reset_control_deassert (priv->reset);
Quoted 8 lines
drivers/usb/dwc3/dwc3-meson-g12a.c line 567
Quoted 7 lines
drivers/usb/dwc3/dwc3-meson-g12a.c new file +7
-0+ +dwc3_meson_g12a_usb_init (priv); + +/* Init PHYs */ +for (i =0 ; i <PHY_COUNT ; ++i) { +if (priv->phys[i]) { + ret =phy_init (priv->phys[i]);
phy_initis NULL-safe, so you can drop the NULL-check above
Good catch...
Quoted 5 lines
Regards
Martin
Thanks !!
Neil