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/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/kernel.h>
37 #include <linux/delay.h>
38 #include <linux/ioport.h>
39 #include <linux/sched.h>
40 #include <linux/slab.h>
41 #include <linux/errno.h>
42 #include <linux/init.h>
43 #include <linux/timer.h>
44 #include <linux/list.h>
45 #include <linux/interrupt.h>
46 #include <linux/usb.h>
47 #include <linux/usb/sl811.h>
48 #include <linux/platform_device.h>
52 #include <asm/system.h>
53 #include <asm/byteorder.h>
55 #include "../core/hcd.h"
59 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
60 MODULE_LICENSE("GPL");
62 #define DRIVER_VERSION "19 May 2005"
66 # define STUB_DEBUG_FILE
69 /* for now, use only one transfer register bank */
72 /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
73 * that just queued one ISO frame per URB then iso transfers "should" work
74 * using the normal urb status fields.
81 static const char hcd_name
[] = "sl811-hcd";
83 /*-------------------------------------------------------------------------*/
85 static void port_power(struct sl811
*sl811
, int is_on
)
87 struct usb_hcd
*hcd
= sl811_to_hcd(sl811
);
89 /* hub is inactive unless the port is powered */
91 if (sl811
->port1
& (1 << USB_PORT_FEAT_POWER
))
94 sl811
->port1
= (1 << USB_PORT_FEAT_POWER
);
95 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
98 sl811
->irq_enable
= 0;
99 hcd
->state
= HC_STATE_HALT
;
102 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
103 sl811_write(sl811
, SL11H_IRQ_STATUS
, ~0);
105 if (sl811
->board
&& sl811
->board
->port_power
) {
106 /* switch VBUS, at 500mA unless hub power budget gets set */
107 DBG("power %s\n", is_on
? "on" : "off");
108 sl811
->board
->port_power(hcd
->self
.controller
, is_on
);
111 /* reset as thoroughly as we can */
112 if (sl811
->board
&& sl811
->board
->reset
)
113 sl811
->board
->reset(hcd
->self
.controller
);
115 sl811_write(sl811
, SL11H_CTLREG1
, SL11H_CTL1MASK_SE0
);
119 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
120 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
121 sl811_write(sl811
, SL811HS_CTLREG2
, SL811HS_CTL2_INIT
);
122 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
124 // if !is_on, put into lowpower mode now
127 /*-------------------------------------------------------------------------*/
129 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
130 * and may start I/O. Endpoint queues are scanned during completion irq
131 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
133 * Using an external DMA engine to copy a packet at a time could work,
134 * though setup/teardown costs may be too big to make it worthwhile.
137 /* SETUP starts a new control request. Devices are not allowed to
138 * STALL or NAK these; they must cancel any pending control requests.
140 static void setup_packet(
142 struct sl811h_ep
*ep
,
150 void __iomem
*data_reg
;
152 addr
= SL811HS_PACKET_BUF(bank
== 0);
153 len
= sizeof(struct usb_ctrlrequest
);
154 data_reg
= sl811
->data_reg
;
155 sl811_write_buf(sl811
, addr
, urb
->setup_packet
, len
);
157 /* autoincrementing */
158 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
159 writeb(len
, data_reg
);
160 writeb(SL_SETUP
/* | ep->epnum */, data_reg
);
161 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
163 /* always OUT/data0 */ ;
164 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
165 control
| SL11H_HCTLMASK_OUT
);
167 PACKET("SETUP qh%p\n", ep
);
170 /* STATUS finishes control requests, often after IN or OUT data packets */
171 static void status_packet(
173 struct sl811h_ep
*ep
,
180 void __iomem
*data_reg
;
182 do_out
= urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
);
183 data_reg
= sl811
->data_reg
;
185 /* autoincrementing */
186 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, 0);
188 writeb((do_out
? SL_OUT
: SL_IN
) /* | ep->epnum */, data_reg
);
189 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
191 /* always data1; sometimes IN */
192 control
|= SL11H_HCTLMASK_TOGGLE
;
194 control
|= SL11H_HCTLMASK_OUT
;
195 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
197 PACKET("STATUS%s/%s qh%p\n", ep
->nak_count
? "/retry" : "",
198 do_out
? "out" : "in", ep
);
201 /* IN packets can be used with any type of endpoint. here we just
202 * start the transfer, data from the peripheral may arrive later.
203 * urb->iso_frame_desc is currently ignored here...
205 static void in_packet(
207 struct sl811h_ep
*ep
,
215 void __iomem
*data_reg
;
217 /* avoid losing data on overflow */
219 addr
= SL811HS_PACKET_BUF(bank
== 0);
220 if (!(control
& SL11H_HCTLMASK_ISOCH
)
221 && usb_gettoggle(urb
->dev
, ep
->epnum
, 0))
222 control
|= SL11H_HCTLMASK_TOGGLE
;
223 data_reg
= sl811
->data_reg
;
225 /* autoincrementing */
226 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
227 writeb(len
, data_reg
);
228 writeb(SL_IN
| ep
->epnum
, data_reg
);
229 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
231 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
232 ep
->length
= min_t(u32
, len
,
233 urb
->transfer_buffer_length
- urb
->actual_length
);
234 PACKET("IN%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
235 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 0), ep
, len
);
238 /* OUT packets can be used with any type of endpoint.
239 * urb->iso_frame_desc is currently ignored here...
241 static void out_packet(
243 struct sl811h_ep
*ep
,
252 void __iomem
*data_reg
;
254 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
257 len
= min_t(u32
, ep
->maxpacket
,
258 urb
->transfer_buffer_length
- urb
->actual_length
);
260 if (!(control
& SL11H_HCTLMASK_ISOCH
)
261 && usb_gettoggle(urb
->dev
, ep
->epnum
, 1))
262 control
|= SL11H_HCTLMASK_TOGGLE
;
263 addr
= SL811HS_PACKET_BUF(bank
== 0);
264 data_reg
= sl811
->data_reg
;
266 sl811_write_buf(sl811
, addr
, buf
, len
);
268 /* autoincrementing */
269 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
270 writeb(len
, data_reg
);
271 writeb(SL_OUT
| ep
->epnum
, data_reg
);
272 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
274 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
275 control
| SL11H_HCTLMASK_OUT
);
277 PACKET("OUT%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
278 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 1), ep
, len
);
281 /*-------------------------------------------------------------------------*/
283 /* caller updates on-chip enables later */
285 static inline void sofirq_on(struct sl811
*sl811
)
287 if (sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
)
289 VDBG("sof irq on\n");
290 sl811
->irq_enable
|= SL11H_INTMASK_SOFINTR
;
293 static inline void sofirq_off(struct sl811
*sl811
)
295 if (!(sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
))
297 VDBG("sof irq off\n");
298 sl811
->irq_enable
&= ~SL11H_INTMASK_SOFINTR
;
301 /*-------------------------------------------------------------------------*/
303 /* pick the next endpoint for a transaction, and issue it.
304 * frames start with periodic transfers (after whatever is pending
305 * from the previous frame), and the rest of the time is async
306 * transfers, scheduled round-robin.
308 static struct sl811h_ep
*start(struct sl811
*sl811
, u8 bank
)
310 struct sl811h_ep
*ep
;
315 /* use endpoint at schedule head */
316 if (sl811
->next_periodic
) {
317 ep
= sl811
->next_periodic
;
318 sl811
->next_periodic
= ep
->next
;
320 if (sl811
->next_async
)
321 ep
= sl811
->next_async
;
322 else if (!list_empty(&sl811
->async
))
323 ep
= container_of(sl811
->async
.next
,
324 struct sl811h_ep
, schedule
);
326 /* could set up the first fullspeed periodic
327 * transfer for the next frame ...
333 if ((bank
&& sl811
->active_b
== ep
) || sl811
->active_a
== ep
)
337 if (ep
->schedule
.next
== &sl811
->async
)
338 sl811
->next_async
= NULL
;
340 sl811
->next_async
= container_of(ep
->schedule
.next
,
341 struct sl811h_ep
, schedule
);
344 if (unlikely(list_empty(&ep
->hep
->urb_list
))) {
345 DBG("empty %p queue?\n", ep
);
349 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
350 control
= ep
->defctrl
;
352 /* if this frame doesn't have enough time left to transfer this
353 * packet, wait till the next frame. too-simple algorithm...
355 fclock
= sl811_read(sl811
, SL11H_SOFTMRREG
) << 6;
356 fclock
-= 100; /* setup takes not much time */
357 if (urb
->dev
->speed
== USB_SPEED_LOW
) {
358 if (control
& SL11H_HCTLMASK_PREAMBLE
) {
359 /* also note erratum 1: some hubs won't work */
362 fclock
-= ep
->maxpacket
<< 8;
364 /* erratum 2: AFTERSOF only works for fullspeed */
367 sl811
->stat_overrun
++;
372 fclock
-= 12000 / 19; /* 19 64byte packets/msec */
375 sl811
->stat_overrun
++;
376 control
|= SL11H_HCTLMASK_AFTERSOF
;
378 /* throttle bulk/control irq noise */
379 } else if (ep
->nak_count
)
380 control
|= SL11H_HCTLMASK_AFTERSOF
;
384 switch (ep
->nextpid
) {
386 in_packet(sl811
, ep
, urb
, bank
, control
);
389 out_packet(sl811
, ep
, urb
, bank
, control
);
392 setup_packet(sl811
, ep
, urb
, bank
, control
);
394 case USB_PID_ACK
: /* for control status */
395 status_packet(sl811
, ep
, urb
, bank
, control
);
398 DBG("bad ep%p pid %02x\n", ep
, ep
->nextpid
);
404 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
406 static inline void start_transfer(struct sl811
*sl811
)
408 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
410 if (sl811
->active_a
== NULL
) {
411 sl811
->active_a
= start(sl811
, SL811_EP_A(SL811_HOST_BUF
));
412 if (sl811
->active_a
!= NULL
)
413 sl811
->jiffies_a
= jiffies
+ MIN_JIFFIES
;
416 if (sl811
->active_b
== NULL
) {
417 sl811
->active_b
= start(sl811
, SL811_EP_B(SL811_HOST_BUF
));
418 if (sl811
->active_b
!= NULL
)
419 sl811
->jiffies_b
= jiffies
+ MIN_JIFFIES
;
424 static void finish_request(
426 struct sl811h_ep
*ep
,
429 ) __releases(sl811
->lock
) __acquires(sl811
->lock
)
433 if (usb_pipecontrol(urb
->pipe
))
434 ep
->nextpid
= USB_PID_SETUP
;
436 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811
), urb
);
437 spin_unlock(&sl811
->lock
);
438 usb_hcd_giveback_urb(sl811_to_hcd(sl811
), urb
, status
);
439 spin_lock(&sl811
->lock
);
441 /* leave active endpoints in the schedule */
442 if (!list_empty(&ep
->hep
->urb_list
))
445 /* async deschedule? */
446 if (!list_empty(&ep
->schedule
)) {
447 list_del_init(&ep
->schedule
);
448 if (ep
== sl811
->next_async
)
449 sl811
->next_async
= NULL
;
453 /* periodic deschedule */
454 DBG("deschedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
455 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
456 struct sl811h_ep
*temp
;
457 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
459 while (*prev
&& ((temp
= *prev
) != ep
))
463 sl811
->load
[i
] -= ep
->load
;
465 ep
->branch
= PERIODIC_SIZE
;
466 sl811
->periodic_count
--;
467 sl811_to_hcd(sl811
)->self
.bandwidth_allocated
468 -= ep
->load
/ ep
->period
;
469 if (ep
== sl811
->next_periodic
)
470 sl811
->next_periodic
= ep
->next
;
472 /* we might turn SOFs back on again for the async schedule */
473 if (sl811
->periodic_count
== 0)
478 done(struct sl811
*sl811
, struct sl811h_ep
*ep
, u8 bank
)
482 int urbstat
= -EINPROGRESS
;
487 status
= sl811_read(sl811
, bank
+ SL11H_PKTSTATREG
);
489 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
491 /* we can safely ignore NAKs */
492 if (status
& SL11H_STATMASK_NAK
) {
493 // PACKET("...NAK_%02x qh%p\n", bank, ep);
498 /* ACK advances transfer, toggle, and maybe queue */
499 } else if (status
& SL11H_STATMASK_ACK
) {
500 struct usb_device
*udev
= urb
->dev
;
504 /* urb->iso_frame_desc is currently ignored here... */
506 ep
->nak_count
= ep
->error_count
= 0;
507 switch (ep
->nextpid
) {
509 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
510 urb
->actual_length
+= ep
->length
;
511 usb_dotoggle(udev
, ep
->epnum
, 1);
512 if (urb
->actual_length
513 == urb
->transfer_buffer_length
) {
514 if (usb_pipecontrol(urb
->pipe
))
515 ep
->nextpid
= USB_PID_ACK
;
517 /* some bulk protocols terminate OUT transfers
518 * by a short packet, using ZLPs not padding.
520 else if (ep
->length
< ep
->maxpacket
521 || !(urb
->transfer_flags
527 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
528 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
530 len
= ep
->maxpacket
- sl811_read(sl811
,
531 bank
+ SL11H_XFERCNTREG
);
532 if (len
> ep
->length
) {
534 urbstat
= -EOVERFLOW
;
536 urb
->actual_length
+= len
;
537 sl811_read_buf(sl811
, SL811HS_PACKET_BUF(bank
== 0),
539 usb_dotoggle(udev
, ep
->epnum
, 0);
540 if (urbstat
== -EINPROGRESS
&&
541 (len
< ep
->maxpacket
||
542 urb
->actual_length
==
543 urb
->transfer_buffer_length
)) {
544 if (usb_pipecontrol(urb
->pipe
))
545 ep
->nextpid
= USB_PID_ACK
;
551 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
552 if (urb
->transfer_buffer_length
== urb
->actual_length
)
553 ep
->nextpid
= USB_PID_ACK
;
554 else if (usb_pipeout(urb
->pipe
)) {
555 usb_settoggle(udev
, 0, 1, 1);
556 ep
->nextpid
= USB_PID_OUT
;
558 usb_settoggle(udev
, 0, 0, 1);
559 ep
->nextpid
= USB_PID_IN
;
563 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
568 /* STALL stops all transfers */
569 } else if (status
& SL11H_STATMASK_STALL
) {
570 PACKET("...STALL_%02x qh%p\n", bank
, ep
);
571 ep
->nak_count
= ep
->error_count
= 0;
574 /* error? retry, until "3 strikes" */
575 } else if (++ep
->error_count
>= 3) {
576 if (status
& SL11H_STATMASK_TMOUT
)
578 else if (status
& SL11H_STATMASK_OVF
)
579 urbstat
= -EOVERFLOW
;
583 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
584 bank
, status
, ep
, urbstat
);
587 if (urbstat
!= -EINPROGRESS
|| urb
->unlinked
)
588 finish_request(sl811
, ep
, urb
, urbstat
);
591 static inline u8
checkdone(struct sl811
*sl811
)
596 if (sl811
->active_a
&& time_before_eq(sl811
->jiffies_a
, jiffies
)) {
597 ctl
= sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
));
598 if (ctl
& SL11H_HCTLMASK_ARM
)
599 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
600 DBG("%s DONE_A: ctrl %02x sts %02x\n",
601 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
603 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
604 irqstat
|= SL11H_INTMASK_DONE_A
;
607 if (sl811
->active_b
&& time_before_eq(sl811
->jiffies_b
, jiffies
)) {
608 ctl
= sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
));
609 if (ctl
& SL11H_HCTLMASK_ARM
)
610 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
611 DBG("%s DONE_B: ctrl %02x sts %02x\n",
612 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
614 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
615 irqstat
|= SL11H_INTMASK_DONE_A
;
621 static irqreturn_t
sl811h_irq(struct usb_hcd
*hcd
)
623 struct sl811
*sl811
= hcd_to_sl811(hcd
);
625 irqreturn_t ret
= IRQ_NONE
;
626 unsigned retries
= 5;
628 spin_lock(&sl811
->lock
);
631 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
) & ~SL11H_INTMASK_DP
;
633 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
634 irqstat
&= sl811
->irq_enable
;
638 /* this may no longer be necessary ... */
640 irqstat
= checkdone(sl811
);
646 /* USB packets, not necessarily handled in the order they're
647 * issued ... that's fine if they're different endpoints.
649 if (irqstat
& SL11H_INTMASK_DONE_A
) {
650 done(sl811
, sl811
->active_a
, SL811_EP_A(SL811_HOST_BUF
));
651 sl811
->active_a
= NULL
;
655 if (irqstat
& SL11H_INTMASK_DONE_B
) {
656 done(sl811
, sl811
->active_b
, SL811_EP_B(SL811_HOST_BUF
));
657 sl811
->active_b
= NULL
;
661 if (irqstat
& SL11H_INTMASK_SOFINTR
) {
664 index
= sl811
->frame
++ % (PERIODIC_SIZE
- 1);
667 /* be graceful about almost-inevitable periodic schedule
668 * overruns: continue the previous frame's transfers iff
669 * this one has nothing scheduled.
671 if (sl811
->next_periodic
) {
672 // ERR("overrun to slot %d\n", index);
673 sl811
->stat_overrun
++;
675 if (sl811
->periodic
[index
])
676 sl811
->next_periodic
= sl811
->periodic
[index
];
679 /* khubd manages debouncing and wakeup */
680 if (irqstat
& SL11H_INTMASK_INSRMV
) {
681 sl811
->stat_insrmv
++;
683 /* most stats are reset for each VBUS session */
684 sl811
->stat_wake
= 0;
688 sl811
->stat_lost
= 0;
691 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
693 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
694 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
696 /* usbcore nukes other pending transactions on disconnect */
697 if (sl811
->active_a
) {
698 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
699 finish_request(sl811
, sl811
->active_a
,
700 container_of(sl811
->active_a
701 ->hep
->urb_list
.next
,
702 struct urb
, urb_list
),
704 sl811
->active_a
= NULL
;
707 if (sl811
->active_b
) {
708 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
709 finish_request(sl811
, sl811
->active_b
,
710 container_of(sl811
->active_b
711 ->hep
->urb_list
.next
,
712 struct urb
, urb_list
),
714 sl811
->active_b
= NULL
;
718 /* port status seems weird until after reset, so
719 * force the reset and make khubd clean up later.
721 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
722 | (1 << USB_PORT_FEAT_CONNECTION
);
724 } else if (irqstat
& SL11H_INTMASK_RD
) {
725 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)) {
727 sl811
->port1
|= 1 << USB_PORT_FEAT_C_SUSPEND
;
730 irqstat
&= ~SL11H_INTMASK_RD
;
734 if (sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
))
735 start_transfer(sl811
);
741 if (sl811
->periodic_count
== 0 && list_empty(&sl811
->async
))
743 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
745 spin_unlock(&sl811
->lock
);
750 /*-------------------------------------------------------------------------*/
752 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
753 * this driver doesn't promise that much since it's got to handle an
754 * IRQ per packet; irq handling latencies also use up that time.
756 * NOTE: the periodic schedule is a sparse tree, with the load for
757 * each branch minimized. see fig 3.5 in the OHCI spec for example.
759 #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
761 static int balance(struct sl811
*sl811
, u16 period
, u16 load
)
763 int i
, branch
= -ENOSPC
;
765 /* search for the least loaded schedule branch of that period
766 * which has enough bandwidth left unreserved.
768 for (i
= 0; i
< period
; i
++) {
769 if (branch
< 0 || sl811
->load
[branch
] > sl811
->load
[i
]) {
772 for (j
= i
; j
< PERIODIC_SIZE
; j
+= period
) {
773 if ((sl811
->load
[j
] + load
)
777 if (j
< PERIODIC_SIZE
)
785 /*-------------------------------------------------------------------------*/
787 static int sl811h_urb_enqueue(
792 struct sl811
*sl811
= hcd_to_sl811(hcd
);
793 struct usb_device
*udev
= urb
->dev
;
794 unsigned int pipe
= urb
->pipe
;
795 int is_out
= !usb_pipein(pipe
);
796 int type
= usb_pipetype(pipe
);
797 int epnum
= usb_pipeendpoint(pipe
);
798 struct sl811h_ep
*ep
= NULL
;
802 struct usb_host_endpoint
*hep
= urb
->ep
;
805 if (type
== PIPE_ISOCHRONOUS
)
809 /* avoid all allocations within spinlocks */
811 ep
= kzalloc(sizeof *ep
, mem_flags
);
813 spin_lock_irqsave(&sl811
->lock
, flags
);
815 /* don't submit to a dead or disabled port */
816 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
))
817 || !HC_IS_RUNNING(hcd
->state
)) {
820 goto fail_not_linked
;
822 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
825 goto fail_not_linked
;
836 INIT_LIST_HEAD(&ep
->schedule
);
839 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
840 ep
->defctrl
= SL11H_HCTLMASK_ARM
| SL11H_HCTLMASK_ENABLE
;
841 usb_settoggle(udev
, epnum
, is_out
, 0);
843 if (type
== PIPE_CONTROL
)
844 ep
->nextpid
= USB_PID_SETUP
;
846 ep
->nextpid
= USB_PID_OUT
;
848 ep
->nextpid
= USB_PID_IN
;
850 if (ep
->maxpacket
> H_MAXPACKET
) {
851 /* iso packets up to 240 bytes could work... */
852 DBG("dev %d ep%d maxpacket %d\n",
853 udev
->devnum
, epnum
, ep
->maxpacket
);
858 if (udev
->speed
== USB_SPEED_LOW
) {
859 /* send preamble for external hub? */
860 if (!(sl811
->ctrl1
& SL11H_CTL1MASK_LSPD
))
861 ep
->defctrl
|= SL11H_HCTLMASK_PREAMBLE
;
864 case PIPE_ISOCHRONOUS
:
866 if (urb
->interval
> PERIODIC_SIZE
)
867 urb
->interval
= PERIODIC_SIZE
;
868 ep
->period
= urb
->interval
;
869 ep
->branch
= PERIODIC_SIZE
;
870 if (type
== PIPE_ISOCHRONOUS
)
871 ep
->defctrl
|= SL11H_HCTLMASK_ISOCH
;
872 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
873 (type
== PIPE_ISOCHRONOUS
),
874 usb_maxpacket(udev
, pipe
, is_out
))
883 /* maybe put endpoint into schedule */
887 if (list_empty(&ep
->schedule
))
888 list_add_tail(&ep
->schedule
, &sl811
->async
);
890 case PIPE_ISOCHRONOUS
:
892 urb
->interval
= ep
->period
;
893 if (ep
->branch
< PERIODIC_SIZE
) {
894 /* NOTE: the phase is correct here, but the value
895 * needs offsetting by the transfer queue depth.
896 * All current drivers ignore start_frame, so this
897 * is unlikely to ever matter...
899 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
904 retval
= balance(sl811
, ep
->period
, ep
->load
);
909 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
912 /* sort each schedule branch by period (slow before fast)
913 * to share the faster parts of the tree without needing
914 * dummy/placeholder nodes
916 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
917 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
918 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
919 struct sl811h_ep
*here
= *prev
;
921 while (here
&& ep
!= here
) {
922 if (ep
->period
> here
->period
)
931 sl811
->load
[i
] += ep
->load
;
933 sl811
->periodic_count
++;
934 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
939 start_transfer(sl811
);
940 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
943 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
945 spin_unlock_irqrestore(&sl811
->lock
, flags
);
949 static int sl811h_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
951 struct sl811
*sl811
= hcd_to_sl811(hcd
);
952 struct usb_host_endpoint
*hep
;
954 struct sl811h_ep
*ep
;
957 spin_lock_irqsave(&sl811
->lock
, flags
);
958 retval
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
965 /* finish right away if this urb can't be active ...
966 * note that some drivers wrongly expect delays
968 if (ep
->hep
->urb_list
.next
!= &urb
->urb_list
) {
969 /* not front of queue? never active */
971 /* for active transfers, we expect an IRQ */
972 } else if (sl811
->active_a
== ep
) {
973 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
974 /* happens a lot with lowspeed?? */
975 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
977 SL811_EP_A(SL11H_HOSTCTLREG
)),
979 SL811_EP_A(SL11H_PKTSTATREG
)));
980 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
982 sl811
->active_a
= NULL
;
986 } else if (sl811
->active_b
== ep
) {
987 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
988 /* happens a lot with lowspeed?? */
989 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
991 SL811_EP_B(SL11H_HOSTCTLREG
)),
993 SL811_EP_B(SL11H_PKTSTATREG
)));
994 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
),
996 sl811
->active_b
= NULL
;
1001 /* front of queue for inactive endpoint */
1005 finish_request(sl811
, ep
, urb
, 0);
1007 VDBG("dequeue, urb %p active %s; wait4irq\n", urb
,
1008 (sl811
->active_a
== ep
) ? "A" : "B");
1012 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1017 sl811h_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
)
1019 struct sl811h_ep
*ep
= hep
->hcpriv
;
1024 /* assume we'd just wait for the irq */
1025 if (!list_empty(&hep
->urb_list
))
1027 if (!list_empty(&hep
->urb_list
))
1028 WARN("ep %p not empty?\n", ep
);
1035 sl811h_get_frame(struct usb_hcd
*hcd
)
1037 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1039 /* wrong except while periodic transfers are scheduled;
1040 * never matches the on-the-wire frame;
1041 * subject to overruns.
1043 return sl811
->frame
;
1047 /*-------------------------------------------------------------------------*/
1049 /* the virtual root hub timer IRQ checks for hub status */
1051 sl811h_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1053 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1055 unsigned long flags
;
1057 /* non-SMP HACK: use root hub timer as i/o watchdog
1058 * this seems essential when SOF IRQs aren't in use...
1060 local_irq_save(flags
);
1061 if (!timer_pending(&sl811
->timer
)) {
1062 if (sl811h_irq( /* ~0, */ hcd
) != IRQ_NONE
)
1065 local_irq_restore(flags
);
1068 if (!(sl811
->port1
& (0xffff << 16)))
1071 /* tell khubd port 1 changed */
1077 sl811h_hub_descriptor (
1078 struct sl811
*sl811
,
1079 struct usb_hub_descriptor
*desc
1083 desc
->bDescriptorType
= 0x29;
1084 desc
->bHubContrCurrent
= 0;
1086 desc
->bNbrPorts
= 1;
1087 desc
->bDescLength
= 9;
1089 /* per-port power switching (gang of one!), or none */
1090 desc
->bPwrOn2PwrGood
= 0;
1091 if (sl811
->board
&& sl811
->board
->port_power
) {
1092 desc
->bPwrOn2PwrGood
= sl811
->board
->potpg
;
1093 if (!desc
->bPwrOn2PwrGood
)
1094 desc
->bPwrOn2PwrGood
= 10;
1099 /* no overcurrent errors detection/handling */
1102 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
1104 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1105 desc
->bitmap
[0] = 0 << 1;
1106 desc
->bitmap
[1] = ~0;
1110 sl811h_timer(unsigned long _sl811
)
1112 struct sl811
*sl811
= (void *) _sl811
;
1113 unsigned long flags
;
1115 u8 signaling
= sl811
->ctrl1
& SL11H_CTL1MASK_FORCE
;
1116 const u32 mask
= (1 << USB_PORT_FEAT_CONNECTION
)
1117 | (1 << USB_PORT_FEAT_ENABLE
)
1118 | (1 << USB_PORT_FEAT_LOWSPEED
);
1120 spin_lock_irqsave(&sl811
->lock
, flags
);
1122 /* stop special signaling */
1123 sl811
->ctrl1
&= ~SL11H_CTL1MASK_FORCE
;
1124 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1127 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
);
1129 switch (signaling
) {
1130 case SL11H_CTL1MASK_SE0
:
1132 sl811
->port1
= (1 << USB_PORT_FEAT_C_RESET
)
1133 | (1 << USB_PORT_FEAT_POWER
);
1135 /* don't wrongly ack RD */
1136 if (irqstat
& SL11H_INTMASK_INSRMV
)
1137 irqstat
&= ~SL11H_INTMASK_RD
;
1139 case SL11H_CTL1MASK_K
:
1140 DBG("end resume\n");
1141 sl811
->port1
&= ~(1 << USB_PORT_FEAT_SUSPEND
);
1144 DBG("odd timer signaling: %02x\n", signaling
);
1147 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
1149 if (irqstat
& SL11H_INTMASK_RD
) {
1150 /* usbcore nukes all pending transactions on disconnect */
1151 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
))
1152 sl811
->port1
|= (1 << USB_PORT_FEAT_C_CONNECTION
)
1153 | (1 << USB_PORT_FEAT_C_ENABLE
);
1154 sl811
->port1
&= ~mask
;
1155 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1157 sl811
->port1
|= mask
;
1158 if (irqstat
& SL11H_INTMASK_DP
)
1159 sl811
->port1
&= ~(1 << USB_PORT_FEAT_LOWSPEED
);
1160 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
| SL11H_INTMASK_RD
;
1163 if (sl811
->port1
& (1 << USB_PORT_FEAT_CONNECTION
)) {
1164 u8 ctrl2
= SL811HS_CTL2_INIT
;
1166 sl811
->irq_enable
|= SL11H_INTMASK_DONE_A
;
1168 sl811
->irq_enable
|= SL11H_INTMASK_DONE_B
;
1170 if (sl811
->port1
& (1 << USB_PORT_FEAT_LOWSPEED
)) {
1171 sl811
->ctrl1
|= SL11H_CTL1MASK_LSPD
;
1172 ctrl2
|= SL811HS_CTL2MASK_DSWAP
;
1175 /* start SOFs flowing, kickstarting with A registers */
1176 sl811
->ctrl1
|= SL11H_CTL1MASK_SOF_ENA
;
1177 sl811_write(sl811
, SL11H_SOFLOWREG
, 0xe0);
1178 sl811_write(sl811
, SL811HS_CTLREG2
, ctrl2
);
1180 /* autoincrementing */
1181 sl811_write(sl811
, SL811_EP_A(SL11H_BUFLNTHREG
), 0);
1182 writeb(SL_SOF
, sl811
->data_reg
);
1183 writeb(0, sl811
->data_reg
);
1184 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1185 SL11H_HCTLMASK_ARM
);
1187 /* khubd provides debounce delay */
1191 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1194 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
1195 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1200 struct usb_hcd
*hcd
,
1207 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1209 unsigned long flags
;
1211 spin_lock_irqsave(&sl811
->lock
, flags
);
1214 case ClearHubFeature
:
1217 case C_HUB_OVER_CURRENT
:
1218 case C_HUB_LOCAL_POWER
:
1224 case ClearPortFeature
:
1225 if (wIndex
!= 1 || wLength
!= 0)
1229 case USB_PORT_FEAT_ENABLE
:
1230 sl811
->port1
&= (1 << USB_PORT_FEAT_POWER
);
1232 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1233 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1234 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1237 case USB_PORT_FEAT_SUSPEND
:
1238 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
)))
1241 /* 20 msec of resume/K signaling, other irqs blocked */
1242 DBG("start resume...\n");
1243 sl811
->irq_enable
= 0;
1244 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1246 sl811
->ctrl1
|= SL11H_CTL1MASK_K
;
1247 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1249 mod_timer(&sl811
->timer
, jiffies
1250 + msecs_to_jiffies(20));
1252 case USB_PORT_FEAT_POWER
:
1253 port_power(sl811
, 0);
1255 case USB_PORT_FEAT_C_ENABLE
:
1256 case USB_PORT_FEAT_C_SUSPEND
:
1257 case USB_PORT_FEAT_C_CONNECTION
:
1258 case USB_PORT_FEAT_C_OVER_CURRENT
:
1259 case USB_PORT_FEAT_C_RESET
:
1264 sl811
->port1
&= ~(1 << wValue
);
1266 case GetHubDescriptor
:
1267 sl811h_hub_descriptor(sl811
, (struct usb_hub_descriptor
*) buf
);
1270 *(__le32
*) buf
= cpu_to_le32(0);
1275 *(__le32
*) buf
= cpu_to_le32(sl811
->port1
);
1278 if (*(u16
*)(buf
+2)) /* only if wPortChange is interesting */
1280 DBG("GetPortStatus %08x\n", sl811
->port1
);
1282 case SetPortFeature
:
1283 if (wIndex
!= 1 || wLength
!= 0)
1286 case USB_PORT_FEAT_SUSPEND
:
1287 if (sl811
->port1
& (1 << USB_PORT_FEAT_RESET
))
1289 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_ENABLE
)))
1292 DBG("suspend...\n");
1293 sl811
->ctrl1
&= ~SL11H_CTL1MASK_SOF_ENA
;
1294 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1296 case USB_PORT_FEAT_POWER
:
1297 port_power(sl811
, 1);
1299 case USB_PORT_FEAT_RESET
:
1300 if (sl811
->port1
& (1 << USB_PORT_FEAT_SUSPEND
))
1302 if (!(sl811
->port1
& (1 << USB_PORT_FEAT_POWER
)))
1305 /* 50 msec of reset/SE0 signaling, irqs blocked */
1306 sl811
->irq_enable
= 0;
1307 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1309 sl811
->ctrl1
= SL11H_CTL1MASK_SE0
;
1310 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1311 sl811
->port1
|= (1 << USB_PORT_FEAT_RESET
);
1312 mod_timer(&sl811
->timer
, jiffies
1313 + msecs_to_jiffies(50));
1318 sl811
->port1
|= 1 << wValue
;
1323 /* "protocol stall" on error */
1327 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1334 sl811h_bus_suspend(struct usb_hcd
*hcd
)
1337 DBG("%s\n", __FUNCTION__
);
1342 sl811h_bus_resume(struct usb_hcd
*hcd
)
1345 DBG("%s\n", __FUNCTION__
);
1351 #define sl811h_bus_suspend NULL
1352 #define sl811h_bus_resume NULL
1357 /*-------------------------------------------------------------------------*/
1359 #ifdef STUB_DEBUG_FILE
1361 static inline void create_debug_file(struct sl811
*sl811
) { }
1362 static inline void remove_debug_file(struct sl811
*sl811
) { }
1366 #include <linux/proc_fs.h>
1367 #include <linux/seq_file.h>
1369 static void dump_irq(struct seq_file
*s
, char *label
, u8 mask
)
1371 seq_printf(s
, "%s %02x%s%s%s%s%s%s\n", label
, mask
,
1372 (mask
& SL11H_INTMASK_DONE_A
) ? " done_a" : "",
1373 (mask
& SL11H_INTMASK_DONE_B
) ? " done_b" : "",
1374 (mask
& SL11H_INTMASK_SOFINTR
) ? " sof" : "",
1375 (mask
& SL11H_INTMASK_INSRMV
) ? " ins/rmv" : "",
1376 (mask
& SL11H_INTMASK_RD
) ? " rd" : "",
1377 (mask
& SL11H_INTMASK_DP
) ? " dp" : "");
1380 static int proc_sl811h_show(struct seq_file
*s
, void *unused
)
1382 struct sl811
*sl811
= s
->private;
1383 struct sl811h_ep
*ep
;
1386 seq_printf(s
, "%s\n%s version %s\nportstatus[1] = %08x\n",
1387 sl811_to_hcd(sl811
)->product_desc
,
1388 hcd_name
, DRIVER_VERSION
,
1391 seq_printf(s
, "insert/remove: %ld\n", sl811
->stat_insrmv
);
1392 seq_printf(s
, "current session: done_a %ld done_b %ld "
1393 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1394 sl811
->stat_a
, sl811
->stat_b
,
1395 sl811
->stat_wake
, sl811
->stat_sof
,
1396 sl811
->stat_overrun
, sl811
->stat_lost
);
1398 spin_lock_irq(&sl811
->lock
);
1400 if (sl811
->ctrl1
& SL11H_CTL1MASK_SUSPEND
)
1401 seq_printf(s
, "(suspended)\n\n");
1403 u8 t
= sl811_read(sl811
, SL11H_CTLREG1
);
1405 seq_printf(s
, "ctrl1 %02x%s%s%s%s\n", t
,
1406 (t
& SL11H_CTL1MASK_SOF_ENA
) ? " sofgen" : "",
1407 ({char *s
; switch (t
& SL11H_CTL1MASK_FORCE
) {
1408 case SL11H_CTL1MASK_NORMAL
: s
= ""; break;
1409 case SL11H_CTL1MASK_SE0
: s
= " se0/reset"; break;
1410 case SL11H_CTL1MASK_K
: s
= " k/resume"; break;
1411 default: s
= "j"; break;
1413 (t
& SL11H_CTL1MASK_LSPD
) ? " lowspeed" : "",
1414 (t
& SL11H_CTL1MASK_SUSPEND
) ? " suspend" : "");
1416 dump_irq(s
, "irq_enable",
1417 sl811_read(sl811
, SL11H_IRQ_ENABLE
));
1418 dump_irq(s
, "irq_status",
1419 sl811_read(sl811
, SL11H_IRQ_STATUS
));
1420 seq_printf(s
, "frame clocks remaining: %d\n",
1421 sl811_read(sl811
, SL11H_SOFTMRREG
) << 6);
1424 seq_printf(s
, "A: qh%p ctl %02x sts %02x\n", sl811
->active_a
,
1425 sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
)),
1426 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
1427 seq_printf(s
, "B: qh%p ctl %02x sts %02x\n", sl811
->active_b
,
1428 sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
)),
1429 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
1430 seq_printf(s
, "\n");
1431 list_for_each_entry (ep
, &sl811
->async
, schedule
) {
1434 seq_printf(s
, "%s%sqh%p, ep%d%s, maxpacket %d"
1436 (ep
== sl811
->active_a
) ? "(A) " : "",
1437 (ep
== sl811
->active_b
) ? "(B) " : "",
1439 ({ char *s
; switch (ep
->nextpid
) {
1440 case USB_PID_IN
: s
= "in"; break;
1441 case USB_PID_OUT
: s
= "out"; break;
1442 case USB_PID_SETUP
: s
= "setup"; break;
1443 case USB_PID_ACK
: s
= "status"; break;
1444 default: s
= "?"; break;
1447 ep
->nak_count
, ep
->error_count
);
1448 list_for_each_entry (urb
, &ep
->hep
->urb_list
, urb_list
) {
1449 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1451 urb
->transfer_buffer_length
);
1454 if (!list_empty(&sl811
->async
))
1455 seq_printf(s
, "\n");
1457 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1459 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1460 ep
= sl811
->periodic
[i
];
1463 seq_printf(s
, "%2d [%3d]:\n", i
, sl811
->load
[i
]);
1465 /* DUMB: prints shared entries multiple times */
1468 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1470 (ep
== sl811
->active_a
) ? "(A) " : "",
1471 (ep
== sl811
->active_b
) ? "(B) " : "",
1473 (ep
->udev
->speed
== USB_SPEED_FULL
)
1475 ep
->udev
->devnum
, ep
->epnum
,
1476 (ep
->epnum
== 0) ? ""
1477 : ((ep
->nextpid
== USB_PID_IN
)
1480 ep
->maxpacket
, ep
->error_count
);
1485 spin_unlock_irq(&sl811
->lock
);
1486 seq_printf(s
, "\n");
1491 static int proc_sl811h_open(struct inode
*inode
, struct file
*file
)
1493 return single_open(file
, proc_sl811h_show
, PDE(inode
)->data
);
1496 static const struct file_operations proc_ops
= {
1497 .open
= proc_sl811h_open
,
1499 .llseek
= seq_lseek
,
1500 .release
= single_release
,
1503 /* expect just one sl811 per system */
1504 static const char proc_filename
[] = "driver/sl811h";
1506 static void create_debug_file(struct sl811
*sl811
)
1508 struct proc_dir_entry
*pde
;
1510 pde
= create_proc_entry(proc_filename
, 0, NULL
);
1514 pde
->proc_fops
= &proc_ops
;
1519 static void remove_debug_file(struct sl811
*sl811
)
1522 remove_proc_entry(proc_filename
, NULL
);
1527 /*-------------------------------------------------------------------------*/
1530 sl811h_stop(struct usb_hcd
*hcd
)
1532 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1533 unsigned long flags
;
1535 del_timer_sync(&hcd
->rh_timer
);
1537 spin_lock_irqsave(&sl811
->lock
, flags
);
1538 port_power(sl811
, 0);
1539 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1543 sl811h_start(struct usb_hcd
*hcd
)
1545 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1547 /* chip has been reset, VBUS power is off */
1548 hcd
->state
= HC_STATE_RUNNING
;
1551 if (!device_can_wakeup(hcd
->self
.controller
))
1552 device_init_wakeup(hcd
->self
.controller
,
1553 sl811
->board
->can_wakeup
);
1554 hcd
->power_budget
= sl811
->board
->power
* 2;
1557 /* enable power and interupts */
1558 port_power(sl811
, 1);
1563 /*-------------------------------------------------------------------------*/
1565 static struct hc_driver sl811h_hc_driver
= {
1566 .description
= hcd_name
,
1567 .hcd_priv_size
= sizeof(struct sl811
),
1570 * generic hardware linkage
1573 .flags
= HCD_USB11
| HCD_MEMORY
,
1575 /* Basic lifecycle operations */
1576 .start
= sl811h_start
,
1577 .stop
= sl811h_stop
,
1580 * managing i/o requests and associated device resources
1582 .urb_enqueue
= sl811h_urb_enqueue
,
1583 .urb_dequeue
= sl811h_urb_dequeue
,
1584 .endpoint_disable
= sl811h_endpoint_disable
,
1587 * periodic schedule support
1589 .get_frame_number
= sl811h_get_frame
,
1594 .hub_status_data
= sl811h_hub_status_data
,
1595 .hub_control
= sl811h_hub_control
,
1596 .bus_suspend
= sl811h_bus_suspend
,
1597 .bus_resume
= sl811h_bus_resume
,
1600 /*-------------------------------------------------------------------------*/
1602 static int __devexit
1603 sl811h_remove(struct platform_device
*dev
)
1605 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1606 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1607 struct resource
*res
;
1609 remove_debug_file(sl811
);
1610 usb_remove_hcd(hcd
);
1612 /* some platforms may use IORESOURCE_IO */
1613 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1615 iounmap(sl811
->data_reg
);
1617 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1619 iounmap(sl811
->addr_reg
);
1625 static int __devinit
1626 sl811h_probe(struct platform_device
*dev
)
1628 struct usb_hcd
*hcd
;
1629 struct sl811
*sl811
;
1630 struct resource
*addr
, *data
;
1632 void __iomem
*addr_reg
;
1633 void __iomem
*data_reg
;
1637 /* basic sanity checks first. board-specific init logic should
1638 * have initialized these three resources and probably board
1639 * specific platform_data. we don't probe for IRQs, and do only
1640 * minimal sanity checking.
1642 irq
= platform_get_irq(dev
, 0);
1643 if (dev
->num_resources
< 3 || irq
< 0)
1646 /* refuse to confuse usbcore */
1647 if (dev
->dev
.dma_mask
) {
1648 DBG("no we won't dma\n");
1652 /* the chip may be wired for either kind of addressing */
1653 addr
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1654 data
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1656 if (!addr
|| !data
) {
1657 addr
= platform_get_resource(dev
, IORESOURCE_IO
, 0);
1658 data
= platform_get_resource(dev
, IORESOURCE_IO
, 1);
1663 * NOTE: 64-bit resource->start is getting truncated
1664 * to avoid compiler warning, assuming that ->start
1665 * is always 32-bit for this case
1667 addr_reg
= (void __iomem
*) (unsigned long) addr
->start
;
1668 data_reg
= (void __iomem
*) (unsigned long) data
->start
;
1670 addr_reg
= ioremap(addr
->start
, 1);
1671 if (addr_reg
== NULL
) {
1676 data_reg
= ioremap(data
->start
, 1);
1677 if (data_reg
== NULL
) {
1683 /* allocate and initialize hcd */
1684 hcd
= usb_create_hcd(&sl811h_hc_driver
, &dev
->dev
, dev
->dev
.bus_id
);
1689 hcd
->rsrc_start
= addr
->start
;
1690 sl811
= hcd_to_sl811(hcd
);
1692 spin_lock_init(&sl811
->lock
);
1693 INIT_LIST_HEAD(&sl811
->async
);
1694 sl811
->board
= dev
->dev
.platform_data
;
1695 init_timer(&sl811
->timer
);
1696 sl811
->timer
.function
= sl811h_timer
;
1697 sl811
->timer
.data
= (unsigned long) sl811
;
1698 sl811
->addr_reg
= addr_reg
;
1699 sl811
->data_reg
= data_reg
;
1701 spin_lock_irq(&sl811
->lock
);
1702 port_power(sl811
, 0);
1703 spin_unlock_irq(&sl811
->lock
);
1706 tmp
= sl811_read(sl811
, SL11H_HWREVREG
);
1709 hcd
->product_desc
= "SL811HS v1.2";
1712 hcd
->product_desc
= "SL811HS v1.5";
1715 /* reject case 0, SL11S is less functional */
1716 DBG("chiprev %02x\n", tmp
);
1721 /* The chip's IRQ is level triggered, active high. A requirement
1722 * for platform device setup is to cope with things like signal
1723 * inverters (e.g. CF is active low) or working only with edge
1724 * triggers (e.g. most ARM CPUs). Initial driver stress testing
1725 * was on a system with single edge triggering, so most sorts of
1726 * triggering arrangement should work.
1728 retval
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| IRQF_SHARED
);
1732 create_debug_file(sl811
);
1744 DBG("init error, %d\n", retval
);
1750 /* for this device there's no useful distinction between the controller
1751 * and its root hub, except that the root hub only gets direct PM calls
1752 * when CONFIG_USB_SUSPEND is enabled.
1756 sl811h_suspend(struct platform_device
*dev
, pm_message_t state
)
1758 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1759 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1762 switch (state
.event
) {
1763 case PM_EVENT_FREEZE
:
1764 retval
= sl811h_bus_suspend(hcd
);
1766 case PM_EVENT_SUSPEND
:
1767 case PM_EVENT_PRETHAW
: /* explicitly discard hw state */
1768 port_power(sl811
, 0);
1775 sl811h_resume(struct platform_device
*dev
)
1777 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1778 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1780 /* with no "check to see if VBUS is still powered" board hook,
1781 * let's assume it'd only be powered to enable remote wakeup.
1783 if (!sl811
->port1
|| !device_can_wakeup(&hcd
->self
.root_hub
->dev
)) {
1785 port_power(sl811
, 1);
1786 usb_root_hub_lost_power(hcd
->self
.root_hub
);
1790 return sl811h_bus_resume(hcd
);
1795 #define sl811h_suspend NULL
1796 #define sl811h_resume NULL
1801 /* this driver is exported so sl811_cs can depend on it */
1802 struct platform_driver sl811h_driver
= {
1803 .probe
= sl811h_probe
,
1804 .remove
= __devexit_p(sl811h_remove
),
1806 .suspend
= sl811h_suspend
,
1807 .resume
= sl811h_resume
,
1809 .name
= (char *) hcd_name
,
1810 .owner
= THIS_MODULE
,
1813 EXPORT_SYMBOL(sl811h_driver
);
1815 /*-------------------------------------------------------------------------*/
1817 static int __init
sl811h_init(void)
1822 INFO("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
1823 return platform_driver_register(&sl811h_driver
);
1825 module_init(sl811h_init
);
1827 static void __exit
sl811h_cleanup(void)
1829 platform_driver_unregister(&sl811h_driver
);
1831 module_exit(sl811h_cleanup
);