2 * SL811 Host Controller Interface driver for USB.
4 * Copyright (c) 2003/06, Courage Co., Ltd.
7 * 1.uhci.c by Linus Torvalds, Johannes Erdfelt, Randy Dunlap,
8 * Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber,
9 * Adam Richter, Gregory P. Smith;
10 * 2.Original SL811 driver (hc_sl811.o) by Pei Liu <pbl@cypress.com>
11 * 3.Rewrited as sl811.o by Yin Aihua <yinah:couragetech.com.cn>
13 * It's now support isochornous mode and more effective than hc_sl811.o
14 * Support x86 architecture now.
16 * 19.09.2003 (05.06.2003) HNE
17 * sl811_alloc_hc: Set "bus->bus_name" at init.
18 * sl811_reg_test (hc_reset,regTest):
19 * Stop output at first failed pattern.
20 * Down-Grade for Kernel 2.4.20 and from 2.4.22
21 * Splitt hardware depens into file sl811-x86.h and sl811-arm.h.
24 * sl811_found_hc: First patterntest, than interrupt enable.
25 * Do nothing, if patterntest failed. Release io, if failed.
26 * Stop Interrupts first, than remove handle. (Old blocked Shred IRQ)
27 * Alternate IO-Base for second Controller (CF/USB1).
30 * Remove all arm specific source (moved into include/asm/sl811-hw.h).
33 * Low level only for port io into hardware-include.
37 * 1.Modify the timeout part, it's some messy
38 * 2.Use usb-a and usb-b set in Ping-Pong mode
39 * o Floppy do not work.
40 * o driver crash, if io region can't register
41 * o Only as module tested! Compiled in Version not tested!
43 * This program is free software; you can redistribute it and/or modify
44 * it under the terms of the GNU General Public License as published by
45 * the Free Software Foundation; either version 2 of the License, or
46 * (at your option) any later version.
50 #include <linux/config.h>
51 #include <linux/module.h>
52 #include <linux/kernel.h>
53 #include <linux/delay.h>
54 #include <linux/sched.h>
55 #include <linux/slab.h>
56 #include <linux/errno.h>
57 #include <linux/init.h>
58 #include <linux/smp_lock.h>
59 #include <linux/list.h>
60 #include <linux/ioport.h>
62 #include <linux/irq.h>
63 #include <linux/usb.h>
69 #define DRIVER_VERSION "v0.30"
70 #define MODNAME "SL811"
71 #define DRIVER_AUTHOR "Yin Aihua <yinah@couragetech.com.cn>, Henry Nestler <hne@ist1.de>"
72 #define DRIVER_DESC "Sl811 USB Host Controller Alternate Driver"
74 static LIST_HEAD(sl811_hcd_list);
77 * 0, normal prompt and information
78 * 1, error should not occur in normal
79 * 2, error maybe occur in normal
80 * 3, useful and detail debug information
81 * 4, function level enter and level inforamtion
82 * 5, endless information will output because of timer function or interrupt
85 MODULE_PARM(debug,"i");
86 MODULE_PARM_DESC(debug,"debug level");
88 #include <asm/sl811-hw.h> /* Include hardware and board depens */
90 static void sl811_rh_int_timer_do(unsigned long ptr);
91 static void sl811_transfer_done(struct sl811_hc *hc, int sof);
94 * Read a byte of data from the SL811H/SL11H
96 static __u8 inline sl811_read(struct sl811_hc *hc, __u8 offset)
98 sl811_write_index (hc, offset);
99 return (sl811_read_data (hc));
103 * Write a byte of data to the SL811H/SL11H
105 static void inline sl811_write(struct sl811_hc *hc, __u8 offset, __u8 data)
107 sl811_write_index_data (hc, offset, data);
111 * Read consecutive bytes of data from the SL811H/SL11H buffer
113 static void inline sl811_read_buf(struct sl811_hc *hc, __u8 offset, __u8 *buf, __u8 size)
115 sl811_write_index (hc, offset);
117 *buf++ = sl811_read_data(hc);
122 * Write consecutive bytes of data to the SL811H/SL11H buffer
124 static void inline sl811_write_buf(struct sl811_hc *hc, __u8 offset, __u8 *buf, __u8 size)
126 sl811_write_index (hc, offset);
128 sl811_write_data (hc, *buf);
134 * This routine test the Read/Write functionality of SL811HS registers
136 static int sl811_reg_test(struct sl811_hc *hc)
138 int i, data, result = 0;
141 for (i = 0x10; i < 256; i++) {
142 /* save the original buffer */
143 buf[i] = sl811_read(hc, i);
145 /* Write the new data to the buffer */
146 sl811_write(hc, i, i);
149 /* compare the written data */
150 for (i = 0x10; i < 256; i++) {
151 data = sl811_read(hc, i);
153 PDEBUG(1, "Pattern test failed!! value = 0x%x, s/b 0x%x", data, i);
156 /* If no Debug, show only first failed Address */
162 /* restore the data */
163 for (i = 0x10; i < 256; i++)
164 sl811_write(hc, i, buf[i]);
170 * Display all SL811HS register values
172 #if 0 /* unused (hne) */
173 static void sl811_reg_show(struct sl811_hc *hc)
177 for (i = 0; i < 256; i++)
178 PDEBUG(4, "offset %d: 0x%x", i, sl811_read(hc, i));
183 * This function enables SL811HS interrupts
185 static void sl811_enable_interrupt(struct sl811_hc *hc)
188 sl811_write(hc, SL811_INTR, SL811_INTR_DONE_A | SL811_INTR_SOF | SL811_INTR_INSRMV);
192 * This function disables SL811HS interrupts
194 static void sl811_disable_interrupt(struct sl811_hc *hc)
197 // Disable all other interrupt except for insert/remove.
198 sl811_write(hc, SL811_INTR, SL811_INTR_INSRMV);
202 * SL811 Virtual Root Hub
205 /* Device descriptor */
206 static __u8 sl811_rh_dev_des[] =
208 0x12, /* __u8 bLength; */
209 0x01, /* __u8 bDescriptorType; Device */
210 0x10, /* __u16 bcdUSB; v1.1 */
212 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
213 0x00, /* __u8 bDeviceSubClass; */
214 0x00, /* __u8 bDeviceProtocol; */
215 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
216 0x00, /* __u16 idVendor; */
218 0x00, /* __u16 idProduct; */
220 0x00, /* __u16 bcdDevice; */
222 0x00, /* __u8 iManufacturer; */
223 0x02, /* __u8 iProduct; */
224 0x01, /* __u8 iSerialNumber; */
225 0x01 /* __u8 bNumConfigurations; */
228 /* Configuration descriptor */
229 static __u8 sl811_rh_config_des[] =
231 0x09, /* __u8 bLength; */
232 0x02, /* __u8 bDescriptorType; Configuration */
233 0x19, /* __u16 wTotalLength; */
235 0x01, /* __u8 bNumInterfaces; */
236 0x01, /* __u8 bConfigurationValue; */
237 0x00, /* __u8 iConfiguration; */
238 0x40, /* __u8 bmAttributes;
239 Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup,
241 0x00, /* __u8 MaxPower; */
244 0x09, /* __u8 if_bLength; */
245 0x04, /* __u8 if_bDescriptorType; Interface */
246 0x00, /* __u8 if_bInterfaceNumber; */
247 0x00, /* __u8 if_bAlternateSetting; */
248 0x01, /* __u8 if_bNumEndpoints; */
249 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
250 0x00, /* __u8 if_bInterfaceSubClass; */
251 0x00, /* __u8 if_bInterfaceProtocol; */
252 0x00, /* __u8 if_iInterface; */
255 0x07, /* __u8 ep_bLength; */
256 0x05, /* __u8 ep_bDescriptorType; Endpoint */
257 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
258 0x03, /* __u8 ep_bmAttributes; Interrupt */
259 0x08, /* __u16 ep_wMaxPacketSize; */
261 0xff /* __u8 ep_bInterval; 255 ms */
264 /* root hub class descriptor*/
265 static __u8 sl811_rh_hub_des[] =
267 0x09, /* __u8 bLength; */
268 0x29, /* __u8 bDescriptorType; Hub-descriptor */
269 0x01, /* __u8 bNbrPorts; */
270 0x00, /* __u16 wHubCharacteristics; */
272 0x50, /* __u8 bPwrOn2pwrGood; 2ms */
273 0x00, /* __u8 bHubContrCurrent; 0 mA */
274 0xfc, /* __u8 DeviceRemovable; *** 7 Ports max *** */
275 0xff /* __u8 PortPwrCtrlMask; *** 7 ports max *** */
279 * This function examine the port change in the virtual root hub. HUB INTERRUPT ENDPOINT.
281 static int sl811_rh_send_irq(struct sl811_hc *hc, __u8 *rh_change, int rh_len)
288 * Right now, It is assume the power is good and no changes and only one port.
290 if (hc->rh_status.wPortChange & (USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE)) {
292 *(__u8 *)rh_change = data;
299 * This function creates a timer that act as interrupt pipe in the virtual hub.
301 * Note: The virtual root hub's interrupt pipe are polled by the timer
302 * every "interval" ms
304 static void sl811_rh_init_int_timer(struct urb * urb)
306 struct sl811_hc *hc = urb->dev->bus->hcpriv;
307 hc->rh.interval = urb->interval;
309 init_timer(&hc->rh.rh_int_timer);
310 hc->rh.rh_int_timer.function = sl811_rh_int_timer_do;
311 hc->rh.rh_int_timer.data = (unsigned long)urb;
312 hc->rh.rh_int_timer.expires = jiffies +
313 (HZ * (urb->interval < 30? 30: urb->interval)) / 1000;
314 add_timer (&hc->rh.rh_int_timer);
318 * This function is called when the timer expires. It gets the the port
319 * change data and pass along to the upper protocol.
321 static void sl811_rh_int_timer_do(unsigned long ptr)
324 struct urb *urb = (struct urb *)ptr;
325 struct sl811_hc *hc = urb->dev->bus->hcpriv;
329 len = sl811_rh_send_irq(hc, urb->transfer_buffer,
330 urb->transfer_buffer_length);
332 urb->actual_length = len;
341 struct list_head *head, *tmp;
342 struct sl811_urb_priv *urbp;
345 static int timeout_count = 0;
347 // check time out every second
348 if (++timeout_count > 4) {
349 int max_scan = hc->active_urbs;
351 for (i = 0; i < 6; ++i) {
352 head = &hc->urb_list[i];
354 while (tmp != head && max_scan--) {
355 u = list_entry(tmp, struct urb, urb_list);
356 urbp = (struct sl811_urb_priv *)u->hcpriv;
358 // Check if the URB timed out
359 if (u->timeout && time_after_eq(jiffies, urbp->inserttime + u->timeout)) {
360 PDEBUG(3, "urb = %p time out, we kill it", urb);
361 u->transfer_flags |= USB_TIMEOUT_KILLED;
369 // re-activate the timer
370 sl811_rh_init_int_timer(urb);
374 #define OK(x) len = (x); break
377 * This function handles all USB request to the the virtual root hub
379 static int sl811_rh_submit_urb(struct urb *urb)
381 struct usb_device *usb_dev = urb->dev;
382 struct sl811_hc *hc = usb_dev->bus->hcpriv;
383 struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *)urb->setup_packet;
384 void *data = urb->transfer_buffer;
385 int buf_len = urb->transfer_buffer_length;
386 unsigned int pipe = urb->pipe;
388 __u8 *bufp = data_buf;
397 if (usb_pipeint(pipe)) {
400 hc->rh.interval = urb->interval;
401 sl811_rh_init_int_timer(urb);
407 bmRType_bReq = cmd->bRequestType | (cmd->bRequest << 8);
408 wValue = le16_to_cpu (cmd->wValue);
409 wIndex = le16_to_cpu (cmd->wIndex);
410 wLength = le16_to_cpu (cmd->wLength);
412 PDEBUG(5, "submit rh urb, req = %d(%x) len=%d", bmRType_bReq, bmRType_bReq, wLength);
414 /* Request Destination:
415 without flags: Device,
416 USB_RECIP_INTERFACE: interface,
417 USB_RECIP_ENDPOINT: endpoint,
418 USB_TYPE_CLASS means HUB here,
419 USB_RECIP_OTHER | USB_TYPE_CLASS almost ever means HUB_PORT here
421 switch (bmRType_bReq) {
423 *(__u16 *)bufp = cpu_to_le16(1);
426 case RH_GET_STATUS | USB_RECIP_INTERFACE:
427 *(__u16 *)bufp = cpu_to_le16(0);
430 case RH_GET_STATUS | USB_RECIP_ENDPOINT:
431 *(__u16 *)bufp = cpu_to_le16(0);
434 case RH_GET_STATUS | USB_TYPE_CLASS:
435 *(__u32 *)bufp = cpu_to_le32(0);
438 case RH_GET_STATUS | USB_RECIP_OTHER | USB_TYPE_CLASS:
439 *(__u32 *)bufp = cpu_to_le32(hc->rh_status.wPortChange<<16 | hc->rh_status.wPortStatus);
442 case RH_CLEAR_FEATURE | USB_RECIP_ENDPOINT:
449 case RH_CLEAR_FEATURE | USB_TYPE_CLASS:
451 case C_HUB_LOCAL_POWER:
454 case C_HUB_OVER_CURRENT:
459 case RH_CLEAR_FEATURE | USB_RECIP_OTHER | USB_TYPE_CLASS:
461 case USB_PORT_FEAT_ENABLE:
462 hc->rh_status.wPortStatus &= ~USB_PORT_STAT_ENABLE;
465 case USB_PORT_FEAT_SUSPEND:
466 hc->rh_status.wPortStatus &= ~USB_PORT_STAT_SUSPEND;
469 case USB_PORT_FEAT_POWER:
470 hc->rh_status.wPortStatus &= ~USB_PORT_STAT_POWER;
473 case USB_PORT_FEAT_C_CONNECTION:
474 hc->rh_status.wPortChange &= ~USB_PORT_STAT_C_CONNECTION;
477 case USB_PORT_FEAT_C_ENABLE:
478 hc->rh_status.wPortChange &= ~USB_PORT_STAT_C_ENABLE;
481 case USB_PORT_FEAT_C_SUSPEND:
482 hc->rh_status.wPortChange &= ~USB_PORT_STAT_C_SUSPEND;
485 case USB_PORT_FEAT_C_OVER_CURRENT:
486 hc->rh_status.wPortChange &= ~USB_PORT_STAT_C_OVERCURRENT;
489 case USB_PORT_FEAT_C_RESET:
490 hc->rh_status.wPortChange &= ~USB_PORT_STAT_C_RESET;
495 case RH_SET_FEATURE | USB_RECIP_OTHER | USB_TYPE_CLASS:
497 case USB_PORT_FEAT_SUSPEND:
498 hc->rh_status.wPortStatus |= USB_PORT_STAT_SUSPEND;
501 case USB_PORT_FEAT_RESET:
502 hc->rh_status.wPortStatus |= USB_PORT_STAT_RESET;
503 hc->rh_status.wPortChange = 0;
504 hc->rh_status.wPortChange |= USB_PORT_STAT_C_RESET;
505 hc->rh_status.wPortStatus &= ~USB_PORT_STAT_RESET;
506 hc->rh_status.wPortStatus |= USB_PORT_STAT_ENABLE;
509 case USB_PORT_FEAT_POWER:
510 hc->rh_status.wPortStatus |= USB_PORT_STAT_POWER;
513 case USB_PORT_FEAT_ENABLE:
514 hc->rh_status.wPortStatus |= USB_PORT_STAT_ENABLE;
520 hc->rh.devnum = wValue;
523 case RH_GET_DESCRIPTOR:
524 switch ((wValue & 0xff00) >> 8) {
526 len = sizeof(sl811_rh_dev_des);
527 bufp = sl811_rh_dev_des;
531 len = sizeof(sl811_rh_config_des);
532 bufp = sl811_rh_config_des;
536 len = usb_root_hub_string(wValue & 0xff, (int)(long)0, "SL811HS", data, wLength);
547 case RH_GET_DESCRIPTOR | USB_TYPE_CLASS:
548 len = sizeof(sl811_rh_hub_des);
549 bufp = sl811_rh_hub_des;
552 case RH_GET_CONFIGURATION:
556 case RH_SET_CONFIGURATION:
560 PDEBUG(1, "unsupported root hub command");
564 len = min(len, buf_len);
566 memcpy(data, bufp, len);
567 urb->actual_length = len;
568 urb->status = status;
570 PDEBUG(5, "len = %d, status = %d", len, status);
581 * This function unlinks the URB
583 static int sl811_rh_unlink_urb(struct urb *urb)
585 struct sl811_hc *hc = urb->dev->bus->hcpriv;
589 if (hc->rh.urb == urb) {
591 del_timer(&hc->rh.rh_int_timer);
594 usb_dec_dev_use(urb->dev);
596 if (urb->transfer_flags & USB_ASYNC_UNLINK) {
597 urb->status = -ECONNRESET;
601 urb->status = -ENOENT;
608 * This function connect the virtual root hub to the USB stack
610 static int sl811_connect_rh(struct sl811_hc * hc)
612 struct usb_device *usb_dev;
615 usb_dev = usb_alloc_dev(NULL, hc->bus);
619 hc->bus->root_hub = usb_dev;
620 usb_connect(usb_dev);
622 if (usb_new_device(usb_dev)) {
623 usb_free_dev(usb_dev);
627 PDEBUG(5, "leave success");
633 * This function allocates private data space for the usb device
635 static int sl811_alloc_dev_priv(struct usb_device *usb_dev)
641 * This function de-allocates private data space for the usb devic
643 static int sl811_free_dev_priv (struct usb_device *usb_dev)
649 * This function allocates private data space for the urb
651 static struct sl811_urb_priv* sl811_alloc_urb_priv(struct urb *urb)
653 struct sl811_urb_priv *urbp;
655 urbp = kmalloc(sizeof(*urbp), GFP_ATOMIC);
659 memset(urbp, 0, sizeof(*urbp));
661 INIT_LIST_HEAD(&urbp->td_list);
670 * This function free private data space for the urb
672 static void sl811_free_urb_priv(struct urb *urb)
674 struct sl811_urb_priv *urbp = urb->hcpriv;
676 struct list_head *head, *tmp;
681 head = &urbp->td_list;
684 while (tmp != head) {
685 td = list_entry(tmp, struct sl811_td, td_list);
697 * This function calculate the bus time need by this td.
698 * Fix me! Can this use usb_calc_bus_time()?
700 static void sl811_calc_td_time(struct sl811_td *td)
705 struct sl811_hc *hc = td->urb->dev->bus->hcpriv;
707 if (hc->rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED)
708 time = 8*8*len + 1024;
710 if (td->ctrl & SL811_USB_CTRL_PREAMBLE)
711 time = 8*8*len + 2048;
724 int low_speed = usb_pipeslow(td->urb->pipe);
725 int input_dir = usb_pipein(td->urb->pipe);
726 int bytecount = td->len;
727 int isoc = usb_pipeisoc(td->urb->pipe);
729 if (low_speed) { /* no isoc. here */
731 tmp = (67667L * (31L + 10L * BitTime (bytecount))) / 1000L;
732 time = (64060L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
734 tmp = (66700L * (31L + 10L * BitTime (bytecount))) / 1000L;
735 time = (64107L + (2 * BW_HUB_LS_SETUP) + BW_HOST_DELAY + tmp);
737 } else if (!isoc){ /* for full-speed: */
738 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
739 time = (9107L + BW_HOST_DELAY + tmp);
740 } else { /* for isoc: */
741 tmp = (8354L * (31L + 10L * BitTime (bytecount))) / 1000L;
742 time = (((input_dir) ? 7268L : 6265L) + BW_HOST_DELAY + tmp);
745 td->bustime = time / 84;
751 * This function calculate the remainder bus time in current frame.
753 static inline int sl811_calc_bus_remainder(struct sl811_hc *hc)
755 return (sl811_read(hc, SL811_SOFCNTDIV) * 64);
759 * This function allocates td for the urb
761 static struct sl811_td* sl811_alloc_td(struct urb *urb)
763 struct sl811_urb_priv *urbp = urb->hcpriv;
766 td = kmalloc(sizeof (*td), GFP_ATOMIC);
770 memset(td, 0, sizeof(*td));
772 INIT_LIST_HEAD(&td->td_list);
775 list_add_tail(&td->td_list, &urbp->td_list);
783 static inline void sl811_fill_td(struct sl811_td *td, __u8 ctrl, __u8 addr, __u8 len, __u8 pidep, __u8 dev, __u8 *buf)
798 static inline void sl811_reset_td(struct sl811_td *td)
808 static void sl811_print_td(int level, struct sl811_td *td)
810 PDEBUG(level, "td = %p, ctrl = %x, addr = %x, len = %x, pidep = %x\n "
811 "dev = %x, status = %x, left = %x, errcnt = %x, done = %x\n "
812 "buf = %p, bustime = %d, td_status = %d\n",
813 td, td->ctrl, td->addr, td->len, td->pidep,
814 td->dev, td->status, td->left, td->errcnt, td->done,
815 td->buf, td->bustime, td->td_status);
819 * Isochronous transfers
821 static int sl811_submit_isochronous(struct urb *urb)
823 __u8 dev = usb_pipedevice(urb->pipe);
824 __u8 pidep = PIDEP(usb_packetid(urb->pipe), usb_pipeendpoint(urb->pipe));
826 struct sl811_urb_priv *urbp = urb->hcpriv;
827 struct sl811_td *td = NULL;
830 PDEBUG(4, "enter, urb = %p, urbp = %p", urb, urbp);
832 /* Can't have low speed bulk transfers */
833 if (usb_pipeslow(urb->pipe)) {
834 PDEBUG(1, "error, urb = %p, low speed device", urb);
838 if (usb_pipeout(urb->pipe))
839 ctrl |= SL811_USB_CTRL_DIR_OUT;
841 ctrl |= SL811_USB_CTRL_ARM | SL811_USB_CTRL_ENABLE | SL811_USB_CTRL_ISO;
843 for (i = 0; i < urb->number_of_packets; i++) {
844 urb->iso_frame_desc[i].actual_length = 0;
845 urb->iso_frame_desc[i].status = -EXDEV;
847 td = sl811_alloc_td(urb);
851 sl811_fill_td(td, ctrl, SL811_DATA_START,
852 urb->iso_frame_desc[i].length,
854 urb->transfer_buffer + urb->iso_frame_desc[i].offset);
855 sl811_calc_td_time(td);
856 if (urbp->cur_td == NULL)
857 urbp->cur_td = urbp->first_td = td;
862 PDEBUG(4, "leave success");
867 struct list_head *head, *tmp;
870 head = &urbp->td_list;
873 if (list_empty(&urbp->td_list)) {
874 PDEBUG(1, "bug!!! td list is empty!");
878 while (tmp != head) {
880 td = list_entry(tmp, struct sl811_td, td_list);
881 PDEBUG(2, "td = %p, i = %d", td, i);
890 * Reset isochronous transfers
892 static void sl811_reset_isochronous(struct urb *urb)
894 struct sl811_urb_priv *urbp = urb->hcpriv;
895 struct sl811_td *td = NULL;
896 struct list_head *head, *tmp;
899 PDEBUG(4, "enter, urb = %p", urb);
901 for (i = 0; i < urb->number_of_packets; i++) {
902 urb->iso_frame_desc[i].actual_length = 0;
903 urb->iso_frame_desc[i].status = -EXDEV;
906 head = &urbp->td_list;
908 while (tmp != head) {
909 td = list_entry(tmp, struct sl811_td, td_list);
914 urbp->cur_td = urbp->first_td;
916 urb->status = -EINPROGRESS;
917 urb->actual_length = 0;
918 urb->error_count = 0;
922 * Result the iso urb.
924 static void sl811_result_isochronous(struct urb *urb)
926 struct list_head *tmp, *head;
927 struct sl811_urb_priv *urbp = urb->hcpriv;
932 PDEBUG(4, "enter, urb = %p", urb);
934 urb->actual_length = 0;
937 head = &urbp->td_list;
939 while (tmp != head) {
940 td = list_entry(tmp, struct sl811_td, td_list);
945 urb->status = -ENOENT;
947 PDEBUG(1, "we should not get here!");
948 urb->status = -EXDEV;
953 status = td->td_status;
955 PDEBUG(1, "error: td = %p, td status = %d", td, td->td_status);
958 urb->iso_frame_desc[i].actual_length = td->len - td->left;
959 urb->actual_length += td->len - td->left;
960 urb->iso_frame_desc[i].status = td->td_status;
963 PDEBUG(3, "short packet, td = %p, len = %d, left = %d", td, td->len, td->left);
966 urb->status = status;
969 PDEBUG(2, "iso urb complete, len = %d, status =%d ", urb->actual_length, urb->status);
971 PDEBUG(4, "leave success");
975 * Interrupt transfers
977 static int sl811_submit_interrupt(struct urb *urb)
979 int maxsze = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
980 int len = urb->transfer_buffer_length;
981 __u8 *data = urb->transfer_buffer;
982 __u8 dev = usb_pipedevice(urb->pipe);
983 __u8 pidep = PIDEP(usb_packetid(urb->pipe), usb_pipeendpoint(urb->pipe));
985 struct sl811_hc *hc = urb->dev->bus->hcpriv;
986 struct sl811_urb_priv *urbp = urb->hcpriv;
987 struct sl811_td *td = NULL;
989 PDEBUG(4, "enter, urb = %p", urb);
992 PDEBUG(1, "length is big than max packet size, len = %d, max packet = %d", len, maxsze);
995 if (usb_pipeslow(urb->pipe) && !(hc->rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED))
996 ctrl |= SL811_USB_CTRL_PREAMBLE;
998 ctrl |= SL811_USB_CTRL_ARM | SL811_USB_CTRL_ENABLE;
999 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)))
1000 ctrl |= SL811_USB_CTRL_TOGGLE_1;
1001 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe));
1002 td = sl811_alloc_td(urb);
1006 sl811_fill_td(td, ctrl, SL811_DATA_START, len, pidep, dev, data);
1007 sl811_calc_td_time(td);
1008 urbp->cur_td = urbp->first_td = urbp->last_td = td;
1011 PDEBUG(4, "leave success");
1017 * Reset interrupt transfers
1019 static void sl811_reset_interrupt(struct urb *urb)
1021 struct sl811_urb_priv *urbp = urb->hcpriv;
1022 struct sl811_td *td = urbp->cur_td;
1024 PDEBUG(4, "enter, interval = %d", urb->interval);
1026 td->ctrl &= ~SL811_USB_CTRL_TOGGLE_1;
1027 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)))
1028 td->ctrl |= SL811_USB_CTRL_TOGGLE_1;
1029 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe));
1033 urbp->interval = urb->interval;
1035 urb->status = -EINPROGRESS;
1036 urb->actual_length = 0;
1040 * Result the interrupt urb.
1042 static void sl811_result_interrupt(struct urb *urb)
1044 struct list_head *tmp;
1045 struct sl811_urb_priv *urbp = urb->hcpriv;
1046 struct sl811_td *td;
1049 PDEBUG(4, "enter, urb = %p", urb);
1051 urb->actual_length = 0;
1053 tmp = &urbp->td_list;
1055 td = list_entry(tmp, struct sl811_td, td_list);
1058 if (td->done && td->td_status == 0) {
1059 urb->actual_length += td->len - td->left;
1063 // tranfer is done but fail, reset the toggle.
1064 else if (td->done && td->td_status) {
1065 urb->status = td->td_status;
1067 toggle = (td->ctrl & SL811_USB_CTRL_TOGGLE_1) ? 1 : 0;
1068 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), toggle);
1069 PDEBUG(3, "error: td = %p, td status = %d", td, td->td_status);
1072 // unlink, and not do transfer yet
1073 else if (td->done == 0 && urbp->unlink && td->td_status == 0) {
1074 urb->status = -ENOENT;
1075 PDEBUG(3, "unlink and not transfer!");
1078 // unlink, and transfer not complete yet.
1079 else if (td->done == 0 && urbp->unlink && td->td_status) {
1080 urb->status = -ENOENT;
1081 PDEBUG(3, "unlink and not complete!");
1085 else {// (td->done == 0 && urbp->unlink == 0)
1086 PDEBUG(1, "we should not get here!");
1087 urb->status = -EPIPE;
1095 static int sl811_submit_control(struct urb *urb)
1097 int maxsze = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
1098 int len = urb->transfer_buffer_length;
1099 __u8 *data = urb->transfer_buffer;
1100 __u8 dev = usb_pipedevice(urb->pipe);
1103 struct sl811_hc *hc = urb->dev->bus->hcpriv;
1104 struct sl811_urb_priv *urbp = urb->hcpriv;
1105 struct sl811_td *td = NULL;
1107 PDEBUG(4, "enter, urb = %p", urb);
1109 if (usb_pipeslow(urb->pipe) && !(hc->rh_status.wPortStatus & USB_PORT_STAT_LOW_SPEED))
1110 ctrl |= SL811_USB_CTRL_PREAMBLE;
1112 /* Build SETUP TD */
1113 pidep = PIDEP(USB_PID_SETUP, usb_pipeendpoint(urb->pipe));
1114 ctrl |= SL811_USB_CTRL_ARM | SL811_USB_CTRL_ENABLE | SL811_USB_CTRL_DIR_OUT;
1115 td = sl811_alloc_td(urb);
1119 sl811_fill_td(td, ctrl, SL811_DATA_START, 8, pidep, dev, urb->setup_packet);
1120 sl811_calc_td_time(td);
1122 urbp->cur_td = urbp->first_td = td;
1125 * If direction is "send", change the frame from SETUP (0x2D)
1126 * to OUT (0xE1). Else change it from SETUP to IN (0x69).
1128 pidep = PIDEP(usb_packetid(urb->pipe), usb_pipeendpoint(urb->pipe));
1129 if (usb_pipeout(urb->pipe))
1130 ctrl |= SL811_USB_CTRL_DIR_OUT;
1132 ctrl &= ~SL811_USB_CTRL_DIR_OUT;
1134 /* Build the DATA TD's */
1138 if (pktsze > maxsze)
1141 /* Alternate Data0/1 (start with Data1) */
1142 ctrl ^= SL811_USB_CTRL_TOGGLE_1;
1144 td = sl811_alloc_td(urb);
1148 sl811_fill_td(td, ctrl, SL811_DATA_START, pktsze, pidep, dev, data);
1149 sl811_calc_td_time(td);
1155 /* Build the final TD for control status */
1156 td = sl811_alloc_td(urb);
1160 /* It's IN if the pipe is an output pipe or we're not expecting data back */
1161 if (usb_pipeout(urb->pipe) || !urb->transfer_buffer_length) {
1162 pidep = PIDEP(USB_PID_IN, usb_pipeendpoint(urb->pipe));
1163 ctrl &= ~SL811_USB_CTRL_DIR_OUT;
1165 pidep = PIDEP(USB_PID_OUT, usb_pipeendpoint(urb->pipe));
1166 ctrl |= SL811_USB_CTRL_DIR_OUT;
1170 ctrl |= SL811_USB_CTRL_TOGGLE_1;
1172 sl811_fill_td(td, ctrl, SL811_DATA_START, 0, pidep, dev, 0);
1173 sl811_calc_td_time(td);
1178 struct list_head *head, *tmp;
1179 struct sl811_td *td;
1181 head = &urbp->td_list;
1184 if (list_empty(&urbp->td_list)) {
1185 PDEBUG(1, "bug!!! td list is empty!");
1189 while (tmp != head) {
1191 td = list_entry(tmp, struct sl811_td, td_list);
1192 PDEBUG(3, "td = %p, i = %d", td, i);
1197 PDEBUG(4, "leave success");
1203 * Result the control urb.
1205 static void sl811_result_control(struct urb *urb)
1207 struct list_head *tmp, *head;
1208 struct sl811_urb_priv *urbp = urb->hcpriv;
1209 struct sl811_td *td;
1211 PDEBUG(4, "enter, urb = %p", urb);
1213 if (list_empty(&urbp->td_list)) {
1214 PDEBUG(1, "td list is empty");
1218 head = &urbp->td_list;
1221 td = list_entry(tmp, struct sl811_td, td_list);
1223 /* The first TD is the SETUP phase, check the status, but skip the count */
1225 PDEBUG(3, "setup phase error, td = %p, done = %d", td, td->done);
1228 if (td->td_status) {
1229 PDEBUG(3, "setup phase error, td = %p, td status = %d", td, td->td_status);
1233 urb->actual_length = 0;
1235 /* The rest of the TD's (but the last) are data */
1237 while (tmp != head && tmp->next != head) {
1238 td = list_entry(tmp, struct sl811_td, td_list);
1241 PDEBUG(3, "data phase error, td = %p, done = %d", td, td->done);
1244 if (td->td_status) {
1245 PDEBUG(3, "data phase error, td = %p, td status = %d", td, td->td_status);
1249 urb->actual_length += td->len - td->left;
1252 PDEBUG(3, "data phase short packet, td = %p, count = %d", td, td->len - td->left);
1257 /* The last td is status phase */
1260 PDEBUG(3, "status phase error, td = %p, done = %d", td, td->done);
1263 if (td->td_status) {
1264 PDEBUG(3, "status phase error, td = %p, td status = %d", td, td->td_status);
1268 PDEBUG(4, "leave success");
1275 urb->status = -ENOENT;
1277 PDEBUG(1, "we should not get here! td = %p", td);
1278 urb->status = -EPIPE;
1283 urb->status = td->td_status;
1290 static int sl811_submit_bulk(struct urb *urb)
1292 int maxsze = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
1293 int len = urb->transfer_buffer_length;
1294 __u8 *data = urb->transfer_buffer;
1295 __u8 dev = usb_pipedevice(urb->pipe);
1296 __u8 pidep = PIDEP(usb_packetid(urb->pipe), usb_pipeendpoint(urb->pipe));
1298 struct sl811_urb_priv *urbp = urb->hcpriv;
1299 struct sl811_td *td = NULL;
1301 PDEBUG(4, "enter, urb = %p", urb);
1304 PDEBUG(1, "error, urb = %p, len = %d", urb, len);
1308 /* Can't have low speed bulk transfers */
1309 if (usb_pipeslow(urb->pipe)) {
1310 PDEBUG(1, "error, urb = %p, low speed device", urb);
1314 if (usb_pipeout(urb->pipe))
1315 ctrl |= SL811_USB_CTRL_DIR_OUT;
1317 ctrl |= SL811_USB_CTRL_ARM | SL811_USB_CTRL_ENABLE;
1319 /* Build the DATA TD's */
1320 do { /* Allow zero length packets */
1323 if (pktsze > maxsze)
1326 td = sl811_alloc_td(urb);
1330 /* Alternate Data0/1 (start with Data1) */
1331 ctrl &= ~SL811_USB_CTRL_TOGGLE_1;
1332 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)))
1333 ctrl |= SL811_USB_CTRL_TOGGLE_1;
1334 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe));
1336 sl811_fill_td(td, ctrl, SL811_DATA_START, pktsze, pidep, dev, data);
1337 sl811_calc_td_time(td);
1339 if (urbp->cur_td == NULL)
1340 urbp->cur_td = urbp->first_td = td;
1347 * USB_ZERO_PACKET means adding a 0-length packet, if
1348 * direction is OUT and the transfer_length was an
1349 * exact multiple of maxsze, hence
1350 * (len = transfer_length - N * maxsze) == 0
1351 * however, if transfer_length == 0, the zero packet
1352 * was already prepared above.
1354 if (usb_pipeout(urb->pipe) && (urb->transfer_flags & USB_ZERO_PACKET) &&
1355 !len && urb->transfer_buffer_length) {
1357 td = sl811_alloc_td(urb);
1361 /* Alternate Data0/1 (start with Data1) */
1362 ctrl &= ~SL811_USB_CTRL_TOGGLE_1;
1363 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)))
1364 ctrl |= SL811_USB_CTRL_TOGGLE_1;
1365 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe));
1367 sl811_fill_td(td, ctrl, SL811_DATA_START, 0, pidep, dev, 0);
1368 sl811_calc_td_time(td);
1373 PDEBUG(4, "leave success");
1379 * Reset bulk transfers
1381 static int sl811_reset_bulk(struct urb *urb)
1383 struct sl811_urb_priv *urbp = urb->hcpriv;
1384 struct sl811_td *td;
1385 struct list_head *head, *tmp;
1387 PDEBUG(4, "enter, urb = %p", urb);
1390 head = &urbp->td_list;
1393 while (tmp != head) {
1394 td = list_entry(tmp, struct sl811_td, td_list);
1396 /* Alternate Data0/1 (start with Data1) */
1397 td->ctrl &= ~SL811_USB_CTRL_TOGGLE_1;
1398 if (usb_gettoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe)))
1399 td->ctrl |= SL811_USB_CTRL_TOGGLE_1;
1400 usb_dotoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe));
1405 urb->status = -EINPROGRESS;
1406 urb->actual_length = 0;
1407 urbp->cur_td = urbp->first_td;
1409 PDEBUG(4, "leave success");
1415 * Result the bulk urb.
1417 static void sl811_result_bulk(struct urb *urb)
1419 struct list_head *tmp, *head;
1420 struct sl811_urb_priv *urbp = urb->hcpriv;
1421 struct sl811_td *td = NULL;
1424 PDEBUG(4, "enter, urb = %p", urb);
1426 urb->actual_length = 0;
1428 head = &urbp->td_list;
1430 while (tmp != head) {
1431 td = list_entry(tmp, struct sl811_td, td_list);
1435 if (td->done && td->td_status == 0) {
1436 urb->actual_length += td->len - td->left;
1441 PDEBUG(3, "short packet, td = %p, count = %d", td, td->len - td->left);
1445 // tranfer is done but fail, reset the toggle.
1446 else if (td->done && td->td_status) {
1447 urb->status = td->td_status;
1448 PDEBUG(3, "error: td = %p, td status = %d", td, td->td_status);
1451 // unlink, and not do transfer yet
1452 else if (td->done == 0 && urbp->unlink && td->td_status == 0) {
1453 urb->status = -ENOENT;
1454 PDEBUG(3, "unlink and not transfer!");
1457 // unlink, and transfer not complete yet.
1458 else if (td->done == 0 && urbp->unlink && td->td_status) {
1459 PDEBUG(3, "unlink and not complete!");
1460 urb->status = -ENOENT;
1464 else {// (td->done == 0 && urbp->unlink == 0)
1465 urb->status = -EPIPE;
1466 PDEBUG(1, "we should not get here!");
1471 PDEBUG(4, "leave success");
1476 toggle = (td->ctrl & SL811_USB_CTRL_TOGGLE_1) ? 1 : 0;
1477 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), toggle);
1481 * Find the first urb have the same dev and endpoint.
1483 static inline int sl811_find_same_urb(struct list_head *head, struct urb *urb)
1485 struct list_head *tmp;
1493 while (tmp != head) {
1494 u = list_entry(tmp, struct urb, urb_list);
1504 * Find the first urb have the same dev and endpoint.
1506 static inline struct urb* sl811_find_same_devep(struct list_head *head, struct urb *urb)
1508 struct list_head *tmp;
1516 while (tmp != head) {
1517 u = list_entry(tmp, struct urb, urb_list);
1518 if ((usb_pipe_endpdev(u->pipe)) == (usb_pipe_endpdev(urb->pipe)))
1527 * This function is called by the USB core API when an URB is available to
1530 static int sl811_submit_urb(struct urb *urb)
1532 struct sl811_hc *hc = urb->dev->bus->hcpriv;
1533 unsigned int pipe = urb->pipe;
1534 struct list_head *head = NULL;
1535 unsigned long flags;
1540 PDEBUG(1, "urb is null");
1545 PDEBUG(1, "urbp is not null, urb = %p, urbp = %p", urb, urb->hcpriv);
1549 if (!urb->dev || !urb->dev->bus || !hc) {
1550 PDEBUG(1, "dev or bus or hc is null");
1554 if (usb_endpoint_halted(urb->dev, usb_pipeendpoint(pipe), usb_pipeout(pipe))) {
1555 PDEBUG(2, "sl811_submit_urb: endpoint_halted");
1559 if (usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)) > SL811_DATA_LIMIT) {
1560 printk(KERN_ERR "Packet size is big for SL811, should < %d!\n", SL811_DATA_LIMIT);
1564 /* a request to the virtual root hub */
1565 if (usb_pipedevice(pipe) == hc->rh.devnum)
1566 return sl811_rh_submit_urb(urb);
1568 spin_lock_irqsave(&hc->hc_lock, flags);
1569 spin_lock(&urb->lock);
1571 switch (usb_pipetype(urb->pipe)) {
1572 case PIPE_ISOCHRONOUS:
1573 head = &hc->iso_list;
1575 case PIPE_INTERRUPT:
1576 head = &hc->intr_list;
1579 head = &hc->ctrl_list;
1582 head = &hc->bulk_list;
1586 if (sl811_find_same_devep(head, urb)) {
1587 list_add(&urb->urb_list, &hc->wait_list);
1588 PDEBUG(4, "add to wait list");
1592 if (!sl811_alloc_urb_priv(urb)) {
1597 switch (usb_pipetype(urb->pipe)) {
1598 case PIPE_ISOCHRONOUS:
1599 if (urb->number_of_packets <= 0) {
1603 bustime = usb_check_bandwidth(urb->dev, urb);
1608 if (!(ret = sl811_submit_isochronous(urb)))
1609 usb_claim_bandwidth(urb->dev, urb, bustime, 1);
1611 case PIPE_INTERRUPT:
1612 bustime = usb_check_bandwidth(urb->dev, urb);
1615 else if (!(ret = sl811_submit_interrupt(urb)))
1616 usb_claim_bandwidth(urb->dev, urb, bustime, 0);
1619 ret = sl811_submit_control(urb);
1622 ret = sl811_submit_bulk(urb);
1627 ((struct sl811_urb_priv *)urb->hcpriv)->inserttime = jiffies;
1628 list_add(&urb->urb_list, head);
1629 PDEBUG(4, "add to type list");
1630 urb->status = -EINPROGRESS;
1631 if (++hc->active_urbs == 1)
1632 sl811_enable_interrupt(hc);
1635 PDEBUG(2, "submit urb fail! error = %d", ret);
1636 sl811_free_urb_priv(urb);
1640 spin_unlock(&urb->lock);
1641 spin_unlock_irqrestore(&hc->hc_lock, flags);
1647 * Submit the urb the wait list.
1649 static int sl811_submit_urb_with_lock(struct urb *urb)
1651 struct sl811_hc *hc = urb->dev->bus->hcpriv;
1652 struct list_head *head = NULL;
1656 spin_lock(&urb->lock);
1658 switch (usb_pipetype(urb->pipe)) {
1659 case PIPE_ISOCHRONOUS:
1660 head = &hc->iso_list;
1662 case PIPE_INTERRUPT:
1663 head = &hc->intr_list;
1666 head = &hc->ctrl_list;
1669 head = &hc->bulk_list;
1673 if (!sl811_alloc_urb_priv(urb)) {
1678 switch (usb_pipetype(urb->pipe)) {
1679 case PIPE_ISOCHRONOUS:
1680 if (urb->number_of_packets <= 0) {
1684 bustime = usb_check_bandwidth(urb->dev, urb);
1689 if (!(ret = sl811_submit_isochronous(urb)))
1690 usb_claim_bandwidth(urb->dev, urb, bustime, 1);
1692 case PIPE_INTERRUPT:
1693 bustime = usb_check_bandwidth(urb->dev, urb);
1696 else if (!(ret = sl811_submit_interrupt(urb)))
1697 usb_claim_bandwidth(urb->dev, urb, bustime, 0);
1700 ret = sl811_submit_control(urb);
1703 ret = sl811_submit_bulk(urb);
1708 ((struct sl811_urb_priv *)urb->hcpriv)->inserttime = jiffies;
1709 list_add(&urb->urb_list, head);
1710 PDEBUG(4, "add to type list");
1711 urb->status = -EINPROGRESS;
1712 if (++hc->active_urbs == 1)
1713 sl811_enable_interrupt(hc);
1716 PDEBUG(2, "submit urb fail! error = %d", ret);
1717 sl811_free_urb_priv(urb);
1721 spin_unlock(&urb->lock);
1729 static void sl811_reset_urb(struct urb *urb)
1731 struct sl811_urb_priv *urbp = urb->hcpriv;
1733 switch (usb_pipetype(urb->pipe)) {
1734 case PIPE_ISOCHRONOUS:
1735 sl811_reset_isochronous(urb);
1737 case PIPE_INTERRUPT:
1738 sl811_reset_interrupt(urb);
1743 sl811_reset_bulk(urb);
1746 urbp->inserttime = jiffies;
1750 * Return the result of a transfer
1752 static void sl811_result_urb(struct urb *urb)
1754 struct sl811_urb_priv *urbp = urb->hcpriv;
1755 struct sl811_hc *hc = urb->dev->bus->hcpriv;
1756 struct list_head *head = NULL;
1757 struct urb *u = NULL;
1761 if (urb->status != -EINPROGRESS) {
1762 PDEBUG(1, "urb status is not EINPROGRESS!");
1766 spin_lock(&urb->lock);
1768 switch (usb_pipetype(urb->pipe)) {
1769 case PIPE_ISOCHRONOUS:
1770 head = &hc->iso_list;
1771 sl811_result_isochronous(urb);
1773 // if the urb is not unlink and is in a urb "ring", we reset it
1774 if (!urbp->unlink && urb->next)
1777 case PIPE_INTERRUPT:
1778 head = &hc->intr_list;
1779 sl811_result_interrupt(urb);
1781 // if the urb is not unlink and not "once" query, we reset.
1782 if (!urbp->unlink && urb->interval)
1786 head = &hc->ctrl_list;
1787 sl811_result_control(urb);
1790 head = &hc->bulk_list;
1791 sl811_result_bulk(urb);
1793 // if the urb is not unlink and is in a urb "ring", we reset it
1794 if (!urbp->unlink && urb->next)
1799 PDEBUG(4, "result urb status = %d", urb->status);
1801 if (ring && urb->next == urb)
1805 switch (usb_pipetype(urb->pipe)) {
1806 case PIPE_ISOCHRONOUS:
1807 usb_release_bandwidth(urb->dev, urb, 1);
1809 case PIPE_INTERRUPT:
1810 usb_release_bandwidth(urb->dev, urb, 0);
1813 sl811_free_urb_priv(urb);
1816 spin_unlock(&urb->lock);
1822 spin_lock(&urb->lock);
1823 sl811_reset_urb(urb);
1824 if (usb_pipeint(urb->pipe))
1825 list_add(&urb->urb_list, &hc->idle_intr_list);
1827 list_add(&urb->urb_list, head);
1828 spin_unlock(&urb->lock);
1830 if (--hc->active_urbs <= 0) {
1831 hc->active_urbs = 0;
1832 sl811_disable_interrupt(hc);
1838 u = sl811_find_same_devep(&hc->wait_list, urb);
1841 if (!list_empty(&u->urb_list))
1842 list_del(&u->urb_list);
1843 if (sl811_submit_urb_with_lock(u))
1844 list_add(&u->urb_list, &hc->wait_list);
1850 #ifdef SL811_TIMEOUT
1853 * Unlink the urb from the urb list
1855 static int sl811_unlink_urb(struct urb *urb)
1857 unsigned long flags;
1858 struct sl811_hc *hc;
1859 struct sl811_urb_priv *urbp;
1865 PDEBUG(1, "urb is null");
1869 if (!urb->dev || !urb->dev->bus) {
1870 PDEBUG(1, "dev or bus is null");
1874 hc = urb->dev->bus->hcpriv;
1877 /* a request to the virtual root hub */
1878 if (usb_pipedevice(urb->pipe) == hc->rh.devnum)
1879 return sl811_rh_unlink_urb(urb);
1881 spin_lock_irqsave(&hc->hc_lock, flags);
1882 spin_lock(&urb->lock);
1885 if (sl811_find_same_urb(&hc->wait_list, urb)) {
1886 PDEBUG(4, "unlink urb in wait list");
1887 list_del_init(&urb->urb_list);
1888 urb->status = -ENOENT;
1893 // in intr idle list.
1894 if (sl811_find_same_urb(&hc->idle_intr_list, urb)) {
1895 PDEBUG(4, "unlink urb in idle intr list");
1896 list_del_init(&urb->urb_list);
1897 urb->status = -ENOENT;
1898 sl811_free_urb_priv(urb);
1899 usb_release_bandwidth(urb->dev, urb, 0);
1900 if (--hc->active_urbs <= 0) {
1901 hc->active_urbs = 0;
1902 sl811_disable_interrupt(hc);
1908 if (urb->status == -EINPROGRESS) {
1909 PDEBUG(3, "urb is still in progress");
1913 // Is it in progress?
1915 if (urbp && hc->cur_td == urbp->cur_td) {
1917 if (sl811_read(hc, 0) & SL811_USB_CTRL_ARM) {
1918 PDEBUG(3, "unlink: cur td is still in progress! count = %d", count);
1921 spin_unlock(&urb->lock);
1922 spin_unlock_irqrestore(&hc->hc_lock, flags);
1923 schedule_timeout(HZ/50);
1924 spin_lock_irqsave(&hc->hc_lock, flags);
1925 spin_lock(&urb->lock);
1927 PDEBUG(3, "unlink: lost of interrupt? do parse! count = %d", count);
1928 spin_unlock(&urb->lock);
1929 sl811_transfer_done(hc, 0);
1930 spin_lock(&urb->lock);
1935 if (list_empty(&urb->urb_list)) {
1936 PDEBUG(3, "unlink: list empty!");
1940 if (urb->transfer_flags & USB_TIMEOUT_KILLED) {
1941 PDEBUG(3, "unlink: time out killed");
1942 // it is timeout killed by us
1944 } else if (urb->transfer_flags & USB_ASYNC_UNLINK) {
1945 // we do nothing, just let it be processing later
1946 PDEBUG(3, "unlink async, do nothing");
1949 // synchron without callback
1950 PDEBUG(3, "unlink synchron, we wait the urb complete or timeout");
1951 if (schedule == 0) {
1952 PDEBUG(3, "goto re_schedule");
1955 PDEBUG(3, "already scheduled");
1959 } else if (!list_empty(&urb->urb_list)) {
1960 PDEBUG(1, "urb = %p, status = %d is in a list, why?", urb, urb->status);
1961 //list_del_init(&urb->urb_list);
1966 spin_unlock(&urb->lock);
1967 spin_unlock_irqrestore(&hc->hc_lock, flags);
1969 if (call && urb->complete)
1975 spin_unlock(&urb->lock);
1977 list_del_init(&urb->urb_list);
1978 sl811_result_urb(urb);
1980 spin_unlock_irqrestore(&hc->hc_lock, flags);
1988 * Unlink the urb from the urb list
1990 static int sl811_unlink_urb(struct urb *urb)
1992 unsigned long flags;
1993 struct sl811_hc *hc;
1994 struct sl811_urb_priv *urbp;
1998 PDEBUG(1, "urb is null");
2002 if (!urb->dev || !urb->dev->bus) {
2003 PDEBUG(1, "dev or bus is null");
2007 hc = urb->dev->bus->hcpriv;
2010 /* a request to the virtual root hub */
2011 if (usb_pipedevice(urb->pipe) == hc->rh.devnum)
2012 return sl811_rh_unlink_urb(urb);
2014 spin_lock_irqsave(&hc->hc_lock, flags);
2015 spin_lock(&urb->lock);
2018 if (sl811_find_same_urb(&hc->wait_list, urb)) {
2019 PDEBUG(2, "unlink urb in wait list");
2020 list_del_init(&urb->urb_list);
2021 urb->status = -ENOENT;
2026 if (urb->status == -EINPROGRESS) {
2027 PDEBUG(2, "urb is still in progress");
2030 // Is it in progress?
2032 if (urbp && hc->cur_td == urbp->cur_td) {
2033 // simple, let it out
2034 PDEBUG(2, "unlink: cur td is still in progress!");
2039 } else if (!list_empty(&urb->urb_list)) {
2040 PDEBUG(1, "urb = %p, status = %d is in a list, why?", urb, urb->status);
2041 list_del_init(&urb->urb_list);
2049 spin_unlock(&urb->lock);
2050 spin_unlock_irqrestore(&hc->hc_lock, flags);
2052 if (call && urb->complete)
2058 spin_unlock(&urb->lock);
2060 list_del_init(&urb->urb_list);
2061 sl811_result_urb(urb);
2063 spin_unlock_irqrestore(&hc->hc_lock, flags);
2070 static int sl811_get_current_frame_number(struct usb_device *usb_dev)
2072 return ((struct sl811_hc *)(usb_dev->bus->hcpriv))->frame_number;
2075 static struct usb_operations sl811_device_operations =
2077 sl811_alloc_dev_priv,
2078 sl811_free_dev_priv,
2079 sl811_get_current_frame_number,
2085 * This functions transmit a td.
2087 static inline void sl811_trans_cur_td(struct sl811_hc *hc, struct sl811_td *td)
2089 sl811_print_td(4, td);
2090 sl811_write_buf(hc, SL811_ADDR_A, &td->addr, 4);
2091 if (td->len && (td->ctrl & SL811_USB_CTRL_DIR_OUT))
2092 sl811_write_buf(hc, td->addr, td->buf, td->len);
2094 sl811_write(hc, SL811_CTRL_A, td->ctrl);
2099 * This function checks the status of the transmitted or received packet
2100 * and copy the data from the SL811HS register into a buffer.
2102 static void sl811_parse_cur_td(struct sl811_hc *hc, struct sl811_td *td)
2104 struct urb *urb = td->urb;
2106 int dev = usb_pipedevice(td->urb->pipe);
2107 int ep = usb_pipeendpoint(td->urb->pipe);
2110 sl811_read_buf(hc, SL811_STS_A, &td->status, 2);
2112 if (td->status & SL811_USB_STS_ACK) {
2115 /* if ((td->ctrl & SL811_USB_CTRL_TOGGLE_1) != (td->status & SL811_USB_STS_TOGGLE_1)) {
2116 PDEBUG(2, "dev %d endpoint %d unexpect data toggle!", dev, ep);
2117 td->td_status = -EILSEQ;
2120 if (!(td->ctrl & SL811_USB_CTRL_DIR_OUT) && td->len > 0)
2121 sl811_read_buf(hc, td->addr, td->buf, td->len - td->left);
2123 if (td->left && (urb->transfer_flags & USB_DISABLE_SPD)) {
2124 PDEBUG(2, "dev %d endpoint %d unexpect short packet! td = %p", dev, ep, td);
2125 td->td_status = -EREMOTEIO;
2128 } else if (td->status & SL811_USB_STS_STALL) {
2129 PDEBUG(2, "dev %d endpoint %d halt, td = %p", dev, ep, td);
2130 td->td_status = -EPIPE;
2132 usb_endpoint_halt(td->urb->dev, usb_pipeendpoint(td->urb->pipe), usb_pipeout(td->urb->pipe));
2134 } else if (td->status & SL811_USB_STS_OVERFLOW) {
2135 PDEBUG(1, "dev %d endpoint %d overflow, sl811 only support packet less than %d", dev, ep, SL811_DATA_LIMIT);
2136 td->td_status = -EOVERFLOW;
2138 } else if (td->status & SL811_USB_STS_TIMEOUT ) {
2139 PDEBUG(2, "dev %d endpoint %d timeout, td = %p", dev, ep, td);
2140 td->td_status = -ETIMEDOUT;
2141 if (--td->errcnt == 0)
2143 } else if (td->status & SL811_USB_STS_ERROR) {
2144 PDEBUG(2, "dev %d endpoint %d error, td = %p", dev, ep, td);
2145 td->td_status = -EILSEQ;
2146 if (--td->errcnt == 0)
2148 } else if (td->status & SL811_USB_STS_NAK) {
2150 PDEBUG(3, "dev %d endpoint %d nak, td = %p, count = %d", dev, ep, td, td->nakcnt);
2151 td->td_status = -EINPROGRESS;
2152 if (!usb_pipeslow(td->urb->pipe) && td->nakcnt > 1024) {
2153 PDEBUG(2, "too many naks, td = %p, count = %d", td, td->nakcnt);
2154 td->td_status = -ETIMEDOUT;
2159 sl811_print_td(4, td);
2163 * This function checks the status of current urb.
2165 static int sl811_parse_cur_urb(struct urb *urb)
2167 struct sl811_urb_priv *urbp = urb->hcpriv;
2168 struct sl811_td *td = urbp->cur_td;
2169 struct list_head *tmp;
2171 sl811_print_td(5, td);
2173 // this td not done yet.
2177 // the last ld, so the urb is done.
2178 if (td == urbp->last_td) {
2179 PDEBUG(4, "urb = %p is done success", td->urb);
2180 if (usb_pipeisoc(td->urb->pipe))
2181 PDEBUG(4, "ISO URB DONE, td = %p", td);
2185 // iso transfer, we always advance to next td
2186 if (usb_pipeisoc(td->urb->pipe)) {
2189 urbp->cur_td = list_entry(tmp, struct sl811_td, td_list);
2190 PDEBUG(4, "ISO NEXT, td = %p", urbp->cur_td);
2194 // some error occur, so the urb is done.
2195 if (td->td_status) {
2196 PDEBUG(3, "urb = %p is done error, td status is = %d", td->urb, td->td_status);
2202 if (usb_pipecontrol(td->urb->pipe)) {
2203 // control packet, we advance to the last td
2204 PDEBUG(3, "ctrl short packet, advance to last td");
2205 urbp->cur_td = urbp->last_td;
2208 // interrut and bulk packet, urb is over.
2209 PDEBUG(3, "bulk or intr short packet, urb is over");
2214 // we advance to next td.
2217 urbp->cur_td = list_entry(tmp, struct sl811_td, td_list);
2219 PDEBUG(4, "advance to the next td, urb = %p, td = %p", urb, urbp->cur_td);
2220 sl811_print_td(5, urbp->cur_td);
2221 if (td == urbp->cur_td)
2222 PDEBUG(1, "bug!!!");
2228 * Find the next td to transfer.
2230 static inline struct sl811_td* sl811_schedule_next_td(struct urb *urb, struct sl811_td *cur_td)
2232 struct sl811_urb_priv *urbp = urb->hcpriv;
2234 PDEBUG(4, "urb at %p, cur td at %p", urb, cur_td);
2236 // iso don't schedule the td in the same frame.
2237 if (usb_pipeisoc(cur_td->urb->pipe))
2240 // cur td is not complete
2244 // here, urbp->cur_td is already the next td;
2245 return urbp->cur_td;
2249 * Scan the list to find a active urb
2251 static inline struct urb* sl811_get_list_next_urb(struct sl811_hc *hc, struct list_head *next)
2256 if (list_empty(next))
2259 if (next == hc->cur_list)
2262 for (i = 0; i < 4; ++i)
2263 if (next == &hc->urb_list[i])
2266 urb = list_entry(next, struct urb, urb_list);
2267 PDEBUG(4, "next urb in list is at %p", urb);
2273 * Find the next td to transfer.
2275 static struct sl811_td* sl811_schedule_next_urb(struct sl811_hc *hc, struct list_head *next)
2277 struct urb *urb = NULL;
2279 struct list_head *old_list = hc->cur_list;
2281 // try to get next urb in the same list.
2283 urb = sl811_get_list_next_urb(hc, next);
2291 // try all the list.
2292 while (hc->cur_list < &hc->urb_list[4]) {
2293 if ((urb = sl811_get_list_next_urb(hc, hc->cur_list->next)))
2294 return ((struct sl811_urb_priv *)urb->hcpriv)->cur_td;
2297 // the last list is try
2298 if (back_loop && (old_list >= &hc->ctrl_list)) {
2299 hc->cur_list = &hc->ctrl_list;
2305 if (hc->cur_list > &hc->urb_list[3])
2306 hc->cur_list = &hc->ctrl_list;
2312 * This function process the transfer rusult.
2314 static void sl811_transfer_done(struct sl811_hc *hc, int sof)
2316 struct sl811_td *cur_td = hc->cur_td, *next_td = NULL;
2317 struct urb *cur_urb = NULL;
2318 struct list_head *next = NULL;
2323 if (cur_td == NULL) {
2324 PDEBUG(1, "in done interrupt, but td is null, be already parsed?");
2328 cur_urb = cur_td->urb;
2330 next = &cur_urb->urb_list;
2333 spin_lock(&cur_urb->lock);
2334 sl811_parse_cur_td(hc, cur_td);
2335 done = sl811_parse_cur_urb(cur_urb);
2336 spin_unlock(&cur_urb->lock);
2339 list_del_init(&cur_urb->urb_list);
2341 sl811_result_urb(cur_urb);
2348 next_td = sl811_schedule_next_td(cur_urb, cur_td);
2349 if (next_td && next_td != cur_td && (sl811_calc_bus_remainder(hc) > next_td->bustime)) {
2350 hc->cur_td = next_td;
2351 PDEBUG(5, "ADD TD");
2352 sl811_trans_cur_td(hc, next_td);
2358 next_td = sl811_schedule_next_urb(hc, next);
2361 if (next_td == cur_td)
2363 next = &next_td->urb->urb_list;
2365 if (sl811_calc_bus_remainder(hc) > next_td->bustime) {
2366 hc->cur_td = next_td;
2367 PDEBUG(5, "ADD TD");
2368 sl811_trans_cur_td(hc, next_td);
2377 static void inline sl811_dec_intr_interval(struct sl811_hc *hc)
2379 struct list_head *head, *tmp;
2381 struct sl811_urb_priv *urbp;
2383 if (list_empty(&hc->idle_intr_list))
2386 head = &hc->idle_intr_list;
2389 while (tmp != head) {
2390 urb = list_entry(tmp, struct urb, urb_list);
2392 spin_lock(&urb->lock);
2394 if (--urbp->interval == 0) {
2395 list_del(&urb->urb_list);
2396 list_add(&urb->urb_list, &hc->intr_list);
2397 PDEBUG(4, "intr urb active");
2399 spin_unlock(&urb->lock);
2404 * The sof interrupt is happen.
2406 static void sl811_start_sof(struct sl811_hc *hc)
2408 struct sl811_td *next_td;
2410 static struct sl811_td *repeat_td = NULL;
2411 static int repeat_cnt = 1;
2413 if (++hc->frame_number > 1024)
2414 hc->frame_number = 0;
2416 if (hc->active_urbs == 0)
2419 sl811_dec_intr_interval(hc);
2422 if (sl811_read(hc, 0) & SL811_USB_CTRL_ARM) {
2424 if (repeat_td == hc->cur_td)
2427 if (repeat_cnt >= 2)
2428 PDEBUG(2, "cur td = %p repeat %d", hc->cur_td, repeat_cnt);
2430 repeat_td = hc->cur_td;
2435 PDEBUG(2, "lost of interrupt in sof? do parse!");
2436 sl811_transfer_done(hc, 1);
2438 // let this frame idle
2443 hc->cur_list = &hc->iso_list;
2445 if (hc->active_urbs == 0)
2448 next_td = sl811_schedule_next_urb(hc, NULL);
2451 if (list_empty(&hc->idle_intr_list))
2452 PDEBUG(2, "not schedule a td, why? urbs = %d", hc->active_urbs);
2456 if (sl811_calc_bus_remainder(hc) > next_td->bustime) {
2457 hc->cur_td = next_td;
2458 sl811_trans_cur_td(hc, next_td);
2460 PDEBUG(2, "bus time if not enough, why?");
2464 * This function resets SL811HS controller and detects the speed of
2465 * the connecting device
2467 * Return: 0 = no device attached; 1 = USB device attached
2469 static int sl811_hc_reset(struct sl811_hc *hc)
2473 sl811_write(hc, SL811_CTRL2, SL811_CTL2_HOST | SL811_12M_HI);
2474 sl811_write(hc, SL811_CTRL1, SL811_CTRL1_RESET);
2478 // Disable hardware SOF generation, clear all irq status.
2479 sl811_write(hc, SL811_CTRL1, 0);
2481 sl811_write(hc, SL811_INTRSTS, 0xff);
2482 status = sl811_read(hc, SL811_INTRSTS);
2484 if (status & SL811_INTR_NOTPRESENT) {
2485 // Device is not present
2486 PDEBUG(0, "Device not present");
2487 hc->rh_status.wPortStatus &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE);
2488 hc->rh_status.wPortChange |= USB_PORT_STAT_C_CONNECTION;
2489 sl811_write(hc, SL811_INTR, SL811_INTR_INSRMV);
2493 // Send SOF to address 0, endpoint 0.
2494 sl811_write(hc, SL811_LEN_B, 0);
2495 sl811_write(hc, SL811_PIDEP_B, PIDEP(USB_PID_SOF, 0));
2496 sl811_write(hc, SL811_DEV_B, 0x00);
2497 sl811_write (hc, SL811_SOFLOW, SL811_12M_HI);
2499 if (status & SL811_INTR_SPEED_FULL) {
2500 /* full speed device connect directly to root hub */
2501 PDEBUG (0, "Full speed Device attached");
2503 sl811_write(hc, SL811_CTRL1, SL811_CTRL1_RESET);
2505 sl811_write(hc, SL811_CTRL2, SL811_CTL2_HOST | SL811_12M_HI);
2506 sl811_write(hc, SL811_CTRL1, SL811_CTRL1_SOF);
2508 /* start the SOF or EOP */
2509 sl811_write(hc, SL811_CTRL_B, SL811_USB_CTRL_ARM);
2510 hc->rh_status.wPortStatus |= USB_PORT_STAT_CONNECTION;
2511 hc->rh_status.wPortStatus &= ~USB_PORT_STAT_LOW_SPEED;
2513 sl811_write (hc, SL811_INTRSTS, 0xff);
2515 /* slow speed device connect directly to root-hub */
2516 PDEBUG(0, "Low speed Device attached");
2518 sl811_write(hc, SL811_CTRL1, SL811_CTRL1_RESET);
2520 sl811_write(hc, SL811_CTRL2, SL811_CTL2_HOST | SL811_CTL2_DSWAP | SL811_12M_HI);
2521 sl811_write(hc, SL811_CTRL1, SL811_CTRL1_SPEED_LOW | SL811_CTRL1_SOF);
2523 /* start the SOF or EOP */
2524 sl811_write(hc, SL811_CTRL_B, SL811_USB_CTRL_ARM);
2525 hc->rh_status.wPortStatus |= USB_PORT_STAT_CONNECTION | USB_PORT_STAT_LOW_SPEED;
2527 sl811_write(hc, SL811_INTRSTS, 0xff);
2530 hc->rh_status.wPortChange |= USB_PORT_STAT_C_CONNECTION;
2531 sl811_write(hc, SL811_INTR, SL811_INTR_INSRMV);
2537 * Interrupt service routine.
2539 static void sl811_interrupt(int irq, void *__hc, struct pt_regs * r)
2542 struct sl811_hc *hc = __hc;
2544 status = sl811_read(hc, SL811_INTRSTS);
2546 return ; /* Not me */
2548 sl811_write(hc, SL811_INTRSTS, 0xff);
2550 if (status & SL811_INTR_INSRMV) {
2551 sl811_write(hc, SL811_INTR, 0);
2552 sl811_write(hc, SL811_CTRL1, 0);
2553 // wait for device stable
2559 spin_lock(&hc->hc_lock);
2561 if (status & SL811_INTR_DONE_A) {
2562 if (status & SL811_INTR_SOF) {
2563 sl811_transfer_done(hc, 1);
2564 PDEBUG(4, "sof in done!");
2565 sl811_start_sof(hc);
2567 sl811_transfer_done(hc, 0);
2568 } else if (status & SL811_INTR_SOF)
2569 sl811_start_sof(hc);
2571 spin_unlock(&hc->hc_lock);
2577 * This function allocates all data structure and store in the
2578 * private data structure.
2580 * Return value : data structure for the host controller
2582 static struct sl811_hc* __devinit sl811_alloc_hc(void)
2584 struct sl811_hc *hc;
2585 struct usb_bus *bus;
2590 hc = (struct sl811_hc *)kmalloc(sizeof(struct sl811_hc), GFP_KERNEL);
2594 memset(hc, 0, sizeof(struct sl811_hc));
2596 hc->rh_status.wPortStatus = USB_PORT_STAT_POWER;
2597 hc->rh_status.wPortChange = 0;
2599 hc->active_urbs = 0;
2600 INIT_LIST_HEAD(&hc->hc_hcd_list);
2601 list_add(&hc->hc_hcd_list, &sl811_hcd_list);
2603 init_waitqueue_head(&hc->waitq);
2605 for (i = 0; i < 6; ++i)
2606 INIT_LIST_HEAD(&hc->urb_list[i]);
2608 hc->cur_list = &hc->iso_list;
2610 bus = usb_alloc_bus(&sl811_device_operations);
2617 bus->bus_name = MODNAME;
2624 * This function De-allocate all resources
2626 static void sl811_release_hc(struct sl811_hc *hc)
2630 /* disconnect all devices */
2631 if (hc->bus->root_hub)
2632 usb_disconnect(&hc->bus->root_hub);
2634 // Stop interrupt handle
2636 free_irq(hc->irq, hc);
2639 /* Stop interrupt for sharing, but only, if PatternTest ok */
2641 /* Disable Interrupts */
2642 sl811_write(hc, SL811_INTR, 0);
2644 /* Remove all Interrupt events */
2646 sl811_write(hc, SL811_INTRSTS, 0xff);
2649 /* free io regions */
2650 sl811_release_regions(hc);
2652 usb_deregister_bus(hc->bus);
2653 usb_free_bus(hc->bus);
2655 list_del(&hc->hc_hcd_list);
2656 INIT_LIST_HEAD(&hc->hc_hcd_list);
2662 * This function request IO memory regions, request IRQ, and
2663 * allocate all other resources.
2665 * Input: addr_io = first IO address
2666 * data_io = second IO address
2667 * irq = interrupt number
2669 * Return: 0 = success or error condition
2671 static int __devinit sl811_found_hc(int addr_io, int data_io, int irq)
2673 struct sl811_hc *hc;
2677 hc = sl811_alloc_hc();
2681 if (sl811_request_regions (hc, addr_io, data_io, MODNAME)) {
2682 PDEBUG(1, "ioport %X,%X is in use!", addr_io, data_io);
2683 sl811_release_hc(hc);
2687 if (sl811_reg_test(hc)) {
2688 PDEBUG(1, "SL811 register test failed!");
2689 sl811_release_hc(hc);
2693 #ifdef SL811_DEBUG_VERBOSE
2695 __u8 u = SL811Read (hci, SL11H_HWREVREG);
2697 // Show the hardware revision of chip
2698 PDEBUG(1, "SL811 HW: %02Xh", u);
2700 case 0x00: PDEBUG(1, "SL11H"); break;
2701 case 0x10: PDEBUG(1, "SL811HS rev1.2"); break;
2702 case 0x20: PDEBUG(1, "SL811HS rev1.5"); break;
2703 default: PDEBUG(1, "Revision unknown!");
2706 #endif // SL811_DEBUG_VERBOSE
2710 usb_register_bus(hc->bus);
2712 if (request_irq(irq, sl811_interrupt, SA_SHIRQ, MODNAME, hc)) {
2713 PDEBUG(1, "request interrupt %d failed", irq);
2714 sl811_release_hc(hc);
2719 printk(KERN_INFO __FILE__ ": USB SL811 at %x,%x, IRQ %d\n",
2720 addr_io, data_io, irq);
2723 sl811_connect_rh(hc);
2729 * This is an init function, and it is the first function being called
2731 * Return: 0 = success or error condition
2733 static int __init sl811_hcd_init(void)
2740 info(DRIVER_VERSION " : " DRIVER_DESC);
2742 // registering some instance
2743 for (count = 0; count < MAX_CONTROLERS; count++) {
2745 ret = sl811_found_hc(io[count], io[count]+OFFSET_DATA_REG, irq[count]);
2755 * This is a cleanup function, and it is called when module is unloaded.
2757 static void __exit sl811_hcd_cleanup(void)
2759 struct list_head *list = sl811_hcd_list.next;
2760 struct sl811_hc *hc;
2764 for (; list != &sl811_hcd_list; ) {
2765 hc = list_entry(list, struct sl811_hc, hc_hcd_list);
2767 sl811_release_hc(hc);
2771 module_init(sl811_hcd_init);
2772 module_exit(sl811_hcd_cleanup);
2774 MODULE_AUTHOR(DRIVER_AUTHOR);
2775 MODULE_DESCRIPTION(DRIVER_DESC);