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/usb/hcd.h>
49 #include <linux/platform_device.h>
50 #include <linux/prefetch.h>
54 #include <asm/byteorder.h>
55 #include <asm/unaligned.h>
60 MODULE_DESCRIPTION("SL811HS USB Host Controller Driver");
61 MODULE_LICENSE("GPL");
62 MODULE_ALIAS("platform:sl811-hcd");
64 #define DRIVER_VERSION "19 May 2005"
68 # define STUB_DEBUG_FILE
71 /* for now, use only one transfer register bank */
77 static const char hcd_name
[] = "sl811-hcd";
79 /*-------------------------------------------------------------------------*/
81 static void port_power(struct sl811
*sl811
, int is_on
)
83 struct usb_hcd
*hcd
= sl811_to_hcd(sl811
);
85 /* hub is inactive unless the port is powered */
87 if (sl811
->port1
& USB_PORT_STAT_POWER
)
90 sl811
->port1
= USB_PORT_STAT_POWER
;
91 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
94 sl811
->irq_enable
= 0;
95 hcd
->state
= HC_STATE_HALT
;
98 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
99 sl811_write(sl811
, SL11H_IRQ_STATUS
, ~0);
101 if (sl811
->board
&& sl811
->board
->port_power
) {
102 /* switch VBUS, at 500mA unless hub power budget gets set */
103 DBG("power %s\n", is_on
? "on" : "off");
104 sl811
->board
->port_power(hcd
->self
.controller
, is_on
);
107 /* reset as thoroughly as we can */
108 if (sl811
->board
&& sl811
->board
->reset
)
109 sl811
->board
->reset(hcd
->self
.controller
);
111 sl811_write(sl811
, SL11H_CTLREG1
, SL11H_CTL1MASK_SE0
);
115 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
116 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
117 sl811_write(sl811
, SL811HS_CTLREG2
, SL811HS_CTL2_INIT
);
118 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
120 // if !is_on, put into lowpower mode now
123 /*-------------------------------------------------------------------------*/
125 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
126 * and may start I/O. Endpoint queues are scanned during completion irq
127 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
129 * Using an external DMA engine to copy a packet at a time could work,
130 * though setup/teardown costs may be too big to make it worthwhile.
133 /* SETUP starts a new control request. Devices are not allowed to
134 * STALL or NAK these; they must cancel any pending control requests.
136 static void setup_packet(
138 struct sl811h_ep
*ep
,
146 void __iomem
*data_reg
;
148 addr
= SL811HS_PACKET_BUF(bank
== 0);
149 len
= sizeof(struct usb_ctrlrequest
);
150 data_reg
= sl811
->data_reg
;
151 sl811_write_buf(sl811
, addr
, urb
->setup_packet
, len
);
153 /* autoincrementing */
154 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
155 writeb(len
, data_reg
);
156 writeb(SL_SETUP
/* | ep->epnum */, data_reg
);
157 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
159 /* always OUT/data0 */ ;
160 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
161 control
| SL11H_HCTLMASK_OUT
);
163 PACKET("SETUP qh%p\n", ep
);
166 /* STATUS finishes control requests, often after IN or OUT data packets */
167 static void status_packet(
169 struct sl811h_ep
*ep
,
176 void __iomem
*data_reg
;
178 do_out
= urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
);
179 data_reg
= sl811
->data_reg
;
181 /* autoincrementing */
182 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, 0);
184 writeb((do_out
? SL_OUT
: SL_IN
) /* | ep->epnum */, data_reg
);
185 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
187 /* always data1; sometimes IN */
188 control
|= SL11H_HCTLMASK_TOGGLE
;
190 control
|= SL11H_HCTLMASK_OUT
;
191 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
193 PACKET("STATUS%s/%s qh%p\n", ep
->nak_count
? "/retry" : "",
194 do_out
? "out" : "in", ep
);
197 /* IN packets can be used with any type of endpoint. here we just
198 * start the transfer, data from the peripheral may arrive later.
199 * urb->iso_frame_desc is currently ignored here...
201 static void in_packet(
203 struct sl811h_ep
*ep
,
211 void __iomem
*data_reg
;
213 /* avoid losing data on overflow */
215 addr
= SL811HS_PACKET_BUF(bank
== 0);
216 if (!(control
& SL11H_HCTLMASK_ISOCH
)
217 && usb_gettoggle(urb
->dev
, ep
->epnum
, 0))
218 control
|= SL11H_HCTLMASK_TOGGLE
;
219 data_reg
= sl811
->data_reg
;
221 /* autoincrementing */
222 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
223 writeb(len
, data_reg
);
224 writeb(SL_IN
| ep
->epnum
, data_reg
);
225 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
227 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
228 ep
->length
= min_t(u32
, len
,
229 urb
->transfer_buffer_length
- urb
->actual_length
);
230 PACKET("IN%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
231 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 0), ep
, len
);
234 /* OUT packets can be used with any type of endpoint.
235 * urb->iso_frame_desc is currently ignored here...
237 static void out_packet(
239 struct sl811h_ep
*ep
,
248 void __iomem
*data_reg
;
250 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
253 len
= min_t(u32
, ep
->maxpacket
,
254 urb
->transfer_buffer_length
- urb
->actual_length
);
256 if (!(control
& SL11H_HCTLMASK_ISOCH
)
257 && usb_gettoggle(urb
->dev
, ep
->epnum
, 1))
258 control
|= SL11H_HCTLMASK_TOGGLE
;
259 addr
= SL811HS_PACKET_BUF(bank
== 0);
260 data_reg
= sl811
->data_reg
;
262 sl811_write_buf(sl811
, addr
, buf
, len
);
264 /* autoincrementing */
265 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
266 writeb(len
, data_reg
);
267 writeb(SL_OUT
| ep
->epnum
, data_reg
);
268 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
270 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
271 control
| SL11H_HCTLMASK_OUT
);
273 PACKET("OUT%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
274 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 1), ep
, len
);
277 /*-------------------------------------------------------------------------*/
279 /* caller updates on-chip enables later */
281 static inline void sofirq_on(struct sl811
*sl811
)
283 if (sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
)
285 VDBG("sof irq on\n");
286 sl811
->irq_enable
|= SL11H_INTMASK_SOFINTR
;
289 static inline void sofirq_off(struct sl811
*sl811
)
291 if (!(sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
))
293 VDBG("sof irq off\n");
294 sl811
->irq_enable
&= ~SL11H_INTMASK_SOFINTR
;
297 /*-------------------------------------------------------------------------*/
299 /* pick the next endpoint for a transaction, and issue it.
300 * frames start with periodic transfers (after whatever is pending
301 * from the previous frame), and the rest of the time is async
302 * transfers, scheduled round-robin.
304 static struct sl811h_ep
*start(struct sl811
*sl811
, u8 bank
)
306 struct sl811h_ep
*ep
;
311 /* use endpoint at schedule head */
312 if (sl811
->next_periodic
) {
313 ep
= sl811
->next_periodic
;
314 sl811
->next_periodic
= ep
->next
;
316 if (sl811
->next_async
)
317 ep
= sl811
->next_async
;
318 else if (!list_empty(&sl811
->async
))
319 ep
= container_of(sl811
->async
.next
,
320 struct sl811h_ep
, schedule
);
322 /* could set up the first fullspeed periodic
323 * transfer for the next frame ...
329 if ((bank
&& sl811
->active_b
== ep
) || sl811
->active_a
== ep
)
333 if (ep
->schedule
.next
== &sl811
->async
)
334 sl811
->next_async
= NULL
;
336 sl811
->next_async
= container_of(ep
->schedule
.next
,
337 struct sl811h_ep
, schedule
);
340 if (unlikely(list_empty(&ep
->hep
->urb_list
))) {
341 DBG("empty %p queue?\n", ep
);
345 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
346 control
= ep
->defctrl
;
348 /* if this frame doesn't have enough time left to transfer this
349 * packet, wait till the next frame. too-simple algorithm...
351 fclock
= sl811_read(sl811
, SL11H_SOFTMRREG
) << 6;
352 fclock
-= 100; /* setup takes not much time */
353 if (urb
->dev
->speed
== USB_SPEED_LOW
) {
354 if (control
& SL11H_HCTLMASK_PREAMBLE
) {
355 /* also note erratum 1: some hubs won't work */
358 fclock
-= ep
->maxpacket
<< 8;
360 /* erratum 2: AFTERSOF only works for fullspeed */
363 sl811
->stat_overrun
++;
368 fclock
-= 12000 / 19; /* 19 64byte packets/msec */
371 sl811
->stat_overrun
++;
372 control
|= SL11H_HCTLMASK_AFTERSOF
;
374 /* throttle bulk/control irq noise */
375 } else if (ep
->nak_count
)
376 control
|= SL11H_HCTLMASK_AFTERSOF
;
380 switch (ep
->nextpid
) {
382 in_packet(sl811
, ep
, urb
, bank
, control
);
385 out_packet(sl811
, ep
, urb
, bank
, control
);
388 setup_packet(sl811
, ep
, urb
, bank
, control
);
390 case USB_PID_ACK
: /* for control status */
391 status_packet(sl811
, ep
, urb
, bank
, control
);
394 DBG("bad ep%p pid %02x\n", ep
, ep
->nextpid
);
400 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
402 static inline void start_transfer(struct sl811
*sl811
)
404 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
)
406 if (sl811
->active_a
== NULL
) {
407 sl811
->active_a
= start(sl811
, SL811_EP_A(SL811_HOST_BUF
));
408 if (sl811
->active_a
!= NULL
)
409 sl811
->jiffies_a
= jiffies
+ MIN_JIFFIES
;
412 if (sl811
->active_b
== NULL
) {
413 sl811
->active_b
= start(sl811
, SL811_EP_B(SL811_HOST_BUF
));
414 if (sl811
->active_b
!= NULL
)
415 sl811
->jiffies_b
= jiffies
+ MIN_JIFFIES
;
420 static void finish_request(
422 struct sl811h_ep
*ep
,
425 ) __releases(sl811
->lock
) __acquires(sl811
->lock
)
429 if (usb_pipecontrol(urb
->pipe
))
430 ep
->nextpid
= USB_PID_SETUP
;
432 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811
), urb
);
433 spin_unlock(&sl811
->lock
);
434 usb_hcd_giveback_urb(sl811_to_hcd(sl811
), urb
, status
);
435 spin_lock(&sl811
->lock
);
437 /* leave active endpoints in the schedule */
438 if (!list_empty(&ep
->hep
->urb_list
))
441 /* async deschedule? */
442 if (!list_empty(&ep
->schedule
)) {
443 list_del_init(&ep
->schedule
);
444 if (ep
== sl811
->next_async
)
445 sl811
->next_async
= NULL
;
449 /* periodic deschedule */
450 DBG("deschedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
451 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
452 struct sl811h_ep
*temp
;
453 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
455 while (*prev
&& ((temp
= *prev
) != ep
))
459 sl811
->load
[i
] -= ep
->load
;
461 ep
->branch
= PERIODIC_SIZE
;
462 sl811
->periodic_count
--;
463 sl811_to_hcd(sl811
)->self
.bandwidth_allocated
464 -= ep
->load
/ ep
->period
;
465 if (ep
== sl811
->next_periodic
)
466 sl811
->next_periodic
= ep
->next
;
468 /* we might turn SOFs back on again for the async schedule */
469 if (sl811
->periodic_count
== 0)
474 done(struct sl811
*sl811
, struct sl811h_ep
*ep
, u8 bank
)
478 int urbstat
= -EINPROGRESS
;
483 status
= sl811_read(sl811
, bank
+ SL11H_PKTSTATREG
);
485 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
487 /* we can safely ignore NAKs */
488 if (status
& SL11H_STATMASK_NAK
) {
489 // PACKET("...NAK_%02x qh%p\n", bank, ep);
494 /* ACK advances transfer, toggle, and maybe queue */
495 } else if (status
& SL11H_STATMASK_ACK
) {
496 struct usb_device
*udev
= urb
->dev
;
500 /* urb->iso_frame_desc is currently ignored here... */
502 ep
->nak_count
= ep
->error_count
= 0;
503 switch (ep
->nextpid
) {
505 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
506 urb
->actual_length
+= ep
->length
;
507 usb_dotoggle(udev
, ep
->epnum
, 1);
508 if (urb
->actual_length
509 == urb
->transfer_buffer_length
) {
510 if (usb_pipecontrol(urb
->pipe
))
511 ep
->nextpid
= USB_PID_ACK
;
513 /* some bulk protocols terminate OUT transfers
514 * by a short packet, using ZLPs not padding.
516 else if (ep
->length
< ep
->maxpacket
517 || !(urb
->transfer_flags
523 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
524 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
526 len
= ep
->maxpacket
- sl811_read(sl811
,
527 bank
+ SL11H_XFERCNTREG
);
528 if (len
> ep
->length
) {
530 urbstat
= -EOVERFLOW
;
532 urb
->actual_length
+= len
;
533 sl811_read_buf(sl811
, SL811HS_PACKET_BUF(bank
== 0),
535 usb_dotoggle(udev
, ep
->epnum
, 0);
536 if (urbstat
== -EINPROGRESS
&&
537 (len
< ep
->maxpacket
||
538 urb
->actual_length
==
539 urb
->transfer_buffer_length
)) {
540 if (usb_pipecontrol(urb
->pipe
))
541 ep
->nextpid
= USB_PID_ACK
;
547 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
548 if (urb
->transfer_buffer_length
== urb
->actual_length
)
549 ep
->nextpid
= USB_PID_ACK
;
550 else if (usb_pipeout(urb
->pipe
)) {
551 usb_settoggle(udev
, 0, 1, 1);
552 ep
->nextpid
= USB_PID_OUT
;
554 usb_settoggle(udev
, 0, 0, 1);
555 ep
->nextpid
= USB_PID_IN
;
559 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
564 /* STALL stops all transfers */
565 } else if (status
& SL11H_STATMASK_STALL
) {
566 PACKET("...STALL_%02x qh%p\n", bank
, ep
);
567 ep
->nak_count
= ep
->error_count
= 0;
570 /* error? retry, until "3 strikes" */
571 } else if (++ep
->error_count
>= 3) {
572 if (status
& SL11H_STATMASK_TMOUT
)
574 else if (status
& SL11H_STATMASK_OVF
)
575 urbstat
= -EOVERFLOW
;
579 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
580 bank
, status
, ep
, urbstat
);
583 if (urbstat
!= -EINPROGRESS
|| urb
->unlinked
)
584 finish_request(sl811
, ep
, urb
, urbstat
);
587 static inline u8
checkdone(struct sl811
*sl811
)
592 if (sl811
->active_a
&& time_before_eq(sl811
->jiffies_a
, jiffies
)) {
593 ctl
= sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
));
594 if (ctl
& SL11H_HCTLMASK_ARM
)
595 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
596 DBG("%s DONE_A: ctrl %02x sts %02x\n",
597 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
599 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
600 irqstat
|= SL11H_INTMASK_DONE_A
;
603 if (sl811
->active_b
&& time_before_eq(sl811
->jiffies_b
, jiffies
)) {
604 ctl
= sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
));
605 if (ctl
& SL11H_HCTLMASK_ARM
)
606 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
607 DBG("%s DONE_B: ctrl %02x sts %02x\n",
608 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
610 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
611 irqstat
|= SL11H_INTMASK_DONE_A
;
617 static irqreturn_t
sl811h_irq(struct usb_hcd
*hcd
)
619 struct sl811
*sl811
= hcd_to_sl811(hcd
);
621 irqreturn_t ret
= IRQ_NONE
;
622 unsigned retries
= 5;
624 spin_lock(&sl811
->lock
);
627 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
) & ~SL11H_INTMASK_DP
;
629 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
630 irqstat
&= sl811
->irq_enable
;
634 /* this may no longer be necessary ... */
636 irqstat
= checkdone(sl811
);
642 /* USB packets, not necessarily handled in the order they're
643 * issued ... that's fine if they're different endpoints.
645 if (irqstat
& SL11H_INTMASK_DONE_A
) {
646 done(sl811
, sl811
->active_a
, SL811_EP_A(SL811_HOST_BUF
));
647 sl811
->active_a
= NULL
;
651 if (irqstat
& SL11H_INTMASK_DONE_B
) {
652 done(sl811
, sl811
->active_b
, SL811_EP_B(SL811_HOST_BUF
));
653 sl811
->active_b
= NULL
;
657 if (irqstat
& SL11H_INTMASK_SOFINTR
) {
660 index
= sl811
->frame
++ % (PERIODIC_SIZE
- 1);
663 /* be graceful about almost-inevitable periodic schedule
664 * overruns: continue the previous frame's transfers iff
665 * this one has nothing scheduled.
667 if (sl811
->next_periodic
) {
668 // ERR("overrun to slot %d\n", index);
669 sl811
->stat_overrun
++;
671 if (sl811
->periodic
[index
])
672 sl811
->next_periodic
= sl811
->periodic
[index
];
675 /* khubd manages debouncing and wakeup */
676 if (irqstat
& SL11H_INTMASK_INSRMV
) {
677 sl811
->stat_insrmv
++;
679 /* most stats are reset for each VBUS session */
680 sl811
->stat_wake
= 0;
684 sl811
->stat_lost
= 0;
687 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
689 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
690 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
692 /* usbcore nukes other pending transactions on disconnect */
693 if (sl811
->active_a
) {
694 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
695 finish_request(sl811
, sl811
->active_a
,
696 container_of(sl811
->active_a
697 ->hep
->urb_list
.next
,
698 struct urb
, urb_list
),
700 sl811
->active_a
= NULL
;
703 if (sl811
->active_b
) {
704 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
705 finish_request(sl811
, sl811
->active_b
,
706 container_of(sl811
->active_b
707 ->hep
->urb_list
.next
,
708 struct urb
, urb_list
),
710 sl811
->active_b
= NULL
;
714 /* port status seems weird until after reset, so
715 * force the reset and make khubd clean up later.
717 if (irqstat
& SL11H_INTMASK_RD
)
718 sl811
->port1
&= ~USB_PORT_STAT_CONNECTION
;
720 sl811
->port1
|= USB_PORT_STAT_CONNECTION
;
722 sl811
->port1
|= USB_PORT_STAT_C_CONNECTION
<< 16;
724 } else if (irqstat
& SL11H_INTMASK_RD
) {
725 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
) {
727 sl811
->port1
|= USB_PORT_STAT_C_SUSPEND
<< 16;
730 irqstat
&= ~SL11H_INTMASK_RD
;
734 if (sl811
->port1
& USB_PORT_STAT_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
;
804 #ifndef CONFIG_USB_SL811_HCD_ISO
805 if (type
== PIPE_ISOCHRONOUS
)
809 /* avoid all allocations within spinlocks */
811 ep
= kzalloc(sizeof *ep
, mem_flags
);
816 spin_lock_irqsave(&sl811
->lock
, flags
);
818 /* don't submit to a dead or disabled port */
819 if (!(sl811
->port1
& USB_PORT_STAT_ENABLE
)
820 || !HC_IS_RUNNING(hcd
->state
)) {
823 goto fail_not_linked
;
825 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
828 goto fail_not_linked
;
839 INIT_LIST_HEAD(&ep
->schedule
);
842 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
843 ep
->defctrl
= SL11H_HCTLMASK_ARM
| SL11H_HCTLMASK_ENABLE
;
844 usb_settoggle(udev
, epnum
, is_out
, 0);
846 if (type
== PIPE_CONTROL
)
847 ep
->nextpid
= USB_PID_SETUP
;
849 ep
->nextpid
= USB_PID_OUT
;
851 ep
->nextpid
= USB_PID_IN
;
853 if (ep
->maxpacket
> H_MAXPACKET
) {
854 /* iso packets up to 240 bytes could work... */
855 DBG("dev %d ep%d maxpacket %d\n",
856 udev
->devnum
, epnum
, ep
->maxpacket
);
862 if (udev
->speed
== USB_SPEED_LOW
) {
863 /* send preamble for external hub? */
864 if (!(sl811
->ctrl1
& SL11H_CTL1MASK_LSPD
))
865 ep
->defctrl
|= SL11H_HCTLMASK_PREAMBLE
;
868 case PIPE_ISOCHRONOUS
:
870 if (urb
->interval
> PERIODIC_SIZE
)
871 urb
->interval
= PERIODIC_SIZE
;
872 ep
->period
= urb
->interval
;
873 ep
->branch
= PERIODIC_SIZE
;
874 if (type
== PIPE_ISOCHRONOUS
)
875 ep
->defctrl
|= SL11H_HCTLMASK_ISOCH
;
876 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
877 (type
== PIPE_ISOCHRONOUS
),
878 usb_maxpacket(udev
, pipe
, is_out
))
887 /* maybe put endpoint into schedule */
891 if (list_empty(&ep
->schedule
))
892 list_add_tail(&ep
->schedule
, &sl811
->async
);
894 case PIPE_ISOCHRONOUS
:
896 urb
->interval
= ep
->period
;
897 if (ep
->branch
< PERIODIC_SIZE
) {
898 /* NOTE: the phase is correct here, but the value
899 * needs offsetting by the transfer queue depth.
900 * All current drivers ignore start_frame, so this
901 * is unlikely to ever matter...
903 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
908 retval
= balance(sl811
, ep
->period
, ep
->load
);
913 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
916 /* sort each schedule branch by period (slow before fast)
917 * to share the faster parts of the tree without needing
918 * dummy/placeholder nodes
920 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
921 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
922 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
923 struct sl811h_ep
*here
= *prev
;
925 while (here
&& ep
!= here
) {
926 if (ep
->period
> here
->period
)
935 sl811
->load
[i
] += ep
->load
;
937 sl811
->periodic_count
++;
938 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
943 start_transfer(sl811
);
944 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
947 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
949 spin_unlock_irqrestore(&sl811
->lock
, flags
);
953 static int sl811h_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
955 struct sl811
*sl811
= hcd_to_sl811(hcd
);
956 struct usb_host_endpoint
*hep
;
958 struct sl811h_ep
*ep
;
961 spin_lock_irqsave(&sl811
->lock
, flags
);
962 retval
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
969 /* finish right away if this urb can't be active ...
970 * note that some drivers wrongly expect delays
972 if (ep
->hep
->urb_list
.next
!= &urb
->urb_list
) {
973 /* not front of queue? never active */
975 /* for active transfers, we expect an IRQ */
976 } else if (sl811
->active_a
== ep
) {
977 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
978 /* happens a lot with lowspeed?? */
979 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
981 SL811_EP_A(SL11H_HOSTCTLREG
)),
983 SL811_EP_A(SL11H_PKTSTATREG
)));
984 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
986 sl811
->active_a
= NULL
;
990 } else if (sl811
->active_b
== ep
) {
991 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
992 /* happens a lot with lowspeed?? */
993 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
995 SL811_EP_B(SL11H_HOSTCTLREG
)),
997 SL811_EP_B(SL11H_PKTSTATREG
)));
998 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
),
1000 sl811
->active_b
= NULL
;
1005 /* front of queue for inactive endpoint */
1009 finish_request(sl811
, ep
, urb
, 0);
1011 VDBG("dequeue, urb %p active %s; wait4irq\n", urb
,
1012 (sl811
->active_a
== ep
) ? "A" : "B");
1016 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1021 sl811h_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*hep
)
1023 struct sl811h_ep
*ep
= hep
->hcpriv
;
1028 /* assume we'd just wait for the irq */
1029 if (!list_empty(&hep
->urb_list
))
1031 if (!list_empty(&hep
->urb_list
))
1032 WARNING("ep %p not empty?\n", ep
);
1039 sl811h_get_frame(struct usb_hcd
*hcd
)
1041 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1043 /* wrong except while periodic transfers are scheduled;
1044 * never matches the on-the-wire frame;
1045 * subject to overruns.
1047 return sl811
->frame
;
1051 /*-------------------------------------------------------------------------*/
1053 /* the virtual root hub timer IRQ checks for hub status */
1055 sl811h_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1057 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1059 unsigned long flags
;
1061 /* non-SMP HACK: use root hub timer as i/o watchdog
1062 * this seems essential when SOF IRQs aren't in use...
1064 local_irq_save(flags
);
1065 if (!timer_pending(&sl811
->timer
)) {
1066 if (sl811h_irq( /* ~0, */ hcd
) != IRQ_NONE
)
1069 local_irq_restore(flags
);
1072 if (!(sl811
->port1
& (0xffff << 16)))
1075 /* tell khubd port 1 changed */
1081 sl811h_hub_descriptor (
1082 struct sl811
*sl811
,
1083 struct usb_hub_descriptor
*desc
1087 desc
->bDescriptorType
= 0x29;
1088 desc
->bHubContrCurrent
= 0;
1090 desc
->bNbrPorts
= 1;
1091 desc
->bDescLength
= 9;
1093 /* per-port power switching (gang of one!), or none */
1094 desc
->bPwrOn2PwrGood
= 0;
1095 if (sl811
->board
&& sl811
->board
->port_power
) {
1096 desc
->bPwrOn2PwrGood
= sl811
->board
->potpg
;
1097 if (!desc
->bPwrOn2PwrGood
)
1098 desc
->bPwrOn2PwrGood
= 10;
1103 /* no overcurrent errors detection/handling */
1106 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
1108 /* ports removable, and legacy PortPwrCtrlMask */
1109 desc
->u
.hs
.DeviceRemovable
[0] = 0 << 1;
1110 desc
->u
.hs
.DeviceRemovable
[1] = ~0;
1114 sl811h_timer(unsigned long _sl811
)
1116 struct sl811
*sl811
= (void *) _sl811
;
1117 unsigned long flags
;
1119 u8 signaling
= sl811
->ctrl1
& SL11H_CTL1MASK_FORCE
;
1120 const u32 mask
= USB_PORT_STAT_CONNECTION
1121 | USB_PORT_STAT_ENABLE
1122 | USB_PORT_STAT_LOW_SPEED
;
1124 spin_lock_irqsave(&sl811
->lock
, flags
);
1126 /* stop special signaling */
1127 sl811
->ctrl1
&= ~SL11H_CTL1MASK_FORCE
;
1128 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1131 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
);
1133 switch (signaling
) {
1134 case SL11H_CTL1MASK_SE0
:
1136 sl811
->port1
= (USB_PORT_STAT_C_RESET
<< 16)
1137 | USB_PORT_STAT_POWER
;
1139 /* don't wrongly ack RD */
1140 if (irqstat
& SL11H_INTMASK_INSRMV
)
1141 irqstat
&= ~SL11H_INTMASK_RD
;
1143 case SL11H_CTL1MASK_K
:
1144 DBG("end resume\n");
1145 sl811
->port1
&= ~USB_PORT_STAT_SUSPEND
;
1148 DBG("odd timer signaling: %02x\n", signaling
);
1151 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
1153 if (irqstat
& SL11H_INTMASK_RD
) {
1154 /* usbcore nukes all pending transactions on disconnect */
1155 if (sl811
->port1
& USB_PORT_STAT_CONNECTION
)
1156 sl811
->port1
|= (USB_PORT_STAT_C_CONNECTION
<< 16)
1157 | (USB_PORT_STAT_C_ENABLE
<< 16);
1158 sl811
->port1
&= ~mask
;
1159 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1161 sl811
->port1
|= mask
;
1162 if (irqstat
& SL11H_INTMASK_DP
)
1163 sl811
->port1
&= ~USB_PORT_STAT_LOW_SPEED
;
1164 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
| SL11H_INTMASK_RD
;
1167 if (sl811
->port1
& USB_PORT_STAT_CONNECTION
) {
1168 u8 ctrl2
= SL811HS_CTL2_INIT
;
1170 sl811
->irq_enable
|= SL11H_INTMASK_DONE_A
;
1172 sl811
->irq_enable
|= SL11H_INTMASK_DONE_B
;
1174 if (sl811
->port1
& USB_PORT_STAT_LOW_SPEED
) {
1175 sl811
->ctrl1
|= SL11H_CTL1MASK_LSPD
;
1176 ctrl2
|= SL811HS_CTL2MASK_DSWAP
;
1179 /* start SOFs flowing, kickstarting with A registers */
1180 sl811
->ctrl1
|= SL11H_CTL1MASK_SOF_ENA
;
1181 sl811_write(sl811
, SL11H_SOFLOWREG
, 0xe0);
1182 sl811_write(sl811
, SL811HS_CTLREG2
, ctrl2
);
1184 /* autoincrementing */
1185 sl811_write(sl811
, SL811_EP_A(SL11H_BUFLNTHREG
), 0);
1186 writeb(SL_SOF
, sl811
->data_reg
);
1187 writeb(0, sl811
->data_reg
);
1188 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1189 SL11H_HCTLMASK_ARM
);
1191 /* khubd provides debounce delay */
1195 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1198 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
1199 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1204 struct usb_hcd
*hcd
,
1211 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1213 unsigned long flags
;
1215 spin_lock_irqsave(&sl811
->lock
, flags
);
1218 case ClearHubFeature
:
1221 case C_HUB_OVER_CURRENT
:
1222 case C_HUB_LOCAL_POWER
:
1228 case ClearPortFeature
:
1229 if (wIndex
!= 1 || wLength
!= 0)
1233 case USB_PORT_FEAT_ENABLE
:
1234 sl811
->port1
&= USB_PORT_STAT_POWER
;
1236 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1237 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1238 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1241 case USB_PORT_FEAT_SUSPEND
:
1242 if (!(sl811
->port1
& USB_PORT_STAT_SUSPEND
))
1245 /* 20 msec of resume/K signaling, other irqs blocked */
1246 DBG("start resume...\n");
1247 sl811
->irq_enable
= 0;
1248 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1250 sl811
->ctrl1
|= SL11H_CTL1MASK_K
;
1251 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1253 mod_timer(&sl811
->timer
, jiffies
1254 + msecs_to_jiffies(20));
1256 case USB_PORT_FEAT_POWER
:
1257 port_power(sl811
, 0);
1259 case USB_PORT_FEAT_C_ENABLE
:
1260 case USB_PORT_FEAT_C_SUSPEND
:
1261 case USB_PORT_FEAT_C_CONNECTION
:
1262 case USB_PORT_FEAT_C_OVER_CURRENT
:
1263 case USB_PORT_FEAT_C_RESET
:
1268 sl811
->port1
&= ~(1 << wValue
);
1270 case GetHubDescriptor
:
1271 sl811h_hub_descriptor(sl811
, (struct usb_hub_descriptor
*) buf
);
1274 put_unaligned_le32(0, buf
);
1279 put_unaligned_le32(sl811
->port1
, buf
);
1282 if (*(u16
*)(buf
+2)) /* only if wPortChange is interesting */
1284 DBG("GetPortStatus %08x\n", sl811
->port1
);
1286 case SetPortFeature
:
1287 if (wIndex
!= 1 || wLength
!= 0)
1290 case USB_PORT_FEAT_SUSPEND
:
1291 if (sl811
->port1
& USB_PORT_STAT_RESET
)
1293 if (!(sl811
->port1
& USB_PORT_STAT_ENABLE
))
1296 DBG("suspend...\n");
1297 sl811
->ctrl1
&= ~SL11H_CTL1MASK_SOF_ENA
;
1298 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1300 case USB_PORT_FEAT_POWER
:
1301 port_power(sl811
, 1);
1303 case USB_PORT_FEAT_RESET
:
1304 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
)
1306 if (!(sl811
->port1
& USB_PORT_STAT_POWER
))
1309 /* 50 msec of reset/SE0 signaling, irqs blocked */
1310 sl811
->irq_enable
= 0;
1311 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1313 sl811
->ctrl1
= SL11H_CTL1MASK_SE0
;
1314 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1315 sl811
->port1
|= USB_PORT_STAT_RESET
;
1316 mod_timer(&sl811
->timer
, jiffies
1317 + msecs_to_jiffies(50));
1322 sl811
->port1
|= 1 << wValue
;
1327 /* "protocol stall" on error */
1331 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1338 sl811h_bus_suspend(struct usb_hcd
*hcd
)
1341 DBG("%s\n", __func__
);
1346 sl811h_bus_resume(struct usb_hcd
*hcd
)
1349 DBG("%s\n", __func__
);
1355 #define sl811h_bus_suspend NULL
1356 #define sl811h_bus_resume NULL
1361 /*-------------------------------------------------------------------------*/
1363 #ifdef STUB_DEBUG_FILE
1365 static inline void create_debug_file(struct sl811
*sl811
) { }
1366 static inline void remove_debug_file(struct sl811
*sl811
) { }
1370 #include <linux/proc_fs.h>
1371 #include <linux/seq_file.h>
1373 static void dump_irq(struct seq_file
*s
, char *label
, u8 mask
)
1375 seq_printf(s
, "%s %02x%s%s%s%s%s%s\n", label
, mask
,
1376 (mask
& SL11H_INTMASK_DONE_A
) ? " done_a" : "",
1377 (mask
& SL11H_INTMASK_DONE_B
) ? " done_b" : "",
1378 (mask
& SL11H_INTMASK_SOFINTR
) ? " sof" : "",
1379 (mask
& SL11H_INTMASK_INSRMV
) ? " ins/rmv" : "",
1380 (mask
& SL11H_INTMASK_RD
) ? " rd" : "",
1381 (mask
& SL11H_INTMASK_DP
) ? " dp" : "");
1384 static int proc_sl811h_show(struct seq_file
*s
, void *unused
)
1386 struct sl811
*sl811
= s
->private;
1387 struct sl811h_ep
*ep
;
1390 seq_printf(s
, "%s\n%s version %s\nportstatus[1] = %08x\n",
1391 sl811_to_hcd(sl811
)->product_desc
,
1392 hcd_name
, DRIVER_VERSION
,
1395 seq_printf(s
, "insert/remove: %ld\n", sl811
->stat_insrmv
);
1396 seq_printf(s
, "current session: done_a %ld done_b %ld "
1397 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1398 sl811
->stat_a
, sl811
->stat_b
,
1399 sl811
->stat_wake
, sl811
->stat_sof
,
1400 sl811
->stat_overrun
, sl811
->stat_lost
);
1402 spin_lock_irq(&sl811
->lock
);
1404 if (sl811
->ctrl1
& SL11H_CTL1MASK_SUSPEND
)
1405 seq_printf(s
, "(suspended)\n\n");
1407 u8 t
= sl811_read(sl811
, SL11H_CTLREG1
);
1409 seq_printf(s
, "ctrl1 %02x%s%s%s%s\n", t
,
1410 (t
& SL11H_CTL1MASK_SOF_ENA
) ? " sofgen" : "",
1411 ({char *s
; switch (t
& SL11H_CTL1MASK_FORCE
) {
1412 case SL11H_CTL1MASK_NORMAL
: s
= ""; break;
1413 case SL11H_CTL1MASK_SE0
: s
= " se0/reset"; break;
1414 case SL11H_CTL1MASK_K
: s
= " k/resume"; break;
1415 default: s
= "j"; break;
1417 (t
& SL11H_CTL1MASK_LSPD
) ? " lowspeed" : "",
1418 (t
& SL11H_CTL1MASK_SUSPEND
) ? " suspend" : "");
1420 dump_irq(s
, "irq_enable",
1421 sl811_read(sl811
, SL11H_IRQ_ENABLE
));
1422 dump_irq(s
, "irq_status",
1423 sl811_read(sl811
, SL11H_IRQ_STATUS
));
1424 seq_printf(s
, "frame clocks remaining: %d\n",
1425 sl811_read(sl811
, SL11H_SOFTMRREG
) << 6);
1428 seq_printf(s
, "A: qh%p ctl %02x sts %02x\n", sl811
->active_a
,
1429 sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
)),
1430 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
1431 seq_printf(s
, "B: qh%p ctl %02x sts %02x\n", sl811
->active_b
,
1432 sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
)),
1433 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
1434 seq_printf(s
, "\n");
1435 list_for_each_entry (ep
, &sl811
->async
, schedule
) {
1438 seq_printf(s
, "%s%sqh%p, ep%d%s, maxpacket %d"
1440 (ep
== sl811
->active_a
) ? "(A) " : "",
1441 (ep
== sl811
->active_b
) ? "(B) " : "",
1443 ({ char *s
; switch (ep
->nextpid
) {
1444 case USB_PID_IN
: s
= "in"; break;
1445 case USB_PID_OUT
: s
= "out"; break;
1446 case USB_PID_SETUP
: s
= "setup"; break;
1447 case USB_PID_ACK
: s
= "status"; break;
1448 default: s
= "?"; break;
1451 ep
->nak_count
, ep
->error_count
);
1452 list_for_each_entry (urb
, &ep
->hep
->urb_list
, urb_list
) {
1453 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1455 urb
->transfer_buffer_length
);
1458 if (!list_empty(&sl811
->async
))
1459 seq_printf(s
, "\n");
1461 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1463 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1464 ep
= sl811
->periodic
[i
];
1467 seq_printf(s
, "%2d [%3d]:\n", i
, sl811
->load
[i
]);
1469 /* DUMB: prints shared entries multiple times */
1472 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1474 (ep
== sl811
->active_a
) ? "(A) " : "",
1475 (ep
== sl811
->active_b
) ? "(B) " : "",
1477 (ep
->udev
->speed
== USB_SPEED_FULL
)
1479 ep
->udev
->devnum
, ep
->epnum
,
1480 (ep
->epnum
== 0) ? ""
1481 : ((ep
->nextpid
== USB_PID_IN
)
1484 ep
->maxpacket
, ep
->error_count
);
1489 spin_unlock_irq(&sl811
->lock
);
1490 seq_printf(s
, "\n");
1495 static int proc_sl811h_open(struct inode
*inode
, struct file
*file
)
1497 return single_open(file
, proc_sl811h_show
, PDE(inode
)->data
);
1500 static const struct file_operations proc_ops
= {
1501 .open
= proc_sl811h_open
,
1503 .llseek
= seq_lseek
,
1504 .release
= single_release
,
1507 /* expect just one sl811 per system */
1508 static const char proc_filename
[] = "driver/sl811h";
1510 static void create_debug_file(struct sl811
*sl811
)
1512 sl811
->pde
= proc_create_data(proc_filename
, 0, NULL
, &proc_ops
, sl811
);
1515 static void remove_debug_file(struct sl811
*sl811
)
1518 remove_proc_entry(proc_filename
, NULL
);
1523 /*-------------------------------------------------------------------------*/
1526 sl811h_stop(struct usb_hcd
*hcd
)
1528 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1529 unsigned long flags
;
1531 del_timer_sync(&hcd
->rh_timer
);
1533 spin_lock_irqsave(&sl811
->lock
, flags
);
1534 port_power(sl811
, 0);
1535 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1539 sl811h_start(struct usb_hcd
*hcd
)
1541 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1543 /* chip has been reset, VBUS power is off */
1544 hcd
->state
= HC_STATE_RUNNING
;
1547 if (!device_can_wakeup(hcd
->self
.controller
))
1548 device_init_wakeup(hcd
->self
.controller
,
1549 sl811
->board
->can_wakeup
);
1550 hcd
->power_budget
= sl811
->board
->power
* 2;
1553 /* enable power and interrupts */
1554 port_power(sl811
, 1);
1559 /*-------------------------------------------------------------------------*/
1561 static struct hc_driver sl811h_hc_driver
= {
1562 .description
= hcd_name
,
1563 .hcd_priv_size
= sizeof(struct sl811
),
1566 * generic hardware linkage
1569 .flags
= HCD_USB11
| HCD_MEMORY
,
1571 /* Basic lifecycle operations */
1572 .start
= sl811h_start
,
1573 .stop
= sl811h_stop
,
1576 * managing i/o requests and associated device resources
1578 .urb_enqueue
= sl811h_urb_enqueue
,
1579 .urb_dequeue
= sl811h_urb_dequeue
,
1580 .endpoint_disable
= sl811h_endpoint_disable
,
1583 * periodic schedule support
1585 .get_frame_number
= sl811h_get_frame
,
1590 .hub_status_data
= sl811h_hub_status_data
,
1591 .hub_control
= sl811h_hub_control
,
1592 .bus_suspend
= sl811h_bus_suspend
,
1593 .bus_resume
= sl811h_bus_resume
,
1596 /*-------------------------------------------------------------------------*/
1598 static int __devexit
1599 sl811h_remove(struct platform_device
*dev
)
1601 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1602 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1603 struct resource
*res
;
1605 remove_debug_file(sl811
);
1606 usb_remove_hcd(hcd
);
1608 /* some platforms may use IORESOURCE_IO */
1609 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1611 iounmap(sl811
->data_reg
);
1613 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1615 iounmap(sl811
->addr_reg
);
1621 static int __devinit
1622 sl811h_probe(struct platform_device
*dev
)
1624 struct usb_hcd
*hcd
;
1625 struct sl811
*sl811
;
1626 struct resource
*addr
, *data
, *ires
;
1628 void __iomem
*addr_reg
;
1629 void __iomem
*data_reg
;
1632 unsigned long irqflags
;
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 ires
= platform_get_resource(dev
, IORESOURCE_IRQ
, 0);
1643 if (dev
->num_resources
< 3 || !ires
)
1647 irqflags
= ires
->flags
& IRQF_TRIGGER_MASK
;
1649 /* refuse to confuse usbcore */
1650 if (dev
->dev
.dma_mask
) {
1651 DBG("no we won't dma\n");
1655 /* the chip may be wired for either kind of addressing */
1656 addr
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1657 data
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1659 if (!addr
|| !data
) {
1660 addr
= platform_get_resource(dev
, IORESOURCE_IO
, 0);
1661 data
= platform_get_resource(dev
, IORESOURCE_IO
, 1);
1666 * NOTE: 64-bit resource->start is getting truncated
1667 * to avoid compiler warning, assuming that ->start
1668 * is always 32-bit for this case
1670 addr_reg
= (void __iomem
*) (unsigned long) addr
->start
;
1671 data_reg
= (void __iomem
*) (unsigned long) data
->start
;
1673 addr_reg
= ioremap(addr
->start
, 1);
1674 if (addr_reg
== NULL
) {
1679 data_reg
= ioremap(data
->start
, 1);
1680 if (data_reg
== NULL
) {
1686 /* allocate and initialize hcd */
1687 hcd
= usb_create_hcd(&sl811h_hc_driver
, &dev
->dev
, dev_name(&dev
->dev
));
1692 hcd
->rsrc_start
= addr
->start
;
1693 sl811
= hcd_to_sl811(hcd
);
1695 spin_lock_init(&sl811
->lock
);
1696 INIT_LIST_HEAD(&sl811
->async
);
1697 sl811
->board
= dev
->dev
.platform_data
;
1698 init_timer(&sl811
->timer
);
1699 sl811
->timer
.function
= sl811h_timer
;
1700 sl811
->timer
.data
= (unsigned long) sl811
;
1701 sl811
->addr_reg
= addr_reg
;
1702 sl811
->data_reg
= data_reg
;
1704 spin_lock_irq(&sl811
->lock
);
1705 port_power(sl811
, 0);
1706 spin_unlock_irq(&sl811
->lock
);
1709 tmp
= sl811_read(sl811
, SL11H_HWREVREG
);
1712 hcd
->product_desc
= "SL811HS v1.2";
1715 hcd
->product_desc
= "SL811HS v1.5";
1718 /* reject case 0, SL11S is less functional */
1719 DBG("chiprev %02x\n", tmp
);
1724 /* The chip's IRQ is level triggered, active high. A requirement
1725 * for platform device setup is to cope with things like signal
1726 * inverters (e.g. CF is active low) or working only with edge
1727 * triggers (e.g. most ARM CPUs). Initial driver stress testing
1728 * was on a system with single edge triggering, so most sorts of
1729 * triggering arrangement should work.
1731 * Use resource IRQ flags if set by platform device setup.
1733 irqflags
|= IRQF_SHARED
;
1734 retval
= usb_add_hcd(hcd
, irq
, irqflags
);
1738 create_debug_file(sl811
);
1750 DBG("init error, %d\n", retval
);
1756 /* for this device there's no useful distinction between the controller
1757 * and its root hub, except that the root hub only gets direct PM calls
1758 * when CONFIG_USB_SUSPEND is enabled.
1762 sl811h_suspend(struct platform_device
*dev
, pm_message_t state
)
1764 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1765 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1768 switch (state
.event
) {
1769 case PM_EVENT_FREEZE
:
1770 retval
= sl811h_bus_suspend(hcd
);
1772 case PM_EVENT_SUSPEND
:
1773 case PM_EVENT_HIBERNATE
:
1774 case PM_EVENT_PRETHAW
: /* explicitly discard hw state */
1775 port_power(sl811
, 0);
1782 sl811h_resume(struct platform_device
*dev
)
1784 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1785 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1787 /* with no "check to see if VBUS is still powered" board hook,
1788 * let's assume it'd only be powered to enable remote wakeup.
1790 if (!sl811
->port1
|| !device_can_wakeup(&hcd
->self
.root_hub
->dev
)) {
1792 port_power(sl811
, 1);
1793 usb_root_hub_lost_power(hcd
->self
.root_hub
);
1797 return sl811h_bus_resume(hcd
);
1802 #define sl811h_suspend NULL
1803 #define sl811h_resume NULL
1808 /* this driver is exported so sl811_cs can depend on it */
1809 struct platform_driver sl811h_driver
= {
1810 .probe
= sl811h_probe
,
1811 .remove
= __devexit_p(sl811h_remove
),
1813 .suspend
= sl811h_suspend
,
1814 .resume
= sl811h_resume
,
1816 .name
= (char *) hcd_name
,
1817 .owner
= THIS_MODULE
,
1820 EXPORT_SYMBOL(sl811h_driver
);
1822 module_platform_driver(sl811h_driver
);