attempt to get some TDs through the HC -> fail :(
[ppcskel.git] / usb / host / ohci.h
1 /*
2        ppcskel - a Free Software replacement for the Nintendo/BroadOn bootloader.
3        ohci hardware support
4
5 Copyright (C) 2009     Bernhard Urban <lewurm@gmx.net>
6 Copyright (C) 2009     Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
7
8 # This code is licensed to you under the terms of the GNU GPL, version 2;
9 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10 */
11
12 #ifndef __OHCI_H__
13 #define __OHCI_H__
14
15 #include "../../types.h"
16
17 /* stolen from drivers/usb/host/ohci.h (linux-kernel) :) */
18
19 /* OHCI CONTROL AND STATUS REGISTER MASKS */
20
21 /*
22  * HcControl (control) register masks
23  */
24 #define OHCI_CTRL_CBSR (3 << 0)        /* control/bulk service ratio */
25 #define OHCI_CTRL_PLE  (1 << 2)        /* periodic list enable */
26 #define OHCI_CTRL_IE   (1 << 3)        /* isochronous enable */
27 #define OHCI_CTRL_CLE  (1 << 4)        /* control list enable */
28 #define OHCI_CTRL_BLE  (1 << 5)        /* bulk list enable */
29 #define OHCI_CTRL_HCFS (3 << 6)        /* host controller functional state */
30 #define OHCI_CTRL_IR   (1 << 8)        /* interrupt routing */
31 #define OHCI_CTRL_RWC  (1 << 9)        /* remote wakeup connected */
32 #define OHCI_CTRL_RWE  (1 << 10)       /* remote wakeup enable */
33
34 /* pre-shifted values for HCFS */
35 #define OHCI_USB_RESET (0 << 6)
36 #define OHCI_USB_RESUME        (1 << 6)
37 #define OHCI_USB_OPER  (2 << 6)
38 #define OHCI_USB_SUSPEND       (3 << 6)
39
40 /*
41  * HcCommandStatus (cmdstatus) register masks
42  */
43 #define OHCI_HCR       (1 << 0)        /* host controller reset */
44 #define OHCI_CLF       (1 << 1)        /* control list filled */
45 #define OHCI_BLF       (1 << 2)        /* bulk list filled */
46 #define OHCI_OCR       (1 << 3)        /* ownership change request */
47 #define OHCI_SOC       (3 << 16)       /* scheduling overrun count */
48
49 /*
50  * masks used with interrupt registers:
51  * HcInterruptStatus (intrstatus)
52  * HcInterruptEnable (intrenable)
53  * HcInterruptDisable (intrdisable)
54  */
55 #define OHCI_INTR_SO   (1 << 0)        /* scheduling overrun */
56 #define OHCI_INTR_WDH  (1 << 1)        /* writeback of done_head */
57 #define OHCI_INTR_SF   (1 << 2)        /* start frame */
58 #define OHCI_INTR_RD   (1 << 3)        /* resume detect */
59 #define OHCI_INTR_UE   (1 << 4)        /* unrecoverable error */
60 #define OHCI_INTR_FNO  (1 << 5)        /* frame number overflow */
61 #define OHCI_INTR_RHSC (1 << 6)        /* root hub status change */
62 #define OHCI_INTR_OC   (1 << 30)       /* ownership change */
63 #define OHCI_INTR_MIE  (1 << 31)       /* master interrupt enable */
64
65 /*
66  * masks used with interrupt registers:
67  * HcInterruptStatus (intrstatus)
68  * HcInterruptEnable (intrenable)
69  * HcInterruptDisable (intrdisable)
70  */
71 #define OHCI_INTR_SO   (1 << 0)        /* scheduling overrun */
72 #define OHCI_INTR_WDH  (1 << 1)        /* writeback of done_head */
73 #define OHCI_INTR_SF   (1 << 2)        /* start frame */
74 #define OHCI_INTR_RD   (1 << 3)        /* resume detect */
75 #define OHCI_INTR_UE   (1 << 4)        /* unrecoverable error */
76 #define OHCI_INTR_FNO  (1 << 5)        /* frame number overflow */
77 #define OHCI_INTR_RHSC (1 << 6)        /* root hub status change */
78 #define OHCI_INTR_OC   (1 << 30)       /* ownership change */
79 #define OHCI_INTR_MIE  (1 << 31)       /* master interrupt enable */
80
81
82 /* For initializing controller (mask in an HCFS mode too) */
83 #define OHCI_CONTROL_INIT      (3 << 0)
84 #define        OHCI_INTR_INIT \
85                (OHCI_INTR_MIE | OHCI_INTR_RHSC | OHCI_INTR_UE \
86                | OHCI_INTR_RD | OHCI_INTR_WDH)
87
88 /* OHCI ROOT HUB REGISTER MASKS */
89
90 /* roothub.portstatus [i] bits */
91 #define RH_PS_CCS            0x00000001                /* current connect status */
92 #define RH_PS_PES            0x00000002                /* port enable status*/
93 #define RH_PS_PSS            0x00000004                /* port suspend status */
94 #define RH_PS_POCI           0x00000008                /* port over current indicator */
95 #define RH_PS_PRS            0x00000010                /* port reset status */
96 #define RH_PS_PPS            0x00000100                /* port power status */
97 #define RH_PS_LSDA           0x00000200                /* low speed device attached */
98 #define RH_PS_CSC            0x00010000                /* connect status change */
99 #define RH_PS_PESC           0x00020000                /* port enable status change */
100 #define RH_PS_PSSC           0x00040000                /* port suspend status change */
101 #define RH_PS_OCIC           0x00080000                /* over current indicator change */
102 #define RH_PS_PRSC           0x00100000                /* port reset status change */
103
104 /* roothub.status bits */
105 #define RH_HS_LPS           0x00000001         /* local power status */
106 #define RH_HS_OCI           0x00000002         /* over current indicator */
107 #define RH_HS_DRWE          0x00008000         /* device remote wakeup enable */
108 #define RH_HS_LPSC          0x00010000         /* local power status change */
109 #define RH_HS_OCIC          0x00020000         /* over current indicator change */
110 #define RH_HS_CRWE          0x80000000         /* clear remote wakeup enable */
111
112 /* roothub.b masks */
113 #define RH_B_DR                0x0000ffff              /* device removable flags */
114 #define RH_B_PPCM      0xffff0000              /* port power control mask */
115
116 /* roothub.a masks */
117 #define        RH_A_NDP        (0xff << 0)             /* number of downstream ports */
118 #define        RH_A_PSM        (1 << 8)                /* power switching mode */
119 #define        RH_A_NPS        (1 << 9)                /* no power switching */
120 #define        RH_A_DT         (1 << 10)               /* device type (mbz) */
121 #define        RH_A_OCPM       (1 << 11)               /* over current protection mode */
122 #define        RH_A_NOCP       (1 << 12)               /* no over current protection */
123 #define        RH_A_POTPGT     (0xff << 24)            /* power on to power good time */
124
125 struct ohci_hcca {
126 #define NUM_INITS 32
127         u32 int_table[NUM_INITS]; /* periodic schedule */
128         /*
129          * OHCI defines u16 frame_no, followed by u16 zero pad.
130          * Since some processors can't do 16 bit bus accesses,
131          * portable access must be a 32 bits wide.
132          */
133         u32 frame_no;                   /* current frame number */
134         u32 done_head;          /* info returned for an interrupt */
135         u8 reserved_for_hc [116];
136         u8 what [4];               /* spec only identifies 252 bytes :) */
137 } ALIGNED(256);
138
139 struct endpoint_descriptor {
140         u32 flags;
141         u32 tailp;
142         u32 headp;
143         u32 nexted;
144 } ALIGNED(16);
145
146 #define OHCI_ENDPOINT_ADDRESS_MASK                              0x0000007f
147 #define OHCI_ENDPOINT_GET_DEVICE_ADDRESS(s)             ((s) & 0x7f)
148 #define OHCI_ENDPOINT_SET_DEVICE_ADDRESS(s)             (s)
149 #define OHCI_ENDPOINT_GET_ENDPOINT_NUMBER(s)    (((s) >> 7) & 0xf)
150 #define OHCI_ENDPOINT_SET_ENDPOINT_NUMBER(s)    ((s) << 7)
151 #define OHCI_ENDPOINT_DIRECTION_MASK                    0x00001800
152 #define OHCI_ENDPOINT_DIRECTION_DESCRIPTOR              0x00000000
153 #define OHCI_ENDPOINT_DIRECTION_OUT                             0x00000800
154 #define OHCI_ENDPOINT_DIRECTION_IN                              0x00001000
155 #define OHCI_ENDPOINT_LOW_SPEED                                 0x00002000
156 #define OHCI_ENDPOINT_FULL_SPEED                                0x00000000
157 #define OHCI_ENDPOINT_SKIP                                              0x00004000
158 #define OHCI_ENDPOINT_GENERAL_FORMAT                    0x00000000
159 #define OHCI_ENDPOINT_ISOCHRONOUS_FORMAT                0x00008000
160 #define OHCI_ENDPOINT_MAX_PACKET_SIZE_MASK              (0x7ff << 16)
161 #define OHCI_ENDPOINT_GET_MAX_PACKET_SIZE(s)    (((s) >> 16) & 0x07ff)
162 #define OHCI_ENDPOINT_SET_MAX_PACKET_SIZE(s)    ((s) << 16)
163 #define OHCI_ENDPOINT_HALTED                                    0x00000001
164 #define OHCI_ENDPOINT_TOGGLE_CARRY                              0x00000002
165 #define OHCI_ENDPOINT_HEAD_MASK                                 0xfffffffc
166
167
168 struct general_td {
169         u32 flags;
170         u32 cbp;
171         u32 nexttd;
172         u32 be;
173 } ALIGNED(16);
174
175 #define OHCI_TD_BUFFER_ROUNDING                 0x00040000
176 #define OHCI_TD_DIRECTION_PID_MASK              0x00180000
177 #define OHCI_TD_DIRECTION_PID_SETUP             0x00000000
178 #define OHCI_TD_DIRECTION_PID_OUT               0x00080000
179 #define OHCI_TD_DIRECTION_PID_IN                0x00100000
180 #define OHCI_TD_GET_DELAY_INTERRUPT(x)  (((x) >> 21) & 7)
181 #define OHCI_TD_SET_DELAY_INTERRUPT(x)  ((x) << 21)
182 #define OHCI_TD_INTERRUPT_MASK                  0x00e00000
183 #define OHCI_TD_TOGGLE_CARRY                    0x00000000
184 #define OHCI_TD_TOGGLE_0                                0x02000000
185 #define OHCI_TD_TOGGLE_1                                0x03000000
186 #define OHCI_TD_TOGGLE_MASK                             0x03000000
187 #define OHCI_TD_GET_ERROR_COUNT(x)              (((x) >> 26) & 3)
188 #define OHCI_TD_GET_CONDITION_CODE(x)   ((x) >> 28)
189 #define OHCI_TD_SET_CONDITION_CODE(x)   ((x) << 28)
190 #define OHCI_TD_CONDITION_CODE_MASK             0xf0000000
191
192 #define OHCI_TD_INTERRUPT_IMMEDIATE                     0x00
193 #define OHCI_TD_INTERRUPT_NONE                          0x07
194
195 #define OHCI_TD_CONDITION_NO_ERROR                      0x00
196 #define OHCI_TD_CONDITION_CRC_ERROR                     0x01
197 #define OHCI_TD_CONDITION_BIT_STUFFING          0x02
198 #define OHCI_TD_CONDITION_TOGGLE_MISMATCH       0x03
199 #define OHCI_TD_CONDITION_STALL                         0x04
200 #define OHCI_TD_CONDITION_NO_RESPONSE           0x05
201 #define OHCI_TD_CONDITION_PID_CHECK_FAILURE     0x06
202 #define OHCI_TD_CONDITION_UNEXPECTED_PID        0x07
203 #define OHCI_TD_CONDITION_DATA_OVERRUN          0x08
204 #define OHCI_TD_CONDITION_DATA_UNDERRUN         0x09
205 #define OHCI_TD_CONDITION_BUFFER_OVERRUN        0x0c
206 #define OHCI_TD_CONDITION_BUFFER_UNDERRUN       0x0d
207 #define OHCI_TD_CONDITION_NOT_ACCESSED          0x0f
208
209 #endif
210