aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host/u132-hcd.c
diff options
context:
space:
mode:
authorDaniel Walker <dwalker@mvista.com>2008-03-23 03:00:01 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-04-25 00:16:44 -0400
commitb40f8d3980d3eef26b3bd77da5314728a5b30aea (patch)
tree6b44b58d2b0c916701799044cf9c2b5ea8712a00 /drivers/usb/host/u132-hcd.c
parent619a6f1d1423d08e74ed2b8a2113f12ef18e4373 (diff)
usb: u132-hcd driver style clean up
I was converting a semaphore in this file to a mutex when I noticed that this file has some fairly rampant style problems. Practically every line has spaces instead of tabs .. Once I cleared that up, checkpatch.pl showed a number of other problem.. I think this file might be a good one to review for new style checks that could be added.. Below are the only two remaining which I didn't remove. #5083: FILE: drivers/usb/host/u132-hcd.c:2907: + error: WARNING: labels should not be indented #5087: FILE: drivers/usb/host/u132-hcd.c:2911: + stall: These labels are actually inside a switch statement, and they are right under "default:". "default:" appears to be exempt and these other label should be too, or default shouldn't be exempt. I also deleted a few lines due to single statements inside { } , if (is_error()) { return; } becomes, if (is_error()) return; with one line deleted. Signed-off-by: Daniel Walker <dwalker@mvista.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host/u132-hcd.c')
-rw-r--r--drivers/usb/host/u132-hcd.c5132
1 files changed, 2563 insertions, 2569 deletions
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 6e9b7edff528..28b8684942d3 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -67,7 +67,7 @@
67#include "ohci.h" 67#include "ohci.h"
68#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR 68#define OHCI_CONTROL_INIT OHCI_CTRL_CBSR
69#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \ 69#define OHCI_INTR_INIT (OHCI_INTR_MIE | OHCI_INTR_UE | OHCI_INTR_RD | \
70 OHCI_INTR_WDH) 70 OHCI_INTR_WDH)
71MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited"); 71MODULE_AUTHOR("Tony Olech - Elan Digital Systems Limited");
72MODULE_DESCRIPTION("U132 USB Host Controller Driver"); 72MODULE_DESCRIPTION("U132 USB Host Controller Driver");
73MODULE_LICENSE("GPL"); 73MODULE_LICENSE("GPL");
@@ -77,15 +77,15 @@ INT_MODULE_PARM(testing, 0);
77static int distrust_firmware = 1; 77static int distrust_firmware = 1;
78module_param(distrust_firmware, bool, 0); 78module_param(distrust_firmware, bool, 0);
79MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren" 79MODULE_PARM_DESC(distrust_firmware, "true to distrust firmware power/overcurren"
80 "t setup"); 80 "t setup");
81static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait); 81static DECLARE_WAIT_QUEUE_HEAD(u132_hcd_wait);
82/* 82/*
83* u132_module_lock exists to protect access to global variables 83* u132_module_lock exists to protect access to global variables
84* 84*
85*/ 85*/
86static struct mutex u132_module_lock; 86static struct mutex u132_module_lock;
87static int u132_exiting = 0; 87static int u132_exiting;
88static int u132_instances = 0; 88static int u132_instances;
89static struct list_head u132_static_list; 89static struct list_head u132_static_list;
90/* 90/*
91* end of the global variables protected by u132_module_lock 91* end of the global variables protected by u132_module_lock
@@ -97,115 +97,115 @@ static struct workqueue_struct *workqueue;
97#define MAX_U132_ENDPS 100 97#define MAX_U132_ENDPS 100
98#define MAX_U132_RINGS 4 98#define MAX_U132_RINGS 4
99static const char *cc_to_text[16] = { 99static const char *cc_to_text[16] = {
100 "No Error ", 100 "No Error ",
101 "CRC Error ", 101 "CRC Error ",
102 "Bit Stuff ", 102 "Bit Stuff ",
103 "Data Togg ", 103 "Data Togg ",
104 "Stall ", 104 "Stall ",
105 "DevNotResp ", 105 "DevNotResp ",
106 "PIDCheck ", 106 "PIDCheck ",
107 "UnExpPID ", 107 "UnExpPID ",
108 "DataOver ", 108 "DataOver ",
109 "DataUnder ", 109 "DataUnder ",
110 "(for hw) ", 110 "(for hw) ",
111 "(for hw) ", 111 "(for hw) ",
112 "BufferOver ", 112 "BufferOver ",
113 "BuffUnder ", 113 "BuffUnder ",
114 "(for HCD) ", 114 "(for HCD) ",
115 "(for HCD) " 115 "(for HCD) "
116}; 116};
117struct u132_port { 117struct u132_port {
118 struct u132 *u132; 118 struct u132 *u132;
119 int reset; 119 int reset;
120 int enable; 120 int enable;
121 int power; 121 int power;
122 int Status; 122 int Status;
123}; 123};
124struct u132_addr { 124struct u132_addr {
125 u8 address; 125 u8 address;
126}; 126};
127struct u132_udev { 127struct u132_udev {
128 struct kref kref; 128 struct kref kref;
129 struct usb_device *usb_device; 129 struct usb_device *usb_device;
130 u8 enumeration; 130 u8 enumeration;
131 u8 udev_number; 131 u8 udev_number;
132 u8 usb_addr; 132 u8 usb_addr;
133 u8 portnumber; 133 u8 portnumber;
134 u8 endp_number_in[16]; 134 u8 endp_number_in[16];
135 u8 endp_number_out[16]; 135 u8 endp_number_out[16];
136}; 136};
137#define ENDP_QUEUE_SHIFT 3 137#define ENDP_QUEUE_SHIFT 3
138#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT) 138#define ENDP_QUEUE_SIZE (1<<ENDP_QUEUE_SHIFT)
139#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1) 139#define ENDP_QUEUE_MASK (ENDP_QUEUE_SIZE-1)
140struct u132_urbq { 140struct u132_urbq {
141 struct list_head urb_more; 141 struct list_head urb_more;
142 struct urb *urb; 142 struct urb *urb;
143}; 143};
144struct u132_spin { 144struct u132_spin {
145 spinlock_t slock; 145 spinlock_t slock;
146}; 146};
147struct u132_endp { 147struct u132_endp {
148 struct kref kref; 148 struct kref kref;
149 u8 udev_number; 149 u8 udev_number;
150 u8 endp_number; 150 u8 endp_number;
151 u8 usb_addr; 151 u8 usb_addr;
152 u8 usb_endp; 152 u8 usb_endp;
153 struct u132 *u132; 153 struct u132 *u132;
154 struct list_head endp_ring; 154 struct list_head endp_ring;
155 struct u132_ring *ring; 155 struct u132_ring *ring;
156 unsigned toggle_bits:2; 156 unsigned toggle_bits:2;
157 unsigned active:1; 157 unsigned active:1;
158 unsigned delayed:1; 158 unsigned delayed:1;
159 unsigned input:1; 159 unsigned input:1;
160 unsigned output:1; 160 unsigned output:1;
161 unsigned pipetype:2; 161 unsigned pipetype:2;
162 unsigned dequeueing:1; 162 unsigned dequeueing:1;
163 unsigned edset_flush:1; 163 unsigned edset_flush:1;
164 unsigned spare_bits:14; 164 unsigned spare_bits:14;
165 unsigned long jiffies; 165 unsigned long jiffies;
166 struct usb_host_endpoint *hep; 166 struct usb_host_endpoint *hep;
167 struct u132_spin queue_lock; 167 struct u132_spin queue_lock;
168 u16 queue_size; 168 u16 queue_size;
169 u16 queue_last; 169 u16 queue_last;
170 u16 queue_next; 170 u16 queue_next;
171 struct urb *urb_list[ENDP_QUEUE_SIZE]; 171 struct urb *urb_list[ENDP_QUEUE_SIZE];
172 struct list_head urb_more; 172 struct list_head urb_more;
173 struct delayed_work scheduler; 173 struct delayed_work scheduler;
174}; 174};
175struct u132_ring { 175struct u132_ring {
176 unsigned in_use:1; 176 unsigned in_use:1;
177 unsigned length:7; 177 unsigned length:7;
178 u8 number; 178 u8 number;
179 struct u132 *u132; 179 struct u132 *u132;
180 struct u132_endp *curr_endp; 180 struct u132_endp *curr_endp;
181 struct delayed_work scheduler; 181 struct delayed_work scheduler;
182}; 182};
183struct u132 { 183struct u132 {
184 struct kref kref; 184 struct kref kref;
185 struct list_head u132_list; 185 struct list_head u132_list;
186 struct mutex sw_lock; 186 struct mutex sw_lock;
187 struct semaphore scheduler_lock; 187 struct semaphore scheduler_lock;
188 struct u132_platform_data *board; 188 struct u132_platform_data *board;
189 struct platform_device *platform_dev; 189 struct platform_device *platform_dev;
190 struct u132_ring ring[MAX_U132_RINGS]; 190 struct u132_ring ring[MAX_U132_RINGS];
191 int sequence_num; 191 int sequence_num;
192 int going; 192 int going;
193 int power; 193 int power;
194 int reset; 194 int reset;
195 int num_ports; 195 int num_ports;
196 u32 hc_control; 196 u32 hc_control;
197 u32 hc_fminterval; 197 u32 hc_fminterval;
198 u32 hc_roothub_status; 198 u32 hc_roothub_status;
199 u32 hc_roothub_a; 199 u32 hc_roothub_a;
200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS]; 200 u32 hc_roothub_portstatus[MAX_ROOT_PORTS];
201 int flags; 201 int flags;
202 unsigned long next_statechange; 202 unsigned long next_statechange;
203 struct delayed_work monitor; 203 struct delayed_work monitor;
204 int num_endpoints; 204 int num_endpoints;
205 struct u132_addr addr[MAX_U132_ADDRS]; 205 struct u132_addr addr[MAX_U132_ADDRS];
206 struct u132_udev udev[MAX_U132_UDEVS]; 206 struct u132_udev udev[MAX_U132_UDEVS];
207 struct u132_port port[MAX_U132_PORTS]; 207 struct u132_port port[MAX_U132_PORTS];
208 struct u132_endp *endp[MAX_U132_ENDPS]; 208 struct u132_endp *endp[MAX_U132_ENDPS];
209}; 209};
210 210
211/* 211/*
@@ -213,34 +213,34 @@ struct u132 {
213* Does anyone have a better way????? 213* Does anyone have a better way?????
214*/ 214*/
215#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \ 215#define ftdi_read_pcimem(pdev, member, data) usb_ftdi_elan_read_pcimem(pdev, \
216 offsetof(struct ohci_regs, member), 0, data); 216 offsetof(struct ohci_regs, member), 0, data);
217#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \ 217#define ftdi_write_pcimem(pdev, member, data) usb_ftdi_elan_write_pcimem(pdev, \
218 offsetof(struct ohci_regs, member), 0, data); 218 offsetof(struct ohci_regs, member), 0, data);
219#define u132_read_pcimem(u132, member, data) \ 219#define u132_read_pcimem(u132, member, data) \
220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \ 220 usb_ftdi_elan_read_pcimem(u132->platform_dev, offsetof(struct \
221 ohci_regs, member), 0, data); 221 ohci_regs, member), 0, data);
222#define u132_write_pcimem(u132, member, data) \ 222#define u132_write_pcimem(u132, member, data) \
223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \ 223 usb_ftdi_elan_write_pcimem(u132->platform_dev, offsetof(struct \
224 ohci_regs, member), 0, data); 224 ohci_regs, member), 0, data);
225static inline struct u132 *udev_to_u132(struct u132_udev *udev) 225static inline struct u132 *udev_to_u132(struct u132_udev *udev)
226{ 226{
227 u8 udev_number = udev->udev_number; 227 u8 udev_number = udev->udev_number;
228 return container_of(udev, struct u132, udev[udev_number]); 228 return container_of(udev, struct u132, udev[udev_number]);
229} 229}
230 230
231static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd) 231static inline struct u132 *hcd_to_u132(struct usb_hcd *hcd)
232{ 232{
233 return (struct u132 *)(hcd->hcd_priv); 233 return (struct u132 *)(hcd->hcd_priv);
234} 234}
235 235
236static inline struct usb_hcd *u132_to_hcd(struct u132 *u132) 236static inline struct usb_hcd *u132_to_hcd(struct u132 *u132)
237{ 237{
238 return container_of((void *)u132, struct usb_hcd, hcd_priv); 238 return container_of((void *)u132, struct usb_hcd, hcd_priv);
239} 239}
240 240
241static inline void u132_disable(struct u132 *u132) 241static inline void u132_disable(struct u132 *u132)
242{ 242{
243 u132_to_hcd(u132)->state = HC_STATE_HALT; 243 u132_to_hcd(u132)->state = HC_STATE_HALT;
244} 244}
245 245
246 246
@@ -250,147 +250,147 @@ static inline void u132_disable(struct u132 *u132)
250#include "../misc/usb_u132.h" 250#include "../misc/usb_u132.h"
251static const char hcd_name[] = "u132_hcd"; 251static const char hcd_name[] = "u132_hcd";
252#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \ 252#define PORT_C_MASK ((USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE | \
253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \ 253 USB_PORT_STAT_C_SUSPEND | USB_PORT_STAT_C_OVERCURRENT | \
254 USB_PORT_STAT_C_RESET) << 16) 254 USB_PORT_STAT_C_RESET) << 16)
255static void u132_hcd_delete(struct kref *kref) 255static void u132_hcd_delete(struct kref *kref)
256{ 256{
257 struct u132 *u132 = kref_to_u132(kref); 257 struct u132 *u132 = kref_to_u132(kref);
258 struct platform_device *pdev = u132->platform_dev; 258 struct platform_device *pdev = u132->platform_dev;
259 struct usb_hcd *hcd = u132_to_hcd(u132); 259 struct usb_hcd *hcd = u132_to_hcd(u132);
260 u132->going += 1; 260 u132->going += 1;
261 mutex_lock(&u132_module_lock); 261 mutex_lock(&u132_module_lock);
262 list_del_init(&u132->u132_list); 262 list_del_init(&u132->u132_list);
263 u132_instances -= 1; 263 u132_instances -= 1;
264 mutex_unlock(&u132_module_lock); 264 mutex_unlock(&u132_module_lock);
265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13" 265 dev_warn(&u132->platform_dev->dev, "FREEING the hcd=%p and thus the u13"
266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev); 266 "2=%p going=%d pdev=%p\n", hcd, u132, u132->going, pdev);
267 usb_put_hcd(hcd); 267 usb_put_hcd(hcd);
268} 268}
269 269
270static inline void u132_u132_put_kref(struct u132 *u132) 270static inline void u132_u132_put_kref(struct u132 *u132)
271{ 271{
272 kref_put(&u132->kref, u132_hcd_delete); 272 kref_put(&u132->kref, u132_hcd_delete);
273} 273}
274 274
275static inline void u132_u132_init_kref(struct u132 *u132) 275static inline void u132_u132_init_kref(struct u132 *u132)
276{ 276{
277 kref_init(&u132->kref); 277 kref_init(&u132->kref);
278} 278}
279 279
280static void u132_udev_delete(struct kref *kref) 280static void u132_udev_delete(struct kref *kref)
281{ 281{
282 struct u132_udev *udev = kref_to_u132_udev(kref); 282 struct u132_udev *udev = kref_to_u132_udev(kref);
283 udev->udev_number = 0; 283 udev->udev_number = 0;
284 udev->usb_device = NULL; 284 udev->usb_device = NULL;
285 udev->usb_addr = 0; 285 udev->usb_addr = 0;
286 udev->enumeration = 0; 286 udev->enumeration = 0;
287} 287}
288 288
289static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev) 289static inline void u132_udev_put_kref(struct u132 *u132, struct u132_udev *udev)
290{ 290{
291 kref_put(&udev->kref, u132_udev_delete); 291 kref_put(&udev->kref, u132_udev_delete);
292} 292}
293 293
294static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev) 294static inline void u132_udev_get_kref(struct u132 *u132, struct u132_udev *udev)
295{ 295{
296 kref_get(&udev->kref); 296 kref_get(&udev->kref);
297} 297}
298 298
299static inline void u132_udev_init_kref(struct u132 *u132, 299static inline void u132_udev_init_kref(struct u132 *u132,
300 struct u132_udev *udev) 300 struct u132_udev *udev)
301{ 301{
302 kref_init(&udev->kref); 302 kref_init(&udev->kref);
303} 303}
304 304
305static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring) 305static inline void u132_ring_put_kref(struct u132 *u132, struct u132_ring *ring)
306{ 306{
307 kref_put(&u132->kref, u132_hcd_delete); 307 kref_put(&u132->kref, u132_hcd_delete);
308} 308}
309 309
310static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring, 310static void u132_ring_requeue_work(struct u132 *u132, struct u132_ring *ring,
311 unsigned int delta) 311 unsigned int delta)
312{ 312{
313 if (delta > 0) { 313 if (delta > 0) {
314 if (queue_delayed_work(workqueue, &ring->scheduler, delta)) 314 if (queue_delayed_work(workqueue, &ring->scheduler, delta))
315 return; 315 return;
316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0)) 316 } else if (queue_delayed_work(workqueue, &ring->scheduler, 0))
317 return; 317 return;
318 kref_put(&u132->kref, u132_hcd_delete); 318 kref_put(&u132->kref, u132_hcd_delete);
319 return; 319 return;
320} 320}
321 321
322static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring, 322static void u132_ring_queue_work(struct u132 *u132, struct u132_ring *ring,
323 unsigned int delta) 323 unsigned int delta)
324{ 324{
325 kref_get(&u132->kref); 325 kref_get(&u132->kref);
326 u132_ring_requeue_work(u132, ring, delta); 326 u132_ring_requeue_work(u132, ring, delta);
327 return; 327 return;
328} 328}
329 329
330static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring) 330static void u132_ring_cancel_work(struct u132 *u132, struct u132_ring *ring)
331{ 331{
332 if (cancel_delayed_work(&ring->scheduler)) { 332 if (cancel_delayed_work(&ring->scheduler))
333 kref_put(&u132->kref, u132_hcd_delete); 333 kref_put(&u132->kref, u132_hcd_delete);
334 }
335} 334}
336 335
337static void u132_endp_delete(struct kref *kref) 336static void u132_endp_delete(struct kref *kref)
338{ 337{
339 struct u132_endp *endp = kref_to_u132_endp(kref); 338 struct u132_endp *endp = kref_to_u132_endp(kref);
340 struct u132 *u132 = endp->u132; 339 struct u132 *u132 = endp->u132;
341 u8 usb_addr = endp->usb_addr; 340 u8 usb_addr = endp->usb_addr;
342 u8 usb_endp = endp->usb_endp; 341 u8 usb_endp = endp->usb_endp;
343 u8 address = u132->addr[usb_addr].address; 342 u8 address = u132->addr[usb_addr].address;
344 struct u132_udev *udev = &u132->udev[address]; 343 struct u132_udev *udev = &u132->udev[address];
345 u8 endp_number = endp->endp_number; 344 u8 endp_number = endp->endp_number;
346 struct usb_host_endpoint *hep = endp->hep; 345 struct usb_host_endpoint *hep = endp->hep;
347 struct u132_ring *ring = endp->ring; 346 struct u132_ring *ring = endp->ring;
348 struct list_head *head = &endp->endp_ring; 347 struct list_head *head = &endp->endp_ring;
349 ring->length -= 1; 348 ring->length -= 1;
350 if (endp == ring->curr_endp) { 349 if (endp == ring->curr_endp) {
351 if (list_empty(head)) { 350 if (list_empty(head)) {
352 ring->curr_endp = NULL; 351 ring->curr_endp = NULL;
353 list_del(head); 352 list_del(head);
354 } else { 353 } else {
355 struct u132_endp *next_endp = list_entry(head->next, 354 struct u132_endp *next_endp = list_entry(head->next,
356 struct u132_endp, endp_ring); 355 struct u132_endp, endp_ring);
357 ring->curr_endp = next_endp; 356 ring->curr_endp = next_endp;
358 list_del(head); 357 list_del(head);
359 }} else 358 }
360 list_del(head); 359 } else
361 if (endp->input) { 360 list_del(head);
362 udev->endp_number_in[usb_endp] = 0; 361 if (endp->input) {
363 u132_udev_put_kref(u132, udev); 362 udev->endp_number_in[usb_endp] = 0;
364 } 363 u132_udev_put_kref(u132, udev);
365 if (endp->output) { 364 }
366 udev->endp_number_out[usb_endp] = 0; 365 if (endp->output) {
367 u132_udev_put_kref(u132, udev); 366 udev->endp_number_out[usb_endp] = 0;
368 } 367 u132_udev_put_kref(u132, udev);
369 u132->endp[endp_number - 1] = NULL; 368 }
370 hep->hcpriv = NULL; 369 u132->endp[endp_number - 1] = NULL;
371 kfree(endp); 370 hep->hcpriv = NULL;
372 u132_u132_put_kref(u132); 371 kfree(endp);
372 u132_u132_put_kref(u132);
373} 373}
374 374
375static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp) 375static inline void u132_endp_put_kref(struct u132 *u132, struct u132_endp *endp)
376{ 376{
377 kref_put(&endp->kref, u132_endp_delete); 377 kref_put(&endp->kref, u132_endp_delete);
378} 378}
379 379
380static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp) 380static inline void u132_endp_get_kref(struct u132 *u132, struct u132_endp *endp)
381{ 381{
382 kref_get(&endp->kref); 382 kref_get(&endp->kref);
383} 383}
384 384
385static inline void u132_endp_init_kref(struct u132 *u132, 385static inline void u132_endp_init_kref(struct u132 *u132,
386 struct u132_endp *endp) 386 struct u132_endp *endp)
387{ 387{
388 kref_init(&endp->kref); 388 kref_init(&endp->kref);
389 kref_get(&u132->kref); 389 kref_get(&u132->kref);
390} 390}
391 391
392static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp, 392static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
393 unsigned int delta) 393 unsigned int delta)
394{ 394{
395 if (queue_delayed_work(workqueue, &endp->scheduler, delta)) 395 if (queue_delayed_work(workqueue, &endp->scheduler, delta))
396 kref_get(&endp->kref); 396 kref_get(&endp->kref);
@@ -398,13 +398,13 @@ static void u132_endp_queue_work(struct u132 *u132, struct u132_endp *endp,
398 398
399static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp) 399static void u132_endp_cancel_work(struct u132 *u132, struct u132_endp *endp)
400{ 400{
401 if (cancel_delayed_work(&endp->scheduler)) 401 if (cancel_delayed_work(&endp->scheduler))
402 kref_put(&endp->kref, u132_endp_delete); 402 kref_put(&endp->kref, u132_endp_delete);
403} 403}
404 404
405static inline void u132_monitor_put_kref(struct u132 *u132) 405static inline void u132_monitor_put_kref(struct u132 *u132)
406{ 406{
407 kref_put(&u132->kref, u132_hcd_delete); 407 kref_put(&u132->kref, u132_hcd_delete);
408} 408}
409 409
410static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta) 410static void u132_monitor_queue_work(struct u132 *u132, unsigned int delta)
@@ -421,200 +421,201 @@ static void u132_monitor_requeue_work(struct u132 *u132, unsigned int delta)
421 421
422static void u132_monitor_cancel_work(struct u132 *u132) 422static void u132_monitor_cancel_work(struct u132 *u132)
423{ 423{
424 if (cancel_delayed_work(&u132->monitor)) 424 if (cancel_delayed_work(&u132->monitor))
425 kref_put(&u132->kref, u132_hcd_delete); 425 kref_put(&u132->kref, u132_hcd_delete);
426} 426}
427 427
428static int read_roothub_info(struct u132 *u132) 428static int read_roothub_info(struct u132 *u132)
429{ 429{
430 u32 revision; 430 u32 revision;
431 int retval; 431 int retval;
432 retval = u132_read_pcimem(u132, revision, &revision); 432 retval = u132_read_pcimem(u132, revision, &revision);
433 if (retval) { 433 if (retval) {
434 dev_err(&u132->platform_dev->dev, "error %d accessing device co" 434 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
435 "ntrol\n", retval); 435 "ntrol\n", retval);
436 return retval; 436 return retval;
437 } else if ((revision & 0xFF) == 0x10) { 437 } else if ((revision & 0xFF) == 0x10) {
438 } else if ((revision & 0xFF) == 0x11) { 438 } else if ((revision & 0xFF) == 0x11) {
439 } else { 439 } else {
440 dev_err(&u132->platform_dev->dev, "device revision is not valid" 440 dev_err(&u132->platform_dev->dev, "device revision is not valid"
441 " %08X\n", revision); 441 " %08X\n", revision);
442 return -ENODEV; 442 return -ENODEV;
443 } 443 }
444 retval = u132_read_pcimem(u132, control, &u132->hc_control); 444 retval = u132_read_pcimem(u132, control, &u132->hc_control);
445 if (retval) { 445 if (retval) {
446 dev_err(&u132->platform_dev->dev, "error %d accessing device co" 446 dev_err(&u132->platform_dev->dev, "error %d accessing device co"
447 "ntrol\n", retval); 447 "ntrol\n", retval);
448 return retval; 448 return retval;
449 } 449 }
450 retval = u132_read_pcimem(u132, roothub.status, 450 retval = u132_read_pcimem(u132, roothub.status,
451 &u132->hc_roothub_status); 451 &u132->hc_roothub_status);
452 if (retval) { 452 if (retval) {
453 dev_err(&u132->platform_dev->dev, "error %d accessing device re" 453 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
454 "g roothub.status\n", retval); 454 "g roothub.status\n", retval);
455 return retval; 455 return retval;
456 } 456 }
457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a); 457 retval = u132_read_pcimem(u132, roothub.a, &u132->hc_roothub_a);
458 if (retval) { 458 if (retval) {
459 dev_err(&u132->platform_dev->dev, "error %d accessing device re" 459 dev_err(&u132->platform_dev->dev, "error %d accessing device re"
460 "g roothub.a\n", retval); 460 "g roothub.a\n", retval);
461 return retval; 461 return retval;
462 } 462 }
463 { 463 {
464 int I = u132->num_ports; 464 int I = u132->num_ports;
465 int i = 0; 465 int i = 0;
466 while (I-- > 0) { 466 while (I-- > 0) {
467 retval = u132_read_pcimem(u132, roothub.portstatus[i], 467 retval = u132_read_pcimem(u132, roothub.portstatus[i],
468 &u132->hc_roothub_portstatus[i]); 468 &u132->hc_roothub_portstatus[i]);
469 if (retval) { 469 if (retval) {
470 dev_err(&u132->platform_dev->dev, "error %d acc" 470 dev_err(&u132->platform_dev->dev, "error %d acc"
471 "essing device roothub.portstatus[%d]\n" 471 "essing device roothub.portstatus[%d]\n"
472 , retval, i); 472 , retval, i);
473 return retval; 473 return retval;
474 } else 474 } else
475 i += 1; 475 i += 1;
476 } 476 }
477 } 477 }
478 return 0; 478 return 0;
479} 479}
480 480
481static void u132_hcd_monitor_work(struct work_struct *work) 481static void u132_hcd_monitor_work(struct work_struct *work)
482{ 482{
483 struct u132 *u132 = container_of(work, struct u132, monitor.work); 483 struct u132 *u132 = container_of(work, struct u132, monitor.work);
484 if (u132->going > 1) { 484 if (u132->going > 1) {
485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 485 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
486 , u132->going); 486 , u132->going);
487 u132_monitor_put_kref(u132); 487 u132_monitor_put_kref(u132);
488 return; 488 return;
489 } else if (u132->going > 0) { 489 } else if (u132->going > 0) {
490 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 490 dev_err(&u132->platform_dev->dev, "device is being removed\n");
491 u132_monitor_put_kref(u132); 491 u132_monitor_put_kref(u132);
492 return; 492 return;
493 } else { 493 } else {
494 int retval; 494 int retval;
495 mutex_lock(&u132->sw_lock); 495 mutex_lock(&u132->sw_lock);
496 retval = read_roothub_info(u132); 496 retval = read_roothub_info(u132);
497 if (retval) { 497 if (retval) {
498 struct usb_hcd *hcd = u132_to_hcd(u132); 498 struct usb_hcd *hcd = u132_to_hcd(u132);
499 u132_disable(u132); 499 u132_disable(u132);
500 u132->going = 1; 500 u132->going = 1;
501 mutex_unlock(&u132->sw_lock); 501 mutex_unlock(&u132->sw_lock);
502 usb_hc_died(hcd); 502 usb_hc_died(hcd);
503 ftdi_elan_gone_away(u132->platform_dev); 503 ftdi_elan_gone_away(u132->platform_dev);
504 u132_monitor_put_kref(u132); 504 u132_monitor_put_kref(u132);
505 return; 505 return;
506 } else { 506 } else {
507 u132_monitor_requeue_work(u132, 500); 507 u132_monitor_requeue_work(u132, 500);
508 mutex_unlock(&u132->sw_lock); 508 mutex_unlock(&u132->sw_lock);
509 return; 509 return;
510 } 510 }
511 } 511 }
512} 512}
513 513
514static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp, 514static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
515 struct urb *urb, int status) 515 struct urb *urb, int status)
516{ 516{
517 struct u132_ring *ring; 517 struct u132_ring *ring;
518 unsigned long irqs; 518 unsigned long irqs;
519 struct usb_hcd *hcd = u132_to_hcd(u132); 519 struct usb_hcd *hcd = u132_to_hcd(u132);
520 urb->error_count = 0; 520 urb->error_count = 0;
521 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 521 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
522 usb_hcd_unlink_urb_from_ep(hcd, urb); 522 usb_hcd_unlink_urb_from_ep(hcd, urb);
523 endp->queue_next += 1; 523 endp->queue_next += 1;
524 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 524 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
525 endp->active = 0; 525 endp->active = 0;
526 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 526 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
527 } else { 527 } else {
528 struct list_head *next = endp->urb_more.next; 528 struct list_head *next = endp->urb_more.next;
529 struct u132_urbq *urbq = list_entry(next, struct u132_urbq, 529 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
530 urb_more); 530 urb_more);
531 list_del(next); 531 list_del(next);
532 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 532 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
533 urbq->urb; 533 urbq->urb;
534 endp->active = 0; 534 endp->active = 0;
535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 535 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
536 kfree(urbq); 536 kfree(urbq);
537 } down(&u132->scheduler_lock); 537 }
538 ring = endp->ring; 538 down(&u132->scheduler_lock);
539 ring->in_use = 0; 539 ring = endp->ring;
540 u132_ring_cancel_work(u132, ring); 540 ring->in_use = 0;
541 u132_ring_queue_work(u132, ring, 0); 541 u132_ring_cancel_work(u132, ring);
542 up(&u132->scheduler_lock); 542 u132_ring_queue_work(u132, ring, 0);
543 u132_endp_put_kref(u132, endp); 543 up(&u132->scheduler_lock);
544 u132_endp_put_kref(u132, endp);
544 usb_hcd_giveback_urb(hcd, urb, status); 545 usb_hcd_giveback_urb(hcd, urb, status);
545 return; 546 return;
546} 547}
547 548
548static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp, 549static void u132_hcd_forget_urb(struct u132 *u132, struct u132_endp *endp,
549 struct urb *urb, int status) 550 struct urb *urb, int status)
550{ 551{
551 u132_endp_put_kref(u132, endp); 552 u132_endp_put_kref(u132, endp);
552} 553}
553 554
554static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp, 555static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
555 struct urb *urb, int status) 556 struct urb *urb, int status)
556{ 557{
557 unsigned long irqs; 558 unsigned long irqs;
558 struct usb_hcd *hcd = u132_to_hcd(u132); 559 struct usb_hcd *hcd = u132_to_hcd(u132);
559 urb->error_count = 0; 560 urb->error_count = 0;
560 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 561 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
561 usb_hcd_unlink_urb_from_ep(hcd, urb); 562 usb_hcd_unlink_urb_from_ep(hcd, urb);
562 endp->queue_next += 1; 563 endp->queue_next += 1;
563 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 564 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
564 endp->active = 0; 565 endp->active = 0;
565 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 566 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
566 } else { 567 } else {
567 struct list_head *next = endp->urb_more.next; 568 struct list_head *next = endp->urb_more.next;
568 struct u132_urbq *urbq = list_entry(next, struct u132_urbq, 569 struct u132_urbq *urbq = list_entry(next, struct u132_urbq,
569 urb_more); 570 urb_more);
570 list_del(next); 571 list_del(next);
571 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 572 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
572 urbq->urb; 573 urbq->urb;
573 endp->active = 0; 574 endp->active = 0;
574 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 575 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
575 kfree(urbq); 576 kfree(urbq);
576 } usb_hcd_giveback_urb(hcd, urb, status); 577 } usb_hcd_giveback_urb(hcd, urb, status);
577 return; 578 return;
578} 579}
579 580
580static inline int edset_input(struct u132 *u132, struct u132_ring *ring, 581static inline int edset_input(struct u132 *u132, struct u132_ring *ring,
581 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 582 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
582 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 583 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
583 int toggle_bits, int error_count, int condition_code, int repeat_number, 584 int toggle_bits, int error_count, int condition_code, int repeat_number,
584 int halted, int skipped, int actual, int non_null)) 585 int halted, int skipped, int actual, int non_null))
585{ 586{
586 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp, 587 return usb_ftdi_elan_edset_input(u132->platform_dev, ring->number, endp,
587 urb, address, endp->usb_endp, toggle_bits, callback); 588 urb, address, endp->usb_endp, toggle_bits, callback);
588} 589}
589 590
590static inline int edset_setup(struct u132 *u132, struct u132_ring *ring, 591static inline int edset_setup(struct u132 *u132, struct u132_ring *ring,
591 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 592 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
592 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 593 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
593 int toggle_bits, int error_count, int condition_code, int repeat_number, 594 int toggle_bits, int error_count, int condition_code, int repeat_number,
594 int halted, int skipped, int actual, int non_null)) 595 int halted, int skipped, int actual, int non_null))
595{ 596{
596 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp, 597 return usb_ftdi_elan_edset_setup(u132->platform_dev, ring->number, endp,
597 urb, address, endp->usb_endp, toggle_bits, callback); 598 urb, address, endp->usb_endp, toggle_bits, callback);
598} 599}
599 600
600static inline int edset_single(struct u132 *u132, struct u132_ring *ring, 601static inline int edset_single(struct u132 *u132, struct u132_ring *ring,
601 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 602 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
602 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 603 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
603 int toggle_bits, int error_count, int condition_code, int repeat_number, 604 int toggle_bits, int error_count, int condition_code, int repeat_number,
604 int halted, int skipped, int actual, int non_null)) 605 int halted, int skipped, int actual, int non_null))
605{ 606{
606 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number, 607 return usb_ftdi_elan_edset_single(u132->platform_dev, ring->number,
607 endp, urb, address, endp->usb_endp, toggle_bits, callback); 608 endp, urb, address, endp->usb_endp, toggle_bits, callback);
608} 609}
609 610
610static inline int edset_output(struct u132 *u132, struct u132_ring *ring, 611static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
611 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits, 612 struct u132_endp *endp, struct urb *urb, u8 address, u8 toggle_bits,
612 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len, 613 void (*callback) (void *endp, struct urb *urb, u8 *buf, int len,
613 int toggle_bits, int error_count, int condition_code, int repeat_number, 614 int toggle_bits, int error_count, int condition_code, int repeat_number,
614 int halted, int skipped, int actual, int non_null)) 615 int halted, int skipped, int actual, int non_null))
615{ 616{
616 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number, 617 return usb_ftdi_elan_edset_output(u132->platform_dev, ring->number,
617 endp, urb, address, endp->usb_endp, toggle_bits, callback); 618 endp, urb, address, endp->usb_endp, toggle_bits, callback);
618} 619}
619 620
620 621
@@ -623,683 +624,678 @@ static inline int edset_output(struct u132 *u132, struct u132_ring *ring,
623* 624*
624*/ 625*/
625static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf, 626static void u132_hcd_interrupt_recv(void *data, struct urb *urb, u8 *buf,
626 int len, int toggle_bits, int error_count, int condition_code, 627 int len, int toggle_bits, int error_count, int condition_code,
627 int repeat_number, int halted, int skipped, int actual, int non_null) 628 int repeat_number, int halted, int skipped, int actual, int non_null)
628{ 629{
629 struct u132_endp *endp = data; 630 struct u132_endp *endp = data;
630 struct u132 *u132 = endp->u132; 631 struct u132 *u132 = endp->u132;
631 u8 address = u132->addr[endp->usb_addr].address; 632 u8 address = u132->addr[endp->usb_addr].address;
632 struct u132_udev *udev = &u132->udev[address]; 633 struct u132_udev *udev = &u132->udev[address];
633 down(&u132->scheduler_lock); 634 down(&u132->scheduler_lock);
634 if (u132->going > 1) { 635 if (u132->going > 1) {
635 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 636 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
636 , u132->going); 637 , u132->going);
637 up(&u132->scheduler_lock); 638 up(&u132->scheduler_lock);
638 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 639 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
639 return; 640 return;
640 } else if (endp->dequeueing) { 641 } else if (endp->dequeueing) {
641 endp->dequeueing = 0; 642 endp->dequeueing = 0;
642 up(&u132->scheduler_lock); 643 up(&u132->scheduler_lock);
643 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 644 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
644 return; 645 return;
645 } else if (u132->going > 0) { 646 } else if (u132->going > 0) {
646 dev_err(&u132->platform_dev->dev, "device is being removed " 647 dev_err(&u132->platform_dev->dev, "device is being removed "
647 "urb=%p\n", urb); 648 "urb=%p\n", urb);
648 up(&u132->scheduler_lock); 649 up(&u132->scheduler_lock);
649 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 650 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
650 return; 651 return;
651 } else if (!urb->unlinked) { 652 } else if (!urb->unlinked) {
652 struct u132_ring *ring = endp->ring; 653 struct u132_ring *ring = endp->ring;
653 u8 *u = urb->transfer_buffer + urb->actual_length; 654 u8 *u = urb->transfer_buffer + urb->actual_length;
654 u8 *b = buf; 655 u8 *b = buf;
655 int L = len; 656 int L = len;
656 while (L-- > 0) { 657
657 *u++ = *b++; 658 while (L-- > 0)
658 } 659 *u++ = *b++;
659 urb->actual_length += len; 660
660 if ((condition_code == TD_CC_NOERROR) && 661 urb->actual_length += len;
661 (urb->transfer_buffer_length > urb->actual_length)) { 662 if ((condition_code == TD_CC_NOERROR) &&
662 endp->toggle_bits = toggle_bits; 663 (urb->transfer_buffer_length > urb->actual_length)) {
663 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 664 endp->toggle_bits = toggle_bits;
664 1 & toggle_bits); 665 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
665 if (urb->actual_length > 0) { 666 1 & toggle_bits);
666 int retval; 667 if (urb->actual_length > 0) {
667 up(&u132->scheduler_lock); 668 int retval;
668 retval = edset_single(u132, ring, endp, urb, 669 up(&u132->scheduler_lock);
669 address, endp->toggle_bits, 670 retval = edset_single(u132, ring, endp, urb,
670 u132_hcd_interrupt_recv); 671 address, endp->toggle_bits,
671 if (retval == 0) { 672 u132_hcd_interrupt_recv);
672 } else 673 if (retval != 0)
673 u132_hcd_giveback_urb(u132, endp, urb, 674 u132_hcd_giveback_urb(u132, endp, urb,
674 retval); 675 retval);
675 } else { 676 } else {
676 ring->in_use = 0; 677 ring->in_use = 0;
677 endp->active = 0; 678 endp->active = 0;
678 endp->jiffies = jiffies + 679 endp->jiffies = jiffies +
679 msecs_to_jiffies(urb->interval); 680 msecs_to_jiffies(urb->interval);
680 u132_ring_cancel_work(u132, ring); 681 u132_ring_cancel_work(u132, ring);
681 u132_ring_queue_work(u132, ring, 0); 682 u132_ring_queue_work(u132, ring, 0);
682 up(&u132->scheduler_lock); 683 up(&u132->scheduler_lock);
683 u132_endp_put_kref(u132, endp); 684 u132_endp_put_kref(u132, endp);
684 } 685 }
685 return; 686 return;
686 } else if ((condition_code == TD_DATAUNDERRUN) && 687 } else if ((condition_code == TD_DATAUNDERRUN) &&
687 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { 688 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
688 endp->toggle_bits = toggle_bits; 689 endp->toggle_bits = toggle_bits;
689 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 690 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
690 1 & toggle_bits); 691 1 & toggle_bits);
691 up(&u132->scheduler_lock); 692 up(&u132->scheduler_lock);
692 u132_hcd_giveback_urb(u132, endp, urb, 0); 693 u132_hcd_giveback_urb(u132, endp, urb, 0);
693 return; 694 return;
694 } else { 695 } else {
695 if (condition_code == TD_CC_NOERROR) { 696 if (condition_code == TD_CC_NOERROR) {
696 endp->toggle_bits = toggle_bits; 697 endp->toggle_bits = toggle_bits;
697 usb_settoggle(udev->usb_device, endp->usb_endp, 698 usb_settoggle(udev->usb_device, endp->usb_endp,
698 0, 1 & toggle_bits); 699 0, 1 & toggle_bits);
699 } else if (condition_code == TD_CC_STALL) { 700 } else if (condition_code == TD_CC_STALL) {
700 endp->toggle_bits = 0x2; 701 endp->toggle_bits = 0x2;
701 usb_settoggle(udev->usb_device, endp->usb_endp, 702 usb_settoggle(udev->usb_device, endp->usb_endp,
702 0, 0); 703 0, 0);
703 } else { 704 } else {
704 endp->toggle_bits = 0x2; 705 endp->toggle_bits = 0x2;
705 usb_settoggle(udev->usb_device, endp->usb_endp, 706 usb_settoggle(udev->usb_device, endp->usb_endp,
706 0, 0); 707 0, 0);
707 dev_err(&u132->platform_dev->dev, "urb=%p givin" 708 dev_err(&u132->platform_dev->dev, "urb=%p givin"
708 "g back INTERRUPT %s\n", urb, 709 "g back INTERRUPT %s\n", urb,
709 cc_to_text[condition_code]); 710 cc_to_text[condition_code]);
710 } 711 }
711 up(&u132->scheduler_lock); 712 up(&u132->scheduler_lock);
712 u132_hcd_giveback_urb(u132, endp, urb, 713 u132_hcd_giveback_urb(u132, endp, urb,
713 cc_to_error[condition_code]); 714 cc_to_error[condition_code]);
714 return; 715 return;
715 } 716 }
716 } else { 717 } else {
717 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 718 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
718 "unlinked=%d\n", urb, urb->unlinked); 719 "unlinked=%d\n", urb, urb->unlinked);
719 up(&u132->scheduler_lock); 720 up(&u132->scheduler_lock);
720 u132_hcd_giveback_urb(u132, endp, urb, 0); 721 u132_hcd_giveback_urb(u132, endp, urb, 0);
721 return; 722 return;
722 } 723 }
723} 724}
724 725
725static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf, 726static void u132_hcd_bulk_output_sent(void *data, struct urb *urb, u8 *buf,
726 int len, int toggle_bits, int error_count, int condition_code, 727 int len, int toggle_bits, int error_count, int condition_code,
727 int repeat_number, int halted, int skipped, int actual, int non_null) 728 int repeat_number, int halted, int skipped, int actual, int non_null)
728{ 729{
729 struct u132_endp *endp = data; 730 struct u132_endp *endp = data;
730 struct u132 *u132 = endp->u132; 731 struct u132 *u132 = endp->u132;
731 u8 address = u132->addr[endp->usb_addr].address; 732 u8 address = u132->addr[endp->usb_addr].address;
732 down(&u132->scheduler_lock); 733 down(&u132->scheduler_lock);
733 if (u132->going > 1) { 734 if (u132->going > 1) {
734 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 735 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
735 , u132->going); 736 , u132->going);
736 up(&u132->scheduler_lock); 737 up(&u132->scheduler_lock);
737 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 738 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
738 return; 739 return;
739 } else if (endp->dequeueing) { 740 } else if (endp->dequeueing) {
740 endp->dequeueing = 0; 741 endp->dequeueing = 0;
741 up(&u132->scheduler_lock); 742 up(&u132->scheduler_lock);
742 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 743 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
743 return; 744 return;
744 } else if (u132->going > 0) { 745 } else if (u132->going > 0) {
745 dev_err(&u132->platform_dev->dev, "device is being removed " 746 dev_err(&u132->platform_dev->dev, "device is being removed "
746 "urb=%p\n", urb); 747 "urb=%p\n", urb);
747 up(&u132->scheduler_lock); 748 up(&u132->scheduler_lock);
748 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 749 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
749 return; 750 return;
750 } else if (!urb->unlinked) { 751 } else if (!urb->unlinked) {
751 struct u132_ring *ring = endp->ring; 752 struct u132_ring *ring = endp->ring;
752 urb->actual_length += len; 753 urb->actual_length += len;
753 endp->toggle_bits = toggle_bits; 754 endp->toggle_bits = toggle_bits;
754 if (urb->transfer_buffer_length > urb->actual_length) { 755 if (urb->transfer_buffer_length > urb->actual_length) {
755 int retval; 756 int retval;
756 up(&u132->scheduler_lock); 757 up(&u132->scheduler_lock);
757 retval = edset_output(u132, ring, endp, urb, address, 758 retval = edset_output(u132, ring, endp, urb, address,
758 endp->toggle_bits, u132_hcd_bulk_output_sent); 759 endp->toggle_bits, u132_hcd_bulk_output_sent);
759 if (retval == 0) { 760 if (retval != 0)
760 } else 761 u132_hcd_giveback_urb(u132, endp, urb, retval);
761 u132_hcd_giveback_urb(u132, endp, urb, retval); 762 return;
762 return; 763 } else {
763 } else { 764 up(&u132->scheduler_lock);
764 up(&u132->scheduler_lock); 765 u132_hcd_giveback_urb(u132, endp, urb, 0);
765 u132_hcd_giveback_urb(u132, endp, urb, 0); 766 return;
766 return; 767 }
767 } 768 } else {
768 } else {
769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 769 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
770 "unlinked=%d\n", urb, urb->unlinked); 770 "unlinked=%d\n", urb, urb->unlinked);
771 up(&u132->scheduler_lock); 771 up(&u132->scheduler_lock);
772 u132_hcd_giveback_urb(u132, endp, urb, 0); 772 u132_hcd_giveback_urb(u132, endp, urb, 0);
773 return; 773 return;
774 } 774 }
775} 775}
776 776
777static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf, 777static void u132_hcd_bulk_input_recv(void *data, struct urb *urb, u8 *buf,
778 int len, int toggle_bits, int error_count, int condition_code, 778 int len, int toggle_bits, int error_count, int condition_code,
779 int repeat_number, int halted, int skipped, int actual, int non_null) 779 int repeat_number, int halted, int skipped, int actual, int non_null)
780{ 780{
781 struct u132_endp *endp = data; 781 struct u132_endp *endp = data;
782 struct u132 *u132 = endp->u132; 782 struct u132 *u132 = endp->u132;
783 u8 address = u132->addr[endp->usb_addr].address; 783 u8 address = u132->addr[endp->usb_addr].address;
784 struct u132_udev *udev = &u132->udev[address]; 784 struct u132_udev *udev = &u132->udev[address];
785 down(&u132->scheduler_lock); 785 down(&u132->scheduler_lock);
786 if (u132->going > 1) { 786 if (u132->going > 1) {
787 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 787 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
788 , u132->going); 788 , u132->going);
789 up(&u132->scheduler_lock); 789 up(&u132->scheduler_lock);
790 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 790 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
791 return; 791 return;
792 } else if (endp->dequeueing) { 792 } else if (endp->dequeueing) {
793 endp->dequeueing = 0; 793 endp->dequeueing = 0;
794 up(&u132->scheduler_lock); 794 up(&u132->scheduler_lock);
795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 795 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
796 return; 796 return;
797 } else if (u132->going > 0) { 797 } else if (u132->going > 0) {
798 dev_err(&u132->platform_dev->dev, "device is being removed " 798 dev_err(&u132->platform_dev->dev, "device is being removed "
799 "urb=%p\n", urb); 799 "urb=%p\n", urb);
800 up(&u132->scheduler_lock); 800 up(&u132->scheduler_lock);
801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 801 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
802 return; 802 return;
803 } else if (!urb->unlinked) { 803 } else if (!urb->unlinked) {
804 struct u132_ring *ring = endp->ring; 804 struct u132_ring *ring = endp->ring;
805 u8 *u = urb->transfer_buffer + urb->actual_length; 805 u8 *u = urb->transfer_buffer + urb->actual_length;
806 u8 *b = buf; 806 u8 *b = buf;
807 int L = len; 807 int L = len;
808 while (L-- > 0) { 808
809 *u++ = *b++; 809 while (L-- > 0)
810 } 810 *u++ = *b++;
811 urb->actual_length += len; 811
812 if ((condition_code == TD_CC_NOERROR) && 812 urb->actual_length += len;
813 (urb->transfer_buffer_length > urb->actual_length)) { 813 if ((condition_code == TD_CC_NOERROR) &&
814 int retval; 814 (urb->transfer_buffer_length > urb->actual_length)) {
815 endp->toggle_bits = toggle_bits; 815 int retval;
816 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 816 endp->toggle_bits = toggle_bits;
817 1 & toggle_bits); 817 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
818 up(&u132->scheduler_lock); 818 1 & toggle_bits);
819 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 819 up(&u132->scheduler_lock);
820 ring->number, endp, urb, address, 820 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
821 endp->usb_endp, endp->toggle_bits, 821 ring->number, endp, urb, address,
822 u132_hcd_bulk_input_recv); 822 endp->usb_endp, endp->toggle_bits,
823 if (retval == 0) { 823 u132_hcd_bulk_input_recv);
824 } else 824 if (retval != 0)
825 u132_hcd_giveback_urb(u132, endp, urb, retval); 825 u132_hcd_giveback_urb(u132, endp, urb, retval);
826 return; 826 return;
827 } else if (condition_code == TD_CC_NOERROR) { 827 } else if (condition_code == TD_CC_NOERROR) {
828 endp->toggle_bits = toggle_bits; 828 endp->toggle_bits = toggle_bits;
829 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 829 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
830 1 & toggle_bits); 830 1 & toggle_bits);
831 up(&u132->scheduler_lock); 831 up(&u132->scheduler_lock);
832 u132_hcd_giveback_urb(u132, endp, urb, 832 u132_hcd_giveback_urb(u132, endp, urb,
833 cc_to_error[condition_code]); 833 cc_to_error[condition_code]);
834 return; 834 return;
835 } else if ((condition_code == TD_DATAUNDERRUN) && 835 } else if ((condition_code == TD_DATAUNDERRUN) &&
836 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) { 836 ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)) {
837 endp->toggle_bits = toggle_bits; 837 endp->toggle_bits = toggle_bits;
838 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 838 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
839 1 & toggle_bits); 839 1 & toggle_bits);
840 up(&u132->scheduler_lock); 840 up(&u132->scheduler_lock);
841 u132_hcd_giveback_urb(u132, endp, urb, 0); 841 u132_hcd_giveback_urb(u132, endp, urb, 0);
842 return; 842 return;
843 } else if (condition_code == TD_DATAUNDERRUN) { 843 } else if (condition_code == TD_DATAUNDERRUN) {
844 endp->toggle_bits = toggle_bits; 844 endp->toggle_bits = toggle_bits;
845 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 845 usb_settoggle(udev->usb_device, endp->usb_endp, 0,
846 1 & toggle_bits); 846 1 & toggle_bits);
847 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK" 847 dev_warn(&u132->platform_dev->dev, "urb=%p(SHORT NOT OK"
848 ") giving back BULK IN %s\n", urb, 848 ") giving back BULK IN %s\n", urb,
849 cc_to_text[condition_code]); 849 cc_to_text[condition_code]);
850 up(&u132->scheduler_lock); 850 up(&u132->scheduler_lock);
851 u132_hcd_giveback_urb(u132, endp, urb, 0); 851 u132_hcd_giveback_urb(u132, endp, urb, 0);
852 return; 852 return;
853 } else if (condition_code == TD_CC_STALL) { 853 } else if (condition_code == TD_CC_STALL) {
854 endp->toggle_bits = 0x2; 854 endp->toggle_bits = 0x2;
855 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); 855 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
856 up(&u132->scheduler_lock); 856 up(&u132->scheduler_lock);
857 u132_hcd_giveback_urb(u132, endp, urb, 857 u132_hcd_giveback_urb(u132, endp, urb,
858 cc_to_error[condition_code]); 858 cc_to_error[condition_code]);
859 return; 859 return;
860 } else { 860 } else {
861 endp->toggle_bits = 0x2; 861 endp->toggle_bits = 0x2;
862 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0); 862 usb_settoggle(udev->usb_device, endp->usb_endp, 0, 0);
863 dev_err(&u132->platform_dev->dev, "urb=%p giving back B" 863 dev_err(&u132->platform_dev->dev, "urb=%p giving back B"
864 "ULK IN code=%d %s\n", urb, condition_code, 864 "ULK IN code=%d %s\n", urb, condition_code,
865 cc_to_text[condition_code]); 865 cc_to_text[condition_code]);
866 up(&u132->scheduler_lock); 866 up(&u132->scheduler_lock);
867 u132_hcd_giveback_urb(u132, endp, urb, 867 u132_hcd_giveback_urb(u132, endp, urb,
868 cc_to_error[condition_code]); 868 cc_to_error[condition_code]);
869 return; 869 return;
870 } 870 }
871 } else { 871 } else {
872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 872 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
873 "unlinked=%d\n", urb, urb->unlinked); 873 "unlinked=%d\n", urb, urb->unlinked);
874 up(&u132->scheduler_lock); 874 up(&u132->scheduler_lock);
875 u132_hcd_giveback_urb(u132, endp, urb, 0); 875 u132_hcd_giveback_urb(u132, endp, urb, 0);
876 return; 876 return;
877 } 877 }
878} 878}
879 879
880static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf, 880static void u132_hcd_configure_empty_sent(void *data, struct urb *urb, u8 *buf,
881 int len, int toggle_bits, int error_count, int condition_code, 881 int len, int toggle_bits, int error_count, int condition_code,
882 int repeat_number, int halted, int skipped, int actual, int non_null) 882 int repeat_number, int halted, int skipped, int actual, int non_null)
883{ 883{
884 struct u132_endp *endp = data; 884 struct u132_endp *endp = data;
885 struct u132 *u132 = endp->u132; 885 struct u132 *u132 = endp->u132;
886 down(&u132->scheduler_lock); 886 down(&u132->scheduler_lock);
887 if (u132->going > 1) { 887 if (u132->going > 1) {
888 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 888 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
889 , u132->going); 889 , u132->going);
890 up(&u132->scheduler_lock); 890 up(&u132->scheduler_lock);
891 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 891 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
892 return; 892 return;
893 } else if (endp->dequeueing) { 893 } else if (endp->dequeueing) {
894 endp->dequeueing = 0; 894 endp->dequeueing = 0;
895 up(&u132->scheduler_lock); 895 up(&u132->scheduler_lock);
896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 896 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
897 return; 897 return;
898 } else if (u132->going > 0) { 898 } else if (u132->going > 0) {
899 dev_err(&u132->platform_dev->dev, "device is being removed " 899 dev_err(&u132->platform_dev->dev, "device is being removed "
900 "urb=%p\n", urb); 900 "urb=%p\n", urb);
901 up(&u132->scheduler_lock); 901 up(&u132->scheduler_lock);
902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 902 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
903 return; 903 return;
904 } else if (!urb->unlinked) { 904 } else if (!urb->unlinked) {
905 up(&u132->scheduler_lock); 905 up(&u132->scheduler_lock);
906 u132_hcd_giveback_urb(u132, endp, urb, 0); 906 u132_hcd_giveback_urb(u132, endp, urb, 0);
907 return; 907 return;
908 } else { 908 } else {
909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 909 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
910 "unlinked=%d\n", urb, urb->unlinked); 910 "unlinked=%d\n", urb, urb->unlinked);
911 up(&u132->scheduler_lock); 911 up(&u132->scheduler_lock);
912 u132_hcd_giveback_urb(u132, endp, urb, 0); 912 u132_hcd_giveback_urb(u132, endp, urb, 0);
913 return; 913 return;
914 } 914 }
915} 915}
916 916
917static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf, 917static void u132_hcd_configure_input_recv(void *data, struct urb *urb, u8 *buf,
918 int len, int toggle_bits, int error_count, int condition_code, 918 int len, int toggle_bits, int error_count, int condition_code,
919 int repeat_number, int halted, int skipped, int actual, int non_null) 919 int repeat_number, int halted, int skipped, int actual, int non_null)
920{ 920{
921 struct u132_endp *endp = data; 921 struct u132_endp *endp = data;
922 struct u132 *u132 = endp->u132; 922 struct u132 *u132 = endp->u132;
923 u8 address = u132->addr[endp->usb_addr].address; 923 u8 address = u132->addr[endp->usb_addr].address;
924 down(&u132->scheduler_lock); 924 down(&u132->scheduler_lock);
925 if (u132->going > 1) { 925 if (u132->going > 1) {
926 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 926 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
927 , u132->going); 927 , u132->going);
928 up(&u132->scheduler_lock); 928 up(&u132->scheduler_lock);
929 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 929 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
930 return; 930 return;
931 } else if (endp->dequeueing) { 931 } else if (endp->dequeueing) {
932 endp->dequeueing = 0; 932 endp->dequeueing = 0;
933 up(&u132->scheduler_lock); 933 up(&u132->scheduler_lock);
934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 934 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
935 return; 935 return;
936 } else if (u132->going > 0) { 936 } else if (u132->going > 0) {
937 dev_err(&u132->platform_dev->dev, "device is being removed " 937 dev_err(&u132->platform_dev->dev, "device is being removed "
938 "urb=%p\n", urb); 938 "urb=%p\n", urb);
939 up(&u132->scheduler_lock); 939 up(&u132->scheduler_lock);
940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 940 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
941 return; 941 return;
942 } else if (!urb->unlinked) { 942 } else if (!urb->unlinked) {
943 struct u132_ring *ring = endp->ring; 943 struct u132_ring *ring = endp->ring;
944 u8 *u = urb->transfer_buffer; 944 u8 *u = urb->transfer_buffer;
945 u8 *b = buf; 945 u8 *b = buf;
946 int L = len; 946 int L = len;
947 while (L-- > 0) { 947
948 *u++ = *b++; 948 while (L-- > 0)
949 } 949 *u++ = *b++;
950 urb->actual_length = len; 950
951 if ((condition_code == TD_CC_NOERROR) || ((condition_code == 951 urb->actual_length = len;
952 TD_DATAUNDERRUN) && ((urb->transfer_flags & 952 if ((condition_code == TD_CC_NOERROR) || ((condition_code ==
953 URB_SHORT_NOT_OK) == 0))) { 953 TD_DATAUNDERRUN) && ((urb->transfer_flags &
954 int retval; 954 URB_SHORT_NOT_OK) == 0))) {
955 up(&u132->scheduler_lock); 955 int retval;
956 retval = usb_ftdi_elan_edset_empty(u132->platform_dev, 956 up(&u132->scheduler_lock);
957 ring->number, endp, urb, address, 957 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
958 endp->usb_endp, 0x3, 958 ring->number, endp, urb, address,
959 u132_hcd_configure_empty_sent); 959 endp->usb_endp, 0x3,
960 if (retval == 0) { 960 u132_hcd_configure_empty_sent);
961 } else 961 if (retval != 0)
962 u132_hcd_giveback_urb(u132, endp, urb, retval); 962 u132_hcd_giveback_urb(u132, endp, urb, retval);
963 return; 963 return;
964 } else if (condition_code == TD_CC_STALL) { 964 } else if (condition_code == TD_CC_STALL) {
965 up(&u132->scheduler_lock); 965 up(&u132->scheduler_lock);
966 dev_warn(&u132->platform_dev->dev, "giving back SETUP I" 966 dev_warn(&u132->platform_dev->dev, "giving back SETUP I"
967 "NPUT STALL urb %p\n", urb); 967 "NPUT STALL urb %p\n", urb);
968 u132_hcd_giveback_urb(u132, endp, urb, 968 u132_hcd_giveback_urb(u132, endp, urb,
969 cc_to_error[condition_code]); 969 cc_to_error[condition_code]);
970 return; 970 return;
971 } else { 971 } else {
972 up(&u132->scheduler_lock); 972 up(&u132->scheduler_lock);
973 dev_err(&u132->platform_dev->dev, "giving back SETUP IN" 973 dev_err(&u132->platform_dev->dev, "giving back SETUP IN"
974 "PUT %s urb %p\n", cc_to_text[condition_code], 974 "PUT %s urb %p\n", cc_to_text[condition_code],
975 urb); 975 urb);
976 u132_hcd_giveback_urb(u132, endp, urb, 976 u132_hcd_giveback_urb(u132, endp, urb,
977 cc_to_error[condition_code]); 977 cc_to_error[condition_code]);
978 return; 978 return;
979 } 979 }
980 } else { 980 } else {
981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 981 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
982 "unlinked=%d\n", urb, urb->unlinked); 982 "unlinked=%d\n", urb, urb->unlinked);
983 up(&u132->scheduler_lock); 983 up(&u132->scheduler_lock);
984 u132_hcd_giveback_urb(u132, endp, urb, 0); 984 u132_hcd_giveback_urb(u132, endp, urb, 0);
985 return; 985 return;
986 } 986 }
987} 987}
988 988
989static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf, 989static void u132_hcd_configure_empty_recv(void *data, struct urb *urb, u8 *buf,
990 int len, int toggle_bits, int error_count, int condition_code, 990 int len, int toggle_bits, int error_count, int condition_code,
991 int repeat_number, int halted, int skipped, int actual, int non_null) 991 int repeat_number, int halted, int skipped, int actual, int non_null)
992{ 992{
993 struct u132_endp *endp = data; 993 struct u132_endp *endp = data;
994 struct u132 *u132 = endp->u132; 994 struct u132 *u132 = endp->u132;
995 down(&u132->scheduler_lock); 995 down(&u132->scheduler_lock);
996 if (u132->going > 1) { 996 if (u132->going > 1) {
997 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 997 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
998 , u132->going); 998 , u132->going);
999 up(&u132->scheduler_lock); 999 up(&u132->scheduler_lock);
1000 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1000 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1001 return; 1001 return;
1002 } else if (endp->dequeueing) { 1002 } else if (endp->dequeueing) {
1003 endp->dequeueing = 0; 1003 endp->dequeueing = 0;
1004 up(&u132->scheduler_lock); 1004 up(&u132->scheduler_lock);
1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1005 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1006 return; 1006 return;
1007 } else if (u132->going > 0) { 1007 } else if (u132->going > 0) {
1008 dev_err(&u132->platform_dev->dev, "device is being removed " 1008 dev_err(&u132->platform_dev->dev, "device is being removed "
1009 "urb=%p\n", urb); 1009 "urb=%p\n", urb);
1010 up(&u132->scheduler_lock); 1010 up(&u132->scheduler_lock);
1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1011 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1012 return; 1012 return;
1013 } else if (!urb->unlinked) { 1013 } else if (!urb->unlinked) {
1014 up(&u132->scheduler_lock); 1014 up(&u132->scheduler_lock);
1015 u132_hcd_giveback_urb(u132, endp, urb, 0); 1015 u132_hcd_giveback_urb(u132, endp, urb, 0);
1016 return; 1016 return;
1017 } else { 1017 } else {
1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1018 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1019 "unlinked=%d\n", urb, urb->unlinked); 1019 "unlinked=%d\n", urb, urb->unlinked);
1020 up(&u132->scheduler_lock); 1020 up(&u132->scheduler_lock);
1021 u132_hcd_giveback_urb(u132, endp, urb, 0); 1021 u132_hcd_giveback_urb(u132, endp, urb, 0);
1022 return; 1022 return;
1023 } 1023 }
1024} 1024}
1025 1025
1026static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf, 1026static void u132_hcd_configure_setup_sent(void *data, struct urb *urb, u8 *buf,
1027 int len, int toggle_bits, int error_count, int condition_code, 1027 int len, int toggle_bits, int error_count, int condition_code,
1028 int repeat_number, int halted, int skipped, int actual, int non_null) 1028 int repeat_number, int halted, int skipped, int actual, int non_null)
1029{ 1029{
1030 struct u132_endp *endp = data; 1030 struct u132_endp *endp = data;
1031 struct u132 *u132 = endp->u132; 1031 struct u132 *u132 = endp->u132;
1032 u8 address = u132->addr[endp->usb_addr].address; 1032 u8 address = u132->addr[endp->usb_addr].address;
1033 down(&u132->scheduler_lock); 1033 down(&u132->scheduler_lock);
1034 if (u132->going > 1) { 1034 if (u132->going > 1) {
1035 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1035 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1036 , u132->going); 1036 , u132->going);
1037 up(&u132->scheduler_lock); 1037 up(&u132->scheduler_lock);
1038 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1038 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1039 return; 1039 return;
1040 } else if (endp->dequeueing) { 1040 } else if (endp->dequeueing) {
1041 endp->dequeueing = 0; 1041 endp->dequeueing = 0;
1042 up(&u132->scheduler_lock); 1042 up(&u132->scheduler_lock);
1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1043 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1044 return; 1044 return;
1045 } else if (u132->going > 0) { 1045 } else if (u132->going > 0) {
1046 dev_err(&u132->platform_dev->dev, "device is being removed " 1046 dev_err(&u132->platform_dev->dev, "device is being removed "
1047 "urb=%p\n", urb); 1047 "urb=%p\n", urb);
1048 up(&u132->scheduler_lock); 1048 up(&u132->scheduler_lock);
1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1049 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1050 return; 1050 return;
1051 } else if (!urb->unlinked) { 1051 } else if (!urb->unlinked) {
1052 if (usb_pipein(urb->pipe)) { 1052 if (usb_pipein(urb->pipe)) {
1053 int retval; 1053 int retval;
1054 struct u132_ring *ring = endp->ring; 1054 struct u132_ring *ring = endp->ring;
1055 up(&u132->scheduler_lock); 1055 up(&u132->scheduler_lock);
1056 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1056 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1057 ring->number, endp, urb, address, 1057 ring->number, endp, urb, address,
1058 endp->usb_endp, 0, 1058 endp->usb_endp, 0,
1059 u132_hcd_configure_input_recv); 1059 u132_hcd_configure_input_recv);
1060 if (retval == 0) { 1060 if (retval != 0)
1061 } else 1061 u132_hcd_giveback_urb(u132, endp, urb, retval);
1062 u132_hcd_giveback_urb(u132, endp, urb, retval); 1062 return;
1063 return; 1063 } else {
1064 } else { 1064 int retval;
1065 int retval; 1065 struct u132_ring *ring = endp->ring;
1066 struct u132_ring *ring = endp->ring; 1066 up(&u132->scheduler_lock);
1067 up(&u132->scheduler_lock); 1067 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1068 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1068 ring->number, endp, urb, address,
1069 ring->number, endp, urb, address, 1069 endp->usb_endp, 0,
1070 endp->usb_endp, 0, 1070 u132_hcd_configure_empty_recv);
1071 u132_hcd_configure_empty_recv); 1071 if (retval != 0)
1072 if (retval == 0) { 1072 u132_hcd_giveback_urb(u132, endp, urb, retval);
1073 } else 1073 return;
1074 u132_hcd_giveback_urb(u132, endp, urb, retval); 1074 }
1075 return; 1075 } else {
1076 }
1077 } else {
1078 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1076 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1079 "unlinked=%d\n", urb, urb->unlinked); 1077 "unlinked=%d\n", urb, urb->unlinked);
1080 up(&u132->scheduler_lock); 1078 up(&u132->scheduler_lock);
1081 u132_hcd_giveback_urb(u132, endp, urb, 0); 1079 u132_hcd_giveback_urb(u132, endp, urb, 0);
1082 return; 1080 return;
1083 } 1081 }
1084} 1082}
1085 1083
1086static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb, 1084static void u132_hcd_enumeration_empty_recv(void *data, struct urb *urb,
1087 u8 *buf, int len, int toggle_bits, int error_count, int condition_code, 1085 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1088 int repeat_number, int halted, int skipped, int actual, int non_null) 1086 int repeat_number, int halted, int skipped, int actual, int non_null)
1089{ 1087{
1090 struct u132_endp *endp = data; 1088 struct u132_endp *endp = data;
1091 struct u132 *u132 = endp->u132; 1089 struct u132 *u132 = endp->u132;
1092 u8 address = u132->addr[endp->usb_addr].address; 1090 u8 address = u132->addr[endp->usb_addr].address;
1093 struct u132_udev *udev = &u132->udev[address]; 1091 struct u132_udev *udev = &u132->udev[address];
1094 down(&u132->scheduler_lock); 1092 down(&u132->scheduler_lock);
1095 if (u132->going > 1) { 1093 if (u132->going > 1) {
1096 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1094 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1097 , u132->going); 1095 , u132->going);
1098 up(&u132->scheduler_lock); 1096 up(&u132->scheduler_lock);
1099 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1097 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1100 return; 1098 return;
1101 } else if (endp->dequeueing) { 1099 } else if (endp->dequeueing) {
1102 endp->dequeueing = 0; 1100 endp->dequeueing = 0;
1103 up(&u132->scheduler_lock); 1101 up(&u132->scheduler_lock);
1104 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1102 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1105 return; 1103 return;
1106 } else if (u132->going > 0) { 1104 } else if (u132->going > 0) {
1107 dev_err(&u132->platform_dev->dev, "device is being removed " 1105 dev_err(&u132->platform_dev->dev, "device is being removed "
1108 "urb=%p\n", urb); 1106 "urb=%p\n", urb);
1109 up(&u132->scheduler_lock); 1107 up(&u132->scheduler_lock);
1110 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1108 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1111 return; 1109 return;
1112 } else if (!urb->unlinked) { 1110 } else if (!urb->unlinked) {
1113 u132->addr[0].address = 0; 1111 u132->addr[0].address = 0;
1114 endp->usb_addr = udev->usb_addr; 1112 endp->usb_addr = udev->usb_addr;
1115 up(&u132->scheduler_lock); 1113 up(&u132->scheduler_lock);
1116 u132_hcd_giveback_urb(u132, endp, urb, 0); 1114 u132_hcd_giveback_urb(u132, endp, urb, 0);
1117 return; 1115 return;
1118 } else { 1116 } else {
1119 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1117 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1120 "unlinked=%d\n", urb, urb->unlinked); 1118 "unlinked=%d\n", urb, urb->unlinked);
1121 up(&u132->scheduler_lock); 1119 up(&u132->scheduler_lock);
1122 u132_hcd_giveback_urb(u132, endp, urb, 0); 1120 u132_hcd_giveback_urb(u132, endp, urb, 0);
1123 return; 1121 return;
1124 } 1122 }
1125} 1123}
1126 1124
1127static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb, 1125static void u132_hcd_enumeration_address_sent(void *data, struct urb *urb,
1128 u8 *buf, int len, int toggle_bits, int error_count, int condition_code, 1126 u8 *buf, int len, int toggle_bits, int error_count, int condition_code,
1129 int repeat_number, int halted, int skipped, int actual, int non_null) 1127 int repeat_number, int halted, int skipped, int actual, int non_null)
1130{ 1128{
1131 struct u132_endp *endp = data; 1129 struct u132_endp *endp = data;
1132 struct u132 *u132 = endp->u132; 1130 struct u132 *u132 = endp->u132;
1133 down(&u132->scheduler_lock); 1131 down(&u132->scheduler_lock);
1134 if (u132->going > 1) { 1132 if (u132->going > 1) {
1135 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1133 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1136 , u132->going); 1134 , u132->going);
1137 up(&u132->scheduler_lock); 1135 up(&u132->scheduler_lock);
1138 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1136 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1139 return; 1137 return;
1140 } else if (endp->dequeueing) { 1138 } else if (endp->dequeueing) {
1141 endp->dequeueing = 0; 1139 endp->dequeueing = 0;
1142 up(&u132->scheduler_lock); 1140 up(&u132->scheduler_lock);
1143 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1141 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1144 return; 1142 return;
1145 } else if (u132->going > 0) { 1143 } else if (u132->going > 0) {
1146 dev_err(&u132->platform_dev->dev, "device is being removed " 1144 dev_err(&u132->platform_dev->dev, "device is being removed "
1147 "urb=%p\n", urb); 1145 "urb=%p\n", urb);
1148 up(&u132->scheduler_lock); 1146 up(&u132->scheduler_lock);
1149 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1147 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1150 return; 1148 return;
1151 } else if (!urb->unlinked) { 1149 } else if (!urb->unlinked) {
1152 int retval; 1150 int retval;
1153 struct u132_ring *ring = endp->ring; 1151 struct u132_ring *ring = endp->ring;
1154 up(&u132->scheduler_lock); 1152 up(&u132->scheduler_lock);
1155 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1153 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1156 ring->number, endp, urb, 0, endp->usb_endp, 0, 1154 ring->number, endp, urb, 0, endp->usb_endp, 0,
1157 u132_hcd_enumeration_empty_recv); 1155 u132_hcd_enumeration_empty_recv);
1158 if (retval == 0) { 1156 if (retval != 0)
1159 } else 1157 u132_hcd_giveback_urb(u132, endp, urb, retval);
1160 u132_hcd_giveback_urb(u132, endp, urb, retval); 1158 return;
1161 return; 1159 } else {
1162 } else {
1163 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1160 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1164 "unlinked=%d\n", urb, urb->unlinked); 1161 "unlinked=%d\n", urb, urb->unlinked);
1165 up(&u132->scheduler_lock); 1162 up(&u132->scheduler_lock);
1166 u132_hcd_giveback_urb(u132, endp, urb, 0); 1163 u132_hcd_giveback_urb(u132, endp, urb, 0);
1167 return; 1164 return;
1168 } 1165 }
1169} 1166}
1170 1167
1171static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf, 1168static void u132_hcd_initial_empty_sent(void *data, struct urb *urb, u8 *buf,
1172 int len, int toggle_bits, int error_count, int condition_code, 1169 int len, int toggle_bits, int error_count, int condition_code,
1173 int repeat_number, int halted, int skipped, int actual, int non_null) 1170 int repeat_number, int halted, int skipped, int actual, int non_null)
1174{ 1171{
1175 struct u132_endp *endp = data; 1172 struct u132_endp *endp = data;
1176 struct u132 *u132 = endp->u132; 1173 struct u132 *u132 = endp->u132;
1177 down(&u132->scheduler_lock); 1174 down(&u132->scheduler_lock);
1178 if (u132->going > 1) { 1175 if (u132->going > 1) {
1179 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1176 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1180 , u132->going); 1177 , u132->going);
1181 up(&u132->scheduler_lock); 1178 up(&u132->scheduler_lock);
1182 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1179 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1183 return; 1180 return;
1184 } else if (endp->dequeueing) { 1181 } else if (endp->dequeueing) {
1185 endp->dequeueing = 0; 1182 endp->dequeueing = 0;
1186 up(&u132->scheduler_lock); 1183 up(&u132->scheduler_lock);
1187 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1184 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1188 return; 1185 return;
1189 } else if (u132->going > 0) { 1186 } else if (u132->going > 0) {
1190 dev_err(&u132->platform_dev->dev, "device is being removed " 1187 dev_err(&u132->platform_dev->dev, "device is being removed "
1191 "urb=%p\n", urb); 1188 "urb=%p\n", urb);
1192 up(&u132->scheduler_lock); 1189 up(&u132->scheduler_lock);
1193 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1190 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1194 return; 1191 return;
1195 } else if (!urb->unlinked) { 1192 } else if (!urb->unlinked) {
1196 up(&u132->scheduler_lock); 1193 up(&u132->scheduler_lock);
1197 u132_hcd_giveback_urb(u132, endp, urb, 0); 1194 u132_hcd_giveback_urb(u132, endp, urb, 0);
1198 return; 1195 return;
1199 } else { 1196 } else {
1200 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1197 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1201 "unlinked=%d\n", urb, urb->unlinked); 1198 "unlinked=%d\n", urb, urb->unlinked);
1202 up(&u132->scheduler_lock); 1199 up(&u132->scheduler_lock);
1203 u132_hcd_giveback_urb(u132, endp, urb, 0); 1200 u132_hcd_giveback_urb(u132, endp, urb, 0);
1204 return; 1201 return;
1205 } 1202 }
1206} 1203}
1207 1204
1208static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf, 1205static void u132_hcd_initial_input_recv(void *data, struct urb *urb, u8 *buf,
1209 int len, int toggle_bits, int error_count, int condition_code, 1206 int len, int toggle_bits, int error_count, int condition_code,
1210 int repeat_number, int halted, int skipped, int actual, int non_null) 1207 int repeat_number, int halted, int skipped, int actual, int non_null)
1211{ 1208{
1212 struct u132_endp *endp = data; 1209 struct u132_endp *endp = data;
1213 struct u132 *u132 = endp->u132; 1210 struct u132 *u132 = endp->u132;
1214 u8 address = u132->addr[endp->usb_addr].address; 1211 u8 address = u132->addr[endp->usb_addr].address;
1215 down(&u132->scheduler_lock); 1212 down(&u132->scheduler_lock);
1216 if (u132->going > 1) { 1213 if (u132->going > 1) {
1217 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1214 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1218 , u132->going); 1215 , u132->going);
1219 up(&u132->scheduler_lock); 1216 up(&u132->scheduler_lock);
1220 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1217 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1221 return; 1218 return;
1222 } else if (endp->dequeueing) { 1219 } else if (endp->dequeueing) {
1223 endp->dequeueing = 0; 1220 endp->dequeueing = 0;
1224 up(&u132->scheduler_lock); 1221 up(&u132->scheduler_lock);
1225 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1222 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1226 return; 1223 return;
1227 } else if (u132->going > 0) { 1224 } else if (u132->going > 0) {
1228 dev_err(&u132->platform_dev->dev, "device is being removed " 1225 dev_err(&u132->platform_dev->dev, "device is being removed "
1229 "urb=%p\n", urb); 1226 "urb=%p\n", urb);
1230 up(&u132->scheduler_lock); 1227 up(&u132->scheduler_lock);
1231 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1228 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1232 return; 1229 return;
1233 } else if (!urb->unlinked) { 1230 } else if (!urb->unlinked) {
1234 int retval; 1231 int retval;
1235 struct u132_ring *ring = endp->ring; 1232 struct u132_ring *ring = endp->ring;
1236 u8 *u = urb->transfer_buffer; 1233 u8 *u = urb->transfer_buffer;
1237 u8 *b = buf; 1234 u8 *b = buf;
1238 int L = len; 1235 int L = len;
1239 while (L-- > 0) { 1236
1240 *u++ = *b++; 1237 while (L-- > 0)
1241 } 1238 *u++ = *b++;
1242 urb->actual_length = len; 1239
1243 up(&u132->scheduler_lock); 1240 urb->actual_length = len;
1244 retval = usb_ftdi_elan_edset_empty(u132->platform_dev, 1241 up(&u132->scheduler_lock);
1245 ring->number, endp, urb, address, endp->usb_endp, 0x3, 1242 retval = usb_ftdi_elan_edset_empty(u132->platform_dev,
1246 u132_hcd_initial_empty_sent); 1243 ring->number, endp, urb, address, endp->usb_endp, 0x3,
1247 if (retval == 0) { 1244 u132_hcd_initial_empty_sent);
1248 } else 1245 if (retval != 0)
1249 u132_hcd_giveback_urb(u132, endp, urb, retval); 1246 u132_hcd_giveback_urb(u132, endp, urb, retval);
1250 return; 1247 return;
1251 } else { 1248 } else {
1252 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1249 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1253 "unlinked=%d\n", urb, urb->unlinked); 1250 "unlinked=%d\n", urb, urb->unlinked);
1254 up(&u132->scheduler_lock); 1251 up(&u132->scheduler_lock);
1255 u132_hcd_giveback_urb(u132, endp, urb, 0); 1252 u132_hcd_giveback_urb(u132, endp, urb, 0);
1256 return; 1253 return;
1257 } 1254 }
1258} 1255}
1259 1256
1260static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf, 1257static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1261 int len, int toggle_bits, int error_count, int condition_code, 1258 int len, int toggle_bits, int error_count, int condition_code,
1262 int repeat_number, int halted, int skipped, int actual, int non_null) 1259 int repeat_number, int halted, int skipped, int actual, int non_null)
1263{ 1260{
1264 struct u132_endp *endp = data; 1261 struct u132_endp *endp = data;
1265 struct u132 *u132 = endp->u132; 1262 struct u132 *u132 = endp->u132;
1266 u8 address = u132->addr[endp->usb_addr].address; 1263 u8 address = u132->addr[endp->usb_addr].address;
1267 down(&u132->scheduler_lock); 1264 down(&u132->scheduler_lock);
1268 if (u132->going > 1) { 1265 if (u132->going > 1) {
1269 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1266 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1270 , u132->going); 1267 , u132->going);
1271 up(&u132->scheduler_lock); 1268 up(&u132->scheduler_lock);
1272 u132_hcd_forget_urb(u132, endp, urb, -ENODEV); 1269 u132_hcd_forget_urb(u132, endp, urb, -ENODEV);
1273 return; 1270 return;
1274 } else if (endp->dequeueing) { 1271 } else if (endp->dequeueing) {
1275 endp->dequeueing = 0; 1272 endp->dequeueing = 0;
1276 up(&u132->scheduler_lock); 1273 up(&u132->scheduler_lock);
1277 u132_hcd_giveback_urb(u132, endp, urb, -EINTR); 1274 u132_hcd_giveback_urb(u132, endp, urb, -EINTR);
1278 return; 1275 return;
1279 } else if (u132->going > 0) { 1276 } else if (u132->going > 0) {
1280 dev_err(&u132->platform_dev->dev, "device is being removed " 1277 dev_err(&u132->platform_dev->dev, "device is being removed "
1281 "urb=%p\n", urb); 1278 "urb=%p\n", urb);
1282 up(&u132->scheduler_lock); 1279 up(&u132->scheduler_lock);
1283 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV); 1280 u132_hcd_giveback_urb(u132, endp, urb, -ENODEV);
1284 return; 1281 return;
1285 } else if (!urb->unlinked) { 1282 } else if (!urb->unlinked) {
1286 int retval; 1283 int retval;
1287 struct u132_ring *ring = endp->ring; 1284 struct u132_ring *ring = endp->ring;
1288 up(&u132->scheduler_lock); 1285 up(&u132->scheduler_lock);
1289 retval = usb_ftdi_elan_edset_input(u132->platform_dev, 1286 retval = usb_ftdi_elan_edset_input(u132->platform_dev,
1290 ring->number, endp, urb, address, endp->usb_endp, 0, 1287 ring->number, endp, urb, address, endp->usb_endp, 0,
1291 u132_hcd_initial_input_recv); 1288 u132_hcd_initial_input_recv);
1292 if (retval == 0) { 1289 if (retval != 0)
1293 } else 1290 u132_hcd_giveback_urb(u132, endp, urb, retval);
1294 u132_hcd_giveback_urb(u132, endp, urb, retval); 1291 return;
1295 return; 1292 } else {
1296 } else {
1297 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p " 1293 dev_err(&u132->platform_dev->dev, "CALLBACK called urb=%p "
1298 "unlinked=%d\n", urb, urb->unlinked); 1294 "unlinked=%d\n", urb, urb->unlinked);
1299 up(&u132->scheduler_lock); 1295 up(&u132->scheduler_lock);
1300 u132_hcd_giveback_urb(u132, endp, urb, 0); 1296 u132_hcd_giveback_urb(u132, endp, urb, 0);
1301 return; 1297 return;
1302 } 1298 }
1303} 1299}
1304 1300
1305/* 1301/*
@@ -1308,300 +1304,296 @@ static void u132_hcd_initial_setup_sent(void *data, struct urb *urb, u8 *buf,
1308*/ 1304*/
1309static void u132_hcd_ring_work_scheduler(struct work_struct *work) 1305static void u132_hcd_ring_work_scheduler(struct work_struct *work)
1310{ 1306{
1311 struct u132_ring *ring = 1307 struct u132_ring *ring =
1312 container_of(work, struct u132_ring, scheduler.work); 1308 container_of(work, struct u132_ring, scheduler.work);
1313 struct u132 *u132 = ring->u132; 1309 struct u132 *u132 = ring->u132;
1314 down(&u132->scheduler_lock); 1310 down(&u132->scheduler_lock);
1315 if (ring->in_use) { 1311 if (ring->in_use) {
1316 up(&u132->scheduler_lock); 1312 up(&u132->scheduler_lock);
1317 u132_ring_put_kref(u132, ring); 1313 u132_ring_put_kref(u132, ring);
1318 return; 1314 return;
1319 } else if (ring->curr_endp) { 1315 } else if (ring->curr_endp) {
1320 struct u132_endp *last_endp = ring->curr_endp; 1316 struct u132_endp *last_endp = ring->curr_endp;
1321 struct list_head *scan; 1317 struct list_head *scan;
1322 struct list_head *head = &last_endp->endp_ring; 1318 struct list_head *head = &last_endp->endp_ring;
1323 unsigned long wakeup = 0; 1319 unsigned long wakeup = 0;
1324 list_for_each(scan, head) { 1320 list_for_each(scan, head) {
1325 struct u132_endp *endp = list_entry(scan, 1321 struct u132_endp *endp = list_entry(scan,
1326 struct u132_endp, endp_ring); 1322 struct u132_endp, endp_ring);
1327 if (endp->queue_next == endp->queue_last) { 1323 if (endp->queue_next == endp->queue_last) {
1328 } else if ((endp->delayed == 0) 1324 } else if ((endp->delayed == 0)
1329 || time_after_eq(jiffies, endp->jiffies)) { 1325 || time_after_eq(jiffies, endp->jiffies)) {
1330 ring->curr_endp = endp; 1326 ring->curr_endp = endp;
1331 u132_endp_cancel_work(u132, last_endp); 1327 u132_endp_cancel_work(u132, last_endp);
1332 u132_endp_queue_work(u132, last_endp, 0); 1328 u132_endp_queue_work(u132, last_endp, 0);
1333 up(&u132->scheduler_lock); 1329 up(&u132->scheduler_lock);
1334 u132_ring_put_kref(u132, ring); 1330 u132_ring_put_kref(u132, ring);
1335 return; 1331 return;
1336 } else { 1332 } else {
1337 unsigned long delta = endp->jiffies - jiffies; 1333 unsigned long delta = endp->jiffies - jiffies;
1338 if (delta > wakeup) 1334 if (delta > wakeup)
1339 wakeup = delta; 1335 wakeup = delta;
1340 } 1336 }
1341 } 1337 }
1342 if (last_endp->queue_next == last_endp->queue_last) { 1338 if (last_endp->queue_next == last_endp->queue_last) {
1343 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies, 1339 } else if ((last_endp->delayed == 0) || time_after_eq(jiffies,
1344 last_endp->jiffies)) { 1340 last_endp->jiffies)) {
1345 u132_endp_cancel_work(u132, last_endp); 1341 u132_endp_cancel_work(u132, last_endp);
1346 u132_endp_queue_work(u132, last_endp, 0); 1342 u132_endp_queue_work(u132, last_endp, 0);
1347 up(&u132->scheduler_lock); 1343 up(&u132->scheduler_lock);
1348 u132_ring_put_kref(u132, ring); 1344 u132_ring_put_kref(u132, ring);
1349 return; 1345 return;
1350 } else { 1346 } else {
1351 unsigned long delta = last_endp->jiffies - jiffies; 1347 unsigned long delta = last_endp->jiffies - jiffies;
1352 if (delta > wakeup) 1348 if (delta > wakeup)
1353 wakeup = delta; 1349 wakeup = delta;
1354 } 1350 }
1355 if (wakeup > 0) { 1351 if (wakeup > 0) {
1356 u132_ring_requeue_work(u132, ring, wakeup); 1352 u132_ring_requeue_work(u132, ring, wakeup);
1357 up(&u132->scheduler_lock); 1353 up(&u132->scheduler_lock);
1358 return; 1354 return;
1359 } else { 1355 } else {
1360 up(&u132->scheduler_lock); 1356 up(&u132->scheduler_lock);
1361 u132_ring_put_kref(u132, ring); 1357 u132_ring_put_kref(u132, ring);
1362 return; 1358 return;
1363 } 1359 }
1364 } else { 1360 } else {
1365 up(&u132->scheduler_lock); 1361 up(&u132->scheduler_lock);
1366 u132_ring_put_kref(u132, ring); 1362 u132_ring_put_kref(u132, ring);
1367 return; 1363 return;
1368 } 1364 }
1369} 1365}
1370 1366
1371static void u132_hcd_endp_work_scheduler(struct work_struct *work) 1367static void u132_hcd_endp_work_scheduler(struct work_struct *work)
1372{ 1368{
1373 struct u132_ring *ring; 1369 struct u132_ring *ring;
1374 struct u132_endp *endp = 1370 struct u132_endp *endp =
1375 container_of(work, struct u132_endp, scheduler.work); 1371 container_of(work, struct u132_endp, scheduler.work);
1376 struct u132 *u132 = endp->u132; 1372 struct u132 *u132 = endp->u132;
1377 down(&u132->scheduler_lock); 1373 down(&u132->scheduler_lock);
1378 ring = endp->ring; 1374 ring = endp->ring;
1379 if (endp->edset_flush) { 1375 if (endp->edset_flush) {
1380 endp->edset_flush = 0; 1376 endp->edset_flush = 0;
1381 if (endp->dequeueing) 1377 if (endp->dequeueing)
1382 usb_ftdi_elan_edset_flush(u132->platform_dev, 1378 usb_ftdi_elan_edset_flush(u132->platform_dev,
1383 ring->number, endp); 1379 ring->number, endp);
1384 up(&u132->scheduler_lock); 1380 up(&u132->scheduler_lock);
1385 u132_endp_put_kref(u132, endp); 1381 u132_endp_put_kref(u132, endp);
1386 return; 1382 return;
1387 } else if (endp->active) { 1383 } else if (endp->active) {
1388 up(&u132->scheduler_lock); 1384 up(&u132->scheduler_lock);
1389 u132_endp_put_kref(u132, endp); 1385 u132_endp_put_kref(u132, endp);
1390 return; 1386 return;
1391 } else if (ring->in_use) { 1387 } else if (ring->in_use) {
1392 up(&u132->scheduler_lock); 1388 up(&u132->scheduler_lock);
1393 u132_endp_put_kref(u132, endp); 1389 u132_endp_put_kref(u132, endp);
1394 return; 1390 return;
1395 } else if (endp->queue_next == endp->queue_last) { 1391 } else if (endp->queue_next == endp->queue_last) {
1396 up(&u132->scheduler_lock); 1392 up(&u132->scheduler_lock);
1397 u132_endp_put_kref(u132, endp); 1393 u132_endp_put_kref(u132, endp);
1398 return; 1394 return;
1399 } else if (endp->pipetype == PIPE_INTERRUPT) { 1395 } else if (endp->pipetype == PIPE_INTERRUPT) {
1400 u8 address = u132->addr[endp->usb_addr].address; 1396 u8 address = u132->addr[endp->usb_addr].address;
1401 if (ring->in_use) { 1397 if (ring->in_use) {
1402 up(&u132->scheduler_lock); 1398 up(&u132->scheduler_lock);
1403 u132_endp_put_kref(u132, endp); 1399 u132_endp_put_kref(u132, endp);
1404 return; 1400 return;
1405 } else { 1401 } else {
1406 int retval; 1402 int retval;
1407 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1403 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1408 endp->queue_next]; 1404 endp->queue_next];
1409 endp->active = 1; 1405 endp->active = 1;
1410 ring->curr_endp = endp; 1406 ring->curr_endp = endp;
1411 ring->in_use = 1; 1407 ring->in_use = 1;
1412 up(&u132->scheduler_lock); 1408 up(&u132->scheduler_lock);
1413 retval = edset_single(u132, ring, endp, urb, address, 1409 retval = edset_single(u132, ring, endp, urb, address,
1414 endp->toggle_bits, u132_hcd_interrupt_recv); 1410 endp->toggle_bits, u132_hcd_interrupt_recv);
1415 if (retval == 0) { 1411 if (retval != 0)
1416 } else 1412 u132_hcd_giveback_urb(u132, endp, urb, retval);
1417 u132_hcd_giveback_urb(u132, endp, urb, retval); 1413 return;
1418 return; 1414 }
1419 } 1415 } else if (endp->pipetype == PIPE_CONTROL) {
1420 } else if (endp->pipetype == PIPE_CONTROL) { 1416 u8 address = u132->addr[endp->usb_addr].address;
1421 u8 address = u132->addr[endp->usb_addr].address; 1417 if (ring->in_use) {
1422 if (ring->in_use) { 1418 up(&u132->scheduler_lock);
1423 up(&u132->scheduler_lock); 1419 u132_endp_put_kref(u132, endp);
1424 u132_endp_put_kref(u132, endp); 1420 return;
1425 return; 1421 } else if (address == 0) {
1426 } else if (address == 0) { 1422 int retval;
1427 int retval; 1423 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1428 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1424 endp->queue_next];
1429 endp->queue_next]; 1425 endp->active = 1;
1430 endp->active = 1; 1426 ring->curr_endp = endp;
1431 ring->curr_endp = endp; 1427 ring->in_use = 1;
1432 ring->in_use = 1; 1428 up(&u132->scheduler_lock);
1433 up(&u132->scheduler_lock); 1429 retval = edset_setup(u132, ring, endp, urb, address,
1434 retval = edset_setup(u132, ring, endp, urb, address, 1430 0x2, u132_hcd_initial_setup_sent);
1435 0x2, u132_hcd_initial_setup_sent); 1431 if (retval != 0)
1436 if (retval == 0) { 1432 u132_hcd_giveback_urb(u132, endp, urb, retval);
1437 } else 1433 return;
1438 u132_hcd_giveback_urb(u132, endp, urb, retval); 1434 } else if (endp->usb_addr == 0) {
1439 return; 1435 int retval;
1440 } else if (endp->usb_addr == 0) { 1436 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1441 int retval; 1437 endp->queue_next];
1442 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1438 endp->active = 1;
1443 endp->queue_next]; 1439 ring->curr_endp = endp;
1444 endp->active = 1; 1440 ring->in_use = 1;
1445 ring->curr_endp = endp; 1441 up(&u132->scheduler_lock);
1446 ring->in_use = 1; 1442 retval = edset_setup(u132, ring, endp, urb, 0, 0x2,
1447 up(&u132->scheduler_lock); 1443 u132_hcd_enumeration_address_sent);
1448 retval = edset_setup(u132, ring, endp, urb, 0, 0x2, 1444 if (retval != 0)
1449 u132_hcd_enumeration_address_sent); 1445 u132_hcd_giveback_urb(u132, endp, urb, retval);
1450 if (retval == 0) { 1446 return;
1451 } else 1447 } else {
1452 u132_hcd_giveback_urb(u132, endp, urb, retval); 1448 int retval;
1453 return; 1449 u8 address = u132->addr[endp->usb_addr].address;
1454 } else { 1450 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK &
1455 int retval; 1451 endp->queue_next];
1456 u8 address = u132->addr[endp->usb_addr].address; 1452 endp->active = 1;
1457 struct urb *urb = endp->urb_list[ENDP_QUEUE_MASK & 1453 ring->curr_endp = endp;
1458 endp->queue_next]; 1454 ring->in_use = 1;
1459 endp->active = 1; 1455 up(&u132->scheduler_lock);
1460 ring->curr_endp = endp; 1456 retval = edset_setup(u132, ring, endp, urb, address,
1461 ring->in_use = 1; 1457 0x2, u132_hcd_configure_setup_sent);
1462 up(&u132->scheduler_lock); 1458 if (retval != 0)
1463 retval = edset_setup(u132, ring, endp, urb, address, 1459 u132_hcd_giveback_urb(u132, endp, urb, retval);
1464 0x2, u132_hcd_configure_setup_sent); 1460 return;
1465 if (retval == 0) { 1461 }
1466 } else 1462 } else {
1467 u132_hcd_giveback_urb(u132, endp, urb, retval); 1463 if (endp->input) {
1468 return; 1464 u8 address = u132->addr[endp->usb_addr].address;
1469 } 1465 if (ring->in_use) {
1470 } else { 1466 up(&u132->scheduler_lock);
1471 if (endp->input) { 1467 u132_endp_put_kref(u132, endp);
1472 u8 address = u132->addr[endp->usb_addr].address; 1468 return;
1473 if (ring->in_use) { 1469 } else {
1474 up(&u132->scheduler_lock); 1470 int retval;
1475 u132_endp_put_kref(u132, endp); 1471 struct urb *urb = endp->urb_list[
1476 return; 1472 ENDP_QUEUE_MASK & endp->queue_next];
1477 } else { 1473 endp->active = 1;
1478 int retval; 1474 ring->curr_endp = endp;
1479 struct urb *urb = endp->urb_list[ 1475 ring->in_use = 1;
1480 ENDP_QUEUE_MASK & endp->queue_next]; 1476 up(&u132->scheduler_lock);
1481 endp->active = 1; 1477 retval = edset_input(u132, ring, endp, urb,
1482 ring->curr_endp = endp; 1478 address, endp->toggle_bits,
1483 ring->in_use = 1; 1479 u132_hcd_bulk_input_recv);
1484 up(&u132->scheduler_lock); 1480 if (retval == 0) {
1485 retval = edset_input(u132, ring, endp, urb, 1481 } else
1486 address, endp->toggle_bits, 1482 u132_hcd_giveback_urb(u132, endp, urb,
1487 u132_hcd_bulk_input_recv); 1483 retval);
1488 if (retval == 0) { 1484 return;
1489 } else 1485 }
1490 u132_hcd_giveback_urb(u132, endp, urb, 1486 } else { /* output pipe */
1491 retval); 1487 u8 address = u132->addr[endp->usb_addr].address;
1492 return; 1488 if (ring->in_use) {
1493 } 1489 up(&u132->scheduler_lock);
1494 } else { /* output pipe */ 1490 u132_endp_put_kref(u132, endp);
1495 u8 address = u132->addr[endp->usb_addr].address; 1491 return;
1496 if (ring->in_use) { 1492 } else {
1497 up(&u132->scheduler_lock); 1493 int retval;
1498 u132_endp_put_kref(u132, endp); 1494 struct urb *urb = endp->urb_list[
1499 return; 1495 ENDP_QUEUE_MASK & endp->queue_next];
1500 } else { 1496 endp->active = 1;
1501 int retval; 1497 ring->curr_endp = endp;
1502 struct urb *urb = endp->urb_list[ 1498 ring->in_use = 1;
1503 ENDP_QUEUE_MASK & endp->queue_next]; 1499 up(&u132->scheduler_lock);
1504 endp->active = 1; 1500 retval = edset_output(u132, ring, endp, urb,
1505 ring->curr_endp = endp; 1501 address, endp->toggle_bits,
1506 ring->in_use = 1; 1502 u132_hcd_bulk_output_sent);
1507 up(&u132->scheduler_lock); 1503 if (retval == 0) {
1508 retval = edset_output(u132, ring, endp, urb, 1504 } else
1509 address, endp->toggle_bits, 1505 u132_hcd_giveback_urb(u132, endp, urb,
1510 u132_hcd_bulk_output_sent); 1506 retval);
1511 if (retval == 0) { 1507 return;
1512 } else 1508 }
1513 u132_hcd_giveback_urb(u132, endp, urb, 1509 }
1514 retval); 1510 }
1515 return;
1516 }
1517 }
1518 }
1519} 1511}
1520#ifdef CONFIG_PM 1512#ifdef CONFIG_PM
1521 1513
1522static void port_power(struct u132 *u132, int pn, int is_on) 1514static void port_power(struct u132 *u132, int pn, int is_on)
1523{ 1515{
1524 u132->port[pn].power = is_on; 1516 u132->port[pn].power = is_on;
1525} 1517}
1526 1518
1527#endif 1519#endif
1528 1520
1529static void u132_power(struct u132 *u132, int is_on) 1521static void u132_power(struct u132 *u132, int is_on)
1530{ 1522{
1531 struct usb_hcd *hcd = u132_to_hcd(u132) 1523 struct usb_hcd *hcd = u132_to_hcd(u132)
1532 ; /* hub is inactive unless the port is powered */ 1524 ; /* hub is inactive unless the port is powered */
1533 if (is_on) { 1525 if (is_on) {
1534 if (u132->power) 1526 if (u132->power)
1535 return; 1527 return;
1536 u132->power = 1; 1528 u132->power = 1;
1537 } else { 1529 } else {
1538 u132->power = 0; 1530 u132->power = 0;
1539 hcd->state = HC_STATE_HALT; 1531 hcd->state = HC_STATE_HALT;
1540 } 1532 }
1541} 1533}
1542 1534
1543static int u132_periodic_reinit(struct u132 *u132) 1535static int u132_periodic_reinit(struct u132 *u132)
1544{ 1536{
1545 int retval; 1537 int retval;
1546 u32 fi = u132->hc_fminterval & 0x03fff; 1538 u32 fi = u132->hc_fminterval & 0x03fff;
1547 u32 fit; 1539 u32 fit;
1548 u32 fminterval; 1540 u32 fminterval;
1549 retval = u132_read_pcimem(u132, fminterval, &fminterval); 1541 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1550 if (retval) 1542 if (retval)
1551 return retval; 1543 return retval;
1552 fit = fminterval & FIT; 1544 fit = fminterval & FIT;
1553 retval = u132_write_pcimem(u132, fminterval, 1545 retval = u132_write_pcimem(u132, fminterval,
1554 (fit ^ FIT) | u132->hc_fminterval); 1546 (fit ^ FIT) | u132->hc_fminterval);
1555 if (retval) 1547 if (retval)
1556 return retval; 1548 return retval;
1557 retval = u132_write_pcimem(u132, periodicstart, 1549 retval = u132_write_pcimem(u132, periodicstart,
1558 ((9 *fi) / 10) & 0x3fff); 1550 ((9 * fi) / 10) & 0x3fff);
1559 if (retval) 1551 if (retval)
1560 return retval; 1552 return retval;
1561 return 0; 1553 return 0;
1562} 1554}
1563 1555
1564static char *hcfs2string(int state) 1556static char *hcfs2string(int state)
1565{ 1557{
1566 switch (state) { 1558 switch (state) {
1567 case OHCI_USB_RESET: 1559 case OHCI_USB_RESET:
1568 return "reset"; 1560 return "reset";
1569 case OHCI_USB_RESUME: 1561 case OHCI_USB_RESUME:
1570 return "resume"; 1562 return "resume";
1571 case OHCI_USB_OPER: 1563 case OHCI_USB_OPER:
1572 return "operational"; 1564 return "operational";
1573 case OHCI_USB_SUSPEND: 1565 case OHCI_USB_SUSPEND:
1574 return "suspend"; 1566 return "suspend";
1575 } 1567 }
1576 return "?"; 1568 return "?";
1577} 1569}
1578 1570
1579static int u132_init(struct u132 *u132) 1571static int u132_init(struct u132 *u132)
1580{ 1572{
1581 int retval; 1573 int retval;
1582 u32 control; 1574 u32 control;
1583 u132_disable(u132); 1575 u132_disable(u132);
1584 u132->next_statechange = jiffies; 1576 u132->next_statechange = jiffies;
1585 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE); 1577 retval = u132_write_pcimem(u132, intrdisable, OHCI_INTR_MIE);
1586 if (retval) 1578 if (retval)
1587 return retval; 1579 return retval;
1588 retval = u132_read_pcimem(u132, control, &control); 1580 retval = u132_read_pcimem(u132, control, &control);
1589 if (retval) 1581 if (retval)
1590 return retval; 1582 return retval;
1591 if (u132->num_ports == 0) { 1583 if (u132->num_ports == 0) {
1592 u32 rh_a = -1; 1584 u32 rh_a = -1;
1593 retval = u132_read_pcimem(u132, roothub.a, &rh_a); 1585 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
1594 if (retval) 1586 if (retval)
1595 return retval; 1587 return retval;
1596 u132->num_ports = rh_a & RH_A_NDP; 1588 u132->num_ports = rh_a & RH_A_NDP;
1597 retval = read_roothub_info(u132); 1589 retval = read_roothub_info(u132);
1598 if (retval) 1590 if (retval)
1599 return retval; 1591 return retval;
1600 } 1592 }
1601 if (u132->num_ports > MAX_U132_PORTS) { 1593 if (u132->num_ports > MAX_U132_PORTS)
1602 return -EINVAL; 1594 return -EINVAL;
1603 } 1595
1604 return 0; 1596 return 0;
1605} 1597}
1606 1598
1607 1599
@@ -1611,280 +1603,278 @@ static int u132_init(struct u132 *u132)
1611*/ 1603*/
1612static int u132_run(struct u132 *u132) 1604static int u132_run(struct u132 *u132)
1613{ 1605{
1614 int retval; 1606 int retval;
1615 u32 control; 1607 u32 control;
1616 u32 status; 1608 u32 status;
1617 u32 fminterval; 1609 u32 fminterval;
1618 u32 periodicstart; 1610 u32 periodicstart;
1619 u32 cmdstatus; 1611 u32 cmdstatus;
1620 u32 roothub_a; 1612 u32 roothub_a;
1621 int mask = OHCI_INTR_INIT; 1613 int mask = OHCI_INTR_INIT;
1622 int first = u132->hc_fminterval == 0; 1614 int first = u132->hc_fminterval == 0;
1623 int sleep_time = 0; 1615 int sleep_time = 0;
1624 int reset_timeout = 30; /* ... allow extra time */ 1616 int reset_timeout = 30; /* ... allow extra time */
1625 u132_disable(u132); 1617 u132_disable(u132);
1626 if (first) { 1618 if (first) {
1627 u32 temp; 1619 u32 temp;
1628 retval = u132_read_pcimem(u132, fminterval, &temp); 1620 retval = u132_read_pcimem(u132, fminterval, &temp);
1629 if (retval) 1621 if (retval)
1630 return retval; 1622 return retval;
1631 u132->hc_fminterval = temp & 0x3fff; 1623 u132->hc_fminterval = temp & 0x3fff;
1632 if (u132->hc_fminterval != FI) { 1624 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16;
1633 } 1625 }
1634 u132->hc_fminterval |= FSMP(u132->hc_fminterval) << 16; 1626 retval = u132_read_pcimem(u132, control, &u132->hc_control);
1635 } 1627 if (retval)
1636 retval = u132_read_pcimem(u132, control, &u132->hc_control); 1628 return retval;
1637 if (retval) 1629 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control "
1638 return retval; 1630 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS),
1639 dev_info(&u132->platform_dev->dev, "resetting from state '%s', control " 1631 u132->hc_control);
1640 "= %08X\n", hcfs2string(u132->hc_control & OHCI_CTRL_HCFS), 1632 switch (u132->hc_control & OHCI_CTRL_HCFS) {
1641 u132->hc_control); 1633 case OHCI_USB_OPER:
1642 switch (u132->hc_control & OHCI_CTRL_HCFS) { 1634 sleep_time = 0;
1643 case OHCI_USB_OPER: 1635 break;
1644 sleep_time = 0; 1636 case OHCI_USB_SUSPEND:
1645 break; 1637 case OHCI_USB_RESUME:
1646 case OHCI_USB_SUSPEND: 1638 u132->hc_control &= OHCI_CTRL_RWC;
1647 case OHCI_USB_RESUME: 1639 u132->hc_control |= OHCI_USB_RESUME;
1648 u132->hc_control &= OHCI_CTRL_RWC; 1640 sleep_time = 10;
1649 u132->hc_control |= OHCI_USB_RESUME; 1641 break;
1650 sleep_time = 10; 1642 default:
1651 break; 1643 u132->hc_control &= OHCI_CTRL_RWC;
1652 default: 1644 u132->hc_control |= OHCI_USB_RESET;
1653 u132->hc_control &= OHCI_CTRL_RWC; 1645 sleep_time = 50;
1654 u132->hc_control |= OHCI_USB_RESET; 1646 break;
1655 sleep_time = 50; 1647 }
1656 break; 1648 retval = u132_write_pcimem(u132, control, u132->hc_control);
1657 } 1649 if (retval)
1658 retval = u132_write_pcimem(u132, control, u132->hc_control); 1650 return retval;
1659 if (retval) 1651 retval = u132_read_pcimem(u132, control, &control);
1660 return retval; 1652 if (retval)
1661 retval = u132_read_pcimem(u132, control, &control); 1653 return retval;
1662 if (retval) 1654 msleep(sleep_time);
1663 return retval; 1655 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1664 msleep(sleep_time); 1656 if (retval)
1665 retval = u132_read_pcimem(u132, roothub.a, &roothub_a); 1657 return retval;
1666 if (retval) 1658 if (!(roothub_a & RH_A_NPS)) {
1667 return retval; 1659 int temp; /* power down each port */
1668 if (!(roothub_a & RH_A_NPS)) { 1660 for (temp = 0; temp < u132->num_ports; temp++) {
1669 int temp; /* power down each port */ 1661 retval = u132_write_pcimem(u132,
1670 for (temp = 0; temp < u132->num_ports; temp++) { 1662 roothub.portstatus[temp], RH_PS_LSDA);
1671 retval = u132_write_pcimem(u132, 1663 if (retval)
1672 roothub.portstatus[temp], RH_PS_LSDA); 1664 return retval;
1673 if (retval) 1665 }
1674 return retval; 1666 }
1675 } 1667 retval = u132_read_pcimem(u132, control, &control);
1676 } 1668 if (retval)
1677 retval = u132_read_pcimem(u132, control, &control); 1669 return retval;
1678 if (retval) 1670retry:
1679 return retval; 1671 retval = u132_read_pcimem(u132, cmdstatus, &status);
1680 retry:retval = u132_read_pcimem(u132, cmdstatus, &status); 1672 if (retval)
1681 if (retval) 1673 return retval;
1682 return retval; 1674 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR);
1683 retval = u132_write_pcimem(u132, cmdstatus, OHCI_HCR); 1675 if (retval)
1684 if (retval) 1676 return retval;
1685 return retval; 1677extra: {
1686 extra:{ 1678 retval = u132_read_pcimem(u132, cmdstatus, &status);
1687 retval = u132_read_pcimem(u132, cmdstatus, &status); 1679 if (retval)
1688 if (retval) 1680 return retval;
1689 return retval; 1681 if (0 != (status & OHCI_HCR)) {
1690 if (0 != (status & OHCI_HCR)) { 1682 if (--reset_timeout == 0) {
1691 if (--reset_timeout == 0) { 1683 dev_err(&u132->platform_dev->dev, "USB HC reset"
1692 dev_err(&u132->platform_dev->dev, "USB HC reset" 1684 " timed out!\n");
1693 " timed out!\n"); 1685 return -ENODEV;
1694 return -ENODEV; 1686 } else {
1695 } else { 1687 msleep(5);
1696 msleep(5); 1688 goto extra;
1697 goto extra; 1689 }
1698 } 1690 }
1699 } 1691 }
1700 } 1692 if (u132->flags & OHCI_QUIRK_INITRESET) {
1701 if (u132->flags & OHCI_QUIRK_INITRESET) { 1693 retval = u132_write_pcimem(u132, control, u132->hc_control);
1702 retval = u132_write_pcimem(u132, control, u132->hc_control); 1694 if (retval)
1703 if (retval) 1695 return retval;
1704 return retval; 1696 retval = u132_read_pcimem(u132, control, &control);
1705 retval = u132_read_pcimem(u132, control, &control); 1697 if (retval)
1706 if (retval) 1698 return retval;
1707 return retval; 1699 }
1708 } 1700 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000);
1709 retval = u132_write_pcimem(u132, ed_controlhead, 0x00000000); 1701 if (retval)
1710 if (retval) 1702 return retval;
1711 return retval; 1703 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000);
1712 retval = u132_write_pcimem(u132, ed_bulkhead, 0x11000000); 1704 if (retval)
1713 if (retval) 1705 return retval;
1714 return retval; 1706 retval = u132_write_pcimem(u132, hcca, 0x00000000);
1715 retval = u132_write_pcimem(u132, hcca, 0x00000000); 1707 if (retval)
1716 if (retval) 1708 return retval;
1717 return retval; 1709 retval = u132_periodic_reinit(u132);
1718 retval = u132_periodic_reinit(u132); 1710 if (retval)
1719 if (retval) 1711 return retval;
1720 return retval; 1712 retval = u132_read_pcimem(u132, fminterval, &fminterval);
1721 retval = u132_read_pcimem(u132, fminterval, &fminterval); 1713 if (retval)
1722 if (retval) 1714 return retval;
1723 return retval; 1715 retval = u132_read_pcimem(u132, periodicstart, &periodicstart);
1724 retval = u132_read_pcimem(u132, periodicstart, &periodicstart); 1716 if (retval)
1725 if (retval) 1717 return retval;
1726 return retval; 1718 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) {
1727 if (0 == (fminterval & 0x3fff0000) || 0 == periodicstart) { 1719 if (!(u132->flags & OHCI_QUIRK_INITRESET)) {
1728 if (!(u132->flags & OHCI_QUIRK_INITRESET)) { 1720 u132->flags |= OHCI_QUIRK_INITRESET;
1729 u132->flags |= OHCI_QUIRK_INITRESET; 1721 goto retry;
1730 goto retry; 1722 } else
1731 } else 1723 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)"
1732 dev_err(&u132->platform_dev->dev, "init err(%08x %04x)" 1724 "\n", fminterval, periodicstart);
1733 "\n", fminterval, periodicstart); 1725 } /* start controller operations */
1734 } /* start controller operations */ 1726 u132->hc_control &= OHCI_CTRL_RWC;
1735 u132->hc_control &= OHCI_CTRL_RWC; 1727 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER;
1736 u132->hc_control |= OHCI_CONTROL_INIT | OHCI_CTRL_BLE | OHCI_USB_OPER; 1728 retval = u132_write_pcimem(u132, control, u132->hc_control);
1737 retval = u132_write_pcimem(u132, control, u132->hc_control); 1729 if (retval)
1738 if (retval) 1730 return retval;
1739 return retval; 1731 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF);
1740 retval = u132_write_pcimem(u132, cmdstatus, OHCI_BLF); 1732 if (retval)
1741 if (retval) 1733 return retval;
1742 return retval; 1734 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus);
1743 retval = u132_read_pcimem(u132, cmdstatus, &cmdstatus); 1735 if (retval)
1744 if (retval) 1736 return retval;
1745 return retval; 1737 retval = u132_read_pcimem(u132, control, &control);
1746 retval = u132_read_pcimem(u132, control, &control); 1738 if (retval)
1747 if (retval) 1739 return retval;
1748 return retval; 1740 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1749 u132_to_hcd(u132)->state = HC_STATE_RUNNING; 1741 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE);
1750 retval = u132_write_pcimem(u132, roothub.status, RH_HS_DRWE); 1742 if (retval)
1751 if (retval) 1743 return retval;
1752 return retval; 1744 retval = u132_write_pcimem(u132, intrstatus, mask);
1753 retval = u132_write_pcimem(u132, intrstatus, mask); 1745 if (retval)
1754 if (retval) 1746 return retval;
1755 return retval; 1747 retval = u132_write_pcimem(u132, intrdisable,
1756 retval = u132_write_pcimem(u132, intrdisable, 1748 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO |
1757 OHCI_INTR_MIE | OHCI_INTR_OC | OHCI_INTR_RHSC | OHCI_INTR_FNO | 1749 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH |
1758 OHCI_INTR_UE | OHCI_INTR_RD | OHCI_INTR_SF | OHCI_INTR_WDH | 1750 OHCI_INTR_SO);
1759 OHCI_INTR_SO); 1751 if (retval)
1760 if (retval) 1752 return retval; /* handle root hub init quirks ... */
1761 return retval; /* handle root hub init quirks ... */ 1753 retval = u132_read_pcimem(u132, roothub.a, &roothub_a);
1762 retval = u132_read_pcimem(u132, roothub.a, &roothub_a); 1754 if (retval)
1763 if (retval) 1755 return retval;
1764 return retval; 1756 roothub_a &= ~(RH_A_PSM | RH_A_OCPM);
1765 roothub_a &= ~(RH_A_PSM | RH_A_OCPM); 1757 if (u132->flags & OHCI_QUIRK_SUPERIO) {
1766 if (u132->flags & OHCI_QUIRK_SUPERIO) { 1758 roothub_a |= RH_A_NOCP;
1767 roothub_a |= RH_A_NOCP; 1759 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS);
1768 roothub_a &= ~(RH_A_POTPGT | RH_A_NPS); 1760 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1769 retval = u132_write_pcimem(u132, roothub.a, roothub_a); 1761 if (retval)
1770 if (retval) 1762 return retval;
1771 return retval; 1763 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) {
1772 } else if ((u132->flags & OHCI_QUIRK_AMD756) || distrust_firmware) { 1764 roothub_a |= RH_A_NPS;
1773 roothub_a |= RH_A_NPS; 1765 retval = u132_write_pcimem(u132, roothub.a, roothub_a);
1774 retval = u132_write_pcimem(u132, roothub.a, roothub_a); 1766 if (retval)
1775 if (retval) 1767 return retval;
1776 return retval; 1768 }
1777 } 1769 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC);
1778 retval = u132_write_pcimem(u132, roothub.status, RH_HS_LPSC); 1770 if (retval)
1779 if (retval) 1771 return retval;
1780 return retval; 1772 retval = u132_write_pcimem(u132, roothub.b,
1781 retval = u132_write_pcimem(u132, roothub.b, 1773 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM);
1782 (roothub_a & RH_A_NPS) ? 0 : RH_B_PPCM); 1774 if (retval)
1783 if (retval) 1775 return retval;
1784 return retval; 1776 retval = u132_read_pcimem(u132, control, &control);
1785 retval = u132_read_pcimem(u132, control, &control); 1777 if (retval)
1786 if (retval) 1778 return retval;
1787 return retval; 1779 mdelay((roothub_a >> 23) & 0x1fe);
1788 mdelay((roothub_a >> 23) & 0x1fe); 1780 u132_to_hcd(u132)->state = HC_STATE_RUNNING;
1789 u132_to_hcd(u132)->state = HC_STATE_RUNNING; 1781 return 0;
1790 return 0;
1791} 1782}
1792 1783
1793static void u132_hcd_stop(struct usb_hcd *hcd) 1784static void u132_hcd_stop(struct usb_hcd *hcd)
1794{ 1785{
1795 struct u132 *u132 = hcd_to_u132(hcd); 1786 struct u132 *u132 = hcd_to_u132(hcd);
1796 if (u132->going > 1) { 1787 if (u132->going > 1) {
1797 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b" 1788 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p) has b"
1798 "een removed %d\n", u132, hcd, u132->going); 1789 "een removed %d\n", u132, hcd, u132->going);
1799 } else if (u132->going > 0) { 1790 } else if (u132->going > 0) {
1800 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 1791 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
1801 "ed\n", hcd); 1792 "ed\n", hcd);
1802 } else { 1793 } else {
1803 mutex_lock(&u132->sw_lock); 1794 mutex_lock(&u132->sw_lock);
1804 msleep(100); 1795 msleep(100);
1805 u132_power(u132, 0); 1796 u132_power(u132, 0);
1806 mutex_unlock(&u132->sw_lock); 1797 mutex_unlock(&u132->sw_lock);
1807 } 1798 }
1808} 1799}
1809 1800
1810static int u132_hcd_start(struct usb_hcd *hcd) 1801static int u132_hcd_start(struct usb_hcd *hcd)
1811{ 1802{
1812 struct u132 *u132 = hcd_to_u132(hcd); 1803 struct u132 *u132 = hcd_to_u132(hcd);
1813 if (u132->going > 1) { 1804 if (u132->going > 1) {
1814 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1805 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1815 , u132->going); 1806 , u132->going);
1816 return -ENODEV; 1807 return -ENODEV;
1817 } else if (u132->going > 0) { 1808 } else if (u132->going > 0) {
1818 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 1809 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1819 return -ESHUTDOWN; 1810 return -ESHUTDOWN;
1820 } else if (hcd->self.controller) { 1811 } else if (hcd->self.controller) {
1821 int retval; 1812 int retval;
1822 struct platform_device *pdev = 1813 struct platform_device *pdev =
1823 to_platform_device(hcd->self.controller); 1814 to_platform_device(hcd->self.controller);
1824 u16 vendor = ((struct u132_platform_data *) 1815 u16 vendor = ((struct u132_platform_data *)
1825 (pdev->dev.platform_data))->vendor; 1816 (pdev->dev.platform_data))->vendor;
1826 u16 device = ((struct u132_platform_data *) 1817 u16 device = ((struct u132_platform_data *)
1827 (pdev->dev.platform_data))->device; 1818 (pdev->dev.platform_data))->device;
1828 mutex_lock(&u132->sw_lock); 1819 mutex_lock(&u132->sw_lock);
1829 msleep(10); 1820 msleep(10);
1830 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) { 1821 if (vendor == PCI_VENDOR_ID_AMD && device == 0x740c) {
1831 u132->flags = OHCI_QUIRK_AMD756; 1822 u132->flags = OHCI_QUIRK_AMD756;
1832 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) { 1823 } else if (vendor == PCI_VENDOR_ID_OPTI && device == 0xc861) {
1833 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar" 1824 dev_err(&u132->platform_dev->dev, "WARNING: OPTi workar"
1834 "ounds unavailable\n"); 1825 "ounds unavailable\n");
1835 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8) 1826 } else if (vendor == PCI_VENDOR_ID_COMPAQ && device == 0xa0f8)
1836 u132->flags |= OHCI_QUIRK_ZFMICRO; 1827 u132->flags |= OHCI_QUIRK_ZFMICRO;
1837 retval = u132_run(u132); 1828 retval = u132_run(u132);
1838 if (retval) { 1829 if (retval) {
1839 u132_disable(u132); 1830 u132_disable(u132);
1840 u132->going = 1; 1831 u132->going = 1;
1841 } 1832 }
1842 msleep(100); 1833 msleep(100);
1843 mutex_unlock(&u132->sw_lock); 1834 mutex_unlock(&u132->sw_lock);
1844 return retval; 1835 return retval;
1845 } else { 1836 } else {
1846 dev_err(&u132->platform_dev->dev, "platform_device missing\n"); 1837 dev_err(&u132->platform_dev->dev, "platform_device missing\n");
1847 return -ENODEV; 1838 return -ENODEV;
1848 } 1839 }
1849} 1840}
1850 1841
1851static int u132_hcd_reset(struct usb_hcd *hcd) 1842static int u132_hcd_reset(struct usb_hcd *hcd)
1852{ 1843{
1853 struct u132 *u132 = hcd_to_u132(hcd); 1844 struct u132 *u132 = hcd_to_u132(hcd);
1854 if (u132->going > 1) { 1845 if (u132->going > 1) {
1855 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 1846 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
1856 , u132->going); 1847 , u132->going);
1857 return -ENODEV; 1848 return -ENODEV;
1858 } else if (u132->going > 0) { 1849 } else if (u132->going > 0) {
1859 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 1850 dev_err(&u132->platform_dev->dev, "device is being removed\n");
1860 return -ESHUTDOWN; 1851 return -ESHUTDOWN;
1861 } else { 1852 } else {
1862 int retval; 1853 int retval;
1863 mutex_lock(&u132->sw_lock); 1854 mutex_lock(&u132->sw_lock);
1864 retval = u132_init(u132); 1855 retval = u132_init(u132);
1865 if (retval) { 1856 if (retval) {
1866 u132_disable(u132); 1857 u132_disable(u132);
1867 u132->going = 1; 1858 u132->going = 1;
1868 } 1859 }
1869 mutex_unlock(&u132->sw_lock); 1860 mutex_unlock(&u132->sw_lock);
1870 return retval; 1861 return retval;
1871 } 1862 }
1872} 1863}
1873 1864
1874static int create_endpoint_and_queue_int(struct u132 *u132, 1865static int create_endpoint_and_queue_int(struct u132 *u132,
1875 struct u132_udev *udev, struct urb *urb, 1866 struct u132_udev *udev, struct urb *urb,
1876 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1867 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1877 gfp_t mem_flags) 1868 gfp_t mem_flags)
1878{ 1869{
1879 struct u132_ring *ring; 1870 struct u132_ring *ring;
1880 unsigned long irqs; 1871 unsigned long irqs;
1881 int rc; 1872 int rc;
1882 u8 endp_number; 1873 u8 endp_number;
1883 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 1874 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1884 1875
1885 if (!endp) { 1876 if (!endp)
1886 return -ENOMEM; 1877 return -ENOMEM;
1887 }
1888 1878
1889 spin_lock_init(&endp->queue_lock.slock); 1879 spin_lock_init(&endp->queue_lock.slock);
1890 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 1880 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -1897,94 +1887,93 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1897 1887
1898 endp_number = ++u132->num_endpoints; 1888 endp_number = ++u132->num_endpoints;
1899 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 1889 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1900 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1890 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1901 INIT_LIST_HEAD(&endp->urb_more); 1891 INIT_LIST_HEAD(&endp->urb_more);
1902 ring = endp->ring = &u132->ring[0]; 1892 ring = endp->ring = &u132->ring[0];
1903 if (ring->curr_endp) { 1893 if (ring->curr_endp) {
1904 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 1894 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
1905 } else { 1895 } else {
1906 INIT_LIST_HEAD(&endp->endp_ring); 1896 INIT_LIST_HEAD(&endp->endp_ring);
1907 ring->curr_endp = endp; 1897 ring->curr_endp = endp;
1908 } 1898 }
1909 ring->length += 1; 1899 ring->length += 1;
1910 endp->dequeueing = 0; 1900 endp->dequeueing = 0;
1911 endp->edset_flush = 0; 1901 endp->edset_flush = 0;
1912 endp->active = 0; 1902 endp->active = 0;
1913 endp->delayed = 0; 1903 endp->delayed = 0;
1914 endp->endp_number = endp_number; 1904 endp->endp_number = endp_number;
1915 endp->u132 = u132; 1905 endp->u132 = u132;
1916 endp->hep = urb->ep; 1906 endp->hep = urb->ep;
1917 endp->pipetype = usb_pipetype(urb->pipe); 1907 endp->pipetype = usb_pipetype(urb->pipe);
1918 u132_endp_init_kref(u132, endp); 1908 u132_endp_init_kref(u132, endp);
1919 if (usb_pipein(urb->pipe)) { 1909 if (usb_pipein(urb->pipe)) {
1920 endp->toggle_bits = 0x2; 1910 endp->toggle_bits = 0x2;
1921 usb_settoggle(udev->usb_device, usb_endp, 0, 0); 1911 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
1922 endp->input = 1; 1912 endp->input = 1;
1923 endp->output = 0; 1913 endp->output = 0;
1924 udev->endp_number_in[usb_endp] = endp_number; 1914 udev->endp_number_in[usb_endp] = endp_number;
1925 u132_udev_get_kref(u132, udev); 1915 u132_udev_get_kref(u132, udev);
1926 } else { 1916 } else {
1927 endp->toggle_bits = 0x2; 1917 endp->toggle_bits = 0x2;
1928 usb_settoggle(udev->usb_device, usb_endp, 1, 0); 1918 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
1929 endp->input = 0; 1919 endp->input = 0;
1930 endp->output = 1; 1920 endp->output = 1;
1931 udev->endp_number_out[usb_endp] = endp_number; 1921 udev->endp_number_out[usb_endp] = endp_number;
1932 u132_udev_get_kref(u132, udev); 1922 u132_udev_get_kref(u132, udev);
1933 } 1923 }
1934 urb->hcpriv = u132; 1924 urb->hcpriv = u132;
1935 endp->delayed = 1; 1925 endp->delayed = 1;
1936 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1926 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1937 endp->udev_number = address; 1927 endp->udev_number = address;
1938 endp->usb_addr = usb_addr; 1928 endp->usb_addr = usb_addr;
1939 endp->usb_endp = usb_endp; 1929 endp->usb_endp = usb_endp;
1940 endp->queue_size = 1; 1930 endp->queue_size = 1;
1941 endp->queue_last = 0; 1931 endp->queue_last = 0;
1942 endp->queue_next = 0; 1932 endp->queue_next = 0;
1943 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 1933 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1944 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 1934 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1945 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval)); 1935 u132_endp_queue_work(u132, endp, msecs_to_jiffies(urb->interval));
1946 return 0; 1936 return 0;
1947} 1937}
1948 1938
1949static int queue_int_on_old_endpoint(struct u132 *u132, 1939static int queue_int_on_old_endpoint(struct u132 *u132,
1950 struct u132_udev *udev, struct urb *urb, 1940 struct u132_udev *udev, struct urb *urb,
1951 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 1941 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1952 u8 usb_endp, u8 address) 1942 u8 usb_endp, u8 address)
1953{ 1943{
1954 urb->hcpriv = u132; 1944 urb->hcpriv = u132;
1955 endp->delayed = 1; 1945 endp->delayed = 1;
1956 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1946 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1957 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 1947 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
1958 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 1948 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
1959 } else { 1949 } else {
1960 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), 1950 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
1961 GFP_ATOMIC); 1951 GFP_ATOMIC);
1962 if (urbq == NULL) { 1952 if (urbq == NULL) {
1963 endp->queue_size -= 1; 1953 endp->queue_size -= 1;
1964 return -ENOMEM; 1954 return -ENOMEM;
1965 } else { 1955 } else {
1966 list_add_tail(&urbq->urb_more, &endp->urb_more); 1956 list_add_tail(&urbq->urb_more, &endp->urb_more);
1967 urbq->urb = urb; 1957 urbq->urb = urb;
1968 } 1958 }
1969 } 1959 }
1970 return 0; 1960 return 0;
1971} 1961}
1972 1962
1973static int create_endpoint_and_queue_bulk(struct u132 *u132, 1963static int create_endpoint_and_queue_bulk(struct u132 *u132,
1974 struct u132_udev *udev, struct urb *urb, 1964 struct u132_udev *udev, struct urb *urb,
1975 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1965 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1976 gfp_t mem_flags) 1966 gfp_t mem_flags)
1977{ 1967{
1978 int ring_number; 1968 int ring_number;
1979 struct u132_ring *ring; 1969 struct u132_ring *ring;
1980 unsigned long irqs; 1970 unsigned long irqs;
1981 int rc; 1971 int rc;
1982 u8 endp_number; 1972 u8 endp_number;
1983 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 1973 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1984 1974
1985 if (!endp) { 1975 if (!endp)
1986 return -ENOMEM; 1976 return -ENOMEM;
1987 }
1988 1977
1989 spin_lock_init(&endp->queue_lock.slock); 1978 spin_lock_init(&endp->queue_lock.slock);
1990 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 1979 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -1997,91 +1986,90 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
1997 1986
1998 endp_number = ++u132->num_endpoints; 1987 endp_number = ++u132->num_endpoints;
1999 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 1988 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2000 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1989 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2001 INIT_LIST_HEAD(&endp->urb_more); 1990 INIT_LIST_HEAD(&endp->urb_more);
2002 endp->dequeueing = 0; 1991 endp->dequeueing = 0;
2003 endp->edset_flush = 0; 1992 endp->edset_flush = 0;
2004 endp->active = 0; 1993 endp->active = 0;
2005 endp->delayed = 0; 1994 endp->delayed = 0;
2006 endp->endp_number = endp_number; 1995 endp->endp_number = endp_number;
2007 endp->u132 = u132; 1996 endp->u132 = u132;
2008 endp->hep = urb->ep; 1997 endp->hep = urb->ep;
2009 endp->pipetype = usb_pipetype(urb->pipe); 1998 endp->pipetype = usb_pipetype(urb->pipe);
2010 u132_endp_init_kref(u132, endp); 1999 u132_endp_init_kref(u132, endp);
2011 if (usb_pipein(urb->pipe)) { 2000 if (usb_pipein(urb->pipe)) {
2012 endp->toggle_bits = 0x2; 2001 endp->toggle_bits = 0x2;
2013 usb_settoggle(udev->usb_device, usb_endp, 0, 0); 2002 usb_settoggle(udev->usb_device, usb_endp, 0, 0);
2014 ring_number = 3; 2003 ring_number = 3;
2015 endp->input = 1; 2004 endp->input = 1;
2016 endp->output = 0; 2005 endp->output = 0;
2017 udev->endp_number_in[usb_endp] = endp_number; 2006 udev->endp_number_in[usb_endp] = endp_number;
2018 u132_udev_get_kref(u132, udev); 2007 u132_udev_get_kref(u132, udev);
2019 } else { 2008 } else {
2020 endp->toggle_bits = 0x2; 2009 endp->toggle_bits = 0x2;
2021 usb_settoggle(udev->usb_device, usb_endp, 1, 0); 2010 usb_settoggle(udev->usb_device, usb_endp, 1, 0);
2022 ring_number = 2; 2011 ring_number = 2;
2023 endp->input = 0; 2012 endp->input = 0;
2024 endp->output = 1; 2013 endp->output = 1;
2025 udev->endp_number_out[usb_endp] = endp_number; 2014 udev->endp_number_out[usb_endp] = endp_number;
2026 u132_udev_get_kref(u132, udev); 2015 u132_udev_get_kref(u132, udev);
2027 } 2016 }
2028 ring = endp->ring = &u132->ring[ring_number - 1]; 2017 ring = endp->ring = &u132->ring[ring_number - 1];
2029 if (ring->curr_endp) { 2018 if (ring->curr_endp) {
2030 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 2019 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2031 } else { 2020 } else {
2032 INIT_LIST_HEAD(&endp->endp_ring); 2021 INIT_LIST_HEAD(&endp->endp_ring);
2033 ring->curr_endp = endp; 2022 ring->curr_endp = endp;
2034 } 2023 }
2035 ring->length += 1; 2024 ring->length += 1;
2036 urb->hcpriv = u132; 2025 urb->hcpriv = u132;
2037 endp->udev_number = address; 2026 endp->udev_number = address;
2038 endp->usb_addr = usb_addr; 2027 endp->usb_addr = usb_addr;
2039 endp->usb_endp = usb_endp; 2028 endp->usb_endp = usb_endp;
2040 endp->queue_size = 1; 2029 endp->queue_size = 1;
2041 endp->queue_last = 0; 2030 endp->queue_last = 0;
2042 endp->queue_next = 0; 2031 endp->queue_next = 0;
2043 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2032 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2044 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2033 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2045 u132_endp_queue_work(u132, endp, 0); 2034 u132_endp_queue_work(u132, endp, 0);
2046 return 0; 2035 return 0;
2047} 2036}
2048 2037
2049static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 2038static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2050 struct urb *urb, 2039 struct urb *urb,
2051 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2040 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2052 u8 usb_endp, u8 address) 2041 u8 usb_endp, u8 address)
2053{ 2042{
2054 urb->hcpriv = u132; 2043 urb->hcpriv = u132;
2055 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2044 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2056 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2045 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2057 } else { 2046 } else {
2058 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq), 2047 struct u132_urbq *urbq = kmalloc(sizeof(struct u132_urbq),
2059 GFP_ATOMIC); 2048 GFP_ATOMIC);
2060 if (urbq == NULL) { 2049 if (urbq == NULL) {
2061 endp->queue_size -= 1; 2050 endp->queue_size -= 1;
2062 return -ENOMEM; 2051 return -ENOMEM;
2063 } else { 2052 } else {
2064 list_add_tail(&urbq->urb_more, &endp->urb_more); 2053 list_add_tail(&urbq->urb_more, &endp->urb_more);
2065 urbq->urb = urb; 2054 urbq->urb = urb;
2066 } 2055 }
2067 } 2056 }
2068 return 0; 2057 return 0;
2069} 2058}
2070 2059
2071static int create_endpoint_and_queue_control(struct u132 *u132, 2060static int create_endpoint_and_queue_control(struct u132 *u132,
2072 struct urb *urb, 2061 struct urb *urb,
2073 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, 2062 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2074 gfp_t mem_flags) 2063 gfp_t mem_flags)
2075{ 2064{
2076 struct u132_ring *ring; 2065 struct u132_ring *ring;
2077 unsigned long irqs; 2066 unsigned long irqs;
2078 int rc; 2067 int rc;
2079 u8 endp_number; 2068 u8 endp_number;
2080 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags); 2069 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2081 2070
2082 if (!endp) { 2071 if (!endp)
2083 return -ENOMEM; 2072 return -ENOMEM;
2084 }
2085 2073
2086 spin_lock_init(&endp->queue_lock.slock); 2074 spin_lock_init(&endp->queue_lock.slock);
2087 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2075 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
@@ -2094,204 +2082,203 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2094 2082
2095 endp_number = ++u132->num_endpoints; 2083 endp_number = ++u132->num_endpoints;
2096 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp; 2084 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2097 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2085 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2098 INIT_LIST_HEAD(&endp->urb_more); 2086 INIT_LIST_HEAD(&endp->urb_more);
2099 ring = endp->ring = &u132->ring[0]; 2087 ring = endp->ring = &u132->ring[0];
2100 if (ring->curr_endp) { 2088 if (ring->curr_endp) {
2101 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring); 2089 list_add_tail(&endp->endp_ring, &ring->curr_endp->endp_ring);
2102 } else { 2090 } else {
2103 INIT_LIST_HEAD(&endp->endp_ring); 2091 INIT_LIST_HEAD(&endp->endp_ring);
2104 ring->curr_endp = endp; 2092 ring->curr_endp = endp;
2105 } 2093 }
2106 ring->length += 1; 2094 ring->length += 1;
2107 endp->dequeueing = 0; 2095 endp->dequeueing = 0;
2108 endp->edset_flush = 0; 2096 endp->edset_flush = 0;
2109 endp->active = 0; 2097 endp->active = 0;
2110 endp->delayed = 0; 2098 endp->delayed = 0;
2111 endp->endp_number = endp_number; 2099 endp->endp_number = endp_number;
2112 endp->u132 = u132; 2100 endp->u132 = u132;
2113 endp->hep = urb->ep; 2101 endp->hep = urb->ep;
2114 u132_endp_init_kref(u132, endp); 2102 u132_endp_init_kref(u132, endp);
2115 u132_endp_get_kref(u132, endp); 2103 u132_endp_get_kref(u132, endp);
2116 if (usb_addr == 0) { 2104 if (usb_addr == 0) {
2117 u8 address = u132->addr[usb_addr].address; 2105 u8 address = u132->addr[usb_addr].address;
2118 struct u132_udev *udev = &u132->udev[address]; 2106 struct u132_udev *udev = &u132->udev[address];
2119 endp->udev_number = address; 2107 endp->udev_number = address;
2120 endp->usb_addr = usb_addr; 2108 endp->usb_addr = usb_addr;
2121 endp->usb_endp = usb_endp; 2109 endp->usb_endp = usb_endp;
2122 endp->input = 1; 2110 endp->input = 1;
2123 endp->output = 1; 2111 endp->output = 1;
2124 endp->pipetype = usb_pipetype(urb->pipe); 2112 endp->pipetype = usb_pipetype(urb->pipe);
2125 u132_udev_init_kref(u132, udev); 2113 u132_udev_init_kref(u132, udev);
2126 u132_udev_get_kref(u132, udev); 2114 u132_udev_get_kref(u132, udev);
2127 udev->endp_number_in[usb_endp] = endp_number; 2115 udev->endp_number_in[usb_endp] = endp_number;
2128 udev->endp_number_out[usb_endp] = endp_number; 2116 udev->endp_number_out[usb_endp] = endp_number;
2129 urb->hcpriv = u132; 2117 urb->hcpriv = u132;
2130 endp->queue_size = 1; 2118 endp->queue_size = 1;
2131 endp->queue_last = 0; 2119 endp->queue_last = 0;
2132 endp->queue_next = 0; 2120 endp->queue_next = 0;
2133 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2121 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2134 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2122 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2135 u132_endp_queue_work(u132, endp, 0); 2123 u132_endp_queue_work(u132, endp, 0);
2136 return 0; 2124 return 0;
2137 } else { /*(usb_addr > 0) */ 2125 } else { /*(usb_addr > 0) */
2138 u8 address = u132->addr[usb_addr].address; 2126 u8 address = u132->addr[usb_addr].address;
2139 struct u132_udev *udev = &u132->udev[address]; 2127 struct u132_udev *udev = &u132->udev[address];
2140 endp->udev_number = address; 2128 endp->udev_number = address;
2141 endp->usb_addr = usb_addr; 2129 endp->usb_addr = usb_addr;
2142 endp->usb_endp = usb_endp; 2130 endp->usb_endp = usb_endp;
2143 endp->input = 1; 2131 endp->input = 1;
2144 endp->output = 1; 2132 endp->output = 1;
2145 endp->pipetype = usb_pipetype(urb->pipe); 2133 endp->pipetype = usb_pipetype(urb->pipe);
2146 u132_udev_get_kref(u132, udev); 2134 u132_udev_get_kref(u132, udev);
2147 udev->enumeration = 2; 2135 udev->enumeration = 2;
2148 udev->endp_number_in[usb_endp] = endp_number; 2136 udev->endp_number_in[usb_endp] = endp_number;
2149 udev->endp_number_out[usb_endp] = endp_number; 2137 udev->endp_number_out[usb_endp] = endp_number;
2150 urb->hcpriv = u132; 2138 urb->hcpriv = u132;
2151 endp->queue_size = 1; 2139 endp->queue_size = 1;
2152 endp->queue_last = 0; 2140 endp->queue_last = 0;
2153 endp->queue_next = 0; 2141 endp->queue_next = 0;
2154 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb; 2142 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = urb;
2155 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2143 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2156 u132_endp_queue_work(u132, endp, 0); 2144 u132_endp_queue_work(u132, endp, 0);
2157 return 0; 2145 return 0;
2158 } 2146 }
2159} 2147}
2160 2148
2161static int queue_control_on_old_endpoint(struct u132 *u132, 2149static int queue_control_on_old_endpoint(struct u132 *u132,
2162 struct urb *urb, 2150 struct urb *urb,
2163 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2151 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2164 u8 usb_endp) 2152 u8 usb_endp)
2165{ 2153{
2166 if (usb_addr == 0) { 2154 if (usb_addr == 0) {
2167 if (usb_pipein(urb->pipe)) { 2155 if (usb_pipein(urb->pipe)) {
2168 urb->hcpriv = u132; 2156 urb->hcpriv = u132;
2169 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2157 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2170 endp->urb_list[ENDP_QUEUE_MASK & 2158 endp->urb_list[ENDP_QUEUE_MASK &
2171 endp->queue_last++] = urb; 2159 endp->queue_last++] = urb;
2172 } else { 2160 } else {
2173 struct u132_urbq *urbq = 2161 struct u132_urbq *urbq =
2174 kmalloc(sizeof(struct u132_urbq), 2162 kmalloc(sizeof(struct u132_urbq),
2175 GFP_ATOMIC); 2163 GFP_ATOMIC);
2176 if (urbq == NULL) { 2164 if (urbq == NULL) {
2177 endp->queue_size -= 1; 2165 endp->queue_size -= 1;
2178 return -ENOMEM; 2166 return -ENOMEM;
2179 } else { 2167 } else {
2180 list_add_tail(&urbq->urb_more, 2168 list_add_tail(&urbq->urb_more,
2181 &endp->urb_more); 2169 &endp->urb_more);
2182 urbq->urb = urb; 2170 urbq->urb = urb;
2183 } 2171 }
2184 } 2172 }
2185 return 0; 2173 return 0;
2186 } else { /* usb_pipeout(urb->pipe) */ 2174 } else { /* usb_pipeout(urb->pipe) */
2187 struct u132_addr *addr = &u132->addr[usb_dev->devnum]; 2175 struct u132_addr *addr = &u132->addr[usb_dev->devnum];
2188 int I = MAX_U132_UDEVS; 2176 int I = MAX_U132_UDEVS;
2189 int i = 0; 2177 int i = 0;
2190 while (--I > 0) { 2178 while (--I > 0) {
2191 struct u132_udev *udev = &u132->udev[++i]; 2179 struct u132_udev *udev = &u132->udev[++i];
2192 if (udev->usb_device) { 2180 if (udev->usb_device) {
2193 continue; 2181 continue;
2194 } else { 2182 } else {
2195 udev->enumeration = 1; 2183 udev->enumeration = 1;
2196 u132->addr[0].address = i; 2184 u132->addr[0].address = i;
2197 endp->udev_number = i; 2185 endp->udev_number = i;
2198 udev->udev_number = i; 2186 udev->udev_number = i;
2199 udev->usb_addr = usb_dev->devnum; 2187 udev->usb_addr = usb_dev->devnum;
2200 u132_udev_init_kref(u132, udev); 2188 u132_udev_init_kref(u132, udev);
2201 udev->endp_number_in[usb_endp] = 2189 udev->endp_number_in[usb_endp] =
2202 endp->endp_number; 2190 endp->endp_number;
2203 u132_udev_get_kref(u132, udev); 2191 u132_udev_get_kref(u132, udev);
2204 udev->endp_number_out[usb_endp] = 2192 udev->endp_number_out[usb_endp] =
2205 endp->endp_number; 2193 endp->endp_number;
2206 udev->usb_device = usb_dev; 2194 udev->usb_device = usb_dev;
2207 ((u8 *) (urb->setup_packet))[2] = 2195 ((u8 *) (urb->setup_packet))[2] =
2208 addr->address = i; 2196 addr->address = i;
2209 u132_udev_get_kref(u132, udev); 2197 u132_udev_get_kref(u132, udev);
2210 break; 2198 break;
2211 } 2199 }
2212 } 2200 }
2213 if (I == 0) { 2201 if (I == 0) {
2214 dev_err(&u132->platform_dev->dev, "run out of d" 2202 dev_err(&u132->platform_dev->dev, "run out of d"
2215 "evice space\n"); 2203 "evice space\n");
2216 return -EINVAL; 2204 return -EINVAL;
2217 } 2205 }
2218 urb->hcpriv = u132; 2206 urb->hcpriv = u132;
2219 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2207 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2220 endp->urb_list[ENDP_QUEUE_MASK & 2208 endp->urb_list[ENDP_QUEUE_MASK &
2221 endp->queue_last++] = urb; 2209 endp->queue_last++] = urb;
2222 } else { 2210 } else {
2223 struct u132_urbq *urbq = 2211 struct u132_urbq *urbq =
2224 kmalloc(sizeof(struct u132_urbq), 2212 kmalloc(sizeof(struct u132_urbq),
2225 GFP_ATOMIC); 2213 GFP_ATOMIC);
2226 if (urbq == NULL) { 2214 if (urbq == NULL) {
2227 endp->queue_size -= 1; 2215 endp->queue_size -= 1;
2228 return -ENOMEM; 2216 return -ENOMEM;
2229 } else { 2217 } else {
2230 list_add_tail(&urbq->urb_more, 2218 list_add_tail(&urbq->urb_more,
2231 &endp->urb_more); 2219 &endp->urb_more);
2232 urbq->urb = urb; 2220 urbq->urb = urb;
2233 } 2221 }
2234 } 2222 }
2235 return 0; 2223 return 0;
2236 } 2224 }
2237 } else { /*(usb_addr > 0) */ 2225 } else { /*(usb_addr > 0) */
2238 u8 address = u132->addr[usb_addr].address; 2226 u8 address = u132->addr[usb_addr].address;
2239 struct u132_udev *udev = &u132->udev[address]; 2227 struct u132_udev *udev = &u132->udev[address];
2240 urb->hcpriv = u132; 2228 urb->hcpriv = u132;
2241 if (udev->enumeration == 2) { 2229 if (udev->enumeration != 2)
2242 } else 2230 udev->enumeration = 2;
2243 udev->enumeration = 2; 2231 if (endp->queue_size++ < ENDP_QUEUE_SIZE) {
2244 if (endp->queue_size++ < ENDP_QUEUE_SIZE) { 2232 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] =
2245 endp->urb_list[ENDP_QUEUE_MASK & endp->queue_last++] = 2233 urb;
2246 urb; 2234 } else {
2247 } else { 2235 struct u132_urbq *urbq =
2248 struct u132_urbq *urbq = 2236 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC);
2249 kmalloc(sizeof(struct u132_urbq), GFP_ATOMIC); 2237 if (urbq == NULL) {
2250 if (urbq == NULL) { 2238 endp->queue_size -= 1;
2251 endp->queue_size -= 1; 2239 return -ENOMEM;
2252 return -ENOMEM; 2240 } else {
2253 } else { 2241 list_add_tail(&urbq->urb_more, &endp->urb_more);
2254 list_add_tail(&urbq->urb_more, &endp->urb_more); 2242 urbq->urb = urb;
2255 urbq->urb = urb; 2243 }
2256 } 2244 }
2257 } 2245 return 0;
2258 return 0; 2246 }
2259 }
2260} 2247}
2261 2248
2262static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, 2249static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2263 gfp_t mem_flags) 2250 gfp_t mem_flags)
2264{ 2251{
2265 struct u132 *u132 = hcd_to_u132(hcd); 2252 struct u132 *u132 = hcd_to_u132(hcd);
2266 if (irqs_disabled()) { 2253 if (irqs_disabled()) {
2267 if (__GFP_WAIT & mem_flags) { 2254 if (__GFP_WAIT & mem_flags) {
2268 printk(KERN_ERR "invalid context for function that migh" 2255 printk(KERN_ERR "invalid context for function that migh"
2269 "t sleep\n"); 2256 "t sleep\n");
2270 return -EINVAL; 2257 return -EINVAL;
2271 } 2258 }
2272 } 2259 }
2273 if (u132->going > 1) { 2260 if (u132->going > 1) {
2274 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2261 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2275 , u132->going); 2262 , u132->going);
2276 return -ENODEV; 2263 return -ENODEV;
2277 } else if (u132->going > 0) { 2264 } else if (u132->going > 0) {
2278 dev_err(&u132->platform_dev->dev, "device is being removed " 2265 dev_err(&u132->platform_dev->dev, "device is being removed "
2279 "urb=%p\n", urb); 2266 "urb=%p\n", urb);
2280 return -ESHUTDOWN; 2267 return -ESHUTDOWN;
2281 } else { 2268 } else {
2282 u8 usb_addr = usb_pipedevice(urb->pipe); 2269 u8 usb_addr = usb_pipedevice(urb->pipe);
2283 u8 usb_endp = usb_pipeendpoint(urb->pipe); 2270 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2284 struct usb_device *usb_dev = urb->dev; 2271 struct usb_device *usb_dev = urb->dev;
2285 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 2272 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2286 u8 address = u132->addr[usb_addr].address; 2273 u8 address = u132->addr[usb_addr].address;
2287 struct u132_udev *udev = &u132->udev[address]; 2274 struct u132_udev *udev = &u132->udev[address];
2288 struct u132_endp *endp = urb->ep->hcpriv; 2275 struct u132_endp *endp = urb->ep->hcpriv;
2289 urb->actual_length = 0; 2276 urb->actual_length = 0;
2290 if (endp) { 2277 if (endp) {
2291 unsigned long irqs; 2278 unsigned long irqs;
2292 int retval; 2279 int retval;
2293 spin_lock_irqsave(&endp->queue_lock.slock, 2280 spin_lock_irqsave(&endp->queue_lock.slock,
2294 irqs); 2281 irqs);
2295 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2282 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2296 if (retval == 0) { 2283 if (retval == 0) {
2297 retval = queue_int_on_old_endpoint( 2284 retval = queue_int_on_old_endpoint(
@@ -2301,39 +2288,39 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2301 address); 2288 address);
2302 if (retval) 2289 if (retval)
2303 usb_hcd_unlink_urb_from_ep( 2290 usb_hcd_unlink_urb_from_ep(
2304 hcd, urb); 2291 hcd, urb);
2292 }
2293 spin_unlock_irqrestore(&endp->queue_lock.slock,
2294 irqs);
2295 if (retval) {
2296 return retval;
2297 } else {
2298 u132_endp_queue_work(u132, endp,
2299 msecs_to_jiffies(urb->interval))
2300 ;
2301 return 0;
2305 } 2302 }
2306 spin_unlock_irqrestore(&endp->queue_lock.slock, 2303 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2307 irqs); 2304 return -EINVAL;
2308 if (retval) { 2305 } else { /*(endp == NULL) */
2309 return retval; 2306 return create_endpoint_and_queue_int(u132, udev,
2310 } else {
2311 u132_endp_queue_work(u132, endp,
2312 msecs_to_jiffies(urb->interval))
2313 ;
2314 return 0;
2315 }
2316 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2317 return -EINVAL;
2318 } else { /*(endp == NULL) */
2319 return create_endpoint_and_queue_int(u132, udev,
2320 urb, usb_dev, usb_addr, 2307 urb, usb_dev, usb_addr,
2321 usb_endp, address, mem_flags); 2308 usb_endp, address, mem_flags);
2322 } 2309 }
2323 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { 2310 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2324 dev_err(&u132->platform_dev->dev, "the hardware does no" 2311 dev_err(&u132->platform_dev->dev, "the hardware does no"
2325 "t support PIPE_ISOCHRONOUS\n"); 2312 "t support PIPE_ISOCHRONOUS\n");
2326 return -EINVAL; 2313 return -EINVAL;
2327 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { 2314 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2328 u8 address = u132->addr[usb_addr].address; 2315 u8 address = u132->addr[usb_addr].address;
2329 struct u132_udev *udev = &u132->udev[address]; 2316 struct u132_udev *udev = &u132->udev[address];
2330 struct u132_endp *endp = urb->ep->hcpriv; 2317 struct u132_endp *endp = urb->ep->hcpriv;
2331 urb->actual_length = 0; 2318 urb->actual_length = 0;
2332 if (endp) { 2319 if (endp) {
2333 unsigned long irqs; 2320 unsigned long irqs;
2334 int retval; 2321 int retval;
2335 spin_lock_irqsave(&endp->queue_lock.slock, 2322 spin_lock_irqsave(&endp->queue_lock.slock,
2336 irqs); 2323 irqs);
2337 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2324 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2338 if (retval == 0) { 2325 if (retval == 0) {
2339 retval = queue_bulk_on_old_endpoint( 2326 retval = queue_bulk_on_old_endpoint(
@@ -2343,46 +2330,46 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2343 address); 2330 address);
2344 if (retval) 2331 if (retval)
2345 usb_hcd_unlink_urb_from_ep( 2332 usb_hcd_unlink_urb_from_ep(
2346 hcd, urb); 2333 hcd, urb);
2334 }
2335 spin_unlock_irqrestore(&endp->queue_lock.slock,
2336 irqs);
2337 if (retval) {
2338 return retval;
2339 } else {
2340 u132_endp_queue_work(u132, endp, 0);
2341 return 0;
2347 } 2342 }
2348 spin_unlock_irqrestore(&endp->queue_lock.slock, 2343 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2349 irqs); 2344 return -EINVAL;
2350 if (retval) { 2345 } else
2351 return retval; 2346 return create_endpoint_and_queue_bulk(u132,
2352 } else {
2353 u132_endp_queue_work(u132, endp, 0);
2354 return 0;
2355 }
2356 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2357 return -EINVAL;
2358 } else
2359 return create_endpoint_and_queue_bulk(u132,
2360 udev, urb, usb_dev, usb_addr, 2347 udev, urb, usb_dev, usb_addr,
2361 usb_endp, address, mem_flags); 2348 usb_endp, address, mem_flags);
2362 } else { 2349 } else {
2363 struct u132_endp *endp = urb->ep->hcpriv; 2350 struct u132_endp *endp = urb->ep->hcpriv;
2364 u16 urb_size = 8; 2351 u16 urb_size = 8;
2365 u8 *b = urb->setup_packet; 2352 u8 *b = urb->setup_packet;
2366 int i = 0; 2353 int i = 0;
2367 char data[30 *3 + 4]; 2354 char data[30 * 3 + 4];
2368 char *d = data; 2355 char *d = data;
2369 int m = (sizeof(data) - 1) / 3; 2356 int m = (sizeof(data) - 1) / 3;
2370 int l = 0; 2357 int l = 0;
2371 data[0] = 0; 2358 data[0] = 0;
2372 while (urb_size-- > 0) { 2359 while (urb_size-- > 0) {
2373 if (i > m) { 2360 if (i > m) {
2374 } else if (i++ < m) { 2361 } else if (i++ < m) {
2375 int w = sprintf(d, " %02X", *b++); 2362 int w = sprintf(d, " %02X", *b++);
2376 d += w; 2363 d += w;
2377 l += w; 2364 l += w;
2378 } else 2365 } else
2379 d += sprintf(d, " .."); 2366 d += sprintf(d, " ..");
2380 } 2367 }
2381 if (endp) { 2368 if (endp) {
2382 unsigned long irqs; 2369 unsigned long irqs;
2383 int retval; 2370 int retval;
2384 spin_lock_irqsave(&endp->queue_lock.slock, 2371 spin_lock_irqsave(&endp->queue_lock.slock,
2385 irqs); 2372 irqs);
2386 retval = usb_hcd_link_urb_to_ep(hcd, urb); 2373 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2387 if (retval == 0) { 2374 if (retval == 0) {
2388 retval = queue_control_on_old_endpoint( 2375 retval = queue_control_on_old_endpoint(
@@ -2393,267 +2380,267 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2393 usb_hcd_unlink_urb_from_ep( 2380 usb_hcd_unlink_urb_from_ep(
2394 hcd, urb); 2381 hcd, urb);
2395 } 2382 }
2396 spin_unlock_irqrestore(&endp->queue_lock.slock, 2383 spin_unlock_irqrestore(&endp->queue_lock.slock,
2397 irqs); 2384 irqs);
2398 if (retval) { 2385 if (retval) {
2399 return retval; 2386 return retval;
2400 } else { 2387 } else {
2401 u132_endp_queue_work(u132, endp, 0); 2388 u132_endp_queue_work(u132, endp, 0);
2402 return 0; 2389 return 0;
2403 } 2390 }
2404 } else if (u132->num_endpoints == MAX_U132_ENDPS) { 2391 } else if (u132->num_endpoints == MAX_U132_ENDPS) {
2405 return -EINVAL; 2392 return -EINVAL;
2406 } else 2393 } else
2407 return create_endpoint_and_queue_control(u132, 2394 return create_endpoint_and_queue_control(u132,
2408 urb, usb_dev, usb_addr, usb_endp, 2395 urb, usb_dev, usb_addr, usb_endp,
2409 mem_flags); 2396 mem_flags);
2410 } 2397 }
2411 } 2398 }
2412} 2399}
2413 2400
2414static int dequeue_from_overflow_chain(struct u132 *u132, 2401static int dequeue_from_overflow_chain(struct u132 *u132,
2415 struct u132_endp *endp, struct urb *urb) 2402 struct u132_endp *endp, struct urb *urb)
2416{ 2403{
2417 struct list_head *scan; 2404 struct list_head *scan;
2418 struct list_head *head = &endp->urb_more; 2405 struct list_head *head = &endp->urb_more;
2419 list_for_each(scan, head) { 2406 list_for_each(scan, head) {
2420 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq, 2407 struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
2421 urb_more); 2408 urb_more);
2422 if (urbq->urb == urb) { 2409 if (urbq->urb == urb) {
2423 struct usb_hcd *hcd = u132_to_hcd(u132); 2410 struct usb_hcd *hcd = u132_to_hcd(u132);
2424 list_del(scan); 2411 list_del(scan);
2425 endp->queue_size -= 1; 2412 endp->queue_size -= 1;
2426 urb->error_count = 0; 2413 urb->error_count = 0;
2427 usb_hcd_giveback_urb(hcd, urb, 0); 2414 usb_hcd_giveback_urb(hcd, urb, 0);
2428 return 0; 2415 return 0;
2429 } else 2416 } else
2430 continue; 2417 continue;
2431 } 2418 }
2432 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring" 2419 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]=%p ring"
2433 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X" 2420 "[%d] %c%c usb_endp=%d usb_addr=%d size=%d next=%04X last=%04X"
2434 "\n", urb, endp->endp_number, endp, endp->ring->number, 2421 "\n", urb, endp->endp_number, endp, endp->ring->number,
2435 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', 2422 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2436 endp->usb_endp, endp->usb_addr, endp->queue_size, 2423 endp->usb_endp, endp->usb_addr, endp->queue_size,
2437 endp->queue_next, endp->queue_last); 2424 endp->queue_next, endp->queue_last);
2438 return -EINVAL; 2425 return -EINVAL;
2439} 2426}
2440 2427
2441static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, 2428static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2442 struct urb *urb, int status) 2429 struct urb *urb, int status)
2443{ 2430{
2444 unsigned long irqs; 2431 unsigned long irqs;
2445 int rc; 2432 int rc;
2446 2433
2447 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2434 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2448 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status); 2435 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2449 if (rc) { 2436 if (rc) {
2450 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2437 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2451 return rc; 2438 return rc;
2452 } 2439 }
2453 if (endp->queue_size == 0) { 2440 if (endp->queue_size == 0) {
2454 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" 2441 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2455 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, 2442 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
2456 endp->endp_number, endp, endp->ring->number, 2443 endp->endp_number, endp, endp->ring->number,
2457 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ', 2444 endp->input ? 'I' : ' ', endp->output ? 'O' : ' ',
2458 endp->usb_endp, endp->usb_addr); 2445 endp->usb_endp, endp->usb_addr);
2459 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2446 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2460 return -EINVAL; 2447 return -EINVAL;
2461 } 2448 }
2462 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) { 2449 if (urb == endp->urb_list[ENDP_QUEUE_MASK & endp->queue_next]) {
2463 if (endp->active) { 2450 if (endp->active) {
2464 endp->dequeueing = 1; 2451 endp->dequeueing = 1;
2465 endp->edset_flush = 1; 2452 endp->edset_flush = 1;
2466 u132_endp_queue_work(u132, endp, 0); 2453 u132_endp_queue_work(u132, endp, 0);
2467 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2454 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2468 return 0; 2455 return 0;
2469 } else { 2456 } else {
2470 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2457 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2471 u132_hcd_abandon_urb(u132, endp, urb, status); 2458 u132_hcd_abandon_urb(u132, endp, urb, status);
2472 return 0; 2459 return 0;
2473 } 2460 }
2474 } else { 2461 } else {
2475 u16 queue_list = 0; 2462 u16 queue_list = 0;
2476 u16 queue_size = endp->queue_size; 2463 u16 queue_size = endp->queue_size;
2477 u16 queue_scan = endp->queue_next; 2464 u16 queue_scan = endp->queue_next;
2478 struct urb **urb_slot = NULL; 2465 struct urb **urb_slot = NULL;
2479 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { 2466 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2480 if (urb == endp->urb_list[ENDP_QUEUE_MASK & 2467 if (urb == endp->urb_list[ENDP_QUEUE_MASK &
2481 ++queue_scan]) { 2468 ++queue_scan]) {
2482 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & 2469 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2483 queue_scan]; 2470 queue_scan];
2484 break; 2471 break;
2485 } else 2472 } else
2486 continue; 2473 continue;
2487 } 2474 }
2488 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) { 2475 while (++queue_list < ENDP_QUEUE_SIZE && --queue_size > 0) {
2489 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK & 2476 *urb_slot = endp->urb_list[ENDP_QUEUE_MASK &
2490 ++queue_scan]; 2477 ++queue_scan];
2491 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK & 2478 urb_slot = &endp->urb_list[ENDP_QUEUE_MASK &
2492 queue_scan]; 2479 queue_scan];
2493 } 2480 }
2494 if (urb_slot) { 2481 if (urb_slot) {
2495 struct usb_hcd *hcd = u132_to_hcd(u132); 2482 struct usb_hcd *hcd = u132_to_hcd(u132);
2496 2483
2497 usb_hcd_unlink_urb_from_ep(hcd, urb); 2484 usb_hcd_unlink_urb_from_ep(hcd, urb);
2498 endp->queue_size -= 1; 2485 endp->queue_size -= 1;
2499 if (list_empty(&endp->urb_more)) { 2486 if (list_empty(&endp->urb_more)) {
2500 spin_unlock_irqrestore(&endp->queue_lock.slock, 2487 spin_unlock_irqrestore(&endp->queue_lock.slock,
2501 irqs); 2488 irqs);
2502 } else { 2489 } else {
2503 struct list_head *next = endp->urb_more.next; 2490 struct list_head *next = endp->urb_more.next;
2504 struct u132_urbq *urbq = list_entry(next, 2491 struct u132_urbq *urbq = list_entry(next,
2505 struct u132_urbq, urb_more); 2492 struct u132_urbq, urb_more);
2506 list_del(next); 2493 list_del(next);
2507 *urb_slot = urbq->urb; 2494 *urb_slot = urbq->urb;
2508 spin_unlock_irqrestore(&endp->queue_lock.slock, 2495 spin_unlock_irqrestore(&endp->queue_lock.slock,
2509 irqs); 2496 irqs);
2510 kfree(urbq); 2497 kfree(urbq);
2511 } urb->error_count = 0; 2498 } urb->error_count = 0;
2512 usb_hcd_giveback_urb(hcd, urb, status); 2499 usb_hcd_giveback_urb(hcd, urb, status);
2513 return 0; 2500 return 0;
2514 } else if (list_empty(&endp->urb_more)) { 2501 } else if (list_empty(&endp->urb_more)) {
2515 dev_err(&u132->platform_dev->dev, "urb=%p not found in " 2502 dev_err(&u132->platform_dev->dev, "urb=%p not found in "
2516 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr" 2503 "endp[%d]=%p ring[%d] %c%c usb_endp=%d usb_addr"
2517 "=%d size=%d next=%04X last=%04X\n", urb, 2504 "=%d size=%d next=%04X last=%04X\n", urb,
2518 endp->endp_number, endp, endp->ring->number, 2505 endp->endp_number, endp, endp->ring->number,
2519 endp->input ? 'I' : ' ', 2506 endp->input ? 'I' : ' ',
2520 endp->output ? 'O' : ' ', endp->usb_endp, 2507 endp->output ? 'O' : ' ', endp->usb_endp,
2521 endp->usb_addr, endp->queue_size, 2508 endp->usb_addr, endp->queue_size,
2522 endp->queue_next, endp->queue_last); 2509 endp->queue_next, endp->queue_last);
2523 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2510 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2524 return -EINVAL; 2511 return -EINVAL;
2525 } else { 2512 } else {
2526 int retval; 2513 int retval;
2527 2514
2528 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb); 2515 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2529 retval = dequeue_from_overflow_chain(u132, endp, 2516 retval = dequeue_from_overflow_chain(u132, endp,
2530 urb); 2517 urb);
2531 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2518 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2532 return retval; 2519 return retval;
2533 } 2520 }
2534 } 2521 }
2535} 2522}
2536 2523
2537static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) 2524static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2538{ 2525{
2539 struct u132 *u132 = hcd_to_u132(hcd); 2526 struct u132 *u132 = hcd_to_u132(hcd);
2540 if (u132->going > 2) { 2527 if (u132->going > 2) {
2541 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2528 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2542 , u132->going); 2529 , u132->going);
2543 return -ENODEV; 2530 return -ENODEV;
2544 } else { 2531 } else {
2545 u8 usb_addr = usb_pipedevice(urb->pipe); 2532 u8 usb_addr = usb_pipedevice(urb->pipe);
2546 u8 usb_endp = usb_pipeendpoint(urb->pipe); 2533 u8 usb_endp = usb_pipeendpoint(urb->pipe);
2547 u8 address = u132->addr[usb_addr].address; 2534 u8 address = u132->addr[usb_addr].address;
2548 struct u132_udev *udev = &u132->udev[address]; 2535 struct u132_udev *udev = &u132->udev[address];
2549 if (usb_pipein(urb->pipe)) { 2536 if (usb_pipein(urb->pipe)) {
2550 u8 endp_number = udev->endp_number_in[usb_endp]; 2537 u8 endp_number = udev->endp_number_in[usb_endp];
2551 struct u132_endp *endp = u132->endp[endp_number - 1]; 2538 struct u132_endp *endp = u132->endp[endp_number - 1];
2552 return u132_endp_urb_dequeue(u132, endp, urb, status); 2539 return u132_endp_urb_dequeue(u132, endp, urb, status);
2553 } else { 2540 } else {
2554 u8 endp_number = udev->endp_number_out[usb_endp]; 2541 u8 endp_number = udev->endp_number_out[usb_endp];
2555 struct u132_endp *endp = u132->endp[endp_number - 1]; 2542 struct u132_endp *endp = u132->endp[endp_number - 1];
2556 return u132_endp_urb_dequeue(u132, endp, urb, status); 2543 return u132_endp_urb_dequeue(u132, endp, urb, status);
2557 } 2544 }
2558 } 2545 }
2559} 2546}
2560 2547
2561static void u132_endpoint_disable(struct usb_hcd *hcd, 2548static void u132_endpoint_disable(struct usb_hcd *hcd,
2562 struct usb_host_endpoint *hep) 2549 struct usb_host_endpoint *hep)
2563{ 2550{
2564 struct u132 *u132 = hcd_to_u132(hcd); 2551 struct u132 *u132 = hcd_to_u132(hcd);
2565 if (u132->going > 2) { 2552 if (u132->going > 2) {
2566 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p" 2553 dev_err(&u132->platform_dev->dev, "u132 device %p(hcd=%p hep=%p"
2567 ") has been removed %d\n", u132, hcd, hep, 2554 ") has been removed %d\n", u132, hcd, hep,
2568 u132->going); 2555 u132->going);
2569 } else { 2556 } else {
2570 struct u132_endp *endp = hep->hcpriv; 2557 struct u132_endp *endp = hep->hcpriv;
2571 if (endp) 2558 if (endp)
2572 u132_endp_put_kref(u132, endp); 2559 u132_endp_put_kref(u132, endp);
2573 } 2560 }
2574} 2561}
2575 2562
2576static int u132_get_frame(struct usb_hcd *hcd) 2563static int u132_get_frame(struct usb_hcd *hcd)
2577{ 2564{
2578 struct u132 *u132 = hcd_to_u132(hcd); 2565 struct u132 *u132 = hcd_to_u132(hcd);
2579 if (u132->going > 1) { 2566 if (u132->going > 1) {
2580 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2567 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2581 , u132->going); 2568 , u132->going);
2582 return -ENODEV; 2569 return -ENODEV;
2583 } else if (u132->going > 0) { 2570 } else if (u132->going > 0) {
2584 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2571 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2585 return -ESHUTDOWN; 2572 return -ESHUTDOWN;
2586 } else { 2573 } else {
2587 int frame = 0; 2574 int frame = 0;
2588 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n"); 2575 dev_err(&u132->platform_dev->dev, "TODO: u132_get_frame\n");
2589 msleep(100); 2576 msleep(100);
2590 return frame; 2577 return frame;
2591 } 2578 }
2592} 2579}
2593 2580
2594static int u132_roothub_descriptor(struct u132 *u132, 2581static int u132_roothub_descriptor(struct u132 *u132,
2595 struct usb_hub_descriptor *desc) 2582 struct usb_hub_descriptor *desc)
2596{ 2583{
2597 int retval; 2584 int retval;
2598 u16 temp; 2585 u16 temp;
2599 u32 rh_a = -1; 2586 u32 rh_a = -1;
2600 u32 rh_b = -1; 2587 u32 rh_b = -1;
2601 retval = u132_read_pcimem(u132, roothub.a, &rh_a); 2588 retval = u132_read_pcimem(u132, roothub.a, &rh_a);
2602 if (retval) 2589 if (retval)
2603 return retval; 2590 return retval;
2604 desc->bDescriptorType = 0x29; 2591 desc->bDescriptorType = 0x29;
2605 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24; 2592 desc->bPwrOn2PwrGood = (rh_a & RH_A_POTPGT) >> 24;
2606 desc->bHubContrCurrent = 0; 2593 desc->bHubContrCurrent = 0;
2607 desc->bNbrPorts = u132->num_ports; 2594 desc->bNbrPorts = u132->num_ports;
2608 temp = 1 + (u132->num_ports / 8); 2595 temp = 1 + (u132->num_ports / 8);
2609 desc->bDescLength = 7 + 2 *temp; 2596 desc->bDescLength = 7 + 2 * temp;
2610 temp = 0; 2597 temp = 0;
2611 if (rh_a & RH_A_NPS) 2598 if (rh_a & RH_A_NPS)
2612 temp |= 0x0002; 2599 temp |= 0x0002;
2613 if (rh_a & RH_A_PSM) 2600 if (rh_a & RH_A_PSM)
2614 temp |= 0x0001; 2601 temp |= 0x0001;
2615 if (rh_a & RH_A_NOCP) { 2602 if (rh_a & RH_A_NOCP)
2616 temp |= 0x0010; 2603 temp |= 0x0010;
2617 } else if (rh_a & RH_A_OCPM) 2604 else if (rh_a & RH_A_OCPM)
2618 temp |= 0x0008; 2605 temp |= 0x0008;
2619 desc->wHubCharacteristics = cpu_to_le16(temp); 2606 desc->wHubCharacteristics = cpu_to_le16(temp);
2620 retval = u132_read_pcimem(u132, roothub.b, &rh_b); 2607 retval = u132_read_pcimem(u132, roothub.b, &rh_b);
2621 if (retval) 2608 if (retval)
2622 return retval; 2609 return retval;
2623 memset(desc->bitmap, 0xff, sizeof(desc->bitmap)); 2610 memset(desc->bitmap, 0xff, sizeof(desc->bitmap));
2624 desc->bitmap[0] = rh_b & RH_B_DR; 2611 desc->bitmap[0] = rh_b & RH_B_DR;
2625 if (u132->num_ports > 7) { 2612 if (u132->num_ports > 7) {
2626 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8; 2613 desc->bitmap[1] = (rh_b & RH_B_DR) >> 8;
2627 desc->bitmap[2] = 0xff; 2614 desc->bitmap[2] = 0xff;
2628 } else 2615 } else
2629 desc->bitmap[1] = 0xff; 2616 desc->bitmap[1] = 0xff;
2630 return 0; 2617 return 0;
2631} 2618}
2632 2619
2633static int u132_roothub_status(struct u132 *u132, __le32 *desc) 2620static int u132_roothub_status(struct u132 *u132, __le32 *desc)
2634{ 2621{
2635 u32 rh_status = -1; 2622 u32 rh_status = -1;
2636 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status); 2623 int ret_status = u132_read_pcimem(u132, roothub.status, &rh_status);
2637 *desc = cpu_to_le32(rh_status); 2624 *desc = cpu_to_le32(rh_status);
2638 return ret_status; 2625 return ret_status;
2639} 2626}
2640 2627
2641static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex) 2628static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2642{ 2629{
2643 if (wIndex == 0 || wIndex > u132->num_ports) { 2630 if (wIndex == 0 || wIndex > u132->num_ports) {
2644 return -EINVAL; 2631 return -EINVAL;
2645 } else { 2632 } else {
2646 int port = wIndex - 1; 2633 int port = wIndex - 1;
2647 u32 rh_portstatus = -1; 2634 u32 rh_portstatus = -1;
2648 int ret_portstatus = u132_read_pcimem(u132, 2635 int ret_portstatus = u132_read_pcimem(u132,
2649 roothub.portstatus[port], &rh_portstatus); 2636 roothub.portstatus[port], &rh_portstatus);
2650 *desc = cpu_to_le32(rh_portstatus); 2637 *desc = cpu_to_le32(rh_portstatus);
2651 if (*(u16 *) (desc + 2)) { 2638 if (*(u16 *) (desc + 2)) {
2652 dev_info(&u132->platform_dev->dev, "Port %d Status Chan" 2639 dev_info(&u132->platform_dev->dev, "Port %d Status Chan"
2653 "ge = %08X\n", port, *desc); 2640 "ge = %08X\n", port, *desc);
2654 } 2641 }
2655 return ret_portstatus; 2642 return ret_portstatus;
2656 } 2643 }
2657} 2644}
2658 2645
2659 2646
@@ -2664,353 +2651,355 @@ static int u132_roothub_portstatus(struct u132 *u132, __le32 *desc, u16 wIndex)
2664#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0) 2651#define tick_before(t1, t2) ((s16)(((s16)(t1))-((s16)(t2))) < 0)
2665static int u132_roothub_portreset(struct u132 *u132, int port_index) 2652static int u132_roothub_portreset(struct u132 *u132, int port_index)
2666{ 2653{
2667 int retval; 2654 int retval;
2668 u32 fmnumber; 2655 u32 fmnumber;
2669 u16 now; 2656 u16 now;
2670 u16 reset_done; 2657 u16 reset_done;
2671 retval = u132_read_pcimem(u132, fmnumber, &fmnumber); 2658 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2672 if (retval) 2659 if (retval)
2673 return retval; 2660 return retval;
2674 now = fmnumber; 2661 now = fmnumber;
2675 reset_done = now + PORT_RESET_MSEC; 2662 reset_done = now + PORT_RESET_MSEC;
2676 do { 2663 do {
2677 u32 portstat; 2664 u32 portstat;
2678 do { 2665 do {
2679 retval = u132_read_pcimem(u132, 2666 retval = u132_read_pcimem(u132,
2680 roothub.portstatus[port_index], &portstat); 2667 roothub.portstatus[port_index], &portstat);
2681 if (retval) 2668 if (retval)
2682 return retval; 2669 return retval;
2683 if (RH_PS_PRS & portstat) { 2670 if (RH_PS_PRS & portstat)
2684 continue; 2671 continue;
2685 } else 2672 else
2686 break; 2673 break;
2687 } while (tick_before(now, reset_done)); 2674 } while (tick_before(now, reset_done));
2688 if (RH_PS_PRS & portstat) 2675 if (RH_PS_PRS & portstat)
2689 return -ENODEV; 2676 return -ENODEV;
2690 if (RH_PS_CCS & portstat) { 2677 if (RH_PS_CCS & portstat) {
2691 if (RH_PS_PRSC & portstat) { 2678 if (RH_PS_PRSC & portstat) {
2692 retval = u132_write_pcimem(u132, 2679 retval = u132_write_pcimem(u132,
2693 roothub.portstatus[port_index], 2680 roothub.portstatus[port_index],
2694 RH_PS_PRSC); 2681 RH_PS_PRSC);
2695 if (retval) 2682 if (retval)
2696 return retval; 2683 return retval;
2697 } 2684 }
2698 } else 2685 } else
2699 break; /* start the next reset, 2686 break; /* start the next reset,
2700 sleep till it's probably done */ 2687 sleep till it's probably done */
2701 retval = u132_write_pcimem(u132, roothub.portstatus[port_index], 2688 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2702 RH_PS_PRS); 2689 RH_PS_PRS);
2703 if (retval) 2690 if (retval)
2704 return retval; 2691 return retval;
2705 msleep(PORT_RESET_HW_MSEC); 2692 msleep(PORT_RESET_HW_MSEC);
2706 retval = u132_read_pcimem(u132, fmnumber, &fmnumber); 2693 retval = u132_read_pcimem(u132, fmnumber, &fmnumber);
2707 if (retval) 2694 if (retval)
2708 return retval; 2695 return retval;
2709 now = fmnumber; 2696 now = fmnumber;
2710 } while (tick_before(now, reset_done)); 2697 } while (tick_before(now, reset_done));
2711 return 0; 2698 return 0;
2712} 2699}
2713 2700
2714static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue, 2701static int u132_roothub_setportfeature(struct u132 *u132, u16 wValue,
2715 u16 wIndex) 2702 u16 wIndex)
2716{ 2703{
2717 if (wIndex == 0 || wIndex > u132->num_ports) { 2704 if (wIndex == 0 || wIndex > u132->num_ports) {
2718 return -EINVAL; 2705 return -EINVAL;
2719 } else { 2706 } else {
2720 int retval; 2707 int retval;
2721 int port_index = wIndex - 1; 2708 int port_index = wIndex - 1;
2722 struct u132_port *port = &u132->port[port_index]; 2709 struct u132_port *port = &u132->port[port_index];
2723 port->Status &= ~(1 << wValue); 2710 port->Status &= ~(1 << wValue);
2724 switch (wValue) { 2711 switch (wValue) {
2725 case USB_PORT_FEAT_SUSPEND: 2712 case USB_PORT_FEAT_SUSPEND:
2726 retval = u132_write_pcimem(u132, 2713 retval = u132_write_pcimem(u132,
2727 roothub.portstatus[port_index], RH_PS_PSS); 2714 roothub.portstatus[port_index], RH_PS_PSS);
2728 if (retval) 2715 if (retval)
2729 return retval; 2716 return retval;
2730 return 0; 2717 return 0;
2731 case USB_PORT_FEAT_POWER: 2718 case USB_PORT_FEAT_POWER:
2732 retval = u132_write_pcimem(u132, 2719 retval = u132_write_pcimem(u132,
2733 roothub.portstatus[port_index], RH_PS_PPS); 2720 roothub.portstatus[port_index], RH_PS_PPS);
2734 if (retval) 2721 if (retval)
2735 return retval; 2722 return retval;
2736 return 0; 2723 return 0;
2737 case USB_PORT_FEAT_RESET: 2724 case USB_PORT_FEAT_RESET:
2738 retval = u132_roothub_portreset(u132, port_index); 2725 retval = u132_roothub_portreset(u132, port_index);
2739 if (retval) 2726 if (retval)
2740 return retval; 2727 return retval;
2741 return 0; 2728 return 0;
2742 default: 2729 default:
2743 return -EPIPE; 2730 return -EPIPE;
2744 } 2731 }
2745 } 2732 }
2746} 2733}
2747 2734
2748static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue, 2735static int u132_roothub_clearportfeature(struct u132 *u132, u16 wValue,
2749 u16 wIndex) 2736 u16 wIndex)
2750{ 2737{
2751 if (wIndex == 0 || wIndex > u132->num_ports) { 2738 if (wIndex == 0 || wIndex > u132->num_ports) {
2752 return -EINVAL; 2739 return -EINVAL;
2753 } else { 2740 } else {
2754 int port_index = wIndex - 1; 2741 int port_index = wIndex - 1;
2755 u32 temp; 2742 u32 temp;
2756 int retval; 2743 int retval;
2757 struct u132_port *port = &u132->port[port_index]; 2744 struct u132_port *port = &u132->port[port_index];
2758 port->Status &= ~(1 << wValue); 2745 port->Status &= ~(1 << wValue);
2759 switch (wValue) { 2746 switch (wValue) {
2760 case USB_PORT_FEAT_ENABLE: 2747 case USB_PORT_FEAT_ENABLE:
2761 temp = RH_PS_CCS; 2748 temp = RH_PS_CCS;
2762 break; 2749 break;
2763 case USB_PORT_FEAT_C_ENABLE: 2750 case USB_PORT_FEAT_C_ENABLE:
2764 temp = RH_PS_PESC; 2751 temp = RH_PS_PESC;
2765 break; 2752 break;
2766 case USB_PORT_FEAT_SUSPEND: 2753 case USB_PORT_FEAT_SUSPEND:
2767 temp = RH_PS_POCI; 2754 temp = RH_PS_POCI;
2768 if ((u132->hc_control & OHCI_CTRL_HCFS) 2755 if ((u132->hc_control & OHCI_CTRL_HCFS)
2769 != OHCI_USB_OPER) { 2756 != OHCI_USB_OPER) {
2770 dev_err(&u132->platform_dev->dev, "TODO resume_" 2757 dev_err(&u132->platform_dev->dev, "TODO resume_"
2771 "root_hub\n"); 2758 "root_hub\n");
2772 } 2759 }
2773 break; 2760 break;
2774 case USB_PORT_FEAT_C_SUSPEND: 2761 case USB_PORT_FEAT_C_SUSPEND:
2775 temp = RH_PS_PSSC; 2762 temp = RH_PS_PSSC;
2776 break; 2763 break;
2777 case USB_PORT_FEAT_POWER: 2764 case USB_PORT_FEAT_POWER:
2778 temp = RH_PS_LSDA; 2765 temp = RH_PS_LSDA;
2779 break; 2766 break;
2780 case USB_PORT_FEAT_C_CONNECTION: 2767 case USB_PORT_FEAT_C_CONNECTION:
2781 temp = RH_PS_CSC; 2768 temp = RH_PS_CSC;
2782 break; 2769 break;
2783 case USB_PORT_FEAT_C_OVER_CURRENT: 2770 case USB_PORT_FEAT_C_OVER_CURRENT:
2784 temp = RH_PS_OCIC; 2771 temp = RH_PS_OCIC;
2785 break; 2772 break;
2786 case USB_PORT_FEAT_C_RESET: 2773 case USB_PORT_FEAT_C_RESET:
2787 temp = RH_PS_PRSC; 2774 temp = RH_PS_PRSC;
2788 break; 2775 break;
2789 default: 2776 default:
2790 return -EPIPE; 2777 return -EPIPE;
2791 } 2778 }
2792 retval = u132_write_pcimem(u132, roothub.portstatus[port_index], 2779 retval = u132_write_pcimem(u132, roothub.portstatus[port_index],
2793 temp); 2780 temp);
2794 if (retval) 2781 if (retval)
2795 return retval; 2782 return retval;
2796 return 0; 2783 return 0;
2797 } 2784 }
2798} 2785}
2799 2786
2800 2787
2801/* the virtual root hub timer IRQ checks for hub status*/ 2788/* the virtual root hub timer IRQ checks for hub status*/
2802static int u132_hub_status_data(struct usb_hcd *hcd, char *buf) 2789static int u132_hub_status_data(struct usb_hcd *hcd, char *buf)
2803{ 2790{
2804 struct u132 *u132 = hcd_to_u132(hcd); 2791 struct u132 *u132 = hcd_to_u132(hcd);
2805 if (u132->going > 1) { 2792 if (u132->going > 1) {
2806 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov" 2793 dev_err(&u132->platform_dev->dev, "device hcd=%p has been remov"
2807 "ed %d\n", hcd, u132->going); 2794 "ed %d\n", hcd, u132->going);
2808 return -ENODEV; 2795 return -ENODEV;
2809 } else if (u132->going > 0) { 2796 } else if (u132->going > 0) {
2810 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov" 2797 dev_err(&u132->platform_dev->dev, "device hcd=%p is being remov"
2811 "ed\n", hcd); 2798 "ed\n", hcd);
2812 return -ESHUTDOWN; 2799 return -ESHUTDOWN;
2813 } else { 2800 } else {
2814 int i, changed = 0, length = 1; 2801 int i, changed = 0, length = 1;
2815 if (u132->flags & OHCI_QUIRK_AMD756) { 2802 if (u132->flags & OHCI_QUIRK_AMD756) {
2816 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) { 2803 if ((u132->hc_roothub_a & RH_A_NDP) > MAX_ROOT_PORTS) {
2817 dev_err(&u132->platform_dev->dev, "bogus NDP, r" 2804 dev_err(&u132->platform_dev->dev, "bogus NDP, r"
2818 "ereads as NDP=%d\n", 2805 "ereads as NDP=%d\n",
2819 u132->hc_roothub_a & RH_A_NDP); 2806 u132->hc_roothub_a & RH_A_NDP);
2820 goto done; 2807 goto done;
2821 } 2808 }
2822 } 2809 }
2823 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC)) { 2810 if (u132->hc_roothub_status & (RH_HS_LPSC | RH_HS_OCIC))
2824 buf[0] = changed = 1; 2811 buf[0] = changed = 1;
2825 } else 2812 else
2826 buf[0] = 0; 2813 buf[0] = 0;
2827 if (u132->num_ports > 7) { 2814 if (u132->num_ports > 7) {
2828 buf[1] = 0; 2815 buf[1] = 0;
2829 length++; 2816 length++;
2830 } 2817 }
2831 for (i = 0; i < u132->num_ports; i++) { 2818 for (i = 0; i < u132->num_ports; i++) {
2832 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC | 2819 if (u132->hc_roothub_portstatus[i] & (RH_PS_CSC |
2833 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC | 2820 RH_PS_PESC | RH_PS_PSSC | RH_PS_OCIC |
2834 RH_PS_PRSC)) { 2821 RH_PS_PRSC)) {
2835 changed = 1; 2822 changed = 1;
2836 if (i < 7) { 2823 if (i < 7)
2837 buf[0] |= 1 << (i + 1); 2824 buf[0] |= 1 << (i + 1);
2838 } else 2825 else
2839 buf[1] |= 1 << (i - 7); 2826 buf[1] |= 1 << (i - 7);
2840 continue; 2827 continue;
2841 } 2828 }
2842 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS)) { 2829 if (!(u132->hc_roothub_portstatus[i] & RH_PS_CCS))
2843 continue; 2830 continue;
2844 } 2831
2845 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS)) { 2832 if ((u132->hc_roothub_portstatus[i] & RH_PS_PSS))
2846 continue; 2833 continue;
2847 } 2834 }
2848 } 2835done:
2849 done:return changed ? length : 0; 2836 return changed ? length : 0;
2850 } 2837 }
2851} 2838}
2852 2839
2853static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, 2840static int u132_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2854 u16 wIndex, char *buf, u16 wLength) 2841 u16 wIndex, char *buf, u16 wLength)
2855{ 2842{
2856 struct u132 *u132 = hcd_to_u132(hcd); 2843 struct u132 *u132 = hcd_to_u132(hcd);
2857 if (u132->going > 1) { 2844 if (u132->going > 1) {
2858 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2845 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2859 , u132->going); 2846 , u132->going);
2860 return -ENODEV; 2847 return -ENODEV;
2861 } else if (u132->going > 0) { 2848 } else if (u132->going > 0) {
2862 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2849 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2863 return -ESHUTDOWN; 2850 return -ESHUTDOWN;
2864 } else { 2851 } else {
2865 int retval = 0; 2852 int retval = 0;
2866 mutex_lock(&u132->sw_lock); 2853 mutex_lock(&u132->sw_lock);
2867 switch (typeReq) { 2854 switch (typeReq) {
2868 case ClearHubFeature: 2855 case ClearHubFeature:
2869 switch (wValue) { 2856 switch (wValue) {
2870 case C_HUB_OVER_CURRENT: 2857 case C_HUB_OVER_CURRENT:
2871 case C_HUB_LOCAL_POWER: 2858 case C_HUB_LOCAL_POWER:
2872 break; 2859 break;
2873 default: 2860 default:
2874 goto stall; 2861 goto stall;
2875 } 2862 }
2876 break; 2863 break;
2877 case SetHubFeature: 2864 case SetHubFeature:
2878 switch (wValue) { 2865 switch (wValue) {
2879 case C_HUB_OVER_CURRENT: 2866 case C_HUB_OVER_CURRENT:
2880 case C_HUB_LOCAL_POWER: 2867 case C_HUB_LOCAL_POWER:
2881 break; 2868 break;
2882 default: 2869 default:
2883 goto stall; 2870 goto stall;
2884 } 2871 }
2885 break; 2872 break;
2886 case ClearPortFeature:{ 2873 case ClearPortFeature:{
2887 retval = u132_roothub_clearportfeature(u132, 2874 retval = u132_roothub_clearportfeature(u132,
2888 wValue, wIndex); 2875 wValue, wIndex);
2889 if (retval) 2876 if (retval)
2890 goto error; 2877 goto error;
2891 break; 2878 break;
2892 } 2879 }
2893 case GetHubDescriptor:{ 2880 case GetHubDescriptor:{
2894 retval = u132_roothub_descriptor(u132, 2881 retval = u132_roothub_descriptor(u132,
2895 (struct usb_hub_descriptor *)buf); 2882 (struct usb_hub_descriptor *)buf);
2896 if (retval) 2883 if (retval)
2897 goto error; 2884 goto error;
2898 break; 2885 break;
2899 } 2886 }
2900 case GetHubStatus:{ 2887 case GetHubStatus:{
2901 retval = u132_roothub_status(u132, 2888 retval = u132_roothub_status(u132,
2902 (__le32 *) buf); 2889 (__le32 *) buf);
2903 if (retval) 2890 if (retval)
2904 goto error; 2891 goto error;
2905 break; 2892 break;
2906 } 2893 }
2907 case GetPortStatus:{ 2894 case GetPortStatus:{
2908 retval = u132_roothub_portstatus(u132, 2895 retval = u132_roothub_portstatus(u132,
2909 (__le32 *) buf, wIndex); 2896 (__le32 *) buf, wIndex);
2910 if (retval) 2897 if (retval)
2911 goto error; 2898 goto error;
2912 break; 2899 break;
2913 } 2900 }
2914 case SetPortFeature:{ 2901 case SetPortFeature:{
2915 retval = u132_roothub_setportfeature(u132, 2902 retval = u132_roothub_setportfeature(u132,
2916 wValue, wIndex); 2903 wValue, wIndex);
2917 if (retval) 2904 if (retval)
2918 goto error; 2905 goto error;
2919 break; 2906 break;
2920 } 2907 }
2921 default: 2908 default:
2922 goto stall; 2909 goto stall;
2923 error:u132_disable(u132); 2910 error:
2924 u132->going = 1; 2911 u132_disable(u132);
2925 break; 2912 u132->going = 1;
2926 stall:retval = -EPIPE; 2913 break;
2927 break; 2914 stall:
2928 } 2915 retval = -EPIPE;
2929 mutex_unlock(&u132->sw_lock); 2916 break;
2930 return retval; 2917 }
2931 } 2918 mutex_unlock(&u132->sw_lock);
2919 return retval;
2920 }
2932} 2921}
2933 2922
2934static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num) 2923static int u132_start_port_reset(struct usb_hcd *hcd, unsigned port_num)
2935{ 2924{
2936 struct u132 *u132 = hcd_to_u132(hcd); 2925 struct u132 *u132 = hcd_to_u132(hcd);
2937 if (u132->going > 1) { 2926 if (u132->going > 1) {
2938 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2927 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2939 , u132->going); 2928 , u132->going);
2940 return -ENODEV; 2929 return -ENODEV;
2941 } else if (u132->going > 0) { 2930 } else if (u132->going > 0) {
2942 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2931 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2943 return -ESHUTDOWN; 2932 return -ESHUTDOWN;
2944 } else 2933 } else
2945 return 0; 2934 return 0;
2946} 2935}
2947 2936
2948static void u132_hub_irq_enable(struct usb_hcd *hcd) 2937static void u132_hub_irq_enable(struct usb_hcd *hcd)
2949{ 2938{
2950 struct u132 *u132 = hcd_to_u132(hcd); 2939 struct u132 *u132 = hcd_to_u132(hcd);
2951 if (u132->going > 1) { 2940 if (u132->going > 1) {
2952 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2941 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2953 , u132->going); 2942 , u132->going);
2954 } else if (u132->going > 0) 2943 } else if (u132->going > 0)
2955 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2944 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2956} 2945}
2957 2946
2958 2947
2959#ifdef CONFIG_PM 2948#ifdef CONFIG_PM
2960static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message) 2949static int u132_hcd_suspend(struct usb_hcd *hcd, pm_message_t message)
2961{ 2950{
2962 struct u132 *u132 = hcd_to_u132(hcd); 2951 struct u132 *u132 = hcd_to_u132(hcd);
2963 if (u132->going > 1) { 2952 if (u132->going > 1) {
2964 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2953 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2965 , u132->going); 2954 , u132->going);
2966 return -ENODEV; 2955 return -ENODEV;
2967 } else if (u132->going > 0) { 2956 } else if (u132->going > 0) {
2968 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2957 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2969 return -ESHUTDOWN; 2958 return -ESHUTDOWN;
2970 } else 2959 } else
2971 return 0; 2960 return 0;
2972} 2961}
2973 2962
2974static int u132_hcd_resume(struct usb_hcd *hcd) 2963static int u132_hcd_resume(struct usb_hcd *hcd)
2975{ 2964{
2976 struct u132 *u132 = hcd_to_u132(hcd); 2965 struct u132 *u132 = hcd_to_u132(hcd);
2977 if (u132->going > 1) { 2966 if (u132->going > 1) {
2978 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2967 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2979 , u132->going); 2968 , u132->going);
2980 return -ENODEV; 2969 return -ENODEV;
2981 } else if (u132->going > 0) { 2970 } else if (u132->going > 0) {
2982 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2971 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2983 return -ESHUTDOWN; 2972 return -ESHUTDOWN;
2984 } else 2973 } else
2985 return 0; 2974 return 0;
2986} 2975}
2987 2976
2988static int u132_bus_suspend(struct usb_hcd *hcd) 2977static int u132_bus_suspend(struct usb_hcd *hcd)
2989{ 2978{
2990 struct u132 *u132 = hcd_to_u132(hcd); 2979 struct u132 *u132 = hcd_to_u132(hcd);
2991 if (u132->going > 1) { 2980 if (u132->going > 1) {
2992 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2981 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
2993 , u132->going); 2982 , u132->going);
2994 return -ENODEV; 2983 return -ENODEV;
2995 } else if (u132->going > 0) { 2984 } else if (u132->going > 0) {
2996 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2985 dev_err(&u132->platform_dev->dev, "device is being removed\n");
2997 return -ESHUTDOWN; 2986 return -ESHUTDOWN;
2998 } else 2987 } else
2999 return 0; 2988 return 0;
3000} 2989}
3001 2990
3002static int u132_bus_resume(struct usb_hcd *hcd) 2991static int u132_bus_resume(struct usb_hcd *hcd)
3003{ 2992{
3004 struct u132 *u132 = hcd_to_u132(hcd); 2993 struct u132 *u132 = hcd_to_u132(hcd);
3005 if (u132->going > 1) { 2994 if (u132->going > 1) {
3006 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 2995 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3007 , u132->going); 2996 , u132->going);
3008 return -ENODEV; 2997 return -ENODEV;
3009 } else if (u132->going > 0) { 2998 } else if (u132->going > 0) {
3010 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 2999 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3011 return -ESHUTDOWN; 3000 return -ESHUTDOWN;
3012 } else 3001 } else
3013 return 0; 3002 return 0;
3014} 3003}
3015 3004
3016#else 3005#else
@@ -3020,25 +3009,25 @@ static int u132_bus_resume(struct usb_hcd *hcd)
3020#define u132_bus_resume NULL 3009#define u132_bus_resume NULL
3021#endif 3010#endif
3022static struct hc_driver u132_hc_driver = { 3011static struct hc_driver u132_hc_driver = {
3023 .description = hcd_name, 3012 .description = hcd_name,
3024 .hcd_priv_size = sizeof(struct u132), 3013 .hcd_priv_size = sizeof(struct u132),
3025 .irq = NULL, 3014 .irq = NULL,
3026 .flags = HCD_USB11 | HCD_MEMORY, 3015 .flags = HCD_USB11 | HCD_MEMORY,
3027 .reset = u132_hcd_reset, 3016 .reset = u132_hcd_reset,
3028 .start = u132_hcd_start, 3017 .start = u132_hcd_start,
3029 .suspend = u132_hcd_suspend, 3018 .suspend = u132_hcd_suspend,
3030 .resume = u132_hcd_resume, 3019 .resume = u132_hcd_resume,
3031 .stop = u132_hcd_stop, 3020 .stop = u132_hcd_stop,
3032 .urb_enqueue = u132_urb_enqueue, 3021 .urb_enqueue = u132_urb_enqueue,
3033 .urb_dequeue = u132_urb_dequeue, 3022 .urb_dequeue = u132_urb_dequeue,
3034 .endpoint_disable = u132_endpoint_disable, 3023 .endpoint_disable = u132_endpoint_disable,
3035 .get_frame_number = u132_get_frame, 3024 .get_frame_number = u132_get_frame,
3036 .hub_status_data = u132_hub_status_data, 3025 .hub_status_data = u132_hub_status_data,
3037 .hub_control = u132_hub_control, 3026 .hub_control = u132_hub_control,
3038 .bus_suspend = u132_bus_suspend, 3027 .bus_suspend = u132_bus_suspend,
3039 .bus_resume = u132_bus_resume, 3028 .bus_resume = u132_bus_resume,
3040 .start_port_reset = u132_start_port_reset, 3029 .start_port_reset = u132_start_port_reset,
3041 .hub_irq_enable = u132_hub_irq_enable, 3030 .hub_irq_enable = u132_hub_irq_enable,
3042}; 3031};
3043 3032
3044/* 3033/*
@@ -3049,148 +3038,152 @@ static struct hc_driver u132_hc_driver = {
3049*/ 3038*/
3050static int __devexit u132_remove(struct platform_device *pdev) 3039static int __devexit u132_remove(struct platform_device *pdev)
3051{ 3040{
3052 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3041 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3053 if (hcd) { 3042 if (hcd) {
3054 struct u132 *u132 = hcd_to_u132(hcd); 3043 struct u132 *u132 = hcd_to_u132(hcd);
3055 if (u132->going++ > 1) { 3044 if (u132->going++ > 1) {
3056 dev_err(&u132->platform_dev->dev, "already being remove" 3045 dev_err(&u132->platform_dev->dev, "already being remove"
3057 "d\n"); 3046 "d\n");
3058 return -ENODEV; 3047 return -ENODEV;
3059 } else { 3048 } else {
3060 int rings = MAX_U132_RINGS; 3049 int rings = MAX_U132_RINGS;
3061 int endps = MAX_U132_ENDPS; 3050 int endps = MAX_U132_ENDPS;
3062 dev_err(&u132->platform_dev->dev, "removing device u132" 3051 dev_err(&u132->platform_dev->dev, "removing device u132"
3063 ".%d\n", u132->sequence_num); 3052 ".%d\n", u132->sequence_num);
3064 msleep(100); 3053 msleep(100);
3065 mutex_lock(&u132->sw_lock); 3054 mutex_lock(&u132->sw_lock);
3066 u132_monitor_cancel_work(u132); 3055 u132_monitor_cancel_work(u132);
3067 while (rings-- > 0) { 3056 while (rings-- > 0) {
3068 struct u132_ring *ring = &u132->ring[rings]; 3057 struct u132_ring *ring = &u132->ring[rings];
3069 u132_ring_cancel_work(u132, ring); 3058 u132_ring_cancel_work(u132, ring);
3070 } while (endps-- > 0) { 3059 } while (endps-- > 0) {
3071 struct u132_endp *endp = u132->endp[endps]; 3060 struct u132_endp *endp = u132->endp[endps];
3072 if (endp) 3061 if (endp)
3073 u132_endp_cancel_work(u132, endp); 3062 u132_endp_cancel_work(u132, endp);
3074 } 3063 }
3075 u132->going += 1; 3064 u132->going += 1;
3076 printk(KERN_INFO "removing device u132.%d\n", 3065 printk(KERN_INFO "removing device u132.%d\n",
3077 u132->sequence_num); 3066 u132->sequence_num);
3078 mutex_unlock(&u132->sw_lock); 3067 mutex_unlock(&u132->sw_lock);
3079 usb_remove_hcd(hcd); 3068 usb_remove_hcd(hcd);
3080 u132_u132_put_kref(u132); 3069 u132_u132_put_kref(u132);
3081 return 0; 3070 return 0;
3082 } 3071 }
3083 } else 3072 } else
3084 return 0; 3073 return 0;
3085} 3074}
3086 3075
3087static void u132_initialise(struct u132 *u132, struct platform_device *pdev) 3076static void u132_initialise(struct u132 *u132, struct platform_device *pdev)
3088{ 3077{
3089 int rings = MAX_U132_RINGS; 3078 int rings = MAX_U132_RINGS;
3090 int ports = MAX_U132_PORTS; 3079 int ports = MAX_U132_PORTS;
3091 int addrs = MAX_U132_ADDRS; 3080 int addrs = MAX_U132_ADDRS;
3092 int udevs = MAX_U132_UDEVS; 3081 int udevs = MAX_U132_UDEVS;
3093 int endps = MAX_U132_ENDPS; 3082 int endps = MAX_U132_ENDPS;
3094 u132->board = pdev->dev.platform_data; 3083 u132->board = pdev->dev.platform_data;
3095 u132->platform_dev = pdev; 3084 u132->platform_dev = pdev;
3096 u132->power = 0; 3085 u132->power = 0;
3097 u132->reset = 0; 3086 u132->reset = 0;
3098 mutex_init(&u132->sw_lock); 3087 mutex_init(&u132->sw_lock);
3099 init_MUTEX(&u132->scheduler_lock); 3088 init_MUTEX(&u132->scheduler_lock);
3100 while (rings-- > 0) { 3089 while (rings-- > 0) {
3101 struct u132_ring *ring = &u132->ring[rings]; 3090 struct u132_ring *ring = &u132->ring[rings];
3102 ring->u132 = u132; 3091 ring->u132 = u132;
3103 ring->number = rings + 1; 3092 ring->number = rings + 1;
3104 ring->length = 0; 3093 ring->length = 0;
3105 ring->curr_endp = NULL; 3094 ring->curr_endp = NULL;
3106 INIT_DELAYED_WORK(&ring->scheduler, 3095 INIT_DELAYED_WORK(&ring->scheduler,
3107 u132_hcd_ring_work_scheduler); 3096 u132_hcd_ring_work_scheduler);
3108 } mutex_lock(&u132->sw_lock); 3097 }
3109 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work); 3098 mutex_lock(&u132->sw_lock);
3110 while (ports-- > 0) { 3099 INIT_DELAYED_WORK(&u132->monitor, u132_hcd_monitor_work);
3111 struct u132_port *port = &u132->port[ports]; 3100 while (ports-- > 0) {
3112 port->u132 = u132; 3101 struct u132_port *port = &u132->port[ports];
3113 port->reset = 0; 3102 port->u132 = u132;
3114 port->enable = 0; 3103 port->reset = 0;
3115 port->power = 0; 3104 port->enable = 0;
3116 port->Status = 0; 3105 port->power = 0;
3117 } while (addrs-- > 0) { 3106 port->Status = 0;
3118 struct u132_addr *addr = &u132->addr[addrs]; 3107 }
3119 addr->address = 0; 3108 while (addrs-- > 0) {
3120 } while (udevs-- > 0) { 3109 struct u132_addr *addr = &u132->addr[addrs];
3121 struct u132_udev *udev = &u132->udev[udevs]; 3110 addr->address = 0;
3122 int i = ARRAY_SIZE(udev->endp_number_in); 3111 }
3123 int o = ARRAY_SIZE(udev->endp_number_out); 3112 while (udevs-- > 0) {
3124 udev->usb_device = NULL; 3113 struct u132_udev *udev = &u132->udev[udevs];
3125 udev->udev_number = 0; 3114 int i = ARRAY_SIZE(udev->endp_number_in);
3126 udev->usb_addr = 0; 3115 int o = ARRAY_SIZE(udev->endp_number_out);
3127 udev->portnumber = 0; 3116 udev->usb_device = NULL;
3128 while (i-- > 0) { 3117 udev->udev_number = 0;
3129 udev->endp_number_in[i] = 0; 3118 udev->usb_addr = 0;
3130 } 3119 udev->portnumber = 0;
3131 while (o-- > 0) { 3120 while (i-- > 0)
3132 udev->endp_number_out[o] = 0; 3121 udev->endp_number_in[i] = 0;
3133 } 3122
3134 } 3123 while (o-- > 0)
3135 while (endps-- > 0) { 3124 udev->endp_number_out[o] = 0;
3136 u132->endp[endps] = NULL; 3125
3137 } 3126 }
3138 mutex_unlock(&u132->sw_lock); 3127 while (endps-- > 0)
3139 return; 3128 u132->endp[endps] = NULL;
3129
3130 mutex_unlock(&u132->sw_lock);
3131 return;
3140} 3132}
3141 3133
3142static int __devinit u132_probe(struct platform_device *pdev) 3134static int __devinit u132_probe(struct platform_device *pdev)
3143{ 3135{
3144 struct usb_hcd *hcd; 3136 struct usb_hcd *hcd;
3145 int retval; 3137 int retval;
3146 u32 control; 3138 u32 control;
3147 u32 rh_a = -1; 3139 u32 rh_a = -1;
3148 u32 num_ports; 3140 u32 num_ports;
3149 msleep(100); 3141
3150 if (u132_exiting > 0) { 3142 msleep(100);
3151 return -ENODEV; 3143 if (u132_exiting > 0)
3152 } 3144 return -ENODEV;
3153 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE); 3145
3154 if (retval) 3146 retval = ftdi_write_pcimem(pdev, intrdisable, OHCI_INTR_MIE);
3155 return retval; 3147 if (retval)
3156 retval = ftdi_read_pcimem(pdev, control, &control); 3148 return retval;
3157 if (retval) 3149 retval = ftdi_read_pcimem(pdev, control, &control);
3158 return retval; 3150 if (retval)
3159 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a); 3151 return retval;
3160 if (retval) 3152 retval = ftdi_read_pcimem(pdev, roothub.a, &rh_a);
3161 return retval; 3153 if (retval)
3162 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */ 3154 return retval;
3163 if (pdev->dev.dma_mask) { 3155 num_ports = rh_a & RH_A_NDP; /* refuse to confuse usbcore */
3164 return -EINVAL; 3156 if (pdev->dev.dma_mask)
3165 } 3157 return -EINVAL;
3166 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id); 3158
3167 if (!hcd) { 3159 hcd = usb_create_hcd(&u132_hc_driver, &pdev->dev, pdev->dev.bus_id);
3168 printk(KERN_ERR "failed to create the usb hcd struct for U132\n" 3160 if (!hcd) {
3169 ); 3161 printk(KERN_ERR "failed to create the usb hcd struct for U132\n"
3170 ftdi_elan_gone_away(pdev); 3162 );
3171 return -ENOMEM; 3163 ftdi_elan_gone_away(pdev);
3172 } else { 3164 return -ENOMEM;
3173 int retval = 0; 3165 } else {
3174 struct u132 *u132 = hcd_to_u132(hcd); 3166 int retval = 0;
3175 hcd->rsrc_start = 0; 3167 struct u132 *u132 = hcd_to_u132(hcd);
3176 mutex_lock(&u132_module_lock); 3168 hcd->rsrc_start = 0;
3177 list_add_tail(&u132->u132_list, &u132_static_list); 3169 mutex_lock(&u132_module_lock);
3178 u132->sequence_num = ++u132_instances; 3170 list_add_tail(&u132->u132_list, &u132_static_list);
3179 mutex_unlock(&u132_module_lock); 3171 u132->sequence_num = ++u132_instances;
3180 u132_u132_init_kref(u132); 3172 mutex_unlock(&u132_module_lock);
3181 u132_initialise(u132, pdev); 3173 u132_u132_init_kref(u132);
3182 hcd->product_desc = "ELAN U132 Host Controller"; 3174 u132_initialise(u132, pdev);
3183 retval = usb_add_hcd(hcd, 0, 0); 3175 hcd->product_desc = "ELAN U132 Host Controller";
3184 if (retval != 0) { 3176 retval = usb_add_hcd(hcd, 0, 0);
3185 dev_err(&u132->platform_dev->dev, "init error %d\n", 3177 if (retval != 0) {
3186 retval); 3178 dev_err(&u132->platform_dev->dev, "init error %d\n",
3187 u132_u132_put_kref(u132); 3179 retval);
3188 return retval; 3180 u132_u132_put_kref(u132);
3189 } else { 3181 return retval;
3190 u132_monitor_queue_work(u132, 100); 3182 } else {
3191 return 0; 3183 u132_monitor_queue_work(u132, 100);
3192 } 3184 return 0;
3193 } 3185 }
3186 }
3194} 3187}
3195 3188
3196 3189
@@ -3201,58 +3194,58 @@ static int __devinit u132_probe(struct platform_device *pdev)
3201*/ 3194*/
3202static int u132_suspend(struct platform_device *pdev, pm_message_t state) 3195static int u132_suspend(struct platform_device *pdev, pm_message_t state)
3203{ 3196{
3204 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3197 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3205 struct u132 *u132 = hcd_to_u132(hcd); 3198 struct u132 *u132 = hcd_to_u132(hcd);
3206 if (u132->going > 1) { 3199 if (u132->going > 1) {
3207 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 3200 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3208 , u132->going); 3201 , u132->going);
3209 return -ENODEV; 3202 return -ENODEV;
3210 } else if (u132->going > 0) { 3203 } else if (u132->going > 0) {
3211 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 3204 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3212 return -ESHUTDOWN; 3205 return -ESHUTDOWN;
3213 } else { 3206 } else {
3214 int retval = 0, ports; 3207 int retval = 0, ports;
3215 3208
3216 switch (state.event) { 3209 switch (state.event) {
3217 case PM_EVENT_FREEZE: 3210 case PM_EVENT_FREEZE:
3218 retval = u132_bus_suspend(hcd); 3211 retval = u132_bus_suspend(hcd);
3219 break; 3212 break;
3220 case PM_EVENT_SUSPEND: 3213 case PM_EVENT_SUSPEND:
3221 case PM_EVENT_HIBERNATE: 3214 case PM_EVENT_HIBERNATE:
3222 ports = MAX_U132_PORTS; 3215 ports = MAX_U132_PORTS;
3223 while (ports-- > 0) { 3216 while (ports-- > 0) {
3224 port_power(u132, ports, 0); 3217 port_power(u132, ports, 0);
3225 } 3218 }
3226 break; 3219 break;
3227 } 3220 }
3228 return retval; 3221 return retval;
3229 } 3222 }
3230} 3223}
3231 3224
3232static int u132_resume(struct platform_device *pdev) 3225static int u132_resume(struct platform_device *pdev)
3233{ 3226{
3234 struct usb_hcd *hcd = platform_get_drvdata(pdev); 3227 struct usb_hcd *hcd = platform_get_drvdata(pdev);
3235 struct u132 *u132 = hcd_to_u132(hcd); 3228 struct u132 *u132 = hcd_to_u132(hcd);
3236 if (u132->going > 1) { 3229 if (u132->going > 1) {
3237 dev_err(&u132->platform_dev->dev, "device has been removed %d\n" 3230 dev_err(&u132->platform_dev->dev, "device has been removed %d\n"
3238 , u132->going); 3231 , u132->going);
3239 return -ENODEV; 3232 return -ENODEV;
3240 } else if (u132->going > 0) { 3233 } else if (u132->going > 0) {
3241 dev_err(&u132->platform_dev->dev, "device is being removed\n"); 3234 dev_err(&u132->platform_dev->dev, "device is being removed\n");
3242 return -ESHUTDOWN; 3235 return -ESHUTDOWN;
3243 } else { 3236 } else {
3244 int retval = 0; 3237 int retval = 0;
3245 if (!u132->port[0].power) { 3238 if (!u132->port[0].power) {
3246 int ports = MAX_U132_PORTS; 3239 int ports = MAX_U132_PORTS;
3247 while (ports-- > 0) { 3240 while (ports-- > 0) {
3248 port_power(u132, ports, 1); 3241 port_power(u132, ports, 1);
3249 } 3242 }
3250 retval = 0; 3243 retval = 0;
3251 } else { 3244 } else {
3252 retval = u132_bus_resume(hcd); 3245 retval = u132_bus_resume(hcd);
3253 } 3246 }
3254 return retval; 3247 return retval;
3255 } 3248 }
3256} 3249}
3257 3250
3258#else 3251#else
@@ -3265,47 +3258,48 @@ static int u132_resume(struct platform_device *pdev)
3265* the platform_driver struct is static because it is per type of module 3258* the platform_driver struct is static because it is per type of module
3266*/ 3259*/
3267static struct platform_driver u132_platform_driver = { 3260static struct platform_driver u132_platform_driver = {
3268 .probe = u132_probe, 3261 .probe = u132_probe,
3269 .remove = __devexit_p(u132_remove), 3262 .remove = __devexit_p(u132_remove),
3270 .suspend = u132_suspend, 3263 .suspend = u132_suspend,
3271 .resume = u132_resume, 3264 .resume = u132_resume,
3272 .driver = { 3265 .driver = {
3273 .name = (char *)hcd_name, 3266 .name = (char *)hcd_name,
3274 .owner = THIS_MODULE, 3267 .owner = THIS_MODULE,
3275 }, 3268 },
3276}; 3269};
3277static int __init u132_hcd_init(void) 3270static int __init u132_hcd_init(void)
3278{ 3271{
3279 int retval; 3272 int retval;
3280 INIT_LIST_HEAD(&u132_static_list); 3273 INIT_LIST_HEAD(&u132_static_list);
3281 u132_instances = 0; 3274 u132_instances = 0;
3282 u132_exiting = 0; 3275 u132_exiting = 0;
3283 mutex_init(&u132_module_lock); 3276 mutex_init(&u132_module_lock);
3284 if (usb_disabled()) 3277 if (usb_disabled())
3285 return -ENODEV; 3278 return -ENODEV;
3286 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__, 3279 printk(KERN_INFO "driver %s built at %s on %s\n", hcd_name, __TIME__,
3287 __DATE__); 3280 __DATE__);
3288 workqueue = create_singlethread_workqueue("u132"); 3281 workqueue = create_singlethread_workqueue("u132");
3289 retval = platform_driver_register(&u132_platform_driver); 3282 retval = platform_driver_register(&u132_platform_driver);
3290 return retval; 3283 return retval;
3291} 3284}
3292 3285
3293 3286
3294module_init(u132_hcd_init); 3287module_init(u132_hcd_init);
3295static void __exit u132_hcd_exit(void) 3288static void __exit u132_hcd_exit(void)
3296{ 3289{
3297 struct u132 *u132; 3290 struct u132 *u132;
3298 struct u132 *temp; 3291 struct u132 *temp;
3299 mutex_lock(&u132_module_lock); 3292 mutex_lock(&u132_module_lock);
3300 u132_exiting += 1; 3293 u132_exiting += 1;
3301 mutex_unlock(&u132_module_lock); 3294 mutex_unlock(&u132_module_lock);
3302 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) { 3295 list_for_each_entry_safe(u132, temp, &u132_static_list, u132_list) {
3303 platform_device_unregister(u132->platform_dev); 3296 platform_device_unregister(u132->platform_dev);
3304 } platform_driver_unregister(&u132_platform_driver); 3297 }
3305 printk(KERN_INFO "u132-hcd driver deregistered\n"); 3298 platform_driver_unregister(&u132_platform_driver);
3306 wait_event(u132_hcd_wait, u132_instances == 0); 3299 printk(KERN_INFO "u132-hcd driver deregistered\n");
3307 flush_workqueue(workqueue); 3300 wait_event(u132_hcd_wait, u132_instances == 0);
3308 destroy_workqueue(workqueue); 3301 flush_workqueue(workqueue);
3302 destroy_workqueue(workqueue);
3309} 3303}
3310 3304
3311 3305