]>
Commit | Line | Data |
---|---|---|
aaf098cf MT |
1 | /*- |
2 | * Copyright (c) 2007-2008, Juniper Networks, Inc. | |
c0d722fe | 3 | * Copyright (c) 2008, Michael Trimarchi <trimarchimichael@yahoo.it> |
aaf098cf MT |
4 | * All rights reserved. |
5 | * | |
e62b5266 | 6 | * SPDX-License-Identifier: GPL-2.0 |
aaf098cf MT |
7 | */ |
8 | ||
9 | #ifndef USB_EHCI_H | |
10 | #define USB_EHCI_H | |
11 | ||
b959655f MV |
12 | #include <usb.h> |
13 | ||
c0d722fe RB |
14 | #if !defined(CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS) |
15 | #define CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS 2 | |
16 | #endif | |
17 | ||
aaf098cf MT |
18 | /* |
19 | * Register Space. | |
20 | */ | |
21 | struct ehci_hccr { | |
db63299b | 22 | uint32_t cr_capbase; |
23 | #define HC_LENGTH(p) (((p) >> 0) & 0x00ff) | |
24 | #define HC_VERSION(p) (((p) >> 16) & 0xffff) | |
aaf098cf | 25 | uint32_t cr_hcsparams; |
c0d722fe RB |
26 | #define HCS_PPC(p) ((p) & (1 << 4)) |
27 | #define HCS_INDICATOR(p) ((p) & (1 << 16)) /* Port indicators */ | |
51ab142b | 28 | #define HCS_N_PORTS(p) (((p) >> 0) & 0xf) |
aaf098cf MT |
29 | uint32_t cr_hccparams; |
30 | uint8_t cr_hcsp_portrt[8]; | |
69716c19 | 31 | } __attribute__ ((packed, aligned(4))); |
aaf098cf MT |
32 | |
33 | struct ehci_hcor { | |
34 | uint32_t or_usbcmd; | |
51ab142b | 35 | #define CMD_PARK (1 << 11) /* enable "park" */ |
36 | #define CMD_PARK_CNT(c) (((c) >> 8) & 3) /* how many transfers to park */ | |
51ab142b | 37 | #define CMD_LRESET (1 << 7) /* partial reset */ |
c02bf458 MY |
38 | #define CMD_IAAD (1 << 6) /* "doorbell" interrupt */ |
39 | #define CMD_ASE (1 << 5) /* async schedule enable */ | |
51ab142b | 40 | #define CMD_PSE (1 << 4) /* periodic schedule enable */ |
41 | #define CMD_RESET (1 << 1) /* reset HC not bus */ | |
42 | #define CMD_RUN (1 << 0) /* start/stop HC */ | |
aaf098cf | 43 | uint32_t or_usbsts; |
14eb79b7 | 44 | #define STS_ASS (1 << 15) |
8f62ca64 | 45 | #define STS_PSS (1 << 14) |
51ab142b | 46 | #define STS_HALT (1 << 12) |
aaf098cf | 47 | uint32_t or_usbintr; |
29c6fbe0 DD |
48 | #define INTR_UE (1 << 0) /* USB interrupt enable */ |
49 | #define INTR_UEE (1 << 1) /* USB error interrupt enable */ | |
50 | #define INTR_PCE (1 << 2) /* Port change detect enable */ | |
51 | #define INTR_SEE (1 << 4) /* system error enable */ | |
52 | #define INTR_AAE (1 << 5) /* Interrupt on async adavance enable */ | |
aaf098cf MT |
53 | uint32_t or_frindex; |
54 | uint32_t or_ctrldssegment; | |
55 | uint32_t or_periodiclistbase; | |
56 | uint32_t or_asynclistaddr; | |
9ab4ce22 SG |
57 | uint32_t _reserved_0_; |
58 | uint32_t or_burstsize; | |
59 | uint32_t or_txfilltuning; | |
14eb79b7 | 60 | #define TXFIFO_THRESH_MASK (0x3f << 16) |
9ab4ce22 SG |
61 | #define TXFIFO_THRESH(p) ((p & 0x3f) << 16) |
62 | uint32_t _reserved_1_[6]; | |
aaf098cf | 63 | uint32_t or_configflag; |
51ab142b | 64 | #define FLAG_CF (1 << 0) /* true: we'll support "high speed" */ |
c0d722fe | 65 | uint32_t or_portsc[CONFIG_SYS_USB_EHCI_MAX_ROOT_PORTS]; |
14eb79b7 BT |
66 | #define PORTSC_PSPD(x) (((x) >> 26) & 0x3) |
67 | #define PORTSC_PSPD_FS 0x0 | |
68 | #define PORTSC_PSPD_LS 0x1 | |
69 | #define PORTSC_PSPD_HS 0x2 | |
aaf098cf | 70 | uint32_t or_systune; |
69716c19 | 71 | } __attribute__ ((packed, aligned(4))); |
aaf098cf | 72 | |
51ab142b | 73 | #define USBMODE 0x68 /* USB Device mode */ |
74 | #define USBMODE_SDIS (1 << 3) /* Stream disable */ | |
75 | #define USBMODE_BE (1 << 2) /* BE/LE endiannes select */ | |
76 | #define USBMODE_CM_HC (3 << 0) /* host controller mode */ | |
77 | #define USBMODE_CM_IDLE (0 << 0) /* idle state */ | |
78 | ||
db63299b | 79 | /* Interface descriptor */ |
80 | struct usb_linux_interface_descriptor { | |
81 | unsigned char bLength; | |
82 | unsigned char bDescriptorType; | |
83 | unsigned char bInterfaceNumber; | |
84 | unsigned char bAlternateSetting; | |
85 | unsigned char bNumEndpoints; | |
86 | unsigned char bInterfaceClass; | |
87 | unsigned char bInterfaceSubClass; | |
88 | unsigned char bInterfaceProtocol; | |
89 | unsigned char iInterface; | |
90 | } __attribute__ ((packed)); | |
91 | ||
92 | /* Configuration descriptor information.. */ | |
93 | struct usb_linux_config_descriptor { | |
94 | unsigned char bLength; | |
95 | unsigned char bDescriptorType; | |
96 | unsigned short wTotalLength; | |
97 | unsigned char bNumInterfaces; | |
98 | unsigned char bConfigurationValue; | |
99 | unsigned char iConfiguration; | |
100 | unsigned char bmAttributes; | |
101 | unsigned char MaxPower; | |
102 | } __attribute__ ((packed)); | |
103 | ||
104 | #if defined CONFIG_EHCI_DESC_BIG_ENDIAN | |
51ab142b | 105 | #define ehci_readl(x) (*((volatile u32 *)(x))) |
106 | #define ehci_writel(a, b) (*((volatile u32 *)(a)) = ((volatile u32)b)) | |
db63299b | 107 | #else |
51ab142b | 108 | #define ehci_readl(x) cpu_to_le32((*((volatile u32 *)(x)))) |
109 | #define ehci_writel(a, b) (*((volatile u32 *)(a)) = \ | |
110 | cpu_to_le32(((volatile u32)b))) | |
db63299b | 111 | #endif |
112 | ||
113 | #if defined CONFIG_EHCI_MMIO_BIG_ENDIAN | |
114 | #define hc32_to_cpu(x) be32_to_cpu((x)) | |
115 | #define cpu_to_hc32(x) cpu_to_be32((x)) | |
116 | #else | |
117 | #define hc32_to_cpu(x) le32_to_cpu((x)) | |
118 | #define cpu_to_hc32(x) cpu_to_le32((x)) | |
119 | #endif | |
120 | ||
c0d722fe RB |
121 | #define EHCI_PS_WKOC_E (1 << 22) /* RW wake on over current */ |
122 | #define EHCI_PS_WKDSCNNT_E (1 << 21) /* RW wake on disconnect */ | |
123 | #define EHCI_PS_WKCNNT_E (1 << 20) /* RW wake on connect */ | |
124 | #define EHCI_PS_PO (1 << 13) /* RW port owner */ | |
125 | #define EHCI_PS_PP (1 << 12) /* RW,RO port power */ | |
126 | #define EHCI_PS_LS (3 << 10) /* RO line status */ | |
127 | #define EHCI_PS_PR (1 << 8) /* RW port reset */ | |
128 | #define EHCI_PS_SUSP (1 << 7) /* RW suspend */ | |
129 | #define EHCI_PS_FPR (1 << 6) /* RW force port resume */ | |
130 | #define EHCI_PS_OCC (1 << 5) /* RWC over current change */ | |
131 | #define EHCI_PS_OCA (1 << 4) /* RO over current active */ | |
132 | #define EHCI_PS_PEC (1 << 3) /* RWC port enable change */ | |
133 | #define EHCI_PS_PE (1 << 2) /* RW port enable */ | |
134 | #define EHCI_PS_CSC (1 << 1) /* RWC connect status change */ | |
135 | #define EHCI_PS_CS (1 << 0) /* RO connect status */ | |
aaf098cf MT |
136 | #define EHCI_PS_CLEAR (EHCI_PS_OCC | EHCI_PS_PEC | EHCI_PS_CSC) |
137 | ||
c0d722fe | 138 | #define EHCI_PS_IS_LOWSPEED(x) (((x) & EHCI_PS_LS) == (1 << 10)) |
aaf098cf MT |
139 | |
140 | /* | |
141 | * Schedule Interface Space. | |
142 | * | |
143 | * IMPORTANT: Software must ensure that no interface data structure | |
144 | * reachable by the EHCI host controller spans a 4K page boundary! | |
145 | * | |
146 | * Periodic transfers (i.e. isochronous and interrupt transfers) are | |
147 | * not supported. | |
148 | */ | |
149 | ||
150 | /* Queue Element Transfer Descriptor (qTD). */ | |
151 | struct qTD { | |
3ed16071 | 152 | /* this part defined by EHCI spec */ |
cdeb9161 | 153 | uint32_t qt_next; /* see EHCI 3.5.1 */ |
aaf098cf | 154 | #define QT_NEXT_TERMINATE 1 |
cdeb9161 BT |
155 | uint32_t qt_altnext; /* see EHCI 3.5.2 */ |
156 | uint32_t qt_token; /* see EHCI 3.5.3 */ | |
14eb79b7 BT |
157 | #define QT_TOKEN_DT(x) (((x) & 0x1) << 31) /* Data Toggle */ |
158 | #define QT_TOKEN_GET_DT(x) (((x) >> 31) & 0x1) | |
159 | #define QT_TOKEN_TOTALBYTES(x) (((x) & 0x7fff) << 16) /* Total Bytes to Transfer */ | |
160 | #define QT_TOKEN_GET_TOTALBYTES(x) (((x) >> 16) & 0x7fff) | |
161 | #define QT_TOKEN_IOC(x) (((x) & 0x1) << 15) /* Interrupt On Complete */ | |
162 | #define QT_TOKEN_CPAGE(x) (((x) & 0x7) << 12) /* Current Page */ | |
163 | #define QT_TOKEN_CERR(x) (((x) & 0x3) << 10) /* Error Counter */ | |
164 | #define QT_TOKEN_PID(x) (((x) & 0x3) << 8) /* PID Code */ | |
165 | #define QT_TOKEN_PID_OUT 0x0 | |
166 | #define QT_TOKEN_PID_IN 0x1 | |
167 | #define QT_TOKEN_PID_SETUP 0x2 | |
168 | #define QT_TOKEN_STATUS(x) (((x) & 0xff) << 0) /* Status */ | |
169 | #define QT_TOKEN_GET_STATUS(x) (((x) >> 0) & 0xff) | |
170 | #define QT_TOKEN_STATUS_ACTIVE 0x80 | |
171 | #define QT_TOKEN_STATUS_HALTED 0x40 | |
172 | #define QT_TOKEN_STATUS_DATBUFERR 0x20 | |
173 | #define QT_TOKEN_STATUS_BABBLEDET 0x10 | |
174 | #define QT_TOKEN_STATUS_XACTERR 0x08 | |
175 | #define QT_TOKEN_STATUS_MISSEDUFRAME 0x04 | |
176 | #define QT_TOKEN_STATUS_SPLITXSTATE 0x02 | |
177 | #define QT_TOKEN_STATUS_PERR 0x01 | |
cdeb9161 BT |
178 | #define QT_BUFFER_CNT 5 |
179 | uint32_t qt_buffer[QT_BUFFER_CNT]; /* see EHCI 3.5.4 */ | |
180 | uint32_t qt_buffer_hi[QT_BUFFER_CNT]; /* Appendix B */ | |
3ed16071 WD |
181 | /* pad struct for 32 byte alignment */ |
182 | uint32_t unused[3]; | |
8b675fe1 | 183 | }; |
aaf098cf | 184 | |
14eb79b7 BT |
185 | #define EHCI_PAGE_SIZE 4096 |
186 | ||
aaf098cf MT |
187 | /* Queue Head (QH). */ |
188 | struct QH { | |
189 | uint32_t qh_link; | |
190 | #define QH_LINK_TERMINATE 1 | |
191 | #define QH_LINK_TYPE_ITD 0 | |
192 | #define QH_LINK_TYPE_QH 2 | |
193 | #define QH_LINK_TYPE_SITD 4 | |
194 | #define QH_LINK_TYPE_FSTN 6 | |
195 | uint32_t qh_endpt1; | |
14eb79b7 BT |
196 | #define QH_ENDPT1_RL(x) (((x) & 0xf) << 28) /* NAK Count Reload */ |
197 | #define QH_ENDPT1_C(x) (((x) & 0x1) << 27) /* Control Endpoint Flag */ | |
198 | #define QH_ENDPT1_MAXPKTLEN(x) (((x) & 0x7ff) << 16) /* Maximum Packet Length */ | |
199 | #define QH_ENDPT1_H(x) (((x) & 0x1) << 15) /* Head of Reclamation List Flag */ | |
200 | #define QH_ENDPT1_DTC(x) (((x) & 0x1) << 14) /* Data Toggle Control */ | |
201 | #define QH_ENDPT1_DTC_IGNORE_QTD_TD 0x0 | |
202 | #define QH_ENDPT1_DTC_DT_FROM_QTD 0x1 | |
203 | #define QH_ENDPT1_EPS(x) (((x) & 0x3) << 12) /* Endpoint Speed */ | |
204 | #define QH_ENDPT1_EPS_FS 0x0 | |
205 | #define QH_ENDPT1_EPS_LS 0x1 | |
206 | #define QH_ENDPT1_EPS_HS 0x2 | |
207 | #define QH_ENDPT1_ENDPT(x) (((x) & 0xf) << 8) /* Endpoint Number */ | |
208 | #define QH_ENDPT1_I(x) (((x) & 0x1) << 7) /* Inactivate on Next Transaction */ | |
209 | #define QH_ENDPT1_DEVADDR(x) (((x) & 0x7f) << 0) /* Device Address */ | |
aaf098cf | 210 | uint32_t qh_endpt2; |
14eb79b7 BT |
211 | #define QH_ENDPT2_MULT(x) (((x) & 0x3) << 30) /* High-Bandwidth Pipe Multiplier */ |
212 | #define QH_ENDPT2_PORTNUM(x) (((x) & 0x7f) << 23) /* Port Number */ | |
213 | #define QH_ENDPT2_HUBADDR(x) (((x) & 0x7f) << 16) /* Hub Address */ | |
214 | #define QH_ENDPT2_UFCMASK(x) (((x) & 0xff) << 8) /* Split Completion Mask */ | |
215 | #define QH_ENDPT2_UFSMASK(x) (((x) & 0xff) << 0) /* Interrupt Schedule Mask */ | |
aaf098cf MT |
216 | uint32_t qh_curtd; |
217 | struct qTD qh_overlay; | |
daa2dafb SR |
218 | /* |
219 | * Add dummy fill value to make the size of this struct | |
220 | * aligned to 32 bytes | |
221 | */ | |
8f62ca64 | 222 | union { |
61755c79 | 223 | uint32_t fill[4]; |
8f62ca64 PG |
224 | void *buffer; |
225 | }; | |
aaf098cf MT |
226 | }; |
227 | ||
7372b5bd SG |
228 | /* Tweak flags for EHCI, used to control operation */ |
229 | enum { | |
230 | /* don't use or_configflag in init */ | |
231 | EHCI_TWEAK_NO_INIT_CF = 1 << 0, | |
232 | }; | |
233 | ||
deb8508c SG |
234 | struct ehci_ctrl; |
235 | ||
236 | struct ehci_ops { | |
237 | void (*set_usb_mode)(struct ehci_ctrl *ctrl); | |
238 | int (*get_port_speed)(struct ehci_ctrl *ctrl, uint32_t reg); | |
239 | void (*powerup_fixup)(struct ehci_ctrl *ctrl, uint32_t *status_reg, | |
240 | uint32_t *reg); | |
241 | uint32_t *(*get_portsc_register)(struct ehci_ctrl *ctrl, int port); | |
242 | }; | |
243 | ||
b959655f | 244 | struct ehci_ctrl { |
49b4c5c7 | 245 | enum usb_init_type init; |
b959655f MV |
246 | struct ehci_hccr *hccr; /* R/O registers, not need for volatile */ |
247 | struct ehci_hcor *hcor; | |
248 | int rootdev; | |
249 | uint16_t portreset; | |
250 | struct QH qh_list __aligned(USB_DMA_MINALIGN); | |
251 | struct QH periodic_queue __aligned(USB_DMA_MINALIGN); | |
252 | uint32_t *periodic_list; | |
36b73109 | 253 | int periodic_schedules; |
b959655f | 254 | int ntds; |
deb8508c | 255 | struct ehci_ops ops; |
c4a3141d | 256 | void *priv; /* client's private data */ |
b959655f MV |
257 | }; |
258 | ||
c4a3141d | 259 | /** |
deb8508c | 260 | * ehci_set_controller_info() - Set up private data for the controller |
c4a3141d SG |
261 | * |
262 | * This function can be called in ehci_hcd_init() to tell the EHCI layer | |
263 | * about the controller's private data pointer. Then in the above functions | |
deb8508c SG |
264 | * this can be accessed given the struct ehci_ctrl pointer. Also special |
265 | * EHCI operation methods can be provided if required | |
c4a3141d SG |
266 | * |
267 | * @index: Controller number to set | |
268 | * @priv: Controller pointer | |
deb8508c | 269 | * @ops: Controller operations, or NULL to use default |
c4a3141d | 270 | */ |
deb8508c SG |
271 | void ehci_set_controller_priv(int index, void *priv, |
272 | const struct ehci_ops *ops); | |
c4a3141d SG |
273 | |
274 | /** | |
275 | * ehci_get_controller_priv() - Get controller private data | |
276 | * | |
277 | * @index Controller number to get | |
278 | * @return controller pointer for this index | |
279 | */ | |
280 | void *ehci_get_controller_priv(int index); | |
281 | ||
c0d722fe | 282 | /* Low level init functions */ |
127efc4f TK |
283 | int ehci_hcd_init(int index, enum usb_init_type init, |
284 | struct ehci_hccr **hccr, struct ehci_hcor **hcor); | |
676ae068 | 285 | int ehci_hcd_stop(int index); |
c0d722fe | 286 | |
46b01797 SG |
287 | int ehci_register(struct udevice *dev, struct ehci_hccr *hccr, |
288 | struct ehci_hcor *hcor, const struct ehci_ops *ops, | |
289 | uint tweaks, enum usb_init_type init); | |
290 | int ehci_deregister(struct udevice *dev); | |
291 | extern struct dm_usb_ops ehci_usb_ops; | |
292 | ||
aaf098cf | 293 | #endif /* USB_EHCI_H */ |