[PATCH resend 01/12] usb: typec: add API to get port type and preferred role

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




This patch add 2 APIs to get port type and preferred role from firmware
description.

Signed-off-by: Li Jun <jun.li@xxxxxxx>
---
 drivers/usb/typec/typec.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/usb/typec.h |  2 ++
 2 files changed, 47 insertions(+)

diff --git a/drivers/usb/typec/typec.c b/drivers/usb/typec/typec.c
index 24e355b..0c77cc4 100644
--- a/drivers/usb/typec/typec.c
+++ b/drivers/usb/typec/typec.c
@@ -12,6 +12,7 @@
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/of.h>
 #include <linux/slab.h>
 #include <linux/usb/typec.h>
 
@@ -1249,6 +1250,50 @@ void typec_set_pwr_opmode(struct typec_port *port,
 }
 EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);
 
+/**
+ * typec_get_port_type - Get the typec port type
+ * @dev: Device to get the property of
+ *
+ * This routine is used by typec hardware driver to read property port type
+ * from the device firmware description.
+ *
+ * Returns typec_port_type if success, otherwise negative error code.
+ */
+int typec_get_port_type(struct device *dev)
+{
+	const char *type_str;
+	int ret;
+
+	ret = device_property_read_string(dev, "port-type", &type_str);
+	if (ret < 0)
+		return ret;
+
+	return match_string(typec_port_types, ARRAY_SIZE(typec_port_types),
+								 type_str);
+}
+EXPORT_SYMBOL_GPL(typec_get_port_type);
+
+/**
+ * typec_get_power_role - Get the typec preferred role
+ * @dev: Device to get the property of
+ *
+ * This routine is used by typec hardware driver to read property default role
+ * from the device firmware description.
+ *
+ * Returns typec_role if success, otherwise negative error code.
+ */
+int typec_get_power_role(struct device *dev)
+{
+	const char *power_str;
+	int ret;
+
+	ret = device_property_read_string(dev, "default-role", &power_str);
+	if (ret < 0)
+		return ret;
+
+	return match_string(typec_roles, ARRAY_SIZE(typec_roles), power_str);
+}
+EXPORT_SYMBOL_GPL(typec_get_power_role);
 /* --------------------------------------- */
 
 /**
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index ffe7487..bfac685 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -243,5 +243,7 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
+int typec_get_port_type(struct device *dev);
+int typec_get_power_role(struct device *dev);
 
 #endif /* __LINUX_USB_TYPEC_H */
-- 
2.6.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux