usb: gadget: atmel: reliably generate disconnect by disabling controller instead of toggling PULLD_DIS
Subsystems (2)
PATCH 1/1 usb: gadget: atmel: reliably generate disconnect by disabling controller instead of toggling PULLD_DIS
Contrary to the datasheet, setting both DETACH and PULLD_DIS bits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.
The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
Disabling and re-enabling the controller entirely, instead of toggling the PULLD_DIS bit, reliably generates a disconnect event.
The Linux driver works correctly because gadget_disconnect/gadget_connect are always followed by gadget_udc_start/gadget_udc_stop. In U-Boot pullup() is used solely.
This behavior has been observed on the SAM9X60-Curiosity and AT91SAM9G25-EK boards and has been reported to Microchip.
--- drivers/usb/gadget/atmel_usba_udc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/usb/gadget/atmel_usba_udc.c +2 -7
@@ -521,16 +521,11 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)static int usba_udc_pullup (struct usb_gadget *gadget,int is_on) {struct usba_udc *udc =to_usba_udc (gadget); -u32 ctrl; - - ctrl =usba_readl (udc,CTRL );if (is_on) - ctrl &= ~USBA_DETACH ; +usba_writel (udc,CTRL ,USBA_ENABLE_MASK );else - ctrl |=USBA_DETACH ; - -usba_writel (udc,CTRL , ctrl); +usba_writel (udc,CTRL ,USBA_DISABLE_MASK );return 0 ; }
---
base-commit: 4d3b5c679bc9d5c6cbbeedcc1e4a186f1cc35541
change-id: 20250602-pullup-83c5540db5cd
Best regards,
Signature · 1 line
Zixun LI <[email protected]>
Hi Zixun,
Thank you for the patch.
On Mon, Jun 02, 2025 at 17:45, Zixun LI <[email protected]> wrote:
I'm surprised that checkpatch.pl does not catch this, but the subject (title) is too long (it should be less than 70 chars):
https://docs.u-boot.org/en/latest/develop/sending_patches.html#commit-message-conventions
Quoted 11 lines
Contrary to the datasheet, setting both DETACH and
PULLD_DISbits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
Disabling and re-enabling the controller entirely, instead of toggling the
PULLD_DISbit, reliably generates a disconnect event.
Quoted 6 lines
The Linux driver works correctly because gadget_disconnect/gadget_connect are always followed by gadget_udc_start/gadget_udc_stop. In U-Boot
pullup()is used solely.This behavior has been observed on the SAM9X60-Curiosity and AT91SAM9G25-EK boards and has been reported to Microchip.
I'm not against this, but the driver supports multiple gadget families according to the compatible.
I'm wondering if this issue is reproduced on other atmel boards that are supported in U-Boot.
Eugen, have you noticed the above limitation on a different board family that you maintain?
If this issue is chip specific, I think we should test for compatible in usba_udc_pullup() to only use USBA_ENABLE/USBA_DISABLE for this particular compatible (microchip,sam9x60-udc).
Quoted 11 lines
Signed-off-by Zixun LI <[email protected]>--- drivers/usb/gadget/atmel_usba_udc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/usb/gadget/atmel_usba_udc.c +0
-0
drivers/usb/gadget/atmel_usba_udc.c usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) · line 526
Quoted 10 lines
drivers/usb/gadget/atmel_usba_udc.c +1
-4@@ -521,16 +521,11 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)static int usba_udc_pullup (struct usb_gadget *gadget,int is_on) {struct usba_udc *udc =to_usba_udc (gadget); -u32 ctrl; - - ctrl =usba_readl (udc,CTRL );if (is_on) - ctrl &= ~USBA_DETACH ; +usba_writel (udc,CTRL ,USBA_ENABLE_MASK );
Could we add a comment in the function as well? Something similar to what's in the commit message:
/* Some chips don't reliably drive DP/DM lines to high impedance when
* using the DETACH/PULLD_DIS bits.
* To ensure a reliable disconnect, power cycle the controller instead */
Feel free to rephrase your preference.
Quoted 16 lines
drivers/usb/gadget/atmel_usba_udc.c +1
-4else - ctrl |=USBA_DETACH ; - -usba_writel (udc,CTRL , ctrl); +usba_writel (udc,CTRL ,USBA_DISABLE_MASK );return 0 ; } ---base-commit:
4d3b5c679bc9d5c6cbbeedcc1e4a186f1cc35541
change-id: 20250602-pullup-83c5540db5cdBest regards,
Signature · 1 line
Zixun LI <[email protected]>
Quoted 28 lines · Mattijs Korpershoek
Hi Zixun,
Thank you for the patch.
On Mon, Jun 02, 2025 at 17:45, Zixun LI <[email protected]> wrote:
I'm surprised that checkpatch.pl does not catch this, but the subject (title) is too long (it should be less than 70 chars):
https://docs.u-boot.org/en/latest/develop/sending_patches.html#commit-message-conventionsQuoted 11 lines
Contrary to the datasheet, setting both DETACH and
PULLD_DISbits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
Disabling and re-enabling the controller entirely, instead of toggling the
PULLD_DISbit, reliably generates a disconnect event.Quoted 6 lines
The Linux driver works correctly because gadget_disconnect/gadget_connect are always followed by gadget_udc_start/gadget_udc_stop. In U-Boot
pullup()is used solely.This behavior has been observed on the SAM9X60-Curiosity and AT91SAM9G25-EK boards and has been reported to Microchip.
Quoted 8 lines
I'm not against this, but the driver supports multiple gadget families according to the compatible.
I'm wondering if this issue is reproduced on other atmel boards that are supported in U-Boot.
Eugen, have you noticed the above limitation on a different board family that you maintain?
I have not seen this before, or don't remember about it.
Adding Mihai from Microchip team to see if we can get more info, whether this is a general gadget thing or it's specific to these chipsets. If it was reported to Microchip it would be interesting to see the response.
Eugen
Quoted 53 lines
If this issue is chip specific, I think we should test for compatible in
usba_udc_pullup()to only use USBA_ENABLE/USBA_DISABLE for this particular compatible (microchip,sam9x60-udc).Quoted 11 lines
Signed-off-by Zixun LI <[email protected]>--- drivers/usb/gadget/atmel_usba_udc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)drivers/usb/gadget/atmel_usba_udc.c +0
-0drivers/usb/gadget/atmel_usba_udc.c usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered) · line 526
Quoted 10 lines
drivers/usb/gadget/atmel_usba_udc.c +1
-4@@ -521,16 +521,11 @@ usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)static int usba_udc_pullup (struct usb_gadget *gadget,int is_on) {struct usba_udc *udc =to_usba_udc (gadget); -u32 ctrl; - - ctrl =usba_readl (udc,CTRL );if (is_on) - ctrl &= ~USBA_DETACH ; +usba_writel (udc,CTRL ,USBA_ENABLE_MASK );Could we add a comment in the function as well? Something similar to what's in the commit message:
/* Some chips don't reliably drive DP/DM lines to high impedance when
* using the DETACH/PULLD_DIS bits.
* To ensure a reliable disconnect, power cycle the controller instead */Feel free to rephrase your preference.
Quoted 16 lines
drivers/usb/gadget/atmel_usba_udc.c +1
-4else - ctrl |=USBA_DETACH ; - -usba_writel (udc,CTRL , ctrl); +usba_writel (udc,CTRL ,USBA_DISABLE_MASK );return 0 ; } ---base-commit:
4d3b5c679bc9d5c6cbbeedcc1e4a186f1cc35541
change-id: 20250602-pullup-83c5540db5cdBest regards,
Signature · 1 line
Zixun LI <[email protected]>
Hi all,
The case has been reported with No.01589331.
In brief line high-impedance is not observed when both PULLD_DIS & DETACH bits are 1:
- In unenumerated state (no cable attached) DP is still pulled up
- In enumerated state, disconnection is not detected by host [1] [2] only by [3].
The test has been done in 3 ways on SAM9X60-Curiosity and AT91SAM9G25-EK boards:
- Modify UDPHS_CTRL on u-boot-at91 with mw command
- Modify UDPHS_CTRL on linux4sam-poky-sam9x60_curiosity-headless-2024.10 with devmem2 utils
- On linux-mchp 6.6, comment out gadget_udc_start/stop in soft_connect_store() of drivers/usb/gadget/udc/core.c,
leaving only gadget_connect/disconnect. Then run echo disconnect > /sys/class/udc/500000.gadget/soft_connect
Host used:
1. AMD Ryzen 5800H native port, Linux 6.14
2. Intel i7-8750H native port, Windows 10
3. Genesys GL3523 hub attached to [1]
Zixun LI
Quoted 111 lines · Eugen Hristev
Quoted 31 lines · Mattijs Korpershoek
Hi Zixun,
Thank you for the patch.
On Mon, Jun 02, 2025 at 17:45, Zixun LI <[email protected]> wrote:
I'm surprised that checkpatch.pl does not catch this, but the subject (title) is too long (it should be less than 70 chars):
https://docs.u-boot.org/en/latest/develop/sending_patches.html#commit-message-conventionsQuoted 12 lines
Contrary to the datasheet, setting both DETACH and
PULLD_DISbits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
Disabling and re-enabling the controller entirely, instead of toggling the
PULLD_DISbit, reliably generates a disconnect event.Quoted 6 lines
The Linux driver works correctly because gadget_disconnect/gadget_connect are always followed by gadget_udc_start/gadget_udc_stop. In U-Boot
pullup()is used solely.This behavior has been observed on the SAM9X60-Curiosity and AT91SAM9G25-EK boards and has been reported to Microchip.
Quoted 8 lines
I'm not against this, but the driver supports multiple gadget families according to the compatible.
I'm wondering if this issue is reproduced on other atmel boards that are supported in U-Boot.
Eugen, have you noticed the above limitation on a different board family that you maintain?
I have not seen this before, or don't remember about it.
Adding Mihai from Microchip team to see if we can get more info, whether this is a general gadget thing or it's specific to these chipsets. If it was reported to Microchip it would be interesting to see the response.
Eugen
Quoted 56 lines
If this issue is chip specific, I think we should test for compatible in
usba_udc_pullup()to only use USBA_ENABLE/USBA_DISABLE for this particular compatible (microchip,sam9x60-udc).Quoted 15 lines
Signed-off-by Zixun LI <[email protected]>---
drivers/usb/gadget/atmel_usba_udc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)diff --git
a/drivers/usb/gadget/atmel_usba_udc.cb/drivers/usb/gadget/atmel_usba_udc.cindexf9326f0a7e7d913bcf201ba3e4aeca9a099e7be7..a38e70957402fb3ade3de611d73e29b990d00703100644 ---a/drivers/usb/gadget/atmel_usba_udc.c
+++b/drivers/usb/gadget/atmel_usba_udc.c
@@ -521,16 +521,11 @@usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
static intusba_udc_pullup(struct usb_gadget *gadget, int is_on){ struct usba_udc *udc = to_usba_udc(gadget);Quoted 7 lines
- u32 ctrl;
-
- ctrl =usba_readl(udc, CTRL);if (is_on)- ctrl &= ~USBA_DETACH;
+usba_writel(udc, CTRL, USBA_ENABLE_MASK);Could we add a comment in the function as well? Something similar to what's in the commit message:
/* Some chips don't reliably drive DP/DM lines to high impedance when
* using the DETACH/PULLD_DIS bits.
* To ensure a reliable disconnect, power cycle the controller instead */Feel free to rephrase your preference.
Quoted 17 lines
else
- ctrl |=USBA_DETACH;
-
-usba_writel(udc, CTRL, ctrl);
+usba_writel(udc, CTRL, USBA_DISABLE_MASK);return 0; }---
base-commit:4d3b5c679bc9d5c6cbbeedcc1e4a186f1cc35541
change-id: 20250602-pullup-83c5540db5cdBest regards,
--
Zixun LI <[email protected]>
Quoted 19 lines · Zixun LI
Hi all,
The case has been reported with No.01589331.
In brief line high-impedance is not observed when both
PULLD_DIS& DETACH bits are 1:
- In unenumerated state (no cable attached) DP is still pulled up
- In enumerated state, disconnection is not detected by host [1] [2] only by [3].The test has been done in 3 ways on SAM9X60-Curiosity and AT91SAM9G25-EK boards:
- ModifyUDPHS_CTRLon u-boot-at91 with mw command
- ModifyUDPHS_CTRLon linux4sam-poky-sam9x60_curiosity-headless-2024.10 with devmem2 utils
- On linux-mchp 6.6, comment out gadget_udc_start/stop insoft_connect_store()ofdrivers/usb/gadget/udc/core.c,
leaving only gadget_connect/disconnect. Then run echo disconnect >/sys/class/udc/500000.gadget/soft_connect
Quoted 58 lines
Host used:
1. AMD Ryzen 5800H native port, Linux 6.14
2. Intel i7-8750H native port, Windows 10
3. Genesys GL3523 hub attached to [1]Zixun LI
Quoted 50 lines · Eugen Hristev
Quoted 31 lines · Mattijs Korpershoek
Hi Zixun,
Thank you for the patch.
On Mon, Jun 02, 2025 at 17:45, Zixun LI <[email protected]> wrote:
I'm surprised that checkpatch.pl does not catch this, but the subject (title) is too long (it should be less than 70 chars):
https://docs.u-boot.org/en/latest/develop/sending_patches.html#commit-message-conventionsQuoted 12 lines
Contrary to the datasheet, setting both DETACH and
PULLD_DISbits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
Disabling and re-enabling the controller entirely, instead of toggling the
PULLD_DISbit, reliably generates a disconnect event.Quoted 6 lines
The Linux driver works correctly because gadget_disconnect/gadget_connect are always followed by gadget_udc_start/gadget_udc_stop. In U-Boot
pullup()is used solely.This behavior has been observed on the SAM9X60-Curiosity and AT91SAM9G25-EK boards and has been reported to Microchip.
Quoted 8 lines
I'm not against this, but the driver supports multiple gadget families according to the compatible.
I'm wondering if this issue is reproduced on other atmel boards that are supported in U-Boot.
Eugen, have you noticed the above limitation on a different board family that you maintain?
I have not seen this before, or don't remember about it.
Adding Mihai from Microchip team to see if we can get more info, whether this is a general gadget thing or it's specific to these chipsets. If it was reported to Microchip it would be interesting to see the response.
Mihai, Zixun, do you have any update on case No.01589331 ?
I'd like to pick this up and some point so please keep me informed.
Thank you
Mattijs
Quoted 61 lines
Quoted 61 lines
Eugen
Quoted 56 lines
If this issue is chip specific, I think we should test for compatible in
usba_udc_pullup()to only use USBA_ENABLE/USBA_DISABLE for this particular compatible (microchip,sam9x60-udc).Quoted 15 lines
Signed-off-by Zixun LI <[email protected]>---
drivers/usb/gadget/atmel_usba_udc.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)diff --git
a/drivers/usb/gadget/atmel_usba_udc.cb/drivers/usb/gadget/atmel_usba_udc.cindexf9326f0a7e7d913bcf201ba3e4aeca9a099e7be7..a38e70957402fb3ade3de611d73e29b990d00703100644 ---a/drivers/usb/gadget/atmel_usba_udc.c
+++b/drivers/usb/gadget/atmel_usba_udc.c
@@ -521,16 +521,11 @@usba_udc_set_selfpowered(struct usb_gadget *gadget, int is_selfpowered)
static intusba_udc_pullup(struct usb_gadget *gadget, int is_on){ struct usba_udc *udc = to_usba_udc(gadget);Quoted 7 lines
- u32 ctrl;
-
- ctrl =usba_readl(udc, CTRL);if (is_on)- ctrl &= ~USBA_DETACH;
+usba_writel(udc, CTRL, USBA_ENABLE_MASK);Could we add a comment in the function as well? Something similar to what's in the commit message:
/* Some chips don't reliably drive DP/DM lines to high impedance when
* using the DETACH/PULLD_DIS bits.
* To ensure a reliable disconnect, power cycle the controller instead */Feel free to rephrase your preference.
Quoted 17 lines
else
- ctrl |=USBA_DETACH;
-
-usba_writel(udc, CTRL, ctrl);
+usba_writel(udc, CTRL, USBA_DISABLE_MASK);return 0; }---
base-commit:4d3b5c679bc9d5c6cbbeedcc1e4a186f1cc35541
change-id: 20250602-pullup-83c5540db5cdBest regards,
--
Zixun LI <[email protected]>
Quoted 9 lines · Mattijs Korpershoek
Mihai, Zixun, do you have any update on case No.01589331 ?
I'd like to pick this up and some point so please keep me informed.
Thank you
Mattijs
Hi Mattijs,
The case was reported in early May and MCHP have also observed the missing of detach event on host.
My latest measure shows a differential signal level about +-350mV between DP&DM lines when
DETACH and PULLD_DIS bits are 1, much lower than the detachment threshold of 625mV from
USB 2.0 specification Table 7.3.
From my view the patch can be picked, even on an unaffected family it won't have side effects.
Unless one day we decide to implement SAM9RL and SAM9G45 errata then it needs to be retested.
Best Regards,
Zixun
Quoted 23 lines · Zixun LI
Quoted 9 lines · Mattijs Korpershoek
Mihai, Zixun, do you have any update on case No.01589331 ?
I'd like to pick this up and some point so please keep me informed.
Thank you
MattijsHi Mattijs,
The case was reported in early May and MCHP have also observed the missing of detach event on host.
My latest measure shows a differential signal level about +-350mV between DP&DM lines when
DETACH andPULLD_DISbits are 1, much lower than the detachment threshold of 625mV from
USB 2.0 specification Table 7.3.
Quoted 4 lines
From my view the patch can be picked, even on an unaffected family it won't have side effects.
Unless one day we decide to implement SAM9RL and SAM9G45 errata then it needs to be retested.
Ok, I will apply it. Since it's a bit late in the release cycle, I'll send this out for -next.
Thanks again for your contribution!
Mattijs
Quoted 3 lines
Best Regards,
Zixun
Quoted 25 lines · Mattijs Korpershoek
Quoted 23 lines · Zixun LI
Quoted 9 lines · Mattijs Korpershoek
Mihai, Zixun, do you have any update on case No.01589331 ?
I'd like to pick this up and some point so please keep me informed.
Thank you
MattijsHi Mattijs,
The case was reported in early May and MCHP have also observed the missing of detach event on host.
My latest measure shows a differential signal level about +-350mV between DP&DM lines when
DETACH andPULLD_DISbits are 1, much lower than the detachment threshold of 625mV from
USB 2.0 specification Table 7.3.
Quoted 7 lines
Quoted 4 lines
From my view the patch can be picked, even on an unaffected family it won't have side effects.
Unless one day we decide to implement SAM9RL and SAM9G45 errata then it needs to be retested.Ok, I will apply it. Since it's a bit late in the release cycle, I'll send this out for -next.
Zixun, before applying the patch, I'd like to add the comment I suggested in the code [1] as well.
Do you you have any objections on that?
PLease let me know
[1] https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
Thanks again for your contribution!
Mattijs
Quoted 3 lines
Best Regards,
Zixun
Quoted 26 lines · Mattijs Korpershoek
Quoted 15 lines · Mattijs Korpershoek
Quoted 13 lines · Zixun LI
On Fri, Jun 13, 2025 at 11:22 AM Mattijs Korpershoek
Hi Mattijs,
The case was reported in early May and MCHP have also observed the missing of detach event on host.
My latest measure shows a differential signal level about +-350mV between DP&DM lines when
DETACH andPULLD_DISbits are 1, much lower than the detachment threshold of 625mV from
USB 2.0 specification Table 7.3.Quoted 7 lines
Quoted 4 lines
From my view the patch can be picked, even on an unaffected family it won't have side effects.
Unless one day we decide to implement SAM9RL and SAM9G45 errata then it needs to be retested.Ok, I will apply it. Since it's a bit late in the release cycle, I'll send this out for -next.
Quoted 16 lines
Zixun, before applying the patch, I'd like to add the comment I suggested in the code [1] as well.
Do you you have any objections on that?
PLease let me know[1] https://lore.kernel.org/all/[email protected]/
Quoted 8 lines
Thanks again for your contribution!
Mattijs
Quoted 3 lines
Best Regards,
Zixun
Hi Mattijs,
I agree to add the comment to make it more clear.
Best regards,
Zixun
Quoted 42 lines · Zixun LI
Quoted 40 lines · Mattijs Korpershoek
Quoted 15 lines · Mattijs Korpershoek
Quoted 13 lines · Zixun LI
On Fri, Jun 13, 2025 at 11:22 AM Mattijs Korpershoek
Hi Mattijs,
The case was reported in early May and MCHP have also observed the missing of detach event on host.
My latest measure shows a differential signal level about +-350mV between DP&DM lines when
DETACH andPULLD_DISbits are 1, much lower than the detachment threshold of 625mV from
USB 2.0 specification Table 7.3.Quoted 7 lines
Quoted 4 lines
From my view the patch can be picked, even on an unaffected family it won't have side effects.
Unless one day we decide to implement SAM9RL and SAM9G45 errata then it needs to be retested.Ok, I will apply it. Since it's a bit late in the release cycle, I'll send this out for -next.
Zixun, before applying the patch, I'd like to add the comment I suggested in the code [1] as well.
Do you you have any objections on that?
PLease let me know[1] https://lore.kernel.org/all/[email protected]/
Quoted 6 lines
Thanks again for your contribution!
Mattijs
Quoted 1 line
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Best Regards,
ZixunHi Mattijs,
I agree to add the comment to make it more clear.
Great, thanks, I'll apply and do the fixup.
Quoted 3 lines
Best regards,
Zixun
Hi,
Quoted 9 lines · Zixun LI
Contrary to the datasheet, setting both DETACH and
PULLD_DISbits to 1 does not always drive the DP and DM lines to high-impedance. This prevents the host from reliably detecting a USB disconnect and subsequent reconnect.The symptom is that the first gadget command (e.g., dhcp) succeeds, while subsequent commands (e.g., nfs) fail.
[...]
Thanks, Applied to https://source.denx.de/u-boot/custodians/u-boot-dfu (u-boot-dfu-next)
[1/1] usb: gadget: atmel: reliably generate disconnect by disabling controller instead of toggling PULLD_DIS
https://source.denx.de/u-boot/custodians/u-boot-dfu/-/commit/ca036308a513759e3e4cbe9f8191861c3232c611
--
Mattijs