blob: 9dd420f3f83031bf0e2fe004ee8f43e0eb6b01d5 [file] [log] [blame]
From 30356db7cd2e4b6b1b805c5bd9ed7627f9262a58 Mon Sep 17 00:00:00 2001
From: Pin-yen Lin <treapking@chromium.org>
Date: Mon, 19 Sep 2022 22:17:17 +0800
Subject: [PATCH] FROMLIST: drm/bridge: it6505: Register number of Type C
switches
Parse the "switches" node, if available, and count and store the number
of Type-C switches within it. The extcon registration is still
supported, but we don't expect both extcon and typec-switch be
registered at the same time.
This patch sets a foundation for the actual registering of Type-C
switches with the Type-C connector class framework.
Signed-off-by: Pin-yen Lin <treapking@chromium.org>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
(am from https://patches.linaro.org/project/linux-usb/patch/20220622173605.1168416-8-pmalani@chromium.org//)
(also found at https://lore.kernel.org/r/20220622173605.1168416-8-pmalani@chromium.org)
BUG=b:212382669
TEST=Check external displays on Kingler/Krabby
UPSTREAM-TASK=b:247731050
Change-Id: Id15a68b7bea65c1d58188bf5485da632c7e28273
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3904830
Reviewed-by: Hsin-Yi Wang <hsinyi@chromium.org>
Commit-Queue: Pin-yen Lin <treapking@chromium.org>
Reviewed-by: Sean Paul <sean@poorly.run>
Tested-by: Pin-yen Lin <treapking@chromium.org>
Kcr-patch: 239023d439d2234d43507a2fe7b3166b6e401411939dd2908f10f351.patch
---
drivers/gpu/drm/bridge/ite-it6505.c | 34 +++++++++++++++++++++++++----
1 file changed, 30 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c
index 22afdcd7475311ea23d36e147de76f102367172f..5e80ee001b1a7797166fcc500e973b7d6bdcea97 100644
--- a/drivers/gpu/drm/bridge/ite-it6505.c
+++ b/drivers/gpu/drm/bridge/ite-it6505.c
@@ -455,6 +455,7 @@ struct it6505 {
struct delayed_work delayed_audio;
struct it6505_audio_data audio;
struct dentry *debugfs;
+ int num_typec_switches;
/* it6505 driver hold option */
bool enable_drv_hold;
@@ -3460,12 +3461,27 @@ static void it6505_shutdown(struct i2c_client *client)
it6505_lane_off(it6505);
}
+static int it6505_register_typec_switches(struct device *device, struct it6505 *it6505)
+{
+ struct device_node *of;
+
+ of = of_get_child_by_name(device->of_node, "switches");
+ if (!of)
+ return -ENODEV;
+
+ it6505->num_typec_switches = of_get_child_count(of);
+ if (it6505->num_typec_switches <= 0)
+ return -ENODEV;
+
+ return 0;
+}
+
static int it6505_i2c_probe(struct i2c_client *client)
{
struct it6505 *it6505;
struct device *dev = &client->dev;
struct extcon_dev *extcon;
- int err;
+ int err, intp_irq, ret;
it6505 = devm_kzalloc(&client->dev, sizeof(*it6505), GFP_KERNEL);
if (!it6505)
@@ -3485,11 +3501,21 @@ 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", PTR_ERR(extcon));
+ it6505->extcon = NULL;
+ } else {
+ it6505->extcon = extcon;
}
- it6505->extcon = extcon;
+ ret = it6505_register_typec_switches(dev, it6505);
+ if (ret) {
+ dev_dbg(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;
+ }
+ }
it6505->regmap = devm_regmap_init_i2c(client, &it6505_regmap_config);
if (IS_ERR(it6505->regmap)) {
--
2.47.0.163.g1226f6d8fa-goog