Skip to content
Snippets Groups Projects
Commit a792a1f1 authored by Dmitry Baryshkov's avatar Dmitry Baryshkov Committed by Bryan O'Donoghue
Browse files

usb: typec: mux: add debugging attribute to change switch orientation


Add typec_switch attribute allowing users to toggle switch orientation.

Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
parent 3f4a6b33
No related merge requests found
......@@ -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,
};
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment