[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240901040658.157425-19-swboyd@chromium.org>
Date: Sat, 31 Aug 2024 21:06:56 -0700
From: Stephen Boyd <swboyd@...omium.org>
To: chrome-platform@...ts.linux.dev
Cc: linux-kernel@...r.kernel.org,
patches@...ts.linux.dev,
devicetree@...r.kernel.org,
Douglas Anderson <dianders@...omium.org>,
Pin-yen Lin <treapking@...omium.org>,
Andrzej Hajda <andrzej.hajda@...el.com>,
Benson Leung <bleung@...omium.org>,
Conor Dooley <conor+dt@...nel.org>,
Daniel Vetter <daniel@...ll.ch>,
David Airlie <airlied@...il.com>,
Dmitry Baryshkov <dmitry.baryshkov@...aro.org>,
dri-devel@...ts.freedesktop.org,
Guenter Roeck <groeck@...omium.org>,
Jernej Skrabec <jernej.skrabec@...il.com>,
Jonas Karlman <jonas@...boo.se>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Laurent Pinchart <Laurent.pinchart@...asonboard.com>,
Lee Jones <lee@...nel.org>,
Maarten Lankhorst <maarten.lankhorst@...ux.intel.com>,
Maxime Ripard <mripard@...nel.org>,
Neil Armstrong <neil.armstrong@...aro.org>,
Prashant Malani <pmalani@...omium.org>,
Robert Foss <rfoss@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Thomas Zimmermann <tzimmermann@...e.de>,
Tzung-Bi Shih <tzungbi@...nel.org>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Ivan Orlov <ivan.orlov0322@...il.com>,
linux-acpi@...r.kernel.org,
linux-usb@...r.kernel.org,
Mika Westerberg <mika.westerberg@...ux.intel.com>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Vinod Koul <vkoul@...nel.org>
Subject: [PATCH v4 18/18] platform/chrome: cros_ec_typec: Handle lack of HPD information
Some EC firmwares on Trogdor/Strongbad boards don't properly indicate
the state of DP HPD on a type-c port. Instead, the EC only indicates
that a type-c port has entered or exited DP mode. To make matters worse,
on these boards the DP signal is muxed between two USB type-c
connectors, so we can't use the DP entry of a port to figure out which
type-c port is actually displaying DP.
Stash the HPD state in this case whenever the drm_bridge is notified of
a connector status change and kick off the port worker so that the
type-c port state can be re-evaluated. If an analog mux is in use, read
the mux to figure out which type-c port signaled HPD. Once we know which
port is actually signaling HPD, inject that state into the message
received from the EC. This simplifies the rest of the logic as it can
all stay the same with respect to picking the first port to assert HPD,
etc.
Cc: Prashant Malani <pmalani@...omium.org>
Cc: Benson Leung <bleung@...omium.org>
Cc: Tzung-Bi Shih <tzungbi@...nel.org>
Cc: <chrome-platform@...ts.linux.dev>
Cc: Pin-yen Lin <treapking@...omium.org>
Signed-off-by: Stephen Boyd <swboyd@...omium.org>
---
drivers/platform/chrome/cros_ec_typec.c | 74 +++++++++++++++++++++++++
drivers/platform/chrome/cros_ec_typec.h | 2 +
2 files changed, 76 insertions(+)
diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 57d1484ce1ef..731b485634af 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -7,6 +7,7 @@
*/
#include <linux/acpi.h>
+#include <linux/gpio/consumer.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_graph.h>
@@ -423,6 +424,17 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
return ret;
}
+static void cros_typec_dp_bridge_hpd_notify(void *data, enum drm_connector_status status)
+{
+ struct cros_typec_data *typec = data;
+
+ /* Proxy the connector status as the HPD state to replay later. */
+ typec->hpd_asserted = status == connector_status_connected;
+
+ /* Refresh port state. */
+ schedule_work(&typec->port_work);
+}
+
static int cros_typec_init_dp_bridge(struct cros_typec_data *typec)
{
struct device *dev = typec->dev;
@@ -432,9 +444,17 @@ static int cros_typec_init_dp_bridge(struct cros_typec_data *typec)
if (!fwnode_property_read_bool(dev_fwnode(dev), "mode-switch"))
return 0;
+ typec->mux_gpio = devm_gpiod_get_optional(dev, "mux", GPIOD_ASIS);
+ if (IS_ERR(typec->mux_gpio))
+ return dev_err_probe(dev, PTR_ERR(typec->mux_gpio), "failed to get mux gpio\n");
+
dp_dev = devm_drm_dp_typec_bridge_alloc(dev, dev->of_node);
if (IS_ERR(dp_dev))
return PTR_ERR(dp_dev);
+
+ if (fwnode_property_read_bool(dev_fwnode(dev), "no-hpd"))
+ drm_dp_typec_bridge_add_hpd_notify(dp_dev, cros_typec_dp_bridge_hpd_notify, typec);
+
typec->dp_bridge = dp_dev;
return devm_drm_dp_typec_bridge_add(dev, dp_dev);
@@ -635,6 +655,59 @@ static int cros_typec_enable_usb4(struct cros_typec_data *typec,
return typec_mux_set(port->mux, &port->state);
}
+/*
+ * Some ECs don't notify AP when HPD goes high or low because their firmware is
+ * broken. Capture the state of HPD in cros_typec_dp_bridge_hpd_notify() and
+ * inject the asserted state into the EC's response (deasserted is the
+ * default).
+ */
+static void cros_typec_inject_hpd(struct cros_typec_data *typec,
+ struct ec_response_usb_pd_mux_info *resp,
+ struct cros_typec_port *port)
+{
+ struct gpio_desc *mux_gpio = typec->mux_gpio;
+ int val;
+
+ /* Never registered a drm_bridge. Skip. */
+ if (!typec->dp_bridge)
+ return;
+
+ /* Don't need to inject HPD level when DP isn't enabled. */
+ if (!(resp->flags & USB_PD_MUX_DP_ENABLED))
+ return;
+
+ /*
+ * The default setting is HPD deasserted. Ignore if nothing to inject.
+ */
+ if (!typec->hpd_asserted)
+ return;
+
+ /*
+ * Only read the mux GPIO setting if we need to change the active port.
+ * Otherwise, an active port is already set and HPD going high or low
+ * doesn't change the muxed port until DP mode is exited.
+ */
+ if (!typec->active_dp_port) {
+ if (mux_gpio) {
+ val = gpiod_get_value_cansleep(mux_gpio);
+ if (val < 0) {
+ dev_err(typec->dev, "Failed to read mux gpio\n");
+ return;
+ }
+ /* Ignore HPD changes for non-active port. */
+ if (typec->ports[val] != port)
+ return;
+ }
+ } else if (port != typec->active_dp_port) {
+ /* Ignore HPD changes for non-active port. */
+ return;
+ }
+
+ /* Inject HPD from the GPIO state if EC firmware is broken. */
+ if (typec->hpd_asserted)
+ resp->flags |= USB_PD_MUX_HPD_LVL;
+}
+
static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
struct ec_response_usb_pd_control_v2 *pd_ctrl)
{
@@ -656,6 +729,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
port_num, ret);
return ret;
}
+ cros_typec_inject_hpd(typec, &resp, port);
/* No change needs to be made, let's exit early. */
if (port->mux_flags == resp.flags && port->role == pd_ctrl->role)
diff --git a/drivers/platform/chrome/cros_ec_typec.h b/drivers/platform/chrome/cros_ec_typec.h
index f3a2b67df07c..4ccd3d014aa6 100644
--- a/drivers/platform/chrome/cros_ec_typec.h
+++ b/drivers/platform/chrome/cros_ec_typec.h
@@ -37,6 +37,8 @@ struct cros_typec_data {
struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
struct drm_dp_typec_bridge_dev *dp_bridge;
struct cros_typec_port *active_dp_port;
+ struct gpio_desc *mux_gpio;
+ bool hpd_asserted;
struct notifier_block nb;
struct work_struct port_work;
bool typec_cmd_supported;
--
https://chromeos.dev
Powered by blists - more mailing lists