Commit f07bd56b authored by Felipe Balbi's avatar Felipe Balbi

usb: gadget: udc-core: allow udc class register gadget device

Currently all UDC drivers are calling
device_register() before calling
usb_add_gadget_udc(). In order to avoid
code duplication, we can allow udc-core.c
register that device.

However that would become a really large patch,
so to cope with the meanwhile and allow us
to write bite-sized patches, we're adding
a flag which will be set by UDC driver once
it removes the code for registering the
gadget device.

Once all are converted, the new flag will
be removed.
Reviewed-by: default avatarTomasz Figa <tomasz.figa@gmail.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 7eaf8f2a
...@@ -173,6 +173,14 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) ...@@ -173,6 +173,14 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
if (!udc) if (!udc)
goto err1; goto err1;
if (gadget->register_my_device) {
dev_set_name(&gadget->dev, "gadget");
ret = device_register(&gadget->dev);
if (ret)
goto err2;
}
device_initialize(&udc->dev); device_initialize(&udc->dev);
udc->dev.release = usb_udc_release; udc->dev.release = usb_udc_release;
udc->dev.class = udc_class; udc->dev.class = udc_class;
...@@ -180,7 +188,7 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) ...@@ -180,7 +188,7 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
udc->dev.parent = parent; udc->dev.parent = parent;
ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj)); ret = dev_set_name(&udc->dev, "%s", kobject_name(&parent->kobj));
if (ret) if (ret)
goto err2; goto err3;
udc->gadget = gadget; udc->gadget = gadget;
...@@ -189,18 +197,22 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) ...@@ -189,18 +197,22 @@ int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget)
ret = device_add(&udc->dev); ret = device_add(&udc->dev);
if (ret) if (ret)
goto err3; goto err4;
mutex_unlock(&udc_lock); mutex_unlock(&udc_lock);
return 0; return 0;
err3:
err4:
list_del(&udc->list); list_del(&udc->list);
mutex_unlock(&udc_lock); mutex_unlock(&udc_lock);
err2: err3:
put_device(&udc->dev); put_device(&udc->dev);
err2:
if (gadget->register_my_device)
put_device(&gadget->dev);
err1: err1:
return ret; return ret;
} }
...@@ -254,6 +266,9 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) ...@@ -254,6 +266,9 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)
kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE);
device_unregister(&udc->dev); device_unregister(&udc->dev);
if (gadget->register_my_device)
device_unregister(&gadget->dev);
} }
EXPORT_SYMBOL_GPL(usb_del_gadget_udc); EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
......
...@@ -494,6 +494,9 @@ struct usb_gadget_ops { ...@@ -494,6 +494,9 @@ struct usb_gadget_ops {
* only supports HNP on a different root port. * only supports HNP on a different root port.
* @b_hnp_enable: OTG device feature flag, indicating that the A-Host * @b_hnp_enable: OTG device feature flag, indicating that the A-Host
* enabled HNP support. * enabled HNP support.
* @register_my_device: Flag telling udc-core that UDC driver didn't
* register the gadget device to the driver model. Temporary until
* all UDC drivers are fixed up properly.
* @name: Identifies the controller hardware type. Used in diagnostics * @name: Identifies the controller hardware type. Used in diagnostics
* and sometimes configuration. * and sometimes configuration.
* @dev: Driver model state for this abstract device. * @dev: Driver model state for this abstract device.
...@@ -531,6 +534,7 @@ struct usb_gadget { ...@@ -531,6 +534,7 @@ struct usb_gadget {
unsigned b_hnp_enable:1; unsigned b_hnp_enable:1;
unsigned a_hnp_support:1; unsigned a_hnp_support:1;
unsigned a_alt_hnp_support:1; unsigned a_alt_hnp_support:1;
unsigned register_my_device:1;
const char *name; const char *name;
struct device dev; struct device dev;
unsigned out_epnum; unsigned out_epnum;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment