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>
53 #include <asm/system.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 */
74 /* this doesn't understand urb->iso_frame_desc[], but if you had a driver
75 * that just queued one ISO frame per URB then iso transfers "should" work
76 * using the normal urb status fields.
83 static const char hcd_name
[] = "sl811-hcd";
85 /*-------------------------------------------------------------------------*/
87 static void port_power(struct sl811
*sl811
, int is_on
)
89 struct usb_hcd
*hcd
= sl811_to_hcd(sl811
);
91 /* hub is inactive unless the port is powered */
93 if (sl811
->port1
& USB_PORT_STAT_POWER
)
96 sl811
->port1
= USB_PORT_STAT_POWER
;
97 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
100 sl811
->irq_enable
= 0;
101 hcd
->state
= HC_STATE_HALT
;
104 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
105 sl811_write(sl811
, SL11H_IRQ_STATUS
, ~0);
107 if (sl811
->board
&& sl811
->board
->port_power
) {
108 /* switch VBUS, at 500mA unless hub power budget gets set */
109 DBG("power %s\n", is_on
? "on" : "off");
110 sl811
->board
->port_power(hcd
->self
.controller
, is_on
);
113 /* reset as thoroughly as we can */
114 if (sl811
->board
&& sl811
->board
->reset
)
115 sl811
->board
->reset(hcd
->self
.controller
);
117 sl811_write(sl811
, SL11H_CTLREG1
, SL11H_CTL1MASK_SE0
);
121 sl811_write(sl811
, SL11H_IRQ_ENABLE
, 0);
122 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
123 sl811_write(sl811
, SL811HS_CTLREG2
, SL811HS_CTL2_INIT
);
124 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
126 // if !is_on, put into lowpower mode now
129 /*-------------------------------------------------------------------------*/
131 /* This is a PIO-only HCD. Queueing appends URBs to the endpoint's queue,
132 * and may start I/O. Endpoint queues are scanned during completion irq
133 * handlers (one per packet: ACK, NAK, faults, etc) and urb cancellation.
135 * Using an external DMA engine to copy a packet at a time could work,
136 * though setup/teardown costs may be too big to make it worthwhile.
139 /* SETUP starts a new control request. Devices are not allowed to
140 * STALL or NAK these; they must cancel any pending control requests.
142 static void setup_packet(
144 struct sl811h_ep
*ep
,
152 void __iomem
*data_reg
;
154 addr
= SL811HS_PACKET_BUF(bank
== 0);
155 len
= sizeof(struct usb_ctrlrequest
);
156 data_reg
= sl811
->data_reg
;
157 sl811_write_buf(sl811
, addr
, urb
->setup_packet
, len
);
159 /* autoincrementing */
160 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
161 writeb(len
, data_reg
);
162 writeb(SL_SETUP
/* | ep->epnum */, data_reg
);
163 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
165 /* always OUT/data0 */ ;
166 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
167 control
| SL11H_HCTLMASK_OUT
);
169 PACKET("SETUP qh%p\n", ep
);
172 /* STATUS finishes control requests, often after IN or OUT data packets */
173 static void status_packet(
175 struct sl811h_ep
*ep
,
182 void __iomem
*data_reg
;
184 do_out
= urb
->transfer_buffer_length
&& usb_pipein(urb
->pipe
);
185 data_reg
= sl811
->data_reg
;
187 /* autoincrementing */
188 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, 0);
190 writeb((do_out
? SL_OUT
: SL_IN
) /* | ep->epnum */, data_reg
);
191 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
193 /* always data1; sometimes IN */
194 control
|= SL11H_HCTLMASK_TOGGLE
;
196 control
|= SL11H_HCTLMASK_OUT
;
197 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
199 PACKET("STATUS%s/%s qh%p\n", ep
->nak_count
? "/retry" : "",
200 do_out
? "out" : "in", ep
);
203 /* IN packets can be used with any type of endpoint. here we just
204 * start the transfer, data from the peripheral may arrive later.
205 * urb->iso_frame_desc is currently ignored here...
207 static void in_packet(
209 struct sl811h_ep
*ep
,
217 void __iomem
*data_reg
;
219 /* avoid losing data on overflow */
221 addr
= SL811HS_PACKET_BUF(bank
== 0);
222 if (!(control
& SL11H_HCTLMASK_ISOCH
)
223 && usb_gettoggle(urb
->dev
, ep
->epnum
, 0))
224 control
|= SL11H_HCTLMASK_TOGGLE
;
225 data_reg
= sl811
->data_reg
;
227 /* autoincrementing */
228 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
229 writeb(len
, data_reg
);
230 writeb(SL_IN
| ep
->epnum
, data_reg
);
231 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
233 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
, control
);
234 ep
->length
= min_t(u32
, len
,
235 urb
->transfer_buffer_length
- urb
->actual_length
);
236 PACKET("IN%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
237 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 0), ep
, len
);
240 /* OUT packets can be used with any type of endpoint.
241 * urb->iso_frame_desc is currently ignored here...
243 static void out_packet(
245 struct sl811h_ep
*ep
,
254 void __iomem
*data_reg
;
256 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
259 len
= min_t(u32
, ep
->maxpacket
,
260 urb
->transfer_buffer_length
- urb
->actual_length
);
262 if (!(control
& SL11H_HCTLMASK_ISOCH
)
263 && usb_gettoggle(urb
->dev
, ep
->epnum
, 1))
264 control
|= SL11H_HCTLMASK_TOGGLE
;
265 addr
= SL811HS_PACKET_BUF(bank
== 0);
266 data_reg
= sl811
->data_reg
;
268 sl811_write_buf(sl811
, addr
, buf
, len
);
270 /* autoincrementing */
271 sl811_write(sl811
, bank
+ SL11H_BUFADDRREG
, addr
);
272 writeb(len
, data_reg
);
273 writeb(SL_OUT
| ep
->epnum
, data_reg
);
274 writeb(usb_pipedevice(urb
->pipe
), data_reg
);
276 sl811_write(sl811
, bank
+ SL11H_HOSTCTLREG
,
277 control
| SL11H_HCTLMASK_OUT
);
279 PACKET("OUT%s/%d qh%p len%d\n", ep
->nak_count
? "/retry" : "",
280 !!usb_gettoggle(urb
->dev
, ep
->epnum
, 1), ep
, len
);
283 /*-------------------------------------------------------------------------*/
285 /* caller updates on-chip enables later */
287 static inline void sofirq_on(struct sl811
*sl811
)
289 if (sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
)
291 VDBG("sof irq on\n");
292 sl811
->irq_enable
|= SL11H_INTMASK_SOFINTR
;
295 static inline void sofirq_off(struct sl811
*sl811
)
297 if (!(sl811
->irq_enable
& SL11H_INTMASK_SOFINTR
))
299 VDBG("sof irq off\n");
300 sl811
->irq_enable
&= ~SL11H_INTMASK_SOFINTR
;
303 /*-------------------------------------------------------------------------*/
305 /* pick the next endpoint for a transaction, and issue it.
306 * frames start with periodic transfers (after whatever is pending
307 * from the previous frame), and the rest of the time is async
308 * transfers, scheduled round-robin.
310 static struct sl811h_ep
*start(struct sl811
*sl811
, u8 bank
)
312 struct sl811h_ep
*ep
;
317 /* use endpoint at schedule head */
318 if (sl811
->next_periodic
) {
319 ep
= sl811
->next_periodic
;
320 sl811
->next_periodic
= ep
->next
;
322 if (sl811
->next_async
)
323 ep
= sl811
->next_async
;
324 else if (!list_empty(&sl811
->async
))
325 ep
= container_of(sl811
->async
.next
,
326 struct sl811h_ep
, schedule
);
328 /* could set up the first fullspeed periodic
329 * transfer for the next frame ...
335 if ((bank
&& sl811
->active_b
== ep
) || sl811
->active_a
== ep
)
339 if (ep
->schedule
.next
== &sl811
->async
)
340 sl811
->next_async
= NULL
;
342 sl811
->next_async
= container_of(ep
->schedule
.next
,
343 struct sl811h_ep
, schedule
);
346 if (unlikely(list_empty(&ep
->hep
->urb_list
))) {
347 DBG("empty %p queue?\n", ep
);
351 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
352 control
= ep
->defctrl
;
354 /* if this frame doesn't have enough time left to transfer this
355 * packet, wait till the next frame. too-simple algorithm...
357 fclock
= sl811_read(sl811
, SL11H_SOFTMRREG
) << 6;
358 fclock
-= 100; /* setup takes not much time */
359 if (urb
->dev
->speed
== USB_SPEED_LOW
) {
360 if (control
& SL11H_HCTLMASK_PREAMBLE
) {
361 /* also note erratum 1: some hubs won't work */
364 fclock
-= ep
->maxpacket
<< 8;
366 /* erratum 2: AFTERSOF only works for fullspeed */
369 sl811
->stat_overrun
++;
374 fclock
-= 12000 / 19; /* 19 64byte packets/msec */
377 sl811
->stat_overrun
++;
378 control
|= SL11H_HCTLMASK_AFTERSOF
;
380 /* throttle bulk/control irq noise */
381 } else if (ep
->nak_count
)
382 control
|= SL11H_HCTLMASK_AFTERSOF
;
386 switch (ep
->nextpid
) {
388 in_packet(sl811
, ep
, urb
, bank
, control
);
391 out_packet(sl811
, ep
, urb
, bank
, control
);
394 setup_packet(sl811
, ep
, urb
, bank
, control
);
396 case USB_PID_ACK
: /* for control status */
397 status_packet(sl811
, ep
, urb
, bank
, control
);
400 DBG("bad ep%p pid %02x\n", ep
, ep
->nextpid
);
406 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
408 static inline void start_transfer(struct sl811
*sl811
)
410 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
)
412 if (sl811
->active_a
== NULL
) {
413 sl811
->active_a
= start(sl811
, SL811_EP_A(SL811_HOST_BUF
));
414 if (sl811
->active_a
!= NULL
)
415 sl811
->jiffies_a
= jiffies
+ MIN_JIFFIES
;
418 if (sl811
->active_b
== NULL
) {
419 sl811
->active_b
= start(sl811
, SL811_EP_B(SL811_HOST_BUF
));
420 if (sl811
->active_b
!= NULL
)
421 sl811
->jiffies_b
= jiffies
+ MIN_JIFFIES
;
426 static void finish_request(
428 struct sl811h_ep
*ep
,
431 ) __releases(sl811
->lock
) __acquires(sl811
->lock
)
435 if (usb_pipecontrol(urb
->pipe
))
436 ep
->nextpid
= USB_PID_SETUP
;
438 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811
), urb
);
439 spin_unlock(&sl811
->lock
);
440 usb_hcd_giveback_urb(sl811_to_hcd(sl811
), urb
, status
);
441 spin_lock(&sl811
->lock
);
443 /* leave active endpoints in the schedule */
444 if (!list_empty(&ep
->hep
->urb_list
))
447 /* async deschedule? */
448 if (!list_empty(&ep
->schedule
)) {
449 list_del_init(&ep
->schedule
);
450 if (ep
== sl811
->next_async
)
451 sl811
->next_async
= NULL
;
455 /* periodic deschedule */
456 DBG("deschedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
457 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
458 struct sl811h_ep
*temp
;
459 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
461 while (*prev
&& ((temp
= *prev
) != ep
))
465 sl811
->load
[i
] -= ep
->load
;
467 ep
->branch
= PERIODIC_SIZE
;
468 sl811
->periodic_count
--;
469 sl811_to_hcd(sl811
)->self
.bandwidth_allocated
470 -= ep
->load
/ ep
->period
;
471 if (ep
== sl811
->next_periodic
)
472 sl811
->next_periodic
= ep
->next
;
474 /* we might turn SOFs back on again for the async schedule */
475 if (sl811
->periodic_count
== 0)
480 done(struct sl811
*sl811
, struct sl811h_ep
*ep
, u8 bank
)
484 int urbstat
= -EINPROGRESS
;
489 status
= sl811_read(sl811
, bank
+ SL11H_PKTSTATREG
);
491 urb
= container_of(ep
->hep
->urb_list
.next
, struct urb
, urb_list
);
493 /* we can safely ignore NAKs */
494 if (status
& SL11H_STATMASK_NAK
) {
495 // PACKET("...NAK_%02x qh%p\n", bank, ep);
500 /* ACK advances transfer, toggle, and maybe queue */
501 } else if (status
& SL11H_STATMASK_ACK
) {
502 struct usb_device
*udev
= urb
->dev
;
506 /* urb->iso_frame_desc is currently ignored here... */
508 ep
->nak_count
= ep
->error_count
= 0;
509 switch (ep
->nextpid
) {
511 // PACKET("...ACK/out_%02x qh%p\n", bank, ep);
512 urb
->actual_length
+= ep
->length
;
513 usb_dotoggle(udev
, ep
->epnum
, 1);
514 if (urb
->actual_length
515 == urb
->transfer_buffer_length
) {
516 if (usb_pipecontrol(urb
->pipe
))
517 ep
->nextpid
= USB_PID_ACK
;
519 /* some bulk protocols terminate OUT transfers
520 * by a short packet, using ZLPs not padding.
522 else if (ep
->length
< ep
->maxpacket
523 || !(urb
->transfer_flags
529 // PACKET("...ACK/in_%02x qh%p\n", bank, ep);
530 buf
= urb
->transfer_buffer
+ urb
->actual_length
;
532 len
= ep
->maxpacket
- sl811_read(sl811
,
533 bank
+ SL11H_XFERCNTREG
);
534 if (len
> ep
->length
) {
536 urbstat
= -EOVERFLOW
;
538 urb
->actual_length
+= len
;
539 sl811_read_buf(sl811
, SL811HS_PACKET_BUF(bank
== 0),
541 usb_dotoggle(udev
, ep
->epnum
, 0);
542 if (urbstat
== -EINPROGRESS
&&
543 (len
< ep
->maxpacket
||
544 urb
->actual_length
==
545 urb
->transfer_buffer_length
)) {
546 if (usb_pipecontrol(urb
->pipe
))
547 ep
->nextpid
= USB_PID_ACK
;
553 // PACKET("...ACK/setup_%02x qh%p\n", bank, ep);
554 if (urb
->transfer_buffer_length
== urb
->actual_length
)
555 ep
->nextpid
= USB_PID_ACK
;
556 else if (usb_pipeout(urb
->pipe
)) {
557 usb_settoggle(udev
, 0, 1, 1);
558 ep
->nextpid
= USB_PID_OUT
;
560 usb_settoggle(udev
, 0, 0, 1);
561 ep
->nextpid
= USB_PID_IN
;
565 // PACKET("...ACK/status_%02x qh%p\n", bank, ep);
570 /* STALL stops all transfers */
571 } else if (status
& SL11H_STATMASK_STALL
) {
572 PACKET("...STALL_%02x qh%p\n", bank
, ep
);
573 ep
->nak_count
= ep
->error_count
= 0;
576 /* error? retry, until "3 strikes" */
577 } else if (++ep
->error_count
>= 3) {
578 if (status
& SL11H_STATMASK_TMOUT
)
580 else if (status
& SL11H_STATMASK_OVF
)
581 urbstat
= -EOVERFLOW
;
585 PACKET("...3STRIKES_%02x %02x qh%p stat %d\n",
586 bank
, status
, ep
, urbstat
);
589 if (urbstat
!= -EINPROGRESS
|| urb
->unlinked
)
590 finish_request(sl811
, ep
, urb
, urbstat
);
593 static inline u8
checkdone(struct sl811
*sl811
)
598 if (sl811
->active_a
&& time_before_eq(sl811
->jiffies_a
, jiffies
)) {
599 ctl
= sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
));
600 if (ctl
& SL11H_HCTLMASK_ARM
)
601 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
602 DBG("%s DONE_A: ctrl %02x sts %02x\n",
603 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
605 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
606 irqstat
|= SL11H_INTMASK_DONE_A
;
609 if (sl811
->active_b
&& time_before_eq(sl811
->jiffies_b
, jiffies
)) {
610 ctl
= sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
));
611 if (ctl
& SL11H_HCTLMASK_ARM
)
612 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
613 DBG("%s DONE_B: ctrl %02x sts %02x\n",
614 (ctl
& SL11H_HCTLMASK_ARM
) ? "timeout" : "lost",
616 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
617 irqstat
|= SL11H_INTMASK_DONE_A
;
623 static irqreturn_t
sl811h_irq(struct usb_hcd
*hcd
)
625 struct sl811
*sl811
= hcd_to_sl811(hcd
);
627 irqreturn_t ret
= IRQ_NONE
;
628 unsigned retries
= 5;
630 spin_lock(&sl811
->lock
);
633 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
) & ~SL11H_INTMASK_DP
;
635 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
636 irqstat
&= sl811
->irq_enable
;
640 /* this may no longer be necessary ... */
642 irqstat
= checkdone(sl811
);
648 /* USB packets, not necessarily handled in the order they're
649 * issued ... that's fine if they're different endpoints.
651 if (irqstat
& SL11H_INTMASK_DONE_A
) {
652 done(sl811
, sl811
->active_a
, SL811_EP_A(SL811_HOST_BUF
));
653 sl811
->active_a
= NULL
;
657 if (irqstat
& SL11H_INTMASK_DONE_B
) {
658 done(sl811
, sl811
->active_b
, SL811_EP_B(SL811_HOST_BUF
));
659 sl811
->active_b
= NULL
;
663 if (irqstat
& SL11H_INTMASK_SOFINTR
) {
666 index
= sl811
->frame
++ % (PERIODIC_SIZE
- 1);
669 /* be graceful about almost-inevitable periodic schedule
670 * overruns: continue the previous frame's transfers iff
671 * this one has nothing scheduled.
673 if (sl811
->next_periodic
) {
674 // ERR("overrun to slot %d\n", index);
675 sl811
->stat_overrun
++;
677 if (sl811
->periodic
[index
])
678 sl811
->next_periodic
= sl811
->periodic
[index
];
681 /* khubd manages debouncing and wakeup */
682 if (irqstat
& SL11H_INTMASK_INSRMV
) {
683 sl811
->stat_insrmv
++;
685 /* most stats are reset for each VBUS session */
686 sl811
->stat_wake
= 0;
690 sl811
->stat_lost
= 0;
693 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
695 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
696 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
698 /* usbcore nukes other pending transactions on disconnect */
699 if (sl811
->active_a
) {
700 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
), 0);
701 finish_request(sl811
, sl811
->active_a
,
702 container_of(sl811
->active_a
703 ->hep
->urb_list
.next
,
704 struct urb
, urb_list
),
706 sl811
->active_a
= NULL
;
709 if (sl811
->active_b
) {
710 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
), 0);
711 finish_request(sl811
, sl811
->active_b
,
712 container_of(sl811
->active_b
713 ->hep
->urb_list
.next
,
714 struct urb
, urb_list
),
716 sl811
->active_b
= NULL
;
720 /* port status seems weird until after reset, so
721 * force the reset and make khubd clean up later.
723 if (irqstat
& SL11H_INTMASK_RD
)
724 sl811
->port1
&= ~USB_PORT_STAT_CONNECTION
;
726 sl811
->port1
|= USB_PORT_STAT_CONNECTION
;
728 sl811
->port1
|= USB_PORT_STAT_C_CONNECTION
<< 16;
730 } else if (irqstat
& SL11H_INTMASK_RD
) {
731 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
) {
733 sl811
->port1
|= USB_PORT_STAT_C_SUSPEND
<< 16;
736 irqstat
&= ~SL11H_INTMASK_RD
;
740 if (sl811
->port1
& USB_PORT_STAT_ENABLE
)
741 start_transfer(sl811
);
747 if (sl811
->periodic_count
== 0 && list_empty(&sl811
->async
))
749 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
751 spin_unlock(&sl811
->lock
);
756 /*-------------------------------------------------------------------------*/
758 /* usb 1.1 says max 90% of a frame is available for periodic transfers.
759 * this driver doesn't promise that much since it's got to handle an
760 * IRQ per packet; irq handling latencies also use up that time.
762 * NOTE: the periodic schedule is a sparse tree, with the load for
763 * each branch minimized. see fig 3.5 in the OHCI spec for example.
765 #define MAX_PERIODIC_LOAD 500 /* out of 1000 usec */
767 static int balance(struct sl811
*sl811
, u16 period
, u16 load
)
769 int i
, branch
= -ENOSPC
;
771 /* search for the least loaded schedule branch of that period
772 * which has enough bandwidth left unreserved.
774 for (i
= 0; i
< period
; i
++) {
775 if (branch
< 0 || sl811
->load
[branch
] > sl811
->load
[i
]) {
778 for (j
= i
; j
< PERIODIC_SIZE
; j
+= period
) {
779 if ((sl811
->load
[j
] + load
)
783 if (j
< PERIODIC_SIZE
)
791 /*-------------------------------------------------------------------------*/
793 static int sl811h_urb_enqueue(
798 struct sl811
*sl811
= hcd_to_sl811(hcd
);
799 struct usb_device
*udev
= urb
->dev
;
800 unsigned int pipe
= urb
->pipe
;
801 int is_out
= !usb_pipein(pipe
);
802 int type
= usb_pipetype(pipe
);
803 int epnum
= usb_pipeendpoint(pipe
);
804 struct sl811h_ep
*ep
= NULL
;
808 struct usb_host_endpoint
*hep
= urb
->ep
;
811 if (type
== PIPE_ISOCHRONOUS
)
815 /* avoid all allocations within spinlocks */
817 ep
= kzalloc(sizeof *ep
, mem_flags
);
822 spin_lock_irqsave(&sl811
->lock
, flags
);
824 /* don't submit to a dead or disabled port */
825 if (!(sl811
->port1
& USB_PORT_STAT_ENABLE
)
826 || !HC_IS_RUNNING(hcd
->state
)) {
829 goto fail_not_linked
;
831 retval
= usb_hcd_link_urb_to_ep(hcd
, urb
);
834 goto fail_not_linked
;
845 INIT_LIST_HEAD(&ep
->schedule
);
848 ep
->maxpacket
= usb_maxpacket(udev
, urb
->pipe
, is_out
);
849 ep
->defctrl
= SL11H_HCTLMASK_ARM
| SL11H_HCTLMASK_ENABLE
;
850 usb_settoggle(udev
, epnum
, is_out
, 0);
852 if (type
== PIPE_CONTROL
)
853 ep
->nextpid
= USB_PID_SETUP
;
855 ep
->nextpid
= USB_PID_OUT
;
857 ep
->nextpid
= USB_PID_IN
;
859 if (ep
->maxpacket
> H_MAXPACKET
) {
860 /* iso packets up to 240 bytes could work... */
861 DBG("dev %d ep%d maxpacket %d\n",
862 udev
->devnum
, epnum
, ep
->maxpacket
);
867 if (udev
->speed
== USB_SPEED_LOW
) {
868 /* send preamble for external hub? */
869 if (!(sl811
->ctrl1
& SL11H_CTL1MASK_LSPD
))
870 ep
->defctrl
|= SL11H_HCTLMASK_PREAMBLE
;
873 case PIPE_ISOCHRONOUS
:
875 if (urb
->interval
> PERIODIC_SIZE
)
876 urb
->interval
= PERIODIC_SIZE
;
877 ep
->period
= urb
->interval
;
878 ep
->branch
= PERIODIC_SIZE
;
879 if (type
== PIPE_ISOCHRONOUS
)
880 ep
->defctrl
|= SL11H_HCTLMASK_ISOCH
;
881 ep
->load
= usb_calc_bus_time(udev
->speed
, !is_out
,
882 (type
== PIPE_ISOCHRONOUS
),
883 usb_maxpacket(udev
, pipe
, is_out
))
892 /* maybe put endpoint into schedule */
896 if (list_empty(&ep
->schedule
))
897 list_add_tail(&ep
->schedule
, &sl811
->async
);
899 case PIPE_ISOCHRONOUS
:
901 urb
->interval
= ep
->period
;
902 if (ep
->branch
< PERIODIC_SIZE
) {
903 /* NOTE: the phase is correct here, but the value
904 * needs offsetting by the transfer queue depth.
905 * All current drivers ignore start_frame, so this
906 * is unlikely to ever matter...
908 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
913 retval
= balance(sl811
, ep
->period
, ep
->load
);
918 urb
->start_frame
= (sl811
->frame
& (PERIODIC_SIZE
- 1))
921 /* sort each schedule branch by period (slow before fast)
922 * to share the faster parts of the tree without needing
923 * dummy/placeholder nodes
925 DBG("schedule qh%d/%p branch %d\n", ep
->period
, ep
, ep
->branch
);
926 for (i
= ep
->branch
; i
< PERIODIC_SIZE
; i
+= ep
->period
) {
927 struct sl811h_ep
**prev
= &sl811
->periodic
[i
];
928 struct sl811h_ep
*here
= *prev
;
930 while (here
&& ep
!= here
) {
931 if (ep
->period
> here
->period
)
940 sl811
->load
[i
] += ep
->load
;
942 sl811
->periodic_count
++;
943 hcd
->self
.bandwidth_allocated
+= ep
->load
/ ep
->period
;
948 start_transfer(sl811
);
949 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
952 usb_hcd_unlink_urb_from_ep(hcd
, urb
);
954 spin_unlock_irqrestore(&sl811
->lock
, flags
);
958 static int sl811h_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
, int status
)
960 struct sl811
*sl811
= hcd_to_sl811(hcd
);
961 struct usb_host_endpoint
*hep
;
963 struct sl811h_ep
*ep
;
966 spin_lock_irqsave(&sl811
->lock
, flags
);
967 retval
= usb_hcd_check_unlink_urb(hcd
, urb
, status
);
974 /* finish right away if this urb can't be active ...
975 * note that some drivers wrongly expect delays
977 if (ep
->hep
->urb_list
.next
!= &urb
->urb_list
) {
978 /* not front of queue? never active */
980 /* for active transfers, we expect an IRQ */
981 } else if (sl811
->active_a
== ep
) {
982 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
983 /* happens a lot with lowspeed?? */
984 DBG("giveup on DONE_A: ctrl %02x sts %02x\n",
986 SL811_EP_A(SL11H_HOSTCTLREG
)),
988 SL811_EP_A(SL11H_PKTSTATREG
)));
989 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
991 sl811
->active_a
= NULL
;
995 } else if (sl811
->active_b
== ep
) {
996 if (time_before_eq(sl811
->jiffies_a
, jiffies
)) {
997 /* happens a lot with lowspeed?? */
998 DBG("giveup on DONE_B: ctrl %02x sts %02x\n",
1000 SL811_EP_B(SL11H_HOSTCTLREG
)),
1002 SL811_EP_B(SL11H_PKTSTATREG
)));
1003 sl811_write(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
),
1005 sl811
->active_b
= NULL
;
1010 /* front of queue for inactive endpoint */
1014 finish_request(sl811
, ep
, urb
, 0);
1016 VDBG("dequeue, urb %p active %s; wait4irq\n", urb
,
1017 (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 WARNING("ep %p not empty?\n", ep
);
1044 sl811h_get_frame(struct usb_hcd
*hcd
)
1046 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1048 /* wrong except while periodic transfers are scheduled;
1049 * never matches the on-the-wire frame;
1050 * subject to overruns.
1052 return sl811
->frame
;
1056 /*-------------------------------------------------------------------------*/
1058 /* the virtual root hub timer IRQ checks for hub status */
1060 sl811h_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
1062 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1064 unsigned long flags
;
1066 /* non-SMP HACK: use root hub timer as i/o watchdog
1067 * this seems essential when SOF IRQs aren't in use...
1069 local_irq_save(flags
);
1070 if (!timer_pending(&sl811
->timer
)) {
1071 if (sl811h_irq( /* ~0, */ hcd
) != IRQ_NONE
)
1074 local_irq_restore(flags
);
1077 if (!(sl811
->port1
& (0xffff << 16)))
1080 /* tell khubd port 1 changed */
1086 sl811h_hub_descriptor (
1087 struct sl811
*sl811
,
1088 struct usb_hub_descriptor
*desc
1092 desc
->bDescriptorType
= 0x29;
1093 desc
->bHubContrCurrent
= 0;
1095 desc
->bNbrPorts
= 1;
1096 desc
->bDescLength
= 9;
1098 /* per-port power switching (gang of one!), or none */
1099 desc
->bPwrOn2PwrGood
= 0;
1100 if (sl811
->board
&& sl811
->board
->port_power
) {
1101 desc
->bPwrOn2PwrGood
= sl811
->board
->potpg
;
1102 if (!desc
->bPwrOn2PwrGood
)
1103 desc
->bPwrOn2PwrGood
= 10;
1108 /* no overcurrent errors detection/handling */
1111 desc
->wHubCharacteristics
= cpu_to_le16(temp
);
1113 /* two bitmaps: ports removable, and legacy PortPwrCtrlMask */
1114 desc
->bitmap
[0] = 0 << 1;
1115 desc
->bitmap
[1] = ~0;
1119 sl811h_timer(unsigned long _sl811
)
1121 struct sl811
*sl811
= (void *) _sl811
;
1122 unsigned long flags
;
1124 u8 signaling
= sl811
->ctrl1
& SL11H_CTL1MASK_FORCE
;
1125 const u32 mask
= USB_PORT_STAT_CONNECTION
1126 | USB_PORT_STAT_ENABLE
1127 | USB_PORT_STAT_LOW_SPEED
;
1129 spin_lock_irqsave(&sl811
->lock
, flags
);
1131 /* stop special signaling */
1132 sl811
->ctrl1
&= ~SL11H_CTL1MASK_FORCE
;
1133 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1136 irqstat
= sl811_read(sl811
, SL11H_IRQ_STATUS
);
1138 switch (signaling
) {
1139 case SL11H_CTL1MASK_SE0
:
1141 sl811
->port1
= (USB_PORT_STAT_C_RESET
<< 16)
1142 | USB_PORT_STAT_POWER
;
1144 /* don't wrongly ack RD */
1145 if (irqstat
& SL11H_INTMASK_INSRMV
)
1146 irqstat
&= ~SL11H_INTMASK_RD
;
1148 case SL11H_CTL1MASK_K
:
1149 DBG("end resume\n");
1150 sl811
->port1
&= ~USB_PORT_STAT_SUSPEND
;
1153 DBG("odd timer signaling: %02x\n", signaling
);
1156 sl811_write(sl811
, SL11H_IRQ_STATUS
, irqstat
);
1158 if (irqstat
& SL11H_INTMASK_RD
) {
1159 /* usbcore nukes all pending transactions on disconnect */
1160 if (sl811
->port1
& USB_PORT_STAT_CONNECTION
)
1161 sl811
->port1
|= (USB_PORT_STAT_C_CONNECTION
<< 16)
1162 | (USB_PORT_STAT_C_ENABLE
<< 16);
1163 sl811
->port1
&= ~mask
;
1164 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1166 sl811
->port1
|= mask
;
1167 if (irqstat
& SL11H_INTMASK_DP
)
1168 sl811
->port1
&= ~USB_PORT_STAT_LOW_SPEED
;
1169 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
| SL11H_INTMASK_RD
;
1172 if (sl811
->port1
& USB_PORT_STAT_CONNECTION
) {
1173 u8 ctrl2
= SL811HS_CTL2_INIT
;
1175 sl811
->irq_enable
|= SL11H_INTMASK_DONE_A
;
1177 sl811
->irq_enable
|= SL11H_INTMASK_DONE_B
;
1179 if (sl811
->port1
& USB_PORT_STAT_LOW_SPEED
) {
1180 sl811
->ctrl1
|= SL11H_CTL1MASK_LSPD
;
1181 ctrl2
|= SL811HS_CTL2MASK_DSWAP
;
1184 /* start SOFs flowing, kickstarting with A registers */
1185 sl811
->ctrl1
|= SL11H_CTL1MASK_SOF_ENA
;
1186 sl811_write(sl811
, SL11H_SOFLOWREG
, 0xe0);
1187 sl811_write(sl811
, SL811HS_CTLREG2
, ctrl2
);
1189 /* autoincrementing */
1190 sl811_write(sl811
, SL811_EP_A(SL11H_BUFLNTHREG
), 0);
1191 writeb(SL_SOF
, sl811
->data_reg
);
1192 writeb(0, sl811
->data_reg
);
1193 sl811_write(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
),
1194 SL11H_HCTLMASK_ARM
);
1196 /* khubd provides debounce delay */
1200 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1203 sl811_write(sl811
, SL11H_IRQ_ENABLE
, sl811
->irq_enable
);
1204 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1209 struct usb_hcd
*hcd
,
1216 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1218 unsigned long flags
;
1220 spin_lock_irqsave(&sl811
->lock
, flags
);
1223 case ClearHubFeature
:
1226 case C_HUB_OVER_CURRENT
:
1227 case C_HUB_LOCAL_POWER
:
1233 case ClearPortFeature
:
1234 if (wIndex
!= 1 || wLength
!= 0)
1238 case USB_PORT_FEAT_ENABLE
:
1239 sl811
->port1
&= USB_PORT_STAT_POWER
;
1241 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1242 sl811
->irq_enable
= SL11H_INTMASK_INSRMV
;
1243 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1246 case USB_PORT_FEAT_SUSPEND
:
1247 if (!(sl811
->port1
& USB_PORT_STAT_SUSPEND
))
1250 /* 20 msec of resume/K signaling, other irqs blocked */
1251 DBG("start resume...\n");
1252 sl811
->irq_enable
= 0;
1253 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1255 sl811
->ctrl1
|= SL11H_CTL1MASK_K
;
1256 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1258 mod_timer(&sl811
->timer
, jiffies
1259 + msecs_to_jiffies(20));
1261 case USB_PORT_FEAT_POWER
:
1262 port_power(sl811
, 0);
1264 case USB_PORT_FEAT_C_ENABLE
:
1265 case USB_PORT_FEAT_C_SUSPEND
:
1266 case USB_PORT_FEAT_C_CONNECTION
:
1267 case USB_PORT_FEAT_C_OVER_CURRENT
:
1268 case USB_PORT_FEAT_C_RESET
:
1273 sl811
->port1
&= ~(1 << wValue
);
1275 case GetHubDescriptor
:
1276 sl811h_hub_descriptor(sl811
, (struct usb_hub_descriptor
*) buf
);
1279 put_unaligned_le32(0, buf
);
1284 put_unaligned_le32(sl811
->port1
, buf
);
1287 if (*(u16
*)(buf
+2)) /* only if wPortChange is interesting */
1289 DBG("GetPortStatus %08x\n", sl811
->port1
);
1291 case SetPortFeature
:
1292 if (wIndex
!= 1 || wLength
!= 0)
1295 case USB_PORT_FEAT_SUSPEND
:
1296 if (sl811
->port1
& USB_PORT_STAT_RESET
)
1298 if (!(sl811
->port1
& USB_PORT_STAT_ENABLE
))
1301 DBG("suspend...\n");
1302 sl811
->ctrl1
&= ~SL11H_CTL1MASK_SOF_ENA
;
1303 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1305 case USB_PORT_FEAT_POWER
:
1306 port_power(sl811
, 1);
1308 case USB_PORT_FEAT_RESET
:
1309 if (sl811
->port1
& USB_PORT_STAT_SUSPEND
)
1311 if (!(sl811
->port1
& USB_PORT_STAT_POWER
))
1314 /* 50 msec of reset/SE0 signaling, irqs blocked */
1315 sl811
->irq_enable
= 0;
1316 sl811_write(sl811
, SL11H_IRQ_ENABLE
,
1318 sl811
->ctrl1
= SL11H_CTL1MASK_SE0
;
1319 sl811_write(sl811
, SL11H_CTLREG1
, sl811
->ctrl1
);
1320 sl811
->port1
|= USB_PORT_STAT_RESET
;
1321 mod_timer(&sl811
->timer
, jiffies
1322 + msecs_to_jiffies(50));
1327 sl811
->port1
|= 1 << wValue
;
1332 /* "protocol stall" on error */
1336 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1343 sl811h_bus_suspend(struct usb_hcd
*hcd
)
1346 DBG("%s\n", __func__
);
1351 sl811h_bus_resume(struct usb_hcd
*hcd
)
1354 DBG("%s\n", __func__
);
1360 #define sl811h_bus_suspend NULL
1361 #define sl811h_bus_resume NULL
1366 /*-------------------------------------------------------------------------*/
1368 #ifdef STUB_DEBUG_FILE
1370 static inline void create_debug_file(struct sl811
*sl811
) { }
1371 static inline void remove_debug_file(struct sl811
*sl811
) { }
1375 #include <linux/proc_fs.h>
1376 #include <linux/seq_file.h>
1378 static void dump_irq(struct seq_file
*s
, char *label
, u8 mask
)
1380 seq_printf(s
, "%s %02x%s%s%s%s%s%s\n", label
, mask
,
1381 (mask
& SL11H_INTMASK_DONE_A
) ? " done_a" : "",
1382 (mask
& SL11H_INTMASK_DONE_B
) ? " done_b" : "",
1383 (mask
& SL11H_INTMASK_SOFINTR
) ? " sof" : "",
1384 (mask
& SL11H_INTMASK_INSRMV
) ? " ins/rmv" : "",
1385 (mask
& SL11H_INTMASK_RD
) ? " rd" : "",
1386 (mask
& SL11H_INTMASK_DP
) ? " dp" : "");
1389 static int proc_sl811h_show(struct seq_file
*s
, void *unused
)
1391 struct sl811
*sl811
= s
->private;
1392 struct sl811h_ep
*ep
;
1395 seq_printf(s
, "%s\n%s version %s\nportstatus[1] = %08x\n",
1396 sl811_to_hcd(sl811
)->product_desc
,
1397 hcd_name
, DRIVER_VERSION
,
1400 seq_printf(s
, "insert/remove: %ld\n", sl811
->stat_insrmv
);
1401 seq_printf(s
, "current session: done_a %ld done_b %ld "
1402 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1403 sl811
->stat_a
, sl811
->stat_b
,
1404 sl811
->stat_wake
, sl811
->stat_sof
,
1405 sl811
->stat_overrun
, sl811
->stat_lost
);
1407 spin_lock_irq(&sl811
->lock
);
1409 if (sl811
->ctrl1
& SL11H_CTL1MASK_SUSPEND
)
1410 seq_printf(s
, "(suspended)\n\n");
1412 u8 t
= sl811_read(sl811
, SL11H_CTLREG1
);
1414 seq_printf(s
, "ctrl1 %02x%s%s%s%s\n", t
,
1415 (t
& SL11H_CTL1MASK_SOF_ENA
) ? " sofgen" : "",
1416 ({char *s
; switch (t
& SL11H_CTL1MASK_FORCE
) {
1417 case SL11H_CTL1MASK_NORMAL
: s
= ""; break;
1418 case SL11H_CTL1MASK_SE0
: s
= " se0/reset"; break;
1419 case SL11H_CTL1MASK_K
: s
= " k/resume"; break;
1420 default: s
= "j"; break;
1422 (t
& SL11H_CTL1MASK_LSPD
) ? " lowspeed" : "",
1423 (t
& SL11H_CTL1MASK_SUSPEND
) ? " suspend" : "");
1425 dump_irq(s
, "irq_enable",
1426 sl811_read(sl811
, SL11H_IRQ_ENABLE
));
1427 dump_irq(s
, "irq_status",
1428 sl811_read(sl811
, SL11H_IRQ_STATUS
));
1429 seq_printf(s
, "frame clocks remaining: %d\n",
1430 sl811_read(sl811
, SL11H_SOFTMRREG
) << 6);
1433 seq_printf(s
, "A: qh%p ctl %02x sts %02x\n", sl811
->active_a
,
1434 sl811_read(sl811
, SL811_EP_A(SL11H_HOSTCTLREG
)),
1435 sl811_read(sl811
, SL811_EP_A(SL11H_PKTSTATREG
)));
1436 seq_printf(s
, "B: qh%p ctl %02x sts %02x\n", sl811
->active_b
,
1437 sl811_read(sl811
, SL811_EP_B(SL11H_HOSTCTLREG
)),
1438 sl811_read(sl811
, SL811_EP_B(SL11H_PKTSTATREG
)));
1439 seq_printf(s
, "\n");
1440 list_for_each_entry (ep
, &sl811
->async
, schedule
) {
1443 seq_printf(s
, "%s%sqh%p, ep%d%s, maxpacket %d"
1445 (ep
== sl811
->active_a
) ? "(A) " : "",
1446 (ep
== sl811
->active_b
) ? "(B) " : "",
1448 ({ char *s
; switch (ep
->nextpid
) {
1449 case USB_PID_IN
: s
= "in"; break;
1450 case USB_PID_OUT
: s
= "out"; break;
1451 case USB_PID_SETUP
: s
= "setup"; break;
1452 case USB_PID_ACK
: s
= "status"; break;
1453 default: s
= "?"; break;
1456 ep
->nak_count
, ep
->error_count
);
1457 list_for_each_entry (urb
, &ep
->hep
->urb_list
, urb_list
) {
1458 seq_printf(s
, " urb%p, %d/%d\n", urb
,
1460 urb
->transfer_buffer_length
);
1463 if (!list_empty(&sl811
->async
))
1464 seq_printf(s
, "\n");
1466 seq_printf(s
, "periodic size= %d\n", PERIODIC_SIZE
);
1468 for (i
= 0; i
< PERIODIC_SIZE
; i
++) {
1469 ep
= sl811
->periodic
[i
];
1472 seq_printf(s
, "%2d [%3d]:\n", i
, sl811
->load
[i
]);
1474 /* DUMB: prints shared entries multiple times */
1477 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1479 (ep
== sl811
->active_a
) ? "(A) " : "",
1480 (ep
== sl811
->active_b
) ? "(B) " : "",
1482 (ep
->udev
->speed
== USB_SPEED_FULL
)
1484 ep
->udev
->devnum
, ep
->epnum
,
1485 (ep
->epnum
== 0) ? ""
1486 : ((ep
->nextpid
== USB_PID_IN
)
1489 ep
->maxpacket
, ep
->error_count
);
1494 spin_unlock_irq(&sl811
->lock
);
1495 seq_printf(s
, "\n");
1500 static int proc_sl811h_open(struct inode
*inode
, struct file
*file
)
1502 return single_open(file
, proc_sl811h_show
, PDE(inode
)->data
);
1505 static const struct file_operations proc_ops
= {
1506 .open
= proc_sl811h_open
,
1508 .llseek
= seq_lseek
,
1509 .release
= single_release
,
1512 /* expect just one sl811 per system */
1513 static const char proc_filename
[] = "driver/sl811h";
1515 static void create_debug_file(struct sl811
*sl811
)
1517 sl811
->pde
= proc_create_data(proc_filename
, 0, NULL
, &proc_ops
, sl811
);
1520 static void remove_debug_file(struct sl811
*sl811
)
1523 remove_proc_entry(proc_filename
, NULL
);
1528 /*-------------------------------------------------------------------------*/
1531 sl811h_stop(struct usb_hcd
*hcd
)
1533 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1534 unsigned long flags
;
1536 del_timer_sync(&hcd
->rh_timer
);
1538 spin_lock_irqsave(&sl811
->lock
, flags
);
1539 port_power(sl811
, 0);
1540 spin_unlock_irqrestore(&sl811
->lock
, flags
);
1544 sl811h_start(struct usb_hcd
*hcd
)
1546 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1548 /* chip has been reset, VBUS power is off */
1549 hcd
->state
= HC_STATE_RUNNING
;
1552 if (!device_can_wakeup(hcd
->self
.controller
))
1553 device_init_wakeup(hcd
->self
.controller
,
1554 sl811
->board
->can_wakeup
);
1555 hcd
->power_budget
= sl811
->board
->power
* 2;
1558 /* enable power and interrupts */
1559 port_power(sl811
, 1);
1564 /*-------------------------------------------------------------------------*/
1566 static struct hc_driver sl811h_hc_driver
= {
1567 .description
= hcd_name
,
1568 .hcd_priv_size
= sizeof(struct sl811
),
1571 * generic hardware linkage
1574 .flags
= HCD_USB11
| HCD_MEMORY
,
1576 /* Basic lifecycle operations */
1577 .start
= sl811h_start
,
1578 .stop
= sl811h_stop
,
1581 * managing i/o requests and associated device resources
1583 .urb_enqueue
= sl811h_urb_enqueue
,
1584 .urb_dequeue
= sl811h_urb_dequeue
,
1585 .endpoint_disable
= sl811h_endpoint_disable
,
1588 * periodic schedule support
1590 .get_frame_number
= sl811h_get_frame
,
1595 .hub_status_data
= sl811h_hub_status_data
,
1596 .hub_control
= sl811h_hub_control
,
1597 .bus_suspend
= sl811h_bus_suspend
,
1598 .bus_resume
= sl811h_bus_resume
,
1601 /*-------------------------------------------------------------------------*/
1603 static int __devexit
1604 sl811h_remove(struct platform_device
*dev
)
1606 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1607 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1608 struct resource
*res
;
1610 remove_debug_file(sl811
);
1611 usb_remove_hcd(hcd
);
1613 /* some platforms may use IORESOURCE_IO */
1614 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1616 iounmap(sl811
->data_reg
);
1618 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1620 iounmap(sl811
->addr_reg
);
1626 static int __devinit
1627 sl811h_probe(struct platform_device
*dev
)
1629 struct usb_hcd
*hcd
;
1630 struct sl811
*sl811
;
1631 struct resource
*addr
, *data
, *ires
;
1633 void __iomem
*addr_reg
;
1634 void __iomem
*data_reg
;
1637 unsigned long irqflags
;
1639 /* basic sanity checks first. board-specific init logic should
1640 * have initialized these three resources and probably board
1641 * specific platform_data. we don't probe for IRQs, and do only
1642 * minimal sanity checking.
1644 ires
= platform_get_resource(dev
, IORESOURCE_IRQ
, 0);
1645 if (dev
->num_resources
< 3 || !ires
)
1649 irqflags
= ires
->flags
& IRQF_TRIGGER_MASK
;
1651 /* refuse to confuse usbcore */
1652 if (dev
->dev
.dma_mask
) {
1653 DBG("no we won't dma\n");
1657 /* the chip may be wired for either kind of addressing */
1658 addr
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
1659 data
= platform_get_resource(dev
, IORESOURCE_MEM
, 1);
1661 if (!addr
|| !data
) {
1662 addr
= platform_get_resource(dev
, IORESOURCE_IO
, 0);
1663 data
= platform_get_resource(dev
, IORESOURCE_IO
, 1);
1668 * NOTE: 64-bit resource->start is getting truncated
1669 * to avoid compiler warning, assuming that ->start
1670 * is always 32-bit for this case
1672 addr_reg
= (void __iomem
*) (unsigned long) addr
->start
;
1673 data_reg
= (void __iomem
*) (unsigned long) data
->start
;
1675 addr_reg
= ioremap(addr
->start
, 1);
1676 if (addr_reg
== NULL
) {
1681 data_reg
= ioremap(data
->start
, 1);
1682 if (data_reg
== NULL
) {
1688 /* allocate and initialize hcd */
1689 hcd
= usb_create_hcd(&sl811h_hc_driver
, &dev
->dev
, dev_name(&dev
->dev
));
1694 hcd
->rsrc_start
= addr
->start
;
1695 sl811
= hcd_to_sl811(hcd
);
1697 spin_lock_init(&sl811
->lock
);
1698 INIT_LIST_HEAD(&sl811
->async
);
1699 sl811
->board
= dev
->dev
.platform_data
;
1700 init_timer(&sl811
->timer
);
1701 sl811
->timer
.function
= sl811h_timer
;
1702 sl811
->timer
.data
= (unsigned long) sl811
;
1703 sl811
->addr_reg
= addr_reg
;
1704 sl811
->data_reg
= data_reg
;
1706 spin_lock_irq(&sl811
->lock
);
1707 port_power(sl811
, 0);
1708 spin_unlock_irq(&sl811
->lock
);
1711 tmp
= sl811_read(sl811
, SL11H_HWREVREG
);
1714 hcd
->product_desc
= "SL811HS v1.2";
1717 hcd
->product_desc
= "SL811HS v1.5";
1720 /* reject case 0, SL11S is less functional */
1721 DBG("chiprev %02x\n", tmp
);
1726 /* The chip's IRQ is level triggered, active high. A requirement
1727 * for platform device setup is to cope with things like signal
1728 * inverters (e.g. CF is active low) or working only with edge
1729 * triggers (e.g. most ARM CPUs). Initial driver stress testing
1730 * was on a system with single edge triggering, so most sorts of
1731 * triggering arrangement should work.
1733 * Use resource IRQ flags if set by platform device setup.
1735 irqflags
|= IRQF_SHARED
;
1736 retval
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
| irqflags
);
1740 create_debug_file(sl811
);
1752 DBG("init error, %d\n", retval
);
1758 /* for this device there's no useful distinction between the controller
1759 * and its root hub, except that the root hub only gets direct PM calls
1760 * when CONFIG_USB_SUSPEND is enabled.
1764 sl811h_suspend(struct platform_device
*dev
, pm_message_t state
)
1766 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1767 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1770 switch (state
.event
) {
1771 case PM_EVENT_FREEZE
:
1772 retval
= sl811h_bus_suspend(hcd
);
1774 case PM_EVENT_SUSPEND
:
1775 case PM_EVENT_HIBERNATE
:
1776 case PM_EVENT_PRETHAW
: /* explicitly discard hw state */
1777 port_power(sl811
, 0);
1784 sl811h_resume(struct platform_device
*dev
)
1786 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
1787 struct sl811
*sl811
= hcd_to_sl811(hcd
);
1789 /* with no "check to see if VBUS is still powered" board hook,
1790 * let's assume it'd only be powered to enable remote wakeup.
1792 if (!sl811
->port1
|| !device_can_wakeup(&hcd
->self
.root_hub
->dev
)) {
1794 port_power(sl811
, 1);
1795 usb_root_hub_lost_power(hcd
->self
.root_hub
);
1799 return sl811h_bus_resume(hcd
);
1804 #define sl811h_suspend NULL
1805 #define sl811h_resume NULL
1810 /* this driver is exported so sl811_cs can depend on it */
1811 struct platform_driver sl811h_driver
= {
1812 .probe
= sl811h_probe
,
1813 .remove
= __devexit_p(sl811h_remove
),
1815 .suspend
= sl811h_suspend
,
1816 .resume
= sl811h_resume
,
1818 .name
= (char *) hcd_name
,
1819 .owner
= THIS_MODULE
,
1822 EXPORT_SYMBOL(sl811h_driver
);
1824 /*-------------------------------------------------------------------------*/
1826 static int __init
sl811h_init(void)
1831 INFO("driver %s, %s\n", hcd_name
, DRIVER_VERSION
);
1832 return platform_driver_register(&sl811h_driver
);
1834 module_init(sl811h_init
);
1836 static void __exit
sl811h_cleanup(void)
1838 platform_driver_unregister(&sl811h_driver
);
1840 module_exit(sl811h_cleanup
);