Changes for v2: - Felipe's comments: " For example we don't want automatic binding, basically we might want to have g_mass_storage running on both ports and this series would prevent it." Currently, it is impossible to let g_mass_storage or other g_xxx gadgets run at both ports due to g_xxx gadget implementation can't re-enter, eg, the struct usb_configuration is global variable, it will be the same for two instances (udcs), the only possible way to run the same function at both udcs is to use gadget_configfs, the same function at different configuration will be treated differently. If we use gadget_configfs to let the same function running at two udcs, we can disable gadget_bus's drivers_autoprobe entry to disable auto-binding before gadget_configfs working. - Andrzej's test that the gadget_configfs can't work well. I made some changes for gadget_configfs to let it use standard device-model bind/unbind to enable/disable udc, see patch[5/7] and patch[7/7] for detail. Since we introduce the gadget bus, we had to use standard device model way to handle device driver register for gadget_configfs. I mark patch[5/7] as RFC, since I still have no good idea for device driver's name for gadget_configfs, the struct usb_gadget_driver is different for each udc, so it has to use different device driver to manage it. Andrzej, would you have some suggestion for this RFC? gadget-configfs works well for v2. ------------------------------------------------------------------------------------ Hi Felipe & Alan, To continue with topic discussed at http://www.spinics.net/lists/linux-usb/msg105279.html, I implement the gadget bus to bind udc to gadget driver follow most ideas from your two. Now this problem is really annoying, many gadget build-in platforms (Eg, Android) will fail to enable usb peripheral function due to udc is probe deferral, I hope we can fix this problem asap. The current "udc class" design can't cover auto-bind/manual bind by device model, so the first patch changes "udc class" to "gadget bus". The second patch adds the implementation of gadget bus, and the udc will bind to gadget driver automatically when they are matched. The rule of auto-binding is: if the udc is not in use and the gadget driver is not used by any udcs, it is matched successfully, and will be binded. Each gadget driver can only be binded at one udc. For example, there are two udcs, "udc-0" and "udc-1", and two gadget drivers, "g_mass_storage" and "g_serial", assumed the udcs is added to bus first, then, the "udc-0" will be binded to "g_mass_storage", and "udc-1" will be binded to "g_seiral". The third patch adds one "tricky" solution for manual bind if both udc and gadget driver are built in. The fourth patch delete the __init marker from all gadget driver's bind function, since the bind may not be executed after gadget driver has loaded due to udc is not ready. Below tests are done: One gadget driver build in and two udcs, udc devices are created first One gadget driver build in and two udcs, gadget driver is created first Two gadget driver build as modules and two udcs build in Two gadget driver build as modules and the udc driver build as module, and no matter which is loaded first. Manual binding/unbinding with different udcs: - Both udc and gadget driver are build in, udc-core.manual_binding=1 echo 0 > /sys/module/udc_core/parameters/manual_binding echo udc-0 > /sys/bus/usb_gadget/drivers/g_serial/bind echo udc-0 > /sys/bus/usb_gadget/drivers/g_serial/unbind echo udc-1 > /sys/bus/usb_gadget/drivers/g_serial/bind echo udc-1 > /sys/bus/usb_gadget/drivers/g_serial/unbind echo udc-0 > /sys/bus/usb_gadget/drivers/g_serial/bind - After auto-bind, unbind current udc and do manual bind echo udc-0 > /sys/bus/usb_gadget/drivers/g_serial/unbind echo udc-1 > /sys/bus/usb_gadget/drivers/g_serial/bind The problem still exists: Some drivers (like mass_storage) call usb_gadget_unregister_driver during their .unbind, it causes device core dead lock at below call chain if udc is unloaded first: device_del->device_lock(dev)->device_release_driver->usb_gadget_remove_driver ->.unbind->usb_gadget_unregister_driver->driver_detach->device_lock(dev) Peter Chen (7): usb: gadget: core: change udc class to gadget bus usb: gadget: core: add implementation of gadget bus usb: gadget: core: add manual binding usb: gadget: remove __init from gadget driver bind function usb: gadget: configfs: changes for gadget bus introducing usb: gadget: core: delete udc_attach_driver API doc: usb: gadget_configfs: change for gadget bus introducing Documentation/usb/gadget_configfs.txt | 13 +- drivers/usb/gadget/acm_ms.c | 4 +- drivers/usb/gadget/audio.c | 4 +- drivers/usb/gadget/cdc2.c | 4 +- drivers/usb/gadget/configfs.c | 115 ++++++++-------- drivers/usb/gadget/dbgp.c | 4 +- drivers/usb/gadget/ether.c | 6 +- drivers/usb/gadget/f_hid.c | 6 +- drivers/usb/gadget/f_midi.c | 12 +- drivers/usb/gadget/f_uac1.c | 12 +- drivers/usb/gadget/f_uac2.c | 2 +- drivers/usb/gadget/f_uvc.c | 28 ++-- drivers/usb/gadget/gmidi.c | 4 +- drivers/usb/gadget/hid.c | 6 +- drivers/usb/gadget/mass_storage.c | 4 +- drivers/usb/gadget/multi.c | 4 +- drivers/usb/gadget/ncm.c | 4 +- drivers/usb/gadget/nokia.c | 4 +- drivers/usb/gadget/printer.c | 6 +- drivers/usb/gadget/serial.c | 2 +- drivers/usb/gadget/u_uac1.c | 2 +- drivers/usb/gadget/udc-core.c | 239 +++++++++++++++++++-------------- drivers/usb/gadget/webcam.c | 4 +- drivers/usb/gadget/zero.c | 2 +- include/linux/usb/gadget.h | 2 - 25 files changed, 263 insertions(+), 230 deletions(-) -- 1.7.8 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html