[PATCH v2 3/7] usb: gadget: core: add manual binding

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

 



The user can bind any unused udc to specific gadget driver if there is
no udc has already been binded to that gadget driver.
For example:
cd /sys/bus/usb_gadget/drivers
echo udc-0 > g_serial
echo udc-1 > g_mass_storage

There are three solutions to do manual binding:

1. If the udc driver or gadget driver can be built as modules

- echo 0 > /sys/bus/usb_gadget/drivers_autoprobe
- load udc or gadget driver
- Do manual binding

2. If both udc driver and gadget are build in

- Add "udc-core.manual_binding=1" to your bootargs
- After rootfs has been mounted, clear the value of manual_binding
using below command:
echo 0 > /sys/module/udc_core/parameters/manual_binding
- Do manual binding

3. Unbind all current bindings first, then rebind the udc to driver
cd /sys/bus/usb_gadget/drivers
echo udc-0 > g_serial/unbind
echo udc-1 > g_mass_storage/unbind
echo udc-1 > g_serial/unbind
echo udc-0 > g_mass_storage/unbind

Signed-off-by: Peter Chen <peter.chen@xxxxxxxxxxxxx>
---
 drivers/usb/gadget/udc-core.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index e2d26c6..00a04e9 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -47,6 +47,21 @@ static struct bus_type gadget_bus_type;
 static DEFINE_MUTEX(udc_lock);
 static DEFINE_IDA(udc_ida);
 
+/*
+ * We can bind any unused udc to specfic driver after setting manual_binding
+ * eg:
+ * echo udc-0 > /sys/bus/usb_gadget/drivers/g_serial
+ * echo udc-1 > /sys/bus/usb_gadget/drivers/g_mass_storage
+ *
+ * How to use manual_binding:
+ * First, set manual_binding = 1 before drivers and devices are added to bus
+ * Second, set manual_binding = 0
+ * Third, do manual_binding like above
+ */
+static bool manual_binding;
+module_param(manual_binding, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(manual_binding, "binding udc and gadget driver manully");
+
 /* ------------------------------------------------------------------------- */
 
 #ifdef	CONFIG_HAS_DMA
@@ -584,6 +599,9 @@ static int usb_gadget_match(struct device *dev, struct device_driver *drv)
 		container_of(drv, struct usb_gadget_driver, driver);
 	bool dev_not_in_use = true, driver_not_in_use = true;
 
+	if (manual_binding)
+		return 0;
+
 	dev_dbg(dev, "%s: driver: %s\n", __func__, drv->name);
 
 	udc = container_of(dev, struct usb_udc, dev);
-- 
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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux