Add the Renesas USBF controller support
Subsystems (5)
Herve Codina
maintainerv4 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/all/[email protected]/
The 'depends-on' property was removed.
Patches 1, 3, 4 and 5 are related to the USBF controller with a new binding definition, the driver itself and myself as a maintainer of this controller.
Patch 2 handles h2mode in sysctrl.
Hope that this v4 can lead to some feedbacks on the USB device controller itself (patch 3).
Best regards,
Herve Codina
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 | 3420 +++++++++++++++++ 7 files changed, 3548 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
Herve Codina
maintainerPATCH v4 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
@@ -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
Re: [PATCH v4 1/5] dt-bindings: usb: add the Renesas RZ/N1 USBF controller
Quoted 9 lines · Herve Codina
The Renesas RZ/N1 USBF controller is an USB2.0 device controller (UDC) available in the Renesas r9a06g032 SoC (RZ/N1 family).
Signed-off-by Herve Codina <[email protected]>--- .../bindings/usb/renesas,rzn1-usbf.yaml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/usb/renesas,rzn1-usbf.yaml
Re: [PATCH v4 1/5] dt-bindings: usb: add the Renesas RZ/N1 USBF controller
In reply to Herve CodinaQuoted 4 lines · Herve Codina
The Renesas RZ/N1 USBF controller is an USB2.0 device controller (UDC) available in the Renesas r9a06g032 SoC (RZ/N1 family).
Signed-off-by Herve Codina <[email protected]>
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
Herve Codina
maintainerPATCH v4 2/5 soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF presence
In reply to Herve CodinaThe 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
@@ -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 0xA0struct r9a06g032_gate {
@@ -919,6 +921,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;
@@ -948,6 +973,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
Herve Codina
maintainerPATCH v4 3/5 usb: gadget: udc: add Renesas RZ/N1 USBF controller support
In reply to Herve CodinaAdd 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 | 3420 +++++++++++++++++++++++++ 3 files changed, 3432 insertions(+) create mode 100644 drivers/usb/gadget/udc/renesas_usbf.c
drivers/usb/gadget/udc/Kconfig +11 -0
@@ -204,6 +204,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
@@ -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 +3420 -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.
Re: [PATCH v4 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support
Hi Hervé,
Quoted 5 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).Signed-off-by Herve Codina <[email protected]>
Thanks for your patch!
Quoted 4 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +1
-0+#ifdef DEBUG
drivers/usb/gadget/udc/renesas_usbf.c line 35
Quoted 10 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +10
-0+#define TRACE (_fmt, ...) trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__) +#define USBF_TRACE_EP_MASK 0x0ffff/* All the 16 endpoints */ +#define TRACEEP (_ep, _fmt, ...) \ + do { \ + if ((1 << (_ep)->id) & USBF_TRACE_EP_MASK) \ + trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define TRACE (_fmt, ...) do { } while (0) +#define TRACEEP (_ep, _fmt, ...) do { } while (0)
Please use "no_printk(fmt, ##__VA_ARGS__)" instead of dummy loops, to avoid bad callers going unnoticed if DEBUG is not defined.
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
Greg Kroah-Hartman
maintainerRe: [PATCH v4 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support
Quoted 14 lines · Geert Uytterhoeven
Hi Hervé,
Quoted 5 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).Signed-off-by Herve Codina <[email protected]>Thanks for your patch!
Quoted 2 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +0
-0
Quoted 14 lines
drivers/usb/gadget/udc/renesas_usbf.c line 35
Quoted 11 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +11
-0+#ifdef DEBUG +#define TRACE (_fmt, ...) trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__) +#define USBF_TRACE_EP_MASK 0x0ffff/* All the 16 endpoints */ +#define TRACEEP (_ep, _fmt, ...) \ + do { \ + if ((1 << (_ep)->id) & USBF_TRACE_EP_MASK) \ + trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define TRACE (_fmt, ...) do { } while (0) +#define TRACEEP (_ep, _fmt, ...) do { } while (0)Please use "
no_printk(fmt, ##__VA_ARGS__)" instead of dummy loops, to avoid bad callers going unnoticed if DEBUG is not defined.
Even better, do NOT define custom debug/trace macros for a single driver, just use the ones that the rest of the kernel uses instead please.
thanks,
greg k-h
Herve Codina
maintainerRe: [PATCH v4 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support
Hi Geert, Greg,
Quoted 30 lines · On Wed, 21 Dec 2022 14:07:53 +0100 Greg Kroah-Hartman…
Quoted 14 lines · Geert Uytterhoeven
Hi Hervé,
Quoted 5 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).Signed-off-by Herve Codina <[email protected]>Thanks for your patch!
Quoted 2 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +0
-0Quoted 14 lines
drivers/usb/gadget/udc/renesas_usbf.c line 35
Quoted 11 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +11
-0+#ifdef DEBUG +#define TRACE (_fmt, ...) trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__) +#define USBF_TRACE_EP_MASK 0x0ffff/* All the 16 endpoints */ +#define TRACEEP (_ep, _fmt, ...) \ + do { \ + if ((1 << (_ep)->id) & USBF_TRACE_EP_MASK) \ + trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define TRACE (_fmt, ...) do { } while (0) +#define TRACEEP (_ep, _fmt, ...) do { } while (0)Please use "
no_printk(fmt, ##__VA_ARGS__)" instead of dummy loops, to avoid bad callers going unnoticed if DEBUG is not defined.
Quoted 7 lines
Even better, do NOT define custom debug/trace macros for a single driver, just use the ones that the rest of the kernel uses instead please.
thanks,
greg k-h
I would like to keep some granularity in debug messages and also keep the function name automatically added.
I propose 3 kinds of messages:
- general ones,
- specific Endpoint0 ones,
- other Endpoints ones.
So before doing any modification in the source code, what do you think about:
/*
* Suggested tracers:
* - no_printk: Disable tracing
* - trace_printk: Print to trace buffer
*/
#define usbf_dbg(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__)
#define usbf_dbg_ep0(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__)
#define usbf_dbg_epn(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__)The code will use only these macros instead of the previously defined TRACE and TRACEEP as follow:
- usbf_dbg() will be called instead of TRACE()
- usbf_dbg_ep0() will be called instead of TRACEEP() for Endpoint0
- usbf_dbg_epn() will be called instead of TRACEEP() for other Endpoints
Is that ok for you ?
Best regards,
Hervé
Signature · 3 lines
Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Greg Kroah-Hartman
maintainerRe: [PATCH v4 3/5] usb: gadget: udc: add Renesas RZ/N1 USBF controller support
Quoted 41 lines · Herve Codina
Hi Geert, Greg,
Quoted 36 lines · On Wed, 21 Dec 2022 14:07:53 +0100 Greg Kroah-Hartman…
Quoted 14 lines · Geert Uytterhoeven
Hi Hervé,
Quoted 5 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).Signed-off-by Herve Codina <[email protected]>Thanks for your patch!
Quoted 2 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +0
-0Quoted 14 lines
drivers/usb/gadget/udc/renesas_usbf.c line 35
Quoted 11 lines
drivers/usb/gadget/udc/renesas_usbf.c new file +11
-0+#ifdef DEBUG +#define TRACE (_fmt, ...) trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__) +#define USBF_TRACE_EP_MASK 0x0ffff/* All the 16 endpoints */ +#define TRACEEP (_ep, _fmt, ...) \ + do { \ + if ((1 << (_ep)->id) & USBF_TRACE_EP_MASK) \ + trace_printk("%s: " _fmt, __func__, ##__VA_ARGS__); \ + } while (0) +#else +#define TRACE (_fmt, ...) do { } while (0) +#define TRACEEP (_ep, _fmt, ...) do { } while (0)Please use "
no_printk(fmt, ##__VA_ARGS__)" instead of dummy loops, to avoid bad callers going unnoticed if DEBUG is not defined.Even better, do NOT define custom debug/trace macros for a single driver, just use the ones that the rest of the kernel uses instead please.
thanks,
Quoted 8 lines
Quoted 1 line
greg k-h
I would like to keep some granularity in debug messages and also keep the function name automatically added.
I propose 3 kinds of messages:
- general ones,
- specific Endpoint0 ones,
- other Endpoints ones.
All of those can work just fine using dev_dbg() today, no need to make anything special for the driver. You can turn those messages on/off with no need to ever rebuild your driver, which is the key point.
Quoted 10 lines
So before doing any modification in the source code, what do you think about:
/* * Suggested tracers: * - no_printk: Disable tracing * - trace_printk: Print to trace buffer */ #define usbf_dbg(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__) #define usbf_dbg_ep0(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__) #define usbf_dbg_epn(_fmt, ...) no_printk("%s: " _fmt, __func__, ##__VA_ARGS__)
Nope, just use dev_dbg() only please. It provides MUCH more funcationality and a unified interface with the rest of the kernel. Please do not attempt to "roll your own" version of debugging macros for just a single driver.
thanks,
greg k-h
Herve Codina
maintainerPATCH v4 4/5 ARM: dts: r9a06g032: Add the USBF controller node
In reply to Herve CodinaAdd 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
@@ -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
Herve Codina
maintainerPATCH v4 5/5 MAINTAINERS: add the Renesas RZ/N1 USBF controller entry
In reply to Herve CodinaAfter contributing the driver, add myself as the maintainer for Renesas RZ/N1 USBF controller.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -17632,6 +17632,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