Lines Matching refs:ci

52 static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep,
66 static inline int ep_to_bit(struct ci_hdrc *ci, int n) in ep_to_bit() argument
68 int fill = 16 - ci->hw_ep_max / 2; in ep_to_bit()
70 if (n >= ci->hw_ep_max / 2) in ep_to_bit()
83 static int hw_device_state(struct ci_hdrc *ci, u32 dma) in hw_device_state() argument
86 hw_write(ci, OP_ENDPTLISTADDR, ~0, dma); in hw_device_state()
88 hw_write(ci, OP_USBINTR, ~0, in hw_device_state()
91 hw_write(ci, OP_USBINTR, ~0, 0); in hw_device_state()
104 static int hw_ep_flush(struct ci_hdrc *ci, int num, int dir) in hw_ep_flush() argument
110 hw_write(ci, OP_ENDPTFLUSH, ~0, BIT(n)); in hw_ep_flush()
111 while (hw_read(ci, OP_ENDPTFLUSH, BIT(n))) in hw_ep_flush()
113 } while (hw_read(ci, OP_ENDPTSTAT, BIT(n))); in hw_ep_flush()
126 static int hw_ep_disable(struct ci_hdrc *ci, int num, int dir) in hw_ep_disable() argument
128 hw_write(ci, OP_ENDPTCTRL + num, in hw_ep_disable()
142 static int hw_ep_enable(struct ci_hdrc *ci, int num, int dir, int type) in hw_ep_enable() argument
165 hw_write(ci, OP_ENDPTCTRL + num, mask, data); in hw_ep_enable()
177 static int hw_ep_get_halt(struct ci_hdrc *ci, int num, int dir) in hw_ep_get_halt() argument
181 return hw_read(ci, OP_ENDPTCTRL + num, mask) ? 1 : 0; in hw_ep_get_halt()
193 static int hw_ep_prime(struct ci_hdrc *ci, int num, int dir, int is_ctrl) in hw_ep_prime() argument
200 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num))) in hw_ep_prime()
203 hw_write(ci, OP_ENDPTPRIME, ~0, BIT(n)); in hw_ep_prime()
205 while (hw_read(ci, OP_ENDPTPRIME, BIT(n))) in hw_ep_prime()
207 if (is_ctrl && dir == RX && hw_read(ci, OP_ENDPTSETUPSTAT, BIT(num))) in hw_ep_prime()
224 static int hw_ep_set_halt(struct ci_hdrc *ci, int num, int dir, int value) in hw_ep_set_halt() argument
235 hw_write(ci, reg, mask_xs|mask_xr, in hw_ep_set_halt()
237 } while (value != hw_ep_get_halt(ci, num, dir)); in hw_ep_set_halt()
248 static int hw_port_is_high_speed(struct ci_hdrc *ci) in hw_port_is_high_speed() argument
250 return ci->hw_bank.lpm ? hw_read(ci, OP_DEVLC, DEVLC_PSPD) : in hw_port_is_high_speed()
251 hw_read(ci, OP_PORTSC, PORTSC_HSP); in hw_port_is_high_speed()
262 static int hw_test_and_clear_complete(struct ci_hdrc *ci, int n) in hw_test_and_clear_complete() argument
264 n = ep_to_bit(ci, n); in hw_test_and_clear_complete()
265 return hw_test_and_clear(ci, OP_ENDPTCOMPLETE, BIT(n)); in hw_test_and_clear_complete()
275 static u32 hw_test_and_clear_intr_active(struct ci_hdrc *ci) in hw_test_and_clear_intr_active() argument
277 u32 reg = hw_read_intr_status(ci) & hw_read_intr_enable(ci); in hw_test_and_clear_intr_active()
279 hw_write(ci, OP_USBSTS, ~0, reg); in hw_test_and_clear_intr_active()
290 static int hw_test_and_clear_setup_guard(struct ci_hdrc *ci) in hw_test_and_clear_setup_guard() argument
292 return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, 0); in hw_test_and_clear_setup_guard()
302 static int hw_test_and_set_setup_guard(struct ci_hdrc *ci) in hw_test_and_set_setup_guard() argument
304 return hw_test_and_write(ci, OP_USBCMD, USBCMD_SUTW, USBCMD_SUTW); in hw_test_and_set_setup_guard()
315 static void hw_usb_set_address(struct ci_hdrc *ci, u8 value) in hw_usb_set_address() argument
317 hw_write(ci, OP_DEVICEADDR, DEVICEADDR_USBADR, in hw_usb_set_address()
328 static int hw_usb_reset(struct ci_hdrc *ci) in hw_usb_reset() argument
330 hw_usb_set_address(ci, 0); in hw_usb_reset()
333 hw_write(ci, OP_ENDPTFLUSH, ~0, ~0); in hw_usb_reset()
336 hw_write(ci, OP_ENDPTSETUPSTAT, 0, 0); in hw_usb_reset()
339 hw_write(ci, OP_ENDPTCOMPLETE, 0, 0); in hw_usb_reset()
342 while (hw_read(ci, OP_ENDPTPRIME, ~0)) in hw_usb_reset()
515 dev_err(hwep->ci->dev, "not supported operation for sg\n"); in prepare_td_for_sg()
521 dev_err(hwep->ci->dev, "not page aligned sg buffer\n"); in prepare_td_for_sg()
552 struct ci_hdrc *ci = hwep->ci; in _hardware_enqueue() local
562 ret = usb_gadget_map_request_by_dev(ci->dev->parent, in _hardware_enqueue()
605 if (ci->rev == CI_REVISION_22) { in _hardware_enqueue()
606 if (!hw_read(ci, OP_ENDPTSTAT, BIT(n))) in _hardware_enqueue()
607 reprime_dtd(ci, hwep, prevlastnode); in _hardware_enqueue()
610 if (hw_read(ci, OP_ENDPTPRIME, BIT(n))) in _hardware_enqueue()
613 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, USBCMD_ATDTW); in _hardware_enqueue()
614 tmp_stat = hw_read(ci, OP_ENDPTSTAT, BIT(n)); in _hardware_enqueue()
615 } while (!hw_read(ci, OP_USBCMD, USBCMD_ATDTW)); in _hardware_enqueue()
616 hw_write(ci, OP_USBCMD, USBCMD_ATDTW, 0); in _hardware_enqueue()
635 ret = hw_ep_prime(ci, hwep->num, hwep->dir, in _hardware_enqueue()
654 static int reprime_dtd(struct ci_hdrc *ci, struct ci_hw_ep *hwep, in reprime_dtd() argument
661 return hw_ep_prime(ci, hwep->num, hwep->dir, in reprime_dtd()
678 struct ci_hdrc *ci = hwep->ci; in _hardware_dequeue() local
691 if (ci->rev == CI_REVISION_24) in _hardware_dequeue()
692 if (!hw_read(ci, OP_ENDPTSTAT, BIT(n))) in _hardware_dequeue()
693 reprime_dtd(ci, hwep, node); in _hardware_dequeue()
732 usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, in _hardware_dequeue()
758 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in _ep_nuke()
812 retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value); in _ep_set_halt()
836 struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); in _gadget_stop_activity() local
843 usb_ep_fifo_flush(&ci->ep0out->ep); in _gadget_stop_activity()
844 usb_ep_fifo_flush(&ci->ep0in->ep); in _gadget_stop_activity()
851 if (ci->status != NULL) { in _gadget_stop_activity()
852 usb_ep_free_request(&ci->ep0in->ep, ci->status); in _gadget_stop_activity()
853 ci->status = NULL; in _gadget_stop_activity()
856 spin_lock_irqsave(&ci->lock, flags); in _gadget_stop_activity()
857 ci->gadget.speed = USB_SPEED_UNKNOWN; in _gadget_stop_activity()
858 ci->remote_wakeup = 0; in _gadget_stop_activity()
859 ci->suspended = 0; in _gadget_stop_activity()
860 spin_unlock_irqrestore(&ci->lock, flags); in _gadget_stop_activity()
874 static void isr_reset_handler(struct ci_hdrc *ci) in isr_reset_handler() argument
875 __releases(ci->lock) in isr_reset_handler()
876 __acquires(ci->lock) in isr_reset_handler()
881 spin_unlock(&ci->lock); in isr_reset_handler()
882 if (ci->gadget.speed != USB_SPEED_UNKNOWN) in isr_reset_handler()
883 usb_gadget_udc_reset(&ci->gadget, ci->driver); in isr_reset_handler()
885 retval = _gadget_stop_activity(&ci->gadget); in isr_reset_handler()
889 retval = hw_usb_reset(ci); in isr_reset_handler()
894 hw_write(ci, OP_USBSTS, USBi_SLI, USBi_SLI); in isr_reset_handler()
895 intr = hw_read(ci, OP_USBINTR, ~0); in isr_reset_handler()
896 hw_write(ci, OP_USBINTR, ~0, intr | USBi_SLI); in isr_reset_handler()
898 ci->status = usb_ep_alloc_request(&ci->ep0in->ep, GFP_ATOMIC); in isr_reset_handler()
899 if (ci->status == NULL) in isr_reset_handler()
903 spin_lock(&ci->lock); in isr_reset_handler()
906 dev_err(ci->dev, "error: %i\n", retval); in isr_reset_handler()
939 struct ci_hdrc *ci = hwep->ci; in _ep_queue() local
947 hwep = (ci->ep0_dir == RX) ? in _ep_queue()
948 ci->ep0out : ci->ep0in; in _ep_queue()
951 dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n", in _ep_queue()
958 dev_err(hwep->ci->dev, "request length too big for isochronous\n"); in _ep_queue()
962 if (ci->has_short_pkt_limit && in _ep_queue()
964 dev_err(hwep->ci->dev, "request length too big (max 16KB)\n"); in _ep_queue()
970 dev_err(hwep->ci->dev, "request already in queue\n"); in _ep_queue()
995 static int isr_get_status_response(struct ci_hdrc *ci, in isr_get_status_response() argument
1000 struct ci_hw_ep *hwep = ci->ep0in; in isr_get_status_response()
1023 *(u16 *)req->buf = (ci->remote_wakeup << 1) | in isr_get_status_response()
1024 ci->gadget.is_selfpowered; in isr_get_status_response()
1030 *(u16 *)req->buf = hw_ep_get_halt(ci, num, dir); in isr_get_status_response()
1060 struct ci_hdrc *ci = req->context; in isr_setup_status_complete() local
1066 if (ci->setaddr) { in isr_setup_status_complete()
1067 hw_usb_set_address(ci, ci->address); in isr_setup_status_complete()
1068 ci->setaddr = false; in isr_setup_status_complete()
1069 if (ci->address) in isr_setup_status_complete()
1070 usb_gadget_set_state(&ci->gadget, USB_STATE_ADDRESS); in isr_setup_status_complete()
1073 spin_lock_irqsave(&ci->lock, flags); in isr_setup_status_complete()
1074 if (ci->test_mode) in isr_setup_status_complete()
1075 hw_port_test_set(ci, ci->test_mode); in isr_setup_status_complete()
1076 spin_unlock_irqrestore(&ci->lock, flags); in isr_setup_status_complete()
1085 static int isr_setup_status_phase(struct ci_hdrc *ci) in isr_setup_status_phase() argument
1095 if (WARN_ON_ONCE(!ci->status)) in isr_setup_status_phase()
1098 hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in; in isr_setup_status_phase()
1099 ci->status->context = ci; in isr_setup_status_phase()
1100 ci->status->complete = isr_setup_status_complete; in isr_setup_status_phase()
1102 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); in isr_setup_status_phase()
1130 hweptemp = hwep->ci->ep0in; in isr_tr_complete_low()
1142 static int otg_a_alt_hnp_support(struct ci_hdrc *ci) in otg_a_alt_hnp_support() argument
1144 dev_warn(&ci->gadget.dev, in otg_a_alt_hnp_support()
1146 return isr_setup_status_phase(ci); in otg_a_alt_hnp_support()
1155 static void isr_setup_packet_handler(struct ci_hdrc *ci) in isr_setup_packet_handler() argument
1156 __releases(ci->lock) in isr_setup_packet_handler()
1157 __acquires(ci->lock) in isr_setup_packet_handler()
1159 struct ci_hw_ep *hwep = &ci->ci_hw_ep[0]; in isr_setup_packet_handler()
1168 _ep_nuke(ci->ep0out); in isr_setup_packet_handler()
1169 _ep_nuke(ci->ep0in); in isr_setup_packet_handler()
1173 hw_test_and_set_setup_guard(ci); in isr_setup_packet_handler()
1175 } while (!hw_test_and_clear_setup_guard(ci)); in isr_setup_packet_handler()
1179 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX; in isr_setup_packet_handler()
1192 num += ci->hw_ep_max / 2; in isr_setup_packet_handler()
1193 if (!ci->ci_hw_ep[num].wedge) { in isr_setup_packet_handler()
1194 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1196 &ci->ci_hw_ep[num].ep); in isr_setup_packet_handler()
1197 spin_lock(&ci->lock); in isr_setup_packet_handler()
1201 err = isr_setup_status_phase(ci); in isr_setup_packet_handler()
1207 ci->remote_wakeup = 0; in isr_setup_packet_handler()
1208 err = isr_setup_status_phase(ci); in isr_setup_packet_handler()
1222 err = isr_get_status_response(ci, &req); in isr_setup_packet_handler()
1230 ci->address = (u8)le16_to_cpu(req.wValue); in isr_setup_packet_handler()
1231 ci->setaddr = true; in isr_setup_packet_handler()
1232 err = isr_setup_status_phase(ci); in isr_setup_packet_handler()
1244 num += ci->hw_ep_max / 2; in isr_setup_packet_handler()
1246 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1247 err = _ep_set_halt(&ci->ci_hw_ep[num].ep, 1, false); in isr_setup_packet_handler()
1248 spin_lock(&ci->lock); in isr_setup_packet_handler()
1250 isr_setup_status_phase(ci); in isr_setup_packet_handler()
1256 ci->remote_wakeup = 1; in isr_setup_packet_handler()
1257 err = isr_setup_status_phase(ci); in isr_setup_packet_handler()
1267 ci->test_mode = tmode; in isr_setup_packet_handler()
1269 ci); in isr_setup_packet_handler()
1276 if (ci_otg_is_fsm_mode(ci)) { in isr_setup_packet_handler()
1277 ci->gadget.b_hnp_enable = 1; in isr_setup_packet_handler()
1279 ci); in isr_setup_packet_handler()
1283 if (ci_otg_is_fsm_mode(ci)) in isr_setup_packet_handler()
1284 err = otg_a_alt_hnp_support(ci); in isr_setup_packet_handler()
1287 if (ci_otg_is_fsm_mode(ci)) { in isr_setup_packet_handler()
1288 ci->gadget.a_hnp_support = 1; in isr_setup_packet_handler()
1290 ci); in isr_setup_packet_handler()
1303 ci->ep0_dir = TX; in isr_setup_packet_handler()
1305 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1306 err = ci->driver->setup(&ci->gadget, &req); in isr_setup_packet_handler()
1307 spin_lock(&ci->lock); in isr_setup_packet_handler()
1312 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1314 dev_err(ci->dev, "error: _ep_set_halt\n"); in isr_setup_packet_handler()
1315 spin_lock(&ci->lock); in isr_setup_packet_handler()
1325 static void isr_tr_complete_handler(struct ci_hdrc *ci) in isr_tr_complete_handler() argument
1326 __releases(ci->lock) in isr_tr_complete_handler()
1327 __acquires(ci->lock) in isr_tr_complete_handler()
1332 for (i = 0; i < ci->hw_ep_max; i++) { in isr_tr_complete_handler()
1333 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in isr_tr_complete_handler()
1338 if (hw_test_and_clear_complete(ci, i)) { in isr_tr_complete_handler()
1342 err = isr_setup_status_phase(ci); in isr_tr_complete_handler()
1344 spin_unlock(&ci->lock); in isr_tr_complete_handler()
1346 dev_err(ci->dev, in isr_tr_complete_handler()
1348 spin_lock(&ci->lock); in isr_tr_complete_handler()
1355 hw_test_and_clear(ci, OP_ENDPTSETUPSTAT, BIT(0))) in isr_tr_complete_handler()
1356 isr_setup_packet_handler(ci); in isr_tr_complete_handler()
1384 dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); in ep_enable()
1415 dev_err(hwep->ci->dev, "Set control xfer at non-ep0\n"); in ep_enable()
1424 retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir, in ep_enable()
1448 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_disable()
1458 retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir); in ep_disable()
1507 dev_err(hwep->ci->dev, "freeing queued request\n"); in ep_free_request()
1541 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_queue()
1568 if (hwep->ci->gadget.speed != USB_SPEED_UNKNOWN) in ep_dequeue()
1569 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_dequeue()
1580 usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); in ep_dequeue()
1635 dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep)); in ep_fifo_flush()
1640 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_fifo_flush()
1645 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_fifo_flush()
1672 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_get_frame() local
1676 spin_lock_irqsave(&ci->lock, flags); in ci_udc_get_frame()
1677 ret = hw_read(ci, OP_FRINDEX, 0x3fff); in ci_udc_get_frame()
1678 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_get_frame()
1687 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_hdrc_gadget_connect() local
1690 pm_runtime_get_sync(ci->dev); in ci_hdrc_gadget_connect()
1691 hw_device_reset(ci); in ci_hdrc_gadget_connect()
1692 spin_lock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1693 if (ci->driver) { in ci_hdrc_gadget_connect()
1694 hw_device_state(ci, ci->ep0out->qh.dma); in ci_hdrc_gadget_connect()
1696 spin_unlock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1699 spin_unlock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1703 if (ci->driver) in ci_hdrc_gadget_connect()
1704 ci->driver->disconnect(&ci->gadget); in ci_hdrc_gadget_connect()
1705 hw_device_state(ci, 0); in ci_hdrc_gadget_connect()
1706 if (ci->platdata->notify_event) in ci_hdrc_gadget_connect()
1707 ci->platdata->notify_event(ci, in ci_hdrc_gadget_connect()
1709 _gadget_stop_activity(&ci->gadget); in ci_hdrc_gadget_connect()
1710 pm_runtime_put_sync(ci->dev); in ci_hdrc_gadget_connect()
1717 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_vbus_session() local
1721 spin_lock_irqsave(&ci->lock, flags); in ci_udc_vbus_session()
1722 ci->vbus_active = is_active; in ci_udc_vbus_session()
1723 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_vbus_session()
1725 if (ci->usb_phy) in ci_udc_vbus_session()
1726 usb_phy_set_charger_state(ci->usb_phy, is_active ? in ci_udc_vbus_session()
1729 if (ci->platdata->notify_event) in ci_udc_vbus_session()
1730 ret = ci->platdata->notify_event(ci, in ci_udc_vbus_session()
1733 if (ci->usb_phy) { in ci_udc_vbus_session()
1735 usb_phy_set_event(ci->usb_phy, USB_EVENT_VBUS); in ci_udc_vbus_session()
1737 usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); in ci_udc_vbus_session()
1740 if (ci->driver) in ci_udc_vbus_session()
1748 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_wakeup() local
1752 spin_lock_irqsave(&ci->lock, flags); in ci_udc_wakeup()
1753 if (ci->gadget.speed == USB_SPEED_UNKNOWN) { in ci_udc_wakeup()
1754 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_wakeup()
1757 if (!ci->remote_wakeup) { in ci_udc_wakeup()
1761 if (!hw_read(ci, OP_PORTSC, PORTSC_SUSP)) { in ci_udc_wakeup()
1765 hw_write(ci, OP_PORTSC, PORTSC_FPR, PORTSC_FPR); in ci_udc_wakeup()
1767 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_wakeup()
1773 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_vbus_draw() local
1775 if (ci->usb_phy) in ci_udc_vbus_draw()
1776 return usb_phy_set_power(ci->usb_phy, ma); in ci_udc_vbus_draw()
1782 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_selfpowered() local
1783 struct ci_hw_ep *hwep = ci->ep0in; in ci_udc_selfpowered()
1798 struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget); in ci_udc_pullup() local
1804 if (ci_otg_is_fsm_mode(ci) || ci->role == CI_ROLE_HOST) in ci_udc_pullup()
1807 pm_runtime_get_sync(ci->dev); in ci_udc_pullup()
1809 hw_write(ci, OP_USBCMD, USBCMD_RS, USBCMD_RS); in ci_udc_pullup()
1811 hw_write(ci, OP_USBCMD, USBCMD_RS, 0); in ci_udc_pullup()
1812 pm_runtime_put_sync(ci->dev); in ci_udc_pullup()
1826 struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); in ci_udc_match_ep() local
1830 list_for_each_entry_reverse(ep, &ci->gadget.ep_list, ep_list) { in ci_udc_match_ep()
1856 static int init_eps(struct ci_hdrc *ci) in init_eps() argument
1860 for (i = 0; i < ci->hw_ep_max/2; i++) in init_eps()
1862 int k = i + j * ci->hw_ep_max/2; in init_eps()
1863 struct ci_hw_ep *hwep = &ci->ci_hw_ep[k]; in init_eps()
1868 hwep->ci = ci; in init_eps()
1869 hwep->lock = &ci->lock; in init_eps()
1870 hwep->td_pool = ci->td_pool; in init_eps()
1896 hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, in init_eps()
1907 ci->ep0out = hwep; in init_eps()
1909 ci->ep0in = hwep; in init_eps()
1915 list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list); in init_eps()
1921 static void destroy_eps(struct ci_hdrc *ci) in destroy_eps() argument
1925 for (i = 0; i < ci->hw_ep_max; i++) { in destroy_eps()
1926 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in destroy_eps()
1930 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); in destroy_eps()
1944 struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); in ci_udc_start() local
1950 ci->ep0out->ep.desc = &ctrl_endpt_out_desc; in ci_udc_start()
1951 retval = usb_ep_enable(&ci->ep0out->ep); in ci_udc_start()
1955 ci->ep0in->ep.desc = &ctrl_endpt_in_desc; in ci_udc_start()
1956 retval = usb_ep_enable(&ci->ep0in->ep); in ci_udc_start()
1960 ci->driver = driver; in ci_udc_start()
1963 if (ci_otg_is_fsm_mode(ci) && ci->fsm.id) { in ci_udc_start()
1964 ci_hdrc_otg_fsm_start(ci); in ci_udc_start()
1968 if (ci->vbus_active) in ci_udc_start()
1971 usb_udc_vbus_handler(&ci->gadget, false); in ci_udc_start()
1976 static void ci_udc_stop_for_otg_fsm(struct ci_hdrc *ci) in ci_udc_stop_for_otg_fsm() argument
1978 if (!ci_otg_is_fsm_mode(ci)) in ci_udc_stop_for_otg_fsm()
1981 mutex_lock(&ci->fsm.lock); in ci_udc_stop_for_otg_fsm()
1982 if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) { in ci_udc_stop_for_otg_fsm()
1983 ci->fsm.a_bidl_adis_tmout = 1; in ci_udc_stop_for_otg_fsm()
1984 ci_hdrc_otg_fsm_start(ci); in ci_udc_stop_for_otg_fsm()
1985 } else if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) { in ci_udc_stop_for_otg_fsm()
1986 ci->fsm.protocol = PROTO_UNDEF; in ci_udc_stop_for_otg_fsm()
1987 ci->fsm.otg->state = OTG_STATE_UNDEFINED; in ci_udc_stop_for_otg_fsm()
1989 mutex_unlock(&ci->fsm.lock); in ci_udc_stop_for_otg_fsm()
1997 struct ci_hdrc *ci = container_of(gadget, struct ci_hdrc, gadget); in ci_udc_stop() local
2000 spin_lock_irqsave(&ci->lock, flags); in ci_udc_stop()
2001 ci->driver = NULL; in ci_udc_stop()
2003 if (ci->vbus_active) { in ci_udc_stop()
2004 hw_device_state(ci, 0); in ci_udc_stop()
2005 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_stop()
2006 if (ci->platdata->notify_event) in ci_udc_stop()
2007 ci->platdata->notify_event(ci, in ci_udc_stop()
2009 _gadget_stop_activity(&ci->gadget); in ci_udc_stop()
2010 spin_lock_irqsave(&ci->lock, flags); in ci_udc_stop()
2011 pm_runtime_put(ci->dev); in ci_udc_stop()
2014 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_stop()
2016 ci_udc_stop_for_otg_fsm(ci); in ci_udc_stop()
2029 static irqreturn_t udc_irq(struct ci_hdrc *ci) in udc_irq() argument
2034 if (ci == NULL) in udc_irq()
2037 spin_lock(&ci->lock); in udc_irq()
2039 if (ci->platdata->flags & CI_HDRC_REGS_SHARED) { in udc_irq()
2040 if (hw_read(ci, OP_USBMODE, USBMODE_CM) != in udc_irq()
2042 spin_unlock(&ci->lock); in udc_irq()
2046 intr = hw_test_and_clear_intr_active(ci); in udc_irq()
2051 isr_reset_handler(ci); in udc_irq()
2054 ci->gadget.speed = hw_port_is_high_speed(ci) ? in udc_irq()
2056 if (ci->usb_phy) in udc_irq()
2057 usb_phy_set_event(ci->usb_phy, in udc_irq()
2059 if (ci->suspended) { in udc_irq()
2060 if (ci->driver->resume) { in udc_irq()
2061 spin_unlock(&ci->lock); in udc_irq()
2062 ci->driver->resume(&ci->gadget); in udc_irq()
2063 spin_lock(&ci->lock); in udc_irq()
2065 ci->suspended = 0; in udc_irq()
2066 usb_gadget_set_state(&ci->gadget, in udc_irq()
2067 ci->resume_state); in udc_irq()
2072 isr_tr_complete_handler(ci); in udc_irq()
2074 if ((USBi_SLI & intr) && !(ci->suspended)) { in udc_irq()
2075 ci->suspended = 1; in udc_irq()
2076 ci->resume_state = ci->gadget.state; in udc_irq()
2077 if (ci->gadget.speed != USB_SPEED_UNKNOWN && in udc_irq()
2078 ci->driver->suspend) { in udc_irq()
2079 spin_unlock(&ci->lock); in udc_irq()
2080 ci->driver->suspend(&ci->gadget); in udc_irq()
2081 spin_lock(&ci->lock); in udc_irq()
2083 usb_gadget_set_state(&ci->gadget, in udc_irq()
2090 spin_unlock(&ci->lock); in udc_irq()
2099 static int udc_start(struct ci_hdrc *ci) in udc_start() argument
2101 struct device *dev = ci->dev; in udc_start()
2102 struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps; in udc_start()
2105 ci->gadget.ops = &usb_gadget_ops; in udc_start()
2106 ci->gadget.speed = USB_SPEED_UNKNOWN; in udc_start()
2107 ci->gadget.max_speed = USB_SPEED_HIGH; in udc_start()
2108 ci->gadget.name = ci->platdata->name; in udc_start()
2109 ci->gadget.otg_caps = otg_caps; in udc_start()
2110 ci->gadget.sg_supported = 1; in udc_start()
2111 ci->gadget.irq = ci->irq; in udc_start()
2113 if (ci->platdata->flags & CI_HDRC_REQUIRES_ALIGNED_DMA) in udc_start()
2114 ci->gadget.quirk_avoids_skb_reserve = 1; in udc_start()
2116 if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support || in udc_start()
2118 ci->gadget.is_otg = 1; in udc_start()
2120 INIT_LIST_HEAD(&ci->gadget.ep_list); in udc_start()
2123 ci->qh_pool = dma_pool_create("ci_hw_qh", dev->parent, in udc_start()
2126 if (ci->qh_pool == NULL) in udc_start()
2129 ci->td_pool = dma_pool_create("ci_hw_td", dev->parent, in udc_start()
2132 if (ci->td_pool == NULL) { in udc_start()
2137 retval = init_eps(ci); in udc_start()
2141 ci->gadget.ep0 = &ci->ep0in->ep; in udc_start()
2143 retval = usb_add_gadget_udc(dev, &ci->gadget); in udc_start()
2150 destroy_eps(ci); in udc_start()
2152 dma_pool_destroy(ci->td_pool); in udc_start()
2154 dma_pool_destroy(ci->qh_pool); in udc_start()
2163 void ci_hdrc_gadget_destroy(struct ci_hdrc *ci) in ci_hdrc_gadget_destroy() argument
2165 if (!ci->roles[CI_ROLE_GADGET]) in ci_hdrc_gadget_destroy()
2168 usb_del_gadget_udc(&ci->gadget); in ci_hdrc_gadget_destroy()
2170 destroy_eps(ci); in ci_hdrc_gadget_destroy()
2172 dma_pool_destroy(ci->td_pool); in ci_hdrc_gadget_destroy()
2173 dma_pool_destroy(ci->qh_pool); in ci_hdrc_gadget_destroy()
2176 static int udc_id_switch_for_device(struct ci_hdrc *ci) in udc_id_switch_for_device() argument
2178 if (ci->platdata->pins_device) in udc_id_switch_for_device()
2179 pinctrl_select_state(ci->platdata->pctl, in udc_id_switch_for_device()
2180 ci->platdata->pins_device); in udc_id_switch_for_device()
2182 if (ci->is_otg) in udc_id_switch_for_device()
2184 hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, in udc_id_switch_for_device()
2190 static void udc_id_switch_for_host(struct ci_hdrc *ci) in udc_id_switch_for_host() argument
2196 if (ci->is_otg) in udc_id_switch_for_host()
2197 hw_write_otgsc(ci, OTGSC_BSVIE | OTGSC_BSVIS, OTGSC_BSVIS); in udc_id_switch_for_host()
2199 ci->vbus_active = 0; in udc_id_switch_for_host()
2201 if (ci->platdata->pins_device && ci->platdata->pins_default) in udc_id_switch_for_host()
2202 pinctrl_select_state(ci->platdata->pctl, in udc_id_switch_for_host()
2203 ci->platdata->pins_default); in udc_id_switch_for_host()
2207 static void udc_suspend(struct ci_hdrc *ci) in udc_suspend() argument
2214 if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0) in udc_suspend()
2215 hw_write(ci, OP_ENDPTLISTADDR, ~0, ~0); in udc_suspend()
2218 static void udc_resume(struct ci_hdrc *ci, bool power_lost) in udc_resume() argument
2221 if (ci->is_otg) in udc_resume()
2222 hw_write_otgsc(ci, OTGSC_BSVIS | OTGSC_BSVIE, in udc_resume()
2224 if (ci->vbus_active) in udc_resume()
2225 usb_gadget_vbus_disconnect(&ci->gadget); in udc_resume()
2229 if (hw_read(ci, OP_ENDPTLISTADDR, ~0) == 0xFFFFFFFF) in udc_resume()
2230 hw_write(ci, OP_ENDPTLISTADDR, ~0, 0); in udc_resume()
2240 int ci_hdrc_gadget_init(struct ci_hdrc *ci) in ci_hdrc_gadget_init() argument
2245 if (!hw_read(ci, CAP_DCCPARAMS, DCCPARAMS_DC)) in ci_hdrc_gadget_init()
2248 rdrv = devm_kzalloc(ci->dev, sizeof(*rdrv), GFP_KERNEL); in ci_hdrc_gadget_init()
2261 ret = udc_start(ci); in ci_hdrc_gadget_init()
2263 ci->roles[CI_ROLE_GADGET] = rdrv; in ci_hdrc_gadget_init()