34 #include <linux/module.h>
36 #include <linux/kernel.h>
39 #include <linux/sched.h>
40 #include <linux/slab.h>
41 #include <linux/errno.h>
44 #include <linux/list.h>
50 #include <linux/prefetch.h>
54 #include <asm/byteorder.h>
55 #include <asm/unaligned.h>
64 #define DRIVER_VERSION "19 May 2005"
68 # define STUB_DEBUG_FILE
77 static const char hcd_name[] =
"sl811-hcd";
81 static void port_power(
struct sl811 *
sl811,
int is_on)
83 struct usb_hcd *hcd = sl811_to_hcd(sl811);
95 hcd->state = HC_STATE_HALT;
101 if (sl811->
board && sl811->
board->port_power) {
103 DBG(
"power %s\n", is_on ?
"on" :
"off");
104 sl811->
board->port_power(hcd->self.controller, is_on);
109 sl811->
board->reset(hcd->self.controller);
136 static void setup_packet(
151 sl811_write_buf(sl811, addr, urb->setup_packet, len);
157 writeb(usb_pipedevice(urb->pipe), data_reg);
163 PACKET(
"SETUP qh%p\n", ep);
167 static void status_packet(
178 do_out = urb->transfer_buffer_length && usb_pipein(urb->pipe);
185 writeb(usb_pipedevice(urb->pipe), data_reg);
194 do_out ?
"out" :
"in", ep);
201 static void in_packet(
217 && usb_gettoggle(urb->dev, ep->
epnum, 0))
225 writeb(usb_pipedevice(urb->pipe), data_reg);
229 urb->transfer_buffer_length - urb->actual_length);
231 !!usb_gettoggle(urb->dev, ep->
epnum, 0), ep, len);
237 static void out_packet(
250 buf = urb->transfer_buffer + urb->actual_length;
254 urb->transfer_buffer_length - urb->actual_length);
256 if (!(control & SL11H_HCTLMASK_ISOCH)
257 && usb_gettoggle(urb->dev, ep->
epnum, 1))
262 sl811_write_buf(sl811, addr, buf, len);
268 writeb(usb_pipedevice(urb->pipe), data_reg);
274 !!usb_gettoggle(urb->dev, ep->
epnum, 1), ep, len);
281 static inline void sofirq_on(
struct sl811 *sl811)
285 VDBG(
"sof irq on\n");
289 static inline void sofirq_off(
struct sl811 *sl811)
293 VDBG(
"sof irq off\n");
318 else if (!list_empty(&sl811->
async))
341 DBG(
"empty %p queue?\n", ep);
368 fclock -= 12000 / 19;
382 in_packet(sl811, ep, urb, bank, control);
385 out_packet(sl811, ep, urb, bank, control);
388 setup_packet(sl811, ep, urb, bank, control);
391 status_packet(sl811, ep, urb, bank, control);
400 #define MIN_JIFFIES ((msecs_to_jiffies(2) > 1) ? msecs_to_jiffies(2) : 2)
402 static inline void start_transfer(
struct sl811 *sl811)
420 static void finish_request(
429 if (usb_pipecontrol(urb->pipe))
433 spin_unlock(&sl811->
lock);
435 spin_lock(&sl811->
lock);
438 if (!list_empty(&ep->
hep->urb_list))
451 for (i = ep->
branch; i < PERIODIC_SIZE; i += ep->
period) {
455 while (*prev && ((temp = *prev) != ep))
463 sl811_to_hcd(sl811)->self.bandwidth_allocated
496 struct usb_device *
udev = urb->dev;
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))
517 || !(urb->transfer_flags
524 buf = urb->transfer_buffer + urb->actual_length;
532 urb->actual_length += len;
535 usb_dotoggle(udev, ep->
epnum, 0);
537 (len < ep->maxpacket ||
538 urb->actual_length ==
539 urb->transfer_buffer_length)) {
540 if (usb_pipecontrol(urb->pipe))
548 if (urb->transfer_buffer_length == urb->actual_length)
550 else if (usb_pipeout(urb->pipe)) {
551 usb_settoggle(udev, 0, 1, 1);
554 usb_settoggle(udev, 0, 0, 1);
566 PACKET(
"...STALL_%02x qh%p\n", bank, ep);
579 PACKET(
"...3STRIKES_%02x %02x qh%p stat %d\n",
580 bank, status, ep, urbstat);
584 finish_request(sl811, ep, urb, urbstat);
587 static inline u8 checkdone(
struct sl811 *sl811)
596 DBG(
"%s DONE_A: ctrl %02x sts %02x\n",
597 (ctl & SL11H_HCTLMASK_ARM) ?
"timeout" :
"lost",
605 if (ctl & SL11H_HCTLMASK_ARM)
607 DBG(
"%s DONE_B: ctrl %02x sts %02x\n",
608 (ctl & SL11H_HCTLMASK_ARM) ?
"timeout" :
"lost",
619 struct sl811 *sl811 = hcd_to_sl811(hcd);
624 spin_lock(&sl811->
lock);
636 irqstat = checkdone(sl811);
695 finish_request(sl811, sl811->
active_a,
697 ->hep->urb_list.next,
705 finish_request(sl811, sl811->
active_b,
707 ->hep->urb_list.next,
730 irqstat &= ~SL11H_INTMASK_RD;
735 start_transfer(sl811);
745 spin_unlock(&sl811->
lock);
759 #define MAX_PERIODIC_LOAD 500
761 static int balance(
struct sl811 *sl811,
u16 period,
u16 load)
768 for (i = 0; i <
period ; i++) {
773 if ((sl811->
load[j] + load)
777 if (j < PERIODIC_SIZE)
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);
802 struct usb_host_endpoint *
hep = urb->ep;
804 #ifndef CONFIG_USB_SL811_HCD_ISO
805 if (type == PIPE_ISOCHRONOUS)
811 ep = kzalloc(
sizeof *ep, mem_flags);
820 || !HC_IS_RUNNING(hcd->state)) {
823 goto fail_not_linked;
828 goto fail_not_linked;
842 ep->
maxpacket = usb_maxpacket(udev, urb->pipe, is_out);
844 usb_settoggle(udev, epnum, is_out, 0);
846 if (type == PIPE_CONTROL)
855 DBG(
"dev %d ep%d maxpacket %d\n",
868 case PIPE_ISOCHRONOUS:
872 ep->
period = urb->interval;
874 if (type == PIPE_ISOCHRONOUS)
877 (type == PIPE_ISOCHRONOUS),
878 usb_maxpacket(udev, pipe, is_out))
894 case PIPE_ISOCHRONOUS:
896 urb->interval = ep->
period;
908 retval = balance(sl811, ep->
period, ep->
load);
921 for (i = ep->
branch; i < PERIODIC_SIZE; i += ep->period) {
925 while (here && ep != here) {
938 hcd->self.bandwidth_allocated += ep->
load / ep->
period;
943 start_transfer(sl811);
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;
972 if (ep->
hep->urb_list.next != &urb->urb_list) {
979 DBG(
"giveup on DONE_A: ctrl %02x sts %02x\n",
993 DBG(
"giveup on DONE_B: ctrl %02x sts %02x\n",
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)
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);
1047 return sl811->
frame;
1055 sl811h_hub_status_data(
struct usb_hcd *hcd,
char *buf)
1057 struct sl811 *sl811 = hcd_to_sl811(hcd);
1059 unsigned long flags;
1065 if (!timer_pending(&sl811->
timer)) {
1072 if (!(sl811->
port1 & (0xffff << 16)))
1081 sl811h_hub_descriptor (
1082 struct sl811 *sl811,
1095 if (sl811->
board && sl811->
board->port_power) {
1114 sl811h_timer(
unsigned long _sl811)
1116 struct sl811 *sl811 = (
void *) _sl811;
1117 unsigned long flags;
1133 switch (signaling) {
1140 if (irqstat & SL11H_INTMASK_INSRMV)
1141 irqstat &= ~SL11H_INTMASK_RD;
1144 DBG(
"end resume\n");
1148 DBG(
"odd timer signaling: %02x\n", signaling);
1153 if (irqstat & SL11H_INTMASK_RD) {
1158 sl811->
port1 &= ~mask;
1189 SL11H_HCTLMASK_ARM);
1199 spin_unlock_irqrestore(&sl811->
lock, flags);
1204 struct usb_hcd *hcd,
1211 struct sl811 *sl811 = hcd_to_sl811(hcd);
1213 unsigned long flags;
1218 case ClearHubFeature:
1228 case ClearPortFeature:
1229 if (wIndex != 1 || wLength != 0)
1246 DBG(
"start resume...\n");
1257 port_power(sl811, 0);
1270 case GetHubDescriptor:
1284 DBG(
"GetPortStatus %08x\n", sl811->
port1);
1286 case SetPortFeature:
1287 if (wIndex != 1 || wLength != 0)
1296 DBG(
"suspend...\n");
1301 port_power(sl811, 1);
1331 spin_unlock_irqrestore(&sl811->
lock, flags);
1341 DBG(
"%s\n", __func__);
1349 DBG(
"%s\n", __func__);
1355 #define sl811h_bus_suspend NULL
1356 #define sl811h_bus_resume NULL
1363 #ifdef STUB_DEBUG_FILE
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" :
"",
1386 struct sl811 *sl811 = s->
private;
1390 seq_printf(s,
"%s\n%s version %s\nportstatus[1] = %08x\n",
1391 sl811_to_hcd(sl811)->product_desc,
1396 seq_printf(s,
"current session: done_a %ld done_b %ld "
1397 "wake %ld sof %ld overrun %ld lost %ld\n\n",
1402 spin_lock_irq(&sl811->
lock);
1415 default: s =
"j";
break;
1420 dump_irq(s,
"irq_enable",
1422 dump_irq(s,
"irq_status",
1424 seq_printf(s,
"frame clocks remaining: %d\n",
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) {
1448 default: s =
"?";
break;
1455 urb->transfer_buffer_length);
1458 if (!list_empty(&sl811->
async))
1472 " %s%sqh%d/%p (%sdev%d ep%d%s max %d) "
1474 (ep == sl811->
active_a) ?
"(A) " :
"",
1475 (ep == sl811->
active_b) ?
"(B) " :
"",
1480 (ep->
epnum == 0) ?
""
1489 spin_unlock_irq(&sl811->
lock);
1501 .
open = proc_sl811h_open,
1508 static const char proc_filename[] =
"driver/sl811h";
1526 sl811h_stop(
struct usb_hcd *hcd)
1528 struct sl811 *sl811 = hcd_to_sl811(hcd);
1529 unsigned long 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);
1544 hcd->state = HC_STATE_RUNNING;
1547 if (!device_can_wakeup(hcd->self.controller))
1549 sl811->
board->can_wakeup);
1550 hcd->power_budget = sl811->
board->power * 2;
1554 port_power(sl811, 1);
1561 static struct hc_driver sl811h_hc_driver = {
1562 .description = hcd_name,
1563 .hcd_priv_size =
sizeof(
struct sl811),
1569 .flags = HCD_USB11 | HCD_MEMORY,
1572 .start = sl811h_start,
1573 .stop = sl811h_stop,
1578 .urb_enqueue = sl811h_urb_enqueue,
1579 .urb_dequeue = sl811h_urb_dequeue,
1580 .endpoint_disable = sl811h_endpoint_disable,
1585 .get_frame_number = sl811h_get_frame,
1590 .hub_status_data = sl811h_hub_status_data,
1591 .hub_control = sl811h_hub_control,
1601 struct usb_hcd *hcd = platform_get_drvdata(dev);
1602 struct sl811 *sl811 = hcd_to_sl811(hcd);
1624 struct usb_hcd *hcd;
1625 struct sl811 *sl811;
1632 unsigned long irqflags;
1650 if (dev->
dev.dma_mask) {
1651 DBG(
"no we won't dma\n");
1659 if (!addr || !data) {
1670 addr_reg = (
void __iomem *) (
unsigned long) addr->
start;
1671 data_reg = (
void __iomem *) (
unsigned long) data->
start;
1674 if (addr_reg ==
NULL) {
1680 if (data_reg ==
NULL) {
1692 hcd->rsrc_start = addr->
start;
1693 sl811 = hcd_to_sl811(hcd);
1696 INIT_LIST_HEAD(&sl811->
async);
1697 sl811->
board = dev->
dev.platform_data;
1699 sl811->
timer.function = sl811h_timer;
1700 sl811->
timer.data = (
unsigned long) sl811;
1704 spin_lock_irq(&sl811->
lock);
1705 port_power(sl811, 0);
1706 spin_unlock_irq(&sl811->
lock);
1712 hcd->product_desc =
"SL811HS v1.2";
1715 hcd->product_desc =
"SL811HS v1.5";
1719 DBG(
"chiprev %02x\n", tmp);
1750 DBG(
"init error, %d\n", retval);
1764 struct usb_hcd *hcd = platform_get_drvdata(dev);
1765 struct sl811 *sl811 = hcd_to_sl811(hcd);
1768 switch (state.
event) {
1775 port_power(sl811, 0);
1784 struct usb_hcd *hcd = platform_get_drvdata(dev);
1785 struct sl811 *sl811 = hcd_to_sl811(hcd);
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);
1802 #define sl811h_suspend NULL
1803 #define sl811h_resume NULL
1810 .probe = sl811h_probe,
1816 .name = (
char *) hcd_name,