Lines Matching +full:halt +full:- +full:regs
1 // SPDX-License-Identifier: GPL-2.0
22 #include "isp1760-core.h"
23 #include "isp1760-regs.h"
24 #include "isp1760-udc.h"
52 return isp1760_field_read(udc->fields, field); in isp1760_udc_read()
57 isp1760_field_write(udc->fields, field, val); in isp1760_udc_write()
64 regmap_raw_read(udc->regs, reg, &val, 4); in isp1760_udc_read_raw()
73 regmap_raw_read(udc->regs, reg, &val, 2); in isp1760_udc_read_raw16()
82 regmap_raw_write(udc->regs, reg, &val_le, 4); in isp1760_udc_write_raw()
89 regmap_raw_write(udc->regs, reg, &val_le, 2); in isp1760_udc_write_raw16()
106 /* -----------------------------------------------------------------------------
116 return &udc->ep[0]; in isp1760_udc_find_ep()
118 for (i = 1; i < ARRAY_SIZE(udc->ep); ++i) { in isp1760_udc_find_ep()
119 if (udc->ep[i].addr == index) in isp1760_udc_find_ep()
120 return udc->ep[i].desc ? &udc->ep[i] : NULL; in isp1760_udc_find_ep()
129 isp1760_udc_write(udc, DC_ENDPIDX, ep->addr & USB_ENDPOINT_NUMBER_MASK); in __isp1760_udc_select_ep()
138 * isp1760_udc_select_ep - Select an endpoint for register access
152 __isp1760_udc_select_ep(udc, ep, ep->addr & USB_ENDPOINT_DIR_MASK); in isp1760_udc_select_ep()
158 struct isp1760_udc *udc = ep->udc; in isp1760_udc_ctrl_send_status()
177 udc->ep0_state = ISP1760_CTRL_SETUP; in isp1760_udc_ctrl_send_status()
185 struct isp1760_udc *udc = ep->udc; in isp1760_udc_request_complete()
188 dev_dbg(ep->udc->isp->dev, "completing request %p with status %d\n", in isp1760_udc_request_complete()
191 req->ep = NULL; in isp1760_udc_request_complete()
192 req->req.status = status; in isp1760_udc_request_complete()
193 req->req.complete(&ep->ep, &req->req); in isp1760_udc_request_complete()
195 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_request_complete()
202 if (status == 0 && ep->addr == 0 && udc->ep0_dir == USB_DIR_OUT) in isp1760_udc_request_complete()
205 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_request_complete()
210 struct isp1760_udc *udc = ep->udc; in isp1760_udc_ctrl_send_stall()
213 dev_dbg(ep->udc->isp->dev, "%s(ep%02x)\n", __func__, ep->addr); in isp1760_udc_ctrl_send_stall()
215 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_ctrl_send_stall()
224 udc->ep0_state = ISP1760_CTRL_SETUP; in isp1760_udc_ctrl_send_stall()
226 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_ctrl_send_stall()
229 /* -----------------------------------------------------------------------------
237 struct isp1760_udc *udc = ep->udc; in isp1760_udc_receive()
245 dev_dbg(udc->isp->dev, "%s: received %u bytes (%u/%u done)\n", in isp1760_udc_receive()
246 __func__, len, req->req.actual, req->req.length); in isp1760_udc_receive()
248 len = min(len, req->req.length - req->req.actual); in isp1760_udc_receive()
263 buf = req->req.buf + req->req.actual; in isp1760_udc_receive()
269 for (i = len; i > 2; i -= 4, ++buf) in isp1760_udc_receive()
274 req->req.actual += len; in isp1760_udc_receive()
281 dev_dbg(udc->isp->dev, in isp1760_udc_receive()
283 __func__, req, req->req.actual, req->req.length, ep->maxpacket, in isp1760_udc_receive()
286 ep->rx_pending = false; in isp1760_udc_receive()
292 if (req->req.actual == req->req.length || len < ep->maxpacket) { in isp1760_udc_receive()
293 list_del(&req->queue); in isp1760_udc_receive()
303 struct isp1760_udc *udc = ep->udc; in isp1760_udc_transmit()
304 u32 *buf = req->req.buf + req->req.actual; in isp1760_udc_transmit()
307 req->packet_size = min(req->req.length - req->req.actual, in isp1760_udc_transmit()
308 ep->maxpacket); in isp1760_udc_transmit()
310 dev_dbg(udc->isp->dev, "%s: transferring %u bytes (%u/%u done)\n", in isp1760_udc_transmit()
311 __func__, req->packet_size, req->req.actual, in isp1760_udc_transmit()
312 req->req.length); in isp1760_udc_transmit()
316 if (req->packet_size) in isp1760_udc_transmit()
317 isp1760_udc_write(udc, DC_BUFLEN, req->packet_size); in isp1760_udc_transmit()
325 for (i = req->packet_size; i > 2; i -= 4, ++buf) in isp1760_udc_transmit()
330 if (ep->addr == 0) in isp1760_udc_transmit()
332 if (!req->packet_size) in isp1760_udc_transmit()
338 struct isp1760_udc *udc = ep->udc; in isp1760_ep_rx_ready()
342 spin_lock(&udc->lock); in isp1760_ep_rx_ready()
344 if (ep->addr == 0 && udc->ep0_state != ISP1760_CTRL_DATA_OUT) { in isp1760_ep_rx_ready()
345 spin_unlock(&udc->lock); in isp1760_ep_rx_ready()
346 dev_dbg(udc->isp->dev, "%s: invalid ep0 state %u\n", __func__, in isp1760_ep_rx_ready()
347 udc->ep0_state); in isp1760_ep_rx_ready()
351 if (ep->addr != 0 && !ep->desc) { in isp1760_ep_rx_ready()
352 spin_unlock(&udc->lock); in isp1760_ep_rx_ready()
353 dev_dbg(udc->isp->dev, "%s: ep%02x is disabled\n", __func__, in isp1760_ep_rx_ready()
354 ep->addr); in isp1760_ep_rx_ready()
358 if (list_empty(&ep->queue)) { in isp1760_ep_rx_ready()
359 ep->rx_pending = true; in isp1760_ep_rx_ready()
360 spin_unlock(&udc->lock); in isp1760_ep_rx_ready()
361 dev_dbg(udc->isp->dev, "%s: ep%02x (%p) has no request queued\n", in isp1760_ep_rx_ready()
362 __func__, ep->addr, ep); in isp1760_ep_rx_ready()
366 req = list_first_entry(&ep->queue, struct isp1760_request, in isp1760_ep_rx_ready()
370 spin_unlock(&udc->lock); in isp1760_ep_rx_ready()
378 struct isp1760_udc *udc = ep->udc; in isp1760_ep_tx_complete()
383 spin_lock(&udc->lock); in isp1760_ep_tx_complete()
385 if (ep->addr == 0 && udc->ep0_state != ISP1760_CTRL_DATA_IN) { in isp1760_ep_tx_complete()
386 spin_unlock(&udc->lock); in isp1760_ep_tx_complete()
387 dev_dbg(udc->isp->dev, "TX IRQ: invalid endpoint state %u\n", in isp1760_ep_tx_complete()
388 udc->ep0_state); in isp1760_ep_tx_complete()
392 if (list_empty(&ep->queue)) { in isp1760_ep_tx_complete()
398 if (ep->addr == 0) { in isp1760_ep_tx_complete()
400 spin_unlock(&udc->lock); in isp1760_ep_tx_complete()
404 spin_unlock(&udc->lock); in isp1760_ep_tx_complete()
405 dev_dbg(udc->isp->dev, "%s: ep%02x has no request queued\n", in isp1760_ep_tx_complete()
406 __func__, ep->addr); in isp1760_ep_tx_complete()
410 req = list_first_entry(&ep->queue, struct isp1760_request, in isp1760_ep_tx_complete()
412 req->req.actual += req->packet_size; in isp1760_ep_tx_complete()
414 need_zlp = req->req.actual == req->req.length && in isp1760_ep_tx_complete()
415 !(req->req.length % ep->maxpacket) && in isp1760_ep_tx_complete()
416 req->packet_size && req->req.zero; in isp1760_ep_tx_complete()
418 dev_dbg(udc->isp->dev, in isp1760_ep_tx_complete()
420 req, req->req.actual, req->req.length, ep->maxpacket, in isp1760_ep_tx_complete()
421 req->packet_size, req->req.zero, need_zlp); in isp1760_ep_tx_complete()
427 if (req->req.actual == req->req.length && !need_zlp) { in isp1760_ep_tx_complete()
429 list_del(&req->queue); in isp1760_ep_tx_complete()
431 if (ep->addr == 0) in isp1760_ep_tx_complete()
434 if (!list_empty(&ep->queue)) in isp1760_ep_tx_complete()
435 req = list_first_entry(&ep->queue, in isp1760_ep_tx_complete()
450 spin_unlock(&udc->lock); in isp1760_ep_tx_complete()
456 static int __isp1760_udc_set_halt(struct isp1760_ep *ep, bool halt) in __isp1760_udc_set_halt() argument
458 struct isp1760_udc *udc = ep->udc; in __isp1760_udc_set_halt()
460 dev_dbg(udc->isp->dev, "%s: %s halt on ep%02x\n", __func__, in __isp1760_udc_set_halt()
461 halt ? "set" : "clear", ep->addr); in __isp1760_udc_set_halt()
463 if (ep->desc && usb_endpoint_xfer_isoc(ep->desc)) { in __isp1760_udc_set_halt()
464 dev_dbg(udc->isp->dev, "%s: ep%02x is isochronous\n", __func__, in __isp1760_udc_set_halt()
465 ep->addr); in __isp1760_udc_set_halt()
466 return -EINVAL; in __isp1760_udc_set_halt()
471 if (halt) in __isp1760_udc_set_halt()
476 if (ep->addr == 0) { in __isp1760_udc_set_halt()
479 if (halt) in __isp1760_udc_set_halt()
483 } else if (!halt) { in __isp1760_udc_set_halt()
495 if ((ep->addr & USB_DIR_IN) && !list_empty(&ep->queue)) { in __isp1760_udc_set_halt()
498 req = list_first_entry(&ep->queue, in __isp1760_udc_set_halt()
504 ep->halted = halt; in __isp1760_udc_set_halt()
509 /* -----------------------------------------------------------------------------
519 if (req->wLength != cpu_to_le16(2) || req->wValue != cpu_to_le16(0)) in isp1760_udc_get_status()
520 return -EINVAL; in isp1760_udc_get_status()
522 switch (req->bRequestType) { in isp1760_udc_get_status()
524 status = udc->devstatus; in isp1760_udc_get_status()
532 ep = isp1760_udc_find_ep(udc, le16_to_cpu(req->wIndex)); in isp1760_udc_get_status()
534 return -EINVAL; in isp1760_udc_get_status()
537 if (ep->halted) in isp1760_udc_get_status()
542 return -EINVAL; in isp1760_udc_get_status()
554 dev_dbg(udc->isp->dev, "%s: status 0x%04x\n", __func__, status); in isp1760_udc_get_status()
562 dev_dbg(udc->isp->dev, "invalid device address %u\n", addr); in isp1760_udc_set_address()
563 return -EINVAL; in isp1760_udc_set_address()
566 if (udc->gadget.state != USB_STATE_DEFAULT && in isp1760_udc_set_address()
567 udc->gadget.state != USB_STATE_ADDRESS) { in isp1760_udc_set_address()
568 dev_dbg(udc->isp->dev, "can't set address in state %u\n", in isp1760_udc_set_address()
569 udc->gadget.state); in isp1760_udc_set_address()
570 return -EINVAL; in isp1760_udc_set_address()
573 usb_gadget_set_state(&udc->gadget, addr ? USB_STATE_ADDRESS : in isp1760_udc_set_address()
579 spin_lock(&udc->lock); in isp1760_udc_set_address()
580 isp1760_udc_ctrl_send_status(&udc->ep[0], USB_DIR_OUT); in isp1760_udc_set_address()
581 spin_unlock(&udc->lock); in isp1760_udc_set_address()
591 switch (req->bRequest) { in isp1760_ep0_setup_standard()
596 switch (req->bRequestType) { in isp1760_ep0_setup_standard()
603 u16 index = le16_to_cpu(req->wIndex); in isp1760_ep0_setup_standard()
606 if (req->wLength != cpu_to_le16(0) || in isp1760_ep0_setup_standard()
607 req->wValue != cpu_to_le16(USB_ENDPOINT_HALT)) in isp1760_ep0_setup_standard()
614 spin_lock(&udc->lock); in isp1760_ep0_setup_standard()
618 * the halt feature. Pretend success in that case, but in isp1760_ep0_setup_standard()
621 if (!ep->wedged) in isp1760_ep0_setup_standard()
627 isp1760_udc_ctrl_send_status(&udc->ep[0], in isp1760_ep0_setup_standard()
630 spin_unlock(&udc->lock); in isp1760_ep0_setup_standard()
640 switch (req->bRequestType) { in isp1760_ep0_setup_standard()
647 u16 index = le16_to_cpu(req->wIndex); in isp1760_ep0_setup_standard()
650 if (req->wLength != cpu_to_le16(0) || in isp1760_ep0_setup_standard()
651 req->wValue != cpu_to_le16(USB_ENDPOINT_HALT)) in isp1760_ep0_setup_standard()
658 spin_lock(&udc->lock); in isp1760_ep0_setup_standard()
662 isp1760_udc_ctrl_send_status(&udc->ep[0], in isp1760_ep0_setup_standard()
665 spin_unlock(&udc->lock); in isp1760_ep0_setup_standard()
675 if (req->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) in isp1760_ep0_setup_standard()
678 return isp1760_udc_set_address(udc, le16_to_cpu(req->wValue)); in isp1760_ep0_setup_standard()
681 if (req->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) in isp1760_ep0_setup_standard()
684 if (udc->gadget.state != USB_STATE_ADDRESS && in isp1760_ep0_setup_standard()
685 udc->gadget.state != USB_STATE_CONFIGURED) in isp1760_ep0_setup_standard()
688 stall = udc->driver->setup(&udc->gadget, req) < 0; in isp1760_ep0_setup_standard()
692 usb_gadget_set_state(&udc->gadget, req->wValue ? in isp1760_ep0_setup_standard()
696 * SET_CONFIGURATION (and SET_INTERFACE) must reset the halt in isp1760_ep0_setup_standard()
699 * reenable endpoints, clearing the halt feature. in isp1760_ep0_setup_standard()
704 return udc->driver->setup(&udc->gadget, req) < 0; in isp1760_ep0_setup_standard()
717 spin_lock(&udc->lock); in isp1760_ep0_setup()
723 spin_unlock(&udc->lock); in isp1760_ep0_setup()
725 dev_err(udc->isp->dev, "invalid length %u for setup packet\n", in isp1760_ep0_setup()
728 isp1760_udc_ctrl_send_stall(&udc->ep[0]); in isp1760_ep0_setup()
735 if (udc->ep0_state != ISP1760_CTRL_SETUP) { in isp1760_ep0_setup()
736 spin_unlock(&udc->lock); in isp1760_ep0_setup()
737 dev_dbg(udc->isp->dev, "unexpected SETUP packet\n"); in isp1760_ep0_setup()
743 udc->ep0_state = ISP1760_CTRL_STATUS; in isp1760_ep0_setup()
745 udc->ep0_state = ISP1760_CTRL_DATA_IN; in isp1760_ep0_setup()
747 udc->ep0_state = ISP1760_CTRL_DATA_OUT; in isp1760_ep0_setup()
749 udc->ep0_dir = req.r.bRequestType & USB_DIR_IN; in isp1760_ep0_setup()
750 udc->ep0_length = le16_to_cpu(req.r.wLength); in isp1760_ep0_setup()
752 spin_unlock(&udc->lock); in isp1760_ep0_setup()
754 dev_dbg(udc->isp->dev, in isp1760_ep0_setup()
763 stall = udc->driver->setup(&udc->gadget, &req.r) < 0; in isp1760_ep0_setup()
766 isp1760_udc_ctrl_send_stall(&udc->ep[0]); in isp1760_ep0_setup()
769 /* -----------------------------------------------------------------------------
777 struct isp1760_udc *udc = uep->udc; in isp1760_ep_enable()
781 dev_dbg(uep->udc->isp->dev, "%s\n", __func__); in isp1760_ep_enable()
787 if (desc->bDescriptorType != USB_DT_ENDPOINT || in isp1760_ep_enable()
788 desc->bEndpointAddress == 0 || in isp1760_ep_enable()
789 desc->bEndpointAddress != uep->addr || in isp1760_ep_enable()
790 le16_to_cpu(desc->wMaxPacketSize) > ep->maxpacket) { in isp1760_ep_enable()
791 dev_dbg(udc->isp->dev, in isp1760_ep_enable()
793 __func__, desc->bDescriptorType, in isp1760_ep_enable()
794 desc->bEndpointAddress, uep->addr, in isp1760_ep_enable()
795 le16_to_cpu(desc->wMaxPacketSize), ep->maxpacket); in isp1760_ep_enable()
796 return -EINVAL; in isp1760_ep_enable()
811 dev_dbg(udc->isp->dev, "%s: control endpoints unsupported\n", in isp1760_ep_enable()
813 return -EINVAL; in isp1760_ep_enable()
816 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_enable()
818 uep->desc = desc; in isp1760_ep_enable()
819 uep->maxpacket = le16_to_cpu(desc->wMaxPacketSize); in isp1760_ep_enable()
820 uep->rx_pending = false; in isp1760_ep_enable()
821 uep->halted = false; in isp1760_ep_enable()
822 uep->wedged = false; in isp1760_ep_enable()
826 isp1760_udc_write(udc, DC_FFOSZ, uep->maxpacket); in isp1760_ep_enable()
827 isp1760_udc_write(udc, DC_BUFLEN, uep->maxpacket); in isp1760_ep_enable()
832 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_enable()
840 struct isp1760_udc *udc = uep->udc; in isp1760_ep_disable()
845 dev_dbg(udc->isp->dev, "%s\n", __func__); in isp1760_ep_disable()
847 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_disable()
849 if (!uep->desc) { in isp1760_ep_disable()
850 dev_dbg(udc->isp->dev, "%s: endpoint not enabled\n", __func__); in isp1760_ep_disable()
851 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_disable()
852 return -EINVAL; in isp1760_ep_disable()
855 uep->desc = NULL; in isp1760_ep_disable()
856 uep->maxpacket = 0; in isp1760_ep_disable()
864 list_splice_init(&uep->queue, &req_list); in isp1760_ep_disable()
866 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_disable()
869 list_del(&req->queue); in isp1760_ep_disable()
870 isp1760_udc_request_complete(uep, req, -ESHUTDOWN); in isp1760_ep_disable()
885 return &req->req; in isp1760_ep_alloc_request()
900 struct isp1760_udc *udc = uep->udc; in isp1760_ep_queue()
905 _req->status = -EINPROGRESS; in isp1760_ep_queue()
906 _req->actual = 0; in isp1760_ep_queue()
908 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_queue()
910 dev_dbg(udc->isp->dev, in isp1760_ep_queue()
912 _req->length, _req->zero ? " (zlp)" : "", uep, uep->addr); in isp1760_ep_queue()
914 req->ep = uep; in isp1760_ep_queue()
916 if (uep->addr == 0) { in isp1760_ep_queue()
917 if (_req->length != udc->ep0_length && in isp1760_ep_queue()
918 udc->ep0_state != ISP1760_CTRL_DATA_IN) { in isp1760_ep_queue()
919 dev_dbg(udc->isp->dev, in isp1760_ep_queue()
921 __func__, _req->length, req); in isp1760_ep_queue()
922 ret = -EINVAL; in isp1760_ep_queue()
926 switch (udc->ep0_state) { in isp1760_ep_queue()
928 dev_dbg(udc->isp->dev, "%s: transmitting req %p\n", in isp1760_ep_queue()
931 list_add_tail(&req->queue, &uep->queue); in isp1760_ep_queue()
936 list_add_tail(&req->queue, &uep->queue); in isp1760_ep_queue()
946 dev_dbg(udc->isp->dev, "%s: invalid ep0 state\n", in isp1760_ep_queue()
948 ret = -EINVAL; in isp1760_ep_queue()
951 } else if (uep->desc) { in isp1760_ep_queue()
952 bool empty = list_empty(&uep->queue); in isp1760_ep_queue()
954 list_add_tail(&req->queue, &uep->queue); in isp1760_ep_queue()
955 if ((uep->addr & USB_DIR_IN) && !uep->halted && empty) in isp1760_ep_queue()
957 else if (!(uep->addr & USB_DIR_IN) && uep->rx_pending) in isp1760_ep_queue()
960 dev_dbg(udc->isp->dev, in isp1760_ep_queue()
962 __func__, uep->addr); in isp1760_ep_queue()
963 ret = -ESHUTDOWN; in isp1760_ep_queue()
968 req->ep = NULL; in isp1760_ep_queue()
970 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_queue()
982 struct isp1760_udc *udc = uep->udc; in isp1760_ep_dequeue()
985 dev_dbg(uep->udc->isp->dev, "%s(ep%02x)\n", __func__, uep->addr); in isp1760_ep_dequeue()
987 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_dequeue()
989 if (req->ep != uep) in isp1760_ep_dequeue()
992 list_del(&req->queue); in isp1760_ep_dequeue()
994 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_dequeue()
997 return -EINVAL; in isp1760_ep_dequeue()
999 isp1760_udc_request_complete(uep, req, -ECONNRESET); in isp1760_ep_dequeue()
1005 struct isp1760_udc *udc = uep->udc; in __isp1760_ep_set_halt()
1008 if (!uep->addr) { in __isp1760_ep_set_halt()
1012 * stage and that the gadget isn't trying to clear the halt in __isp1760_ep_set_halt()
1015 if (WARN_ON(udc->ep0_state == ISP1760_CTRL_SETUP || !stall || in __isp1760_ep_set_halt()
1017 return -EINVAL; in __isp1760_ep_set_halt()
1021 if (uep->addr && !uep->desc) { in __isp1760_ep_set_halt()
1022 dev_dbg(udc->isp->dev, "%s: ep%02x is disabled\n", __func__, in __isp1760_ep_set_halt()
1023 uep->addr); in __isp1760_ep_set_halt()
1024 return -EINVAL; in __isp1760_ep_set_halt()
1027 if (uep->addr & USB_DIR_IN) { in __isp1760_ep_set_halt()
1028 /* Refuse to halt IN endpoints with active transfers. */ in __isp1760_ep_set_halt()
1029 if (!list_empty(&uep->queue)) { in __isp1760_ep_set_halt()
1030 dev_dbg(udc->isp->dev, in __isp1760_ep_set_halt()
1032 uep->addr); in __isp1760_ep_set_halt()
1033 return -EAGAIN; in __isp1760_ep_set_halt()
1041 if (!uep->addr) { in __isp1760_ep_set_halt()
1046 udc->ep0_state = ISP1760_CTRL_SETUP; in __isp1760_ep_set_halt()
1051 uep->wedged = true; in __isp1760_ep_set_halt()
1053 uep->wedged = false; in __isp1760_ep_set_halt()
1064 dev_dbg(uep->udc->isp->dev, "%s: %s halt on ep%02x\n", __func__, in isp1760_ep_set_halt()
1065 value ? "set" : "clear", uep->addr); in isp1760_ep_set_halt()
1067 spin_lock_irqsave(&uep->udc->lock, flags); in isp1760_ep_set_halt()
1069 spin_unlock_irqrestore(&uep->udc->lock, flags); in isp1760_ep_set_halt()
1080 dev_dbg(uep->udc->isp->dev, "%s: set wedge on ep%02x)\n", __func__, in isp1760_ep_set_wedge()
1081 uep->addr); in isp1760_ep_set_wedge()
1083 spin_lock_irqsave(&uep->udc->lock, flags); in isp1760_ep_set_wedge()
1085 spin_unlock_irqrestore(&uep->udc->lock, flags); in isp1760_ep_set_wedge()
1093 struct isp1760_udc *udc = uep->udc; in isp1760_ep_fifo_flush()
1096 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_fifo_flush()
1107 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_fifo_flush()
1122 /* -----------------------------------------------------------------------------
1129 usb_gadget_set_state(&udc->gadget, USB_STATE_POWERED); in isp1760_udc_connect()
1130 mod_timer(&udc->vbus_timer, jiffies + ISP1760_VBUS_POLL_INTERVAL); in isp1760_udc_connect()
1136 if (udc->gadget.state < USB_STATE_POWERED) in isp1760_udc_disconnect()
1139 dev_dbg(udc->isp->dev, "Device disconnected in state %u\n", in isp1760_udc_disconnect()
1140 udc->gadget.state); in isp1760_udc_disconnect()
1142 udc->gadget.speed = USB_SPEED_UNKNOWN; in isp1760_udc_disconnect()
1143 usb_gadget_set_state(&udc->gadget, USB_STATE_ATTACHED); in isp1760_udc_disconnect()
1145 if (udc->driver->disconnect) in isp1760_udc_disconnect()
1146 udc->driver->disconnect(&udc->gadget); in isp1760_udc_disconnect()
1148 del_timer(&udc->vbus_timer); in isp1760_udc_disconnect()
1155 u32 intconf = udc->is_isp1763 ? ISP1763_DC_INTCONF : ISP176x_DC_INTCONF; in isp1760_udc_init_hw()
1156 u32 intena = udc->is_isp1763 ? ISP1763_DC_INTENABLE : in isp1760_udc_init_hw()
1162 * the to active-low level-triggered. in isp1760_udc_init_hw()
1168 isp1760_reg_write(udc->regs, intconf, in isp1760_udc_init_hw()
1172 isp1760_reg_write(udc->regs, intena, DC_IEPRXTX(7) | in isp1760_udc_init_hw()
1180 if (udc->connected) in isp1760_udc_init_hw()
1181 isp1760_set_pullup(udc->isp, true); in isp1760_udc_init_hw()
1190 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_reset()
1198 udc->ep0_state = ISP1760_CTRL_SETUP; in isp1760_udc_reset()
1199 udc->gadget.speed = USB_SPEED_FULL; in isp1760_udc_reset()
1201 usb_gadget_udc_reset(&udc->gadget, udc->driver); in isp1760_udc_reset()
1203 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_reset()
1208 if (udc->gadget.state < USB_STATE_DEFAULT) in isp1760_udc_suspend()
1211 if (udc->driver->suspend) in isp1760_udc_suspend()
1212 udc->driver->suspend(&udc->gadget); in isp1760_udc_suspend()
1217 if (udc->gadget.state < USB_STATE_DEFAULT) in isp1760_udc_resume()
1220 if (udc->driver->resume) in isp1760_udc_resume()
1221 udc->driver->resume(&udc->gadget); in isp1760_udc_resume()
1224 /* -----------------------------------------------------------------------------
1239 dev_dbg(udc->isp->dev, "%s\n", __func__); in isp1760_udc_wakeup()
1240 return -ENOTSUPP; in isp1760_udc_wakeup()
1249 udc->devstatus |= 1 << USB_DEVICE_SELF_POWERED; in isp1760_udc_set_selfpowered()
1251 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in isp1760_udc_set_selfpowered()
1260 isp1760_set_pullup(udc->isp, is_on); in isp1760_udc_pullup()
1261 udc->connected = is_on; in isp1760_udc_pullup()
1273 if (driver->max_speed < USB_SPEED_FULL) { in isp1760_udc_start()
1274 dev_err(udc->isp->dev, "Invalid gadget driver\n"); in isp1760_udc_start()
1275 return -EINVAL; in isp1760_udc_start()
1278 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_start()
1280 if (udc->driver) { in isp1760_udc_start()
1281 dev_err(udc->isp->dev, "UDC already has a gadget driver\n"); in isp1760_udc_start()
1282 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_start()
1283 return -EBUSY; in isp1760_udc_start()
1286 udc->driver = driver; in isp1760_udc_start()
1288 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_start()
1290 dev_dbg(udc->isp->dev, "starting UDC with driver %s\n", in isp1760_udc_start()
1291 driver->function); in isp1760_udc_start()
1293 udc->devstatus = 0; in isp1760_udc_start()
1294 udc->connected = true; in isp1760_udc_start()
1296 usb_gadget_set_state(&udc->gadget, USB_STATE_ATTACHED); in isp1760_udc_start()
1303 dev_dbg(udc->isp->dev, "UDC started with driver %s\n", in isp1760_udc_start()
1304 driver->function); in isp1760_udc_start()
1312 u32 mode_reg = udc->is_isp1763 ? ISP1763_DC_MODE : ISP176x_DC_MODE; in isp1760_udc_stop()
1315 dev_dbg(udc->isp->dev, "%s\n", __func__); in isp1760_udc_stop()
1317 del_timer_sync(&udc->vbus_timer); in isp1760_udc_stop()
1319 isp1760_reg_write(udc->regs, mode_reg, 0); in isp1760_udc_stop()
1321 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_stop()
1322 udc->driver = NULL; in isp1760_udc_stop()
1323 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_stop()
1337 /* -----------------------------------------------------------------------------
1345 if (udc->is_isp1763) { in isp1760_udc_irq_get_status()
1346 status = isp1760_reg_read(udc->regs, ISP1763_DC_INTERRUPT) in isp1760_udc_irq_get_status()
1347 & isp1760_reg_read(udc->regs, ISP1763_DC_INTENABLE); in isp1760_udc_irq_get_status()
1348 isp1760_reg_write(udc->regs, ISP1763_DC_INTERRUPT, status); in isp1760_udc_irq_get_status()
1350 status = isp1760_reg_read(udc->regs, ISP176x_DC_INTERRUPT) in isp1760_udc_irq_get_status()
1351 & isp1760_reg_read(udc->regs, ISP176x_DC_INTENABLE); in isp1760_udc_irq_get_status()
1352 isp1760_reg_write(udc->regs, ISP176x_DC_INTERRUPT, status); in isp1760_udc_irq_get_status()
1367 dev_dbg(udc->isp->dev, "%s(VBUS)\n", __func__); in isp1760_udc_irq()
1369 spin_lock(&udc->lock); in isp1760_udc_irq()
1371 spin_unlock(&udc->lock); in isp1760_udc_irq()
1375 dev_dbg(udc->isp->dev, "%s(BRST)\n", __func__); in isp1760_udc_irq()
1381 struct isp1760_ep *ep = &udc->ep[i*2]; in isp1760_udc_irq()
1384 dev_dbg(udc->isp->dev, "%s(EPTX%u)\n", __func__, i); in isp1760_udc_irq()
1389 dev_dbg(udc->isp->dev, "%s(EPRX%u)\n", __func__, i); in isp1760_udc_irq()
1390 isp1760_ep_rx_ready(i ? ep - 1 : ep); in isp1760_udc_irq()
1395 dev_dbg(udc->isp->dev, "%s(EP0SETUP)\n", __func__); in isp1760_udc_irq()
1401 dev_dbg(udc->isp->dev, "%s(RESM)\n", __func__); in isp1760_udc_irq()
1406 dev_dbg(udc->isp->dev, "%s(SUSP)\n", __func__); in isp1760_udc_irq()
1408 spin_lock(&udc->lock); in isp1760_udc_irq()
1413 spin_unlock(&udc->lock); in isp1760_udc_irq()
1417 dev_dbg(udc->isp->dev, "%s(HS_STA)\n", __func__); in isp1760_udc_irq()
1418 udc->gadget.speed = USB_SPEED_HIGH; in isp1760_udc_irq()
1429 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_vbus_poll()
1433 else if (udc->gadget.state >= USB_STATE_POWERED) in isp1760_udc_vbus_poll()
1434 mod_timer(&udc->vbus_timer, in isp1760_udc_vbus_poll()
1437 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_udc_vbus_poll()
1440 /* -----------------------------------------------------------------------------
1448 INIT_LIST_HEAD(&udc->gadget.ep_list); in isp1760_udc_init_eps()
1450 for (i = 0; i < ARRAY_SIZE(udc->ep); ++i) { in isp1760_udc_init_eps()
1451 struct isp1760_ep *ep = &udc->ep[i]; in isp1760_udc_init_eps()
1455 ep->udc = udc; in isp1760_udc_init_eps()
1457 INIT_LIST_HEAD(&ep->queue); in isp1760_udc_init_eps()
1459 ep->addr = (ep_num && is_in ? USB_DIR_IN : USB_DIR_OUT) in isp1760_udc_init_eps()
1461 ep->desc = NULL; in isp1760_udc_init_eps()
1463 sprintf(ep->name, "ep%u%s", ep_num, in isp1760_udc_init_eps()
1466 ep->ep.ops = &isp1760_ep_ops; in isp1760_udc_init_eps()
1467 ep->ep.name = ep->name; in isp1760_udc_init_eps()
1472 * This fits in the 8kB FIFO without double-buffering. in isp1760_udc_init_eps()
1475 usb_ep_set_maxpacket_limit(&ep->ep, 64); in isp1760_udc_init_eps()
1476 ep->ep.caps.type_control = true; in isp1760_udc_init_eps()
1477 ep->ep.caps.dir_in = true; in isp1760_udc_init_eps()
1478 ep->ep.caps.dir_out = true; in isp1760_udc_init_eps()
1479 ep->maxpacket = 64; in isp1760_udc_init_eps()
1480 udc->gadget.ep0 = &ep->ep; in isp1760_udc_init_eps()
1482 usb_ep_set_maxpacket_limit(&ep->ep, 512); in isp1760_udc_init_eps()
1483 ep->ep.caps.type_iso = true; in isp1760_udc_init_eps()
1484 ep->ep.caps.type_bulk = true; in isp1760_udc_init_eps()
1485 ep->ep.caps.type_int = true; in isp1760_udc_init_eps()
1486 ep->maxpacket = 0; in isp1760_udc_init_eps()
1487 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in isp1760_udc_init_eps()
1491 ep->ep.caps.dir_in = true; in isp1760_udc_init_eps()
1493 ep->ep.caps.dir_out = true; in isp1760_udc_init_eps()
1499 u32 mode_reg = udc->is_isp1763 ? ISP1763_DC_MODE : ISP176x_DC_MODE; in isp1760_udc_init()
1515 dev_err(udc->isp->dev, in isp1760_udc_init()
1518 return -ENODEV; in isp1760_udc_init()
1523 dev_err(udc->isp->dev, "udc: invalid chip ID 0x%08x\n", chipid); in isp1760_udc_init()
1524 return -ENODEV; in isp1760_udc_init()
1530 isp1760_reg_write(udc->regs, mode_reg, 0); in isp1760_udc_init()
1539 struct isp1760_udc *udc = &isp->udc; in isp1760_udc_register()
1542 udc->irq = -1; in isp1760_udc_register()
1543 udc->isp = isp; in isp1760_udc_register()
1545 spin_lock_init(&udc->lock); in isp1760_udc_register()
1546 timer_setup(&udc->vbus_timer, isp1760_udc_vbus_poll, 0); in isp1760_udc_register()
1552 udc->irqname = kasprintf(GFP_KERNEL, "%s (udc)", dev_name(isp->dev)); in isp1760_udc_register()
1553 if (!udc->irqname) in isp1760_udc_register()
1554 return -ENOMEM; in isp1760_udc_register()
1557 udc->irqname, udc); in isp1760_udc_register()
1561 udc->irq = irq; in isp1760_udc_register()
1568 udc->gadget.ops = &isp1760_udc_ops; in isp1760_udc_register()
1569 udc->gadget.speed = USB_SPEED_UNKNOWN; in isp1760_udc_register()
1570 udc->gadget.max_speed = USB_SPEED_HIGH; in isp1760_udc_register()
1571 udc->gadget.name = "isp1761_udc"; in isp1760_udc_register()
1575 ret = usb_add_gadget_udc(isp->dev, &udc->gadget); in isp1760_udc_register()
1582 if (udc->irq >= 0) in isp1760_udc_register()
1583 free_irq(udc->irq, udc); in isp1760_udc_register()
1584 kfree(udc->irqname); in isp1760_udc_register()
1591 struct isp1760_udc *udc = &isp->udc; in isp1760_udc_unregister()
1593 if (!udc->isp) in isp1760_udc_unregister()
1596 usb_del_gadget_udc(&udc->gadget); in isp1760_udc_unregister()
1598 free_irq(udc->irq, udc); in isp1760_udc_unregister()
1599 kfree(udc->irqname); in isp1760_udc_unregister()