Skip to contentSkip to conversation

Add the Renesas USBF controller support

PATCH In review Herve Codina 3 participants 9 messages Jan 5, 2023 – Mar 17, 2024

Subsystems (5)
lore
Share & tools
lore

Herve Codina

author maintainer
#0 lore raw

v5 cover Add the Renesas USBF controller support

Hi,

This series add support for the Renesas USBF controller (USB Device Controller) available in the Renesas RZ/N1 SoC.

Based on previous iteration:
https://lore.kernel.org/lkml/[email protected]/
Custom debug macros present in the controller driver source code have been replaced by dev_dbg() calls.

Best regards,
Herve Codina

Changes v4 -> v5:
- patch 1
Add 'Reviewed-by: Rob Herring <[email protected]>'
Add 'Reviewed-by: Geert Uytterhoeven <[email protected]>'

- patch 3
Remove custom TRACE() and TRACEEP() debug macros and use directly dev_dbg() instead.

- patch 2, 4 and 5
No changes

Changes v3 -> v4:
- v3 patches 1, 2, 3 and 4 removed

- Patch 1 (v3 patch 5)
Remove 'depends-on' property

- Patch 2 (v3 patch 6)
Add 'Reviewed-by: Geert Uytterhoeven <[email protected]>'

- Patch 3 (v3 patch 7)
Fix warning raised by the kernel test robot

- Patch 4 (v3 patch 8)
Remove 'depends-on' property
add 'Reviewed-by: Geert Uytterhoeven <[email protected]>'

- Patch 5 (v3 patch 9)
No changes

Changes v2 -> v3:
- v2 Patches 1, 2 and 3 removed.

- Patches 1, 2, 3 and 4 (new patches)

- Patch 5 (v2 patch 4):
Add 'depends-on' property
Removed redundant 'binding' word

- Patch 6 (new patch)

- Patch 7 (v2 patch 5)
Removed h2mode checking. This check is no more needed and the API no more available.

- Patch 8 (v2 patch 6)
Add 'depends-on' property

- Patch 9 (v2 patch 7)
Fix file name

Changes v1 -> v2:
- Patch 1:
Rename r9a06g032_sysctrl_get_usb_h2mode to r9a06g032_sysctrl_get_usb_role and return USB_ROLE_{HOST,DEVICE} or an error code.
Reword commit log

- Patches 2 and 3:

    No changes. Some previous feedbacks still need to be taken into account
      https://lore.kernel.org/all/[email protected]/
      https://lore.kernel.org/all/[email protected]/

- Patch 4:
Rename file from renesas,usbf.yaml to renesas,rzn1-usbf.yaml. Remove 'oneOf'.
Add blank line and line break.
Add 'power-domains'.
Reword commit log

- Patch 5:
Remove clocks handling (handled by runtime PM through the clock domain pointed by power-domains).
Fix compilation warning raised by the 'kernel test robot'.

- Patch 6:
Add 'power-domains'

- Patch 7:
Add 'Reviewed-by: Geert Uytterhoeven <[email protected]>'

Herve Codina (5):
dt-bindings: usb: add the Renesas RZ/N1 USBF controller
soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF
presence
usb: gadget: udc: add Renesas RZ/N1 USBF controller support
ARM: dts: r9a06g032: Add the USBF controller node
MAINTAINERS: add the Renesas RZ/N1 USBF controller entry

 .../bindings/usb/renesas,rzn1-usbf.yaml       |   68 +
 MAINTAINERS                                   |    8 +
 arch/arm/boot/dts/r9a06g032.dtsi              |   12 +
 drivers/clk/renesas/r9a06g032-clocks.c        |   28 +
 drivers/usb/gadget/udc/Kconfig                |   11 +
 drivers/usb/gadget/udc/Makefile               |    1 +
 drivers/usb/gadget/udc/renesas_usbf.c         | 3406 +++++++++++++++++
 7 files changed, 3534 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/renesas,rzn1-usbf.yaml
 create mode 100644 drivers/usb/gadget/udc/renesas_usbf.c
Signature · 1 line
2.38.1
author maintainer
#1 lore raw

PATCH v5 1/5 dt-bindings: usb: add the Renesas RZ/N1 USBF controller

The Renesas RZ/N1 USBF controller is an USB2.0 device controller (UDC) available in the Renesas r9a06g032 SoC (RZ/N1 family).

---
 .../bindings/usb/renesas,rzn1-usbf.yaml       | 68 +++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/renesas,rzn1-usbf.yaml
Documentation/devicetree/bindings/usb/renesas,rzn1-usbf.yaml new file +68 -0
new file mode 100644
index 000000000000..b6e84a2a6925
@@ -0,0 +1,68 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/renesas,rzn1-usbf.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas RZ/N1 SoCs USBF (USB Function) controller
+
+description: |
+   The Renesas USBF controller is an USB2.0 device
+   controller (UDC).
+
+maintainers:
+  - Herve Codina <[email protected]>
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - renesas,r9a06g032-usbf
+      - const: renesas,rzn1-usbf
+
+  reg:
+    maxItems: 1
+
+  clocks:
+    items:
+      - description: Internal bus clock (AHB) for Function
+      - description: Internal bus clock (AHB) for Power Management
+
+  clock-names:
+    items:
+      - const: hclkf
+      - const: hclkpm
+
+  power-domains:
+    maxItems: 1
+
+  interrupts:
+    items:
+      - description: The USBF EPC interrupt
+      - description: The USBF AHB-EPC interrupt
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - power-domains
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/r9a06g032-sysctrl.h>
+
+    usb@4001e000 {
+        compatible = "renesas,r9a06g032-usbf", "renesas,rzn1-usbf";
+        reg = <0x4001e000 0x2000>;
+        interrupts = <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&sysctrl R9A06G032_HCLK_USBF>,
+                 <&sysctrl R9A06G032_HCLK_USBPM>;
+        clock-names = "hclkf", "hclkpm";
+        power-domains = <&sysctrl>;
+    };
Signature · 1 line
2.38.1
author maintainer
#2 lore raw

PATCH v5 2/5 soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF presence

In reply to Herve Codina

The CFG_USB[H2MODE] allows to switch the USB configuration. The configuration supported are:
- One host and one device
or
- Two hosts

Set CFG_USB[H2MODE] based on the USBF controller (USB device) availability.

---
 drivers/clk/renesas/r9a06g032-clocks.c | 28 ++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
drivers/clk/renesas/r9a06g032-clocks.c +28 -0
index 983faa5707b9..087146f2ee06 100644
@@ -25,6 +25,8 @@
 #include <linux/spinlock.h>
 #include <dt-bindings/clock/r9a06g032-sysctrl.h>
 
+#define R9A06G032_SYSCTRL_USB    0x00
+#define R9A06G032_SYSCTRL_USB_H2MODE  (1<<1)
 #define R9A06G032_SYSCTRL_DMAMUX 0xA0
 
 struct r9a06g032_gate {
@@ -918,6 +920,29 @@ static void r9a06g032_clocks_del_clk_provider(void *data)
 	of_clk_del_provider(data);
 }
 
+static void __init r9a06g032_init_h2mode(struct r9a06g032_priv *clocks)
+{
+	struct device_node *usbf_np = NULL;
+	u32 usb;
+
+	while ((usbf_np = of_find_compatible_node(usbf_np, NULL,
+						  "renesas,rzn1-usbf"))) {
+		if (of_device_is_available(usbf_np))
+			break;
+	}
+
+	usb = readl(clocks->reg + R9A06G032_SYSCTRL_USB);
+	if (usbf_np) {
+		/* 1 host and 1 device mode */
+		usb &= ~R9A06G032_SYSCTRL_USB_H2MODE;
+		of_node_put(usbf_np);
+	} else {
+		/* 2 hosts mode */
+		usb |= R9A06G032_SYSCTRL_USB_H2MODE;
+	}
+	writel(usb, clocks->reg + R9A06G032_SYSCTRL_USB);
+}
+
 static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -947,6 +972,9 @@ static int __init r9a06g032_clocks_probe(struct platform_device *pdev)
 	clocks->reg = of_iomap(np, 0);
 	if (WARN_ON(!clocks->reg))
 		return -ENOMEM;
+
+	r9a06g032_init_h2mode(clocks);
+
 	for (i = 0; i < ARRAY_SIZE(r9a06g032_clocks); ++i) {
 		const struct r9a06g032_clkdesc *d = &r9a06g032_clocks[i];
 		const char *parent_name = d->source ?
Signature · 1 line
2.38.1
author maintainer
#3 lore raw

PATCH v5 3/5 usb: gadget: udc: add Renesas RZ/N1 USBF controller support

In reply to Herve Codina

Add support for the Renesas USBF controller.
This controller is an USB2.0 UDC controller available in the Renesas r9a06g032 SoC (RZ/N1 family).

---
 drivers/usb/gadget/udc/Kconfig        |   11 +
 drivers/usb/gadget/udc/Makefile       |    1 +
 drivers/usb/gadget/udc/renesas_usbf.c | 3406 +++++++++++++++++++++++++
 3 files changed, 3418 insertions(+)
 create mode 100644 drivers/usb/gadget/udc/renesas_usbf.c
drivers/usb/gadget/udc/Kconfig +11 -0
index b3006d8b04ab..12f7323869fe 100644
@@ -193,6 +193,17 @@ config USB_RENESAS_USB3
 	   dynamically linked module called "renesas_usb3" and force all
 	   gadget drivers to also be dynamically linked.
 
+config USB_RENESAS_USBF
+	tristate 'Renesas USB Function controller'
+	depends on ARCH_RENESAS || COMPILE_TEST
+	help
+	   Renesas USB Function controller is a USB peripheral controller
+	   available on RZ/N1 Renesas SoCs.
+
+	   Say "y" to link the driver statically, or "m" to build a
+	   dynamically linked module called "renesas_usbf" and force all
+	   gadget drivers to also be dynamically linked.
+
 config USB_PXA27X
 	tristate "PXA 27x"
 	depends on HAS_IOMEM
drivers/usb/gadget/udc/Makefile +1 -0
index 39daf36a2baa..1e23627733eb 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_USB_TEGRA_XUDC)	+= tegra-xudc.o
 obj-$(CONFIG_USB_M66592)	+= m66592-udc.o
 obj-$(CONFIG_USB_R8A66597)	+= r8a66597-udc.o
 obj-$(CONFIG_USB_RENESAS_USB3)	+= renesas_usb3.o
+obj-$(CONFIG_USB_RENESAS_USBF)	+= renesas_usbf.o
 obj-$(CONFIG_USB_FSL_QE)	+= fsl_qe_udc.o
 obj-$(CONFIG_USB_S3C_HSUDC)	+= s3c-hsudc.o
 obj-$(CONFIG_USB_LPC32XX)	+= lpc32xx_udc.o
drivers/usb/gadget/udc/renesas_usbf.c new file +3406 -0

2,976 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.38.1

Part of the diff is not shown here. View the raw message.

#4 lore raw

Re: [PATCH v5 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support

Quoted 3 lines · Herve Codina

Add support for the Renesas USBF controller.
This controller is an USB2.0 UDC controller available in the Renesas r9a06g032 SoC (RZ/N1 family).

I think I've done the NEC EC-4255 USBF driver for Robert Bosch
Car Multimedia, too bad it's never hit upstream... :-)

Quoted 1 line

[...]

MBR, Sergey

#5 lore raw

Re: [PATCH v5 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support

On 3/17/24 3:18 PM, Sergei Shtylyov wrote:
[...]

Quoted 6 lines
Quoted 3 lines

Add support for the Renesas USBF controller.
This controller is an USB2.0 UDC controller available in the Renesas r9a06g032 SoC (RZ/N1 family).

I think I've done the NEC EC-4255 USBF driver for Robert Bosch
Car Multimedia, too bad it's never hit upstream... :-)

EC-4260, sorry; it was mostly known to us back then as NaviEngine
(mid)...

Quoted 1 line
Quoted 1 line

[...]

MBR, Sergey

author maintainer
#6 lore raw

PATCH v5 4/5 ARM: dts: r9a06g032: Add the USBF controller node

In reply to Herve Codina

Add the USBF controller available in the r9a06g032 SoC.

---
 arch/arm/boot/dts/r9a06g032.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm/boot/dts/r9a06g032.dtsi +12 -0
index 41e19c0986ce..0fa565a1c3ad 100644
@@ -117,6 +117,18 @@ dmamux: dma-router@a0 {
 			};
 		};
 
+		udc: usb@4001e000 {
+			compatible = "renesas,r9a06g032-usbf", "renesas,rzn1-usbf";
+			reg = <0x4001e000 0x2000>;
+			interrupts = <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&sysctrl R9A06G032_HCLK_USBF>,
+				 <&sysctrl R9A06G032_HCLK_USBPM>;
+			clock-names = "hclkf", "hclkpm";
+			power-domains = <&sysctrl>;
+			status = "disabled";
+		};
+
 		pci_usb: pci@40030000 {
 			compatible = "renesas,pci-r9a06g032", "renesas,pci-rzn1";
 			device_type = "pci";
Signature · 1 line
2.38.1
author maintainer
#7 lore raw

PATCH v5 5/5 MAINTAINERS: add the Renesas RZ/N1 USBF controller entry

In reply to Herve Codina

After contributing the driver, add myself as the maintainer for Renesas RZ/N1 USBF controller.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 7f86d02cb427..ed8afef5386f 100644
@@ -17859,6 +17859,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/rtc/renesas,rzn1-rtc.yaml
 F:	drivers/rtc/rtc-rzn1.c
 
+RENESAS RZ/N1 USBF CONTROLLER DRIVER
+M:	Herve Codina <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/usb/renesas,rzn1-usbf.yaml
+F:	drivers/usb/gadget/udc/renesas_usbf.c
+
 RENESAS R-CAR GEN3 & RZ/N1 NAND CONTROLLER DRIVER
 M:	Miquel Raynal <[email protected]>
 L:	[email protected]
Signature · 1 line
2.38.1
#8 lore raw
In reply to Herve Codina

Hi Hervé,

Quoted 2 lines · Herve Codina

This series add support for the Renesas USBF controller (USB Device Controller) available in the Renesas RZ/N1 SoC.

As Greg seems to be happy with the USB patches (he took the whole (sigh) series through usb-next), I will queue

Quoted 4 lines

Herve Codina (5):
dt-bindings: usb: add the Renesas RZ/N1 USBF controller
soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF
presence

... this "clk" patch in renesas-clk-for-v6.3...

Quoted 2 lines

usb: gadget: udc: add Renesas RZ/N1 USBF controller support
ARM: dts: r9a06g032: Add the USBF controller node

... and this DT patch in renesas-devel for v6.3.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds