Re: [PATCH 01/12] usb: typec: add API to get port type and preferred role
On 09/25/2017 05:45 PM, Li Jun wrote: 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", _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", _str); + if (ret < 0) + return ret; + + return match_string(typec_roles, ARRAY_SIZE(typec_roles), power_str); +} +EXPORT_SYMBOL_GPL(typec_get_power_role); Add empty line /* --- */ /** 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 */ -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH 01/12] usb: typec: add API to get port type and preferred role
> -Original Message- > From: Heikki Krogerus [mailto:heikki.kroge...@linux.intel.com] > Sent: Tuesday, September 26, 2017 4:03 PM > To: Jun Li <jun...@nxp.com> > Cc: gre...@linuxfoundation.org; li...@roeck-us.net; robh...@kernel.org; > mark.rutl...@arm.com; yue...@google.com; o_leve...@orange.fr; Peter > Chen <peter.c...@nxp.com>; A.s. Dong <aisheng.d...@nxp.com>; linux- > u...@vger.kernel.org; devicet...@vger.kernel.org > Subject: Re: [PATCH 01/12] usb: typec: add API to get port type and preferred > role > > Hi, > > On Tue, Sep 26, 2017 at 08:45:16AM +0800, Li Jun wrote: > > This patch add 2 APIs to get port type and preferred role from > > firmware description. > > > > Signed-off-by: Li Jun <jun...@nxp.com> > > --- > > 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 > > Not needed. I will change to #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", _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", _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 > > Thanks, > > -- > heikki -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 01/12] usb: typec: add API to get port type and preferred role
Hi, On Tue, Sep 26, 2017 at 08:45:16AM +0800, Li Jun wrote: > 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 Not needed. > #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", _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", _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 Thanks, -- heikki -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 01/12] usb: typec: add API to get port type and preferred role
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", _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", _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 majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html