Lines Matching +full:otg +full:- +full:rev

1 // SPDX-License-Identifier: GPL-2.0
3 * udc.c - ChipIdea UDC driver
5 * Copyright (C) 2008 Chipidea - MIPS Technologies, Inc. All rights reserved.
13 #include <linux/dma-direct.h>
22 #include <linux/usb/otg-fsm.h>
28 #include "otg.h"
69 int fill = 16 - ci->hw_ep_max / 2; in ep_to_bit()
71 if (n >= ci->hw_ep_max / 2) in ep_to_bit()
202 return -EAGAIN; in hw_ep_prime()
209 return -EAGAIN; in hw_ep_prime()
228 return -EINVAL; in hw_ep_set_halt()
235 /* data toggle - reserved for EP0 but it's in ESS */ in hw_ep_set_halt()
251 return ci->hw_bank.lpm ? hw_read(ci, OP_DEVLC, DEVLC_PSPD) : in hw_port_is_high_speed()
367 return -ENOMEM; in add_td_to_list()
369 node->ptr = dma_pool_zalloc(hwep->td_pool, GFP_ATOMIC, &node->dma); in add_td_to_list()
370 if (node->ptr == NULL) { in add_td_to_list()
372 return -ENOMEM; in add_td_to_list()
375 node->ptr->token = cpu_to_le32(length << __ffs(TD_TOTAL_BYTES)); in add_td_to_list()
376 node->ptr->token &= cpu_to_le32(TD_TOTAL_BYTES); in add_td_to_list()
377 node->ptr->token |= cpu_to_le32(TD_STATUS_ACTIVE); in add_td_to_list()
378 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) { in add_td_to_list()
379 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in add_td_to_list()
381 if (hwreq->req.length == 0 in add_td_to_list()
382 || hwreq->req.length % hwep->ep.maxpacket) in add_td_to_list()
384 node->ptr->token |= cpu_to_le32(mul << __ffs(TD_MULTO)); in add_td_to_list()
388 temp = (u32) (sg_dma_address(s) + hwreq->req.actual); in add_td_to_list()
389 node->td_remaining_size = CI_MAX_BUF_SIZE - length; in add_td_to_list()
391 temp = (u32) (hwreq->req.dma + hwreq->req.actual); in add_td_to_list()
395 node->ptr->page[0] = cpu_to_le32(temp); in add_td_to_list()
399 node->ptr->page[i] = cpu_to_le32(page); in add_td_to_list()
403 hwreq->req.actual += length; in add_td_to_list()
405 if (!list_empty(&hwreq->tds)) { in add_td_to_list()
407 lastnode = list_entry(hwreq->tds.prev, in add_td_to_list()
409 lastnode->ptr->next = cpu_to_le32(node->dma); in add_td_to_list()
412 INIT_LIST_HEAD(&node->td); in add_td_to_list()
413 list_add_tail(&node->td, &hwreq->tds); in add_td_to_list()
424 return ((ep->dir == TX) ? USB_ENDPOINT_DIR_MASK : 0) | ep->num; in _usb_addr()
430 unsigned int rest = hwreq->req.length; in prepare_td_for_non_sg()
444 if (hwreq->req.dma % PAGE_SIZE) in prepare_td_for_non_sg()
445 pages--; in prepare_td_for_non_sg()
448 unsigned int count = min(hwreq->req.length - hwreq->req.actual, in prepare_td_for_non_sg()
455 rest -= count; in prepare_td_for_non_sg()
458 if (hwreq->req.zero && hwreq->req.length && hwep->dir == TX in prepare_td_for_non_sg()
459 && (hwreq->req.length % hwep->ep.maxpacket == 0)) { in prepare_td_for_non_sg()
474 hwreq->req.actual = 0; in prepare_td_per_sg()
483 rest -= count; in prepare_td_per_sg()
491 int empty_td_slot_index = (CI_MAX_BUF_SIZE - node->td_remaining_size) in ci_add_buffer_entry()
496 token = le32_to_cpu(node->ptr->token) + (sg_dma_len(s) << __ffs(TD_TOTAL_BYTES)); in ci_add_buffer_entry()
497 node->ptr->token = cpu_to_le32(token); in ci_add_buffer_entry()
501 (i - empty_td_slot_index) * CI_HDRC_PAGE_SIZE; in ci_add_buffer_entry()
504 node->ptr->page[i] = cpu_to_le32(page); in ci_add_buffer_entry()
510 struct usb_request *req = &hwreq->req; in prepare_td_for_sg()
511 struct scatterlist *s = req->sg; in prepare_td_for_sg()
515 if (!s || req->zero || req->length == 0) { in prepare_td_for_sg()
516 dev_err(hwep->ci->dev, "not supported operation for sg\n"); in prepare_td_for_sg()
517 return -EINVAL; in prepare_td_for_sg()
520 while (i++ < req->num_mapped_sgs) { in prepare_td_for_sg()
522 dev_err(hwep->ci->dev, "not page aligned sg buffer\n"); in prepare_td_for_sg()
523 return -EINVAL; in prepare_td_for_sg()
526 if (node && (node->td_remaining_size >= sg_dma_len(s))) { in prepare_td_for_sg()
528 node->td_remaining_size -= sg_dma_len(s); in prepare_td_for_sg()
534 node = list_entry(hwreq->tds.prev, in prepare_td_for_sg()
552 struct scatterlist *s = req->sg; in sglist_get_invalid_entry()
554 if (req->num_sgs == 1) in sglist_get_invalid_entry()
559 for (i = 0; i < req->num_sgs; i++, s = sg_next(s)) { in sglist_get_invalid_entry()
561 * that happens. we can't ensure the addr is page-aligned in sglist_get_invalid_entry()
564 if (dma_kmalloc_needs_bounce(dma_dev, s->length, dir)) in sglist_get_invalid_entry()
568 * page-aligned and end address (except last sg) is also in sglist_get_invalid_entry()
569 * page-aligned. in sglist_get_invalid_entry()
572 if (!IS_ALIGNED(s->offset + s->length, in sglist_get_invalid_entry()
576 if (s->offset) in sglist_get_invalid_entry()
578 if (!sg_is_last(s) && !IS_ALIGNED(s->length, in sglist_get_invalid_entry()
596 ret = sg_alloc_table(&hwreq->sgt, nents, GFP_KERNEL); in sglist_do_bounce()
600 sg = src = hwreq->req.sg; in sglist_do_bounce()
601 num_sgs = hwreq->req.num_sgs; in sglist_do_bounce()
602 rest = hwreq->req.length; in sglist_do_bounce()
603 dst = hwreq->sgt.sgl; in sglist_do_bounce()
607 rest -= src->length; in sglist_do_bounce()
616 sg_free_table(&hwreq->sgt); in sglist_do_bounce()
617 return -ENOMEM; in sglist_do_bounce()
622 hwreq->req.sg = hwreq->sgt.sgl; in sglist_do_bounce()
623 hwreq->req.num_sgs = nents; in sglist_do_bounce()
624 hwreq->sgt.sgl = sg; in sglist_do_bounce()
625 hwreq->sgt.nents = num_sgs; in sglist_do_bounce()
628 sg_copy_to_buffer(src, num_sgs - index, buf, rest); in sglist_do_bounce()
641 sg = hwreq->req.sg; in sglist_do_debounce()
642 num_sgs = hwreq->req.num_sgs; in sglist_do_debounce()
647 dst = hwreq->sgt.sgl; in sglist_do_debounce()
648 for (i = 0; i < num_sgs - 1; i++) in sglist_do_debounce()
651 nents = hwreq->sgt.nents - num_sgs + 1; in sglist_do_debounce()
655 hwreq->req.sg = hwreq->sgt.sgl; in sglist_do_debounce()
656 hwreq->req.num_sgs = hwreq->sgt.nents; in sglist_do_debounce()
657 hwreq->sgt.sgl = sg; in sglist_do_debounce()
658 hwreq->sgt.nents = num_sgs; in sglist_do_debounce()
661 sg_free_table(&hwreq->sgt); in sglist_do_debounce()
673 struct ci_hdrc *ci = hwep->ci; in _hardware_enqueue()
680 if (hwreq->req.status == -EALREADY) in _hardware_enqueue()
681 return -EALREADY; in _hardware_enqueue()
683 hwreq->req.status = -EALREADY; in _hardware_enqueue()
685 if (hwreq->req.num_sgs && hwreq->req.length && in _hardware_enqueue()
686 ci->has_short_pkt_limit) { in _hardware_enqueue()
687 ret = sglist_get_invalid_entry(ci->dev->parent, hwep->dir, in _hardware_enqueue()
688 &hwreq->req); in _hardware_enqueue()
689 if (ret < hwreq->req.num_sgs) { in _hardware_enqueue()
690 ret = sglist_do_bounce(hwreq, ret, hwep->dir == TX, in _hardware_enqueue()
697 ret = usb_gadget_map_request_by_dev(ci->dev->parent, in _hardware_enqueue()
698 &hwreq->req, hwep->dir); in _hardware_enqueue()
702 if (hwreq->sgt.sgl) { in _hardware_enqueue()
704 sg = sg_last(hwreq->req.sg, hwreq->req.num_sgs); in _hardware_enqueue()
708 if (hwreq->req.num_mapped_sgs) in _hardware_enqueue()
716 lastnode = list_entry(hwreq->tds.prev, in _hardware_enqueue()
719 lastnode->ptr->next = cpu_to_le32(TD_TERMINATE); in _hardware_enqueue()
720 if (!hwreq->req.no_interrupt) in _hardware_enqueue()
721 lastnode->ptr->token |= cpu_to_le32(TD_IOC); in _hardware_enqueue()
723 list_for_each_entry_safe(firstnode, lastnode, &hwreq->tds, td) in _hardware_enqueue()
726 firstnode = list_first_entry(&hwreq->tds, struct td_node, td); in _hardware_enqueue()
730 hwreq->req.actual = 0; in _hardware_enqueue()
731 if (!list_empty(&hwep->qh.queue)) { in _hardware_enqueue()
733 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_enqueue()
736 u32 next = firstnode->dma & TD_ADDR_MASK; in _hardware_enqueue()
738 hwreqprev = list_entry(hwep->qh.queue.prev, in _hardware_enqueue()
740 prevlastnode = list_entry(hwreqprev->tds.prev, in _hardware_enqueue()
743 prevlastnode->ptr->next = cpu_to_le32(next); in _hardware_enqueue()
746 if (ci->rev == CI_REVISION_22) { in _hardware_enqueue()
765 if (hwep->qh.ptr->curr != cpu_to_le32(prevlastnode->dma)) in _hardware_enqueue()
770 hwep->qh.ptr->td.next = cpu_to_le32(firstnode->dma); in _hardware_enqueue()
771 hwep->qh.ptr->td.token &= in _hardware_enqueue()
774 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == RX) { in _hardware_enqueue()
775 u32 mul = hwreq->req.length / hwep->ep.maxpacket; in _hardware_enqueue()
777 if (hwreq->req.length == 0 in _hardware_enqueue()
778 || hwreq->req.length % hwep->ep.maxpacket) in _hardware_enqueue()
780 hwep->qh.ptr->cap |= cpu_to_le32(mul << __ffs(QH_MULT)); in _hardware_enqueue()
783 ret = hw_ep_prime(ci, hwep->num, hwep->dir, in _hardware_enqueue()
784 hwep->type == USB_ENDPOINT_XFER_CONTROL); in _hardware_enqueue()
795 struct td_node *pending = hwep->pending_td; in free_pending_td()
797 dma_pool_free(hwep->td_pool, pending->ptr, pending->dma); in free_pending_td()
798 hwep->pending_td = NULL; in free_pending_td()
805 hwep->qh.ptr->td.next = cpu_to_le32(node->dma); in reprime_dtd()
806 hwep->qh.ptr->td.token &= in reprime_dtd()
809 return hw_ep_prime(ci, hwep->num, hwep->dir, in reprime_dtd()
810 hwep->type == USB_ENDPOINT_XFER_CONTROL); in reprime_dtd()
825 unsigned actual = hwreq->req.length; in _hardware_dequeue()
826 struct ci_hdrc *ci = hwep->ci; in _hardware_dequeue()
827 bool is_isoc = hwep->type == USB_ENDPOINT_XFER_ISOC; in _hardware_dequeue()
829 if (hwreq->req.status != -EALREADY) in _hardware_dequeue()
830 return -EINVAL; in _hardware_dequeue()
832 hwreq->req.status = 0; in _hardware_dequeue()
834 list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) { in _hardware_dequeue()
835 tmptoken = le32_to_cpu(node->ptr->token); in _hardware_dequeue()
838 int n = hw_ep_bit(hwep->num, hwep->dir); in _hardware_dequeue()
840 if (ci->rev == CI_REVISION_24 || in _hardware_dequeue()
841 ci->rev == CI_REVISION_22 || is_isoc) in _hardware_dequeue()
844 hwreq->req.status = -EALREADY; in _hardware_dequeue()
845 return -EBUSY; in _hardware_dequeue()
850 actual -= remaining_length; in _hardware_dequeue()
852 hwreq->req.status = tmptoken & TD_STATUS; in _hardware_dequeue()
853 if ((TD_STATUS_HALTED & hwreq->req.status)) { in _hardware_dequeue()
854 hwreq->req.status = -EPIPE; in _hardware_dequeue()
856 } else if ((TD_STATUS_DT_ERR & hwreq->req.status)) { in _hardware_dequeue()
857 hwreq->req.status = -EPROTO; in _hardware_dequeue()
859 } else if ((TD_STATUS_TR_ERR & hwreq->req.status)) { in _hardware_dequeue()
861 hwreq->req.status = 0; in _hardware_dequeue()
863 hwreq->req.status = -EILSEQ; in _hardware_dequeue()
869 if (hwep->dir == TX) { in _hardware_dequeue()
870 hwreq->req.status = -EPROTO; in _hardware_dequeue()
879 if (hwep->pending_td) in _hardware_dequeue()
882 hwep->pending_td = node; in _hardware_dequeue()
883 list_del_init(&node->td); in _hardware_dequeue()
886 usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, in _hardware_dequeue()
887 &hwreq->req, hwep->dir); in _hardware_dequeue()
890 if (hwreq->sgt.sgl) in _hardware_dequeue()
891 sglist_do_debounce(hwreq, hwep->dir == RX); in _hardware_dequeue()
893 hwreq->req.actual += actual; in _hardware_dequeue()
895 if (hwreq->req.status) in _hardware_dequeue()
896 return hwreq->req.status; in _hardware_dequeue()
898 return hwreq->req.actual; in _hardware_dequeue()
909 __releases(hwep->lock) in _ep_nuke()
910 __acquires(hwep->lock) in _ep_nuke()
914 return -EINVAL; in _ep_nuke()
916 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in _ep_nuke()
918 while (!list_empty(&hwep->qh.queue)) { in _ep_nuke()
921 struct ci_hw_req *hwreq = list_entry(hwep->qh.queue.next, in _ep_nuke()
924 list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) { in _ep_nuke()
925 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in _ep_nuke()
926 list_del_init(&node->td); in _ep_nuke()
927 node->ptr = NULL; in _ep_nuke()
931 list_del_init(&hwreq->queue); in _ep_nuke()
932 hwreq->req.status = -ESHUTDOWN; in _ep_nuke()
934 if (hwreq->req.complete != NULL) { in _ep_nuke()
935 spin_unlock(hwep->lock); in _ep_nuke()
936 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in _ep_nuke()
937 spin_lock(hwep->lock); in _ep_nuke()
941 if (hwep->pending_td) in _ep_nuke()
953 if (ep == NULL || hwep->ep.desc == NULL) in _ep_set_halt()
954 return -EINVAL; in _ep_set_halt()
956 if (usb_endpoint_xfer_isoc(hwep->ep.desc)) in _ep_set_halt()
957 return -EOPNOTSUPP; in _ep_set_halt()
959 spin_lock_irqsave(hwep->lock, flags); in _ep_set_halt()
961 if (value && hwep->dir == TX && check_transfer && in _ep_set_halt()
962 !list_empty(&hwep->qh.queue) && in _ep_set_halt()
963 !usb_endpoint_xfer_control(hwep->ep.desc)) { in _ep_set_halt()
964 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
965 return -EAGAIN; in _ep_set_halt()
968 direction = hwep->dir; in _ep_set_halt()
970 retval |= hw_ep_set_halt(hwep->ci, hwep->num, hwep->dir, value); in _ep_set_halt()
973 hwep->wedge = 0; in _ep_set_halt()
975 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in _ep_set_halt()
976 hwep->dir = (hwep->dir == TX) ? RX : TX; in _ep_set_halt()
978 } while (hwep->dir != direction); in _ep_set_halt()
980 spin_unlock_irqrestore(hwep->lock, flags); in _ep_set_halt()
1001 usb_ep_fifo_flush(&ci->ep0out->ep); in _gadget_stop_activity()
1002 usb_ep_fifo_flush(&ci->ep0in->ep); in _gadget_stop_activity()
1009 if (ci->status != NULL) { in _gadget_stop_activity()
1010 usb_ep_free_request(&ci->ep0in->ep, ci->status); in _gadget_stop_activity()
1011 ci->status = NULL; in _gadget_stop_activity()
1014 spin_lock_irqsave(&ci->lock, flags); in _gadget_stop_activity()
1015 ci->gadget.speed = USB_SPEED_UNKNOWN; in _gadget_stop_activity()
1016 ci->remote_wakeup = 0; in _gadget_stop_activity()
1017 ci->suspended = 0; in _gadget_stop_activity()
1018 spin_unlock_irqrestore(&ci->lock, flags); in _gadget_stop_activity()
1033 __releases(ci->lock) in isr_reset_handler()
1034 __acquires(ci->lock) in isr_reset_handler()
1039 spin_unlock(&ci->lock); in isr_reset_handler()
1040 if (ci->gadget.speed != USB_SPEED_UNKNOWN) in isr_reset_handler()
1041 usb_gadget_udc_reset(&ci->gadget, ci->driver); in isr_reset_handler()
1043 retval = _gadget_stop_activity(&ci->gadget); in isr_reset_handler()
1056 ci->status = usb_ep_alloc_request(&ci->ep0in->ep, GFP_ATOMIC); in isr_reset_handler()
1057 if (ci->status == NULL) in isr_reset_handler()
1058 retval = -ENOMEM; in isr_reset_handler()
1061 spin_lock(&ci->lock); in isr_reset_handler()
1064 dev_err(ci->dev, "error: %i\n", retval); in isr_reset_handler()
1079 kfree(req->buf); in isr_get_status_complete()
1097 struct ci_hdrc *ci = hwep->ci; in _ep_queue()
1100 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in _ep_queue()
1101 return -EINVAL; in _ep_queue()
1103 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in _ep_queue()
1104 if (req->length) in _ep_queue()
1105 hwep = (ci->ep0_dir == RX) ? in _ep_queue()
1106 ci->ep0out : ci->ep0in; in _ep_queue()
1107 if (!list_empty(&hwep->qh.queue)) { in _ep_queue()
1109 dev_warn(hwep->ci->dev, "endpoint ctrl %X nuked\n", in _ep_queue()
1114 if (usb_endpoint_xfer_isoc(hwep->ep.desc) && in _ep_queue()
1115 hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) { in _ep_queue()
1116 dev_err(hwep->ci->dev, "request length too big for isochronous\n"); in _ep_queue()
1117 return -EMSGSIZE; in _ep_queue()
1120 if (ci->has_short_pkt_limit && in _ep_queue()
1121 hwreq->req.length > CI_MAX_REQ_SIZE) { in _ep_queue()
1122 dev_err(hwep->ci->dev, "request length too big (max 16KB)\n"); in _ep_queue()
1123 return -EMSGSIZE; in _ep_queue()
1127 if (!list_empty(&hwreq->queue)) { in _ep_queue()
1128 dev_err(hwep->ci->dev, "request already in queue\n"); in _ep_queue()
1129 return -EBUSY; in _ep_queue()
1133 hwreq->req.status = -EINPROGRESS; in _ep_queue()
1134 hwreq->req.actual = 0; in _ep_queue()
1138 if (retval == -EALREADY) in _ep_queue()
1141 list_add_tail(&hwreq->queue, &hwep->qh.queue); in _ep_queue()
1155 __releases(hwep->lock) in isr_get_status_response()
1156 __acquires(hwep->lock) in isr_get_status_response()
1158 struct ci_hw_ep *hwep = ci->ep0in; in isr_get_status_response()
1164 return -EINVAL; in isr_get_status_response()
1166 spin_unlock(hwep->lock); in isr_get_status_response()
1167 req = usb_ep_alloc_request(&hwep->ep, gfp_flags); in isr_get_status_response()
1168 spin_lock(hwep->lock); in isr_get_status_response()
1170 return -ENOMEM; in isr_get_status_response()
1172 req->complete = isr_get_status_complete; in isr_get_status_response()
1173 req->length = 2; in isr_get_status_response()
1174 req->buf = kzalloc(req->length, gfp_flags); in isr_get_status_response()
1175 if (req->buf == NULL) { in isr_get_status_response()
1176 retval = -ENOMEM; in isr_get_status_response()
1180 if ((setup->bRequestType & USB_RECIP_MASK) == USB_RECIP_DEVICE) { in isr_get_status_response()
1181 *(u16 *)req->buf = (ci->remote_wakeup << 1) | in isr_get_status_response()
1182 ci->gadget.is_selfpowered; in isr_get_status_response()
1183 } else if ((setup->bRequestType & USB_RECIP_MASK) \ in isr_get_status_response()
1185 dir = (le16_to_cpu(setup->wIndex) & USB_ENDPOINT_DIR_MASK) ? in isr_get_status_response()
1187 num = le16_to_cpu(setup->wIndex) & USB_ENDPOINT_NUMBER_MASK; in isr_get_status_response()
1188 *(u16 *)req->buf = hw_ep_get_halt(ci, num, dir); in isr_get_status_response()
1192 retval = _ep_queue(&hwep->ep, req, gfp_flags); in isr_get_status_response()
1199 kfree(req->buf); in isr_get_status_response()
1201 spin_unlock(hwep->lock); in isr_get_status_response()
1202 usb_ep_free_request(&hwep->ep, req); in isr_get_status_response()
1203 spin_lock(hwep->lock); in isr_get_status_response()
1218 struct ci_hdrc *ci = req->context; in isr_setup_status_complete()
1221 if (req->status < 0) in isr_setup_status_complete()
1224 if (ci->setaddr) { in isr_setup_status_complete()
1225 hw_usb_set_address(ci, ci->address); in isr_setup_status_complete()
1226 ci->setaddr = false; in isr_setup_status_complete()
1227 if (ci->address) in isr_setup_status_complete()
1228 usb_gadget_set_state(&ci->gadget, USB_STATE_ADDRESS); in isr_setup_status_complete()
1231 spin_lock_irqsave(&ci->lock, flags); in isr_setup_status_complete()
1232 if (ci->test_mode) in isr_setup_status_complete()
1233 hw_port_test_set(ci, ci->test_mode); in isr_setup_status_complete()
1234 spin_unlock_irqrestore(&ci->lock, flags); in isr_setup_status_complete()
1250 * being called with ci->status equal to NULL. in isr_setup_status_phase()
1253 if (WARN_ON_ONCE(!ci->status)) in isr_setup_status_phase()
1254 return -EPIPE; in isr_setup_status_phase()
1256 hwep = (ci->ep0_dir == TX) ? ci->ep0out : ci->ep0in; in isr_setup_status_phase()
1257 ci->status->context = ci; in isr_setup_status_phase()
1258 ci->status->complete = isr_setup_status_complete; in isr_setup_status_phase()
1260 return _ep_queue(&hwep->ep, ci->status, GFP_ATOMIC); in isr_setup_status_phase()
1271 __releases(hwep->lock) in isr_tr_complete_low()
1272 __acquires(hwep->lock) in isr_tr_complete_low()
1278 list_for_each_entry_safe(hwreq, hwreqtemp, &hwep->qh.queue, in isr_tr_complete_low()
1283 list_del_init(&hwreq->queue); in isr_tr_complete_low()
1284 if (hwreq->req.complete != NULL) { in isr_tr_complete_low()
1285 spin_unlock(hwep->lock); in isr_tr_complete_low()
1286 if ((hwep->type == USB_ENDPOINT_XFER_CONTROL) && in isr_tr_complete_low()
1287 hwreq->req.length) in isr_tr_complete_low()
1288 hweptemp = hwep->ci->ep0in; in isr_tr_complete_low()
1289 usb_gadget_giveback_request(&hweptemp->ep, &hwreq->req); in isr_tr_complete_low()
1290 spin_lock(hwep->lock); in isr_tr_complete_low()
1294 if (retval == -EBUSY) in isr_tr_complete_low()
1302 dev_warn(&ci->gadget.dev, in otg_a_alt_hnp_support()
1314 __releases(ci->lock) in isr_setup_packet_handler()
1315 __acquires(ci->lock) in isr_setup_packet_handler()
1317 struct ci_hw_ep *hwep = &ci->ci_hw_ep[0]; in isr_setup_packet_handler()
1319 int type, num, dir, err = -EINVAL; in isr_setup_packet_handler()
1326 _ep_nuke(ci->ep0out); in isr_setup_packet_handler()
1327 _ep_nuke(ci->ep0in); in isr_setup_packet_handler()
1332 memcpy(&req, &hwep->qh.ptr->setup, sizeof(req)); in isr_setup_packet_handler()
1337 ci->ep0_dir = (type & USB_DIR_IN) ? TX : RX; in isr_setup_packet_handler()
1350 num += ci->hw_ep_max / 2; in isr_setup_packet_handler()
1351 if (!ci->ci_hw_ep[num].wedge) { in isr_setup_packet_handler()
1352 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1354 &ci->ci_hw_ep[num].ep); in isr_setup_packet_handler()
1355 spin_lock(&ci->lock); in isr_setup_packet_handler()
1365 ci->remote_wakeup = 0; in isr_setup_packet_handler()
1388 ci->address = (u8)le16_to_cpu(req.wValue); in isr_setup_packet_handler()
1389 ci->setaddr = true; in isr_setup_packet_handler()
1402 num += ci->hw_ep_max / 2; in isr_setup_packet_handler()
1404 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1405 err = _ep_set_halt(&ci->ci_hw_ep[num].ep, 1, false); in isr_setup_packet_handler()
1406 spin_lock(&ci->lock); in isr_setup_packet_handler()
1414 ci->remote_wakeup = 1; in isr_setup_packet_handler()
1425 ci->test_mode = tmode; in isr_setup_packet_handler()
1435 ci->gadget.b_hnp_enable = 1; in isr_setup_packet_handler()
1446 ci->gadget.a_hnp_support = 1; in isr_setup_packet_handler()
1461 ci->ep0_dir = TX; in isr_setup_packet_handler()
1463 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1464 err = ci->driver->setup(&ci->gadget, &req); in isr_setup_packet_handler()
1465 spin_lock(&ci->lock); in isr_setup_packet_handler()
1470 spin_unlock(&ci->lock); in isr_setup_packet_handler()
1471 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_setup_packet_handler()
1472 dev_err(ci->dev, "error: _ep_set_halt\n"); in isr_setup_packet_handler()
1473 spin_lock(&ci->lock); in isr_setup_packet_handler()
1484 __releases(ci->lock) in isr_tr_complete_handler()
1485 __acquires(ci->lock) in isr_tr_complete_handler()
1490 for (i = 0; i < ci->hw_ep_max; i++) { in isr_tr_complete_handler()
1491 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in isr_tr_complete_handler()
1493 if (hwep->ep.desc == NULL) in isr_tr_complete_handler()
1498 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) { in isr_tr_complete_handler()
1502 spin_unlock(&ci->lock); in isr_tr_complete_handler()
1503 if (_ep_set_halt(&hwep->ep, 1, false)) in isr_tr_complete_handler()
1504 dev_err(ci->dev, in isr_tr_complete_handler()
1506 spin_lock(&ci->lock); in isr_tr_complete_handler()
1535 return -EINVAL; in ep_enable()
1537 spin_lock_irqsave(hwep->lock, flags); in ep_enable()
1541 if (!list_empty(&hwep->qh.queue)) { in ep_enable()
1542 dev_warn(hwep->ci->dev, "enabling a non-empty endpoint!\n"); in ep_enable()
1543 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1544 return -EBUSY; in ep_enable()
1547 hwep->ep.desc = desc; in ep_enable()
1549 hwep->dir = usb_endpoint_dir_in(desc) ? TX : RX; in ep_enable()
1550 hwep->num = usb_endpoint_num(desc); in ep_enable()
1551 hwep->type = usb_endpoint_type(desc); in ep_enable()
1553 hwep->ep.maxpacket = usb_endpoint_maxp(desc); in ep_enable()
1554 hwep->ep.mult = usb_endpoint_maxp_mult(desc); in ep_enable()
1556 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_enable()
1560 cap |= (hwep->ep.maxpacket << __ffs(QH_MAX_PKT)) & QH_MAX_PKT; in ep_enable()
1562 * For ISO-TX, we set mult at QH as the largest value, and use in ep_enable()
1565 if (hwep->type == USB_ENDPOINT_XFER_ISOC && hwep->dir == TX) in ep_enable()
1568 hwep->qh.ptr->cap = cpu_to_le32(cap); in ep_enable()
1570 hwep->qh.ptr->td.next |= cpu_to_le32(TD_TERMINATE); /* needed? */ in ep_enable()
1572 if (hwep->num != 0 && hwep->type == USB_ENDPOINT_XFER_CONTROL) { in ep_enable()
1573 dev_err(hwep->ci->dev, "Set control xfer at non-ep0\n"); in ep_enable()
1574 retval = -EINVAL; in ep_enable()
1581 if (hwep->num) in ep_enable()
1582 retval |= hw_ep_enable(hwep->ci, hwep->num, hwep->dir, in ep_enable()
1583 hwep->type); in ep_enable()
1585 spin_unlock_irqrestore(hwep->lock, flags); in ep_enable()
1601 return -EINVAL; in ep_disable()
1602 else if (hwep->ep.desc == NULL) in ep_disable()
1603 return -EBUSY; in ep_disable()
1605 spin_lock_irqsave(hwep->lock, flags); in ep_disable()
1606 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_disable()
1607 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1613 direction = hwep->dir; in ep_disable()
1616 retval |= hw_ep_disable(hwep->ci, hwep->num, hwep->dir); in ep_disable()
1618 if (hwep->type == USB_ENDPOINT_XFER_CONTROL) in ep_disable()
1619 hwep->dir = (hwep->dir == TX) ? RX : TX; in ep_disable()
1621 } while (hwep->dir != direction); in ep_disable()
1623 hwep->ep.desc = NULL; in ep_disable()
1625 spin_unlock_irqrestore(hwep->lock, flags); in ep_disable()
1643 INIT_LIST_HEAD(&hwreq->queue); in ep_alloc_request()
1644 INIT_LIST_HEAD(&hwreq->tds); in ep_alloc_request()
1647 return (hwreq == NULL) ? NULL : &hwreq->req; in ep_alloc_request()
1664 } else if (!list_empty(&hwreq->queue)) { in ep_free_request()
1665 dev_err(hwep->ci->dev, "freeing queued request\n"); in ep_free_request()
1669 spin_lock_irqsave(hwep->lock, flags); in ep_free_request()
1671 list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) { in ep_free_request()
1672 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_free_request()
1673 list_del_init(&node->td); in ep_free_request()
1674 node->ptr = NULL; in ep_free_request()
1680 spin_unlock_irqrestore(hwep->lock, flags); in ep_free_request()
1695 if (ep == NULL || req == NULL || hwep->ep.desc == NULL) in ep_queue()
1696 return -EINVAL; in ep_queue()
1698 spin_lock_irqsave(hwep->lock, flags); in ep_queue()
1699 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_queue()
1700 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1704 spin_unlock_irqrestore(hwep->lock, flags); in ep_queue()
1720 if (ep == NULL || req == NULL || hwreq->req.status != -EALREADY || in ep_dequeue()
1721 hwep->ep.desc == NULL || list_empty(&hwreq->queue) || in ep_dequeue()
1722 list_empty(&hwep->qh.queue)) in ep_dequeue()
1723 return -EINVAL; in ep_dequeue()
1725 spin_lock_irqsave(hwep->lock, flags); in ep_dequeue()
1726 if (hwep->ci->gadget.speed != USB_SPEED_UNKNOWN) in ep_dequeue()
1727 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_dequeue()
1729 list_for_each_entry_safe(node, tmpnode, &hwreq->tds, td) { in ep_dequeue()
1730 dma_pool_free(hwep->td_pool, node->ptr, node->dma); in ep_dequeue()
1731 list_del(&node->td); in ep_dequeue()
1736 list_del_init(&hwreq->queue); in ep_dequeue()
1738 usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); in ep_dequeue()
1740 if (hwreq->sgt.sgl) in ep_dequeue()
1743 req->status = -ECONNRESET; in ep_dequeue()
1745 if (hwreq->req.complete != NULL) { in ep_dequeue()
1746 spin_unlock(hwep->lock); in ep_dequeue()
1747 usb_gadget_giveback_request(&hwep->ep, &hwreq->req); in ep_dequeue()
1748 spin_lock(hwep->lock); in ep_dequeue()
1751 spin_unlock_irqrestore(hwep->lock, flags); in ep_dequeue()
1775 if (ep == NULL || hwep->ep.desc == NULL) in ep_set_wedge()
1776 return -EINVAL; in ep_set_wedge()
1778 spin_lock_irqsave(hwep->lock, flags); in ep_set_wedge()
1779 hwep->wedge = 1; in ep_set_wedge()
1780 spin_unlock_irqrestore(hwep->lock, flags); in ep_set_wedge()
1796 dev_err(hwep->ci->dev, "%02X: -EINVAL\n", _usb_addr(hwep)); in ep_fifo_flush()
1800 spin_lock_irqsave(hwep->lock, flags); in ep_fifo_flush()
1801 if (hwep->ci->gadget.speed == USB_SPEED_UNKNOWN) { in ep_fifo_flush()
1802 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1806 hw_ep_flush(hwep->ci, hwep->num, hwep->dir); in ep_fifo_flush()
1808 spin_unlock_irqrestore(hwep->lock, flags); in ep_fifo_flush()
1812 * Endpoint-specific part of the API to the USB controller hardware
1837 spin_lock_irqsave(&ci->lock, flags); in ci_udc_get_frame()
1839 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_get_frame()
1851 pm_runtime_get_sync(ci->dev); in ci_hdrc_gadget_connect()
1853 spin_lock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1854 if (ci->driver) { in ci_hdrc_gadget_connect()
1855 hw_device_state(ci, ci->ep0out->qh.dma); in ci_hdrc_gadget_connect()
1857 spin_unlock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1860 spin_unlock_irq(&ci->lock); in ci_hdrc_gadget_connect()
1864 if (ci->driver) in ci_hdrc_gadget_connect()
1865 ci->driver->disconnect(&ci->gadget); in ci_hdrc_gadget_connect()
1867 if (ci->platdata->notify_event) in ci_hdrc_gadget_connect()
1868 ci->platdata->notify_event(ci, in ci_hdrc_gadget_connect()
1870 _gadget_stop_activity(&ci->gadget); in ci_hdrc_gadget_connect()
1871 pm_runtime_put_sync(ci->dev); in ci_hdrc_gadget_connect()
1882 spin_lock_irqsave(&ci->lock, flags); in ci_udc_vbus_session()
1883 ci->vbus_active = is_active; in ci_udc_vbus_session()
1884 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_vbus_session()
1886 if (ci->usb_phy) in ci_udc_vbus_session()
1887 usb_phy_set_charger_state(ci->usb_phy, is_active ? in ci_udc_vbus_session()
1890 if (ci->platdata->notify_event) in ci_udc_vbus_session()
1891 ret = ci->platdata->notify_event(ci, in ci_udc_vbus_session()
1894 if (ci->usb_phy) { in ci_udc_vbus_session()
1896 usb_phy_set_event(ci->usb_phy, USB_EVENT_VBUS); in ci_udc_vbus_session()
1898 usb_phy_set_event(ci->usb_phy, USB_EVENT_NONE); in ci_udc_vbus_session()
1901 if (ci->driver) in ci_udc_vbus_session()
1913 spin_lock_irqsave(&ci->lock, flags); in ci_udc_wakeup()
1914 if (ci->gadget.speed == USB_SPEED_UNKNOWN) { in ci_udc_wakeup()
1915 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_wakeup()
1918 if (!ci->remote_wakeup) { in ci_udc_wakeup()
1919 ret = -EOPNOTSUPP; in ci_udc_wakeup()
1923 ret = -EINVAL; in ci_udc_wakeup()
1928 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_wakeup()
1936 if (ci->usb_phy) in ci_udc_vbus_draw()
1937 return usb_phy_set_power(ci->usb_phy, ma); in ci_udc_vbus_draw()
1938 return -ENOTSUPP; in ci_udc_vbus_draw()
1944 struct ci_hw_ep *hwep = ci->ep0in; in ci_udc_selfpowered()
1947 spin_lock_irqsave(hwep->lock, flags); in ci_udc_selfpowered()
1948 _gadget->is_selfpowered = (is_on != 0); in ci_udc_selfpowered()
1949 spin_unlock_irqrestore(hwep->lock, flags); in ci_udc_selfpowered()
1962 * Data+ pullup controlled by OTG state machine in OTG fsm mode; in ci_udc_pullup()
1965 if (ci_otg_is_fsm_mode(ci) || ci->role == CI_ROLE_HOST) in ci_udc_pullup()
1968 pm_runtime_get_sync(ci->dev); in ci_udc_pullup()
1974 if (ci->platdata->notify_event) { in ci_udc_pullup()
1975 _gadget->connected = is_on; in ci_udc_pullup()
1976 ci->platdata->notify_event(ci, CI_HDRC_CONTROLLER_PULLUP_EVENT); in ci_udc_pullup()
1978 pm_runtime_put_sync(ci->dev); in ci_udc_pullup()
1996 list_for_each_entry_reverse(ep, &ci->gadget.ep_list, ep_list) { in ci_udc_match_ep()
1997 if (ep->caps.dir_in && !ep->claimed) in ci_udc_match_ep()
2026 for (i = 0; i < ci->hw_ep_max/2; i++) in init_eps()
2028 int k = i + j * ci->hw_ep_max/2; in init_eps()
2029 struct ci_hw_ep *hwep = &ci->ci_hw_ep[k]; in init_eps()
2031 scnprintf(hwep->name, sizeof(hwep->name), "ep%i%s", i, in init_eps()
2034 hwep->ci = ci; in init_eps()
2035 hwep->lock = &ci->lock; in init_eps()
2036 hwep->td_pool = ci->td_pool; in init_eps()
2038 hwep->ep.name = hwep->name; in init_eps()
2039 hwep->ep.ops = &usb_ep_ops; in init_eps()
2042 hwep->ep.caps.type_control = true; in init_eps()
2044 hwep->ep.caps.type_iso = true; in init_eps()
2045 hwep->ep.caps.type_bulk = true; in init_eps()
2046 hwep->ep.caps.type_int = true; in init_eps()
2050 hwep->ep.caps.dir_in = true; in init_eps()
2052 hwep->ep.caps.dir_out = true; in init_eps()
2059 usb_ep_set_maxpacket_limit(&hwep->ep, (unsigned short)~0); in init_eps()
2061 INIT_LIST_HEAD(&hwep->qh.queue); in init_eps()
2062 hwep->qh.ptr = dma_pool_zalloc(ci->qh_pool, GFP_KERNEL, in init_eps()
2063 &hwep->qh.dma); in init_eps()
2064 if (hwep->qh.ptr == NULL) in init_eps()
2065 retval = -ENOMEM; in init_eps()
2073 ci->ep0out = hwep; in init_eps()
2075 ci->ep0in = hwep; in init_eps()
2077 usb_ep_set_maxpacket_limit(&hwep->ep, CTRL_PAYLOAD_MAX); in init_eps()
2081 list_add_tail(&hwep->ep.ep_list, &ci->gadget.ep_list); in init_eps()
2091 for (i = 0; i < ci->hw_ep_max; i++) { in destroy_eps()
2092 struct ci_hw_ep *hwep = &ci->ci_hw_ep[i]; in destroy_eps()
2094 if (hwep->pending_td) in destroy_eps()
2096 dma_pool_free(ci->qh_pool, hwep->qh.ptr, hwep->qh.dma); in destroy_eps()
2113 if (driver->disconnect == NULL) in ci_udc_start()
2114 return -EINVAL; in ci_udc_start()
2116 ci->ep0out->ep.desc = &ctrl_endpt_out_desc; in ci_udc_start()
2117 retval = usb_ep_enable(&ci->ep0out->ep); in ci_udc_start()
2121 ci->ep0in->ep.desc = &ctrl_endpt_in_desc; in ci_udc_start()
2122 retval = usb_ep_enable(&ci->ep0in->ep); in ci_udc_start()
2126 ci->driver = driver; in ci_udc_start()
2128 /* Start otg fsm for B-device */ in ci_udc_start()
2129 if (ci_otg_is_fsm_mode(ci) && ci->fsm.id) { in ci_udc_start()
2134 if (ci->vbus_active) in ci_udc_start()
2137 usb_udc_vbus_handler(&ci->gadget, false); in ci_udc_start()
2147 mutex_lock(&ci->fsm.lock); in ci_udc_stop_for_otg_fsm()
2148 if (ci->fsm.otg->state == OTG_STATE_A_PERIPHERAL) { in ci_udc_stop_for_otg_fsm()
2149 ci->fsm.a_bidl_adis_tmout = 1; in ci_udc_stop_for_otg_fsm()
2151 } else if (ci->fsm.otg->state == OTG_STATE_B_PERIPHERAL) { in ci_udc_stop_for_otg_fsm()
2152 ci->fsm.protocol = PROTO_UNDEF; in ci_udc_stop_for_otg_fsm()
2153 ci->fsm.otg->state = OTG_STATE_UNDEFINED; in ci_udc_stop_for_otg_fsm()
2155 mutex_unlock(&ci->fsm.lock); in ci_udc_stop_for_otg_fsm()
2166 spin_lock_irqsave(&ci->lock, flags); in ci_udc_stop()
2167 ci->driver = NULL; in ci_udc_stop()
2169 if (ci->vbus_active) { in ci_udc_stop()
2171 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_stop()
2172 if (ci->platdata->notify_event) in ci_udc_stop()
2173 ci->platdata->notify_event(ci, in ci_udc_stop()
2175 _gadget_stop_activity(&ci->gadget); in ci_udc_stop()
2176 spin_lock_irqsave(&ci->lock, flags); in ci_udc_stop()
2177 pm_runtime_put(ci->dev); in ci_udc_stop()
2180 spin_unlock_irqrestore(&ci->lock, flags); in ci_udc_stop()
2203 spin_lock(&ci->lock); in udc_irq()
2205 if (ci->platdata->flags & CI_HDRC_REGS_SHARED) { in udc_irq()
2208 spin_unlock(&ci->lock); in udc_irq()
2215 /* order defines priority - do NOT change it */ in udc_irq()
2220 ci->gadget.speed = hw_port_is_high_speed(ci) ? in udc_irq()
2222 if (ci->usb_phy) in udc_irq()
2223 usb_phy_set_event(ci->usb_phy, in udc_irq()
2225 if (ci->suspended) { in udc_irq()
2226 if (ci->driver->resume) { in udc_irq()
2227 spin_unlock(&ci->lock); in udc_irq()
2228 ci->driver->resume(&ci->gadget); in udc_irq()
2229 spin_lock(&ci->lock); in udc_irq()
2231 ci->suspended = 0; in udc_irq()
2232 usb_gadget_set_state(&ci->gadget, in udc_irq()
2233 ci->resume_state); in udc_irq()
2240 if ((USBi_SLI & intr) && !(ci->suspended)) { in udc_irq()
2241 ci->suspended = 1; in udc_irq()
2242 ci->resume_state = ci->gadget.state; in udc_irq()
2243 if (ci->gadget.speed != USB_SPEED_UNKNOWN && in udc_irq()
2244 ci->driver->suspend) { in udc_irq()
2245 spin_unlock(&ci->lock); in udc_irq()
2246 ci->driver->suspend(&ci->gadget); in udc_irq()
2247 spin_lock(&ci->lock); in udc_irq()
2249 usb_gadget_set_state(&ci->gadget, in udc_irq()
2256 spin_unlock(&ci->lock); in udc_irq()
2267 struct device *dev = ci->dev; in udc_start()
2268 struct usb_otg_caps *otg_caps = &ci->platdata->ci_otg_caps; in udc_start()
2271 ci->gadget.ops = &usb_gadget_ops; in udc_start()
2272 ci->gadget.speed = USB_SPEED_UNKNOWN; in udc_start()
2273 ci->gadget.max_speed = USB_SPEED_HIGH; in udc_start()
2274 ci->gadget.name = ci->platdata->name; in udc_start()
2275 ci->gadget.otg_caps = otg_caps; in udc_start()
2276 ci->gadget.sg_supported = 1; in udc_start()
2277 ci->gadget.irq = ci->irq; in udc_start()
2279 if (ci->platdata->flags & CI_HDRC_REQUIRES_ALIGNED_DMA) in udc_start()
2280 ci->gadget.quirk_avoids_skb_reserve = 1; in udc_start()
2282 if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support || in udc_start()
2283 otg_caps->adp_support)) in udc_start()
2284 ci->gadget.is_otg = 1; in udc_start()
2286 INIT_LIST_HEAD(&ci->gadget.ep_list); in udc_start()
2289 ci->qh_pool = dma_pool_create("ci_hw_qh", dev->parent, in udc_start()
2292 if (ci->qh_pool == NULL) in udc_start()
2293 return -ENOMEM; in udc_start()
2295 ci->td_pool = dma_pool_create("ci_hw_td", dev->parent, in udc_start()
2298 if (ci->td_pool == NULL) { in udc_start()
2299 retval = -ENOMEM; in udc_start()
2307 ci->gadget.ep0 = &ci->ep0in->ep; in udc_start()
2309 retval = usb_add_gadget_udc(dev, &ci->gadget); in udc_start()
2318 dma_pool_destroy(ci->td_pool); in udc_start()
2320 dma_pool_destroy(ci->qh_pool); in udc_start()
2331 if (!ci->roles[CI_ROLE_GADGET]) in ci_hdrc_gadget_destroy()
2334 usb_del_gadget_udc(&ci->gadget); in ci_hdrc_gadget_destroy()
2338 dma_pool_destroy(ci->td_pool); in ci_hdrc_gadget_destroy()
2339 dma_pool_destroy(ci->qh_pool); in ci_hdrc_gadget_destroy()
2344 if (ci->platdata->pins_device) in udc_id_switch_for_device()
2345 pinctrl_select_state(ci->platdata->pctl, in udc_id_switch_for_device()
2346 ci->platdata->pins_device); in udc_id_switch_for_device()
2348 if (ci->is_otg) in udc_id_switch_for_device()
2362 if (ci->is_otg) in udc_id_switch_for_host()
2365 ci->vbus_active = 0; in udc_id_switch_for_host()
2367 if (ci->platdata->pins_device && ci->platdata->pins_default) in udc_id_switch_for_host()
2368 pinctrl_select_state(ci->platdata->pctl, in udc_id_switch_for_host()
2369 ci->platdata->pins_default); in udc_id_switch_for_host()
2376 * Set OP_ENDPTLISTADDR to be non-zero for in udc_suspend()
2378 * in non-host mode. in udc_suspend()
2383 if (ci->gadget.connected && in udc_suspend()
2384 (!ci->suspended || !device_may_wakeup(ci->dev))) in udc_suspend()
2385 usb_gadget_disconnect(&ci->gadget); in udc_suspend()
2391 if (ci->is_otg) in udc_resume()
2394 if (ci->vbus_active) in udc_resume()
2395 usb_gadget_vbus_disconnect(&ci->gadget); in udc_resume()
2396 } else if (ci->vbus_active && ci->driver && in udc_resume()
2397 !ci->gadget.connected) { in udc_resume()
2398 usb_gadget_connect(&ci->gadget); in udc_resume()
2408 * ci_hdrc_gadget_init - initialize device related bits
2419 return -ENXIO; in ci_hdrc_gadget_init()
2421 rdrv = devm_kzalloc(ci->dev, sizeof(*rdrv), GFP_KERNEL); in ci_hdrc_gadget_init()
2423 return -ENOMEM; in ci_hdrc_gadget_init()
2425 rdrv->start = udc_id_switch_for_device; in ci_hdrc_gadget_init()
2426 rdrv->stop = udc_id_switch_for_host; in ci_hdrc_gadget_init()
2428 rdrv->suspend = udc_suspend; in ci_hdrc_gadget_init()
2429 rdrv->resume = udc_resume; in ci_hdrc_gadget_init()
2431 rdrv->irq = udc_irq; in ci_hdrc_gadget_init()
2432 rdrv->name = "gadget"; in ci_hdrc_gadget_init()
2436 ci->roles[CI_ROLE_GADGET] = rdrv; in ci_hdrc_gadget_init()