RE: [PATCH 3/4] usb: typec: add typec orientation switch support via mux controller

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

 




> -----Original Message-----
> From: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
> Sent: Thursday, May 20, 2021 8:34 PM
> To: Jun Li <jun.li@xxxxxxx>
> Cc: robh+dt@xxxxxxxxxx; shawnguo@xxxxxxxxxx; gregkh@xxxxxxxxxxxxxxxxxxx;
> linux@xxxxxxxxxxxx; linux-usb@xxxxxxxxxxxxxxx; dl-linux-imx
> <linux-imx@xxxxxxx>; devicetree@xxxxxxxxxxxxxxx;
> linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> Subject: Re: [PATCH 3/4] usb: typec: add typec orientation switch support
> via mux controller
> 
> On Wed, May 19, 2021 at 03:14:49PM +0800, Li Jun wrote:
> > Some dedicated mux block can use existing mux controller as a mux
> > provider, typec port as a consumer to select channel for orientation
> > switch, this can be an alternate way to current typec_switch
> > interface.
> >
> > Signed-off-by: Li Jun <jun.li@xxxxxxx>
> > ---
> >  drivers/usb/typec/class.c     | 26 +++++++++++++++++++++++++-
> >  drivers/usb/typec/class.h     |  2 ++
> >  drivers/usb/typec/mux.c       | 34 ++++++++++++++++++++++++++++++++++
> >  include/linux/usb/typec_mux.h |  4 ++++
> >  4 files changed, 65 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> > index a29bf2c32233..1bb0275e6204 100644
> > --- a/drivers/usb/typec/class.c
> > +++ b/drivers/usb/typec/class.c
> > @@ -1601,6 +1601,7 @@ static void typec_release(struct device *dev)
> >  	ida_simple_remove(&typec_index_ida, port->id);
> >  	ida_destroy(&port->mode_ids);
> >  	typec_switch_put(port->sw);
> > +	typec_mux_control_switch_put(port->mux_control_switch);
> >  	typec_mux_put(port->mux);
> >  	kfree(port->cap);
> >  	kfree(port);
> > @@ -1816,6 +1817,13 @@ int typec_set_orientation(struct typec_port *port,
> >  	if (ret)
> >  		return ret;
> >
> > +	if (!port->sw) {
> > +		ret = typec_mux_control_switch_set(port->mux_control_switch,
> > +				port->mux_control_switch_states[orientation]);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> >  	port->orientation = orientation;
> >  	sysfs_notify(&port->dev.kobj, NULL, "orientation");
> >  	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE); @@ -1991,7 +1999,7 @@
> > struct typec_port *typec_register_port(struct device *parent,
> >  				       const struct typec_capability *cap)  {
> >  	struct typec_port *port;
> > -	int ret;
> > +	int ret = 0;
> >  	int id;
> >
> >  	port = kzalloc(sizeof(*port), GFP_KERNEL); @@ -2068,6 +2076,22 @@
> > struct typec_port *typec_register_port(struct device *parent,
> >  		return ERR_PTR(ret);
> >  	}
> >
> > +	if (!port->sw) {
> > +		/* Try to get typec switch via general mux controller */
> > +		port->mux_control_switch =
> typec_mux_control_switch_get(&port->dev);
> > +		if (IS_ERR(port->mux_control_switch))
> > +			ret = PTR_ERR(port->mux_control_switch);
> > +		else if (port->mux_control_switch)
> > +			ret = device_property_read_u32_array(&port->dev,
> > +					"mux-control-switch-states",
> > +					port->mux_control_switch_states,
> > +					3);
> > +		if (ret) {
> > +			put_device(&port->dev);
> > +			return ERR_PTR(ret);
> > +		}
> > +	}
> 
> Why not just do that inside fwnode_typec_switch_get() and handle the whole
> thing in drivers/usb/typec/mux.c (or in its own file if you prefer)?
> 
> You'll just need to register a "wrapper" Type-C switch object for the OF
> mux controller, but that should not be a problem. That way you don't need
> to export any new functions, touch this file or anything else.
> 

Okay, so stick to current typec_switch is preferred, actually I hesitated
on this, I know that approach will have a unified interface, but with
the cost of creating it only for wrap.

My v2 will go with the direction you suggested.

Thanks
Li Jun

> 
> thanks,
> 
> --
> heikki




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux