From mboxrd@z Thu Jan 1 00:00:00 1970 From: Li Jun Subject: [PATCH resend 01/12] usb: typec: add API to get port type and preferred role Date: Tue, 26 Sep 2017 12:05:12 +0800 Message-ID: <1506398723-19359-2-git-send-email-jun.li@nxp.com> References: <1506398723-19359-1-git-send-email-jun.li@nxp.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1506398723-19359-1-git-send-email-jun.li-3arQi8VN3Tc@public.gmane.org> Sender: linux-usb-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org To: gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org, linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org, robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, mark.rutland-5wv7dgnIgG8@public.gmane.org, heikki.krogerus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org Cc: yueyao-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org, o_leveque-1tsiiZ//OF9QFI55V6+gNQ@public.gmane.org, peter.chen-3arQi8VN3Tc@public.gmane.org, aisheng.dong-3arQi8VN3Tc@public.gmane.org, jun.li-3arQi8VN3Tc@public.gmane.org, linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-Id: devicetree@vger.kernel.org This patch add 2 APIs to get port type and preferred role from firmware description. Signed-off-by: Li Jun --- 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 #include #include +#include #include #include @@ -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 linux-usb" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html