Lines Matching full:udc
24 #include "isp1760-udc.h"
50 static u32 isp1760_udc_read(struct isp1760_udc *udc, u16 field) in isp1760_udc_read() argument
52 return isp1760_field_read(udc->fields, field); in isp1760_udc_read()
55 static void isp1760_udc_write(struct isp1760_udc *udc, u16 field, u32 val) in isp1760_udc_write() argument
57 isp1760_field_write(udc->fields, field, val); in isp1760_udc_write()
60 static u32 isp1760_udc_read_raw(struct isp1760_udc *udc, u16 reg) in isp1760_udc_read_raw() argument
64 regmap_raw_read(udc->regs, reg, &val, 4); in isp1760_udc_read_raw()
69 static u16 isp1760_udc_read_raw16(struct isp1760_udc *udc, u16 reg) in isp1760_udc_read_raw16() argument
73 regmap_raw_read(udc->regs, reg, &val, 2); in isp1760_udc_read_raw16()
78 static void isp1760_udc_write_raw(struct isp1760_udc *udc, u16 reg, u32 val) in isp1760_udc_write_raw() argument
82 regmap_raw_write(udc->regs, reg, &val_le, 4); in isp1760_udc_write_raw()
85 static void isp1760_udc_write_raw16(struct isp1760_udc *udc, u16 reg, u16 val) in isp1760_udc_write_raw16() argument
89 regmap_raw_write(udc->regs, reg, &val_le, 2); in isp1760_udc_write_raw16()
92 static void isp1760_udc_set(struct isp1760_udc *udc, u32 field) in isp1760_udc_set() argument
94 isp1760_udc_write(udc, field, 0xFFFFFFFF); in isp1760_udc_set()
97 static void isp1760_udc_clear(struct isp1760_udc *udc, u32 field) in isp1760_udc_clear() argument
99 isp1760_udc_write(udc, field, 0); in isp1760_udc_clear()
102 static bool isp1760_udc_is_set(struct isp1760_udc *udc, u32 field) in isp1760_udc_is_set() argument
104 return !!isp1760_udc_read(udc, field); in isp1760_udc_is_set()
110 static struct isp1760_ep *isp1760_udc_find_ep(struct isp1760_udc *udc, in isp1760_udc_find_ep() argument
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()
126 static void __isp1760_udc_select_ep(struct isp1760_udc *udc, in __isp1760_udc_select_ep() argument
129 isp1760_udc_write(udc, DC_ENDPIDX, ep->addr & USB_ENDPOINT_NUMBER_MASK); in __isp1760_udc_select_ep()
132 isp1760_udc_set(udc, DC_EPDIR); in __isp1760_udc_select_ep()
134 isp1760_udc_clear(udc, DC_EPDIR); in __isp1760_udc_select_ep()
140 * @udc: Reference to the device controller
147 * Called with the UDC spinlock held.
149 static void isp1760_udc_select_ep(struct isp1760_udc *udc, in isp1760_udc_select_ep() argument
152 __isp1760_udc_select_ep(udc, ep, ep->addr & USB_ENDPOINT_DIR_MASK); in isp1760_udc_select_ep()
155 /* Called with the UDC spinlock held. */
158 struct isp1760_udc *udc = ep->udc; in isp1760_udc_ctrl_send_status() local
166 isp1760_udc_clear(udc, DC_EPDIR); in isp1760_udc_ctrl_send_status()
168 isp1760_udc_set(udc, DC_EPDIR); in isp1760_udc_ctrl_send_status()
170 isp1760_udc_write(udc, DC_ENDPIDX, 1); in isp1760_udc_ctrl_send_status()
171 isp1760_udc_set(udc, DC_STATUS); in isp1760_udc_ctrl_send_status()
177 udc->ep0_state = ISP1760_CTRL_SETUP; in isp1760_udc_ctrl_send_status()
180 /* Called without the UDC spinlock held. */
185 struct isp1760_udc *udc = ep->udc; in isp1760_udc_request_complete() local
188 dev_dbg(ep->udc->isp->dev, "completing request %p with status %d\n", 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() local
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()
218 __isp1760_udc_select_ep(udc, ep, USB_DIR_OUT); in isp1760_udc_ctrl_send_stall()
219 isp1760_udc_set(udc, DC_STALL); in isp1760_udc_ctrl_send_stall()
220 __isp1760_udc_select_ep(udc, ep, USB_DIR_IN); in isp1760_udc_ctrl_send_stall()
221 isp1760_udc_set(udc, DC_STALL); 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()
233 /* Called with the UDC spinlock held. */
237 struct isp1760_udc *udc = ep->udc; in isp1760_udc_receive() local
242 isp1760_udc_select_ep(udc, ep); in isp1760_udc_receive()
243 len = isp1760_udc_read(udc, DC_BUFLEN); in isp1760_udc_receive()
245 dev_dbg(udc->isp->dev, "%s: received %u bytes (%u/%u done)\n", in isp1760_udc_receive()
259 isp1760_udc_set(udc, DC_CLBUF); in isp1760_udc_receive()
270 *buf = isp1760_udc_read_raw(udc, ISP176x_DC_DATAPORT); in isp1760_udc_receive()
272 *(u16 *)buf = isp1760_udc_read_raw16(udc, ISP176x_DC_DATAPORT); in isp1760_udc_receive()
281 dev_dbg(udc->isp->dev, in isp1760_udc_receive()
303 struct isp1760_udc *udc = ep->udc; in isp1760_udc_transmit() local
310 dev_dbg(udc->isp->dev, "%s: transferring %u bytes (%u/%u done)\n", in isp1760_udc_transmit()
314 __isp1760_udc_select_ep(udc, ep, USB_DIR_IN); in isp1760_udc_transmit()
317 isp1760_udc_write(udc, DC_BUFLEN, req->packet_size); in isp1760_udc_transmit()
326 isp1760_udc_write_raw(udc, ISP176x_DC_DATAPORT, *buf); in isp1760_udc_transmit()
328 isp1760_udc_write_raw16(udc, ISP176x_DC_DATAPORT, *(u16 *)buf); in isp1760_udc_transmit()
331 isp1760_udc_set(udc, DC_DSEN); in isp1760_udc_transmit()
333 isp1760_udc_set(udc, DC_VENDP); in isp1760_udc_transmit()
338 struct isp1760_udc *udc = ep->udc; in isp1760_ep_rx_ready() local
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()
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()
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()
370 spin_unlock(&udc->lock); in isp1760_ep_rx_ready()
378 struct isp1760_udc *udc = ep->udc; in isp1760_ep_tx_complete() local
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()
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()
418 dev_dbg(udc->isp->dev, in isp1760_ep_tx_complete()
450 spin_unlock(&udc->lock); in isp1760_ep_tx_complete()
458 struct isp1760_udc *udc = ep->udc; in __isp1760_udc_set_halt() local
460 dev_dbg(udc->isp->dev, "%s: %s halt on ep%02x\n", __func__, in __isp1760_udc_set_halt()
464 dev_dbg(udc->isp->dev, "%s: ep%02x is isochronous\n", __func__, in __isp1760_udc_set_halt()
469 isp1760_udc_select_ep(udc, ep); in __isp1760_udc_set_halt()
472 isp1760_udc_set(udc, DC_STALL); in __isp1760_udc_set_halt()
474 isp1760_udc_clear(udc, DC_STALL); in __isp1760_udc_set_halt()
478 __isp1760_udc_select_ep(udc, ep, USB_DIR_IN); in __isp1760_udc_set_halt()
480 isp1760_udc_set(udc, DC_STALL); in __isp1760_udc_set_halt()
482 isp1760_udc_clear(udc, DC_STALL); in __isp1760_udc_set_halt()
485 isp1760_udc_clear(udc, DC_EPENABLE); in __isp1760_udc_set_halt()
486 isp1760_udc_set(udc, DC_EPENABLE); in __isp1760_udc_set_halt()
513 static int isp1760_udc_get_status(struct isp1760_udc *udc, in isp1760_udc_get_status() argument
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()
545 isp1760_udc_set(udc, DC_EPDIR); in isp1760_udc_get_status()
546 isp1760_udc_write(udc, DC_ENDPIDX, 1); in isp1760_udc_get_status()
548 isp1760_udc_write(udc, DC_BUFLEN, 2); in isp1760_udc_get_status()
550 isp1760_udc_write_raw16(udc, ISP176x_DC_DATAPORT, status); in isp1760_udc_get_status()
552 isp1760_udc_set(udc, DC_DSEN); in isp1760_udc_get_status()
554 dev_dbg(udc->isp->dev, "%s: status 0x%04x\n", __func__, status); in isp1760_udc_get_status()
559 static int isp1760_udc_set_address(struct isp1760_udc *udc, u16 addr) in isp1760_udc_set_address() argument
562 dev_dbg(udc->isp->dev, "invalid device address %u\n", addr); 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()
573 usb_gadget_set_state(&udc->gadget, addr ? USB_STATE_ADDRESS : in isp1760_udc_set_address()
576 isp1760_udc_write(udc, DC_DEVADDR, addr); in isp1760_udc_set_address()
577 isp1760_udc_set(udc, DC_DEVEN); 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()
586 static bool isp1760_ep0_setup_standard(struct isp1760_udc *udc, in isp1760_ep0_setup_standard() argument
593 return isp1760_udc_get_status(udc, req); in isp1760_ep0_setup_standard()
610 ep = isp1760_udc_find_ep(udc, index); in isp1760_ep0_setup_standard()
614 spin_lock(&udc->lock); 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()
654 ep = isp1760_udc_find_ep(udc, index); 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()
678 return isp1760_udc_set_address(udc, le16_to_cpu(req->wValue)); 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()
704 return udc->driver->setup(&udc->gadget, req) < 0; in isp1760_ep0_setup_standard()
708 static void isp1760_ep0_setup(struct isp1760_udc *udc) in isp1760_ep0_setup() argument
717 spin_lock(&udc->lock); in isp1760_ep0_setup()
719 isp1760_udc_set(udc, DC_EP0SETUP); in isp1760_ep0_setup()
721 count = isp1760_udc_read(udc, DC_BUFLEN); 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()
732 req.data[0] = isp1760_udc_read_raw(udc, ISP176x_DC_DATAPORT); in isp1760_ep0_setup()
733 req.data[1] = isp1760_udc_read_raw(udc, ISP176x_DC_DATAPORT); 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()
761 stall = isp1760_ep0_setup_standard(udc, &req.r); 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()
777 struct isp1760_udc *udc = uep->udc; in isp1760_ep_enable() local
781 dev_dbg(uep->udc->isp->dev, "%s\n", __func__); in isp1760_ep_enable()
791 dev_dbg(udc->isp->dev, in isp1760_ep_enable()
811 dev_dbg(udc->isp->dev, "%s: control endpoints unsupported\n", in isp1760_ep_enable()
816 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_enable()
824 isp1760_udc_select_ep(udc, uep); 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()
829 isp1760_udc_write(udc, DC_ENDPTYP, type); in isp1760_ep_enable()
830 isp1760_udc_set(udc, DC_EPENABLE); 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() local
845 dev_dbg(udc->isp->dev, "%s\n", __func__); in isp1760_ep_disable()
847 spin_lock_irqsave(&udc->lock, flags); 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()
858 isp1760_udc_select_ep(udc, uep); in isp1760_ep_disable()
859 isp1760_udc_clear(udc, DC_EPENABLE); in isp1760_ep_disable()
860 isp1760_udc_clear(udc, DC_ENDPTYP); in isp1760_ep_disable()
866 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_disable()
900 struct isp1760_udc *udc = uep->udc; in isp1760_ep_queue() local
908 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_queue()
910 dev_dbg(udc->isp->dev, 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()
926 switch (udc->ep0_state) { in isp1760_ep_queue()
928 dev_dbg(udc->isp->dev, "%s: transmitting req %p\n", in isp1760_ep_queue()
937 __isp1760_udc_select_ep(udc, uep, USB_DIR_OUT); in isp1760_ep_queue()
938 isp1760_udc_set(udc, DC_DSEN); in isp1760_ep_queue()
946 dev_dbg(udc->isp->dev, "%s: invalid ep0 state\n", in isp1760_ep_queue()
960 dev_dbg(udc->isp->dev, 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() local
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()
994 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_dequeue()
1005 struct isp1760_udc *udc = uep->udc; in __isp1760_ep_set_halt() local
1015 if (WARN_ON(udc->ep0_state == ISP1760_CTRL_SETUP || !stall || in __isp1760_ep_set_halt()
1022 dev_dbg(udc->isp->dev, "%s: ep%02x is disabled\n", __func__, in __isp1760_ep_set_halt()
1030 dev_dbg(udc->isp->dev, in __isp1760_ep_set_halt()
1046 udc->ep0_state = ISP1760_CTRL_SETUP; 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()
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()
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() local
1096 spin_lock_irqsave(&udc->lock, flags); in isp1760_ep_fifo_flush()
1098 isp1760_udc_select_ep(udc, uep); in isp1760_ep_fifo_flush()
1104 isp1760_udc_set(udc, DC_CLBUF); in isp1760_ep_fifo_flush()
1105 isp1760_udc_set(udc, DC_CLBUF); in isp1760_ep_fifo_flush()
1107 spin_unlock_irqrestore(&udc->lock, flags); in isp1760_ep_fifo_flush()
1126 /* Called with the UDC spinlock held. */
1127 static void isp1760_udc_connect(struct isp1760_udc *udc) in isp1760_udc_connect() argument
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()
1133 /* Called with the UDC spinlock held. */
1134 static void isp1760_udc_disconnect(struct isp1760_udc *udc) in isp1760_udc_disconnect() argument
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()
1153 static void isp1760_udc_init_hw(struct isp1760_udc *udc) in isp1760_udc_init_hw() argument
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()
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()
1183 isp1760_udc_set(udc, DC_DEVEN); in isp1760_udc_init_hw()
1186 static void isp1760_udc_reset(struct isp1760_udc *udc) in isp1760_udc_reset() argument
1190 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_reset()
1194 * reinitialize the UDC hardware. in isp1760_udc_reset()
1196 isp1760_udc_init_hw(udc); 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()
1206 static void isp1760_udc_suspend(struct isp1760_udc *udc) in isp1760_udc_suspend() argument
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()
1215 static void isp1760_udc_resume(struct isp1760_udc *udc) in isp1760_udc_resume() argument
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()
1230 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_get_frame() local
1232 return isp1760_udc_read(udc, DC_FRAMENUM); in isp1760_udc_get_frame()
1237 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_wakeup() local
1239 dev_dbg(udc->isp->dev, "%s\n", __func__); in isp1760_udc_wakeup()
1246 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_set_selfpowered() local
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()
1258 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_pullup() local
1260 isp1760_set_pullup(udc->isp, is_on); in isp1760_udc_pullup()
1261 udc->connected = is_on; in isp1760_udc_pullup()
1269 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_start() local
1274 dev_err(udc->isp->dev, "Invalid gadget driver\n"); 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()
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()
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()
1299 isp1760_udc_set(udc, DC_GLINTENA); in isp1760_udc_start()
1301 isp1760_udc_init_hw(udc); in isp1760_udc_start()
1303 dev_dbg(udc->isp->dev, "UDC started with driver %s\n", in isp1760_udc_start()
1311 struct isp1760_udc *udc = gadget_to_udc(gadget); in isp1760_udc_stop() local
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()
1341 static u32 isp1760_udc_irq_get_status(struct isp1760_udc *udc) in isp1760_udc_irq_get_status() argument
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()
1360 struct isp1760_udc *udc = dev; in isp1760_udc_irq() local
1364 status = isp1760_udc_irq_get_status(udc); in isp1760_udc_irq()
1367 dev_dbg(udc->isp->dev, "%s(VBUS)\n", __func__); in isp1760_udc_irq()
1369 spin_lock(&udc->lock); in isp1760_udc_irq()
1370 isp1760_udc_connect(udc); 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()
1377 isp1760_udc_reset(udc); 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()
1395 dev_dbg(udc->isp->dev, "%s(EP0SETUP)\n", __func__); in isp1760_udc_irq()
1397 isp1760_ep0_setup(udc); in isp1760_udc_irq()
1401 dev_dbg(udc->isp->dev, "%s(RESM)\n", __func__); in isp1760_udc_irq()
1402 isp1760_udc_resume(udc); 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()
1409 if (!isp1760_udc_is_set(udc, DC_VBUSSTAT)) in isp1760_udc_irq()
1410 isp1760_udc_disconnect(udc); in isp1760_udc_irq()
1412 isp1760_udc_suspend(udc); 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()
1426 struct isp1760_udc *udc = from_timer(udc, t, vbus_timer); in isp1760_udc_vbus_poll() local
1429 spin_lock_irqsave(&udc->lock, flags); in isp1760_udc_vbus_poll()
1431 if (!(isp1760_udc_is_set(udc, DC_VBUSSTAT))) in isp1760_udc_vbus_poll()
1432 isp1760_udc_disconnect(udc); 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()
1444 static void isp1760_udc_init_eps(struct isp1760_udc *udc) in isp1760_udc_init_eps() argument
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()
1480 udc->gadget.ep0 = &ep->ep; in isp1760_udc_init_eps()
1487 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in isp1760_udc_init_eps()
1497 static int isp1760_udc_init(struct isp1760_udc *udc) in isp1760_udc_init() argument
1499 u32 mode_reg = udc->is_isp1763 ? ISP1763_DC_MODE : ISP176x_DC_MODE; in isp1760_udc_init()
1509 isp1760_udc_write(udc, DC_SCRATCH, 0xbabe); in isp1760_udc_init()
1510 chipid = isp1760_udc_read(udc, DC_CHIP_ID_HIGH) << 16; in isp1760_udc_init()
1511 chipid |= isp1760_udc_read(udc, DC_CHIP_ID_LOW); in isp1760_udc_init()
1512 scratch = isp1760_udc_read(udc, DC_SCRATCH); in isp1760_udc_init()
1515 dev_err(udc->isp->dev, in isp1760_udc_init()
1516 "udc: scratch test failed (0x%04x/0x%08x)\n", in isp1760_udc_init()
1523 dev_err(udc->isp->dev, "udc: invalid chip ID 0x%08x\n", chipid); in isp1760_udc_init()
1528 isp1760_udc_set(udc, DC_SFRESET); 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() local
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()
1548 ret = isp1760_udc_init(udc); 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()
1557 udc->irqname, udc); in isp1760_udc_register()
1561 udc->irq = irq; in isp1760_udc_register()
1566 * by the UDC core. 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()
1573 isp1760_udc_init_eps(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() local
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()