Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 2 | /* |
Marek Vasut | 4a7629a | 2015-12-04 02:55:37 +0100 | [diff] [blame] | 3 | * Designware DWC2 on-chip full/high speed USB device controllers |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 4 | * Copyright (C) 2005 for Samsung Electronics |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Marek Vasut | 4811c66 | 2015-12-04 02:32:22 +0100 | [diff] [blame] | 7 | #ifndef __DWC2_UDC_OTG_PRIV__ |
| 8 | #define __DWC2_UDC_OTG_PRIV__ |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 9 | |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 10 | #include <linux/errno.h> |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 11 | #include <linux/sizes.h> |
| 12 | #include <linux/usb/ch9.h> |
| 13 | #include <linux/usb/gadget.h> |
| 14 | #include <linux/list.h> |
Marek Vasut | f1be9cb | 2015-12-04 02:51:20 +0100 | [diff] [blame] | 15 | #include <usb/dwc2_udc.h> |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 16 | |
| 17 | /*-------------------------------------------------------------------------*/ |
| 18 | /* DMA bounce buffer size, 16K is enough even for mass storage */ |
| 19 | #define DMA_BUFFER_SIZE (16*SZ_1K) |
| 20 | |
| 21 | #define EP0_FIFO_SIZE 64 |
| 22 | #define EP_FIFO_SIZE 512 |
| 23 | #define EP_FIFO_SIZE2 1024 |
| 24 | /* ep0-control, ep1in-bulk, ep2out-bulk, ep3in-int */ |
Marek Vasut | cb9c5d0 | 2015-12-04 02:44:33 +0100 | [diff] [blame] | 25 | #define DWC2_MAX_ENDPOINTS 4 |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 26 | |
| 27 | #define WAIT_FOR_SETUP 0 |
| 28 | #define DATA_STATE_XMIT 1 |
| 29 | #define DATA_STATE_NEED_ZLP 2 |
| 30 | #define WAIT_FOR_OUT_STATUS 3 |
| 31 | #define DATA_STATE_RECV 4 |
| 32 | #define WAIT_FOR_COMPLETE 5 |
| 33 | #define WAIT_FOR_OUT_COMPLETE 6 |
| 34 | #define WAIT_FOR_IN_COMPLETE 7 |
| 35 | #define WAIT_FOR_NULL_COMPLETE 8 |
| 36 | |
| 37 | #define TEST_J_SEL 0x1 |
| 38 | #define TEST_K_SEL 0x2 |
| 39 | #define TEST_SE0_NAK_SEL 0x3 |
| 40 | #define TEST_PACKET_SEL 0x4 |
| 41 | #define TEST_FORCE_ENABLE_SEL 0x5 |
| 42 | |
| 43 | /* ************************************************************************* */ |
| 44 | /* IO |
| 45 | */ |
| 46 | |
| 47 | enum ep_type { |
| 48 | ep_control, ep_bulk_in, ep_bulk_out, ep_interrupt |
| 49 | }; |
| 50 | |
Marek Vasut | 5b309f7 | 2015-12-04 01:48:57 +0100 | [diff] [blame] | 51 | struct dwc2_ep { |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 52 | struct usb_ep ep; |
| 53 | struct dwc2_udc *dev; |
| 54 | |
| 55 | const struct usb_endpoint_descriptor *desc; |
| 56 | struct list_head queue; |
| 57 | unsigned long pio_irqs; |
| 58 | int len; |
| 59 | void *dma_buf; |
| 60 | |
| 61 | u8 stopped; |
| 62 | u8 bEndpointAddress; |
| 63 | u8 bmAttributes; |
| 64 | |
| 65 | enum ep_type ep_type; |
| 66 | int fifo_num; |
| 67 | }; |
| 68 | |
Marek Vasut | 32f931c | 2015-12-04 01:51:07 +0100 | [diff] [blame] | 69 | struct dwc2_request { |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 70 | struct usb_request req; |
| 71 | struct list_head queue; |
| 72 | }; |
| 73 | |
| 74 | struct dwc2_udc { |
| 75 | struct usb_gadget gadget; |
| 76 | struct usb_gadget_driver *driver; |
| 77 | |
Marek Vasut | 6939aca | 2015-12-04 02:23:29 +0100 | [diff] [blame] | 78 | struct dwc2_plat_otg_data *pdata; |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 79 | |
| 80 | int ep0state; |
Marek Vasut | cb9c5d0 | 2015-12-04 02:44:33 +0100 | [diff] [blame] | 81 | struct dwc2_ep ep[DWC2_MAX_ENDPOINTS]; |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 82 | |
| 83 | unsigned char usb_address; |
| 84 | |
| 85 | unsigned req_pending:1, req_std:1; |
| 86 | }; |
| 87 | |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 88 | #define ep_is_in(EP) (((EP)->bEndpointAddress&USB_DIR_IN) == USB_DIR_IN) |
| 89 | #define ep_index(EP) ((EP)->bEndpointAddress&0xF) |
| 90 | #define ep_maxpacket(EP) ((EP)->ep.maxpacket) |
| 91 | |
Marek Vasut | 6f1c6f5 | 2015-12-04 02:21:41 +0100 | [diff] [blame] | 92 | void otg_phy_init(struct dwc2_udc *dev); |
| 93 | void otg_phy_off(struct dwc2_udc *dev); |
Marek Vasut | 0b90750 | 2015-12-04 01:36:36 +0100 | [diff] [blame] | 94 | |
Marek Vasut | 4811c66 | 2015-12-04 02:32:22 +0100 | [diff] [blame] | 95 | #endif /* __DWC2_UDC_OTG_PRIV__ */ |