cmd: bind/unbind by class index doesn't work with usb gadget

Bind/unbind a gadget function driver to a USB gadget device doesn't work with class index, while using node path is ok. For example:
U-Boot> dm tree
Class Index Probed Driver Name ----------------------------------------------------------- root 0 [ + ] root_driver root_driver simple_bus 0 [ + ] simple_bus |-- ahb simple_bus 1 [ + ] simple_bus | |-- apb ... usb 0 [ ] atmel_usba_udc | | |-- gadget@f803c000
U-Boot> bind usb 0 usb_ether Cannot find device 0 of class usb
Both USB host uclass and USB gadget uclass are using the same name "usb" while they are under different class id of UCLASS_USB and UCLASS_USB_GADGET_GENERIC.
bind_by_class_index() of cmd/bind.c uses uclass_get_by_name() to find class id, since both class have the same name it will get the id of UCLASS_USB instead since it is at the front of the uclass id list.
Then uclass_find_device() will try to find the wrong device and fail.
But fixing this issue simply by renaming gadget uclass name will break the DT alias feature DM_UC_FLAG_SEQ_ALIAS.
Any idea how to fix it ? Like adding a name_seq_alias field to uclass_driver structure ?

Hi Zixun,
On Fri, 26 Jul 2024 at 07:24, Zixun LI admin@hifiphile.com wrote:
Bind/unbind a gadget function driver to a USB gadget device doesn't work with class index, while using node path is ok. For example:
U-Boot> dm tree
Class Index Probed Driver Name
root 0 [ + ] root_driver root_driver simple_bus 0 [ + ] simple_bus |-- ahb simple_bus 1 [ + ] simple_bus | |-- apb ... usb 0 [ ] atmel_usba_udc | | |-- gadget@f803c000
U-Boot> bind usb 0 usb_ether Cannot find device 0 of class usb
Both USB host uclass and USB gadget uclass are using the same name "usb" while they are under different class id of UCLASS_USB and UCLASS_USB_GADGET_GENERIC.
bind_by_class_index() of cmd/bind.c uses uclass_get_by_name() to find class id, since both class have the same name it will get the id of UCLASS_USB instead since it is at the front of the uclass id list.
Then uclass_find_device() will try to find the wrong device and fail.
But fixing this issue simply by renaming gadget uclass name will break the DT alias feature DM_UC_FLAG_SEQ_ALIAS.
Any idea how to fix it ? Like adding a name_seq_alias field to uclass_driver structure ?
It looks like test/py/tests/test_bind.py does not cover this case.
We don't have a check for duplicate uclass names but probably should. Also sandbox builds USB gadget support but I don't think it is used. If it were we could add a test for this case.
I think the UDC uclass should be renamed to "usb_gadget". That may end up requiring changes elsewhere, but I'm not sure.
There are also weird things like omap2430_musb having two different uclass IDs!
Regards, SImon
participants (2)
-
Simon Glass
-
Zixun LI