Lines Matching full:udc
48 spin_lock_irq(&ep->udc->lock); in queue_dbg_open()
55 spin_unlock_irq(&ep->udc->lock); in queue_dbg_open()
61 spin_unlock_irq(&ep->udc->lock); in queue_dbg_open()
141 struct usba_udc *udc; in regs_dbg_open() local
147 udc = inode->i_private; in regs_dbg_open()
152 spin_lock_irq(&udc->lock); in regs_dbg_open()
154 data[i] = readl_relaxed(udc->regs + i * 4); in regs_dbg_open()
155 spin_unlock_irq(&udc->lock); in regs_dbg_open()
202 static void usba_ep_init_debugfs(struct usba_udc *udc, in usba_ep_init_debugfs() argument
207 ep_root = debugfs_create_dir(ep->ep.name, udc->debugfs_root); in usba_ep_init_debugfs()
223 static void usba_init_debugfs(struct usba_udc *udc) in usba_init_debugfs() argument
228 root = debugfs_create_dir(udc->gadget.name, usb_debug_root); in usba_init_debugfs()
229 udc->debugfs_root = root; in usba_init_debugfs()
231 regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM, in usba_init_debugfs()
235 debugfs_create_file_size("regs", 0400, root, udc, in usba_init_debugfs()
240 usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0)); in usba_init_debugfs()
243 static void usba_cleanup_debugfs(struct usba_udc *udc) in usba_cleanup_debugfs() argument
245 usba_ep_cleanup_debugfs(to_usba_ep(udc->gadget.ep0)); in usba_cleanup_debugfs()
246 debugfs_remove_recursive(udc->debugfs_root); in usba_cleanup_debugfs()
249 static inline void usba_ep_init_debugfs(struct usba_udc *udc, in usba_ep_init_debugfs() argument
260 static inline void usba_init_debugfs(struct usba_udc *udc) in usba_init_debugfs() argument
265 static inline void usba_cleanup_debugfs(struct usba_udc *udc) in usba_cleanup_debugfs() argument
322 static int usba_config_fifo_table(struct usba_udc *udc) in usba_config_fifo_table() argument
331 udc->fifo_cfg = NULL; in usba_config_fifo_table()
335 udc->fifo_cfg = mode_1_cfg; in usba_config_fifo_table()
339 udc->fifo_cfg = mode_2_cfg; in usba_config_fifo_table()
343 udc->fifo_cfg = mode_3_cfg; in usba_config_fifo_table()
347 udc->fifo_cfg = mode_4_cfg; in usba_config_fifo_table()
356 static inline u32 usba_int_enb_get(struct usba_udc *udc) in usba_int_enb_get() argument
358 return udc->int_enb_cache; in usba_int_enb_get()
361 static inline void usba_int_enb_set(struct usba_udc *udc, u32 mask) in usba_int_enb_set() argument
365 val = udc->int_enb_cache | mask; in usba_int_enb_set()
366 usba_writel(udc, INT_ENB, val); in usba_int_enb_set()
367 udc->int_enb_cache = val; in usba_int_enb_set()
370 static inline void usba_int_enb_clear(struct usba_udc *udc, u32 mask) in usba_int_enb_clear() argument
374 val = udc->int_enb_cache & ~mask; in usba_int_enb_clear()
375 usba_writel(udc, INT_ENB, val); in usba_int_enb_clear()
376 udc->int_enb_cache = val; in usba_int_enb_clear()
379 static int vbus_is_present(struct usba_udc *udc) in vbus_is_present() argument
381 if (udc->vbus_pin) in vbus_is_present()
382 return gpiod_get_value(udc->vbus_pin); in vbus_is_present()
388 static void toggle_bias(struct usba_udc *udc, int is_on) in toggle_bias() argument
390 if (udc->errata && udc->errata->toggle_bias) in toggle_bias()
391 udc->errata->toggle_bias(udc, is_on); in toggle_bias()
394 static void generate_bias_pulse(struct usba_udc *udc) in generate_bias_pulse() argument
396 if (!udc->bias_pulse_needed) in generate_bias_pulse()
399 if (udc->errata && udc->errata->pulse_bias) in generate_bias_pulse()
400 udc->errata->pulse_bias(udc); in generate_bias_pulse()
402 udc->bias_pulse_needed = false; in generate_bias_pulse()
475 static void send_status(struct usba_udc *udc, struct usba_ep *ep) in send_status() argument
484 struct usba_udc *udc = ep->udc; in receive_data() local
523 spin_unlock(&udc->lock); in receive_data()
525 spin_lock(&udc->lock); in receive_data()
532 send_status(udc, ep); in receive_data()
541 struct usba_udc *udc = ep->udc; in request_complete() local
549 usb_gadget_unmap_request(&udc->gadget, &req->req, ep->is_in); in request_complete()
555 spin_unlock(&udc->lock); in request_complete()
557 spin_lock(&udc->lock); in request_complete()
575 struct usba_udc *udc = ep->udc; in usba_ep_enable() local
635 spin_lock_irqsave(&ep->udc->lock, flags); in usba_ep_enable()
646 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index) | in usba_ep_enable()
651 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_enable()
654 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_enable()
659 (unsigned long)usba_int_enb_get(udc)); in usba_ep_enable()
667 struct usba_udc *udc = ep->udc; in usba_ep_disable() local
673 spin_lock_irqsave(&udc->lock, flags); in usba_ep_disable()
676 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
689 usba_int_enb_clear(udc, USBA_BF(EPT_INT, 1 << ep->index)); in usba_ep_disable()
693 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_disable()
724 static int queue_dma(struct usba_udc *udc, struct usba_ep *ep, in queue_dma() argument
742 ret = usb_gadget_map_request(&udc->gadget, &req->req, ep->is_in); in queue_dma()
760 spin_lock_irqsave(&udc->lock, flags); in queue_dma()
768 spin_unlock_irqrestore(&udc->lock, flags); in queue_dma()
778 struct usba_udc *udc = ep->udc; in usba_ep_queue() local
785 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN || in usba_ep_queue()
797 return queue_dma(udc, ep, req, gfp_flags); in usba_ep_queue()
801 spin_lock_irqsave(&udc->lock, flags); in usba_ep_queue()
814 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_queue()
848 dev_err(&ep->udc->pdev->dev, in stop_dma()
860 struct usba_udc *udc = ep->udc; in usba_ep_dequeue() local
869 spin_lock_irqsave(&udc->lock, flags); in usba_ep_dequeue()
879 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
897 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_dequeue()
913 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_dequeue()
921 struct usba_udc *udc = ep->udc; in usba_ep_set_halt() local
939 spin_lock_irqsave(&udc->lock, flags); in usba_ep_set_halt()
958 spin_unlock_irqrestore(&udc->lock, flags); in usba_ep_set_halt()
973 struct usba_udc *udc = ep->udc; in usba_ep_fifo_flush() local
975 usba_writel(udc, EPT_RST, 1 << ep->index); in usba_ep_fifo_flush()
992 struct usba_udc *udc = to_usba_udc(gadget); in usba_udc_get_frame() local
994 return USBA_BFEXT(FRAME_NUMBER, usba_readl(udc, FNUM)); in usba_udc_get_frame()
999 struct usba_udc *udc = to_usba_udc(gadget); in usba_udc_wakeup() local
1004 spin_lock_irqsave(&udc->lock, flags); in usba_udc_wakeup()
1005 if (udc->devstatus & (1 << USB_DEVICE_REMOTE_WAKEUP)) { in usba_udc_wakeup()
1006 ctrl = usba_readl(udc, CTRL); in usba_udc_wakeup()
1007 usba_writel(udc, CTRL, ctrl | USBA_REMOTE_WAKE_UP); in usba_udc_wakeup()
1010 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_wakeup()
1018 struct usba_udc *udc = to_usba_udc(gadget); in usba_udc_set_selfpowered() local
1022 spin_lock_irqsave(&udc->lock, flags); in usba_udc_set_selfpowered()
1024 udc->devstatus |= 1 << USB_DEVICE_SELF_POWERED; in usba_udc_set_selfpowered()
1026 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in usba_udc_set_selfpowered()
1027 spin_unlock_irqrestore(&udc->lock, flags); in usba_udc_set_selfpowered()
1065 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1071 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1082 if (ep->udc->ep_prealloc) in atmel_usba_match_ep()
1131 * Called with interrupts disabled and udc->lock held.
1133 static void reset_all_endpoints(struct usba_udc *udc) in reset_all_endpoints() argument
1138 usba_writel(udc, EPT_RST, ~0UL); in reset_all_endpoints()
1140 ep = to_usba_ep(udc->gadget.ep0); in reset_all_endpoints()
1147 static struct usba_ep *get_ep_by_addr(struct usba_udc *udc, u16 wIndex) in get_ep_by_addr() argument
1152 return to_usba_ep(udc->gadget.ep0); in get_ep_by_addr()
1154 list_for_each_entry (ep, &udc->gadget.ep_list, ep.ep_list) { in get_ep_by_addr()
1170 /* Called with interrupts disabled and udc->lock held */
1171 static inline void set_protocol_stall(struct usba_udc *udc, struct usba_ep *ep) in set_protocol_stall() argument
1177 static inline int is_stalled(struct usba_udc *udc, struct usba_ep *ep) in is_stalled() argument
1184 static inline void set_address(struct usba_udc *udc, unsigned int addr) in set_address() argument
1189 regval = usba_readl(udc, CTRL); in set_address()
1191 usba_writel(udc, CTRL, regval); in set_address()
1194 static int do_test_mode(struct usba_udc *udc) in do_test_mode() argument
1212 struct device *dev = &udc->pdev->dev; in do_test_mode()
1215 test_mode = udc->test_mode; in do_test_mode()
1218 reset_all_endpoints(udc); in do_test_mode()
1223 usba_writel(udc, TST, USBA_TST_J_MODE); in do_test_mode()
1228 usba_writel(udc, TST, USBA_TST_K_MODE); in do_test_mode()
1236 ep = &udc->usba_ep[0]; in do_test_mode()
1237 usba_writel(udc, TST, in do_test_mode()
1245 set_protocol_stall(udc, ep); in do_test_mode()
1254 ep = &udc->usba_ep[0]; in do_test_mode()
1261 set_protocol_stall(udc, ep); in do_test_mode()
1265 usba_writel(udc, TST, USBA_TST_PKT_MODE); in do_test_mode()
1302 static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep, in handle_ep0_setup() argument
1312 status = cpu_to_le16(udc->devstatus); in handle_ep0_setup()
1320 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1325 if (is_stalled(udc, target)) in handle_ep0_setup()
1342 udc->devstatus in handle_ep0_setup()
1353 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1365 send_status(udc, ep); in handle_ep0_setup()
1372 send_status(udc, ep); in handle_ep0_setup()
1374 udc->test_mode = le16_to_cpu(crq->wIndex); in handle_ep0_setup()
1377 udc->devstatus |= 1 << USB_DEVICE_REMOTE_WAKEUP; in handle_ep0_setup()
1388 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); in handle_ep0_setup()
1396 send_status(udc, ep); in handle_ep0_setup()
1404 set_address(udc, le16_to_cpu(crq->wValue)); in handle_ep0_setup()
1405 send_status(udc, ep); in handle_ep0_setup()
1411 spin_unlock(&udc->lock); in handle_ep0_setup()
1412 retval = udc->driver->setup(&udc->gadget, crq); in handle_ep0_setup()
1413 spin_lock(&udc->lock); in handle_ep0_setup()
1419 pr_err("udc: %s: Invalid setup request: %02x.%02x v%04x i%04x l%d, " in handle_ep0_setup()
1424 set_protocol_stall(udc, ep); in handle_ep0_setup()
1428 static void usba_control_irq(struct usba_udc *udc, struct usba_ep *ep) in usba_control_irq() argument
1469 usba_writel(udc, CTRL, (usba_readl(udc, CTRL) in usba_control_irq()
1486 if (do_test_mode(udc)) in usba_control_irq()
1487 set_protocol_stall(udc, ep); in usba_control_irq()
1490 pr_err("udc: %s: TXCOMP: Invalid endpoint state %d, " in usba_control_irq()
1493 set_protocol_stall(udc, ep); in usba_control_irq()
1519 pr_err("udc: %s: RXRDY: Invalid endpoint state %d, " in usba_control_irq()
1522 set_protocol_stall(udc, ep); in usba_control_irq()
1564 pr_warn("udc: Invalid packet length %u (expected %zu)\n", in usba_control_irq()
1566 set_protocol_stall(udc, ep); in usba_control_irq()
1598 ret = handle_ep0_setup(udc, ep, &crq.crq); in usba_control_irq()
1600 spin_unlock(&udc->lock); in usba_control_irq()
1601 ret = udc->driver->setup(&udc->gadget, &crq.crq); in usba_control_irq()
1602 spin_lock(&udc->lock); in usba_control_irq()
1611 set_protocol_stall(udc, ep); in usba_control_irq()
1616 static void usba_ep_irq(struct usba_udc *udc, struct usba_ep *ep) in usba_ep_irq() argument
1631 dev_warn(&udc->pdev->dev, "ep_irq: queue empty\n"); in usba_ep_irq()
1669 static void usba_dma_irq(struct usba_udc *udc, struct usba_ep *ep) in usba_dma_irq() argument
1683 dev_err(&udc->pdev->dev, in usba_dma_irq()
1685 dev_err(&udc->pdev->dev, in usba_dma_irq()
1709 static int start_clock(struct usba_udc *udc);
1710 static void stop_clock(struct usba_udc *udc);
1714 struct usba_udc *udc = devid; in usba_udc_irq() local
1719 spin_lock(&udc->lock); in usba_udc_irq()
1721 int_enb = usba_int_enb_get(udc); in usba_udc_irq()
1722 status = usba_readl(udc, INT_STA) & (int_enb | USBA_HIGH_SPEED); in usba_udc_irq()
1726 usba_writel(udc, INT_CLR, USBA_DET_SUSPEND|USBA_WAKE_UP); in usba_udc_irq()
1727 usba_int_enb_set(udc, USBA_WAKE_UP); in usba_udc_irq()
1728 usba_int_enb_clear(udc, USBA_DET_SUSPEND); in usba_udc_irq()
1729 udc->suspended = true; in usba_udc_irq()
1730 toggle_bias(udc, 0); in usba_udc_irq()
1731 udc->bias_pulse_needed = true; in usba_udc_irq()
1732 stop_clock(udc); in usba_udc_irq()
1734 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1735 && udc->driver && udc->driver->suspend) { in usba_udc_irq()
1736 spin_unlock(&udc->lock); in usba_udc_irq()
1737 udc->driver->suspend(&udc->gadget); in usba_udc_irq()
1738 spin_lock(&udc->lock); in usba_udc_irq()
1743 start_clock(udc); in usba_udc_irq()
1744 toggle_bias(udc, 1); in usba_udc_irq()
1745 usba_writel(udc, INT_CLR, USBA_WAKE_UP); in usba_udc_irq()
1750 udc->suspended = false; in usba_udc_irq()
1751 usba_writel(udc, INT_CLR, USBA_END_OF_RESUME); in usba_udc_irq()
1752 usba_int_enb_clear(udc, USBA_WAKE_UP); in usba_udc_irq()
1753 usba_int_enb_set(udc, USBA_DET_SUSPEND); in usba_udc_irq()
1754 generate_bias_pulse(udc); in usba_udc_irq()
1756 if (udc->gadget.speed != USB_SPEED_UNKNOWN in usba_udc_irq()
1757 && udc->driver && udc->driver->resume) { in usba_udc_irq()
1758 spin_unlock(&udc->lock); in usba_udc_irq()
1759 udc->driver->resume(&udc->gadget); in usba_udc_irq()
1760 spin_lock(&udc->lock); in usba_udc_irq()
1768 usba_int_enb_set(udc, USBA_DET_SUSPEND); in usba_udc_irq()
1772 usba_dma_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1779 usba_int_enb_set(udc, USBA_DET_SUSPEND); in usba_udc_irq()
1781 for (i = 0; i < udc->num_ep; i++) in usba_udc_irq()
1783 if (ep_is_control(&udc->usba_ep[i])) in usba_udc_irq()
1784 usba_control_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1786 usba_ep_irq(udc, &udc->usba_ep[i]); in usba_udc_irq()
1794 usba_writel(udc, INT_CLR, in usba_udc_irq()
1797 generate_bias_pulse(udc); in usba_udc_irq()
1798 reset_all_endpoints(udc); in usba_udc_irq()
1800 if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) { in usba_udc_irq()
1801 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_udc_irq()
1802 spin_unlock(&udc->lock); in usba_udc_irq()
1803 usb_gadget_udc_reset(&udc->gadget, udc->driver); in usba_udc_irq()
1804 spin_lock(&udc->lock); in usba_udc_irq()
1808 udc->gadget.speed = USB_SPEED_HIGH; in usba_udc_irq()
1810 udc->gadget.speed = USB_SPEED_FULL; in usba_udc_irq()
1812 usb_speed_string(udc->gadget.speed)); in usba_udc_irq()
1814 ep0 = &udc->usba_ep[0]; in usba_udc_irq()
1825 udc->suspended = false; in usba_udc_irq()
1826 usba_int_enb_clear(udc, USBA_WAKE_UP); in usba_udc_irq()
1828 usba_int_enb_set(udc, USBA_BF(EPT_INT, 1) | in usba_udc_irq()
1836 dev_err(&udc->pdev->dev, in usba_udc_irq()
1840 for (i = 1; i < udc->num_ep; i++) { in usba_udc_irq()
1841 ep = &udc->usba_ep[i]; in usba_udc_irq()
1845 dev_err(&udc->pdev->dev, in usba_udc_irq()
1851 spin_unlock(&udc->lock); in usba_udc_irq()
1856 static int start_clock(struct usba_udc *udc) in start_clock() argument
1860 if (udc->clocked) in start_clock()
1863 pm_stay_awake(&udc->pdev->dev); in start_clock()
1865 ret = clk_prepare_enable(udc->pclk); in start_clock()
1868 ret = clk_prepare_enable(udc->hclk); in start_clock()
1870 clk_disable_unprepare(udc->pclk); in start_clock()
1874 udc->clocked = true; in start_clock()
1878 static void stop_clock(struct usba_udc *udc) in stop_clock() argument
1880 if (!udc->clocked) in stop_clock()
1883 clk_disable_unprepare(udc->hclk); in stop_clock()
1884 clk_disable_unprepare(udc->pclk); in stop_clock()
1886 udc->clocked = false; in stop_clock()
1888 pm_relax(&udc->pdev->dev); in stop_clock()
1891 static int usba_start(struct usba_udc *udc) in usba_start() argument
1896 ret = start_clock(udc); in usba_start()
1900 if (udc->suspended) in usba_start()
1903 spin_lock_irqsave(&udc->lock, flags); in usba_start()
1904 toggle_bias(udc, 1); in usba_start()
1905 usba_writel(udc, CTRL, USBA_ENABLE_MASK); in usba_start()
1907 usba_writel(udc, INT_ENB, 0); in usba_start()
1908 udc->int_enb_cache = 0; in usba_start()
1909 usba_writel(udc, INT_CLR, in usba_start()
1913 usba_int_enb_set(udc, USBA_END_OF_RESET); in usba_start()
1914 spin_unlock_irqrestore(&udc->lock, flags); in usba_start()
1919 static void usba_stop(struct usba_udc *udc) in usba_stop() argument
1923 if (udc->suspended) in usba_stop()
1926 spin_lock_irqsave(&udc->lock, flags); in usba_stop()
1927 udc->gadget.speed = USB_SPEED_UNKNOWN; in usba_stop()
1928 reset_all_endpoints(udc); in usba_stop()
1931 toggle_bias(udc, 0); in usba_stop()
1932 usba_writel(udc, CTRL, USBA_DISABLE_MASK); in usba_stop()
1933 spin_unlock_irqrestore(&udc->lock, flags); in usba_stop()
1935 stop_clock(udc); in usba_stop()
1940 struct usba_udc *udc = devid; in usba_vbus_irq_thread() local
1946 mutex_lock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1948 vbus = vbus_is_present(udc); in usba_vbus_irq_thread()
1949 if (vbus != udc->vbus_prev) { in usba_vbus_irq_thread()
1951 usba_start(udc); in usba_vbus_irq_thread()
1953 udc->suspended = false; in usba_vbus_irq_thread()
1954 if (udc->driver->disconnect) in usba_vbus_irq_thread()
1955 udc->driver->disconnect(&udc->gadget); in usba_vbus_irq_thread()
1957 usba_stop(udc); in usba_vbus_irq_thread()
1959 udc->vbus_prev = vbus; in usba_vbus_irq_thread()
1962 mutex_unlock(&udc->vbus_mutex); in usba_vbus_irq_thread()
1968 struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); in atmel_usba_pullup() local
1972 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_pullup()
1973 ctrl = usba_readl(udc, CTRL); in atmel_usba_pullup()
1978 usba_writel(udc, CTRL, ctrl); in atmel_usba_pullup()
1979 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_pullup()
1988 struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); in atmel_usba_start() local
1991 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
1992 udc->devstatus = 1 << USB_DEVICE_SELF_POWERED; in atmel_usba_start()
1993 udc->driver = driver; in atmel_usba_start()
1994 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
1996 mutex_lock(&udc->vbus_mutex); in atmel_usba_start()
1998 if (udc->vbus_pin) in atmel_usba_start()
1999 enable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2002 udc->vbus_prev = vbus_is_present(udc); in atmel_usba_start()
2003 if (udc->vbus_prev) { in atmel_usba_start()
2004 ret = usba_start(udc); in atmel_usba_start()
2009 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2013 if (udc->vbus_pin) in atmel_usba_start()
2014 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_start()
2016 mutex_unlock(&udc->vbus_mutex); in atmel_usba_start()
2018 spin_lock_irqsave(&udc->lock, flags); in atmel_usba_start()
2019 udc->devstatus &= ~(1 << USB_DEVICE_SELF_POWERED); in atmel_usba_start()
2020 udc->driver = NULL; in atmel_usba_start()
2021 spin_unlock_irqrestore(&udc->lock, flags); in atmel_usba_start()
2027 struct usba_udc *udc = container_of(gadget, struct usba_udc, gadget); in atmel_usba_stop() local
2029 if (udc->vbus_pin) in atmel_usba_stop()
2030 disable_irq(gpiod_to_irq(udc->vbus_pin)); in atmel_usba_stop()
2032 udc->suspended = false; in atmel_usba_stop()
2033 usba_stop(udc); in atmel_usba_stop()
2035 udc->driver = NULL; in atmel_usba_stop()
2040 static void at91sam9rl_toggle_bias(struct usba_udc *udc, int is_on) in at91sam9rl_toggle_bias() argument
2042 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9rl_toggle_bias()
2046 static void at91sam9g45_pulse_bias(struct usba_udc *udc) in at91sam9g45_pulse_bias() argument
2048 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, 0); in at91sam9g45_pulse_bias()
2049 regmap_update_bits(udc->pmc, AT91_CKGR_UCKR, AT91_PMC_BIASEN, in at91sam9g45_pulse_bias()
2117 { .compatible = "atmel,at91sam9rl-udc", .data = &udc_at91sam9rl_cfg },
2118 { .compatible = "atmel,at91sam9g45-udc", .data = &udc_at91sam9g45_cfg },
2119 { .compatible = "atmel,sama5d3-udc", .data = &udc_sama5d3_cfg },
2120 { .compatible = "microchip,sam9x60-udc", .data = &udc_sam9x60_cfg },
2134 struct usba_udc *udc) in atmel_udc_of_init() argument
2148 udc->ep_prealloc = udc_config->ep_prealloc; in atmel_udc_of_init()
2149 udc->errata = udc_config->errata; in atmel_udc_of_init()
2150 if (udc->errata) { in atmel_udc_of_init()
2156 udc->pmc = syscon_node_to_regmap(pp); in atmel_udc_of_init()
2158 if (IS_ERR(udc->pmc)) in atmel_udc_of_init()
2159 return ERR_CAST(udc->pmc); in atmel_udc_of_init()
2162 udc->num_ep = 0; in atmel_udc_of_init()
2164 udc->vbus_pin = devm_gpiod_get_optional(&pdev->dev, "atmel,vbus", in atmel_udc_of_init()
2166 if (IS_ERR(udc->vbus_pin)) in atmel_udc_of_init()
2167 return ERR_CAST(udc->vbus_pin); in atmel_udc_of_init()
2170 udc->num_ep = udc_config->num_ep; in atmel_udc_of_init()
2172 udc->num_ep = usba_config_fifo_table(udc); in atmel_udc_of_init()
2175 eps = devm_kcalloc(&pdev->dev, udc->num_ep, sizeof(struct usba_ep), in atmel_udc_of_init()
2180 udc->gadget.ep0 = &eps[0].ep; in atmel_udc_of_init()
2185 while (i < udc->num_ep) { in atmel_udc_of_init()
2190 ep->index = fifo_mode ? udc->fifo_cfg[i].hw_ep_num : i; in atmel_udc_of_init()
2199 if (ep->fifo_size < udc->fifo_cfg[i].fifo_size) in atmel_udc_of_init()
2203 ep->fifo_size = udc->fifo_cfg[i].fifo_size; in atmel_udc_of_init()
2208 if (ep->nr_banks < udc->fifo_cfg[i].nr_banks) in atmel_udc_of_init()
2212 ep->nr_banks = udc->fifo_cfg[i].nr_banks; in atmel_udc_of_init()
2221 ep->ep_regs = udc->regs + USBA_EPT_BASE(i); in atmel_udc_of_init()
2222 ep->dma_regs = udc->regs + USBA_DMA_BASE(i); in atmel_udc_of_init()
2223 ep->fifo = udc->fifo + USBA_FIFO_BASE(i); in atmel_udc_of_init()
2226 ep->udc = udc; in atmel_udc_of_init()
2256 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in atmel_udc_of_init()
2276 struct usba_udc *udc; in usba_udc_probe() local
2279 udc = devm_kzalloc(&pdev->dev, sizeof(*udc), GFP_KERNEL); in usba_udc_probe()
2280 if (!udc) in usba_udc_probe()
2283 udc->gadget = usba_gadget_template; in usba_udc_probe()
2284 INIT_LIST_HEAD(&udc->gadget.ep_list); in usba_udc_probe()
2286 udc->regs = devm_platform_get_and_ioremap_resource(pdev, CTRL_IOMEM_ID, &res); in usba_udc_probe()
2287 if (IS_ERR(udc->regs)) in usba_udc_probe()
2288 return PTR_ERR(udc->regs); in usba_udc_probe()
2290 res, udc->regs); in usba_udc_probe()
2292 udc->fifo = devm_platform_get_and_ioremap_resource(pdev, FIFO_IOMEM_ID, &res); in usba_udc_probe()
2293 if (IS_ERR(udc->fifo)) in usba_udc_probe()
2294 return PTR_ERR(udc->fifo); in usba_udc_probe()
2295 dev_info(&pdev->dev, "FIFO at %pR mapped at %p\n", res, udc->fifo); in usba_udc_probe()
2308 spin_lock_init(&udc->lock); in usba_udc_probe()
2309 mutex_init(&udc->vbus_mutex); in usba_udc_probe()
2310 udc->pdev = pdev; in usba_udc_probe()
2311 udc->pclk = pclk; in usba_udc_probe()
2312 udc->hclk = hclk; in usba_udc_probe()
2314 platform_set_drvdata(pdev, udc); in usba_udc_probe()
2323 usba_writel(udc, CTRL, USBA_DISABLE_MASK); in usba_udc_probe()
2326 udc->usba_ep = atmel_udc_of_init(pdev, udc); in usba_udc_probe()
2328 toggle_bias(udc, 0); in usba_udc_probe()
2330 if (IS_ERR(udc->usba_ep)) in usba_udc_probe()
2331 return PTR_ERR(udc->usba_ep); in usba_udc_probe()
2334 "atmel_usba_udc", udc); in usba_udc_probe()
2340 udc->irq = irq; in usba_udc_probe()
2342 if (udc->vbus_pin) { in usba_udc_probe()
2343 irq_set_status_flags(gpiod_to_irq(udc->vbus_pin), IRQ_NOAUTOEN); in usba_udc_probe()
2345 gpiod_to_irq(udc->vbus_pin), NULL, in usba_udc_probe()
2347 "atmel_usba_udc", udc); in usba_udc_probe()
2349 udc->vbus_pin = NULL; in usba_udc_probe()
2350 dev_warn(&udc->pdev->dev, in usba_udc_probe()
2356 ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget); in usba_udc_probe()
2361 usba_init_debugfs(udc); in usba_udc_probe()
2362 for (i = 1; i < udc->num_ep; i++) in usba_udc_probe()
2363 usba_ep_init_debugfs(udc, &udc->usba_ep[i]); in usba_udc_probe()
2370 struct usba_udc *udc; in usba_udc_remove() local
2373 udc = platform_get_drvdata(pdev); in usba_udc_remove()
2376 usb_del_gadget_udc(&udc->gadget); in usba_udc_remove()
2378 for (i = 1; i < udc->num_ep; i++) in usba_udc_remove()
2379 usba_ep_cleanup_debugfs(&udc->usba_ep[i]); in usba_udc_remove()
2380 usba_cleanup_debugfs(udc); in usba_udc_remove()
2386 struct usba_udc *udc = dev_get_drvdata(dev); in usba_udc_suspend() local
2389 if (!udc->driver) in usba_udc_suspend()
2392 mutex_lock(&udc->vbus_mutex); in usba_udc_suspend()
2395 udc->suspended = false; in usba_udc_suspend()
2396 usba_stop(udc); in usba_udc_suspend()
2404 if (udc->vbus_pin) { in usba_udc_suspend()
2406 usba_stop(udc); in usba_udc_suspend()
2407 enable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_suspend()
2410 enable_irq_wake(udc->irq); in usba_udc_suspend()
2413 mutex_unlock(&udc->vbus_mutex); in usba_udc_suspend()
2419 struct usba_udc *udc = dev_get_drvdata(dev); in usba_udc_resume() local
2422 if (!udc->driver) in usba_udc_resume()
2426 if (udc->vbus_pin) in usba_udc_resume()
2427 disable_irq_wake(gpiod_to_irq(udc->vbus_pin)); in usba_udc_resume()
2429 disable_irq_wake(udc->irq); in usba_udc_resume()
2433 mutex_lock(&udc->vbus_mutex); in usba_udc_resume()
2434 udc->vbus_prev = vbus_is_present(udc); in usba_udc_resume()
2435 if (udc->vbus_prev) in usba_udc_resume()
2436 usba_start(udc); in usba_udc_resume()
2437 mutex_unlock(&udc->vbus_mutex); in usba_udc_resume()
2456 MODULE_DESCRIPTION("Atmel USBA UDC driver");