Skip to contentSkip to conversation

phy: bcm63xx-usbh: Add BCM63xx USBH driver

PATCH Superseded Álvaro Fernández Rojas 3 participants 10 messages Jun 16, 2020 – Jun 17, 2020

Subsystems (2)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover phy: bcm63xx-usbh: Add BCM63xx USBH driver

Add BCM63xx USBH PHY driver for BMIPS.

Álvaro Fernández Rojas (2):
dt-bindings: phy: add bcm63xx-usbh bindings
phy: bcm63xx-usbh: Add BCM63xx USBH driver

 .../bindings/phy/brcm,bcm63xx-usbh-phy.yaml   |  72 +++
 drivers/phy/broadcom/Kconfig                  |  10 +
 drivers/phy/broadcom/Makefile                 |   1 +
 drivers/phy/broadcom/phy-bcm63xx-usbh.c       | 463 ++++++++++++++++++
 4 files changed, 546 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml
 create mode 100644 drivers/phy/broadcom/phy-bcm63xx-usbh.c
Signature · 1 line
2.27.0
#1 lore raw

PATCH 1/2 dt-bindings: phy: add bcm63xx-usbh bindings

Document BCM63xx USBH PHY bindings.

---
 .../bindings/phy/brcm,bcm63xx-usbh-phy.yaml   | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +72 -0
new file mode 100644
index 000000000000..3e7c97799b91
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/phy/brcm,bcm63xx-usbh-phy.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: BCM63xx USBH PHY
+
+maintainers:
+  - Álvaro Fernández Rojas <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm6318-usbh-phy
+      - brcm,bcm6328-usbh-phy
+      - brcm,bcm6358-usbh-phy
+      - brcm,bcm6362-usbh-phy
+      - brcm,bcm6368-usbh-phy
+      - brcm,bcm63268-usbh-phy
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: usbh
+      - const: usb_ref
+
+  resets:
+    maxItems: 1
+
+  "#phy-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+  - "#phy-cells"
+
+if:
+  properties:
+    compatible:
+      enum:
+        - brcm,bcm6318-usbh-phy
+        - brcm,bcm6328-usbh-phy
+        - brcm,bcm6362-usbh-phy
+        - brcm,bcm63268-usbh-phy
+
+then:
+  properties:
+    power-domains:
+      maxItems: 1
+  required:
+    - power-domains
+
+examples:
+  - |
+    usbh: usb-phy@10001700 {
+      compatible = "brcm,bcm6368-usbh-phy";
+      reg = <0x10001700 0x38>;
+      clocks = <&periph_clk BCM6368_CLK_USBH>;
+      clock-names = "usbh";
+      resets = <&periph_rst BCM6368_RST_USBH>;
+      #phy-cells = <0>;
+    };
Signature · 1 line
2.27.0
#2 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

Quoted 41 lines · Álvaro Fernández Rojas

Document BCM63xx USBH PHY bindings.

---
 .../bindings/phy/brcm,bcm63xx-usbh-phy.yaml   | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +27 -0
new file mode 100644
index 000000000000..3e7c97799b91
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/phy/brcm,bcm63xx-usbh-phy.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: BCM63xx USBH PHY
+
+maintainers:
+  - Álvaro Fernández Rojas <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm6318-usbh-phy
+      - brcm,bcm6328-usbh-phy
+      - brcm,bcm6358-usbh-phy
+      - brcm,bcm6362-usbh-phy
+      - brcm,bcm6368-usbh-phy
+      - brcm,bcm63268-usbh-phy
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml line 37

Quoted 10 lines
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +10 -0
+  clock-names:
+    items:
+      - const: usbh
+      - const: usb_ref
+
+  resets:
+    maxItems: 1
+
+  "#phy-cells":
+    const: 0

On 6328, the same register space allows the controlling of the USB PHY in either host or device mode, so I believe you would need to add a #phy-cells = 1 in order to distinguish the consumer (host versus device) if we get to the point where drivers/usb/gadget/udc/bcm63xx_udc.c becomes DT aware.

Other than that, this looks good to me!

Signature · 1 line
Florian
#3 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

Hello Florian,

Quoted 54 lines · Florian Fainelli
Quoted 49 lines · Álvaro Fernández Rojas

Document BCM63xx USBH PHY bindings.

---
.../bindings/phy/brcm,bcm63xx-usbh-phy.yaml | 72 +++++++++++++++++++

1 file changed, 72 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +35 -0
new file mode 100644
index 000000000000..3e7c97799b91
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/phy/brcm,bcm63xx-usbh-phy.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: BCM63xx USBH PHY
+
+maintainers:
+  - Álvaro Fernández Rojas <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm6318-usbh-phy
+      - brcm,bcm6328-usbh-phy
+      - brcm,bcm6358-usbh-phy
+      - brcm,bcm6362-usbh-phy
+      - brcm,bcm6368-usbh-phy
+      - brcm,bcm63268-usbh-phy
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: usbh
+      - const: usb_ref
+
+  resets:
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml line 37

Quoted 2 lines
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +2 -0
+  "#phy-cells":
+    const: 0

On 6328, the same register space allows the controlling of the USB PHY in either host or device mode, so I believe you would need to add a #phy-cells = 1 in order to distinguish the consumer (host versus device) if we get to the point where drivers/usb/gadget/udc/bcm63xx_udc.c becomes DT aware.

I’m not really sure about how I should do this because there’s no definition for device phy mode in dt-bindings/phy/phy.h:
https://github.com/torvalds/linux/blob/master/include/dt-bindings/phy/phy.h#L13

Which value should I use for device mode and which one for host? Should I support both modes at the same time or are they exclusive?

Quoted 4 lines

Other than that, this looks good to me!

Signature · 1 line
Florian

Best regards,
Álvaro.

#4 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

Quoted 65 lines · Álvaro Fernández Rojas

Hello Florian,

Quoted 54 lines · Florian Fainelli
Quoted 49 lines · Álvaro Fernández Rojas

Document BCM63xx USBH PHY bindings.

---
.../bindings/phy/brcm,bcm63xx-usbh-phy.yaml | 72 +++++++++++++++++++

1 file changed, 72 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +35 -0
new file mode 100644
index 000000000000..3e7c97799b91
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/phy/brcm,bcm63xx-usbh-phy.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: BCM63xx USBH PHY
+
+maintainers:
+  - Álvaro Fernández Rojas <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm6318-usbh-phy
+      - brcm,bcm6328-usbh-phy
+      - brcm,bcm6358-usbh-phy
+      - brcm,bcm6362-usbh-phy
+      - brcm,bcm6368-usbh-phy
+      - brcm,bcm63268-usbh-phy
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: usbh
+      - const: usb_ref
+
+  resets:
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml line 37

Quoted 2 lines
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +2 -0
+  "#phy-cells":
+    const: 0

On 6328, the same register space allows the controlling of the USB PHY in either host or device mode, so I believe you would need to add a #phy-cells = 1 in order to distinguish the consumer (host versus device) if we get to the point where drivers/usb/gadget/udc/bcm63xx_udc.c becomes DT aware.

Quoted 4 lines

I’m not really sure about how I should do this because there’s no definition for device phy mode in dt-bindings/phy/phy.h:
https://github.com/torvalds/linux/blob/master/include/dt-bindings/phy/phy.h#L13

Which value should I use for device mode and which one for host?

0 for the host, which would be equivalent to not specifying the property, and 1 for the device.

Quoted 1 line

Should I support both modes at the same time or are they exclusive?

This is an OTG controller so you need to be able to dynamically re-configure the PHY to be in either device or host mode (see comment about bcm63xx_select_phy_mode), but there would not be both at the same time.

Signature · 1 line
Florian
#5 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

In reply to Florian Fainelli

Hi Florian,

Quoted 54 lines · Florian Fainelli
Quoted 49 lines · Álvaro Fernández Rojas

Document BCM63xx USBH PHY bindings.

---
.../bindings/phy/brcm,bcm63xx-usbh-phy.yaml | 72 +++++++++++++++++++

1 file changed, 72 insertions(+)

create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +35 -0
new file mode 100644
index 000000000000..3e7c97799b91
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/phy/brcm,bcm63xx-usbh-phy.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: BCM63xx USBH PHY
+
+maintainers:
+  - Álvaro Fernández Rojas <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - brcm,bcm6318-usbh-phy
+      - brcm,bcm6328-usbh-phy
+      - brcm,bcm6358-usbh-phy
+      - brcm,bcm6362-usbh-phy
+      - brcm,bcm6368-usbh-phy
+      - brcm,bcm63268-usbh-phy
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: usbh
+      - const: usb_ref
+
+  resets:
+    maxItems: 1
+
Quoted 8 lines

Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml line 37

Quoted 2 lines
Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml new file +2 -0
+  "#phy-cells":
+    const: 0

On 6328, the same register space allows the controlling of the USB PHY in either host or device mode, so I believe you would need to add a #phy-cells = 1 in order to distinguish the consumer (host versus device) if we get to the point where drivers/usb/gadget/udc/bcm63xx_udc.c becomes DT aware.

I’ve just realized that I have implemented this wrong in v3, because I implemented the SwapControl USB_DEVICE_SEL value, and you meant the UTMIControl1 USB_DEVICE_MODE_SEL value. So I have a couple of questions about this, because I haven’t got any bcm63xx with usb device configuration to test:
- Is USB_DEVICE_SEL also needed in SwapControl or do we only need USB_DEVICE_MODE_SEL in UTMIControl1?
- Are the rest of the host values needed when configured in device mode? Should I only set the device values when in device mode?

Quoted 4 lines

Other than that, this looks good to me!

Signature · 1 line
Florian

Best regards,
Álvaro.

#6 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

Quoted 7 lines · Álvaro Fernández Rojas
Quoted 5 lines

On 6328, the same register space allows the controlling of the USB PHY in either host or device mode, so I believe you would need to add a #phy-cells = 1 in order to distinguish the consumer (host versus device) if we get to the point where drivers/usb/gadget/udc/bcm63xx_udc.c becomes DT aware.

I’ve just realized that I have implemented this wrong in v3, because I implemented the SwapControl USB_DEVICE_SEL value, and you meant the UTMIControl1 USB_DEVICE_MODE_SEL value.

Right that is the register I was referring to.

Quoted 2 lines

So I have a couple of questions about this, because I haven’t got any bcm63xx with usb device configuration to test:
- Is USB_DEVICE_SEL also needed in SwapControl or do we only need USB_DEVICE_MODE_SEL in UTMIControl1?

It looks like it depends on the device, for 6318 and 63268, there is USB_DEVICE_MODE_SEL defined, but not for 6328, 6362 or 6368 for instance. Note that USB_DEVICE_MODE_SEL is relevant for port 2 only for 6318 and 63268 whereas the UTMI_CONTROL1 appears to be for any port.

Quoted 1 line

- Are the rest of the host values needed when configured in device mode? Should I only set the device values when in device mode?

They could probably be configured although I am not sure they sure they will be used at all, it's been a while since I looked at this (over 8 years).

I don't know if you have any board with USB device mode capability, if you do not please email privately and I will ship you one.

Signature · 1 line
Florian
maintainer
#7 lore raw

Re: [PATCH 1/2] dt-bindings: phy: add bcm63xx-usbh bindings

In reply to Álvaro Fernández Rojas
Quoted 8 lines · Álvaro Fernández Rojas

Document BCM63xx USBH PHY bindings.

---
 .../bindings/phy/brcm,bcm63xx-usbh-phy.yaml   | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.yaml

My bot found errors running 'make dt_binding_check' on your patch:

Error: Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.example.dts:22.33-34 syntax error
FATAL ERROR: Unable to parse input tree
scripts/Makefile.lib:315: recipe for target 'Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.example.dt.yaml' failed make[1]: *** [Documentation/devicetree/bindings/phy/brcm,bcm63xx-usbh-phy.example.dt.yaml] Error 1
make[1]: *** Waiting for unfinished jobs....
Makefile:1347: recipe for target 'dt_binding_check' failed
make: *** [dt_binding_check] Error 2

See https://patchwork.ozlabs.org/patch/1310130

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure dt-schema is up to date:

pip3 install git+https://github.com/devicetree-org/dt-schema.git@master --upgrade

Please check and re-submit.

#8 lore raw

PATCH 2/2 phy: bcm63xx-usbh: Add BCM63xx USBH driver

In reply to Álvaro Fernández Rojas

Add BCM63xx USBH PHY driver for BMIPS.

---
 drivers/phy/broadcom/Kconfig            |  10 +
 drivers/phy/broadcom/Makefile           |   1 +
 drivers/phy/broadcom/phy-bcm63xx-usbh.c | 463 ++++++++++++++++++++++++
 3 files changed, 474 insertions(+)
 create mode 100644 drivers/phy/broadcom/phy-bcm63xx-usbh.c
drivers/phy/broadcom/Kconfig +10 -0
index b29f11c19155..896506c7b1f8 100644
@@ -2,6 +2,16 @@
 #
 # Phy drivers for Broadcom platforms
 #
+config PHY_BCM63XX_USBH
+	tristate "BCM63xx USBH PHY driver"
+	depends on BMIPS_GENERIC || COMPILE_TEST
+	depends on OF
+	select GENERIC_PHY
+	default BMIPS_GENERIC
+	help
+	  Enable this to support the BCM63xx USBH PHY driver.
+	  If unsure, say N.
+
 config PHY_CYGNUS_PCIE
 	tristate "Broadcom Cygnus PCIe PHY driver"
 	depends on OF && (ARCH_BCM_CYGNUS || COMPILE_TEST)
drivers/phy/broadcom/Makefile +1 -0
index c78de546135c..7024127f86ad 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PHY_BCM63XX_USBH)		+= phy-bcm63xx-usbh.o
 obj-$(CONFIG_PHY_CYGNUS_PCIE)		+= phy-bcm-cygnus-pcie.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)		+= phy-bcm-kona-usb2.o
 obj-$(CONFIG_PHY_BCM_NS_USB2)		+= phy-bcm-ns-usb2.o
drivers/phy/broadcom/phy-bcm63xx-usbh.c new file +463 -0

463 lines not on this page · raw message

Signature · 1 line
2.27.0
#9 lore raw
Quoted 3 lines · Álvaro Fernández Rojas

Add BCM63xx USBH PHY driver for BMIPS.

This looks good to me at first glance, just a few comments below.

Quoted 12 lines
---
 drivers/phy/broadcom/Kconfig            |  10 +
 drivers/phy/broadcom/Makefile           |   1 +
 drivers/phy/broadcom/phy-bcm63xx-usbh.c | 463 ++++++++++++++++++++++++
 3 files changed, 474 insertions(+)
 create mode 100644 drivers/phy/broadcom/phy-bcm63xx-usbh.c
drivers/phy/broadcom/Kconfig +0 -0
index b29f11c19155..896506c7b1f8 100644

drivers/phy/broadcom/Kconfig line 8

Quoted 7 lines
drivers/phy/broadcom/Kconfig +4 -0
@@ -2,6 +2,16 @@
 #
 # Phy drivers for Broadcom platforms
 #
+config PHY_BCM63XX_USBH
+	tristate "BCM63xx USBH PHY driver"
+	depends on BMIPS_GENERIC || COMPILE_TEST
+	depends on OF

I do not think you need to add the depends on OF here if you use device_get_match_data() instead of of_device_get_match_data() and devm_of_phy_provider_register() has an inline stub provided when CONFIG_OF=n.

[snip]

Quoted 4 lines
drivers/phy/broadcom/Kconfig +4 -0
+static int __init bcm63xx_usbh_phy_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct bcm63xx_usbh_phy	*usbh;

drivers/phy/broadcom/Kconfig

Quoted 10 lines
drivers/phy/broadcom/Kconfig +10 -0
+	const struct bcm63xx_usbh_phy_variant *variant;
+	struct resource *res;
+	struct phy *phy;
+	struct phy_provider *phy_provider;
+
+	usbh = devm_kzalloc(dev, sizeof(*usbh), GFP_KERNEL);
+	if (!usbh)
+		return -ENOMEM;
+
+	variant = of_device_get_match_data(dev);

We can use device_get_match_data() to be OF independent.

drivers/phy/broadcom/Kconfig

Quoted 3 lines
drivers/phy/broadcom/Kconfig +3 -0
+	if (!variant)
+		return -EINVAL;
+	memcpy(&usbh->variant, variant, sizeof(*variant));

I would just avoid marking the variant tables with __initconst, and just reference them directly here.

Quoted 5 lines
drivers/phy/broadcom/Kconfig +5 -0
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	usbh->base = devm_ioremap_resource(dev, res);
+	if (IS_ERR(usbh->base))
+		return PTR_ERR(usbh->base);

drivers/phy/broadcom/Kconfig

Quoted 10 lines
drivers/phy/broadcom/Kconfig +10 -0
+
+	usbh->reset = devm_reset_control_get(dev, NULL);
+	if (IS_ERR(usbh->reset)) {
+		if (PTR_ERR(usbh->reset) != -EPROBE_DEFER)
+			dev_err(dev, "failed to get reset\n");
+		return PTR_ERR(usbh->reset);
+	}
+
+	if (variant->has_usb_clk) {
+		usbh->usbh_clk = devm_clk_get(dev, "usbh");

You can use devm_clk_get_optional() which would save you from having to record whether the clock is needed or not.

drivers/phy/broadcom/Kconfig

Quoted 11 lines
drivers/phy/broadcom/Kconfig +11 -0
+		if (IS_ERR(usbh->usbh_clk)) {
+			if (PTR_ERR(usbh->usbh_clk) != -EPROBE_DEFER)
+				dev_err(dev, "failed to get usbh clock\n");
+			return PTR_ERR(usbh->usbh_clk);
+		}
+	} else {
+		usbh->usbh_clk = NULL;
+	}
+
+	if (variant->has_usb_ref_clk) {
+		usbh->usb_ref_clk = devm_clk_get(dev, "usb_ref");

Likewise.

Signature · 1 line
Florian