Re: [PATCH 3/3] usb: typec: ucsi: retry find role swithch when module load late

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

 



On Wed, Apr 13, 2022 at 08:16:53AM +0000, Linyu Yuan (QUIC) wrote:
> > From: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
> > Sent: Wednesday, April 13, 2022 4:10 PM
> > To: Linyu Yuan (QUIC) <quic_linyyuan@xxxxxxxxxxx>
> > Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; linux-
> > usb@xxxxxxxxxxxxxxx; Jack Pham (QUIC) <quic_jackp@xxxxxxxxxxx>
> > Subject: Re: [PATCH 3/3] usb: typec: ucsi: retry find role swithch when
> > module load late
> > 
> > On Wed, Apr 13, 2022 at 08:00:35AM +0000, Linyu Yuan (QUIC) wrote:
> > > > From: Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx>
> > > > Sent: Wednesday, April 13, 2022 3:46 PM
> > > > To: Linyu Yuan (QUIC) <quic_linyyuan@xxxxxxxxxxx>
> > > > Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>; linux-
> > > > usb@xxxxxxxxxxxxxxx; Jack Pham (QUIC) <quic_jackp@xxxxxxxxxxx>
> > > > Subject: Re: [PATCH 3/3] usb: typec: ucsi: retry find role swithch when
> > > > module load late
> > > >
> > > > On Tue, Apr 12, 2022 at 06:30:07PM +0800, Linyu Yuan wrote:
> > > > > When role switch enabled, return -EAGAIN if fail to find it due to
> > > > > module load ordering issue, then restart ucsi init work to find
> > > > > it again every 100ms.
> > > > >
> > > > > It also means change ucsi init work to delayed_work.
> > > > >
> > > > > Signed-off-by: Linyu Yuan <quic_linyyuan@xxxxxxxxxxx>
> > > > > ---
> > > > >  drivers/usb/typec/ucsi/ucsi.c | 28 ++++++++++++++++------------
> > > > >  drivers/usb/typec/ucsi/ucsi.h |  2 +-
> > > > >  2 files changed, 17 insertions(+), 13 deletions(-)
> > > > >
> > > > > diff --git a/drivers/usb/typec/ucsi/ucsi.c
> > b/drivers/usb/typec/ucsi/ucsi.c
> > > > > index 684fc4f..fabd4df 100644
> > > > > --- a/drivers/usb/typec/ucsi/ucsi.c
> > > > > +++ b/drivers/usb/typec/ucsi/ucsi.c
> > > > > @@ -1053,6 +1053,14 @@ static int ucsi_register_port(struct ucsi *ucsi,
> > int
> > > > index)
> > > > >  	con->num = index + 1;
> > > > >  	con->ucsi = ucsi;
> > > > >
> > > > > +	cap->fwnode = ucsi_find_fwnode(con);
> > > > > +	con->usb_role_sw = fwnode_usb_role_switch_get(cap->fwnode);
> > > > > +	if (IS_ERR(con->usb_role_sw)) {
> > > > > +		dev_err(ucsi->dev, "con%d: failed to get usb role switch\n",
> > > > > +			index + 1);
> > > > > +		return -EAGAIN;
> > > > > +	}
> > > >
> > > > No, this is wrong. If there is a role switch assigned in the firmware
> > > > for the port, then fwnode_usb_role_switch_get() will return
> > > > -EPROBE_DEFER until the switch has been registered.
> > > >
> > > > So I think what you want to do is just make the failure to get the
> > > > role switch fatal in this driver. Just return PTR_ERR(con->usb_role_sw).
> > > Thanks, will change it to check -EPROBE_DEFER.
> > 
> > No, you don't check that, you just return that.
> Yes, I do like it.
> > 
> > So you don't need that crazy polling mechanism where you queue a work
> > until you get the resource. Just let the driver core handle the
> > situation.
> The issue is when a UCSI implementation driver probe, it call ucsi_register(),
> But this function will not return -EPROBE_DEFER,
> It just queue a work to start connector discovery.

Ah, right right. This is a library. But we should be able use
wait_for_device_probe().

So if fwnode_usb_role_switch_get() returns -EPROBE_DEFER, you call
wait_for_device_probe() and try again.

Br,

-- 
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