Skip to contentSkip to conversation

Add support for nuvoton ma35 usb2 phy

PATCH Superseded Hui-Ping Chen 3 participants 8 messages Aug 1, 2024 – Aug 2, 2024

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Add support for nuvoton ma35 usb2 phy

This patch series adds the usb2 phy driver for the nuvoton ma35 ARMv8 SoC. It includes DT binding documentation and the ma35 usb2 phy driver.

v3:
- Update nuvoton,ma35d1-usb2-phy.yaml
- Update the syscon usage description.

v2:
- Update nuvoton,ma35d1-usb2-phy.yaml
- Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'.
- Remove unnecessary descriptions.
- Add explanations related to SYS.
- Update ma35d1 usb2 phy driver
- Update the 'nuvoton,ma35-usb2-phy' to 'nuvoton,ma35d1-usb2-phy'.
- Use readl_poll_timeout() to make the system more efficient and the code more streamlined.
- Use the same variable name. Update the 'p_phy->dev' to 'pdev->dev'.

Hui-Ping Chen (2):
dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings
phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

 .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml |  45 ++++++
 drivers/phy/Kconfig                           |   1 +
 drivers/phy/Makefile                          |   1 +
 drivers/phy/nuvoton/Kconfig                   |  13 ++
 drivers/phy/nuvoton/Makefile                  |   3 +
 drivers/phy/nuvoton/phy-ma35d1-usb2.c         | 146 ++++++++++++++++++
 6 files changed, 209 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml
 create mode 100644 drivers/phy/nuvoton/Kconfig
 create mode 100644 drivers/phy/nuvoton/Makefile
 create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/2 dt-bindings: phy: nuvoton,ma35-usb2-phy: add new bindings

Add dt-bindings for USB2 PHY found on the Nuvoton MA35 SoC.

---
 .../bindings/phy/nuvoton,ma35d1-usb2-phy.yaml | 45 +++++++++++++++++++
 1 file changed, 45 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml
Documentation/devicetree/bindings/phy/nuvoton,ma35d1-usb2-phy.yaml new file +45 -0
new file mode 100644
index 000000000000..fff858c909a0
@@ -0,0 +1,45 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/nuvoton,ma35d1-usb2-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Nuvoton MA35D1 USB2 phy
+
+maintainers:
+  - Hui-Ping Chen <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - nuvoton,ma35d1-usb2-phy
+
+  "#phy-cells":
+    const: 0
+
+  clocks:
+    maxItems: 1
+
+  nuvoton,sys:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to syscon for checking the PHY clock status.
+
+required:
+  - compatible
+  - "#phy-cells"
+  - clocks
+  - nuvoton,sys
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/nuvoton,ma35d1-clk.h>
+
+    usb_phy: usb-phy {
+        compatible = "nuvoton,ma35d1-usb2-phy";
+        clocks = <&clk USBD_GATE>;
+        nuvoton,sys = <&sys>;
+        #phy-cells = <0>;
+    };
Signature · 1 line
2.25.1
#3 lore raw

PATCH v3 2/2 phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

In reply to Hui-Ping Chen

Nuvoton MA35 SoCs support DWC2 USB controller. Add the driver to drive the USB 2.0 PHY transceivers.

---
 drivers/phy/Kconfig                   |   1 +
 drivers/phy/Makefile                  |   1 +
 drivers/phy/nuvoton/Kconfig           |  13 +++
 drivers/phy/nuvoton/Makefile          |   3 +
 drivers/phy/nuvoton/phy-ma35d1-usb2.c | 146 ++++++++++++++++++++++++++
 5 files changed, 164 insertions(+)
 create mode 100644 drivers/phy/nuvoton/Kconfig
 create mode 100644 drivers/phy/nuvoton/Makefile
 create mode 100644 drivers/phy/nuvoton/phy-ma35d1-usb2.c
drivers/phy/Kconfig +1 -0
index dfab1c66b3e5..f73abff416be 100644
@@ -95,6 +95,7 @@ source "drivers/phy/mediatek/Kconfig"
 source "drivers/phy/microchip/Kconfig"
 source "drivers/phy/motorola/Kconfig"
 source "drivers/phy/mscc/Kconfig"
+source "drivers/phy/nuvoton/Kconfig"
 source "drivers/phy/qualcomm/Kconfig"
 source "drivers/phy/ralink/Kconfig"
 source "drivers/phy/realtek/Kconfig"
drivers/phy/Makefile +1 -0
index 5fcbce5f9ab1..ebc399560da4 100644
@@ -25,6 +25,7 @@ obj-y					+= allwinner/	\
 					   microchip/	\
 					   motorola/	\
 					   mscc/	\
+					   nuvoton/	\
 					   qualcomm/	\
 					   ralink/	\
 					   realtek/	\
drivers/phy/nuvoton/Kconfig new file +13 -0
new file mode 100644
index 000000000000..270ee2943287
@@ -0,0 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# PHY drivers for Nuvoton MA35 platforms
+#
+config PHY_MA35_USB
+	tristate "Nuvoton MA35 USB2.0 PHY driver"
+	depends on ARCH_MA35 || COMPILE_TEST
+	depends on OF
+	select GENERIC_PHY
+	help
+	  Enable this to support the USB2.0 PHY on the Nuvoton MA35
+	  series SoCs.
+
drivers/phy/nuvoton/Makefile new file +3 -0
new file mode 100644
index 000000000000..2937e3921898
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_PHY_MA35_USB)		+= phy-ma35d1-usb2.o
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +146 -0

146 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

…

Quoted 2 lines

+++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c

(quoted diff) +0 -0
@@ -0,0 +1,146 @@

…

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 145

Quoted 2 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +2 -0
+MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver");
+MODULE_AUTHOR("[email protected]");

…

How do you think about to add a personal name to such an email address?

Regards,
Markus

#5 lore raw

Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

Dear Markus,

Thank you for your reply.

Quoted 9 lines · Markus Elfring

…

Quoted 2 lines

+++ b/drivers/phy/nuvoton/phy-ma35d1-usb2.c

(quoted diff) +0 -0
@@ -0,0 +1,146 @@

…

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 145

Quoted 2 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +2 -0
+MODULE_DESCRIPTION("Nuvoton ma35d1 USB2.0 PHY driver");
+MODULE_AUTHOR("[email protected]");

…

How do you think about to add a personal name to such an email address?

I'm sorry. I forgot to put my name here. I'll make it up.

Quoted 2 lines

Regards,
Markus

Best regards,

Hui-Ping Chen

#6 lore raw

Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

In reply to Hui-Ping Chen

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 27

Quoted 1 line · Hui-Ping Chen
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +1 -0
+	struct regmap *sysreg;

Look here - iomem? No.

Quoted 11 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +11 -0
+};
+
+static int ma35_usb_phy_power_on(struct phy *phy)
+{
+	struct ma35_usb_phy *p_phy = phy_get_drvdata(phy);
+	unsigned int val;
+	int ret;
+
+	ret = clk_prepare_enable(p_phy->clk);
+	if (ret < 0) {
+		dev_err(p_phy->dev, "Failed to enable PHY clock: %d\n", ret);

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 48

Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +10 -0
+		return ret;
+	}
+
+	regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
+	if (val & PHY0SUSPEND) {
+		/*
+		 * USB PHY0 is in operation mode already
+		 * make sure USB PHY 60 MHz UTMI Interface Clock ready
+		 */
+		ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR,

Eh, I responded to v2, not here, so repeating:

sysreg is a regmap, not io address. How could it possibly work and be tested?!? This cannot work. Test your code *before* sending it.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v3 2/2] phy: nuvoton: add new driver for the Nuvoton MA35 SoC USB 2.0 PHY

Dear Krzysztof,

Thank you for your reply.

Quoted 3 lines · Krzysztof Kozlowski

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 27

Quoted 1 line · Hui-Ping Chen
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +1 -0
+	struct regmap *sysreg;

Look here - iomem? No.

Yes, this is my mistake.

Quoted 23 lines
Quoted 11 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +11 -0
+};
+
+static int ma35_usb_phy_power_on(struct phy *phy)
+{
+	struct ma35_usb_phy *p_phy = phy_get_drvdata(phy);
+	unsigned int val;
+	int ret;
+
+	ret = clk_prepare_enable(p_phy->clk);
+	if (ret < 0) {
+		dev_err(p_phy->dev, "Failed to enable PHY clock: %d\n", ret);

drivers/phy/nuvoton/phy-ma35d1-usb2.c line 48

Quoted 10 lines
drivers/phy/nuvoton/phy-ma35d1-usb2.c new file +10 -0
+		return ret;
+	}
+
+	regmap_read(p_phy->sysreg, MA35_SYS_REG_USBPMISCR, &val);
+	if (val & PHY0SUSPEND) {
+		/*
+		 * USB PHY0 is in operation mode already
+		 * make sure USB PHY 60 MHz UTMI Interface Clock ready
+		 */
+		ret = readl_poll_timeout((void __iomem *)p_phy->sysreg + MA35_SYS_REG_USBPMISCR,

Eh, I responded to v2, not here, so repeating:

Quoted 3 lines

sysreg is a regmap, not io address. How could it possibly work and be tested?!? This cannot work. Test your code *before* sending it.

Yes, this is my mistake. I won't reply to v2. I will reply here.

I would change 'readl_poll_timeout' to 'regmap_read_poll_timeout'.

And it has been tested OK on our platform.

Quoted 2 lines

Best regards,
Krzysztof

Best regards,

Hui-Ping Chen