Lines Matching +full:rz +full:- +full:dmac
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2015-2017 Renesas Electronics Corporation
11 #include <linux/dma-mapping.h>
13 #include <linux/extcon-provider.h>
37 #define USB3_DMA_CH0_CON(n) (0x030 + ((n) - 1) * 0x10) /* n = 1 to 4 */
38 #define USB3_DMA_CH0_PRD_ADR(n) (0x034 + ((n) - 1) * 0x10) /* n = 1 to 4 */
43 #define USB3_DRD_CON(p) ((p)->is_rzv2m ? 0x400 : 0x218)
50 #define USB3_USB_OTG_STA(p) ((p)->is_rzv2m ? 0x410 : 0x268)
51 #define USB3_USB_OTG_INT_STA(p) ((p)->is_rzv2m ? 0x414 : 0x26c)
52 #define USB3_USB_OTG_INT_ENA(p) ((p)->is_rzv2m ? 0x418 : 0x270)
77 #define AXI_INT_PRDEN_CLR_STA_SHIFT(n) (16 + (n) - 1)
78 #define AXI_INT_PRDERR_STA_SHIFT(n) (0 + (n) - 1)
162 #define USB_OTG_IDMON(p) ((p)->is_rzv2m ? BIT(0) : BIT(4))
262 #define USB3_MAX_NUM_PIPES(p) ((p)->is_rzv2m ? 16 : 6) /* This includes PIPE 0 */
266 * To avoid double-meaning of "0" (xferred 65536 bytes or received zlp if
333 bool is_rzv2m; /* if true, RZ/V2M SoC */
378 #define renesas_usb3_to_gadget(renesas_usb3) (&renesas_usb3->gadget)
379 #define usb3_to_dev(_usb3) (_usb3->gadget.dev.parent)
382 #define usb3_ep_to_usb3(_usb3_ep) (_usb3_ep->usb3)
386 #define usb3_get_ep(usb3, n) ((usb3)->usb3_ep + (n))
389 (i) < (usb3)->num_usb3_eps; \
392 #define usb3_get_dma(usb3, i) (&(usb3)->dma[i])
402 MODULE_PARM_DESC(use_dma, "use dedicated DMAC");
406 iowrite32(data, usb3->reg + offs); in usb3_write()
411 return ioread32(usb3->reg + offs); in usb3_read()
434 if (usb3->is_rzv2m) in usb3_drd_write()
435 reg = usb3->drd_reg + offs - USB3_DRD_CON(usb3); in usb3_drd_write()
437 reg = usb3->reg + offs; in usb3_drd_write()
446 if (usb3->is_rzv2m) in usb3_drd_read()
447 reg = usb3->drd_reg + offs - USB3_DRD_CON(usb3); in usb3_drd_read()
449 reg = usb3->reg + offs; in usb3_drd_read()
484 return -EBUSY; in usb3_wait()
492 extcon_set_state_sync(usb3->extcon, EXTCON_USB_HOST, usb3->extcon_host); in renesas_usb3_extcon_work()
493 extcon_set_state_sync(usb3->extcon, EXTCON_USB, usb3->extcon_usb); in renesas_usb3_extcon_work()
532 if (!usb3->workaround_for_vbus) in usb3_init_epc_registers()
551 if (usb3->softconnect && pullup) in usb3_usb2_pullup()
562 val |= USB20_CON_B2_TSTMOD(usb3->test_mode); in usb3_set_test_mode()
564 if (!usb3->test_mode) in usb3_set_test_mode()
570 usb3->disabled_count++; in usb3_start_usb2_connection()
677 usb3->test_mode = 0; in usb3_reset_epc()
683 usb3->disabled_count = 0; in usb3_disconnect()
695 if (usb3->driver) in usb3_disconnect()
696 usb3->driver->disconnect(&usb3->gadget); in usb3_disconnect()
701 if (usb3->workaround_for_vbus) { in usb3_check_vbus()
704 usb3->extcon_usb = !!(usb3_read(usb3, USB3_USB_STA) & in usb3_check_vbus()
706 if (usb3->extcon_usb) in usb3_check_vbus()
711 schedule_work(&usb3->extcon_work); in usb3_check_vbus()
720 usb_role_switch_set_role(usb3->role_sw, usb3->role); in renesas_usb3_role_work()
725 if (usb3->is_rzv2m) { in usb3_set_mode()
743 if (usb3->role_sw) { in usb3_set_mode_by_role_sw()
744 usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE; in usb3_set_mode_by_role_sw()
745 schedule_work(&usb3->role_work); in usb3_set_mode_by_role_sw()
763 spin_lock_irqsave(&usb3->lock, flags); in usb3_mode_config()
764 if (!usb3->role_sw_by_connector || in usb3_mode_config()
765 usb3->connection_state != USB_ROLE_NONE) { in usb3_mode_config()
769 /* for A-Peripheral or forced B-device mode */ in usb3_mode_config()
770 if ((!host && a_dev) || usb3->start_to_connect) in usb3_mode_config()
772 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_mode_config()
782 usb3->extcon_host = usb3_is_a_device(usb3); in usb3_check_id()
784 if ((!usb3->role_sw_by_connector && usb3->extcon_host && in usb3_check_id()
785 !usb3->forced_b_device) || usb3->connection_state == USB_ROLE_HOST) in usb3_check_id()
790 schedule_work(&usb3->extcon_work); in usb3_check_id()
840 if (usb3->gadget.speed != USB_SPEED_UNKNOWN && in usb3_irq_epc_int_1_suspend()
841 usb3->gadget.state != USB_STATE_NOTATTACHED) { in usb3_irq_epc_int_1_suspend()
842 if (usb3->driver && usb3->driver->suspend) in usb3_irq_epc_int_1_suspend()
843 usb3->driver->suspend(&usb3->gadget); in usb3_irq_epc_int_1_suspend()
844 usb_gadget_set_state(&usb3->gadget, USB_STATE_SUSPENDED); in usb3_irq_epc_int_1_suspend()
858 if (usb3->disabled_count < 3) in usb3_irq_epc_int_1_bus_reset()
893 usb3->gadget.speed = USB_SPEED_SUPER; in usb3_irq_epc_int_1_speed()
894 usb3->gadget.ep0->maxpacket = USB3_EP0_SS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
897 usb3->gadget.speed = USB_SPEED_HIGH; in usb3_irq_epc_int_1_speed()
898 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
901 usb3->gadget.speed = USB_SPEED_FULL; in usb3_irq_epc_int_1_speed()
902 usb3->gadget.ep0->maxpacket = USB3_EP0_HSFS_MAX_PACKET_SIZE; in usb3_irq_epc_int_1_speed()
905 usb3->gadget.speed = USB_SPEED_UNKNOWN; in usb3_irq_epc_int_1_speed()
946 return list_first_entry_or_null(&usb3_ep->queue, in __usb3_get_request()
957 spin_lock_irqsave(&usb3->lock, flags); in usb3_get_request()
959 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_get_request()
971 usb3_ep->num, usb3_req->req.length, usb3_req->req.actual, in __usb3_request_done()
973 usb3_req->req.status = status; in __usb3_request_done()
974 usb3_ep->started = false; in __usb3_request_done()
975 list_del_init(&usb3_req->queue); in __usb3_request_done()
976 spin_unlock(&usb3->lock); in __usb3_request_done()
977 usb_gadget_giveback_request(&usb3_ep->ep, &usb3_req->req); in __usb3_request_done()
978 spin_lock(&usb3->lock); in __usb3_request_done()
987 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done()
989 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done()
999 if (usb3->test_mode) in usb3_irq_epc_pipe0_status_end()
1013 usb3_ep->dir_in = !!(ctrl->bRequestType & USB_DIR_IN); in usb3_get_setup_data()
1076 if (num == 0 || num > usb3->num_usb3_eps) in usb3_pn_change()
1077 return -ENXIO; in usb3_pn_change()
1119 struct usb_request *req = &usb3_req->req; in usb3_is_transfer_complete()
1121 if ((!req->zero && req->actual == req->length) || in usb3_is_transfer_complete()
1122 (req->actual % usb3_ep->ep.maxpacket) || (req->length == 0)) in usb3_is_transfer_complete()
1131 u32 sta_reg = usb3_ep->num ? USB3_PN_STA : USB3_P0_STA; in usb3_wait_pipe_status()
1140 u32 con_reg = usb3_ep->num ? USB3_PN_CON : USB3_P0_CON; in usb3_set_px_con_send()
1144 val |= (usb3_ep->num && last) ? PN_CON_LAST : 0; in usb3_set_px_con_send()
1154 int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, in usb3_write_pipe()
1155 usb3_ep->ep.maxpacket); in usb3_write_pipe()
1156 u8 *buf = usb3_req->req.buf + usb3_req->req.actual; in usb3_write_pipe()
1161 return -EBUSY; in usb3_write_pipe()
1164 usb3_req->req.actual += len; in usb3_write_pipe()
1168 iowrite32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_write_pipe()
1184 return is_last ? 0 : -EAGAIN; in usb3_write_pipe()
1190 u32 lng_reg = usb3_ep->num ? USB3_PN_LNG : USB3_P0_LNG; in usb3_get_received_length()
1200 int len = min_t(unsigned, usb3_req->req.length - usb3_req->req.actual, in usb3_read_pipe()
1202 u8 *buf = usb3_req->req.buf + usb3_req->req.actual; in usb3_read_pipe()
1209 usb3_req->req.actual += len; in usb3_read_pipe()
1213 ioread32_rep(usb3->reg + fifo_reg, buf, len / 4); in usb3_read_pipe()
1224 return usb3_is_transfer_complete(usb3_ep, usb3_req) ? 0 : -EAGAIN; in usb3_read_pipe()
1232 if (usb3_ep->dir_in) { in usb3_set_status_stage()
1235 if (!usb3_req->req.length) in usb3_set_status_stage()
1247 if (usb3_ep->dir_in) in usb3_p0_xfer()
1261 if (usb3_ep->started) in usb3_start_pipe0()
1264 usb3_ep->started = true; in usb3_start_pipe0()
1266 if (usb3_ep->dir_in) { in usb3_start_pipe0()
1271 if (usb3_req->req.length) in usb3_start_pipe0()
1300 switch (usb3_ep->ep.maxpacket) { in usb3_dma_mps_to_prd_word1()
1326 if (usb3_req->req.length > USB3_DMA_MAX_XFER_SIZE_ALL_PRDS) { in usb3_dma_get_setting_area()
1328 __func__, usb3_req->req.length); in usb3_dma_get_setting_area()
1332 /* The driver doesn't handle zero-length packet via dmac */ in usb3_dma_get_setting_area()
1333 if (!usb3_req->req.length) in usb3_dma_get_setting_area()
1340 if (dma->used) in usb3_dma_get_setting_area()
1343 if (usb_gadget_map_request(&usb3->gadget, &usb3_req->req, in usb3_dma_get_setting_area()
1344 usb3_ep->dir_in) < 0) in usb3_dma_get_setting_area()
1347 dma->used = true; in usb3_dma_get_setting_area()
1348 usb3_ep->dma = dma; in usb3_dma_get_setting_area()
1364 if (usb3_ep->dma == dma) { in usb3_dma_put_setting_area()
1365 usb_gadget_unmap_request(&usb3->gadget, &usb3_req->req, in usb3_dma_put_setting_area()
1366 usb3_ep->dir_in); in usb3_dma_put_setting_area()
1367 dma->used = false; in usb3_dma_put_setting_area()
1368 usb3_ep->dma = NULL; in usb3_dma_put_setting_area()
1377 struct renesas_usb3_prd *cur_prd = usb3_ep->dma->prd; in usb3_dma_fill_prd()
1378 u32 remain = usb3_req->req.length; in usb3_dma_fill_prd()
1379 u32 dma = usb3_req->req.dma; in usb3_dma_fill_prd()
1386 cur_prd->word1 = usb3_dma_mps_to_prd_word1(usb3_ep) | in usb3_dma_fill_prd()
1388 cur_prd->bap = dma; in usb3_dma_fill_prd()
1389 remain -= len; in usb3_dma_fill_prd()
1398 cur_prd->word1 |= USB3_PRD1_E | USB3_PRD1_INT; in usb3_dma_fill_prd()
1399 if (usb3_ep->dir_in) in usb3_dma_fill_prd()
1400 cur_prd->word1 |= USB3_PRD1_LST; in usb3_dma_fill_prd()
1405 struct renesas_usb3_dma *dma = usb3_ep->dma; in usb3_dma_kick_prd()
1407 u32 dma_con = DMA_COM_PIPE_NO(usb3_ep->num) | DMA_CON_PRD_EN; in usb3_dma_kick_prd()
1409 if (usb3_ep->dir_in) in usb3_dma_kick_prd()
1414 usb3_write(usb3, 1 << usb3_ep->num, USB3_DMA_INT_STA); in usb3_dma_kick_prd()
1415 usb3_write(usb3, AXI_INT_PRDEN_CLR_STA(dma->num) | in usb3_dma_kick_prd()
1416 AXI_INT_PRDERR_STA(dma->num), USB3_AXI_INT_STA); in usb3_dma_kick_prd()
1418 usb3_write(usb3, dma->prd_dma, USB3_DMA_CH0_PRD_ADR(dma->num)); in usb3_dma_kick_prd()
1419 usb3_write(usb3, dma_con, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_kick_prd()
1420 usb3_enable_dma_irq(usb3, usb3_ep->num); in usb3_dma_kick_prd()
1426 struct renesas_usb3_dma *dma = usb3_ep->dma; in usb3_dma_stop_prd()
1428 usb3_disable_dma_irq(usb3, usb3_ep->num); in usb3_dma_stop_prd()
1429 usb3_write(usb3, 0, USB3_DMA_CH0_CON(dma->num)); in usb3_dma_stop_prd()
1435 struct renesas_usb3_prd *cur_prd = usb3_ep->dma->prd; in usb3_dma_update_status()
1436 struct usb_request *req = &usb3_req->req; in usb3_dma_update_status()
1444 if (cur_prd->word1 & USB3_PRD1_D) in usb3_dma_update_status()
1445 status = -EIO; in usb3_dma_update_status()
1446 if (cur_prd->word1 & USB3_PRD1_E) in usb3_dma_update_status()
1447 len = req->length % USB3_DMA_MAX_XFER_SIZE; in usb3_dma_update_status()
1450 remain = cur_prd->word1 & USB3_PRD1_SIZE_MASK; in usb3_dma_update_status()
1451 req->actual += len - remain; in usb3_dma_update_status()
1453 if (cur_prd->word1 & USB3_PRD1_E || in usb3_dma_update_status()
1491 spin_lock_irqsave(&usb3->lock, flags); in usb3_dma_try_stop()
1492 if (!usb3_ep->dma) in usb3_dma_try_stop()
1495 if (!usb3_pn_change(usb3, usb3_ep->num)) in usb3_dma_try_stop()
1502 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_dma_try_stop()
1513 if (dma->prd) { in renesas_usb3_dma_free_prd()
1515 dma->prd, dma->prd_dma); in renesas_usb3_dma_free_prd()
1516 dma->prd = NULL; in renesas_usb3_dma_free_prd()
1533 dma->prd = dma_alloc_coherent(dev, USB3_DMA_PRD_SIZE, in renesas_usb3_dma_alloc_prd()
1534 &dma->prd_dma, GFP_KERNEL); in renesas_usb3_dma_alloc_prd()
1535 if (!dma->prd) { in renesas_usb3_dma_alloc_prd()
1537 return -ENOMEM; in renesas_usb3_dma_alloc_prd()
1539 dma->num = i + 1; in renesas_usb3_dma_alloc_prd()
1551 int ret = -EAGAIN; in usb3_start_pipen()
1554 spin_lock_irqsave(&usb3->lock, flags); in usb3_start_pipen()
1555 if (usb3_ep->halt || usb3_ep->started) in usb3_start_pipen()
1561 if (usb3_pn_change(usb3, usb3_ep->num) < 0) in usb3_start_pipen()
1564 usb3_ep->started = true; in usb3_start_pipen()
1571 if (usb3_ep->dir_in) { in usb3_start_pipen()
1581 usb3_enable_pipe_irq(usb3, usb3_ep->num); in usb3_start_pipen()
1584 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_start_pipen()
1595 dev_dbg(usb3_to_dev(usb3), "ep_queue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_queue()
1596 _req->length); in renesas_usb3_ep_queue()
1598 _req->status = -EINPROGRESS; in renesas_usb3_ep_queue()
1599 _req->actual = 0; in renesas_usb3_ep_queue()
1600 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_queue()
1601 list_add_tail(&usb3_req->queue, &usb3_ep->queue); in renesas_usb3_ep_queue()
1602 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_queue()
1604 if (!usb3_ep->num) in renesas_usb3_ep_queue()
1621 if (le16_to_cpu(ctrl->wValue) >= 128) in usb3_std_req_set_address()
1624 usb3_set_device_address(usb3, le16_to_cpu(ctrl->wValue)); in usb3_std_req_set_address()
1638 memcpy(usb3->ep0_buf, tx_data, in usb3_pipe0_internal_xfer()
1641 usb3->ep0_req->buf = &usb3->ep0_buf; in usb3_pipe0_internal_xfer()
1642 usb3->ep0_req->length = len; in usb3_pipe0_internal_xfer()
1643 usb3->ep0_req->complete = complete; in usb3_pipe0_internal_xfer()
1644 renesas_usb3_ep_queue(&usb3_ep->ep, usb3->ep0_req, GFP_ATOMIC); in usb3_pipe0_internal_xfer()
1661 switch (ctrl->bRequestType & USB_RECIP_MASK) { in usb3_std_req_get_status()
1663 if (usb3->gadget.is_selfpowered) in usb3_std_req_get_status()
1665 if (usb3->gadget.speed == USB_SPEED_SUPER) in usb3_std_req_get_status()
1671 num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; in usb3_std_req_get_status()
1673 if (usb3_ep->halt) in usb3_std_req_get_status()
1684 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_get_status()
1696 u16 w_value = le16_to_cpu(ctrl->wValue); in usb3_std_req_feature_device()
1702 usb3->test_mode = le16_to_cpu(ctrl->wIndex) >> 8; in usb3_std_req_feature_device()
1707 if (usb3->gadget.speed != USB_SPEED_SUPER) in usb3_std_req_feature_device()
1726 if (unlikely(usb3_ep->num)) in usb3_set_halt_p0()
1727 return -EINVAL; in usb3_set_halt_p0()
1729 usb3_ep->halt = halt; in usb3_set_halt_p0()
1744 spin_lock_irqsave(&usb3->lock, flags); in usb3_set_halt_pn()
1745 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_set_halt_pn()
1746 usb3_ep->halt = halt; in usb3_set_halt_pn()
1749 } else if (!is_clear_feature || !usb3_ep->wedge) { in usb3_set_halt_pn()
1755 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_set_halt_pn()
1765 if (halt && usb3_ep->started) in usb3_set_halt()
1766 return -EAGAIN; in usb3_set_halt()
1768 if (usb3_ep->num) in usb3_set_halt()
1780 int num = le16_to_cpu(ctrl->wIndex) & USB_ENDPOINT_NUMBER_MASK; in usb3_std_req_feature_endpoint()
1784 if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) in usb3_std_req_feature_endpoint()
1792 usb3_ep->started = false; in usb3_std_req_feature_endpoint()
1806 switch (ctrl->bRequestType & USB_RECIP_MASK) { in usb3_std_req_feature()
1835 u16 w_length = le16_to_cpu(ctrl->wLength); in usb3_std_req_set_sel()
1841 usb_req_to_usb3_req(usb3->ep0_req)); in usb3_std_req_set_sel()
1850 if (le16_to_cpu(ctrl->wValue) > 0) in usb3_std_req_set_configuration()
1859 * usb3_handle_standard_request - handle some standard requests
1871 if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { in usb3_handle_standard_request()
1872 switch (ctrl->bRequest) { in usb3_handle_standard_request()
1925 if (usb3_ep->started) in usb3_irq_epc_pipe0_setup()
1927 -ECONNRESET); in usb3_irq_epc_pipe0_setup()
1932 if (usb3->driver->setup(&usb3->gadget, &ctrl) < 0) in usb3_irq_epc_pipe0_setup()
1968 spin_lock_irqsave(&usb3->lock, flags); in usb3_request_done_pipen()
1969 if (usb3_pn_change(usb3, usb3_ep->num)) in usb3_request_done_pipen()
1971 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_request_done_pipen()
1973 usb3_disable_pipe_irq(usb3, usb3_ep->num); in usb3_request_done_pipen()
1990 if (usb3_ep->dir_in) { in usb3_irq_epc_pipen_lsttr()
1992 __func__, usb3_req->req.length, usb3_req->req.actual); in usb3_irq_epc_pipen_lsttr()
2006 spin_lock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
2010 if (usb3_ep->dir_in) { in usb3_irq_epc_pipen_bfrdy()
2021 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen_bfrdy()
2031 spin_lock(&usb3->lock); in usb3_irq_epc_pipen()
2033 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
2040 spin_unlock(&usb3->lock); in usb3_irq_epc_pipen()
2051 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_epc_int_2()
2093 if (!usb3->is_rzv2m) in usb3_irq_epc()
2103 for (i = 0; i < usb3->num_usb3_eps; i++) { in usb3_irq_dma_int()
2109 AXI_INT_PRDEN_CLR_STA(usb3_ep->dma->num))) in usb3_irq_dma_int()
2163 val |= usb3_ep->dir_in ? PN_MOD_DIR : 0; in usb3_write_pn_mod()
2197 return usb3_ep->rammap_val | mpkt; in usb3_calc_rammap_val()
2206 usb3_ep->dir_in = usb_endpoint_dir_in(desc); in usb3_enable_pipe_n()
2208 spin_lock_irqsave(&usb3->lock, flags); in usb3_enable_pipe_n()
2209 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_enable_pipe_n()
2216 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_enable_pipe_n()
2226 usb3_ep->halt = false; in usb3_disable_pipe_n()
2228 spin_lock_irqsave(&usb3->lock, flags); in usb3_disable_pipe_n()
2229 if (!usb3_pn_change(usb3, usb3_ep->num)) { in usb3_disable_pipe_n()
2234 spin_unlock_irqrestore(&usb3->lock, flags); in usb3_disable_pipe_n()
2239 /*------- usb_ep_ops -----------------------------------------------------*/
2258 usb3_request_done(usb3_ep, usb3_req, -ESHUTDOWN); in renesas_usb3_ep_disable()
2272 INIT_LIST_HEAD(&usb3_req->queue); in __renesas_usb3_ep_alloc_request()
2274 return &usb3_req->req; in __renesas_usb3_ep_alloc_request()
2302 dev_dbg(usb3_to_dev(usb3), "ep_dequeue: ep%2d, %u\n", usb3_ep->num, in renesas_usb3_ep_dequeue()
2303 _req->length); in renesas_usb3_ep_dequeue()
2306 usb3_request_done_pipen(usb3, usb3_ep, usb3_req, -ECONNRESET); in renesas_usb3_ep_dequeue()
2320 usb3_ep->wedge = true; in renesas_usb3_ep_set_wedge()
2330 if (usb3_ep->num) { in renesas_usb3_ep_fifo_flush()
2331 spin_lock_irqsave(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2332 if (!usb3_pn_change(usb3, usb3_ep->num)) { in renesas_usb3_ep_fifo_flush()
2336 spin_unlock_irqrestore(&usb3->lock, flags); in renesas_usb3_ep_fifo_flush()
2357 /*------- usb_gadget_ops -------------------------------------------------*/
2363 if (!driver || driver->max_speed < USB_SPEED_FULL || in renesas_usb3_start()
2364 !driver->setup) in renesas_usb3_start()
2365 return -EINVAL; in renesas_usb3_start()
2369 if (usb3->is_rzv2m && usb3_is_a_device(usb3)) in renesas_usb3_start()
2370 return -EBUSY; in renesas_usb3_start()
2373 usb3->driver = driver; in renesas_usb3_start()
2375 if (usb3->phy) in renesas_usb3_start()
2376 phy_init(usb3->phy); in renesas_usb3_start()
2381 if (usb3->is_rzv2m) in renesas_usb3_start()
2382 rzv2m_usb3drd_reset(usb3_to_dev(usb3)->parent, false); in renesas_usb3_start()
2393 usb3->softconnect = false; in renesas_usb3_stop()
2394 usb3->gadget.speed = USB_SPEED_UNKNOWN; in renesas_usb3_stop()
2395 usb3->driver = NULL; in renesas_usb3_stop()
2396 if (usb3->is_rzv2m) in renesas_usb3_stop()
2397 rzv2m_usb3drd_reset(usb3_to_dev(usb3)->parent, false); in renesas_usb3_stop()
2400 if (usb3->phy) in renesas_usb3_stop()
2401 phy_exit(usb3->phy); in renesas_usb3_stop()
2410 return -EOPNOTSUPP; in renesas_usb3_get_frame()
2417 usb3->softconnect = !!is_on; in renesas_usb3_pullup()
2424 gadget->is_selfpowered = !!is_self; in renesas_usb3_set_selfpowered()
2453 struct device *host = usb3->host_dev; in handle_ext_role_switch_states()
2454 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_ext_role_switch_states()
2458 usb3->connection_state = USB_ROLE_NONE; in handle_ext_role_switch_states()
2459 if (!usb3->is_rzv2m && cur_role == USB_ROLE_HOST) in handle_ext_role_switch_states()
2461 if (usb3->driver) { in handle_ext_role_switch_states()
2462 if (usb3->is_rzv2m) in handle_ext_role_switch_states()
2463 rzv2m_usb3drd_reset(dev->parent, false); in handle_ext_role_switch_states()
2468 if (usb3->is_rzv2m) { in handle_ext_role_switch_states()
2469 rzv2m_usb3drd_reset(dev->parent, true); in handle_ext_role_switch_states()
2474 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2475 usb3->connection_state = USB_ROLE_DEVICE; in handle_ext_role_switch_states()
2477 if (usb3->driver) { in handle_ext_role_switch_states()
2478 if (usb3->is_rzv2m) in handle_ext_role_switch_states()
2485 if (usb3->driver) in handle_ext_role_switch_states()
2491 if (usb3->connection_state == USB_ROLE_NONE) { in handle_ext_role_switch_states()
2492 if (usb3->driver) { in handle_ext_role_switch_states()
2493 if (usb3->is_rzv2m) in handle_ext_role_switch_states()
2494 rzv2m_usb3drd_reset(dev->parent, false); in handle_ext_role_switch_states()
2498 usb3->connection_state = USB_ROLE_HOST; in handle_ext_role_switch_states()
2521 struct device *host = usb3->host_dev; in handle_role_switch_states()
2522 enum usb_role cur_role = renesas_usb3_role_switch_get(usb3->role_sw); in handle_role_switch_states()
2543 if (usb3->role_sw_by_connector) in renesas_usb3_role_switch_set()
2559 if (!usb3->driver) in role_store()
2560 return -ENODEV; in role_store()
2562 if (usb3->forced_b_device) in role_store()
2563 return -EBUSY; in role_store()
2570 return -EINVAL; in role_store()
2573 return -EINVAL; in role_store()
2585 if (!usb3->driver) in role_show()
2586 return -ENODEV; in role_show()
2594 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_show()
2596 seq_printf(s, "%d\n", usb3->forced_b_device); in renesas_usb3_b_device_show()
2603 return single_open(file, renesas_usb3_b_device_show, inode->i_private); in renesas_usb3_b_device_open()
2610 struct seq_file *s = file->private_data; in renesas_usb3_b_device_write()
2611 struct renesas_usb3 *usb3 = s->private; in renesas_usb3_b_device_write()
2614 if (!usb3->driver) in renesas_usb3_b_device_write()
2615 return -ENODEV; in renesas_usb3_b_device_write()
2617 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) in renesas_usb3_b_device_write()
2618 return -EFAULT; in renesas_usb3_b_device_write()
2620 usb3->start_to_connect = false; in renesas_usb3_b_device_write()
2621 if (usb3->workaround_for_vbus && usb3->forced_b_device && in renesas_usb3_b_device_write()
2623 usb3->start_to_connect = true; in renesas_usb3_b_device_write()
2625 usb3->forced_b_device = true; in renesas_usb3_b_device_write()
2627 usb3->forced_b_device = false; in renesas_usb3_b_device_write()
2629 if (usb3->workaround_for_vbus) in renesas_usb3_b_device_write()
2649 usb3->dentry = debugfs_create_dir(dev_name(dev), usb_debug_root); in renesas_usb3_debugfs_init()
2651 debugfs_create_file("b_device", 0644, usb3->dentry, usb3, in renesas_usb3_debugfs_init()
2655 /*------- platform_driver ------------------------------------------------*/
2660 debugfs_remove_recursive(usb3->dentry); in renesas_usb3_remove()
2661 device_remove_file(&pdev->dev, &dev_attr_role); in renesas_usb3_remove()
2663 cancel_work_sync(&usb3->role_work); in renesas_usb3_remove()
2664 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_remove()
2666 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_remove()
2667 reset_control_assert(usb3->usbp_rstc); in renesas_usb3_remove()
2668 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_remove()
2670 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_remove()
2671 pm_runtime_disable(&pdev->dev); in renesas_usb3_remove()
2681 usb3->num_usb3_eps = priv->ramsize_per_ramif * priv->num_ramif * 2 / in renesas_usb3_init_ep()
2682 priv->ramsize_per_pipe + 1; in renesas_usb3_init_ep()
2684 if (usb3->num_usb3_eps > USB3_MAX_NUM_PIPES(usb3)) in renesas_usb3_init_ep()
2685 usb3->num_usb3_eps = USB3_MAX_NUM_PIPES(usb3); in renesas_usb3_init_ep()
2687 usb3->usb3_ep = devm_kcalloc(dev, in renesas_usb3_init_ep()
2688 usb3->num_usb3_eps, sizeof(*usb3_ep), in renesas_usb3_init_ep()
2690 if (!usb3->usb3_ep) in renesas_usb3_init_ep()
2691 return -ENOMEM; in renesas_usb3_init_ep()
2693 dev_dbg(dev, "%s: num_usb3_eps = %d\n", __func__, usb3->num_usb3_eps); in renesas_usb3_init_ep()
2696 * - odd pipes = IN pipe in renesas_usb3_init_ep()
2697 * - even pipes = OUT pipe (except pipe 0) in renesas_usb3_init_ep()
2700 snprintf(usb3_ep->ep_name, sizeof(usb3_ep->ep_name), "ep%d", i); in renesas_usb3_init_ep()
2701 usb3_ep->usb3 = usb3; in renesas_usb3_init_ep()
2702 usb3_ep->num = i; in renesas_usb3_init_ep()
2703 usb3_ep->ep.name = usb3_ep->ep_name; in renesas_usb3_init_ep()
2704 usb3_ep->ep.ops = &renesas_usb3_ep_ops; in renesas_usb3_init_ep()
2705 INIT_LIST_HEAD(&usb3_ep->queue); in renesas_usb3_init_ep()
2706 INIT_LIST_HEAD(&usb3_ep->ep.ep_list); in renesas_usb3_init_ep()
2709 usb3->gadget.ep0 = &usb3_ep->ep; in renesas_usb3_init_ep()
2710 usb_ep_set_maxpacket_limit(&usb3_ep->ep, in renesas_usb3_init_ep()
2712 usb3_ep->ep.caps.type_control = true; in renesas_usb3_init_ep()
2713 usb3_ep->ep.caps.dir_in = true; in renesas_usb3_init_ep()
2714 usb3_ep->ep.caps.dir_out = true; in renesas_usb3_init_ep()
2719 usb_ep_set_maxpacket_limit(&usb3_ep->ep, ~0); in renesas_usb3_init_ep()
2720 list_add_tail(&usb3_ep->ep.ep_list, &usb3->gadget.ep_list); in renesas_usb3_init_ep()
2721 usb3_ep->ep.caps.type_bulk = true; in renesas_usb3_init_ep()
2722 usb3_ep->ep.caps.type_int = true; in renesas_usb3_init_ep()
2724 usb3_ep->ep.caps.dir_in = true; in renesas_usb3_init_ep()
2726 usb3_ep->ep.caps.dir_out = true; in renesas_usb3_init_ep()
2746 * - all pipes = the same size as "ramsize_per_pipe" in renesas_usb3_init_ram()
2752 if (usb3_ep->ep.caps.dir_in) { in renesas_usb3_init_ram()
2760 if (*cur_basead > priv->ramsize_per_ramif) in renesas_usb3_init_ram()
2765 val |= usb3_calc_ramarea(priv->ramsize_per_pipe); in renesas_usb3_init_ram()
2767 usb3_ep->rammap_val = val; in renesas_usb3_init_ram()
2773 if (*cur_ramif + 1 == priv->num_ramif) { in renesas_usb3_init_ram()
2775 *cur_basead += priv->ramsize_per_pipe; in renesas_usb3_init_ram()
2804 .compatible = "renesas,r8a774c0-usb3-peri",
2807 .compatible = "renesas,r8a7795-usb3-peri",
2810 .compatible = "renesas,r8a77990-usb3-peri",
2813 .compatible = "renesas,rzv2m-usb3-peri",
2816 .compatible = "renesas,rcar-gen3-usb3-peri",
2841 priv = of_device_get_match_data(&pdev->dev); in renesas_usb3_probe()
2847 usb3 = devm_kzalloc(&pdev->dev, sizeof(*usb3), GFP_KERNEL); in renesas_usb3_probe()
2849 return -ENOMEM; in renesas_usb3_probe()
2851 usb3->is_rzv2m = priv->is_rzv2m; in renesas_usb3_probe()
2853 usb3->reg = devm_platform_ioremap_resource(pdev, 0); in renesas_usb3_probe()
2854 if (IS_ERR(usb3->reg)) in renesas_usb3_probe()
2855 return PTR_ERR(usb3->reg); in renesas_usb3_probe()
2858 spin_lock_init(&usb3->lock); in renesas_usb3_probe()
2860 usb3->gadget.ops = &renesas_usb3_gadget_ops; in renesas_usb3_probe()
2861 usb3->gadget.name = udc_name; in renesas_usb3_probe()
2862 usb3->gadget.max_speed = USB_SPEED_SUPER; in renesas_usb3_probe()
2863 INIT_LIST_HEAD(&usb3->gadget.ep_list); in renesas_usb3_probe()
2864 ret = renesas_usb3_init_ep(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2867 renesas_usb3_init_ram(usb3, &pdev->dev, priv); in renesas_usb3_probe()
2869 ret = devm_request_irq(&pdev->dev, irq, renesas_usb3_irq, 0, in renesas_usb3_probe()
2870 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
2874 if (usb3->is_rzv2m) { in renesas_usb3_probe()
2875 struct rzv2m_usb3drd *ddata = dev_get_drvdata(pdev->dev.parent); in renesas_usb3_probe()
2877 usb3->drd_reg = ddata->reg; in renesas_usb3_probe()
2878 ret = devm_request_irq(&pdev->dev, ddata->drd_irq, in renesas_usb3_probe()
2880 dev_name(&pdev->dev), usb3); in renesas_usb3_probe()
2885 INIT_WORK(&usb3->extcon_work, renesas_usb3_extcon_work); in renesas_usb3_probe()
2886 usb3->extcon = devm_extcon_dev_allocate(&pdev->dev, renesas_usb3_cable); in renesas_usb3_probe()
2887 if (IS_ERR(usb3->extcon)) in renesas_usb3_probe()
2888 return PTR_ERR(usb3->extcon); in renesas_usb3_probe()
2890 ret = devm_extcon_dev_register(&pdev->dev, usb3->extcon); in renesas_usb3_probe()
2892 dev_err(&pdev->dev, "Failed to register extcon\n"); in renesas_usb3_probe()
2897 usb3->ep0_req = __renesas_usb3_ep_alloc_request(GFP_KERNEL); in renesas_usb3_probe()
2898 if (!usb3->ep0_req) in renesas_usb3_probe()
2899 return -ENOMEM; in renesas_usb3_probe()
2901 ret = renesas_usb3_dma_alloc_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2909 usb3->phy = devm_phy_optional_get(&pdev->dev, "usb"); in renesas_usb3_probe()
2910 if (IS_ERR(usb3->phy)) { in renesas_usb3_probe()
2911 ret = PTR_ERR(usb3->phy); in renesas_usb3_probe()
2915 usb3->usbp_rstc = devm_reset_control_get_optional_shared(&pdev->dev, in renesas_usb3_probe()
2917 if (IS_ERR(usb3->usbp_rstc)) { in renesas_usb3_probe()
2918 ret = PTR_ERR(usb3->usbp_rstc); in renesas_usb3_probe()
2922 reset_control_deassert(usb3->usbp_rstc); in renesas_usb3_probe()
2924 pm_runtime_enable(&pdev->dev); in renesas_usb3_probe()
2925 ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget); in renesas_usb3_probe()
2929 ret = device_create_file(&pdev->dev, &dev_attr_role); in renesas_usb3_probe()
2933 if (device_property_read_bool(&pdev->dev, "usb-role-switch")) { in renesas_usb3_probe()
2934 usb3->role_sw_by_connector = true; in renesas_usb3_probe()
2935 renesas_usb3_role_switch_desc.fwnode = dev_fwnode(&pdev->dev); in renesas_usb3_probe()
2940 INIT_WORK(&usb3->role_work, renesas_usb3_role_work); in renesas_usb3_probe()
2941 usb3->role_sw = usb_role_switch_register(&pdev->dev, in renesas_usb3_probe()
2943 if (!IS_ERR(usb3->role_sw)) { in renesas_usb3_probe()
2944 usb3->host_dev = usb_of_get_companion_dev(&pdev->dev); in renesas_usb3_probe()
2945 if (!usb3->host_dev) { in renesas_usb3_probe()
2947 usb_role_switch_unregister(usb3->role_sw); in renesas_usb3_probe()
2948 usb3->role_sw = NULL; in renesas_usb3_probe()
2951 usb3->role_sw = NULL; in renesas_usb3_probe()
2954 usb3->workaround_for_vbus = priv->workaround_for_vbus; in renesas_usb3_probe()
2956 renesas_usb3_debugfs_init(usb3, &pdev->dev); in renesas_usb3_probe()
2958 dev_info(&pdev->dev, "probed%s\n", usb3->phy ? " with phy" : ""); in renesas_usb3_probe()
2963 usb_del_gadget_udc(&usb3->gadget); in renesas_usb3_probe()
2966 reset_control_assert(usb3->usbp_rstc); in renesas_usb3_probe()
2969 renesas_usb3_dma_free_prd(usb3, &pdev->dev); in renesas_usb3_probe()
2972 __renesas_usb3_ep_free_request(usb3->ep0_req); in renesas_usb3_probe()
2983 if (!usb3->driver) in renesas_usb3_suspend()
2987 if (usb3->phy) in renesas_usb3_suspend()
2988 phy_exit(usb3->phy); in renesas_usb3_suspend()
2999 if (!usb3->driver) in renesas_usb3_resume()
3002 if (usb3->phy) in renesas_usb3_resume()
3003 phy_init(usb3->phy); in renesas_usb3_resume()