2 * SL811HS HCD (Host Controller Driver) for USB.
4 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
5 * Copyright (C) 2004 David Brownell
7 * Periodic scheduling is based on Roman's OHCI code
8 * Copyright (C) 1999 Roman Weissgaerber
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).
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.
21 * Status: Passed basic stress testing, works with hubs, mice, keyboards,
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
34 #include <linux/config.h>
36 #ifdef CONFIG_USB_DEBUG
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>
60 #include <asm/system.h>
61 #include <asm/byteorder.h>
63 #include "../core/hcd.h"
67 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
68 MODULE_LICENSE("GPL");
70 #define DRIVER_VERSION "06 Dec 2004"
74 # define STUB_DEBUG_FILE
77 /* for now, use only one transfer register bank */
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.
89 static const char hcd_name[] = "sl811-hcd";
91 /*-------------------------------------------------------------------------*/
93 static irqreturn_t sl811h_irq(int irq, void *_sl811, struct pt_regs *regs);
95 static void port_power(struct sl811 *sl811, int is_on)
97 /* hub is inactive unless the port is powered */
99 if (sl811->port1 & (1 << USB_PORT_FEAT_POWER))
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;
107 sl811->irq_enable = 0;
108 sl811->hcd.state = USB_STATE_HALT;
109 sl811->hcd.self.controller->power.power_state = PM_SUSPEND_DISK;
112 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
113 sl811_write(sl811, SL11H_IRQ_STATUS, ~0);
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);
121 /* reset as thoroughly as we can */
122 if (sl811->board && sl811->board->reset)
123 sl811->board->reset(sl811->hcd.self.controller);
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);
130 // if !is_on, put into lowpower mode now
133 /*-------------------------------------------------------------------------*/
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.
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.
143 /* SETUP starts a new control request. Devices are not allowed to
144 * STALL or NAK these; they must cancel any pending control requests.
146 static void setup_packet(
148 struct sl811h_ep *ep,
156 void __iomem *data_reg;
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);
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);
169 /* always OUT/data0 */ ;
170 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
171 control | SL11H_HCTLMASK_OUT);
173 PACKET("SETUP qh%p\n", ep);
176 /* STATUS finishes control requests, often after IN or OUT data packets */
177 static void status_packet(
179 struct sl811h_ep *ep,
186 void __iomem *data_reg;
188 do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
189 data_reg = sl811->data_reg;
191 /* autoincrementing */
192 sl811_write(sl811, bank + SL11H_BUFADDRREG, 0);
194 writeb((do_out ? SL_OUT : SL_IN) /* | ep->epnum */, data_reg);
195 writeb(usb_pipedevice(urb->pipe), data_reg);
197 /* always data1; sometimes IN */
198 control |= SL11H_HCTLMASK_TOGGLE;
200 control |= SL11H_HCTLMASK_OUT;
201 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
203 PACKET("STATUS%s/%s qh%p\n", ep->nak_count ? "/retry" : "",
204 do_out ? "out" : "in", ep);
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...
211 static void in_packet(
213 struct sl811h_ep *ep,
221 void __iomem *data_reg;
223 /* avoid losing data on overflow */
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;
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);
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);
244 /* OUT packets can be used with any type of endpoint.
245 * urb->iso_frame_desc is currently ignored here...
247 static void out_packet(
249 struct sl811h_ep *ep,
258 void __iomem *data_reg;
260 buf = urb->transfer_buffer + urb->actual_length;
263 len = min((int)ep->maxpacket,
264 urb->transfer_buffer_length - urb->actual_length);
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;
272 sl811_write_buf(sl811, addr, buf, len);
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);
280 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
281 control | SL11H_HCTLMASK_OUT);
283 PACKET("OUT%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
284 !!usb_gettoggle(urb->dev, ep->epnum, 1), ep, len);
287 /*-------------------------------------------------------------------------*/
289 /* caller updates on-chip enables later */
291 static inline void sofirq_on(struct sl811 *sl811)
293 if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
295 VDBG("sof irq on\n");
296 sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
299 static inline void sofirq_off(struct sl811 *sl811)
301 if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
303 VDBG("sof irq off\n");
304 sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
307 /*-------------------------------------------------------------------------*/
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.
314 static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
316 struct sl811h_ep *ep;
317 struct sl811h_req *req;
322 /* use endpoint at schedule head */
323 if (sl811->next_periodic) {
324 ep = sl811->next_periodic;
325 sl811->next_periodic = ep->next;
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);
333 /* could set up the first fullspeed periodic
334 * transfer for the next frame ...
340 if ((bank && sl811->active_b == ep) || sl811->active_a == ep)
344 if (ep->schedule.next == &sl811->async)
345 sl811->next_async = NULL;
347 sl811->next_async = container_of(ep->schedule.next,
348 struct sl811h_ep, schedule);
351 if (unlikely(list_empty(&ep->queue))) {
352 DBG("empty %p queue?\n", ep);
356 req = container_of(ep->queue.next, struct sl811h_req, queue);
358 control = ep->defctrl;
360 /* if this frame doesn't have enough time left to transfer this
361 * packet, wait till the next frame. too-simple algorithm...
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 */
370 fclock -= ep->maxpacket << 8;
372 /* erratum 2: AFTERSOF only works for fullspeed */
375 sl811->stat_overrun++;
380 fclock -= 12000 / 19; /* 19 64byte packets/msec */
383 sl811->stat_overrun++;
384 control |= SL11H_HCTLMASK_AFTERSOF;
386 /* throttle bulk/control irq noise */
387 } else if (ep->nak_count)
388 control |= SL11H_HCTLMASK_AFTERSOF;
392 switch (ep->nextpid) {
394 in_packet(sl811, ep, urb, bank, control);
397 out_packet(sl811, ep, urb, bank, control);
400 setup_packet(sl811, ep, urb, bank, control);
402 case USB_PID_ACK: /* for control status */
403 status_packet(sl811, ep, urb, bank, control);
406 DBG("bad ep%p pid %02x\n", ep, ep->nextpid);
412 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
414 static inline void start_transfer(struct sl811 *sl811)
416 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
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;
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;
432 static void finish_request(
434 struct sl811h_ep *ep,
435 struct sl811h_req *req,
436 struct pt_regs *regs,
438 ) __releases(sl811->lock) __acquires(sl811->lock)
441 struct urb *urb = req->urb;
443 list_del(&req->queue);
447 if (usb_pipecontrol(urb->pipe))
448 ep->nextpid = USB_PID_SETUP;
450 spin_lock(&urb->lock);
451 if (urb->status == -EINPROGRESS)
452 urb->status = status;
453 spin_unlock(&urb->lock);
455 spin_unlock(&sl811->lock);
456 usb_hcd_giveback_urb(&sl811->hcd, urb, regs);
457 spin_lock(&sl811->lock);
459 /* leave active endpoints in the schedule */
460 if (!list_empty(&ep->queue))
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;
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];
477 while (*prev && ((temp = *prev) != ep))
481 sl811->load[i] -= ep->load;
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;
490 /* we might turn SOFs back on again for the async schedule */
491 if (sl811->periodic_count == 0)
496 done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank, struct pt_regs *regs)
499 struct sl811h_req *req;
501 int urbstat = -EINPROGRESS;
506 status = sl811_read(sl811, bank + SL11H_PKTSTATREG);
508 req = container_of(ep->queue.next, struct sl811h_req, queue);
511 /* we can safely ignore NAKs */
512 if (status & SL11H_STATMASK_NAK) {
513 // PACKET("...NAK_%02x qh%p\n", bank, ep);
518 /* ACK advances transfer, toggle, and maybe queue */
519 } else if (status & SL11H_STATMASK_ACK) {
520 struct usb_device *udev = urb->dev;
524 /* urb->iso_frame_desc is currently ignored here... */
526 ep->nak_count = ep->error_count = 0;
527 switch (ep->nextpid) {
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;
537 /* some bulk protocols terminate OUT transfers
538 * by a short packet, using ZLPs not padding.
540 else if (ep->length < ep->maxpacket
541 || !(urb->transfer_flags
547 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
548 buf = urb->transfer_buffer + urb->actual_length;
550 len = ep->maxpacket - sl811_read(sl811,
551 bank + SL11H_XFERCNTREG);
552 if (len > ep->length) {
554 urb->status = -EOVERFLOW;
556 urb->actual_length += len;
557 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
559 usb_dotoggle(udev, ep->epnum, 0);
560 if (urb->actual_length == urb->transfer_buffer_length)
562 else if (len < ep->maxpacket) {
563 if (urb->transfer_flags & URB_SHORT_NOT_OK)
564 urbstat = -EREMOTEIO;
568 if (usb_pipecontrol(urb->pipe)
569 && (urbstat == -EREMOTEIO
572 /* NOTE if the status stage STALLs (why?),
573 * this reports the wrong urb status.
575 spin_lock(&urb->lock);
576 if (urb->status == -EINPROGRESS)
577 urb->status = urbstat;
578 spin_unlock(&urb->lock);
581 ep->nextpid = USB_PID_ACK;
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;
592 usb_settoggle(udev, 0, 0, 1);
593 ep->nextpid = USB_PID_IN;
597 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
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;
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;
617 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
618 bank, status, ep, urbstat);
621 if ((urbstat != -EINPROGRESS || urb->status != -EINPROGRESS)
623 finish_request(sl811, ep, req, regs, urbstat);
626 static inline u8 checkdone(struct sl811 *sl811)
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",
638 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
639 irqstat |= SL11H_INTMASK_DONE_A;
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",
649 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
650 irqstat |= SL11H_INTMASK_DONE_A;
656 static irqreturn_t sl811h_irq(int irq, void *_sl811, struct pt_regs *regs)
658 struct sl811 *sl811 = _sl811;
660 irqreturn_t ret = IRQ_NONE;
661 unsigned retries = 5;
663 spin_lock(&sl811->lock);
666 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS) & ~SL11H_INTMASK_DP;
668 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
669 irqstat &= sl811->irq_enable;
673 /* this may no longer be necessary ... */
674 if (irqstat == 0 && ret == IRQ_NONE) {
675 irqstat = checkdone(sl811);
676 if (irqstat && irq != ~0)
681 /* USB packets, not necessarily handled in the order they're
682 * issued ... that's fine if they're different endpoints.
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;
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;
696 if (irqstat & SL11H_INTMASK_SOFINTR) {
699 index = sl811->frame++ % (PERIODIC_SIZE - 1);
702 /* be graceful about almost-inevitable periodic schedule
703 * overruns: continue the previous frame's transfers iff
704 * this one has nothing scheduled.
706 if (sl811->next_periodic) {
707 // ERR("overrun to slot %d\n", index);
708 sl811->stat_overrun++;
710 if (sl811->periodic[index])
711 sl811->next_periodic = sl811->periodic[index];
714 /* khubd manages debouncing and wakeup */
715 if (irqstat & SL11H_INTMASK_INSRMV) {
716 sl811->stat_insrmv++;
718 /* most stats are reset for each VBUS session */
719 sl811->stat_wake = 0;
723 sl811->stat_lost = 0;
726 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
728 sl811->irq_enable = SL11H_INTMASK_INSRMV;
729 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
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),
738 sl811->active_a = NULL;
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),
747 sl811->active_b = NULL;
751 /* port status seems wierd until after reset, so
752 * force the reset and make khubd clean up later.
754 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
755 | (1 << USB_PORT_FEAT_CONNECTION);
757 } else if (irqstat & SL11H_INTMASK_RD) {
758 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
760 sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND;
763 irqstat &= ~SL11H_INTMASK_RD;
767 if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
768 start_transfer(sl811);
770 sl811->hcd.saw_irq = 1;
775 if (sl811->periodic_count == 0 && list_empty(&sl811->async))
777 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
779 spin_unlock(&sl811->lock);
784 /*-------------------------------------------------------------------------*/
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.
790 #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
792 static int balance(struct sl811 *sl811, u16 period, u16 load)
794 int i, branch = -ENOSPC;
796 /* search for the least loaded schedule branch of that period
797 * which has enough bandwidth left unreserved.
799 for (i = 0; i < period ; i++) {
800 if (branch < 0 || sl811->load[branch] > sl811->load[i]) {
803 for (j = i; j < PERIODIC_SIZE; j += period) {
804 if ((sl811->load[j] + load)
808 if (j < PERIODIC_SIZE)
816 /*-------------------------------------------------------------------------*/
818 static int sl811h_urb_enqueue(
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;
837 if (type == PIPE_ISOCHRONOUS)
841 /* avoid all allocations within spinlocks: request or endpoint */
842 urb->hcpriv = req = kmalloc(sizeof *req, mem_flags);
851 ep = kcalloc(1, sizeof *ep, mem_flags);
853 spin_lock_irqsave(&sl811->lock, flags);
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)) {
870 INIT_LIST_HEAD(&ep->queue);
871 INIT_LIST_HEAD(&ep->schedule);
872 ep->udev = usb_get_dev(udev);
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);
878 if (type == PIPE_CONTROL)
879 ep->nextpid = USB_PID_SETUP;
881 ep->nextpid = USB_PID_OUT;
883 ep->nextpid = USB_PID_IN;
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);
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;
899 case PIPE_ISOCHRONOUS:
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))
917 /* maybe put endpoint into schedule */
921 if (list_empty(&ep->schedule))
922 list_add_tail(&ep->schedule, &sl811->async);
924 case PIPE_ISOCHRONOUS:
926 urb->interval = ep->period;
927 if (ep->branch < PERIODIC_SIZE)
930 retval = balance(sl811, ep->period, ep->load);
935 urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
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
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;
947 while (here && ep != here) {
948 if (ep->period > here->period)
957 sl811->load[i] += ep->load;
959 sl811->periodic_count++;
960 hcd_to_bus(&sl811->hcd)->bandwidth_allocated
961 += ep->load / ep->period;
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);
974 list_add_tail(&req->queue, &ep->queue);
975 spin_unlock(&urb->lock);
977 start_transfer(sl811);
978 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
980 spin_unlock_irqrestore(&sl811->lock, flags);
986 static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
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);
995 struct sl811h_ep *ep;
996 struct sl811h_req *req = urb->hcpriv;
999 i = usb_pipeendpoint(pipe) << 1;
1003 spin_lock_irqsave(&sl811->lock, flags);
1006 /* finish right away if this urb can't be active ...
1007 * note that some drivers wrongly expect delays
1009 if (ep->queue.next != &req->queue) {
1010 /* not front of queue? never active */
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",
1018 SL811_EP_A(SL11H_HOSTCTLREG)),
1020 SL811_EP_A(SL11H_PKTSTATREG)));
1021 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1023 sl811->active_a = NULL;
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",
1032 SL811_EP_B(SL11H_HOSTCTLREG)),
1034 SL811_EP_B(SL11H_PKTSTATREG)));
1035 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG),
1037 sl811->active_b = NULL;
1042 /* front of queue for inactive endpoint */
1046 finish_request(sl811, ep, req, NULL, 0);
1048 VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1049 (sl811->active_a == ep) ? "A" : "B");
1052 spin_unlock_irqrestore(&sl811->lock, flags);
1057 sl811h_endpoint_disable(struct usb_hcd *hcd, struct hcd_dev *hdev, int epnum)
1059 struct sl811 *sl811 = hcd_to_sl811(hcd);
1060 struct sl811h_ep *ep;
1061 unsigned long flags;
1064 i = (epnum & 0xf) << 1;
1065 if (epnum && !(epnum & USB_DIR_IN))
1068 spin_lock_irqsave(&sl811->lock, flags);
1071 spin_unlock_irqrestore(&sl811->lock, flags);
1074 /* assume we'd just wait for the irq */
1075 if (!list_empty(&ep->queue))
1077 if (!list_empty(&ep->queue))
1078 WARN("ep %p not empty?\n", ep);
1080 usb_put_dev(ep->udev);
1087 sl811h_get_frame(struct usb_hcd *hcd)
1089 struct sl811 *sl811 = hcd_to_sl811(hcd);
1091 /* wrong except while periodic transfers are scheduled;
1092 * never matches the on-the-wire frame;
1093 * subject to overruns.
1095 return sl811->frame;
1099 /*-------------------------------------------------------------------------*/
1101 /* the virtual root hub timer IRQ checks for hub status */
1103 sl811h_hub_status_data(struct usb_hcd *hcd, char *buf)
1105 struct sl811 *sl811 = hcd_to_sl811(hcd);
1107 unsigned long flags;
1109 /* non-SMP HACK: use root hub timer as i/o watchdog
1110 * this seems essential when SOF IRQs aren't in use...
1112 local_irq_save(flags);
1113 if (!timer_pending(&sl811->timer)) {
1114 if (sl811h_irq(~0, sl811, NULL) != IRQ_NONE)
1117 local_irq_restore(flags);
1120 if (!(sl811->port1 & (0xffff << 16)))
1123 /* tell khubd port 1 changed */
1129 sl811h_hub_descriptor (
1130 struct sl811 *sl811,
1131 struct usb_hub_descriptor *desc
1135 desc->bDescriptorType = 0x29;
1136 desc->bHubContrCurrent = 0;
1138 desc->bNbrPorts = 1;
1139 desc->bDescLength = 9;
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;
1151 /* no overcurrent errors detection/handling */
1154 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp);
1156 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1157 desc->bitmap[0] = 1 << 1;
1158 desc->bitmap[1] = ~0;
1162 sl811h_timer(unsigned long _sl811)
1164 struct sl811 *sl811 = (void *) _sl811;
1165 unsigned long flags;
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);
1172 spin_lock_irqsave(&sl811->lock, flags);
1174 /* stop special signaling */
1175 sl811->ctrl1 &= ~SL11H_CTL1MASK_FORCE;
1176 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1179 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS);
1181 switch (signaling) {
1182 case SL11H_CTL1MASK_SE0:
1184 sl811->port1 = (1 << USB_PORT_FEAT_C_RESET)
1185 | (1 << USB_PORT_FEAT_POWER);
1187 /* don't wrongly ack RD */
1188 if (irqstat & SL11H_INTMASK_INSRMV)
1189 irqstat &= ~SL11H_INTMASK_RD;
1191 case SL11H_CTL1MASK_K:
1192 DBG("end resume\n");
1193 sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND);
1196 DBG("odd timer signaling: %02x\n", signaling);
1199 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
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;
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;
1215 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) {
1216 u8 ctrl2 = SL811HS_CTL2_INIT;
1218 sl811->irq_enable |= SL11H_INTMASK_DONE_A;
1220 sl811->irq_enable |= SL11H_INTMASK_DONE_B;
1222 if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) {
1223 sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
1224 ctrl2 |= SL811HS_CTL2MASK_DSWAP;
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);
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);
1239 /* khubd provides debounce delay */
1243 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1246 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
1247 spin_unlock_irqrestore(&sl811->lock, flags);
1252 struct usb_hcd *hcd,
1259 struct sl811 *sl811 = hcd_to_sl811(hcd);
1261 unsigned long flags;
1263 spin_lock_irqsave(&sl811->lock, flags);
1266 case ClearHubFeature:
1269 case C_HUB_OVER_CURRENT:
1270 case C_HUB_LOCAL_POWER:
1276 case ClearPortFeature:
1277 if (wIndex != 1 || wLength != 0)
1281 case USB_PORT_FEAT_ENABLE:
1282 sl811->port1 &= (1 << USB_PORT_FEAT_POWER);
1284 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1285 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1286 sl811_write(sl811, SL11H_IRQ_ENABLE,
1289 case USB_PORT_FEAT_SUSPEND:
1290 if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)))
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,
1298 sl811->ctrl1 |= SL11H_CTL1MASK_K;
1299 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1301 mod_timer(&sl811->timer, jiffies
1302 + msecs_to_jiffies(20));
1304 case USB_PORT_FEAT_POWER:
1305 port_power(sl811, 0);
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:
1316 sl811->port1 &= ~(1 << wValue);
1318 case GetHubDescriptor:
1319 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
1322 *(__le32 *) buf = cpu_to_le32(0);
1327 *(__le32 *) buf = cpu_to_le32(sl811->port1);
1330 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
1332 DBG("GetPortStatus %08x\n", sl811->port1);
1334 case SetPortFeature:
1335 if (wIndex != 1 || wLength != 0)
1338 case USB_PORT_FEAT_SUSPEND:
1339 if (sl811->port1 & (1 << USB_PORT_FEAT_RESET))
1341 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)))
1344 DBG("suspend...\n");
1345 sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
1346 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1348 case USB_PORT_FEAT_POWER:
1349 port_power(sl811, 1);
1351 case USB_PORT_FEAT_RESET:
1352 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
1354 if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER)))
1357 /* 50 msec of reset/SE0 signaling, irqs blocked */
1358 sl811->irq_enable = 0;
1359 sl811_write(sl811, SL11H_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));
1370 sl811->port1 |= 1 << wValue;
1375 /* "protocol stall" on error */
1379 spin_unlock_irqrestore(&sl811->lock, flags);
1386 sl811h_hub_suspend(struct usb_hcd *hcd)
1389 DBG("%s\n", __FUNCTION__);
1394 sl811h_hub_resume(struct usb_hcd *hcd)
1397 DBG("%s\n", __FUNCTION__);
1403 #define sl811h_hub_suspend NULL
1404 #define sl811h_hub_resume NULL
1409 /*-------------------------------------------------------------------------*/
1411 #ifdef STUB_DEBUG_FILE
1413 static inline void create_debug_file(struct sl811 *sl811) { }
1414 static inline void remove_debug_file(struct sl811 *sl811) { }
1418 #include <linux/proc_fs.h>
1419 #include <linux/seq_file.h>
1421 static void dump_irq(struct seq_file *s, char *label, u8 mask)
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" : "");
1432 static int proc_sl811h_show(struct seq_file *s, void *unused)
1434 struct sl811 *sl811 = s->private;
1435 struct sl811h_ep *ep;
1438 seq_printf(s, "%s\n%s version %s\nportstatus[1] = %08x\n",
1439 sl811->hcd.product_desc,
1440 hcd_name, DRIVER_VERSION,
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);
1450 spin_lock_irq(&sl811->lock);
1452 if (sl811->ctrl1 & SL11H_CTL1MASK_SUSPEND)
1453 seq_printf(s, "(suspended)\n\n");
1455 u8 t = sl811_read(sl811, SL11H_CTLREG1);
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;
1465 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1466 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
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);
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;
1486 seq_printf(s, "%s%sqh%p, ep%d%s, maxpacket %d"
1488 (ep == sl811->active_a) ? "(A) " : "",
1489 (ep == sl811->active_b) ? "(B) " : "",
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;
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);
1506 if (!list_empty(&sl811->async))
1507 seq_printf(s, "\n");
1509 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1511 for (i = 0; i < PERIODIC_SIZE; i++) {
1512 ep = sl811->periodic[i];
1515 seq_printf(s, "%2d [%3d]:\n", i, sl811->load[i]);
1517 /* DUMB: prints shared entries multiple times */
1520 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1522 (ep == sl811->active_a) ? "(A) " : "",
1523 (ep == sl811->active_b) ? "(B) " : "",
1525 (ep->udev->speed == USB_SPEED_FULL)
1527 ep->udev->devnum, ep->epnum,
1528 (ep->epnum == 0) ? ""
1529 : ((ep->nextpid == USB_PID_IN)
1532 ep->maxpacket, ep->error_count);
1537 spin_unlock_irq(&sl811->lock);
1538 seq_printf(s, "\n");
1543 static int proc_sl811h_open(struct inode *inode, struct file *file)
1545 return single_open(file, proc_sl811h_show, PDE(inode)->data);
1548 static struct file_operations proc_ops = {
1549 .open = proc_sl811h_open,
1551 .llseek = seq_lseek,
1552 .release = single_release,
1555 /* expect just one sl811 per system */
1556 static const char proc_filename[] = "driver/sl811h";
1558 static void create_debug_file(struct sl811 *sl811)
1560 struct proc_dir_entry *pde;
1562 pde = create_proc_entry(proc_filename, 0, NULL);
1566 pde->proc_fops = &proc_ops;
1571 static void remove_debug_file(struct sl811 *sl811)
1574 remove_proc_entry(proc_filename, NULL);
1579 /*-------------------------------------------------------------------------*/
1582 sl811h_stop(struct usb_hcd *hcd)
1584 struct sl811 *sl811 = hcd_to_sl811(hcd);
1585 unsigned long flags;
1587 del_timer_sync(&sl811->hcd.rh_timer);
1589 spin_lock_irqsave(&sl811->lock, flags);
1590 port_power(sl811, 0);
1591 spin_unlock_irqrestore(&sl811->lock, flags);
1595 sl811h_start(struct usb_hcd *hcd)
1597 struct sl811 *sl811 = hcd_to_sl811(hcd);
1598 struct usb_device *udev;
1600 /* chip has been reset, VBUS power is off */
1602 udev = usb_alloc_dev(NULL, &sl811->hcd.self, 0);
1606 udev->speed = USB_SPEED_FULL;
1607 hcd->state = USB_STATE_RUNNING;
1610 sl811->hcd.can_wakeup = sl811->board->can_wakeup;
1612 if (hcd_register_root(udev, &sl811->hcd) != 0) {
1618 if (sl811->board && sl811->board->power)
1619 hub_set_power_budget(udev, sl811->board->power * 2);
1624 /*-------------------------------------------------------------------------*/
1626 static struct hc_driver sl811h_hc_driver = {
1627 .description = hcd_name,
1630 * generic hardware linkage
1635 * managing i/o requests and associated device resources
1637 .urb_enqueue = sl811h_urb_enqueue,
1638 .urb_dequeue = sl811h_urb_dequeue,
1639 .endpoint_disable = sl811h_endpoint_disable,
1642 * periodic schedule support
1644 .get_frame_number = sl811h_get_frame,
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,
1655 /*-------------------------------------------------------------------------*/
1657 static int __init_or_module
1658 sl811h_remove(struct device *dev)
1660 struct sl811 *sl811 = dev_get_drvdata(dev);
1661 struct platform_device *pdev;
1662 struct resource *res;
1664 pdev = container_of(dev, struct platform_device, dev);
1666 if (HCD_IS_RUNNING(sl811->hcd.state))
1667 sl811->hcd.state = USB_STATE_QUIESCING;
1669 usb_disconnect(&sl811->hcd.self.root_hub);
1670 remove_debug_file(sl811);
1671 sl811h_stop(&sl811->hcd);
1673 if (!list_empty(&sl811->hcd.self.bus_list))
1674 usb_deregister_bus(&sl811->hcd.self);
1676 if (sl811->hcd.irq >= 0)
1677 free_irq(sl811->hcd.irq, sl811);
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);
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);
1693 #define resource_len(r) (((r)->end - (r)->start) + 1)
1696 sl811h_probe(struct device *dev)
1698 struct sl811 *sl811;
1699 struct platform_device *pdev;
1700 struct resource *addr, *data;
1704 unsigned long flags;
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.
1711 pdev = container_of(dev, struct platform_device, dev);
1712 if (pdev->num_resources < 3)
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)
1721 /* refuse to confuse usbcore */
1722 if (dev->dma_mask) {
1723 DBG("no we won't dma\n");
1727 if (!request_mem_region(addr->start, 1, hcd_name))
1729 if (!request_mem_region(data->start, 1, hcd_name)) {
1730 release_mem_region(addr->start, 1);
1734 /* allocate and initialize hcd */
1735 sl811 = kcalloc(1, sizeof *sl811, GFP_KERNEL);
1738 dev_set_drvdata(dev, sl811);
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;
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
1750 INIT_LIST_HEAD(&sl811->hcd.dev_list);
1751 sl811->hcd.self.release = &usb_hcd_release;
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;
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;
1766 sl811->addr_reg = ioremap(addr->start, resource_len(addr));
1767 if (sl811->addr_reg == NULL) {
1771 sl811->data_reg = ioremap(data->start, resource_len(addr));
1772 if (sl811->data_reg == NULL) {
1777 spin_lock_irqsave(&sl811->lock, flags);
1778 port_power(sl811, 0);
1779 spin_unlock_irqrestore(&sl811->lock, flags);
1782 tmp = sl811_read(sl811, SL11H_HWREVREG);
1785 sl811->hcd.product_desc = "SL811HS v1.2";
1788 sl811->hcd.product_desc = "SL811HS v1.5";
1791 /* reject case 0, SL11S is less functional */
1792 DBG("chiprev %02x\n", tmp);
1797 /* sl811s would need a different handler for this irq */
1799 /* Cypress docs say the IRQ is IRQT_HIGH ... */
1800 set_irq_type(irq, IRQT_RISING);
1802 status = request_irq(irq, sl811h_irq, SA_INTERRUPT, hcd_name, sl811);
1805 sl811->hcd.irq = irq;
1807 INFO("%s, irq %d\n", sl811->hcd.product_desc, irq);
1809 status = usb_register_bus(&sl811->hcd.self);
1812 status = sl811h_start(&sl811->hcd);
1814 create_debug_file(sl811);
1819 DBG("init error, %d\n", status);
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.
1831 sl811h_suspend(struct device *dev, u32 state, u32 phase)
1833 struct sl811 *sl811 = dev_get_drvdata(dev);
1836 if (phase != SUSPEND_POWER_DOWN)
1839 if (state <= PM_SUSPEND_MEM)
1840 retval = sl811h_hub_suspend(&sl811->hcd);
1842 port_power(sl811, 0);
1844 dev->power.power_state = state;
1849 sl811h_resume(struct device *dev, u32 phase)
1851 struct sl811 *sl811 = dev_get_drvdata(dev);
1853 if (phase != RESUME_POWER_ON)
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.
1859 if (dev->power.power_state > PM_SUSPEND_MEM
1860 || !sl811->hcd.can_wakeup) {
1862 port_power(sl811, 1);
1866 dev->power.power_state = PM_SUSPEND_ON;
1867 return sl811h_hub_resume(&sl811->hcd);
1872 #define sl811h_suspend NULL
1873 #define sl811h_resume NULL
1878 static struct device_driver sl811h_driver = {
1879 .name = (char *) hcd_name,
1880 .bus = &platform_bus_type,
1882 .probe = sl811h_probe,
1883 .remove = sl811h_remove,
1885 .suspend = sl811h_suspend,
1886 .resume = sl811h_resume,
1889 /*-------------------------------------------------------------------------*/
1891 static int __init sl811h_init(void)
1896 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1897 return driver_register(&sl811h_driver);
1899 module_init(sl811h_init);
1901 static void __exit sl811h_cleanup(void)
1903 driver_unregister(&sl811h_driver);
1905 module_exit(sl811h_cleanup);