Add CIX Sky1 USBSSP controller support
v8 cover Add CIX Sky1 USBSSP controller support
This series adds support for the Cadence USBSSP DRD controller integrated in the CIX Sky1 SoC: the device tree binding and the glue driver. It is a USB series only. The arm64 device tree nodes belong to the SoC subsystem, so they are not part of this series and will be sent separately once the binding is accepted.
Tested on Radxa Orion O6 (Sky1) in host mode, together with the CIX USB3 PHY series posted separately. The series applies on top of v7.4-rc1.
Each controller is described as one address range in the USB30 Type-A DRD RCSU block at 0x091c0000, starting at its AXI cache attribute strap register and ending after its AXI clock status register. The two Type-A controllers interleave their strap and status registers in that block:
0x300 STRAP_PIN0 stream ID USB4 0x304 STRAP_PIN1 stream ID USB5 0x30c STRAP_PIN3 clock enables USB4, USB5 0x314 STRAP_PIN5 awcache/arcache USB4 0x324 STRAP_PIN9 awcache/arcache USB5 0x328 STRAP_PIN10 USB2 PLL USB4 0x400 STRAP_STATUS0 AXI clock state USB4 0x410 STRAP_STATUS4 AXI clock state USB5
Only STRAP_PIN3 is common to both controllers; every other register is read or written by one of them. There is no contiguous window that covers the registers of one controller only, so the two ranges overlap. The range is mapped with devm_ioremap() instead of devm_platform_ioremap_resource(): requesting the region would make the second controller fail with -EBUSY.
Thanks to Krzysztof Kozlowski for the review of the earlier versions.
Changes in v8:
- Fix the example: the USB3 PHY is a single provider shared by both controllers, so the core node references one phandle. The example still carried the per-lane two-PHY form that v5 of the PHY series used. Keep the USB2 PHY reference and describe it as usb-nop-xceiv, since it needs no configuration.
- Add the vendor prefix to the two board properties: cix,ssp-disable and cix,u3-port-disable.
- Driver: do not assert the resets in system suspend/resume, and do not cache the wakeup state; the child device that owns the wakeup interrupt is asked instead.
- Driver: rewrite shutdown() to use the same teardown as remove(), and allocate the child platform data with kzalloc() so that platform_device_release() can free it.
- Driver: only set PS_PME_En when wakeup is requested, and return -ETIMEDOUT when the controller does not reach D3 or does not leave it.
Changes in v7:
- Describe the RCSU registers of each controller as one address range starting at its AXI cache attribute register, instead of two 16-byte register slots, and drop the reg-names property.
- Map that range with devm_ioremap(); request_mem_region() cannot be used because the two Type-A controllers share the block and their ranges overlap.
- Take the offset of the AXI clock status register from per-compatible driver data (0xec on Type-A, 0xf0 on Type-C), instead of two reg-names.
- Dropped #syscon-cells from the S5 system controller binding: the property does not exist in the kernel, and the series no longer touches bindings/soc/cix.
- Removed the arm64 dts from the series: it is a separate SoC patchset.
Changes in v6:
- Dropped the simple-bus RCSU container; each node is placed at the address of its glue registers and the core is a child at its own address.
- Replaced the usbN aliases and the undocumented id property with the register offset and bit position arguments of cix,usb-syscon.
- Converted probe error paths to dev_err_probe().
- Removed the unused over-current GPIO handling and the unused dr_base and cdnsp_pdev fields.
- Fixed the 125us prescaler value: time * frequency - 1.
- Made the AXI halt writes read-modify-write so the preserved and RW1C bits of XEC_AXI_CAP keep their state.
Changes in v5:
- Dropped the cix,sky1-usbss-rcsu syscon binding and the cix,usb-rcsu phandle; the glue registers are described in the controller node.
- Added the MAINTAINERS entry for the glue driver.
Changes in v4:
- Split the combined PHY/USBSSP series into two independent series.
- Restructured the RCSU registers as a shared syscon region with offsets (reverted in v5).
- Fixed the indentation reported by checkpatch.
Changes in v3:
- Fixed the interrupt specifiers of the core nodes: the Sky1 GICv3 uses four cells, so every entry needs the fourth (empty) cell.
- PHY driver: assert the resets before registering the PHY provider, disable clocks in LIFO order, and fix the error unroll path so clocks that were never enabled are not disabled.
Changes in v2:
- Split the single binding into a PHY binding and a USBSSP binding.
- clock-names: apb/ref for the PHY, sof/axi/lpm/apb for the controller.
- reset-names: core/apb instead of reset/preset.
- Dropped axi_bmax_value from DT; it is a driver constant.
- Added the MAINTAINERS entries.
Changes in v1: initial version.
Hongliang Yang (2):
dt-bindings: usb: Add CIX Sky1 USBSSP controller
usb: cdns3: Add CIX Sky1 glue driver
.../bindings/usb/cix,sky1-usbssp.yaml | 163 +++++ MAINTAINERS | 2 + drivers/usb/cdns3/Kconfig | 13 + drivers/usb/cdns3/Makefile | 1 + drivers/usb/cdns3/cdnsp-sky1.c | 663 ++++++++++++++++++ drivers/usb/cdns3/cdnsp-sky1.h | 99 +++ 6 files changed, 941 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml create mode 100644 drivers/usb/cdns3/cdnsp-sky1.c create mode 100644 drivers/usb/cdns3/cdnsp-sky1.h
--
2.54.0
PATCH v8 1/2 dt-bindings: usb: Add CIX Sky1 USBSSP controller
Add device tree binding for the Cadence USBSSP DRD controller integrated in the CIX Sky1 SoC. Each instance wraps one of the two USB3 Type-A DRD controllers of the SoC.
The register range of an instance is its window in the USB30 Type-A DRD RCSU block at 0x091c0000, from the AXI cache attribute strap register of the instance up to and including its AXI clock status register. The strap registers of the two controllers and of their PHYs are interleaved in that block, so the ranges of the two instances overlap.
The Cadence USBSSP core is described by a child node at its own address. Mode strap controls are programmed through the Sky1 S5 system controller referenced by the cix,usb-syscon phandle.
---
Changes in v8:
- Fix the example: the USB3 PHY is a single provider shared by both controllers, so the core node references one phandle. The example still carried the per-lane two-PHY form that v5 of the PHY series used. Keep the USB2 PHY reference and describe it as usb-nop-xceiv, since it needs no configuration.
- Add the vendor prefix to the two board properties: cix,ssp-disable and cix,u3-port-disable.
Changes in v7:
- Describe the RCSU registers of each controller as one address range starting at its AXI cache attribute register, instead of two 16-byte register slots, and drop the reg-names property.
- Take the offset of the AXI clock status register from per-compatible driver data (0xec on Type-A, 0xf0 on Type-C), instead of two reg-names.
- Dropped #syscon-cells from the S5 system controller binding: the property does not exist in the kernel, and the series no longer touches bindings/soc/cix.
- Removed the arm64 dts from the series: it is a separate SoC patchset.
Changes in v6:
- Dropped the simple-bus RCSU container; each node is placed at the address of its glue registers and the core is a child at its own address.
- Replaced the usbN aliases and the undocumented id property with the register offset and bit position arguments of cix,usb-syscon.
- Converted probe error paths to dev_err_probe().
- Removed the unused over-current GPIO handling and the unused dr_base and cdnsp_pdev fields.
- Fixed the 125us prescaler value: time * frequency - 1.
- Made the AXI halt writes read-modify-write so the preserved and RW1C bits of XEC_AXI_CAP keep their state.
Changes in v5:
- Dropped the cix,sky1-usbss-rcsu syscon binding and the cix,usb-rcsu phandle; the glue registers are described in the controller node.
- Added the MAINTAINERS entry for the glue driver.
Changes in v4:
- Split the combined PHY/USBSSP series into two independent series.
- Restructured the RCSU registers as a shared syscon region with offsets (reverted in v5).
- Fixed the indentation reported by checkpatch.
Changes in v3:
- Fixed the interrupt specifiers of the core nodes: the Sky1 GICv3 uses four cells, so every entry needs the fourth (empty) cell.
Changes in v2:
- Split the single binding into a PHY binding and a USBSSP binding.
- clock-names: sof/axi/lpm/apb for the controller.
- reset-names: core/apb instead of reset/preset.
- Dropped axi_bmax_value from DT; it is a driver constant.
- Added the MAINTAINERS entries.
Changes in v1: initial version.
--- .../bindings/usb/cix,sky1-usbssp.yaml | 163 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 164 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +163 -0
@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/cix,sky1-usbssp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: CIX Sky1 Cadence USBSSP Controller + +maintainers: + - Hongliang Yang <[email protected]> + +description: | + The CIX Sky1 USBSSP controller is based on the Cadence USBSSP DRD + controller. Each instance wraps one of the two USB3 Type-A DRD + controllers of the SoC. + + The register range of an instance is a window in the USB30 Type-A DRD + RCSU block at 0x091c0000, starting at the AXI cache attribute strap + register of the instance and ending after its AXI clock status + register. The strap registers of the two controllers and of their PHYs + are interleaved in that block, so the ranges of the two instances + overlap. + + The Cadence USBSSP core itself is described by a child node at its own + address. Mode strap controls are programmed through the Sky1 S5 system + controller referenced by the cix,usb-syscon phandle, whose arguments + give the register offset and the bit position of the strap field. + + The USB2 PHY of the controller needs no configuration. It is described + as a usb-nop-xceiv device and referenced by the core node like any + other PHY. + +properties: + compatible: + const: cix,sky1-usbssp + + reg: + maxItems: 1 + description: + Window from the AXI cache attribute strap register of this instance + up to and including its AXI clock status register. + + ranges: true + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + clocks: + items: + - description: Start-of-frame clock + - description: AXI bus clock + - description: Low-power mode clock + - description: APB register interface clock + + clock-names: + items: + - const: sof + - const: axi + - const: lpm + - const: apb + + resets: + items: + - description: APB register reset + - description: Controller reset + + reset-names: + items: + - const: apb + - const: core + + cix,ssp-disable: + type: boolean + description: Disable SuperSpeed Plus mode of the controller. + + cix,u3-port-disable: + type: boolean + description: The board does not route the USB3 port of the controller. + + cix,usb-syscon: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + Phandle to the Sky1 S5 system controller followed by the register + offset and the bit position of the USB mode strap field. + items: + - items: + - description: Phandle to the Sky1 S5 system controller + - description: Register offset of the USB mode strap field + - description: Bit position of the USB mode strap field + +required: + - compatible + - reg + - ranges + - "#address-cells" + - "#size-cells" + - clocks + - clock-names + - resets + - reset-names + - cix,usb-syscon + +patternProperties: + "^usb@[0-9a-f]+$": + $ref: cdns,usb3.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/cix,sky1.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/reset/cix,sky1-s5-system-control.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + usb@91c0314 { + compatible = "cix,sky1-usbssp"; + reg = <0x00 0x91c0314 0x00 0x100>; + ranges; + #address-cells = <2>; + #size-cells = <2>; + + clocks = <&scmi_clk CLK_TREE_USB3A_H0_CLK_SOF>, + <&scmi_clk CLK_TREE_USB3A_0_AXI_GATE>, + <&scmi_clk CLK_TREE_USB3A_H0_CLK_LPM>, + <&scmi_clk CLK_TREE_USB3A_0_APB_GATE>; + clock-names = "sof", "axi", "lpm", "apb"; + resets = <&src SKY1_USBC_SS2_PRST_N>, + <&src SKY1_USBC_SS2_RST_N>; + reset-names = "apb", "core"; + cix,usb-syscon = <&src 0x424 8>; + + usb@91d0000 { + compatible = "cdns,usb3"; + reg = <0x00 0x91d0000 0x00 0x4000>, + <0x00 0x91d8000 0x00 0x8000>, + <0x00 0x91d4000 0x00 0x4000>; + reg-names = "otg", "xhci", "dev"; + dr_mode = "otg"; + + interrupts = <GIC_SPI 168 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 170 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 171 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "host", "peripheral", "otg", "wakeup"; + maximum-speed = "super-speed-plus"; + + phys = <&usb3_phy4>, <&usb2_phy4>; + phy-names = "cdns3,usb3-phy", "cdns3,usb2-phy"; + }; + }; + + usb2_phy4: usb-phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0>; + }; + };
MAINTAINERS +1 -0
@@ -2903,6 +2903,7 @@ S: Maintained T: git https://github.com/cixtech/linux-mainline.git F: Documentation/devicetree/bindings/arm/cix.yaml F: Documentation/devicetree/bindings/mailbox/cix,sky1-mbox.yaml +F: Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml F: arch/arm64/boot/dts/cix/ F: drivers/mailbox/cix-mailbox.c K: \bcix\b
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v8 1/2] dt-bindings: usb: Add CIX Sky1 USBSSP controller
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] dt-bindings: usb: cix,sky1-usbssp: overlapping reg windows in RCSU block - [Medium] dt-bindings…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] dt-bindings: usb: cix,sky1-usbssp: overlapping reg windows in RCSU block
- [Medium] dt-bindings: usb: cix,sky1-usbssp: redundant disable properties
--
commit e68eb2e5dd3e2c328c5e798e76df60be2d4b127a
Author: Hongliang Yang <[email protected]>
dt-bindings: usb: Add CIX Sky1 USBSSP controller
This commit adds the Device Tree binding schema for the Cadence USBSSP DRD controller wrapper on the CIX Sky1 SoC.
Quoted 37 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +31
-0@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/cix,sky1-usbssp.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: CIX Sky1 Cadence USBSSP Controller + +maintainers: + - Hongliang Yang <[email protected]> + +description: | + The CIX Sky1 USBSSP controller is based on the Cadence USBSSP DRD + controller. Each instance wraps one of the two USB3 Type-A DRD + controllers of the SoC. + + The register range of an instance is a window in the USB30 Type-A DRD + RCSU block at 0x091c0000, starting at the AXI cache attribute strap + register of the instance and ending after its AXI clock status + register. The strap registers of the two controllers and of their PHYs + are interleaved in that block, so the ranges of the two instances + overlap. + + The Cadence USBSSP core itself is described by a child node at its own + address. Mode strap controls are programmed through the Sky1 S5 system + controller referenced by the cix,usb-syscon phandle, whose arguments + give the register offset and the bit position of the strap field. + + The USB2 PHY of the controller needs no configuration. It is described + as a usb-nop-xceiv device and referenced by the core node like any + other PHY.
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml line 41
Quoted 10 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +10
-0+ +properties: + compatible: + const: cix,sky1-usbssp + + reg: + maxItems: 1 + description: + Window from the AXI cache attribute strap register of this instance + up to and including its AXI clock status register.
[Severity: Medium]
Should each instance describe its disjoint strap and status registers as two separate reg entries (like rcsu_strap and rcsu_status in cix,sky1-pcie-host.yaml) or model the RCSU block as a shared parent node rather than a single overlapping reg window?
Because the RCSU block places all strap registers in 0x091c0300..0x091c03ff and all status registers in 0x091c0400..0x091c04ff, combining both into one contiguous range causes the two sibling nodes on the same bus (usb@91c0314 and usb@91c0324) to overlap across 0x091c0324..0x091c0403 and the PHY's strap register at 0x091c0328. Overlapping reg ranges prevent standard exclusive MMIO resource reservation via devm_platform_ioremap_resource(), as the second instance fails probe with -EBUSY.
In addition, the example below uses reg = <0x00 0x91c0314 0x00 0x100>, which extends to 0x091c0413 (including the second controller's status register at 0x091c0410) instead of 0xf0 bytes ending after this instance's status register at 0x091c0400.
[ ... ]
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml line 81
Quoted 7 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +7
-0+ cix,ssp-disable: + type: boolean + description: Disable SuperSpeed Plus mode of the controller. + + cix,u3-port-disable: + type: boolean + description: The board does not route the USB3 port of the controller.
[Severity: Medium]
Are cix,ssp-disable and cix,u3-port-disable redundant with the standard USB properties already present on the child cdns,usb3 node?
Limiting the controller to Gen1 SuperSpeed is already expressed by setting maximum-speed = "super-speed" on the child node, and an unrouted USB3 port is expressed by maximum-speed = "high-speed" along with omitting cdns3,usb3-phy from phys and phy-names. Keeping separate disable properties on the parent wrapper also allows contradictory configuration between the glue driver and cdnsp_run() in the Cadence gadget driver, which reads maximum-speed from the child node and programs the same 3xPort mode register.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v8 1/2] dt-bindings: usb: Add CIX Sky1 USBSSP controller
Two points.
Quoted 2 lines
[Medium] dt-bindings: usb: cix,sky1-usbssp: overlapping reg windows in RCSU block
The example size is wrong, thank you. The window of one instance ends after STRAP_STATUS0 at 0x091c0400, so it is 0xf0 bytes. With 0x100 the example reaches 0x091c0413 and includes STRAP_STATUS4 at 0x091c0410, which is the status register of the other instance. v9 fixes the example; the arm64 dts is not part of this series and gets the same fix when it is posted.
The -EBUSY does not happen. cdnsp_sky1_probe() maps the range with devm_ioremap(), not devm_platform_ioremap_resource(), because the windows overlap, and that is why the overlap is written down in the schema.
Two 4-byte entries, "strap" and "status", as in cix,sky1-pcie-host.yaml, would remove the overlap, and the driver would not need the offset of the status register inside the window either. That is the shape question the DT review already asked, though: v8 keeps the single range that v7 introduced in answer to it, and I asked Krzysztof which of the two he wants before posting another version ([email protected]). If he prefers two entries, v9 will be that.
Quoted 2 lines
[Medium] dt-bindings: usb: cix,sky1-usbssp: redundant disable properties
cix,ssp-disable is not redundant. It clears CFG_3XPORT_SSP_SUPPORT, BIT(31) of the 3xPort mode register in the host register set. maximum-speed is read only by the gadget paths, through usb_get_maximum_speed() in cdns3-gadget.c and cdnsp-gadget.c; nothing in the host path reads it. For a port that runs in host mode there is no other way to keep it at Gen1.
cix,u3-port-disable is not redundant either: it writes the integration value 0xa0031e07 to the 3xPort mode register in both register sets, and maximum-speed can neither express nor restore those port mode bits. You are right that the device-side register is also updated by cdnsp_run() from the child's speed, so a dual-role port could ask for SuperSpeed Plus on an integration without SuperSpeed lanes. Every board we ship that sets the property uses it on a host-only port (dr_mode = "host"), where the gadget is never started, so the two writers do not meet there. v9 states that constraint in the property description.
Best regards,
Hongliang Yang
Re: [PATCH v8 1/2] dt-bindings: usb: Add CIX Sky1 USBSSP controller
In reply to Hongliang YangQuoted 5 lines · Hongliang Yang
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +5
-0+required: + - compatible + - reg + - ranges + - "#address-cells"
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml line 108
Quoted 10 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +10
-0+ - "#size-cells" + - clocks + - clock-names + - resets + - reset-names + - cix,usb-syscon + +patternProperties: + "^usb@[0-9a-f]+$": + $ref: cdns,usb3.yaml#
Please move patternProperties before "required:" block.
Quoted 44 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +44
-0+ +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/cix,sky1.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/reset/cix,sky1-s5-system-control.h> + + soc { + #address-cells = <2>; + #size-cells = <2>; + + usb@91c0314 { + compatible = "cix,sky1-usbssp"; + reg = <0x00 0x91c0314 0x00 0x100>; + ranges; + #address-cells = <2>; + #size-cells = <2>; + + clocks = <&scmi_clk CLK_TREE_USB3A_H0_CLK_SOF>, + <&scmi_clk CLK_TREE_USB3A_0_AXI_GATE>, + <&scmi_clk CLK_TREE_USB3A_H0_CLK_LPM>, + <&scmi_clk CLK_TREE_USB3A_0_APB_GATE>; + clock-names = "sof", "axi", "lpm", "apb"; + resets = <&src SKY1_USBC_SS2_PRST_N>, + <&src SKY1_USBC_SS2_RST_N>; + reset-names = "apb", "core"; + cix,usb-syscon = <&src 0x424 8>; + + usb@91d0000 { + compatible = "cdns,usb3"; + reg = <0x00 0x91d0000 0x00 0x4000>, + <0x00 0x91d8000 0x00 0x8000>, + <0x00 0x91d4000 0x00 0x4000>; + reg-names = "otg", "xhci", "dev"; + dr_mode = "otg"; + + interrupts = <GIC_SPI 168 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 169 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 170 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 171 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "host", "peripheral", "otg", "wakeup"; + maximum-speed = "super-speed-plus";
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml line 162
Quoted 10 lines
Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml new file +10
-0+ + phys = <&usb3_phy4>, <&usb2_phy4>; + phy-names = "cdns3,usb3-phy", "cdns3,usb2-phy"; + }; + }; + + usb2_phy4: usb-phy { + compatible = "usb-nop-xceiv"; + #phy-cells = <0>; + };
And drop usb-phy
With these two:
Best regards,
Krzysztof
PATCH v8 2/2 usb: cdns3: Add CIX Sky1 glue driver
In reply to Hongliang YangAdd a glue layer driver for the Cadence USBSSP controller integrated in the CIX Sky1 SoC. The driver manages the controller clocks, resets and the mode strap controls located in the Sky1 S5 system controller, and writes the AXI cache attributes and polls the AXI clock status of its own controller in the RCSU block.
The register range is mapped with devm_ioremap() instead of devm_platform_ioremap_resource(): the two Type-A controllers share one RCSU block and their register ranges overlap, so reserving the region would make the second controller fail with -EBUSY. The offset of the AXI clock status register inside the range is taken from the per-compatible match data, as it differs between the Type-A and Type-C register blocks of the SoC.
---
Changes in v8:
- Read the two board properties with their vendor prefix:
cix,ssp-disable and cix,u3-port-disable.
- Do not assert the resets in system suspend/resume: that discards the OTG registers programmed by cdns_drd_init(), and nothing programs them again after the child device resumes. Only the clocks are gated.
- Rewrite shutdown() to use the same teardown as remove(): depopulate the child while its clocks are still on, then assert the resets and disable the clocks. Whether to stay alive is decided on the child device, which owns the wakeup interrupt.
- Allocate the child platform data with kzalloc() and free it if the children cannot be created: platform_device_release() kfree()s dev.platform_data, so it must not be devm-managed.
- Only set PS_PME_En when wakeup is requested, and return -ETIMEDOUT when the controller does not reach D3 or does not leave it.
- Drop the cached wakeup state: it went stale as soon as the child changed its own wakeup setting.
Changes in v7:
- Map one register range taken from the first reg entry, instead of two ranges selected with reg-names.
- Map it with devm_ioremap() because the ranges of the two Type-A controllers overlap.
- Take the offset of the AXI clock status register from the match data.
Changes in v6:
- Read the USB mode strap register offset and bit position from the cix,usb-syscon phandle arguments instead of relying on the usbN aliases and the undocumented id property.
- Use dev_err_probe() in the probe error paths.
- Drop the unused over-current GPIO handling and the unused dr_base and cdnsp_pdev fields.
- Do not disable the clocks before they have been acquired.
- Drop the redundant depends on USB_CDNS3 and fix the compatible name in the Kconfig help text.
--- MAINTAINERS | 1 + drivers/usb/cdns3/Kconfig | 13 + drivers/usb/cdns3/Makefile | 1 + drivers/usb/cdns3/cdnsp-sky1.c | 663 +++++++++++++++++++++++++++++++++ drivers/usb/cdns3/cdnsp-sky1.h | 99 +++++ 5 files changed, 777 insertions(+) create mode 100644 drivers/usb/cdns3/cdnsp-sky1.c create mode 100644 drivers/usb/cdns3/cdnsp-sky1.h
MAINTAINERS +1 -0
@@ -2906,6 +2906,7 @@ F: Documentation/devicetree/bindings/mailbox/cix,sky1-mbox.yaml F: Documentation/devicetree/bindings/usb/cix,sky1-usbssp.yaml F: arch/arm64/boot/dts/cix/ F: drivers/mailbox/cix-mailbox.c +F: drivers/usb/cdns3/cdnsp-sky1.* K: \bcix\b ARM/CLKDEV SUPPORT
drivers/usb/cdns3/Kconfig +13 -0
@@ -77,6 +77,19 @@ config USB_CDNSP_PCI If you choose to build this driver as module it will be dynamically linked and module will be called cdnsp-pci.ko +config USB_CDNSP_SKY1 + tristate "Cadence USB3 support on CIX Sky1 SoC platforms" + depends on ARCH_CIX || COMPILE_TEST + default USB_CDNS3 + help + Glue driver for the Cadence USB dual-role controllers on CIX Sky1 + (device tree compatible cix,sky1-usbssp). It enables clocks and + resets from the SoC, then uses the shared cdns3 platform core + (cdns.ko). + + If built as a module, the module is named cdnsp-sky1.ko and must be + loaded after the cdns core module when both are loadable modules. + config USB_CDNS3_TI tristate "Cadence USB3 support on TI platforms" depends on ARCH_K3 || COMPILE_TEST
drivers/usb/cdns3/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_USB_CDNSP_PCI) += cdnsp-pci.o obj-$(CONFIG_USB_CDNS3_TI) += cdns3-ti.o obj-$(CONFIG_USB_CDNS3_IMX) += cdns3-imx.o obj-$(CONFIG_USB_CDNS3_STARFIVE) += cdns3-starfive.o +obj-$(CONFIG_USB_CDNSP_SKY1) += cdnsp-sky1.o
drivers/usb/cdns3/cdnsp-sky1.c new file +663 -0
663 lines not on this page · raw message
drivers/usb/cdns3/cdnsp-sky1.h new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH v8 2/2] usb: cdns3: Add CIX Sky1 glue driver
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider: - [Medium] usb: cdns3: cdns_sky1_pdata leak in cdnsp_sky1_probe() - [Medium] usb: cdns3: unconditional clock…
Thank you for your contribution! Sashiko AI review found 5 potential issues to consider:
- [Medium] usb: cdns3: cdns_sky1_pdata leak in cdnsp_sky1_probe()
- [Medium] usb: cdns3: unconditional clock gating in cdnsp_sky1_system_suspend()
- [Medium] usb: cdns3: cdnsp-sky1: clock refcount underflow after resume failure
- [Low] usb: cdns3: PS_PME_En not cleared in cdns_sky1_platform_suspend()
- [Low] usb: cdns3: missing MFD_SYSCON dependency for USB_CDNSP_SKY1 --
commit 7c5b7619382aea292ee4e64d01413bfd07b37097
Author: Hongliang Yang <[email protected]>
usb: cdns3: Add CIX Sky1 glue driver
This commit adds a glue driver for the Cadence USBSSP DRD controller on CIX Sky1 SoCs, managing clocks, resets, S5 syscon mode straps, and RCSU registers.
drivers/usb/cdns3/Kconfig config USB_CDNSP_PCI · line 83
Quoted 12 lines
drivers/usb/cdns3/Kconfig +4
-0@@ -77,6 +77,19 @@ config USB_CDNSP_PCI If you choose to build this driver as module it will be dynamically linked and module will be called cdnsp-pci.ko +config USB_CDNSP_SKY1 + tristate "Cadence USB3 support on CIX Sky1 SoC platforms" + depends on ARCH_CIX || COMPILE_TEST + default USB_CDNS3
[Severity: Low]
Should USB_CDNSP_SKY1 select or depend on MFD_SYSCON? Without CONFIG_MFD_SYSCON, syscon_regmap_lookup_by_phandle_args() is a stub that returns ERR_PTR(-ENOTSUPP), so cdnsp_sky1_probe() always fails.
[ ... ]
Quoted 5 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +0
-0
[ ... ]
Quoted 11 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +11
-0+static int cdnsp_sky1_clk_enable_resume (struct device *dev) +{ +int i, ret; +struct cdnsp_sky1 *data =dev_get_drvdata (dev); +struct clk **cix_usb_clks = data->cix_usb_clks; + +for (i =0 ; i <CIX_USB_CLK_OFF_NUM ; i++) { + ret =clk_prepare_enable (cix_usb_clks[i]); +if (ret) { +dev_err (dev,"failed to enable clock %s: %d\n" , + cix_usb_clk_names[i], ret);
drivers/usb/cdns3/cdnsp-sky1.c line 126
Quoted 10 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +10
-0+ goto err_usb_clks; + } + } +return 0 ; + +err_usb_clks: +while (--i >=0 ) +clk_disable_unprepare (cix_usb_clks[i]); +return ret; +};
[Severity: Medium]
Can a failure here underflow the enable and prepare counts of the sof and axi clocks?
If clk_prepare_enable() fails during system resume, those two clocks are left disabled and unprepared, but a later cdnsp_sky1_remove(), cdnsp_sky1_shutdown(), or cdnsp_sky1_system_suspend() still calls clk_disable_unprepare() on them unconditionally.
[ ... ]
drivers/usb/cdns3/cdnsp-sky1.c line 200
Quoted 8 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +8
-0+if (suspend) { +while (count--) { + value =readl (hcd->regs +XECP_PM_PMCSR ); + value &= ~PS_MASK ; + value |=PS_D3 ; +if (wakeup) + value |= PS_PME_En; +writel (value, hcd->regs +XECP_PM_PMCSR );
[Severity: Low]
Should this clear PS_PME_En when wakeup is false? If PS_PME_En is already set in XECP_PM_PMCSR (for example from initial state or after a prior resume timeout), suspending with wakeup disabled leaves PME wakeup signaling enabled in hardware. Also, cdns3_controller_suspend() and cdns3_controller_resume() ignore the return value of platform_suspend(), so the -ETIMEDOUT returned by cdns_sky1_platform_suspend() is discarded.
[ ... ]
Quoted 4 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +4
-0+ cdns_sky1_pdata =kzalloc (sizeof (*cdns_sky1_pdata),GFP_KERNEL ); +if (!cdns_sky1_pdata) { + ret = -ENOMEM ; + goto err_quiesce;
drivers/usb/cdns3/cdnsp-sky1.c line 535
Quoted 10 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +10
-0+ } + cdns_sky1_pdata->platform_suspend = cdns_sky1_platform_suspend; + cdns_sky1_pdata->quirks =CDNS3_DEFAULT_PM_RUNTIME_ALLOW ; + cdns_sky1_auxdata[0 ].platform_data = cdns_sky1_pdata; + ret =of_platform_populate (node,NULL , cdns_sky1_auxdata, dev); +if (ret) { +dev_err (dev,"failed to create children: %d\n" , ret); +kfree (cdns_sky1_pdata); + goto err_quiesce; + }
[Severity: Medium]
Can this leak cdns_sky1_pdata when no child device is created?
of_platform_populate() calls of_platform_bus_create() with matches set to NULL:
drivers/of/platform.c:of_platform_bus_create() {
...
dev = of_platform_device_create_pdata(bus, bus_id, platform_data, parent);
if (!dev || !of_match_node(matches, bus))
return 0;
...
}Because of_platform_bus_create() returns 0 even when of_platform_device_create_pdata() fails or when no child node matches "cdns,usb3", of_platform_populate() returns 0 whenever node is non-NULL. The if (ret) branch is unreachable and cdns_sky1_pdata is leaked if no child takes ownership of it (or double freed in platform_device_release() if more than one child matches "cdns,usb3").
[ ... ]
Quoted 6 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +6
-0+/* +* Because the wake-up interrupt and host interrupt are the same interrupt, +* closing the axi and sof clock will result in the inability to generate +* port status change interrupt. +* +* The resets are left alone here. Asserting them throws away the OTG
drivers/usb/cdns3/cdnsp-sky1.c line 584
Quoted 10 lines
drivers/usb/cdns3/cdnsp-sky1.c new file +10
-0+* registers programmed by cdns_drd_init(), and nothing programs them again +* after the child device resumes, so the controller keeps its state across +* system suspend and only the clocks are gated. +*/ +static int cdnsp_sky1_system_suspend (struct device *dev) +{ +cdnsp_sky1_clk_disable_suspend (dev); + +return 0 ; +}
[Severity: Medium]
Should cdnsp_sky1_system_suspend() skip gating the sof and axi clocks when wakeup is enabled or the controller has not entered D3?
As the comment notes, disabling sof and axi prevents port status change wakeup interrupts, yet cdnsp_sky1_system_suspend() gates both clocks even when device_may_wakeup() is true on the child device. In addition, cdns_sky1_platform_suspend() only puts the controller into D3 and waits for AXI_CLOCK_VALID to clear when cdns->role == USB_ROLE_HOST (and its -ETIMEDOUT return is ignored by cdns3_controller_suspend()), so in device or idle OTG role, or after a D3 entry timeout, this gates the AXI and SOF clocks while AXI_CLOCK_VALID is still asserted.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v8 2/2] usb: cdns3: Add CIX Sky1 glue driver
All five are real. Fixes go into v9; the binding patch is unaffected.
Quoted 1 line
[Low] missing
MFD_SYSCONdependency forUSB_CDNSP_SKY1
Confirmed. ARCH_CIX does not select MFD_SYSCON, and without it syscon_regmap_lookup_by_phandle_args() returns -ENOTSUPP, so probe fails with a minimal configuration. v9 adds "select MFD_SYSCON".
Quoted 1 line
[Medium] clock refcount underflow after resume failure
Confirmed, and it is not limited to a failed resume: shutting the system down or removing the driver after system suspend, without an intervening resume, reaches cdnsp_sky1_clk_disable_all() and disables the sof and axi clocks a second time.
v9 records which clocks are on in a bitmap and routes every user through one idempotent pair, cdnsp_sky1_clk_enable(data, mask) and cdnsp_sky1_clk_disable(data, mask). A clock that is already on is skipped, and the enable error path disables only the clocks that call enabled. CIX_USB_CLK_OFF_NUM goes away; the suspend window is a mask instead.
Quoted 1 line
[Low]
PS_PME_Ennot cleared incdns_sky1_platform_suspend()
Confirmed, the read-modify-write keeps whatever PS_PME_En was left in the register. v9 clears PS_PME_En together with PS_MASK before setting the new power state.
You are also right that the core drops the return value. That means -ETIMEDOUT does not prevent the half-suspended state, so v9 restores PS_D0 when the D3 entry times out, as the vendor driver does, and keeps the error return for when the core propagates it.
Quoted 1 line
[Medium]
cdns_sky1_pdataleak incdnsp_sky1_probe()
Confirmed. of_platform_bus_create() returns 0 when the child device is not created, so the if (ret) branch after of_platform_populate() never runs.
v9 checks the children twice. Before the populate it requires exactly one enabled cdns,usb3 child node, so the auxdata platform data can never be handed to more than one device, which would be a double free in platform_device_release(). After the populate it looks for the created child and, when there is none, frees the platform data and fails probe.
Quoted 1 line
[Medium] unconditional clock gating in
cdnsp_sky1_system_suspend()
Confirmed, the function contradicts the comment above it. v9 gates the clocks only when both conditions hold:
- the child device, which owns the shared wakeup interrupt, does not have
wakeup enabled;
- AXI_CLOCK_VALID reads 0, that is the controller has stopped using AXI.
The second test answers the device/idle role and the D3 entry timeout cases without depending on the role, and it is the same status bit that cdns_sky1_platform_suspend() polls on a successful D3 entry.
Best regards,
Hongliang Yang