5994d43c8a31653cdfcbc38447094a25d6a7fcf4
[15.05/openwrt.git] / target / linux / adm5120 / patches-3.3 / a15-adm5120-usb-driver-cleanup.patch
1 --- a/drivers/usb/host/adm5120.h
2 +++ b/drivers/usb/host/adm5120.h
3 @@ -403,6 +403,7 @@ struct admhcd {
4          * other external transceivers should be software-transparent
5          */
6         struct otg_transceiver  *transceiver;
7 +       void (*start_hnp)(struct admhcd *ahcd);
8  #endif
9  
10         /*
11 @@ -537,15 +538,7 @@ static inline struct usb_hcd *admhcd_to_
12   * Big-endian read/write functions are arch-specific.
13   * Other arches can be added if/when they're needed.
14   *
15 - * REVISIT: arch/powerpc now has readl/writel_be, so the
16 - * definition below can die once the STB04xxx support is
17 - * finally ported over.
18   */
19 -#if defined(CONFIG_PPC) && !defined(CONFIG_PPC_MERGE)
20 -#define readl_be(addr)         in_be32((__force unsigned *)addr)
21 -#define writel_be(val, addr)   out_be32((__force unsigned *)addr, val)
22 -#endif
23 -
24  static inline unsigned int admhc_readl(const struct admhcd *ahcd,
25         __hc32 __iomem *regs)
26  {
27 --- a/drivers/usb/host/adm5120-drv.c
28 +++ b/drivers/usb/host/adm5120-drv.c
29 @@ -9,7 +9,7 @@
30   *   (C) Copyright 2002 Hewlett-Packard Company
31   *
32   *   Written by Christopher Hoover <ch@hpl.hp.com>
33 - *   Based on fragments of previous driver by Rusell King et al.
34 + *   Based on fragments of previous driver by Russell King et al.
35   *
36   *   Modified for LH7A404 from ahcd-sa1111.c
37   *    by Durgesh Pattamatta <pattamattad@sharpsec.com>
38 @@ -81,7 +81,7 @@ static int admhc_adm5120_probe(const str
39  
40         admhc_hcd_init(hcd_to_admhcd(hcd));
41  
42 -       retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
43 +       retval = usb_add_hcd(hcd, irq, 0);
44         if (retval)
45                 goto err_io;
46  
47 @@ -109,10 +109,7 @@ static void admhc_adm5120_remove(struct
48         usb_put_hcd(hcd);
49  }
50  
51 -/*-------------------------------------------------------------------------*/
52 -
53 -static int __devinit
54 -admhc_adm5120_start(struct usb_hcd *hcd)
55 +static int __devinit admhc_adm5120_start(struct usb_hcd *hcd)
56  {
57         struct admhcd   *ahcd = hcd_to_admhcd(hcd);
58         int             ret;
59 @@ -137,8 +134,6 @@ err:
60         return ret;
61  }
62  
63 -/*-------------------------------------------------------------------------*/
64 -
65  static const struct hc_driver adm5120_hc_driver = {
66         .description =          hcd_name,
67         .product_desc =         "ADM5120 built-in USB 1.1 Host Controller",
68 @@ -181,8 +176,6 @@ static const struct hc_driver adm5120_hc
69         .start_port_reset =     admhc_start_port_reset,
70  };
71  
72 -/*-------------------------------------------------------------------------*/
73 -
74  static int usb_hcd_adm5120_probe(struct platform_device *pdev)
75  {
76         int ret;
77 --- a/drivers/usb/host/adm5120-dbg.c
78 +++ b/drivers/usb/host/adm5120-dbg.c
79 @@ -401,25 +401,28 @@ static const struct file_operations debu
80         .open           = debug_async_open,
81         .read           = debug_output,
82         .release        = debug_close,
83 +       .llseek         = default_llseek,
84  };
85  static const struct file_operations debug_periodic_fops = {
86         .owner          = THIS_MODULE,
87         .open           = debug_periodic_open,
88         .read           = debug_output,
89         .release        = debug_close,
90 +       .llseek         = default_llseek,
91  };
92  static const struct file_operations debug_registers_fops = {
93         .owner          = THIS_MODULE,
94         .open           = debug_registers_open,
95         .read           = debug_output,
96         .release        = debug_close,
97 +       .llseek         = default_llseek,
98  };
99  
100  static struct dentry *admhc_debug_root;
101  
102  struct debug_buffer {
103         ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
104 -       struct device *dev;
105 +       struct admhcd *ahcd;
106         struct mutex mutex;     /* protect filling of buffer */
107         size_t count;           /* number of characters filled into buffer */
108         char *page;
109 @@ -494,15 +497,11 @@ show_list(struct admhcd *ahcd, char *buf
110  
111  static ssize_t fill_async_buffer(struct debug_buffer *buf)
112  {
113 -       struct usb_bus          *bus;
114 -       struct usb_hcd          *hcd;
115         struct admhcd           *ahcd;
116         size_t                  temp;
117         unsigned long           flags;
118  
119 -       bus = dev_get_drvdata(buf->dev);
120 -       hcd = bus_to_hcd(bus);
121 -       ahcd = hcd_to_admhcd(hcd);
122 +       ahcd = buf->ahcd;
123  
124         spin_lock_irqsave(&ahcd->lock, flags);
125         temp = show_list(ahcd, buf->page, PAGE_SIZE, ahcd->ed_head);
126 @@ -516,8 +515,6 @@ static ssize_t fill_async_buffer(struct
127  
128  static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
129  {
130 -       struct usb_bus          *bus;
131 -       struct usb_hcd          *hcd;
132         struct admhcd           *ahcd;
133         struct ed               **seen, *ed;
134         unsigned long           flags;
135 @@ -530,9 +527,7 @@ static ssize_t fill_periodic_buffer(stru
136                 return 0;
137         seen_count = 0;
138  
139 -       bus = dev_get_drvdata(buf->dev);
140 -       hcd = bus_to_hcd(bus);
141 -       ahcd = hcd_to_admhcd(hcd);
142 +       ahcd = buf->ahcd;
143         next = buf->page;
144         size = PAGE_SIZE;
145  
146 @@ -615,7 +610,6 @@ static ssize_t fill_periodic_buffer(stru
147  
148  static ssize_t fill_registers_buffer(struct debug_buffer *buf)
149  {
150 -       struct usb_bus          *bus;
151         struct usb_hcd          *hcd;
152         struct admhcd           *ahcd;
153         struct admhcd_regs __iomem *regs;
154 @@ -624,9 +618,8 @@ static ssize_t fill_registers_buffer(str
155         char                    *next;
156         u32                     rdata;
157  
158 -       bus = dev_get_drvdata(buf->dev);
159 -       hcd = bus_to_hcd(bus);
160 -       ahcd = hcd_to_admhcd(hcd);
161 +       ahcd = buf->ahcd;
162 +       hcd = admhc_to_hcd(ahcd);
163         regs = ahcd->regs;
164         next = buf->page;
165         size = PAGE_SIZE;
166 @@ -638,13 +631,13 @@ static ssize_t fill_registers_buffer(str
167         admhc_dbg_sw(ahcd, &next, &size,
168                 "bus %s, device %s\n"
169                 "%s\n"
170 -               "%s version " DRIVER_VERSION "\n",
171 +               "%s\n",
172                 hcd->self.controller->bus->name,
173                 dev_name(hcd->self.controller),
174                 hcd->product_desc,
175                 hcd_name);
176  
177 -       if (bus->controller->power.power_state.event) {
178 +       if (!HCD_HW_ACCESSIBLE(hcd)) {
179                 size -= scnprintf(next, size,
180                         "SUSPENDED (no register access)\n");
181                 goto done;
182 @@ -691,7 +684,7 @@ done:
183  }
184  
185  
186 -static struct debug_buffer *alloc_buffer(struct device *dev,
187 +static struct debug_buffer *alloc_buffer(struct admhcd *ahcd,
188                                 ssize_t (*fill_func)(struct debug_buffer *))
189  {
190         struct debug_buffer *buf;
191 @@ -699,7 +692,7 @@ static struct debug_buffer *alloc_buffer
192         buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
193  
194         if (buf) {
195 -               buf->dev = dev;
196 +               buf->ahcd = ahcd;
197                 buf->fill_func = fill_func;
198                 mutex_init(&buf->mutex);
199         }
200 @@ -792,26 +785,25 @@ static int debug_registers_open(struct i
201  static inline void create_debug_files(struct admhcd *ahcd)
202  {
203         struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
204 -       struct device *dev = bus->dev;
205  
206         ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
207         if (!ahcd->debug_dir)
208                 goto dir_error;
209  
210         ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
211 -                                               ahcd->debug_dir, dev,
212 +                                               ahcd->debug_dir, ahcd,
213                                                 &debug_async_fops);
214         if (!ahcd->debug_async)
215                 goto async_error;
216  
217         ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
218 -                                               ahcd->debug_dir, dev,
219 +                                               ahcd->debug_dir, ahcd,
220                                                 &debug_periodic_fops);
221         if (!ahcd->debug_periodic)
222                 goto periodic_error;
223  
224         ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO,
225 -                                               ahcd->debug_dir, dev,
226 +                                               ahcd->debug_dir, ahcd,
227                                                 &debug_registers_fops);
228         if (!ahcd->debug_registers)
229                 goto registers_error;
230 --- a/drivers/usb/host/adm5120-pm.c
231 +++ b/drivers/usb/host/adm5120-pm.c
232 @@ -257,7 +257,7 @@ static int admhc_bus_suspend(struct usb_
233  
234         spin_lock_irq(&ahcd->lock);
235  
236 -       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
237 +       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
238                 rc = -ESHUTDOWN;
239         else
240                 rc = admhc_rh_suspend(ahcd, 0);
241 @@ -275,7 +275,7 @@ static int admhc_bus_resume(struct usb_h
242  
243         spin_lock_irq(&ahcd->lock);
244  
245 -       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
246 +       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
247                 rc = -ESHUTDOWN;
248         else
249                 rc = admhc_rh_resume(ahcd);
250 --- a/drivers/usb/host/adm5120-hcd.c
251 +++ b/drivers/usb/host/adm5120-hcd.c
252 @@ -32,9 +32,9 @@
253  #include <linux/list.h>
254  #include <linux/usb.h>
255  #include <linux/usb/otg.h>
256 +#include <linux/usb/hcd.h>
257  #include <linux/dma-mapping.h>
258  #include <linux/dmapool.h>
259 -#include <linux/reboot.h>
260  #include <linux/debugfs.h>
261  #include <linux/io.h>
262  
263 @@ -43,9 +43,6 @@
264  #include <asm/unaligned.h>
265  #include <asm/byteorder.h>
266  
267 -#include "../core/hcd.h"
268 -#include "../core/hub.h"
269 -
270  #define DRIVER_VERSION "0.27.0"
271  #define DRIVER_AUTHOR  "Gabor Juhos <juhosg@openwrt.org>"
272  #define DRIVER_DESC    "ADMtek USB 1.1 Host Controller Driver"
273 @@ -117,7 +114,7 @@ static int admhc_urb_enqueue(struct usb_
274                 td_cnt = 2;
275                 /* FALLTHROUGH */
276         case PIPE_BULK:
277 -               /* one TD for every 4096 Bytes (can be upto 8K) */
278 +               /* one TD for every 4096 Bytes (can be up to 8K) */
279                 td_cnt += urb->transfer_buffer_length / TD_DATALEN_MAX;
280                 /* ... and for any remaining bytes ... */
281                 if ((urb->transfer_buffer_length % TD_DATALEN_MAX) != 0)
282 @@ -153,7 +150,7 @@ static int admhc_urb_enqueue(struct usb_
283  
284         spin_lock_irqsave(&ahcd->lock, flags);
285         /* don't submit to a dead HC */
286 -       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) {
287 +       if (!HCD_HW_ACCESSIBLE(hcd)) {
288                 ret = -ENODEV;
289                 goto fail;
290         }
291 @@ -321,7 +318,6 @@ sanitize:
292         ep->hcpriv = NULL;
293  
294         spin_unlock_irqrestore(&ahcd->lock, flags);
295 -       return;
296  }
297  
298  static int admhc_get_frame_number(struct usb_hcd *hcd)
299 @@ -488,7 +484,7 @@ err:
300   */
301  static int admhc_run(struct admhcd *ahcd)
302  {
303 -       u32                     temp;
304 +       u32                     val;
305         int                     first = ahcd->fminterval == 0;
306         struct usb_hcd          *hcd = admhcd_to_hcd(ahcd);
307  
308 @@ -496,8 +492,8 @@ static int admhc_run(struct admhcd *ahcd
309  
310         /* boot firmware should have set this up (5.1.1.3.1) */
311         if (first) {
312 -               temp = admhc_readl(ahcd, &ahcd->regs->fminterval);
313 -               ahcd->fminterval = temp & ADMHC_SFI_FI_MASK;
314 +               val = admhc_readl(ahcd, &ahcd->regs->fminterval);
315 +               ahcd->fminterval = val & ADMHC_SFI_FI_MASK;
316                 if (ahcd->fminterval != FI)
317                         admhc_dbg(ahcd, "fminterval delta %d\n",
318                                 ahcd->fminterval - FI);
319 @@ -507,30 +503,30 @@ static int admhc_run(struct admhcd *ahcd
320         }
321  
322  #if 0  /* TODO: not applicable */
323 -       /* Reset USB nearly "by the book".  RemoteWakeupConnected was
324 -        * saved if boot firmware (BIOS/SMM/...) told us it's connected,
325 -        * or if bus glue did the same (e.g. for PCI add-in cards with
326 -        * PCI PM support).
327 +       /* Reset USB nearly "by the book".  RemoteWakeupConnected has
328 +        * to be checked in case boot firmware (BIOS/SMM/...) has set up
329 +        * wakeup in a way the bus isn't aware of (e.g., legacy PCI PM).
330 +        * If the bus glue detected wakeup capability then it should
331 +        * already be enabled; if so we'll just enable it again.
332          */
333 -       if ((ahcd->hc_control & OHCI_CTRL_RWC) != 0
334 -                       && !device_may_wakeup(hcd->self.controller))
335 -               device_init_wakeup(hcd->self.controller, 1);
336 +       if ((ahcd->hc_control & OHCI_CTRL_RWC) != 0)
337 +               device_set_wakeup_capable(hcd->self.controller, 1);
338  #endif
339  
340         switch (ahcd->host_control & ADMHC_HC_BUSS) {
341         case ADMHC_BUSS_OPER:
342 -               temp = 0;
343 +               val = 0;
344                 break;
345         case ADMHC_BUSS_SUSPEND:
346                 /* FALLTHROUGH ? */
347         case ADMHC_BUSS_RESUME:
348                 ahcd->host_control = ADMHC_BUSS_RESUME;
349 -               temp = 10 /* msec wait */;
350 +               val = 10 /* msec wait */;
351                 break;
352         /* case ADMHC_BUSS_RESET: */
353         default:
354                 ahcd->host_control = ADMHC_BUSS_RESET;
355 -               temp = 50 /* msec wait */;
356 +               val = 50 /* msec wait */;
357                 break;
358         }
359         admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control);
360 @@ -538,12 +534,12 @@ static int admhc_run(struct admhcd *ahcd
361         /* flush the writes */
362         admhc_writel_flush(ahcd);
363  
364 -       msleep(temp);
365 -       temp = admhc_read_rhdesc(ahcd);
366 -       if (!(temp & ADMHC_RH_NPS)) {
367 +       msleep(val);
368 +       val = admhc_read_rhdesc(ahcd);
369 +       if (!(val & ADMHC_RH_NPS)) {
370                 /* power down each port */
371 -               for (temp = 0; temp < ahcd->num_ports; temp++)
372 -                       admhc_write_portstatus(ahcd, temp, ADMHC_PS_CPP);
373 +               for (val = 0; val < ahcd->num_ports; val++)
374 +                       admhc_write_portstatus(ahcd, val, ADMHC_PS_CPP);
375         }
376         /* flush those writes */
377         admhc_writel_flush(ahcd);
378 @@ -552,9 +548,9 @@ static int admhc_run(struct admhcd *ahcd
379         spin_lock_irq(&ahcd->lock);
380  
381         admhc_writel(ahcd, ADMHC_CTRL_SR,  &ahcd->regs->gencontrol);
382 -       temp = 30;      /* ... allow extra time */
383 +       val = 30;       /* ... allow extra time */
384         while ((admhc_readl(ahcd, &ahcd->regs->gencontrol) & ADMHC_CTRL_SR) != 0) {
385 -               if (--temp == 0) {
386 +               if (--val == 0) {
387                         spin_unlock_irq(&ahcd->lock);
388                         admhc_err(ahcd, "USB HC reset timed out!\n");
389                         return -1;
390 @@ -571,7 +567,7 @@ static int admhc_run(struct admhcd *ahcd
391         periodic_reinit(ahcd);
392  
393         /* use rhsc irqs after khubd is fully initialized */
394 -       hcd->poll_rh = 1;
395 +       set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
396         hcd->uses_new_polling = 1;
397  
398  #if 0
399 @@ -594,10 +590,10 @@ static int admhc_run(struct admhcd *ahcd
400         ahcd->host_control = ADMHC_BUSS_OPER;
401         admhc_writel(ahcd, ahcd->host_control, &ahcd->regs->host_control);
402  
403 -       temp = 20;
404 +       val = 20;
405         while ((admhc_readl(ahcd, &ahcd->regs->host_control)
406                         & ADMHC_HC_BUSS) != ADMHC_BUSS_OPER) {
407 -               if (--temp == 0) {
408 +               if (--val == 0) {
409                         spin_unlock_irq(&ahcd->lock);
410                         admhc_err(ahcd, "unable to setup operational mode!\n");
411                         return -1;
412 @@ -613,10 +609,10 @@ static int admhc_run(struct admhcd *ahcd
413         /* FIXME: enabling DMA is always failed here for an unknown reason */
414         admhc_dma_enable(ahcd);
415  
416 -       temp = 200;
417 +       val = 200;
418         while ((admhc_readl(ahcd, &ahcd->regs->host_control)
419                         & ADMHC_HC_DMAE) != ADMHC_HC_DMAE) {
420 -               if (--temp == 0) {
421 +               if (--val == 0) {
422                         spin_unlock_irq(&ahcd->lock);
423                         admhc_err(ahcd, "unable to enable DMA!\n");
424                         admhc_dump(ahcd, 1);
425 @@ -688,7 +684,7 @@ static irqreturn_t admhc_irq(struct usb_
426                  */
427                 admhc_vdbg(ahcd, "Resume Detect\n");
428                 admhc_intr_ack(ahcd, ADMHC_INTR_RESI);
429 -               hcd->poll_rh = 1;
430 +               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
431                 if (ahcd->autostop) {
432                         spin_lock(&ahcd->lock);
433                         admhc_rh_resume(ahcd);
434 @@ -799,9 +795,10 @@ static int __init admhc_hcd_mod_init(voi
435         pr_info("%s: " DRIVER_INFO "\n", hcd_name);
436         pr_info("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
437                 sizeof(struct ed), sizeof(struct td));
438 +       set_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
439  
440  #ifdef DEBUG
441 -       admhc_debug_root = debugfs_create_dir("admhc", NULL);
442 +       admhc_debug_root = debugfs_create_dir("admhc", usb_debug_root);
443         if (!admhc_debug_root) {
444                 ret = -ENOENT;
445                 goto error_debug;
446 @@ -826,6 +823,7 @@ error_platform:
447         admhc_debug_root = NULL;
448  error_debug:
449  #endif
450 +       clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
451         return ret;
452  }
453  module_init(admhc_hcd_mod_init);
454 @@ -836,6 +834,7 @@ static void __exit admhc_hcd_mod_exit(vo
455  #ifdef DEBUG
456         debugfs_remove(admhc_debug_root);
457  #endif
458 +       clear_bit(USB_OHCI_LOADED, &usb_hcds_loaded);
459  }
460  module_exit(admhc_hcd_mod_exit);
461  
462 --- a/drivers/usb/host/adm5120-hub.c
463 +++ b/drivers/usb/host/adm5120-hub.c
464 @@ -75,7 +75,7 @@ admhc_hub_status_data(struct usb_hcd *hc
465         u32             status;
466  
467         spin_lock_irqsave(&ahcd->lock, flags);
468 -       if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags))
469 +       if (!HCD_HW_ACCESSIBLE(hcd))
470                 goto done;
471  
472         /* init status */
473 @@ -106,8 +106,11 @@ admhc_hub_status_data(struct usb_hcd *hc
474                 }
475         }
476  
477 -       hcd->poll_rh = admhc_root_hub_state_changes(ahcd, changed,
478 -                       any_connected);
479 +       if (admhc_root_hub_state_changes(ahcd, changed,
480 +                       any_connected))
481 +               set_bit(HCD_FLAG_POLL_RH, &hcd->flags);
482 +       else
483 +               clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
484  
485  done:
486         spin_unlock_irqrestore(&ahcd->lock, flags);
487 @@ -143,9 +146,9 @@ static int admhc_get_hub_descriptor(stru
488             temp |= 0x0008;
489         desc->wHubCharacteristics = (__force __u16)cpu_to_hc16(ahcd, temp);
490  
491 -       /* two bitmaps:  ports removable, and usb 1.0 legacy PortPwrCtrlMask */
492 -       desc->bitmap[0] = 0;
493 -       desc->bitmap[0] = ~0;
494 +       /* ports removable, and usb 1.0 legacy PortPwrCtrlMask */
495 +       desc->u.hs.DeviceRemovable[0] = 0;
496 +       desc->u.hs.DeviceRemovable[0] = ~0;
497  
498         return 0;
499  }
500 @@ -310,10 +313,10 @@ static int admhc_hub_control(struct usb_
501                 u16 wIndex, char *buf, u16 wLength)
502  {
503         struct admhcd   *ahcd = hcd_to_admhcd(hcd);
504 -       int             ports = hcd_to_bus(hcd)->root_hub->maxchild;
505 +       int             ports = ahcd->num_ports;
506         int             ret = 0;
507  
508 -       if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)))
509 +       if (unlikely(!HCD_HW_ACCESSIBLE(hcd)))
510                 return -ESHUTDOWN;
511  
512         switch (typeReq) {
513 --- a/drivers/usb/host/adm5120-q.c
514 +++ b/drivers/usb/host/adm5120-q.c
515 @@ -14,6 +14,7 @@
516   */
517  
518  #include <linux/irq.h>
519 +#include <linux/slab.h>
520  
521  /*-------------------------------------------------------------------------*/
522  
523 @@ -300,7 +301,7 @@ static struct ed *ed_get(struct admhcd *
524                 u32             info;
525  
526                 /* FIXME: usbcore changes dev->devnum before SET_ADDRESS
527 -                * suceeds ... otherwise we wouldn't need "pipe".
528 +                * succeeds ... otherwise we wouldn't need "pipe".
529                  */
530                 info = usb_pipedevice(pipe);
531                 info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << ED_EN_SHIFT;
532 @@ -634,8 +635,7 @@ static int td_done(struct admhcd *ahcd,
533  
534  /*-------------------------------------------------------------------------*/
535  
536 -static inline void
537 -ed_halted(struct admhcd *ahcd, struct td *td, int cc, struct td *rev)
538 +static void ed_halted(struct admhcd *ahcd, struct td *td, int cc)
539  {
540         struct urb              *urb = td->urb;
541         struct urb_priv         *urb_priv = urb->hcpriv;
542 @@ -764,6 +764,7 @@ rescan_this:
543                         struct urb      *urb;
544                         struct urb_priv *urb_priv;
545                         __hc32          savebits;
546 +                       u32             tdINFO;
547                         int             status;
548  
549                         td = list_entry(entry, struct td, td_list);
550 @@ -781,6 +782,16 @@ rescan_this:
551                         /* patch pointer hc uses */
552                         savebits = *prev & ~cpu_to_hc32(ahcd, TD_MASK);
553                         *prev = td->hwNextTD | savebits;
554 +                       /* If this was unlinked, the TD may not have been
555 +                        * retired ... so manually save dhe data toggle.
556 +                        * The controller ignores the value we save for
557 +                        * control and ISO endpoints.
558 +                        */
559 +                       tdINFO = hc32_to_cpup(ahcd, &td->hwINFO);
560 +                       if ((tdINFO & TD_T) == TD_T_DATA0)
561 +                               ed->hwHeadP &= ~cpu_to_hc32(ahcd, ED_C);
562 +                       else if ((tdINFO & TD_T) == TD_T_DATA1)
563 +                               ed->hwHeadP |= cpu_to_hc32(ahcd, ED_C);
564  
565                         /* HC may have partly processed this TD */
566  #ifdef ADMHC_VERBOSE_DEBUG
567 @@ -816,13 +827,12 @@ rescan_this:
568  }
569  
570  /*-------------------------------------------------------------------------*/
571 -
572  /*
573   * Process normal completions (error or success) and clean the schedules.
574   *
575   * This is the main path for handing urbs back to drivers.  The only other
576 - * path is finish_unlinks(), which unlinks URBs using ed_rm_list, instead of
577 - * scanning the (re-reversed) donelist as this does.
578 + * normal path is finish_unlinks(), which unlinks URBs using ed_rm_list,
579 + * instead of scanning the (re-reversed) donelist as this does.
580   */
581  
582  static void ed_unhalt(struct admhcd *ahcd, struct ed *ed, struct urb *urb)