1 /* 2 * Copyright 2011, Marvell Semiconductor Inc. 3 * 4 * Licensed under the GPL-2 or later. 5 */ 6 #ifndef __GADGET__CI_UDC_H__ 7 #define __GADGET__CI_UDC_H__ 8 9 #define NUM_ENDPOINTS 6 10 11 #ifdef CONFIG_CI_UDC_HAS_HOSTPC 12 struct ci_udc { 13 u32 usbcmd; /* 0x130 */ 14 u32 usbsts; /* 0x134 */ 15 u32 pad1[3]; 16 u32 devaddr; /* 0x144 */ 17 u32 epinitaddr; /* 0x148 */ 18 u32 pad2[10]; 19 u32 portsc; /* 0x174 */ 20 u32 pad178[(0x1b4 - (0x174 + 4)) / 4]; 21 u32 hostpc1_devlc; /* 0x1b4 */ 22 u32 pad1b8[(0x1f8 - (0x1b4 + 4)) / 4]; 23 u32 usbmode; /* 0x1f8 */ 24 u32 pad1fc[(0x208 - (0x1f8 + 4)) / 4]; 25 u32 epsetupstat; /* 0x208 */ 26 u32 epprime; /* 0x20c */ 27 u32 epflush; /* 0x210 */ 28 u32 epstat; /* 0x214 */ 29 u32 epcomp; /* 0x218 */ 30 u32 epctrl[16]; /* 0x21c */ 31 }; 32 #else 33 struct ci_udc { 34 u32 usbcmd; /* 0x140 */ 35 u32 usbsts; /* 0x144 */ 36 u32 pad1[3]; 37 u32 devaddr; /* 0x154 */ 38 u32 epinitaddr; /* 0x158 */ 39 u32 pad2[10]; 40 u32 portsc; /* 0x184 */ 41 u32 pad3[8]; 42 u32 usbmode; /* 0x1a8 */ 43 u32 epstat; /* 0x1ac */ 44 u32 epprime; /* 0x1b0 */ 45 u32 epflush; /* 0x1b4 */ 46 u32 pad4; 47 u32 epcomp; /* 0x1bc */ 48 u32 epctrl[16]; /* 0x1c0 */ 49 }; 50 51 #define PTS_ENABLE 2 52 #define PTS(x) (((x) & 0x3) << 30) 53 #define PFSC (1 << 24) 54 #endif 55 56 #define MICRO_8FRAME 0x8 57 #define USBCMD_ITC(x) ((((x) > 0xff) ? 0xff : x) << 16) 58 #define USBCMD_FS2 (1 << 15) 59 #define USBCMD_RST (1 << 1) 60 #define USBCMD_RUN (1) 61 62 #define STS_SLI (1 << 8) 63 #define STS_URI (1 << 6) 64 #define STS_PCI (1 << 2) 65 #define STS_UEI (1 << 1) 66 #define STS_UI (1 << 0) 67 68 #define USBMODE_DEVICE 2 69 70 #define EPT_TX(x) (1 << (((x) & 0xffff) + 16)) 71 #define EPT_RX(x) (1 << ((x) & 0xffff)) 72 73 #define CTRL_TXE (1 << 23) 74 #define CTRL_TXR (1 << 22) 75 #define CTRL_RXE (1 << 7) 76 #define CTRL_RXR (1 << 6) 77 #define CTRL_TXT_BULK (2 << 18) 78 #define CTRL_RXT_BULK (2 << 2) 79 80 struct ci_ep { 81 struct usb_ep ep; 82 struct list_head queue; 83 const struct usb_endpoint_descriptor *desc; 84 85 struct usb_request req; 86 uint8_t *b_buf; 87 uint32_t b_len; 88 uint8_t b_fast[64] __aligned(ARCH_DMA_MINALIGN); 89 }; 90 91 struct ci_drv { 92 struct usb_gadget gadget; 93 struct usb_gadget_driver *driver; 94 struct ehci_ctrl *ctrl; 95 struct ept_queue_head *epts; 96 struct ept_queue_item *items[2 * NUM_ENDPOINTS]; 97 uint8_t *items_mem; 98 struct ci_ep ep[NUM_ENDPOINTS]; 99 }; 100 101 struct ept_queue_head { 102 unsigned config; 103 unsigned current; /* read-only */ 104 105 unsigned next; 106 unsigned info; 107 unsigned page0; 108 unsigned page1; 109 unsigned page2; 110 unsigned page3; 111 unsigned page4; 112 unsigned reserved_0; 113 114 unsigned char setup_data[8]; 115 116 unsigned reserved_1; 117 unsigned reserved_2; 118 unsigned reserved_3; 119 unsigned reserved_4; 120 }; 121 122 #define CONFIG_MAX_PKT(n) ((n) << 16) 123 #define CONFIG_ZLT (1 << 29) /* stop on zero-len xfer */ 124 #define CONFIG_IOS (1 << 15) /* IRQ on setup */ 125 126 struct ept_queue_item { 127 unsigned next; 128 unsigned info; 129 unsigned page0; 130 unsigned page1; 131 unsigned page2; 132 unsigned page3; 133 unsigned page4; 134 unsigned reserved; 135 }; 136 137 #define TERMINATE 1 138 #define INFO_BYTES(n) ((n) << 16) 139 #define INFO_IOC (1 << 15) 140 #define INFO_ACTIVE (1 << 7) 141 #define INFO_HALTED (1 << 6) 142 #define INFO_BUFFER_ERROR (1 << 5) 143 #define INFO_TX_ERROR (1 << 3) 144 #endif 145