Lines Matching full:udc
157 struct max3420_udc *udc; member
190 static const char driver_name[] = "max3420-udc";
199 static void spi_ack_ctrl(struct max3420_udc *udc) in spi_ack_ctrl() argument
201 struct spi_device *spi = udc->spi; in spi_ack_ctrl()
218 static u8 spi_rd8_ack(struct max3420_udc *udc, u8 reg, int actstat) in spi_rd8_ack() argument
220 struct spi_device *spi = udc->spi; in spi_rd8_ack()
240 static u8 spi_rd8(struct max3420_udc *udc, u8 reg) in spi_rd8() argument
242 return spi_rd8_ack(udc, reg, 0); in spi_rd8()
245 static void spi_wr8_ack(struct max3420_udc *udc, u8 reg, u8 val, int actstat) in spi_wr8_ack() argument
247 struct spi_device *spi = udc->spi; in spi_wr8_ack()
266 static void spi_wr8(struct max3420_udc *udc, u8 reg, u8 val) in spi_wr8() argument
268 spi_wr8_ack(udc, reg, val, 0); in spi_wr8()
271 static void spi_rd_buf(struct max3420_udc *udc, u8 reg, void *buf, u8 len) in spi_rd_buf() argument
273 struct spi_device *spi = udc->spi; in spi_rd_buf()
293 static void spi_wr_buf(struct max3420_udc *udc, u8 reg, void *buf, u8 len) in spi_wr_buf() argument
295 struct spi_device *spi = udc->spi; in spi_wr_buf()
316 struct max3420_udc *udc = ep->udc; in spi_max3420_enable() local
329 epien = spi_rd8(udc, MAX3420_REG_EPIEN); in spi_max3420_enable()
330 epdis = spi_rd8(udc, MAX3420_REG_CLRTOGS); in spi_max3420_enable()
340 spi_wr8(udc, MAX3420_REG_CLRTOGS, epdis); in spi_max3420_enable()
341 spi_wr8(udc, MAX3420_REG_EPIEN, epien); in spi_max3420_enable()
348 struct max3420_udc *udc = ep->udc; in spi_max3420_stall() local
361 epstalls = spi_rd8(udc, MAX3420_REG_EPSTALLS); in spi_max3420_stall()
370 clrtogs = spi_rd8(udc, MAX3420_REG_CLRTOGS); in spi_max3420_stall()
372 spi_wr8(udc, MAX3420_REG_CLRTOGS, clrtogs); in spi_max3420_stall()
374 spi_wr8(udc, MAX3420_REG_EPSTALLS, epstalls | ACKSTAT); in spi_max3420_stall()
379 static int spi_max3420_rwkup(struct max3420_udc *udc) in spi_max3420_rwkup() argument
385 spin_lock_irqsave(&udc->lock, flags); in spi_max3420_rwkup()
386 wake_remote = udc->todo & REMOTE_WAKEUP; in spi_max3420_rwkup()
387 udc->todo &= ~REMOTE_WAKEUP; in spi_max3420_rwkup()
388 spin_unlock_irqrestore(&udc->lock, flags); in spi_max3420_rwkup()
390 if (!wake_remote || !udc->suspended) in spi_max3420_rwkup()
394 usbctl = spi_rd8(udc, MAX3420_REG_USBCTL); in spi_max3420_rwkup()
396 spi_wr8(udc, MAX3420_REG_USBCTL, usbctl); in spi_max3420_rwkup()
401 usbctl = spi_rd8(udc, MAX3420_REG_USBCTL); in spi_max3420_rwkup()
403 spi_wr8(udc, MAX3420_REG_USBCTL, usbctl); in spi_max3420_rwkup()
405 udc->suspended = false; in spi_max3420_rwkup()
411 static void __max3420_stop(struct max3420_udc *udc) in __max3420_stop() argument
418 max3420_nuke(&udc->ep[i], -ECONNRESET); in __max3420_stop()
421 spi_wr8(udc, MAX3420_REG_CPUCTL, 0); in __max3420_stop()
423 val = spi_rd8(udc, MAX3420_REG_USBCTL); in __max3420_stop()
425 if (udc->is_selfpowered) in __max3420_stop()
429 spi_wr8(udc, MAX3420_REG_USBCTL, val); in __max3420_stop()
432 static void __max3420_start(struct max3420_udc *udc) in __max3420_start() argument
442 spi_wr8(udc, MAX3420_REG_PINCTL, FDUPSPI); in __max3420_start()
445 spi_wr8(udc, MAX3420_REG_USBCTL, CHIPRES); in __max3420_start()
447 spi_wr8(udc, MAX3420_REG_USBCTL, 0); in __max3420_start()
451 val = spi_rd8(udc, MAX3420_REG_USBIRQ); in __max3420_start()
458 val = spi_rd8(udc, MAX3420_REG_USBCTL); in __max3420_start()
460 spi_wr8(udc, MAX3420_REG_USBCTL, val); in __max3420_start()
463 if (udc->is_selfpowered) in __max3420_start()
465 spi_wr8(udc, MAX3420_REG_USBIEN, val); in __max3420_start()
469 spi_wr8(udc, MAX3420_REG_EPIEN, val); in __max3420_start()
472 spi_wr8(udc, MAX3420_REG_CPUCTL, IE); in __max3420_start()
475 static int max3420_start(struct max3420_udc *udc) in max3420_start() argument
480 spin_lock_irqsave(&udc->lock, flags); in max3420_start()
481 todo = udc->todo & UDC_START; in max3420_start()
482 udc->todo &= ~UDC_START; in max3420_start()
483 spin_unlock_irqrestore(&udc->lock, flags); in max3420_start()
488 if (udc->vbus_active && udc->softconnect) in max3420_start()
489 __max3420_start(udc); in max3420_start()
491 __max3420_stop(udc); in max3420_start()
498 struct max3420_udc *udc = dev_id; in max3420_vbus_handler() local
501 spin_lock_irqsave(&udc->lock, flags); in max3420_vbus_handler()
503 udc->vbus_active = !udc->vbus_active; in max3420_vbus_handler()
504 udc->todo |= UDC_START; in max3420_vbus_handler()
505 usb_udc_vbus_handler(&udc->gadget, udc->vbus_active); in max3420_vbus_handler()
506 usb_gadget_set_state(&udc->gadget, udc->vbus_active in max3420_vbus_handler()
508 spin_unlock_irqrestore(&udc->lock, flags); in max3420_vbus_handler()
510 if (udc->thread_task) in max3420_vbus_handler()
511 wake_up_process(udc->thread_task); in max3420_vbus_handler()
518 struct max3420_udc *udc = dev_id; in max3420_irq_handler() local
519 struct spi_device *spi = udc->spi; in max3420_irq_handler()
522 spin_lock_irqsave(&udc->lock, flags); in max3420_irq_handler()
523 if ((udc->todo & ENABLE_IRQ) == 0) { in max3420_irq_handler()
525 udc->todo |= ENABLE_IRQ; in max3420_irq_handler()
527 spin_unlock_irqrestore(&udc->lock, flags); in max3420_irq_handler()
529 if (udc->thread_task) in max3420_irq_handler()
530 wake_up_process(udc->thread_task); in max3420_irq_handler()
535 static void max3420_getstatus(struct max3420_udc *udc) in max3420_getstatus() argument
540 switch (udc->setup.bRequestType & USB_RECIP_MASK) { in max3420_getstatus()
543 status = udc->gadget.is_selfpowered << USB_DEVICE_SELF_POWERED; in max3420_getstatus()
544 status |= (udc->remote_wkp << USB_DEVICE_REMOTE_WAKEUP); in max3420_getstatus()
547 if (udc->driver->setup(&udc->gadget, &udc->setup) < 0) in max3420_getstatus()
551 ep = &udc->ep[udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK]; in max3420_getstatus()
552 if (udc->setup.wIndex & USB_DIR_IN) { in max3420_getstatus()
567 spi_wr_buf(udc, MAX3420_REG_EP0FIFO, &status, 2); in max3420_getstatus()
568 spi_wr8_ack(udc, MAX3420_REG_EP0BC, 2, 1); in max3420_getstatus()
571 dev_err(udc->dev, "Can't respond to getstatus request\n"); in max3420_getstatus()
572 spi_wr8(udc, MAX3420_REG_EPSTALLS, STLEP0IN | STLEP0OUT | STLSTAT); in max3420_getstatus()
575 static void max3420_set_clear_feature(struct max3420_udc *udc) in max3420_set_clear_feature() argument
578 int set = udc->setup.bRequest == USB_REQ_SET_FEATURE; in max3420_set_clear_feature()
582 switch (udc->setup.bRequestType) { in max3420_set_clear_feature()
584 if (udc->setup.wValue != USB_DEVICE_REMOTE_WAKEUP) in max3420_set_clear_feature()
587 if (udc->setup.bRequest == USB_REQ_SET_FEATURE) in max3420_set_clear_feature()
588 udc->remote_wkp = 1; in max3420_set_clear_feature()
590 udc->remote_wkp = 0; in max3420_set_clear_feature()
592 return spi_ack_ctrl(udc); in max3420_set_clear_feature()
595 if (udc->setup.wValue != USB_ENDPOINT_HALT) in max3420_set_clear_feature()
598 id = udc->setup.wIndex & USB_ENDPOINT_NUMBER_MASK; in max3420_set_clear_feature()
599 ep = &udc->ep[id]; in max3420_set_clear_feature()
615 dev_err(udc->dev, "Can't respond to SET/CLEAR FEATURE\n"); in max3420_set_clear_feature()
616 spi_wr8(udc, MAX3420_REG_EPSTALLS, STLEP0IN | STLEP0OUT | STLSTAT); in max3420_set_clear_feature()
619 static void max3420_handle_setup(struct max3420_udc *udc) in max3420_handle_setup() argument
623 spi_rd_buf(udc, MAX3420_REG_SUDFIFO, (void *)&setup, 8); in max3420_handle_setup()
625 udc->setup = setup; in max3420_handle_setup()
626 udc->setup.wValue = cpu_to_le16(setup.wValue); in max3420_handle_setup()
627 udc->setup.wIndex = cpu_to_le16(setup.wIndex); in max3420_handle_setup()
628 udc->setup.wLength = cpu_to_le16(setup.wLength); in max3420_handle_setup()
630 switch (udc->setup.bRequest) { in max3420_handle_setup()
632 /* Data+Status phase form udc */ in max3420_handle_setup()
633 if ((udc->setup.bRequestType & in max3420_handle_setup()
638 return max3420_getstatus(udc); in max3420_handle_setup()
640 /* Status phase from udc */ in max3420_handle_setup()
641 if (udc->setup.bRequestType != (USB_DIR_OUT | in max3420_handle_setup()
645 spi_rd8_ack(udc, MAX3420_REG_FNADDR, 1); in max3420_handle_setup()
646 dev_dbg(udc->dev, "Assigned Address=%d\n", udc->setup.wValue); in max3420_handle_setup()
650 /* Requests with no data phase, status phase from udc */ in max3420_handle_setup()
651 if ((udc->setup.bRequestType & USB_TYPE_MASK) in max3420_handle_setup()
654 return max3420_set_clear_feature(udc); in max3420_handle_setup()
659 if (udc->driver->setup(&udc->gadget, &setup) < 0) { in max3420_handle_setup()
661 spi_wr8(udc, MAX3420_REG_EPSTALLS, in max3420_handle_setup()
669 struct max3420_udc *udc = ep->udc; in max3420_req_done() local
677 dev_err(udc->dev, "%s done %p, status %d\n", in max3420_req_done()
684 static int max3420_do_data(struct max3420_udc *udc, int ep_id, int in) in max3420_do_data() argument
686 struct max3420_ep *ep = &udc->ep[ep_id]; in max3420_do_data()
709 spi_wr_buf(udc, MAX3420_REG_EP0FIFO + ep_id, buf, length); in max3420_do_data()
710 spi_wr8(udc, MAX3420_REG_EP0BC + ep_id, length); in max3420_do_data()
714 psz = spi_rd8(udc, MAX3420_REG_EP0BC + ep_id); in max3420_do_data()
717 spi_rd_buf(udc, MAX3420_REG_EP0FIFO + ep_id, buf, length); in max3420_do_data()
736 spi_ack_ctrl(udc); in max3420_do_data()
744 static int max3420_handle_irqs(struct max3420_udc *udc) in max3420_handle_irqs() argument
749 spi_rd_buf(udc, MAX3420_REG_EPIRQ, reg, 4); in max3420_handle_irqs()
759 spi_wr8(udc, MAX3420_REG_EPIRQ, SUDAVIRQ); in max3420_handle_irqs()
760 max3420_handle_setup(udc); in max3420_handle_irqs()
765 spi_wr8(udc, MAX3420_REG_USBIRQ, VBUSIRQ); in max3420_handle_irqs()
766 dev_dbg(udc->dev, "Cable plugged in\n"); in max3420_handle_irqs()
771 spi_wr8(udc, MAX3420_REG_USBIRQ, NOVBUSIRQ); in max3420_handle_irqs()
772 dev_dbg(udc->dev, "Cable pulled out\n"); in max3420_handle_irqs()
777 spi_wr8(udc, MAX3420_REG_USBIRQ, URESIRQ); in max3420_handle_irqs()
778 dev_dbg(udc->dev, "USB Reset - Start\n"); in max3420_handle_irqs()
783 spi_wr8(udc, MAX3420_REG_USBIRQ, URESDNIRQ); in max3420_handle_irqs()
784 dev_dbg(udc->dev, "USB Reset - END\n"); in max3420_handle_irqs()
785 spi_wr8(udc, MAX3420_REG_USBIEN, URESDNIRQ | URESIRQ); in max3420_handle_irqs()
786 spi_wr8(udc, MAX3420_REG_EPIEN, SUDAVIRQ | IN0BAVIRQ in max3420_handle_irqs()
792 spi_wr8(udc, MAX3420_REG_USBIRQ, SUSPIRQ); in max3420_handle_irqs()
793 dev_dbg(udc->dev, "USB Suspend - Enter\n"); in max3420_handle_irqs()
794 udc->suspended = true; in max3420_handle_irqs()
799 spi_wr8(udc, MAX3420_REG_USBIRQ, BUSACTIRQ); in max3420_handle_irqs()
800 dev_dbg(udc->dev, "USB Suspend - Exit\n"); in max3420_handle_irqs()
801 udc->suspended = false; in max3420_handle_irqs()
806 spi_wr8(udc, MAX3420_REG_USBIRQ, RWUDNIRQ); in max3420_handle_irqs()
807 dev_dbg(udc->dev, "Asked Host to wakeup\n"); in max3420_handle_irqs()
812 spi_wr8(udc, MAX3420_REG_USBIRQ, OSCOKIRQ); in max3420_handle_irqs()
813 dev_dbg(udc->dev, "Osc stabilized, start work\n"); in max3420_handle_irqs()
817 if (epirq & OUT0DAVIRQ && max3420_do_data(udc, 0, 0)) { in max3420_handle_irqs()
818 spi_wr8_ack(udc, MAX3420_REG_EPIRQ, OUT0DAVIRQ, 1); in max3420_handle_irqs()
822 if (epirq & IN0BAVIRQ && max3420_do_data(udc, 0, 1)) in max3420_handle_irqs()
825 if (epirq & OUT1DAVIRQ && max3420_do_data(udc, 1, 0)) { in max3420_handle_irqs()
826 spi_wr8_ack(udc, MAX3420_REG_EPIRQ, OUT1DAVIRQ, 1); in max3420_handle_irqs()
830 if (epirq & IN2BAVIRQ && max3420_do_data(udc, 2, 1)) in max3420_handle_irqs()
833 if (epirq & IN3BAVIRQ && max3420_do_data(udc, 3, 1)) in max3420_handle_irqs()
841 struct max3420_udc *udc = dev_id; in max3420_thread() local
842 struct spi_device *spi = udc->spi; in max3420_thread()
852 spin_lock_irqsave(&udc->lock, flags); in max3420_thread()
853 if (udc->todo & ENABLE_IRQ) { in max3420_thread()
855 udc->todo &= ~ENABLE_IRQ; in max3420_thread()
857 spin_unlock_irqrestore(&udc->lock, flags); in max3420_thread()
863 mutex_lock(&udc->spi_bus_mutex); in max3420_thread()
866 if (!udc->vbus_active || !udc->softconnect) in max3420_thread()
869 if (max3420_start(udc)) { in max3420_thread()
874 if (max3420_handle_irqs(udc)) { in max3420_thread()
879 if (spi_max3420_rwkup(udc)) { in max3420_thread()
884 max3420_do_data(udc, 0, 1); /* get done with the EP0 ZLP */ in max3420_thread()
887 struct max3420_ep *ep = &udc->ep[i]; in max3420_thread()
895 mutex_unlock(&udc->spi_bus_mutex); in max3420_thread()
899 dev_info(udc->dev, "SPI thread exiting\n"); in max3420_thread()
906 struct max3420_udc *udc = ep->udc; in max3420_ep_set_halt() local
919 wake_up_process(udc->thread_task); in max3420_ep_set_halt()
921 dev_dbg(udc->dev, "%sStall %s\n", stall ? "" : "Un", ep->name); in max3420_ep_set_halt()
946 struct max3420_udc *udc = ep->udc; in max3420_ep_enable() local
950 wake_up_process(udc->thread_task); in max3420_ep_enable()
975 struct max3420_udc *udc = ep->udc; in __max3420_ep_disable() local
987 dev_dbg(udc->dev, "Disabled %s\n", ep->name); in __max3420_ep_disable()
993 struct max3420_udc *udc = ep->udc; in max3420_ep_disable() local
999 wake_up_process(udc->thread_task); in max3420_ep_disable()
1029 struct max3420_udc *udc = ep->udc; in max3420_ep_queue() local
1039 wake_up_process(udc->thread_task); in max3420_ep_queue()
1082 struct max3420_udc *udc = to_udc(gadget); in max3420_wakeup() local
1086 spin_lock_irqsave(&udc->lock, flags); in max3420_wakeup()
1089 if (udc->remote_wkp) { in max3420_wakeup()
1090 udc->todo |= REMOTE_WAKEUP; in max3420_wakeup()
1094 spin_unlock_irqrestore(&udc->lock, flags); in max3420_wakeup()
1096 if (udc->thread_task) in max3420_wakeup()
1097 wake_up_process(udc->thread_task); in max3420_wakeup()
1104 struct max3420_udc *udc = to_udc(gadget); in max3420_udc_start() local
1107 spin_lock_irqsave(&udc->lock, flags); in max3420_udc_start()
1109 udc->driver = driver; in max3420_udc_start()
1110 udc->gadget.speed = USB_SPEED_FULL; in max3420_udc_start()
1112 udc->gadget.is_selfpowered = udc->is_selfpowered; in max3420_udc_start()
1113 udc->remote_wkp = 0; in max3420_udc_start()
1114 udc->softconnect = true; in max3420_udc_start()
1115 udc->todo |= UDC_START; in max3420_udc_start()
1116 spin_unlock_irqrestore(&udc->lock, flags); in max3420_udc_start()
1118 if (udc->thread_task) in max3420_udc_start()
1119 wake_up_process(udc->thread_task); in max3420_udc_start()
1126 struct max3420_udc *udc = to_udc(gadget); in max3420_udc_stop() local
1129 spin_lock_irqsave(&udc->lock, flags); in max3420_udc_stop()
1130 udc->is_selfpowered = udc->gadget.is_selfpowered; in max3420_udc_stop()
1131 udc->gadget.speed = USB_SPEED_UNKNOWN; in max3420_udc_stop()
1132 udc->driver = NULL; in max3420_udc_stop()
1133 udc->softconnect = false; in max3420_udc_stop()
1134 udc->todo |= UDC_START; in max3420_udc_stop()
1135 spin_unlock_irqrestore(&udc->lock, flags); in max3420_udc_stop()
1137 if (udc->thread_task) in max3420_udc_stop()
1138 wake_up_process(udc->thread_task); in max3420_udc_stop()
1149 static void max3420_eps_init(struct max3420_udc *udc) in max3420_eps_init() argument
1153 INIT_LIST_HEAD(&udc->gadget.ep_list); in max3420_eps_init()
1156 struct max3420_ep *ep = &udc->ep[idx]; in max3420_eps_init()
1161 ep->udc = udc; in max3420_eps_init()
1194 &udc->gadget.ep_list); in max3420_eps_init()
1200 struct max3420_udc *udc; in max3420_probe() local
1205 dev_err(&spi->dev, "UDC needs full duplex to work\n"); in max3420_probe()
1218 udc = devm_kzalloc(&spi->dev, sizeof(*udc), GFP_KERNEL); in max3420_probe()
1219 if (!udc) in max3420_probe()
1222 udc->spi = spi; in max3420_probe()
1224 udc->remote_wkp = 0; in max3420_probe()
1227 udc->gadget.ops = &max3420_udc_ops; in max3420_probe()
1228 udc->gadget.max_speed = USB_SPEED_FULL; in max3420_probe()
1229 udc->gadget.speed = USB_SPEED_UNKNOWN; in max3420_probe()
1230 udc->gadget.ep0 = &udc->ep[0].ep_usb; in max3420_probe()
1231 udc->gadget.name = driver_name; in max3420_probe()
1233 spin_lock_init(&udc->lock); in max3420_probe()
1234 mutex_init(&udc->spi_bus_mutex); in max3420_probe()
1236 udc->ep0req.ep = &udc->ep[0]; in max3420_probe()
1237 udc->ep0req.usb_req.buf = udc->ep0buf; in max3420_probe()
1238 INIT_LIST_HEAD(&udc->ep0req.queue); in max3420_probe()
1241 max3420_eps_init(udc); in max3420_probe()
1244 spi_rd_buf(udc, MAX3420_REG_EPIRQ, reg, 8); in max3420_probe()
1245 spi_wr8(udc, MAX3420_REG_PINCTL, FDUPSPI); in max3420_probe()
1247 err = usb_add_gadget_udc(&spi->dev, &udc->gadget); in max3420_probe()
1251 udc->dev = &udc->gadget.dev; in max3420_probe()
1253 spi_set_drvdata(spi, udc); in max3420_probe()
1255 irq = of_irq_get_byname(spi->dev.of_node, "udc"); in max3420_probe()
1257 "max3420", udc); in max3420_probe()
1261 udc->thread_task = kthread_create(max3420_thread, udc, in max3420_probe()
1263 if (IS_ERR(udc->thread_task)) { in max3420_probe()
1264 err = PTR_ERR(udc->thread_task); in max3420_probe()
1270 udc->is_selfpowered = 1; in max3420_probe()
1271 udc->vbus_active = true; in max3420_probe()
1272 udc->todo |= UDC_START; in max3420_probe()
1273 usb_udc_vbus_handler(&udc->gadget, udc->vbus_active); in max3420_probe()
1274 usb_gadget_set_state(&udc->gadget, USB_STATE_POWERED); in max3420_probe()
1275 max3420_start(udc); in max3420_probe()
1277 udc->is_selfpowered = 0; in max3420_probe()
1279 spi_rd_buf(udc, MAX3420_REG_EPIRQ, reg, 8); in max3420_probe()
1281 udc->vbus_active = true; in max3420_probe()
1284 max3420_vbus_handler, 0, "vbus", udc); in max3420_probe()
1292 usb_del_gadget_udc(&udc->gadget); in max3420_probe()
1298 struct max3420_udc *udc = spi_get_drvdata(spi); in max3420_remove() local
1301 usb_del_gadget_udc(&udc->gadget); in max3420_remove()
1303 spin_lock_irqsave(&udc->lock, flags); in max3420_remove()
1305 kthread_stop(udc->thread_task); in max3420_remove()
1307 spin_unlock_irqrestore(&udc->lock, flags); in max3420_remove()
1311 { .compatible = "maxim,max3420-udc"},
1312 { .compatible = "maxim,max3421-udc"},
1319 .name = "max3420-udc",