Lines Matching +full:can +full:- +full:transceiver
1 // SPDX-License-Identifier: GPL-2.0+
48 * controller can be enabled (minor, and not uncommon); and each endpoint
49 * can only have one configuration, interface and alternative interface
60 * - zero gadget
61 * - file storage gadget
62 * - ether gadget
65 * made of UDC's double buffering either. USB "On-The-Go" is not implemented.
68 * - the drivers tries to handle the request directly to the IO
69 * - if the IO fifo is not big enough, the remaining is send/received in
73 #define DRIVER_VERSION "2008-04-18"
92 struct pxa_udc *udc = s->private; in state_dbg_show()
95 if (!udc->driver) in state_dbg_show()
96 return -ENODEV; in state_dbg_show()
103 udc->driver ? udc->driver->driver.name : "(none)"); in state_dbg_show()
129 udc->stats.irqs_reset, udc->stats.irqs_suspend, in state_dbg_show()
130 udc->stats.irqs_resume, udc->stats.irqs_reconfig); in state_dbg_show()
138 struct pxa_udc *udc = s->private; in queues_dbg_show()
143 if (!udc->driver) in queues_dbg_show()
144 return -ENODEV; in queues_dbg_show()
148 ep = &udc->pxa_ep[i]; in queues_dbg_show()
149 maxpkt = ep->fifo_size; in queues_dbg_show()
150 seq_printf(s, "%-12s max_pkt=%d %s\n", in queues_dbg_show()
153 if (list_empty(&ep->queue)) { in queues_dbg_show()
158 list_for_each_entry(req, &ep->queue, queue) { in queues_dbg_show()
160 &req->req, req->req.actual, in queues_dbg_show()
161 req->req.length, req->req.buf); in queues_dbg_show()
171 struct pxa_udc *udc = s->private; in eps_dbg_show()
176 if (!udc->driver) in eps_dbg_show()
177 return -ENODEV; in eps_dbg_show()
179 ep = &udc->pxa_ep[0]; in eps_dbg_show()
191 ep = &udc->pxa_ep[i]; in eps_dbg_show()
193 …seq_printf(s, "%-12s: IN %lu(%lu reqs), OUT %lu(%lu reqs), irqs=%lu, udccr=0x%08x, udccsr=0x%03x, … in eps_dbg_show()
195 ep->stats.in_bytes, ep->stats.in_ops, in eps_dbg_show()
196 ep->stats.out_bytes, ep->stats.out_ops, in eps_dbg_show()
197 ep->stats.irqs, in eps_dbg_show()
210 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in pxa_init_debugfs()
218 debugfs_lookup_and_remove(udc->gadget.name, usb_debug_root); in pxa_cleanup_debugfs()
232 * is_match_usb_pxa - check if usb_ep and pxa_ep match
244 if (usb_endpoint_num(&udc_usb_ep->desc) != ep->addr) in is_match_usb_pxa()
246 if (usb_endpoint_dir_in(&udc_usb_ep->desc) != ep->dir_in) in is_match_usb_pxa()
248 if (usb_endpoint_type(&udc_usb_ep->desc) != ep->type) in is_match_usb_pxa()
250 if ((ep->config != config) || (ep->interface != interface) in is_match_usb_pxa()
251 || (ep->alternate != altsetting)) in is_match_usb_pxa()
257 * find_pxa_ep - find pxa_ep structure matching udc_usb_ep
264 * no change can be made to their address, direction, or in which configuration,
270 * - we rely on UDCCR register "active interface" and "active altsetting".
273 * - if we knew for sure that the pxa can handle multiple interface at the
286 int cfg = udc->config; in find_pxa_ep()
287 int iface = udc->last_interface; in find_pxa_ep()
288 int alt = udc->last_alternate; in find_pxa_ep()
290 if (udc_usb_ep == &udc->udc_usb_ep[0]) in find_pxa_ep()
291 return &udc->pxa_ep[0]; in find_pxa_ep()
294 ep = &udc->pxa_ep[i]; in find_pxa_ep()
302 * update_pxa_ep_matches - update pxa_ep cached values in all udc_usb_ep
317 udc_usb_ep = &udc->udc_usb_ep[i]; in update_pxa_ep_matches()
318 if (udc_usb_ep->pxa_ep) in update_pxa_ep_matches()
319 udc_usb_ep->pxa_ep = find_pxa_ep(udc, udc_usb_ep); in update_pxa_ep_matches()
324 * pio_irq_enable - Enables irq generation for one endpoint
329 struct pxa_udc *udc = ep->dev; in pio_irq_enable()
337 udc_writel(udc, UDCICR1, udcicr1 | (3 << ((index - 16) * 2))); in pio_irq_enable()
341 * pio_irq_disable - Disables irq generation for one endpoint
346 struct pxa_udc *udc = ep->dev; in pio_irq_disable()
354 udc_writel(udc, UDCICR1, udcicr1 & ~(3 << ((index - 16) * 2))); in pio_irq_disable()
358 * udc_set_mask_UDCCR - set bits in UDCCR
372 * udc_clear_mask_UDCCR - clears bits in UDCCR
386 * ep_write_UDCCSR - set bits in UDCCSR
403 * ep_count_bytes_remain - get how many bytes in udc endpoint
406 * Returns number of bytes in OUT fifos. Broken for IN fifos (-EOPNOTSUPP)
410 if (ep->dir_in) in ep_count_bytes_remain()
411 return -EOPNOTSUPP; in ep_count_bytes_remain()
416 * ep_is_empty - checks if ep has byte ready for reading
423 * Returns 0 if ep not empty, 1 if ep empty, -EOPNOTSUPP if IN endpoint
429 if (!is_ep0(ep) && ep->dir_in) in ep_is_empty()
430 return -EOPNOTSUPP; in ep_is_empty()
439 * ep_is_full - checks if ep has place to write bytes
445 * Returns 0 if ep not full, 1 if ep full, -EOPNOTSUPP if OUT endpoint
451 if (!ep->dir_in) in ep_is_full()
452 return -EOPNOTSUPP; in ep_is_full()
457 * epout_has_pkt - checks if OUT endpoint fifo has a packet available
460 * Returns 1 if a complete packet is available, 0 if not, -EOPNOTSUPP for IN ep.
464 if (!is_ep0(ep) && ep->dir_in) in epout_has_pkt()
465 return -EOPNOTSUPP; in epout_has_pkt()
472 * set_ep0state - Set ep0 automata state
478 struct pxa_ep *ep = &udc->pxa_ep[0]; in set_ep0state()
481 udc->ep0state = state; in set_ep0state()
482 ep_dbg(ep, "state=%s->%s, udccsr0=0x%03x, udcbcr=%d\n", old_stname, in set_ep0state()
488 * ep0_idle - Put control endpoint into idle state
497 * inc_ep_stats_reqs - Update ep stats counts
505 ep->stats.in_ops++; in inc_ep_stats_reqs()
507 ep->stats.out_ops++; in inc_ep_stats_reqs()
511 * inc_ep_stats_bytes - Update ep stats counts
519 ep->stats.in_bytes += count; in inc_ep_stats_bytes()
521 ep->stats.out_bytes += count; in inc_ep_stats_bytes()
525 * pxa_ep_setup - Sets up an usb physical endpoint
534 new_udccr = ((ep->config << UDCCONR_CN_S) & UDCCONR_CN) in pxa_ep_setup()
535 | ((ep->interface << UDCCONR_IN_S) & UDCCONR_IN) in pxa_ep_setup()
536 | ((ep->alternate << UDCCONR_AISN_S) & UDCCONR_AISN) in pxa_ep_setup()
539 | ((ep->dir_in) ? UDCCONR_ED : 0) in pxa_ep_setup()
540 | ((ep->fifo_size << UDCCONR_MPS_S) & UDCCONR_MPS) in pxa_ep_setup()
547 * pxa_eps_setup - Sets up all usb physical endpoints
556 dev_dbg(dev->dev, "%s: dev=%p\n", __func__, dev); in pxa_eps_setup()
559 pxa_ep_setup(&dev->pxa_ep[i]); in pxa_eps_setup()
563 * pxa_ep_alloc_request - Allocate usb request
567 * For the pxa27x, these can just wrap kmalloc/kfree. gadget drivers
580 INIT_LIST_HEAD(&req->queue); in pxa_ep_alloc_request()
581 req->in_use = 0; in pxa_ep_alloc_request()
582 req->udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); in pxa_ep_alloc_request()
584 return &req->req; in pxa_ep_alloc_request()
588 * pxa_ep_free_request - Free usb request
599 WARN_ON(!list_empty(&req->queue)); in pxa_ep_free_request()
604 * ep_add_request - add a request to the endpoint's queue
608 * Context: ep->lock held
618 req->req.length, udc_ep_readl(ep, UDCCSR)); in ep_add_request()
620 req->in_use = 1; in ep_add_request()
621 list_add_tail(&req->queue, &ep->queue); in ep_add_request()
626 * ep_del_request - removes a request from the endpoint's queue
630 * Context: ep->lock held
641 req->req.length, udc_ep_readl(ep, UDCCSR)); in ep_del_request()
643 list_del_init(&req->queue); in ep_del_request()
644 req->in_use = 0; in ep_del_request()
645 if (!is_ep0(ep) && list_empty(&ep->queue)) in ep_del_request()
650 * req_done - Complete an usb request
656 * Context: ep->lock held if flags not NULL, else ep->lock released
666 if (likely(req->req.status == -EINPROGRESS)) in req_done()
667 req->req.status = status; in req_done()
669 status = req->req.status; in req_done()
671 if (status && status != -ESHUTDOWN) in req_done()
673 &req->req, status, in req_done()
674 req->req.actual, req->req.length); in req_done()
677 spin_unlock_irqrestore(&ep->lock, *pflags); in req_done()
679 usb_gadget_giveback_request(&req->udc_usb_ep->usb_ep, &req->req); in req_done()
682 spin_lock_irqsave(&ep->lock, *pflags); in req_done()
686 * ep_end_out_req - Ends endpoint OUT request
691 * Context: ep->lock held or released (see req_done())
703 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
708 * Context: ep->lock held or released (see req_done())
716 set_ep0state(ep->dev, OUT_STATUS_STAGE); in ep0_end_out_req()
718 ep0_idle(ep->dev); in ep0_end_out_req()
722 * ep_end_in_req - Ends endpoint IN request
727 * Context: ep->lock held or released (see req_done())
739 * ep0_end_in_req - Ends control endpoint IN request (ends data stage)
744 * Context: ep->lock held or released (see req_done())
752 set_ep0state(ep->dev, IN_STATUS_STAGE); in ep0_end_in_req()
757 * nuke - Dequeue all requests
761 * Context: ep->lock released
771 spin_lock_irqsave(&ep->lock, flags); in nuke()
772 while (!list_empty(&ep->queue)) { in nuke()
773 req = list_entry(ep->queue.next, struct pxa27x_request, queue); in nuke()
776 spin_unlock_irqrestore(&ep->lock, flags); in nuke()
780 * read_packet - transfer 1 packet from an OUT endpoint into request
796 bufferspace = req->req.length - req->req.actual; in read_packet()
798 buf = (u32 *)(req->req.buf + req->req.actual); in read_packet()
806 for (i = count; i > 0; i -= 4) in read_packet()
808 req->req.actual += count; in read_packet()
816 * write_packet - transfer 1 packet from request into an IN endpoint
834 buf = (u32 *)(req->req.buf + req->req.actual); in write_packet()
837 length = min(req->req.length - req->req.actual, max); in write_packet()
838 req->req.actual += length; in write_packet()
842 for (i = count; i > 0 ; i -= 4) in write_packet()
846 for (i = remain; i > 0; i--) in write_packet()
856 * read_fifo - Transfer packets from OUT endpoint into usb request
877 is_short = (count < ep->fifo_size); in read_fifo()
880 &req->req, req->req.actual, req->req.length); in read_fifo()
883 if (is_short || req->req.actual == req->req.length) { in read_fifo()
893 * write_fifo - transfer packets from usb request into an IN endpoint
910 max = ep->fifo_size; in write_fifo()
933 if (likely(req->req.length > req->req.actual) in write_fifo()
934 || req->req.zero) in write_fifo()
939 is_short = unlikely(max < ep->fifo_size); in write_fifo()
954 req->req.length - req->req.actual, &req->req); in write_fifo()
960 * read_ep0_fifo - Transfer packets from control endpoint into usb request
965 * endpoint as can be read, and stores them into usb request (limited by request
979 is_short = (count < ep->fifo_size); in read_ep0_fifo()
982 &req->req, req->req.actual, req->req.length); in read_ep0_fifo()
984 if (is_short || req->req.actual >= req->req.length) { in read_ep0_fifo()
994 * write_ep0_fifo - Send a request to control endpoint (ep0 in)
1003 * - last write transferred all remaining bytes, but fifo was not fully filled
1004 * - last write was a 0 length write
1025 req->req.length - req->req.actual, in write_ep0_fifo()
1026 &req->req, udc_ep_readl(ep, UDCCSR)); in write_ep0_fifo()
1032 * pxa_ep_queue - Queue a request into an IN endpoint
1039 * (irq->handle_ep0_ctrl_req->gadget_setup->pxa_ep_queue)
1059 if (unlikely(!_req || !_req->complete || !_req->buf)) in pxa_ep_queue()
1060 return -EINVAL; in pxa_ep_queue()
1063 return -EINVAL; in pxa_ep_queue()
1065 ep = udc_usb_ep->pxa_ep; in pxa_ep_queue()
1067 return -EINVAL; in pxa_ep_queue()
1069 dev = ep->dev; in pxa_ep_queue()
1070 if (unlikely(!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)) { in pxa_ep_queue()
1072 return -ESHUTDOWN; in pxa_ep_queue()
1076 * we can report per-packet status. that also helps with dma. in pxa_ep_queue()
1079 && req->req.length > ep->fifo_size)) in pxa_ep_queue()
1080 return -EMSGSIZE; in pxa_ep_queue()
1082 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_queue()
1083 recursion_detected = ep->in_handle_ep; in pxa_ep_queue()
1085 is_first_req = list_empty(&ep->queue); in pxa_ep_queue()
1088 _req->length, _req->buf); in pxa_ep_queue()
1090 if (!ep->enabled) { in pxa_ep_queue()
1091 _req->status = -ESHUTDOWN; in pxa_ep_queue()
1092 rc = -ESHUTDOWN; in pxa_ep_queue()
1096 if (req->in_use) { in pxa_ep_queue()
1101 length = _req->length; in pxa_ep_queue()
1102 _req->status = -EINPROGRESS; in pxa_ep_queue()
1103 _req->actual = 0; in pxa_ep_queue()
1106 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_queue()
1109 switch (dev->ep0state) { in pxa_ep_queue()
1118 rc = -EL2HLT; in pxa_ep_queue()
1120 ep0_idle(ep->dev); in pxa_ep_queue()
1134 EP0_STNAME(ep->dev)); in pxa_ep_queue()
1136 rc = -EL2HLT; in pxa_ep_queue()
1147 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_queue()
1152 * pxa_ep_dequeue - Dequeue one request
1156 * Return 0 if no error, -EINVAL or -ECONNRESET otherwise
1164 int rc = -EINVAL; in pxa_ep_dequeue()
1169 ep = udc_usb_ep->pxa_ep; in pxa_ep_dequeue()
1173 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_dequeue()
1176 list_for_each_entry(iter, &ep->queue, queue) { in pxa_ep_dequeue()
1177 if (&iter->req != _req) in pxa_ep_dequeue()
1184 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_dequeue()
1186 req_done(ep, req, -ECONNRESET, NULL); in pxa_ep_dequeue()
1191 * pxa_ep_set_halt - Halts operations on one endpoint
1195 * Returns 0 if no error, -EINVAL, -EROFS, -EAGAIN otherwise
1206 return -EINVAL; in pxa_ep_set_halt()
1208 ep = udc_usb_ep->pxa_ep; in pxa_ep_set_halt()
1210 return -EINVAL; in pxa_ep_set_halt()
1215 * SET_INTERFACE on normal hardware. but it can't be in pxa_ep_set_halt()
1219 ep_dbg(ep, "only host can clear halt\n"); in pxa_ep_set_halt()
1220 return -EROFS; in pxa_ep_set_halt()
1223 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_set_halt()
1225 rc = -EAGAIN; in pxa_ep_set_halt()
1226 if (ep->dir_in && (ep_is_full(ep) || !list_empty(&ep->queue))) in pxa_ep_set_halt()
1233 set_ep0state(ep->dev, STALL); in pxa_ep_set_halt()
1236 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_set_halt()
1241 * pxa_ep_fifo_status - Get how many bytes in physical endpoint
1252 return -ENODEV; in pxa_ep_fifo_status()
1254 ep = udc_usb_ep->pxa_ep; in pxa_ep_fifo_status()
1256 return -ENODEV; in pxa_ep_fifo_status()
1258 if (ep->dir_in) in pxa_ep_fifo_status()
1259 return -EOPNOTSUPP; in pxa_ep_fifo_status()
1260 if (ep->dev->gadget.speed == USB_SPEED_UNKNOWN || ep_is_empty(ep)) in pxa_ep_fifo_status()
1267 * pxa_ep_fifo_flush - Flushes one endpoint
1281 ep = udc_usb_ep->pxa_ep; in pxa_ep_fifo_flush()
1285 spin_lock_irqsave(&ep->lock, flags); in pxa_ep_fifo_flush()
1287 if (unlikely(!list_empty(&ep->queue))) in pxa_ep_fifo_flush()
1292 if (!ep->dir_in) { in pxa_ep_fifo_flush()
1296 /* most IN status is the same, but ISO can't stall */ in pxa_ep_fifo_flush()
1302 spin_unlock_irqrestore(&ep->lock, flags); in pxa_ep_fifo_flush()
1306 * pxa_ep_enable - Enables usb endpoint
1312 * can be changed.
1323 return -EINVAL; in pxa_ep_enable()
1326 if (udc_usb_ep->pxa_ep) { in pxa_ep_enable()
1327 ep = udc_usb_ep->pxa_ep; in pxa_ep_enable()
1329 _ep->name); in pxa_ep_enable()
1331 ep = find_pxa_ep(udc_usb_ep->dev, udc_usb_ep); in pxa_ep_enable()
1335 dev_err(udc_usb_ep->dev->dev, in pxa_ep_enable()
1337 _ep->name); in pxa_ep_enable()
1338 return -EINVAL; in pxa_ep_enable()
1341 if ((desc->bDescriptorType != USB_DT_ENDPOINT) in pxa_ep_enable()
1342 || (ep->type != usb_endpoint_type(desc))) { in pxa_ep_enable()
1344 return -EINVAL; in pxa_ep_enable()
1347 if (ep->fifo_size < usb_endpoint_maxp(desc)) { in pxa_ep_enable()
1349 return -ERANGE; in pxa_ep_enable()
1352 udc_usb_ep->pxa_ep = ep; in pxa_ep_enable()
1353 udc = ep->dev; in pxa_ep_enable()
1355 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in pxa_ep_enable()
1357 return -ESHUTDOWN; in pxa_ep_enable()
1360 ep->enabled = 1; in pxa_ep_enable()
1370 * pxa_ep_disable - Disable usb endpoint
1373 * Same as for pxa_ep_enable, no physical endpoint configuration can be
1383 return -EINVAL; in pxa_ep_disable()
1386 ep = udc_usb_ep->pxa_ep; in pxa_ep_disable()
1387 if (!ep || is_ep0(ep) || !list_empty(&ep->queue)) in pxa_ep_disable()
1388 return -EINVAL; in pxa_ep_disable()
1390 ep->enabled = 0; in pxa_ep_disable()
1391 nuke(ep, -ESHUTDOWN); in pxa_ep_disable()
1394 udc_usb_ep->pxa_ep = NULL; in pxa_ep_disable()
1416 * dplus_pullup - Connect or disconnect pullup resistor to D+ pin
1426 if (udc->gpiod) { in dplus_pullup()
1427 gpiod_set_value(udc->gpiod, on); in dplus_pullup()
1428 } else if (udc->udc_command) { in dplus_pullup()
1430 udc->udc_command(PXA2XX_UDC_CMD_CONNECT); in dplus_pullup()
1432 udc->udc_command(PXA2XX_UDC_CMD_DISCONNECT); in dplus_pullup()
1434 udc->pullup_on = on; in dplus_pullup()
1438 * pxa_udc_get_frame - Returns usb frame number
1449 * pxa_udc_wakeup - Force udc device out of suspend
1460 return -EHOSTUNREACH; in pxa_udc_wakeup()
1469 * should_enable_udc - Tells if UDC should be enabled
1474 * - the pullup resistor is connected
1475 * - and a gadget driver is bound
1476 * - and vbus is sensed (or no vbus sense is available)
1484 put_on = ((udc->pullup_on) && (udc->driver)); in should_enable_udc()
1485 put_on &= ((udc->vbus_sensed) || (IS_ERR_OR_NULL(udc->transceiver))); in should_enable_udc()
1490 * should_disable_udc - Tells if UDC should be disabled
1495 * - the pullup resistor is not connected
1496 * - or no gadget driver is bound
1497 * - or no vbus is sensed (when vbus sesing is available)
1505 put_off = ((!udc->pullup_on) || (!udc->driver)); in should_disable_udc()
1506 put_off |= ((!udc->vbus_sensed) && (!IS_ERR_OR_NULL(udc->transceiver))); in should_disable_udc()
1511 * pxa_udc_pullup - Offer manual D+ pullup control
1517 * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup
1523 if (!udc->gpiod && !udc->udc_command) in pxa_udc_pullup()
1524 return -EOPNOTSUPP; in pxa_udc_pullup()
1536 * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc
1549 udc->vbus_sensed = is_active; in pxa_udc_vbus_session()
1559 * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed
1566 * current can be drawn by the device from VBus line.
1568 * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc
1575 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_vbus_draw()
1576 return usb_phy_set_power(udc->transceiver, mA); in pxa_udc_vbus_draw()
1577 return -EOPNOTSUPP; in pxa_udc_vbus_draw()
1581 * pxa_udc_phy_event - Called by phy upon VBus event
1626 * udc_disable - disable udc device controller
1635 if (!udc->enabled) in udc_disable()
1644 udc->gadget.speed = USB_SPEED_UNKNOWN; in udc_disable()
1645 clk_disable(udc->clk); in udc_disable()
1647 udc->enabled = 0; in udc_disable()
1651 * udc_init_data - Initialize udc device data structures
1663 INIT_LIST_HEAD(&dev->gadget.ep_list); in udc_init_data()
1664 INIT_LIST_HEAD(&dev->gadget.ep0->ep_list); in udc_init_data()
1665 dev->udc_usb_ep[0].pxa_ep = &dev->pxa_ep[0]; in udc_init_data()
1666 dev->gadget.quirk_altset_not_supp = 1; in udc_init_data()
1671 ep = &dev->pxa_ep[i]; in udc_init_data()
1673 ep->enabled = is_ep0(ep); in udc_init_data()
1674 INIT_LIST_HEAD(&ep->queue); in udc_init_data()
1675 spin_lock_init(&ep->lock); in udc_init_data()
1680 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, in udc_init_data()
1681 &dev->gadget.ep_list); in udc_init_data()
1682 usb_ep_set_maxpacket_limit(&dev->udc_usb_ep[i].usb_ep, in udc_init_data()
1683 dev->udc_usb_ep[i].usb_ep.maxpacket); in udc_init_data()
1688 * udc_enable - Enables the udc device
1696 if (udc->enabled) in udc_enable()
1699 clk_enable(udc->clk); in udc_enable()
1705 udc->gadget.speed = USB_SPEED_FULL; in udc_enable()
1706 memset(&udc->stats, 0, sizeof(udc->stats)); in udc_enable()
1710 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_ACM); in udc_enable()
1713 dev_err(udc->dev, "Configuration errors, udc disabled\n"); in udc_enable()
1726 pio_irq_enable(&udc->pxa_ep[0]); in udc_enable()
1728 udc->enabled = 1; in udc_enable()
1732 * pxa27x_udc_start - Register gadget driver
1737 * including set_configuration(), which enables non-control requests. Then
1744 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1753 udc->driver = driver; in pxa27x_udc_start()
1755 if (!IS_ERR_OR_NULL(udc->transceiver)) { in pxa27x_udc_start()
1756 retval = otg_set_peripheral(udc->transceiver->otg, in pxa27x_udc_start()
1757 &udc->gadget); in pxa27x_udc_start()
1759 dev_err(udc->dev, "can't bind to transceiver\n"); in pxa27x_udc_start()
1769 udc->driver = NULL; in pxa27x_udc_start()
1774 * stop_activity - Stops udc endpoints
1784 udc->gadget.speed = USB_SPEED_UNKNOWN; in stop_activity()
1787 pxa_ep_disable(&udc->udc_usb_ep[i].usb_ep); in stop_activity()
1791 * pxa27x_udc_stop - Unregister the gadget driver
1794 * Returns 0 if no error, -ENODEV, -EINVAL otherwise
1803 udc->driver = NULL; in pxa27x_udc_stop()
1805 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa27x_udc_stop()
1806 return otg_set_peripheral(udc->transceiver->otg, NULL); in pxa27x_udc_stop()
1811 * handle_ep0_ctrl_req - handle control endpoint control request
1818 struct pxa_ep *ep = &udc->pxa_ep[0]; in handle_ep0_ctrl_req()
1827 nuke(ep, -EPROTO); in handle_ep0_ctrl_req()
1828 spin_lock_irqsave(&ep->lock, flags); in handle_ep0_ctrl_req()
1831 * In the PXA320 manual, in the section about Back-to-Back setup in handle_ep0_ctrl_req()
1867 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep0_ctrl_req()
1868 i = udc->driver->setup(&udc->gadget, &u.r); in handle_ep0_ctrl_req()
1869 spin_lock_irqsave(&ep->lock, flags); in handle_ep0_ctrl_req()
1873 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep0_ctrl_req()
1884 * handle_ep0 - Handle control endpoint data transfers
1909 * - on every setup token, bit UDCCSR0_SA is raised and held until cleared by
1911 * - on every OUT packet received, UDCCSR0_OPC is raised and held until
1913 * - clearing UDCCSR0_OPC always flushes ep0. If in setup stage, never do it
1916 * (check Back-to-Back setup packet in developers guide).
1917 * - irq can be called on a "packet complete" event (opc_irq=1), while
1918 * UDCCSR0_OPC is not yet raised (delta can be as big as 100ms
1920 * - as UDCCSR0_SA can be activated while in irq handling, and clearing
1924 * - hardware as no idea of STATUS STAGE, it only handle SETUP STAGE and DATA
1927 * - special attention was needed for IN_STATUS_STAGE. If a packet complete
1934 struct pxa_ep *ep = &udc->pxa_ep[0]; in handle_ep0()
1938 if (!list_empty(&ep->queue)) in handle_ep0()
1939 req = list_entry(ep->queue.next, struct pxa27x_request, queue); in handle_ep0()
1948 nuke(ep, -EPIPE); in handle_ep0()
1958 switch (udc->ep0state) { in handle_ep0()
2001 EP0_STNAME(ep->dev)); in handle_ep0()
2008 * handle_ep - Handle endpoint data tranfers
2014 * Is always called from the interrupt handler. ep->lock must not be held.
2021 int is_in = ep->dir_in; in handle_ep()
2025 spin_lock_irqsave(&ep->lock, flags); in handle_ep()
2026 if (ep->in_handle_ep) in handle_ep()
2028 ep->in_handle_ep = 1; in handle_ep()
2034 if (likely(!list_empty(&ep->queue))) in handle_ep()
2035 req = list_entry(ep->queue.next, in handle_ep()
2065 ep->in_handle_ep = 0; in handle_ep()
2067 spin_unlock_irqrestore(&ep->lock, flags); in handle_ep()
2071 * pxa27x_change_configuration - Handle SET_CONF usb request notification
2082 dev_dbg(udc->dev, "config=%d\n", config); in pxa27x_change_configuration()
2084 udc->config = config; in pxa27x_change_configuration()
2085 udc->last_interface = 0; in pxa27x_change_configuration()
2086 udc->last_alternate = 0; in pxa27x_change_configuration()
2095 udc->driver->setup(&udc->gadget, &req); in pxa27x_change_configuration()
2096 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN); in pxa27x_change_configuration()
2100 * pxa27x_change_interface - Handle SET_INTERF usb request notification
2112 dev_dbg(udc->dev, "interface=%d, alternate setting=%d\n", iface, alt); in pxa27x_change_interface()
2114 udc->last_interface = iface; in pxa27x_change_interface()
2115 udc->last_alternate = alt; in pxa27x_change_interface()
2124 udc->driver->setup(&udc->gadget, &req); in pxa27x_change_interface()
2125 ep_write_UDCCSR(&udc->pxa_ep[0], UDCCSR0_AREN); in pxa27x_change_interface()
2129 * irq_handle_data - Handle data transfer
2143 udc->pxa_ep[0].stats.irqs++; in irq_handle_data()
2156 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep)); in irq_handle_data()
2157 if (i < ARRAY_SIZE(udc->pxa_ep)) { in irq_handle_data()
2158 ep = &udc->pxa_ep[i]; in irq_handle_data()
2159 ep->stats.irqs++; in irq_handle_data()
2165 udc_writel(udc, UDCISR1, UDCISR_INT(i - 16, UDCISR_INT_MASK)); in irq_handle_data()
2169 WARN_ON(i >= ARRAY_SIZE(udc->pxa_ep)); in irq_handle_data()
2170 if (i < ARRAY_SIZE(udc->pxa_ep)) { in irq_handle_data()
2171 ep = &udc->pxa_ep[i]; in irq_handle_data()
2172 ep->stats.irqs++; in irq_handle_data()
2180 * irq_udc_suspend - Handle IRQ "UDC Suspend"
2186 udc->stats.irqs_suspend++; in irq_udc_suspend()
2188 if (udc->gadget.speed != USB_SPEED_UNKNOWN in irq_udc_suspend()
2189 && udc->driver && udc->driver->suspend) in irq_udc_suspend()
2190 udc->driver->suspend(&udc->gadget); in irq_udc_suspend()
2195 * irq_udc_resume - Handle IRQ "UDC Resume"
2201 udc->stats.irqs_resume++; in irq_udc_resume()
2203 if (udc->gadget.speed != USB_SPEED_UNKNOWN in irq_udc_resume()
2204 && udc->driver && udc->driver->resume) in irq_udc_resume()
2205 udc->driver->resume(&udc->gadget); in irq_udc_resume()
2209 * irq_udc_reconfig - Handle IRQ "UDC Change Configuration"
2218 udc->stats.irqs_reconfig++; in irq_udc_reconfig()
2221 config_change = (config != udc->config); in irq_udc_reconfig()
2234 * irq_udc_reset - Handle IRQ "UDC Reset"
2240 struct pxa_ep *ep = &udc->pxa_ep[0]; in irq_udc_reset()
2242 dev_info(udc->dev, "USB reset\n"); in irq_udc_reset()
2244 udc->stats.irqs_reset++; in irq_udc_reset()
2247 dev_dbg(udc->dev, "USB reset start\n"); in irq_udc_reset()
2250 udc->gadget.speed = USB_SPEED_FULL; in irq_udc_reset()
2251 memset(&udc->stats, 0, sizeof udc->stats); in irq_udc_reset()
2253 nuke(ep, -EPROTO); in irq_udc_reset()
2259 * pxa_udc_irq - Main irq handler
2273 dev_vdbg(udc->dev, "Interrupt, UDCISR0:0x%08x, UDCISR1:0x%08x, " in pxa_udc_irq()
2341 { .compatible = "marvell,pxa270-udc" },
2348 * pxa_udc_probe - probes the udc device
2358 struct pxa2xx_udc_mach_info *mach = dev_get_platdata(&pdev->dev); in pxa_udc_probe()
2361 gpio = mach->gpio_pullup; in pxa_udc_probe()
2363 retval = devm_gpio_request_one(&pdev->dev, gpio, in pxa_udc_probe()
2368 udc->gpiod = gpio_to_desc(mach->gpio_pullup); in pxa_udc_probe()
2370 if (mach->gpio_pullup_inverted ^ gpiod_is_active_low(udc->gpiod)) in pxa_udc_probe()
2371 gpiod_toggle_active_low(udc->gpiod); in pxa_udc_probe()
2373 udc->udc_command = mach->udc_command; in pxa_udc_probe()
2375 udc->gpiod = devm_gpiod_get(&pdev->dev, NULL, GPIOD_ASIS); in pxa_udc_probe()
2378 udc->regs = devm_platform_ioremap_resource(pdev, 0); in pxa_udc_probe()
2379 if (IS_ERR(udc->regs)) in pxa_udc_probe()
2380 return PTR_ERR(udc->regs); in pxa_udc_probe()
2381 udc->irq = platform_get_irq(pdev, 0); in pxa_udc_probe()
2382 if (udc->irq < 0) in pxa_udc_probe()
2383 return udc->irq; in pxa_udc_probe()
2385 udc->dev = &pdev->dev; in pxa_udc_probe()
2387 udc->transceiver = in pxa_udc_probe()
2388 devm_usb_get_phy_by_phandle(udc->dev, "phys", 0); in pxa_udc_probe()
2389 if (IS_ERR(udc->transceiver)) in pxa_udc_probe()
2390 return PTR_ERR(udc->transceiver); in pxa_udc_probe()
2392 udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2); in pxa_udc_probe()
2395 if (IS_ERR(udc->gpiod)) { in pxa_udc_probe()
2396 dev_err(&pdev->dev, "Couldn't find or request D+ gpio : %ld\n", in pxa_udc_probe()
2397 PTR_ERR(udc->gpiod)); in pxa_udc_probe()
2398 return PTR_ERR(udc->gpiod); in pxa_udc_probe()
2400 if (udc->gpiod) in pxa_udc_probe()
2401 gpiod_direction_output(udc->gpiod, 0); in pxa_udc_probe()
2403 udc->clk = devm_clk_get(&pdev->dev, NULL); in pxa_udc_probe()
2404 if (IS_ERR(udc->clk)) in pxa_udc_probe()
2405 return PTR_ERR(udc->clk); in pxa_udc_probe()
2407 retval = clk_prepare(udc->clk); in pxa_udc_probe()
2411 udc->vbus_sensed = 0; in pxa_udc_probe()
2418 retval = devm_request_irq(&pdev->dev, udc->irq, pxa_udc_irq, in pxa_udc_probe()
2421 dev_err(udc->dev, "%s: can't get irq %i, err %d\n", in pxa_udc_probe()
2422 driver_name, udc->irq, retval); in pxa_udc_probe()
2426 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_probe()
2427 usb_register_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_probe()
2428 retval = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in pxa_udc_probe()
2438 if (!IS_ERR_OR_NULL(udc->transceiver)) in pxa_udc_probe()
2439 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_probe()
2441 clk_unprepare(udc->clk); in pxa_udc_probe()
2446 * pxa_udc_remove - removes the udc device driver
2453 usb_del_gadget_udc(&udc->gadget); in pxa_udc_remove()
2456 if (!IS_ERR_OR_NULL(udc->transceiver)) { in pxa_udc_remove()
2457 usb_unregister_notifier(udc->transceiver, &pxa27x_udc_phy); in pxa_udc_remove()
2458 usb_put_phy(udc->transceiver); in pxa_udc_remove()
2461 udc->transceiver = NULL; in pxa_udc_remove()
2463 clk_unprepare(udc->clk); in pxa_udc_remove()
2476 * pxa_udc_suspend - Suspend udc device
2488 ep = &udc->pxa_ep[0]; in pxa_udc_suspend()
2489 udc->udccsr0 = udc_ep_readl(ep, UDCCSR); in pxa_udc_suspend()
2492 udc->pullup_resume = udc->pullup_on; in pxa_udc_suspend()
2495 if (udc->driver) in pxa_udc_suspend()
2496 udc->driver->disconnect(&udc->gadget); in pxa_udc_suspend()
2502 * pxa_udc_resume - Resume udc device
2513 ep = &udc->pxa_ep[0]; in pxa_udc_resume()
2514 udc_ep_writel(ep, UDCCSR, udc->udccsr0 & (UDCCSR0_FST | UDCCSR0_DME)); in pxa_udc_resume()
2516 dplus_pullup(udc, udc->pullup_resume); in pxa_udc_resume()
2535 MODULE_ALIAS("platform:pxa27x-udc");
2539 .name = "pxa27x-udc",