[PATCH] usb: gadget: dwc2_udc_otg: implement pullup()
marex at denx.de
Tue Jan 10 14:45:44 CET 2023
On 1/10/23 14:39, Mattijs Korpershoek wrote:
> Hi Harald,
> Thank you for your review.
> On Tue, Jan 10, 2023 at 14:30, Harald Seiler <hws at denx.de> wrote:
>> On Tue, 2023-01-10 at 10:11 +0100, Mattijs Korpershoek wrote:
>>> Pullup is used by the usb framework in order to do software-controlled
>>> usb_gadget_connect() and usb_gadget_disconnect().
>>> Implement pullup() for dwc2 using the SOFT_DISCONNECT bit in the dctl
>>> This is especially useful when a gadget disconnection is initiated but
>>> no board_usb_cleanup() is called.
>>> Signed-off-by: Mattijs Korpershoek <mkorpershoek at baylibre.com>
>>> On some boards using the dwc2 controller, like the Khadas VIM3L, whenever
>>> usb_gadget_release() is called, the D+ and D- lines are in an unknown state.
>>> Because of that, the host can't detect usb disconnection.
>>> It was attempted to be be fixed with  but ended up doing the gadget disconnection
>>> too early, creating issues on NXP-based boards which use uuu .
>>> By implementing pullup() in the controller driver, we ensure that the disconnection will
>>> only be done when the framework calls usb_gadget_disconnect().
>>>  https://firstname.lastname@example.org/
>>>  https://email@example.com/
>>> drivers/usb/gadget/dwc2_udc_otg.c | 16 ++++++++++++++++
>>> 1 file changed, 16 insertions(+)
>>> diff --git a/drivers/usb/gadget/dwc2_udc_otg.c b/drivers/usb/gadget/dwc2_udc_otg.c
>>> index 77988f78ab30..93ed9712d18a 100644
>>> --- a/drivers/usb/gadget/dwc2_udc_otg.c
>>> +++ b/drivers/usb/gadget/dwc2_udc_otg.c
>>> @@ -236,6 +236,21 @@ static int udc_enable(struct dwc2_udc *dev)
>>> return 0;
>>> +static int dwc2_gadget_pullup(struct usb_gadget *g, int is_on)
>>> + unsigned int uTemp;
>> Just some minor points about style...
>> I think the `u32` type should be used for 32-bit registers instead.
>> More explicit and no room for accidentally choosing the wrong size.
>> Also, U-Boot and Linux don't use hungarian notation for variable names,
>> just call it `tmp` or even better `dctl` to be explicit.
> I agree with this. I actually picked up some of the code from
> reconfig_usbd() where hungarian nototation is used. That's also where
> the unsigned int comes from.
> Sorry I did not convert it to some more Linux/U-Boot oriented style
> before submitting.
>>> + is_on = !!is_on;
>> This is superfluous, the if condition works either way.
> The maintainer (Marek) already picked this up in his usb tree:
> Should I send a clean-up/follow-up patch for this?
The maintainer already dropped it and waits for V2 :)
More information about the U-Boot