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 "15 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 *_hcd, struct pt_regs *regs);
95 static void port_power(struct sl811 *sl811, int is_on)
97 struct usb_hcd *hcd = sl811_to_hcd(sl811);
99 /* hub is inactive unless the port is powered */
101 if (sl811->port1 & (1 << USB_PORT_FEAT_POWER))
104 sl811->port1 = (1 << USB_PORT_FEAT_POWER);
105 sl811->irq_enable = SL11H_INTMASK_INSRMV;
106 hcd->self.controller->power.power_state = PM_SUSPEND_ON;
109 sl811->irq_enable = 0;
110 hcd->state = USB_STATE_HALT;
111 hcd->self.controller->power.power_state = PM_SUSPEND_DISK;
114 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
115 sl811_write(sl811, SL11H_IRQ_STATUS, ~0);
117 if (sl811->board && sl811->board->port_power) {
118 /* switch VBUS, at 500mA unless hub power budget gets set */
119 DBG("power %s\n", is_on ? "on" : "off");
120 sl811->board->port_power(hcd->self.controller, is_on);
123 /* reset as thoroughly as we can */
124 if (sl811->board && sl811->board->reset)
125 sl811->board->reset(hcd->self.controller);
127 sl811_write(sl811, SL11H_IRQ_ENABLE, 0);
128 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
129 sl811_write(sl811, SL811HS_CTLREG2, SL811HS_CTL2_INIT);
130 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
132 // if !is_on, put into lowpower mode now
135 /*-------------------------------------------------------------------------*/
137 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
138 * and may start I/O. Endpoint queues are scanned during completion irq
139 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancelation.
141 * Using an external DMA engine to copy a packet at a time could work,
142 * though setup/teardown costs may be too big to make it worthwhile.
145 /* SETUP starts a new control request. Devices are not allowed to
146 * STALL or NAK these; they must cancel any pending control requests.
148 static void setup_packet(
150 struct sl811h_ep *ep,
158 void __iomem *data_reg;
160 addr = SL811HS_PACKET_BUF(bank == 0);
161 len = sizeof(struct usb_ctrlrequest);
162 data_reg = sl811->data_reg;
163 sl811_write_buf(sl811, addr, urb->setup_packet, len);
165 /* autoincrementing */
166 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
167 writeb(len, data_reg);
168 writeb(SL_SETUP /* | ep->epnum */, data_reg);
169 writeb(usb_pipedevice(urb->pipe), data_reg);
171 /* always OUT/data0 */ ;
172 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
173 control | SL11H_HCTLMASK_OUT);
175 PACKET("SETUP qh%p\n", ep);
178 /* STATUS finishes control requests, often after IN or OUT data packets */
179 static void status_packet(
181 struct sl811h_ep *ep,
188 void __iomem *data_reg;
190 do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
191 data_reg = sl811->data_reg;
193 /* autoincrementing */
194 sl811_write(sl811, bank + SL11H_BUFADDRREG, 0);
196 writeb((do_out ? SL_OUT : SL_IN) /* | ep->epnum */, data_reg);
197 writeb(usb_pipedevice(urb->pipe), data_reg);
199 /* always data1; sometimes IN */
200 control |= SL11H_HCTLMASK_TOGGLE;
202 control |= SL11H_HCTLMASK_OUT;
203 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
205 PACKET("STATUS%s/%s qh%p\n", ep->nak_count ? "/retry" : "",
206 do_out ? "out" : "in", ep);
209 /* IN packets can be used with any type of endpoint. here we just
210 * start the transfer, data from the peripheral may arrive later.
211 * urb->iso_frame_desc is currently ignored here...
213 static void in_packet(
215 struct sl811h_ep *ep,
223 void __iomem *data_reg;
225 /* avoid losing data on overflow */
227 addr = SL811HS_PACKET_BUF(bank == 0);
228 if (!(control & SL11H_HCTLMASK_ISOCH)
229 && usb_gettoggle(urb->dev, ep->epnum, 0))
230 control |= SL11H_HCTLMASK_TOGGLE;
231 data_reg = sl811->data_reg;
233 /* autoincrementing */
234 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
235 writeb(len, data_reg);
236 writeb(SL_IN | ep->epnum, data_reg);
237 writeb(usb_pipedevice(urb->pipe), data_reg);
239 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
240 ep->length = min((int)len,
241 urb->transfer_buffer_length - urb->actual_length);
242 PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
243 !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len);
246 /* OUT packets can be used with any type of endpoint.
247 * urb->iso_frame_desc is currently ignored here...
249 static void out_packet(
251 struct sl811h_ep *ep,
260 void __iomem *data_reg;
262 buf = urb->transfer_buffer + urb->actual_length;
265 len = min((int)ep->maxpacket,
266 urb->transfer_buffer_length - urb->actual_length);
268 if (!(control & SL11H_HCTLMASK_ISOCH)
269 && usb_gettoggle(urb->dev, ep->epnum, 1))
270 control |= SL11H_HCTLMASK_TOGGLE;
271 addr = SL811HS_PACKET_BUF(bank == 0);
272 data_reg = sl811->data_reg;
274 sl811_write_buf(sl811, addr, buf, len);
276 /* autoincrementing */
277 sl811_write(sl811, bank + SL11H_BUFADDRREG, addr);
278 writeb(len, data_reg);
279 writeb(SL_OUT | ep->epnum, data_reg);
280 writeb(usb_pipedevice(urb->pipe), data_reg);
282 sl811_write(sl811, bank + SL11H_HOSTCTLREG,
283 control | SL11H_HCTLMASK_OUT);
285 PACKET("OUT%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
286 !!usb_gettoggle(urb->dev, ep->epnum, 1), ep, len);
289 /*-------------------------------------------------------------------------*/
291 /* caller updates on-chip enables later */
293 static inline void sofirq_on(struct sl811 *sl811)
295 if (sl811->irq_enable & SL11H_INTMASK_SOFINTR)
297 VDBG("sof irq on\n");
298 sl811->irq_enable |= SL11H_INTMASK_SOFINTR;
301 static inline void sofirq_off(struct sl811 *sl811)
303 if (!(sl811->irq_enable & SL11H_INTMASK_SOFINTR))
305 VDBG("sof irq off\n");
306 sl811->irq_enable &= ~SL11H_INTMASK_SOFINTR;
309 /*-------------------------------------------------------------------------*/
311 /* pick the next endpoint for a transaction, and issue it.
312 * frames start with periodic transfers (after whatever is pending
313 * from the previous frame), and the rest of the time is async
314 * transfers, scheduled round-robin.
316 static struct sl811h_ep *start(struct sl811 *sl811, u8 bank)
318 struct sl811h_ep *ep;
323 /* use endpoint at schedule head */
324 if (sl811->next_periodic) {
325 ep = sl811->next_periodic;
326 sl811->next_periodic = ep->next;
328 if (sl811->next_async)
329 ep = sl811->next_async;
330 else if (!list_empty(&sl811->async))
331 ep = container_of(sl811->async.next,
332 struct sl811h_ep, schedule);
334 /* could set up the first fullspeed periodic
335 * transfer for the next frame ...
341 if ((bank && sl811->active_b == ep) || sl811->active_a == ep)
345 if (ep->schedule.next == &sl811->async)
346 sl811->next_async = NULL;
348 sl811->next_async = container_of(ep->schedule.next,
349 struct sl811h_ep, schedule);
352 if (unlikely(list_empty(&ep->hep->urb_list))) {
353 DBG("empty %p queue?\n", ep);
357 urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
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,
436 struct pt_regs *regs,
438 ) __releases(sl811->lock) __acquires(sl811->lock)
442 if (usb_pipecontrol(urb->pipe))
443 ep->nextpid = USB_PID_SETUP;
445 spin_lock(&urb->lock);
446 if (urb->status == -EINPROGRESS)
447 urb->status = status;
448 spin_unlock(&urb->lock);
450 spin_unlock(&sl811->lock);
451 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb, regs);
452 spin_lock(&sl811->lock);
454 /* leave active endpoints in the schedule */
455 if (!list_empty(&ep->hep->urb_list))
458 /* async deschedule? */
459 if (!list_empty(&ep->schedule)) {
460 list_del_init(&ep->schedule);
461 if (ep == sl811->next_async)
462 sl811->next_async = NULL;
466 /* periodic deschedule */
467 DBG("deschedule qh%d/%p branch %d\n", ep->period, ep, ep->branch);
468 for (i = ep->branch; i < PERIODIC_SIZE; i += ep->period) {
469 struct sl811h_ep *temp;
470 struct sl811h_ep **prev = &sl811->periodic[i];
472 while (*prev && ((temp = *prev) != ep))
476 sl811->load[i] -= ep->load;
478 ep->branch = PERIODIC_SIZE;
479 sl811->periodic_count--;
480 sl811_to_hcd(sl811)->self.bandwidth_allocated
481 -= ep->load / ep->period;
482 if (ep == sl811->next_periodic)
483 sl811->next_periodic = ep->next;
485 /* we might turn SOFs back on again for the async schedule */
486 if (sl811->periodic_count == 0)
491 done(struct sl811 *sl811, struct sl811h_ep *ep, u8 bank, struct pt_regs *regs)
495 int urbstat = -EINPROGRESS;
500 status = sl811_read(sl811, bank + SL11H_PKTSTATREG);
502 urb = container_of(ep->hep->urb_list.next, struct urb, urb_list);
504 /* we can safely ignore NAKs */
505 if (status & SL11H_STATMASK_NAK) {
506 // PACKET("...NAK_%02x qh%p\n", bank, ep);
511 /* ACK advances transfer, toggle, and maybe queue */
512 } else if (status & SL11H_STATMASK_ACK) {
513 struct usb_device *udev = urb->dev;
517 /* urb->iso_frame_desc is currently ignored here... */
519 ep->nak_count = ep->error_count = 0;
520 switch (ep->nextpid) {
522 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
523 urb->actual_length += ep->length;
524 usb_dotoggle(udev, ep->epnum, 1);
525 if (urb->actual_length
526 == urb->transfer_buffer_length) {
527 if (usb_pipecontrol(urb->pipe))
528 ep->nextpid = USB_PID_ACK;
530 /* some bulk protocols terminate OUT transfers
531 * by a short packet, using ZLPs not padding.
533 else if (ep->length < ep->maxpacket
534 || !(urb->transfer_flags
540 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
541 buf = urb->transfer_buffer + urb->actual_length;
543 len = ep->maxpacket - sl811_read(sl811,
544 bank + SL11H_XFERCNTREG);
545 if (len > ep->length) {
547 urb->status = -EOVERFLOW;
549 urb->actual_length += len;
550 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0),
552 usb_dotoggle(udev, ep->epnum, 0);
553 if (urb->actual_length == urb->transfer_buffer_length)
555 else if (len < ep->maxpacket) {
556 if (urb->transfer_flags & URB_SHORT_NOT_OK)
557 urbstat = -EREMOTEIO;
561 if (usb_pipecontrol(urb->pipe)
562 && (urbstat == -EREMOTEIO
565 /* NOTE if the status stage STALLs (why?),
566 * this reports the wrong urb status.
568 spin_lock(&urb->lock);
569 if (urb->status == -EINPROGRESS)
570 urb->status = urbstat;
571 spin_unlock(&urb->lock);
574 ep->nextpid = USB_PID_ACK;
578 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
579 if (urb->transfer_buffer_length == urb->actual_length)
580 ep->nextpid = USB_PID_ACK;
581 else if (usb_pipeout(urb->pipe)) {
582 usb_settoggle(udev, 0, 1, 1);
583 ep->nextpid = USB_PID_OUT;
585 usb_settoggle(udev, 0, 0, 1);
586 ep->nextpid = USB_PID_IN;
590 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
595 /* STALL stops all transfers */
596 } else if (status & SL11H_STATMASK_STALL) {
597 PACKET("...STALL_%02x qh%p\n", bank, ep);
598 ep->nak_count = ep->error_count = 0;
601 /* error? retry, until "3 strikes" */
602 } else if (++ep->error_count >= 3) {
603 if (status & SL11H_STATMASK_TMOUT)
604 urbstat = -ETIMEDOUT;
605 else if (status & SL11H_STATMASK_OVF)
606 urbstat = -EOVERFLOW;
610 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
611 bank, status, ep, urbstat);
614 if (urb && (urbstat != -EINPROGRESS || urb->status != -EINPROGRESS))
615 finish_request(sl811, ep, urb, regs, urbstat);
618 static inline u8 checkdone(struct sl811 *sl811)
623 if (sl811->active_a && time_before_eq(sl811->jiffies_a, jiffies)) {
624 ctl = sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG));
625 if (ctl & SL11H_HCTLMASK_ARM)
626 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
627 DBG("%s DONE_A: ctrl %02x sts %02x\n",
628 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
630 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
631 irqstat |= SL11H_INTMASK_DONE_A;
634 if (sl811->active_b && time_before_eq(sl811->jiffies_b, jiffies)) {
635 ctl = sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG));
636 if (ctl & SL11H_HCTLMASK_ARM)
637 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
638 DBG("%s DONE_B: ctrl %02x sts %02x\n",
639 (ctl & SL11H_HCTLMASK_ARM) ? "timeout" : "lost",
641 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
642 irqstat |= SL11H_INTMASK_DONE_A;
648 static irqreturn_t sl811h_irq(int irq, void *_hcd, struct pt_regs *regs)
650 struct usb_hcd *hcd = _hcd;
651 struct sl811 *sl811 = hcd_to_sl811(hcd);
653 irqreturn_t ret = IRQ_NONE;
654 unsigned retries = 5;
656 spin_lock(&sl811->lock);
659 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS) & ~SL11H_INTMASK_DP;
661 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
662 irqstat &= sl811->irq_enable;
666 /* this may no longer be necessary ... */
667 if (irqstat == 0 && ret == IRQ_NONE) {
668 irqstat = checkdone(sl811);
669 if (irqstat && irq != ~0)
674 /* USB packets, not necessarily handled in the order they're
675 * issued ... that's fine if they're different endpoints.
677 if (irqstat & SL11H_INTMASK_DONE_A) {
678 done(sl811, sl811->active_a, SL811_EP_A(SL811_HOST_BUF), regs);
679 sl811->active_a = NULL;
683 if (irqstat & SL11H_INTMASK_DONE_B) {
684 done(sl811, sl811->active_b, SL811_EP_B(SL811_HOST_BUF), regs);
685 sl811->active_b = NULL;
689 if (irqstat & SL11H_INTMASK_SOFINTR) {
692 index = sl811->frame++ % (PERIODIC_SIZE - 1);
695 /* be graceful about almost-inevitable periodic schedule
696 * overruns: continue the previous frame's transfers iff
697 * this one has nothing scheduled.
699 if (sl811->next_periodic) {
700 // ERR("overrun to slot %d\n", index);
701 sl811->stat_overrun++;
703 if (sl811->periodic[index])
704 sl811->next_periodic = sl811->periodic[index];
707 /* khubd manages debouncing and wakeup */
708 if (irqstat & SL11H_INTMASK_INSRMV) {
709 sl811->stat_insrmv++;
711 /* most stats are reset for each VBUS session */
712 sl811->stat_wake = 0;
716 sl811->stat_lost = 0;
719 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
721 sl811->irq_enable = SL11H_INTMASK_INSRMV;
722 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
724 /* usbcore nukes other pending transactions on disconnect */
725 if (sl811->active_a) {
726 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG), 0);
727 finish_request(sl811, sl811->active_a,
728 container_of(sl811->active_a->hep->urb_list.next,
729 struct urb, urb_list),
731 sl811->active_a = NULL;
734 if (sl811->active_b) {
735 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG), 0);
736 finish_request(sl811, sl811->active_b,
737 container_of(sl811->active_b->hep->urb_list.next,
738 struct urb, urb_list),
740 sl811->active_b = NULL;
744 /* port status seems wierd until after reset, so
745 * force the reset and make khubd clean up later.
747 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
748 | (1 << USB_PORT_FEAT_CONNECTION);
750 } else if (irqstat & SL11H_INTMASK_RD) {
751 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)) {
753 sl811->port1 |= 1 << USB_PORT_FEAT_C_SUSPEND;
756 irqstat &= ~SL11H_INTMASK_RD;
760 if (sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
761 start_transfer(sl811);
768 if (sl811->periodic_count == 0 && list_empty(&sl811->async))
770 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
772 spin_unlock(&sl811->lock);
777 /*-------------------------------------------------------------------------*/
779 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
780 * this driver doesn't promise that much since it's got to handle an
781 * IRQ per packet; irq handling latencies also use up that time.
783 #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
785 static int balance(struct sl811 *sl811, u16 period, u16 load)
787 int i, branch = -ENOSPC;
789 /* search for the least loaded schedule branch of that period
790 * which has enough bandwidth left unreserved.
792 for (i = 0; i < period ; i++) {
793 if (branch < 0 || sl811->load[branch] > sl811->load[i]) {
796 for (j = i; j < PERIODIC_SIZE; j += period) {
797 if ((sl811->load[j] + load)
801 if (j < PERIODIC_SIZE)
809 /*-------------------------------------------------------------------------*/
811 static int sl811h_urb_enqueue(
813 struct usb_host_endpoint *hep,
817 struct sl811 *sl811 = hcd_to_sl811(hcd);
818 struct usb_device *udev = urb->dev;
819 unsigned int pipe = urb->pipe;
820 int is_out = !usb_pipein(pipe);
821 int type = usb_pipetype(pipe);
822 int epnum = usb_pipeendpoint(pipe);
823 struct sl811h_ep *ep = NULL;
829 if (type == PIPE_ISOCHRONOUS)
833 /* avoid all allocations within spinlocks */
835 ep = kcalloc(1, sizeof *ep, mem_flags);
837 spin_lock_irqsave(&sl811->lock, flags);
839 /* don't submit to a dead or disabled port */
840 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE))
841 || !HCD_IS_RUNNING(hcd->state)) {
854 INIT_LIST_HEAD(&ep->schedule);
855 ep->udev = usb_get_dev(udev);
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);
861 if (type == PIPE_CONTROL)
862 ep->nextpid = USB_PID_SETUP;
864 ep->nextpid = USB_PID_OUT;
866 ep->nextpid = USB_PID_IN;
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);
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;
882 case PIPE_ISOCHRONOUS:
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))
900 /* maybe put endpoint into schedule */
904 if (list_empty(&ep->schedule))
905 list_add_tail(&ep->schedule, &sl811->async);
907 case PIPE_ISOCHRONOUS:
909 urb->interval = ep->period;
910 if (ep->branch < PERIODIC_SIZE)
913 retval = balance(sl811, ep->period, ep->load);
918 urb->start_frame = (sl811->frame & (PERIODIC_SIZE - 1))
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
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;
930 while (here && ep != here) {
931 if (ep->period > here->period)
940 sl811->load[i] += ep->load;
942 sl811->periodic_count++;
943 hcd->self.bandwidth_allocated += ep->load / ep->period;
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);
956 spin_unlock(&urb->lock);
958 start_transfer(sl811);
959 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
961 spin_unlock_irqrestore(&sl811->lock, flags);
965 static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
967 struct sl811 *sl811 = hcd_to_sl811(hcd);
968 struct usb_host_endpoint *hep = urb->hcpriv;
970 struct sl811h_ep *ep;
976 spin_lock_irqsave(&sl811->lock, flags);
979 /* finish right away if this urb can't be active ...
980 * note that some drivers wrongly expect delays
982 if (ep->hep->urb_list.next != &urb->urb_list) {
983 /* not front of queue? never active */
985 /* for active transfers, we expect an IRQ */
986 } else if (sl811->active_a == ep) {
987 if (time_before_eq(sl811->jiffies_a, jiffies)) {
988 /* happens a lot with lowspeed?? */
989 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
991 SL811_EP_A(SL11H_HOSTCTLREG)),
993 SL811_EP_A(SL11H_PKTSTATREG)));
994 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
996 sl811->active_a = NULL;
1000 } else if (sl811->active_b == ep) {
1001 if (time_before_eq(sl811->jiffies_a, jiffies)) {
1002 /* happens a lot with lowspeed?? */
1003 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1005 SL811_EP_B(SL11H_HOSTCTLREG)),
1007 SL811_EP_B(SL11H_PKTSTATREG)));
1008 sl811_write(sl811, SL811_EP_B(SL11H_HOSTCTLREG),
1010 sl811->active_b = NULL;
1015 /* front of queue for inactive endpoint */
1019 finish_request(sl811, ep, urb, NULL, 0);
1021 VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1022 (sl811->active_a == ep) ? "A" : "B");
1025 spin_unlock_irqrestore(&sl811->lock, flags);
1030 sl811h_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *hep)
1032 struct sl811h_ep *ep = hep->hcpriv;
1037 /* assume we'd just wait for the irq */
1038 if (!list_empty(&hep->urb_list))
1040 if (!list_empty(&hep->urb_list))
1041 WARN("ep %p not empty?\n", ep);
1043 usb_put_dev(ep->udev);
1049 sl811h_get_frame(struct usb_hcd *hcd)
1051 struct sl811 *sl811 = hcd_to_sl811(hcd);
1053 /* wrong except while periodic transfers are scheduled;
1054 * never matches the on-the-wire frame;
1055 * subject to overruns.
1057 return sl811->frame;
1061 /*-------------------------------------------------------------------------*/
1063 /* the virtual root hub timer IRQ checks for hub status */
1065 sl811h_hub_status_data(struct usb_hcd *hcd, char *buf)
1067 struct sl811 *sl811 = hcd_to_sl811(hcd);
1069 unsigned long flags;
1071 /* non-SMP HACK: use root hub timer as i/o watchdog
1072 * this seems essential when SOF IRQs aren't in use...
1074 local_irq_save(flags);
1075 if (!timer_pending(&sl811->timer)) {
1076 if (sl811h_irq(~0, sl811, NULL) != IRQ_NONE)
1079 local_irq_restore(flags);
1082 if (!(sl811->port1 & (0xffff << 16)))
1085 /* tell khubd port 1 changed */
1091 sl811h_hub_descriptor (
1092 struct sl811 *sl811,
1093 struct usb_hub_descriptor *desc
1097 desc->bDescriptorType = 0x29;
1098 desc->bHubContrCurrent = 0;
1100 desc->bNbrPorts = 1;
1101 desc->bDescLength = 9;
1103 /* per-port power switching (gang of one!), or none */
1104 desc->bPwrOn2PwrGood = 0;
1105 if (sl811->board && sl811->board->port_power) {
1106 desc->bPwrOn2PwrGood = sl811->board->potpg;
1107 if (!desc->bPwrOn2PwrGood)
1108 desc->bPwrOn2PwrGood = 10;
1113 /* no overcurrent errors detection/handling */
1116 desc->wHubCharacteristics = (__force __u16)cpu_to_le16(temp);
1118 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1119 desc->bitmap[0] = 1 << 1;
1120 desc->bitmap[1] = ~0;
1124 sl811h_timer(unsigned long _sl811)
1126 struct sl811 *sl811 = (void *) _sl811;
1127 unsigned long flags;
1129 u8 signaling = sl811->ctrl1 & SL11H_CTL1MASK_FORCE;
1130 const u32 mask = (1 << USB_PORT_FEAT_CONNECTION)
1131 | (1 << USB_PORT_FEAT_ENABLE)
1132 | (1 << USB_PORT_FEAT_LOWSPEED);
1134 spin_lock_irqsave(&sl811->lock, flags);
1136 /* stop special signaling */
1137 sl811->ctrl1 &= ~SL11H_CTL1MASK_FORCE;
1138 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1141 irqstat = sl811_read(sl811, SL11H_IRQ_STATUS);
1143 switch (signaling) {
1144 case SL11H_CTL1MASK_SE0:
1146 sl811->port1 = (1 << USB_PORT_FEAT_C_RESET)
1147 | (1 << USB_PORT_FEAT_POWER);
1149 /* don't wrongly ack RD */
1150 if (irqstat & SL11H_INTMASK_INSRMV)
1151 irqstat &= ~SL11H_INTMASK_RD;
1153 case SL11H_CTL1MASK_K:
1154 DBG("end resume\n");
1155 sl811->port1 &= ~(1 << USB_PORT_FEAT_SUSPEND);
1158 DBG("odd timer signaling: %02x\n", signaling);
1161 sl811_write(sl811, SL11H_IRQ_STATUS, irqstat);
1163 if (irqstat & SL11H_INTMASK_RD) {
1164 /* usbcore nukes all pending transactions on disconnect */
1165 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION))
1166 sl811->port1 |= (1 << USB_PORT_FEAT_C_CONNECTION)
1167 | (1 << USB_PORT_FEAT_C_ENABLE);
1168 sl811->port1 &= ~mask;
1169 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1171 sl811->port1 |= mask;
1172 if (irqstat & SL11H_INTMASK_DP)
1173 sl811->port1 &= ~(1 << USB_PORT_FEAT_LOWSPEED);
1174 sl811->irq_enable = SL11H_INTMASK_INSRMV | SL11H_INTMASK_RD;
1177 if (sl811->port1 & (1 << USB_PORT_FEAT_CONNECTION)) {
1178 u8 ctrl2 = SL811HS_CTL2_INIT;
1180 sl811->irq_enable |= SL11H_INTMASK_DONE_A;
1182 sl811->irq_enable |= SL11H_INTMASK_DONE_B;
1184 if (sl811->port1 & (1 << USB_PORT_FEAT_LOWSPEED)) {
1185 sl811->ctrl1 |= SL11H_CTL1MASK_LSPD;
1186 ctrl2 |= SL811HS_CTL2MASK_DSWAP;
1189 /* start SOFs flowing, kickstarting with A registers */
1190 sl811->ctrl1 |= SL11H_CTL1MASK_SOF_ENA;
1191 sl811_write(sl811, SL11H_SOFLOWREG, 0xe0);
1192 sl811_write(sl811, SL811HS_CTLREG2, ctrl2);
1194 /* autoincrementing */
1195 sl811_write(sl811, SL811_EP_A(SL11H_BUFLNTHREG), 0);
1196 writeb(SL_SOF, sl811->data_reg);
1197 writeb(0, sl811->data_reg);
1198 sl811_write(sl811, SL811_EP_A(SL11H_HOSTCTLREG),
1199 SL11H_HCTLMASK_ARM);
1201 /* khubd provides debounce delay */
1205 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1208 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
1209 spin_unlock_irqrestore(&sl811->lock, flags);
1214 struct usb_hcd *hcd,
1221 struct sl811 *sl811 = hcd_to_sl811(hcd);
1223 unsigned long flags;
1225 spin_lock_irqsave(&sl811->lock, flags);
1228 case ClearHubFeature:
1231 case C_HUB_OVER_CURRENT:
1232 case C_HUB_LOCAL_POWER:
1238 case ClearPortFeature:
1239 if (wIndex != 1 || wLength != 0)
1243 case USB_PORT_FEAT_ENABLE:
1244 sl811->port1 &= (1 << USB_PORT_FEAT_POWER);
1246 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1247 sl811->irq_enable = SL11H_INTMASK_INSRMV;
1248 sl811_write(sl811, SL11H_IRQ_ENABLE,
1251 case USB_PORT_FEAT_SUSPEND:
1252 if (!(sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND)))
1255 /* 20 msec of resume/K signaling, other irqs blocked */
1256 DBG("start resume...\n");
1257 sl811->irq_enable = 0;
1258 sl811_write(sl811, SL11H_IRQ_ENABLE,
1260 sl811->ctrl1 |= SL11H_CTL1MASK_K;
1261 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1263 mod_timer(&sl811->timer, jiffies
1264 + msecs_to_jiffies(20));
1266 case USB_PORT_FEAT_POWER:
1267 port_power(sl811, 0);
1269 case USB_PORT_FEAT_C_ENABLE:
1270 case USB_PORT_FEAT_C_SUSPEND:
1271 case USB_PORT_FEAT_C_CONNECTION:
1272 case USB_PORT_FEAT_C_OVER_CURRENT:
1273 case USB_PORT_FEAT_C_RESET:
1278 sl811->port1 &= ~(1 << wValue);
1280 case GetHubDescriptor:
1281 sl811h_hub_descriptor(sl811, (struct usb_hub_descriptor *) buf);
1284 *(__le32 *) buf = cpu_to_le32(0);
1289 *(__le32 *) buf = cpu_to_le32(sl811->port1);
1292 if (*(u16*)(buf+2)) /* only if wPortChange is interesting */
1294 DBG("GetPortStatus %08x\n", sl811->port1);
1296 case SetPortFeature:
1297 if (wIndex != 1 || wLength != 0)
1300 case USB_PORT_FEAT_SUSPEND:
1301 if (sl811->port1 & (1 << USB_PORT_FEAT_RESET))
1303 if (!(sl811->port1 & (1 << USB_PORT_FEAT_ENABLE)))
1306 DBG("suspend...\n");
1307 sl811->ctrl1 &= ~SL11H_CTL1MASK_SOF_ENA;
1308 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1310 case USB_PORT_FEAT_POWER:
1311 port_power(sl811, 1);
1313 case USB_PORT_FEAT_RESET:
1314 if (sl811->port1 & (1 << USB_PORT_FEAT_SUSPEND))
1316 if (!(sl811->port1 & (1 << USB_PORT_FEAT_POWER)))
1319 /* 50 msec of reset/SE0 signaling, irqs blocked */
1320 sl811->irq_enable = 0;
1321 sl811_write(sl811, SL11H_IRQ_ENABLE,
1323 sl811->ctrl1 = SL11H_CTL1MASK_SE0;
1324 sl811_write(sl811, SL11H_CTLREG1, sl811->ctrl1);
1325 sl811->port1 |= (1 << USB_PORT_FEAT_RESET);
1326 mod_timer(&sl811->timer, jiffies
1327 + msecs_to_jiffies(50));
1332 sl811->port1 |= 1 << wValue;
1337 /* "protocol stall" on error */
1341 spin_unlock_irqrestore(&sl811->lock, flags);
1348 sl811h_hub_suspend(struct usb_hcd *hcd)
1351 DBG("%s\n", __FUNCTION__);
1356 sl811h_hub_resume(struct usb_hcd *hcd)
1359 DBG("%s\n", __FUNCTION__);
1365 #define sl811h_hub_suspend NULL
1366 #define sl811h_hub_resume NULL
1371 /*-------------------------------------------------------------------------*/
1373 #ifdef STUB_DEBUG_FILE
1375 static inline void create_debug_file(struct sl811 *sl811) { }
1376 static inline void remove_debug_file(struct sl811 *sl811) { }
1380 #include <linux/proc_fs.h>
1381 #include <linux/seq_file.h>
1383 static void dump_irq(struct seq_file *s, char *label, u8 mask)
1385 seq_printf(s, "%s %02x%s%s%s%s%s%s\n", label, mask,
1386 (mask & SL11H_INTMASK_DONE_A) ? " done_a" : "",
1387 (mask & SL11H_INTMASK_DONE_B) ? " done_b" : "",
1388 (mask & SL11H_INTMASK_SOFINTR) ? " sof" : "",
1389 (mask & SL11H_INTMASK_INSRMV) ? " ins/rmv" : "",
1390 (mask & SL11H_INTMASK_RD) ? " rd" : "",
1391 (mask & SL11H_INTMASK_DP) ? " dp" : "");
1394 static int proc_sl811h_show(struct seq_file *s, void *unused)
1396 struct sl811 *sl811 = s->private;
1397 struct sl811h_ep *ep;
1400 seq_printf(s, "%s\n%s version %s\nportstatus[1] = %08x\n",
1401 sl811_to_hcd(sl811)->product_desc,
1402 hcd_name, DRIVER_VERSION,
1405 seq_printf(s, "insert/remove: %ld\n", sl811->stat_insrmv);
1406 seq_printf(s, "current session: done_a %ld done_b %ld "
1407 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1408 sl811->stat_a, sl811->stat_b,
1409 sl811->stat_wake, sl811->stat_sof,
1410 sl811->stat_overrun, sl811->stat_lost);
1412 spin_lock_irq(&sl811->lock);
1414 if (sl811->ctrl1 & SL11H_CTL1MASK_SUSPEND)
1415 seq_printf(s, "(suspended)\n\n");
1417 u8 t = sl811_read(sl811, SL11H_CTLREG1);
1419 seq_printf(s, "ctrl1 %02x%s%s%s%s\n", t,
1420 (t & SL11H_CTL1MASK_SOF_ENA) ? " sofgen" : "",
1421 ({char *s; switch (t & SL11H_CTL1MASK_FORCE) {
1422 case SL11H_CTL1MASK_NORMAL: s = ""; break;
1423 case SL11H_CTL1MASK_SE0: s = " se0/reset"; break;
1424 case SL11H_CTL1MASK_K: s = " k/resume"; break;
1425 default: s = "j"; break;
1427 (t & SL11H_CTL1MASK_LSPD) ? " lowspeed" : "",
1428 (t & SL11H_CTL1MASK_SUSPEND) ? " suspend" : "");
1430 dump_irq(s, "irq_enable",
1431 sl811_read(sl811, SL11H_IRQ_ENABLE));
1432 dump_irq(s, "irq_status",
1433 sl811_read(sl811, SL11H_IRQ_STATUS));
1434 seq_printf(s, "frame clocks remaining: %d\n",
1435 sl811_read(sl811, SL11H_SOFTMRREG) << 6);
1438 seq_printf(s, "A: qh%p ctl %02x sts %02x\n", sl811->active_a,
1439 sl811_read(sl811, SL811_EP_A(SL11H_HOSTCTLREG)),
1440 sl811_read(sl811, SL811_EP_A(SL11H_PKTSTATREG)));
1441 seq_printf(s, "B: qh%p ctl %02x sts %02x\n", sl811->active_b,
1442 sl811_read(sl811, SL811_EP_B(SL11H_HOSTCTLREG)),
1443 sl811_read(sl811, SL811_EP_B(SL11H_PKTSTATREG)));
1444 seq_printf(s, "\n");
1445 list_for_each_entry (ep, &sl811->async, schedule) {
1448 seq_printf(s, "%s%sqh%p, ep%d%s, maxpacket %d"
1450 (ep == sl811->active_a) ? "(A) " : "",
1451 (ep == sl811->active_b) ? "(B) " : "",
1453 ({ char *s; switch (ep->nextpid) {
1454 case USB_PID_IN: s = "in"; break;
1455 case USB_PID_OUT: s = "out"; break;
1456 case USB_PID_SETUP: s = "setup"; break;
1457 case USB_PID_ACK: s = "status"; break;
1458 default: s = "?"; break;
1461 ep->nak_count, ep->error_count);
1462 list_for_each_entry (urb, &ep->hep->urb_list, urb_list) {
1463 seq_printf(s, " urb%p, %d/%d\n", urb,
1465 urb->transfer_buffer_length);
1468 if (!list_empty(&sl811->async))
1469 seq_printf(s, "\n");
1471 seq_printf(s, "periodic size= %d\n", PERIODIC_SIZE);
1473 for (i = 0; i < PERIODIC_SIZE; i++) {
1474 ep = sl811->periodic[i];
1477 seq_printf(s, "%2d [%3d]:\n", i, sl811->load[i]);
1479 /* DUMB: prints shared entries multiple times */
1482 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1484 (ep == sl811->active_a) ? "(A) " : "",
1485 (ep == sl811->active_b) ? "(B) " : "",
1487 (ep->udev->speed == USB_SPEED_FULL)
1489 ep->udev->devnum, ep->epnum,
1490 (ep->epnum == 0) ? ""
1491 : ((ep->nextpid == USB_PID_IN)
1494 ep->maxpacket, ep->error_count);
1499 spin_unlock_irq(&sl811->lock);
1500 seq_printf(s, "\n");
1505 static int proc_sl811h_open(struct inode *inode, struct file *file)
1507 return single_open(file, proc_sl811h_show, PDE(inode)->data);
1510 static struct file_operations proc_ops = {
1511 .open = proc_sl811h_open,
1513 .llseek = seq_lseek,
1514 .release = single_release,
1517 /* expect just one sl811 per system */
1518 static const char proc_filename[] = "driver/sl811h";
1520 static void create_debug_file(struct sl811 *sl811)
1522 struct proc_dir_entry *pde;
1524 pde = create_proc_entry(proc_filename, 0, NULL);
1528 pde->proc_fops = &proc_ops;
1533 static void remove_debug_file(struct sl811 *sl811)
1536 remove_proc_entry(proc_filename, NULL);
1541 /*-------------------------------------------------------------------------*/
1544 sl811h_stop(struct usb_hcd *hcd)
1546 struct sl811 *sl811 = hcd_to_sl811(hcd);
1547 unsigned long flags;
1549 del_timer_sync(&hcd->rh_timer);
1551 spin_lock_irqsave(&sl811->lock, flags);
1552 port_power(sl811, 0);
1553 spin_unlock_irqrestore(&sl811->lock, flags);
1557 sl811h_start(struct usb_hcd *hcd)
1559 struct sl811 *sl811 = hcd_to_sl811(hcd);
1560 struct usb_device *udev;
1562 /* chip has been reset, VBUS power is off */
1564 udev = usb_alloc_dev(NULL, &hcd->self, 0);
1568 udev->speed = USB_SPEED_FULL;
1569 hcd->state = USB_STATE_RUNNING;
1572 hcd->can_wakeup = sl811->board->can_wakeup;
1574 if (hcd_register_root(udev, hcd) != 0) {
1580 if (sl811->board && sl811->board->power)
1581 hub_set_power_budget(udev, sl811->board->power * 2);
1586 /*-------------------------------------------------------------------------*/
1588 static struct hc_driver sl811h_hc_driver = {
1589 .description = hcd_name,
1590 .hcd_priv_size = sizeof(struct sl811),
1593 * generic hardware linkage
1598 * managing i/o requests and associated device resources
1600 .urb_enqueue = sl811h_urb_enqueue,
1601 .urb_dequeue = sl811h_urb_dequeue,
1602 .endpoint_disable = sl811h_endpoint_disable,
1605 * periodic schedule support
1607 .get_frame_number = sl811h_get_frame,
1612 .hub_status_data = sl811h_hub_status_data,
1613 .hub_control = sl811h_hub_control,
1614 .hub_suspend = sl811h_hub_suspend,
1615 .hub_resume = sl811h_hub_resume,
1618 /*-------------------------------------------------------------------------*/
1620 static int __init_or_module
1621 sl811h_remove(struct device *dev)
1623 struct sl811 *sl811 = dev_get_drvdata(dev);
1624 struct usb_hcd *hcd = sl811_to_hcd(sl811);
1625 struct platform_device *pdev;
1626 struct resource *res;
1628 pdev = container_of(dev, struct platform_device, dev);
1630 if (HCD_IS_RUNNING(hcd->state))
1631 hcd->state = USB_STATE_QUIESCING;
1633 usb_disconnect(&hcd->self.root_hub);
1634 remove_debug_file(sl811);
1637 usb_deregister_bus(&hcd->self);
1639 free_irq(hcd->irq, hcd);
1641 iounmap(sl811->data_reg);
1642 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1643 release_mem_region(res->start, 1);
1645 iounmap(sl811->addr_reg);
1646 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1647 release_mem_region(res->start, 1);
1653 #define resource_len(r) (((r)->end - (r)->start) + 1)
1656 sl811h_probe(struct device *dev)
1658 struct usb_hcd *hcd;
1659 struct sl811 *sl811;
1660 struct platform_device *pdev;
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 pdev = container_of(dev, struct platform_device, dev);
1674 if (pdev->num_resources < 3)
1677 addr = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1678 data = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1679 irq = platform_get_irq(pdev, 0);
1680 if (!addr || !data || irq < 0)
1683 /* refuse to confuse usbcore */
1684 if (dev->dma_mask) {
1685 DBG("no we won't dma\n");
1689 if (!request_mem_region(addr->start, 1, hcd_name)) {
1693 addr_reg = ioremap(addr->start, resource_len(addr));
1694 if (addr_reg == NULL) {
1699 if (!request_mem_region(data->start, 1, hcd_name)) {
1703 data_reg = ioremap(data->start, resource_len(addr));
1704 if (data_reg == NULL) {
1709 /* allocate and initialize hcd */
1710 hcd = usb_create_hcd(&sl811h_hc_driver);
1715 sl811 = hcd_to_sl811(hcd);
1716 dev_set_drvdata(dev, sl811);
1718 hcd->self.controller = dev;
1719 hcd->self.bus_name = dev->bus_id;
1721 hcd->regs = addr_reg;
1723 spin_lock_init(&sl811->lock);
1724 INIT_LIST_HEAD(&sl811->async);
1725 sl811->board = dev->platform_data;
1726 init_timer(&sl811->timer);
1727 sl811->timer.function = sl811h_timer;
1728 sl811->timer.data = (unsigned long) sl811;
1729 sl811->addr_reg = addr_reg;
1730 sl811->data_reg = data_reg;
1732 spin_lock_irq(&sl811->lock);
1733 port_power(sl811, 0);
1734 spin_unlock_irq(&sl811->lock);
1737 tmp = sl811_read(sl811, SL11H_HWREVREG);
1740 hcd->product_desc = "SL811HS v1.2";
1743 hcd->product_desc = "SL811HS v1.5";
1746 /* reject case 0, SL11S is less functional */
1747 DBG("chiprev %02x\n", tmp);
1752 /* sl811s would need a different handler for this irq */
1754 /* Cypress docs say the IRQ is IRQT_HIGH ... */
1755 set_irq_type(irq, IRQT_RISING);
1757 retval = request_irq(irq, sl811h_irq, SA_INTERRUPT,
1758 hcd->driver->description, hcd);
1762 INFO("%s, irq %d\n", hcd->product_desc, irq);
1764 retval = usb_register_bus(&hcd->self);
1768 retval = sl811h_start(hcd);
1772 create_debug_file(sl811);
1776 usb_deregister_bus(&hcd->self);
1778 free_irq(hcd->irq, hcd);
1784 release_mem_region(data->start, 1);
1788 release_mem_region(addr->start, 1);
1790 DBG("init error, %d\n", retval);
1796 /* for this device there's no useful distinction between the controller
1797 * and its root hub, except that the root hub only gets direct PM calls
1798 * when CONFIG_USB_SUSPEND is enabled.
1802 sl811h_suspend(struct device *dev, u32 state, u32 phase)
1804 struct sl811 *sl811 = dev_get_drvdata(dev);
1807 if (phase != SUSPEND_POWER_DOWN)
1810 if (state <= PM_SUSPEND_MEM)
1811 retval = sl811h_hub_suspend(sl811_to_hcd(sl811));
1813 port_power(sl811, 0);
1815 dev->power.power_state = state;
1820 sl811h_resume(struct device *dev, u32 phase)
1822 struct sl811 *sl811 = dev_get_drvdata(dev);
1824 if (phase != RESUME_POWER_ON)
1827 /* with no "check to see if VBUS is still powered" board hook,
1828 * let's assume it'd only be powered to enable remote wakeup.
1830 if (dev->power.power_state > PM_SUSPEND_MEM
1831 || !sl811_to_hcd(sl811)->can_wakeup) {
1833 port_power(sl811, 1);
1837 dev->power.power_state = PM_SUSPEND_ON;
1838 return sl811h_hub_resume(sl811_to_hcd(sl811));
1843 #define sl811h_suspend NULL
1844 #define sl811h_resume NULL
1849 static struct device_driver sl811h_driver = {
1850 .name = (char *) hcd_name,
1851 .bus = &platform_bus_type,
1853 .probe = sl811h_probe,
1854 .remove = sl811h_remove,
1856 .suspend = sl811h_suspend,
1857 .resume = sl811h_resume,
1860 /*-------------------------------------------------------------------------*/
1862 static int __init sl811h_init(void)
1867 INFO("driver %s, %s\n", hcd_name, DRIVER_VERSION);
1868 return driver_register(&sl811h_driver);
1870 module_init(sl811h_init);
1872 static void __exit sl811h_cleanup(void)
1874 driver_unregister(&sl811h_driver);
1876 module_exit(sl811h_cleanup);