All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC v2 0/6] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs
@ 2018-04-26 11:26 Yoshihiro Shimoda
  2018-04-26 11:26   ` [PATCH/RFC,v2,1/6] " Yoshihiro Shimoda
                   ` (5 more replies)
  0 siblings, 6 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch set is based on renesas-drivers-2018-04-17-v4.17-rc1 tag
of renesas-drivers.git

In last week, I submitted a patch as RFC [1]. But, I completely
misunderstood the discussion of previous' one [2].

I marked this patch set as "RFC" because dtsi patch and udc patch
are not good for upstreaming (should separate a few patches).
I would like to know whether this way is good or not.

[1] https://patchwork.kernel.org/patch/10347511/
[2] https://patchwork.kernel.org/patch/10332865/

Changes from RFC:
 - Remove "device-connection-id" and "usb role switch driver" dt-bingings.
 - Remove drivers/of code.
 - Add a new API for find the connection by using graph on devcon.c and roles.c.
 - Use each new API on the rcar usb role switch and renesas_usb3 drivers.
 - Update the dtsi file for r8a7795.

Yoshihiro Shimoda (6):
  dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
  base: devcon: add a new API to find the graph
  usb: common: roles: add a new API to find the graph
  usb: role: rcar-usb3-role-switch: add support for R-Car SoCs
  usb: gadget: udc: renesas_usb3: add support for a usb role switch
  arm64: dts: renesas: r8a7795: add OF graph for usb role switch

 .../bindings/usb/renesas,rcar-usb3-role-sw.txt     |  47 +++++
 Documentation/driver-api/device_connection.rst     |   4 +-
 arch/arm64/boot/dts/renesas/r8a7795.dtsi           |  38 +++++
 drivers/base/devcon.c                              |  43 +++++
 drivers/usb/common/roles.c                         |  30 ++++
 drivers/usb/gadget/udc/Kconfig                     |   1 +
 drivers/usb/gadget/udc/renesas_usb3.c              |  34 +++-
 drivers/usb/roles/Kconfig                          |  13 ++
 drivers/usb/roles/Makefile                         |   1 +
 drivers/usb/roles/rcar-usb3-role-switch.c          | 190 +++++++++++++++++++++
 include/linux/device.h                             |   2 +
 include/linux/usb/role.h                           |   2 +
 12 files changed, 397 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
 create mode 100644 drivers/usb/roles/rcar-usb3-role-switch.c

-- 
1.9.1

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new documentation for Renesas R-Car USB 3.0 role
switch that can change the USB 3.0 role to either host or peripheral
by a hardware register that is included in USB3.0 peripheral module.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt

diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
new file mode 100644
index 0000000..e074c03
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
@@ -0,0 +1,47 @@
+Renesas Electronics R-Car USB 3.0 role switch
+
+A renesas_usb3's node can contain this node.
+
+Required properties:
+ - compatible: Must contain "renesas,rcar-usb3-role-switch".
+
+Required nodes:
+ - The connection to a usb3.0 host node needs by using OF graph bindings.
+  - port@0 = USB 3.0 host port
+  - port@1 = USB 3.0 peripheral port
+
+Example of R-Car H3 ES2.0:
+	usb3_peri0: usb@ee020000 {
+		compatible = "renesas,r8a7795-usb3-peri",
+			     "renesas,rcar-gen3-usb3-peri";
+		reg = <0 0xee020000 0 0x400>;
+		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cpg CPG_MOD 328>;
+		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+		resets = <&cpg 328>;
+
+		usb3-role-sw {
+			compatible = "renesas,rcar-usb3-role-switch";
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					usb3_host_sw: endpoint {
+						remote-endpoint = <&usb3_host_ep>;
+					};
+				};
+
+				port@1 {
+					reg = <1>;
+
+					usb3_peri_sw: endpoint {
+						remote-endpoint = <&usb3_peri_ep>;
+					};
+				};
+			};
+		};
+	};
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new documentation for Renesas R-Car USB 3.0 role
switch that can change the USB 3.0 role to either host or peripheral
by a hardware register that is included in USB3.0 peripheral module.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt

diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
new file mode 100644
index 0000000..e074c03
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
@@ -0,0 +1,47 @@
+Renesas Electronics R-Car USB 3.0 role switch
+
+A renesas_usb3's node can contain this node.
+
+Required properties:
+ - compatible: Must contain "renesas,rcar-usb3-role-switch".
+
+Required nodes:
+ - The connection to a usb3.0 host node needs by using OF graph bindings.
+  - port@0 = USB 3.0 host port
+  - port@1 = USB 3.0 peripheral port
+
+Example of R-Car H3 ES2.0:
+	usb3_peri0: usb@ee020000 {
+		compatible = "renesas,r8a7795-usb3-peri",
+			     "renesas,rcar-gen3-usb3-peri";
+		reg = <0 0xee020000 0 0x400>;
+		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cpg CPG_MOD 328>;
+		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
+		resets = <&cpg 328>;
+
+		usb3-role-sw {
+			compatible = "renesas,rcar-usb3-role-switch";
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				port@0 {
+					reg = <0>;
+
+					usb3_host_sw: endpoint {
+						remote-endpoint = <&usb3_host_ep>;
+					};
+				};
+
+				port@1 {
+					reg = <1>;
+
+					usb3_peri_sw: endpoint {
+						remote-endpoint = <&usb3_peri_ep>;
+					};
+				};
+			};
+		};
+	};

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 2/6] base: devcon: add a new API to find the graph
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new API "device_connection_find_by_graph()" to
find device connection by using graph.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 Documentation/driver-api/device_connection.rst |  4 +--
 drivers/base/devcon.c                          | 43 ++++++++++++++++++++++++++
 include/linux/device.h                         |  2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/device_connection.rst b/Documentation/driver-api/device_connection.rst
index affbc556..2e2d26f 100644
--- a/Documentation/driver-api/device_connection.rst
+++ b/Documentation/driver-api/device_connection.rst
@@ -19,7 +19,7 @@ Device connections alone do not create a dependency between the two devices.
 They are only descriptions which are not tied to either of the devices directly.
 A dependency between the two devices exists only if one of the two endpoint
 devices requests a reference to the other. The descriptions themselves can be
-defined in firmware (not yet supported) or they can be built-in.
+defined in firmware or they can be built-in.
 
 Usage
 -----
@@ -40,4 +40,4 @@ API
 ---
 
 .. kernel-doc:: drivers/base/devcon.c
-   : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove
+   : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove device_connection_find_by_graph
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index d427e80..5a0da33 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/device.h>
+#include <linux/property.h>
 
 static DEFINE_MUTEX(devcon_lock);
 static LIST_HEAD(devcon_list);
@@ -134,3 +135,45 @@ void device_connection_remove(struct device_connection *con)
 	mutex_unlock(&devcon_lock);
 }
 EXPORT_SYMBOL_GPL(device_connection_remove);
+
+static int generic_graph_match(struct device *dev, void *fwnode)
+{
+	return dev->fwnode == fwnode;
+}
+
+/**
+ * device_connection_find_by_graph - Find two devices connected together
+ * @dev: Device to find connected device
+ * @port: identifier of the @dev port node
+ * @endpoint: identifier of the @dev endpoint node
+ *
+ * Find a connection with @port and @endpoint by using graph between @dev and
+ * another device. On success returns handle to the device that is connected
+ * to @dev, with the reference count for the found device incremented. Returns
+ * NULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when
+ * a connection was found but the other device has not been enumerated yet.
+ */
+struct device *device_connection_find_by_graph(struct device *dev, u32 port,
+					       u32 endpoint)
+{
+	struct bus_type *bus;
+	struct fwnode_handle *remote;
+	struct device *conn;
+
+	remote = fwnode_graph_get_remote_node(dev_fwnode(dev), port, endpoint);
+	if (!remote)
+		return NULL;
+
+	for (bus = generic_match_buses[0]; bus; bus++) {
+		conn = bus_find_device(bus, NULL, remote, generic_graph_match);
+		if (conn)
+			return conn;
+	}
+
+	/*
+	 * We only get called if a connection was found, tell the caller to
+	 * wait for the other device to show up.
+	 */
+	return ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL_GPL(device_connection_find_by_graph);
diff --git a/include/linux/device.h b/include/linux/device.h
index 0059b99..58f8544 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -751,6 +751,8 @@ void *device_connection_find_match(struct device *dev, const char *con_id,
 
 void device_connection_add(struct device_connection *con);
 void device_connection_remove(struct device_connection *con);
+struct device *device_connection_find_by_graph(struct device *dev, u32 port,
+					       u32 endpoint);
 
 /**
  * enum device_link_state - Device link states.
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,2/6] base: devcon: add a new API to find the graph
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new API "device_connection_find_by_graph()" to
find device connection by using graph.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 Documentation/driver-api/device_connection.rst |  4 +--
 drivers/base/devcon.c                          | 43 ++++++++++++++++++++++++++
 include/linux/device.h                         |  2 ++
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/Documentation/driver-api/device_connection.rst b/Documentation/driver-api/device_connection.rst
index affbc556..2e2d26f 100644
--- a/Documentation/driver-api/device_connection.rst
+++ b/Documentation/driver-api/device_connection.rst
@@ -19,7 +19,7 @@ Device connections alone do not create a dependency between the two devices.
 They are only descriptions which are not tied to either of the devices directly.
 A dependency between the two devices exists only if one of the two endpoint
 devices requests a reference to the other. The descriptions themselves can be
-defined in firmware (not yet supported) or they can be built-in.
+defined in firmware or they can be built-in.
 
 Usage
 -----
@@ -40,4 +40,4 @@ API
 ---
 
 .. kernel-doc:: drivers/base/devcon.c
-   : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove
+   : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove device_connection_find_by_graph
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index d427e80..5a0da33 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -7,6 +7,7 @@
  */
 
 #include <linux/device.h>
+#include <linux/property.h>
 
 static DEFINE_MUTEX(devcon_lock);
 static LIST_HEAD(devcon_list);
@@ -134,3 +135,45 @@ void device_connection_remove(struct device_connection *con)
 	mutex_unlock(&devcon_lock);
 }
 EXPORT_SYMBOL_GPL(device_connection_remove);
+
+static int generic_graph_match(struct device *dev, void *fwnode)
+{
+	return dev->fwnode == fwnode;
+}
+
+/**
+ * device_connection_find_by_graph - Find two devices connected together
+ * @dev: Device to find connected device
+ * @port: identifier of the @dev port node
+ * @endpoint: identifier of the @dev endpoint node
+ *
+ * Find a connection with @port and @endpoint by using graph between @dev and
+ * another device. On success returns handle to the device that is connected
+ * to @dev, with the reference count for the found device incremented. Returns
+ * NULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when
+ * a connection was found but the other device has not been enumerated yet.
+ */
+struct device *device_connection_find_by_graph(struct device *dev, u32 port,
+					       u32 endpoint)
+{
+	struct bus_type *bus;
+	struct fwnode_handle *remote;
+	struct device *conn;
+
+	remote = fwnode_graph_get_remote_node(dev_fwnode(dev), port, endpoint);
+	if (!remote)
+		return NULL;
+
+	for (bus = generic_match_buses[0]; bus; bus++) {
+		conn = bus_find_device(bus, NULL, remote, generic_graph_match);
+		if (conn)
+			return conn;
+	}
+
+	/*
+	 * We only get called if a connection was found, tell the caller to
+	 * wait for the other device to show up.
+	 */
+	return ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL_GPL(device_connection_find_by_graph);
diff --git a/include/linux/device.h b/include/linux/device.h
index 0059b99..58f8544 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -751,6 +751,8 @@ void *device_connection_find_match(struct device *dev, const char *con_id,
 
 void device_connection_add(struct device_connection *con);
 void device_connection_remove(struct device_connection *con);
+struct device *device_connection_find_by_graph(struct device *dev, u32 port,
+					       u32 endpoint);
 
 /**
  * enum device_link_state - Device link states.

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 3/6] usb: common: roles: add a new API to find the graph
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new API "usb_role_switch_get_by_graph()" to find
device connection by using graph.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/common/roles.c | 30 ++++++++++++++++++++++++++++++
 include/linux/usb/role.h   |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/usb/common/roles.c b/drivers/usb/common/roles.c
index 15cc76e..9fa26c1 100644
--- a/drivers/usb/common/roles.c
+++ b/drivers/usb/common/roles.c
@@ -114,6 +114,36 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_get);
 
+static int by_graph_match(struct device *dev, void *parent)
+{
+	return dev->parent == parent;
+}
+
+/**
+ * usb_role_switch_get_by_graph - Find USB role switch linked with the caller
+ * @dev: The caller device
+ * @port: identifier of the @dev port node
+ * @endpoint: identifier of the @dev endpoint node
+ *
+ * Finds and returns role switch linked with @dev, port and endpoint.
+ * The reference count for the found switch is incremented.
+ */
+struct usb_role_switch *usb_role_switch_get_by_graph(struct device *dev,
+						     u32 port, u32 endpoint)
+{
+	struct device *conn;
+	struct device *sw;
+
+	conn = device_connection_find_by_graph(dev, port, endpoint);
+	if (IS_ERR_OR_NULL(conn))
+		return ERR_PTR(-EPROBE_DEFER);
+
+	sw = device_find_child(conn, conn, by_graph_match);
+
+	return !IS_ERR(sw) ? to_role_switch(sw) : ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL_GPL(usb_role_switch_get_by_graph);
+
 /**
  * usb_role_switch_put - Release handle to a switch
  * @sw: USB Role Switch
diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h
index edc51be..6573fdd 100644
--- a/include/linux/usb/role.h
+++ b/include/linux/usb/role.h
@@ -43,6 +43,8 @@ struct usb_role_switch_desc {
 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
 struct usb_role_switch *usb_role_switch_get(struct device *dev);
+struct usb_role_switch *usb_role_switch_get_by_graph(struct device *dev,
+						     u32 port, u32 endpoint);
 void usb_role_switch_put(struct usb_role_switch *sw);
 
 struct usb_role_switch *
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,3/6] usb: common: roles: add a new API to find the graph
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds a new API "usb_role_switch_get_by_graph()" to find
device connection by using graph.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/common/roles.c | 30 ++++++++++++++++++++++++++++++
 include/linux/usb/role.h   |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/usb/common/roles.c b/drivers/usb/common/roles.c
index 15cc76e..9fa26c1 100644
--- a/drivers/usb/common/roles.c
+++ b/drivers/usb/common/roles.c
@@ -114,6 +114,36 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_get);
 
+static int by_graph_match(struct device *dev, void *parent)
+{
+	return dev->parent == parent;
+}
+
+/**
+ * usb_role_switch_get_by_graph - Find USB role switch linked with the caller
+ * @dev: The caller device
+ * @port: identifier of the @dev port node
+ * @endpoint: identifier of the @dev endpoint node
+ *
+ * Finds and returns role switch linked with @dev, port and endpoint.
+ * The reference count for the found switch is incremented.
+ */
+struct usb_role_switch *usb_role_switch_get_by_graph(struct device *dev,
+						     u32 port, u32 endpoint)
+{
+	struct device *conn;
+	struct device *sw;
+
+	conn = device_connection_find_by_graph(dev, port, endpoint);
+	if (IS_ERR_OR_NULL(conn))
+		return ERR_PTR(-EPROBE_DEFER);
+
+	sw = device_find_child(conn, conn, by_graph_match);
+
+	return !IS_ERR(sw) ? to_role_switch(sw) : ERR_PTR(-EPROBE_DEFER);
+}
+EXPORT_SYMBOL_GPL(usb_role_switch_get_by_graph);
+
 /**
  * usb_role_switch_put - Release handle to a switch
  * @sw: USB Role Switch
diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h
index edc51be..6573fdd 100644
--- a/include/linux/usb/role.h
+++ b/include/linux/usb/role.h
@@ -43,6 +43,8 @@ struct usb_role_switch_desc {
 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
 struct usb_role_switch *usb_role_switch_get(struct device *dev);
+struct usb_role_switch *usb_role_switch_get_by_graph(struct device *dev,
+						     u32 port, u32 endpoint);
 void usb_role_switch_put(struct usb_role_switch *sw);
 
 struct usb_role_switch *

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 4/6] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds role switch support for R-Car SoCs. Some R-Car SoCs
(e.g. R-Car H3) have USB 3.0 dual-role device controller which has
the USB 3.0 xHCI host and Renesas USB 3.0 peripheral.

Unfortunately, the mode change register contains the USB 3.0 peripheral
controller side only. So, the USB 3.0 peripheral driver (renesas_usb3)
manages this register. However, in peripheral mode, the host should
stop. Also the host hardware needs to reinitialize its own registers
when the mode changes from peripheral to host mode. Otherwise,
the host cannot work correctly (e.g. detect a device as high-speed).

To achieve this by a driver, this role switch driver manages
the mode change register and attach/release the xhci-plat driver.
The renesas_usb3 udc driver should call devm_of_platform_populate()
to probe this driver.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/roles/Kconfig                 |  13 ++
 drivers/usb/roles/Makefile                |   1 +
 drivers/usb/roles/rcar-usb3-role-switch.c | 190 ++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/usb/roles/rcar-usb3-role-switch.c

diff --git a/drivers/usb/roles/Kconfig b/drivers/usb/roles/Kconfig
index f5a5e6f..a44cbc7 100644
--- a/drivers/usb/roles/Kconfig
+++ b/drivers/usb/roles/Kconfig
@@ -11,4 +11,17 @@ config USB_ROLES_INTEL_XHCI
 	  To compile the driver as a module, choose M here: the module will
 	  be called intel-xhci-usb-role-switch.
 
+config USB_ROLES_RCAR_USB3
+	tristate "Renesas R-Car USB3.0 Role Switch"
+	depends on OF
+	depends on ARCH_RENESAS || COMPILE_TEST
+	help
+	  Driver for the internal USB role switch for switching the USB data
+	  lines between the xHCI host controller and the Renesas gadget
+	  controller (by using renesas_usb3 driver) found on various Renesas
+	  R-Car SoCs.
+
+	  To compile the driver as a module, choose M here: the module will
+	  be called rcar-usb3-role-switch.
+
 endif # USB_ROLE_SWITCH
diff --git a/drivers/usb/roles/Makefile b/drivers/usb/roles/Makefile
index e44b179..7ce3be3 100644
--- a/drivers/usb/roles/Makefile
+++ b/drivers/usb/roles/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_USB_ROLES_INTEL_XHCI) += intel-xhci-usb-role-switch.o
+obj-$(CONFIG_USB_ROLES_RCAR_USB3) += rcar-usb3-role-switch.o
diff --git a/drivers/usb/roles/rcar-usb3-role-switch.c b/drivers/usb/roles/rcar-usb3-role-switch.c
new file mode 100644
index 0000000..2bcab60
--- /dev/null
+++ b/drivers/usb/roles/rcar-usb3-role-switch.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas R-Car USB 3.0 role switch driver
+ *
+ * Copyright (C) 2018  Renesas Electronics Corporation
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/usb/role.h>
+
+#define USB3_DRD_CON		0x218
+#define DRD_CON_PERI_CON	BIT(24)
+
+struct rcar_usb3_role_switch {
+	struct usb_role_switch *role_sw;
+	void __iomem *reg;
+	struct device *host_dev;
+	enum usb_role save_role;	/* for suspend/resume */
+};
+
+static enum usb_role
+rcar_usb3_role_switch_get_mode(struct rcar_usb3_role_switch *rcar_sw)
+{
+	u32 val = readl(rcar_sw->reg + USB3_DRD_CON);
+
+	if (val & DRD_CON_PERI_CON)
+		return USB_ROLE_DEVICE;
+
+	return USB_ROLE_HOST;
+}
+
+static void
+rcar_usb3_role_switch_set_mode(struct rcar_usb3_role_switch *rcar_sw,
+			       bool host)
+{
+	void __iomem *drd_con = rcar_sw->reg + USB3_DRD_CON;
+
+	if (host)
+		writel(readl(drd_con) & ~DRD_CON_PERI_CON, drd_con);
+	else
+		writel(readl(drd_con) | DRD_CON_PERI_CON, drd_con);
+}
+
+static int rcar_usb3_role_switch_set_role(struct device *dev,
+					  enum usb_role role)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	struct device *host = rcar_sw->host_dev;
+	enum usb_role cur_role;
+
+	pm_runtime_get_sync(dev->parent);
+
+	cur_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) {
+		device_release_driver(host);
+		rcar_usb3_role_switch_set_mode(rcar_sw, false);
+	} else if (cur_role == USB_ROLE_DEVICE && role == USB_ROLE_HOST) {
+		/* Must set the mode before device_attach of the host */
+		rcar_usb3_role_switch_set_mode(rcar_sw, true);
+		if (device_attach(host) < 0)
+			dev_err(dev, "device_attach(usb3_port) failed\n");
+	}
+
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static enum usb_role rcar_usb3_role_switch_get_role(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	enum usb_role cur_role;
+
+	pm_runtime_get(dev->parent);
+	cur_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	pm_runtime_put(dev->parent);
+
+	return cur_role;
+}
+
+static struct usb_role_switch_desc rcar_usb3_role_switch_desc = {
+	.set = rcar_usb3_role_switch_set_role,
+	.get = rcar_usb3_role_switch_get_role,
+};
+
+static const struct of_device_id rcar_usb3_role_switch_of_match[] = {
+	{ .compatible = "renesas,rcar-usb3-role-switch" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, rcar_usb3_role_switch_of_match);
+
+static int rcar_usb3_role_switch_remove(struct platform_device *pdev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = platform_get_drvdata(pdev);
+
+	usb_role_switch_unregister(rcar_sw->role_sw);
+	pm_runtime_disable(pdev->dev.parent);
+
+	return 0;
+}
+
+static int rcar_usb3_role_switch_probe(struct platform_device *pdev)
+{
+	struct rcar_usb3_role_switch *rcar_sw;
+	struct resource *res;
+
+	rcar_sw = devm_kzalloc(&pdev->dev, sizeof(*rcar_sw), GFP_KERNEL);
+	if (!rcar_sw)
+		return -ENOMEM;
+
+	res = platform_get_resource(to_platform_device(pdev->dev.parent),
+				    IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+
+	rcar_sw->reg = devm_ioremap_nocache(&pdev->dev, res->start,
+					    resource_size(res));
+	if (IS_ERR(rcar_sw->reg))
+		return PTR_ERR(rcar_sw->reg);
+
+	platform_set_drvdata(pdev, rcar_sw);
+	pm_runtime_enable(pdev->dev.parent);
+
+	rcar_usb3_role_switch_desc.allow_userspace_control = true;
+	rcar_sw->role_sw = usb_role_switch_register(&pdev->dev,
+						&rcar_usb3_role_switch_desc);
+	if (IS_ERR(rcar_sw->role_sw)) {
+		pm_runtime_disable(pdev->dev.parent);
+		return PTR_ERR(rcar_sw->role_sw);
+	}
+
+	rcar_sw->host_dev = device_connection_find_by_graph(&pdev->dev, 0, 0);
+	if (!IS_ERR_OR_NULL(rcar_sw->host_dev)) {
+		dev_info(&pdev->dev, "%s: host_dev = %p (%s)\n", __func__,
+			 rcar_sw->host_dev, dev_name(rcar_sw->host_dev));
+	} else {
+		usb_role_switch_unregister(rcar_sw->role_sw);
+		pm_runtime_disable(pdev->dev.parent);
+		return PTR_ERR(rcar_sw->host_dev);
+	}
+
+	return 0;
+}
+
+static int __maybe_unused rcar_usb3_role_switch_suspend(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+
+	pm_runtime_get_sync(dev->parent);
+	rcar_sw->save_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static int __maybe_unused rcar_usb3_role_switch_resume(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	bool host = rcar_sw->save_role == USB_ROLE_HOST ? true : false;
+
+	pm_runtime_get_sync(dev->parent);
+	rcar_usb3_role_switch_set_mode(rcar_sw, host);
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(rcar_usb3_role_switch_pm_ops,
+			 rcar_usb3_role_switch_suspend,
+			 rcar_usb3_role_switch_resume);
+
+static struct platform_driver rcar_usb3_role_switch_driver = {
+	.probe		= rcar_usb3_role_switch_probe,
+	.remove		= rcar_usb3_role_switch_remove,
+	.driver		= {
+		.name =	"rcar_usb3_role_switch",
+		.pm		= &rcar_usb3_role_switch_pm_ops,
+		.of_match_table = rcar_usb3_role_switch_of_match,
+	},
+};
+module_platform_driver(rcar_usb3_role_switch_driver);
+
+MODULE_DESCRIPTION("Renesas USB3.0 role switch driver");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>");
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,4/6] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds role switch support for R-Car SoCs. Some R-Car SoCs
(e.g. R-Car H3) have USB 3.0 dual-role device controller which has
the USB 3.0 xHCI host and Renesas USB 3.0 peripheral.

Unfortunately, the mode change register contains the USB 3.0 peripheral
controller side only. So, the USB 3.0 peripheral driver (renesas_usb3)
manages this register. However, in peripheral mode, the host should
stop. Also the host hardware needs to reinitialize its own registers
when the mode changes from peripheral to host mode. Otherwise,
the host cannot work correctly (e.g. detect a device as high-speed).

To achieve this by a driver, this role switch driver manages
the mode change register and attach/release the xhci-plat driver.
The renesas_usb3 udc driver should call devm_of_platform_populate()
to probe this driver.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/roles/Kconfig                 |  13 ++
 drivers/usb/roles/Makefile                |   1 +
 drivers/usb/roles/rcar-usb3-role-switch.c | 190 ++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/usb/roles/rcar-usb3-role-switch.c

diff --git a/drivers/usb/roles/Kconfig b/drivers/usb/roles/Kconfig
index f5a5e6f..a44cbc7 100644
--- a/drivers/usb/roles/Kconfig
+++ b/drivers/usb/roles/Kconfig
@@ -11,4 +11,17 @@ config USB_ROLES_INTEL_XHCI
 	  To compile the driver as a module, choose M here: the module will
 	  be called intel-xhci-usb-role-switch.
 
+config USB_ROLES_RCAR_USB3
+	tristate "Renesas R-Car USB3.0 Role Switch"
+	depends on OF
+	depends on ARCH_RENESAS || COMPILE_TEST
+	help
+	  Driver for the internal USB role switch for switching the USB data
+	  lines between the xHCI host controller and the Renesas gadget
+	  controller (by using renesas_usb3 driver) found on various Renesas
+	  R-Car SoCs.
+
+	  To compile the driver as a module, choose M here: the module will
+	  be called rcar-usb3-role-switch.
+
 endif # USB_ROLE_SWITCH
diff --git a/drivers/usb/roles/Makefile b/drivers/usb/roles/Makefile
index e44b179..7ce3be3 100644
--- a/drivers/usb/roles/Makefile
+++ b/drivers/usb/roles/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_USB_ROLES_INTEL_XHCI) += intel-xhci-usb-role-switch.o
+obj-$(CONFIG_USB_ROLES_RCAR_USB3) += rcar-usb3-role-switch.o
diff --git a/drivers/usb/roles/rcar-usb3-role-switch.c b/drivers/usb/roles/rcar-usb3-role-switch.c
new file mode 100644
index 0000000..2bcab60
--- /dev/null
+++ b/drivers/usb/roles/rcar-usb3-role-switch.c
@@ -0,0 +1,190 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas R-Car USB 3.0 role switch driver
+ *
+ * Copyright (C) 2018  Renesas Electronics Corporation
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/slab.h>
+#include <linux/usb/role.h>
+
+#define USB3_DRD_CON		0x218
+#define DRD_CON_PERI_CON	BIT(24)
+
+struct rcar_usb3_role_switch {
+	struct usb_role_switch *role_sw;
+	void __iomem *reg;
+	struct device *host_dev;
+	enum usb_role save_role;	/* for suspend/resume */
+};
+
+static enum usb_role
+rcar_usb3_role_switch_get_mode(struct rcar_usb3_role_switch *rcar_sw)
+{
+	u32 val = readl(rcar_sw->reg + USB3_DRD_CON);
+
+	if (val & DRD_CON_PERI_CON)
+		return USB_ROLE_DEVICE;
+
+	return USB_ROLE_HOST;
+}
+
+static void
+rcar_usb3_role_switch_set_mode(struct rcar_usb3_role_switch *rcar_sw,
+			       bool host)
+{
+	void __iomem *drd_con = rcar_sw->reg + USB3_DRD_CON;
+
+	if (host)
+		writel(readl(drd_con) & ~DRD_CON_PERI_CON, drd_con);
+	else
+		writel(readl(drd_con) | DRD_CON_PERI_CON, drd_con);
+}
+
+static int rcar_usb3_role_switch_set_role(struct device *dev,
+					  enum usb_role role)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	struct device *host = rcar_sw->host_dev;
+	enum usb_role cur_role;
+
+	pm_runtime_get_sync(dev->parent);
+
+	cur_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) {
+		device_release_driver(host);
+		rcar_usb3_role_switch_set_mode(rcar_sw, false);
+	} else if (cur_role == USB_ROLE_DEVICE && role == USB_ROLE_HOST) {
+		/* Must set the mode before device_attach of the host */
+		rcar_usb3_role_switch_set_mode(rcar_sw, true);
+		if (device_attach(host) < 0)
+			dev_err(dev, "device_attach(usb3_port) failed\n");
+	}
+
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static enum usb_role rcar_usb3_role_switch_get_role(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	enum usb_role cur_role;
+
+	pm_runtime_get(dev->parent);
+	cur_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	pm_runtime_put(dev->parent);
+
+	return cur_role;
+}
+
+static struct usb_role_switch_desc rcar_usb3_role_switch_desc = {
+	.set = rcar_usb3_role_switch_set_role,
+	.get = rcar_usb3_role_switch_get_role,
+};
+
+static const struct of_device_id rcar_usb3_role_switch_of_match[] = {
+	{ .compatible = "renesas,rcar-usb3-role-switch" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, rcar_usb3_role_switch_of_match);
+
+static int rcar_usb3_role_switch_remove(struct platform_device *pdev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = platform_get_drvdata(pdev);
+
+	usb_role_switch_unregister(rcar_sw->role_sw);
+	pm_runtime_disable(pdev->dev.parent);
+
+	return 0;
+}
+
+static int rcar_usb3_role_switch_probe(struct platform_device *pdev)
+{
+	struct rcar_usb3_role_switch *rcar_sw;
+	struct resource *res;
+
+	rcar_sw = devm_kzalloc(&pdev->dev, sizeof(*rcar_sw), GFP_KERNEL);
+	if (!rcar_sw)
+		return -ENOMEM;
+
+	res = platform_get_resource(to_platform_device(pdev->dev.parent),
+				    IORESOURCE_MEM, 0);
+	if (!res)
+		return -ENODEV;
+
+	rcar_sw->reg = devm_ioremap_nocache(&pdev->dev, res->start,
+					    resource_size(res));
+	if (IS_ERR(rcar_sw->reg))
+		return PTR_ERR(rcar_sw->reg);
+
+	platform_set_drvdata(pdev, rcar_sw);
+	pm_runtime_enable(pdev->dev.parent);
+
+	rcar_usb3_role_switch_desc.allow_userspace_control = true;
+	rcar_sw->role_sw = usb_role_switch_register(&pdev->dev,
+						&rcar_usb3_role_switch_desc);
+	if (IS_ERR(rcar_sw->role_sw)) {
+		pm_runtime_disable(pdev->dev.parent);
+		return PTR_ERR(rcar_sw->role_sw);
+	}
+
+	rcar_sw->host_dev = device_connection_find_by_graph(&pdev->dev, 0, 0);
+	if (!IS_ERR_OR_NULL(rcar_sw->host_dev)) {
+		dev_info(&pdev->dev, "%s: host_dev = %p (%s)\n", __func__,
+			 rcar_sw->host_dev, dev_name(rcar_sw->host_dev));
+	} else {
+		usb_role_switch_unregister(rcar_sw->role_sw);
+		pm_runtime_disable(pdev->dev.parent);
+		return PTR_ERR(rcar_sw->host_dev);
+	}
+
+	return 0;
+}
+
+static int __maybe_unused rcar_usb3_role_switch_suspend(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+
+	pm_runtime_get_sync(dev->parent);
+	rcar_sw->save_role = rcar_usb3_role_switch_get_mode(rcar_sw);
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static int __maybe_unused rcar_usb3_role_switch_resume(struct device *dev)
+{
+	struct rcar_usb3_role_switch *rcar_sw = dev_get_drvdata(dev);
+	bool host = rcar_sw->save_role == USB_ROLE_HOST ? true : false;
+
+	pm_runtime_get_sync(dev->parent);
+	rcar_usb3_role_switch_set_mode(rcar_sw, host);
+	pm_runtime_put(dev->parent);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(rcar_usb3_role_switch_pm_ops,
+			 rcar_usb3_role_switch_suspend,
+			 rcar_usb3_role_switch_resume);
+
+static struct platform_driver rcar_usb3_role_switch_driver = {
+	.probe		= rcar_usb3_role_switch_probe,
+	.remove		= rcar_usb3_role_switch_remove,
+	.driver		= {
+		.name =	"rcar_usb3_role_switch",
+		.pm		= &rcar_usb3_role_switch_pm_ops,
+		.of_match_table = rcar_usb3_role_switch_of_match,
+	},
+};
+module_platform_driver(rcar_usb3_role_switch_driver);
+
+MODULE_DESCRIPTION("Renesas USB3.0 role switch driver");
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>");

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 5/6] usb: gadget: udc: renesas_usb3: add support for a usb role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds support for a usb role switch driver. And then,
this driver uses the usb role switch APIs instead of hardware
access to initialize usb host side at specific timings.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/gadget/udc/Kconfig        |  1 +
 drivers/usb/gadget/udc/renesas_usb3.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 0875d38..7e4a5dd 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -193,6 +193,7 @@ config USB_RENESAS_USB3
 	tristate 'Renesas USB3.0 Peripheral controller'
 	depends on ARCH_RENESAS || COMPILE_TEST
 	depends on EXTCON && HAS_DMA
+	select USB_ROLE_SWITCH
 	help
 	   Renesas USB3.0 Peripheral controller is a USB peripheral controller
 	   that supports super, high, and full speed USB 3.0 data transfers.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index 409cde4..5b7b1ce 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -23,6 +23,7 @@
 #include <linux/uaccess.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/usb/role.h>
 
 /* register definitions */
 #define USB3_AXI_INT_STA	0x008
@@ -330,6 +331,7 @@ struct renesas_usb3 {
 
 	struct usb_gadget gadget;
 	struct usb_gadget_driver *driver;
+	struct usb_role_switch *role_sw;	/* Optional */
 	struct extcon_dev *extcon;
 	struct work_struct extcon_work;
 	struct phy *phy;
@@ -454,7 +456,11 @@ static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num)
 
 static bool usb3_is_host(struct renesas_usb3 *usb3)
 {
-	return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON);
+	if (usb3->role_sw)
+		return usb_role_switch_get_role(usb3->role_sw) ==
+						USB_ROLE_HOST ? true : false;
+	else
+		return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON);
 }
 
 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
@@ -645,10 +651,16 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
 
 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host)
 {
-	if (host)
-		usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
-	else
-		usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+	if (usb3->role_sw) {
+		enum usb_role role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE;
+
+		usb_role_switch_set_role(usb3->role_sw, role);
+	} else {
+		if (host)
+			usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+		else
+			usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+	}
 }
 
 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable)
@@ -663,8 +675,8 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&usb3->lock, flags);
 	usb3_set_mode(usb3, host);
+	spin_lock_irqsave(&usb3->lock, flags);
 	usb3_vbus_out(usb3, a_dev);
 	/* for A-Peripheral or forced B-device mode */
 	if ((!host && a_dev) ||
@@ -2238,6 +2250,10 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
 	/* hook up the driver */
 	usb3->driver = driver;
 
+	usb3->role_sw = usb_role_switch_get_by_graph(usb3_to_dev(usb3), 0, 0);
+	if (IS_ERR_OR_NULL(usb3->role_sw))
+		usb3->role_sw = NULL;
+
 	if (usb3->phy)
 		phy_init(usb3->phy);
 
@@ -2260,6 +2276,8 @@ static int renesas_usb3_stop(struct usb_gadget *gadget)
 	if (usb3->phy)
 		phy_exit(usb3->phy);
 
+	usb_role_switch_put(usb3->role_sw);
+
 	pm_runtime_put(usb3_to_dev(usb3));
 
 	return 0;
@@ -2632,6 +2650,10 @@ static int renesas_usb3_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto err_add_udc;
 
+	ret = devm_of_platform_populate(&pdev->dev);
+	if (ret < 0)
+		goto err_dev_create;
+
 	ret = device_create_file(&pdev->dev, &dev_attr_role);
 	if (ret < 0)
 		goto err_dev_create;
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,5/6] usb: gadget: udc: renesas_usb3: add support for a usb role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds support for a usb role switch driver. And then,
this driver uses the usb role switch APIs instead of hardware
access to initialize usb host side at specific timings.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/usb/gadget/udc/Kconfig        |  1 +
 drivers/usb/gadget/udc/renesas_usb3.c | 34 ++++++++++++++++++++++++++++------
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 0875d38..7e4a5dd 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -193,6 +193,7 @@ config USB_RENESAS_USB3
 	tristate 'Renesas USB3.0 Peripheral controller'
 	depends on ARCH_RENESAS || COMPILE_TEST
 	depends on EXTCON && HAS_DMA
+	select USB_ROLE_SWITCH
 	help
 	   Renesas USB3.0 Peripheral controller is a USB peripheral controller
 	   that supports super, high, and full speed USB 3.0 data transfers.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c b/drivers/usb/gadget/udc/renesas_usb3.c
index 409cde4..5b7b1ce 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -23,6 +23,7 @@
 #include <linux/uaccess.h>
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
+#include <linux/usb/role.h>
 
 /* register definitions */
 #define USB3_AXI_INT_STA	0x008
@@ -330,6 +331,7 @@ struct renesas_usb3 {
 
 	struct usb_gadget gadget;
 	struct usb_gadget_driver *driver;
+	struct usb_role_switch *role_sw;	/* Optional */
 	struct extcon_dev *extcon;
 	struct work_struct extcon_work;
 	struct phy *phy;
@@ -454,7 +456,11 @@ static void usb3_disable_pipe_irq(struct renesas_usb3 *usb3, int num)
 
 static bool usb3_is_host(struct renesas_usb3 *usb3)
 {
-	return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON);
+	if (usb3->role_sw)
+		return usb_role_switch_get_role(usb3->role_sw) ==
+						USB_ROLE_HOST ? true : false;
+	else
+		return !(usb3_read(usb3, USB3_DRD_CON) & DRD_CON_PERI_CON);
 }
 
 static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
@@ -645,10 +651,16 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
 
 static void usb3_set_mode(struct renesas_usb3 *usb3, bool host)
 {
-	if (host)
-		usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
-	else
-		usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+	if (usb3->role_sw) {
+		enum usb_role role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE;
+
+		usb_role_switch_set_role(usb3->role_sw, role);
+	} else {
+		if (host)
+			usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+		else
+			usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
+	}
 }
 
 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable)
@@ -663,8 +675,8 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, bool host, bool a_dev)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&usb3->lock, flags);
 	usb3_set_mode(usb3, host);
+	spin_lock_irqsave(&usb3->lock, flags);
 	usb3_vbus_out(usb3, a_dev);
 	/* for A-Peripheral or forced B-device mode */
 	if ((!host && a_dev) ||
@@ -2238,6 +2250,10 @@ static int renesas_usb3_start(struct usb_gadget *gadget,
 	/* hook up the driver */
 	usb3->driver = driver;
 
+	usb3->role_sw = usb_role_switch_get_by_graph(usb3_to_dev(usb3), 0, 0);
+	if (IS_ERR_OR_NULL(usb3->role_sw))
+		usb3->role_sw = NULL;
+
 	if (usb3->phy)
 		phy_init(usb3->phy);
 
@@ -2260,6 +2276,8 @@ static int renesas_usb3_stop(struct usb_gadget *gadget)
 	if (usb3->phy)
 		phy_exit(usb3->phy);
 
+	usb_role_switch_put(usb3->role_sw);
+
 	pm_runtime_put(usb3_to_dev(usb3));
 
 	return 0;
@@ -2632,6 +2650,10 @@ static int renesas_usb3_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto err_add_udc;
 
+	ret = devm_of_platform_populate(&pdev->dev);
+	if (ret < 0)
+		goto err_dev_create;
+
 	ret = device_create_file(&pdev->dev, &dev_attr_role);
 	if (ret < 0)
 		goto err_dev_create;

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC v2 6/6] arm64: dts: renesas: r8a7795: add OF graph for usb role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds OF graph properties for usb role switch in r8a7795.

TODO:
 - separate a few patches to add new properties into each node.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 5ae85d8..2e52835 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2206,6 +2206,12 @@
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			resets = <&cpg 328>;
 			status = "disabled";
+
+			port {
+				usb3_host_ep: endpoint {
+					remote-endpoint = <&usb3_host_ep>;
+				};
+			};
 		};
 
 		usb3_peri0: usb@ee020000 {
@@ -2217,6 +2223,38 @@
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			resets = <&cpg 328>;
 			status = "disabled";
+
+			port {
+				usb3_peri_ep: endpoint {
+					remote-endpoint = <&usb3_peri_sw>;
+				};
+			};
+
+			usb3_role_sw0: usb3-role-sw {
+				compatible = "renesas,rcar-usb3-role-switch";
+				renesas,host = <&xhci0>;
+
+				ports {
+					#address-cells = <1>;
+					#size-cells = <0>;
+
+					port@0 {
+						reg = <0>;
+
+						usb3_host_sw: endpoint {
+							remote-endpoint = <&usb3_host_ep>;
+						};
+					};
+
+					port@1 {
+						reg = <1>;
+
+						usb3_peri_sw: endpoint {
+							remote-endpoint = <&usb3_peri_ep>;
+						};
+					};
+				};
+			};
 		};
 
 		ohci0: usb@ee080000 {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,6/6] arm64: dts: renesas: r8a7795: add OF graph for usb role switch
@ 2018-04-26 11:26   ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-04-26 11:26 UTC (permalink / raw)
  To: gregkh, robh+dt, mark.rutland
  Cc: heikki.krogerus, hdegoede, andy.shevchenko, linux-usb,
	linux-renesas-soc, devicetree, Yoshihiro Shimoda

This patch adds OF graph properties for usb role switch in r8a7795.

TODO:
 - separate a few patches to add new properties into each node.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 arch/arm64/boot/dts/renesas/r8a7795.dtsi | 38 ++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 5ae85d8..2e52835 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -2206,6 +2206,12 @@
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			resets = <&cpg 328>;
 			status = "disabled";
+
+			port {
+				usb3_host_ep: endpoint {
+					remote-endpoint = <&usb3_host_ep>;
+				};
+			};
 		};
 
 		usb3_peri0: usb@ee020000 {
@@ -2217,6 +2223,38 @@
 			power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
 			resets = <&cpg 328>;
 			status = "disabled";
+
+			port {
+				usb3_peri_ep: endpoint {
+					remote-endpoint = <&usb3_peri_sw>;
+				};
+			};
+
+			usb3_role_sw0: usb3-role-sw {
+				compatible = "renesas,rcar-usb3-role-switch";
+				renesas,host = <&xhci0>;
+
+				ports {
+					#address-cells = <1>;
+					#size-cells = <0>;
+
+					port@0 {
+						reg = <0>;
+
+						usb3_host_sw: endpoint {
+							remote-endpoint = <&usb3_host_ep>;
+						};
+					};
+
+					port@1 {
+						reg = <1>;
+
+						usb3_peri_sw: endpoint {
+							remote-endpoint = <&usb3_peri_ep>;
+						};
+					};
+				};
+			};
 		};
 
 		ohci0: usb@ee080000 {

^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-04-27 20:05     ` Rob Herring
  0 siblings, 0 replies; 21+ messages in thread
From: Rob Herring @ 2018-04-27 20:05 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> This patch adds a new documentation for Renesas R-Car USB 3.0 role
> switch that can change the USB 3.0 role to either host or peripheral
> by a hardware register that is included in USB3.0 peripheral module.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
>  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> 
> diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> new file mode 100644
> index 0000000..e074c03
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> @@ -0,0 +1,47 @@
> +Renesas Electronics R-Car USB 3.0 role switch
> +
> +A renesas_usb3's node can contain this node.
> +
> +Required properties:
> + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> +
> +Required nodes:
> + - The connection to a usb3.0 host node needs by using OF graph bindings.
> +  - port@0 = USB 3.0 host port
> +  - port@1 = USB 3.0 peripheral port
> +
> +Example of R-Car H3 ES2.0:
> +	usb3_peri0: usb@ee020000 {
> +		compatible = "renesas,r8a7795-usb3-peri",
> +			     "renesas,rcar-gen3-usb3-peri";
> +		reg = <0 0xee020000 0 0x400>;
> +		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> +		clocks = <&cpg CPG_MOD 328>;
> +		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> +		resets = <&cpg 328>;
> +
> +		usb3-role-sw {
> +			compatible = "renesas,rcar-usb3-role-switch";

You don't define any h/w resources. How is this device accessed?


> +			ports {
> +				#address-cells = <1>;
> +				#size-cells = <0>;
> +
> +				port@0 {
> +					reg = <0>;
> +
> +					usb3_host_sw: endpoint {
> +						remote-endpoint = <&usb3_host_ep>;
> +					};
> +				};
> +
> +				port@1 {
> +					reg = <1>;
> +
> +					usb3_peri_sw: endpoint {
> +						remote-endpoint = <&usb3_peri_ep>;
> +					};
> +				};
> +			};
> +		};
> +	};
> -- 
> 1.9.1
> 

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-04-27 20:05     ` Rob Herring
  0 siblings, 0 replies; 21+ messages in thread
From: Rob Herring @ 2018-04-27 20:05 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> This patch adds a new documentation for Renesas R-Car USB 3.0 role
> switch that can change the USB 3.0 role to either host or peripheral
> by a hardware register that is included in USB3.0 peripheral module.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> ---
>  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
>  1 file changed, 47 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> 
> diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> new file mode 100644
> index 0000000..e074c03
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> @@ -0,0 +1,47 @@
> +Renesas Electronics R-Car USB 3.0 role switch
> +
> +A renesas_usb3's node can contain this node.
> +
> +Required properties:
> + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> +
> +Required nodes:
> + - The connection to a usb3.0 host node needs by using OF graph bindings.
> +  - port@0 = USB 3.0 host port
> +  - port@1 = USB 3.0 peripheral port
> +
> +Example of R-Car H3 ES2.0:
> +	usb3_peri0: usb@ee020000 {
> +		compatible = "renesas,r8a7795-usb3-peri",
> +			     "renesas,rcar-gen3-usb3-peri";
> +		reg = <0 0xee020000 0 0x400>;
> +		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> +		clocks = <&cpg CPG_MOD 328>;
> +		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> +		resets = <&cpg 328>;
> +
> +		usb3-role-sw {
> +			compatible = "renesas,rcar-usb3-role-switch";

You don't define any h/w resources. How is this device accessed?


> +			ports {
> +				#address-cells = <1>;
> +				#size-cells = <0>;
> +
> +				port@0 {
> +					reg = <0>;
> +
> +					usb3_host_sw: endpoint {
> +						remote-endpoint = <&usb3_host_ep>;
> +					};
> +				};
> +
> +				port@1 {
> +					reg = <1>;
> +
> +					usb3_peri_sw: endpoint {
> +						remote-endpoint = <&usb3_peri_ep>;
> +					};
> +				};
> +			};
> +		};
> +	};
> -- 
> 1.9.1
>
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-08  2:43       ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-05-08  2:43 UTC (permalink / raw)
  To: Rob Herring
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

Hi Rob,

Sorry for the delayed response. I had a vacation in last week.

> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
> 
> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
> > switch that can change the USB 3.0 role to either host or peripheral
> > by a hardware register that is included in USB3.0 peripheral module.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > ---
> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
> >  1 file changed, 47 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >
> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> > new file mode 100644
> > index 0000000..e074c03
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> > @@ -0,0 +1,47 @@
> > +Renesas Electronics R-Car USB 3.0 role switch
> > +
> > +A renesas_usb3's node can contain this node.
> > +
> > +Required properties:
> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> > +
> > +Required nodes:
> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
> > +  - port@0 = USB 3.0 host port
> > +  - port@1 = USB 3.0 peripheral port
> > +
> > +Example of R-Car H3 ES2.0:
> > +	usb3_peri0: usb@ee020000 {
> > +		compatible = "renesas,r8a7795-usb3-peri",
> > +			     "renesas,rcar-gen3-usb3-peri";
> > +		reg = <0 0xee020000 0 0x400>;
> > +		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> > +		clocks = <&cpg CPG_MOD 328>;
> > +		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> > +		resets = <&cpg 328>;
> > +
> > +		usb3-role-sw {
> > +			compatible = "renesas,rcar-usb3-role-switch";
> 
> You don't define any h/w resources. How is this device accessed?

This device accesses one of registers in the usb3_peri0.
In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
(Unfortunately, the hardware design is not good...)

In this case, should I describe the following in the usb3-role-sw node?

	reg = <0 0xee020218 0 4>;

Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
take care for it?

Best regards,
Yoshihiro Shimoda

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-08  2:43       ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-05-08  2:43 UTC (permalink / raw)
  To: Rob Herring
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

Hi Rob,

Sorry for the delayed response. I had a vacation in last week.

> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
> 
> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
> > switch that can change the USB 3.0 role to either host or peripheral
> > by a hardware register that is included in USB3.0 peripheral module.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> > ---
> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
> >  1 file changed, 47 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >
> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> > new file mode 100644
> > index 0000000..e074c03
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> > @@ -0,0 +1,47 @@
> > +Renesas Electronics R-Car USB 3.0 role switch
> > +
> > +A renesas_usb3's node can contain this node.
> > +
> > +Required properties:
> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> > +
> > +Required nodes:
> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
> > +  - port@0 = USB 3.0 host port
> > +  - port@1 = USB 3.0 peripheral port
> > +
> > +Example of R-Car H3 ES2.0:
> > +	usb3_peri0: usb@ee020000 {
> > +		compatible = "renesas,r8a7795-usb3-peri",
> > +			     "renesas,rcar-gen3-usb3-peri";
> > +		reg = <0 0xee020000 0 0x400>;
> > +		interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> > +		clocks = <&cpg CPG_MOD 328>;
> > +		power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> > +		resets = <&cpg 328>;
> > +
> > +		usb3-role-sw {
> > +			compatible = "renesas,rcar-usb3-role-switch";
> 
> You don't define any h/w resources. How is this device accessed?

This device accesses one of registers in the usb3_peri0.
In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
(Unfortunately, the hardware design is not good...)

In this case, should I describe the following in the usb3-role-sw node?

	reg = <0 0xee020218 0 4>;

Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
take care for it?

Best regards,
Yoshihiro Shimoda
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-11 16:07         ` Rob Herring
  0 siblings, 0 replies; 21+ messages in thread
From: Rob Herring @ 2018-05-11 16:07 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

On Mon, May 7, 2018 at 9:43 PM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> Hi Rob,
>
> Sorry for the delayed response. I had a vacation in last week.
>
>> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
>>
>> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
>> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
>> > switch that can change the USB 3.0 role to either host or peripheral
>> > by a hardware register that is included in USB3.0 peripheral module.
>> >
>> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
>> > ---
>> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
>> >  1 file changed, 47 insertions(+)
>> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> >
>> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> > new file mode 100644
>> > index 0000000..e074c03
>> > --- /dev/null
>> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> > @@ -0,0 +1,47 @@
>> > +Renesas Electronics R-Car USB 3.0 role switch
>> > +
>> > +A renesas_usb3's node can contain this node.
>> > +
>> > +Required properties:
>> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
>> > +
>> > +Required nodes:
>> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
>> > +  - port@0 = USB 3.0 host port
>> > +  - port@1 = USB 3.0 peripheral port
>> > +
>> > +Example of R-Car H3 ES2.0:
>> > +   usb3_peri0: usb@ee020000 {
>> > +           compatible = "renesas,r8a7795-usb3-peri",
>> > +                        "renesas,rcar-gen3-usb3-peri";
>> > +           reg = <0 0xee020000 0 0x400>;
>> > +           interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
>> > +           clocks = <&cpg CPG_MOD 328>;
>> > +           power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
>> > +           resets = <&cpg 328>;
>> > +
>> > +           usb3-role-sw {
>> > +                   compatible = "renesas,rcar-usb3-role-switch";
>>
>> You don't define any h/w resources. How is this device accessed?
>
> This device accesses one of registers in the usb3_peri0.
> In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
> (Unfortunately, the hardware design is not good...)
>
> In this case, should I describe the following in the usb3-role-sw node?
>
>         reg = <0 0xee020218 0 4>;
>
> Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
> take care for it?

IMO, the driver should take care of it.

Rob

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-11 16:07         ` Rob Herring
  0 siblings, 0 replies; 21+ messages in thread
From: Rob Herring @ 2018-05-11 16:07 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

On Mon, May 7, 2018 at 9:43 PM, Yoshihiro Shimoda
<yoshihiro.shimoda.uh@renesas.com> wrote:
> Hi Rob,
>
> Sorry for the delayed response. I had a vacation in last week.
>
>> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
>>
>> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
>> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
>> > switch that can change the USB 3.0 role to either host or peripheral
>> > by a hardware register that is included in USB3.0 peripheral module.
>> >
>> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
>> > ---
>> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
>> >  1 file changed, 47 insertions(+)
>> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> >
>> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> > new file mode 100644
>> > index 0000000..e074c03
>> > --- /dev/null
>> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
>> > @@ -0,0 +1,47 @@
>> > +Renesas Electronics R-Car USB 3.0 role switch
>> > +
>> > +A renesas_usb3's node can contain this node.
>> > +
>> > +Required properties:
>> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
>> > +
>> > +Required nodes:
>> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
>> > +  - port@0 = USB 3.0 host port
>> > +  - port@1 = USB 3.0 peripheral port
>> > +
>> > +Example of R-Car H3 ES2.0:
>> > +   usb3_peri0: usb@ee020000 {
>> > +           compatible = "renesas,r8a7795-usb3-peri",
>> > +                        "renesas,rcar-gen3-usb3-peri";
>> > +           reg = <0 0xee020000 0 0x400>;
>> > +           interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
>> > +           clocks = <&cpg CPG_MOD 328>;
>> > +           power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
>> > +           resets = <&cpg 328>;
>> > +
>> > +           usb3-role-sw {
>> > +                   compatible = "renesas,rcar-usb3-role-switch";
>>
>> You don't define any h/w resources. How is this device accessed?
>
> This device accesses one of registers in the usb3_peri0.
> In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
> (Unfortunately, the hardware design is not good...)
>
> In this case, should I describe the following in the usb3-role-sw node?
>
>         reg = <0 0xee020218 0 4>;
>
> Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
> take care for it?

IMO, the driver should take care of it.

Rob
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 21+ messages in thread

* RE: [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-14  2:31           ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-05-14  2:31 UTC (permalink / raw)
  To: Rob Herring
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

Hi Rob,

> From: Rob Herring, Sent: Saturday, May 12, 2018 1:07 AM
> 
> On Mon, May 7, 2018 at 9:43 PM, Yoshihiro Shimoda
> <yoshihiro.shimoda.uh@renesas.com> wrote:
> > Hi Rob,
> >
> > Sorry for the delayed response. I had a vacation in last week.
> >
> >> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
> >>
> >> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> >> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
> >> > switch that can change the USB 3.0 role to either host or peripheral
> >> > by a hardware register that is included in USB3.0 peripheral module.
> >> >
> >> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> >> > ---
> >> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
> >> >  1 file changed, 47 insertions(+)
> >> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> > new file mode 100644
> >> > index 0000000..e074c03
> >> > --- /dev/null
> >> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> > @@ -0,0 +1,47 @@
> >> > +Renesas Electronics R-Car USB 3.0 role switch
> >> > +
> >> > +A renesas_usb3's node can contain this node.
> >> > +
> >> > +Required properties:
> >> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> >> > +
> >> > +Required nodes:
> >> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
> >> > +  - port@0 = USB 3.0 host port
> >> > +  - port@1 = USB 3.0 peripheral port
> >> > +
> >> > +Example of R-Car H3 ES2.0:
> >> > +   usb3_peri0: usb@ee020000 {
> >> > +           compatible = "renesas,r8a7795-usb3-peri",
> >> > +                        "renesas,rcar-gen3-usb3-peri";
> >> > +           reg = <0 0xee020000 0 0x400>;
> >> > +           interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> >> > +           clocks = <&cpg CPG_MOD 328>;
> >> > +           power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> >> > +           resets = <&cpg 328>;
> >> > +
> >> > +           usb3-role-sw {
> >> > +                   compatible = "renesas,rcar-usb3-role-switch";
> >>
> >> You don't define any h/w resources. How is this device accessed?
> >
> > This device accesses one of registers in the usb3_peri0.
> > In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
> > (Unfortunately, the hardware design is not good...)
> >
> > In this case, should I describe the following in the usb3-role-sw node?
> >
> >         reg = <0 0xee020218 0 4>;
> >
> > Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
> > take care for it?
> 
> IMO, the driver should take care of it.

Thank you for the reply. I'll modify the usb3_peri0 driver for role switch.

Best regards,
Yoshihiro Shimoda

> Rob

^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH/RFC,v2,1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch
@ 2018-05-14  2:31           ` Yoshihiro Shimoda
  0 siblings, 0 replies; 21+ messages in thread
From: Yoshihiro Shimoda @ 2018-05-14  2:31 UTC (permalink / raw)
  To: Rob Herring
  Cc: gregkh, mark.rutland, heikki.krogerus, hdegoede, andy.shevchenko,
	linux-usb, linux-renesas-soc, devicetree

Hi Rob,

> From: Rob Herring, Sent: Saturday, May 12, 2018 1:07 AM
> 
> On Mon, May 7, 2018 at 9:43 PM, Yoshihiro Shimoda
> <yoshihiro.shimoda.uh@renesas.com> wrote:
> > Hi Rob,
> >
> > Sorry for the delayed response. I had a vacation in last week.
> >
> >> From: Rob Herring, Sent: Saturday, April 28, 2018 5:06 AM
> >>
> >> On Thu, Apr 26, 2018 at 08:26:41PM +0900, Yoshihiro Shimoda wrote:
> >> > This patch adds a new documentation for Renesas R-Car USB 3.0 role
> >> > switch that can change the USB 3.0 role to either host or peripheral
> >> > by a hardware register that is included in USB3.0 peripheral module.
> >> >
> >> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> >> > ---
> >> >  .../bindings/usb/renesas,rcar-usb3-role-sw.txt     | 47 ++++++++++++++++++++++
> >> >  1 file changed, 47 insertions(+)
> >> >  create mode 100644 Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> >
> >> > diff --git a/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> > new file mode 100644
> >> > index 0000000..e074c03
> >> > --- /dev/null
> >> > +++ b/Documentation/devicetree/bindings/usb/renesas,rcar-usb3-role-sw.txt
> >> > @@ -0,0 +1,47 @@
> >> > +Renesas Electronics R-Car USB 3.0 role switch
> >> > +
> >> > +A renesas_usb3's node can contain this node.
> >> > +
> >> > +Required properties:
> >> > + - compatible: Must contain "renesas,rcar-usb3-role-switch".
> >> > +
> >> > +Required nodes:
> >> > + - The connection to a usb3.0 host node needs by using OF graph bindings.
> >> > +  - port@0 = USB 3.0 host port
> >> > +  - port@1 = USB 3.0 peripheral port
> >> > +
> >> > +Example of R-Car H3 ES2.0:
> >> > +   usb3_peri0: usb@ee020000 {
> >> > +           compatible = "renesas,r8a7795-usb3-peri",
> >> > +                        "renesas,rcar-gen3-usb3-peri";
> >> > +           reg = <0 0xee020000 0 0x400>;
> >> > +           interrupts = <GIC_SPI 104 IRQ_TYPE_LEVEL_HIGH>;
> >> > +           clocks = <&cpg CPG_MOD 328>;
> >> > +           power-domains = <&sysc R8A7795_PD_ALWAYS_ON>;
> >> > +           resets = <&cpg 328>;
> >> > +
> >> > +           usb3-role-sw {
> >> > +                   compatible = "renesas,rcar-usb3-role-switch";
> >>
> >> You don't define any h/w resources. How is this device accessed?
> >
> > This device accesses one of registers in the usb3_peri0.
> > In the detail, the usb3-role-sw uses 0xee020218 (32-bit register) only.
> > (Unfortunately, the hardware design is not good...)
> >
> > In this case, should I describe the following in the usb3-role-sw node?
> >
> >         reg = <0 0xee020218 0 4>;
> >
> > Or, shouldn't I add the usb3-role-sw node and a driver for usb3_peri0 should
> > take care for it?
> 
> IMO, the driver should take care of it.

Thank you for the reply. I'll modify the usb3_peri0 driver for role switch.

Best regards,
Yoshihiro Shimoda

> Rob

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2018-05-14  2:31 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-26 11:26 [PATCH/RFC v2 0/6] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 1/6] dt-bindings: usb: add Renesas R-Car USB 3.0 role switch Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,1/6] " Yoshihiro Shimoda
2018-04-27 20:05   ` [PATCH/RFC v2 1/6] " Rob Herring
2018-04-27 20:05     ` [PATCH/RFC,v2,1/6] " Rob Herring
2018-05-08  2:43     ` [PATCH/RFC v2 1/6] " Yoshihiro Shimoda
2018-05-08  2:43       ` [PATCH/RFC,v2,1/6] " Yoshihiro Shimoda
2018-05-11 16:07       ` [PATCH/RFC v2 1/6] " Rob Herring
2018-05-11 16:07         ` [PATCH/RFC,v2,1/6] " Rob Herring
2018-05-14  2:31         ` [PATCH/RFC v2 1/6] " Yoshihiro Shimoda
2018-05-14  2:31           ` [PATCH/RFC,v2,1/6] " Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 2/6] base: devcon: add a new API to find the graph Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,2/6] " Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 3/6] usb: common: roles: " Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,3/6] " Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 4/6] usb: role: rcar-usb3-role-switch: add support for R-Car SoCs Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,4/6] " Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 5/6] usb: gadget: udc: renesas_usb3: add support for a usb role switch Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,5/6] " Yoshihiro Shimoda
2018-04-26 11:26 ` [PATCH/RFC v2 6/6] arm64: dts: renesas: r8a7795: add OF graph for " Yoshihiro Shimoda
2018-04-26 11:26   ` [PATCH/RFC,v2,6/6] " Yoshihiro Shimoda

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.