This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / usb / host / sl811-hcd.c
1 /*
2  * SL811HS HCD (Host Controller Driver) for USB.
3  *
4  * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
5  * Copyright (C) 2004 David Brownell
6  * 
7  * Periodic scheduling is based on Roman's OHCI code
8  *      Copyright (C) 1999 Roman Weissgaerber
9  *
10  * The SL811HS controller handles host side USB (like the SL11H, but with
11  * another register set and SOF generation) as well as peripheral side USB
12  * (like the SL811S).  This driver version doesn't implement the Gadget API
13  * for the peripheral role; or OTG (that'd need much external circuitry).
14  *
15  * For documentation, see the SL811HS spec and the "SL811HS Embedded Host"
16  * document (providing significant pieces missing from that spec); plus
17  * the SL811S spec if you want peripheral side info.
18  */ 
19
20 /*
21  * Status:  Passed basic stress testing, works with hubs, mice, keyboards,
22  * and usb-storage.
23  *
24  * TODO:
25  * - usb suspend/resume triggered by sl811 (with USB_SUSPEND)
26  * - various issues noted in the code
27  * - performance work; use both register banks; ...
28  * - use urb->iso_frame_desc[] with ISO transfers
29  */
30
31 #undef  VERBOSE
32 #undef  PACKET_TRACE
33
34 #include <linux/config.h>
35
36 #ifdef CONFIG_USB_DEBUG
37 #       define DEBUG
38 #else
39 #       undef DEBUG
40 #endif
41
42 #include <linux/module.h>
43 #include <linux/moduleparam.h>
44 #include <linux/kernel.h>
45 #include <linux/delay.h>
46 #include <linux/ioport.h>
47 #include <linux/sched.h>
48 #include <linux/slab.h>
49 #include <linux/smp_lock.h>
50 #include <linux/errno.h>
51 #include <linux/init.h>
52 #include <linux/timer.h>
53 #include <linux/list.h>
54 #include <linux/interrupt.h>
55 #include <linux/usb.h>
56 #include <linux/usb_sl811.h>
57
58 #include <asm/io.h>
59 #include <asm/irq.h>
60 #include <asm/system.h>
61 #include <asm/byteorder.h>
62
63 #include "../core/hcd.h"
64 #include "sl811.h"
65
66
67 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
68 MODULE_LICENSE("GPL");
69
70 #define DRIVER_VERSION  "06 Dec 2004"
71
72
73 #ifndef DEBUG
74 #       define  STUB_DEBUG_FILE
75 #endif
76
77 /* for now, use only one transfer register bank */
78 #undef  USE_B
79
80 /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
81  * that just queued one ISO frame per URB then iso transfers "should" work
82  * using the normal urb status fields.
83  */
84 #define DISABLE_ISO
85
86 // #define      QUIRK2
87 #define QUIRK3
88
89 static const char hcd_name[] = "sl811-hcd";
90
91 /*-------------------------------------------------------------------------*/
92
93 static irqreturn_t sl811h_irq(int irq, void *_sl811, struct pt_regs *regs);
94
95 static void port_power(struct sl811 *sl811, int is_on)
96 {
97         /* hub is inactive unless the port is powered */
98         if (is_on) {
99                 if (sl811->port1 & (1 << USB_PORT_FEAT_POWER))
100                         return;
101
102                 sl811->port1 = (1 << USB_PORT_FEAT_POWER);
103                 sl811->irq_enable = SL11H_INTMASK_INSRMV;
104                 sl811->hcd.self.controller->power.power_state = PM_SUSPEND_ON;
105         } else {
106                 sl811->port1 = 0;
107                 sl811->irq_enable = 0;
108                 sl811->hcd.state = USB_STATE_HALT;
109                 sl811->hcd.self.controller->power.power_state = PM_SUSPEND_DISK;
110         }
111         sl811->ctrl1 = 0;
112         sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
113         sl811_write(sl811, SL11H_IRQ_STATUS, ~0);
114
115         if (sl811->board && sl811->board->port_power) {
116                 /* switch VBUS, at 500mA unless hub power budget gets set */
117                 DBG("power %s\n", is_on ? "on" : "off");
118                 sl811->board->port_power(sl811->hcd.self.controller, is_on);
119         }
120
121         /* reset as thoroughly as we can */
122         if (sl811->board && sl811->board->reset)
123                 sl811->board->reset(sl811->hcd.self.controller);
124
125         sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
126         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
127         sl811_write(sl811, SL811HS_CTLREG2, SL811HS_CTL2_INIT);
128         sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
129
130         // if !is_on, put into lowpower mode now
131 }
132
133 /*-------------------------------------------------------------------------*/
134
135 /* This is a PIO-only HCD.  Queueing appends URBs to the endpoint's queue,
136  * and may start I/O.  Endpoint queues are scanned during completion irq
137  * handlers (one per packet: ACK, NAK, faults, etc) and urb cancelation.
138  *
139  * Using an external DMA engine to copy a packet at a time could work,
140  * though setup/teardown costs may be too big to make it worthwhile.
141  */
142
143 /* SETUP starts a new control request.  Devices are not allowed to
144  * STALL or NAK these; they must cancel any pending control requests.
145  */
146 static void setup_packet(
147         struct sl811            *sl811,
148         struct sl811h_ep        *ep,
149         struct urb              *urb,
150         u8                      bank,
151         u8                      control
152 )
153 {
154         u8                      addr;
155         u8                      len;
156         void __iomem            *data_reg;
157
158         addr = SL811HS_PACKET_BUF(bank == 0);
159         len = sizeof(struct usb_ctrlrequest);
160         data_reg = sl811->data_reg;
161         sl811_write_buf(sl811, addr, urb->setup_packet, len);
162
163         /* autoincrementing */
164         sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
165         writeb(len, data_reg);
166         writeb(SL_SETUP /* | ep->epnum */, data_reg);
167         writeb(usb_pipedevice(urb->pipe), data_reg);
168
169         /* always OUT/data0 */ ;
170         sl811_write(sl811, bank + SL11H_HOSTCTLREG,
171                         control | SL11H_HCTLMASK_OUT);
172         ep->length = 0;
173         PACKET("SETUP qh%p\n", ep);
174 }
175
176 /* STATUS finishes control requests, often after IN or OUT data packets */
177 static void status_packet(
178         struct sl811            *sl811,
179         struct sl811h_ep        *ep,
180         struct urb              *urb,
181         u8                      bank,
182         u8                      control
183 )
184 {
185         int                     do_out;
186         void __iomem            *data_reg;
187
188         do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
189         data_reg = sl811->data_reg;
190
191         /* autoincrementing */
192         sl811_write(sl811, bank + SL11H_BUFADDRREG, 0);
193         writeb(0, data_reg);
194         writeb((do_out ? SL_OUT : SL_IN) /* | ep->epnum */, data_reg);
195         writeb(usb_pipedevice(urb->pipe), data_reg);
196
197         /* always data1; sometimes IN */
198         control |= SL11H_HCTLMASK_TOGGLE;
199         if (do_out)
200                 control |= SL11H_HCTLMASK_OUT;
201         sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
202         ep->length = 0;
203         PACKET("STATUS%s/%s qh%p\n", ep->nak_count ? "/retry" : "",
204                         do_out ? "out" : "in", ep);
205 }
206
207 /* IN packets can be used with any type of endpoint. here we just
208  * start the transfer, data from the peripheral may arrive later.
209  * urb->iso_frame_desc is currently ignored here...
210  */
211 static void in_packet(
212         struct sl811            *sl811,
213         struct sl811h_ep        *ep,
214         struct urb              *urb,
215         u8                      bank,
216         u8                      control
217 )
218 {
219         u8                      addr;
220         u8                      len;
221         void __iomem            *data_reg;
222
223         /* avoid losing data on overflow */
224         len = ep->maxpacket;
225         addr = SL811HS_PACKET_BUF(bank == 0);
226         if (!(control & SL11H_HCTLMASK_ISOCH)
227                         && usb_gettoggle(urb->dev, ep->epnum, 0))
228                 control |= SL11H_HCTLMASK_TOGGLE;
229         data_reg = sl811->data_reg;
230
231         /* autoincrementing */
232         sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
233         writeb(len, data_reg);
234         writeb(SL_IN | ep->epnum, data_reg);
235         writeb(usb_pipedevice(urb->pipe), data_reg);
236
237         sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
238         ep->length = min((int)len,
239                         urb->transfer_buffer_length - urb->actual_length);
240         PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
241                         !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len);
242 }
243
244 /* OUT packets can be used with any type of endpoint.
245  * urb->iso_frame_desc is currently ignored here...
246  */
247 static void out_packet(
248         struct sl811            *sl811,
249         struct sl811h_ep        *ep,
250         struct urb              *urb,
251         u8                      bank,
252         u8                      control
253 )
254 {
255         void                    *buf;
256         u8                      addr;
257         u8                      len;
258         void __iomem            *data_reg;
259
260         buf = urb->transfer_buffer + urb->actual_length;
261         prefetch(buf);
262
263         len = min((int)ep->maxpacket,
264                         urb->transfer_buffer_length - urb->actual_length);
265
266         if (!(control & SL11H_HCTLMASK_ISOCH)
267                         && usb_gettoggle(urb->dev, ep->epnum, 1))
268                 control |= SL11H_HCTLMASK_TOGGLE;
269         addr = SL811HS_PACKET_BUF(bank == 0);
270         data_reg = sl811->data_reg;
271
272         sl811_write_buf(sl811, addr, buf, len);
273
274         /* autoincrementing */
275         sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
276         writeb(len, data_reg);
277         writeb(SL_OUT | ep->epnum, data_reg);
278         writeb(usb_pipedevice(urb->pipe), data_reg);
279
280         sl811_write(sl811, bank + SL11H_HOSTCTLREG,
281                         control | SL11H_HCTLMASK_OUT);
282         ep->length = len;
283         PACKET("OUT%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
284                         !!usb_gettoggle(urb->dev, ep->epnum, 1), ep, len);
285 }
286
287 /*-------------------------------------------------------------------------*/
288
289 /* caller updates on-chip enables later */
290
291 static inline void sofirq_on(struct sl811 *sl811)
292 {
293         if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
294                 return;
295         VDBG("sof irq on\n");
296         sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
297 }
298
299 static inline void sofirq_off(struct sl811 *sl811)
300 {
301         if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
302                 return;
303         VDBG("sof irq off\n");
304         sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
305 }
306
307 /*-------------------------------------------------------------------------*/
308
309 /* pick the next endpoint for a transaction, and issue it.
310  * frames start with periodic transfers (after whatever is pending
311  * from the previous frame), and the rest of the time is async
312  * transfers, scheduled round-robin.
313  */
314 static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
315 {
316         struct sl811h_ep        *ep;
317         struct sl811h_req       *req;
318         struct urb              *urb;
319         int                     fclock;
320         u8                      control;
321
322         /* use endpoint at schedule head */
323         if (sl811->next_periodic) {
324                 ep = sl811->next_periodic;
325                 sl811->next_periodic = ep->next;
326         } else {
327                 if (sl811->next_async)
328                         ep = sl811->next_async;
329                 else if (!list_empty(&sl811->async))
330                         ep = container_of(sl811->async.next,
331                                         struct sl811h_ep, schedule);
332                 else {
333                         /* could set up the first fullspeed periodic
334                          * transfer for the next frame ...
335                          */
336                         return NULL;
337                 }
338
339 #ifdef USE_B
340                 if ((bank && sl811->active_b == ep) || sl811->active_a == ep)
341                         return NULL;
342 #endif
343
344                 if (ep->schedule.next == &sl811->async)
345                         sl811->next_async = NULL;
346                 else
347                         sl811->next_async = container_of(ep->schedule.next,
348                                         struct sl811h_ep, schedule);
349         }
350
351         if (unlikely(list_empty(&ep->queue))) {
352                 DBG("empty %p queue?\n", ep);
353                 return NULL;
354         }
355
356         req = container_of(ep->queue.next, struct sl811h_req, queue);
357         urb = req->urb;
358         control = ep->defctrl;
359
360         /* if this frame doesn't have enough time left to transfer this
361          * packet, wait till the next frame.  too-simple algorithm...
362          */
363         fclock = sl811_read(sl811, SL11H_SOFTMRREG) << 6;
364         fclock -= 100;          /* setup takes not much time */
365         if (urb->dev->speed == USB_SPEED_LOW) {
366                 if (control & SL11H_HCTLMASK_PREAMBLE) {
367                         /* also note erratum 1: some hubs won't work */
368                         fclock -= 800;
369                 }
370                 fclock -= ep->maxpacket << 8;
371
372                 /* erratum 2: AFTERSOF only works for fullspeed */
373                 if (fclock < 0) {
374                         if (ep->period)
375                                 sl811->stat_overrun++;
376                         sofirq_on(sl811);
377                         return NULL;
378                 }
379         } else {
380                 fclock -= 12000 / 19;   /* 19 64byte packets/msec */
381                 if (fclock < 0) {
382                         if (ep->period)
383                                 sl811->stat_overrun++;
384                         control |= SL11H_HCTLMASK_AFTERSOF;
385
386                 /* throttle bulk/control irq noise */
387                 } else if (ep->nak_count)
388                         control |= SL11H_HCTLMASK_AFTERSOF;
389         }
390
391
392         switch (ep->nextpid) {
393         case USB_PID_IN:
394                 in_packet(sl811, ep, urb, bank, control);
395                 break;
396         case USB_PID_OUT:
397                 out_packet(sl811, ep, urb, bank, control);
398                 break;
399         case USB_PID_SETUP:
400                 setup_packet(sl811, ep, urb, bank, control);
401                 break;
402         case USB_PID_ACK:               /* for control status */
403                 status_packet(sl811, ep, urb, bank, control);
404                 break;
405         default:
406                 DBG("bad ep%p pid %02x\n", ep, ep->nextpid);
407                 ep = NULL;
408         }
409         return ep;
410 }
411
412 #define MIN_JIFFIES     ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
413
414 static inline void start_transfer(struct sl811 *sl811)
415 {
416         if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
417                 return;
418         if (sl811->active_a == NULL) {
419                 sl811->active_a = start(sl811, SL811_EP_A(SL811_HOST_BUF));
420                 if (sl811->active_a != NULL)
421                         sl811->jiffies_a = jiffies + MIN_JIFFIES;
422         }
423 #ifdef USE_B
424         if (sl811->active_b == NULL) {
425                 sl811->active_b = start(sl811, SL811_EP_B(SL811_HOST_BUF));
426                 if (sl811->active_b != NULL)
427                         sl811->jiffies_b = jiffies + MIN_JIFFIES;
428         }
429 #endif
430 }
431
432 static void finish_request(
433         struct sl811            *sl811,
434         struct sl811h_ep        *ep,
435         struct sl811h_req       *req,
436         struct pt_regs          *regs,
437         int                     status
438 ) __releases(sl811->lock) __acquires(sl811->lock)
439 {
440         unsigned                i;
441         struct urb              *urb = req->urb;
442
443         list_del(&req->queue);
444         kfree(req);
445         urb->hcpriv = NULL;
446
447         if (usb_pipecontrol(urb->pipe))
448                 ep->nextpid = USB_PID_SETUP;
449
450         spin_lock(&urb->lock);
451         if (urb->status == -EINPROGRESS)
452                 urb->status = status;
453         spin_unlock(&urb->lock);
454
455         spin_unlock(&sl811->lock);
456         usb_hcd_giveback_urb(&sl811->hcd, urb, regs);
457         spin_lock(&sl811->lock);
458
459         /* leave active endpoints in the schedule */
460         if (!list_empty(&ep->queue))
461                 return;
462
463         /* async deschedule? */
464         if (!list_empty(&ep->schedule)) {
465                 list_del_init(&ep->schedule);
466                 if (ep == sl811->next_async)
467                         sl811->next_async = NULL;
468                 return;
469         }
470
471         /* periodic deschedule */
472         DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
473         for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
474                 struct sl811h_ep        *temp;
475                 struct sl811h_ep        **prev = &sl811->periodic[i];
476
477                 while (*prev && ((temp = *prev) != ep))
478                         prev = &temp->next;
479                 if (*prev)
480                         *prev = ep->next;
481                 sl811->load[i] -= ep->load;
482         }       
483         ep->branch = PERIODIC_SIZE;
484         sl811->periodic_count--;
485         hcd_to_bus(&sl811->hcd)->bandwidth_allocated
486                 -= ep->load / ep->period;
487         if (ep == sl811->next_periodic)
488                 sl811->next_periodic = ep->next;
489
490         /* we might turn SOFs back on again for the async schedule */
491         if (sl811->periodic_count == 0)
492                 sofirq_off(sl811);
493 }
494
495 static void
496 done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank, struct pt_regs *regs)
497 {
498         u8                      status;
499         struct sl811h_req       *req;
500         struct urb              *urb;
501         int                     urbstat = -EINPROGRESS;
502
503         if (unlikely(!ep))
504                 return;
505
506         status = sl811_read(sl811, bank + SL11H_PKTSTATREG);
507
508         req = container_of(ep->queue.next, struct sl811h_req, queue);
509         urb = req->urb;
510
511         /* we can safely ignore NAKs */
512         if (status & SL11H_STATMASK_NAK) {
513                 // PACKET("...NAK_%02x qh%p\n", bank, ep);
514                 if (!ep->period)
515                         ep->nak_count++;
516                 ep->error_count = 0;
517
518         /* ACK advances transfer, toggle, and maybe queue */
519         } else if (status & SL11H_STATMASK_ACK) {
520                 struct usb_device       *udev = urb->dev;
521                 int                     len;
522                 unsigned char           *buf;
523
524                 /* urb->iso_frame_desc is currently ignored here... */
525
526                 ep->nak_count = ep->error_count = 0;
527                 switch (ep->nextpid) {
528                 case USB_PID_OUT:
529                         // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
530                         urb->actual_length += ep->length;
531                         usb_dotoggle(udev, ep->epnum, 1);
532                         if (urb->actual_length
533                                         == urb->transfer_buffer_length) {
534                                 if (usb_pipecontrol(urb->pipe))
535                                         ep->nextpid = USB_PID_ACK;
536
537                                 /* some bulk protocols terminate OUT transfers
538                                  * by a short packet, using ZLPs not padding.
539                                  */
540                                 else if (ep->length < ep->maxpacket
541                                                 || !(urb->transfer_flags
542                                                         & URB_ZERO_PACKET))
543                                         urbstat = 0;
544                         }
545                         break;
546                 case USB_PID_IN:
547                         // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
548                         buf = urb->transfer_buffer + urb->actual_length;
549                         prefetchw(buf);
550                         len = ep->maxpacket - sl811_read(sl811,
551                                                 bank + SL11H_XFERCNTREG);
552                         if (len > ep->length) {
553                                 len = ep->length;
554                                 urb->status = -EOVERFLOW;
555                         }
556                         urb->actual_length += len;
557                         sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
558                                         buf, len);
559                         usb_dotoggle(udev, ep->epnum, 0);
560                         if (urb->actual_length == urb->transfer_buffer_length)
561                                 urbstat = 0;
562                         else if (len < ep->maxpacket) {
563                                 if (urb->transfer_flags & URB_SHORT_NOT_OK)
564                                         urbstat = -EREMOTEIO;
565                                 else
566                                         urbstat = 0;
567                         }
568                         if (usb_pipecontrol(urb->pipe)
569                                         && (urbstat == -EREMOTEIO
570                                                 || urbstat == 0)) {
571
572                                 /* NOTE if the status stage STALLs (why?),
573                                  * this reports the wrong urb status.
574                                  */
575                                 spin_lock(&urb->lock);
576                                 if (urb->status == -EINPROGRESS)
577                                         urb->status = urbstat;
578                                 spin_unlock(&urb->lock);
579
580                                 req = NULL;
581                                 ep->nextpid = USB_PID_ACK;
582                         }
583                         break;
584                 case USB_PID_SETUP:
585                         // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
586                         if (urb->transfer_buffer_length == urb->actual_length)
587                                 ep->nextpid = USB_PID_ACK;
588                         else if (usb_pipeout(urb->pipe)) {
589                                 usb_settoggle(udev, 0, 1, 1);
590                                 ep->nextpid = USB_PID_OUT;
591                         } else {
592                                 usb_settoggle(udev, 0, 0, 1);
593                                 ep->nextpid = USB_PID_IN;
594                         }
595                         break;
596                 case USB_PID_ACK:
597                         // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
598                         urbstat = 0;
599                         break;
600                 }
601
602         /* STALL stops all transfers */
603         } else if (status & SL11H_STATMASK_STALL) {
604                 PACKET("...STALL_%02x qh%p\n", bank, ep);
605                 ep->nak_count = ep->error_count = 0;
606                 urbstat = -EPIPE;
607
608         /* error? retry, until "3 strikes" */
609         } else if (++ep->error_count >= 3) {
610                 if (status & SL11H_STATMASK_TMOUT)
611                         urbstat = -ETIMEDOUT;
612                 else if (status & SL11H_STATMASK_OVF)
613                         urbstat = -EOVERFLOW;
614                 else
615                         urbstat = -EPROTO;
616                 ep->error_count = 0;
617                 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
618                                 bank, status, ep, urbstat);
619         }
620
621         if ((urbstat != -EINPROGRESS || urb->status != -EINPROGRESS)
622                         && req)
623                 finish_request(sl811, ep, req, regs, urbstat);
624 }
625
626 static inline u8 checkdone(struct sl811 *sl811)
627 {
628         u8      ctl;
629         u8      irqstat = 0;
630
631         if (sl811->active_a && time_before_eq(sl811->jiffies_a, jiffies)) {
632                 ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG));
633                 if (ctl & SL11H_HCTLMASK_ARM)
634                         sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
635                 DBG("%s DONE_A: ctrl %02x sts %02x\n",
636                         (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
637                         ctl,
638                         sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
639                 irqstat |= SL11H_INTMASK_DONE_A;
640         }
641 #ifdef  USE_B
642         if (sl811->active_b && time_before_eq(sl811->jiffies_b, jiffies)) {
643                 ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG));
644                 if (ctl & SL11H_HCTLMASK_ARM)
645                         sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
646                 DBG("%s DONE_B: ctrl %02x sts %02x\n", ctl,
647                         (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
648                         ctl,
649                         sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
650                 irqstat |= SL11H_INTMASK_DONE_A;
651         }
652 #endif
653         return irqstat;
654 }
655
656 static irqreturn_t sl811h_irq(int irq, void *_sl811, struct pt_regs *regs)
657 {
658         struct sl811    *sl811 = _sl811;
659         u8              irqstat;
660         irqreturn_t     ret = IRQ_NONE;
661         unsigned        retries = 5;
662
663         spin_lock(&sl811->lock);
664
665 retry:
666         irqstat = sl811_read(sl811, SL11H_IRQ_STATUS) & ~SL11H_INTMASK_DP;
667         if (irqstat) {
668                 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
669                 irqstat &= sl811->irq_enable;
670         }
671
672 #ifdef  QUIRK2
673         /* this may no longer be necessary ... */
674         if (irqstat == 0 && ret == IRQ_NONE) {
675                 irqstat = checkdone(sl811);
676                 if (irqstat && irq != ~0)
677                         sl811->stat_lost++;
678         }
679 #endif
680
681         /* USB packets, not necessarily handled in the order they're
682          * issued ... that's fine if they're different endpoints.
683          */
684         if (irqstat & SL11H_INTMASK_DONE_A) {
685                 done(sl811, sl811->active_a, SL811_EP_A(SL811_HOST_BUF), regs);
686                 sl811->active_a = NULL;
687                 sl811->stat_a++;
688         }
689 #ifdef USE_B
690         if (irqstat & SL11H_INTMASK_DONE_B) {
691                 done(sl811, sl811->active_b, SL811_EP_B(SL811_HOST_BUF), regs);
692                 sl811->active_b = NULL;
693                 sl811->stat_b++;
694         }
695 #endif
696         if (irqstat & SL11H_INTMASK_SOFINTR) {
697                 unsigned index;
698
699                 index = sl811->frame++ % (PERIODIC_SIZE - 1);
700                 sl811->stat_sof++;
701
702                 /* be graceful about almost-inevitable periodic schedule
703                  * overruns:  continue the previous frame's transfers iff
704                  * this one has nothing scheduled.
705                  */
706                 if (sl811->next_periodic) {
707                         // ERR("overrun to slot %d\n", index);
708                         sl811->stat_overrun++;
709                 }
710                 if (sl811->periodic[index])
711                         sl811->next_periodic = sl811->periodic[index];
712         }
713
714         /* khubd manages debouncing and wakeup */
715         if (irqstat & SL11H_INTMASK_INSRMV) {
716                 sl811->stat_insrmv++;
717
718                 /* most stats are reset for each VBUS session */
719                 sl811->stat_wake = 0;
720                 sl811->stat_sof = 0;
721                 sl811->stat_a = 0;
722                 sl811->stat_b = 0;
723                 sl811->stat_lost = 0;
724
725                 sl811->ctrl1 = 0;
726                 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
727
728                 sl811->irq_enable = SL11H_INTMASK_INSRMV;
729                 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
730
731                 /* usbcore nukes other pending transactions on disconnect */
732                 if (sl811->active_a) {
733                         sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
734                         finish_request(sl811, sl811->active_a,
735                                 container_of(sl811->active_a->queue.next,
736                                         struct sl811h_req, queue),
737                                 NULL, -ESHUTDOWN);
738                         sl811->active_a = NULL;
739                 }
740 #ifdef  USE_B
741                 if (sl811->active_b) {
742                         sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
743                         finish_request(sl811, sl811->active_b,
744                                 container_of(sl811->active_b->queue.next,
745                                         struct sl811h_req, queue),
746                                 NULL, -ESHUTDOWN);
747                         sl811->active_b = NULL;
748                 }
749 #endif
750
751                 /* port status seems wierd until after reset, so
752                  * force the reset and make khubd clean up later.
753                  */
754                 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
755                                 | (1 << USB_PORT_FEAT_CONNECTION);
756
757         } else if (irqstat & SL11H_INTMASK_RD) {
758                 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
759                         DBG("wakeup\n");
760                         sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND;
761                         sl811->stat_wake++;
762                 } else
763                         irqstat &= ~SL11H_INTMASK_RD;
764         }
765
766         if (irqstat) {
767                 if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
768                         start_transfer(sl811);
769                 ret = IRQ_HANDLED;
770                 sl811->hcd.saw_irq = 1;
771                 if (retries--)
772                         goto retry;
773         }
774
775         if (sl811->periodic_count == 0 && list_empty(&sl811->async)) 
776                 sofirq_off(sl811);
777         sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
778
779         spin_unlock(&sl811->lock);
780
781         return ret;
782 }
783
784 /*-------------------------------------------------------------------------*/
785
786 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
787  * this driver doesn't promise that much since it's got to handle an
788  * IRQ per packet; irq handling latencies also use up that time.
789  */
790 #define MAX_PERIODIC_LOAD       500     /* out of 1000 usec */
791
792 static int balance(struct sl811 *sl811, u16 period, u16 load)
793 {
794         int     i, branch = -ENOSPC;
795
796         /* search for the least loaded schedule branch of that period
797          * which has enough bandwidth left unreserved.
798          */
799         for (i = 0; i < period ; i++) {
800                 if (branch < 0 || sl811->load[branch] > sl811->load[i]) {
801                         int     j;
802
803                         for (j = i; j < PERIODIC_SIZE; j += period) {
804                                 if ((sl811->load[j] + load)
805                                                 > MAX_PERIODIC_LOAD)
806                                         break;
807                         }
808                         if (j < PERIODIC_SIZE)
809                                 continue;
810                         branch = i; 
811                 }
812         }
813         return branch;
814 }
815
816 /*-------------------------------------------------------------------------*/
817
818 static int sl811h_urb_enqueue(
819         struct usb_hcd  *hcd,
820         struct urb      *urb,
821         int             mem_flags
822 ) {
823         struct sl811            *sl811 = hcd_to_sl811(hcd);
824         struct usb_device       *udev = urb->dev;
825         struct hcd_dev          *hdev = (struct hcd_dev *) udev->hcpriv;
826         unsigned int            pipe = urb->pipe;
827         int                     is_out = !usb_pipein(pipe);
828         int                     type = usb_pipetype(pipe);
829         int                     epnum = usb_pipeendpoint(pipe);
830         struct sl811h_ep        *ep = NULL;
831         struct sl811h_req       *req;
832         unsigned long           flags;
833         int                     i;
834         int                     retval = 0;
835
836 #ifdef  DISABLE_ISO
837         if (type == PIPE_ISOCHRONOUS)
838                 return -ENOSPC;
839 #endif
840
841         /* avoid all allocations within spinlocks: request or endpoint */
842         urb->hcpriv = req = kmalloc(sizeof *req, mem_flags);
843         if (!req)
844                 return -ENOMEM;
845         req->urb = urb;
846
847         i = epnum << 1;
848         if (i && is_out)
849                 i |= 1;
850         if (!hdev->ep[i])
851                 ep = kcalloc(1, sizeof *ep, mem_flags);
852
853         spin_lock_irqsave(&sl811->lock, flags);
854
855         /* don't submit to a dead or disabled port */
856         if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
857                         || !HCD_IS_RUNNING(sl811->hcd.state)) {
858                 retval = -ENODEV;
859                 goto fail;
860         }
861
862         if (hdev->ep[i]) {
863                 kfree(ep);
864                 ep = hdev->ep[i];
865         } else if (!ep) {
866                 retval = -ENOMEM;
867                 goto fail;
868
869         } else {
870                 INIT_LIST_HEAD(&ep->queue);
871                 INIT_LIST_HEAD(&ep->schedule);
872                 ep->udev = usb_get_dev(udev);
873                 ep->epnum = epnum;
874                 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
875                 ep->defctrl = SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENABLE;
876                 usb_settoggle(udev, epnum, is_out, 0);
877
878                 if (type == PIPE_CONTROL)
879                         ep->nextpid = USB_PID_SETUP;
880                 else if (is_out)
881                         ep->nextpid = USB_PID_OUT;
882                 else
883                         ep->nextpid = USB_PID_IN;
884
885                 if (ep->maxpacket > H_MAXPACKET) {
886                         /* iso packets up to 240 bytes could work... */
887                         DBG("dev %d ep%d maxpacket %d\n",
888                                 udev->devnum, epnum, ep->maxpacket);
889                         retval = -EINVAL;
890                         goto fail;
891                 }
892
893                 if (udev->speed == USB_SPEED_LOW) {
894                         /* send preamble for external hub? */
895                         if (!(sl811->ctrl1 & SL11H_CTL1MASK_LSPD))
896                                 ep->defctrl |= SL11H_HCTLMASK_PREAMBLE;
897                 }
898                 switch (type) {
899                 case PIPE_ISOCHRONOUS:
900                 case PIPE_INTERRUPT:
901                         if (urb->interval > PERIODIC_SIZE)
902                                 urb->interval = PERIODIC_SIZE;
903                         ep->period = urb->interval;
904                         ep->branch = PERIODIC_SIZE;
905                         if (type == PIPE_ISOCHRONOUS)
906                                 ep->defctrl |= SL11H_HCTLMASK_ISOCH;
907                         ep->load = usb_calc_bus_time(udev->speed, !is_out,
908                                 (type == PIPE_ISOCHRONOUS),
909                                 usb_maxpacket(udev, pipe, is_out))
910                                         / 1000;
911                         break;
912                 }
913
914                 hdev->ep[i] = ep;
915         }
916
917         /* maybe put endpoint into schedule */
918         switch (type) {
919         case PIPE_CONTROL:
920         case PIPE_BULK:
921                 if (list_empty(&ep->schedule))
922                         list_add_tail(&ep->schedule, &sl811->async);
923                 break;
924         case PIPE_ISOCHRONOUS:
925         case PIPE_INTERRUPT:
926                 urb->interval = ep->period;
927                 if (ep->branch < PERIODIC_SIZE)
928                         break;
929
930                 retval = balance(sl811, ep->period, ep->load);
931                 if (retval < 0)
932                         goto fail;
933                 ep->branch = retval;
934                 retval = 0;
935                 urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
936                                         + ep->branch;
937
938                 /* sort each schedule branch by period (slow before fast)
939                  * to share the faster parts of the tree without needing
940                  * dummy/placeholder nodes
941                  */
942                 DBG("schedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
943                 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
944                         struct sl811h_ep        **prev = &sl811->periodic[i];
945                         struct sl811h_ep        *here = *prev;
946
947                         while (here && ep != here) {
948                                 if (ep->period > here->period)
949                                         break;
950                                 prev = &here->next;
951                                 here = *prev;
952                         }
953                         if (ep != here) {
954                                 ep->next = here;
955                                 *prev = ep;
956                         }
957                         sl811->load[i] += ep->load;
958                 }
959                 sl811->periodic_count++;
960                 hcd_to_bus(&sl811->hcd)->bandwidth_allocated
961                                 += ep->load / ep->period;
962                 sofirq_on(sl811);
963         }
964
965         /* in case of unlink-during-submit */
966         spin_lock(&urb->lock);
967         if (urb->status != -EINPROGRESS) {
968                 spin_unlock(&urb->lock);
969                 finish_request(sl811, ep, req, NULL, 0);
970                 req = NULL;
971                 retval = 0;
972                 goto fail;
973         }
974         list_add_tail(&req->queue, &ep->queue);
975         spin_unlock(&urb->lock);
976
977         start_transfer(sl811);
978         sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
979 fail:
980         spin_unlock_irqrestore(&sl811->lock, flags);
981         if (retval)
982                 kfree(req);
983         return retval;
984 }
985
986 static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
987 {
988         struct sl811            *sl811 = hcd_to_sl811(hcd);
989         struct usb_device       *udev = urb->dev;
990         struct hcd_dev          *hdev = (struct hcd_dev *) udev->hcpriv;
991         unsigned int            pipe = urb->pipe;
992         int                     is_out = !usb_pipein(pipe);
993         unsigned long           flags;
994         unsigned                i;
995         struct sl811h_ep        *ep;
996         struct sl811h_req       *req = urb->hcpriv;
997         int                     retval = 0;
998
999         i = usb_pipeendpoint(pipe) << 1;
1000         if (i && is_out)
1001                 i |= 1;
1002
1003         spin_lock_irqsave(&sl811->lock, flags);
1004         ep = hdev->ep[i];
1005         if (ep) {
1006                 /* finish right away if this urb can't be active ...
1007                  * note that some drivers wrongly expect delays
1008                  */
1009                 if (ep->queue.next != &req->queue) {
1010                         /* not front of queue?  never active */
1011
1012                 /* for active transfers, we expect an IRQ */
1013                 } else if (sl811->active_a == ep) {
1014                         if (time_before_eq(sl811->jiffies_a, jiffies)) {
1015                                 /* happens a lot with lowspeed?? */
1016                                 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
1017                                         sl811_read(sl811,
1018                                                 SL811_EP_A(SL11H_HOSTCTLREG)),
1019                                         sl811_read(sl811,
1020                                                 SL811_EP_A(SL11H_PKTSTATREG)));
1021                                 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1022                                                 0);
1023                                 sl811->active_a = NULL;
1024                         } else
1025                                 req = NULL;
1026 #ifdef  USE_B
1027                 } else if (sl811->active_b == ep) {
1028                         if (time_before_eq(sl811->jiffies_a, jiffies)) {
1029                                 /* happens a lot with lowspeed?? */
1030                                 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1031                                         sl811_read(sl811,
1032                                                 SL811_EP_B(SL11H_HOSTCTLREG)),
1033                                         sl811_read(sl811,
1034                                                 SL811_EP_B(SL11H_PKTSTATREG)));
1035                                 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG),
1036                                                 0);
1037                                 sl811->active_b = NULL;
1038                         } else
1039                                 req = NULL;
1040 #endif
1041                 } else {
1042                         /* front of queue for inactive endpoint */
1043                 }
1044
1045                 if (req)
1046                         finish_request(sl811, ep, req, NULL, 0);
1047                 else
1048                         VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1049                                 (sl811->active_a == ep) ? "A" : "B");
1050         } else
1051                 retval = -EINVAL;
1052         spin_unlock_irqrestore(&sl811->lock, flags);
1053         return retval;
1054 }
1055
1056 static void
1057 sl811h_endpoint_disable(struct usb_hcd *hcd, struct hcd_dev *hdev, int epnum)
1058 {
1059         struct sl811            *sl811 = hcd_to_sl811(hcd);
1060         struct sl811h_ep        *ep;
1061         unsigned long           flags;
1062         int                     i;
1063
1064         i = (epnum & 0xf) << 1;
1065         if (epnum && !(epnum & USB_DIR_IN))
1066                 i |= 1;
1067
1068         spin_lock_irqsave(&sl811->lock, flags);
1069         ep = hdev->ep[i];
1070         hdev->ep[i] = NULL;
1071         spin_unlock_irqrestore(&sl811->lock, flags);
1072
1073         if (ep) {
1074                 /* assume we'd just wait for the irq */
1075                 if (!list_empty(&ep->queue))
1076                         msleep(3);
1077                 if (!list_empty(&ep->queue))
1078                         WARN("ep %p not empty?\n", ep);
1079
1080                 usb_put_dev(ep->udev);
1081                 kfree(ep);
1082         }
1083         return;
1084 }
1085
1086 static int
1087 sl811h_get_frame(struct usb_hcd *hcd)
1088 {
1089         struct sl811 *sl811 = hcd_to_sl811(hcd);
1090
1091         /* wrong except while periodic transfers are scheduled;
1092          * never matches the on-the-wire frame;
1093          * subject to overruns.
1094          */
1095         return sl811->frame;
1096 }
1097
1098
1099 /*-------------------------------------------------------------------------*/
1100
1101 /* the virtual root hub timer IRQ checks for hub status */
1102 static int
1103 sl811h_hub_status_data(struct usb_hcd *hcd, char *buf)
1104 {
1105         struct sl811 *sl811 = hcd_to_sl811(hcd);
1106 #ifdef  QUIRK3
1107         unsigned long flags;
1108
1109         /* non-SMP HACK: use root hub timer as i/o watchdog
1110          * this seems essential when SOF IRQs aren't in use...
1111          */
1112         local_irq_save(flags);
1113         if (!timer_pending(&sl811->timer)) {
1114                 if (sl811h_irq(~0, sl811, NULL) != IRQ_NONE)
1115                         sl811->stat_lost++;
1116         }
1117         local_irq_restore(flags);
1118 #endif
1119
1120         if (!(sl811->port1 & (0xffff << 16)))
1121                 return 0;
1122
1123         /* tell khubd port 1 changed */
1124         *buf = (1 << 1);
1125         return 1;
1126 }
1127
1128 static void
1129 sl811h_hub_descriptor (
1130         struct sl811                    *sl811,
1131         struct usb_hub_descriptor       *desc
1132 ) {
1133         u16             temp = 0;
1134
1135         desc->bDescriptorType = 0x29;
1136         desc->bHubContrCurrent = 0;
1137
1138         desc->bNbrPorts = 1;
1139         desc->bDescLength = 9;
1140
1141         /* per-port power switching (gang of one!), or none */
1142         desc->bPwrOn2PwrGood = 0;
1143         if (sl811->board && sl811->board->port_power) {
1144                 desc->bPwrOn2PwrGood = sl811->board->potpg;
1145                 if (!desc->bPwrOn2PwrGood)
1146                         desc->bPwrOn2PwrGood = 10;
1147                 temp = 0x0001;
1148         } else
1149                 temp = 0x0002;
1150
1151         /* no overcurrent errors detection/handling */
1152         temp |= 0x0010;
1153
1154         desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp);
1155
1156         /* two bitmaps:  ports removable, and legacy PortPwrCtrlMask */
1157         desc->bitmap[0] = 1 << 1;
1158         desc->bitmap[1] = ~0;
1159 }
1160
1161 static void
1162 sl811h_timer(unsigned long _sl811)
1163 {
1164         struct sl811    *sl811 = (void *) _sl811;
1165         unsigned long   flags;
1166         u8              irqstat;
1167         u8              signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE;
1168         const u32       mask = (1 << USB_PORT_FEAT_CONNECTION)
1169                                 | (1 << USB_PORT_FEAT_ENABLE)
1170                                 | (1 << USB_PORT_FEAT_LOWSPEED);
1171
1172         spin_lock_irqsave(&sl811->lock, flags);
1173
1174         /* stop special signaling */
1175         sl811->ctrl1 &= ~SL11H_CTL1MASK_FORCE;
1176         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1177         udelay(3);
1178
1179         irqstat = sl811_read(sl811, SL11H_IRQ_STATUS);
1180
1181         switch (signaling) {
1182         case SL11H_CTL1MASK_SE0:
1183                 DBG("end reset\n");
1184                 sl811->port1 = (1 << USB_PORT_FEAT_C_RESET)
1185                                 | (1 << USB_PORT_FEAT_POWER);
1186                 sl811->ctrl1 = 0;
1187                 /* don't wrongly ack RD */
1188                 if (irqstat & SL11H_INTMASK_INSRMV)
1189                         irqstat &= ~SL11H_INTMASK_RD;
1190                 break;
1191         case SL11H_CTL1MASK_K:
1192                 DBG("end resume\n");
1193                 sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND);
1194                 break;
1195         default:
1196                 DBG("odd timer signaling: %02x\n", signaling);
1197                 break;
1198         }
1199         sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
1200
1201         if (irqstat & SL11H_INTMASK_RD) {
1202                 /* usbcore nukes all pending transactions on disconnect */
1203                 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION))
1204                         sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
1205                                         | (1 << USB_PORT_FEAT_C_ENABLE);
1206                 sl811->port1 &= ~mask;
1207                 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1208         } else {
1209                 sl811->port1 |= mask;
1210                 if (irqstat & SL11H_INTMASK_DP)
1211                         sl811->port1 &= ~(1 << USB_PORT_FEAT_LOWSPEED);
1212                 sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD;
1213         }
1214
1215         if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) {
1216                 u8      ctrl2 = SL811HS_CTL2_INIT;
1217
1218                 sl811->irq_enable |= SL11H_INTMASK_DONE_A;
1219 #ifdef USE_B
1220                 sl811->irq_enable |= SL11H_INTMASK_DONE_B;
1221 #endif
1222                 if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) {
1223                         sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
1224                         ctrl2 |= SL811HS_CTL2MASK_DSWAP;
1225                 }
1226
1227                 /* start SOFs flowing, kickstarting with A registers */
1228                 sl811->ctrl1 |= SL11H_CTL1MASK_SOF_ENA;
1229                 sl811_write(sl811, SL11H_SOFLOWREG, 0xe0);
1230                 sl811_write(sl811, SL811HS_CTLREG2, ctrl2);
1231
1232                 /* autoincrementing */
1233                 sl811_write(sl811, SL811_EP_A(SL11H_BUFLNTHREG), 0);
1234                 writeb(SL_SOF, sl811->data_reg);
1235                 writeb(0, sl811->data_reg);
1236                 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1237                                 SL11H_HCTLMASK_ARM);
1238
1239                 /* khubd provides debounce delay */
1240         } else {
1241                 sl811->ctrl1 = 0;
1242         }
1243         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1244
1245         /* reenable irqs */
1246         sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
1247         spin_unlock_irqrestore(&sl811->lock, flags);
1248 }
1249
1250 static int
1251 sl811h_hub_control(
1252         struct usb_hcd  *hcd,
1253         u16             typeReq,
1254         u16             wValue,
1255         u16             wIndex,
1256         char            *buf,
1257         u16             wLength
1258 ) {
1259         struct sl811    *sl811 = hcd_to_sl811(hcd);
1260         int             retval = 0;
1261         unsigned long   flags;
1262
1263         spin_lock_irqsave(&sl811->lock, flags);
1264
1265         switch (typeReq) {
1266         case ClearHubFeature:
1267         case SetHubFeature:
1268                 switch (wValue) {
1269                 case C_HUB_OVER_CURRENT:
1270                 case C_HUB_LOCAL_POWER:
1271                         break;
1272                 default:
1273                         goto error;
1274                 }
1275                 break;
1276         case ClearPortFeature:
1277                 if (wIndex != 1 || wLength != 0)
1278                         goto error;
1279
1280                 switch (wValue) {
1281                 case USB_PORT_FEAT_ENABLE:
1282                         sl811->port1 &= (1 << USB_PORT_FEAT_POWER);
1283                         sl811->ctrl1 = 0;
1284                         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1285                         sl811->irq_enable = SL11H_INTMASK_INSRMV;
1286                         sl811_write(sl811, SL11H_IRQ_ENABLE,
1287                                                 sl811->irq_enable);
1288                         break;
1289                 case USB_PORT_FEAT_SUSPEND:
1290                         if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)))
1291                                 break;
1292
1293                         /* 20 msec of resume/K signaling, other irqs blocked */
1294                         DBG("start resume...\n");
1295                         sl811->irq_enable = 0;
1296                         sl811_write(sl811, SL11H_IRQ_ENABLE,
1297                                                 sl811->irq_enable);
1298                         sl811->ctrl1 |= SL11H_CTL1MASK_K;
1299                         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1300
1301                         mod_timer(&sl811->timer, jiffies
1302                                         + msecs_to_jiffies(20));
1303                         break;
1304                 case USB_PORT_FEAT_POWER:
1305                         port_power(sl811, 0);
1306                         break;
1307                 case USB_PORT_FEAT_C_ENABLE:
1308                 case USB_PORT_FEAT_C_SUSPEND:
1309                 case USB_PORT_FEAT_C_CONNECTION:
1310                 case USB_PORT_FEAT_C_OVER_CURRENT:
1311                 case USB_PORT_FEAT_C_RESET:
1312                         break;
1313                 default:
1314                         goto error;
1315                 }
1316                 sl811->port1 &= ~(1 << wValue);
1317                 break;
1318         case GetHubDescriptor:
1319                 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
1320                 break;
1321         case GetHubStatus:
1322                 *(__le32 *) buf = cpu_to_le32(0);
1323                 break;
1324         case GetPortStatus:
1325                 if (wIndex != 1)
1326                         goto error;
1327                 *(__le32 *) buf = cpu_to_le32(sl811->port1);
1328
1329 #ifndef VERBOSE
1330         if (*(u16*)(buf+2))     /* only if wPortChange is interesting */
1331 #endif
1332                 DBG("GetPortStatus %08x\n", sl811->port1);
1333                 break;
1334         case SetPortFeature:
1335                 if (wIndex != 1 || wLength != 0)
1336                         goto error;
1337                 switch (wValue) {
1338                 case USB_PORT_FEAT_SUSPEND:
1339                         if (sl811->port1 & (1 << USB_PORT_FEAT_RESET))
1340                                 goto error;
1341                         if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)))
1342                                 goto error;
1343
1344                         DBG("suspend...\n");
1345                         sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
1346                         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1347                         break;
1348                 case USB_PORT_FEAT_POWER:
1349                         port_power(sl811, 1);
1350                         break;
1351                 case USB_PORT_FEAT_RESET:
1352                         if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
1353                                 goto error;
1354                         if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER)))
1355                                 break;
1356
1357                         /* 50 msec of reset/SE0 signaling, irqs blocked */
1358                         sl811->irq_enable = 0;
1359                         sl811_write(sl811, SL11H_IRQ_ENABLE,
1360                                                 sl811->irq_enable);
1361                         sl811->ctrl1 = SL11H_CTL1MASK_SE0;
1362                         sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1363                         sl811->port1 |= (1 << USB_PORT_FEAT_RESET);
1364                         mod_timer(&sl811->timer, jiffies
1365                                         + msecs_to_jiffies(50));
1366                         break;
1367                 default:
1368                         goto error;
1369                 }
1370                 sl811->port1 |= 1 << wValue;
1371                 break;
1372
1373         default:
1374 error:
1375                 /* "protocol stall" on error */
1376                 retval = -EPIPE;
1377         }
1378
1379         spin_unlock_irqrestore(&sl811->lock, flags);
1380         return retval;
1381 }
1382
1383 #ifdef  CONFIG_PM
1384
1385 static int
1386 sl811h_hub_suspend(struct usb_hcd *hcd)
1387 {
1388         // SOFs off
1389         DBG("%s\n", __FUNCTION__);
1390         return 0;
1391 }
1392
1393 static int
1394 sl811h_hub_resume(struct usb_hcd *hcd)
1395 {
1396         // SOFs on
1397         DBG("%s\n", __FUNCTION__);
1398         return 0;
1399 }
1400
1401 #else
1402
1403 #define sl811h_hub_suspend      NULL
1404 #define sl811h_hub_resume       NULL
1405
1406 #endif
1407
1408
1409 /*-------------------------------------------------------------------------*/
1410
1411 #ifdef STUB_DEBUG_FILE
1412
1413 static inline void create_debug_file(struct sl811 *sl811) { }
1414 static inline void remove_debug_file(struct sl811 *sl811) { }
1415
1416 #else
1417
1418 #include <linux/proc_fs.h>
1419 #include <linux/seq_file.h>
1420
1421 static void dump_irq(struct seq_file *s, char *label, u8 mask)
1422 {
1423         seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask,
1424                 (mask & SL11H_INTMASK_DONE_A) ? " done_a" : "",
1425                 (mask & SL11H_INTMASK_DONE_B) ? " done_b" : "",
1426                 (mask & SL11H_INTMASK_SOFINTR) ? " sof" : "",
1427                 (mask & SL11H_INTMASK_INSRMV) ? " ins/rmv" : "",
1428                 (mask & SL11H_INTMASK_RD) ? " rd" : "",
1429                 (mask & SL11H_INTMASK_DP) ? " dp" : "");
1430 }
1431
1432 static int proc_sl811h_show(struct seq_file *s, void *unused)
1433 {
1434         struct sl811            *sl811 = s->private;
1435         struct sl811h_ep        *ep;
1436         unsigned                i;
1437
1438         seq_printf(s, "%s\n%s version %s\nportstatus[1] = %08x\n",
1439                 sl811->hcd.product_desc,
1440                 hcd_name, DRIVER_VERSION,
1441                 sl811->port1);
1442
1443         seq_printf(s, "insert/remove: %ld\n", sl811->stat_insrmv);
1444         seq_printf(s, "current session:  done_a %ld done_b %ld "
1445                         "wake %ld sof %ld overrun %ld lost %ld\n\n",
1446                 sl811->stat_a, sl811->stat_b,
1447                 sl811->stat_wake, sl811->stat_sof,
1448                 sl811->stat_overrun, sl811->stat_lost);
1449
1450         spin_lock_irq(&sl811->lock);
1451
1452         if (sl811->ctrl1 & SL11H_CTL1MASK_SUSPEND)
1453                 seq_printf(s, "(suspended)\n\n");
1454         else {
1455                 u8      t = sl811_read(sl811, SL11H_CTLREG1);
1456
1457                 seq_printf(s, "ctrl1 %02x%s%s%s%s\n", t,
1458                         (t & SL11H_CTL1MASK_SOF_ENA) ? " sofgen" : "",
1459                         ({char *s; switch (t & SL11H_CTL1MASK_FORCE) {
1460                         case SL11H_CTL1MASK_NORMAL: s = ""; break;
1461                         case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
1462                         case SL11H_CTL1MASK_K: s = " k/resume"; break;
1463                         default: s = "j"; break;
1464                         }; s; }),
1465                         (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1466                         (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
1467
1468                 dump_irq(s, "irq_enable",
1469                                 sl811_read(sl811, SL11H_IRQ_ENABLE));
1470                 dump_irq(s, "irq_status",
1471                                 sl811_read(sl811, SL11H_IRQ_STATUS));
1472                 seq_printf(s, "frame clocks remaining:  %d\n",
1473                                 sl811_read(sl811, SL11H_SOFTMRREG) << 6);
1474         }
1475
1476         seq_printf(s, "A: qh%p ctl %02x sts %02x\n", sl811->active_a,
1477                 sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG)),
1478                 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
1479         seq_printf(s, "B: qh%p ctl %02x sts %02x\n", sl811->active_b,
1480                 sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG)),
1481                 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
1482         seq_printf(s, "\n");
1483         list_for_each_entry (ep, &sl811->async, schedule) {
1484                 struct sl811h_req       *req;
1485
1486                 seq_printf(s, "%s%sqh%p, ep%d%s, maxpacket %d"
1487                                         " nak %d err %d\n",
1488                         (ep == sl811->active_a) ? "(A) " : "",
1489                         (ep == sl811->active_b) ? "(B) " : "",
1490                         ep, ep->epnum,
1491                         ({ char *s; switch (ep->nextpid) {
1492                         case USB_PID_IN: s = "in"; break;
1493                         case USB_PID_OUT: s = "out"; break;
1494                         case USB_PID_SETUP: s = "setup"; break;
1495                         case USB_PID_ACK: s = "status"; break;
1496                         default: s = "?"; break;
1497                         }; s;}),
1498                         ep->maxpacket,
1499                         ep->nak_count, ep->error_count);
1500                 list_for_each_entry (req, &ep->queue, queue) {
1501                         seq_printf(s, "  urb%p, %d/%d\n", req->urb,
1502                                 req->urb->actual_length,
1503                                 req->urb->transfer_buffer_length);
1504                 }
1505         }
1506         if (!list_empty(&sl811->async))
1507                 seq_printf(s, "\n");
1508
1509         seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1510
1511         for (i = 0; i < PERIODIC_SIZE; i++) {
1512                 ep = sl811->periodic[i];
1513                 if (!ep)
1514                         continue;
1515                 seq_printf(s, "%2d [%3d]:\n", i, sl811->load[i]);
1516
1517                 /* DUMB: prints shared entries multiple times */
1518                 do {
1519                         seq_printf(s,
1520                                 "   %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1521                                         "err %d\n",
1522                                 (ep == sl811->active_a) ? "(A) " : "",
1523                                 (ep == sl811->active_b) ? "(B) " : "",
1524                                 ep->period, ep,
1525                                 (ep->udev->speed == USB_SPEED_FULL)
1526                                         ? "" : "ls ",
1527                                 ep->udev->devnum, ep->epnum,
1528                                 (ep->epnum == 0) ? ""
1529                                         : ((ep->nextpid == USB_PID_IN)
1530                                                 ? "in"
1531                                                 : "out"),
1532                                 ep->maxpacket, ep->error_count);
1533                         ep = ep->next;
1534                 } while (ep);
1535         }
1536
1537         spin_unlock_irq(&sl811->lock);
1538         seq_printf(s, "\n");
1539
1540         return 0;
1541 }
1542
1543 static int proc_sl811h_open(struct inode *inode, struct file *file)
1544 {
1545         return single_open(file, proc_sl811h_show, PDE(inode)->data);
1546 }
1547
1548 static struct file_operations proc_ops = {
1549         .open           = proc_sl811h_open,
1550         .read           = seq_read,
1551         .llseek         = seq_lseek,
1552         .release        = single_release,
1553 };
1554
1555 /* expect just one sl811 per system */
1556 static const char proc_filename[] = "driver/sl811h";
1557
1558 static void create_debug_file(struct sl811 *sl811)
1559 {
1560         struct proc_dir_entry *pde;
1561
1562         pde = create_proc_entry(proc_filename, 0, NULL);
1563         if (pde == NULL)
1564                 return;
1565
1566         pde->proc_fops = &proc_ops;
1567         pde->data = sl811;
1568         sl811->pde = pde;
1569 }
1570
1571 static void remove_debug_file(struct sl811 *sl811)
1572 {
1573         if (sl811->pde)
1574                 remove_proc_entry(proc_filename, NULL);
1575 }
1576
1577 #endif
1578
1579 /*-------------------------------------------------------------------------*/
1580
1581 static void
1582 sl811h_stop(struct usb_hcd *hcd)
1583 {
1584         struct sl811    *sl811 = hcd_to_sl811(hcd);
1585         unsigned long   flags;
1586
1587         del_timer_sync(&sl811->hcd.rh_timer);
1588
1589         spin_lock_irqsave(&sl811->lock, flags);
1590         port_power(sl811, 0);
1591         spin_unlock_irqrestore(&sl811->lock, flags);
1592 }
1593
1594 static int
1595 sl811h_start(struct usb_hcd *hcd)
1596 {
1597         struct sl811            *sl811 = hcd_to_sl811(hcd);
1598         struct usb_device       *udev;
1599
1600         /* chip has been reset, VBUS power is off */
1601
1602         udev = usb_alloc_dev(NULL, &sl811->hcd.self, 0);
1603         if (!udev)
1604                 return -ENOMEM;
1605
1606         udev->speed = USB_SPEED_FULL;
1607         hcd->state = USB_STATE_RUNNING;
1608
1609         if (sl811->board)
1610                 sl811->hcd.can_wakeup = sl811->board->can_wakeup;
1611
1612         if (hcd_register_root(udev, &sl811->hcd) != 0) {
1613                 usb_put_dev(udev);
1614                 sl811h_stop(hcd);
1615                 return -ENODEV;
1616         }
1617
1618         if (sl811->board && sl811->board->power)
1619                 hub_set_power_budget(udev, sl811->board->power * 2);
1620
1621         return 0;
1622 }
1623
1624 /*-------------------------------------------------------------------------*/
1625
1626 static struct hc_driver sl811h_hc_driver = {
1627         .description =          hcd_name,
1628
1629         /*
1630          * generic hardware linkage
1631          */
1632         .flags =                HCD_USB11,
1633
1634         /*
1635          * managing i/o requests and associated device resources
1636          */
1637         .urb_enqueue =          sl811h_urb_enqueue,
1638         .urb_dequeue =          sl811h_urb_dequeue,
1639         .endpoint_disable =     sl811h_endpoint_disable,
1640
1641         /*
1642          * periodic schedule support
1643          */
1644         .get_frame_number =     sl811h_get_frame,
1645
1646         /*
1647          * root hub support
1648          */
1649         .hub_status_data =      sl811h_hub_status_data,
1650         .hub_control =          sl811h_hub_control,
1651         .hub_suspend =          sl811h_hub_suspend,
1652         .hub_resume =           sl811h_hub_resume,
1653 };
1654
1655 /*-------------------------------------------------------------------------*/
1656
1657 static int __init_or_module
1658 sl811h_remove(struct device *dev)
1659 {
1660         struct sl811            *sl811 = dev_get_drvdata(dev);
1661         struct platform_device  *pdev;
1662         struct resource         *res;
1663
1664         pdev = container_of(dev, struct platform_device, dev);
1665
1666         if (HCD_IS_RUNNING(sl811->hcd.state))
1667                 sl811->hcd.state = USB_STATE_QUIESCING;
1668
1669         usb_disconnect(&sl811->hcd.self.root_hub);
1670         remove_debug_file(sl811);
1671         sl811h_stop(&sl811->hcd);
1672
1673         if (!list_empty(&sl811->hcd.self.bus_list))
1674                 usb_deregister_bus(&sl811->hcd.self);
1675
1676         if (sl811->hcd.irq >= 0)
1677                 free_irq(sl811->hcd.irq, sl811);
1678
1679         if (sl811->data_reg)
1680                 iounmap(sl811->data_reg);
1681         res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1682         release_mem_region(res->start, 1);
1683
1684         if (sl811->addr_reg) 
1685                 iounmap(sl811->addr_reg);
1686         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1687         release_mem_region(res->start, 1);
1688
1689         kfree(sl811);
1690         return 0;
1691 }
1692
1693 #define resource_len(r) (((r)->end - (r)->start) + 1)
1694
1695 static int __init
1696 sl811h_probe(struct device *dev)
1697 {
1698         struct sl811            *sl811;
1699         struct platform_device  *pdev;
1700         struct resource         *addr, *data;
1701         int                     irq;
1702         int                     status;
1703         u8                      tmp;
1704         unsigned long           flags;
1705
1706         /* basic sanity checks first.  board-specific init logic should
1707          * have initialized these three resources and probably board
1708          * specific platform_data.  we don't probe for IRQs, and do only
1709          * minimal sanity checking.
1710          */
1711         pdev = container_of(dev, struct platform_device, dev);
1712         if (pdev->num_resources < 3)
1713                 return -ENODEV;
1714
1715         addr = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1716         data = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1717         irq = platform_get_irq(pdev, 0);
1718         if (!addr || !data || irq < 0)
1719                 return -ENODEV;
1720
1721         /* refuse to confuse usbcore */
1722         if (dev->dma_mask) {
1723                 DBG("no we won't dma\n");
1724                 return -EINVAL;
1725         }
1726
1727         if (!request_mem_region(addr->start, 1, hcd_name))
1728                 return -EBUSY;
1729         if (!request_mem_region(data->start, 1, hcd_name)) {
1730                 release_mem_region(addr->start, 1);
1731                 return -EBUSY;
1732         }
1733
1734         /* allocate and initialize hcd */
1735         sl811 = kcalloc(1, sizeof *sl811, GFP_KERNEL);
1736         if (!sl811)
1737                 return 0;
1738         dev_set_drvdata(dev, sl811);
1739
1740         usb_bus_init(&sl811->hcd.self);
1741         sl811->hcd.self.controller = dev;
1742         sl811->hcd.self.bus_name = dev->bus_id;
1743         sl811->hcd.self.op = &usb_hcd_operations;
1744         sl811->hcd.self.hcpriv = sl811;
1745
1746         // NOTE: 2.6.11 starts to change the hcd glue layer some more,
1747         // eventually letting us eliminate struct sl811h_req and a
1748         // lot of the boilerplate code here 
1749
1750         INIT_LIST_HEAD(&sl811->hcd.dev_list);
1751         sl811->hcd.self.release = &usb_hcd_release;
1752
1753         sl811->hcd.description = sl811h_hc_driver.description;
1754         init_timer(&sl811->hcd.rh_timer);
1755         sl811->hcd.driver = &sl811h_hc_driver;
1756         sl811->hcd.irq = -1;
1757         sl811->hcd.state = USB_STATE_HALT;
1758
1759         spin_lock_init(&sl811->lock);
1760         INIT_LIST_HEAD(&sl811->async);
1761         sl811->board = dev->platform_data;
1762         init_timer(&sl811->timer);
1763         sl811->timer.function = sl811h_timer;
1764         sl811->timer.data = (unsigned long) sl811;
1765
1766         sl811->addr_reg = ioremap(addr->start, resource_len(addr));
1767         if (sl811->addr_reg == NULL) {
1768                 status = -ENOMEM;
1769                 goto fail;
1770         }
1771         sl811->data_reg = ioremap(data->start, resource_len(addr));
1772         if (sl811->data_reg == NULL) {
1773                 status = -ENOMEM;
1774                 goto fail;
1775         }
1776
1777         spin_lock_irqsave(&sl811->lock, flags);
1778         port_power(sl811, 0);
1779         spin_unlock_irqrestore(&sl811->lock, flags);
1780         msleep(200);
1781
1782         tmp = sl811_read(sl811, SL11H_HWREVREG);
1783         switch (tmp >> 4) {
1784         case 1:
1785                 sl811->hcd.product_desc = "SL811HS v1.2";
1786                 break;
1787         case 2:
1788                 sl811->hcd.product_desc = "SL811HS v1.5";
1789                 break;
1790         default:
1791                 /* reject case 0, SL11S is less functional */
1792                 DBG("chiprev %02x\n", tmp);
1793                 status = -ENXIO;
1794                 goto fail;
1795         }
1796
1797         /* sl811s would need a different handler for this irq */
1798 #ifdef  CONFIG_ARM
1799         /* Cypress docs say the IRQ is IRQT_HIGH ... */
1800         set_irq_type(irq, IRQT_RISING);
1801 #endif
1802         status = request_irq(irq, sl811h_irq, SA_INTERRUPT, hcd_name, sl811);
1803         if (status < 0)
1804                 goto fail;
1805         sl811->hcd.irq = irq;
1806
1807         INFO("%s, irq %d\n", sl811->hcd.product_desc, irq);
1808
1809         status = usb_register_bus(&sl811->hcd.self);
1810         if (status < 0)
1811                 goto fail;
1812         status = sl811h_start(&sl811->hcd);
1813         if (status == 0) {
1814                 create_debug_file(sl811);
1815                 return 0;
1816         }
1817 fail:
1818         sl811h_remove(dev);
1819         DBG("init error, %d\n", status);
1820         return status;
1821 }
1822
1823 #ifdef  CONFIG_PM
1824
1825 /* for this device there's no useful distinction between the controller
1826  * and its root hub, except that the root hub only gets direct PM calls 
1827  * when CONFIG_USB_SUSPEND is enabled.
1828  */
1829
1830 static int
1831 sl811h_suspend(struct device *dev, u32 state, u32 phase)
1832 {
1833         struct sl811    *sl811 = dev_get_drvdata(dev);
1834         int             retval = 0;
1835
1836         if (phase != SUSPEND_POWER_DOWN)
1837                 return retval;
1838
1839         if (state <= PM_SUSPEND_MEM)
1840                 retval = sl811h_hub_suspend(&sl811->hcd);
1841         else
1842                 port_power(sl811, 0);
1843         if (retval == 0)
1844                 dev->power.power_state = state;
1845         return retval;
1846 }
1847
1848 static int
1849 sl811h_resume(struct device *dev, u32 phase)
1850 {
1851         struct sl811    *sl811 = dev_get_drvdata(dev);
1852
1853         if (phase != RESUME_POWER_ON)
1854                 return 0;
1855
1856         /* with no "check to see if VBUS is still powered" board hook,
1857          * let's assume it'd only be powered to enable remote wakeup.
1858          */
1859         if (dev->power.power_state > PM_SUSPEND_MEM
1860                         || !sl811->hcd.can_wakeup) {
1861                 sl811->port1 = 0;
1862                 port_power(sl811, 1);
1863                 return 0;
1864         }
1865
1866         dev->power.power_state = PM_SUSPEND_ON;
1867         return sl811h_hub_resume(&sl811->hcd);
1868 }
1869
1870 #else
1871
1872 #define sl811h_suspend  NULL
1873 #define sl811h_resume   NULL
1874
1875 #endif
1876
1877
1878 static struct device_driver sl811h_driver = {
1879         .name =         (char *) hcd_name,
1880         .bus =          &platform_bus_type,
1881
1882         .probe =        sl811h_probe,
1883         .remove =       sl811h_remove,
1884
1885         .suspend =      sl811h_suspend,
1886         .resume =       sl811h_resume,
1887 };
1888
1889 /*-------------------------------------------------------------------------*/
1890  
1891 static int __init sl811h_init(void) 
1892 {
1893         if (usb_disabled())
1894                 return -ENODEV;
1895
1896         INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1897         return driver_register(&sl811h_driver);
1898 }
1899 module_init(sl811h_init);
1900
1901 static void __exit sl811h_cleanup(void) 
1902 {       
1903         driver_unregister(&sl811h_driver);
1904 }
1905 module_exit(sl811h_cleanup);