2022-06-22 18:21:58

by Prashant Malani

[permalink] [raw]
Subject: [PATCH v5 0/9] usb: typec: Introduce typec-switch binding

This series introduces a binding for Type-C data lane switches. These
control the routing and operating modes of USB Type-C data lanes based
on the PD messaging from the Type-C port driver regarding connected
peripherals.

The first 2 patches introduce the new "typec-switch" binding as
well as one user of it (the ANX7625 drm bridge).

Patches 3-5 add functionality to the anx7625 driver to
register the mode-switches, as well as program its crosspoint
switch depending on which Type-C port has a DisplayPort (DP) peripheral
connected to it.

Patch 6-9 add similar bindings update and Type-C switch support to the
it6505 driver.

v4:
https://lore.kernel.org/linux-usb/[email protected]/

Changes in v5:
- Rebased on usb-next, so removed Patch v4 1/7 and Patch v4 2/7 from
this version (v5) since they are already in usb-next.
- Added newer Reviewed-by tags.
- Added new patches (6-9) in this version for a 2nd example (it6505)
of a binding of the user.

Patch submission suggestions:
Option 1:
- Bindings patches 1/9 and 2/9 can go through the USB repo (since they are
already reviewed from v4 [1]).
- Bindings patch 6/9 can go through the USB repo, and the remaining patches
(3-5,7-9) can go through the DRM repo.
<or>
- Patches 3-9 can all go through the DRM repo.

Option 2:
- All patches (1-9) go through the USB repo.

(My apologies if I've made this confusing, and I appreciate any
suggestions for better submission strategy).

[1]: https://lore.kernel.org/linux-usb/YrMxFeMc0tk%[email protected]/

Pin-Yen Lin (5):
drm/bridge: anx7625: Add typec_mux_set callback function
dt/bindings: drm/bridge: it6505: Add mode-switch support
drm/bridge: it6505: Register number of Type C switches
drm/bridge: it6505: Register Type-C mode switches
drm/bridge: it6505: Add typec_mux_set callback function

Prashant Malani (4):
dt-bindings: usb: Add Type-C switch binding
dt-bindings: drm/bridge: anx7625: Add mode-switch support
drm/bridge: anx7625: Register number of Type C switches
drm/bridge: anx7625: Register Type-C mode switches

.../display/bridge/analogix,anx7625.yaml | 64 +++++++
.../bindings/display/bridge/ite,it6505.yaml | 97 +++++++++-
.../devicetree/bindings/usb/typec-switch.yaml | 74 ++++++++
drivers/gpu/drm/bridge/analogix/anx7625.c | 148 +++++++++++++++
drivers/gpu/drm/bridge/analogix/anx7625.h | 20 ++
drivers/gpu/drm/bridge/ite-it6505.c | 171 +++++++++++++++++-
6 files changed, 569 insertions(+), 5 deletions(-)
create mode 100644 Documentation/devicetree/bindings/usb/typec-switch.yaml

--
2.37.0.rc0.104.g0611611a94-goog


2022-06-22 18:38:00

by Prashant Malani

[permalink] [raw]
Subject: [PATCH v5 8/9] drm/bridge: it6505: Register Type-C mode switches

From: Pin-Yen Lin <[email protected]>

When the DT node has "switches" available, register a Type-C mode-switch
for each listed "switch". This allows the driver to receive state
information about what operating mode a Type-C port and its connected
peripherals are in, as well as status information (like VDOs) related to
that state.

The callback function is currently a stub, but subsequent patches will
implement the required functionality.

Signed-off-by: Pin-Yen Lin <[email protected]>
Signed-off-by: Prashant Malani <[email protected]>
---

v5 is the first version for this patch.

drivers/gpu/drm/bridge/ite-it6505.c | 85 ++++++++++++++++++++++++++++-
1 file changed, 82 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index b259f9f367f6..cb1dd4cbd33b 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -17,6 +17,7 @@
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/types.h>
+#include <linux/usb/typec_mux.h>
#include <linux/wait.h>

#include <crypto/hash.h>
@@ -402,6 +403,11 @@ struct debugfs_entries {
const struct file_operations *fops;
};

+struct it6505_port_data {
+ struct typec_mux_dev *typec_mux;
+ struct it6505 *it6505;
+};
+
struct it6505 {
struct drm_dp_aux aux;
struct drm_bridge bridge;
@@ -453,6 +459,7 @@ struct it6505 {
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;
@@ -3230,9 +3237,59 @@ static void it6505_shutdown(struct i2c_client *client)
it6505_lane_off(it6505);
}

+static int it6505_typec_mux_set(struct typec_mux_dev *mux,
+ struct typec_mux_state *state)
+{
+ 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 port_num;
+ int ret;
+
+ ret = of_property_read_u32(node, "reg", &port_num);
+ if (ret)
+ return ret;
+
+ if (port_num >= it6505->num_typec_switches) {
+ dev_err(dev, "Invalid port number specified: %d\n", port_num);
+ return -EINVAL;
+ }
+
+ 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", 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 *device, struct it6505 *it6505)
{
- struct device_node *of;
+ struct device_node *of, *sw;
+ int ret = 0;

of = of_get_child_by_name(device->of_node, "switches");
if (!of)
@@ -3241,8 +3298,28 @@ static int it6505_register_typec_switches(struct device *device, struct it6505 *
it6505->num_typec_switches = of_get_child_count(of);
if (it6505->num_typec_switches <= 0)
return -ENODEV;
+ it6505->typec_ports = devm_kzalloc(device,
+ it6505->num_typec_switches *
+ sizeof(struct it6505_port_data),
+ GFP_KERNEL);
+ if (!it6505->typec_ports)
+ return -ENOMEM;

- return 0;
+ /* Register switches for each connector. */
+ for_each_available_child_of_node(of, sw) {
+ if (!of_property_read_bool(sw, "mode-switch"))
+ continue;
+ ret = it6505_register_mode_switch(device, sw, it6505);
+ if (ret) {
+ dev_err(device, "Failed to register mode switch: %d\n", ret);
+ break;
+ }
+ }
+
+ if (ret)
+ it6505_unregister_typec_switches(it6505);
+
+ return ret;
}

static int it6505_i2c_probe(struct i2c_client *client,
@@ -3280,7 +3357,8 @@ static int it6505_i2c_probe(struct i2c_client *client,

ret = it6505_register_typec_switches(dev, it6505);
if (ret) {
- dev_dbg(dev, "Didn't register Type C switches, err: %d", ret);
+ if (ret != -ENODEV)
+ dev_warn(dev, "Didn't register Type C switches, err: %d", ret);
if (!it6505->extcon) {
dev_err(dev, "Both extcon and typec-switch are not registered.");
return -EINVAL;
@@ -3350,6 +3428,7 @@ static int 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);

return 0;
}
--
2.37.0.rc0.104.g0611611a94-goog

2022-06-22 18:54:38

by Prashant Malani

[permalink] [raw]
Subject: [PATCH v5 9/9] drm/bridge: it6505: Add typec_mux_set callback function

From: Pin-Yen Lin <[email protected]>

Add the callback function when the driver receives state changes of the
Type-C ports. The callback function configures the lane_swap state and
ends up updating the lane swap registers of it6505 bridge chip.

Signed-off-by: Pin-Yen Lin <[email protected]>
Signed-off-by: Prashant Malani <[email protected]>
---

v5 is the first version for this patch.

drivers/gpu/drm/bridge/ite-it6505.c | 58 +++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)

diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index cb1dd4cbd33b..87b9bd742b52 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -17,6 +17,7 @@
#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>

@@ -404,6 +405,7 @@ struct debugfs_entries {
};

struct it6505_port_data {
+ bool dp_connected;
struct typec_mux_dev *typec_mux;
struct it6505 *it6505;
};
@@ -3237,9 +3239,65 @@ 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;
+
+ dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n",
+ 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);
+
+ 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");
+ goto unlock;
+ }
+
+ it6505_typec_ports_update(it6505);
+
+ if (!old_dp_connected && new_dp_connected)
+ pm_runtime_get_sync(dev);
+
+ if (old_dp_connected && !new_dp_connected) {
+ 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;
}

--
2.37.0.rc0.104.g0611611a94-goog