From: Pin-yen Lin <treapking@chromium.org>
To: Andrzej Hajda <andrzej.hajda@intel.com>,
Neil Armstrong <neil.armstrong@linaro.org>,
Robert Foss <robert.foss@linaro.org>,
Laurent Pinchart <Laurent.pinchart@ideasonboard.com>,
Jonas Karlman <jonas@kwiboo.se>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J . Wysocki" <rafael@kernel.org>,
Prashant Malani <pmalani@chromium.org>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>
Cc: "Thomas Zimmermann" <tzimmermann@suse.de>,
dri-devel@lists.freedesktop.org, "Lyude Paul" <lyude@redhat.com>,
"Javier Martinez Canillas" <javierm@redhat.com>,
linux-kernel@vger.kernel.org, "Xin Ji" <xji@analogixsemi.com>,
"Pin-yen Lin" <treapking@chromium.org>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
"Allen Chen" <allen.chen@ite.com.tw>,
"Hsin-Yi Wang" <hsinyi@chromium.org>,
chrome-platform@lists.linux.dev,
"Nícolas F . R . A . Prado" <nfraprado@collabora.com>,
devicetree@vger.kernel.org, "Marek Vasut" <marex@denx.de>,
linux-acpi@vger.kernel.org, "Stephen Boyd" <swboyd@chromium.org>
Subject: [PATCH v8 6/9] drm/bridge: anx7625: Register Type C mode switches
Date: Sat, 7 Jan 2023 18:22:28 +0800 [thread overview]
Message-ID: <20230107102231.23682-7-treapking@chromium.org> (raw)
In-Reply-To: <20230107102231.23682-1-treapking@chromium.org>
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>
---
(no changes since v7)
Changes in v7:
- Fixed style issues in anx7625 driver
- Removed DT property validation in anx7625 driver.
- Extracted common codes to another commit.
Changes in v6:
- Squashed to a single patch
drivers/gpu/drm/bridge/analogix/Kconfig | 1 +
drivers/gpu/drm/bridge/analogix/anx7625.c | 88 +++++++++++++++++++++++
drivers/gpu/drm/bridge/analogix/anx7625.h | 13 ++++
3 files changed, 102 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 1cf242130b91..2bb504a8d789 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>
@@ -2572,6 +2574,86 @@ 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)
+{
+ struct drm_dp_typec_switch_desc switch_desc = ctx->switch_desc;
+ /* Check if both ports available and do nothing to retain the current one */
+ if (switch_desc.typec_ports[0].dp_connected && switch_desc.typec_ports[1].dp_connected)
+ return;
+
+ if (switch_desc.typec_ports[0].dp_connected)
+ anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL);
+ else if (switch_desc.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 drm_dp_typec_port_data *port_data = typec_mux_get_drvdata(mux);
+ struct anx7625_data *ctx = (struct anx7625_data *) port_data->data;
+ struct device *dev = &ctx->client->dev;
+ struct drm_dp_typec_switch_desc switch_desc = ctx->switch_desc;
+ bool new_dp_connected, old_dp_connected;
+
+ if (switch_desc.num_typec_switches == 1)
+ return 0;
+
+ old_dp_connected = switch_desc.typec_ports[0].dp_connected ||
+ switch_desc.typec_ports[1].dp_connected;
+
+ port_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",
+ switch_desc.typec_ports[0].dp_connected, switch_desc.typec_ports[1].dp_connected);
+
+ new_dp_connected = switch_desc.typec_ports[0].dp_connected ||
+ switch_desc.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 void anx7625_unregister_typec_switches(struct anx7625_data *ctx)
+{
+ drm_dp_unregister_typec_switches(&ctx->switch_desc);
+}
+
+static int anx7625_register_typec_switches(struct device *dev, struct anx7625_data *ctx)
+{
+ struct device_node *port = of_graph_get_port_by_id(dev->of_node, 1);
+
+ return drm_dp_register_typec_switches(dev, port, &ctx->switch_desc,
+ ctx, anx7625_typec_mux_set);
+}
+
static int anx7625_i2c_probe(struct i2c_client *client)
{
struct anx7625_data *platform;
@@ -2679,6 +2761,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))
@@ -2730,6 +2816,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..38abbd3d6b36 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 ********/
/***************************************************************/
@@ -479,6 +491,7 @@ struct anx7625_data {
struct drm_connector *connector;
struct mipi_dsi_device *dsi;
struct drm_dp_aux aux;
+ struct drm_dp_typec_switch_desc switch_desc;
};
#endif /* __ANX7625_H__ */
--
2.39.0.314.g84b9a713c41-goog
next prev parent reply other threads:[~2023-01-07 10:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-07 10:22 [PATCH v8 0/9] Register Type-C mode-switch in DP bridge endpoints Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 1/9] device property: Add remote endpoint to devcon matcher Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 2/9] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 3/9] drm/display: Add Type-C switch helpers Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 4/9] dt-bindings: display: bridge: anx7625: Add mode-switch support Pin-yen Lin
2023-01-08 14:56 ` Krzysztof Kozlowski
2023-01-07 10:22 ` [PATCH v8 5/9] drm/bridge: anx7625: Check for Type-C during panel registration Pin-yen Lin
2023-01-07 10:22 ` Pin-yen Lin [this message]
2023-01-07 10:22 ` [PATCH v8 7/9] dt/bindings: display: bridge: it6505: Add mode-switch support Pin-yen Lin
2023-01-08 14:59 ` Krzysztof Kozlowski
2023-01-09 8:36 ` Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 8/9] drm/bridge: it6505: Fix Kconfig indentation Pin-yen Lin
2023-01-07 10:22 ` [PATCH v8 9/9] drm/bridge: it6505: Register Type C mode switches Pin-yen Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230107102231.23682-7-treapking@chromium.org \
--to=treapking@chromium.org \
--cc=Laurent.pinchart@ideasonboard.com \
--cc=airlied@gmail.com \
--cc=allen.chen@ite.com.tw \
--cc=andriy.shevchenko@linux.intel.com \
--cc=andrzej.hajda@intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=daniel@ffwll.ch \
--cc=devicetree@vger.kernel.org \
--cc=djrscally@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=groeck@chromium.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=hsinyi@chromium.org \
--cc=javierm@redhat.com \
--cc=jernej.skrabec@gmail.com \
--cc=jonas@kwiboo.se \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lyude@redhat.com \
--cc=marex@denx.de \
--cc=neil.armstrong@linaro.org \
--cc=nfraprado@collabora.com \
--cc=pmalani@chromium.org \
--cc=rafael@kernel.org \
--cc=robert.foss@linaro.org \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
--cc=swboyd@chromium.org \
--cc=tzimmermann@suse.de \
--cc=xji@analogixsemi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox