linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Herve Codina <herve.codina@bootlin.com>
To: Geert Uytterhoeven <geert+renesas@glider.be>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Herve Codina <herve.codina@bootlin.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Gareth Williams <gareth.williams.jx@renesas.com>
Cc: linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-usb@vger.kernel.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Miquel Raynal <miquel.raynal@bootlin.com>
Subject: [PATCH v3 6/9] soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF presence
Date: Wed,  7 Dec 2022 17:24:32 +0100	[thread overview]
Message-ID: <20221207162435.1001782-7-herve.codina@bootlin.com> (raw)
In-Reply-To: <20221207162435.1001782-1-herve.codina@bootlin.com>

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.

Signed-off-by: Herve Codina <herve.codina@bootlin.com>
---
 drivers/clk/renesas/r9a06g032-clocks.c | 28 ++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/drivers/clk/renesas/r9a06g032-clocks.c b/drivers/clk/renesas/r9a06g032-clocks.c
index 1488c9d6e639..8a09ba79b97f 100644
--- a/drivers/clk/renesas/r9a06g032-clocks.c
+++ b/drivers/clk/renesas/r9a06g032-clocks.c
@@ -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 {
@@ -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 ?
-- 
2.38.1


  parent reply	other threads:[~2022-12-07 16:25 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07 16:24 [PATCH v3 0/9] Add the Renesas USBF controller support Herve Codina
2022-12-07 16:24 ` [PATCH v3 1/9] dt-bindings: PCI: renesas,pci-rcar-gen2: Add depends-on for RZ/N1 SoC family Herve Codina
2022-12-07 16:24 ` [PATCH v3 2/9] ARM: dts: r9a06g032: Add dependency to sysctrl in the PCI bridge Herve Codina
2022-12-07 16:24 ` [PATCH v3 3/9] dt-bindings: PCI: renesas,pci-rcar-gen2: 'depends-on' is no more optional Herve Codina
2022-12-08  8:26   ` Krzysztof Kozlowski
2022-12-08  9:05     ` Herve Codina
2022-12-08  9:46       ` Krzysztof Kozlowski
2022-12-08 15:51         ` Herve Codina
2022-12-09  8:06           ` Krzysztof Kozlowski
2022-12-13 13:22             ` Herve Codina
2022-12-07 16:24 ` [PATCH v3 4/9] of: property: fw_devlink: Add support for "depends-on" Herve Codina
2022-12-07 16:24 ` [PATCH v3 5/9] dt-bindings: usb: add the Renesas RZ/N1 USBF controller Herve Codina
2022-12-07 16:24 ` Herve Codina [this message]
2022-12-08  9:05   ` [PATCH v3 6/9] soc: renesas: r9a06g032-sysctrl: Handle h2mode setting based on USBF presence Geert Uytterhoeven
2022-12-13 13:28     ` Herve Codina
2022-12-07 16:24 ` [PATCH v3 7/9] usb: gadget: udc: add Renesas RZ/N1 USBF controller support Herve Codina
2022-12-07 16:24 ` [PATCH v3 8/9] ARM: dts: r9a06g032: Add the USBF controller node Herve Codina
2022-12-08  9:09   ` Geert Uytterhoeven
2022-12-13 13:27     ` Herve Codina
2022-12-07 16:24 ` [PATCH v3 9/9] MAINTAINERS: add the Renesas RZ/N1 USBF controller entry Herve Codina
2022-12-07 22:19 ` [PATCH v3 0/9] Add the Renesas USBF controller support Rob Herring
2022-12-08  8:24   ` Herve Codina
2022-12-08  9:11     ` Geert Uytterhoeven
2022-12-08 20:44     ` Rob Herring
2022-12-13 13:26       ` Herve Codina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221207162435.1001782-7-herve.codina@bootlin.com \
    --to=herve.codina@bootlin.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gareth.williams.jx@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=mturquette@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).