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