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>
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/kernel.h>
38 #include <linux/delay.h>
39 #include <linux/ioport.h>
40 #include <linux/sched.h>
41 #include <linux/slab.h>
42 #include <linux/smp_lock.h>
43 #include <linux/errno.h>
44 #include <linux/init.h>
45 #include <linux/timer.h>
46 #include <linux/list.h>
47 #include <linux/interrupt.h>
48 #include <linux/usb.h>
49 #include <linux/usb_sl811.h>
50 #include <linux/platform_device.h>
54 #include <asm/system.h>
55 #include <asm/byteorder.h>
57 #include "../core/hcd.h"
61 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
62 MODULE_LICENSE("GPL");
64 #define DRIVER_VERSION "19 May 2005"
68 # define STUB_DEBUG_FILE
71 /* for now, use only one transfer register bank */
74 /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
75 * that just queued one ISO frame per URB then iso transfers "should" work
76 * using the normal urb status fields.
83 static const char hcd_name
[] = "sl811-hcd";
85 /*-------------------------------------------------------------------------*/
87 static void port_power(struct sl811
*sl811
, int is_on
)
89 struct usb_hcd
*hcd
= sl811_to_hcd(sl811
);
91 /* hub is inactive unless the port is powered */
93 if (sl811
->port1
& (1 << USB_PORT_FEAT_POWER
))
96 sl811
->port1
= (1 << USB_PORT_FEAT_POWER
);
97 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
98 hcd
->self
.controller
->power
.power_state
= PMSG_ON
;
101 sl811
->irq_enable
= 0;
102 hcd
->state
= HC_STATE_HALT
;
103 hcd
->self
.controller
->power
.power_state
= PMSG_SUSPEND
;
106 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
107 sl811_write(sl811
, SL11H_IRQ_STATUS
, ~0);
109 if (sl811
->board
&& sl811
->board
->port_power
) {
110 /* switch VBUS, at 500mA unless hub power budget gets set */
111 DBG("power %s\n", is_on
? "on" : "off");
112 sl811
->board
->port_power(hcd
->self
.controller
, is_on
);
115 /* reset as thoroughly as we can */
116 if (sl811
->board
&& sl811
->board
->reset
)
117 sl811
->board
->reset(hcd
->self
.controller
);
119 sl811_write(sl811
, SL11H_CTLREG1
, SL11H_CTL1MASK_SE0
);
123 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
124 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
125 sl811_write(sl811
, SL811HS_CTLREG2
, SL811HS_CTL2_INIT
);
126 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
128 // if !is_on, put into lowpower mode now
131 /*-------------------------------------------------------------------------*/
133 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
134 * and may start I/O. Endpoint queues are scanned during completion irq
135 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
137 * Using an external DMA engine to copy a packet at a time could work,
138 * though setup/teardown costs may be too big to make it worthwhile.
141 /* SETUP starts a new control request. Devices are not allowed to
142 * STALL or NAK these; they must cancel any pending control requests.
144 static void setup_packet(
146 struct sl811h_ep
*ep
,
154 void __iomem
*data_reg
;
156 addr
= SL811HS_PACKET_BUF(bank
== 0);
157 len
= sizeof(struct usb_ctrlrequest
);
158 data_reg
= sl811
->data_reg
;
159 sl811_write_buf(sl811
, addr
, urb
->setup_packet
, len
);
161 /* autoincrementing */
162 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
163 writeb(len
, data_reg
);
164 writeb(SL_SETUP
/* | ep->epnum */, data_reg
);
165 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
167 /* always OUT/data0 */ ;
168 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
169 control
| SL11H_HCTLMASK_OUT
);
171 PACKET("SETUP qh%p\n", ep
);
174 /* STATUS finishes control requests, often after IN or OUT data packets */
175 static void status_packet(
177 struct sl811h_ep
*ep
,
184 void __iomem
*data_reg
;
186 do_out
= urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
);
187 data_reg
= sl811
->data_reg
;
189 /* autoincrementing */
190 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, 0);
192 writeb((do_out
? SL_OUT
: SL_IN
) /* | ep->epnum */, data_reg
);
193 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
195 /* always data1; sometimes IN */
196 control
|= SL11H_HCTLMASK_TOGGLE
;
198 control
|= SL11H_HCTLMASK_OUT
;
199 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
201 PACKET("STATUS%s/%s qh%p\n", ep
->nak_count
? "/retry" : "",
202 do_out
? "out" : "in", ep
);
205 /* IN packets can be used with any type of endpoint. here we just
206 * start the transfer, data from the peripheral may arrive later.
207 * urb->iso_frame_desc is currently ignored here...
209 static void in_packet(
211 struct sl811h_ep
*ep
,
219 void __iomem
*data_reg
;
221 /* avoid losing data on overflow */
223 addr
= SL811HS_PACKET_BUF(bank
== 0);
224 if (!(control
& SL11H_HCTLMASK_ISOCH
)
225 && usb_gettoggle(urb
->dev
, ep
->epnum
, 0))
226 control
|= SL11H_HCTLMASK_TOGGLE
;
227 data_reg
= sl811
->data_reg
;
229 /* autoincrementing */
230 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
231 writeb(len
, data_reg
);
232 writeb(SL_IN
| ep
->epnum
, data_reg
);
233 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
235 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
236 ep
->length
= min((int)len
,
237 urb
->transfer_buffer_length
- urb
->actual_length
);
238 PACKET("IN%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
239 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 0), ep
, len
);
242 /* OUT packets can be used with any type of endpoint.
243 * urb->iso_frame_desc is currently ignored here...
245 static void out_packet(
247 struct sl811h_ep
*ep
,
256 void __iomem
*data_reg
;
258 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
261 len
= min((int)ep
->maxpacket
,
262 urb
->transfer_buffer_length
- urb
->actual_length
);
264 if (!(control
& SL11H_HCTLMASK_ISOCH
)
265 && usb_gettoggle(urb
->dev
, ep
->epnum
, 1))
266 control
|= SL11H_HCTLMASK_TOGGLE
;
267 addr
= SL811HS_PACKET_BUF(bank
== 0);
268 data_reg
= sl811
->data_reg
;
270 sl811_write_buf(sl811
, addr
, buf
, len
);
272 /* autoincrementing */
273 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
274 writeb(len
, data_reg
);
275 writeb(SL_OUT
| ep
->epnum
, data_reg
);
276 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
278 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
279 control
| SL11H_HCTLMASK_OUT
);
281 PACKET("OUT%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
282 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 1), ep
, len
);
285 /*-------------------------------------------------------------------------*/
287 /* caller updates on-chip enables later */
289 static inline void sofirq_on(struct sl811
*sl811
)
291 if (sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
)
293 VDBG("sof irq on\n");
294 sl811
->irq_enable
|= SL11H_INTMASK_SOFINTR
;
297 static inline void sofirq_off(struct sl811
*sl811
)
299 if (!(sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
))
301 VDBG("sof irq off\n");
302 sl811
->irq_enable
&= ~SL11H_INTMASK_SOFINTR
;
305 /*-------------------------------------------------------------------------*/
307 /* pick the next endpoint for a transaction, and issue it.
308 * frames start with periodic transfers (after whatever is pending
309 * from the previous frame), and the rest of the time is async
310 * transfers, scheduled round-robin.
312 static struct sl811h_ep
*start(struct sl811
*sl811
, u8 bank
)
314 struct sl811h_ep
*ep
;
319 /* use endpoint at schedule head */
320 if (sl811
->next_periodic
) {
321 ep
= sl811
->next_periodic
;
322 sl811
->next_periodic
= ep
->next
;
324 if (sl811
->next_async
)
325 ep
= sl811
->next_async
;
326 else if (!list_empty(&sl811
->async
))
327 ep
= container_of(sl811
->async
.next
,
328 struct sl811h_ep
, schedule
);
330 /* could set up the first fullspeed periodic
331 * transfer for the next frame ...
337 if ((bank
&& sl811
->active_b
== ep
) || sl811
->active_a
== ep
)
341 if (ep
->schedule
.next
== &sl811
->async
)
342 sl811
->next_async
= NULL
;
344 sl811
->next_async
= container_of(ep
->schedule
.next
,
345 struct sl811h_ep
, schedule
);
348 if (unlikely(list_empty(&ep
->hep
->urb_list
))) {
349 DBG("empty %p queue?\n", ep
);
353 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
354 control
= ep
->defctrl
;
356 /* if this frame doesn't have enough time left to transfer this
357 * packet, wait till the next frame. too-simple algorithm...
359 fclock
= sl811_read(sl811
, SL11H_SOFTMRREG
) << 6;
360 fclock
-= 100; /* setup takes not much time */
361 if (urb
->dev
->speed
== USB_SPEED_LOW
) {
362 if (control
& SL11H_HCTLMASK_PREAMBLE
) {
363 /* also note erratum 1: some hubs won't work */
366 fclock
-= ep
->maxpacket
<< 8;
368 /* erratum 2: AFTERSOF only works for fullspeed */
371 sl811
->stat_overrun
++;
376 fclock
-= 12000 / 19; /* 19 64byte packets/msec */
379 sl811
->stat_overrun
++;
380 control
|= SL11H_HCTLMASK_AFTERSOF
;
382 /* throttle bulk/control irq noise */
383 } else if (ep
->nak_count
)
384 control
|= SL11H_HCTLMASK_AFTERSOF
;
388 switch (ep
->nextpid
) {
390 in_packet(sl811
, ep
, urb
, bank
, control
);
393 out_packet(sl811
, ep
, urb
, bank
, control
);
396 setup_packet(sl811
, ep
, urb
, bank
, control
);
398 case USB_PID_ACK
: /* for control status */
399 status_packet(sl811
, ep
, urb
, bank
, control
);
402 DBG("bad ep%p pid %02x\n", ep
, ep
->nextpid
);
408 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
410 static inline void start_transfer(struct sl811
*sl811
)
412 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
414 if (sl811
->active_a
== NULL
) {
415 sl811
->active_a
= start(sl811
, SL811_EP_A(SL811_HOST_BUF
));
416 if (sl811
->active_a
!= NULL
)
417 sl811
->jiffies_a
= jiffies
+ MIN_JIFFIES
;
420 if (sl811
->active_b
== NULL
) {
421 sl811
->active_b
= start(sl811
, SL811_EP_B(SL811_HOST_BUF
));
422 if (sl811
->active_b
!= NULL
)
423 sl811
->jiffies_b
= jiffies
+ MIN_JIFFIES
;
428 static void finish_request(
430 struct sl811h_ep
*ep
,
432 struct pt_regs
*regs
,
434 ) __releases(sl811
->lock
) __acquires(sl811
->lock
)
438 if (usb_pipecontrol(urb
->pipe
))
439 ep
->nextpid
= USB_PID_SETUP
;
441 spin_lock(&urb
->lock
);
442 if (urb
->status
== -EINPROGRESS
)
443 urb
->status
= status
;
445 spin_unlock(&urb
->lock
);
447 spin_unlock(&sl811
->lock
);
448 usb_hcd_giveback_urb(sl811_to_hcd(sl811
), urb
, regs
);
449 spin_lock(&sl811
->lock
);
451 /* leave active endpoints in the schedule */
452 if (!list_empty(&ep
->hep
->urb_list
))
455 /* async deschedule? */
456 if (!list_empty(&ep
->schedule
)) {
457 list_del_init(&ep
->schedule
);
458 if (ep
== sl811
->next_async
)
459 sl811
->next_async
= NULL
;
463 /* periodic deschedule */
464 DBG("deschedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
465 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
466 struct sl811h_ep
*temp
;
467 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
469 while (*prev
&& ((temp
= *prev
) != ep
))
473 sl811
->load
[i
] -= ep
->load
;
475 ep
->branch
= PERIODIC_SIZE
;
476 sl811
->periodic_count
--;
477 sl811_to_hcd(sl811
)->self
.bandwidth_allocated
478 -= ep
->load
/ ep
->period
;
479 if (ep
== sl811
->next_periodic
)
480 sl811
->next_periodic
= ep
->next
;
482 /* we might turn SOFs back on again for the async schedule */
483 if (sl811
->periodic_count
== 0)
488 done(struct sl811
*sl811
, struct sl811h_ep
*ep
, u8 bank
, struct pt_regs
*regs
)
492 int urbstat
= -EINPROGRESS
;
497 status
= sl811_read(sl811
, bank
+ SL11H_PKTSTATREG
);
499 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
501 /* we can safely ignore NAKs */
502 if (status
& SL11H_STATMASK_NAK
) {
503 // PACKET("...NAK_%02x qh%p\n", bank, ep);
508 /* ACK advances transfer, toggle, and maybe queue */
509 } else if (status
& SL11H_STATMASK_ACK
) {
510 struct usb_device
*udev
= urb
->dev
;
514 /* urb->iso_frame_desc is currently ignored here... */
516 ep
->nak_count
= ep
->error_count
= 0;
517 switch (ep
->nextpid
) {
519 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
520 urb
->actual_length
+= ep
->length
;
521 usb_dotoggle(udev
, ep
->epnum
, 1);
522 if (urb
->actual_length
523 == urb
->transfer_buffer_length
) {
524 if (usb_pipecontrol(urb
->pipe
))
525 ep
->nextpid
= USB_PID_ACK
;
527 /* some bulk protocols terminate OUT transfers
528 * by a short packet, using ZLPs not padding.
530 else if (ep
->length
< ep
->maxpacket
531 || !(urb
->transfer_flags
537 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
538 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
540 len
= ep
->maxpacket
- sl811_read(sl811
,
541 bank
+ SL11H_XFERCNTREG
);
542 if (len
> ep
->length
) {
544 urb
->status
= -EOVERFLOW
;
546 urb
->actual_length
+= len
;
547 sl811_read_buf(sl811
, SL811HS_PACKET_BUF(bank
== 0),
549 usb_dotoggle(udev
, ep
->epnum
, 0);
550 if (urb
->actual_length
== urb
->transfer_buffer_length
)
552 else if (len
< ep
->maxpacket
) {
553 if (urb
->transfer_flags
& URB_SHORT_NOT_OK
)
554 urbstat
= -EREMOTEIO
;
558 if (usb_pipecontrol(urb
->pipe
)
559 && (urbstat
== -EREMOTEIO
562 /* NOTE if the status stage STALLs (why?),
563 * this reports the wrong urb status.
565 spin_lock(&urb
->lock
);
566 if (urb
->status
== -EINPROGRESS
)
567 urb
->status
= urbstat
;
568 spin_unlock(&urb
->lock
);
571 ep
->nextpid
= USB_PID_ACK
;
575 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
576 if (urb
->transfer_buffer_length
== urb
->actual_length
)
577 ep
->nextpid
= USB_PID_ACK
;
578 else if (usb_pipeout(urb
->pipe
)) {
579 usb_settoggle(udev
, 0, 1, 1);
580 ep
->nextpid
= USB_PID_OUT
;
582 usb_settoggle(udev
, 0, 0, 1);
583 ep
->nextpid
= USB_PID_IN
;
587 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
592 /* STALL stops all transfers */
593 } else if (status
& SL11H_STATMASK_STALL
) {
594 PACKET("...STALL_%02x qh%p\n", bank
, ep
);
595 ep
->nak_count
= ep
->error_count
= 0;
598 /* error? retry, until "3 strikes" */
599 } else if (++ep
->error_count
>= 3) {
600 if (status
& SL11H_STATMASK_TMOUT
)
601 urbstat
= -ETIMEDOUT
;
602 else if (status
& SL11H_STATMASK_OVF
)
603 urbstat
= -EOVERFLOW
;
607 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
608 bank
, status
, ep
, urbstat
);
611 if (urb
&& (urbstat
!= -EINPROGRESS
|| urb
->status
!= -EINPROGRESS
))
612 finish_request(sl811
, ep
, urb
, regs
, urbstat
);
615 static inline u8
checkdone(struct sl811
*sl811
)
620 if (sl811
->active_a
&& time_before_eq(sl811
->jiffies_a
, jiffies
)) {
621 ctl
= sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
));
622 if (ctl
& SL11H_HCTLMASK_ARM
)
623 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
624 DBG("%s DONE_A: ctrl %02x sts %02x\n",
625 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
627 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
628 irqstat
|= SL11H_INTMASK_DONE_A
;
631 if (sl811
->active_b
&& time_before_eq(sl811
->jiffies_b
, jiffies
)) {
632 ctl
= sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
));
633 if (ctl
& SL11H_HCTLMASK_ARM
)
634 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
635 DBG("%s DONE_B: ctrl %02x sts %02x\n",
636 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
638 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
639 irqstat
|= SL11H_INTMASK_DONE_A
;
645 static irqreturn_t
sl811h_irq(struct usb_hcd
*hcd
, struct pt_regs
*regs
)
647 struct sl811
*sl811
= hcd_to_sl811(hcd
);
649 irqreturn_t ret
= IRQ_NONE
;
650 unsigned retries
= 5;
652 spin_lock(&sl811
->lock
);
655 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
) & ~SL11H_INTMASK_DP
;
657 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
658 irqstat
&= sl811
->irq_enable
;
662 /* this may no longer be necessary ... */
664 irqstat
= checkdone(sl811
);
670 /* USB packets, not necessarily handled in the order they're
671 * issued ... that's fine if they're different endpoints.
673 if (irqstat
& SL11H_INTMASK_DONE_A
) {
674 done(sl811
, sl811
->active_a
, SL811_EP_A(SL811_HOST_BUF
), regs
);
675 sl811
->active_a
= NULL
;
679 if (irqstat
& SL11H_INTMASK_DONE_B
) {
680 done(sl811
, sl811
->active_b
, SL811_EP_B(SL811_HOST_BUF
), regs
);
681 sl811
->active_b
= NULL
;
685 if (irqstat
& SL11H_INTMASK_SOFINTR
) {
688 index
= sl811
->frame
++ % (PERIODIC_SIZE
- 1);
691 /* be graceful about almost-inevitable periodic schedule
692 * overruns: continue the previous frame's transfers iff
693 * this one has nothing scheduled.
695 if (sl811
->next_periodic
) {
696 // ERR("overrun to slot %d\n", index);
697 sl811
->stat_overrun
++;
699 if (sl811
->periodic
[index
])
700 sl811
->next_periodic
= sl811
->periodic
[index
];
703 /* khubd manages debouncing and wakeup */
704 if (irqstat
& SL11H_INTMASK_INSRMV
) {
705 sl811
->stat_insrmv
++;
707 /* most stats are reset for each VBUS session */
708 sl811
->stat_wake
= 0;
712 sl811
->stat_lost
= 0;
715 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
717 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
718 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
720 /* usbcore nukes other pending transactions on disconnect */
721 if (sl811
->active_a
) {
722 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
723 finish_request(sl811
, sl811
->active_a
,
724 container_of(sl811
->active_a
725 ->hep
->urb_list
.next
,
726 struct urb
, urb_list
),
728 sl811
->active_a
= NULL
;
731 if (sl811
->active_b
) {
732 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
733 finish_request(sl811
, sl811
->active_b
,
734 container_of(sl811
->active_b
735 ->hep
->urb_list
.next
,
736 struct urb
, urb_list
),
738 sl811
->active_b
= NULL
;
742 /* port status seems weird until after reset, so
743 * force the reset and make khubd clean up later.
745 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
746 | (1 << USB_PORT_FEAT_CONNECTION
);
748 } else if (irqstat
& SL11H_INTMASK_RD
) {
749 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)) {
751 sl811
->port1
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
754 irqstat
&= ~SL11H_INTMASK_RD
;
758 if (sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
))
759 start_transfer(sl811
);
765 if (sl811
->periodic_count
== 0 && list_empty(&sl811
->async
))
767 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
769 spin_unlock(&sl811
->lock
);
774 /*-------------------------------------------------------------------------*/
776 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
777 * this driver doesn't promise that much since it's got to handle an
778 * IRQ per packet; irq handling latencies also use up that time.
780 * NOTE: the periodic schedule is a sparse tree, with the load for
781 * each branch minimized. see fig 3.5 in the OHCI spec for example.
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
= kzalloc(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 || !HC_IS_RUNNING(hcd
->state
)) {
855 INIT_LIST_HEAD(&ep
->schedule
);
858 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
859 ep
->defctrl
= SL11H_HCTLMASK_ARM
| SL11H_HCTLMASK_ENABLE
;
860 usb_settoggle(udev
, epnum
, is_out
, 0);
862 if (type
== PIPE_CONTROL
)
863 ep
->nextpid
= USB_PID_SETUP
;
865 ep
->nextpid
= USB_PID_OUT
;
867 ep
->nextpid
= USB_PID_IN
;
869 if (ep
->maxpacket
> H_MAXPACKET
) {
870 /* iso packets up to 240 bytes could work... */
871 DBG("dev %d ep%d maxpacket %d\n",
872 udev
->devnum
, epnum
, ep
->maxpacket
);
877 if (udev
->speed
== USB_SPEED_LOW
) {
878 /* send preamble for external hub? */
879 if (!(sl811
->ctrl1
& SL11H_CTL1MASK_LSPD
))
880 ep
->defctrl
|= SL11H_HCTLMASK_PREAMBLE
;
883 case PIPE_ISOCHRONOUS
:
885 if (urb
->interval
> PERIODIC_SIZE
)
886 urb
->interval
= PERIODIC_SIZE
;
887 ep
->period
= urb
->interval
;
888 ep
->branch
= PERIODIC_SIZE
;
889 if (type
== PIPE_ISOCHRONOUS
)
890 ep
->defctrl
|= SL11H_HCTLMASK_ISOCH
;
891 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
892 (type
== PIPE_ISOCHRONOUS
),
893 usb_maxpacket(udev
, pipe
, is_out
))
902 /* maybe put endpoint into schedule */
906 if (list_empty(&ep
->schedule
))
907 list_add_tail(&ep
->schedule
, &sl811
->async
);
909 case PIPE_ISOCHRONOUS
:
911 urb
->interval
= ep
->period
;
912 if (ep
->branch
< PERIODIC_SIZE
) {
913 /* NOTE: the phase is correct here, but the value
914 * needs offsetting by the transfer queue depth.
915 * All current drivers ignore start_frame, so this
916 * is unlikely to ever matter...
918 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
923 retval
= balance(sl811
, ep
->period
, ep
->load
);
928 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
931 /* sort each schedule branch by period (slow before fast)
932 * to share the faster parts of the tree without needing
933 * dummy/placeholder nodes
935 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
936 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
937 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
938 struct sl811h_ep
*here
= *prev
;
940 while (here
&& ep
!= here
) {
941 if (ep
->period
> here
->period
)
950 sl811
->load
[i
] += ep
->load
;
952 sl811
->periodic_count
++;
953 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
957 /* in case of unlink-during-submit */
958 spin_lock(&urb
->lock
);
959 if (urb
->status
!= -EINPROGRESS
) {
960 spin_unlock(&urb
->lock
);
961 finish_request(sl811
, ep
, urb
, NULL
, 0);
966 spin_unlock(&urb
->lock
);
968 start_transfer(sl811
);
969 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
971 spin_unlock_irqrestore(&sl811
->lock
, flags
);
975 static int sl811h_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
977 struct sl811
*sl811
= hcd_to_sl811(hcd
);
978 struct usb_host_endpoint
*hep
;
980 struct sl811h_ep
*ep
;
983 spin_lock_irqsave(&sl811
->lock
, flags
);
990 /* finish right away if this urb can't be active ...
991 * note that some drivers wrongly expect delays
993 if (ep
->hep
->urb_list
.next
!= &urb
->urb_list
) {
994 /* not front of queue? never active */
996 /* for active transfers, we expect an IRQ */
997 } else if (sl811
->active_a
== ep
) {
998 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
999 /* happens a lot with lowspeed?? */
1000 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
1002 SL811_EP_A(SL11H_HOSTCTLREG
)),
1004 SL811_EP_A(SL11H_PKTSTATREG
)));
1005 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1007 sl811
->active_a
= NULL
;
1011 } else if (sl811
->active_b
== ep
) {
1012 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
1013 /* happens a lot with lowspeed?? */
1014 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1016 SL811_EP_B(SL11H_HOSTCTLREG
)),
1018 SL811_EP_B(SL11H_PKTSTATREG
)));
1019 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
),
1021 sl811
->active_b
= NULL
;
1026 /* front of queue for inactive endpoint */
1030 finish_request(sl811
, ep
, urb
, NULL
, 0);
1032 VDBG("dequeue, urb %p active %s; wait4irq\n", urb
,
1033 (sl811
->active_a
== ep
) ? "A" : "B");
1037 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1042 sl811h_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
)
1044 struct sl811h_ep
*ep
= hep
->hcpriv
;
1049 /* assume we'd just wait for the irq */
1050 if (!list_empty(&hep
->urb_list
))
1052 if (!list_empty(&hep
->urb_list
))
1053 WARN("ep %p not empty?\n", ep
);
1060 sl811h_get_frame(struct usb_hcd
*hcd
)
1062 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1064 /* wrong except while periodic transfers are scheduled;
1065 * never matches the on-the-wire frame;
1066 * subject to overruns.
1068 return sl811
->frame
;
1072 /*-------------------------------------------------------------------------*/
1074 /* the virtual root hub timer IRQ checks for hub status */
1076 sl811h_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1078 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1080 unsigned long flags
;
1082 /* non-SMP HACK: use root hub timer as i/o watchdog
1083 * this seems essential when SOF IRQs aren't in use...
1085 local_irq_save(flags
);
1086 if (!timer_pending(&sl811
->timer
)) {
1087 if (sl811h_irq( /* ~0, */ hcd
, NULL
) != IRQ_NONE
)
1090 local_irq_restore(flags
);
1093 if (!(sl811
->port1
& (0xffff << 16)))
1096 /* tell khubd port 1 changed */
1102 sl811h_hub_descriptor (
1103 struct sl811
*sl811
,
1104 struct usb_hub_descriptor
*desc
1108 desc
->bDescriptorType
= 0x29;
1109 desc
->bHubContrCurrent
= 0;
1111 desc
->bNbrPorts
= 1;
1112 desc
->bDescLength
= 9;
1114 /* per-port power switching (gang of one!), or none */
1115 desc
->bPwrOn2PwrGood
= 0;
1116 if (sl811
->board
&& sl811
->board
->port_power
) {
1117 desc
->bPwrOn2PwrGood
= sl811
->board
->potpg
;
1118 if (!desc
->bPwrOn2PwrGood
)
1119 desc
->bPwrOn2PwrGood
= 10;
1124 /* no overcurrent errors detection/handling */
1127 desc
->wHubCharacteristics
= (__force __u16
)cpu_to_le16(temp
);
1129 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1130 desc
->bitmap
[0] = 0 << 1;
1131 desc
->bitmap
[1] = ~0;
1135 sl811h_timer(unsigned long _sl811
)
1137 struct sl811
*sl811
= (void *) _sl811
;
1138 unsigned long flags
;
1140 u8 signaling
= sl811
->ctrl1
& SL11H_CTL1MASK_FORCE
;
1141 const u32 mask
= (1 << USB_PORT_FEAT_CONNECTION
)
1142 | (1 << USB_PORT_FEAT_ENABLE
)
1143 | (1 << USB_PORT_FEAT_LOWSPEED
);
1145 spin_lock_irqsave(&sl811
->lock
, flags
);
1147 /* stop special signaling */
1148 sl811
->ctrl1
&= ~SL11H_CTL1MASK_FORCE
;
1149 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1152 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
);
1154 switch (signaling
) {
1155 case SL11H_CTL1MASK_SE0
:
1157 sl811
->port1
= (1 << USB_PORT_FEAT_C_RESET
)
1158 | (1 << USB_PORT_FEAT_POWER
);
1160 /* don't wrongly ack RD */
1161 if (irqstat
& SL11H_INTMASK_INSRMV
)
1162 irqstat
&= ~SL11H_INTMASK_RD
;
1164 case SL11H_CTL1MASK_K
:
1165 DBG("end resume\n");
1166 sl811
->port1
&= ~(1 << USB_PORT_FEAT_SUSPEND
);
1169 DBG("odd timer signaling: %02x\n", signaling
);
1172 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
1174 if (irqstat
& SL11H_INTMASK_RD
) {
1175 /* usbcore nukes all pending transactions on disconnect */
1176 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
))
1177 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
1178 | (1 << USB_PORT_FEAT_C_ENABLE
);
1179 sl811
->port1
&= ~mask
;
1180 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1182 sl811
->port1
|= mask
;
1183 if (irqstat
& SL11H_INTMASK_DP
)
1184 sl811
->port1
&= ~(1 << USB_PORT_FEAT_LOWSPEED
);
1185 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
| SL11H_INTMASK_RD
;
1188 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
)) {
1189 u8 ctrl2
= SL811HS_CTL2_INIT
;
1191 sl811
->irq_enable
|= SL11H_INTMASK_DONE_A
;
1193 sl811
->irq_enable
|= SL11H_INTMASK_DONE_B
;
1195 if (sl811
->port1
& (1 << USB_PORT_FEAT_LOWSPEED
)) {
1196 sl811
->ctrl1
|= SL11H_CTL1MASK_LSPD
;
1197 ctrl2
|= SL811HS_CTL2MASK_DSWAP
;
1200 /* start SOFs flowing, kickstarting with A registers */
1201 sl811
->ctrl1
|= SL11H_CTL1MASK_SOF_ENA
;
1202 sl811_write(sl811
, SL11H_SOFLOWREG
, 0xe0);
1203 sl811_write(sl811
, SL811HS_CTLREG2
, ctrl2
);
1205 /* autoincrementing */
1206 sl811_write(sl811
, SL811_EP_A(SL11H_BUFLNTHREG
), 0);
1207 writeb(SL_SOF
, sl811
->data_reg
);
1208 writeb(0, sl811
->data_reg
);
1209 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1210 SL11H_HCTLMASK_ARM
);
1212 /* khubd provides debounce delay */
1216 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1219 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
1220 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1225 struct usb_hcd
*hcd
,
1232 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1234 unsigned long flags
;
1236 spin_lock_irqsave(&sl811
->lock
, flags
);
1239 case ClearHubFeature
:
1242 case C_HUB_OVER_CURRENT
:
1243 case C_HUB_LOCAL_POWER
:
1249 case ClearPortFeature
:
1250 if (wIndex
!= 1 || wLength
!= 0)
1254 case USB_PORT_FEAT_ENABLE
:
1255 sl811
->port1
&= (1 << USB_PORT_FEAT_POWER
);
1257 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1258 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1259 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1262 case USB_PORT_FEAT_SUSPEND
:
1263 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)))
1266 /* 20 msec of resume/K signaling, other irqs blocked */
1267 DBG("start resume...\n");
1268 sl811
->irq_enable
= 0;
1269 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1271 sl811
->ctrl1
|= SL11H_CTL1MASK_K
;
1272 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1274 mod_timer(&sl811
->timer
, jiffies
1275 + msecs_to_jiffies(20));
1277 case USB_PORT_FEAT_POWER
:
1278 port_power(sl811
, 0);
1280 case USB_PORT_FEAT_C_ENABLE
:
1281 case USB_PORT_FEAT_C_SUSPEND
:
1282 case USB_PORT_FEAT_C_CONNECTION
:
1283 case USB_PORT_FEAT_C_OVER_CURRENT
:
1284 case USB_PORT_FEAT_C_RESET
:
1289 sl811
->port1
&= ~(1 << wValue
);
1291 case GetHubDescriptor
:
1292 sl811h_hub_descriptor(sl811
, (struct usb_hub_descriptor
*) buf
);
1295 *(__le32
*) buf
= cpu_to_le32(0);
1300 *(__le32
*) buf
= cpu_to_le32(sl811
->port1
);
1303 if (*(u16
*)(buf
+2)) /* only if wPortChange is interesting */
1305 DBG("GetPortStatus %08x\n", sl811
->port1
);
1307 case SetPortFeature
:
1308 if (wIndex
!= 1 || wLength
!= 0)
1311 case USB_PORT_FEAT_SUSPEND
:
1312 if (sl811
->port1
& (1 << USB_PORT_FEAT_RESET
))
1314 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
)))
1317 DBG("suspend...\n");
1318 sl811
->ctrl1
&= ~SL11H_CTL1MASK_SOF_ENA
;
1319 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1321 case USB_PORT_FEAT_POWER
:
1322 port_power(sl811
, 1);
1324 case USB_PORT_FEAT_RESET
:
1325 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
1327 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_POWER
)))
1330 /* 50 msec of reset/SE0 signaling, irqs blocked */
1331 sl811
->irq_enable
= 0;
1332 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1334 sl811
->ctrl1
= SL11H_CTL1MASK_SE0
;
1335 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1336 sl811
->port1
|= (1 << USB_PORT_FEAT_RESET
);
1337 mod_timer(&sl811
->timer
, jiffies
1338 + msecs_to_jiffies(50));
1343 sl811
->port1
|= 1 << wValue
;
1348 /* "protocol stall" on error */
1352 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1359 sl811h_bus_suspend(struct usb_hcd
*hcd
)
1362 DBG("%s\n", __FUNCTION__
);
1367 sl811h_bus_resume(struct usb_hcd
*hcd
)
1370 DBG("%s\n", __FUNCTION__
);
1376 #define sl811h_bus_suspend NULL
1377 #define sl811h_bus_resume NULL
1382 /*-------------------------------------------------------------------------*/
1384 #ifdef STUB_DEBUG_FILE
1386 static inline void create_debug_file(struct sl811
*sl811
) { }
1387 static inline void remove_debug_file(struct sl811
*sl811
) { }
1391 #include <linux/proc_fs.h>
1392 #include <linux/seq_file.h>
1394 static void dump_irq(struct seq_file
*s
, char *label
, u8 mask
)
1396 seq_printf(s
, "%s %02x%s%s%s%s%s%s\n", label
, mask
,
1397 (mask
& SL11H_INTMASK_DONE_A
) ? " done_a" : "",
1398 (mask
& SL11H_INTMASK_DONE_B
) ? " done_b" : "",
1399 (mask
& SL11H_INTMASK_SOFINTR
) ? " sof" : "",
1400 (mask
& SL11H_INTMASK_INSRMV
) ? " ins/rmv" : "",
1401 (mask
& SL11H_INTMASK_RD
) ? " rd" : "",
1402 (mask
& SL11H_INTMASK_DP
) ? " dp" : "");
1405 static int proc_sl811h_show(struct seq_file
*s
, void *unused
)
1407 struct sl811
*sl811
= s
->private;
1408 struct sl811h_ep
*ep
;
1411 seq_printf(s
, "%s\n%s version %s\nportstatus[1] = %08x\n",
1412 sl811_to_hcd(sl811
)->product_desc
,
1413 hcd_name
, DRIVER_VERSION
,
1416 seq_printf(s
, "insert/remove: %ld\n", sl811
->stat_insrmv
);
1417 seq_printf(s
, "current session: done_a %ld done_b %ld "
1418 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1419 sl811
->stat_a
, sl811
->stat_b
,
1420 sl811
->stat_wake
, sl811
->stat_sof
,
1421 sl811
->stat_overrun
, sl811
->stat_lost
);
1423 spin_lock_irq(&sl811
->lock
);
1425 if (sl811
->ctrl1
& SL11H_CTL1MASK_SUSPEND
)
1426 seq_printf(s
, "(suspended)\n\n");
1428 u8 t
= sl811_read(sl811
, SL11H_CTLREG1
);
1430 seq_printf(s
, "ctrl1 %02x%s%s%s%s\n", t
,
1431 (t
& SL11H_CTL1MASK_SOF_ENA
) ? " sofgen" : "",
1432 ({char *s
; switch (t
& SL11H_CTL1MASK_FORCE
) {
1433 case SL11H_CTL1MASK_NORMAL
: s
= ""; break;
1434 case SL11H_CTL1MASK_SE0
: s
= " se0/reset"; break;
1435 case SL11H_CTL1MASK_K
: s
= " k/resume"; break;
1436 default: s
= "j"; break;
1438 (t
& SL11H_CTL1MASK_LSPD
) ? " lowspeed" : "",
1439 (t
& SL11H_CTL1MASK_SUSPEND
) ? " suspend" : "");
1441 dump_irq(s
, "irq_enable",
1442 sl811_read(sl811
, SL11H_IRQ_ENABLE
));
1443 dump_irq(s
, "irq_status",
1444 sl811_read(sl811
, SL11H_IRQ_STATUS
));
1445 seq_printf(s
, "frame clocks remaining: %d\n",
1446 sl811_read(sl811
, SL11H_SOFTMRREG
) << 6);
1449 seq_printf(s
, "A: qh%p ctl %02x sts %02x\n", sl811
->active_a
,
1450 sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
)),
1451 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
1452 seq_printf(s
, "B: qh%p ctl %02x sts %02x\n", sl811
->active_b
,
1453 sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
)),
1454 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
1455 seq_printf(s
, "\n");
1456 list_for_each_entry (ep
, &sl811
->async
, schedule
) {
1459 seq_printf(s
, "%s%sqh%p, ep%d%s, maxpacket %d"
1461 (ep
== sl811
->active_a
) ? "(A) " : "",
1462 (ep
== sl811
->active_b
) ? "(B) " : "",
1464 ({ char *s
; switch (ep
->nextpid
) {
1465 case USB_PID_IN
: s
= "in"; break;
1466 case USB_PID_OUT
: s
= "out"; break;
1467 case USB_PID_SETUP
: s
= "setup"; break;
1468 case USB_PID_ACK
: s
= "status"; break;
1469 default: s
= "?"; break;
1472 ep
->nak_count
, ep
->error_count
);
1473 list_for_each_entry (urb
, &ep
->hep
->urb_list
, urb_list
) {
1474 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1476 urb
->transfer_buffer_length
);
1479 if (!list_empty(&sl811
->async
))
1480 seq_printf(s
, "\n");
1482 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1484 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1485 ep
= sl811
->periodic
[i
];
1488 seq_printf(s
, "%2d [%3d]:\n", i
, sl811
->load
[i
]);
1490 /* DUMB: prints shared entries multiple times */
1493 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1495 (ep
== sl811
->active_a
) ? "(A) " : "",
1496 (ep
== sl811
->active_b
) ? "(B) " : "",
1498 (ep
->udev
->speed
== USB_SPEED_FULL
)
1500 ep
->udev
->devnum
, ep
->epnum
,
1501 (ep
->epnum
== 0) ? ""
1502 : ((ep
->nextpid
== USB_PID_IN
)
1505 ep
->maxpacket
, ep
->error_count
);
1510 spin_unlock_irq(&sl811
->lock
);
1511 seq_printf(s
, "\n");
1516 static int proc_sl811h_open(struct inode
*inode
, struct file
*file
)
1518 return single_open(file
, proc_sl811h_show
, PDE(inode
)->data
);
1521 static struct file_operations proc_ops
= {
1522 .open
= proc_sl811h_open
,
1524 .llseek
= seq_lseek
,
1525 .release
= single_release
,
1528 /* expect just one sl811 per system */
1529 static const char proc_filename
[] = "driver/sl811h";
1531 static void create_debug_file(struct sl811
*sl811
)
1533 struct proc_dir_entry
*pde
;
1535 pde
= create_proc_entry(proc_filename
, 0, NULL
);
1539 pde
->proc_fops
= &proc_ops
;
1544 static void remove_debug_file(struct sl811
*sl811
)
1547 remove_proc_entry(proc_filename
, NULL
);
1552 /*-------------------------------------------------------------------------*/
1555 sl811h_stop(struct usb_hcd
*hcd
)
1557 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1558 unsigned long flags
;
1560 del_timer_sync(&hcd
->rh_timer
);
1562 spin_lock_irqsave(&sl811
->lock
, flags
);
1563 port_power(sl811
, 0);
1564 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1568 sl811h_start(struct usb_hcd
*hcd
)
1570 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1572 /* chip has been reset, VBUS power is off */
1573 hcd
->state
= HC_STATE_RUNNING
;
1576 if (!device_can_wakeup(hcd
->self
.controller
))
1577 device_init_wakeup(hcd
->self
.controller
,
1578 sl811
->board
->can_wakeup
);
1579 hcd
->power_budget
= sl811
->board
->power
* 2;
1582 /* enable power and interupts */
1583 port_power(sl811
, 1);
1588 /*-------------------------------------------------------------------------*/
1590 static struct hc_driver sl811h_hc_driver
= {
1591 .description
= hcd_name
,
1592 .hcd_priv_size
= sizeof(struct sl811
),
1595 * generic hardware linkage
1598 .flags
= HCD_USB11
| HCD_MEMORY
,
1600 /* Basic lifecycle operations */
1601 .start
= sl811h_start
,
1602 .stop
= sl811h_stop
,
1605 * managing i/o requests and associated device resources
1607 .urb_enqueue
= sl811h_urb_enqueue
,
1608 .urb_dequeue
= sl811h_urb_dequeue
,
1609 .endpoint_disable
= sl811h_endpoint_disable
,
1612 * periodic schedule support
1614 .get_frame_number
= sl811h_get_frame
,
1619 .hub_status_data
= sl811h_hub_status_data
,
1620 .hub_control
= sl811h_hub_control
,
1621 .bus_suspend
= sl811h_bus_suspend
,
1622 .bus_resume
= sl811h_bus_resume
,
1625 /*-------------------------------------------------------------------------*/
1627 static int __devexit
1628 sl811h_remove(struct platform_device
*dev
)
1630 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1631 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1632 struct resource
*res
;
1634 remove_debug_file(sl811
);
1635 usb_remove_hcd(hcd
);
1637 /* some platforms may use IORESOURCE_IO */
1638 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1640 iounmap(sl811
->data_reg
);
1642 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1644 iounmap(sl811
->addr_reg
);
1650 static int __devinit
1651 sl811h_probe(struct platform_device
*dev
)
1653 struct usb_hcd
*hcd
;
1654 struct sl811
*sl811
;
1655 struct resource
*addr
, *data
;
1657 void __iomem
*addr_reg
;
1658 void __iomem
*data_reg
;
1662 /* basic sanity checks first. board-specific init logic should
1663 * have initialized these three resources and probably board
1664 * specific platform_data. we don't probe for IRQs, and do only
1665 * minimal sanity checking.
1667 irq
= platform_get_irq(dev
, 0);
1668 if (dev
->num_resources
< 3 || irq
< 0)
1671 /* refuse to confuse usbcore */
1672 if (dev
->dev
.dma_mask
) {
1673 DBG("no we won't dma\n");
1677 /* the chip may be wired for either kind of addressing */
1678 addr
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1679 data
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1681 if (!addr
|| !data
) {
1682 addr
= platform_get_resource(dev
, IORESOURCE_IO
, 0);
1683 data
= platform_get_resource(dev
, IORESOURCE_IO
, 1);
1688 addr_reg
= (void __iomem
*) addr
->start
;
1689 data_reg
= (void __iomem
*) data
->start
;
1691 addr_reg
= ioremap(addr
->start
, 1);
1692 if (addr_reg
== NULL
) {
1697 data_reg
= ioremap(data
->start
, 1);
1698 if (data_reg
== NULL
) {
1704 /* allocate and initialize hcd */
1705 hcd
= usb_create_hcd(&sl811h_hc_driver
, &dev
->dev
, dev
->dev
.bus_id
);
1710 hcd
->rsrc_start
= addr
->start
;
1711 sl811
= hcd_to_sl811(hcd
);
1713 spin_lock_init(&sl811
->lock
);
1714 INIT_LIST_HEAD(&sl811
->async
);
1715 sl811
->board
= dev
->dev
.platform_data
;
1716 init_timer(&sl811
->timer
);
1717 sl811
->timer
.function
= sl811h_timer
;
1718 sl811
->timer
.data
= (unsigned long) sl811
;
1719 sl811
->addr_reg
= addr_reg
;
1720 sl811
->data_reg
= data_reg
;
1722 spin_lock_irq(&sl811
->lock
);
1723 port_power(sl811
, 0);
1724 spin_unlock_irq(&sl811
->lock
);
1727 tmp
= sl811_read(sl811
, SL11H_HWREVREG
);
1730 hcd
->product_desc
= "SL811HS v1.2";
1733 hcd
->product_desc
= "SL811HS v1.5";
1736 /* reject case 0, SL11S is less functional */
1737 DBG("chiprev %02x\n", tmp
);
1742 /* The chip's IRQ is level triggered, active high. A requirement
1743 * for platform device setup is to cope with things like signal
1744 * inverters (e.g. CF is active low) or working only with edge
1745 * triggers (e.g. most ARM CPUs). Initial driver stress testing
1746 * was on a system with single edge triggering, so most sorts of
1747 * triggering arrangement should work.
1749 retval
= usb_add_hcd(hcd
, irq
, SA_INTERRUPT
| SA_SHIRQ
);
1753 create_debug_file(sl811
);
1765 DBG("init error, %d\n", retval
);
1771 /* for this device there's no useful distinction between the controller
1772 * and its root hub, except that the root hub only gets direct PM calls
1773 * when CONFIG_USB_SUSPEND is enabled.
1777 sl811h_suspend(struct platform_device
*dev
, pm_message_t state
)
1779 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1780 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1783 if (state
.event
== PM_EVENT_FREEZE
)
1784 retval
= sl811h_bus_suspend(hcd
);
1785 else if (state
.event
== PM_EVENT_SUSPEND
)
1786 port_power(sl811
, 0);
1788 dev
->dev
.power
.power_state
= state
;
1793 sl811h_resume(struct platform_device
*dev
)
1795 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1796 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1798 /* with no "check to see if VBUS is still powered" board hook,
1799 * let's assume it'd only be powered to enable remote wakeup.
1801 if (dev
->dev
.power
.power_state
.event
== PM_EVENT_SUSPEND
1802 || !device_can_wakeup(&hcd
->self
.root_hub
->dev
)) {
1804 port_power(sl811
, 1);
1805 usb_root_hub_lost_power(hcd
->self
.root_hub
);
1809 dev
->dev
.power
.power_state
= PMSG_ON
;
1810 return sl811h_bus_resume(hcd
);
1815 #define sl811h_suspend NULL
1816 #define sl811h_resume NULL
1821 /* this driver is exported so sl811_cs can depend on it */
1822 struct platform_driver sl811h_driver
= {
1823 .probe
= sl811h_probe
,
1824 .remove
= __devexit_p(sl811h_remove
),
1826 .suspend
= sl811h_suspend
,
1827 .resume
= sl811h_resume
,
1829 .name
= (char *) hcd_name
,
1830 .owner
= THIS_MODULE
,
1833 EXPORT_SYMBOL(sl811h_driver
);
1835 /*-------------------------------------------------------------------------*/
1837 static int __init
sl811h_init(void)
1842 INFO("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
1843 return platform_driver_register(&sl811h_driver
);
1845 module_init(sl811h_init
);
1847 static void __exit
sl811h_cleanup(void)
1849 platform_driver_unregister(&sl811h_driver
);
1851 module_exit(sl811h_cleanup
);