2 * SL811HS HCD (Host Controller Driver) for USB.
4 * Copyright (C) 2004 Psion Teklogix (for NetBook PRO)
5 * Copyright (C) 2004-2005 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>
57 #include <linux/platform_device.h>
61 #include <asm/system.h>
62 #include <asm/byteorder.h>
64 #include "../core/hcd.h"
68 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
69 MODULE_LICENSE("GPL");
71 #define DRIVER_VERSION "19 May 2005"
75 # define STUB_DEBUG_FILE
78 /* for now, use only one transfer register bank */
81 /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
82 * that just queued one ISO frame per URB then iso transfers "should" work
83 * using the normal urb status fields.
90 static const char hcd_name[] = "sl811-hcd";
92 /*-------------------------------------------------------------------------*/
94 static void port_power(struct sl811 *sl811, int is_on)
96 struct usb_hcd *hcd = sl811_to_hcd(sl811);
98 /* hub is inactive unless the port is powered */
100 if (sl811->port1 & (1 << USB_PORT_FEAT_POWER))
103 sl811->port1 = (1 << USB_PORT_FEAT_POWER);
104 sl811->irq_enable = SL11H_INTMASK_INSRMV;
105 hcd->self.controller->power.power_state = PMSG_ON;
108 sl811->irq_enable = 0;
109 hcd->state = HC_STATE_HALT;
110 hcd->self.controller->power.power_state = PMSG_SUSPEND;
113 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
114 sl811_write(sl811, SL11H_IRQ_STATUS, ~0);
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);
122 /* reset as thoroughly as we can */
123 if (sl811->board && sl811->board->reset)
124 sl811->board->reset(hcd->self.controller);
126 sl811_write(sl811, SL11H_CTLREG1, SL11H_CTL1MASK_SE0);
130 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
131 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
132 sl811_write(sl811, SL811HS_CTLREG2, SL811HS_CTL2_INIT);
133 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
135 // if !is_on, put into lowpower mode now
138 /*-------------------------------------------------------------------------*/
140 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
141 * and may start I/O. Endpoint queues are scanned during completion irq
142 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
144 * Using an external DMA engine to copy a packet at a time could work,
145 * though setup/teardown costs may be too big to make it worthwhile.
148 /* SETUP starts a new control request. Devices are not allowed to
149 * STALL or NAK these; they must cancel any pending control requests.
151 static void setup_packet(
153 struct sl811h_ep *ep,
161 void __iomem *data_reg;
163 addr = SL811HS_PACKET_BUF(bank == 0);
164 len = sizeof(struct usb_ctrlrequest);
165 data_reg = sl811->data_reg;
166 sl811_write_buf(sl811, addr, urb->setup_packet, len);
168 /* autoincrementing */
169 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
170 writeb(len, data_reg);
171 writeb(SL_SETUP /* | ep->epnum */, data_reg);
172 writeb(usb_pipedevice(urb->pipe), data_reg);
174 /* always OUT/data0 */ ;
175 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
176 control | SL11H_HCTLMASK_OUT);
178 PACKET("SETUP qh%p\n", ep);
181 /* STATUS finishes control requests, often after IN or OUT data packets */
182 static void status_packet(
184 struct sl811h_ep *ep,
191 void __iomem *data_reg;
193 do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
194 data_reg = sl811->data_reg;
196 /* autoincrementing */
197 sl811_write(sl811, bank + SL11H_BUFADDRREG, 0);
199 writeb((do_out ? SL_OUT : SL_IN) /* | ep->epnum */, data_reg);
200 writeb(usb_pipedevice(urb->pipe), data_reg);
202 /* always data1; sometimes IN */
203 control |= SL11H_HCTLMASK_TOGGLE;
205 control |= SL11H_HCTLMASK_OUT;
206 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
208 PACKET("STATUS%s/%s qh%p\n", ep->nak_count ? "/retry" : "",
209 do_out ? "out" : "in", ep);
212 /* IN packets can be used with any type of endpoint. here we just
213 * start the transfer, data from the peripheral may arrive later.
214 * urb->iso_frame_desc is currently ignored here...
216 static void in_packet(
218 struct sl811h_ep *ep,
226 void __iomem *data_reg;
228 /* avoid losing data on overflow */
230 addr = SL811HS_PACKET_BUF(bank == 0);
231 if (!(control & SL11H_HCTLMASK_ISOCH)
232 && usb_gettoggle(urb->dev, ep->epnum, 0))
233 control |= SL11H_HCTLMASK_TOGGLE;
234 data_reg = sl811->data_reg;
236 /* autoincrementing */
237 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
238 writeb(len, data_reg);
239 writeb(SL_IN | ep->epnum, data_reg);
240 writeb(usb_pipedevice(urb->pipe), data_reg);
242 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
243 ep->length = min((int)len,
244 urb->transfer_buffer_length - urb->actual_length);
245 PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
246 !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len);
249 /* OUT packets can be used with any type of endpoint.
250 * urb->iso_frame_desc is currently ignored here...
252 static void out_packet(
254 struct sl811h_ep *ep,
263 void __iomem *data_reg;
265 buf = urb->transfer_buffer + urb->actual_length;
268 len = min((int)ep->maxpacket,
269 urb->transfer_buffer_length - urb->actual_length);
271 if (!(control & SL11H_HCTLMASK_ISOCH)
272 && usb_gettoggle(urb->dev, ep->epnum, 1))
273 control |= SL11H_HCTLMASK_TOGGLE;
274 addr = SL811HS_PACKET_BUF(bank == 0);
275 data_reg = sl811->data_reg;
277 sl811_write_buf(sl811, addr, buf, len);
279 /* autoincrementing */
280 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
281 writeb(len, data_reg);
282 writeb(SL_OUT | ep->epnum, data_reg);
283 writeb(usb_pipedevice(urb->pipe), data_reg);
285 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
286 control | SL11H_HCTLMASK_OUT);
288 PACKET("OUT%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
289 !!usb_gettoggle(urb->dev, ep->epnum, 1), ep, len);
292 /*-------------------------------------------------------------------------*/
294 /* caller updates on-chip enables later */
296 static inline void sofirq_on(struct sl811 *sl811)
298 if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
300 VDBG("sof irq on\n");
301 sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
304 static inline void sofirq_off(struct sl811 *sl811)
306 if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
308 VDBG("sof irq off\n");
309 sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
312 /*-------------------------------------------------------------------------*/
314 /* pick the next endpoint for a transaction, and issue it.
315 * frames start with periodic transfers (after whatever is pending
316 * from the previous frame), and the rest of the time is async
317 * transfers, scheduled round-robin.
319 static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
321 struct sl811h_ep *ep;
326 /* use endpoint at schedule head */
327 if (sl811->next_periodic) {
328 ep = sl811->next_periodic;
329 sl811->next_periodic = ep->next;
331 if (sl811->next_async)
332 ep = sl811->next_async;
333 else if (!list_empty(&sl811->async))
334 ep = container_of(sl811->async.next,
335 struct sl811h_ep, schedule);
337 /* could set up the first fullspeed periodic
338 * transfer for the next frame ...
344 if ((bank && sl811->active_b == ep) || sl811->active_a == ep)
348 if (ep->schedule.next == &sl811->async)
349 sl811->next_async = NULL;
351 sl811->next_async = container_of(ep->schedule.next,
352 struct sl811h_ep, schedule);
355 if (unlikely(list_empty(&ep->hep->urb_list))) {
356 DBG("empty %p queue?\n", ep);
360 urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
361 control = ep->defctrl;
363 /* if this frame doesn't have enough time left to transfer this
364 * packet, wait till the next frame. too-simple algorithm...
366 fclock = sl811_read(sl811, SL11H_SOFTMRREG) << 6;
367 fclock -= 100; /* setup takes not much time */
368 if (urb->dev->speed == USB_SPEED_LOW) {
369 if (control & SL11H_HCTLMASK_PREAMBLE) {
370 /* also note erratum 1: some hubs won't work */
373 fclock -= ep->maxpacket << 8;
375 /* erratum 2: AFTERSOF only works for fullspeed */
378 sl811->stat_overrun++;
383 fclock -= 12000 / 19; /* 19 64byte packets/msec */
386 sl811->stat_overrun++;
387 control |= SL11H_HCTLMASK_AFTERSOF;
389 /* throttle bulk/control irq noise */
390 } else if (ep->nak_count)
391 control |= SL11H_HCTLMASK_AFTERSOF;
395 switch (ep->nextpid) {
397 in_packet(sl811, ep, urb, bank, control);
400 out_packet(sl811, ep, urb, bank, control);
403 setup_packet(sl811, ep, urb, bank, control);
405 case USB_PID_ACK: /* for control status */
406 status_packet(sl811, ep, urb, bank, control);
409 DBG("bad ep%p pid %02x\n", ep, ep->nextpid);
415 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
417 static inline void start_transfer(struct sl811 *sl811)
419 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
421 if (sl811->active_a == NULL) {
422 sl811->active_a = start(sl811, SL811_EP_A(SL811_HOST_BUF));
423 if (sl811->active_a != NULL)
424 sl811->jiffies_a = jiffies + MIN_JIFFIES;
427 if (sl811->active_b == NULL) {
428 sl811->active_b = start(sl811, SL811_EP_B(SL811_HOST_BUF));
429 if (sl811->active_b != NULL)
430 sl811->jiffies_b = jiffies + MIN_JIFFIES;
435 static void finish_request(
437 struct sl811h_ep *ep,
439 struct pt_regs *regs,
441 ) __releases(sl811->lock) __acquires(sl811->lock)
445 if (usb_pipecontrol(urb->pipe))
446 ep->nextpid = USB_PID_SETUP;
448 spin_lock(&urb->lock);
449 if (urb->status == -EINPROGRESS)
450 urb->status = status;
452 spin_unlock(&urb->lock);
454 spin_unlock(&sl811->lock);
455 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb, regs);
456 spin_lock(&sl811->lock);
458 /* leave active endpoints in the schedule */
459 if (!list_empty(&ep->hep->urb_list))
462 /* async deschedule? */
463 if (!list_empty(&ep->schedule)) {
464 list_del_init(&ep->schedule);
465 if (ep == sl811->next_async)
466 sl811->next_async = NULL;
470 /* periodic deschedule */
471 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
472 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
473 struct sl811h_ep *temp;
474 struct sl811h_ep **prev = &sl811->periodic[i];
476 while (*prev && ((temp = *prev) != ep))
480 sl811->load[i] -= ep->load;
482 ep->branch = PERIODIC_SIZE;
483 sl811->periodic_count--;
484 sl811_to_hcd(sl811)->self.bandwidth_allocated
485 -= ep->load / ep->period;
486 if (ep == sl811->next_periodic)
487 sl811->next_periodic = ep->next;
489 /* we might turn SOFs back on again for the async schedule */
490 if (sl811->periodic_count == 0)
495 done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank, struct pt_regs *regs)
499 int urbstat = -EINPROGRESS;
504 status = sl811_read(sl811, bank + SL11H_PKTSTATREG);
506 urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
508 /* we can safely ignore NAKs */
509 if (status & SL11H_STATMASK_NAK) {
510 // PACKET("...NAK_%02x qh%p\n", bank, ep);
515 /* ACK advances transfer, toggle, and maybe queue */
516 } else if (status & SL11H_STATMASK_ACK) {
517 struct usb_device *udev = urb->dev;
521 /* urb->iso_frame_desc is currently ignored here... */
523 ep->nak_count = ep->error_count = 0;
524 switch (ep->nextpid) {
526 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
527 urb->actual_length += ep->length;
528 usb_dotoggle(udev, ep->epnum, 1);
529 if (urb->actual_length
530 == urb->transfer_buffer_length) {
531 if (usb_pipecontrol(urb->pipe))
532 ep->nextpid = USB_PID_ACK;
534 /* some bulk protocols terminate OUT transfers
535 * by a short packet, using ZLPs not padding.
537 else if (ep->length < ep->maxpacket
538 || !(urb->transfer_flags
544 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
545 buf = urb->transfer_buffer + urb->actual_length;
547 len = ep->maxpacket - sl811_read(sl811,
548 bank + SL11H_XFERCNTREG);
549 if (len > ep->length) {
551 urb->status = -EOVERFLOW;
553 urb->actual_length += len;
554 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
556 usb_dotoggle(udev, ep->epnum, 0);
557 if (urb->actual_length == urb->transfer_buffer_length)
559 else if (len < ep->maxpacket) {
560 if (urb->transfer_flags & URB_SHORT_NOT_OK)
561 urbstat = -EREMOTEIO;
565 if (usb_pipecontrol(urb->pipe)
566 && (urbstat == -EREMOTEIO
569 /* NOTE if the status stage STALLs (why?),
570 * this reports the wrong urb status.
572 spin_lock(&urb->lock);
573 if (urb->status == -EINPROGRESS)
574 urb->status = urbstat;
575 spin_unlock(&urb->lock);
578 ep->nextpid = USB_PID_ACK;
582 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
583 if (urb->transfer_buffer_length == urb->actual_length)
584 ep->nextpid = USB_PID_ACK;
585 else if (usb_pipeout(urb->pipe)) {
586 usb_settoggle(udev, 0, 1, 1);
587 ep->nextpid = USB_PID_OUT;
589 usb_settoggle(udev, 0, 0, 1);
590 ep->nextpid = USB_PID_IN;
594 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
599 /* STALL stops all transfers */
600 } else if (status & SL11H_STATMASK_STALL) {
601 PACKET("...STALL_%02x qh%p\n", bank, ep);
602 ep->nak_count = ep->error_count = 0;
605 /* error? retry, until "3 strikes" */
606 } else if (++ep->error_count >= 3) {
607 if (status & SL11H_STATMASK_TMOUT)
608 urbstat = -ETIMEDOUT;
609 else if (status & SL11H_STATMASK_OVF)
610 urbstat = -EOVERFLOW;
614 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
615 bank, status, ep, urbstat);
618 if (urb && (urbstat != -EINPROGRESS || urb->status != -EINPROGRESS))
619 finish_request(sl811, ep, urb, regs, urbstat);
622 static inline u8 checkdone(struct sl811 *sl811)
627 if (sl811->active_a && time_before_eq(sl811->jiffies_a, jiffies)) {
628 ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG));
629 if (ctl & SL11H_HCTLMASK_ARM)
630 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
631 DBG("%s DONE_A: ctrl %02x sts %02x\n",
632 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
634 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
635 irqstat |= SL11H_INTMASK_DONE_A;
638 if (sl811->active_b && time_before_eq(sl811->jiffies_b, jiffies)) {
639 ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG));
640 if (ctl & SL11H_HCTLMASK_ARM)
641 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
642 DBG("%s DONE_B: ctrl %02x sts %02x\n",
643 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
645 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
646 irqstat |= SL11H_INTMASK_DONE_A;
652 static irqreturn_t sl811h_irq(struct usb_hcd *hcd, struct pt_regs *regs)
654 struct sl811 *sl811 = hcd_to_sl811(hcd);
656 irqreturn_t ret = IRQ_NONE;
657 unsigned retries = 5;
659 spin_lock(&sl811->lock);
662 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS) & ~SL11H_INTMASK_DP;
664 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
665 irqstat &= sl811->irq_enable;
669 /* this may no longer be necessary ... */
671 irqstat = checkdone(sl811);
677 /* USB packets, not necessarily handled in the order they're
678 * issued ... that's fine if they're different endpoints.
680 if (irqstat & SL11H_INTMASK_DONE_A) {
681 done(sl811, sl811->active_a, SL811_EP_A(SL811_HOST_BUF), regs);
682 sl811->active_a = NULL;
686 if (irqstat & SL11H_INTMASK_DONE_B) {
687 done(sl811, sl811->active_b, SL811_EP_B(SL811_HOST_BUF), regs);
688 sl811->active_b = NULL;
692 if (irqstat & SL11H_INTMASK_SOFINTR) {
695 index = sl811->frame++ % (PERIODIC_SIZE - 1);
698 /* be graceful about almost-inevitable periodic schedule
699 * overruns: continue the previous frame's transfers iff
700 * this one has nothing scheduled.
702 if (sl811->next_periodic) {
703 // ERR("overrun to slot %d\n", index);
704 sl811->stat_overrun++;
706 if (sl811->periodic[index])
707 sl811->next_periodic = sl811->periodic[index];
710 /* khubd manages debouncing and wakeup */
711 if (irqstat & SL11H_INTMASK_INSRMV) {
712 sl811->stat_insrmv++;
714 /* most stats are reset for each VBUS session */
715 sl811->stat_wake = 0;
719 sl811->stat_lost = 0;
722 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
724 sl811->irq_enable = SL11H_INTMASK_INSRMV;
725 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
727 /* usbcore nukes other pending transactions on disconnect */
728 if (sl811->active_a) {
729 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
730 finish_request(sl811, sl811->active_a,
731 container_of(sl811->active_a
732 ->hep->urb_list.next,
733 struct urb, urb_list),
735 sl811->active_a = NULL;
738 if (sl811->active_b) {
739 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
740 finish_request(sl811, sl811->active_b,
741 container_of(sl811->active_b
742 ->hep->urb_list.next,
743 struct urb, urb_list),
745 sl811->active_b = NULL;
749 /* port status seems weird until after reset, so
750 * force the reset and make khubd clean up later.
752 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
753 | (1 << USB_PORT_FEAT_CONNECTION);
755 } else if (irqstat & SL11H_INTMASK_RD) {
756 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
758 sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND;
761 irqstat &= ~SL11H_INTMASK_RD;
765 if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
766 start_transfer(sl811);
772 if (sl811->periodic_count == 0 && list_empty(&sl811->async))
774 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
776 spin_unlock(&sl811->lock);
781 /*-------------------------------------------------------------------------*/
783 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
784 * this driver doesn't promise that much since it's got to handle an
785 * IRQ per packet; irq handling latencies also use up that time.
787 * NOTE: the periodic schedule is a sparse tree, with the load for
788 * each branch minimized. see fig 3.5 in the OHCI spec for example.
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(
820 struct usb_host_endpoint *hep,
824 struct sl811 *sl811 = hcd_to_sl811(hcd);
825 struct usb_device *udev = urb->dev;
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;
836 if (type == PIPE_ISOCHRONOUS)
840 /* avoid all allocations within spinlocks */
842 ep = kzalloc(sizeof *ep, mem_flags);
844 spin_lock_irqsave(&sl811->lock, flags);
846 /* don't submit to a dead or disabled port */
847 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
848 || !HC_IS_RUNNING(hcd->state)) {
862 INIT_LIST_HEAD(&ep->schedule);
863 ep->udev = usb_get_dev(udev);
865 ep->maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
866 ep->defctrl = SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENABLE;
867 usb_settoggle(udev, epnum, is_out, 0);
869 if (type == PIPE_CONTROL)
870 ep->nextpid = USB_PID_SETUP;
872 ep->nextpid = USB_PID_OUT;
874 ep->nextpid = USB_PID_IN;
876 if (ep->maxpacket > H_MAXPACKET) {
877 /* iso packets up to 240 bytes could work... */
878 DBG("dev %d ep%d maxpacket %d\n",
879 udev->devnum, epnum, ep->maxpacket);
884 if (udev->speed == USB_SPEED_LOW) {
885 /* send preamble for external hub? */
886 if (!(sl811->ctrl1 & SL11H_CTL1MASK_LSPD))
887 ep->defctrl |= SL11H_HCTLMASK_PREAMBLE;
890 case PIPE_ISOCHRONOUS:
892 if (urb->interval > PERIODIC_SIZE)
893 urb->interval = PERIODIC_SIZE;
894 ep->period = urb->interval;
895 ep->branch = PERIODIC_SIZE;
896 if (type == PIPE_ISOCHRONOUS)
897 ep->defctrl |= SL11H_HCTLMASK_ISOCH;
898 ep->load = usb_calc_bus_time(udev->speed, !is_out,
899 (type == PIPE_ISOCHRONOUS),
900 usb_maxpacket(udev, pipe, is_out))
909 /* maybe put endpoint into schedule */
913 if (list_empty(&ep->schedule))
914 list_add_tail(&ep->schedule, &sl811->async);
916 case PIPE_ISOCHRONOUS:
918 urb->interval = ep->period;
919 if (ep->branch < PERIODIC_SIZE) {
920 /* NOTE: the phase is correct here, but the value
921 * needs offsetting by the transfer queue depth.
922 * All current drivers ignore start_frame, so this
923 * is unlikely to ever matter...
925 urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
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->self.bandwidth_allocated += ep->load / ep->period;
964 /* in case of unlink-during-submit */
965 spin_lock(&urb->lock);
966 if (urb->status != -EINPROGRESS) {
967 spin_unlock(&urb->lock);
968 finish_request(sl811, ep, urb, NULL, 0);
973 spin_unlock(&urb->lock);
975 start_transfer(sl811);
976 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
978 spin_unlock_irqrestore(&sl811->lock, flags);
982 static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
984 struct sl811 *sl811 = hcd_to_sl811(hcd);
985 struct usb_host_endpoint *hep;
987 struct sl811h_ep *ep;
990 spin_lock_irqsave(&sl811->lock, flags);
997 /* finish right away if this urb can't be active ...
998 * note that some drivers wrongly expect delays
1000 if (ep->hep->urb_list.next != &urb->urb_list) {
1001 /* not front of queue? never active */
1003 /* for active transfers, we expect an IRQ */
1004 } else if (sl811->active_a == ep) {
1005 if (time_before_eq(sl811->jiffies_a, jiffies)) {
1006 /* happens a lot with lowspeed?? */
1007 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
1009 SL811_EP_A(SL11H_HOSTCTLREG)),
1011 SL811_EP_A(SL11H_PKTSTATREG)));
1012 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1014 sl811->active_a = NULL;
1018 } else if (sl811->active_b == ep) {
1019 if (time_before_eq(sl811->jiffies_a, jiffies)) {
1020 /* happens a lot with lowspeed?? */
1021 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1023 SL811_EP_B(SL11H_HOSTCTLREG)),
1025 SL811_EP_B(SL11H_PKTSTATREG)));
1026 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG),
1028 sl811->active_b = NULL;
1033 /* front of queue for inactive endpoint */
1037 finish_request(sl811, ep, urb, NULL, 0);
1039 VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1040 (sl811->active_a == ep) ? "A" : "B");
1044 spin_unlock_irqrestore(&sl811->lock, flags);
1049 sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1051 struct sl811h_ep *ep = hep->hcpriv;
1056 /* assume we'd just wait for the irq */
1057 if (!list_empty(&hep->urb_list))
1059 if (!list_empty(&hep->urb_list))
1060 WARN("ep %p not empty?\n", ep);
1062 usb_put_dev(ep->udev);
1068 sl811h_get_frame(struct usb_hcd *hcd)
1070 struct sl811 *sl811 = hcd_to_sl811(hcd);
1072 /* wrong except while periodic transfers are scheduled;
1073 * never matches the on-the-wire frame;
1074 * subject to overruns.
1076 return sl811->frame;
1080 /*-------------------------------------------------------------------------*/
1082 /* the virtual root hub timer IRQ checks for hub status */
1084 sl811h_hub_status_data(struct usb_hcd *hcd, char *buf)
1086 struct sl811 *sl811 = hcd_to_sl811(hcd);
1088 unsigned long flags;
1090 /* non-SMP HACK: use root hub timer as i/o watchdog
1091 * this seems essential when SOF IRQs aren't in use...
1093 local_irq_save(flags);
1094 if (!timer_pending(&sl811->timer)) {
1095 if (sl811h_irq( /* ~0, */ hcd, NULL) != IRQ_NONE)
1098 local_irq_restore(flags);
1101 if (!(sl811->port1 & (0xffff << 16)))
1104 /* tell khubd port 1 changed */
1110 sl811h_hub_descriptor (
1111 struct sl811 *sl811,
1112 struct usb_hub_descriptor *desc
1116 desc->bDescriptorType = 0x29;
1117 desc->bHubContrCurrent = 0;
1119 desc->bNbrPorts = 1;
1120 desc->bDescLength = 9;
1122 /* per-port power switching (gang of one!), or none */
1123 desc->bPwrOn2PwrGood = 0;
1124 if (sl811->board && sl811->board->port_power) {
1125 desc->bPwrOn2PwrGood = sl811->board->potpg;
1126 if (!desc->bPwrOn2PwrGood)
1127 desc->bPwrOn2PwrGood = 10;
1132 /* no overcurrent errors detection/handling */
1135 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp);
1137 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1138 desc->bitmap[0] = 0 << 1;
1139 desc->bitmap[1] = ~0;
1143 sl811h_timer(unsigned long _sl811)
1145 struct sl811 *sl811 = (void *) _sl811;
1146 unsigned long flags;
1148 u8 signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE;
1149 const u32 mask = (1 << USB_PORT_FEAT_CONNECTION)
1150 | (1 << USB_PORT_FEAT_ENABLE)
1151 | (1 << USB_PORT_FEAT_LOWSPEED);
1153 spin_lock_irqsave(&sl811->lock, flags);
1155 /* stop special signaling */
1156 sl811->ctrl1 &= ~SL11H_CTL1MASK_FORCE;
1157 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1160 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS);
1162 switch (signaling) {
1163 case SL11H_CTL1MASK_SE0:
1165 sl811->port1 = (1 << USB_PORT_FEAT_C_RESET)
1166 | (1 << USB_PORT_FEAT_POWER);
1168 /* don't wrongly ack RD */
1169 if (irqstat & SL11H_INTMASK_INSRMV)
1170 irqstat &= ~SL11H_INTMASK_RD;
1172 case SL11H_CTL1MASK_K:
1173 DBG("end resume\n");
1174 sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND);
1177 DBG("odd timer signaling: %02x\n", signaling);
1180 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
1182 if (irqstat & SL11H_INTMASK_RD) {
1183 /* usbcore nukes all pending transactions on disconnect */
1184 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION))
1185 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
1186 | (1 << USB_PORT_FEAT_C_ENABLE);
1187 sl811->port1 &= ~mask;
1188 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1190 sl811->port1 |= mask;
1191 if (irqstat & SL11H_INTMASK_DP)
1192 sl811->port1 &= ~(1 << USB_PORT_FEAT_LOWSPEED);
1193 sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD;
1196 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) {
1197 u8 ctrl2 = SL811HS_CTL2_INIT;
1199 sl811->irq_enable |= SL11H_INTMASK_DONE_A;
1201 sl811->irq_enable |= SL11H_INTMASK_DONE_B;
1203 if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) {
1204 sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
1205 ctrl2 |= SL811HS_CTL2MASK_DSWAP;
1208 /* start SOFs flowing, kickstarting with A registers */
1209 sl811->ctrl1 |= SL11H_CTL1MASK_SOF_ENA;
1210 sl811_write(sl811, SL11H_SOFLOWREG, 0xe0);
1211 sl811_write(sl811, SL811HS_CTLREG2, ctrl2);
1213 /* autoincrementing */
1214 sl811_write(sl811, SL811_EP_A(SL11H_BUFLNTHREG), 0);
1215 writeb(SL_SOF, sl811->data_reg);
1216 writeb(0, sl811->data_reg);
1217 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1218 SL11H_HCTLMASK_ARM);
1220 /* khubd provides debounce delay */
1224 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1227 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
1228 spin_unlock_irqrestore(&sl811->lock, flags);
1233 struct usb_hcd *hcd,
1240 struct sl811 *sl811 = hcd_to_sl811(hcd);
1242 unsigned long flags;
1244 spin_lock_irqsave(&sl811->lock, flags);
1247 case ClearHubFeature:
1250 case C_HUB_OVER_CURRENT:
1251 case C_HUB_LOCAL_POWER:
1257 case ClearPortFeature:
1258 if (wIndex != 1 || wLength != 0)
1262 case USB_PORT_FEAT_ENABLE:
1263 sl811->port1 &= (1 << USB_PORT_FEAT_POWER);
1265 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1266 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1267 sl811_write(sl811, SL11H_IRQ_ENABLE,
1270 case USB_PORT_FEAT_SUSPEND:
1271 if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)))
1274 /* 20 msec of resume/K signaling, other irqs blocked */
1275 DBG("start resume...\n");
1276 sl811->irq_enable = 0;
1277 sl811_write(sl811, SL11H_IRQ_ENABLE,
1279 sl811->ctrl1 |= SL11H_CTL1MASK_K;
1280 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1282 mod_timer(&sl811->timer, jiffies
1283 + msecs_to_jiffies(20));
1285 case USB_PORT_FEAT_POWER:
1286 port_power(sl811, 0);
1288 case USB_PORT_FEAT_C_ENABLE:
1289 case USB_PORT_FEAT_C_SUSPEND:
1290 case USB_PORT_FEAT_C_CONNECTION:
1291 case USB_PORT_FEAT_C_OVER_CURRENT:
1292 case USB_PORT_FEAT_C_RESET:
1297 sl811->port1 &= ~(1 << wValue);
1299 case GetHubDescriptor:
1300 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
1303 *(__le32 *) buf = cpu_to_le32(0);
1308 *(__le32 *) buf = cpu_to_le32(sl811->port1);
1311 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
1313 DBG("GetPortStatus %08x\n", sl811->port1);
1315 case SetPortFeature:
1316 if (wIndex != 1 || wLength != 0)
1319 case USB_PORT_FEAT_SUSPEND:
1320 if (sl811->port1 & (1 << USB_PORT_FEAT_RESET))
1322 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)))
1325 DBG("suspend...\n");
1326 sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
1327 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1329 case USB_PORT_FEAT_POWER:
1330 port_power(sl811, 1);
1332 case USB_PORT_FEAT_RESET:
1333 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
1335 if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER)))
1338 /* 50 msec of reset/SE0 signaling, irqs blocked */
1339 sl811->irq_enable = 0;
1340 sl811_write(sl811, SL11H_IRQ_ENABLE,
1342 sl811->ctrl1 = SL11H_CTL1MASK_SE0;
1343 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1344 sl811->port1 |= (1 << USB_PORT_FEAT_RESET);
1345 mod_timer(&sl811->timer, jiffies
1346 + msecs_to_jiffies(50));
1351 sl811->port1 |= 1 << wValue;
1356 /* "protocol stall" on error */
1360 spin_unlock_irqrestore(&sl811->lock, flags);
1367 sl811h_bus_suspend(struct usb_hcd *hcd)
1370 DBG("%s\n", __FUNCTION__);
1375 sl811h_bus_resume(struct usb_hcd *hcd)
1378 DBG("%s\n", __FUNCTION__);
1384 #define sl811h_bus_suspend NULL
1385 #define sl811h_bus_resume NULL
1390 /*-------------------------------------------------------------------------*/
1392 #ifdef STUB_DEBUG_FILE
1394 static inline void create_debug_file(struct sl811 *sl811) { }
1395 static inline void remove_debug_file(struct sl811 *sl811) { }
1399 #include <linux/proc_fs.h>
1400 #include <linux/seq_file.h>
1402 static void dump_irq(struct seq_file *s, char *label, u8 mask)
1404 seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask,
1405 (mask & SL11H_INTMASK_DONE_A) ? " done_a" : "",
1406 (mask & SL11H_INTMASK_DONE_B) ? " done_b" : "",
1407 (mask & SL11H_INTMASK_SOFINTR) ? " sof" : "",
1408 (mask & SL11H_INTMASK_INSRMV) ? " ins/rmv" : "",
1409 (mask & SL11H_INTMASK_RD) ? " rd" : "",
1410 (mask & SL11H_INTMASK_DP) ? " dp" : "");
1413 static int proc_sl811h_show(struct seq_file *s, void *unused)
1415 struct sl811 *sl811 = s->private;
1416 struct sl811h_ep *ep;
1419 seq_printf(s, "%s\n%s version %s\nportstatus[1] = %08x\n",
1420 sl811_to_hcd(sl811)->product_desc,
1421 hcd_name, DRIVER_VERSION,
1424 seq_printf(s, "insert/remove: %ld\n", sl811->stat_insrmv);
1425 seq_printf(s, "current session: done_a %ld done_b %ld "
1426 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1427 sl811->stat_a, sl811->stat_b,
1428 sl811->stat_wake, sl811->stat_sof,
1429 sl811->stat_overrun, sl811->stat_lost);
1431 spin_lock_irq(&sl811->lock);
1433 if (sl811->ctrl1 & SL11H_CTL1MASK_SUSPEND)
1434 seq_printf(s, "(suspended)\n\n");
1436 u8 t = sl811_read(sl811, SL11H_CTLREG1);
1438 seq_printf(s, "ctrl1 %02x%s%s%s%s\n", t,
1439 (t & SL11H_CTL1MASK_SOF_ENA) ? " sofgen" : "",
1440 ({char *s; switch (t & SL11H_CTL1MASK_FORCE) {
1441 case SL11H_CTL1MASK_NORMAL: s = ""; break;
1442 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
1443 case SL11H_CTL1MASK_K: s = " k/resume"; break;
1444 default: s = "j"; break;
1446 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1447 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
1449 dump_irq(s, "irq_enable",
1450 sl811_read(sl811, SL11H_IRQ_ENABLE));
1451 dump_irq(s, "irq_status",
1452 sl811_read(sl811, SL11H_IRQ_STATUS));
1453 seq_printf(s, "frame clocks remaining: %d\n",
1454 sl811_read(sl811, SL11H_SOFTMRREG) << 6);
1457 seq_printf(s, "A: qh%p ctl %02x sts %02x\n", sl811->active_a,
1458 sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG)),
1459 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
1460 seq_printf(s, "B: qh%p ctl %02x sts %02x\n", sl811->active_b,
1461 sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG)),
1462 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
1463 seq_printf(s, "\n");
1464 list_for_each_entry (ep, &sl811->async, schedule) {
1467 seq_printf(s, "%s%sqh%p, ep%d%s, maxpacket %d"
1469 (ep == sl811->active_a) ? "(A) " : "",
1470 (ep == sl811->active_b) ? "(B) " : "",
1472 ({ char *s; switch (ep->nextpid) {
1473 case USB_PID_IN: s = "in"; break;
1474 case USB_PID_OUT: s = "out"; break;
1475 case USB_PID_SETUP: s = "setup"; break;
1476 case USB_PID_ACK: s = "status"; break;
1477 default: s = "?"; break;
1480 ep->nak_count, ep->error_count);
1481 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) {
1482 seq_printf(s, " urb%p, %d/%d\n", urb,
1484 urb->transfer_buffer_length);
1487 if (!list_empty(&sl811->async))
1488 seq_printf(s, "\n");
1490 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1492 for (i = 0; i < PERIODIC_SIZE; i++) {
1493 ep = sl811->periodic[i];
1496 seq_printf(s, "%2d [%3d]:\n", i, sl811->load[i]);
1498 /* DUMB: prints shared entries multiple times */
1501 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1503 (ep == sl811->active_a) ? "(A) " : "",
1504 (ep == sl811->active_b) ? "(B) " : "",
1506 (ep->udev->speed == USB_SPEED_FULL)
1508 ep->udev->devnum, ep->epnum,
1509 (ep->epnum == 0) ? ""
1510 : ((ep->nextpid == USB_PID_IN)
1513 ep->maxpacket, ep->error_count);
1518 spin_unlock_irq(&sl811->lock);
1519 seq_printf(s, "\n");
1524 static int proc_sl811h_open(struct inode *inode, struct file *file)
1526 return single_open(file, proc_sl811h_show, PDE(inode)->data);
1529 static struct file_operations proc_ops = {
1530 .open = proc_sl811h_open,
1532 .llseek = seq_lseek,
1533 .release = single_release,
1536 /* expect just one sl811 per system */
1537 static const char proc_filename[] = "driver/sl811h";
1539 static void create_debug_file(struct sl811 *sl811)
1541 struct proc_dir_entry *pde;
1543 pde = create_proc_entry(proc_filename, 0, NULL);
1547 pde->proc_fops = &proc_ops;
1552 static void remove_debug_file(struct sl811 *sl811)
1555 remove_proc_entry(proc_filename, NULL);
1560 /*-------------------------------------------------------------------------*/
1563 sl811h_stop(struct usb_hcd *hcd)
1565 struct sl811 *sl811 = hcd_to_sl811(hcd);
1566 unsigned long flags;
1568 del_timer_sync(&hcd->rh_timer);
1570 spin_lock_irqsave(&sl811->lock, flags);
1571 port_power(sl811, 0);
1572 spin_unlock_irqrestore(&sl811->lock, flags);
1576 sl811h_start(struct usb_hcd *hcd)
1578 struct sl811 *sl811 = hcd_to_sl811(hcd);
1580 /* chip has been reset, VBUS power is off */
1581 hcd->state = HC_STATE_RUNNING;
1584 hcd->can_wakeup = sl811->board->can_wakeup;
1585 hcd->power_budget = sl811->board->power * 2;
1588 /* enable power and interupts */
1589 port_power(sl811, 1);
1594 /*-------------------------------------------------------------------------*/
1596 static struct hc_driver sl811h_hc_driver = {
1597 .description = hcd_name,
1598 .hcd_priv_size = sizeof(struct sl811),
1601 * generic hardware linkage
1604 .flags = HCD_USB11 | HCD_MEMORY,
1606 /* Basic lifecycle operations */
1607 .start = sl811h_start,
1608 .stop = sl811h_stop,
1611 * managing i/o requests and associated device resources
1613 .urb_enqueue = sl811h_urb_enqueue,
1614 .urb_dequeue = sl811h_urb_dequeue,
1615 .endpoint_disable = sl811h_endpoint_disable,
1618 * periodic schedule support
1620 .get_frame_number = sl811h_get_frame,
1625 .hub_status_data = sl811h_hub_status_data,
1626 .hub_control = sl811h_hub_control,
1627 .bus_suspend = sl811h_bus_suspend,
1628 .bus_resume = sl811h_bus_resume,
1631 /*-------------------------------------------------------------------------*/
1633 static int __devexit
1634 sl811h_remove(struct platform_device *dev)
1636 struct usb_hcd *hcd = platform_get_drvdata(dev);
1637 struct sl811 *sl811 = hcd_to_sl811(hcd);
1638 struct resource *res;
1640 remove_debug_file(sl811);
1641 usb_remove_hcd(hcd);
1643 /* some platforms may use IORESOURCE_IO */
1644 res = platform_get_resource(dev, IORESOURCE_MEM, 1);
1646 iounmap(sl811->data_reg);
1648 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
1650 iounmap(sl811->addr_reg);
1656 static int __devinit
1657 sl811h_probe(struct platform_device *dev)
1659 struct usb_hcd *hcd;
1660 struct sl811 *sl811;
1661 struct resource *addr, *data;
1663 void __iomem *addr_reg;
1664 void __iomem *data_reg;
1668 /* basic sanity checks first. board-specific init logic should
1669 * have initialized these three resources and probably board
1670 * specific platform_data. we don't probe for IRQs, and do only
1671 * minimal sanity checking.
1673 irq = platform_get_irq(dev, 0);
1674 if (dev->num_resources < 3 || irq < 0)
1677 /* refuse to confuse usbcore */
1678 if (dev->dev.dma_mask) {
1679 DBG("no we won't dma\n");
1683 /* the chip may be wired for either kind of addressing */
1684 addr = platform_get_resource(dev, IORESOURCE_MEM, 0);
1685 data = platform_get_resource(dev, IORESOURCE_MEM, 1);
1687 if (!addr || !data) {
1688 addr = platform_get_resource(dev, IORESOURCE_IO, 0);
1689 data = platform_get_resource(dev, IORESOURCE_IO, 1);
1694 addr_reg = (void __iomem *) addr->start;
1695 data_reg = (void __iomem *) data->start;
1697 addr_reg = ioremap(addr->start, 1);
1698 if (addr_reg == NULL) {
1703 data_reg = ioremap(data->start, 1);
1704 if (data_reg == NULL) {
1710 /* allocate and initialize hcd */
1711 hcd = usb_create_hcd(&sl811h_hc_driver, &dev->dev, dev->dev.bus_id);
1716 hcd->rsrc_start = addr->start;
1717 sl811 = hcd_to_sl811(hcd);
1719 spin_lock_init(&sl811->lock);
1720 INIT_LIST_HEAD(&sl811->async);
1721 sl811->board = dev->dev.platform_data;
1722 init_timer(&sl811->timer);
1723 sl811->timer.function = sl811h_timer;
1724 sl811->timer.data = (unsigned long) sl811;
1725 sl811->addr_reg = addr_reg;
1726 sl811->data_reg = data_reg;
1728 spin_lock_irq(&sl811->lock);
1729 port_power(sl811, 0);
1730 spin_unlock_irq(&sl811->lock);
1733 tmp = sl811_read(sl811, SL11H_HWREVREG);
1736 hcd->product_desc = "SL811HS v1.2";
1739 hcd->product_desc = "SL811HS v1.5";
1742 /* reject case 0, SL11S is less functional */
1743 DBG("chiprev %02x\n", tmp);
1748 /* The chip's IRQ is level triggered, active high. A requirement
1749 * for platform device setup is to cope with things like signal
1750 * inverters (e.g. CF is active low) or working only with edge
1751 * triggers (e.g. most ARM CPUs). Initial driver stress testing
1752 * was on a system with single edge triggering, so most sorts of
1753 * triggering arrangement should work.
1755 retval = usb_add_hcd(hcd, irq, SA_INTERRUPT | SA_SHIRQ);
1759 create_debug_file(sl811);
1771 DBG("init error, %d\n", retval);
1777 /* for this device there's no useful distinction between the controller
1778 * and its root hub, except that the root hub only gets direct PM calls
1779 * when CONFIG_USB_SUSPEND is enabled.
1783 sl811h_suspend(struct platform_device *dev, pm_message_t state)
1785 struct usb_hcd *hcd = platform_get_drvdata(dev);
1786 struct sl811 *sl811 = hcd_to_sl811(hcd);
1789 if (state.event == PM_EVENT_FREEZE)
1790 retval = sl811h_bus_suspend(hcd);
1791 else if (state.event == PM_EVENT_SUSPEND)
1792 port_power(sl811, 0);
1794 dev->dev.power.power_state = state;
1799 sl811h_resume(struct platform_device *dev)
1801 struct usb_hcd *hcd = platform_get_drvdata(dev);
1802 struct sl811 *sl811 = hcd_to_sl811(hcd);
1804 /* with no "check to see if VBUS is still powered" board hook,
1805 * let's assume it'd only be powered to enable remote wakeup.
1807 if (dev->dev.power.power_state.event == PM_EVENT_SUSPEND
1808 || !hcd->can_wakeup) {
1810 port_power(sl811, 1);
1814 dev->dev.power.power_state = PMSG_ON;
1815 return sl811h_bus_resume(hcd);
1820 #define sl811h_suspend NULL
1821 #define sl811h_resume NULL
1826 /* this driver is exported so sl811_cs can depend on it */
1827 struct platform_driver sl811h_driver = {
1828 .probe = sl811h_probe,
1829 .remove = __devexit_p(sl811h_remove),
1831 .suspend = sl811h_suspend,
1832 .resume = sl811h_resume,
1834 .name = (char *) hcd_name,
1835 .owner = THIS_MODULE,
1838 EXPORT_SYMBOL(sl811h_driver);
1840 /*-------------------------------------------------------------------------*/
1842 static int __init sl811h_init(void)
1847 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1848 return platform_driver_register(&sl811h_driver);
1850 module_init(sl811h_init);
1852 static void __exit sl811h_cleanup(void)
1854 platform_driver_unregister(&sl811h_driver);
1856 module_exit(sl811h_cleanup);