aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Baryshkov <dmitry.baryshkov@linaro.org>2021-04-01 20:07:33 +0300
committerBryan O'Donoghue <bryan.odonoghue@linaro.org>2021-04-07 11:27:41 +0100
commita792a1f1c505b022ab1e7a8a81c8e9de9f673fdb (patch)
tree8f504dfd034f8e3c76cc56d63b43badea4474b6c
parent3f4a6b339a6caa588c52416af61766d33774554f (diff)
usb: typec: mux: add debugging attribute to change switch orientationdmitry-qmp-fixes
Add typec_switch attribute allowing users to toggle switch orientation. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
-rw-r--r--drivers/usb/typec/mux.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index cf720e944aaa..ebcefe6c1294 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -85,6 +85,48 @@ void typec_switch_put(struct typec_switch *sw)
}
EXPORT_SYMBOL_GPL(typec_switch_put);
+static ssize_t orientation_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count) {
+ enum typec_orientation orientation = TYPEC_ORIENTATION_NONE;
+ struct typec_switch *sw = to_typec_switch(dev);
+ int ret;
+
+ if (count <= 3)
+ return -EINVAL;
+
+ if (!strncasecmp(buf, "cc1", 3))
+ orientation = TYPEC_ORIENTATION_NORMAL;
+ else if (!strncasecmp(buf, "cc2", 3))
+ orientation = TYPEC_ORIENTATION_REVERSE;
+
+ dev_info(dev, "Overriding switch to %s direction",
+ orientation == TYPEC_ORIENTATION_REVERSE ? "CC2" :
+ orientation == TYPEC_ORIENTATION_NORMAL ? "CC1" :
+ "none");
+
+ ret = sw->set(sw, orientation);
+ if (ret < 0)
+ return ret;
+
+ return count;
+}
+
+static DEVICE_ATTR_WO(orientation);
+
+static struct attribute *typec_switch_attrs[] = {
+ &dev_attr_orientation.attr,
+ NULL
+};
+
+static struct attribute_group typec_switch_attr_group = {
+ .attrs = typec_switch_attrs,
+};
+
+static const struct attribute_group *typec_switch_attr_groups[] = {
+ &typec_switch_attr_group,
+ NULL
+};
+
static void typec_switch_release(struct device *dev)
{
kfree(to_typec_switch(dev));
@@ -93,6 +135,7 @@ static void typec_switch_release(struct device *dev)
static const struct device_type typec_switch_dev_type = {
.name = "orientation_switch",
.release = typec_switch_release,
+ .groups = typec_switch_attr_groups,
};
/**