Current renesas_usbhs supported 1 channel. This patch support multi-channels. Cc: Magnus <magnus.damm@xxxxxxxxx> Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@xxxxxxxxxxx> --- v2 -> v3 - linked list version drivers/usb/renesas_usbhs/mod_gadget.c | 54 +++++++++++++++++++++++-------- 1 files changed, 40 insertions(+), 14 deletions(-) diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c b/drivers/usb/renesas_usbhs/mod_gadget.c index aa591b6..c6975ad 100644 --- a/drivers/usb/renesas_usbhs/mod_gadget.c +++ b/drivers/usb/renesas_usbhs/mod_gadget.c @@ -44,6 +44,7 @@ struct usbhsg_uep { struct usbhsg_gpriv { struct usb_gadget gadget; struct usbhs_mod mod; + struct list_head link; struct usbhsg_uep *uep; int uep_size; @@ -113,6 +114,16 @@ struct usbhsg_recip_handle { #define usbhsg_status_clr(gp, b) (gp->status &= ~b) #define usbhsg_status_has(gp, b) (gp->status & b) +/* controller */ +LIST_HEAD(the_controller_link); + +#define usbhsg_for_each_controller(gpriv)\ + list_for_each_entry(gpriv, &the_controller_link, link) +#define usbhsg_controller_register(gpriv)\ + list_add_tail(&(gpriv)->link, &the_controller_link) +#define usbhsg_controller_unregister(gpriv)\ + list_del_init(&(gpriv)->link) + /* * list push/pop */ @@ -724,11 +735,10 @@ static int usbhsg_try_stop(struct usbhs_priv *priv, u32 status) * linux usb function * */ -struct usbhsg_gpriv *the_controller; int usb_gadget_probe_driver(struct usb_gadget_driver *driver, int (*bind)(struct usb_gadget *)) { - struct usbhsg_gpriv *gpriv = the_controller; + struct usbhsg_gpriv *gpriv; struct usbhs_priv *priv; struct device *dev; int ret; @@ -738,10 +748,17 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver, !driver->setup || driver->speed != USB_SPEED_HIGH) return -EINVAL; - if (!gpriv) - return -ENODEV; - if (gpriv->driver) - return -EBUSY; + + /* + * find unused controller + */ + usbhsg_for_each_controller(gpriv) { + if (!gpriv->driver) + goto find_unused_controller; + } + return -ENODEV; + +find_unused_controller: dev = usbhsg_gpriv_to_dev(gpriv); priv = usbhsg_gpriv_to_priv(gpriv); @@ -779,18 +796,25 @@ EXPORT_SYMBOL(usb_gadget_probe_driver); int usb_gadget_unregister_driver(struct usb_gadget_driver *driver) { - struct usbhsg_gpriv *gpriv = the_controller; + struct usbhsg_gpriv *gpriv; struct usbhs_priv *priv; - struct device *dev = usbhsg_gpriv_to_dev(gpriv); - - if (!gpriv) - return -ENODEV; + struct device *dev; if (!driver || - !driver->unbind || - driver != gpriv->driver) + !driver->unbind) return -EINVAL; + /* + * find controller + */ + usbhsg_for_each_controller(gpriv) { + if (gpriv->driver == driver) + goto find_muching_controller; + } + return -ENODEV; + +find_muching_controller: + dev = usbhsg_gpriv_to_dev(gpriv); priv = usbhsg_gpriv_to_priv(gpriv); @@ -909,7 +933,7 @@ int __devinit usbhs_mod_gadget_probe(struct usbhs_priv *priv) } } - the_controller = gpriv; + usbhsg_controller_register(gpriv); dev_info(dev, "gadget probed\n"); @@ -925,6 +949,8 @@ void __devexit usbhs_mod_gadget_remove(struct usbhs_priv *priv) { struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv); + usbhsg_controller_unregister(gpriv); + kfree(gpriv->uep); kfree(gpriv); } -- 1.7.4.1 -- 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