Lines Matching full:gadget

22 #include <linux/usb/gadget.h>
33 * @driver: the gadget driver pointer. For use by the class code
35 * @gadget: the gadget. For use by the class code
41 * Set/cleared by gadget_(un)bind_driver() after gadget driver is bound or
44 * @connect_lock: protects udc->started, gadget->connect,
45 * gadget->allow_connect and gadget->deactivate. The routines
51 * to hold information about udc driver and gadget together.
55 struct usb_gadget *gadget; member
149 * gadget drivers must call usb_ep_enable() again before queueing
232 * request queued; they complete in FIFO order. Once a gadget driver
270 * arranges to poll once per interval, and the gadget driver usually will
283 * @req->complete() will be called exactly once, when the Gadget core and
294 pr_debug("USB gadget: queue request to disabled ep 0x%x (%s)\n", in usb_ep_queue()
348 * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the
402 * requests. If the gadget driver clears the halt status, it will
430 * the IN data written by the gadget driver (and reported by a request
431 * completion). The gadget driver may not have collected all the data
480 * @gadget: controller that reports the frame number
485 int usb_gadget_frame_number(struct usb_gadget *gadget) in usb_gadget_frame_number() argument
489 ret = gadget->ops->get_frame(gadget); in usb_gadget_frame_number()
491 trace_usb_gadget_frame_number(gadget, ret); in usb_gadget_frame_number()
498 * usb_gadget_wakeup - tries to wake up the host connected to this gadget
499 * @gadget: controller used to wake up the host
510 int usb_gadget_wakeup(struct usb_gadget *gadget) in usb_gadget_wakeup() argument
514 if (!gadget->ops->wakeup) { in usb_gadget_wakeup()
519 ret = gadget->ops->wakeup(gadget); in usb_gadget_wakeup()
522 trace_usb_gadget_wakeup(gadget, ret); in usb_gadget_wakeup()
530 * @gadget:the device being configured for remote wakeup
537 int usb_gadget_set_remote_wakeup(struct usb_gadget *gadget, int set) in usb_gadget_set_remote_wakeup() argument
541 if (!gadget->ops->set_remote_wakeup) { in usb_gadget_set_remote_wakeup()
546 ret = gadget->ops->set_remote_wakeup(gadget, set); in usb_gadget_set_remote_wakeup()
549 trace_usb_gadget_set_remote_wakeup(gadget, ret); in usb_gadget_set_remote_wakeup()
557 * @gadget:the device being declared as self-powered
564 int usb_gadget_set_selfpowered(struct usb_gadget *gadget) in usb_gadget_set_selfpowered() argument
568 if (!gadget->ops->set_selfpowered) { in usb_gadget_set_selfpowered()
573 ret = gadget->ops->set_selfpowered(gadget, 1); in usb_gadget_set_selfpowered()
576 trace_usb_gadget_set_selfpowered(gadget, ret); in usb_gadget_set_selfpowered()
584 * @gadget:the device being declared as bus-powered
592 int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) in usb_gadget_clear_selfpowered() argument
596 if (!gadget->ops->set_selfpowered) { in usb_gadget_clear_selfpowered()
601 ret = gadget->ops->set_selfpowered(gadget, 0); in usb_gadget_clear_selfpowered()
604 trace_usb_gadget_clear_selfpowered(gadget, ret); in usb_gadget_clear_selfpowered()
612 * @gadget:The device which now has VBUS power.
623 int usb_gadget_vbus_connect(struct usb_gadget *gadget) in usb_gadget_vbus_connect() argument
627 if (!gadget->ops->vbus_session) { in usb_gadget_vbus_connect()
632 ret = gadget->ops->vbus_session(gadget, 1); in usb_gadget_vbus_connect()
635 trace_usb_gadget_vbus_connect(gadget, ret); in usb_gadget_vbus_connect()
643 * @gadget:The device whose VBUS usage is being described
647 * This call is used by gadget drivers during SET_CONFIGURATION calls,
653 int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) in usb_gadget_vbus_draw() argument
657 if (!gadget->ops->vbus_draw) { in usb_gadget_vbus_draw()
662 ret = gadget->ops->vbus_draw(gadget, mA); in usb_gadget_vbus_draw()
664 gadget->mA = mA; in usb_gadget_vbus_draw()
667 trace_usb_gadget_vbus_draw(gadget, ret); in usb_gadget_vbus_draw()
675 * @gadget:the device whose VBUS supply is being described
684 int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) in usb_gadget_vbus_disconnect() argument
688 if (!gadget->ops->vbus_session) { in usb_gadget_vbus_disconnect()
693 ret = gadget->ops->vbus_session(gadget, 0); in usb_gadget_vbus_disconnect()
696 trace_usb_gadget_vbus_disconnect(gadget, ret); in usb_gadget_vbus_disconnect()
702 static int usb_gadget_connect_locked(struct usb_gadget *gadget) in usb_gadget_connect_locked() argument
703 __must_hold(&gadget->udc->connect_lock) in usb_gadget_connect_locked()
707 if (!gadget->ops->pullup) { in usb_gadget_connect_locked()
712 if (gadget->deactivated || !gadget->udc->allow_connect || !gadget->udc->started) { in usb_gadget_connect_locked()
714 * If the gadget isn't usable (because it is deactivated, in usb_gadget_connect_locked()
716 * The gadget will be connected automatically when it is in usb_gadget_connect_locked()
719 gadget->connected = true; in usb_gadget_connect_locked()
723 ret = gadget->ops->pullup(gadget, 1); in usb_gadget_connect_locked()
725 gadget->connected = 1; in usb_gadget_connect_locked()
728 trace_usb_gadget_connect(gadget, ret); in usb_gadget_connect_locked()
735 * @gadget:the peripheral being connected
738 * enumerating this gadget when the pullup is active and a VBUS session
743 int usb_gadget_connect(struct usb_gadget *gadget) in usb_gadget_connect() argument
747 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_connect()
748 ret = usb_gadget_connect_locked(gadget); in usb_gadget_connect()
749 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_connect()
755 static int usb_gadget_disconnect_locked(struct usb_gadget *gadget) in usb_gadget_disconnect_locked() argument
756 __must_hold(&gadget->udc->connect_lock) in usb_gadget_disconnect_locked()
760 if (!gadget->ops->pullup) { in usb_gadget_disconnect_locked()
765 if (!gadget->connected) in usb_gadget_disconnect_locked()
768 if (gadget->deactivated || !gadget->udc->started) { in usb_gadget_disconnect_locked()
770 * If gadget is deactivated we only save new state. in usb_gadget_disconnect_locked()
771 * Gadget will stay disconnected after activation. in usb_gadget_disconnect_locked()
773 gadget->connected = false; in usb_gadget_disconnect_locked()
777 ret = gadget->ops->pullup(gadget, 0); in usb_gadget_disconnect_locked()
779 gadget->connected = 0; 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()
787 trace_usb_gadget_disconnect(gadget, ret); in usb_gadget_disconnect_locked()
794 * @gadget:the peripheral being disconnected
801 * for the current gadget driver so that UDC drivers don't need to.
805 int usb_gadget_disconnect(struct usb_gadget *gadget) in usb_gadget_disconnect() argument
809 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_disconnect()
810 ret = usb_gadget_disconnect_locked(gadget); in usb_gadget_disconnect()
811 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_disconnect()
819 * @gadget: the peripheral being deactivated
821 * This routine may be used during the gadget driver bind() call to prevent
827 * (such as from within a gadget driver's disconnect() callback).
831 int usb_gadget_deactivate(struct usb_gadget *gadget) in usb_gadget_deactivate() argument
835 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_deactivate()
836 if (gadget->deactivated) in usb_gadget_deactivate()
839 if (gadget->connected) { in usb_gadget_deactivate()
840 ret = usb_gadget_disconnect_locked(gadget); in usb_gadget_deactivate()
845 * If gadget was being connected before deactivation, we want in usb_gadget_deactivate()
848 gadget->connected = true; in usb_gadget_deactivate()
850 gadget->deactivated = true; in usb_gadget_deactivate()
853 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_deactivate()
854 trace_usb_gadget_deactivate(gadget, ret); in usb_gadget_deactivate()
862 * @gadget: the peripheral being activated
864 * This routine activates gadget which was previously deactivated with
871 int usb_gadget_activate(struct usb_gadget *gadget) in usb_gadget_activate() argument
875 mutex_lock(&gadget->udc->connect_lock); in usb_gadget_activate()
876 if (!gadget->deactivated) in usb_gadget_activate()
879 gadget->deactivated = false; in usb_gadget_activate()
882 * If gadget has been connected before deactivation, or became connected in usb_gadget_activate()
885 if (gadget->connected) in usb_gadget_activate()
886 ret = usb_gadget_connect_locked(gadget); in usb_gadget_activate()
889 mutex_unlock(&gadget->udc->connect_lock); in usb_gadget_activate()
890 trace_usb_gadget_activate(gadget, ret); in usb_gadget_activate()
946 int usb_gadget_map_request(struct usb_gadget *gadget, in usb_gadget_map_request() argument
949 return usb_gadget_map_request_by_dev(gadget->dev.parent, req, is_in); in usb_gadget_map_request()
972 void usb_gadget_unmap_request(struct usb_gadget *gadget, in usb_gadget_unmap_request() argument
975 usb_gadget_unmap_request_by_dev(gadget->dev.parent, req, is_in); in usb_gadget_unmap_request()
984 * usb_gadget_giveback_request - give the request back to the gadget layer
989 * completed request back to the gadget layer.
1026 int usb_gadget_ep_match_desc(struct usb_gadget *gadget, in usb_gadget_ep_match_desc() argument
1050 if (!gadget_is_dualspeed(gadget) && usb_endpoint_maxp_mult(desc) > 1) in usb_gadget_ep_match_desc()
1061 if (!gadget_is_dualspeed(gadget) && max > 1023) in usb_gadget_ep_match_desc()
1067 if (ep_comp && gadget_is_superspeed(gadget)) { in usb_gadget_ep_match_desc()
1084 if (!gadget_is_dualspeed(gadget) && max > 64) in usb_gadget_ep_match_desc()
1096 * @gadget: controller to check the USB configuration
1104 int usb_gadget_check_config(struct usb_gadget *gadget) in usb_gadget_check_config() argument
1106 if (gadget->ops->check_config) in usb_gadget_check_config()
1107 return gadget->ops->check_config(gadget); in usb_gadget_check_config()
1116 struct usb_gadget *gadget = work_to_gadget(work); in usb_gadget_state_work() local
1117 struct usb_udc *udc = gadget->udc; in usb_gadget_state_work()
1123 void usb_gadget_set_state(struct usb_gadget *gadget, in usb_gadget_set_state() argument
1126 gadget->state = state; in usb_gadget_set_state()
1127 schedule_work(&gadget->work); in usb_gadget_set_state()
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()
1153 * connect or disconnect gadget
1154 * @gadget: The gadget which vbus change occurs
1157 * The udc driver calls it when it wants to connect or disconnect gadget
1161 * the gadget drivers, however, usb_udc_connect_control() has to run in
1163 * a. Some of the gadget driver implementations expect the ->pullup
1168 void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status) in usb_udc_vbus_handler() argument
1170 struct usb_udc *udc = gadget->udc; in usb_udc_vbus_handler()
1181 * @gadget: The gadget which bus reset occurs
1182 * @driver: The gadget driver we want to notify
1185 * reset occurs, it notifies the gadget driver that the bus reset occurs as
1186 * well as updates gadget state.
1188 void usb_gadget_udc_reset(struct usb_gadget *gadget, in usb_gadget_udc_reset() argument
1191 driver->reset(gadget); in usb_gadget_udc_reset()
1192 usb_gadget_set_state(gadget, USB_STATE_DEFAULT); in usb_gadget_udc_reset()
1201 * to register a gadget driver to the device controller, before
1202 * calling gadget driver's bind() method.
1221 ret = udc->gadget->ops->udc_start(udc->gadget, udc->driver); in usb_gadget_udc_start_locked()
1233 * gadget driver's unbind() method.
1249 udc->gadget->ops->udc_stop(udc->gadget); in usb_gadget_udc_stop_locked()
1261 * connect on speeds the gadget driver doesn't support.
1266 struct usb_gadget *gadget = udc->gadget; in usb_gadget_udc_set_speed() local
1270 s = gadget->max_speed; in usb_gadget_udc_set_speed()
1272 s = min(speed, gadget->max_speed); in usb_gadget_udc_set_speed()
1274 if (s == USB_SPEED_SUPER_PLUS && gadget->ops->udc_set_ssp_rate) in usb_gadget_udc_set_speed()
1275 gadget->ops->udc_set_ssp_rate(gadget, gadget->max_ssp_rate); in usb_gadget_udc_set_speed()
1276 else if (gadget->ops->udc_set_speed) in usb_gadget_udc_set_speed()
1277 gadget->ops->udc_set_speed(gadget, s); in usb_gadget_udc_set_speed()
1284 * This routine is used when binding gadget drivers. It undoes the effect
1292 struct usb_gadget *gadget = udc->gadget; in usb_gadget_enable_async_callbacks() local
1294 if (gadget->ops->udc_async_callbacks) in usb_gadget_enable_async_callbacks()
1295 gadget->ops->udc_async_callbacks(gadget, true); in usb_gadget_enable_async_callbacks()
1302 * This routine is used when unbinding gadget drivers. It prevents a race:
1303 * The UDC driver doesn't know when the gadget driver's ->unbind callback
1308 * ->resume, ->disconnect, ->reset, and ->setup callbacks to the gadget driver
1321 struct usb_gadget *gadget = udc->gadget; in usb_gadget_disable_async_callbacks() local
1323 if (gadget->ops->udc_async_callbacks) in usb_gadget_disable_async_callbacks()
1324 gadget->ops->udc_async_callbacks(gadget, false); in usb_gadget_disable_async_callbacks()
1351 * usb_initialize_gadget - initialize a gadget and its embedded struct device
1354 * @gadget: the gadget to be initialized.
1355 * @release: a gadget release function.
1357 void usb_initialize_gadget(struct device *parent, struct usb_gadget *gadget, in usb_initialize_gadget() argument
1360 INIT_WORK(&gadget->work, usb_gadget_state_work); in usb_initialize_gadget()
1361 gadget->dev.parent = parent; in usb_initialize_gadget()
1364 gadget->dev.release = release; in usb_initialize_gadget()
1366 gadget->dev.release = usb_udc_nop_release; in usb_initialize_gadget()
1368 device_initialize(&gadget->dev); in usb_initialize_gadget()
1369 gadget->dev.bus = &gadget_bus_type; in usb_initialize_gadget()
1374 * usb_add_gadget - adds a new gadget to the udc class driver list
1375 * @gadget: the gadget to be added to the list.
1380 int usb_add_gadget(struct usb_gadget *gadget) in usb_add_gadget() argument
1393 udc->dev.parent = gadget->dev.parent; in usb_add_gadget()
1395 kobject_name(&gadget->dev.parent->kobj)); in usb_add_gadget()
1399 udc->gadget = gadget; in usb_add_gadget()
1400 gadget->udc = udc; in usb_add_gadget()
1414 usb_gadget_set_state(gadget, USB_STATE_NOTATTACHED); in usb_add_gadget()
1420 gadget->id_number = ret; in usb_add_gadget()
1421 dev_set_name(&gadget->dev, "gadget.%d", ret); in usb_add_gadget()
1423 ret = device_add(&gadget->dev); in usb_add_gadget()
1428 &gadget->dev.kobj, "gadget"); in usb_add_gadget()
1435 device_del(&gadget->dev); in usb_add_gadget()
1438 ida_free(&gadget_id_numbers, gadget->id_number); in usb_add_gadget()
1441 flush_work(&gadget->work); in usb_add_gadget()
1458 * usb_add_gadget_udc_release - adds a new gadget to the udc class driver list
1461 * @gadget: the gadget to be added to the list.
1462 * @release: a gadget release function.
1465 * Calls the gadget release function in the latter case.
1467 int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, in usb_add_gadget_udc_release() argument
1472 usb_initialize_gadget(parent, gadget, release); in usb_add_gadget_udc_release()
1473 ret = usb_add_gadget(gadget); in usb_add_gadget_udc_release()
1475 usb_put_gadget(gadget); in usb_add_gadget_udc_release()
1486 * of the returned name will be still available, when gadget driver registers
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
1514 * @gadget: the gadget to be added to the list
1518 int usb_add_gadget_udc(struct device *parent, struct usb_gadget *gadget) in usb_add_gadget_udc() argument
1520 return usb_add_gadget_udc_release(parent, gadget, NULL); in usb_add_gadget_udc()
1525 * usb_del_gadget - deletes a gadget and unregisters its udc
1526 * @gadget: the gadget to be deleted.
1528 * This will unbind @gadget, if it is bound.
1531 void usb_del_gadget(struct usb_gadget *gadget) in usb_del_gadget() argument
1533 struct usb_udc *udc = gadget->udc; in usb_del_gadget()
1538 dev_vdbg(gadget->dev.parent, "unregistering gadget\n"); in usb_del_gadget()
1545 sysfs_remove_link(&udc->dev.kobj, "gadget"); in usb_del_gadget()
1546 flush_work(&gadget->work); in usb_del_gadget()
1547 device_del(&gadget->dev); in usb_del_gadget()
1548 ida_free(&gadget_id_numbers, gadget->id_number); in usb_del_gadget()
1555 * usb_del_gadget_udc - unregisters a gadget
1556 * @gadget: the gadget to be unregistered.
1560 void usb_del_gadget_udc(struct usb_gadget *gadget) in usb_del_gadget_udc() argument
1562 usb_del_gadget(gadget); in usb_del_gadget_udc()
1563 usb_put_gadget(gadget); in usb_del_gadget_udc()
1571 struct usb_gadget *gadget = dev_to_usb_gadget(dev); in gadget_match_driver() local
1572 struct usb_udc *udc = gadget->udc; in gadget_match_driver()
1581 /* If the driver is already bound to a gadget, it doesn't match */ in gadget_match_driver()
1585 /* Otherwise any gadget driver matches any UDC */ in gadget_match_driver()
1591 struct usb_gadget *gadget = dev_to_usb_gadget(dev); in gadget_bind_driver() local
1592 struct usb_udc *udc = gadget->udc; in gadget_bind_driver()
1600 return -ENXIO; /* Driver binds to only one gadget */ in gadget_bind_driver()
1606 dev_dbg(&udc->dev, "binding gadget driver [%s]\n", driver->function); in gadget_bind_driver()
1610 ret = driver->bind(udc->gadget, driver); in gadget_bind_driver()
1634 if (gadget->irq) in gadget_bind_driver()
1635 synchronize_irq(gadget->irq); in gadget_bind_driver()
1640 driver->unbind(udc->gadget); in gadget_bind_driver()
1657 struct usb_gadget *gadget = dev_to_usb_gadget(dev); in gadget_unbind_driver() local
1658 struct usb_udc *udc = gadget->udc; in gadget_unbind_driver()
1661 dev_dbg(&udc->dev, "unbinding gadget driver [%s]\n", driver->function); in gadget_unbind_driver()
1666 usb_gadget_disconnect_locked(gadget); in gadget_unbind_driver()
1668 if (gadget->irq) in gadget_unbind_driver()
1669 synchronize_irq(gadget->irq); in gadget_unbind_driver()
1672 udc->driver->unbind(gadget); in gadget_unbind_driver()
1745 usb_gadget_wakeup(udc->gadget); in srp_store()
1757 device_lock(&udc->gadget->dev); in soft_connect_store()
1759 dev_err(dev, "soft-connect without a gadget driver\n"); in soft_connect_store()
1767 usb_gadget_connect_locked(udc->gadget); in soft_connect_store()
1771 usb_gadget_disconnect_locked(udc->gadget); in soft_connect_store()
1782 device_unlock(&udc->gadget->dev); in soft_connect_store()
1791 struct usb_gadget *gadget = udc->gadget; in state_show() local
1793 return sprintf(buf, "%s\n", usb_state_string(gadget->state)); in state_show()
1819 usb_speed_string(udc->gadget->param)); \
1831 struct usb_gadget *gadget = udc->gadget; \
1833 return scnprintf(buf, PAGE_SIZE, "%d\n", gadget->name); \
1875 ret = add_uevent_var(env, "USB_UDC_NAME=%s", udc->gadget->name); in usb_udc_uevent()
1900 .name = "gadget",