Message ID | 1525307094-27402-6-git-send-email-jun.li@nxp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Li Jun, On 2018-05-03 02:24, Li Jun wrote: > This patch adds 3 APIs to get the typec port power and data type, > and preferred power role by its name string. > > Signed-off-by: Li Jun <jun.li@nxp.com> > --- > drivers/usb/typec/class.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ > include/linux/usb/typec.h | 3 +++ > 2 files changed, 55 insertions(+) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index 53df10d..5981e18 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -9,6 +9,7 @@ > #include <linux/device.h> > #include <linux/module.h> > #include <linux/mutex.h> > +#include <linux/property.h> > #include <linux/slab.h> > #include <linux/usb/typec.h> > #include <linux/usb/typec_mux.h> > @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { > [TYPEC_PORT_DRP] = "dual", > }; > > +static const char * const typec_data_types[] = { > + [TYPEC_PORT_DFP] = "host", > + [TYPEC_PORT_UFP] = "device", > + [TYPEC_PORT_DRD] = "dual", > +}; > + > static const char * const typec_port_types_drp[] = { > [TYPEC_PORT_SRC] = "dual [source] sink", > [TYPEC_PORT_SNK] = "dual source [sink]", > @@ -1252,6 +1259,51 @@ void typec_set_pwr_opmode(struct typec_port *port, > } > EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); > > +/** > + * typec_find_power_type - Get the typec port power type Why is this function called typec_find_power_type() and not typec_find_port_type()? It's called port_type in sysfs, having different names just adds confusion. (Otherwise I agree power_type is a better name but...) > + * @name: port type string > + * > + * This routine is used to find the typec_port_type by its string name. > + * > + * Returns typec_port_type if success, otherwise negative error code. > + */ > +int typec_find_power_type(const char *name) > +{ > + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), > + name); > +} > +EXPORT_SYMBOL_GPL(typec_find_power_type); > + > +/** > + * typec_find_preferred_role - Find the typec drp port preferred power role Why typec_find_preferred_role()? Could be used for any power_role so why not typec_find_power_role()? BR // Mats > + * @name: power role string > + * > + * This routine is used to find the typec_role by its string name of > + * preferred power role(Try.SRC or Try.SNK). > + * > + * Returns typec_role if success, otherwise negative error code. > + */ > +int typec_find_preferred_role(const char *name) > +{ > + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); > +} > +EXPORT_SYMBOL_GPL(typec_find_preferred_role); > + > +/** > + * typec_find_data_type - Get the typec port data capability > + * @name: data type string > + * > + * This routine is used to find the typec_port_data by its string name. > + * > + * Returns typec_port_data if success, otherwise negative error code. > + */ > +int typec_find_data_type(const char *name) > +{ > + return match_string(typec_data_types, ARRAY_SIZE(typec_data_types), > + name); > +} > +EXPORT_SYMBOL_GPL(typec_find_data_type); > + > /* ------------------------------------------ */ > /* API for Multiplexer/DeMultiplexer Switches */ > > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h > index 672b39b..00c93e7 100644 > --- a/include/linux/usb/typec.h > +++ b/include/linux/usb/typec.h > @@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, > enum typec_orientation orientation); > int typec_set_mode(struct typec_port *port, int mode); > > +int typec_find_power_type(const char *name); > +int typec_find_preferred_role(const char *name); > +int typec_find_data_type(const char *name); > #endif /* __LINUX_USB_TYPEC_H */ > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi > -----Original Message----- > From: Mats Karrman [mailto:mats.dev.list@gmail.com] > Sent: 2018年5月12日 3:56 > To: Jun Li <jun.li@nxp.com>; robh+dt@kernel.org; gregkh@linuxfoundation.org; > heikki.krogerus@linux.intel.com; linux@roeck-us.net > Cc: a.hajda@samsung.com; cw00.choi@samsung.com; > shufan_lee@richtek.com; Peter Chen <peter.chen@nxp.com>; > gsomlo@gmail.com; devicetree@vger.kernel.org; linux-usb@vger.kernel.org; > dl-linux-imx <linux-imx@nxp.com> > Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > and data config > > Hi Li Jun, > > On 2018-05-03 02:24, Li Jun wrote: > > > This patch adds 3 APIs to get the typec port power and data type, and > > preferred power role by its name string. > > > > Signed-off-by: Li Jun <jun.li@nxp.com> > > --- > > drivers/usb/typec/class.c | 52 > +++++++++++++++++++++++++++++++++++++++++++++++ > > include/linux/usb/typec.h | 3 +++ > > 2 files changed, 55 insertions(+) > > > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > > index 53df10d..5981e18 100644 > > --- a/drivers/usb/typec/class.c > > +++ b/drivers/usb/typec/class.c > > @@ -9,6 +9,7 @@ > > #include <linux/device.h> > > #include <linux/module.h> > > #include <linux/mutex.h> > > +#include <linux/property.h> > > #include <linux/slab.h> > > #include <linux/usb/typec.h> > > #include <linux/usb/typec_mux.h> > > @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { > > [TYPEC_PORT_DRP] = "dual", > > }; > > > > +static const char * const typec_data_types[] = { > > + [TYPEC_PORT_DFP] = "host", > > + [TYPEC_PORT_UFP] = "device", > > + [TYPEC_PORT_DRD] = "dual", > > +}; > > + > > static const char * const typec_port_types_drp[] = { > > [TYPEC_PORT_SRC] = "dual [source] sink", > > [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 > @@ > > void typec_set_pwr_opmode(struct typec_port *port, > > } > > EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); > > > > +/** > > + * typec_find_power_type - Get the typec port power type > > Why is this function called typec_find_power_type() and not > typec_find_port_type()? > It's called port_type in sysfs, having different names just adds confusion. > (Otherwise I agree power_type is a better name but...) We have "port type" before the power and data role separation, this API name's intention is to reflect the power cap, anyway I leave this to be decided by Heikki then. > > > + * @name: port type string > > + * > > + * This routine is used to find the typec_port_type by its string name. > > + * > > + * Returns typec_port_type if success, otherwise negative error code. > > + */ > > +int typec_find_power_type(const char *name) { > > + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), > > + name); > > +} > > +EXPORT_SYMBOL_GPL(typec_find_power_type); > > + > > +/** > > + * typec_find_preferred_role - Find the typec drp port preferred > > +power role > > Why typec_find_preferred_role()? Could be used for any power_role so why not > typec_find_power_role()? I am not sure if I catch your point of this comment. For preferred role(if support try.sink or try.src) the only allowed power roles are "sink" "source" But for power role, the allowed type are "sink" "source" "dual" Thanks Li Jun > > BR // Mats > > > + * @name: power role string > > + * > > + * This routine is used to find the typec_role by its string name of > > + * preferred power role(Try.SRC or Try.SNK). > > + * > > + * Returns typec_role if success, otherwise negative error code. > > + */ > > +int typec_find_preferred_role(const char *name) { > > + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); } > > +EXPORT_SYMBOL_GPL(typec_find_preferred_role); > > + > > +/** > > + * typec_find_data_type - Get the typec port data capability > > + * @name: data type string > > + * > > + * This routine is used to find the typec_port_data by its string name. > > + * > > + * Returns typec_port_data if success, otherwise negative error code. > > + */ > > +int typec_find_data_type(const char *name) { > > + return match_string(typec_data_types, ARRAY_SIZE(typec_data_types), > > + name); > > +} > > +EXPORT_SYMBOL_GPL(typec_find_data_type); > > + > > /* ------------------------------------------ */ > > /* API for Multiplexer/DeMultiplexer Switches */ > > > > diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h > > index 672b39b..00c93e7 100644 > > --- a/include/linux/usb/typec.h > > +++ b/include/linux/usb/typec.h > > @@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, > > enum typec_orientation orientation); > > int typec_set_mode(struct typec_port *port, int mode); > > > > +int typec_find_power_type(const char *name); int > > +typec_find_preferred_role(const char *name); int > > +typec_find_data_type(const char *name); > > #endif /* __LINUX_USB_TYPEC_H */ > >
Hi, On 05/14/2018 11:36 AM, Jun Li wrote: > Hi >> -----Original Message----- >> From: Mats Karrman [mailto:mats.dev.list@gmail.com] >> Sent: 2018年5月12日 3:56 >> To: Jun Li <jun.li@nxp.com>; robh+dt@kernel.org; gregkh@linuxfoundation.org; >> heikki.krogerus@linux.intel.com; linux@roeck-us.net >> Cc: a.hajda@samsung.com; cw00.choi@samsung.com; >> shufan_lee@richtek.com; Peter Chen <peter.chen@nxp.com>; >> gsomlo@gmail.com; devicetree@vger.kernel.org; linux-usb@vger.kernel.org; >> dl-linux-imx <linux-imx@nxp.com> >> Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power >> and data config >> >> Hi Li Jun, >> >> On 2018-05-03 02:24, Li Jun wrote: >> >>> This patch adds 3 APIs to get the typec port power and data type, and >>> preferred power role by its name string. >>> >>> Signed-off-by: Li Jun <jun.li@nxp.com> >>> --- >>> drivers/usb/typec/class.c | 52 >> +++++++++++++++++++++++++++++++++++++++++++++++ >>> include/linux/usb/typec.h | 3 +++ >>> 2 files changed, 55 insertions(+) >>> >>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c >>> index 53df10d..5981e18 100644 >>> --- a/drivers/usb/typec/class.c >>> +++ b/drivers/usb/typec/class.c >>> @@ -9,6 +9,7 @@ >>> #include <linux/device.h> >>> #include <linux/module.h> >>> #include <linux/mutex.h> >>> +#include <linux/property.h> >>> #include <linux/slab.h> >>> #include <linux/usb/typec.h> >>> #include <linux/usb/typec_mux.h> >>> @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { >>> [TYPEC_PORT_DRP] = "dual", >>> }; >>> >>> +static const char * const typec_data_types[] = { >>> + [TYPEC_PORT_DFP] = "host", >>> + [TYPEC_PORT_UFP] = "device", >>> + [TYPEC_PORT_DRD] = "dual", >>> +}; >>> + >>> static const char * const typec_port_types_drp[] = { >>> [TYPEC_PORT_SRC] = "dual [source] sink", >>> [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 >> @@ >>> void typec_set_pwr_opmode(struct typec_port *port, >>> } >>> EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); >>> >>> +/** >>> + * typec_find_power_type - Get the typec port power type >> Why is this function called typec_find_power_type() and not >> typec_find_port_type()? >> It's called port_type in sysfs, having different names just adds confusion. >> (Otherwise I agree power_type is a better name but...) > We have "port type" before the power and data role separation, > this API name's intention is to reflect the power cap, anyway I > leave this to be decided by Heikki then. >>> + * @name: port type string >>> + * >>> + * This routine is used to find the typec_port_type by its string name. >>> + * >>> + * Returns typec_port_type if success, otherwise negative error code. >>> + */ >>> +int typec_find_power_type(const char *name) { >>> + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), >>> + name); >>> +} >>> +EXPORT_SYMBOL_GPL(typec_find_power_type); >>> + >>> +/** >>> + * typec_find_preferred_role - Find the typec drp port preferred >>> +power role >> Why typec_find_preferred_role()? Could be used for any power_role so why not >> typec_find_power_role()? > I am not sure if I catch your point of this comment. > For preferred role(if support try.sink or try.src) the only allowed power roles are > "sink" > "source" > But for power role, the allowed type are > "sink" > "source" > "dual" Uhm, typing too fast again, I am. A better name would be just typec_find_role(). What I mean is that the function could be used for any situation when someone wants to map a string to a TYPEC_{SOURCE,SINK} constant so it is unnecessary to limit its usage to just preferred role. // Mats > Thanks > Li Jun >> BR // Mats >> >>> + * @name: power role string >>> + * >>> + * This routine is used to find the typec_role by its string name of >>> + * preferred power role(Try.SRC or Try.SNK). >>> + * >>> + * Returns typec_role if success, otherwise negative error code. >>> + */ >>> +int typec_find_preferred_role(const char *name) { >>> + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); } >>> +EXPORT_SYMBOL_GPL(typec_find_preferred_role); >>> + >>> +/** >>> + * typec_find_data_type - Get the typec port data capability >>> + * @name: data type string >>> + * >>> + * This routine is used to find the typec_port_data by its string name. >>> + * >>> + * Returns typec_port_data if success, otherwise negative error code. >>> + */ >>> +int typec_find_data_type(const char *name) { >>> + return match_string(typec_data_types, ARRAY_SIZE(typec_data_types), >>> + name); >>> +} >>> +EXPORT_SYMBOL_GPL(typec_find_data_type); >>> + >>> /* ------------------------------------------ */ >>> /* API for Multiplexer/DeMultiplexer Switches */ >>> >>> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h >>> index 672b39b..00c93e7 100644 >>> --- a/include/linux/usb/typec.h >>> +++ b/include/linux/usb/typec.h >>> @@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, >>> enum typec_orientation orientation); >>> int typec_set_mode(struct typec_port *port, int mode); >>> >>> +int typec_find_power_type(const char *name); int >>> +typec_find_preferred_role(const char *name); int >>> +typec_find_data_type(const char *name); >>> #endif /* __LINUX_USB_TYPEC_H */ -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi guys, On Tue, May 15, 2018 at 10:52:57PM +0200, Mats Karrman wrote: > Hi, > > On 05/14/2018 11:36 AM, Jun Li wrote: > > > Hi > >> -----Original Message----- > >> From: Mats Karrman [mailto:mats.dev.list@gmail.com] > >> Sent: 2018???5???12??? 3:56 > >> To: Jun Li <jun.li@nxp.com>; robh+dt@kernel.org; gregkh@linuxfoundation.org; > >> heikki.krogerus@linux.intel.com; linux@roeck-us.net > >> Cc: a.hajda@samsung.com; cw00.choi@samsung.com; > >> shufan_lee@richtek.com; Peter Chen <peter.chen@nxp.com>; > >> gsomlo@gmail.com; devicetree@vger.kernel.org; linux-usb@vger.kernel.org; > >> dl-linux-imx <linux-imx@nxp.com> > >> Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > >> and data config > >> > >> Hi Li Jun, > >> > >> On 2018-05-03 02:24, Li Jun wrote: > >> > >>> This patch adds 3 APIs to get the typec port power and data type, and > >>> preferred power role by its name string. > >>> > >>> Signed-off-by: Li Jun <jun.li@nxp.com> > >>> --- > >>> drivers/usb/typec/class.c | 52 > >> +++++++++++++++++++++++++++++++++++++++++++++++ > >>> include/linux/usb/typec.h | 3 +++ > >>> 2 files changed, 55 insertions(+) > >>> > >>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > >>> index 53df10d..5981e18 100644 > >>> --- a/drivers/usb/typec/class.c > >>> +++ b/drivers/usb/typec/class.c > >>> @@ -9,6 +9,7 @@ > >>> #include <linux/device.h> > >>> #include <linux/module.h> > >>> #include <linux/mutex.h> > >>> +#include <linux/property.h> I don't think you need that anymore. > >>> #include <linux/slab.h> > >>> #include <linux/usb/typec.h> > >>> #include <linux/usb/typec_mux.h> > >>> @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { > >>> [TYPEC_PORT_DRP] = "dual", > >>> }; > >>> > >>> +static const char * const typec_data_types[] = { > >>> + [TYPEC_PORT_DFP] = "host", > >>> + [TYPEC_PORT_UFP] = "device", > >>> + [TYPEC_PORT_DRD] = "dual", > >>> +}; > >>> + > >>> static const char * const typec_port_types_drp[] = { > >>> [TYPEC_PORT_SRC] = "dual [source] sink", > >>> [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 > >> @@ > >>> void typec_set_pwr_opmode(struct typec_port *port, > >>> } > >>> EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); > >>> > >>> +/** > >>> + * typec_find_power_type - Get the typec port power type > >> Why is this function called typec_find_power_type() and not > >> typec_find_port_type()? > >> It's called port_type in sysfs, having different names just adds confusion. > >> (Otherwise I agree power_type is a better name but...) > > We have "port type" before the power and data role separation, > > this API name's intention is to reflect the power cap, anyway I > > leave this to be decided by Heikki then. I really hate the "*_type" naming. It was understandable when there was no separate power and data roles defined in the specification, but now that there are, it's just confusing. IMO we should not use it anywhere. So to me typec_find_type() is just as bad as typec_find_power_type() because it has the "type" in it. I wonder if this function is necessary at all? If it is, then perhaps we can think of some better name for it, name that gives a better hint what it is used for. > >>> + * @name: port type string > >>> + * > >>> + * This routine is used to find the typec_port_type by its string name. > >>> + * > >>> + * Returns typec_port_type if success, otherwise negative error code. > >>> + */ > >>> +int typec_find_power_type(const char *name) { > >>> + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), > >>> + name); > >>> +} > >>> +EXPORT_SYMBOL_GPL(typec_find_power_type); > >>> + > >>> +/** > >>> + * typec_find_preferred_role - Find the typec drp port preferred > >>> +power role > >> Why typec_find_preferred_role()? Could be used for any power_role so why not > >> typec_find_power_role()? > > I am not sure if I catch your point of this comment. > > For preferred role(if support try.sink or try.src) the only allowed power roles are > > "sink" > > "source" > > But for power role, the allowed type are > > "sink" > > "source" > > "dual" > > Uhm, typing too fast again, I am. A better name would be just typec_find_role(). > What I mean is that the function could be used for any situation when > someone wants to map a string to a TYPEC_{SOURCE,SINK} constant so it > is unnecessary to limit its usage to just preferred role. That sounds reasonable to me. Thanks,
Hi, On 05/16/2018 02:25 PM, Heikki Krogerus wrote: > Hi guys, > > On Tue, May 15, 2018 at 10:52:57PM +0200, Mats Karrman wrote: >> Hi, >> >> On 05/14/2018 11:36 AM, Jun Li wrote: >> >>> Hi >>>> -----Original Message----- >>>> From: Mats Karrman [mailto:mats.dev.list@gmail.com] >>>> Sent: 2018???5???12??? 3:56 >>>> To: Jun Li <jun.li@nxp.com>; robh+dt@kernel.org; gregkh@linuxfoundation.org; >>>> heikki.krogerus@linux.intel.com; linux@roeck-us.net >>>> Cc: a.hajda@samsung.com; cw00.choi@samsung.com; >>>> shufan_lee@richtek.com; Peter Chen <peter.chen@nxp.com>; >>>> gsomlo@gmail.com; devicetree@vger.kernel.org; linux-usb@vger.kernel.org; >>>> dl-linux-imx <linux-imx@nxp.com> >>>> Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power >>>> and data config >>>> >>>> Hi Li Jun, >>>> >>>> On 2018-05-03 02:24, Li Jun wrote: >>>> >>>>> This patch adds 3 APIs to get the typec port power and data type, and >>>>> preferred power role by its name string. >>>>> >>>>> Signed-off-by: Li Jun <jun.li@nxp.com> >>>>> --- >>>>> drivers/usb/typec/class.c | 52 >>>> +++++++++++++++++++++++++++++++++++++++++++++++ >>>>> include/linux/usb/typec.h | 3 +++ >>>>> 2 files changed, 55 insertions(+) >>>>> >>>>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c >>>>> index 53df10d..5981e18 100644 >>>>> --- a/drivers/usb/typec/class.c >>>>> +++ b/drivers/usb/typec/class.c >>>>> @@ -9,6 +9,7 @@ >>>>> #include <linux/device.h> >>>>> #include <linux/module.h> >>>>> #include <linux/mutex.h> >>>>> +#include <linux/property.h> > I don't think you need that anymore. > >>>>> #include <linux/slab.h> >>>>> #include <linux/usb/typec.h> >>>>> #include <linux/usb/typec_mux.h> >>>>> @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { >>>>> [TYPEC_PORT_DRP] = "dual", >>>>> }; >>>>> >>>>> +static const char * const typec_data_types[] = { >>>>> + [TYPEC_PORT_DFP] = "host", >>>>> + [TYPEC_PORT_UFP] = "device", >>>>> + [TYPEC_PORT_DRD] = "dual", >>>>> +}; >>>>> + >>>>> static const char * const typec_port_types_drp[] = { >>>>> [TYPEC_PORT_SRC] = "dual [source] sink", >>>>> [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 >>>> @@ >>>>> void typec_set_pwr_opmode(struct typec_port *port, >>>>> } >>>>> EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); >>>>> >>>>> +/** >>>>> + * typec_find_power_type - Get the typec port power type >>>> Why is this function called typec_find_power_type() and not >>>> typec_find_port_type()? >>>> It's called port_type in sysfs, having different names just adds confusion. >>>> (Otherwise I agree power_type is a better name but...) >>> We have "port type" before the power and data role separation, >>> this API name's intention is to reflect the power cap, anyway I >>> leave this to be decided by Heikki then. > I really hate the "*_type" naming. It was understandable when there > was no separate power and data roles defined in the specification, but > now that there are, it's just confusing. IMO we should not use it > anywhere. > > So to me typec_find_type() is just as bad as typec_find_power_type() > because it has the "type" in it. I wonder if this function is > necessary at all? If it is, then perhaps we can think of some better > name for it, name that gives a better hint what it is used for. I reread this patch and tried to see it more in the context of the other patches and the existing code. The naming of the existing string tables doesn't help in getting this right, however I have a proposal: typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD typec_find_power_role() to get to TYPEC_SINK/SOURCE and sometime, if the use should arise typec_find_data_role() to get to TYPEC_DEVICE/HOST I think it is fairly comprehensible, *_port_* concerns a capability and without *_port_* it is an actual state. Plus it matches the names of the constants. BR // Mats >>>>> + * @name: port type string >>>>> + * >>>>> + * This routine is used to find the typec_port_type by its string name. >>>>> + * >>>>> + * Returns typec_port_type if success, otherwise negative error code. >>>>> + */ >>>>> +int typec_find_power_type(const char *name) { >>>>> + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), >>>>> + name); >>>>> +} >>>>> +EXPORT_SYMBOL_GPL(typec_find_power_type); >>>>> + >>>>> +/** >>>>> + * typec_find_preferred_role - Find the typec drp port preferred >>>>> +power role >>>> Why typec_find_preferred_role()? Could be used for any power_role so why not >>>> typec_find_power_role()? >>> I am not sure if I catch your point of this comment. >>> For preferred role(if support try.sink or try.src) the only allowed power roles are >>> "sink" >>> "source" >>> But for power role, the allowed type are >>> "sink" >>> "source" >>> "dual" >> Uhm, typing too fast again, I am. A better name would be just typec_find_role(). >> What I mean is that the function could be used for any situation when >> someone wants to map a string to a TYPEC_{SOURCE,SINK} constant so it >> is unnecessary to limit its usage to just preferred role. > That sounds reasonable to me. > > > Thanks, > -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, May 16, 2018 at 10:55:36PM +0200, Mats Karrman wrote: > Hi, > > On 05/16/2018 02:25 PM, Heikki Krogerus wrote: > > > Hi guys, > > > > On Tue, May 15, 2018 at 10:52:57PM +0200, Mats Karrman wrote: > >> Hi, > >> > >> On 05/14/2018 11:36 AM, Jun Li wrote: > >> > >>> Hi > >>>> -----Original Message----- > >>>> From: Mats Karrman [mailto:mats.dev.list@gmail.com] > >>>> Sent: 2018???5???12??? 3:56 > >>>> To: Jun Li <jun.li@nxp.com>; robh+dt@kernel.org; gregkh@linuxfoundation.org; > >>>> heikki.krogerus@linux.intel.com; linux@roeck-us.net > >>>> Cc: a.hajda@samsung.com; cw00.choi@samsung.com; > >>>> shufan_lee@richtek.com; Peter Chen <peter.chen@nxp.com>; > >>>> gsomlo@gmail.com; devicetree@vger.kernel.org; linux-usb@vger.kernel.org; > >>>> dl-linux-imx <linux-imx@nxp.com> > >>>> Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > >>>> and data config > >>>> > >>>> Hi Li Jun, > >>>> > >>>> On 2018-05-03 02:24, Li Jun wrote: > >>>> > >>>>> This patch adds 3 APIs to get the typec port power and data type, and > >>>>> preferred power role by its name string. > >>>>> > >>>>> Signed-off-by: Li Jun <jun.li@nxp.com> > >>>>> --- > >>>>> drivers/usb/typec/class.c | 52 > >>>> +++++++++++++++++++++++++++++++++++++++++++++++ > >>>>> include/linux/usb/typec.h | 3 +++ > >>>>> 2 files changed, 55 insertions(+) > >>>>> > >>>>> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > >>>>> index 53df10d..5981e18 100644 > >>>>> --- a/drivers/usb/typec/class.c > >>>>> +++ b/drivers/usb/typec/class.c > >>>>> @@ -9,6 +9,7 @@ > >>>>> #include <linux/device.h> > >>>>> #include <linux/module.h> > >>>>> #include <linux/mutex.h> > >>>>> +#include <linux/property.h> > > I don't think you need that anymore. > > > >>>>> #include <linux/slab.h> > >>>>> #include <linux/usb/typec.h> > >>>>> #include <linux/usb/typec_mux.h> > >>>>> @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { > >>>>> [TYPEC_PORT_DRP] = "dual", > >>>>> }; > >>>>> > >>>>> +static const char * const typec_data_types[] = { > >>>>> + [TYPEC_PORT_DFP] = "host", > >>>>> + [TYPEC_PORT_UFP] = "device", > >>>>> + [TYPEC_PORT_DRD] = "dual", > >>>>> +}; > >>>>> + > >>>>> static const char * const typec_port_types_drp[] = { > >>>>> [TYPEC_PORT_SRC] = "dual [source] sink", > >>>>> [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 > >>>> @@ > >>>>> void typec_set_pwr_opmode(struct typec_port *port, > >>>>> } > >>>>> EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); > >>>>> > >>>>> +/** > >>>>> + * typec_find_power_type - Get the typec port power type > >>>> Why is this function called typec_find_power_type() and not > >>>> typec_find_port_type()? > >>>> It's called port_type in sysfs, having different names just adds confusion. > >>>> (Otherwise I agree power_type is a better name but...) > >>> We have "port type" before the power and data role separation, > >>> this API name's intention is to reflect the power cap, anyway I > >>> leave this to be decided by Heikki then. > > I really hate the "*_type" naming. It was understandable when there > > was no separate power and data roles defined in the specification, but > > now that there are, it's just confusing. IMO we should not use it > > anywhere. > > > > So to me typec_find_type() is just as bad as typec_find_power_type() > > because it has the "type" in it. I wonder if this function is > > necessary at all? If it is, then perhaps we can think of some better > > name for it, name that gives a better hint what it is used for. > > I reread this patch and tried to see it more in the context of the other > patches and the existing code. The naming of the existing string tables > doesn't help in getting this right, however I have a proposal: > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > and sometime, if the use should arise > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > I think it is fairly comprehensible, *_port_* concerns a capability and > without *_port_* it is an actual state. Plus it matches the names of the > constants. Well, there are now four things to consider: 1) the roles (power and data) the port is capable of supporting 2) Try.SRC and Try.SNK, i.e. the preferred role 3) the current roles 4) the role(s) the user want's to limit the use of a port with DRP ports The last one I don't know if it's relevant with these functions. It's not information that we would get for example from firmware. I also don't think we need to use these functions with the current roles the port is in. If the preferred role is "sink" or "source", so just like the power role, we don't need separate function for it here. So isn't two functions all we need here: one for the power and one for data role? Thanks,
Hi Mats, > > Uhm, typing too fast again, I am. A better name would be just > typec_find_role(). > What I mean is that the function could be used for any situation when > someone wants to map a string to a TYPEC_{SOURCE,SINK} constant so it is > unnecessary to limit its usage to just preferred role. Get your idea, that will be a more general API for typec class. Thanks Li Jun
SGkNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogSGVpa2tpIEtyb2dlcnVz IFttY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dG8gbWUuDQoNCkFncmVlZA0K DQp0aGFua3MNCkxpIEp1bg0KPiANCj4gDQo+IFRoYW5rcywNCj4gDQo+IC0tDQo+IGhlaWtraQ0K -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mats > I reread this patch and tried to see it more in the context of the other patches > and the existing code. The naming of the existing string tables doesn't help in > getting this right, however I have a proposal: > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > and sometime, if the use should arise > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > I think it is fairly comprehensible, *_port_* concerns a capability and without > *_port_* it is an actual state. Plus it matches the names of the constants. > Reasonable to me, I was using "type" to concern a capability but it was not preferred, if Heikki agree this proposal, I will change the API names like this and include 4 APIs above. Thanks Li Jun
Hi Heikki, > > I reread this patch and tried to see it more in the context of the > > other patches and the existing code. The naming of the existing string > > tables doesn't help in getting this right, however I have a proposal: > > > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > > > and sometime, if the use should arise > > > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > > > I think it is fairly comprehensible, *_port_* concerns a capability > > and without *_port_* it is an actual state. Plus it matches the names > > of the constants. > > Well, there are now four things to consider: > > 1) the roles (power and data) the port is capable of supporting > 2) Try.SRC and Try.SNK, i.e. the preferred role > 3) the current roles > 4) the role(s) the user want's to limit the use of a port with DRP ports > > The last one I don't know if it's relevant with these functions. It's not > information that we would get for example from firmware. > > I also don't think we need to use these functions with the current roles the port > is in. > > If the preferred role is "sink" or "source", so just like the power role, we don't > need separate function for it here. > > So isn't two functions all we need here: one for the power and one for data > role? Take power as an example, can we use one function to only look up typec_port_types[]? as capability(typec_port_type) and state(typec_role) are different enum, and the allowed strings are different. static const char * const typec_roles[] = { [TYPEC_SINK] = "sink", [TYPEC_SOURCE] = "source", }; static const char * const typec_port_types[] = { [TYPEC_PORT_SRC] = "source", [TYPEC_PORT_SNK] = "sink", [TYPEC_PORT_DRP] = "dual", }; Thanks Li Jun > > > Thanks, > > -- > heikki -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, May 17, 2018 at 02:05:41PM +0000, Jun Li wrote: > Hi Heikki, > > > > I reread this patch and tried to see it more in the context of the > > > other patches and the existing code. The naming of the existing string > > > tables doesn't help in getting this right, however I have a proposal: > > > > > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > > > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > > > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > > > > > and sometime, if the use should arise > > > > > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > > > > > I think it is fairly comprehensible, *_port_* concerns a capability > > > and without *_port_* it is an actual state. Plus it matches the names > > > of the constants. > > > > Well, there are now four things to consider: > > > > 1) the roles (power and data) the port is capable of supporting > > 2) Try.SRC and Try.SNK, i.e. the preferred role > > 3) the current roles > > 4) the role(s) the user want's to limit the use of a port with DRP ports > > > > The last one I don't know if it's relevant with these functions. It's not > > information that we would get for example from firmware. > > > > I also don't think we need to use these functions with the current roles the port > > is in. > > > > If the preferred role is "sink" or "source", so just like the power role, we don't > > need separate function for it here. > > > > So isn't two functions all we need here: one for the power and one for data > > role? > > Take power as an example, can we use one function to only look up > typec_port_types[]? as capability(typec_port_type) and state(typec_role) > are different enum, and the allowed strings are different. > > static const char * const typec_roles[] = { > [TYPEC_SINK] = "sink", > [TYPEC_SOURCE] = "source", > }; > > static const char * const typec_port_types[] = { > [TYPEC_PORT_SRC] = "source", > [TYPEC_PORT_SNK] = "sink", > [TYPEC_PORT_DRP] = "dual", > }; Where out side the class code we need to convert the current role, the "state", with these functions? Thanks,
Hi > -----Original Message----- > From: Heikki Krogerus [mailto:heikki.krogerus@linux.intel.com] > Sent: 2018年5月17日 22:24 > To: Jun Li <jun.li@nxp.com> > Cc: Mats Karrman <mats.dev.list@gmail.com>; robh+dt@kernel.org; > gregkh@linuxfoundation.org; linux@roeck-us.net; a.hajda@samsung.com; > cw00.choi@samsung.com; shufan_lee@richtek.com; Peter Chen > <peter.chen@nxp.com>; gsomlo@gmail.com; devicetree@vger.kernel.org; > linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com> > Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > and data config > > On Thu, May 17, 2018 at 02:05:41PM +0000, Jun Li wrote: > > Hi Heikki, > > > > > > I reread this patch and tried to see it more in the context of the > > > > other patches and the existing code. The naming of the existing > > > > string tables doesn't help in getting this right, however I have a proposal: > > > > > > > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > > > > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > > > > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > > > > > > > and sometime, if the use should arise > > > > > > > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > > > > > > > I think it is fairly comprehensible, *_port_* concerns a > > > > capability and without *_port_* it is an actual state. Plus it > > > > matches the names of the constants. > > > > > > Well, there are now four things to consider: > > > > > > 1) the roles (power and data) the port is capable of supporting > > > 2) Try.SRC and Try.SNK, i.e. the preferred role > > > 3) the current roles > > > 4) the role(s) the user want's to limit the use of a port with DRP > > > ports > > > > > > The last one I don't know if it's relevant with these functions. > > > It's not information that we would get for example from firmware. > > > > > > I also don't think we need to use these functions with the current > > > roles the port is in. > > > > > > If the preferred role is "sink" or "source", so just like the power > > > role, we don't need separate function for it here. > > > > > > So isn't two functions all we need here: one for the power and one > > > for data role? > > > > Take power as an example, can we use one function to only look up > > typec_port_types[]? as capability(typec_port_type) and > > state(typec_role) are different enum, and the allowed strings are different. > > > > static const char * const typec_roles[] = { > > [TYPEC_SINK] = "sink", > > [TYPEC_SOURCE] = "source", > > }; > > > > static const char * const typec_port_types[] = { > > [TYPEC_PORT_SRC] = "source", > > [TYPEC_PORT_SNK] = "sink", > > [TYPEC_PORT_DRP] = "dual", > > }; > > Where out side the class code we need to convert the current role, the "state", > with these functions? Currently, the only call site is getting the preferred power role from firmware. Thanks Li Jun > > > Thanks, > > -- > heikki
Hi Jun, Sorry for the delay. On Thu, May 17, 2018 at 02:41:31PM +0000, Jun Li wrote: > Hi > > -----Original Message----- > > From: Heikki Krogerus [mailto:heikki.krogerus@linux.intel.com] > > Sent: 2018??5??17?? 22:24 > > To: Jun Li <jun.li@nxp.com> > > Cc: Mats Karrman <mats.dev.list@gmail.com>; robh+dt@kernel.org; > > gregkh@linuxfoundation.org; linux@roeck-us.net; a.hajda@samsung.com; > > cw00.choi@samsung.com; shufan_lee@richtek.com; Peter Chen > > <peter.chen@nxp.com>; gsomlo@gmail.com; devicetree@vger.kernel.org; > > linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com> > > Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > > and data config > > > > On Thu, May 17, 2018 at 02:05:41PM +0000, Jun Li wrote: > > > Hi Heikki, > > > > > > > > I reread this patch and tried to see it more in the context of the > > > > > other patches and the existing code. The naming of the existing > > > > > string tables doesn't help in getting this right, however I have a proposal: > > > > > > > > > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > > > > > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > > > > > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > > > > > > > > > and sometime, if the use should arise > > > > > > > > > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > > > > > > > > > I think it is fairly comprehensible, *_port_* concerns a > > > > > capability and without *_port_* it is an actual state. Plus it > > > > > matches the names of the constants. > > > > > > > > Well, there are now four things to consider: > > > > > > > > 1) the roles (power and data) the port is capable of supporting > > > > 2) Try.SRC and Try.SNK, i.e. the preferred role > > > > 3) the current roles > > > > 4) the role(s) the user want's to limit the use of a port with DRP > > > > ports > > > > > > > > The last one I don't know if it's relevant with these functions. > > > > It's not information that we would get for example from firmware. > > > > > > > > I also don't think we need to use these functions with the current > > > > roles the port is in. > > > > > > > > If the preferred role is "sink" or "source", so just like the power > > > > role, we don't need separate function for it here. > > > > > > > > So isn't two functions all we need here: one for the power and one > > > > for data role? > > > > > > Take power as an example, can we use one function to only look up > > > typec_port_types[]? as capability(typec_port_type) and > > > state(typec_role) are different enum, and the allowed strings are different. > > > > > > static const char * const typec_roles[] = { > > > [TYPEC_SINK] = "sink", > > > [TYPEC_SOURCE] = "source", > > > }; > > > > > > static const char * const typec_port_types[] = { > > > [TYPEC_PORT_SRC] = "source", > > > [TYPEC_PORT_SNK] = "sink", > > > [TYPEC_PORT_DRP] = "dual", > > > }; > > > > Where out side the class code we need to convert the current role, the "state", > > with these functions? > > Currently, the only call site is getting the preferred power role from firmware. My point was that if we used enum typec_port_type with the prefered role, we could use the helper for power role with prefered role. But never mind. Thanks,
Hi Heikki, > -----Original Message----- > From: Heikki Krogerus [mailto:heikki.krogerus@linux.intel.com] > Sent: 2018年5月21日 21:13 > To: Jun Li <jun.li@nxp.com> > Cc: Mats Karrman <mats.dev.list@gmail.com>; robh+dt@kernel.org; > gregkh@linuxfoundation.org; linux@roeck-us.net; a.hajda@samsung.com; > cw00.choi@samsung.com; shufan_lee@richtek.com; Peter Chen > <peter.chen@nxp.com>; gsomlo@gmail.com; devicetree@vger.kernel.org; > linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com> > Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic port power > and data config > > Hi Jun, > > Sorry for the delay. > > On Thu, May 17, 2018 at 02:41:31PM +0000, Jun Li wrote: > > Hi > > > -----Original Message----- > > > From: Heikki Krogerus [mailto:heikki.krogerus@linux.intel.com] > > > Sent: 2018??5??17?? 22:24 > > > To: Jun Li <jun.li@nxp.com> > > > Cc: Mats Karrman <mats.dev.list@gmail.com>; robh+dt@kernel.org; > > > gregkh@linuxfoundation.org; linux@roeck-us.net; a.hajda@samsung.com; > > > cw00.choi@samsung.com; shufan_lee@richtek.com; Peter Chen > > > <peter.chen@nxp.com>; gsomlo@gmail.com; devicetree@vger.kernel.org; > > > linux-usb@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com> > > > Subject: Re: [PATCH v5 05/14] usb: typec: add API to get typec basic > > > port power and data config > > > > > > On Thu, May 17, 2018 at 02:05:41PM +0000, Jun Li wrote: > > > > Hi Heikki, > > > > > > > > > > I reread this patch and tried to see it more in the context of > > > > > > the other patches and the existing code. The naming of the > > > > > > existing string tables doesn't help in getting this right, however I have > a proposal: > > > > > > > > > > > > typec_find_port_power_role() to get to TYPEC_PORT_SRC/SNK/DRP > > > > > > typec_find_port_data_role() to get to TYPEC_PORT_DFP/UFP/DRD > > > > > > typec_find_power_role() to get to TYPEC_SINK/SOURCE > > > > > > > > > > > > and sometime, if the use should arise > > > > > > > > > > > > typec_find_data_role() to get to TYPEC_DEVICE/HOST > > > > > > > > > > > > I think it is fairly comprehensible, *_port_* concerns a > > > > > > capability and without *_port_* it is an actual state. Plus it > > > > > > matches the names of the constants. > > > > > > > > > > Well, there are now four things to consider: > > > > > > > > > > 1) the roles (power and data) the port is capable of supporting > > > > > 2) Try.SRC and Try.SNK, i.e. the preferred role > > > > > 3) the current roles > > > > > 4) the role(s) the user want's to limit the use of a port with > > > > > DRP ports > > > > > > > > > > The last one I don't know if it's relevant with these functions. > > > > > It's not information that we would get for example from firmware. > > > > > > > > > > I also don't think we need to use these functions with the > > > > > current roles the port is in. > > > > > > > > > > If the preferred role is "sink" or "source", so just like the > > > > > power role, we don't need separate function for it here. > > > > > > > > > > So isn't two functions all we need here: one for the power and > > > > > one for data role? > > > > > > > > Take power as an example, can we use one function to only look up > > > > typec_port_types[]? as capability(typec_port_type) and > > > > state(typec_role) are different enum, and the allowed strings are > different. > > > > > > > > static const char * const typec_roles[] = { > > > > [TYPEC_SINK] = "sink", > > > > [TYPEC_SOURCE] = "source", > > > > }; > > > > > > > > static const char * const typec_port_types[] = { > > > > [TYPEC_PORT_SRC] = "source", > > > > [TYPEC_PORT_SNK] = "sink", > > > > [TYPEC_PORT_DRP] = "dual", > > > > }; > > > > > > Where out side the class code we need to convert the current role, > > > the "state", with these functions? > > > > Currently, the only call site is getting the preferred power role from firmware. > > My point was that if we used enum typec_port_type with the prefered role, we > could use the helper for power role with prefered role. But never mind. Got your point. So let's follow Mats's suggestion on this, I will update a new version. Thanks Li Jun > > > Thanks, > > -- > heikki
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 53df10d..5981e18 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -9,6 +9,7 @@ #include <linux/device.h> #include <linux/module.h> #include <linux/mutex.h> +#include <linux/property.h> #include <linux/slab.h> #include <linux/usb/typec.h> #include <linux/usb/typec_mux.h> @@ -802,6 +803,12 @@ static const char * const typec_port_types[] = { [TYPEC_PORT_DRP] = "dual", }; +static const char * const typec_data_types[] = { + [TYPEC_PORT_DFP] = "host", + [TYPEC_PORT_UFP] = "device", + [TYPEC_PORT_DRD] = "dual", +}; + static const char * const typec_port_types_drp[] = { [TYPEC_PORT_SRC] = "dual [source] sink", [TYPEC_PORT_SNK] = "dual source [sink]", @@ -1252,6 +1259,51 @@ void typec_set_pwr_opmode(struct typec_port *port, } EXPORT_SYMBOL_GPL(typec_set_pwr_opmode); +/** + * typec_find_power_type - Get the typec port power type + * @name: port type string + * + * This routine is used to find the typec_port_type by its string name. + * + * Returns typec_port_type if success, otherwise negative error code. + */ +int typec_find_power_type(const char *name) +{ + return match_string(typec_port_types, ARRAY_SIZE(typec_port_types), + name); +} +EXPORT_SYMBOL_GPL(typec_find_power_type); + +/** + * typec_find_preferred_role - Find the typec drp port preferred power role + * @name: power role string + * + * This routine is used to find the typec_role by its string name of + * preferred power role(Try.SRC or Try.SNK). + * + * Returns typec_role if success, otherwise negative error code. + */ +int typec_find_preferred_role(const char *name) +{ + return match_string(typec_roles, ARRAY_SIZE(typec_roles), name); +} +EXPORT_SYMBOL_GPL(typec_find_preferred_role); + +/** + * typec_find_data_type - Get the typec port data capability + * @name: data type string + * + * This routine is used to find the typec_port_data by its string name. + * + * Returns typec_port_data if success, otherwise negative error code. + */ +int typec_find_data_type(const char *name) +{ + return match_string(typec_data_types, ARRAY_SIZE(typec_data_types), + name); +} +EXPORT_SYMBOL_GPL(typec_find_data_type); + /* ------------------------------------------ */ /* API for Multiplexer/DeMultiplexer Switches */ diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 672b39b..00c93e7 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -267,4 +267,7 @@ int typec_set_orientation(struct typec_port *port, enum typec_orientation orientation); int typec_set_mode(struct typec_port *port, int mode); +int typec_find_power_type(const char *name); +int typec_find_preferred_role(const char *name); +int typec_find_data_type(const char *name); #endif /* __LINUX_USB_TYPEC_H */
This patch adds 3 APIs to get the typec port power and data type, and preferred power role by its name string. Signed-off-by: Li Jun <jun.li@nxp.com> --- drivers/usb/typec/class.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 3 +++ 2 files changed, 55 insertions(+)