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 void port_power(struct sl811
*sl811
, int is_on
)
95 struct usb_hcd
*hcd
= sl811_to_hcd(sl811
);
97 /* hub is inactive unless the port is powered */
99 if (sl811
->port1
& (1 << USB_PORT_FEAT_POWER
))
102 sl811
->port1
= (1 << USB_PORT_FEAT_POWER
);
103 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
104 hcd
->self
.controller
->power
.power_state
= PMSG_ON
;
107 sl811
->irq_enable
= 0;
108 hcd
->state
= HC_STATE_HALT
;
109 hcd
->self
.controller
->power
.power_state
= PMSG_SUSPEND
;
112 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
113 sl811_write(sl811
, SL11H_IRQ_STATUS
, ~0);
115 if (sl811
->board
&& sl811
->board
->port_power
) {
116 /* switch VBUS, at 500mA unless hub power budget gets set */
117 DBG("power %s\n", is_on
? "on" : "off");
118 sl811
->board
->port_power(hcd
->self
.controller
, is_on
);
121 /* reset as thoroughly as we can */
122 if (sl811
->board
&& sl811
->board
->reset
)
123 sl811
->board
->reset(hcd
->self
.controller
);
125 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
126 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
127 sl811_write(sl811
, SL811HS_CTLREG2
, SL811HS_CTL2_INIT
);
128 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
130 // if !is_on, put into lowpower mode now
133 /*-------------------------------------------------------------------------*/
135 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
136 * and may start I/O. Endpoint queues are scanned during completion irq
137 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
139 * Using an external DMA engine to copy a packet at a time could work,
140 * though setup/teardown costs may be too big to make it worthwhile.
143 /* SETUP starts a new control request. Devices are not allowed to
144 * STALL or NAK these; they must cancel any pending control requests.
146 static void setup_packet(
148 struct sl811h_ep
*ep
,
156 void __iomem
*data_reg
;
158 addr
= SL811HS_PACKET_BUF(bank
== 0);
159 len
= sizeof(struct usb_ctrlrequest
);
160 data_reg
= sl811
->data_reg
;
161 sl811_write_buf(sl811
, addr
, urb
->setup_packet
, len
);
163 /* autoincrementing */
164 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
165 writeb(len
, data_reg
);
166 writeb(SL_SETUP
/* | ep->epnum */, data_reg
);
167 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
169 /* always OUT/data0 */ ;
170 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
171 control
| SL11H_HCTLMASK_OUT
);
173 PACKET("SETUP qh%p\n", ep
);
176 /* STATUS finishes control requests, often after IN or OUT data packets */
177 static void status_packet(
179 struct sl811h_ep
*ep
,
186 void __iomem
*data_reg
;
188 do_out
= urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
);
189 data_reg
= sl811
->data_reg
;
191 /* autoincrementing */
192 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, 0);
194 writeb((do_out
? SL_OUT
: SL_IN
) /* | ep->epnum */, data_reg
);
195 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
197 /* always data1; sometimes IN */
198 control
|= SL11H_HCTLMASK_TOGGLE
;
200 control
|= SL11H_HCTLMASK_OUT
;
201 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
203 PACKET("STATUS%s/%s qh%p\n", ep
->nak_count
? "/retry" : "",
204 do_out
? "out" : "in", ep
);
207 /* IN packets can be used with any type of endpoint. here we just
208 * start the transfer, data from the peripheral may arrive later.
209 * urb->iso_frame_desc is currently ignored here...
211 static void in_packet(
213 struct sl811h_ep
*ep
,
221 void __iomem
*data_reg
;
223 /* avoid losing data on overflow */
225 addr
= SL811HS_PACKET_BUF(bank
== 0);
226 if (!(control
& SL11H_HCTLMASK_ISOCH
)
227 && usb_gettoggle(urb
->dev
, ep
->epnum
, 0))
228 control
|= SL11H_HCTLMASK_TOGGLE
;
229 data_reg
= sl811
->data_reg
;
231 /* autoincrementing */
232 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
233 writeb(len
, data_reg
);
234 writeb(SL_IN
| ep
->epnum
, data_reg
);
235 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
237 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
238 ep
->length
= min((int)len
,
239 urb
->transfer_buffer_length
- urb
->actual_length
);
240 PACKET("IN%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
241 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 0), ep
, len
);
244 /* OUT packets can be used with any type of endpoint.
245 * urb->iso_frame_desc is currently ignored here...
247 static void out_packet(
249 struct sl811h_ep
*ep
,
258 void __iomem
*data_reg
;
260 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
263 len
= min((int)ep
->maxpacket
,
264 urb
->transfer_buffer_length
- urb
->actual_length
);
266 if (!(control
& SL11H_HCTLMASK_ISOCH
)
267 && usb_gettoggle(urb
->dev
, ep
->epnum
, 1))
268 control
|= SL11H_HCTLMASK_TOGGLE
;
269 addr
= SL811HS_PACKET_BUF(bank
== 0);
270 data_reg
= sl811
->data_reg
;
272 sl811_write_buf(sl811
, addr
, buf
, len
);
274 /* autoincrementing */
275 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
276 writeb(len
, data_reg
);
277 writeb(SL_OUT
| ep
->epnum
, data_reg
);
278 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
280 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
281 control
| SL11H_HCTLMASK_OUT
);
283 PACKET("OUT%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
284 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 1), ep
, len
);
287 /*-------------------------------------------------------------------------*/
289 /* caller updates on-chip enables later */
291 static inline void sofirq_on(struct sl811
*sl811
)
293 if (sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
)
295 VDBG("sof irq on\n");
296 sl811
->irq_enable
|= SL11H_INTMASK_SOFINTR
;
299 static inline void sofirq_off(struct sl811
*sl811
)
301 if (!(sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
))
303 VDBG("sof irq off\n");
304 sl811
->irq_enable
&= ~SL11H_INTMASK_SOFINTR
;
307 /*-------------------------------------------------------------------------*/
309 /* pick the next endpoint for a transaction, and issue it.
310 * frames start with periodic transfers (after whatever is pending
311 * from the previous frame), and the rest of the time is async
312 * transfers, scheduled round-robin.
314 static struct sl811h_ep
*start(struct sl811
*sl811
, u8 bank
)
316 struct sl811h_ep
*ep
;
321 /* use endpoint at schedule head */
322 if (sl811
->next_periodic
) {
323 ep
= sl811
->next_periodic
;
324 sl811
->next_periodic
= ep
->next
;
326 if (sl811
->next_async
)
327 ep
= sl811
->next_async
;
328 else if (!list_empty(&sl811
->async
))
329 ep
= container_of(sl811
->async
.next
,
330 struct sl811h_ep
, schedule
);
332 /* could set up the first fullspeed periodic
333 * transfer for the next frame ...
339 if ((bank
&& sl811
->active_b
== ep
) || sl811
->active_a
== ep
)
343 if (ep
->schedule
.next
== &sl811
->async
)
344 sl811
->next_async
= NULL
;
346 sl811
->next_async
= container_of(ep
->schedule
.next
,
347 struct sl811h_ep
, schedule
);
350 if (unlikely(list_empty(&ep
->hep
->urb_list
))) {
351 DBG("empty %p queue?\n", ep
);
355 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
356 control
= ep
->defctrl
;
358 /* if this frame doesn't have enough time left to transfer this
359 * packet, wait till the next frame. too-simple algorithm...
361 fclock
= sl811_read(sl811
, SL11H_SOFTMRREG
) << 6;
362 fclock
-= 100; /* setup takes not much time */
363 if (urb
->dev
->speed
== USB_SPEED_LOW
) {
364 if (control
& SL11H_HCTLMASK_PREAMBLE
) {
365 /* also note erratum 1: some hubs won't work */
368 fclock
-= ep
->maxpacket
<< 8;
370 /* erratum 2: AFTERSOF only works for fullspeed */
373 sl811
->stat_overrun
++;
378 fclock
-= 12000 / 19; /* 19 64byte packets/msec */
381 sl811
->stat_overrun
++;
382 control
|= SL11H_HCTLMASK_AFTERSOF
;
384 /* throttle bulk/control irq noise */
385 } else if (ep
->nak_count
)
386 control
|= SL11H_HCTLMASK_AFTERSOF
;
390 switch (ep
->nextpid
) {
392 in_packet(sl811
, ep
, urb
, bank
, control
);
395 out_packet(sl811
, ep
, urb
, bank
, control
);
398 setup_packet(sl811
, ep
, urb
, bank
, control
);
400 case USB_PID_ACK
: /* for control status */
401 status_packet(sl811
, ep
, urb
, bank
, control
);
404 DBG("bad ep%p pid %02x\n", ep
, ep
->nextpid
);
410 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
412 static inline void start_transfer(struct sl811
*sl811
)
414 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
416 if (sl811
->active_a
== NULL
) {
417 sl811
->active_a
= start(sl811
, SL811_EP_A(SL811_HOST_BUF
));
418 if (sl811
->active_a
!= NULL
)
419 sl811
->jiffies_a
= jiffies
+ MIN_JIFFIES
;
422 if (sl811
->active_b
== NULL
) {
423 sl811
->active_b
= start(sl811
, SL811_EP_B(SL811_HOST_BUF
));
424 if (sl811
->active_b
!= NULL
)
425 sl811
->jiffies_b
= jiffies
+ MIN_JIFFIES
;
430 static void finish_request(
432 struct sl811h_ep
*ep
,
434 struct pt_regs
*regs
,
436 ) __releases(sl811
->lock
) __acquires(sl811
->lock
)
440 if (usb_pipecontrol(urb
->pipe
))
441 ep
->nextpid
= USB_PID_SETUP
;
443 spin_lock(&urb
->lock
);
444 if (urb
->status
== -EINPROGRESS
)
445 urb
->status
= status
;
446 spin_unlock(&urb
->lock
);
448 spin_unlock(&sl811
->lock
);
449 usb_hcd_giveback_urb(sl811_to_hcd(sl811
), urb
, regs
);
450 spin_lock(&sl811
->lock
);
452 /* leave active endpoints in the schedule */
453 if (!list_empty(&ep
->hep
->urb_list
))
456 /* async deschedule? */
457 if (!list_empty(&ep
->schedule
)) {
458 list_del_init(&ep
->schedule
);
459 if (ep
== sl811
->next_async
)
460 sl811
->next_async
= NULL
;
464 /* periodic deschedule */
465 DBG("deschedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
466 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
467 struct sl811h_ep
*temp
;
468 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
470 while (*prev
&& ((temp
= *prev
) != ep
))
474 sl811
->load
[i
] -= ep
->load
;
476 ep
->branch
= PERIODIC_SIZE
;
477 sl811
->periodic_count
--;
478 sl811_to_hcd(sl811
)->self
.bandwidth_allocated
479 -= ep
->load
/ ep
->period
;
480 if (ep
== sl811
->next_periodic
)
481 sl811
->next_periodic
= ep
->next
;
483 /* we might turn SOFs back on again for the async schedule */
484 if (sl811
->periodic_count
== 0)
489 done(struct sl811
*sl811
, struct sl811h_ep
*ep
, u8 bank
, struct pt_regs
*regs
)
493 int urbstat
= -EINPROGRESS
;
498 status
= sl811_read(sl811
, bank
+ SL11H_PKTSTATREG
);
500 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
502 /* we can safely ignore NAKs */
503 if (status
& SL11H_STATMASK_NAK
) {
504 // PACKET("...NAK_%02x qh%p\n", bank, ep);
509 /* ACK advances transfer, toggle, and maybe queue */
510 } else if (status
& SL11H_STATMASK_ACK
) {
511 struct usb_device
*udev
= urb
->dev
;
515 /* urb->iso_frame_desc is currently ignored here... */
517 ep
->nak_count
= ep
->error_count
= 0;
518 switch (ep
->nextpid
) {
520 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
521 urb
->actual_length
+= ep
->length
;
522 usb_dotoggle(udev
, ep
->epnum
, 1);
523 if (urb
->actual_length
524 == urb
->transfer_buffer_length
) {
525 if (usb_pipecontrol(urb
->pipe
))
526 ep
->nextpid
= USB_PID_ACK
;
528 /* some bulk protocols terminate OUT transfers
529 * by a short packet, using ZLPs not padding.
531 else if (ep
->length
< ep
->maxpacket
532 || !(urb
->transfer_flags
538 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
539 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
541 len
= ep
->maxpacket
- sl811_read(sl811
,
542 bank
+ SL11H_XFERCNTREG
);
543 if (len
> ep
->length
) {
545 urb
->status
= -EOVERFLOW
;
547 urb
->actual_length
+= len
;
548 sl811_read_buf(sl811
, SL811HS_PACKET_BUF(bank
== 0),
550 usb_dotoggle(udev
, ep
->epnum
, 0);
551 if (urb
->actual_length
== urb
->transfer_buffer_length
)
553 else if (len
< ep
->maxpacket
) {
554 if (urb
->transfer_flags
& URB_SHORT_NOT_OK
)
555 urbstat
= -EREMOTEIO
;
559 if (usb_pipecontrol(urb
->pipe
)
560 && (urbstat
== -EREMOTEIO
563 /* NOTE if the status stage STALLs (why?),
564 * this reports the wrong urb status.
566 spin_lock(&urb
->lock
);
567 if (urb
->status
== -EINPROGRESS
)
568 urb
->status
= urbstat
;
569 spin_unlock(&urb
->lock
);
572 ep
->nextpid
= USB_PID_ACK
;
576 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
577 if (urb
->transfer_buffer_length
== urb
->actual_length
)
578 ep
->nextpid
= USB_PID_ACK
;
579 else if (usb_pipeout(urb
->pipe
)) {
580 usb_settoggle(udev
, 0, 1, 1);
581 ep
->nextpid
= USB_PID_OUT
;
583 usb_settoggle(udev
, 0, 0, 1);
584 ep
->nextpid
= USB_PID_IN
;
588 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
593 /* STALL stops all transfers */
594 } else if (status
& SL11H_STATMASK_STALL
) {
595 PACKET("...STALL_%02x qh%p\n", bank
, ep
);
596 ep
->nak_count
= ep
->error_count
= 0;
599 /* error? retry, until "3 strikes" */
600 } else if (++ep
->error_count
>= 3) {
601 if (status
& SL11H_STATMASK_TMOUT
)
602 urbstat
= -ETIMEDOUT
;
603 else if (status
& SL11H_STATMASK_OVF
)
604 urbstat
= -EOVERFLOW
;
608 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
609 bank
, status
, ep
, urbstat
);
612 if (urb
&& (urbstat
!= -EINPROGRESS
|| urb
->status
!= -EINPROGRESS
))
613 finish_request(sl811
, ep
, urb
, regs
, urbstat
);
616 static inline u8
checkdone(struct sl811
*sl811
)
621 if (sl811
->active_a
&& time_before_eq(sl811
->jiffies_a
, jiffies
)) {
622 ctl
= sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
));
623 if (ctl
& SL11H_HCTLMASK_ARM
)
624 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
625 DBG("%s DONE_A: ctrl %02x sts %02x\n",
626 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
628 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
629 irqstat
|= SL11H_INTMASK_DONE_A
;
632 if (sl811
->active_b
&& time_before_eq(sl811
->jiffies_b
, jiffies
)) {
633 ctl
= sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
));
634 if (ctl
& SL11H_HCTLMASK_ARM
)
635 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
636 DBG("%s DONE_B: ctrl %02x sts %02x\n",
637 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
639 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
640 irqstat
|= SL11H_INTMASK_DONE_A
;
646 static irqreturn_t
sl811h_irq(struct usb_hcd
*hcd
, struct pt_regs
*regs
)
648 struct sl811
*sl811
= hcd_to_sl811(hcd
);
650 irqreturn_t ret
= IRQ_NONE
;
651 unsigned retries
= 5;
653 spin_lock(&sl811
->lock
);
656 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
) & ~SL11H_INTMASK_DP
;
658 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
659 irqstat
&= sl811
->irq_enable
;
663 /* this may no longer be necessary ... */
664 if (irqstat
== 0 && ret
== IRQ_NONE
) {
665 irqstat
= checkdone(sl811
);
666 if (irqstat
/* && irq != ~0 */ )
671 /* USB packets, not necessarily handled in the order they're
672 * issued ... that's fine if they're different endpoints.
674 if (irqstat
& SL11H_INTMASK_DONE_A
) {
675 done(sl811
, sl811
->active_a
, SL811_EP_A(SL811_HOST_BUF
), regs
);
676 sl811
->active_a
= NULL
;
680 if (irqstat
& SL11H_INTMASK_DONE_B
) {
681 done(sl811
, sl811
->active_b
, SL811_EP_B(SL811_HOST_BUF
), regs
);
682 sl811
->active_b
= NULL
;
686 if (irqstat
& SL11H_INTMASK_SOFINTR
) {
689 index
= sl811
->frame
++ % (PERIODIC_SIZE
- 1);
692 /* be graceful about almost-inevitable periodic schedule
693 * overruns: continue the previous frame's transfers iff
694 * this one has nothing scheduled.
696 if (sl811
->next_periodic
) {
697 // ERR("overrun to slot %d\n", index);
698 sl811
->stat_overrun
++;
700 if (sl811
->periodic
[index
])
701 sl811
->next_periodic
= sl811
->periodic
[index
];
704 /* khubd manages debouncing and wakeup */
705 if (irqstat
& SL11H_INTMASK_INSRMV
) {
706 sl811
->stat_insrmv
++;
708 /* most stats are reset for each VBUS session */
709 sl811
->stat_wake
= 0;
713 sl811
->stat_lost
= 0;
716 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
718 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
719 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
721 /* usbcore nukes other pending transactions on disconnect */
722 if (sl811
->active_a
) {
723 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
724 finish_request(sl811
, sl811
->active_a
,
725 container_of(sl811
->active_a
->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
->hep
->urb_list
.next
,
735 struct urb
, urb_list
),
737 sl811
->active_b
= NULL
;
741 /* port status seems weird until after reset, so
742 * force the reset and make khubd clean up later.
744 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
745 | (1 << USB_PORT_FEAT_CONNECTION
);
747 } else if (irqstat
& SL11H_INTMASK_RD
) {
748 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)) {
750 sl811
->port1
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
753 irqstat
&= ~SL11H_INTMASK_RD
;
757 if (sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
))
758 start_transfer(sl811
);
764 if (sl811
->periodic_count
== 0 && list_empty(&sl811
->async
))
766 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
768 spin_unlock(&sl811
->lock
);
773 /*-------------------------------------------------------------------------*/
775 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
776 * this driver doesn't promise that much since it's got to handle an
777 * IRQ per packet; irq handling latencies also use up that time.
779 #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
781 static int balance(struct sl811
*sl811
, u16 period
, u16 load
)
783 int i
, branch
= -ENOSPC
;
785 /* search for the least loaded schedule branch of that period
786 * which has enough bandwidth left unreserved.
788 for (i
= 0; i
< period
; i
++) {
789 if (branch
< 0 || sl811
->load
[branch
] > sl811
->load
[i
]) {
792 for (j
= i
; j
< PERIODIC_SIZE
; j
+= period
) {
793 if ((sl811
->load
[j
] + load
)
797 if (j
< PERIODIC_SIZE
)
805 /*-------------------------------------------------------------------------*/
807 static int sl811h_urb_enqueue(
809 struct usb_host_endpoint
*hep
,
813 struct sl811
*sl811
= hcd_to_sl811(hcd
);
814 struct usb_device
*udev
= urb
->dev
;
815 unsigned int pipe
= urb
->pipe
;
816 int is_out
= !usb_pipein(pipe
);
817 int type
= usb_pipetype(pipe
);
818 int epnum
= usb_pipeendpoint(pipe
);
819 struct sl811h_ep
*ep
= NULL
;
825 if (type
== PIPE_ISOCHRONOUS
)
829 /* avoid all allocations within spinlocks */
831 ep
= kcalloc(1, sizeof *ep
, mem_flags
);
833 spin_lock_irqsave(&sl811
->lock
, flags
);
835 /* don't submit to a dead or disabled port */
836 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
))
837 || !HC_IS_RUNNING(hcd
->state
)) {
850 INIT_LIST_HEAD(&ep
->schedule
);
851 ep
->udev
= usb_get_dev(udev
);
853 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
854 ep
->defctrl
= SL11H_HCTLMASK_ARM
| SL11H_HCTLMASK_ENABLE
;
855 usb_settoggle(udev
, epnum
, is_out
, 0);
857 if (type
== PIPE_CONTROL
)
858 ep
->nextpid
= USB_PID_SETUP
;
860 ep
->nextpid
= USB_PID_OUT
;
862 ep
->nextpid
= USB_PID_IN
;
864 if (ep
->maxpacket
> H_MAXPACKET
) {
865 /* iso packets up to 240 bytes could work... */
866 DBG("dev %d ep%d maxpacket %d\n",
867 udev
->devnum
, epnum
, ep
->maxpacket
);
872 if (udev
->speed
== USB_SPEED_LOW
) {
873 /* send preamble for external hub? */
874 if (!(sl811
->ctrl1
& SL11H_CTL1MASK_LSPD
))
875 ep
->defctrl
|= SL11H_HCTLMASK_PREAMBLE
;
878 case PIPE_ISOCHRONOUS
:
880 if (urb
->interval
> PERIODIC_SIZE
)
881 urb
->interval
= PERIODIC_SIZE
;
882 ep
->period
= urb
->interval
;
883 ep
->branch
= PERIODIC_SIZE
;
884 if (type
== PIPE_ISOCHRONOUS
)
885 ep
->defctrl
|= SL11H_HCTLMASK_ISOCH
;
886 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
887 (type
== PIPE_ISOCHRONOUS
),
888 usb_maxpacket(udev
, pipe
, is_out
))
896 /* maybe put endpoint into schedule */
900 if (list_empty(&ep
->schedule
))
901 list_add_tail(&ep
->schedule
, &sl811
->async
);
903 case PIPE_ISOCHRONOUS
:
905 urb
->interval
= ep
->period
;
906 if (ep
->branch
< PERIODIC_SIZE
)
909 retval
= balance(sl811
, ep
->period
, ep
->load
);
914 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
917 /* sort each schedule branch by period (slow before fast)
918 * to share the faster parts of the tree without needing
919 * dummy/placeholder nodes
921 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
922 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
923 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
924 struct sl811h_ep
*here
= *prev
;
926 while (here
&& ep
!= here
) {
927 if (ep
->period
> here
->period
)
936 sl811
->load
[i
] += ep
->load
;
938 sl811
->periodic_count
++;
939 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
943 /* in case of unlink-during-submit */
944 spin_lock(&urb
->lock
);
945 if (urb
->status
!= -EINPROGRESS
) {
946 spin_unlock(&urb
->lock
);
947 finish_request(sl811
, ep
, urb
, NULL
, 0);
952 spin_unlock(&urb
->lock
);
954 start_transfer(sl811
);
955 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
957 spin_unlock_irqrestore(&sl811
->lock
, flags
);
961 static int sl811h_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
963 struct sl811
*sl811
= hcd_to_sl811(hcd
);
964 struct usb_host_endpoint
*hep
= urb
->hcpriv
;
966 struct sl811h_ep
*ep
;
972 spin_lock_irqsave(&sl811
->lock
, flags
);
975 /* finish right away if this urb can't be active ...
976 * note that some drivers wrongly expect delays
978 if (ep
->hep
->urb_list
.next
!= &urb
->urb_list
) {
979 /* not front of queue? never active */
981 /* for active transfers, we expect an IRQ */
982 } else if (sl811
->active_a
== ep
) {
983 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
984 /* happens a lot with lowspeed?? */
985 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
987 SL811_EP_A(SL11H_HOSTCTLREG
)),
989 SL811_EP_A(SL11H_PKTSTATREG
)));
990 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
992 sl811
->active_a
= NULL
;
996 } else if (sl811
->active_b
== ep
) {
997 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
998 /* happens a lot with lowspeed?? */
999 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1001 SL811_EP_B(SL11H_HOSTCTLREG
)),
1003 SL811_EP_B(SL11H_PKTSTATREG
)));
1004 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
),
1006 sl811
->active_b
= NULL
;
1011 /* front of queue for inactive endpoint */
1015 finish_request(sl811
, ep
, urb
, NULL
, 0);
1017 VDBG("dequeue, urb %p active %s; wait4irq\n", urb
,
1018 (sl811
->active_a
== ep
) ? "A" : "B");
1021 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1026 sl811h_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
)
1028 struct sl811h_ep
*ep
= hep
->hcpriv
;
1033 /* assume we'd just wait for the irq */
1034 if (!list_empty(&hep
->urb_list
))
1036 if (!list_empty(&hep
->urb_list
))
1037 WARN("ep %p not empty?\n", ep
);
1039 usb_put_dev(ep
->udev
);
1045 sl811h_get_frame(struct usb_hcd
*hcd
)
1047 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1049 /* wrong except while periodic transfers are scheduled;
1050 * never matches the on-the-wire frame;
1051 * subject to overruns.
1053 return sl811
->frame
;
1057 /*-------------------------------------------------------------------------*/
1059 /* the virtual root hub timer IRQ checks for hub status */
1061 sl811h_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1063 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1065 unsigned long flags
;
1067 /* non-SMP HACK: use root hub timer as i/o watchdog
1068 * this seems essential when SOF IRQs aren't in use...
1070 local_irq_save(flags
);
1071 if (!timer_pending(&sl811
->timer
)) {
1072 if (sl811h_irq( /* ~0, */ hcd
, NULL
) != IRQ_NONE
)
1075 local_irq_restore(flags
);
1078 if (!(sl811
->port1
& (0xffff << 16)))
1081 /* tell khubd port 1 changed */
1087 sl811h_hub_descriptor (
1088 struct sl811
*sl811
,
1089 struct usb_hub_descriptor
*desc
1093 desc
->bDescriptorType
= 0x29;
1094 desc
->bHubContrCurrent
= 0;
1096 desc
->bNbrPorts
= 1;
1097 desc
->bDescLength
= 9;
1099 /* per-port power switching (gang of one!), or none */
1100 desc
->bPwrOn2PwrGood
= 0;
1101 if (sl811
->board
&& sl811
->board
->port_power
) {
1102 desc
->bPwrOn2PwrGood
= sl811
->board
->potpg
;
1103 if (!desc
->bPwrOn2PwrGood
)
1104 desc
->bPwrOn2PwrGood
= 10;
1109 /* no overcurrent errors detection/handling */
1112 desc
->wHubCharacteristics
= (__force __u16
)cpu_to_le16(temp
);
1114 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1115 desc
->bitmap
[0] = 1 << 1;
1116 desc
->bitmap
[1] = ~0;
1120 sl811h_timer(unsigned long _sl811
)
1122 struct sl811
*sl811
= (void *) _sl811
;
1123 unsigned long flags
;
1125 u8 signaling
= sl811
->ctrl1
& SL11H_CTL1MASK_FORCE
;
1126 const u32 mask
= (1 << USB_PORT_FEAT_CONNECTION
)
1127 | (1 << USB_PORT_FEAT_ENABLE
)
1128 | (1 << USB_PORT_FEAT_LOWSPEED
);
1130 spin_lock_irqsave(&sl811
->lock
, flags
);
1132 /* stop special signaling */
1133 sl811
->ctrl1
&= ~SL11H_CTL1MASK_FORCE
;
1134 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1137 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
);
1139 switch (signaling
) {
1140 case SL11H_CTL1MASK_SE0
:
1142 sl811
->port1
= (1 << USB_PORT_FEAT_C_RESET
)
1143 | (1 << USB_PORT_FEAT_POWER
);
1145 /* don't wrongly ack RD */
1146 if (irqstat
& SL11H_INTMASK_INSRMV
)
1147 irqstat
&= ~SL11H_INTMASK_RD
;
1149 case SL11H_CTL1MASK_K
:
1150 DBG("end resume\n");
1151 sl811
->port1
&= ~(1 << USB_PORT_FEAT_SUSPEND
);
1154 DBG("odd timer signaling: %02x\n", signaling
);
1157 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
1159 if (irqstat
& SL11H_INTMASK_RD
) {
1160 /* usbcore nukes all pending transactions on disconnect */
1161 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
))
1162 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
1163 | (1 << USB_PORT_FEAT_C_ENABLE
);
1164 sl811
->port1
&= ~mask
;
1165 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1167 sl811
->port1
|= mask
;
1168 if (irqstat
& SL11H_INTMASK_DP
)
1169 sl811
->port1
&= ~(1 << USB_PORT_FEAT_LOWSPEED
);
1170 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
| SL11H_INTMASK_RD
;
1173 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
)) {
1174 u8 ctrl2
= SL811HS_CTL2_INIT
;
1176 sl811
->irq_enable
|= SL11H_INTMASK_DONE_A
;
1178 sl811
->irq_enable
|= SL11H_INTMASK_DONE_B
;
1180 if (sl811
->port1
& (1 << USB_PORT_FEAT_LOWSPEED
)) {
1181 sl811
->ctrl1
|= SL11H_CTL1MASK_LSPD
;
1182 ctrl2
|= SL811HS_CTL2MASK_DSWAP
;
1185 /* start SOFs flowing, kickstarting with A registers */
1186 sl811
->ctrl1
|= SL11H_CTL1MASK_SOF_ENA
;
1187 sl811_write(sl811
, SL11H_SOFLOWREG
, 0xe0);
1188 sl811_write(sl811
, SL811HS_CTLREG2
, ctrl2
);
1190 /* autoincrementing */
1191 sl811_write(sl811
, SL811_EP_A(SL11H_BUFLNTHREG
), 0);
1192 writeb(SL_SOF
, sl811
->data_reg
);
1193 writeb(0, sl811
->data_reg
);
1194 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1195 SL11H_HCTLMASK_ARM
);
1197 /* khubd provides debounce delay */
1201 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1204 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
1205 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1210 struct usb_hcd
*hcd
,
1217 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1219 unsigned long flags
;
1221 spin_lock_irqsave(&sl811
->lock
, flags
);
1224 case ClearHubFeature
:
1227 case C_HUB_OVER_CURRENT
:
1228 case C_HUB_LOCAL_POWER
:
1234 case ClearPortFeature
:
1235 if (wIndex
!= 1 || wLength
!= 0)
1239 case USB_PORT_FEAT_ENABLE
:
1240 sl811
->port1
&= (1 << USB_PORT_FEAT_POWER
);
1242 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1243 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1244 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1247 case USB_PORT_FEAT_SUSPEND
:
1248 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)))
1251 /* 20 msec of resume/K signaling, other irqs blocked */
1252 DBG("start resume...\n");
1253 sl811
->irq_enable
= 0;
1254 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1256 sl811
->ctrl1
|= SL11H_CTL1MASK_K
;
1257 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1259 mod_timer(&sl811
->timer
, jiffies
1260 + msecs_to_jiffies(20));
1262 case USB_PORT_FEAT_POWER
:
1263 port_power(sl811
, 0);
1265 case USB_PORT_FEAT_C_ENABLE
:
1266 case USB_PORT_FEAT_C_SUSPEND
:
1267 case USB_PORT_FEAT_C_CONNECTION
:
1268 case USB_PORT_FEAT_C_OVER_CURRENT
:
1269 case USB_PORT_FEAT_C_RESET
:
1274 sl811
->port1
&= ~(1 << wValue
);
1276 case GetHubDescriptor
:
1277 sl811h_hub_descriptor(sl811
, (struct usb_hub_descriptor
*) buf
);
1280 *(__le32
*) buf
= cpu_to_le32(0);
1285 *(__le32
*) buf
= cpu_to_le32(sl811
->port1
);
1288 if (*(u16
*)(buf
+2)) /* only if wPortChange is interesting */
1290 DBG("GetPortStatus %08x\n", sl811
->port1
);
1292 case SetPortFeature
:
1293 if (wIndex
!= 1 || wLength
!= 0)
1296 case USB_PORT_FEAT_SUSPEND
:
1297 if (sl811
->port1
& (1 << USB_PORT_FEAT_RESET
))
1299 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
)))
1302 DBG("suspend...\n");
1303 sl811
->ctrl1
&= ~SL11H_CTL1MASK_SOF_ENA
;
1304 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1306 case USB_PORT_FEAT_POWER
:
1307 port_power(sl811
, 1);
1309 case USB_PORT_FEAT_RESET
:
1310 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
1312 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_POWER
)))
1315 /* 50 msec of reset/SE0 signaling, irqs blocked */
1316 sl811
->irq_enable
= 0;
1317 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1319 sl811
->ctrl1
= SL11H_CTL1MASK_SE0
;
1320 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1321 sl811
->port1
|= (1 << USB_PORT_FEAT_RESET
);
1322 mod_timer(&sl811
->timer
, jiffies
1323 + msecs_to_jiffies(50));
1328 sl811
->port1
|= 1 << wValue
;
1333 /* "protocol stall" on error */
1337 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1344 sl811h_hub_suspend(struct usb_hcd
*hcd
)
1347 DBG("%s\n", __FUNCTION__
);
1352 sl811h_hub_resume(struct usb_hcd
*hcd
)
1355 DBG("%s\n", __FUNCTION__
);
1361 #define sl811h_hub_suspend NULL
1362 #define sl811h_hub_resume NULL
1367 /*-------------------------------------------------------------------------*/
1369 #ifdef STUB_DEBUG_FILE
1371 static inline void create_debug_file(struct sl811
*sl811
) { }
1372 static inline void remove_debug_file(struct sl811
*sl811
) { }
1376 #include <linux/proc_fs.h>
1377 #include <linux/seq_file.h>
1379 static void dump_irq(struct seq_file
*s
, char *label
, u8 mask
)
1381 seq_printf(s
, "%s %02x%s%s%s%s%s%s\n", label
, mask
,
1382 (mask
& SL11H_INTMASK_DONE_A
) ? " done_a" : "",
1383 (mask
& SL11H_INTMASK_DONE_B
) ? " done_b" : "",
1384 (mask
& SL11H_INTMASK_SOFINTR
) ? " sof" : "",
1385 (mask
& SL11H_INTMASK_INSRMV
) ? " ins/rmv" : "",
1386 (mask
& SL11H_INTMASK_RD
) ? " rd" : "",
1387 (mask
& SL11H_INTMASK_DP
) ? " dp" : "");
1390 static int proc_sl811h_show(struct seq_file
*s
, void *unused
)
1392 struct sl811
*sl811
= s
->private;
1393 struct sl811h_ep
*ep
;
1396 seq_printf(s
, "%s\n%s version %s\nportstatus[1] = %08x\n",
1397 sl811_to_hcd(sl811
)->product_desc
,
1398 hcd_name
, DRIVER_VERSION
,
1401 seq_printf(s
, "insert/remove: %ld\n", sl811
->stat_insrmv
);
1402 seq_printf(s
, "current session: done_a %ld done_b %ld "
1403 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1404 sl811
->stat_a
, sl811
->stat_b
,
1405 sl811
->stat_wake
, sl811
->stat_sof
,
1406 sl811
->stat_overrun
, sl811
->stat_lost
);
1408 spin_lock_irq(&sl811
->lock
);
1410 if (sl811
->ctrl1
& SL11H_CTL1MASK_SUSPEND
)
1411 seq_printf(s
, "(suspended)\n\n");
1413 u8 t
= sl811_read(sl811
, SL11H_CTLREG1
);
1415 seq_printf(s
, "ctrl1 %02x%s%s%s%s\n", t
,
1416 (t
& SL11H_CTL1MASK_SOF_ENA
) ? " sofgen" : "",
1417 ({char *s
; switch (t
& SL11H_CTL1MASK_FORCE
) {
1418 case SL11H_CTL1MASK_NORMAL
: s
= ""; break;
1419 case SL11H_CTL1MASK_SE0
: s
= " se0/reset"; break;
1420 case SL11H_CTL1MASK_K
: s
= " k/resume"; break;
1421 default: s
= "j"; break;
1423 (t
& SL11H_CTL1MASK_LSPD
) ? " lowspeed" : "",
1424 (t
& SL11H_CTL1MASK_SUSPEND
) ? " suspend" : "");
1426 dump_irq(s
, "irq_enable",
1427 sl811_read(sl811
, SL11H_IRQ_ENABLE
));
1428 dump_irq(s
, "irq_status",
1429 sl811_read(sl811
, SL11H_IRQ_STATUS
));
1430 seq_printf(s
, "frame clocks remaining: %d\n",
1431 sl811_read(sl811
, SL11H_SOFTMRREG
) << 6);
1434 seq_printf(s
, "A: qh%p ctl %02x sts %02x\n", sl811
->active_a
,
1435 sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
)),
1436 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
1437 seq_printf(s
, "B: qh%p ctl %02x sts %02x\n", sl811
->active_b
,
1438 sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
)),
1439 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
1440 seq_printf(s
, "\n");
1441 list_for_each_entry (ep
, &sl811
->async
, schedule
) {
1444 seq_printf(s
, "%s%sqh%p, ep%d%s, maxpacket %d"
1446 (ep
== sl811
->active_a
) ? "(A) " : "",
1447 (ep
== sl811
->active_b
) ? "(B) " : "",
1449 ({ char *s
; switch (ep
->nextpid
) {
1450 case USB_PID_IN
: s
= "in"; break;
1451 case USB_PID_OUT
: s
= "out"; break;
1452 case USB_PID_SETUP
: s
= "setup"; break;
1453 case USB_PID_ACK
: s
= "status"; break;
1454 default: s
= "?"; break;
1457 ep
->nak_count
, ep
->error_count
);
1458 list_for_each_entry (urb
, &ep
->hep
->urb_list
, urb_list
) {
1459 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1461 urb
->transfer_buffer_length
);
1464 if (!list_empty(&sl811
->async
))
1465 seq_printf(s
, "\n");
1467 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1469 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1470 ep
= sl811
->periodic
[i
];
1473 seq_printf(s
, "%2d [%3d]:\n", i
, sl811
->load
[i
]);
1475 /* DUMB: prints shared entries multiple times */
1478 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1480 (ep
== sl811
->active_a
) ? "(A) " : "",
1481 (ep
== sl811
->active_b
) ? "(B) " : "",
1483 (ep
->udev
->speed
== USB_SPEED_FULL
)
1485 ep
->udev
->devnum
, ep
->epnum
,
1486 (ep
->epnum
== 0) ? ""
1487 : ((ep
->nextpid
== USB_PID_IN
)
1490 ep
->maxpacket
, ep
->error_count
);
1495 spin_unlock_irq(&sl811
->lock
);
1496 seq_printf(s
, "\n");
1501 static int proc_sl811h_open(struct inode
*inode
, struct file
*file
)
1503 return single_open(file
, proc_sl811h_show
, PDE(inode
)->data
);
1506 static struct file_operations proc_ops
= {
1507 .open
= proc_sl811h_open
,
1509 .llseek
= seq_lseek
,
1510 .release
= single_release
,
1513 /* expect just one sl811 per system */
1514 static const char proc_filename
[] = "driver/sl811h";
1516 static void create_debug_file(struct sl811
*sl811
)
1518 struct proc_dir_entry
*pde
;
1520 pde
= create_proc_entry(proc_filename
, 0, NULL
);
1524 pde
->proc_fops
= &proc_ops
;
1529 static void remove_debug_file(struct sl811
*sl811
)
1532 remove_proc_entry(proc_filename
, NULL
);
1537 /*-------------------------------------------------------------------------*/
1540 sl811h_stop(struct usb_hcd
*hcd
)
1542 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1543 unsigned long flags
;
1545 del_timer_sync(&hcd
->rh_timer
);
1547 spin_lock_irqsave(&sl811
->lock
, flags
);
1548 port_power(sl811
, 0);
1549 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1553 sl811h_start(struct usb_hcd
*hcd
)
1555 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1556 struct usb_device
*udev
;
1558 /* chip has been reset, VBUS power is off */
1560 udev
= usb_alloc_dev(NULL
, &hcd
->self
, 0);
1564 udev
->speed
= USB_SPEED_FULL
;
1565 hcd
->state
= HC_STATE_RUNNING
;
1568 hcd
->can_wakeup
= sl811
->board
->can_wakeup
;
1570 if (usb_hcd_register_root_hub(udev
, hcd
) != 0) {
1576 if (sl811
->board
&& sl811
->board
->power
)
1577 hub_set_power_budget(udev
, sl811
->board
->power
* 2);
1582 /*-------------------------------------------------------------------------*/
1584 static struct hc_driver sl811h_hc_driver
= {
1585 .description
= hcd_name
,
1586 .hcd_priv_size
= sizeof(struct sl811
),
1589 * generic hardware linkage
1592 .flags
= HCD_USB11
| HCD_MEMORY
,
1594 /* Basic lifecycle operations */
1595 .start
= sl811h_start
,
1596 .stop
= sl811h_stop
,
1599 * managing i/o requests and associated device resources
1601 .urb_enqueue
= sl811h_urb_enqueue
,
1602 .urb_dequeue
= sl811h_urb_dequeue
,
1603 .endpoint_disable
= sl811h_endpoint_disable
,
1606 * periodic schedule support
1608 .get_frame_number
= sl811h_get_frame
,
1613 .hub_status_data
= sl811h_hub_status_data
,
1614 .hub_control
= sl811h_hub_control
,
1615 .hub_suspend
= sl811h_hub_suspend
,
1616 .hub_resume
= sl811h_hub_resume
,
1619 /*-------------------------------------------------------------------------*/
1621 static int __init_or_module
1622 sl811h_remove(struct device
*dev
)
1624 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1625 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1626 struct platform_device
*pdev
;
1627 struct resource
*res
;
1629 pdev
= container_of(dev
, struct platform_device
, dev
);
1631 remove_debug_file(sl811
);
1632 usb_remove_hcd(hcd
);
1634 iounmap(sl811
->data_reg
);
1635 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1636 release_mem_region(res
->start
, 1);
1638 iounmap(sl811
->addr_reg
);
1639 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1640 release_mem_region(res
->start
, 1);
1646 #define resource_len(r) (((r)->end - (r)->start) + 1)
1649 sl811h_probe(struct device
*dev
)
1651 struct usb_hcd
*hcd
;
1652 struct sl811
*sl811
;
1653 struct platform_device
*pdev
;
1654 struct resource
*addr
, *data
;
1656 void __iomem
*addr_reg
;
1657 void __iomem
*data_reg
;
1661 /* basic sanity checks first. board-specific init logic should
1662 * have initialized these three resources and probably board
1663 * specific platform_data. we don't probe for IRQs, and do only
1664 * minimal sanity checking.
1666 pdev
= container_of(dev
, struct platform_device
, dev
);
1667 if (pdev
->num_resources
< 3)
1670 addr
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1671 data
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
1672 irq
= platform_get_irq(pdev
, 0);
1673 if (!addr
|| !data
|| irq
< 0)
1676 /* refuse to confuse usbcore */
1677 if (dev
->dma_mask
) {
1678 DBG("no we won't dma\n");
1682 if (!request_mem_region(addr
->start
, 1, hcd_name
)) {
1686 addr_reg
= ioremap(addr
->start
, resource_len(addr
));
1687 if (addr_reg
== NULL
) {
1692 if (!request_mem_region(data
->start
, 1, hcd_name
)) {
1696 data_reg
= ioremap(data
->start
, resource_len(addr
));
1697 if (data_reg
== NULL
) {
1702 /* allocate and initialize hcd */
1703 hcd
= usb_create_hcd(&sl811h_hc_driver
, dev
, dev
->bus_id
);
1708 hcd
->rsrc_start
= addr
->start
;
1709 sl811
= hcd_to_sl811(hcd
);
1711 spin_lock_init(&sl811
->lock
);
1712 INIT_LIST_HEAD(&sl811
->async
);
1713 sl811
->board
= dev
->platform_data
;
1714 init_timer(&sl811
->timer
);
1715 sl811
->timer
.function
= sl811h_timer
;
1716 sl811
->timer
.data
= (unsigned long) sl811
;
1717 sl811
->addr_reg
= addr_reg
;
1718 sl811
->data_reg
= data_reg
;
1720 spin_lock_irq(&sl811
->lock
);
1721 port_power(sl811
, 0);
1722 spin_unlock_irq(&sl811
->lock
);
1725 tmp
= sl811_read(sl811
, SL11H_HWREVREG
);
1728 hcd
->product_desc
= "SL811HS v1.2";
1731 hcd
->product_desc
= "SL811HS v1.5";
1734 /* reject case 0, SL11S is less functional */
1735 DBG("chiprev %02x\n", tmp
);
1740 /* sl811s would need a different handler for this irq */
1742 /* Cypress docs say the IRQ is IRQT_HIGH ... */
1743 set_irq_type(irq
, IRQT_RISING
);
1745 retval
= usb_add_hcd(hcd
, irq
, SA_INTERRUPT
);
1749 create_debug_file(sl811
);
1757 release_mem_region(data
->start
, 1);
1761 release_mem_region(addr
->start
, 1);
1763 DBG("init error, %d\n", retval
);
1769 /* for this device there's no useful distinction between the controller
1770 * and its root hub, except that the root hub only gets direct PM calls
1771 * when CONFIG_USB_SUSPEND is enabled.
1775 sl811h_suspend(struct device
*dev
, pm_message_t state
, u32 phase
)
1777 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1778 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1781 if (phase
!= SUSPEND_POWER_DOWN
)
1784 if (state
<= PM_SUSPEND_MEM
)
1785 retval
= sl811h_hub_suspend(hcd
);
1787 port_power(sl811
, 0);
1789 dev
->power
.power_state
= state
;
1794 sl811h_resume(struct device
*dev
, u32 phase
)
1796 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
1797 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1799 if (phase
!= RESUME_POWER_ON
)
1802 /* with no "check to see if VBUS is still powered" board hook,
1803 * let's assume it'd only be powered to enable remote wakeup.
1805 if (dev
->power
.power_state
> PM_SUSPEND_MEM
1806 || !hcd
->can_wakeup
) {
1808 port_power(sl811
, 1);
1812 dev
->power
.power_state
= PMSG_ON
;
1813 return sl811h_hub_resume(hcd
);
1818 #define sl811h_suspend NULL
1819 #define sl811h_resume NULL
1824 static struct device_driver sl811h_driver
= {
1825 .name
= (char *) hcd_name
,
1826 .bus
= &platform_bus_type
,
1828 .probe
= sl811h_probe
,
1829 .remove
= sl811h_remove
,
1831 .suspend
= sl811h_suspend
,
1832 .resume
= sl811h_resume
,
1835 /*-------------------------------------------------------------------------*/
1837 static int __init
sl811h_init(void)
1842 INFO("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
1843 return driver_register(&sl811h_driver
);
1845 module_init(sl811h_init
);
1847 static void __exit
sl811h_cleanup(void)
1849 driver_unregister(&sl811h_driver
);
1851 module_exit(sl811h_cleanup
);