linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] usb: typec: Add sysfs node to show connector orientation
@ 2019-10-22  8:59 Puma Hsu
  2019-10-22 17:27 ` Greg KH
  2019-10-23  8:32 ` Heikki Krogerus
  0 siblings, 2 replies; 12+ messages in thread
From: Puma Hsu @ 2019-10-22  8:59 UTC (permalink / raw)
  To: heikki.krogerus, gregkh
  Cc: badhri, kyletso, albertccwang, rickyniu, linux-usb, linux-kernel,
	Puma Hsu

Export the Type-C connector orientation so that user space
can get this information.

Signed-off-by: Puma Hsu <pumahsu@google.com>
---
 Documentation/ABI/testing/sysfs-class-typec | 11 +++++++++++
 drivers/usb/typec/class.c                   | 18 ++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec
index d7647b258c3c..b22f71801671 100644
--- a/Documentation/ABI/testing/sysfs-class-typec
+++ b/Documentation/ABI/testing/sysfs-class-typec
@@ -108,6 +108,17 @@ Contact:	Heikki Krogerus <heikki.krogerus@linux.intel.com>
 Description:
 		Revision number of the supported USB Type-C specification.
 
+What:		/sys/class/typec/<port>/connector_orientation
+Date:		October 2019
+Contact:	Puma Hsu <pumahsu@google.com>
+Description:
+		Indicates which typec connector orientation is configured now.
+		cc1 is defined as "normal" and cc2 is defined as "reversed".
+
+		Valid value:
+		- unknown (nothing configured)
+		- normal (configured in cc1 side)
+		- reversed (configured in cc2 side)
 
 USB Type-C partner devices (eg. /sys/class/typec/port0-partner/)
 
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 94a3eda62add..911d06676aeb 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -1245,6 +1245,23 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(usb_power_delivery_revision);
 
+static const char * const typec_connector_orientation[] = {
+	[TYPEC_ORIENTATION_NONE]		= "unknown",
+	[TYPEC_ORIENTATION_NORMAL]		= "normal",
+	[TYPEC_ORIENTATION_REVERSE]		= "reversed",
+};
+
+static ssize_t connector_orientation_show(struct device *dev,
+						struct device_attribute *attr,
+						char *buf)
+{
+	struct typec_port *p = to_typec_port(dev);
+
+	return sprintf(buf, "%s\n",
+		       typec_connector_orientation[p->orientation]);
+}
+static DEVICE_ATTR_RO(connector_orientation);
+
 static struct attribute *typec_attrs[] = {
 	&dev_attr_data_role.attr,
 	&dev_attr_power_operation_mode.attr,
@@ -1255,6 +1272,7 @@ static struct attribute *typec_attrs[] = {
 	&dev_attr_usb_typec_revision.attr,
 	&dev_attr_vconn_source.attr,
 	&dev_attr_port_type.attr,
+	&dev_attr_connector_orientation.attr,
 	NULL,
 };
 ATTRIBUTE_GROUPS(typec);
-- 
2.23.0.866.gb869b98d4c-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-10-25  6:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22  8:59 [PATCH V2] usb: typec: Add sysfs node to show connector orientation Puma Hsu
2019-10-22 17:27 ` Greg KH
2019-10-23  3:26   ` Puma Hsu
2019-10-23  8:32 ` Heikki Krogerus
2019-10-23 13:44   ` Guenter Roeck
2019-10-23 13:53     ` Puma Hsu
2019-10-23 14:29     ` Heikki Krogerus
2019-10-23 15:01       ` Guenter Roeck
2019-10-23 15:57         ` Heikki Krogerus
2019-10-24  9:02           ` Puma Hsu
2019-10-24 12:06             ` Heikki Krogerus
2019-10-25  6:46               ` Puma Hsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).