Lines Matching +full:endpoint +full:- +full:config

1 // SPDX-License-Identifier: GPL-2.0+
47 * controller can be enabled (minor, and not uncommon); and each endpoint
59 * - zero gadget
60 * - file storage gadget
61 * - ether gadget
64 * made of UDC's double buffering either. USB "On-The-Go" is not implemented.
67 * - the drivers tries to handle the request directly to the IO
68 * - if the IO fifo is not big enough, the remaining is send/received in
72 #define DRIVER_VERSION "2008-04-18"
91 struct pxa_udc *udc = s->private; in state_dbg_show()
94 if (!udc->driver) in state_dbg_show()
95 return -ENODEV; in state_dbg_show()
102 udc->driver ? udc->driver->driver.name : "(none)"); in state_dbg_show()
128 udc->stats.irqs_reset, udc->stats.irqs_suspend, in state_dbg_show()
129 udc->stats.irqs_resume, udc->stats.irqs_reconfig); in state_dbg_show()
137 struct pxa_udc *udc = s->private; in queues_dbg_show()
142 if (!udc->driver) in queues_dbg_show()
143 return -ENODEV; in queues_dbg_show()
145 /* dump endpoint queues */ in queues_dbg_show()
147 ep = &udc->pxa_ep[i]; in queues_dbg_show()
148 maxpkt = ep->fifo_size; in queues_dbg_show()
149 seq_printf(s, "%-12s max_pkt=%d %s\n", in queues_dbg_show()
152 if (list_empty(&ep->queue)) { in queues_dbg_show()
157 list_for_each_entry(req, &ep->queue, queue) { in queues_dbg_show()
159 &req->req, req->req.actual, in queues_dbg_show()
160 req->req.length, req->req.buf); in queues_dbg_show()
170 struct pxa_udc *udc = s->private; in eps_dbg_show()
175 if (!udc->driver) in eps_dbg_show()
176 return -ENODEV; in eps_dbg_show()
178 ep = &udc->pxa_ep[0]; in eps_dbg_show()
190 ep = &udc->pxa_ep[i]; in eps_dbg_show()
192 …seq_printf(s, "%-12s: IN %lu(%lu reqs), OUT %lu(%lu reqs), irqs=%lu, udccr=0x%08x, udccsr=0x%03x, … in eps_dbg_show()
194 ep->stats.in_bytes, ep->stats.in_ops, in eps_dbg_show()
195 ep->stats.out_bytes, ep->stats.out_ops, in eps_dbg_show()
196 ep->stats.irqs, in eps_dbg_show()
209 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in pxa_init_debugfs()
217 debugfs_lookup_and_remove(udc->gadget.name, usb_debug_root); in pxa_cleanup_debugfs()
231 * is_match_usb_pxa - check if usb_ep and pxa_ep match
232 * @udc_usb_ep: usb endpoint
233 * @ep: pxa endpoint
234 * @config: configuration required in pxa_ep
238 * Returns 1 if all criteria match between pxa and usb endpoint, 0 otherwise
241 int config, int interface, int altsetting) in is_match_usb_pxa() argument
243 if (usb_endpoint_num(&udc_usb_ep->desc) != ep->addr) in is_match_usb_pxa()
245 if (usb_endpoint_dir_in(&udc_usb_ep->desc) != ep->dir_in) in is_match_usb_pxa()
247 if (usb_endpoint_type(&udc_usb_ep->desc) != ep->type) in is_match_usb_pxa()
249 if ((ep->config != config) || (ep->interface != interface) in is_match_usb_pxa()
250 || (ep->alternate != altsetting)) in is_match_usb_pxa()
256 * find_pxa_ep - find pxa_ep structure matching udc_usb_ep
269 * - we rely on UDCCR register "active interface" and "active altsetting".
272 * - if we knew for sure that the pxa can handle multiple interface at the
285 int cfg = udc->config; in find_pxa_ep()
286 int iface = udc->last_interface; in find_pxa_ep()
287 int alt = udc->last_alternate; in find_pxa_ep()
289 if (udc_usb_ep == &udc->udc_usb_ep[0]) in find_pxa_ep()
290 return &udc->pxa_ep[0]; in find_pxa_ep()
293 ep = &udc->pxa_ep[i]; in find_pxa_ep()
301 * update_pxa_ep_matches - update pxa_ep cached values in all udc_usb_ep
316 udc_usb_ep = &udc->udc_usb_ep[i]; in update_pxa_ep_matches()
317 if (udc_usb_ep->pxa_ep) in update_pxa_ep_matches()
318 udc_usb_ep->pxa_ep = find_pxa_ep(udc, udc_usb_ep); in update_pxa_ep_matches()
323 * pio_irq_enable - Enables irq generation for one endpoint
324 * @ep: udc endpoint
328 struct pxa_udc *udc = ep->dev; in pio_irq_enable()
336 udc_writel(udc, UDCICR1, udcicr1 | (3 << ((index - 16) * 2))); in pio_irq_enable()
340 * pio_irq_disable - Disables irq generation for one endpoint
341 * @ep: udc endpoint
345 struct pxa_udc *udc = ep->dev; in pio_irq_disable()
353 udc_writel(udc, UDCICR1, udcicr1 & ~(3 << ((index - 16) * 2))); in pio_irq_disable()
357 * udc_set_mask_UDCCR - set bits in UDCCR
371 * udc_clear_mask_UDCCR - clears bits in UDCCR
385 * ep_write_UDCCSR - set bits in UDCCSR
386 * @ep: udc endpoint
402 * ep_count_bytes_remain - get how many bytes in udc endpoint
403 * @ep: udc endpoint
405 * Returns number of bytes in OUT fifos. Broken for IN fifos (-EOPNOTSUPP)
409 if (ep->dir_in) in ep_count_bytes_remain()
410 return -EOPNOTSUPP; in ep_count_bytes_remain()
415 * ep_is_empty - checks if ep has byte ready for reading
416 * @ep: udc endpoint
418 * If endpoint is the control endpoint, checks if there are bytes in the
419 * control endpoint fifo. If endpoint is a data endpoint, checks if bytes
420 * are ready for reading on OUT endpoint.
422 * Returns 0 if ep not empty, 1 if ep empty, -EOPNOTSUPP if IN endpoint
428 if (!is_ep0(ep) && ep->dir_in) in ep_is_empty()
429 return -EOPNOTSUPP; in ep_is_empty()
438 * ep_is_full - checks if ep has place to write bytes
439 * @ep: udc endpoint
441 * If endpoint is not the control endpoint and is an IN endpoint, checks if
442 * there is place to write bytes into the endpoint.
444 * Returns 0 if ep not full, 1 if ep full, -EOPNOTSUPP if OUT endpoint
450 if (!ep->dir_in) in ep_is_full()
451 return -EOPNOTSUPP; in ep_is_full()
456 * epout_has_pkt - checks if OUT endpoint fifo has a packet available
457 * @ep: pxa endpoint
459 * Returns 1 if a complete packet is available, 0 if not, -EOPNOTSUPP for IN ep.
463 if (!is_ep0(ep) && ep->dir_in) in epout_has_pkt()
464 return -EOPNOTSUPP; in epout_has_pkt()
471 * set_ep0state - Set ep0 automata state
477 struct pxa_ep *ep = &udc->pxa_ep[0]; in set_ep0state()
480 udc->ep0state = state; in set_ep0state()
481 ep_dbg(ep, "state=%s->%s, udccsr0=0x%03x, udcbcr=%d\n", old_stname, in set_ep0state()
487 * ep0_idle - Put control endpoint into idle state
496 * inc_ep_stats_reqs - Update ep stats counts
497 * @ep: physical endpoint
504 ep->stats.in_ops++; in inc_ep_stats_reqs()
506 ep->stats.out_ops++; in inc_ep_stats_reqs()
510 * inc_ep_stats_bytes - Update ep stats counts
511 * @ep: physical endpoint
512 * @count: bytes transferred on endpoint
518 ep->stats.in_bytes += count; in inc_ep_stats_bytes()
520 ep->stats.out_bytes += count; in inc_ep_stats_bytes()
524 * pxa_ep_setup - Sets up an usb physical endpoint
525 * @ep: pxa27x physical endpoint
533 new_udccr = ((ep->config << UDCCONR_CN_S) & UDCCONR_CN) in pxa_ep_setup()
534 | ((ep->interface << UDCCONR_IN_S) & UDCCONR_IN) in pxa_ep_setup()
535 | ((ep->alternate << UDCCONR_AISN_S) & UDCCONR_AISN) in pxa_ep_setup()
538 | ((ep->dir_in) ? UDCCONR_ED : 0) in pxa_ep_setup()
539 | ((ep->fifo_size << UDCCONR_MPS_S) & UDCCONR_MPS) in pxa_ep_setup()
546 * pxa_eps_setup - Sets up all usb physical endpoints
555 dev_dbg(dev->dev, "%s: dev=%p\n", __func__, dev); in pxa_eps_setup()
558 pxa_ep_setup(&dev->pxa_ep[i]); in pxa_eps_setup()
562 * pxa_ep_alloc_request - Allocate usb request
563 * @_ep: usb endpoint
579 INIT_LIST_HEAD(&req->queue); in pxa_ep_alloc_request()
580 req->in_use = 0; in pxa_ep_alloc_request()
581 req->udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); in pxa_ep_alloc_request()
583 return &req->req; in pxa_ep_alloc_request()
587 * pxa_ep_free_request - Free usb request
588 * @_ep: usb endpoint
598 WARN_ON(!list_empty(&req->queue)); in pxa_ep_free_request()
603 * ep_add_request - add a request to the endpoint's queue
604 * @ep: usb endpoint
607 * Context: ep->lock held
609 * Queues the request in the endpoint's queue, and enables the interrupts
610 * on the endpoint.
617 req->req.length, udc_ep_readl(ep, UDCCSR)); in ep_add_request()
619 req->in_use = 1; in ep_add_request()
620 list_add_tail(&req->queue, &ep->queue); in ep_add_request()
625 * ep_del_request - removes a request from the endpoint's queue
626 * @ep: usb endpoint
629 * Context: ep->lock held
631 * Unqueue the request from the endpoint's queue. If there are no more requests
632 * on the endpoint, and if it's not the control endpoint, interrupts are
633 * disabled on the endpoint.
640 req->req.length, udc_ep_readl(ep, UDCCSR)); in ep_del_request()
642 list_del_init(&req->queue); in ep_del_request()
643 req->in_use = 0; in ep_del_request()
644 if (!is_ep0(ep) && list_empty(&ep->queue)) in ep_del_request()
649 * req_done - Complete an usb request
650 * @ep: pxa physical endpoint
655 * Context: ep->lock held if flags not NULL, else ep->lock released
657 * Retire a pxa27x usb request. Endpoint must be locked.
665 if (likely(req->req.status == -EINPROGRESS)) in req_done()
666 req->req.status = status; in req_done()
668 status = req->req.status; in req_done()
670 if (status && status != -ESHUTDOWN) in req_done()
672 &req->req, status, in req_done()
673 req->req.actual, req->req.length); in req_done()
676 spin_unlock_irqrestore(&ep->lock, *pflags); in req_done()
678 usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req); in req_done()
681 spin_lock_irqsave(&ep->lock, *pflags); in req_done()
685 * ep_end_out_req - Ends endpoint OUT request
686 * @ep: physical endpoint
690 * Context: ep->lock held or released (see req_done())
692 * Ends endpoint OUT request (completes usb request).
702 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
703 * @ep: physical endpoint
707 * Context: ep->lock held or released (see req_done())
709 * Ends control endpoint OUT request (completes usb request), and puts
710 * control endpoint into idle state
715 set_ep0state(ep->dev, OUT_STATUS_STAGE); in ep0_end_out_req()
717 ep0_idle(ep->dev); in ep0_end_out_req()
721 * ep_end_in_req - Ends endpoint IN request
722 * @ep: physical endpoint
726 * Context: ep->lock held or released (see req_done())
728 * Ends endpoint IN request (completes usb request).
738 * ep0_end_in_req - Ends control endpoint IN request (ends data stage)
739 * @ep: physical endpoint
743 * Context: ep->lock held or released (see req_done())
745 * Ends control endpoint IN request (completes usb request), and puts
746 * control endpoint into status state
751 set_ep0state(ep->dev, IN_STATUS_STAGE); in ep0_end_in_req()
756 * nuke - Dequeue all requests
757 * @ep: pxa endpoint
760 * Context: ep->lock released
762 * Dequeues all requests on an endpoint. As a side effect, interrupts will be
763 * disabled on that endpoint (because no more requests).
770 spin_lock_irqsave(&ep->lock, flags); in nuke()
771 while (!list_empty(&ep->queue)) { in nuke()
772 req = list_entry(ep->queue.next, struct pxa27x_request, queue); in nuke()
775 spin_unlock_irqrestore(&ep->lock, flags); in nuke()
779 * read_packet - transfer 1 packet from an OUT endpoint into request
780 * @ep: pxa physical endpoint
783 * Takes bytes from OUT endpoint and transfers them info the usb request.
784 * If there is less space in request than bytes received in OUT endpoint,
785 * bytes are left in the OUT endpoint.
795 bufferspace = req->req.length - req->req.actual; in read_packet()
797 buf = (u32 *)(req->req.buf + req->req.actual); in read_packet()
805 for (i = count; i > 0; i -= 4) in read_packet()
807 req->req.actual += count; in read_packet()
815 * write_packet - transfer 1 packet from request into an IN endpoint
816 * @ep: pxa physical endpoint
818 * @max: max bytes that fit into endpoint
821 * endpoint. If there are no bytes to transfer, doesn't write anything
822 * to physical endpoint.
833 buf = (u32 *)(req->req.buf + req->req.actual); in write_packet()
836 length = min(req->req.length - req->req.actual, max); in write_packet()
837 req->req.actual += length; in write_packet()
841 for (i = count; i > 0 ; i -= 4) in write_packet()
845 for (i = remain; i > 0; i--) in write_packet()
855 * read_fifo - Transfer packets from OUT endpoint into usb request
856 * @ep: pxa physical endpoint
876 is_short = (count < ep->fifo_size); in read_fifo()
879 &req->req, req->req.actual, req->req.length); in read_fifo()
882 if (is_short || req->req.actual == req->req.length) { in read_fifo()
892 * write_fifo - transfer packets from usb request into an IN endpoint
893 * @ep: pxa physical endpoint
896 * Write to an IN endpoint fifo, as many packets as possible.
909 max = ep->fifo_size; in write_fifo()
932 if (likely(req->req.length > req->req.actual) in write_fifo()
933 || req->req.zero) in write_fifo()
938 is_short = unlikely(max < ep->fifo_size); in write_fifo()
953 req->req.length - req->req.actual, &req->req); in write_fifo()
959 * read_ep0_fifo - Transfer packets from control endpoint into usb request
960 * @ep: control endpoint
964 * endpoint as can be read, and stores them into usb request (limited by request
978 is_short = (count < ep->fifo_size); in read_ep0_fifo()
981 &req->req, req->req.actual, req->req.length); in read_ep0_fifo()
983 if (is_short || req->req.actual >= req->req.length) { in read_ep0_fifo()
993 * write_ep0_fifo - Send a request to control endpoint (ep0 in)
994 * @ep: control endpoint
999 * Sends a request (or a part of the request) to the control endpoint (ep0 in).
1002 * - last write transferred all remaining bytes, but fifo was not fully filled
1003 * - last write was a 0 length write
1024 req->req.length - req->req.actual, in write_ep0_fifo()
1025 &req->req, udc_ep_readl(ep, UDCCSR)); in write_ep0_fifo()
1031 * pxa_ep_queue - Queue a request into an IN endpoint
1032 * @_ep: usb endpoint
1038 * (irq->handle_ep0_ctrl_req->gadget_setup->pxa_ep_queue)
1058 if (unlikely(!_req || !_req->complete || !_req->buf)) in pxa_ep_queue()
1059 return -EINVAL; in pxa_ep_queue()
1062 return -EINVAL; in pxa_ep_queue()
1064 ep = udc_usb_ep->pxa_ep; in pxa_ep_queue()
1066 return -EINVAL; in pxa_ep_queue()
1068 dev = ep->dev; in pxa_ep_queue()
1069 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { in pxa_ep_queue()
1071 return -ESHUTDOWN; in pxa_ep_queue()
1075 * we can report per-packet status. that also helps with dma. in pxa_ep_queue()
1078 && req->req.length > ep->fifo_size)) in pxa_ep_queue()
1079 return -EMSGSIZE; in pxa_ep_queue()
1081 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_queue()
1082 recursion_detected = ep->in_handle_ep; in pxa_ep_queue()
1084 is_first_req = list_empty(&ep->queue); in pxa_ep_queue()
1087 _req->length, _req->buf); in pxa_ep_queue()
1089 if (!ep->enabled) { in pxa_ep_queue()
1090 _req->status = -ESHUTDOWN; in pxa_ep_queue()
1091 rc = -ESHUTDOWN; in pxa_ep_queue()
1095 if (req->in_use) { in pxa_ep_queue()
1100 length = _req->length; in pxa_ep_queue()
1101 _req->status = -EINPROGRESS; in pxa_ep_queue()
1102 _req->actual = 0; in pxa_ep_queue()
1105 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_queue()
1108 switch (dev->ep0state) { in pxa_ep_queue()
1117 rc = -EL2HLT; in pxa_ep_queue()
1119 ep0_idle(ep->dev); in pxa_ep_queue()
1133 EP0_STNAME(ep->dev)); in pxa_ep_queue()
1135 rc = -EL2HLT; in pxa_ep_queue()
1146 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_queue()
1151 * pxa_ep_dequeue - Dequeue one request
1152 * @_ep: usb endpoint
1155 * Return 0 if no error, -EINVAL or -ECONNRESET otherwise
1163 int rc = -EINVAL; in pxa_ep_dequeue()
1168 ep = udc_usb_ep->pxa_ep; in pxa_ep_dequeue()
1172 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_dequeue()
1174 /* make sure it's actually queued on this endpoint */ in pxa_ep_dequeue()
1175 list_for_each_entry(iter, &ep->queue, queue) { in pxa_ep_dequeue()
1176 if (&iter->req != _req) in pxa_ep_dequeue()
1183 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_dequeue()
1185 req_done(ep, req, -ECONNRESET, NULL); in pxa_ep_dequeue()
1190 * pxa_ep_set_halt - Halts operations on one endpoint
1191 * @_ep: usb endpoint
1194 * Returns 0 if no error, -EINVAL, -EROFS, -EAGAIN otherwise
1205 return -EINVAL; in pxa_ep_set_halt()
1207 ep = udc_usb_ep->pxa_ep; in pxa_ep_set_halt()
1209 return -EINVAL; in pxa_ep_set_halt()
1219 return -EROFS; in pxa_ep_set_halt()
1222 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_set_halt()
1224 rc = -EAGAIN; in pxa_ep_set_halt()
1225 if (ep->dir_in && (ep_is_full(ep) || !list_empty(&ep->queue))) in pxa_ep_set_halt()
1232 set_ep0state(ep->dev, STALL); in pxa_ep_set_halt()
1235 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_set_halt()
1240 * pxa_ep_fifo_status - Get how many bytes in physical endpoint
1241 * @_ep: usb endpoint
1251 return -ENODEV; in pxa_ep_fifo_status()
1253 ep = udc_usb_ep->pxa_ep; in pxa_ep_fifo_status()
1255 return -ENODEV; in pxa_ep_fifo_status()
1257 if (ep->dir_in) in pxa_ep_fifo_status()
1258 return -EOPNOTSUPP; in pxa_ep_fifo_status()
1259 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN || ep_is_empty(ep)) in pxa_ep_fifo_status()
1266 * pxa_ep_fifo_flush - Flushes one endpoint
1267 * @_ep: usb endpoint
1269 * Discards all data in one endpoint(IN or OUT), except control endpoint.
1280 ep = udc_usb_ep->pxa_ep; in pxa_ep_fifo_flush()
1284 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_fifo_flush()
1286 if (unlikely(!list_empty(&ep->queue))) in pxa_ep_fifo_flush()
1291 if (!ep->dir_in) { in pxa_ep_fifo_flush()
1301 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_fifo_flush()
1305 * pxa_ep_enable - Enables usb endpoint
1306 * @_ep: usb endpoint
1307 * @desc: usb endpoint descriptor
1310 * before udc is enabled. After udc enable, no physical endpoint configuration
1312 * Function makes sanity checks and flushes the endpoint.
1322 return -EINVAL; in pxa_ep_enable()
1325 if (udc_usb_ep->pxa_ep) { in pxa_ep_enable()
1326 ep = udc_usb_ep->pxa_ep; in pxa_ep_enable()
1328 _ep->name); in pxa_ep_enable()
1330 ep = find_pxa_ep(udc_usb_ep->dev, udc_usb_ep); in pxa_ep_enable()
1334 dev_err(udc_usb_ep->dev->dev, in pxa_ep_enable()
1336 _ep->name); in pxa_ep_enable()
1337 return -EINVAL; in pxa_ep_enable()
1340 if ((desc->bDescriptorType != USB_DT_ENDPOINT) in pxa_ep_enable()
1341 || (ep->type != usb_endpoint_type(desc))) { in pxa_ep_enable()
1343 return -EINVAL; in pxa_ep_enable()
1346 if (ep->fifo_size < usb_endpoint_maxp(desc)) { in pxa_ep_enable()
1348 return -ERANGE; in pxa_ep_enable()
1351 udc_usb_ep->pxa_ep = ep; in pxa_ep_enable()
1352 udc = ep->dev; in pxa_ep_enable()
1354 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in pxa_ep_enable()
1356 return -ESHUTDOWN; in pxa_ep_enable()
1359 ep->enabled = 1; in pxa_ep_enable()
1369 * pxa_ep_disable - Disable usb endpoint
1370 * @_ep: usb endpoint
1372 * Same as for pxa_ep_enable, no physical endpoint configuration can be
1374 * Function flushes the endpoint and related requests.
1382 return -EINVAL; in pxa_ep_disable()
1385 ep = udc_usb_ep->pxa_ep; in pxa_ep_disable()
1386 if (!ep || is_ep0(ep) || !list_empty(&ep->queue)) in pxa_ep_disable()
1387 return -EINVAL; in pxa_ep_disable()
1389 ep->enabled = 0; in pxa_ep_disable()
1390 nuke(ep, -ESHUTDOWN); in pxa_ep_disable()
1393 udc_usb_ep->pxa_ep = NULL; in pxa_ep_disable()
1415 * dplus_pullup - Connect or disconnect pullup resistor to D+ pin
1425 if (udc->gpiod) { in dplus_pullup()
1426 gpiod_set_value(udc->gpiod, on); in dplus_pullup()
1427 } else if (udc->udc_command) { in dplus_pullup()
1429 udc->udc_command(PXA2XX_UDC_CMD_CONNECT); in dplus_pullup()
1431 udc->udc_command(PXA2XX_UDC_CMD_DISCONNECT); in dplus_pullup()
1433 udc->pullup_on = on; in dplus_pullup()
1437 * pxa_udc_get_frame - Returns usb frame number
1448 * pxa_udc_wakeup - Force udc device out of suspend
1459 return -EHOSTUNREACH; in pxa_udc_wakeup()
1468 * should_enable_udc - Tells if UDC should be enabled
1473 * - the pullup resistor is connected
1474 * - and a gadget driver is bound
1475 * - and vbus is sensed (or no vbus sense is available)
1483 put_on = ((udc->pullup_on) && (udc->driver)); in should_enable_udc()
1484 put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL(udc->transceiver))); in should_enable_udc()
1489 * should_disable_udc - Tells if UDC should be disabled
1494 * - the pullup resistor is not connected
1495 * - or no gadget driver is bound
1496 * - or no vbus is sensed (when vbus sesing is available)
1504 put_off = ((!udc->pullup_on) || (!udc->driver)); in should_disable_udc()
1505 put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL(udc->transceiver))); in should_disable_udc()
1510 * pxa_udc_pullup - Offer manual D+ pullup control
1516 * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup
1522 if (!udc->gpiod && !udc->udc_command) in pxa_udc_pullup()
1523 return -EOPNOTSUPP; in pxa_udc_pullup()
1535 * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc
1548 udc->vbus_sensed = is_active; in pxa_udc_vbus_session()
1558 * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed
1567 * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc
1574 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_vbus_draw()
1575 return usb_phy_set_power(udc->transceiver, mA); in pxa_udc_vbus_draw()
1576 return -EOPNOTSUPP; in pxa_udc_vbus_draw()
1580 * pxa_udc_phy_event - Called by phy upon VBus event
1625 * udc_disable - disable udc device controller
1629 * Disables the udc device : disables clocks, udc interrupts, control endpoint
1634 if (!udc->enabled) in udc_disable()
1643 udc->gadget.speed = USB_SPEED_UNKNOWN; in udc_disable()
1644 clk_disable(udc->clk); in udc_disable()
1646 udc->enabled = 0; in udc_disable()
1650 * udc_init_data - Initialize udc device data structures
1653 * Initializes gadget endpoint list, endpoints locks. No action is taken
1662 INIT_LIST_HEAD(&dev->gadget.ep_list); in udc_init_data()
1663 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); in udc_init_data()
1664 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0]; in udc_init_data()
1665 dev->gadget.quirk_altset_not_supp = 1; in udc_init_data()
1670 ep = &dev->pxa_ep[i]; in udc_init_data()
1672 ep->enabled = is_ep0(ep); in udc_init_data()
1673 INIT_LIST_HEAD(&ep->queue); in udc_init_data()
1674 spin_lock_init(&ep->lock); in udc_init_data()
1679 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, in udc_init_data()
1680 &dev->gadget.ep_list); in udc_init_data()
1681 usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep, in udc_init_data()
1682 dev->udc_usb_ep[i].usb_ep.maxpacket); in udc_init_data()
1687 * udc_enable - Enables the udc device
1690 * Enables the udc device : enables clocks, udc interrupts, control endpoint
1695 if (udc->enabled) in udc_enable()
1698 clk_enable(udc->clk); in udc_enable()
1704 udc->gadget.speed = USB_SPEED_FULL; in udc_enable()
1705 memset(&udc->stats, 0, sizeof(udc->stats)); in udc_enable()
1709 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM); in udc_enable()
1712 dev_err(udc->dev, "Configuration errors, udc disabled\n"); in udc_enable()
1725 pio_irq_enable(&udc->pxa_ep[0]); in udc_enable()
1727 udc->enabled = 1; in udc_enable()
1731 * pxa27x_udc_start - Register gadget driver
1736 * including set_configuration(), which enables non-control requests. Then
1743 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1752 udc->driver = driver; in pxa27x_udc_start()
1754 if (!IS_ERR_OR_NULL(udc->transceiver)) { in pxa27x_udc_start()
1755 retval = otg_set_peripheral(udc->transceiver->otg, in pxa27x_udc_start()
1756 &udc->gadget); in pxa27x_udc_start()
1758 dev_err(udc->dev, "can't bind to transceiver\n"); in pxa27x_udc_start()
1768 udc->driver = NULL; in pxa27x_udc_start()
1773 * stop_activity - Stops udc endpoints
1776 * Disables all udc endpoints (even control endpoint), report disconnect to
1783 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
1786 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep); in stop_activity()
1790 * pxa27x_udc_stop - Unregister the gadget driver
1793 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1802 udc->driver = NULL; in pxa27x_udc_stop()
1804 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa27x_udc_stop()
1805 return otg_set_peripheral(udc->transceiver->otg, NULL); in pxa27x_udc_stop()
1810 * handle_ep0_ctrl_req - handle control endpoint control request
1817 struct pxa_ep *ep = &udc->pxa_ep[0]; in handle_ep0_ctrl_req()
1826 nuke(ep, -EPROTO); in handle_ep0_ctrl_req()
1827 spin_lock_irqsave(&ep->lock, flags); in handle_ep0_ctrl_req()
1830 * In the PXA320 manual, in the section about Back-to-Back setup in handle_ep0_ctrl_req()
1866 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep0_ctrl_req()
1867 i = udc->driver->setup(&udc->gadget, &u.r); in handle_ep0_ctrl_req()
1868 spin_lock_irqsave(&ep->lock, flags); in handle_ep0_ctrl_req()
1872 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep0_ctrl_req()
1883 * handle_ep0 - Handle control endpoint data transfers
1890 * Tries to transfer all pending request data into the endpoint and/or
1891 * transfer all pending data in the endpoint into usb requests.
1905 * The control endpoint state machine is _not_ USB spec compliant, it's even
1908 * - on every setup token, bit UDCCSR0_SA is raised and held until cleared by
1910 * - on every OUT packet received, UDCCSR0_OPC is raised and held until
1912 * - clearing UDCCSR0_OPC always flushes ep0. If in setup stage, never do it
1915 * (check Back-to-Back setup packet in developers guide).
1916 * - irq can be called on a "packet complete" event (opc_irq=1), while
1919 * - as UDCCSR0_SA can be activated while in irq handling, and clearing
1923 * - hardware as no idea of STATUS STAGE, it only handle SETUP STAGE and DATA
1926 * - special attention was needed for IN_STATUS_STAGE. If a packet complete
1933 struct pxa_ep *ep = &udc->pxa_ep[0]; in handle_ep0()
1937 if (!list_empty(&ep->queue)) in handle_ep0()
1938 req = list_entry(ep->queue.next, struct pxa27x_request, queue); in handle_ep0()
1947 nuke(ep, -EPIPE); in handle_ep0()
1957 switch (udc->ep0state) { in handle_ep0()
2000 EP0_STNAME(ep->dev)); in handle_ep0()
2007 * handle_ep - Handle endpoint data tranfers
2008 * @ep: pxa physical endpoint
2010 * Tries to transfer all pending request data into the endpoint and/or
2011 * transfer all pending data in the endpoint into usb requests.
2013 * Is always called from the interrupt handler. ep->lock must not be held.
2020 int is_in = ep->dir_in; in handle_ep()
2024 spin_lock_irqsave(&ep->lock, flags); in handle_ep()
2025 if (ep->in_handle_ep) in handle_ep()
2027 ep->in_handle_ep = 1; in handle_ep()
2033 if (likely(!list_empty(&ep->queue))) in handle_ep()
2034 req = list_entry(ep->queue.next, in handle_ep()
2064 ep->in_handle_ep = 0; in handle_ep()
2066 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep()
2070 * pxa27x_change_configuration - Handle SET_CONF usb request notification
2072 * @config: usb configuration
2077 static void pxa27x_change_configuration(struct pxa_udc *udc, int config) in pxa27x_change_configuration() argument
2081 dev_dbg(udc->dev, "config=%d\n", config); in pxa27x_change_configuration()
2083 udc->config = config; in pxa27x_change_configuration()
2084 udc->last_interface = 0; in pxa27x_change_configuration()
2085 udc->last_alternate = 0; in pxa27x_change_configuration()
2089 req.wValue = config; in pxa27x_change_configuration()
2094 udc->driver->setup(&udc->gadget, &req); in pxa27x_change_configuration()
2095 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN); in pxa27x_change_configuration()
2099 * pxa27x_change_interface - Handle SET_INTERF usb request notification
2111 dev_dbg(udc->dev, "interface=%d, alternate setting=%d\n", iface, alt); in pxa27x_change_interface()
2113 udc->last_interface = iface; in pxa27x_change_interface()
2114 udc->last_alternate = alt; in pxa27x_change_interface()
2123 udc->driver->setup(&udc->gadget, &req); in pxa27x_change_interface()
2124 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN); in pxa27x_change_interface()
2128 * irq_handle_data - Handle data transfer
2132 * Called from irq handler, transferts data to or from endpoint to queue
2142 udc->pxa_ep[0].stats.irqs++; in irq_handle_data()
2155 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep)); in irq_handle_data()
2156 if (i < ARRAY_SIZE(udc->pxa_ep)) { in irq_handle_data()
2157 ep = &udc->pxa_ep[i]; in irq_handle_data()
2158 ep->stats.irqs++; in irq_handle_data()
2164 udc_writel(udc, UDCISR1, UDCISR_INT(i - 16, UDCISR_INT_MASK)); in irq_handle_data()
2168 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep)); in irq_handle_data()
2169 if (i < ARRAY_SIZE(udc->pxa_ep)) { in irq_handle_data()
2170 ep = &udc->pxa_ep[i]; in irq_handle_data()
2171 ep->stats.irqs++; in irq_handle_data()
2179 * irq_udc_suspend - Handle IRQ "UDC Suspend"
2185 udc->stats.irqs_suspend++; in irq_udc_suspend()
2187 if (udc->gadget.speed != USB_SPEED_UNKNOWN in irq_udc_suspend()
2188 && udc->driver && udc->driver->suspend) in irq_udc_suspend()
2189 udc->driver->suspend(&udc->gadget); in irq_udc_suspend()
2194 * irq_udc_resume - Handle IRQ "UDC Resume"
2200 udc->stats.irqs_resume++; in irq_udc_resume()
2202 if (udc->gadget.speed != USB_SPEED_UNKNOWN in irq_udc_resume()
2203 && udc->driver && udc->driver->resume) in irq_udc_resume()
2204 udc->driver->resume(&udc->gadget); in irq_udc_resume()
2208 * irq_udc_reconfig - Handle IRQ "UDC Change Configuration"
2213 unsigned config, interface, alternate, config_change; in irq_udc_reconfig() local
2217 udc->stats.irqs_reconfig++; in irq_udc_reconfig()
2219 config = (udccr & UDCCR_ACN) >> UDCCR_ACN_S; in irq_udc_reconfig()
2220 config_change = (config != udc->config); in irq_udc_reconfig()
2221 pxa27x_change_configuration(udc, config); in irq_udc_reconfig()
2233 * irq_udc_reset - Handle IRQ "UDC Reset"
2239 struct pxa_ep *ep = &udc->pxa_ep[0]; in irq_udc_reset()
2241 dev_info(udc->dev, "USB reset\n"); in irq_udc_reset()
2243 udc->stats.irqs_reset++; in irq_udc_reset()
2246 dev_dbg(udc->dev, "USB reset start\n"); in irq_udc_reset()
2249 udc->gadget.speed = USB_SPEED_FULL; in irq_udc_reset()
2250 memset(&udc->stats, 0, sizeof udc->stats); in irq_udc_reset()
2252 nuke(ep, -EPROTO); in irq_udc_reset()
2258 * pxa_udc_irq - Main irq handler
2272 dev_vdbg(udc->dev, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, " in pxa_udc_irq()
2332 /* Endpoint for CDC Ether */
2340 { .compatible = "marvell,pxa270-udc" },
2347 * pxa_udc_probe - probes the udc device
2357 struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev); in pxa_udc_probe()
2361 gpio_flags = mach->gpio_pullup_inverted ? GPIOF_ACTIVE_LOW : 0; in pxa_udc_probe()
2362 gpio = mach->gpio_pullup; in pxa_udc_probe()
2364 retval = devm_gpio_request_one(&pdev->dev, gpio, in pxa_udc_probe()
2369 udc->gpiod = gpio_to_desc(mach->gpio_pullup); in pxa_udc_probe()
2371 udc->udc_command = mach->udc_command; in pxa_udc_probe()
2373 udc->gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_ASIS); in pxa_udc_probe()
2376 udc->regs = devm_platform_ioremap_resource(pdev, 0); in pxa_udc_probe()
2377 if (IS_ERR(udc->regs)) in pxa_udc_probe()
2378 return PTR_ERR(udc->regs); in pxa_udc_probe()
2379 udc->irq = platform_get_irq(pdev, 0); in pxa_udc_probe()
2380 if (udc->irq < 0) in pxa_udc_probe()
2381 return udc->irq; in pxa_udc_probe()
2383 udc->dev = &pdev->dev; in pxa_udc_probe()
2385 udc->transceiver = in pxa_udc_probe()
2386 devm_usb_get_phy_by_phandle(udc->dev, "phys", 0); in pxa_udc_probe()
2387 if (IS_ERR(udc->transceiver)) in pxa_udc_probe()
2388 return PTR_ERR(udc->transceiver); in pxa_udc_probe()
2390 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); in pxa_udc_probe()
2393 if (IS_ERR(udc->gpiod)) { in pxa_udc_probe()
2394 dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n", in pxa_udc_probe()
2395 PTR_ERR(udc->gpiod)); in pxa_udc_probe()
2396 return PTR_ERR(udc->gpiod); in pxa_udc_probe()
2398 if (udc->gpiod) in pxa_udc_probe()
2399 gpiod_direction_output(udc->gpiod, 0); in pxa_udc_probe()
2401 udc->clk = devm_clk_get(&pdev->dev, NULL); in pxa_udc_probe()
2402 if (IS_ERR(udc->clk)) in pxa_udc_probe()
2403 return PTR_ERR(udc->clk); in pxa_udc_probe()
2405 retval = clk_prepare(udc->clk); in pxa_udc_probe()
2409 udc->vbus_sensed = 0; in pxa_udc_probe()
2416 retval = devm_request_irq(&pdev->dev, udc->irq, pxa_udc_irq, in pxa_udc_probe()
2419 dev_err(udc->dev, "%s: can't get irq %i, err %d\n", in pxa_udc_probe()
2420 driver_name, udc->irq, retval); in pxa_udc_probe()
2424 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_probe()
2425 usb_register_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_probe()
2426 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in pxa_udc_probe()
2436 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_probe()
2437 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_probe()
2439 clk_unprepare(udc->clk); in pxa_udc_probe()
2444 * pxa_udc_remove - removes the udc device driver
2451 usb_del_gadget_udc(&udc->gadget); in pxa_udc_remove()
2454 if (!IS_ERR_OR_NULL(udc->transceiver)) { in pxa_udc_remove()
2455 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_remove()
2456 usb_put_phy(udc->transceiver); in pxa_udc_remove()
2459 udc->transceiver = NULL; in pxa_udc_remove()
2461 clk_unprepare(udc->clk); in pxa_udc_remove()
2474 * pxa_udc_suspend - Suspend udc device
2486 ep = &udc->pxa_ep[0]; in pxa_udc_suspend()
2487 udc->udccsr0 = udc_ep_readl(ep, UDCCSR); in pxa_udc_suspend()
2490 udc->pullup_resume = udc->pullup_on; in pxa_udc_suspend()
2493 if (udc->driver) in pxa_udc_suspend()
2494 udc->driver->disconnect(&udc->gadget); in pxa_udc_suspend()
2500 * pxa_udc_resume - Resume udc device
2511 ep = &udc->pxa_ep[0]; in pxa_udc_resume()
2512 udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME)); in pxa_udc_resume()
2514 dplus_pullup(udc, udc->pullup_resume); in pxa_udc_resume()
2533 MODULE_ALIAS("platform:pxa27x-udc");
2537 .name = "pxa27x-udc",