Lines Matching full:udc

3  * udc.c - Core UDC Framework
9 #define pr_fmt(fmt) "UDC core: " fmt
36 * @list: for use by the udc class driver
39 * @started: the UDC's started state. True if the UDC had started.
40 * @allow_connect: Indicates whether UDC is allowed to be pulled up.
44 * @connect_lock: protects udc->started, gadget->connect,
50 * This represents the internal data structure which is used by the UDC-class
51 * to hold information about udc driver and gadget together.
68 /* Protects udc_list, udc->driver, driver->is_bound, and related calls */
78 * This function should be used only in UDC drivers to initialize endpoint
120 /* UDC drivers can't handle endpoints with maxpacket size 0 */ in usb_ep_enable()
284 * UDC are finished with the request. When the completion function is called,
703 __must_hold(&gadget->udc->connect_lock) in usb_gadget_connect_locked()
712 if (gadget->deactivated || !gadget->udc->allow_connect || !gadget->udc->started) { in usb_gadget_connect_locked()
747 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_connect()
749 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_connect()
756 __must_hold(&gadget->udc->connect_lock) in usb_gadget_disconnect_locked()
768 if (gadget->deactivated || !gadget->udc->started) { in usb_gadget_disconnect_locked()
782 if (gadget->udc->driver) in usb_gadget_disconnect_locked()
783 gadget->udc->driver->disconnect(gadget); in usb_gadget_disconnect_locked()
801 * for the current gadget driver so that UDC drivers don't need to.
809 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_disconnect()
811 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_disconnect()
835 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_deactivate()
853 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_deactivate()
875 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_activate()
889 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_activate()
1094 * usb_gadget_check_config - checks if the UDC can support the binded
1098 * Ensure that a UDC is able to support the requested resources by a
1117 struct usb_udc *udc = gadget->udc; in usb_gadget_state_work() local
1119 if (udc) in usb_gadget_state_work()
1120 sysfs_notify(&udc->dev.kobj, NULL, "state"); in usb_gadget_state_work()
1134 static int usb_udc_connect_control_locked(struct usb_udc *udc) __must_hold(&udc->connect_lock) in usb_udc_connect_control_locked() argument
1136 if (udc->vbus) in usb_udc_connect_control_locked()
1137 return usb_gadget_connect_locked(udc->gadget); in usb_udc_connect_control_locked()
1139 return usb_gadget_disconnect_locked(udc->gadget); in usb_udc_connect_control_locked()
1144 struct usb_udc *udc = container_of(work, struct usb_udc, vbus_work); in vbus_event_work() local
1146 mutex_lock(&udc->connect_lock); in vbus_event_work()
1147 usb_udc_connect_control_locked(udc); in vbus_event_work()
1148 mutex_unlock(&udc->connect_lock); in vbus_event_work()
1152 * usb_udc_vbus_handler - updates the udc core vbus status, and try to
1157 * The udc driver calls it when it wants to connect or disconnect gadget
1170 struct usb_udc *udc = gadget->udc; in usb_udc_vbus_handler() local
1172 if (udc) { in usb_udc_vbus_handler()
1173 udc->vbus = status; in usb_udc_vbus_handler()
1174 schedule_work(&udc->vbus_work); in usb_udc_vbus_handler()
1180 * usb_gadget_udc_reset - notifies the udc core that bus reset occurs
1184 * If the udc driver has bus reset handler, it needs to call this when the bus
1198 * @udc: The UDC to be started
1200 * This call is issued by the UDC Class driver when it's about
1211 static inline int usb_gadget_udc_start_locked(struct usb_udc *udc) in usb_gadget_udc_start_locked() argument
1212 __must_hold(&udc->connect_lock) in usb_gadget_udc_start_locked()
1216 if (udc->started) { in usb_gadget_udc_start_locked()
1217 dev_err(&udc->dev, "UDC had already started\n"); in usb_gadget_udc_start_locked()
1221 ret = udc->gadget->ops->udc_start(udc->gadget, udc->driver); in usb_gadget_udc_start_locked()
1223 udc->started = true; in usb_gadget_udc_start_locked()
1230 * @udc: The UDC to be stopped
1232 * This call is issued by the UDC Class driver after calling
1236 * far as powering off UDC completely and disable its data
1241 static inline void usb_gadget_udc_stop_locked(struct usb_udc *udc) in usb_gadget_udc_stop_locked() argument
1242 __must_hold(&udc->connect_lock) in usb_gadget_udc_stop_locked()
1244 if (!udc->started) { in usb_gadget_udc_stop_locked()
1245 dev_err(&udc->dev, "UDC had already stopped\n"); in usb_gadget_udc_stop_locked()
1249 udc->gadget->ops->udc_stop(udc->gadget); in usb_gadget_udc_stop_locked()
1250 udc->started = false; in usb_gadget_udc_stop_locked()
1256 * @udc: The device we want to set maximum speed
1259 * This call is issued by the UDC Class driver before calling
1263 static inline void usb_gadget_udc_set_speed(struct usb_udc *udc, in usb_gadget_udc_set_speed() argument
1266 struct usb_gadget *gadget = udc->gadget; in usb_gadget_udc_set_speed()
1282 * @udc: The UDC which should enable async callbacks
1285 * of usb_gadget_disable_async_callbacks(); the UDC driver should enable IRQs
1290 static inline void usb_gadget_enable_async_callbacks(struct usb_udc *udc) in usb_gadget_enable_async_callbacks() argument
1292 struct usb_gadget *gadget = udc->gadget; in usb_gadget_enable_async_callbacks()
1300 * @udc: The UDC which should disable async callbacks
1303 * The UDC driver doesn't know when the gadget driver's ->unbind callback
1307 * After this function runs, the UDC driver must suppress all ->suspend,
1310 * way to accomplish this is to tell the UDC hardware not to generate any
1319 static inline void usb_gadget_disable_async_callbacks(struct usb_udc *udc) in usb_gadget_disable_async_callbacks() argument
1321 struct usb_gadget *gadget = udc->gadget; in usb_gadget_disable_async_callbacks()
1336 struct usb_udc *udc; in usb_udc_release() local
1338 udc = container_of(dev, struct usb_udc, dev); in usb_udc_release()
1340 kfree(udc); in usb_udc_release()
1352 * @parent: the parent device to this udc. Usually the controller driver's
1374 * usb_add_gadget - adds a new gadget to the udc class driver list
1382 struct usb_udc *udc; in usb_add_gadget() local
1385 udc = kzalloc(sizeof(*udc), GFP_KERNEL); in usb_add_gadget()
1386 if (!udc) in usb_add_gadget()
1389 device_initialize(&udc->dev); in usb_add_gadget()
1390 udc->dev.release = usb_udc_release; in usb_add_gadget()
1391 udc->dev.class = &udc_class; in usb_add_gadget()
1392 udc->dev.groups = usb_udc_attr_groups; in usb_add_gadget()
1393 udc->dev.parent = gadget->dev.parent; in usb_add_gadget()
1394 ret = dev_set_name(&udc->dev, "%s", in usb_add_gadget()
1399 udc->gadget = gadget; in usb_add_gadget()
1400 gadget->udc = udc; in usb_add_gadget()
1401 mutex_init(&udc->connect_lock); in usb_add_gadget()
1403 udc->started = false; in usb_add_gadget()
1406 list_add_tail(&udc->list, &udc_list); in usb_add_gadget()
1408 INIT_WORK(&udc->vbus_work, vbus_event_work); in usb_add_gadget()
1410 ret = device_add(&udc->dev); in usb_add_gadget()
1415 udc->vbus = true; in usb_add_gadget()
1427 ret = sysfs_create_link(&udc->dev.kobj, in usb_add_gadget()
1442 device_del(&udc->dev); in usb_add_gadget()
1446 list_del(&udc->list); in usb_add_gadget()
1450 put_device(&udc->dev); in usb_add_gadget()
1458 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
1459 * @parent: the parent device to this udc. Usually the controller driver's
1481 * usb_get_gadget_udc_name - get the name of the first UDC controller
1482 * This functions returns the name of the first UDC controller in the system.
1484 * assume that there is only one UDC controller in the system and they need to
1485 * get its name before initialization. There is no guarantee that the UDC
1489 * Returns pointer to string with UDC controller name on success, NULL
1494 struct usb_udc *udc; in usb_get_gadget_udc_name() local
1497 /* For now we take the first available UDC */ in usb_get_gadget_udc_name()
1499 list_for_each_entry(udc, &udc_list, list) { in usb_get_gadget_udc_name()
1500 if (!udc->driver) { in usb_get_gadget_udc_name()
1501 name = kstrdup(udc->gadget->name, GFP_KERNEL); in usb_get_gadget_udc_name()
1511 * usb_add_gadget_udc - adds a new gadget to the udc class driver list
1512 * @parent: the parent device to this udc. Usually the controller
1525 * usb_del_gadget - deletes a gadget and unregisters its udc
1533 struct usb_udc *udc = gadget->udc; in usb_del_gadget() local
1535 if (!udc) in usb_del_gadget()
1541 list_del(&udc->list); in usb_del_gadget()
1544 kobject_uevent(&udc->dev.kobj, KOBJ_REMOVE); in usb_del_gadget()
1545 sysfs_remove_link(&udc->dev.kobj, "gadget"); in usb_del_gadget()
1549 cancel_work_sync(&udc->vbus_work); in usb_del_gadget()
1550 device_unregister(&udc->dev); in usb_del_gadget()
1572 struct usb_udc *udc = gadget->udc; in gadget_match_driver() local
1576 /* If the driver specifies a udc_name, it must match the UDC's name */ in gadget_match_driver()
1578 strcmp(driver->udc_name, dev_name(&udc->dev)) != 0) in gadget_match_driver()
1585 /* Otherwise any gadget driver matches any UDC */ in gadget_match_driver()
1592 struct usb_udc *udc = gadget->udc; in gadget_bind_driver() local
1603 udc->driver = driver; in gadget_bind_driver()
1606 dev_dbg(&udc->dev, "binding gadget driver [%s]\n", driver->function); in gadget_bind_driver()
1608 usb_gadget_udc_set_speed(udc, driver->max_speed); in gadget_bind_driver()
1610 ret = driver->bind(udc->gadget, driver); in gadget_bind_driver()
1614 mutex_lock(&udc->connect_lock); in gadget_bind_driver()
1615 ret = usb_gadget_udc_start_locked(udc); in gadget_bind_driver()
1617 mutex_unlock(&udc->connect_lock); in gadget_bind_driver()
1620 usb_gadget_enable_async_callbacks(udc); in gadget_bind_driver()
1621 udc->allow_connect = true; in gadget_bind_driver()
1622 ret = usb_udc_connect_control_locked(udc); in gadget_bind_driver()
1626 mutex_unlock(&udc->connect_lock); in gadget_bind_driver()
1628 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); in gadget_bind_driver()
1632 udc->allow_connect = false; in gadget_bind_driver()
1633 usb_gadget_disable_async_callbacks(udc); in gadget_bind_driver()
1636 usb_gadget_udc_stop_locked(udc); in gadget_bind_driver()
1637 mutex_unlock(&udc->connect_lock); in gadget_bind_driver()
1640 driver->unbind(udc->gadget); in gadget_bind_driver()
1644 dev_err(&udc->dev, "failed to start %s: %d\n", in gadget_bind_driver()
1648 udc->driver = NULL; in gadget_bind_driver()
1658 struct usb_udc *udc = gadget->udc; in gadget_unbind_driver() local
1659 struct usb_gadget_driver *driver = udc->driver; in gadget_unbind_driver()
1661 dev_dbg(&udc->dev, "unbinding gadget driver [%s]\n", driver->function); in gadget_unbind_driver()
1663 udc->allow_connect = false; in gadget_unbind_driver()
1664 cancel_work_sync(&udc->vbus_work); in gadget_unbind_driver()
1665 mutex_lock(&udc->connect_lock); in gadget_unbind_driver()
1667 usb_gadget_disable_async_callbacks(udc); in gadget_unbind_driver()
1670 mutex_unlock(&udc->connect_lock); in gadget_unbind_driver()
1672 udc->driver->unbind(gadget); in gadget_unbind_driver()
1674 mutex_lock(&udc->connect_lock); in gadget_unbind_driver()
1675 usb_gadget_udc_stop_locked(udc); in gadget_unbind_driver()
1676 mutex_unlock(&udc->connect_lock); in gadget_unbind_driver()
1680 udc->driver = NULL; in gadget_unbind_driver()
1683 kobject_uevent(&udc->dev.kobj, KOBJ_CHANGE); in gadget_unbind_driver()
1710 pr_warn("%s: couldn't find an available UDC or it's busy\n", in usb_gadget_register_driver_owner()
1714 pr_info("%s: couldn't find an available UDC\n", in usb_gadget_register_driver_owner()
1742 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); in srp_store() local
1745 usb_gadget_wakeup(udc->gadget); in srp_store()
1754 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); in soft_connect_store() local
1757 device_lock(&udc->gadget->dev); in soft_connect_store()
1758 if (!udc->driver) { in soft_connect_store()
1765 mutex_lock(&udc->connect_lock); in soft_connect_store()
1766 usb_gadget_udc_start_locked(udc); in soft_connect_store()
1767 usb_gadget_connect_locked(udc->gadget); in soft_connect_store()
1768 mutex_unlock(&udc->connect_lock); in soft_connect_store()
1770 mutex_lock(&udc->connect_lock); in soft_connect_store()
1771 usb_gadget_disconnect_locked(udc->gadget); in soft_connect_store()
1772 usb_gadget_udc_stop_locked(udc); in soft_connect_store()
1773 mutex_unlock(&udc->connect_lock); in soft_connect_store()
1782 device_unlock(&udc->gadget->dev); in soft_connect_store()
1790 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); in state_show() local
1791 struct usb_gadget *gadget = udc->gadget; in state_show()
1800 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); in function_show() local
1805 drv = udc->driver; in function_show()
1817 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
1819 usb_speed_string(udc->gadget->param)); \
1830 struct usb_udc *udc = container_of(dev, struct usb_udc, dev); \
1831 struct usb_gadget *gadget = udc->gadget; \
1872 const struct usb_udc *udc = container_of(dev, struct usb_udc, dev); in usb_udc_uevent() local
1875 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); in usb_udc_uevent()
1882 if (udc->driver) in usb_udc_uevent()
1884 udc->driver->function); in usb_udc_uevent()
1895 .name = "udc",
1928 MODULE_DESCRIPTION("UDC Framework");