linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints
@ 2022-11-24 10:20 Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 1/7] device property: Add remote endpoint to devcon matcher Pin-yen Lin
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen


This series introduces bindings for anx7625/it6505 to register Type-C
mode-switch in their output endpoints, and use data-lanes property to
describe the pin connections.

The first two patch modifies fwnode_graph_devcon_matches and
cros_typec_init_ports to enable the registration of the switches.

Patch 3~5 introduce the bindings for anx7625 and the corresponding driver
modifications.

Patch 6~7 add similar bindings and driver changes for it6505.

v5: https://lore.kernel.org/linux-usb/20220622173605.1168416-1-pmalani@chromium.org/


Changes in v6:
- Dropped typec-switch binding and use endpoints and data-lanes properties
  to describe the pin connections
- Changed the driver implementation to accommodate with the new bindings
- Changed it6505_typec_mux_set callback function to accommodate with
  the latest drm-misc patches
- Added new patches (patch 1,2,4) to fix probing issues
- Merged it6505/anx7625 driver changes into a single patch

Pin-yen Lin (5):
  dt-bindings: drm/bridge: anx7625: Add mode-switch support
  drm/bridge: anx7625: Check for Type-C during panel registration
  drm/bridge: anx7625: Register Type C mode switches
  dt/bindings: drm/bridge: it6505: Add mode-switch support
  drm/bridge: it6505: Register Type C mode switches

Prashant Malani (2):
  device property: Add remote endpoint to devcon matcher
  platform/chrome: cros_ec_typec: Purge blocking switch devlinks

 .../display/bridge/analogix,anx7625.yaml      |  73 ++++++-
 .../bindings/display/bridge/ite,it6505.yaml   |  94 +++++++-
 drivers/base/property.c                       |  15 ++
 drivers/gpu/drm/bridge/Kconfig                |   1 +
 drivers/gpu/drm/bridge/analogix/Kconfig       |   1 +
 drivers/gpu/drm/bridge/analogix/anx7625.c     | 182 +++++++++++++++-
 drivers/gpu/drm/bridge/analogix/anx7625.h     |  20 ++
 drivers/gpu/drm/bridge/ite-it6505.c           | 205 +++++++++++++++++-
 drivers/platform/chrome/cros_ec_typec.c       |   9 +
 9 files changed, 589 insertions(+), 11 deletions(-)

-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 1/7] device property: Add remote endpoint to devcon matcher
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Pin-yen Lin
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

From: Prashant Malani <pmalani@chromium.org>

When searching the device graph for device matches, check the
remote-endpoint itself for a match.

Some drivers register devices for individual endpoints. This allows
the matcher code to evaluate those for a match too, instead
of only looking at the remote parent devices. This is required when a
device supports two mode switches in its endpoints, so we can't simply
register the mode switch with the parent node.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- New in v6

 drivers/base/property.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 4d6278a84868..2ab8be8ca45e 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1223,6 +1223,21 @@ static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode,
 			break;
 		}
 
+		/*
+		 * Some drivers may register devices for endpoints. Check
+		 * the remote-endpoints for matches in addition to the remote
+		 * port parent.
+		 */
+		node = fwnode_graph_get_remote_endpoint(ep);
+		if (fwnode_device_is_available(node)) {
+			ret = match(node, con_id, data);
+			if (ret) {
+				if (matches)
+					matches[count] = ret;
+				count++;
+			}
+		}
+
 		node = fwnode_graph_get_remote_port_parent(ep);
 		if (!fwnode_device_is_available(node)) {
 			fwnode_handle_put(node);
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 1/7] device property: Add remote endpoint to devcon matcher Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 12:24   ` Andy Shevchenko
  2022-11-24 10:20 ` [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support Pin-yen Lin
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

From: Prashant Malani <pmalani@chromium.org>

When using OF graph, the fw_devlink code will create links between the
individual port driver (cros-ec-typec here) and the parent device for
a Type-C switch (like mode-switch). Since the mode-switch will in turn
have the usb-c-connector (i.e the child of the port driver) as a
supplier, fw_devlink will not be able to resolve the cyclic dependency
correctly.

As a result, the mode-switch driver probe() never runs, so mode-switches
are never registered. Because of that, the port driver probe constantly
fails with -EPROBE_DEFER, because the Type-C connector class requires all
switch devices to be registered prior to port registration.

To break this deadlock and allow the mode-switch registration to occur,
purge all the usb-c-connector nodes' absent suppliers. This eliminates
the connector as a supplier for a switch and allows it to be probed.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Signed-off-by: Pin-yen Lin <treapking@chromium.org>
---

Changes in v6:
- New in v6

 drivers/platform/chrome/cros_ec_typec.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 2a7ff14dc37e..f74e01d18ef3 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -382,6 +382,15 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
 		return -EINVAL;
 	}
 
+	/*
+	 * OF graph may have set up some device links with switches, since connectors have their
+	 * own compatible. Purge these to avoid a deadlock in switch probe (the switch mistakenly
+	 * assumes the connector is a supplier).
+	 */
+	if (dev->of_node)
+		device_for_each_child_node(dev, fwnode)
+			fw_devlink_purge_absent_suppliers(fwnode);
+
 	/* DT uses "reg" to specify port number. */
 	port_prop = dev->of_node ? "reg" : "port-number";
 	device_for_each_child_node(dev, fwnode) {
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 1/7] device property: Add remote endpoint to devcon matcher Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 17:39   ` Rob Herring
  2022-11-27 20:58   ` Krzysztof Kozlowski
  2022-11-24 10:20 ` [PATCH v6 4/7] drm/bridge: anx7625: Check for Type-C during panel registration Pin-yen Lin
                   ` (3 subsequent siblings)
  6 siblings, 2 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

Analogix 7625 can be used in systems to switch the DP traffic between
two downstreams, which can be USB Type-C DisplayPort alternate mode
lane or regular DisplayPort output ports.

Update the binding to accommodate this usage by introducing a
data-lanes and a mode-switch property on endpoints.

Also include the link to the product brief in the bindings.

Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- Remove switches node and use endpoints and data-lanes property to
  describe the connections.

 .../display/bridge/analogix,anx7625.yaml      | 73 ++++++++++++++++++-
 1 file changed, 71 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
index 4590186c4a0b..5fdbf1f3bab8 100644
--- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
@@ -12,7 +12,8 @@ maintainers:
 
 description: |
   The ANX7625 is an ultra-low power 4K Mobile HD Transmitter
-  designed for portable devices.
+  designed for portable devices. Product brief is available at
+  https://www.analogix.com/en/system/files/AA-002291-PB-6-ANX7625_ProductBrief.pdf
 
 properties:
   compatible:
@@ -112,10 +113,36 @@ properties:
               data-lanes: true
 
       port@1:
-        $ref: /schemas/graph.yaml#/properties/port
+        $ref: /schemas/graph.yaml#/properties/port-base
         description:
           Video port for panel or connector.
 
+        patternProperties:
+          "^endpoint@[01]$":
+            $ref: /schemas/media/video-interfaces.yaml#
+            type: object
+            unevaluatedProperties: false
+
+            properties:
+              reg:
+                maxItems: 1
+
+              remote-endpoint: true
+
+              data-lanes:
+                minItems: 1
+                uniqueItems: true
+                items:
+                  - enum: [ 0, 1, 2, 3]
+
+              mode-switch:
+                type: boolean
+                description: Register this node as a Type-C mode switch or not.
+
+            required:
+              - reg
+              - remote-endpoint
+
     required:
       - port@0
       - port@1
@@ -186,3 +213,45 @@ examples:
             };
         };
     };
+  - |
+    &i2c3 {
+	anx_bridge_dp: anx7625-dp@58 {
+	    compatible = "analogix,anx7625";
+	    reg = <0x58>;
+	    pinctrl-names = "default";
+	    pinctrl-0 = <&anx7625_dp_pins>;
+	    enable-gpios = <&pio 176 GPIO_ACTIVE_HIGH>;
+	    reset-gpios = <&pio 177 GPIO_ACTIVE_HIGH>;
+	    vdd10-supply = <&pp1100_dpbrdg>;
+	    vdd18-supply = <&pp1800_dpbrdg_dx>;
+	    vdd33-supply = <&pp3300_dpbrdg_dx>;
+	    analogix,audio-enable;
+
+	    ports {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		port@0 {
+		    reg = <0>;
+		    anx7625_dp_in: endpoint {
+			bus-type = <7>;
+			remote-endpoint = <&dpi_out>;
+		    };
+		};
+
+		port@1 {
+		    reg = <1>;
+		    anx_typec0: endpoint@0 {
+			mode-switch;
+			data-lanes = <0 1>;
+			remote-endpoint = <&typec_port0>;
+		    };
+		    anx_typec1: endpoint@1 {
+			mode-switch;
+			data-lanes = <2 3>;
+			remote-endpoint = <&typec_port1>;
+		    };
+		};
+	    };
+	};
+    };
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 4/7] drm/bridge: anx7625: Check for Type-C during panel registration
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
                   ` (2 preceding siblings ...)
  2022-11-24 10:20 ` [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches Pin-yen Lin
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

The output port endpoints can be connected to USB-C connectors.
Running drm_of_find_panel_or_bridge() with such endpoints leads to
a continuous return value of -EPROBE_DEFER, even though there is
no panel present.

To avoid this, check for the existence of a "mode-switch" property in
the port endpoint, and skip panel registration completely if so.

Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- New in v6

 drivers/gpu/drm/bridge/analogix/anx7625.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index b0ff1ecb80a5..b9e3d6ad8846 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -1650,7 +1650,7 @@ static int anx7625_get_swing_setting(struct device *dev,
 static int anx7625_parse_dt(struct device *dev,
 			    struct anx7625_platform_data *pdata)
 {
-	struct device_node *np = dev->of_node, *ep0;
+	struct device_node *np = dev->of_node, *ep0, *sw;
 	int bus_type, mipi_lanes;
 
 	anx7625_get_swing_setting(dev, pdata);
@@ -1689,6 +1689,17 @@ static int anx7625_parse_dt(struct device *dev,
 	if (of_property_read_bool(np, "analogix,audio-enable"))
 		pdata->audio_en = 1;
 
+	/*
+	 * Don't bother finding a panel if a Type-C `mode-switch` property is
+	 * present in one of the endpoints.
+	 */
+	for_each_endpoint_of_node(np, sw) {
+		if (of_property_read_bool(sw, "mode-switch")) {
+			of_node_put(sw);
+			return 0;
+		}
+	}
+
 	pdata->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0);
 	if (IS_ERR(pdata->panel_bridge)) {
 		if (PTR_ERR(pdata->panel_bridge) == -ENODEV) {
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
                   ` (3 preceding siblings ...)
  2022-11-24 10:20 ` [PATCH v6 4/7] drm/bridge: anx7625: Check for Type-C during panel registration Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 12:18   ` Andy Shevchenko
  2022-11-24 10:20 ` [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support Pin-yen Lin
  2022-11-24 10:20 ` [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches Pin-yen Lin
  6 siblings, 1 reply; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

Register USB Type-C mode switches when the "mode-switch" property and
relevant port are available in Device Tree. Configure the crosspoint
switch based on the entered alternate mode for a specific Type-C
connector.

Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- Squashed to a single patch

 drivers/gpu/drm/bridge/analogix/Kconfig   |   1 +
 drivers/gpu/drm/bridge/analogix/anx7625.c | 169 ++++++++++++++++++++++
 drivers/gpu/drm/bridge/analogix/anx7625.h |  20 +++
 3 files changed, 190 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig
index 173dada218ec..992b43ed1dd7 100644
--- a/drivers/gpu/drm/bridge/analogix/Kconfig
+++ b/drivers/gpu/drm/bridge/analogix/Kconfig
@@ -34,6 +34,7 @@ config DRM_ANALOGIX_ANX7625
 	tristate "Analogix Anx7625 MIPI to DP interface support"
 	depends on DRM
 	depends on OF
+	depends on TYPEC || TYPEC=n
 	select DRM_DISPLAY_DP_HELPER
 	select DRM_DISPLAY_HDCP_HELPER
 	select DRM_DISPLAY_HELPER
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index b9e3d6ad8846..2485e61f5cab 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -15,6 +15,8 @@
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 #include <linux/types.h>
+#include <linux/usb/typec_dp.h>
+#include <linux/usb/typec_mux.h>
 #include <linux/workqueue.h>
 
 #include <linux/of_gpio.h>
@@ -2573,6 +2575,167 @@ static void anx7625_runtime_disable(void *data)
 	pm_runtime_disable(data);
 }
 
+static void anx7625_set_crosspoint_switch(struct anx7625_data *ctx,
+					  enum typec_orientation orientation)
+{
+	if (orientation == TYPEC_ORIENTATION_NORMAL) {
+		anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0,
+				  SW_SEL1_SSRX_RX1 | SW_SEL1_DPTX0_RX2);
+		anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1,
+				  SW_SEL2_SSTX_TX1 | SW_SEL2_DPTX1_TX2);
+	} else if (orientation == TYPEC_ORIENTATION_REVERSE) {
+		anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0,
+				  SW_SEL1_SSRX_RX2 | SW_SEL1_DPTX0_RX1);
+		anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1,
+				  SW_SEL2_SSTX_TX2 | SW_SEL2_DPTX1_TX1);
+	}
+}
+
+static void anx7625_typec_two_ports_update(struct anx7625_data *ctx)
+{
+	if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected)
+		/* Both ports available, do nothing to retain the current one. */
+		return;
+	else if (ctx->typec_ports[0].dp_connected)
+		anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL);
+	else if (ctx->typec_ports[1].dp_connected)
+		anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE);
+}
+
+static int anx7625_typec_mux_set(struct typec_mux_dev *mux,
+				 struct typec_mux_state *state)
+{
+	struct anx7625_port_data *data = typec_mux_get_drvdata(mux);
+	struct anx7625_data *ctx = data->ctx;
+	struct device *dev = &ctx->client->dev;
+	bool new_dp_connected, old_dp_connected;
+
+	if (ctx->num_typec_switches == 1)
+		return 0;
+
+	old_dp_connected = ctx->typec_ports[0].dp_connected || ctx->typec_ports[1].dp_connected;
+
+	data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID &&
+			      state->alt->mode == USB_TYPEC_DP_MODE);
+
+	dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n",
+		ctx->typec_ports[0].dp_connected, ctx->typec_ports[1].dp_connected);
+
+	new_dp_connected = ctx->typec_ports[0].dp_connected || ctx->typec_ports[1].dp_connected;
+
+	/* dp on, power on first */
+	if (!old_dp_connected && new_dp_connected)
+		pm_runtime_get_sync(dev);
+
+	anx7625_typec_two_ports_update(ctx);
+
+	/* dp off, power off last */
+	if (old_dp_connected && !new_dp_connected)
+		pm_runtime_put_sync(dev);
+
+	return 0;
+}
+
+static int anx7625_register_mode_switch(struct device *dev, struct device_node *node,
+					struct anx7625_data *ctx)
+{
+	struct anx7625_port_data *port_data;
+	struct typec_mux_desc mux_desc = {};
+	char name[32];
+	u32 dp_lanes[2];
+	int ret, num_lanes, i, port_num = -1;
+
+	num_lanes = drm_of_get_data_lanes_count(node, 0, 2);
+	if (num_lanes < 0) {
+		dev_err(dev, "Error on getting data lanes count: %d\n", num_lanes);
+		return num_lanes;
+	}
+
+	ret = of_property_read_u32_array(node, "data-lanes", dp_lanes, num_lanes);
+	if (ret) {
+		dev_err(dev, "Failed to read the data-lanes variable: %d\n",
+			ret);
+		return ret;
+	}
+
+	/*
+	 * <0 1> refers to SSRX1/SSTX1, and <2 3> refers to SSRX2/SSTX2.
+	 */
+	for (i = 0; i < num_lanes; i++) {
+		if (port_num != -1 && port_num != dp_lanes[i] / 2) {
+			dev_err(dev, "Invalid data lane numbers\n");
+			return -EINVAL;
+		}
+		port_num = dp_lanes[i] / 2;
+	}
+
+	port_data = &ctx->typec_ports[port_num];
+	port_data->ctx = ctx;
+	mux_desc.fwnode = &node->fwnode;
+	mux_desc.drvdata = port_data;
+	snprintf(name, sizeof(name), "%s-%u", node->name, port_num);
+	mux_desc.name = name;
+	mux_desc.set = anx7625_typec_mux_set;
+
+	port_data->typec_mux = typec_mux_register(dev, &mux_desc);
+	if (IS_ERR(port_data->typec_mux)) {
+		ret = PTR_ERR(port_data->typec_mux);
+		dev_err(dev, "Mode switch register for port %d failed: %d\n",
+			port_num, ret);
+	}
+
+	return ret;
+}
+
+static void anx7625_unregister_typec_switches(struct anx7625_data *ctx)
+{
+	int i;
+
+	for (i = 0; i < ctx->num_typec_switches; i++)
+		typec_mux_unregister(ctx->typec_ports[i].typec_mux);
+}
+
+static int anx7625_register_typec_switches(struct device *dev, struct anx7625_data *ctx)
+{
+	struct device_node *port, *sw;
+	int ret = 0;
+
+	port = of_graph_get_port_by_id(dev->of_node, 1);
+
+	for_each_child_of_node(port, sw) {
+		if (of_property_read_bool(sw, "mode-switch"))
+			ctx->num_typec_switches++;
+	}
+
+	if (!ctx->num_typec_switches) {
+		dev_warn(dev, "No Type-C switches node found\n");
+		return ret;
+	}
+
+	ctx->typec_ports = devm_kcalloc(
+		dev, ctx->num_typec_switches, sizeof(struct anx7625_port_data),
+		GFP_KERNEL);
+	if (!ctx->typec_ports)
+		return -ENOMEM;
+
+	/* Register switches for each connector. */
+	for_each_child_of_node(port, sw) {
+		if (!of_property_read_bool(sw, "mode-switch"))
+			continue;
+		ret = anx7625_register_mode_switch(dev, sw, ctx);
+		if (ret) {
+			dev_err(dev, "Failed to register mode switch: %d\n", ret);
+			of_node_put(sw);
+			break;
+		}
+	}
+
+	if (ret)
+		anx7625_unregister_typec_switches(ctx);
+
+	return ret;
+}
+
 static int anx7625_i2c_probe(struct i2c_client *client,
 			     const struct i2c_device_id *id)
 {
@@ -2681,6 +2844,10 @@ static int anx7625_i2c_probe(struct i2c_client *client,
 	if (platform->pdata.intp_irq)
 		queue_work(platform->workqueue, &platform->work);
 
+	ret = anx7625_register_typec_switches(dev, platform);
+	if (ret && ret != -ENODEV)
+		dev_warn(dev, "Didn't register Type-C switches, err: %d\n", ret);
+
 	platform->bridge.funcs = &anx7625_bridge_funcs;
 	platform->bridge.of_node = client->dev.of_node;
 	if (!anx7625_of_panel_on_aux_bus(&client->dev))
@@ -2732,6 +2899,8 @@ static void anx7625_i2c_remove(struct i2c_client *client)
 
 	drm_bridge_remove(&platform->bridge);
 
+	anx7625_unregister_typec_switches(platform);
+
 	if (platform->pdata.intp_irq)
 		destroy_workqueue(platform->workqueue);
 
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 14f33d6be289..b8634766b04e 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -55,6 +55,18 @@
 #define HPD_STATUS_CHANGE 0x80
 #define HPD_STATUS 0x80
 
+#define TCPC_SWITCH_0 0xB4
+#define SW_SEL1_DPTX0_RX2 BIT(0)
+#define SW_SEL1_DPTX0_RX1 BIT(1)
+#define SW_SEL1_SSRX_RX2 BIT(4)
+#define SW_SEL1_SSRX_RX1 BIT(5)
+
+#define TCPC_SWITCH_1 0xB5
+#define SW_SEL2_DPTX1_TX2 BIT(0)
+#define SW_SEL2_DPTX1_TX1 BIT(1)
+#define SW_SEL2_SSTX_TX2 BIT(4)
+#define SW_SEL2_SSTX_TX1 BIT(5)
+
 /******** END of I2C Address 0x58 ********/
 
 /***************************************************************/
@@ -449,6 +461,12 @@ struct anx7625_i2c_client {
 	struct i2c_client *tcpc_client;
 };
 
+struct anx7625_port_data {
+	bool dp_connected;
+	struct typec_mux_dev *typec_mux;
+	struct anx7625_data *ctx;
+};
+
 struct anx7625_data {
 	struct anx7625_platform_data pdata;
 	struct platform_device *audio_pdev;
@@ -479,6 +497,8 @@ struct anx7625_data {
 	struct drm_connector *connector;
 	struct mipi_dsi_device *dsi;
 	struct drm_dp_aux aux;
+	int num_typec_switches;
+	struct anx7625_port_data *typec_ports;
 };
 
 #endif  /* __ANX7625_H__ */
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
                   ` (4 preceding siblings ...)
  2022-11-24 10:20 ` [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 17:39   ` Rob Herring
  2022-11-27 21:02   ` Krzysztof Kozlowski
  2022-11-24 10:20 ` [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches Pin-yen Lin
  6 siblings, 2 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

ITE IT6505 can be used in systems to switch the DP traffic between
two downstreams, which can be USB Type-C DisplayPort alternate mode
lane or regular DisplayPort output ports.

Update the binding to accommodate this usage by introducing a
data-lanes and a mode-switch property on endpoints.

Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- Remove switches node and use endpoints and data-lanes property to
  describe the connections.

 .../bindings/display/bridge/ite,it6505.yaml   | 94 ++++++++++++++++++-
 1 file changed, 90 insertions(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
index 833d11b2303a..b4b9881c7759 100644
--- a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
+++ b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
@@ -52,9 +52,53 @@ properties:
     maxItems: 1
     description: extcon specifier for the Power Delivery
 
-  port:
-    $ref: /schemas/graph.yaml#/properties/port
-    description: A port node pointing to DPI host port node
+  data-lanes:
+    maxItems: 1
+    description: restrict the dp output data-lanes with value of 1-4
+
+  max-pixel-clock-khz:
+    maxItems: 1
+    description: restrict max pixel clock
+
+  ports:
+    $ref: /schemas/graph.yaml#/properties/ports
+
+    properties:
+      port@0:
+        $ref: /schemas/graph.yaml#/$defs/port-base
+        unevaluatedProperties: false
+        description: A port node pointing to DPI host port node
+
+      port@1:
+        $ref: /schemas/graph.yaml#/properties/port-base
+        description:
+          Video port for panel or connector.
+
+        patternProperties:
+          "^endpoint@[01]$":
+            $ref: /schemas/media/video-interfaces.yaml#
+            type: object
+            unevaluatedProperties: false
+
+            properties:
+              reg:
+                maxItems: 1
+
+              remote-endpoint: true
+
+              data-lanes:
+                minItems: 1
+                uniqueItems: true
+                items:
+                  - enum: [ 0, 1, 2, 3]
+
+              mode-switch:
+                type: boolean
+                description: Register this node as a Type-C mode switch or not.
+
+	    required:
+        - reg
+	      - remote-endpoint
 
 required:
   - compatible
@@ -62,7 +106,7 @@ required:
   - pwr18-supply
   - interrupts
   - reset-gpios
-  - extcon
+  - ports
 
 additionalProperties: false
 
@@ -92,3 +136,45 @@ examples:
             };
         };
     };
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    &i2c3 {
+        clock-frequency = <100000>;
+
+        it6505dptx: it6505dptx@5c {
+            compatible = "ite,it6505";
+            interrupts = <8 IRQ_TYPE_LEVEL_LOW 8 0>;
+            reg = <0x5c>;
+            pinctrl-names = "default";
+            pinctrl-0 = <&it6505_pins>;
+            ovdd-supply = <&mt6366_vsim2_reg>;
+            pwr18-supply = <&pp1800_dpbrdg_dx>;
+            reset-gpios = <&pio 177 0>;
+            hpd-gpios = <&pio 10 0>;
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    it6505_in: endpoint {
+                        remote-endpoint = <&dpi_out>;
+                    };
+                };
+                port@1 {
+                    reg = <1>;
+                    ite_typec0: endpoint@0 {
+                        mode-switch;
+                        data-lanes = <0 1>;
+                        remote-endpoint = <&typec_port0>;
+                    };
+                    ite_typec1: endpoint@1 {
+                        mode-switch;
+                        data-lanes = <2 3>;
+                        remote-endpoint = <&typec_port1>;
+                    };
+                };
+            };
+        };
+    };
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches
  2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
                   ` (5 preceding siblings ...)
  2022-11-24 10:20 ` [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support Pin-yen Lin
@ 2022-11-24 10:20 ` Pin-yen Lin
  2022-11-24 12:23   ` Andy Shevchenko
  6 siblings, 1 reply; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-24 10:20 UTC (permalink / raw)
  To: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, Pin-yen Lin, chrome-platform,
	linux-acpi, Marek Vasut, Xin Ji, Lyude Paul,
	Nícolas F . R . A . Prado, AngeloGioacchino Del Regno,
	linux-kernel, Allen Chen

Register USB Type-C mode switches when the "mode-switch" property and
relevant port are available in Device Tree. Configure the "lane_swap"
state based on the entered alternate mode for a specific Type-C
connector, which ends up updating the lane swap registers of the it6505
chip.

Signed-off-by: Pin-yen Lin <treapking@chromium.org>

---

Changes in v6:
- Changed it6505_typec_mux_set callback function to accommodate with
  the latest drm-misc patches
- Changed the driver implementation to accommodate with the new binding
- Squashed to a single patch

 drivers/gpu/drm/bridge/Kconfig      |   1 +
 drivers/gpu/drm/bridge/ite-it6505.c | 205 +++++++++++++++++++++++++++-
 2 files changed, 202 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig
index 57946d80b02d..9b1240ef3981 100644
--- a/drivers/gpu/drm/bridge/Kconfig
+++ b/drivers/gpu/drm/bridge/Kconfig
@@ -87,6 +87,7 @@ config DRM_FSL_LDB
 config DRM_ITE_IT6505
         tristate "ITE IT6505 DisplayPort bridge"
         depends on OF
+	depends on TYPEC || TYPEC=n
 	select DRM_DISPLAY_DP_HELPER
 	select DRM_DISPLAY_HDCP_HELPER
 	select DRM_DISPLAY_HELPER
diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index 21a9b8422bda..37e2bd8d8d79 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -17,6 +17,8 @@
 #include <linux/regmap.h>
 #include <linux/regulator/consumer.h>
 #include <linux/types.h>
+#include <linux/usb/typec_dp.h>
+#include <linux/usb/typec_mux.h>
 #include <linux/wait.h>
 
 #include <crypto/hash.h>
@@ -30,6 +32,7 @@
 #include <drm/drm_edid.h>
 #include <drm/drm_print.h>
 #include <drm/drm_probe_helper.h>
+#include <drm/drm_of.h>
 
 #include <sound/hdmi-codec.h>
 
@@ -402,6 +405,12 @@ struct debugfs_entries {
 	const struct file_operations *fops;
 };
 
+struct it6505_port_data {
+	bool dp_connected;
+	struct typec_mux_dev *typec_mux;
+	struct it6505 *it6505;
+};
+
 struct it6505 {
 	struct drm_dp_aux aux;
 	struct drm_bridge bridge;
@@ -454,6 +463,8 @@ struct it6505 {
 	struct delayed_work delayed_audio;
 	struct it6505_audio_data audio;
 	struct dentry *debugfs;
+	int num_typec_switches;
+	struct it6505_port_data *typec_ports;
 
 	/* it6505 driver hold option */
 	bool enable_drv_hold;
@@ -3265,13 +3276,185 @@ static void it6505_shutdown(struct i2c_client *client)
 		it6505_lane_off(it6505);
 }
 
+static void it6505_typec_ports_update(struct it6505 *it6505)
+{
+	usleep_range(3000, 4000);
+
+	if (it6505->typec_ports[0].dp_connected && it6505->typec_ports[1].dp_connected)
+		/* Both ports available, do nothing to retain the current one. */
+		return;
+	else if (it6505->typec_ports[0].dp_connected)
+		it6505->lane_swap = false;
+	else if (it6505->typec_ports[1].dp_connected)
+		it6505->lane_swap = true;
+
+	usleep_range(3000, 4000);
+}
+
+static int it6505_typec_mux_set(struct typec_mux_dev *mux,
+				struct typec_mux_state *state)
+{
+	struct it6505_port_data *data = typec_mux_get_drvdata(mux);
+	struct it6505 *it6505 = data->it6505;
+	struct device *dev = &it6505->client->dev;
+	bool old_dp_connected, new_dp_connected;
+
+	if (it6505->num_typec_switches == 1)
+		return 0;
+
+	mutex_lock(&it6505->extcon_lock);
+
+	old_dp_connected = it6505->typec_ports[0].dp_connected ||
+			   it6505->typec_ports[1].dp_connected;
+
+	data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID &&
+			      state->alt->mode == USB_TYPEC_DP_MODE);
+
+	dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n",
+		it6505->typec_ports[0].dp_connected, it6505->typec_ports[1].dp_connected);
+
+	new_dp_connected = it6505->typec_ports[0].dp_connected ||
+			   it6505->typec_ports[1].dp_connected;
+
+	if (it6505->enable_drv_hold) {
+		dev_dbg(dev, "enable driver hold\n");
+		goto unlock;
+	}
+
+	it6505_typec_ports_update(it6505);
+
+	if (!old_dp_connected && new_dp_connected) {
+		int ret = pm_runtime_get_sync(dev);
+
+		/*
+		 * On system resume, mux_set can be triggered before
+		 * pm_runtime_force_resume re-enables runtime power management.
+		 * Handling the error here to make sure the bridge is powered on.
+		 */
+		if (ret < 0)
+			it6505_poweron(it6505);
+
+		complete_all(&it6505->extcon_completion);
+	}
+
+	if (old_dp_connected && !new_dp_connected) {
+		reinit_completion(&it6505->extcon_completion);
+		pm_runtime_put_sync(dev);
+		if (it6505->bridge.dev)
+			drm_helper_hpd_irq_event(it6505->bridge.dev);
+		memset(it6505->dpcd, 0, sizeof(it6505->dpcd));
+	}
+
+unlock:
+	mutex_unlock(&it6505->extcon_lock);
+	return 0;
+}
+
+static int it6505_register_mode_switch(struct device *dev, struct device_node *node,
+				       struct it6505 *it6505)
+{
+	struct it6505_port_data *port_data;
+	struct typec_mux_desc mux_desc = {};
+	char name[32];
+	u32 dp_lanes[2];
+	int ret, num_lanes, i, port_num = -1;
+
+	num_lanes = drm_of_get_data_lanes_count(node, 0, 2);
+	if (num_lanes <= 0) {
+		dev_err(dev, "Error on getting data lanes count: %d\n",
+			num_lanes);
+		return num_lanes;
+	}
+
+	ret = of_property_read_u32_array(node, "data-lanes", dp_lanes, num_lanes);
+	if (ret) {
+		dev_err(dev, "Failed to read the data-lanes variable: %d\n",
+			ret);
+		return ret;
+	}
+
+	for (i = 0; i < num_lanes; i++) {
+		if (port_num != -1 && port_num != dp_lanes[i] / 2) {
+			dev_err(dev, "Invalid data lane numbers\n");
+			return -EINVAL;
+		}
+		port_num = dp_lanes[i] / 2;
+	}
+
+	port_data = &it6505->typec_ports[port_num];
+	port_data->it6505 = it6505;
+	mux_desc.fwnode = &node->fwnode;
+	mux_desc.drvdata = port_data;
+	snprintf(name, sizeof(name), "%s-%u", node->name, port_num);
+	mux_desc.name = name;
+	mux_desc.set = it6505_typec_mux_set;
+
+	port_data->typec_mux = typec_mux_register(dev, &mux_desc);
+	if (IS_ERR(port_data->typec_mux)) {
+		ret = PTR_ERR(port_data->typec_mux);
+		dev_err(dev, "Mode switch register for port %d failed: %d\n",
+			port_num, ret);
+	}
+
+	return ret;
+}
+
+static void it6505_unregister_typec_switches(struct it6505 *it6505)
+{
+	int i;
+
+	for (i = 0; i < it6505->num_typec_switches; i++)
+		typec_mux_unregister(it6505->typec_ports[i].typec_mux);
+}
+
+static int it6505_register_typec_switches(struct device *dev, struct it6505 *it6505)
+{
+	struct device_node *port, *sw;
+	int ret = 0;
+
+	port = of_graph_get_port_by_id(dev->of_node, 1);
+
+	for_each_child_of_node(port, sw) {
+		if (of_property_read_bool(sw, "mode-switch"))
+			it6505->num_typec_switches++;
+	}
+
+	if (!it6505->num_typec_switches) {
+		dev_warn(dev, "No Type-C switches node found\n");
+		return ret;
+	}
+
+	it6505->typec_ports = devm_kzalloc(
+		dev, it6505->num_typec_switches * sizeof(struct it6505_port_data),
+		GFP_KERNEL);
+	if (!it6505->typec_ports)
+		return -ENOMEM;
+
+	/* Register switches for each connector. */
+	for_each_child_of_node(port, sw) {
+		if (!of_property_read_bool(sw, "mode-switch"))
+			continue;
+		ret = it6505_register_mode_switch(dev, sw, it6505);
+		if (ret) {
+			dev_err(dev, "Failed to register mode switch: %d\n", ret);
+			of_node_put(sw);
+			break;
+		}
+	}
+
+	if (ret)
+		it6505_unregister_typec_switches(it6505);
+
+	return ret;
+}
+
 static int it6505_i2c_probe(struct i2c_client *client,
 			    const struct i2c_device_id *id)
 {
 	struct it6505 *it6505;
 	struct device *dev = &client->dev;
 	struct extcon_dev *extcon;
-	int err, intp_irq;
+	int err, intp_irq, ret;
 
 	it6505 = devm_kzalloc(&client->dev, sizeof(*it6505), GFP_KERNEL);
 	if (!it6505)
@@ -3292,11 +3475,24 @@ static int it6505_i2c_probe(struct i2c_client *client,
 	if (PTR_ERR(extcon) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 	if (IS_ERR(extcon)) {
-		dev_err(dev, "can not get extcon device!");
-		return PTR_ERR(extcon);
+		if (PTR_ERR(extcon) != -ENODEV)
+			dev_warn(dev, "Cannot get extcon device: %ld\n",
+				 PTR_ERR(extcon));
+		it6505->extcon = NULL;
+	} else {
+		it6505->extcon = extcon;
 	}
 
-	it6505->extcon = extcon;
+	ret = it6505_register_typec_switches(dev, it6505);
+	if (ret) {
+		if (ret != -ENODEV)
+			dev_warn(dev, "Didn't register Type-C switches, err: %d\n",
+				 ret);
+		if (!it6505->extcon) {
+			dev_err(dev, "Both extcon and typec-switch are not registered.\n");
+			return -EINVAL;
+		}
+	}
 
 	it6505->regmap = devm_regmap_init_i2c(client, &it6505_regmap_config);
 	if (IS_ERR(it6505->regmap)) {
@@ -3367,6 +3563,7 @@ static void it6505_i2c_remove(struct i2c_client *client)
 	drm_dp_aux_unregister(&it6505->aux);
 	it6505_debugfs_remove(it6505);
 	it6505_poweroff(it6505);
+	it6505_unregister_typec_switches(it6505);
 }
 
 static const struct i2c_device_id it6505_id[] = {
-- 
2.38.1.584.g0f3c55d4c2-goog


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

* Re: [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches
  2022-11-24 10:20 ` [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches Pin-yen Lin
@ 2022-11-24 12:18   ` Andy Shevchenko
  2022-11-25  6:58     ` Pin-yen Lin
  0 siblings, 1 reply; 23+ messages in thread
From: Andy Shevchenko @ 2022-11-24 12:18 UTC (permalink / raw)
  To: Pin-yen Lin
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

On Thu, Nov 24, 2022 at 06:20:54PM +0800, Pin-yen Lin wrote:
> Register USB Type-C mode switches when the "mode-switch" property and
> relevant port are available in Device Tree. Configure the crosspoint
> switch based on the entered alternate mode for a specific Type-C
> connector.

...

> +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx)
> +{
> +	if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected)
> +		/* Both ports available, do nothing to retain the current one. */
> +		return;

> +	else if (ctx->typec_ports[0].dp_connected)

This 'else' is redundant. I would rewrite above as

	/* Check if both ports available and do nothing to retain the current one */
	if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected)
		return;

	if (ctx->typec_ports[0].dp_connected)

> +		anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL);
> +	else if (ctx->typec_ports[1].dp_connected)
> +		anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE);
> +}

...

> +	data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID &&
> +			      state->alt->mode == USB_TYPEC_DP_MODE);

Parentheses are not needed.

...

> +	/*
> +	 * <0 1> refers to SSRX1/SSTX1, and <2 3> refers to SSRX2/SSTX2.
> +	 */
> +	for (i = 0; i < num_lanes; i++) {

> +		if (port_num != -1 && port_num != dp_lanes[i] / 2) {
> +			dev_err(dev, "Invalid data lane numbers\n");
> +			return -EINVAL;
> +		}

According to Rob Linux must not validate device tree. If you need it, use
proper YAML schema.

> +		port_num = dp_lanes[i] / 2;
> +	}

...

> +	if (!ctx->num_typec_switches) {
> +		dev_warn(dev, "No Type-C switches node found\n");

> +		return ret;

Why not to return 0 explicitly?

> +	}

...

> +	ctx->typec_ports = devm_kcalloc(

Broken indentation.

> +		dev, ctx->num_typec_switches, sizeof(struct anx7625_port_data),
> +		GFP_KERNEL);
> +	if (!ctx->typec_ports)
> +		return -ENOMEM;

...

> +struct anx7625_port_data {

> +	bool dp_connected;

You can save some bytes on some architectures if move this to be last field.

> +	struct typec_mux_dev *typec_mux;
> +	struct anx7625_data *ctx;
> +};

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches
  2022-11-24 10:20 ` [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches Pin-yen Lin
@ 2022-11-24 12:23   ` Andy Shevchenko
  2022-11-25  6:55     ` Pin-yen Lin
  0 siblings, 1 reply; 23+ messages in thread
From: Andy Shevchenko @ 2022-11-24 12:23 UTC (permalink / raw)
  To: Pin-yen Lin
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

On Thu, Nov 24, 2022 at 06:20:56PM +0800, Pin-yen Lin wrote:
> Register USB Type-C mode switches when the "mode-switch" property and
> relevant port are available in Device Tree. Configure the "lane_swap"
> state based on the entered alternate mode for a specific Type-C
> connector, which ends up updating the lane swap registers of the it6505
> chip.

...

>  config DRM_ITE_IT6505
>          tristate "ITE IT6505 DisplayPort bridge"
>          depends on OF
> +	depends on TYPEC || TYPEC=n
>  	select DRM_DISPLAY_DP_HELPER
>  	select DRM_DISPLAY_HDCP_HELPER
>  	select DRM_DISPLAY_HELPER

Something went wrong with the indentation. Perhaps you need to fix it first.

...

>  #include <drm/drm_edid.h>
>  #include <drm/drm_print.h>
>  #include <drm/drm_probe_helper.h>
> +#include <drm/drm_of.h>

Make it ordered?

...

> +struct it6505_port_data {

> +	bool dp_connected;

Perhaps make it last?

> +	struct typec_mux_dev *typec_mux;
> +	struct it6505 *it6505;
> +};

...

> +static void it6505_typec_ports_update(struct it6505 *it6505)
> +{
> +	usleep_range(3000, 4000);
> +
> +	if (it6505->typec_ports[0].dp_connected && it6505->typec_ports[1].dp_connected)
> +		/* Both ports available, do nothing to retain the current one. */
> +		return;
> +	else if (it6505->typec_ports[0].dp_connected)
> +		it6505->lane_swap = false;
> +	else if (it6505->typec_ports[1].dp_connected)
> +		it6505->lane_swap = true;
> +
> +	usleep_range(3000, 4000);
> +}

As per previous patch comments.

Also, comment out these long sleeps. Why they are needed.

...

> +		int ret = pm_runtime_get_sync(dev);
> +
> +		/*
> +		 * On system resume, mux_set can be triggered before
> +		 * pm_runtime_force_resume re-enables runtime power management.

We refer to the functions as func().

> +		 * Handling the error here to make sure the bridge is powered on.
> +		 */
> +		if (ret < 0)
> +			it6505_poweron(it6505);

This seems needed a bit more of explanation, esp. why you leave PM runtime
reference count bumped up.

...

> +	num_lanes = drm_of_get_data_lanes_count(node, 0, 2);
> +	if (num_lanes <= 0) {
> +		dev_err(dev, "Error on getting data lanes count: %d\n",
> +			num_lanes);
> +		return num_lanes;
> +	}
> +
> +	ret = of_property_read_u32_array(node, "data-lanes", dp_lanes, num_lanes);
> +	if (ret) {
> +		dev_err(dev, "Failed to read the data-lanes variable: %d\n",
> +			ret);
> +		return ret;
> +	}
> +
> +	for (i = 0; i < num_lanes; i++) {
> +		if (port_num != -1 && port_num != dp_lanes[i] / 2) {
> +			dev_err(dev, "Invalid data lane numbers\n");
> +			return -EINVAL;
> +		}

As per previous patch comments.

> +		port_num = dp_lanes[i] / 2;
> +	}

The above seems like tons of duplicating code that drivers need to implement.
Can we shrink that burden by adding some library functions?

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks
  2022-11-24 10:20 ` [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Pin-yen Lin
@ 2022-11-24 12:24   ` Andy Shevchenko
  2022-11-25  5:52     ` Pin-yen Lin
  2022-11-25  5:53     ` Prashant Malani
  0 siblings, 2 replies; 23+ messages in thread
From: Andy Shevchenko @ 2022-11-24 12:24 UTC (permalink / raw)
  To: Pin-yen Lin
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

On Thu, Nov 24, 2022 at 06:20:51PM +0800, Pin-yen Lin wrote:
> From: Prashant Malani <pmalani@chromium.org>
> 
> When using OF graph, the fw_devlink code will create links between the
> individual port driver (cros-ec-typec here) and the parent device for
> a Type-C switch (like mode-switch). Since the mode-switch will in turn
> have the usb-c-connector (i.e the child of the port driver) as a
> supplier, fw_devlink will not be able to resolve the cyclic dependency
> correctly.
> 
> As a result, the mode-switch driver probe() never runs, so mode-switches
> are never registered. Because of that, the port driver probe constantly
> fails with -EPROBE_DEFER, because the Type-C connector class requires all
> switch devices to be registered prior to port registration.
> 
> To break this deadlock and allow the mode-switch registration to occur,
> purge all the usb-c-connector nodes' absent suppliers. This eliminates
> the connector as a supplier for a switch and allows it to be probed.

...

> +	/*
> +	 * OF graph may have set up some device links with switches, since connectors have their
> +	 * own compatible. Purge these to avoid a deadlock in switch probe (the switch mistakenly
> +	 * assumes the connector is a supplier).
> +	 */

A bit too long lines...

> +	if (dev->of_node)

Why do you need this check?

> +		device_for_each_child_node(dev, fwnode)
> +			fw_devlink_purge_absent_suppliers(fwnode);

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support
  2022-11-24 10:20 ` [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support Pin-yen Lin
@ 2022-11-24 17:39   ` Rob Herring
  2022-11-25  3:58     ` Pin-yen Lin
  2022-11-27 21:02   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 23+ messages in thread
From: Rob Herring @ 2022-11-24 17:39 UTC (permalink / raw)
  To: Pin-yen Lin
  Cc: Krzysztof Kozlowski, Jernej Skrabec, Daniel Vetter,
	Greg Kroah-Hartman, Heikki Krogerus, Rafael J . Wysocki, Xin Ji,
	Lyude Paul, Thomas Zimmermann, Benson Leung, Stephen Boyd,
	Jonas Karlman, David Airlie, dri-devel, devicetree,
	Prashant Malani, Hsin-Yi Wang, Javier Martinez Canillas,
	Sakari Ailus, Nícolas F . R . A . Prado, Andrzej Hajda,
	Allen Chen, Marek Vasut, linux-acpi, Andy Shevchenko,
	Daniel Scally, Robert Foss, Laurent Pinchart, Neil Armstrong,
	linux-kernel, Guenter Roeck, AngeloGioacchino Del Regno,
	Rob Herring, chrome-platform


On Thu, 24 Nov 2022 18:20:55 +0800, Pin-yen Lin wrote:
> ITE IT6505 can be used in systems to switch the DP traffic between
> two downstreams, which can be USB Type-C DisplayPort alternate mode
> lane or regular DisplayPort output ports.
> 
> Update the binding to accommodate this usage by introducing a
> data-lanes and a mode-switch property on endpoints.
> 
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 
> ---
> 
> Changes in v6:
> - Remove switches node and use endpoints and data-lanes property to
>   describe the connections.
> 
>  .../bindings/display/bridge/ite,it6505.yaml   | 94 ++++++++++++++++++-
>  1 file changed, 90 insertions(+), 4 deletions(-)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: [error] syntax error: found character '\t' that cannot start any token (syntax)

dtschema/dtc warnings/errors:
make[1]: *** Deleting file 'Documentation/devicetree/bindings/display/bridge/ite,it6505.example.dts'
Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: found character '\t' that cannot start any token
make[1]: *** [Documentation/devicetree/bindings/Makefile:26: Documentation/devicetree/bindings/display/bridge/ite,it6505.example.dts] Error 1
make[1]: *** Waiting for unfinished jobs....
./Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: found character '\t' that cannot start any token
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml: ignoring, error parsing file
make: *** [Makefile:1492: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20221124102056.393220-7-treapking@chromium.org

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command.


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

* Re: [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support
  2022-11-24 10:20 ` [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support Pin-yen Lin
@ 2022-11-24 17:39   ` Rob Herring
  2022-11-25  3:58     ` Pin-yen Lin
  2022-11-27 20:58   ` Krzysztof Kozlowski
  1 sibling, 1 reply; 23+ messages in thread
From: Rob Herring @ 2022-11-24 17:39 UTC (permalink / raw)
  To: Pin-yen Lin
  Cc: Prashant Malani, Greg Kroah-Hartman, Heikki Krogerus, devicetree,
	, Andy Shevchenko, dri-devel, Laurent Pinchart, linux-acpi,
	AngeloGioacchino Del Regno, Rob Herring, chrome-platform,
	Robert Foss, Allen Chen, Hsin-Yi Wang,
	Nícolas F . R . A . Prado, Neil Armstrong, Daniel Vetter,
	Sakari Ailus, Guenter Roeck, Stephen Boyd, Andrzej Hajda,
	Daniel Scally, Marek Vasut, Benson Leung, Rafael J . Wysocki,
	Thomas Zimmermann, David Airlie, linux-kernel, Jonas Karlman,
	Lyude Paul, Krzysztof Kozlowski, Javier Martinez Canillas,
	Xin Ji, Jernej Skrabec


On Thu, 24 Nov 2022 18:20:52 +0800, Pin-yen Lin wrote:
> Analogix 7625 can be used in systems to switch the DP traffic between
> two downstreams, which can be USB Type-C DisplayPort alternate mode
> lane or regular DisplayPort output ports.
> 
> Update the binding to accommodate this usage by introducing a
> data-lanes and a mode-switch property on endpoints.
> 
> Also include the link to the product brief in the bindings.
> 
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 
> ---
> 
> Changes in v6:
> - Remove switches node and use endpoints and data-lanes property to
>   describe the connections.
> 
>  .../display/bridge/analogix,anx7625.yaml      | 73 ++++++++++++++++++-
>  1 file changed, 71 insertions(+), 2 deletions(-)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:
./Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: [error] syntax error: found character '\t' that cannot start any token (syntax)

dtschema/dtc warnings/errors:
make[1]: *** Deleting file 'Documentation/devicetree/bindings/display/bridge/analogix,anx7625.example.dts'
Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: found character '\t' that cannot start any token
make[1]: *** [Documentation/devicetree/bindings/Makefile:26: Documentation/devicetree/bindings/display/bridge/analogix,anx7625.example.dts] Error 1
make[1]: *** Waiting for unfinished jobs....
./Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: found character '\t' that cannot start any token
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml: ignoring, error parsing file
make: *** [Makefile:1492: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20221124102056.393220-4-treapking@chromium.org

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command.


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

* Re: [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support
  2022-11-24 17:39   ` Rob Herring
@ 2022-11-25  3:58     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-25  3:58 UTC (permalink / raw)
  To: Rob Herring
  Cc: Prashant Malani, Greg Kroah-Hartman, Heikki Krogerus, devicetree,
	, Andy Shevchenko, dri-devel, Laurent Pinchart, linux-acpi,
	AngeloGioacchino Del Regno, Rob Herring, chrome-platform,
	Robert Foss, Allen Chen, Hsin-Yi Wang,
	Nícolas F . R . A . Prado, Neil Armstrong, Daniel Vetter,
	Sakari Ailus, Guenter Roeck, Stephen Boyd, Andrzej Hajda,
	Daniel Scally, Marek Vasut, Benson Leung, Rafael J . Wysocki,
	Thomas Zimmermann, David Airlie, linux-kernel, Jonas Karlman,
	Lyude Paul, Krzysztof Kozlowski, Javier Martinez Canillas,
	Xin Ji, Jernej Skrabec

Sorry for accidentally using the tab characters. Will fix this in v7.

On Fri, Nov 25, 2022 at 1:39 AM Rob Herring <robh@kernel.org> wrote:
>
>
> On Thu, 24 Nov 2022 18:20:52 +0800, Pin-yen Lin wrote:
> > Analogix 7625 can be used in systems to switch the DP traffic between
> > two downstreams, which can be USB Type-C DisplayPort alternate mode
> > lane or regular DisplayPort output ports.
> >
> > Update the binding to accommodate this usage by introducing a
> > data-lanes and a mode-switch property on endpoints.
> >
> > Also include the link to the product brief in the bindings.
> >
> > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> >
> > ---
> >
> > Changes in v6:
> > - Remove switches node and use endpoints and data-lanes property to
> >   describe the connections.
> >
> >  .../display/bridge/analogix,anx7625.yaml      | 73 ++++++++++++++++++-
> >  1 file changed, 71 insertions(+), 2 deletions(-)
> >
>
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
>
> yamllint warnings/errors:
> ./Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: [error] syntax error: found character '\t' that cannot start any token (syntax)
>
> dtschema/dtc warnings/errors:
> make[1]: *** Deleting file 'Documentation/devicetree/bindings/display/bridge/analogix,anx7625.example.dts'
> Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: found character '\t' that cannot start any token
> make[1]: *** [Documentation/devicetree/bindings/Makefile:26: Documentation/devicetree/bindings/display/bridge/analogix,anx7625.example.dts] Error 1
> make[1]: *** Waiting for unfinished jobs....
> ./Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml:218:1: found character '\t' that cannot start any token
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml: ignoring, error parsing file
> make: *** [Makefile:1492: dt_binding_check] Error 2
>
> doc reference errors (make refcheckdocs):
>
> See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20221124102056.393220-4-treapking@chromium.org
>
> This check can fail if there are any dependencies. The base for a patch
> series is generally the most recent rc1.
>
> If you already ran 'make dt_binding_check' and didn't see the above
> error(s), then make sure 'yamllint' is installed and dt-schema is up to
> date:
>
> pip3 install dtschema --upgrade
>
> Please check and re-submit after running the above command.
>

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

* Re: [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support
  2022-11-24 17:39   ` Rob Herring
@ 2022-11-25  3:58     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-25  3:58 UTC (permalink / raw)
  To: Rob Herring
  Cc: Krzysztof Kozlowski, Jernej Skrabec, Daniel Vetter,
	Greg Kroah-Hartman, Heikki Krogerus, Rafael J . Wysocki, Xin Ji,
	Lyude Paul, Thomas Zimmermann, Benson Leung, Stephen Boyd,
	Jonas Karlman, David Airlie, dri-devel, devicetree,
	Prashant Malani, Hsin-Yi Wang, Javier Martinez Canillas,
	Sakari Ailus, Nícolas F . R . A . Prado, Andrzej Hajda,
	Allen Chen, Marek Vasut, linux-acpi, Andy Shevchenko,
	Daniel Scally, Robert Foss, Laurent Pinchart, Neil Armstrong,
	linux-kernel, Guenter Roeck, AngeloGioacchino Del Regno,
	Rob Herring, chrome-platform

Sorry for accidentally using the tab characters. Will fix this in v7.

On Fri, Nov 25, 2022 at 1:39 AM Rob Herring <robh@kernel.org> wrote:
>
>
> On Thu, 24 Nov 2022 18:20:55 +0800, Pin-yen Lin wrote:
> > ITE IT6505 can be used in systems to switch the DP traffic between
> > two downstreams, which can be USB Type-C DisplayPort alternate mode
> > lane or regular DisplayPort output ports.
> >
> > Update the binding to accommodate this usage by introducing a
> > data-lanes and a mode-switch property on endpoints.
> >
> > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> >
> > ---
> >
> > Changes in v6:
> > - Remove switches node and use endpoints and data-lanes property to
> >   describe the connections.
> >
> >  .../bindings/display/bridge/ite,it6505.yaml   | 94 ++++++++++++++++++-
> >  1 file changed, 90 insertions(+), 4 deletions(-)
> >
>
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
>
> yamllint warnings/errors:
> ./Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: [error] syntax error: found character '\t' that cannot start any token (syntax)
>
> dtschema/dtc warnings/errors:
> make[1]: *** Deleting file 'Documentation/devicetree/bindings/display/bridge/ite,it6505.example.dts'
> Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: found character '\t' that cannot start any token
> make[1]: *** [Documentation/devicetree/bindings/Makefile:26: Documentation/devicetree/bindings/display/bridge/ite,it6505.example.dts] Error 1
> make[1]: *** Waiting for unfinished jobs....
> ./Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml:99:1: found character '\t' that cannot start any token
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml: ignoring, error parsing file
> make: *** [Makefile:1492: dt_binding_check] Error 2
>
> doc reference errors (make refcheckdocs):
>
> See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20221124102056.393220-7-treapking@chromium.org
>
> This check can fail if there are any dependencies. The base for a patch
> series is generally the most recent rc1.
>
> If you already ran 'make dt_binding_check' and didn't see the above
> error(s), then make sure 'yamllint' is installed and dt-schema is up to
> date:
>
> pip3 install dtschema --upgrade
>
> Please check and re-submit after running the above command.
>

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

* Re: [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks
  2022-11-24 12:24   ` Andy Shevchenko
@ 2022-11-25  5:52     ` Pin-yen Lin
  2022-11-25  5:53     ` Prashant Malani
  1 sibling, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-25  5:52 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Andy,

On Thu, Nov 24, 2022 at 8:25 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Nov 24, 2022 at 06:20:51PM +0800, Pin-yen Lin wrote:
> > From: Prashant Malani <pmalani@chromium.org>
> >
> > When using OF graph, the fw_devlink code will create links between the
> > individual port driver (cros-ec-typec here) and the parent device for
> > a Type-C switch (like mode-switch). Since the mode-switch will in turn
> > have the usb-c-connector (i.e the child of the port driver) as a
> > supplier, fw_devlink will not be able to resolve the cyclic dependency
> > correctly.
> >
> > As a result, the mode-switch driver probe() never runs, so mode-switches
> > are never registered. Because of that, the port driver probe constantly
> > fails with -EPROBE_DEFER, because the Type-C connector class requires all
> > switch devices to be registered prior to port registration.
> >
> > To break this deadlock and allow the mode-switch registration to occur,
> > purge all the usb-c-connector nodes' absent suppliers. This eliminates
> > the connector as a supplier for a switch and allows it to be probed.
>
> ...
>
> > +     /*
> > +      * OF graph may have set up some device links with switches, since connectors have their
> > +      * own compatible. Purge these to avoid a deadlock in switch probe (the switch mistakenly
> > +      * assumes the connector is a supplier).
> > +      */
>
> A bit too long lines...

I'll fix this in v7.

>
> > +     if (dev->of_node)
>
> Why do you need this check?

We use this check to make sure only platforms using OF have their
links purged. I'm not sure if this should also be done on x86
platforms.

Best regards,
Pin-yen

>
> > +             device_for_each_child_node(dev, fwnode)
> > +                     fw_devlink_purge_absent_suppliers(fwnode);
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

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

* Re: [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks
  2022-11-24 12:24   ` Andy Shevchenko
  2022-11-25  5:52     ` Pin-yen Lin
@ 2022-11-25  5:53     ` Prashant Malani
  1 sibling, 0 replies; 23+ messages in thread
From: Prashant Malani @ 2022-11-25  5:53 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Pin-yen Lin, Andrzej Hajda, Neil Armstrong, Robert Foss,
	Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Andy,

Thanks for taking a look at this patch.

Pin-Yen beat me to the punch with comment responses, but I'll add mine anyway.

On Thu, Nov 24, 2022 at 4:25 AM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> ...
>
> > +     /*
> > +      * OF graph may have set up some device links with switches, since connectors have their
> > +      * own compatible. Purge these to avoid a deadlock in switch probe (the switch mistakenly
> > +      * assumes the connector is a supplier).
> > +      */
>
> A bit too long lines...

They are within the 100 character limit [1] which is followed
elsewhere in the driver; has something
changed recently to make that invalid?

>
> > +     if (dev->of_node)
>
> Why do you need this check?

This issue only arises when using DT for this device. So the rationale
is we don't need to
perform this step on systems that don't use DT.

Best regards,

-Prashant

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bdc48fa11e46f867ea4d75fa59ee87a7f48be144

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

* Re: [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches
  2022-11-24 12:23   ` Andy Shevchenko
@ 2022-11-25  6:55     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-25  6:55 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Andy,

Thanks for reviewing the patch.

On Thu, Nov 24, 2022 at 8:23 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Nov 24, 2022 at 06:20:56PM +0800, Pin-yen Lin wrote:
> > Register USB Type-C mode switches when the "mode-switch" property and
> > relevant port are available in Device Tree. Configure the "lane_swap"
> > state based on the entered alternate mode for a specific Type-C
> > connector, which ends up updating the lane swap registers of the it6505
> > chip.
>
> ...
>
> >  config DRM_ITE_IT6505
> >          tristate "ITE IT6505 DisplayPort bridge"
> >          depends on OF
> > +     depends on TYPEC || TYPEC=n
> >       select DRM_DISPLAY_DP_HELPER
> >       select DRM_DISPLAY_HDCP_HELPER
> >       select DRM_DISPLAY_HELPER
>
> Something went wrong with the indentation. Perhaps you need to fix it first.
>
> ...
>
> >  #include <drm/drm_edid.h>
> >  #include <drm/drm_print.h>
> >  #include <drm/drm_probe_helper.h>
> > +#include <drm/drm_of.h>
>
> Make it ordered?

Will fix it in v7.

>
> ...
>
> > +struct it6505_port_data {
>
> > +     bool dp_connected;
>
> Perhaps make it last?

Will fix it in v7.

>
> > +     struct typec_mux_dev *typec_mux;
> > +     struct it6505 *it6505;
> > +};
>
> ...
>
> > +static void it6505_typec_ports_update(struct it6505 *it6505)
> > +{
> > +     usleep_range(3000, 4000);
> > +
> > +     if (it6505->typec_ports[0].dp_connected && it6505->typec_ports[1].dp_connected)
> > +             /* Both ports available, do nothing to retain the current one. */
> > +             return;
> > +     else if (it6505->typec_ports[0].dp_connected)
> > +             it6505->lane_swap = false;
> > +     else if (it6505->typec_ports[1].dp_connected)
> > +             it6505->lane_swap = true;
> > +
> > +     usleep_range(3000, 4000);
> > +}
>
> As per previous patch comments.

Will update it in v7.

>
> Also, comment out these long sleeps. Why they are needed.

Actually, it turns out that these sleeps are not needed. I'll remove it in v7.

>
> ...
>
> > +             int ret = pm_runtime_get_sync(dev);
> > +
> > +             /*
> > +              * On system resume, mux_set can be triggered before
> > +              * pm_runtime_force_resume re-enables runtime power management.
>
> We refer to the functions as func().

Will fix this in v7.

>
> > +              * Handling the error here to make sure the bridge is powered on.
> > +              */
> > +             if (ret < 0)
> > +                     it6505_poweron(it6505);
>
> This seems needed a bit more of explanation, esp. why you leave PM runtime
> reference count bumped up.

pm_runtime_force_suspend() disables runtime PM when the device enters
suspend, and sometime it6505_typec_mux_set() is called before
pm_runtime_force_resume brings runtime PM back. We force power up the
bridge in this case and leave the ref count incremented to make the
future pm_runtime_(get|put)_sync() calls balanced.

I'll include more explanations around this in v7.

>
> ...
>
> > +     num_lanes = drm_of_get_data_lanes_count(node, 0, 2);
> > +     if (num_lanes <= 0) {
> > +             dev_err(dev, "Error on getting data lanes count: %d\n",
> > +                     num_lanes);
> > +             return num_lanes;
> > +     }
> > +
> > +     ret = of_property_read_u32_array(node, "data-lanes", dp_lanes, num_lanes);
> > +     if (ret) {
> > +             dev_err(dev, "Failed to read the data-lanes variable: %d\n",
> > +                     ret);
> > +             return ret;
> > +     }
> > +
> > +     for (i = 0; i < num_lanes; i++) {
> > +             if (port_num != -1 && port_num != dp_lanes[i] / 2) {
> > +                     dev_err(dev, "Invalid data lane numbers\n");
> > +                     return -EINVAL;
> > +             }
>
> As per previous patch comments.

I'll remove this part in v7 and try to figure out how to do similar
checking with schemas.
>
> > +             port_num = dp_lanes[i] / 2;
> > +     }
>
> The above seems like tons of duplicating code that drivers need to implement.
> Can we shrink that burden by adding some library functions?

Could you advise where this lib file should go, and what the namings
can be? The "port-switching" logic is specific to some of the DP
bridges, and I'm not sure what kinds of naming/structure fit into this
case.

Thanks and regards,
Pin-yen

>
> --
> With Best Regards,
> Andy Shevchenko
>
>

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

* Re: [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches
  2022-11-24 12:18   ` Andy Shevchenko
@ 2022-11-25  6:58     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-11-25  6:58 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Daniel Scally, Heikki Krogerus,
	Sakari Ailus, Greg Kroah-Hartman, Rafael J . Wysocki,
	Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Andy,

Thanks for reviewing the patch.

On Thu, Nov 24, 2022 at 8:18 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Nov 24, 2022 at 06:20:54PM +0800, Pin-yen Lin wrote:
> > Register USB Type-C mode switches when the "mode-switch" property and
> > relevant port are available in Device Tree. Configure the crosspoint
> > switch based on the entered alternate mode for a specific Type-C
> > connector.
>
> ...
>
> > +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx)
> > +{
> > +     if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected)
> > +             /* Both ports available, do nothing to retain the current one. */
> > +             return;
>
> > +     else if (ctx->typec_ports[0].dp_connected)
>
> This 'else' is redundant. I would rewrite above as
>
>         /* Check if both ports available and do nothing to retain the current one */
>         if (ctx->typec_ports[0].dp_connected && ctx->typec_ports[1].dp_connected)
>                 return;
>
>         if (ctx->typec_ports[0].dp_connected)
>
> > +             anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL);
> > +     else if (ctx->typec_ports[1].dp_connected)
> > +             anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE);
> > +}

Thanks for the detailed suggestion. I'll adapt this in v7.
>
> ...
>
> > +     data->dp_connected = (state->alt && state->alt->svid == USB_TYPEC_DP_SID &&
> > +                           state->alt->mode == USB_TYPEC_DP_MODE);
>
> Parentheses are not needed.

Will fix this in v7.
>
> ...
>
> > +     /*
> > +      * <0 1> refers to SSRX1/SSTX1, and <2 3> refers to SSRX2/SSTX2.
> > +      */
> > +     for (i = 0; i < num_lanes; i++) {
>
> > +             if (port_num != -1 && port_num != dp_lanes[i] / 2) {
> > +                     dev_err(dev, "Invalid data lane numbers\n");
> > +                     return -EINVAL;
> > +             }
>
> According to Rob Linux must not validate device tree. If you need it, use
> proper YAML schema.
>
> > +             port_num = dp_lanes[i] / 2;
> > +     }
>

I'll remove this from the driver in v7.

> ...
>
> > +     if (!ctx->num_typec_switches) {
> > +             dev_warn(dev, "No Type-C switches node found\n");
>
> > +             return ret;
>
> Why not to return 0 explicitly?

Will update to just "return 0" in v7.

>
> > +     }
>
> ...
>
> > +     ctx->typec_ports = devm_kcalloc(
>
> Broken indentation.

Will fix in v7
>
> > +             dev, ctx->num_typec_switches, sizeof(struct anx7625_port_data),
> > +             GFP_KERNEL);
> > +     if (!ctx->typec_ports)
> > +             return -ENOMEM;
>
> ...
>
> > +struct anx7625_port_data {
>
> > +     bool dp_connected;
>
> You can save some bytes on some architectures if move this to be last field.

Thanks for the suggestion. I'll do so in v7
>
> > +     struct typec_mux_dev *typec_mux;
> > +     struct anx7625_data *ctx;
> > +};
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

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

* Re: [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support
  2022-11-24 10:20 ` [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support Pin-yen Lin
  2022-11-24 17:39   ` Rob Herring
@ 2022-11-27 20:58   ` Krzysztof Kozlowski
  2022-12-26  8:49     ` Pin-yen Lin
  1 sibling, 1 reply; 23+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-27 20:58 UTC (permalink / raw)
  To: Pin-yen Lin, Andrzej Hajda, Neil Armstrong, Robert Foss,
	Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

On 24/11/2022 11:20, Pin-yen Lin wrote:
> Analogix 7625 can be used in systems to switch the DP traffic between
> two downstreams, which can be USB Type-C DisplayPort alternate mode
> lane or regular DisplayPort output ports.
> 
> Update the binding to accommodate this usage by introducing a
> data-lanes and a mode-switch property on endpoints.
> 
> Also include the link to the product brief in the bindings.
> 
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 
> ---
> 
> Changes in v6:
> - Remove switches node and use endpoints and data-lanes property to
>   describe the connections.

Except missing testing few things...

> 
>  .../display/bridge/analogix,anx7625.yaml      | 73 ++++++++++++++++++-
>  1 file changed, 71 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> index 4590186c4a0b..5fdbf1f3bab8 100644
> --- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> +++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> @@ -12,7 +12,8 @@ maintainers:
>  
>  description: |
>    The ANX7625 is an ultra-low power 4K Mobile HD Transmitter
> -  designed for portable devices.
> +  designed for portable devices. Product brief is available at
> +  https://www.analogix.com/en/system/files/AA-002291-PB-6-ANX7625_ProductBrief.pdf
>  
>  properties:
>    compatible:
> @@ -112,10 +113,36 @@ properties:
>                data-lanes: true
>  
>        port@1:
> -        $ref: /schemas/graph.yaml#/properties/port
> +        $ref: /schemas/graph.yaml#/properties/port-base

I don't understand why you are changing this line.

>          description:
>            Video port for panel or connector.
>  
> +        patternProperties:
> +          "^endpoint@[01]$":
> +            $ref: /schemas/media/video-interfaces.yaml#
> +            type: object
> +            unevaluatedProperties: false
> +
> +            properties:
> +              reg:
> +                maxItems: 1
> +
> +              remote-endpoint: true
> +
> +              data-lanes:
> +                minItems: 1
> +                uniqueItems: true

These are confusing... you allow only one item, so why minItems and
uniqueItems?

> +                items:
> +                  - enum: [ 0, 1, 2, 3]
> +
> +              mode-switch:
> +                type: boolean
> +                description: Register this node as a Type-C mode switch or not.
> +
> +            required:
> +              - reg
> +              - remote-endpoint
> +
>      required:
>        - port@0
>        - port@1
> @@ -186,3 +213,45 @@ examples:
>              };
>          };
>      };
> +  - |
> +    &i2c3 {
> +	anx_bridge_dp: anx7625-dp@58 {

Messed up indentation.

> +	    compatible = "analogix,anx7625

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

";
> +	    reg = <0x58>;

Best regards,
Krzysztof


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

* Re: [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support
  2022-11-24 10:20 ` [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support Pin-yen Lin
  2022-11-24 17:39   ` Rob Herring
@ 2022-11-27 21:02   ` Krzysztof Kozlowski
  2022-12-26  8:57     ` Pin-yen Lin
  1 sibling, 1 reply; 23+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-27 21:02 UTC (permalink / raw)
  To: Pin-yen Lin, Andrzej Hajda, Neil Armstrong, Robert Foss,
	Laurent Pinchart, Jonas Karlman, Jernej Skrabec, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Andy Shevchenko,
	Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck
  Cc: Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

On 24/11/2022 11:20, Pin-yen Lin wrote:
> ITE IT6505 can be used in systems to switch the DP traffic between
> two downstreams, which can be USB Type-C DisplayPort alternate mode
> lane or regular DisplayPort output ports.
> 
> Update the binding to accommodate this usage by introducing a
> data-lanes and a mode-switch property on endpoints.
> 
> Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> 
> ---
> 
> Changes in v6:
> - Remove switches node and use endpoints and data-lanes property to
>   describe the connections.
> 
>  .../bindings/display/bridge/ite,it6505.yaml   | 94 ++++++++++++++++++-
>  1 file changed, 90 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> index 833d11b2303a..b4b9881c7759 100644
> --- a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> +++ b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> @@ -52,9 +52,53 @@ properties:
>      maxItems: 1
>      description: extcon specifier for the Power Delivery
>  
> -  port:
> -    $ref: /schemas/graph.yaml#/properties/port
> -    description: A port node pointing to DPI host port node
> +  data-lanes:
> +    maxItems: 1
> +    description: restrict the dp output data-lanes with value of 1-4

Hm, where is the definition of this type? For example it comes with
video-interfaces, which you did not reference here.

> +
> +  max-pixel-clock-khz:

There is no such unit accepted:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

> +    maxItems: 1

maxItems of what type? What is this?

> +    description: restrict max pixel clock
> +
> +  ports:
> +    $ref: /schemas/graph.yaml#/properties/ports

This is incompatible change... how do you handle now ABI break?

> +
> +    properties:
> +      port@0:
> +        $ref: /schemas/graph.yaml#/$defs/port-base

Why changing the ref?

> +        unevaluatedProperties: false
> +        description: A port node pointing to DPI host port node
> +
> +      port@1:
> +        $ref: /schemas/graph.yaml#/properties/port-base
> +        description:
> +          Video port for panel or connector.
> +
> +        patternProperties:
> +          "^endpoint@[01]$":
> +            $ref: /schemas/media/video-interfaces.yaml#
> +            type: object
> +            unevaluatedProperties: false
> +
> +            properties:
> +              reg:
> +                maxItems: 1
> +
> +              remote-endpoint: true
> +
> +              data-lanes:
> +                minItems: 1
> +                uniqueItems: true
> +                items:
> +                  - enum: [ 0, 1, 2, 3]

Same problem as your previouspatch.

> +
> +              mode-switch:
> +                type: boolean
> +                description: Register this node as a Type-C mode switch or not.
> +
> +	    required:
> +        - reg
> +	      - remote-endpoint
>  
>  required:
>    - compatible
> @@ -62,7 +106,7 @@ required:
>    - pwr18-supply
>    - interrupts
>    - reset-gpios
> -  - extcon
> +  - ports
>  
>  additionalProperties: false
>  
> @@ -92,3 +136,45 @@ examples:
>              };
>          };
>      };
> +  - |
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +
> +    &i2c3 {
> +        clock-frequency = <100000>;
> +
> +        it6505dptx: it6505dptx@5c {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

> +            compatible = "ite,it6505";
> +            interrupts = <8 IRQ_TYPE_LEVEL_LOW 8 0>;
> +            reg = <0x5c>;
> +            pinctrl-names = "default";
> +            pinctrl-0 = <&it6505_pins>;
> +            ovdd-supply = <&mt6366_vsim2_reg>;
> +            pwr18-supply = <&pp1800_dpbrdg_dx>;
> +            reset-gpios = <&pio 177 0>;
> +            hpd-gpios = <&pio 10 0>;
> +
> +            ports {
> +                #address-cells = <1>;
> +                #size-cells = <0>;
> +                port@0 {
> +                    reg = <0>;
> +                    it6505_in: endpoint {
> +                        remote-endpoint = <&dpi_out>;
> +                    };
> +                };
> +                port@1 {
> +                    reg = <1>;
> +                    ite_typec0: endpoint@0 {
> +                        mode-switch;
> +                        data-lanes = <0 1>;

Does not look like you tested the bindings. Please run `make
dt_binding_check` (see
Documentation/devicetree/bindings/writing-schema.rst for instructions).

Best regards,
Krzysztof


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

* Re: [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support
  2022-11-27 20:58   ` Krzysztof Kozlowski
@ 2022-12-26  8:49     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-12-26  8:49 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Krzysztof,

Thanks for the review.

On Mon, Nov 28, 2022 at 4:58 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 24/11/2022 11:20, Pin-yen Lin wrote:
> > Analogix 7625 can be used in systems to switch the DP traffic between
> > two downstreams, which can be USB Type-C DisplayPort alternate mode
> > lane or regular DisplayPort output ports.
> >
> > Update the binding to accommodate this usage by introducing a
> > data-lanes and a mode-switch property on endpoints.
> >
> > Also include the link to the product brief in the bindings.
> >
> > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> >
> > ---
> >
> > Changes in v6:
> > - Remove switches node and use endpoints and data-lanes property to
> >   describe the connections.
>
> Except missing testing few things...
>
> >
> >  .../display/bridge/analogix,anx7625.yaml      | 73 ++++++++++++++++++-
> >  1 file changed, 71 insertions(+), 2 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > index 4590186c4a0b..5fdbf1f3bab8 100644
> > --- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > +++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml
> > @@ -12,7 +12,8 @@ maintainers:
> >
> >  description: |
> >    The ANX7625 is an ultra-low power 4K Mobile HD Transmitter
> > -  designed for portable devices.
> > +  designed for portable devices. Product brief is available at
> > +  https://www.analogix.com/en/system/files/AA-002291-PB-6-ANX7625_ProductBrief.pdf
> >
> >  properties:
> >    compatible:
> > @@ -112,10 +113,36 @@ properties:
> >                data-lanes: true
> >
> >        port@1:
> > -        $ref: /schemas/graph.yaml#/properties/port
> > +        $ref: /schemas/graph.yaml#/properties/port-base
>
> I don't understand why you are changing this line.

Without this change, the `unevaluatedProperties: false` in
`/schemas/graph.yaml#/properties/port` does not allow me to add new
properties.
>
> >          description:
> >            Video port for panel or connector.
> >
> > +        patternProperties:
> > +          "^endpoint@[01]$":
> > +            $ref: /schemas/media/video-interfaces.yaml#
> > +            type: object
> > +            unevaluatedProperties: false
> > +
> > +            properties:
> > +              reg:
> > +                maxItems: 1
> > +
> > +              remote-endpoint: true
> > +
> > +              data-lanes:
> > +                minItems: 1
> > +                uniqueItems: true
>
> These are confusing... you allow only one item, so why minItems and
> uniqueItems?

What I want to use is something like:
```
items:
  enum: [0,1, 2, 3]
```
That is, all the items should be an integer between 0 and 3. I'll
update this to a stricter version in v7.
>
> > +                items:
> > +                  - enum: [ 0, 1, 2, 3]
> > +
> > +              mode-switch:
> > +                type: boolean
> > +                description: Register this node as a Type-C mode switch or not.
> > +
> > +            required:
> > +              - reg
> > +              - remote-endpoint
> > +
> >      required:
> >        - port@0
> >        - port@1
> > @@ -186,3 +213,45 @@ examples:
> >              };
> >          };
> >      };
> > +  - |
> > +    &i2c3 {
> > +     anx_bridge_dp: anx7625-dp@58 {
>
> Messed up indentation.
I'll fix this in the next version.
>
> > +         compatible = "analogix,anx7625
>
> Node names should be generic.
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
I'll update this in v7.
>
> ";
> > +         reg = <0x58>;
>
> Best regards,
> Krzysztof
>

Best regards,
Pin-yen

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

* Re: [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support
  2022-11-27 21:02   ` Krzysztof Kozlowski
@ 2022-12-26  8:57     ` Pin-yen Lin
  0 siblings, 0 replies; 23+ messages in thread
From: Pin-yen Lin @ 2022-12-26  8:57 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Andrzej Hajda, Neil Armstrong, Robert Foss, Laurent Pinchart,
	Jonas Karlman, Jernej Skrabec, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Andy Shevchenko, Daniel Scally,
	Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J . Wysocki, Prashant Malani, Benson Leung, Guenter Roeck,
	Javier Martinez Canillas, Stephen Boyd, dri-devel, Hsin-Yi Wang,
	Thomas Zimmermann, devicetree, chrome-platform, linux-acpi,
	Marek Vasut, Xin Ji, Lyude Paul, Nícolas F . R . A . Prado,
	AngeloGioacchino Del Regno, linux-kernel, Allen Chen

Hi Krzysztof,

On Mon, Nov 28, 2022 at 5:02 AM Krzysztof Kozlowski
<krzysztof.kozlowski@linaro.org> wrote:
>
> On 24/11/2022 11:20, Pin-yen Lin wrote:
> > ITE IT6505 can be used in systems to switch the DP traffic between
> > two downstreams, which can be USB Type-C DisplayPort alternate mode
> > lane or regular DisplayPort output ports.
> >
> > Update the binding to accommodate this usage by introducing a
> > data-lanes and a mode-switch property on endpoints.
> >
> > Signed-off-by: Pin-yen Lin <treapking@chromium.org>
> >
> > ---
> >
> > Changes in v6:
> > - Remove switches node and use endpoints and data-lanes property to
> >   describe the connections.
> >
> >  .../bindings/display/bridge/ite,it6505.yaml   | 94 ++++++++++++++++++-
> >  1 file changed, 90 insertions(+), 4 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> > index 833d11b2303a..b4b9881c7759 100644
> > --- a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> > +++ b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml
> > @@ -52,9 +52,53 @@ properties:
> >      maxItems: 1
> >      description: extcon specifier for the Power Delivery
> >
> > -  port:
> > -    $ref: /schemas/graph.yaml#/properties/port
> > -    description: A port node pointing to DPI host port node
> > +  data-lanes:
> > +    maxItems: 1
> > +    description: restrict the dp output data-lanes with value of 1-4
>
> Hm, where is the definition of this type? For example it comes with
> video-interfaces, which you did not reference here.
>
Actually I messed up here with another accepted patch:
https://lore.kernel.org/all/20221103091243.96036-2-allen.chen@ite.com.tw/

This and the next new property have been added in that patch.
> > +
> > +  max-pixel-clock-khz:
>
> There is no such unit accepted:
> https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml
>
> > +    maxItems: 1
>
> maxItems of what type? What is this?
>
> > +    description: restrict max pixel clock
> > +
> > +  ports:
> > +    $ref: /schemas/graph.yaml#/properties/ports
>
> This is incompatible change... how do you handle now ABI break?
>
This is also added in another patch, and currently we don't have any
upstream it6505 users now.
> > +
> > +    properties:
> > +      port@0:
> > +        $ref: /schemas/graph.yaml#/$defs/port-base
>
> Why changing the ref?

The `unevaluatedProperties: false` in
`/schemas/graph.yaml#/properties/port` does not allow me to add new
properties here.
>
> > +        unevaluatedProperties: false
> > +        description: A port node pointing to DPI host port node
> > +
> > +      port@1:
> > +        $ref: /schemas/graph.yaml#/properties/port-base
> > +        description:
> > +          Video port for panel or connector.
> > +
> > +        patternProperties:
> > +          "^endpoint@[01]$":
> > +            $ref: /schemas/media/video-interfaces.yaml#
> > +            type: object
> > +            unevaluatedProperties: false
> > +
> > +            properties:
> > +              reg:
> > +                maxItems: 1
> > +
> > +              remote-endpoint: true
> > +
> > +              data-lanes:
> > +                minItems: 1
> > +                uniqueItems: true
> > +                items:
> > +                  - enum: [ 0, 1, 2, 3]
>
> Same problem as your previouspatch.
>
> > +
> > +              mode-switch:
> > +                type: boolean
> > +                description: Register this node as a Type-C mode switch or not.
> > +
> > +         required:
> > +        - reg
> > +           - remote-endpoint
> >
> >  required:
> >    - compatible
> > @@ -62,7 +106,7 @@ required:
> >    - pwr18-supply
> >    - interrupts
> >    - reset-gpios
> > -  - extcon
> > +  - ports
> >
> >  additionalProperties: false
> >
> > @@ -92,3 +136,45 @@ examples:
> >              };
> >          };
> >      };
> > +  - |
> > +    #include <dt-bindings/interrupt-controller/irq.h>
> > +
> > +    &i2c3 {
> > +        clock-frequency = <100000>;
> > +
> > +        it6505dptx: it6505dptx@5c {
>
> Node names should be generic.
> https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation
>
I'll fix this in v7.
> > +            compatible = "ite,it6505";
> > +            interrupts = <8 IRQ_TYPE_LEVEL_LOW 8 0>;
> > +            reg = <0x5c>;
> > +            pinctrl-names = "default";
> > +            pinctrl-0 = <&it6505_pins>;
> > +            ovdd-supply = <&mt6366_vsim2_reg>;
> > +            pwr18-supply = <&pp1800_dpbrdg_dx>;
> > +            reset-gpios = <&pio 177 0>;
> > +            hpd-gpios = <&pio 10 0>;
> > +
> > +            ports {
> > +                #address-cells = <1>;
> > +                #size-cells = <0>;
> > +                port@0 {
> > +                    reg = <0>;
> > +                    it6505_in: endpoint {
> > +                        remote-endpoint = <&dpi_out>;
> > +                    };
> > +                };
> > +                port@1 {
> > +                    reg = <1>;
> > +                    ite_typec0: endpoint@0 {
> > +                        mode-switch;
> > +                        data-lanes = <0 1>;
>
> Does not look like you tested the bindings. Please run `make
> dt_binding_check` (see
> Documentation/devicetree/bindings/writing-schema.rst for instructions).
Sorry for not checking the documentation and testing the patches
before submitting this.

I'll fix the errors in v7.

Best regards,
Pin-yen
>
> Best regards,
> Krzysztof
>

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

end of thread, other threads:[~2022-12-26  8:57 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-24 10:20 [PATCH v6 0/7] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 1/7] device property: Add remote endpoint to devcon matcher Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 2/7] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Pin-yen Lin
2022-11-24 12:24   ` Andy Shevchenko
2022-11-25  5:52     ` Pin-yen Lin
2022-11-25  5:53     ` Prashant Malani
2022-11-24 10:20 ` [PATCH v6 3/7] dt-bindings: drm/bridge: anx7625: Add mode-switch support Pin-yen Lin
2022-11-24 17:39   ` Rob Herring
2022-11-25  3:58     ` Pin-yen Lin
2022-11-27 20:58   ` Krzysztof Kozlowski
2022-12-26  8:49     ` Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 4/7] drm/bridge: anx7625: Check for Type-C during panel registration Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 5/7] drm/bridge: anx7625: Register Type C mode switches Pin-yen Lin
2022-11-24 12:18   ` Andy Shevchenko
2022-11-25  6:58     ` Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 6/7] dt/bindings: drm/bridge: it6505: Add mode-switch support Pin-yen Lin
2022-11-24 17:39   ` Rob Herring
2022-11-25  3:58     ` Pin-yen Lin
2022-11-27 21:02   ` Krzysztof Kozlowski
2022-12-26  8:57     ` Pin-yen Lin
2022-11-24 10:20 ` [PATCH v6 7/7] drm/bridge: it6505: Register Type C mode switches Pin-yen Lin
2022-11-24 12:23   ` Andy Shevchenko
2022-11-25  6:55     ` Pin-yen Lin

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).