diff mbox series

[v4,3/4] usb: typec: mux: add "compatible" property for switch match

Message ID 1603098195-9923-3-git-send-email-jun.li@nxp.com (mailing list archive)
State Superseded
Headers show
Series [v4,1/4] dt-bindings: usb: add documentation for typec switch simple driver | expand

Commit Message

Jun Li Oct. 19, 2020, 9:03 a.m. UTC
For those need a dedicated typec switch simple solution driver,
use compatible property for matching.

Signed-off-by: Li Jun <jun.li@nxp.com>
---
New patch for v4.

 drivers/usb/typec/mux.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Peter Chen Oct. 20, 2020, 6:05 a.m. UTC | #1
On 20-10-19 17:03:14, Li Jun wrote:
> For those need a dedicated typec switch simple solution driver,
> use compatible property for matching.
> 
> Signed-off-by: Li Jun <jun.li@nxp.com>
> ---
> New patch for v4.
> 
>  drivers/usb/typec/mux.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index 52ad277..3da17d1 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -39,7 +39,8 @@ static void *typec_switch_match(struct device_connection *con, int ep,
>  {
>  	struct device *dev;
>  
> -	if (con->id && !fwnode_property_present(con->fwnode, con->id))
> +	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
> +		       !fwnode_property_present(con->fwnode, con->id))
>  		return NULL;

If property is not present, should not fwnode_is_compatible return NULL?

Peter

>  
>  	dev = class_find_device(&typec_mux_class, NULL, con->fwnode,
> @@ -61,8 +62,8 @@ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
>  {
>  	struct typec_switch *sw;
>  
> -	sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL,
> -					  typec_switch_match);
> +	sw = fwnode_connection_find_match(fwnode, "typec-orientation-switch",
> +					  NULL, typec_switch_match);
>  	if (!IS_ERR_OR_NULL(sw))
>  		WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
>  
> -- 
> 2.7.4
>
Jun Li Oct. 20, 2020, 1:02 p.m. UTC | #2
> -----Original Message-----
> From: Peter Chen <peter.chen@nxp.com>
> Sent: Tuesday, October 20, 2020 2:05 PM
> To: Jun Li <jun.li@nxp.com>
> Cc: heikki.krogerus@linux.intel.com; robh+dt@kernel.org;
> rafael@kernel.org; gregkh@linuxfoundation.org;
> andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
> lee.jones@linaro.org; mika.westerberg@linux.intel.com;
> dmitry.torokhov@gmail.com; prabhakar.mahadev-lad.rj@bp.renesas.com;
> laurent.pinchart+renesas@ideasonboard.com; linux-usb@vger.kernel.org;
> devicetree@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v4 3/4] usb: typec: mux: add "compatible" property for
> switch match
> 
> On 20-10-19 17:03:14, Li Jun wrote:
> > For those need a dedicated typec switch simple solution driver, use
> > compatible property for matching.
> >
> > Signed-off-by: Li Jun <jun.li@nxp.com>
> > ---
> > New patch for v4.
> >
> >  drivers/usb/typec/mux.c | 7 ++++---
> >  1 file changed, 4 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index
> > 52ad277..3da17d1 100644
> > --- a/drivers/usb/typec/mux.c
> > +++ b/drivers/usb/typec/mux.c
> > @@ -39,7 +39,8 @@ static void *typec_switch_match(struct
> > device_connection *con, int ep,  {
> >  	struct device *dev;
> >
> > -	if (con->id && !fwnode_property_present(con->fwnode, con->id))
> > +	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
> > +		       !fwnode_property_present(con->fwnode, con->id))
> >  		return NULL;
> 
> If property is not present, should not fwnode_is_compatible return NULL?

Do you want to say:

If property is not present, should not *typec_switch_match* return NULL?

Li Jun
> 
> Peter
> 
> >
> >  	dev = class_find_device(&typec_mux_class, NULL, con->fwnode, @@
> > -61,8 +62,8 @@ struct typec_switch *fwnode_typec_switch_get(struct
> > fwnode_handle *fwnode)  {
> >  	struct typec_switch *sw;
> >
> > -	sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL,
> > -					  typec_switch_match);
> > +	sw = fwnode_connection_find_match(fwnode, "typec-orientation-switch",
> > +					  NULL, typec_switch_match);
> >  	if (!IS_ERR_OR_NULL(sw))
> >  		WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
> >
> > --
> > 2.7.4
> >
> 
> --
> 
> Thanks,
> Peter Chen
Peter Chen Oct. 21, 2020, 12:16 a.m. UTC | #3
On 20-10-20 13:02:30, Jun Li wrote:
> 
> 
> > -----Original Message-----
> > From: Peter Chen <peter.chen@nxp.com>
> > Sent: Tuesday, October 20, 2020 2:05 PM
> > To: Jun Li <jun.li@nxp.com>
> > Cc: heikki.krogerus@linux.intel.com; robh+dt@kernel.org;
> > rafael@kernel.org; gregkh@linuxfoundation.org;
> > andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
> > lee.jones@linaro.org; mika.westerberg@linux.intel.com;
> > dmitry.torokhov@gmail.com; prabhakar.mahadev-lad.rj@bp.renesas.com;
> > laurent.pinchart+renesas@ideasonboard.com; linux-usb@vger.kernel.org;
> > devicetree@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> > Subject: Re: [PATCH v4 3/4] usb: typec: mux: add "compatible" property for
> > switch match
> > 
> > On 20-10-19 17:03:14, Li Jun wrote:
> > > For those need a dedicated typec switch simple solution driver, use
> > > compatible property for matching.
> > >
> > > Signed-off-by: Li Jun <jun.li@nxp.com>
> > > ---
> > > New patch for v4.
> > >
> > >  drivers/usb/typec/mux.c | 7 ++++---
> > >  1 file changed, 4 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index
> > > 52ad277..3da17d1 100644
> > > --- a/drivers/usb/typec/mux.c
> > > +++ b/drivers/usb/typec/mux.c
> > > @@ -39,7 +39,8 @@ static void *typec_switch_match(struct
> > > device_connection *con, int ep,  {
> > >  	struct device *dev;
> > >
> > > -	if (con->id && !fwnode_property_present(con->fwnode, con->id))
> > > +	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
> > > +		       !fwnode_property_present(con->fwnode, con->id))
> > >  		return NULL;
> > 
> > If property is not present, should not fwnode_is_compatible return NULL?
> 
> Do you want to say:
> 
> If property is not present, should not *typec_switch_match* return NULL?

If fwnode_is_compatible returns true, it should mean the fwnode_property_present is
true too. But if fwnode_is_compatible is false, the fwnode_property_present may return
true, the code does not return NULL. Then, with this new patch, what changes compared
to original logic?

Peter

> > 
> > >
> > >  	dev = class_find_device(&typec_mux_class, NULL, con->fwnode, @@
> > > -61,8 +62,8 @@ struct typec_switch *fwnode_typec_switch_get(struct
> > > fwnode_handle *fwnode)  {
> > >  	struct typec_switch *sw;
> > >
> > > -	sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL,
> > > -					  typec_switch_match);
> > > +	sw = fwnode_connection_find_match(fwnode, "typec-orientation-switch",
> > > +					  NULL, typec_switch_match);
> > >  	if (!IS_ERR_OR_NULL(sw))
> > >  		WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
> > >
> > > --
> > > 2.7.4
> > >
> > 
> > --
> > 
> > Thanks,
> > Peter Chen
Jun Li Oct. 21, 2020, 2:43 a.m. UTC | #4
> -----Original Message-----
> From: Peter Chen <peter.chen@nxp.com>
> Sent: Wednesday, October 21, 2020 8:16 AM
> To: Jun Li <jun.li@nxp.com>
> Cc: heikki.krogerus@linux.intel.com; robh+dt@kernel.org;
> rafael@kernel.org; gregkh@linuxfoundation.org;
> andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
> lee.jones@linaro.org; mika.westerberg@linux.intel.com;
> dmitry.torokhov@gmail.com; prabhakar.mahadev-lad.rj@bp.renesas.com;
> laurent.pinchart+renesas@ideasonboard.com; linux-usb@vger.kernel.org;
> devicetree@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH v4 3/4] usb: typec: mux: add "compatible" property for
> switch match
> 
> On 20-10-20 13:02:30, Jun Li wrote:
> >
> >
> > > -----Original Message-----
> > > From: Peter Chen <peter.chen@nxp.com>
> > > Sent: Tuesday, October 20, 2020 2:05 PM
> > > To: Jun Li <jun.li@nxp.com>
> > > Cc: heikki.krogerus@linux.intel.com; robh+dt@kernel.org;
> > > rafael@kernel.org; gregkh@linuxfoundation.org;
> > > andriy.shevchenko@linux.intel.com; hdegoede@redhat.com;
> > > lee.jones@linaro.org; mika.westerberg@linux.intel.com;
> > > dmitry.torokhov@gmail.com; prabhakar.mahadev-lad.rj@bp.renesas.com;
> > > laurent.pinchart+renesas@ideasonboard.com;
> > > linux-usb@vger.kernel.org; devicetree@vger.kernel.org; dl-linux-imx
> > > <linux-imx@nxp.com>
> > > Subject: Re: [PATCH v4 3/4] usb: typec: mux: add "compatible"
> > > property for switch match
> > >
> > > On 20-10-19 17:03:14, Li Jun wrote:
> > > > For those need a dedicated typec switch simple solution driver,
> > > > use compatible property for matching.
> > > >
> > > > Signed-off-by: Li Jun <jun.li@nxp.com>
> > > > ---
> > > > New patch for v4.
> > > >
> > > >  drivers/usb/typec/mux.c | 7 ++++---
> > > >  1 file changed, 4 insertions(+), 3 deletions(-)
> > > >
> > > > diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> > > > index
> > > > 52ad277..3da17d1 100644
> > > > --- a/drivers/usb/typec/mux.c
> > > > +++ b/drivers/usb/typec/mux.c
> > > > @@ -39,7 +39,8 @@ static void *typec_switch_match(struct
> > > > device_connection *con, int ep,  {
> > > >  	struct device *dev;
> > > >
> > > > -	if (con->id && !fwnode_property_present(con->fwnode, con->id))
> > > > +	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
> > > > +		       !fwnode_property_present(con->fwnode, con->id))
> > > >  		return NULL;
> > >
> > > If property is not present, should not fwnode_is_compatible return NULL?
> >
> > Do you want to say:
> >
> > If property is not present, should not *typec_switch_match* return NULL?
> 
> If fwnode_is_compatible returns true, it should mean the
> fwnode_property_present is true too. 

Nope.

fwnode_is_compatible():
        property name: compatible
fwnode_property_present():
        property name: typec-orientation-switch

> But if fwnode_is_compatible is false,
> the fwnode_property_present may return true, the code does not return NULL.

Yes. Original matching via bool property is still allowed.

> Then, with this new patch, what changes compared to original logic?

One more way to match typec switch via compatible.

> 
> Peter
> 
> > >
> > > >
> > > >  	dev = class_find_device(&typec_mux_class, NULL, con->fwnode, @@
> > > > -61,8 +62,8 @@ struct typec_switch *fwnode_typec_switch_get(struct
> > > > fwnode_handle *fwnode)  {
> > > >  	struct typec_switch *sw;
> > > >
> > > > -	sw = fwnode_connection_find_match(fwnode, "orientation-switch",
> NULL,
> > > > -					  typec_switch_match);
> > > > +	sw = fwnode_connection_find_match(fwnode,
> "typec-orientation-switch",
> > > > +					  NULL, typec_switch_match);
> > > >  	if (!IS_ERR_OR_NULL(sw))
> > > >  		WARN_ON(!try_module_get(sw->dev.parent->driver->owner));
> > > >
> > > > --
> > > > 2.7.4
> > > >
> > >
> > > --
> > >
> > > Thanks,
> > > Peter Chen
> 
> --
> 
> Thanks,
> Peter Chen
diff mbox series

Patch

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index 52ad277..3da17d1 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -39,7 +39,8 @@  static void *typec_switch_match(struct device_connection *con, int ep,
 {
 	struct device *dev;
 
-	if (con->id && !fwnode_property_present(con->fwnode, con->id))
+	if (con->id && !fwnode_is_compatible(con->fwnode, con->id) &&
+		       !fwnode_property_present(con->fwnode, con->id))
 		return NULL;
 
 	dev = class_find_device(&typec_mux_class, NULL, con->fwnode,
@@ -61,8 +62,8 @@  struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 {
 	struct typec_switch *sw;
 
-	sw = fwnode_connection_find_match(fwnode, "orientation-switch", NULL,
-					  typec_switch_match);
+	sw = fwnode_connection_find_match(fwnode, "typec-orientation-switch",
+					  NULL, typec_switch_match);
 	if (!IS_ERR_OR_NULL(sw))
 		WARN_ON(!try_module_get(sw->dev.parent->driver->owner));