1 #ifndef __LINUX_UHCI_H
2 #define __LINUX_UHCI_H
3
4 /*
5 $Id: usb-uhci.h,v 1.55 2000/05/13 12:50:30 acher Exp $
6 */
7 #define MODNAME "usb-uhci"
8 #define UHCI_LATENCY_TIMER 0
9
10 static __inline__ void uhci_wait_ms(unsigned int ms)
11 {
12 if(!in_interrupt())
13 {
14 current->state = TASK_UNINTERRUPTIBLE;
15 schedule_timeout(1 + ms * HZ / 1000);
16 }
17 else
18 mdelay(ms);
19 }
20
21 /* Command register */
22 #define USBCMD 0
23 #define USBCMD_RS 0x0001 /* Run/Stop */
24 #define USBCMD_HCRESET 0x0002 /* Host reset */
25 #define USBCMD_GRESET 0x0004 /* Global reset */
26 #define USBCMD_EGSM 0x0008 /* Global Suspend Mode */
27 #define USBCMD_FGR 0x0010 /* Force Global Resume */
28 #define USBCMD_SWDBG 0x0020 /* SW Debug mode */
29 #define USBCMD_CF 0x0040 /* Config Flag (sw only) */
30 #define USBCMD_MAXP 0x0080 /* Max Packet (0 = 32, 1 = 64) */
31
32 /* Status register */
33 #define USBSTS 2
34 #define USBSTS_USBINT 0x0001 /* Interrupt due to IOC */
35 #define USBSTS_ERROR 0x0002 /* Interrupt due to error */
36 #define USBSTS_RD 0x0004 /* Resume Detect */
37 #define USBSTS_HSE 0x0008 /* Host System Error - basically PCI problems */
38 #define USBSTS_HCPE 0x0010 /* Host Controller Process Error - the scripts were buggy */
39 #define USBSTS_HCH 0x0020 /* HC Halted */
40
41 /* Interrupt enable register */
42 #define USBINTR 4
43 #define USBINTR_TIMEOUT 0x0001 /* Timeout/CRC error enable */
44 #define USBINTR_RESUME 0x0002 /* Resume interrupt enable */
45 #define USBINTR_IOC 0x0004 /* Interrupt On Complete enable */
46 #define USBINTR_SP 0x0008 /* Short packet interrupt enable */
47
48 #define USBFRNUM 6
49 #define USBFLBASEADD 8
50 #define USBSOF 12
51
52 /* USB port status and control registers */
53 #define USBPORTSC1 16
54 #define USBPORTSC2 18
55 #define USBPORTSC_CCS 0x0001 /* Current Connect Status ("device present") */
56 #define USBPORTSC_CSC 0x0002 /* Connect Status Change */
57 #define USBPORTSC_PE 0x0004 /* Port Enable */
58 #define USBPORTSC_PEC 0x0008 /* Port Enable Change */
59 #define USBPORTSC_LS 0x0030 /* Line Status */
60 #define USBPORTSC_RD 0x0040 /* Resume Detect */
61 #define USBPORTSC_LSDA 0x0100 /* Low Speed Device Attached */
62 #define USBPORTSC_PR 0x0200 /* Port Reset */
63 #define USBPORTSC_SUSP 0x1000 /* Suspend */
64
65 /* Legacy support register */
66 #define USBLEGSUP 0xc0
67 #define USBLEGSUP_DEFAULT 0x2000 /* only PIRQ enable set */
68
69 #define UHCI_NULL_DATA_SIZE 0x7ff /* for UHCI controller TD */
70 #define UHCI_PID 0xff /* PID MASK */
71
72 #define UHCI_PTR_BITS 0x000F
73 #define UHCI_PTR_TERM 0x0001
74 #define UHCI_PTR_QH 0x0002
75 #define UHCI_PTR_DEPTH 0x0004
76
77 #define UHCI_NUMFRAMES 1024 /* in the frame list [array] */
78 #define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */
79 #define CAN_SCHEDULE_FRAMES 1000 /* how far future frames can be scheduled */
80
81 /*
82 * for TD <status>:
83 */
84 #define TD_CTRL_SPD (1 << 29) /* Short Packet Detect */
85 #define TD_CTRL_C_ERR_MASK (3 << 27) /* Error Counter bits */
86 #define TD_CTRL_LS (1 << 26) /* Low Speed Device */
87 #define TD_CTRL_IOS (1 << 25) /* Isochronous Select */
88 #define TD_CTRL_IOC (1 << 24) /* Interrupt on Complete */
89 #define TD_CTRL_ACTIVE (1 << 23) /* TD Active */
90 #define TD_CTRL_STALLED (1 << 22) /* TD Stalled */
91 #define TD_CTRL_DBUFERR (1 << 21) /* Data Buffer Error */
92 #define TD_CTRL_BABBLE (1 << 20) /* Babble Detected */
93 #define TD_CTRL_NAK (1 << 19) /* NAK Received */
94 #define TD_CTRL_CRCTIMEO (1 << 18) /* CRC/Time Out Error */
95 #define TD_CTRL_BITSTUFF (1 << 17) /* Bit Stuff Error */
96 #define TD_CTRL_ACTLEN_MASK 0x7ff /* actual length, encoded as n - 1 */
97
98 #define TD_CTRL_ANY_ERROR (TD_CTRL_STALLED | TD_CTRL_DBUFERR | \
99 TD_CTRL_BABBLE | TD_CTRL_CRCTIME | TD_CTRL_BITSTUFF)
100
101 #define uhci_status_bits(ctrl_sts) (ctrl_sts & 0xFE0000)
102 #define uhci_actual_length(ctrl_sts) ((ctrl_sts + 1) & TD_CTRL_ACTLEN_MASK) /* 1-based */
103 #define uhci_ptr_to_virt(x) bus_to_virt(x & ~UHCI_PTR_BITS)
104
105 /*
106 * for TD <flags>:
107 */
108 #define UHCI_TD_REMOVE 0x0001 /* Remove when done */
109
110 /*
111 * for TD <info>: (a.k.a. Token)
112 */
113 #define TD_TOKEN_TOGGLE 19
114
115 #define uhci_maxlen(token) ((token) >> 21)
116 #define uhci_toggle(token) (((token) >> TD_TOKEN_TOGGLE) & 1)
117 #define uhci_endpoint(token) (((token) >> 15) & 0xf)
118 #define uhci_devaddr(token) (((token) >> 8) & 0x7f)
119 #define uhci_devep(token) (((token) >> 8) & 0x7ff)
120 #define uhci_packetid(token) ((token) & 0xff)
121 #define uhci_packetout(token) (uhci_packetid(token) != USB_PID_IN)
122 #define uhci_packetin(token) (uhci_packetid(token) == USB_PID_IN)
123
124 /* ------------------------------------------------------------------------------------
125 New TD/QH-structures
126 ------------------------------------------------------------------------------------ */
127 typedef enum {
128 TD_TYPE, QH_TYPE
129 } uhci_desc_type_t;
130
131 typedef struct {
132 __u32 link;
133 __u32 status;
134 __u32 info;
135 __u32 buffer;
136 } uhci_td_t, *puhci_td_t;
137
138 typedef struct {
139 __u32 head;
140 __u32 element; /* Queue element pointer */
141 } uhci_qh_t, *puhci_qh_t;
142
143 typedef struct {
144 union {
145 uhci_td_t td;
146 uhci_qh_t qh;
147 } hw;
148 uhci_desc_type_t type;
149 struct list_head horizontal;
150 struct list_head vertical;
151 struct list_head desc_list;
152 int last_used;
153 } uhci_desc_t, *puhci_desc_t;
154
155 typedef struct {
156 struct list_head desc_list; // list pointer to all corresponding TDs/QHs associated with this request
157 unsigned long started;
158 urb_t *next_queued_urb; // next queued urb for this EP
159 urb_t *prev_queued_urb;
160 uhci_desc_t *bottom_qh;
161 uhci_desc_t *next_qh; // next helper QH
162 char use_loop;
163 char flags;
164 } urb_priv_t, *purb_priv_t;
165
166 struct virt_root_hub {
167 int devnum; /* Address of Root Hub endpoint */
168 void *urb;
169 void *int_addr;
170 int send;
171 int interval;
172 int numports;
173 int c_p_r[8];
174 struct timer_list rh_int_timer;
175 };
176
177 typedef struct uhci {
178 int irq;
179 unsigned int io_addr;
180 unsigned int io_size;
181 unsigned int maxports;
182 int running;
183
184 int apm_state;
185
186 struct uhci *next; // chain of uhci device contexts
187
188 struct list_head urb_list; // list of all pending urbs
189
190 spinlock_t urb_list_lock; // lock to keep consistency
191
192 int unlink_urb_done;
193 atomic_t avoid_bulk;
194
195 struct usb_bus *bus; // our bus
196
197 __u32 *framelist;
198 uhci_desc_t **iso_td;
199 uhci_desc_t *int_chain[8];
200 uhci_desc_t *ls_control_chain;
201 uhci_desc_t *control_chain;
202 uhci_desc_t *bulk_chain;
203 uhci_desc_t *chain_end;
204 uhci_desc_t *td1ms;
205 uhci_desc_t *td32ms;
206 struct list_head free_desc;
207 spinlock_t qh_lock;
208 spinlock_t td_lock;
209 struct virt_root_hub rh; //private data of the virtual root hub
210 int loop_usage; // URBs using bandwidth reclamation
211
212 struct list_head urb_unlinked; // list of all unlinked urbs
213 long timeout_check;
214 int timeout_urbs;
215 struct pci_dev *uhci_pci;
216 } uhci_t, *puhci_t;
217
218
219 #define MAKE_TD_ADDR(a) (virt_to_bus(a)&~UHCI_PTR_QH)
220 #define MAKE_QH_ADDR(a) (virt_to_bus(a)|UHCI_PTR_QH)
221 #define UHCI_GET_CURRENT_FRAME(uhci) (inw ((uhci)->io_addr + USBFRNUM))
222
223 /* ------------------------------------------------------------------------------------
224 Virtual Root HUB
225 ------------------------------------------------------------------------------------ */
226 /* destination of request */
227 #define RH_INTERFACE 0x01
228 #define RH_ENDPOINT 0x02
229 #define RH_OTHER 0x03
230
231 #define RH_CLASS 0x20
232 #define RH_VENDOR 0x40
233
234 /* Requests: bRequest << 8 | bmRequestType */
235 #define RH_GET_STATUS 0x0080
236 #define RH_CLEAR_FEATURE 0x0100
237 #define RH_SET_FEATURE 0x0300
238 #define RH_SET_ADDRESS 0x0500
239 #define RH_GET_DESCRIPTOR 0x0680
240 #define RH_SET_DESCRIPTOR 0x0700
241 #define RH_GET_CONFIGURATION 0x0880
242 #define RH_SET_CONFIGURATION 0x0900
243 #define RH_GET_STATE 0x0280
244 #define RH_GET_INTERFACE 0x0A80
245 #define RH_SET_INTERFACE 0x0B00
246 #define RH_SYNC_FRAME 0x0C80
247 /* Our Vendor Specific Request */
248 #define RH_SET_EP 0x2000
249
250
251 /* Hub port features */
252 #define RH_PORT_CONNECTION 0x00
253 #define RH_PORT_ENABLE 0x01
254 #define RH_PORT_SUSPEND 0x02
255 #define RH_PORT_OVER_CURRENT 0x03
256 #define RH_PORT_RESET 0x04
257 #define RH_PORT_POWER 0x08
258 #define RH_PORT_LOW_SPEED 0x09
259 #define RH_C_PORT_CONNECTION 0x10
260 #define RH_C_PORT_ENABLE 0x11
261 #define RH_C_PORT_SUSPEND 0x12
262 #define RH_C_PORT_OVER_CURRENT 0x13
263 #define RH_C_PORT_RESET 0x14
264
265 /* Hub features */
266 #define RH_C_HUB_LOCAL_POWER 0x00
267 #define RH_C_HUB_OVER_CURRENT 0x01
268
269 #define RH_DEVICE_REMOTE_WAKEUP 0x00
270 #define RH_ENDPOINT_STALL 0x01
271
272 /* Our Vendor Specific feature */
273 #define RH_REMOVE_EP 0x00
274
275
276 #define RH_ACK 0x01
277 #define RH_REQ_ERR -1
278 #define RH_NACK 0x00
279
280 #define min(a,b) (((a)<(b))?(a):(b))
281
282 #endif
283
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.