1 | /*
|
---|
2 | * Copyright (c) 2011 Jan Vesely
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup drvusbohci
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief OHCI host controller register structure
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef DRV_OHCI_OHCI_REGS_H
|
---|
37 | #define DRV_OHCI_OHCI_REGS_H
|
---|
38 |
|
---|
39 | #include <ddi.h>
|
---|
40 | #include <byteorder.h>
|
---|
41 |
|
---|
42 | #define OHCI_WR(reg, val) pio_write_32(&(reg), host2uint32_t_le(val))
|
---|
43 | #define OHCI_RD(reg) uint32_t_le2host(pio_read_32(&(reg)))
|
---|
44 | #define OHCI_SET(reg, val) pio_set_32(&(reg), host2uint32_t_le(val), 1)
|
---|
45 | #define OHCI_CLR(reg, val) pio_clear_32(&(reg), host2uint32_t_le(val), 1)
|
---|
46 |
|
---|
47 | #define LEGACY_REGS_OFFSET 0x100
|
---|
48 |
|
---|
49 | /** OHCI memory mapped registers structure */
|
---|
50 | typedef struct ohci_regs {
|
---|
51 | const ioport32_t revision;
|
---|
52 |
|
---|
53 | ioport32_t control;
|
---|
54 |
|
---|
55 | ioport32_t command_status;
|
---|
56 |
|
---|
57 | /** Interupt enable/disable/status,
|
---|
58 | * reads give the same value,
|
---|
59 | * writing causes enable/disable,
|
---|
60 | * status is write-clean (writing 1 clears the bit
|
---|
61 | */
|
---|
62 | ioport32_t interrupt_status;
|
---|
63 | ioport32_t interrupt_enable;
|
---|
64 | ioport32_t interrupt_disable;
|
---|
65 |
|
---|
66 | /** HCCA pointer (see hw_struct hcca.h) */
|
---|
67 | ioport32_t hcca;
|
---|
68 |
|
---|
69 | /** Currently executed periodic endpoint */
|
---|
70 | const ioport32_t periodic_current;
|
---|
71 |
|
---|
72 | /** The first control endpoint */
|
---|
73 | ioport32_t control_head;
|
---|
74 |
|
---|
75 | /** Currently executed control endpoint */
|
---|
76 | ioport32_t control_current;
|
---|
77 |
|
---|
78 | /** The first bulk endpoint */
|
---|
79 | ioport32_t bulk_head;
|
---|
80 |
|
---|
81 | /** Currently executed bulk endpoint */
|
---|
82 | ioport32_t bulk_current;
|
---|
83 |
|
---|
84 | /** Done TD list, this value is periodically written to HCCA */
|
---|
85 | const ioport32_t done_head;
|
---|
86 |
|
---|
87 | /** Frame time and max packet size for all transfers */
|
---|
88 | ioport32_t fm_interval;
|
---|
89 |
|
---|
90 | /** Bit times remaining in current frame */
|
---|
91 | const ioport32_t fm_remaining;
|
---|
92 |
|
---|
93 | /** Frame number */
|
---|
94 | const ioport32_t fm_number;
|
---|
95 |
|
---|
96 | /** Remaining bit time in frame to start periodic transfers */
|
---|
97 | ioport32_t periodic_start;
|
---|
98 |
|
---|
99 | /** Threshold for starting LS transaction */
|
---|
100 | ioport32_t ls_threshold;
|
---|
101 |
|
---|
102 | /** The first root hub control register */
|
---|
103 | ioport32_t rh_desc_a;
|
---|
104 |
|
---|
105 | /** The other root hub control register */
|
---|
106 | ioport32_t rh_desc_b;
|
---|
107 |
|
---|
108 | /** Root hub status register */
|
---|
109 | ioport32_t rh_status;
|
---|
110 |
|
---|
111 | /** Root hub per port status */
|
---|
112 | ioport32_t rh_port_status[];
|
---|
113 | #define RHPS_CCS_FLAG (1 << 0) /* r: current connect status,
|
---|
114 | * w: 1-clear port enable, 0-N/S*/
|
---|
115 | #define RHPS_CLEAR_PORT_ENABLE RHPS_CCS_FLAG
|
---|
116 | #define RHPS_PES_FLAG (1 << 1) /* r: port enable status
|
---|
117 | * w: 1-set port enable, 0-N/S */
|
---|
118 | #define RHPS_SET_PORT_ENABLE RHPS_PES_FLAG
|
---|
119 | #define RHPS_PSS_FLAG (1 << 2) /* r: port suspend status
|
---|
120 | * w: 1-set port suspend, 0-N/S */
|
---|
121 | #define RHPS_SET_PORT_SUSPEND RHPS_PSS_FLAG
|
---|
122 | #define RHPS_POCI_FLAG (1 << 3) /* r: port over-current
|
---|
123 | * (if reports are per-port
|
---|
124 | * w: 1-clear port suspend
|
---|
125 | * (start resume if suspened)
|
---|
126 | * 0-nothing */
|
---|
127 | #define RHPS_CLEAR_PORT_SUSPEND RHPS_POCI_FLAG
|
---|
128 | #define RHPS_PRS_FLAG (1 << 4) /* r: port reset status
|
---|
129 | * w: 1-set port reset, 0-N/S */
|
---|
130 | #define RHPS_SET_PORT_RESET RHPS_PRS_FLAG
|
---|
131 | #define RHPS_PPS_FLAG (1 << 8) /* r: port power status
|
---|
132 | * w: 1-set port power, 0-N/S */
|
---|
133 | #define RHPS_SET_PORT_POWER RHPS_PPS_FLAG
|
---|
134 | #define RHPS_LSDA_FLAG (1 << 9) /* r: low speed device attached
|
---|
135 | * w: 1-clear port power, 0-N/S*/
|
---|
136 | #define RHPS_CLEAR_PORT_POWER RHPS_LSDA_FLAG
|
---|
137 | #define RHPS_CSC_FLAG (1 << 16) /* connect status change WC */
|
---|
138 | #define RHPS_PESC_FLAG (1 << 17) /* port enable status change WC */
|
---|
139 | #define RHPS_PSSC_FLAG (1 << 18) /* port suspend status change WC */
|
---|
140 | #define RHPS_OCIC_FLAG (1 << 19) /* port over-current change WC */
|
---|
141 | #define RHPS_PRSC_FLAG (1 << 20) /* port reset status change WC */
|
---|
142 | #define RHPS_CHANGE_WC_MASK (0x1f0000)
|
---|
143 | } ohci_regs_t;
|
---|
144 |
|
---|
145 | /*
|
---|
146 | * ohci_regs_t.revision
|
---|
147 | */
|
---|
148 |
|
---|
149 | #define R_REVISION_MASK (0x3f)
|
---|
150 | #define R_LEGACY_FLAG (0x80)
|
---|
151 |
|
---|
152 | /*
|
---|
153 | * ohci_regs_t.control
|
---|
154 | */
|
---|
155 |
|
---|
156 | /* Control-bulk service ratio */
|
---|
157 | #define C_CBSR_1_1 (0x0)
|
---|
158 | #define C_CBSR_1_2 (0x1)
|
---|
159 | #define C_CBSR_1_3 (0x2)
|
---|
160 | #define C_CBSR_1_4 (0x3)
|
---|
161 | #define C_CBSR_MASK (0x3)
|
---|
162 | #define C_CBSR_SHIFT 0
|
---|
163 |
|
---|
164 | #define C_PLE (1 << 2) /* Periodic list enable */
|
---|
165 | #define C_IE (1 << 3) /* Isochronous enable */
|
---|
166 | #define C_CLE (1 << 4) /* Control list enable */
|
---|
167 | #define C_BLE (1 << 5) /* Bulk list enable */
|
---|
168 |
|
---|
169 | /* Host controller functional state */
|
---|
170 | #define C_HCFS_RESET (0x0)
|
---|
171 | #define C_HCFS_RESUME (0x1)
|
---|
172 | #define C_HCFS_OPERATIONAL (0x2)
|
---|
173 | #define C_HCFS_SUSPEND (0x3)
|
---|
174 | #define C_HCFS_GET(reg) ((OHCI_RD(reg) >> 6) & 0x3)
|
---|
175 | #define C_HCFS_SET(reg, value) \
|
---|
176 | do { \
|
---|
177 | uint32_t r = OHCI_RD(reg); \
|
---|
178 | r &= ~(0x3 << 6); \
|
---|
179 | r |= (value & 0x3) << 6; \
|
---|
180 | OHCI_WR(reg, r); \
|
---|
181 | } while (0)
|
---|
182 |
|
---|
183 | #define C_IR (1 << 8) /* Interrupt routing, make sure it's 0 */
|
---|
184 | #define C_RWC (1 << 9) /* Remote wakeup connected, host specific */
|
---|
185 | #define C_RWE (1 << 10) /* Remote wakeup enable */
|
---|
186 |
|
---|
187 | /*
|
---|
188 | * ohci_regs_t.command_status
|
---|
189 | */
|
---|
190 |
|
---|
191 | #define CS_HCR (1 << 0) /* Host controller reset */
|
---|
192 | #define CS_CLF (1 << 1) /* Control list filled */
|
---|
193 | #define CS_BLF (1 << 2) /* Bulk list filled */
|
---|
194 | #define CS_OCR (1 << 3) /* Ownership change request */
|
---|
195 | #if 0
|
---|
196 | #define CS_SOC_MASK (0x3) /* Scheduling overrun count */
|
---|
197 | #define CS_SOC_SHIFT (16)
|
---|
198 | #endif
|
---|
199 |
|
---|
200 | /*
|
---|
201 | * ohci_regs_t.interrupt_xxx
|
---|
202 | */
|
---|
203 |
|
---|
204 | #define I_SO (1 << 0) /* Scheduling overrun */
|
---|
205 | #define I_WDH (1 << 1) /* Done head write-back */
|
---|
206 | #define I_SF (1 << 2) /* Start of frame */
|
---|
207 | #define I_RD (1 << 3) /* Resume detect */
|
---|
208 | #define I_UE (1 << 4) /* Unrecoverable error */
|
---|
209 | #define I_FNO (1 << 5) /* Frame number overflow */
|
---|
210 | #define I_RHSC (1 << 6) /* Root hub status change */
|
---|
211 | #define I_OC (1 << 30) /* Ownership change */
|
---|
212 | #define I_MI (1 << 31) /* Master interrupt (any/all) */
|
---|
213 |
|
---|
214 | /*
|
---|
215 | * ohci_regs_t.hcca
|
---|
216 | */
|
---|
217 |
|
---|
218 | #define HCCA_PTR_MASK 0xffffff00 /* HCCA is 256B aligned */
|
---|
219 |
|
---|
220 | /*
|
---|
221 | * ohci_regs_t.fm_interval
|
---|
222 | */
|
---|
223 |
|
---|
224 | #define FMI_FI_MASK (0x3fff) /* Frame interval in bit times (should be 11999)*/
|
---|
225 | #define FMI_FI_SHIFT (0)
|
---|
226 | #define FMI_FSMPS_MASK (0x7fff) /* Full speed max packet size */
|
---|
227 | #define FMI_FSMPS_SHIFT (16)
|
---|
228 | #define FMI_TOGGLE_FLAG (1 << 31)
|
---|
229 |
|
---|
230 | /*
|
---|
231 | * ohci_regs_t.fm_remaining
|
---|
232 | */
|
---|
233 |
|
---|
234 | #define FMR_FR_MASK FMI_FI_MASK
|
---|
235 | #define FMR_FR_SHIFT FMI_FI_SHIFT
|
---|
236 | #define FMR_TOGGLE_FLAG FMI_TOGGLE_FLAG
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * ohci_regs_t.fm_number
|
---|
240 | */
|
---|
241 |
|
---|
242 | #define FMN_NUMBER_MASK (0xffff)
|
---|
243 |
|
---|
244 | /*
|
---|
245 | * ohci_regs_t.periodic_start
|
---|
246 | */
|
---|
247 |
|
---|
248 | #define PS_MASK 0x3fff
|
---|
249 | #define PS_SHIFT 0
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * ohci_regs_t.ls_threshold
|
---|
253 | */
|
---|
254 |
|
---|
255 | #define LST_LST_MASK (0x7fff)
|
---|
256 |
|
---|
257 | /*
|
---|
258 | * ohci_regs_t.rh_desc_a
|
---|
259 | */
|
---|
260 |
|
---|
261 | /** Number of downstream ports, max 15 */
|
---|
262 | #define RHDA_NDS_MASK (0xff)
|
---|
263 | /** Power switching mode: 0-global, 1-per port */
|
---|
264 | #define RHDA_PSM_FLAG (1 << 8)
|
---|
265 | /** No power switch: 1-power on, 0-use PSM */
|
---|
266 | #define RHDA_NPS_FLAG (1 << 9)
|
---|
267 | /** 1-Compound device, must be 0 */
|
---|
268 | #define RHDA_DT_FLAG (1 << 10)
|
---|
269 | /** Over-current mode: 0-global, 1-per port */
|
---|
270 | #define RHDA_OCPM_FLAG (1 << 11)
|
---|
271 | /** OC control: 0-use OCPM, 1-OC off */
|
---|
272 | #define RHDA_NOCP_FLAG (1 << 12)
|
---|
273 | /** Power on to power good time */
|
---|
274 | #define RHDA_POTPGT_SHIFT 24
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * ohci_regs_t.rh_desc_b
|
---|
278 | */
|
---|
279 |
|
---|
280 | /** Device removable mask */
|
---|
281 | #define RHDB_DR_SHIFT 0
|
---|
282 | #define RHDB_DR_MASK 0xffffU
|
---|
283 |
|
---|
284 | /** Power control mask */
|
---|
285 | #define RHDB_PCC_MASK 0xffffU
|
---|
286 | #define RHDB_PCC_SHIFT 16
|
---|
287 |
|
---|
288 | /*
|
---|
289 | * ohci_regs_t.rh_status
|
---|
290 | */
|
---|
291 |
|
---|
292 | /*
|
---|
293 | * read: 0,
|
---|
294 | * write: 0-no effect,
|
---|
295 | * 1-turn off port power for ports
|
---|
296 | * specified in PPCM(RHDB), or all ports,
|
---|
297 | * if power is set globally
|
---|
298 | */
|
---|
299 | #define RHS_LPS_FLAG (1 << 0)
|
---|
300 | #define RHS_CLEAR_GLOBAL_POWER RHS_LPS_FLAG /* synonym for the above */
|
---|
301 | /** Over-current indicator, if per-port: 0 */
|
---|
302 | #define RHS_OCI_FLAG (1 << 1)
|
---|
303 | /*
|
---|
304 | * read: 0-connect status change does not wake HC
|
---|
305 | * 1-connect status change wakes HC
|
---|
306 | * write: 1-set DRWE, 0-no effect
|
---|
307 | */
|
---|
308 | #define RHS_DRWE_FLAG (1 << 15)
|
---|
309 | #define RHS_SET_DRWE RHS_DRWE_FLAG
|
---|
310 | /*
|
---|
311 | * read: 0,
|
---|
312 | * write: 0-no effect
|
---|
313 | * 1-turn on port power for ports
|
---|
314 | * specified in PPCM(RHDB), or all ports,
|
---|
315 | * if power is set globally
|
---|
316 | */
|
---|
317 | #define RHS_LPSC_FLAG (1 << 16)
|
---|
318 | #define RHS_SET_GLOBAL_POWER RHS_LPSC_FLAG /* synonym for the above */
|
---|
319 | /** Over-current change indicator */
|
---|
320 | #define RHS_OCIC_FLAG (1 << 17)
|
---|
321 | #define RHS_CLEAR_DRWE (1 << 31)
|
---|
322 |
|
---|
323 | #endif
|
---|
324 |
|
---|
325 | /*
|
---|
326 | * ohci_regs_t.rh_port_status[x]
|
---|
327 | */
|
---|
328 |
|
---|
329 | /** r: current connect status, w: 1-clear port enable, 0-N/S */
|
---|
330 | #define RHPS_CCS_FLAG (1 << 0)
|
---|
331 | #define RHPS_CLEAR_PORT_ENABLE RHPS_CCS_FLAG
|
---|
332 | /** r: port enable status, w: 1-set port enable, 0-N/S */
|
---|
333 | #define RHPS_PES_FLAG (1 << 1)
|
---|
334 | #define RHPS_SET_PORT_ENABLE RHPS_PES_FLAG
|
---|
335 | /** r: port suspend status, w: 1-set port suspend, 0-N/S */
|
---|
336 | #define RHPS_PSS_FLAG (1 << 2)
|
---|
337 | #define RHPS_SET_PORT_SUSPEND RHPS_PSS_FLAG
|
---|
338 | /** r: port over-current (if reports are per-port
|
---|
339 | * w: 1-clear port suspend (start resume if suspened), 0-nothing
|
---|
340 | */
|
---|
341 | #define RHPS_POCI_FLAG (1 << 3)
|
---|
342 | #define RHPS_CLEAR_PORT_SUSPEND RHPS_POCI_FLAG
|
---|
343 | /** r: port reset status, w: 1-set port reset, 0-N/S */
|
---|
344 | #define RHPS_PRS_FLAG (1 << 4)
|
---|
345 | #define RHPS_SET_PORT_RESET RHPS_PRS_FLAG
|
---|
346 | /** r: port power status, w: 1-set port power, 0-N/S */
|
---|
347 | #define RHPS_PPS_FLAG (1 << 8)
|
---|
348 | #define RHPS_SET_PORT_POWER RHPS_PPS_FLAG
|
---|
349 | /** r: low speed device attached, w: 1-clear port power, 0-N/S */
|
---|
350 | #define RHPS_LSDA_FLAG (1 << 9)
|
---|
351 | #define RHPS_CLEAR_PORT_POWER RHPS_LSDA_FLAG
|
---|
352 | /** connect status change WC */
|
---|
353 | #define RHPS_CSC_FLAG (1 << 16)
|
---|
354 | /** port enable status change WC */
|
---|
355 | #define RHPS_PESC_FLAG (1 << 17)
|
---|
356 | /** port suspend status change WC */
|
---|
357 | #define RHPS_PSSC_FLAG (1 << 18)
|
---|
358 | /** port over-current change WC */
|
---|
359 | #define RHPS_OCIC_FLAG (1 << 19)
|
---|
360 | /** port reset status change WC */
|
---|
361 | #define RHPS_PRSC_FLAG (1 << 20)
|
---|
362 | #define RHPS_CHANGE_WC_MASK (0x1f0000)
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * @}
|
---|
366 | */
|
---|