patch-2.3.34 linux/drivers/usb/ohci-hcd.c
Next file: linux/drivers/usb/ohci-hcd.h
Previous file: linux/drivers/usb/ohci-debug.c
Back to the patch index
Back to the overall index
- Lines: 2948
- Date:
Mon Dec 20 14:07:38 1999
- Orig file:
v2.3.33/linux/drivers/usb/ohci-hcd.c
- Orig date:
Tue Dec 7 09:32:46 1999
diff -u --recursive --new-file v2.3.33/linux/drivers/usb/ohci-hcd.c linux/drivers/usb/ohci-hcd.c
@@ -1,20 +1,21 @@
/*
- * OHCI HCD (Host Controller Driver) for USB.
+ * URB OHCI HCD (Host Controller Driver) for USB.
*
* (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
- *
- * The OHCI HCD layer is a simple but nearly complete implementation of what
- * the USB people would call a HCD for the OHCI.
- * (ISO alpha , Bulk, INT u. CTRL transfers enabled)
- * The layer on top of it, is for interfacing to the alternate-usb
- * device-drivers.
*
- * [ This is based on Linus' UHCI code and gregs OHCI fragments
- * (0.03c source tree). ]
- * [ Open Host Controller Interface driver for USB. ]
- * [ (C) Copyright 1999 Linus Torvalds (uhci.c) ]
- * [ (C) Copyright 1999 Gregory P. Smith <greg@electricrain.com> ]
+ * [ Initialisation is based on Linus' ]
+ * [ uhci code and gregs ohci fragments ]
+ * [ (C) Copyright 1999 Linus Torvalds ]
+ * [ (C) Copyright 1999 Gregory P. Smith]
+ *
*
+ * History:
+ *
+ * v5.2 1999/12/07 URB 3rd preview,
+ * v5.1 1999/11/30 URB 2nd preview, cpia, (usb-scsi)
+ * v5.0 1999/11/22 URB Technical preview, Paul Mackerras powerbook susp/resume
+ * i386: HUB, Keyboard, Mouse, Printer
+ *
* v4.3 1999/10/27 multiple HCs, bulk_request
* v4.2 1999/09/05 ISO API alpha, new dev alloc, neg Error-codes
* v4.1 1999/08/27 Randy Dunlap's - ISO API first impl.
@@ -22,18 +23,10 @@
* v3.0 1999/06/25
* v2.1 1999/05/09 code clean up
* v2.0 1999/05/04
- * virtual root hub is now enabled,
- * memory allocation based on kmalloc and kfree now, Bus error handling,
- * INT, CTRL and BULK transfers enabled, ISO needs testing (alpha)
- *
- * from Linus Torvalds (uhci.c) (APM not tested; hub, usb_device, bus and related stuff)
- * from Greg Smith (ohci.c) (reset controller handling, hub)
- *
* v1.0 1999/04/27 initial release
- * ohci-hcd.c
+ *
+
*/
-
-
#include <linux/config.h>
#include <linux/module.h>
@@ -46,584 +39,514 @@
#include <linux/smp_lock.h>
#include <linux/errno.h>
#include <linux/timer.h>
-#include <linux/spinlock.h>
+// #include <linux/spinlock.h>
#include <linux/list.h>
+#include <linux/interrupt.h> /* for in_interrupt() */
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
+// #define DEBUG
+
#include "usb.h"
#include "ohci-hcd.h"
+
+#ifdef DEBUG
+ #define dbg(format, arg...) printk(format, ## arg)
+#else
+ #define dbg(format, arg...)
+#endif
+
#ifdef CONFIG_APM
#include <linux/apm_bios.h>
-static int handle_apm_event(apm_event_t event);
-static int apm_resume = 0;
+static int handle_apm_event (apm_event_t event);
#endif
-static LIST_HEAD(ohci_hcd_list);
-
-static int ohci_link_ed(struct ohci * ohci, struct usb_ohci_ed *ed);
-static int sohci_kill_isoc (struct usb_isoc_desc *id);
-static int sohci_get_current_frame_number (struct usb_device *usb_dev);
-static int sohci_run_isoc(struct usb_isoc_desc *id, struct usb_isoc_desc *pr_id);
-static DECLARE_WAIT_QUEUE_HEAD(op_wakeup);
-
-void usb_pipe_to_hcd_ed(struct usb_device *usb_dev, unsigned int pipe, struct usb_hcd_ed *hcd_ed)
-{
- hcd_ed->endpoint = usb_pipeendpoint(pipe);
- hcd_ed->out = usb_pipeout(pipe);
- hcd_ed->function = usb_pipedevice(pipe);
- hcd_ed->type = usb_pipetype(pipe);
- hcd_ed->slow = usb_pipeslow(pipe);
- hcd_ed->maxpack = usb_maxpacket(usb_dev, pipe, usb_pipeout(pipe));
- OHCI_DEBUG(printk("******* hcd_ed: pipe: %8x, endpoint: %4x, function: %4x, out: %4x, type: %4x, slow: %4x, maxpack: %4x\n", pipe, hcd_ed->endpoint, hcd_ed->function, hcd_ed->out, hcd_ed->type, hcd_ed->slow, hcd_ed->maxpack); )
-OHCI_DEBUG(printk("******* dev: devnum: %4x, slow: %4x, maxpacketsize: %4x\n",usb_dev->devnum, usb_dev->slow, usb_dev->maxpacketsize); )
-}
+#ifdef CONFIG_PMAC_PBOOK
+#include <linux/adb.h>
+#include <linux/pmu.h>
+#endif
-/********
- **** Interface functions
- ***********************************************/
-
-static int sohci_blocking_handler(void * ohci_in, struct usb_ohci_td *td, void * data, int data_len, int dlen, int status, __OHCI_BAG lw0, __OHCI_BAG lw1)
-{
- struct usb_ohci_ed *ed = td->ed;
- if(lw0 != NULL) {
- if((status == USB_ST_DATAUNDERRUN || status == USB_ST_NOERROR))
- ((struct ohci_state * )lw0)->status = data_len;
- else
- ((struct ohci_state * )lw0)->status = status;
- ((struct ohci_state * )lw0)->len = data_len;
- }
- if(lw1 != NULL) {
- add_wait_queue(&op_wakeup, lw1);
- wake_up(&op_wakeup);
- }
-
- OHCI_DEBUG( { int i; printk("USB HC bh <<<: %x: ", ed->hwINFO);)
- OHCI_DEBUG( printk(" data(%d):", data_len);)
- OHCI_DEBUG( for(i=0; i < data_len; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk(" ret_status: %x\n", status); })
-
- return 0;
-}
-
-static int sohci_int_handler(void * ohci_in, struct usb_ohci_td *td, void * data, int data_len, int dlen, int status, __OHCI_BAG lw0, __OHCI_BAG lw1)
-{
- struct usb_ohci_ed *ed = td->ed;
- struct ohci * ohci = ohci_in;
- usb_device_irq handler=(void *) lw0;
- void *dev_id = (void *) lw1;
- int ret;
+static DECLARE_WAIT_QUEUE_HEAD (op_wakeup);
+static LIST_HEAD (ohci_hcd_list);
+spinlock_t usb_ed_lock = SPIN_LOCK_UNLOCKED;
- OHCI_DEBUG({ int i; printk("USB HC IRQ <<<: %x: data(%d):", ed->hwINFO, data_len);)
- OHCI_DEBUG( for(i=0; i < data_len; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk(" ret_status: %x\n", status); })
-
- ret = handler(status, data, data_len, dev_id);
- if(ret == 0) return 0; /* 0 .. do not requeue */
- if(status < 0) return -1; /* error occured do not requeue ? */
- ohci_trans_req(ohci, ed, 0, NULL, data, (ed->hwINFO >> 16) & 0x3f, (__OHCI_BAG) handler, (__OHCI_BAG) dev_id, INT_IN, sohci_int_handler); /* requeue int request */
+/*-------------------------------------------------------------------------*
+ * URB support functions
+ *-------------------------------------------------------------------------*/
- return 0;
-}
-
-static int sohci_ret_handler(void * ohci_in, struct usb_ohci_td *td, void * data, int data_len, int dlen, int status, __OHCI_BAG lw0, __OHCI_BAG lw1)
-{
- struct usb_ohci_ed *ed = td->ed;
- struct ohci * ohci = ohci_in;
- usb_device_irq handler=(void *) lw0;
- void *dev_id = (void *) lw1;
- int ret;
-
- OHCI_DEBUG({ int i; printk("USB HC RET <<<: %x: data(%d):", ed->hwINFO, data_len);)
- OHCI_DEBUG( for(i=0; i < data_len; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk(" ret_status: %x\n", status); })
-
- ret = handler(status, data, data_len, dev_id);
- if(ret == 0) return 0; /* 0 .. do not requeue */
- if(status > 0) return -1; /* error occured do not requeue ? */
- ohci_trans_req(ohci, ed, 0, NULL, data, dlen, (__OHCI_BAG) handler, (__OHCI_BAG) dev_id, td->type & 0x7, sohci_ret_handler); /* requeue int request */
+/* free the private part of an URB */
- return 0;
-}
-
-static int sohci_iso_handler(void * ohci_in, struct usb_ohci_td *td, void * data, int data_len, int dlen, int status, __OHCI_BAG lw0, __OHCI_BAG lw1) {
-
- // struct ohci * ohci = ohci_in;
- struct usb_ohci_ed *ed = td->ed;
- unsigned int ix = (unsigned int) lw0;
- struct usb_isoc_desc * id = (struct usb_isoc_desc *) lw1;
- struct usb_ohci_td **tdp = id->td;
- int ret = 0;
- int fx;
-
- OHCI_DEBUG({ int i; printk("USB HC ISO |||: %x: data(%d):", ed->hwINFO, data_len);)
- OHCI_DEBUG( for(i=0; i < 16 ; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk(" ... ret_status: %x\n", status); })
-
- tdp[ix] = NULL;
- id->frames[ix].frame_length = data_len;
- id->frames[ix].frame_status = status;
- id->total_length += data_len;
- if(status) id->error_count++;
-
- id->cur_completed_frame++;
- id->total_completed_frames++;
-
- if(id->cur_completed_frame == id->callback_frames) {
- id->prev_completed_frame = id->cur_completed_frame;
- id->cur_completed_frame = 0;
- OHCI_DEBUG(printk("USB HC ISO <<<: %x: \n", ed->hwINFO);)
- ret = id->callback_fn(id->error_count, id->data, id->total_length, id);
- switch (ret) {
- case CB_CONT_RUN:
- for (fx = 0; fx < id->frame_count; fx++)
- id->frames[fx].frame_length = id->frame_size;
- sohci_run_isoc(id, id->prev_isocdesc);
- break;
-
- case CB_CONTINUE:
- break;
-
- case CB_REUSE:
- break;
-
- case CB_RESTART:
- break;
-
- case CB_ABORT:
- sohci_kill_isoc(id);
- break;
+static void urb_rm_priv (urb_t * urb)
+{
+ urb_priv_t * urb_priv = urb->hcpriv;
+ int i;
+ void * wait;
+
+ if (!urb_priv) return;
+
+ wait = urb_priv->wait;
+
+ for (i = 0; i < urb_priv->length; i++) {
+ if (urb_priv->td [i]) {
+ OHCI_FREE (urb_priv->td [i]);
}
}
+ kfree (urb->hcpriv);
+ urb->hcpriv = NULL;
- return 0;
-}
-
-static int sohci_request_irq(struct usb_device *usb_dev, unsigned int pipe, usb_device_irq handler, int period, void *dev_id, void **handle, long bustime)
-{
- struct ohci * ohci = usb_dev->bus->hcpriv;
- struct ohci_device * dev = usb_to_ohci(usb_dev);
- struct usb_hcd_ed hcd_ed;
- struct usb_ohci_ed * ed;
-
-#ifdef VROOTHUB
- if(usb_pipedevice(pipe) == ohci->rh.devnum)
- return root_hub_request_irq(usb_dev, pipe, handler, period, dev_id, handle);
-#endif
-
- usb_pipe_to_hcd_ed(usb_dev, pipe, &hcd_ed);
- hcd_ed.type = INT;
- ed = usb_ohci_add_ep(usb_dev, &hcd_ed, period, 1);
-
- OHCI_DEBUG( printk("USB HC IRQ>>>: %x: every %d ms\n", ed->hwINFO, period);)
-
- ohci_trans_req(ohci, ed, 0, NULL, dev->data, hcd_ed.maxpack, (__OHCI_BAG) handler, (__OHCI_BAG) dev_id, INT_IN, sohci_int_handler);
- if (ED_STATE(ed) != ED_OPER) ohci_link_ed(ohci, ed);
- *handle = ed;
- return 0;
-
+ if (wait) {
+ add_wait_queue (&op_wakeup, wait);
+ wake_up (&op_wakeup);
+ }
}
-static int sohci_release_irq(struct usb_device *usb_dev, void * ed)
-{
- // struct usb_device *usb_dev = ((struct ohci_device *) ((unsigned int)ed & 0xfffff000))->usb;
- struct ohci * ohci = usb_dev->bus->hcpriv;
-
- OHCI_DEBUG( printk("USB HC ***** RM_IRQ>>>:%4x\n", (unsigned int) ed);)
-
- if(ed == NULL) return 0;
-
-#ifdef VROOTHUB
- if(ed == ohci->rh.int_addr)
- return root_hub_release_irq(usb_dev, ed);
-#endif
- ED_setSTATE((struct usb_ohci_ed *)ed, ED_STOP);
-
- usb_ohci_rm_ep(usb_dev, (struct usb_ohci_ed *) ed, NULL, NULL, NULL, 0);
+/*-------------------------------------------------------------------------*/
- return 0;
-}
+#ifdef DEBUG
+static int sohci_get_current_frame_number (struct usb_device * dev);
-static int sohci_control_msg(struct usb_device *usb_dev, unsigned int pipe, devrequest *cmd, void *data, int len, int timeout)
+/* debug| print the main components of an URB
+ * small: 0) header + data packets 1) just header */
+
+static void urb_print (urb_t * urb, char * str, int small)
{
- DECLARE_WAITQUEUE(wait, current);
- struct ohci_state state = {0, TD_NOTACCESSED};
- struct ohci * ohci = usb_dev->bus->hcpriv;
- struct usb_hcd_ed hcd_ed;
- struct usb_ohci_ed *ed;
-
-#ifdef VROOTHUB
- if(usb_pipedevice(pipe) == ohci->rh.devnum)
- return root_hub_control_msg(usb_dev, pipe, cmd, data, len);
-#endif
-
- usb_pipe_to_hcd_ed(usb_dev, pipe, &hcd_ed);
- hcd_ed.type = CTRL;
-
- ed = usb_ohci_add_ep(usb_dev, &hcd_ed, 0, 1);
+ unsigned int pipe= urb->pipe;
+ int i, len;
- OHCI_DEBUG( { int i; printk("USB HC CTRL>>>: ed:%x-%x: ctrl(%d):", (unsigned int) ed, ed->hwINFO, 8);)
- OHCI_DEBUG( for(i=0; i < 8; i++ ) printk(" %02x", ((__u8 *) cmd)[i]);)
- OHCI_DEBUG( printk(" data(%d):", len);)
- OHCI_DEBUG( for(i=0; i < len; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk("\n"); })
- current->state = TASK_UNINTERRUPTIBLE;
-
- ohci_trans_req(ohci, ed, 8, cmd, data, len, (__OHCI_BAG) &state, (__OHCI_BAG) &wait, (usb_pipeout(pipe))?CTRL_OUT:CTRL_IN, sohci_blocking_handler);
-
- OHCI_DEBUG(printk("USB HC trans req ed %x: %x :", ed->hwINFO, (unsigned int ) ed); )
- OHCI_DEBUG({ int i; for( i= 0; i<8 ;i++) printk(" %4x", ((unsigned int *) ed)[i]) ; printk("\n"); }; )
- if (ED_STATE(ed) != ED_OPER) ohci_link_ed(ohci, ed);
- schedule_timeout(timeout);
-
- if(state.status == TD_NOTACCESSED) {
- current->state = TASK_UNINTERRUPTIBLE;
- usb_ohci_rm_ep(usb_dev, ed, sohci_blocking_handler, NULL, NULL, 0);
- schedule();
- state.status = USB_ST_TIMEOUT;
- }
- remove_wait_queue(&op_wakeup, &wait);
- return state.status;
-}
-
-static int sohci_bulk_msg(struct usb_device *usb_dev, unsigned int pipe, void *data, int len, unsigned long *rval, int timeout)
-{
- DECLARE_WAITQUEUE(wait, current);
- struct ohci_state state = {0, TD_NOTACCESSED};
- struct ohci * ohci = usb_dev->bus->hcpriv;
- struct usb_hcd_ed hcd_ed;
- struct usb_ohci_ed *ed;
+ if (!urb->dev || !urb->dev->bus) {
+ printk(KERN_DEBUG " %s URB: no dev\n", str);
+ return;
+ }
- usb_pipe_to_hcd_ed(usb_dev, pipe, &hcd_ed);
- hcd_ed.type = BULK;
- ed = usb_ohci_add_ep(usb_dev, &hcd_ed, 0, 1);
- OHCI_DEBUG( { int i; printk("USB HC BULK>>>: %x: ", ed->hwINFO);)
- OHCI_DEBUG( printk(" data(%d):", len);)
- OHCI_DEBUG( for(i=0; i < len; i++ ) printk(" %02x", ((__u8 *) data)[i]);)
- OHCI_DEBUG( printk("\n"); })
- current->state = TASK_UNINTERRUPTIBLE;
-
- ohci_trans_req(ohci, ed, 0, NULL, data, len, (__OHCI_BAG) &state, (__OHCI_BAG) &wait,(usb_pipeout(pipe))?BULK_OUT:BULK_IN, sohci_blocking_handler);
- if (ED_STATE(ed) != ED_OPER) ohci_link_ed(ohci, ed);
+ printk (KERN_DEBUG "%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,"
+ "flags:%4x,len:%d/%d,stat:%d(%x)\n",
+ str,
+ sohci_get_current_frame_number (urb->dev),
+ usb_pipedevice (pipe),
+ usb_pipeendpoint (pipe),
+ usb_pipeout (pipe)? 'O': 'I',
+ usb_pipetype (pipe) < 2? (usb_pipeint (pipe)? "INTR": "ISOC"):
+ (usb_pipecontrol (pipe)? "CTRL": "BULK"),
+ urb->transfer_flags,
+ urb->actual_length,
+ urb->transfer_buffer_length,
+ urb->status, urb->status);
+ if (!small) {
+ if (usb_pipecontrol (pipe)) {
+ printk (KERN_DEBUG " cmd(8):");
+ for (i = 0; i < 8 ; i++)
+ printk (" %02x", ((__u8 *) urb->setup_packet) [i]);
+ printk ("\n");
+ }
+ if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
+ printk (KERN_DEBUG " data(%d/%d):",
+ urb->actual_length,
+ urb->transfer_buffer_length);
+ len = usb_pipeout (pipe)?
+ urb->transfer_buffer_length: urb->actual_length;
+ for (i = 0; i < 16 && i < len; i++)
+ printk (" %02x", ((__u8 *) urb->transfer_buffer) [i]);
+ printk ("%s stat:%d\n", i < len? "...": "", urb->status);
+ }
+ }
- schedule_timeout(timeout);
-
- if(state.status == TD_NOTACCESSED) {
- current->state = TASK_UNINTERRUPTIBLE;
- usb_ohci_rm_ep(usb_dev, ed, sohci_blocking_handler, NULL, NULL, 0);
- schedule();
- state.status = USB_ST_TIMEOUT;
+}
+/* just for debugging; prints all 32 branches of the int ed tree inclusive iso eds*/
+void ep_print_int_eds (ohci_t * ohci, char * str) {
+ int i, j;
+ __u32 * ed_p;
+ for (i= 0; i < 32; i++) {
+ j = 5;
+ printk (KERN_DEBUG " %s branch int %2d(%2x): ", str, i, i);
+ ed_p = &(ohci->hcca.int_table [i]);
+ while (*ed_p != 0 && j--) {
+ printk ("ed: %4x; ", (((ed_t *) bus_to_virt (*ed_p))->hwINFO));
+ ed_p = &(((ed_t *) bus_to_virt (*ed_p))->hwNextED);
+ }
+ printk ("\n");
}
- remove_wait_queue(&op_wakeup, &wait);
- *rval = state.len;
- return state.status;
}
+
-static void * sohci_request_bulk(struct usb_device *usb_dev, unsigned int pipe, usb_device_irq handler, void *data, int len, void *dev_id)
-{
- struct ohci * ohci = usb_dev->bus->hcpriv;
- struct usb_hcd_ed hcd_ed;
- struct usb_ohci_ed * ed;
-
- usb_pipe_to_hcd_ed(usb_dev, pipe, &hcd_ed);
- hcd_ed.type = BULK;
- ed = usb_ohci_add_ep(usb_dev, &hcd_ed, 0, 1);
-
- OHCI_DEBUG( printk("USB HC BULK_RQ>>>: %x \n", ed->hwINFO);)
-
- ohci_trans_req(ohci, ed, 0, NULL, data, len, (__OHCI_BAG) handler, (__OHCI_BAG) dev_id, (usb_pipeout(pipe))?BULK_OUT:BULK_IN, sohci_ret_handler);
- if (ED_STATE(ed) != ED_OPER) ohci_link_ed(ohci, ed);
+#endif
- return ed;
-}
+/*-------------------------------------------------------------------------*
+ * Interface functions (URB)
+ *-------------------------------------------------------------------------*/
+
+/* return a request to the completion handler */
-static int sohci_terminate_bulk(struct usb_device *usb_dev, void * ed)
+static int sohci_return_urb (urb_t * urb)
{
+ urb_priv_t * urb_priv = urb->hcpriv;
+ urb_t * urbt;
+ unsigned int flags;
+ int i;
- OHCI_DEBUG( printk("USB HC TERM_BULK>>>:%4x\n", (unsigned int) ed);)
-
- ED_setSTATE((struct usb_ohci_ed *)ed, ED_STOP);
-
- usb_ohci_rm_ep(usb_dev, (struct usb_ohci_ed *) ed, NULL, NULL, NULL, 0);
+ /* just to be sure */
+ if (!urb->complete) {
+ urb_rm_priv (urb);
+ usb_dec_dev_use (urb->dev);
+ return -1;
+ }
+
+ if (!urb_priv) return -1; /* urb already unlinked */
+
+#ifdef DEBUG
+ urb_print (urb, "RET", usb_pipeout (urb->pipe));
+#endif
+
+ switch (usb_pipetype (urb->pipe)) {
+ case PIPE_INTERRUPT:
+ urb->complete (urb); /* call complete and requeue URB */
+ urb->actual_length = 0;
+ urb->status = USB_ST_URB_PENDING;
+ if (urb_priv->state != URB_DEL)
+ td_submit_urb (urb);
+ break;
+
+ case PIPE_ISOCHRONOUS:
+ for (urbt = urb->next; urbt && (urbt != urb); urbt = urbt->next);
+ if (urbt) { /* send the reply and requeue URB */
+ urb->complete (urb);
+
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ urb->actual_length = 0;
+ urb->status = USB_ST_URB_PENDING;
+ urb->start_frame = urb_priv->ed->last_iso + 1;
+ if (urb_priv->state != URB_DEL) {
+ for (i = 0; i < urb->number_of_packets; i++) {
+ urb->iso_frame_desc[i].actual_length = 0;
+ urb->iso_frame_desc[i].status = -EXDEV;
+ }
+ td_submit_urb (urb);
+ }
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+
+ } else { /* unlink URB, call complete */
+ urb_rm_priv (urb);
+ usb_dec_dev_use (urb->dev);
+ urb->complete (urb);
+ }
+ break;
+
+ case PIPE_BULK:
+ case PIPE_CONTROL: /* unlink URB, call complete */
+ urb_rm_priv (urb);
+ usb_dec_dev_use (urb->dev);
+ urb->complete (urb);
+ break;
+ }
return 0;
}
-static int sohci_alloc_dev(struct usb_device *usb_dev)
-{
- struct ohci_device *dev;
-
- /* Allocate the OHCI_HCD device private data */
- dev = kmalloc(sizeof(*dev), GFP_KERNEL);
- if (!dev)
- return -1;
-
- /* Initialize "dev" */
- memset(dev, 0, sizeof(*dev));
+/*-------------------------------------------------------------------------*/
- usb_dev->hcpriv = dev;
- dev->usb = usb_dev;
- atomic_set(&dev->refcnt, 1);
+/* get a transfer request */
+
+static int sohci_submit_urb (urb_t * urb)
+{
+ ohci_t * ohci;
+ ed_t * ed;
+ urb_priv_t * urb_priv;
+ unsigned int pipe = urb->pipe;
+ int i, size = 0;
+ unsigned int flags;
+
+ if (!urb->dev || !urb->dev->bus) return -EINVAL;
+
+ if (urb->hcpriv) return -EINVAL; /* urb already in use */
- if (usb_dev->parent)
- dev->ohci = usb_to_ohci(usb_dev->parent)->ohci;
+ usb_inc_dev_use (urb->dev);
+ ohci = (ohci_t *) urb->dev->bus->hcpriv;
+
+#ifdef DEBUG
+ urb_print (urb, "SUB", usb_pipein (pipe));
+#endif
+
+ if (usb_pipedevice (pipe) == ohci->rh.devnum)
+ return rh_submit_urb (urb); /* a request to the virtual root hub */
- return 0;
-}
+ /* every endpoint has a ed, locate and fill it */
+ if (!(ed = ep_add_ed (urb->dev, pipe, urb->interval, 1))) {
+ usb_dec_dev_use (urb->dev);
+ return -ENOMEM;
+ }
-static int sohci_free_dev(struct usb_device *usb_dev)
-{
- int cnt;
- DECLARE_WAITQUEUE(wait, current);
- struct ohci_device *dev = usb_to_ohci(usb_dev);
-
- OHCI_DEBUG(printk("USB HC ***** free %x\n", usb_dev->devnum);)
- wait_ms(10);
- if(usb_dev->devnum >= 0) {
- current->state = TASK_UNINTERRUPTIBLE;
- cnt = usb_ohci_rm_function(usb_dev, sohci_blocking_handler, NULL, &wait);
- if(cnt > 0) {
- schedule();
- remove_wait_queue(&op_wakeup, &wait);
- }
- current->state = TASK_INTERRUPTIBLE;
+ /* for the private part of the URB we need the number of TDs (size) */
+ switch (usb_pipetype (pipe)) {
+ case PIPE_BULK: /* one TD for every 4096 Byte */
+ size = (urb->transfer_buffer_length - 1) / 4096 + 1;
+ break;
+ case PIPE_ISOCHRONOUS: /* number of packets from URB */
+ size = urb->number_of_packets;
+ for (i = 0; i < urb->number_of_packets; i++) {
+ urb->iso_frame_desc[i].actual_length = 0;
+ urb->iso_frame_desc[i].status = -EXDEV;
+ }
+ break;
+ case PIPE_CONTROL: /* 1 TD for setup, 1 for ACK and 1 for every 4096 B */
+ size = (urb->transfer_buffer_length == 0)? 2:
+ (urb->transfer_buffer_length - 1) / 4096 + 3;
+ break;
+ case PIPE_INTERRUPT: /* one TD */
+ size = 1;
+
+ break;
}
-if (atomic_dec_and_test(&dev->refcnt))
- kfree(dev);
+ /* allocate the private part or the URB */
+ urb_priv = kmalloc (sizeof (urb_priv_t) + size * sizeof (td_t *),
+ in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+ if (!urb_priv) {
+ usb_dec_dev_use (urb->dev);
+ return -ENOMEM;
+ }
+ memset (urb_priv, 0, sizeof (urb_priv_t) + size * sizeof (td_t *));
+
+ /* fill the private part of the URB */
+ urb->hcpriv = urb_priv;
+ urb_priv->length = size;
+ urb_priv->td_cnt = 0;
+ urb_priv->state = 0;
+ urb_priv->ed = ed;
+ urb_priv->wait = NULL;
+
+ /* allocate the TDs */
+ for (i = 0; i < size; i++) {
+ OHCI_ALLOC (urb_priv->td[i], sizeof (td_t));
+ if (!urb_priv->td[i]) {
+ usb_dec_dev_use (urb->dev);
+ urb_rm_priv (urb);
+ return -ENOMEM;
+ }
+ }
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ if (ed->state == ED_NEW || (ed->state & ED_DEL)) {
+ urb_rm_priv(urb);
+ usb_dec_dev_use (urb->dev);
+ return -EINVAL;
+ }
+
+ /* for ISOC transfers calculate start frame index */
+ if (urb->transfer_flags & USB_ISO_ASAP) {
+ urb->start_frame = ((ed->state == ED_OPER)? (ed->last_iso + 1):
+ (ohci->hcca.frame_no + 10)) & 0xffff;
+ }
+
+ td_submit_urb (urb); /* fill the TDs and link it to the ed */
+
+ if (ed->state != ED_OPER) /* link the ed into a chain if is not already */
+ ep_link (ohci, ed);
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+
+ urb->status = USB_ST_URB_PENDING;
+ // queue_urb(s, &urb->urb_list);
- return 0;
+ return 0;
}
-
-
-/*
- * ISO Interface designed by Randy Dunlap
- */
-
-static int sohci_get_current_frame_number(struct usb_device *usb_dev) {
+/*-------------------------------------------------------------------------*/
- struct ohci * ohci = usb_dev->bus->hcpriv;
+/* deactivate all TDs and remove the private part of the URB */
+
+static int sohci_unlink_urb (urb_t * urb)
+{
+ unsigned int flags;
+ ohci_t * ohci;
+ DECLARE_WAITQUEUE (wait, current);
- return ohci->hc_area->hcca.frame_no & 0xffff;
+ if (!urb) /* just to be sure */
+ return -EINVAL;
+
+#ifdef DEBUG
+ urb_print (urb, "UNLINK", 1);
+#endif
+
+ ohci = (ohci_t *) urb->dev->bus->hcpriv;
+
+ if (usb_pipedevice (urb->pipe) == ohci->rh.devnum)
+ return rh_unlink_urb (urb); /* a request to the virtual root hub */
+
+ if (urb->hcpriv) {
+ if (urb->status == USB_ST_URB_PENDING) { /* URB active? */
+ urb_priv_t * urb_priv = urb->hcpriv;
+ urb_priv->state = URB_DEL;
+ /* we want to delete the TDs of an URB from an ed
+ * request the deletion, it will be handled at the next USB-frame */
+ urb_priv->wait = &wait;
+
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ ep_rm_ed (urb->dev, urb_priv->ed);
+ urb_priv->ed->state |= ED_URB_DEL;
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+
+ current->state = TASK_UNINTERRUPTIBLE;
+ schedule_timeout (HZ / 10); /* wait until all TDs are deleted */
+ remove_wait_queue (&op_wakeup, &wait);
+ } else
+ urb_rm_priv (urb);
+ usb_dec_dev_use (urb->dev);
+ }
+ return 0;
}
+/*-------------------------------------------------------------------------*/
-static int sohci_init_isoc(struct usb_device *usb_dev, unsigned int pipe, int frame_count, void *context, struct usb_isoc_desc **idp) {
+/* allocate private data space for a usb device */
- struct usb_isoc_desc *id;
-
- *idp = NULL;
+static int sohci_alloc_dev (struct usb_device *usb_dev)
+{
+ struct ohci_device * dev;
- id = kmalloc (sizeof (struct usb_isoc_desc) + (sizeof (struct isoc_frame_desc) * frame_count), GFP_KERNEL);
- if(!id) return -ENOMEM;
- memset (id, 0, sizeof (struct usb_isoc_desc) + (sizeof (struct isoc_frame_desc) * frame_count));
-OHCI_DEBUG(printk("ISO alloc id: %p, size: %d\n", id, sizeof (struct usb_isoc_desc) + (sizeof (struct isoc_frame_desc) * frame_count));)
- id->td = kmalloc (sizeof (void *) * frame_count, GFP_KERNEL);
- if(!id->td) {
- kfree (id);
+ dev = kmalloc (sizeof (*dev), GFP_KERNEL);
+ if (!dev)
return -ENOMEM;
- }
- memset (id->td, 0, sizeof (void *) * frame_count);
-OHCI_DEBUG(printk("ISO alloc id->td: %p, size: %d\n", id->td, sizeof (void *) * frame_count);)
-
- id->frame_count = frame_count;
- id->frame_size = usb_maxpacket (usb_dev, pipe, usb_pipeout(pipe));
- id->start_frame = -1;
- id->end_frame = -1;
- id->usb_dev = usb_dev;
- id->pipe = pipe;
- id->context = context;
-
- *idp = id;
- return 0;
-}
-
-void print_int_eds(struct ohci * ohci);
-
-static int sohci_run_isoc(struct usb_isoc_desc *id, struct usb_isoc_desc *pr_id) {
-
- struct ohci * ohci = id->usb_dev->bus->hcpriv;
- struct usb_ohci_td ** tdp = (struct usb_ohci_td **) id->td;
- struct usb_hcd_ed hcd_ed;
- struct usb_ohci_ed * ed;
- int ix, frlen;
- unsigned char *bufptr;
-
- if(pr_id)
- id->start_frame = pr_id->end_frame + 1;
- else {
- switch(id->start_type) {
- case START_ABSOLUTE:
- break;
-
- case START_RELATIVE:
- if(id->start_frame < START_FRAME_FUDGE) id->start_frame = START_FRAME_FUDGE;
- id->start_frame += sohci_get_current_frame_number(id->usb_dev);
- break;
-
- case START_ASAP:
- id->start_frame = START_FRAME_FUDGE + sohci_get_current_frame_number(id->usb_dev);
- break;
- }
- }
+
+ memset (dev, 0, sizeof (*dev));
- id->start_frame &= 0xffff;
- id->end_frame = (id->start_frame + id->frame_count - 1) & 0xffff;
+ usb_dev->hcpriv = dev;
- id->prev_completed_frame = 0;
- id->cur_completed_frame = 0;
- if (id->frame_spacing <= 0) id->frame_spacing = 1;
-
- bufptr = id->data;
-
- usb_pipe_to_hcd_ed(id->usb_dev, id->pipe, &hcd_ed);
- hcd_ed.type = ISO;
- ed = usb_ohci_add_ep(id->usb_dev, &hcd_ed, 1, 1);
- OHCI_DEBUG( printk("USB HC ISO>>>: ed: %x-%x: (%d tds)\n", (unsigned int) ed, ed->hwINFO, id->frame_count);)
-
- for (ix = 0; ix < id->frame_count; ix++) {
- frlen = (id->frames[ix].frame_length > id->frame_size)? id->frame_size : id->frames[ix].frame_length;
- printk("ISO run id->td: %p \n", &tdp[ix]);
- tdp[ix] = ohci_trans_req(ohci, ed, id->start_frame + ix , NULL, bufptr, frlen, (__OHCI_BAG) ix, (__OHCI_BAG) id,
- (usb_pipeout(id->pipe))?ISO_OUT:ISO_IN,
- sohci_iso_handler);
- bufptr += frlen;
- }
-
- if (ED_STATE(ed) != ED_OPER) ohci_link_ed(ohci, ed);
- print_int_eds(ohci);
return 0;
}
-static int sohci_kill_isoc(struct usb_isoc_desc *id) {
+/*-------------------------------------------------------------------------*/
- struct usb_ohci_ed *ed = NULL;
- struct usb_ohci_td **td = id->td;
- int i;
-
- for (i = 0; i < id->frame_count; i++) {
- if(td[i]) {
- td[i]->type |= DEL;
- ed = td[i]->ed;
- OHCI_DEBUG(printk(" %d", i);)
- td[i] = NULL;
+/* free private data space of usb device */
+
+static int sohci_free_dev (struct usb_device * usb_dev)
+{
+ unsigned int flags;
+ int i, cnt = 0;
+ ed_t * ed;
+ DECLARE_WAITQUEUE (wait, current);
+ struct ohci_device * dev = usb_to_ohci (usb_dev);
+ ohci_t * ohci = usb_dev->bus->hcpriv;
+
+ if (!dev) return 0;
+
+ if (usb_dev->devnum >= 0) {
+
+ /* delete all TDs of all EDs */
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ for(i = 0; i < NUM_EDS; i++) {
+ ed = &(dev->ed[i]);
+ if (ed->state != ED_NEW) {
+ if (ed->state == ED_OPER) ep_unlink (ohci, ed);
+ ep_rm_ed (usb_dev, ed);
+ ed->state = ED_DEL;
+ cnt++;
+ }
+ }
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+
+ if (cnt > 0) {
+ dev->wait = &wait;
+ current->state = TASK_UNINTERRUPTIBLE;
+ schedule_timeout (HZ / 10);
+ remove_wait_queue (&op_wakeup, &wait);
}
- }
- if(ed) usb_ohci_rm_ep(id->usb_dev, ed, NULL, NULL, NULL, TD_RM);
-
- id->start_frame = -1;
+ }
+ kfree (dev);
+
return 0;
}
+/*-------------------------------------------------------------------------*/
-static void sohci_free_isoc(struct usb_isoc_desc *id) {
+/* tell us the current USB frame number */
- if(id->start_frame >= 0) sohci_kill_isoc(id);
- kfree(id->td);
- kfree(id);
+static int sohci_get_current_frame_number (struct usb_device *usb_dev)
+{
+ ohci_t * ohci = usb_dev->bus->hcpriv;
+
+ return ohci->hcca.frame_no;
}
+/*-------------------------------------------------------------------------*/
+
struct usb_operations sohci_device_operations = {
sohci_alloc_dev,
sohci_free_dev,
- sohci_control_msg,
- sohci_bulk_msg,
- sohci_request_irq,
- sohci_release_irq,
- sohci_request_bulk,
- sohci_terminate_bulk,
sohci_get_current_frame_number,
- sohci_init_isoc,
- sohci_free_isoc,
- sohci_run_isoc,
- sohci_kill_isoc
+ sohci_submit_urb,
+ sohci_unlink_urb
};
-
-/******
- *** ED handling functions
- ************************************/
-
-/* just for debugging; prints all 32 branches of the int ed tree inclusive iso eds*/
-void print_int_eds(struct ohci * ohci) {int i; __u32 * ed_p;
- for(i= 0; i < 32; i++) {
- OHCI_DEBUG(printk("branch int %2d(%2x): ", i,i); )
- ed_p = &(ohci->hc_area->hcca.int_table[i]);
- while (*ed_p != 0) {
- OHCI_DEBUG(printk("ed: %4x; ", (((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwINFO));)
- ed_p = &(((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwNextED);
- }
- OHCI_DEBUG(printk("\n");)
- }
-}
+/*-------------------------------------------------------------------------*
+ * ED handling functions
+ *-------------------------------------------------------------------------*/
-/*
- * search for the right branch to insert an interrupt ed into the int tree
- * do some load ballancing
+/* search for the right branch to insert an interrupt ed into the int tree
+ * do some load ballancing;
* returns the branch and
- * sets the interval to interval = 2^integer(ld(interval))
- * */
-
-static int usb_ohci_int_ballance(struct ohci * ohci, int * interval, int load) {
+ * sets the interval to interval = 2^integer (ld (interval)) */
- int i,j;
-
- j = 0; /* search for the least loaded interrupt endpoint branch of all 32 branches */
- for(i=0; i< 32; i++) if(ohci->ohci_int_load[j] > ohci->ohci_int_load[i]) j=i;
-
- for(i= 0; ((*interval >> i) > 1 ) && (i < 5); i++ ); /* interval = 2^int(ld(interval)) */
- *interval = 1 << i;
-
- j = j % (*interval);
- for(i=j; i< 32; i+=(*interval)) ohci->ohci_int_load[i] += load;
+static int ep_int_ballance (ohci_t * ohci, int interval, int load)
+{
+ int i, branch = 0;
+ /* search for the least loaded interrupt endpoint branch of all 32 branches */
+ for (i = 0; i < 32; i++)
+ if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i]) branch = i;
- OHCI_DEBUG(printk("USB HC new int ed on pos %d of interval %d \n",j, *interval);)
-
- return j;
+ branch = branch % interval;
+ for (i = branch; i < 32; i += interval) ohci->ohci_int_load [i] += load;
+
+ return branch;
+}
+
+/*-------------------------------------------------------------------------*/
+
+/* 2^int( ld (inter)) */
+
+static int ep_2_n_interval (int inter)
+{
+ int i;
+ for (i = 0; ((inter >> i) > 1 ) && (i < 5); i++);
+ return 1 << i;
}
+/*-------------------------------------------------------------------------*/
+
/* the int tree is a binary tree
* in order to process it sequentially the indexes of the branches have to be mapped
- * the mapping reverses the bits of a word of num_bits length
- * */
-static int rev(int num_bits, int word) {
- int i;
- int wout = 0;
+ * the mapping reverses the bits of a word of num_bits length */
+
+static int ep_rev (int num_bits, int word)
+{
+ int i, wout = 0;
- for(i = 0; i < num_bits; i++) wout |= (((word >> i) & 1) << (num_bits - i - 1));
+ for (i = 0; i < num_bits; i++) wout |= (((word >> i) & 1) << (num_bits - i - 1));
return wout;
}
-/* get the ed from the endpoint / usb_device address */
-
-struct usb_ohci_ed * ohci_find_ep(struct usb_device *usb_dev, struct usb_hcd_ed *hcd_ed) {
- return &(usb_to_ohci(usb_dev)->ed[(hcd_ed->endpoint << 1) | ((hcd_ed->type == CTRL)? 0:hcd_ed->out)]);
-}
+/*-------------------------------------------------------------------------*/
/* link an ed into one of the HC chains */
-static int ohci_link_ed(struct ohci * ohci, struct usb_ohci_ed *ed) {
+static int ep_link (ohci_t * ohci, ed_t * edi)
+{
int int_branch;
int i;
int inter;
int interval;
int load;
__u32 * ed_p;
+ volatile ed_t * ed = edi;
- ED_setSTATE(ed, ED_OPER);
+ ed->state = ED_OPER;
- switch(ED_TYPE(ed)) {
+ switch (ed->type) {
case CTRL:
ed->hwNextED = 0;
- if(ohci->ed_controltail == NULL) {
- writel(virt_to_bus(ed), &ohci->regs->ed_controlhead);
- }
- else {
- ohci->ed_controltail->hwNextED = virt_to_bus(ed);
+ if (ohci->ed_controltail == NULL) {
+ writel (virt_to_bus (ed), &ohci->regs->ed_controlhead);
+ } else {
+ ohci->ed_controltail->hwNextED = cpu_to_le32 (virt_to_bus (ed));
}
ed->ed_prev = ohci->ed_controltail;
ohci->ed_controltail = ed;
@@ -631,67 +554,71 @@
case BULK:
ed->hwNextED = 0;
- if(ohci->ed_bulktail == NULL) {
- writel(virt_to_bus(ed), &ohci->regs->ed_bulkhead);
- }
- else {
- ohci->ed_bulktail->hwNextED = virt_to_bus(ed);
+ if (ohci->ed_bulktail == NULL) {
+ writel (virt_to_bus (ed), &ohci->regs->ed_bulkhead);
+ } else {
+ ohci->ed_bulktail->hwNextED = cpu_to_le32 (virt_to_bus (ed));
}
ed->ed_prev = ohci->ed_bulktail;
ohci->ed_bulktail = ed;
break;
case INT:
- interval = ed->int_period;
load = ed->int_load;
- int_branch = usb_ohci_int_ballance(ohci, &interval, load);
+ interval = ep_2_n_interval (ed->int_period);
ed->int_interval = interval;
+ int_branch = ep_int_ballance (ohci, interval, load);
ed->int_branch = int_branch;
- for( i= 0; i < rev(6, interval); i += inter) {
+ for (i = 0; i < ep_rev (6, interval); i += inter) {
inter = 1;
- for(ed_p = &(ohci->hc_area->hcca.int_table[rev(5,i)+int_branch]);
- (*ed_p != 0) && (((struct usb_ohci_ed *)bus_to_virt(*ed_p))->int_interval >= interval);
- ed_p = &(((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwNextED))
- inter = rev(6,((struct usb_ohci_ed *)bus_to_virt(*ed_p))->int_interval);
+ for (ed_p = &(ohci->hcca.int_table[ep_rev (5, i) + int_branch]);
+ (*ed_p != 0) && (((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->int_interval >= interval);
+ ed_p = &(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->hwNextED))
+ inter = ep_rev (6, ((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->int_interval);
ed->hwNextED = *ed_p;
- *ed_p = virt_to_bus(ed);
- OHCI_DEBUG(printk("int_link i: %2x, inter: %2x, ed: %4x\n", i, inter, ed->hwINFO);)
+ *ed_p = cpu_to_le32 (virt_to_bus (ed));
}
+#ifdef DEBUG
+ ep_print_int_eds (ohci, "LINK_INT");
+#endif
break;
case ISO:
- if(ohci->ed_isotail != NULL) {
- ohci->ed_isotail->hwNextED = virt_to_bus(ed);
+ ed->hwNextED = 0;
+ ed->int_interval = 1;
+ if (ohci->ed_isotail != NULL) {
+ ohci->ed_isotail->hwNextED = cpu_to_le32 (virt_to_bus (ed));
ed->ed_prev = ohci->ed_isotail;
- }
- else {
- for( i= 0; i < 32; i += inter) {
+ } else {
+ for ( i = 0; i < 32; i += inter) {
inter = 1;
- for(ed_p = &(ohci->hc_area->hcca.int_table[rev(5,i)]);
+ for (ed_p = &(ohci->hcca.int_table[ep_rev (5, i)]);
*ed_p != 0;
- ed_p = &(((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwNextED))
- inter = rev(6,((struct usb_ohci_ed *)bus_to_virt(*ed_p))->int_interval);
- *ed_p = virt_to_bus(ed);
+ ed_p = &(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->hwNextED))
+ inter = ep_rev (6, ((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->int_interval);
+ *ed_p = cpu_to_le32 (virt_to_bus (ed));
}
ed->ed_prev = NULL;
}
- ed->hwNextED = 0;
ohci->ed_isotail = ed;
+#ifdef DEBUG
+ ep_print_int_eds (ohci, "LINK_ISO");
+#endif
break;
- }
-
-
- return 1;
+ }
+ return 0;
}
+/*-------------------------------------------------------------------------*/
+
/* unlink an ed from one of the HC chains.
* just the link to the ed is unlinked.
* the link from the ed still points to another operational ed or 0
- * so the HC can eventually finish the processing of the unlinked ed
- * */
-static int ohci_unlink_ed(struct ohci * ohci, struct usb_ohci_ed *ed) {
+ * so the HC can eventually finish the processing of the unlinked ed */
+static int ep_unlink (ohci_t * ohci, ed_t * ed)
+{
int int_branch;
int i;
int inter;
@@ -699,125 +626,129 @@
__u32 * ed_p;
- switch(ED_TYPE(ed)) {
- case CTRL:
- if(ed->ed_prev == NULL) {
- writel(ed->hwNextED, &ohci->regs->ed_controlhead);
- }
- else {
- ed->ed_prev->hwNextED = ed->hwNextED;
- }
- if(ohci->ed_controltail == ed) {
- ohci->ed_controltail = ed->ed_prev;
- }
- else {
- ((struct usb_ohci_ed *)bus_to_virt(ed->hwNextED))->ed_prev = ed->ed_prev;
- }
- break;
+ switch (ed->type) {
+ case CTRL:
+ if (ed->ed_prev == NULL) {
+ writel (le32_to_cpu (ed->hwNextED), &ohci->regs->ed_controlhead);
+ } else {
+ ed->ed_prev->hwNextED = ed->hwNextED;
+ }
+ if(ohci->ed_controltail == ed) {
+ ohci->ed_controltail = ed->ed_prev;
+ } else {
+ ((ed_t *) bus_to_virt (le32_to_cpu (ed->hwNextED)))->ed_prev = ed->ed_prev;
+ }
+ break;
- case BULK:
- if(ed->ed_prev == NULL) {
- writel(ed->hwNextED, &ohci->regs->ed_bulkhead);
- }
- else {
- ed->ed_prev->hwNextED = ed->hwNextED;
- }
- if(ohci->ed_bulktail == ed) {
- ohci->ed_bulktail = ed->ed_prev;
- }
- else {
- ((struct usb_ohci_ed *)bus_to_virt(ed->hwNextED))->ed_prev = ed->ed_prev;
- }
- break;
+ case BULK:
+ if (ed->ed_prev == NULL) {
+ writel (le32_to_cpu (ed->hwNextED), &ohci->regs->ed_bulkhead);
+ } else {
+ ed->ed_prev->hwNextED = ed->hwNextED;
+ }
+ if (ohci->ed_bulktail == ed) {
+ ohci->ed_bulktail = ed->ed_prev;
+ } else {
+ ((ed_t *) bus_to_virt (le32_to_cpu (ed->hwNextED)))->ed_prev = ed->ed_prev;
+ }
+ break;
case INT:
int_branch = ed->int_branch;
interval = ed->int_interval;
- for( i= 0; i < rev(6,interval); i += inter) {
- for(ed_p = &(ohci->hc_area->hcca.int_table[rev(5,i)+int_branch]), inter = 1;
+ for (i = 0; i < ep_rev (6, interval); i += inter) {
+ for (ed_p = &(ohci->hcca.int_table[ep_rev (5, i) + int_branch]), inter = 1;
(*ed_p != 0) && (*ed_p != ed->hwNextED);
- ed_p = &(((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwNextED),
- inter = rev(6, ((struct usb_ohci_ed *)bus_to_virt(*ed_p))->int_interval)) {
- if(((struct usb_ohci_ed *)bus_to_virt(*ed_p)) == ed) {
+ ed_p = &(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->hwNextED),
+ inter = ep_rev (6, ((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->int_interval)) {
+ if(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p))) == ed) {
*ed_p = ed->hwNextED;
break;
}
}
- OHCI_DEBUG(printk("int_link i: %2x, inter: %2x, ed: %4x\n", i, inter, ed->hwINFO);)
}
- for(i=int_branch; i< 32; i+=interval) ohci->ohci_int_load[i] -= ed->int_load;
- break;
+ for (i = int_branch; i < 32; i += interval) ohci->ohci_int_load[i] -= ed->int_load;
+#ifdef DEBUG
+ ep_print_int_eds (ohci, "UNLINK_INT");
+#endif break;
case ISO:
- if(ohci->ed_isotail == ed)
+ if (ohci->ed_isotail == ed)
ohci->ed_isotail = ed->ed_prev;
- if(ed->hwNextED != 0)
- ((struct usb_ohci_ed *)bus_to_virt(ed->hwNextED))->ed_prev = ed->ed_prev;
+ if (ed->hwNextED != 0)
+ ((ed_t *) bus_to_virt (le32_to_cpu (ed->hwNextED)))->ed_prev = ed->ed_prev;
- if(ed->ed_prev != NULL) {
+ if (ed->ed_prev != NULL) {
ed->ed_prev->hwNextED = ed->hwNextED;
- }
- else {
- for( i= 0; i < 32; i += inter) {
+ } else {
+ for (i = 0; i < 32; i += inter) {
inter = 1;
- for(ed_p = &(ohci->hc_area->hcca.int_table[rev(5,i)]);
+ for (ed_p = &(ohci->hcca.int_table[ep_rev (5, i)]);
*ed_p != 0;
- ed_p = &(((struct usb_ohci_ed *)bus_to_virt(*ed_p))->hwNextED)) {
- inter = rev(6,((struct usb_ohci_ed *)bus_to_virt(*ed_p))->int_interval);
- if(((struct usb_ohci_ed *)bus_to_virt(*ed_p)) == ed) {
+ ed_p = &(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->hwNextED)) {
+ inter = ep_rev (6, ((ed_t *) bus_to_virt (le32_to_cpu (*ed_p)))->int_interval);
+ if(((ed_t *) bus_to_virt (le32_to_cpu (*ed_p))) == ed) {
*ed_p = ed->hwNextED;
break;
}
}
}
}
+#ifdef DEBUG
+ ep_print_int_eds (ohci, "UNLINK_ISO");
+#endif
break;
}
- ED_setSTATE(ed, ED_UNLINK);
- return 1;
+ ed->state = ED_UNLINK;
+ return 0;
}
-spinlock_t usb_ed_lock = SPIN_LOCK_UNLOCKED;
+
+/*-------------------------------------------------------------------------*/
/* add/reinit an endpoint; this should be done once at the usb_set_configuration command,
* but the USB stack is a little bit stateless so we do it at every transaction
* if the state of the ed is ED_NEW then a dummy td is added and the state is changed to ED_UNLINK
* in all other cases the state is left unchanged
- * the ed info fields are setted anyway even though they should not change
- * */
-struct usb_ohci_ed *usb_ohci_add_ep(struct usb_device * usb_dev, struct usb_hcd_ed * hcd_ed, int interval, int load) {
-
- // struct ohci * ohci = usb_dev->bus->hcpriv;
- struct usb_ohci_td * td;
- struct usb_ohci_ed * ed;
-
- int ed_state;
+ * the ed info fields are setted anyway even though most of them should not change */
- spin_lock(&usb_ed_lock);
+static ed_t * ep_add_ed (struct usb_device * usb_dev, unsigned int pipe, int interval, int load)
+{
+ ohci_t * ohci = usb_dev->bus->hcpriv;
+ td_t * td;
+ volatile ed_t * ed;
+
+
+ spin_lock (&usb_ed_lock);
- ed = ohci_find_ep(usb_dev, hcd_ed);
+ ed = &(usb_to_ohci (usb_dev)->ed[(usb_pipeendpoint (pipe) << 1) |
+ (usb_pipecontrol (pipe)? 0: usb_pipeout (pipe))]);
- ed_state = ED_STATE(ed); /* store state of ed */
- OHCI_DEBUG(printk("USB HC add ed %x: %x :state: %x\n", ed->hwINFO, (unsigned int ) ed, ed_state); )
- if (ed_state == ED_NEW) {
- OHCI_ALLOC(td, sizeof(*td)); /* dummy td; end of td list for ed */
- ed->hwTailP = virt_to_bus(td);
+ if((ed->state & ED_DEL) || (ed->state & ED_URB_DEL))
+ return NULL; /* pending delete request */
+
+ if (ed->state == ED_NEW) {
+ ed->hwINFO = cpu_to_le32 (OHCI_ED_SKIP); /* skip ed */
+ OHCI_ALLOC (td, sizeof (*td)); /* dummy td; end of td list for ed */
+ if(!td) return NULL; /* out of memory */
+ ed->hwTailP = cpu_to_le32 (virt_to_bus (td));
ed->hwHeadP = ed->hwTailP;
- ed_state = ED_UNLINK;
+ ed->state = ED_UNLINK;
+ ed->type = usb_pipetype (pipe);
+ usb_to_ohci (usb_dev)->ed_cnt++;
}
-
- ed->hwINFO = hcd_ed->function
- | hcd_ed->endpoint << 7
- | (hcd_ed->type == ISO? 0x8000 : 0)
- | (hcd_ed->type == CTRL? 0:(hcd_ed->out == 1? 0x800 : 0x1000 ))
- | hcd_ed->slow << 13
- | hcd_ed->maxpack << 16
- | hcd_ed->type << 27
- // | 1 << 14
- | ed_state << 29 ;
-
- if (ED_TYPE(ed) == INT && ed_state == ED_UNLINK) {
+
+ ohci->dev[usb_pipedevice (pipe)] = usb_dev;
+
+ ed->hwINFO = cpu_to_le32 (usb_pipedevice (pipe)
+ | usb_pipeendpoint (pipe) << 7
+ | (usb_pipeisoc (pipe)? 0x8000: 0)
+ | (usb_pipecontrol (pipe)? 0: (usb_pipeout (pipe)? 0x800: 0x1000))
+ | usb_pipeslow (pipe) << 13
+ | usb_maxpacket (usb_dev, pipe, usb_pipeout (pipe)) << 16);
+
+ if (ed->type == INT && ed->state == ED_UNLINK) {
ed->int_period = interval;
ed->int_load = load;
}
@@ -826,569 +757,839 @@
return ed;
}
-
+/*-------------------------------------------------------------------------*/
-/*****
- * Request the removal of an endpoint
- *
+/* request the removal of an endpoint
* put the ep on the rm_list and request a stop of the bulk or ctrl list
- * real removal is done at the next start of frame (SOF) hardware interrupt
- * the dummy td carries the essential information (handler, proc queue, ...)
- * if(send & TD_RM) then just the TD witch have (TD->type & DEL) set will be removed
- * otherwise all TDs including the dummy TD of the ED will be removed
- */
-int usb_ohci_rm_ep(struct usb_device * usb_dev, struct usb_ohci_ed *ed, f_handler handler, __OHCI_BAG lw0, __OHCI_BAG lw1, int send)
+ * real removal is done at the next start of frame (SOF) hardware interrupt */
+
+static void ep_rm_ed (struct usb_device * usb_dev, ed_t * ed)
{
- unsigned int flags;
-
- struct ohci * ohci = usb_dev->bus->hcpriv;
- struct usb_ohci_td *td;
-
- OHCI_DEBUG(printk("USB HC remove ed %x: %x :\n", ed->hwINFO, (unsigned int ) ed); )
+ unsigned int frame;
+ ohci_t * ohci = usb_dev->bus->hcpriv;
- spin_lock_irqsave(&usb_ed_lock, flags);
- ed->hwINFO |= OHCI_ED_SKIP;
- writel( OHCI_INTR_SF, &ohci->regs->intrenable); /* enable sof interrupt */
-
-
- if(send & TD_RM) { /* delete selected TDs */
- ED_setSTATE(ed, ED_TD_DEL);
- }
- else { /* delete all TDS */
- if(ED_STATE(ed) == ED_OPER) ohci_unlink_ed(ohci, ed);
- td = (struct usb_ohci_td *) bus_to_virt(ed->hwTailP);
- td->lw0 = lw0;
- td->lw1 = lw1;
- td->ed = ed;
- td->hwINFO = TD_CC;
- td->handler = handler;
- td->type = send;
- ED_setSTATE(ed, ED_DEL);
- }
- ed->ed_prev = ohci->ed_rm_list;
- ohci->ed_rm_list = ed;
-
- switch(ED_TYPE(ed)) {
- case CTRL:
- writel_mask(~(0x01<<4), &ohci->regs->control); /* stop CTRL list */
+ if ((ed->state & ED_DEL) || (ed->state & ED_URB_DEL)) return;
+
+ ed->hwINFO |= cpu_to_le32 (OHCI_ED_SKIP);
+
+ writel (OHCI_INTR_SF, &ohci->regs->intrstatus);
+ writel (OHCI_INTR_SF, &ohci->regs->intrenable); /* enable sof interrupt */
+
+ frame = ohci->hcca.frame_no & 0x1;
+ ed->ed_rm_list = ohci->ed_rm_list[frame];
+ ohci->ed_rm_list[frame] = ed;
+
+ switch (ed->type) {
+ case CTRL: /* stop CTRL list */
+ writel (ohci->hc_control &= ~(0x01 << 4), &ohci->regs->control);
break;
- case BULK:
- writel_mask(~(0x01<<5), &ohci->regs->control); /* stop BULK list */
+ case BULK: /* stop BULK list */
+ writel (ohci->hc_control &= ~(0x01 << 5), &ohci->regs->control);
break;
}
-
- spin_unlock_irqrestore(&usb_ed_lock, flags);
-
- return 1;
}
-
-/* remove all endpoints of a function (device)
- * just the last ed sends a reply
- * the last ed is ed0 as there always should be an ep0
- * */
-int usb_ohci_rm_function(struct usb_device * usb_dev, f_handler handler,__OHCI_BAG tw0, __OHCI_BAG tw1)
-{
- struct usb_ohci_ed *ed;
- int i;
- int cnt = 0;
-
-
- for(i = NUM_EDS - 1 ; i >= 0; i--) {
- ed = &(usb_to_ohci(usb_dev)->ed[i]);
- if(ED_STATE(ed) != ED_NEW) {
- OHCI_DEBUG(printk("USB RM FUNCTION ed: %4x;\n", ed->hwINFO);)
- usb_ohci_rm_ep(usb_dev, ed, handler, tw0, tw1, i==0?SEND:0);
- cnt++;
- }
- }
- OHCI_DEBUG(printk("USB RM FUNCTION %d eds removed;\n", cnt);)
- return cnt;
-}
+/*-------------------------------------------------------------------------*
+ * TD handling functions
+ *-------------------------------------------------------------------------*/
+/* prepare a TD */
+static void td_fill (unsigned int info, void * data, int len, urb_t * urb, int type, int index)
+{
+ volatile td_t * td, * td_pt;
+ urb_priv_t * urb_priv = urb->hcpriv;
-/******
- *** TD handling functions
- ************************************/
-
-
-#define FILL_TD(INFO, DATA, LEN, LW0, LW1, TYPE, HANDLER) \
- OHCI_ALLOC(td_pt, sizeof(*td_pt)); \
- td_ret = (struct usb_ohci_td *) bus_to_virt(usb_ed->hwTailP & 0xfffffff0); \
- td_pt1 = td_ret; \
- td_pt1->ed = ed; \
- td_pt1->buffer_start = (DATA); \
- td_pt1->type = (TYPE); \
- td_pt1->handler = (HANDLER); \
- td_pt1->lw0 = (LW0); \
- td_pt1->lw1 = (LW1); \
- td_pt1->hwINFO = (INFO); \
- td_pt1->hwCBP = (((DATA)==NULL)||((LEN)==0))?0:virt_to_bus(DATA); \
- td_pt1->hwBE = (((DATA)==NULL)||((LEN)==0))?0:virt_to_bus((DATA) + (LEN) - 1); \
- td_pt1->hwNextTD = virt_to_bus(td_pt); \
- td_pt->hwNextTD = 0; \
- usb_ed->hwTailP = td_pt1->hwNextTD
-
-#define FILL_ISO_TD(INFO, DATA, LEN, LW0, LW1, TYPE, HANDLER) \
- OHCI_ALLOC(td_pt, sizeof(*td_pt)); \
- td_ret = (struct usb_ohci_td *) bus_to_virt(usb_ed->hwTailP & 0xfffffff0); \
- td_pt1 = td_ret; \
- td_pt1->ed = ed; \
- td_pt1->buffer_start = (DATA); \
- td_pt1->type = (TYPE); \
- td_pt1->handler = (HANDLER); \
- td_pt1->lw0 = (LW0); \
- td_pt1->lw1 = (LW1); \
- td_pt1->hwINFO = (INFO); \
- td_pt1->hwCBP = (((DATA)==NULL)||((LEN)==0))?0:(virt_to_bus(DATA) & 0xfffff000); \
- td_pt1->hwBE = (((DATA)==NULL)||((LEN)==0))?0:virt_to_bus((DATA) + (LEN) - 1); \
- td_pt1->hwNextTD = virt_to_bus(td_pt); \
- td_pt1->hwPSW[0] = (virt_to_bus(DATA) & 0xfff) | 0xe000; \
- td_pt->hwNextTD = 0; \
- usb_ed->hwTailP = td_pt1->hwNextTD
-
-
-spinlock_t usb_req_lock = SPIN_LOCK_UNLOCKED;
-
-struct usb_ohci_td * ohci_trans_req(struct ohci * ohci, struct usb_ohci_ed * ed, int ctrl_len,
- void *ctrl, void * data, int data_len, __OHCI_BAG lw0, __OHCI_BAG lw1, unsigned int ed_type, f_handler handler) {
-
+ if (index >= urb_priv->length) {
+ printk (KERN_ERR MODSTR "internal OHCI error: TD index > length\n");
+ return;
+ }
+
+ td_pt = urb_priv->td [index];
+ /* fill the old dummy TD */
+ td = (td_t *) bus_to_virt (le32_to_cpu (urb_priv->ed->hwTailP) & 0xfffffff0);
+ td->ed = urb_priv->ed;
+ td->index = index;
+ td->urb = urb;
+ td->hwINFO = cpu_to_le32 (info);
+ td->type = type;
+ if ((td->ed->type & 3) == PIPE_ISOCHRONOUS) {
+ td->hwCBP = cpu_to_le32 (((!data || !len)?
+ 0 : virt_to_bus (data)) & 0xFFFFF000);
+ td->ed->last_iso = info & 0xffff;
+ } else {
+ td->hwCBP = cpu_to_le32 (((!data || !len)? 0 : virt_to_bus (data)));
+ }
+ td->hwBE = cpu_to_le32 ((!data || !len )? 0: virt_to_bus (data + len - 1));
+ td->hwNextTD = cpu_to_le32 (virt_to_bus (td_pt));
+ td->hwPSW [0] = cpu_to_le16 ((virt_to_bus (data) & 0x0FFF) | 0xE000);
+ td_pt->hwNextTD = 0;
+ td->ed->hwTailP = td->hwNextTD;
+ urb_priv->td [index] = td;
- unsigned int flags;
- volatile struct usb_ohci_ed *usb_ed = ed;
- volatile struct usb_ohci_td *td_pt;
- volatile struct usb_ohci_td *td_pt1 = NULL;
+ td->next_dl_td = NULL; //td_pt;
+}
- struct usb_ohci_td *td_ret = NULL;
-
- int cnt = 0;
+/*-------------------------------------------------------------------------*/
-
- if(usb_ed == NULL ) return NULL; /* not known ep */
-
-
- spin_lock_irqsave(&usb_req_lock, flags);
-
- switch(ed_type) {
- case BULK_IN:
- while(data_len > 4096)
- {
- FILL_TD( TD_CC | TD_DP_IN | TD_T_TOGGLE, data, 4096, NULL, NULL, BULK_IN | ADD_LEN|(cnt++?0:ST_ADDR), NULL);
- data += 4096; data_len -= 4096;
- }
- FILL_TD( TD_CC | TD_R | TD_DP_IN | TD_T_TOGGLE, data, data_len, lw0, lw1, BULK_IN |ADD_LEN|SEND|(cnt++?0:ST_ADDR), handler);
- writel( OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
- break;
-
- case BULK_OUT:
- while(data_len > 4096)
- {
- FILL_TD( TD_CC | TD_DP_OUT | TD_T_TOGGLE, data, 4096, NULL, NULL, BULK_OUT | ADD_LEN|(cnt++?0:ST_ADDR), NULL);
- data += 4096; data_len -= 4096;
- }
- FILL_TD( TD_CC | TD_DP_OUT | TD_T_TOGGLE, data, data_len, lw0, lw1, BULK_OUT |ADD_LEN|SEND|(cnt++?0:ST_ADDR), handler);
- writel( OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
- break;
-
- case INT_IN:
- FILL_TD( TD_CC | TD_R | TD_DP_IN | TD_T_TOGGLE, data, data_len, lw0, lw1, INT_IN | ST_ADDR|ADD_LEN|SEND, handler);
- break;
-
- case INT_OUT:
- FILL_TD( TD_CC | TD_DP_OUT | TD_T_TOGGLE, data, data_len, lw0, lw1, INT_OUT | ST_ADDR|ADD_LEN|SEND, handler);
- break;
-
- case CTRL_IN:
- FILL_TD( TD_CC | TD_DP_SETUP | TD_T_DATA0, ctrl, ctrl_len, 0, 0, CTRL_SETUP |ST_ADDR, NULL);
- if(data_len > 0) {
- FILL_TD( TD_CC | TD_R | TD_DP_IN | TD_T_DATA1, data, data_len, 0, 0, CTRL_DATA_IN | ST_ADDR|ADD_LEN, NULL);
- }
- FILL_TD( TD_CC | TD_DP_OUT | TD_T_DATA1, NULL, 0, lw0, lw1, CTRL_STATUS_OUT |SEND, handler);
- writel( OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
- break;
-
- case CTRL_OUT:
- FILL_TD( TD_CC | TD_DP_SETUP | TD_T_DATA0, ctrl, ctrl_len, 0, 0, CTRL_SETUP |ST_ADDR, NULL);
- if(data_len > 0) {
- FILL_TD( TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1, data, data_len, 0, 0, CTRL_DATA_OUT | ST_ADDR|ADD_LEN, NULL);
- }
- FILL_TD( TD_CC | TD_DP_IN | TD_T_DATA1, NULL, 0, lw0, lw1, CTRL_STATUS_IN |SEND, handler);
- writel( OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
- break;
-
- case ISO_IN:
- FILL_ISO_TD( TD_CC|TD_ISO|(ctrl_len & 0xffff), data, data_len, lw0, lw1, ISO_IN | ST_ADDR|ADD_LEN|SEND, handler);
- break;
-
- case ISO_OUT:
- FILL_ISO_TD( TD_CC|TD_ISO|(ctrl_len & 0xffff), data, data_len, lw0, lw1, ISO_OUT | ST_ADDR|ADD_LEN|SEND, handler);
- break;
- }
+/* prepare all TDs of a transfer */
+
+static void td_submit_urb (urb_t * urb)
+{
+ urb_priv_t * urb_priv = urb->hcpriv;
+ ohci_t * ohci = (ohci_t *) urb->dev->bus->hcpriv;
+ void * ctrl = urb->setup_packet;
+ void * data = urb->transfer_buffer;
+ int data_len = urb->transfer_buffer_length;
+ int cnt = 0;
+ __u32 info = 0;
- spin_unlock_irqrestore(&usb_req_lock, flags);
- return td_ret;
-}
+ urb_priv->td_cnt = 0;
+
+ switch (usb_pipetype (urb->pipe)) {
+ case PIPE_BULK:
+ info = usb_pipeout (urb->pipe)?
+ TD_CC | TD_DP_OUT | TD_T_TOGGLE: TD_CC | TD_DP_IN | TD_T_TOGGLE;
+ while(data_len > 4096) {
+ td_fill (info, data, 4096, urb, (cnt? 0: ST_ADDR) | ADD_LEN, cnt);
+ data += 4096; data_len -= 4096; cnt++;
+ }
+ info = usb_pipeout (urb->pipe)?
+ TD_CC | TD_DP_OUT | TD_T_TOGGLE: TD_CC | TD_R | TD_DP_IN | TD_T_TOGGLE;
+ td_fill (info, data, data_len, urb, (cnt? 0: ST_ADDR) | ADD_LEN, cnt);
+ cnt++;
+ writel (OHCI_BLF, &ohci->regs->cmdstatus); /* start bulk list */
+ break;
+
+ case PIPE_INTERRUPT:
+ info = usb_pipeout (urb->pipe)?
+ TD_CC | TD_DP_OUT | TD_T_TOGGLE: TD_CC | TD_R | TD_DP_IN | TD_T_TOGGLE;
+ td_fill (info, data, data_len, urb, ST_ADDR | ADD_LEN, cnt++);
+ break;
+
+ case PIPE_CONTROL:
+ info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
+ td_fill (info, ctrl, 8, urb, ST_ADDR, cnt++);
+ if (data_len > 0) {
+ info = usb_pipeout (urb->pipe)?
+ TD_CC | TD_R | TD_DP_OUT | TD_T_DATA1 : TD_CC | TD_R | TD_DP_IN | TD_T_DATA1;
+ td_fill (info, data, data_len, urb, ADD_LEN, cnt++);
+ }
+ info = usb_pipeout (urb->pipe)?
+ TD_CC | TD_DP_IN | TD_T_DATA1: TD_CC | TD_DP_OUT | TD_T_DATA1;
+ td_fill (info, NULL, 0, urb, 0, cnt++);
+ writel (OHCI_CLF, &ohci->regs->cmdstatus); /* start Control list */
+ break;
-/******
- *** Done List handling functions
- ************************************/
-/* the HC halts an ED if an error occurs;
- * on error move all pending tds of a transaction (from ed) onto the done list
- * * */
-static struct usb_ohci_td * ohci_append_error_tds(struct usb_ohci_td * td_list, struct usb_ohci_td * td_rev) {
-
- struct usb_ohci_td * tdl;
- struct usb_ohci_td * tdx;
- struct usb_ohci_td * tdt;
- int cc;
-
- tdl = (struct usb_ohci_td *) bus_to_virt( td_list->ed->hwHeadP & 0xfffffff0);
- tdt = (struct usb_ohci_td *) bus_to_virt( td_list->ed->hwTailP);
- cc = TD_CC_GET(td_list->hwINFO);
-
- for ( tdx = tdl; tdx != tdt; tdx = tdx->next_dl_td) {
- if(tdx->type & SEND) break;
- tdx->next_dl_td = bus_to_virt(tdx->hwNextTD & 0xfffffff0);
- }
- tdx->next_dl_td = td_rev;
- td_list->ed->hwHeadP = (tdx->hwNextTD & 0xfffffff0) | (td_list->ed->hwHeadP & 0x2);
- TD_CC_SET(tdx->hwINFO, cc);
- return tdl;
+ case PIPE_ISOCHRONOUS:
+ for (cnt = 0; cnt < urb->number_of_packets; cnt++) {
+ td_fill (TD_CC|TD_ISO | ((urb->start_frame + cnt) & 0xffff),
+ (__u8 *) data + urb->iso_frame_desc[cnt].offset,
+ urb->iso_frame_desc[cnt].length, urb, (cnt? 0: ST_ADDR) | ADD_LEN, cnt);
+ }
+ break;
+ }
+#ifdef DEBUG
+ if (urb_priv->length != cnt)
+ dbg (KERN_ERR MODSTR " ********* TD LENGTH %d != CNT %d\n", urb_priv->length, cnt);
+#endif
}
+/*-------------------------------------------------------------------------*
+ * Done List handling functions
+ *-------------------------------------------------------------------------*/
+
/* replies to the request have to be on a FIFO basis so
* we reverse the reversed done-list */
-static struct usb_ohci_td * ohci_reverse_done_list(struct ohci * ohci) {
-
+static td_t * dl_reverse_done_list (ohci_t * ohci)
+{
__u32 td_list_hc;
- struct usb_ohci_td * td_rev = NULL;
- struct usb_ohci_td * td_list = NULL;
+ td_t * td_rev = NULL;
+ td_t * td_list = NULL;
+ urb_priv_t * urb_priv = NULL;
+ unsigned int flags;
- td_list_hc = ohci->hc_area->hcca.done_head & 0xfffffff0;
- ohci->hc_area->hcca.done_head = 0;
+ spin_lock_irqsave (&usb_ed_lock, flags);
+
+ td_list_hc = le32_to_cpu (ohci->hcca.done_head) & 0xfffffff0;
+ ohci->hcca.done_head = 0;
+
+ while (td_list_hc) {
+ td_list = (td_t *) bus_to_virt (td_list_hc);
-
- while(td_list_hc) {
-
- td_list = (struct usb_ohci_td *) bus_to_virt(td_list_hc);
- if(TD_CC_GET(td_list->hwINFO) && !(td_list->type & SEND))
- td_list->next_dl_td = ohci_append_error_tds(td_list, td_rev);
- else
- td_list->next_dl_td = td_rev;
-
+ if (TD_CC_GET (le32_to_cpu (td_list->hwINFO))) {
+ urb_priv = (urb_priv_t *) td_list->urb->hcpriv;
+ dbg (KERN_DEBUG MODSTR "**** USB-error/status: %x : %p \n",
+ TD_CC_GET (le32_to_cpu (td_list->hwINFO)), td_list);
+ if (td_list->ed->hwHeadP & cpu_to_le32 (0x1)) {
+ if (urb_priv && ((td_list->index + 1) < urb_priv->length)) {
+ td_list->ed->hwHeadP =
+ (urb_priv->td[urb_priv->length - 1]->hwNextTD & cpu_to_le32 (0xfffffff0)) |
+ (td_list->ed->hwHeadP & cpu_to_le32 (0x2));
+ urb_priv->td_cnt += urb_priv->length - td_list->index - 1;
+ } else
+ td_list->ed->hwHeadP &= cpu_to_le32 (0xfffffff2);
+ }
+ }
+
+ td_list->next_dl_td = td_rev;
td_rev = td_list;
- td_list_hc = td_list->hwNextTD & 0xfffffff0;
-
-
+ td_list_hc = le32_to_cpu (td_list->hwNextTD) & 0xfffffff0;
}
- return td_list;
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+ return td_list;
}
-/* there are some pending requests to remove some of the eds
- * we either process every td including the dummy td of these eds
- * or just those marked with TD->type&DEL
- * and link them to a list
- * */
-static struct usb_ohci_td * usb_ohci_del_list(struct ohci * ohci) {
- struct usb_ohci_ed * ed;
- struct usb_ohci_td * td;
- struct usb_ohci_td * td_tmp = NULL;
- struct usb_ohci_td * td_list = NULL;
- __u32 * td_hw;
-
- for(ed = ohci->ed_rm_list; ed != NULL; ed = ed->ed_prev) {
- OHCI_DEBUG(printk("USB HC ed_rm_list: %4x :next : %p\n", ed->hwINFO, ed->ed_prev);)
-
-
- for( td_hw = &(ed->hwHeadP); (*td_hw & 0xfffffff0) != ed->hwTailP; td_hw = &(td->hwNextTD)) {
- td = (struct usb_ohci_td *)bus_to_virt(*td_hw & 0xfffffff0);
- if((ED_STATE(ed) == ED_DEL) || (td->type & DEL)) {
- *td_hw = td->hwNextTD;
- if(td_list == NULL)
- td_list = td;
- else
- td_tmp->next_dl_td = td;
- td_tmp = td;
- OHCI_DEBUG(printk("USB HC ed_rm_list: td: %4x\n", (unsigned int) td);)
- td->next_dl_td = NULL;
- }
- }
- if(ED_STATE(ed) == ED_DEL) { /* send dummy td */
- td = (struct usb_ohci_td *)bus_to_virt(*td_hw & 0xfffffff0);
- td->ed = ed;
- if(td_list == NULL)
- td_list = td;
- else
- td_tmp->next_dl_td = td;
- td_tmp = td;
- td->type |= DEL_ED;
- OHCI_DEBUG(printk("USB HC ed_rm_list: dummy (ED_DEL) td: %4x\n", (unsigned int) td);)
- ED_setSTATE(td->ed, ED_DEL| ED_NEW);
- td->next_dl_td = NULL;
- }
- if(ED_TYPE(ed) == CTRL) writel(0, &ohci->regs->ed_controlcurrent); /* reset CTRL list */
- if(ED_TYPE(ed) == BULK) writel(0, &ohci->regs->ed_bulkcurrent); /* reset BULK list */
-
- }
-
- writel_set((0x03<<4), &ohci->regs->control); /* start CTRL u. BULK list */
+/*-------------------------------------------------------------------------*/
- ohci->ed_rm_list = NULL;
-
+/* there are some pending requests to remove
+ * - some of the eds (if ed->state & ED_DEL (set by sohci_free_dev)
+ * - some URBs/TDs if urb_priv->state == URB_DEL */
- return td_list;
-}
+static void dl_del_list (ohci_t * ohci, unsigned int frame)
+{
+ unsigned int flags;
+ ed_t * ed;
+ __u32 edINFO;
+ td_t * td = NULL, * td_next = NULL, * tdHeadP = NULL, * tdTailP;
+ __u32 * td_p;
+ int ctrl = 0, bulk = 0;
+
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ for (ed = ohci->ed_rm_list[frame]; ed != NULL; ed = ed->ed_rm_list) {
+
+ tdTailP = bus_to_virt (le32_to_cpu (ed->hwTailP) & 0xfffffff0);
+ tdHeadP = bus_to_virt (le32_to_cpu (ed->hwHeadP) & 0xfffffff0);
+ edINFO = le32_to_cpu (ed->hwINFO);
+ td_p = &ed->hwHeadP;
+
+ for (td = tdHeadP; td != tdTailP; td = td_next) {
+ urb_t * urb = td->urb;
+ urb_priv_t * urb_priv = td->urb->hcpriv;
+
+ td_next = bus_to_virt (le32_to_cpu (td->hwNextTD) & 0xfffffff0);
+ if ((urb_priv->state == URB_DEL) || (ed->state & ED_DEL)) {
+ *td_p = td->hwNextTD | (*td_p & cpu_to_le32 (0x3));
+ if(++ (urb_priv->td_cnt) == urb_priv->length)
+ urb_rm_priv (urb);
+ } else {
+ td_p = &td->hwNextTD;
+ }
+
+ }
+ if (ed->state & ED_DEL) { /* set by sohci_free_dev */
+ struct ohci_device * dev = usb_to_ohci (ohci->dev[edINFO & 0x7F]);
+ OHCI_FREE (tdTailP); /* free dummy td */
+ ed->hwINFO = cpu_to_le32 (OHCI_ED_SKIP);
+ ed->state = ED_NEW;
+ /* if all eds are removed wake up sohci_free_dev */
+ if ((! --dev->ed_cnt) && dev->wait) {
+ add_wait_queue (&op_wakeup, dev->wait);
+ wake_up (&op_wakeup);
+ }
+ }
+ else {
+ ed->state &= ~ED_URB_DEL;
+ ed->hwINFO &= ~cpu_to_le32 (OHCI_ED_SKIP);
+ }
+
+ if ((ed->type & 3) == CTRL) ctrl |= 1;
+ if ((ed->type & 3) == BULK) bulk |= 1;
+ }
+
+ if (ctrl) writel (0, &ohci->regs->ed_controlcurrent); /* reset CTRL list */
+ if (bulk) writel (0, &ohci->regs->ed_bulkcurrent); /* reset BULK list */
+ if (!ohci->ed_rm_list[!frame]) /* start CTRL u. BULK list */
+ writel (ohci->hc_control |= (0x03<<4), &ohci->regs->control);
+ ohci->ed_rm_list[frame] = NULL;
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+}
-/* all tds ever alive go through this loop
- * requests are replied here
- * the handler is the
- * interface handler (blocking/non blocking) the real reply-handler
- * is called in the non blocking interface routine
- * */
-static int usb_ohci_done_list(struct ohci * ohci, struct usb_ohci_td * td_list) {
+/*-------------------------------------------------------------------------*/
- struct usb_ohci_td * td_list_next = NULL;
+/* td done list */
- int cc;
- int i;
+static void dl_done_list (ohci_t * ohci, td_t * td_list)
+{
+ td_t * td_list_next = NULL;
+ ed_t * ed;
int dlen = 0;
-
- while(td_list) {
+ int cc = 0;
+ urb_t * urb;
+ urb_priv_t * urb_priv;
+ __u32 tdINFO, tdBE, tdCBP, edHeadP, edTailP;
+ __u16 tdPSW;
+ unsigned int flags;
+
+ while (td_list) {
td_list_next = td_list->next_dl_td;
-
- if(td_list->type & ST_ADDR) { /* remember start address of data buffer */
- td_list->ed->buffer_start = td_list->buffer_start;
- td_list->ed->len = 0;
- }
-
- if(td_list->type & ADD_LEN) { /* accumulate length of multi td transfers */
- if(td_list->hwINFO & TD_ISO) {
- for(i= 0; i <= ((td_list->hwINFO >> 24) & 0x7); i++)
- if((td_list->hwPSW[i] >> 12) < 0xE) td_list->ed->len += (td_list->hwPSW[i] & 0x3ff);
- }
- else {
- if(td_list->hwBE != 0) {
- dlen = (bus_to_virt(td_list->hwBE) - td_list->buffer_start + 1);
- if(td_list->hwCBP == 0)
- td_list->ed->len += dlen;
+
+ urb = td_list->urb;
+ urb_priv = urb->hcpriv;
+ tdINFO = le32_to_cpu (td_list->hwINFO);
+ tdBE = le32_to_cpu (td_list->hwBE);
+ tdCBP = le32_to_cpu (td_list->hwCBP);
+
+ ed = td_list->ed;
+
+ if (td_list->type & ST_ADDR)
+ urb->actual_length = 0;
+
+ if (td_list->type & ADD_LEN) { /* accumulate length of multi td transfers */
+ if (tdINFO & TD_ISO) {
+ tdPSW = le16_to_cpu (td_list->hwPSW[0]);
+ cc = (tdPSW >> 12) & 0xF;
+ if (cc < 0xE) {
+ if (usb_pipeout(urb->pipe)) {
+ dlen = urb->iso_frame_desc[td_list->index].length;
+ } else {
+ dlen = tdPSW & 0x3ff;
+ }
+ urb->actual_length += dlen;
+ urb->iso_frame_desc[td_list->index].actual_length = dlen;
+ if (!(urb->transfer_flags & USB_DISABLE_SPD) && (cc == TD_DATAUNDERRUN))
+ cc = TD_CC_NOERROR;
+
+ urb->iso_frame_desc[td_list->index].status = cc_to_error[cc];
+ }
+ } else {
+ if (tdBE != 0) {
+ dlen = (bus_to_virt (tdBE) - urb->transfer_buffer + 1);
+ if (td_list->hwCBP == 0)
+ urb->actual_length += dlen;
else
- td_list->ed->len += (bus_to_virt(td_list->hwCBP) - td_list->buffer_start);
+ urb->actual_length += (bus_to_virt(tdCBP) - urb->transfer_buffer);
}
}
}
/* error code of transfer */
- cc = (ED_STATE(td_list->ed) == ED_DEL || (td_list->type & DEL))? USB_ST_REMOVED : (USB_ST_CRC*TD_CC_GET(td_list->hwINFO));
-
- if(td_list->type & DEL_ED) ED_setSTATE(td_list->ed, ED_NEW); /* remove ed */
-
- if((td_list->type & SEND) && (ED_STATE(td_list->ed) != ED_STOP) && (td_list->handler)) { /* send the reply */
- td_list->handler((void *) ohci,
- td_list,
- td_list->ed->buffer_start,
- td_list->ed->len,
- dlen,
- cc,
- td_list->lw0,
- td_list->lw1);
- OHCI_DEBUG(if(cc != TD_CC_NOERROR) printk("******* USB BUS error %x @ep %x\n", TD_CC_GET(td_list->hwINFO), td_list->ed->hwINFO);)
-
- }
- if(ED_STATE(td_list->ed) == ED_TD_DEL) td_list->ed->hwINFO &= ~OHCI_ED_SKIP;
-
- if(((td_list->ed->hwHeadP & 0xfffffff0) == td_list->ed->hwTailP) && (ED_STATE(td_list->ed) > ED_UNLINK))
- ohci_unlink_ed(ohci, td_list->ed); /* unlink eds if they are not busy */
-
- OHCI_FREE(td_list);
+ cc = TD_CC_GET (tdINFO);
+ if (!(urb->transfer_flags & USB_DISABLE_SPD) && (cc == TD_DATAUNDERRUN))
+ cc = TD_CC_NOERROR;
+ if (++(urb_priv->td_cnt) == urb_priv->length) {
+ if (urb_priv->state != URB_DEL && !(ed->state & ED_DEL) && ed->state != ED_NEW) {
+ urb->status = cc_to_error[cc];
+ sohci_return_urb (urb);
+ } else {
+ urb_rm_priv (urb);
+ }
+ }
+
+ spin_lock_irqsave (&usb_ed_lock, flags);
+ if (ed->state != ED_NEW) {
+ edHeadP = le32_to_cpu (ed->hwHeadP) & 0xfffffff0;
+ edTailP = le32_to_cpu (ed->hwTailP);
+
+ if((edHeadP == edTailP) && (ed->state == ED_OPER))
+ ep_unlink (ohci, ed); /* unlink eds if they are not busy */
+
+ }
+ spin_unlock_irqrestore (&usb_ed_lock, flags);
+
td_list = td_list_next;
}
- return 0;
}
-/******
- *** HC functions
- ************************************/
+
+/*-------------------------------------------------------------------------*
+ * Virtual Root Hub
+ *-------------------------------------------------------------------------*/
+
+static __u8 root_hub_dev_des[] =
+{
+ 0x12, /* __u8 bLength; */
+ 0x01, /* __u8 bDescriptorType; Device */
+ 0x00, /* __u16 bcdUSB; v1.0 */
+ 0x01,
+ 0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
+ 0x00, /* __u8 bDeviceSubClass; */
+ 0x00, /* __u8 bDeviceProtocol; */
+ 0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
+ 0x00, /* __u16 idVendor; */
+ 0x00,
+ 0x00, /* __u16 idProduct; */
+ 0x00,
+ 0x00, /* __u16 bcdDevice; */
+ 0x00,
+ 0x00, /* __u8 iManufacturer; */
+ 0x00, /* __u8 iProduct; */
+ 0x00, /* __u8 iSerialNumber; */
+ 0x01 /* __u8 bNumConfigurations; */
+};
+
+
+/* Configuration descriptor */
+static __u8 root_hub_config_des[] =
+{
+ 0x09, /* __u8 bLength; */
+ 0x02, /* __u8 bDescriptorType; Configuration */
+ 0x19, /* __u16 wTotalLength; */
+ 0x00,
+ 0x01, /* __u8 bNumInterfaces; */
+ 0x01, /* __u8 bConfigurationValue; */
+ 0x00, /* __u8 iConfiguration; */
+ 0x40, /* __u8 bmAttributes;
+ Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup, 4..0: resvd */
+ 0x00, /* __u8 MaxPower; */
+
+ /* interface */
+ 0x09, /* __u8 if_bLength; */
+ 0x04, /* __u8 if_bDescriptorType; Interface */
+ 0x00, /* __u8 if_bInterfaceNumber; */
+ 0x00, /* __u8 if_bAlternateSetting; */
+ 0x01, /* __u8 if_bNumEndpoints; */
+ 0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
+ 0x00, /* __u8 if_bInterfaceSubClass; */
+ 0x00, /* __u8 if_bInterfaceProtocol; */
+ 0x00, /* __u8 if_iInterface; */
+
+ /* endpoint */
+ 0x07, /* __u8 ep_bLength; */
+ 0x05, /* __u8 ep_bDescriptorType; Endpoint */
+ 0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
+ 0x03, /* __u8 ep_bmAttributes; Interrupt */
+ 0x08, /* __u16 ep_wMaxPacketSize; 8 Bytes */
+ 0x00,
+ 0xff /* __u8 ep_bInterval; 255 ms */
+};
+
+/*
+For OHCI we need just the 2nd Byte, so we
+don't need this constant byte-array
+
+static __u8 root_hub_hub_des[] =
+{
+ 0x00, * __u8 bLength; *
+ 0x29, * __u8 bDescriptorType; Hub-descriptor *
+ 0x02, * __u8 bNbrPorts; *
+ 0x00, * __u16 wHubCharacteristics; *
+ 0x00,
+ 0x01, * __u8 bPwrOn2pwrGood; 2ms *
+ 0x00, * __u8 bHubContrCurrent; 0 mA *
+ 0x00, * __u8 DeviceRemovable; *** 8 Ports max *** *
+ 0xff * __u8 PortPwrCtrlMask; *** 8 ports max *** *
+};
+*/
+
+/*-------------------------------------------------------------------------*/
+
+/* prepare Interrupt pipe data; HUB INTERRUPT ENDPOINT */
+
+static int rh_send_irq (ohci_t * ohci, void * rh_data, int rh_len)
+{
+ int num_ports;
+ int i;
+ int ret;
+ int len;
+
+ __u8 data[8];
+
+ num_ports = readl (&ohci->regs->roothub.a) & 0xff;
+ *(__u8 *) data = (readl (&ohci->regs->roothub.status) & 0x00030000) > 0? 1: 0;
+ ret = *(__u8 *) data;
+
+ for ( i = 0; i < num_ports; i++) {
+ *(__u8 *) (data + i / 8) |=
+ ((readl (&ohci->regs->roothub.portstatus[i]) & 0x001f0000) > 0? 1: 0) << ((i + 1) % 8);
+ ret += *(__u8 *) (data + i / 8);
+ }
+ len = i/8 + 1;
+
+ if (ret > 0) {
+ memcpy (rh_data, data, min (len, min (rh_len, sizeof(data))));
+ return len;
+ }
+ return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+/* Virtual Root Hub INTs are polled by this timer every "intervall" ms */
+
+static void rh_int_timer_do (unsigned long ptr)
+{
+ int len;
+
+ urb_t * urb = (urb_t *) ptr;
+ ohci_t * ohci = urb->dev->bus->hcpriv;
+
+ if(ohci->rh.send) {
+ len = rh_send_irq (ohci, urb->transfer_buffer, urb->transfer_buffer_length);
+ if (len > 0) {
+ urb->actual_length = len;
+#ifdef DEBUG
+ urb_print (urb, "RET(rh)", usb_pipeout (urb->pipe));
+#endif
+ if (urb->complete) urb->complete (urb);
+ }
+ }
+ rh_init_int_timer (urb);
+}
+
+/*-------------------------------------------------------------------------*/
+
+/* Root Hub INTs are polled by this timer */
+
+static int rh_init_int_timer (urb_t * urb)
+{
+ ohci_t * ohci = urb->dev->bus->hcpriv;
+
+ ohci->rh.interval = urb->interval;
+ init_timer (&ohci->rh.rh_int_timer);
+ ohci->rh.rh_int_timer.function = rh_int_timer_do;
+ ohci->rh.rh_int_timer.data = (unsigned long) urb;
+ ohci->rh.rh_int_timer.expires =
+ jiffies + (HZ * (urb->interval < 30? 30: urb->interval)) / 1000;
+ add_timer (&ohci->rh.rh_int_timer);
+
+ return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+#define OK(x) len = (x); break
+#define WR_RH_STAT(x) writel((x), &ohci->regs->roothub.status)
+#define WR_RH_PORTSTAT(x) writel((x), &ohci->regs->roothub.portstatus[wIndex-1])
+#define RD_RH_STAT readl(&ohci->regs->roothub.status)
+#define RD_RH_PORTSTAT readl(&ohci->regs->roothub.portstatus[wIndex-1])
+
+/* request to virtual root hub */
+
+static int rh_submit_urb (urb_t * urb)
+{
+ struct usb_device * usb_dev = urb->dev;
+ ohci_t * ohci = usb_dev->bus->hcpriv;
+ unsigned int pipe = urb->pipe;
+ devrequest * cmd = (devrequest *) urb->setup_packet;
+ void * data = urb->transfer_buffer;
+ int leni = urb->transfer_buffer_length;
+ int len = 0;
+ int status = TD_CC_NOERROR;
+
+ __u8 datab[16];
+ __u8 * data_buf = datab;
+
+ __u16 bmRType_bReq;
+ __u16 wValue;
+ __u16 wIndex;
+ __u16 wLength;
+
+ if (usb_pipeint(pipe)) {
+
+ ohci->rh.urb = urb;
+ ohci->rh.send = 1;
+ ohci->rh.interval = urb->interval;
+ rh_init_int_timer(urb);
+ urb->status = cc_to_error [TD_CC_NOERROR];
+
+ return 0;
+ }
+
+ bmRType_bReq = cmd->requesttype | (cmd->request << 8);
+ wValue = le16_to_cpu (cmd->value);
+ wIndex = le16_to_cpu (cmd->index);
+ wLength = le16_to_cpu (cmd->length);
+ switch (bmRType_bReq) {
+ /* Request Destination:
+ without flags: Device,
+ RH_INTERFACE: interface,
+ RH_ENDPOINT: endpoint,
+ RH_CLASS means HUB here,
+ RH_OTHER | RH_CLASS almost ever means HUB_PORT here
+ */
+
+ case RH_GET_STATUS:
+ *(__u16 *) data_buf = cpu_to_le16 (1); OK (2);
+ case RH_GET_STATUS | RH_INTERFACE:
+ *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
+ case RH_GET_STATUS | RH_ENDPOINT:
+ *(__u16 *) data_buf = cpu_to_le16 (0); OK (2);
+ case RH_GET_STATUS | RH_CLASS:
+ *(__u32 *) data_buf = cpu_to_le32 (RD_RH_STAT & 0x7fff7fff); OK (4);
+ case RH_GET_STATUS | RH_OTHER | RH_CLASS:
+ *(__u32 *) data_buf = cpu_to_le32 (RD_RH_PORTSTAT); OK (4);
+
+ case RH_CLEAR_FEATURE | RH_ENDPOINT:
+ switch (wValue) {
+ case (RH_ENDPOINT_STALL): OK (0);
+ }
+ break;
+
+ case RH_CLEAR_FEATURE | RH_CLASS:
+ switch (wValue) {
+ case (RH_C_HUB_OVER_CURRENT):
+ WR_RH_STAT(RH_PS_OCIC); OK (0);
+ }
+ break;
+
+ case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
+ switch (wValue) {
+ case (RH_PORT_ENABLE):
+ WR_RH_PORTSTAT (RH_PS_CCS ); OK (0);
+ case (RH_PORT_SUSPEND):
+ WR_RH_PORTSTAT (RH_PS_POCI); OK (0);
+ case (RH_PORT_POWER):
+ WR_RH_PORTSTAT (RH_PS_LSDA); OK (0);
+ case (RH_C_PORT_CONNECTION):
+ WR_RH_PORTSTAT (RH_PS_CSC ); OK (0);
+ case (RH_C_PORT_ENABLE):
+ WR_RH_PORTSTAT (RH_PS_PESC); OK (0);
+ case (RH_C_PORT_SUSPEND):
+ WR_RH_PORTSTAT (RH_PS_PSSC); OK (0);
+ case (RH_C_PORT_OVER_CURRENT):
+ WR_RH_PORTSTAT (RH_PS_OCIC); OK (0);
+ case (RH_C_PORT_RESET):
+ WR_RH_PORTSTAT (RH_PS_PRSC); OK (0);
+ }
+ break;
+
+ case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
+ switch (wValue) {
+ case (RH_PORT_SUSPEND):
+ WR_RH_PORTSTAT (RH_PS_PSS ); OK (0);
+ case (RH_PORT_RESET): /* BUG IN HUP CODE *********/
+ if((RD_RH_PORTSTAT &1) != 0) WR_RH_PORTSTAT (RH_PS_PRS ); OK (0);
+ case (RH_PORT_POWER):
+ WR_RH_PORTSTAT (RH_PS_PPS ); OK (0);
+ case (RH_PORT_ENABLE): /* BUG IN HUP CODE *********/
+ if((RD_RH_PORTSTAT &1) != 0) WR_RH_PORTSTAT (RH_PS_PES ); OK (0);
+ }
+ break;
+
+ case RH_SET_ADDRESS: ohci->rh.devnum = wValue; OK(0);
+
+ case RH_GET_DESCRIPTOR:
+ switch ((wValue & 0xff00) >> 8) {
+ case (0x01): /* device descriptor */
+ len = min (leni, min (sizeof (root_hub_dev_des), wLength));
+ data_buf = root_hub_dev_des; OK(len);
+ case (0x02): /* configuration descriptor */
+ len = min (leni, min (sizeof (root_hub_config_des), wLength));
+ data_buf = root_hub_config_des; OK(len);
+ case (0x03): /* string descriptors */
+ default:
+ status = TD_CC_STALL;
+ }
+ break;
+
+ case RH_GET_DESCRIPTOR | RH_CLASS:
+ *(__u8 *) (data_buf+1) = 0x29;
+ *(__u32 *) (data_buf+2) = cpu_to_le32 (readl (&ohci->regs->roothub.a));
+ *(__u8 *) data_buf = (*(__u8 *) (data_buf + 2) / 8) * 2 + 9; /* length of descriptor */
+
+ len = min (leni, min(*(__u8 *) data_buf, wLength));
+ *(__u8 *) (data_buf+6) = 0; /* Root Hub needs no current from bus */
+ if (*(__u8 *) (data_buf+2) < 8) { /* less than 8 Ports */
+ *(__u8 *) (data_buf+7) = readl (&ohci->regs->roothub.b) & 0xff;
+ *(__u8 *) (data_buf+8) = (readl (&ohci->regs->roothub.b) & 0xff0000) >> 16;
+ } else {
+ *(__u32 *) (data_buf+7) = cpu_to_le32 (readl(&ohci->regs->roothub.b));
+ }
+ OK (len);
+
+ case RH_GET_CONFIGURATION: *(__u8 *) data_buf = 0x01; OK (1);
+
+ case RH_SET_CONFIGURATION: WR_RH_STAT (0x10000); OK (0);
+
+ default:
+ status = TD_CC_STALL;
+ }
+
+ dbg (KERN_DEBUG MODSTR "USB HC roothubstat1: %x \n",
+ readl ( &(ohci->regs->roothub.portstatus[0]) ));
+ dbg (KERN_DEBUG MODSTR "USB HC roothubstat2: %x \n",
+ readl ( &(ohci->regs->roothub.portstatus[1]) ));
+
+ len = min(len, leni);
+ memcpy (data, data_buf, len);
+ urb->actual_length = len;
+ urb->status = cc_to_error [status];
+
+#ifdef DEBUG
+ urb_print (urb, "RET(rh)", usb_pipeout (urb->pipe));
+#endif
+
+ if (urb->complete) urb->complete (urb);
+ return 0;
+}
+
+/*-------------------------------------------------------------------------*/
+
+static int rh_unlink_urb (urb_t * urb)
+{
+ ohci_t * ohci = urb->dev->bus->hcpriv;
+
+ ohci->rh.send = 0;
+ del_timer (&ohci->rh.rh_int_timer);
+ return 0;
+}
+/*-------------------------------------------------------------------------*
+ * HC functions
+ *-------------------------------------------------------------------------*/
/* reset the HC not the BUS */
-void reset_hc(struct ohci *ohci) {
+static void hc_reset (ohci_t * ohci)
+{
int timeout = 30;
int smm_timeout = 50; /* 0,5 sec */
- if(readl(&ohci->regs->control) & 0x100) { /* SMM owns the HC */
- writel(0x08, &ohci->regs->cmdstatus); /* request ownership */
- printk("USB HC TakeOver from SMM\n");
- while(readl(&ohci->regs->control) & 0x100) {
- wait_ms(10);
+ if (readl (&ohci->regs->control) & 0x100) { /* SMM owns the HC */
+ writel (0x08, &ohci->regs->cmdstatus); /* request ownership */
+ printk (KERN_DEBUG MODSTR "USB HC TakeOver from SMM\n");
+ while (readl (&ohci->regs->control) & 0x100) {
+ wait_ms (10);
if (--smm_timeout == 0) {
- printk("USB HC TakeOver failed!\n");
+ printk (KERN_ERR MODSTR "USB HC TakeOver failed!\n");
break;
}
}
}
- writel((1<<31), &ohci->regs->intrdisable); /* Disable HC interrupts */
- OHCI_DEBUG(printk("USB HC reset_hc: %x ; \n", readl(&ohci->regs->control));)
-
- writel(1, &ohci->regs->cmdstatus); /* HC Reset */
- while ((readl(&ohci->regs->cmdstatus) & 0x01) != 0) { /* 10us Reset */
+ writel ((1 << 31), &ohci->regs->intrdisable); /* Disable HC interrupts */
+ dbg (KERN_DEBUG MODSTR "USB HC reset_hc: %x ; \n", readl (&ohci->regs->control));
+ /* this seems to be needed for the lucent controller on powerbooks.. */
+ writel (0, &ohci->regs->control); /* Move USB to reset state */
+
+ writel (1, &ohci->regs->cmdstatus); /* HC Reset */
+ while ((readl (&ohci->regs->cmdstatus) & 0x01) != 0) { /* 10us Reset */
if (--timeout == 0) {
- printk("USB HC reset timed out!\n");
+ printk (KERN_ERR MODSTR "USB HC reset timed out!\n");
return;
}
- udelay(1);
+ udelay (1);
}
}
+/*-------------------------------------------------------------------------*/
-/*
- * Start an OHCI controller, set the BUS operational
- * set and enable interrupts
- * connect the virtual root hub
- * * */
+/* Start an OHCI controller, set the BUS operational
+ * enable interrupts
+ * connect the virtual root hub */
-int start_hc(struct ohci *ohci)
+static int hc_start (ohci_t * ohci)
{
- unsigned int mask;
- int fminterval;
-
- /*
- * Tell the controller where the control and bulk lists are
- * The lists are empty now.
- */
- writel(0, &ohci->regs->ed_controlhead);
- writel(0, &ohci->regs->ed_bulkhead);
+ unsigned int mask;
+ unsigned int fminterval;
+ struct usb_device * usb_dev;
+ struct ohci_device * dev;
+
+ /* Tell the controller where the control and bulk lists are
+ * The lists are empty now. */
+
+ writel (0, &ohci->regs->ed_controlhead);
+ writel (0, &ohci->regs->ed_bulkhead);
- writel(virt_to_bus(&ohci->hc_area->hcca), &ohci->regs->hcca); /* a reset clears this */
+ writel (virt_to_bus(&ohci->hcca), &ohci->regs->hcca); /* a reset clears this */
- writel((0xBF), &ohci->regs->control); /* USB Operational */
-
fminterval = 0x2edf;
- writel(((fminterval)*9)/10, &ohci->regs->periodicstart);
- fminterval |= ((((fminterval -210) * 6)/7)<<16);
- writel(fminterval, &ohci->regs->fminterval);
- writel(0x628, &ohci->regs->lsthresh);
- OHCI_DEBUG(printk("USB HC fminterval: %x \n", readl( &(ohci->regs->fminterval) )); )
- OHCI_DEBUG(printk("USB HC periodicstart: %x \n", readl( &(ohci->regs->periodicstart) )); )
- OHCI_DEBUG(printk("USB HC lsthresh: %x \n", readl( &(ohci->regs->lsthresh) )); )
- OHCI_DEBUG(printk("USB HC control: %x\n", readl(&ohci->regs->control)); )
- OHCI_DEBUG(printk("USB HC roothubstata: %x \n", readl( &(ohci->regs->roothub.a) )); )
- OHCI_DEBUG(printk("USB HC roothubstatb: %x \n", readl( &(ohci->regs->roothub.b) )); )
- OHCI_DEBUG(printk("USB HC roothubstatu: %x \n", readl( &(ohci->regs->roothub.status) )); )
- OHCI_DEBUG(printk("USB HC roothubstat1: %x \n", readl( &(ohci->regs->roothub.portstatus[0]) )); )
- OHCI_DEBUG(printk("USB HC roothubstat2: %x \n", readl( &(ohci->regs->roothub.portstatus[1]) )); )
+ writel ((fminterval * 9) / 10, &ohci->regs->periodicstart);
+ fminterval |= ((((fminterval - 210) * 6) / 7) << 16);
+ writel (fminterval, &ohci->regs->fminterval);
+ writel (0x628, &ohci->regs->lsthresh);
+
/* Choose the interrupts we care about now, others later on demand */
mask = OHCI_INTR_MIE | OHCI_INTR_WDH | OHCI_INTR_SO;
-
- writel(mask, &ohci->regs->intrenable);
- writel(mask, &ohci->regs->intrstatus);
+
+ writel (ohci->hc_control = 0xBF, &ohci->regs->control); /* USB Operational */
+ writel (mask, &ohci->regs->intrenable);
+ writel (mask, &ohci->regs->intrstatus);
-#ifdef VROOTHUB
- {
/* connect the virtual root hub */
- struct usb_device * usb_dev;
- struct ohci_device *dev;
-
-
- usb_dev = usb_alloc_dev(NULL, ohci->bus);
+
+ usb_dev = usb_alloc_dev (NULL, ohci->bus);
if (!usb_dev) return -1;
- dev = usb_to_ohci(usb_dev);
- // usb_dev->bus = ohci->bus;
+ dev = usb_to_ohci (usb_dev);
ohci->bus->root_hub = usb_dev;
- dev->ohci = ohci;
- usb_connect(usb_dev);
- if(usb_new_device(usb_dev) != 0) {
- usb_free_dev(usb_dev);
+ usb_connect (usb_dev);
+ if (usb_new_device (usb_dev) != 0) {
+ usb_free_dev (usb_dev);
return -1;
}
-
- }
-#endif
+
return 0;
}
+/*-------------------------------------------------------------------------*/
+
/* an interrupt happens */
-static void ohci_interrupt(int irq, void *__ohci, struct pt_regs *r)
+
+static void hc_interrupt (int irq, void * __ohci, struct pt_regs * r)
{
- struct ohci *ohci = __ohci;
- struct ohci_regs *regs = ohci->regs;
+ ohci_t * ohci = __ohci;
+ struct ohci_regs * regs = ohci->regs;
int ints;
- if((ohci->hc_area->hcca.done_head != 0) && !(ohci->hc_area->hcca.done_head & 0x01)) {
+ if ((ohci->hcca.done_head != 0) && !(ohci->hcca.done_head & 0x01)) {
ints = OHCI_INTR_WDH;
- }
- else {
- if((ints = (readl(®s->intrstatus) & readl(®s->intrenable))) == 0)
- return;
+ } else {
+ if ((ints = (readl (®s->intrstatus) & readl (®s->intrenable))) == 0)
+ return;
}
-
- OHCI_DEBUG(printk("USB HC interrupt: %x (%x) \n", ints, readl(®s->intrstatus));)
-
- if(ints & OHCI_INTR_WDH) {
- writel(OHCI_INTR_WDH, ®s->intrdisable);
- usb_ohci_done_list(ohci, ohci_reverse_done_list(ohci));
- writel(OHCI_INTR_WDH, ®s->intrenable);
+ dbg (KERN_DEBUG MODSTR "Interrupt: %x frame: %x \n", ints, ohci->hcca.frame_no);
+
+ if (ints & OHCI_INTR_WDH) {
+ writel (OHCI_INTR_WDH, ®s->intrdisable);
+ dl_done_list (ohci, dl_reverse_done_list (ohci));
+ writel (OHCI_INTR_WDH, ®s->intrenable);
}
- if(ints & OHCI_INTR_SO) {
- printk("**** USB Schedule overrun ");
- writel(OHCI_INTR_SO, ®s->intrenable);
+ if (ints & OHCI_INTR_SO) {
+ dbg (KERN_ERR MODSTR " USB Schedule overrun \n");
+ writel (OHCI_INTR_SO, ®s->intrenable);
}
- if(ints & OHCI_INTR_SF) {
- writel(OHCI_INTR_SF, ®s->intrdisable);
- if(ohci->ed_rm_list != NULL) {
- usb_ohci_done_list(ohci, usb_ohci_del_list(ohci));
+ if (ints & OHCI_INTR_SF) {
+ unsigned int frame = (ohci->hcca.frame_no) & 1;
+ writel (OHCI_INTR_SF, ®s->intrdisable);
+ if (ohci->ed_rm_list[!frame] != NULL) {
+ dl_del_list (ohci, !frame);
}
+ if (ohci->ed_rm_list[frame] != NULL) writel (OHCI_INTR_SF, ®s->intrenable);
}
- writel(ints, ®s->intrstatus);
- writel(OHCI_INTR_MIE, ®s->intrenable);
+ writel (ints, ®s->intrstatus);
+ writel (OHCI_INTR_MIE, ®s->intrenable);
}
+/*-------------------------------------------------------------------------*/
+
/* allocate OHCI */
-static struct ohci *alloc_ohci(void* mem_base)
+static ohci_t * hc_alloc_ohci (void * mem_base)
{
int i;
- struct ohci *ohci;
- struct ohci_hc_area *hc_area;
- struct usb_bus *bus;
+ ohci_t * ohci;
+ struct usb_bus * bus;
- hc_area = (struct ohci_hc_area *) __get_free_pages(GFP_KERNEL, 1);
- if (!hc_area)
+ ohci = (ohci_t *) __get_free_pages (GFP_KERNEL, 1);
+ if (!ohci)
return NULL;
- memset(hc_area, 0, sizeof(*hc_area));
- ohci = &hc_area->ohci;
+ memset (ohci, 0, sizeof (ohci_t));
+
ohci->irq = -1;
ohci->regs = mem_base;
- ohci->hc_area = hc_area;
- /*
- * for load ballancing of the interrupt branches
- */
+ /* for load ballancing of the interrupt branches */
for (i = 0; i < NUM_INTS; i++) ohci->ohci_int_load[i] = 0;
- for (i = 0; i < NUM_INTS; i++) hc_area->hcca.int_table[i] = 0;
+ for (i = 0; i < NUM_INTS; i++) ohci->hcca.int_table[i] = 0;
- /*
- * Store the end of control and bulk list eds. So, we know where we can add
- * elements to these lists.
- */
+ /* end of control and bulk lists */
ohci->ed_isotail = NULL;
ohci->ed_controltail = NULL;
ohci->ed_bulktail = NULL;
- bus = usb_alloc_bus(&sohci_device_operations);
+ bus = usb_alloc_bus (&sohci_device_operations);
if (!bus) {
- free_pages((unsigned int) ohci->hc_area, 1);
+ free_pages ((unsigned int) ohci, 1);
return NULL;
}
@@ -1398,121 +1599,166 @@
return ohci;
}
+/*-------------------------------------------------------------------------*/
-/*
- * De-allocate all resources..
- * */
-static void release_ohci(struct ohci *ohci)
-{
-
- OHCI_DEBUG(printk("USB HC release ohci \n"););
- /* stop hc */
-
-
-
- /* disconnect all devices */
- if(ohci->bus->root_hub) usb_disconnect(&ohci->bus->root_hub);
+/* De-allocate all resources.. */
+
+static void hc_release_ohci (ohci_t * ohci)
+{
+ dbg (KERN_DEBUG MODSTR "USB HC release ohci\n");
+
+ /* disconnect all devices */
+ if (ohci->bus->root_hub) usb_disconnect (&ohci->bus->root_hub);
- reset_hc(ohci);
- writel(OHCI_USB_RESET, &ohci->regs->control);
- wait_ms(10);
+ hc_reset (ohci);
+ writel (OHCI_USB_RESET, &ohci->regs->control);
+ wait_ms (10);
if (ohci->irq >= 0) {
- free_irq(ohci->irq, ohci);
+ free_irq (ohci->irq, ohci);
ohci->irq = -1;
}
- usb_deregister_bus(ohci->bus);
- usb_free_bus(ohci->bus);
+ usb_deregister_bus (ohci->bus);
+ usb_free_bus (ohci->bus);
/* unmap the IO address space */
- iounmap(ohci->regs);
+ iounmap (ohci->regs);
- free_pages((unsigned int) ohci->hc_area, 1);
+ free_pages ((unsigned int) ohci, 1);
}
+/*-------------------------------------------------------------------------*/
-/*
- * Increment the module usage count, start the control thread and
- * return success.
- * */
-static int found_ohci(int irq, void* mem_base)
+/* Increment the module usage count, start the control thread and
+ * return success. */
+
+static int hc_found_ohci (int irq, void * mem_base)
{
- struct ohci *ohci;
- OHCI_DEBUG(printk("USB HC found ohci: irq= %d membase= %x \n", irq, (int)mem_base);)
+ ohci_t * ohci;
+ dbg (KERN_DEBUG MODSTR "USB HC found: irq= %d membase= %x \n", irq, (int) mem_base);
- ohci = alloc_ohci(mem_base);
+ ohci = hc_alloc_ohci (mem_base);
if (!ohci) {
return -ENOMEM;
}
- INIT_LIST_HEAD(&ohci->ohci_hcd_list);
- list_add(&ohci->ohci_hcd_list, &ohci_hcd_list);
+ INIT_LIST_HEAD (&ohci->ohci_hcd_list);
+ list_add (&ohci->ohci_hcd_list, &ohci_hcd_list);
- reset_hc(ohci);
- writel(OHCI_USB_RESET, &ohci->regs->control);
- wait_ms(10);
- usb_register_bus(ohci->bus);
+ hc_reset (ohci);
+ writel (ohci->hc_control = OHCI_USB_RESET, &ohci->regs->control);
+ wait_ms (10);
+ usb_register_bus (ohci->bus);
- if (request_irq(irq, ohci_interrupt, SA_SHIRQ, "ohci-usb", ohci) == 0) {
+ if (request_irq (irq, hc_interrupt, SA_SHIRQ, "ohci-usb", ohci) == 0) {
ohci->irq = irq;
- start_hc(ohci);
+ hc_start (ohci);
return 0;
}
- printk(KERN_ERR "USB HC (ohci-hcd): request interrupt %d failed\n", irq);
- release_ohci(ohci);
+ printk (KERN_ERR MODSTR "request interrupt %d failed\n", irq);
+ hc_release_ohci (ohci);
return -EBUSY;
}
+
+/*-------------------------------------------------------------------------*/
-static int start_ohci(struct pci_dev *dev)
+static int hc_start_ohci (struct pci_dev * dev)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,0)
unsigned int mem_base = dev->resource[0].start;
+#else
+ unsigned int mem_base = dev->base_address[0];
+ if (mem_base & PCI_BASE_ADDRESS_SPACE_IO) return -ENODEV;
+ mem_base &= PCI_BASE_ADDRESS_MEM_MASK;
+#endif
- pci_set_master(dev);
- mem_base = (unsigned int) ioremap_nocache(mem_base, 4096);
+ pci_set_master (dev);
+ mem_base = (unsigned int) ioremap_nocache (mem_base, 4096);
if (!mem_base) {
- printk("Error mapping OHCI memory\n");
+ printk (KERN_ERR MODSTR "Error mapping OHCI memory\n");
return -EFAULT;
}
- return found_ohci(dev->irq, (void *) mem_base);
+ return hc_found_ohci (dev->irq, (void *) mem_base);
}
+/*-------------------------------------------------------------------------*/
+
+#ifdef CONFIG_PMAC_PBOOK
+
+/* On Powerbooks, put the controller into suspend mode when going
+ * to sleep, and do a resume when waking up. */
+
+static int ohci_sleep_notify (struct pmu_sleep_notifier * self, int when)
+{
+ struct list_head * ohci_l;
+ ohci_t * ohci;
+
+ for (ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
+ ohci = list_entry (ohci_l, ohci_t, ohci_hcd_list);
+
+ switch (when) {
+ case PBOOK_SLEEP_NOW:
+ disable_irq (ohci->irq);
+ writel (ohci->hc_control = OHCI_USB_SUSPEND, &ohci->regs->control);
+ wait_ms (10);
+ break;
+ case PBOOK_WAKE:
+ writel (ohci->hc_control = OHCI_USB_RESUME, &ohci->regs->control);
+ wait_ms (20);
+ writel (ohci->hc_control = 0xBF, &ohci->regs->control);
+ enable_irq (ohci->irq);
+ break;
+ }
+ }
+ return PBOOK_SLEEP_OK;
+}
+
+static struct pmu_sleep_notifier ohci_sleep_notifier = {
+ ohci_sleep_notify, SLEEP_LEVEL_MISC,
+};
+#endif /* CONFIG_PMAC_PBOOK */
+/*-------------------------------------------------------------------------*/
+
#ifdef CONFIG_APM
-static int handle_apm_event(apm_event_t event)
+static int handle_apm_event (apm_event_t event)
{
static int down = 0;
- struct ohci * ohci;
- struct list_head *ohci_l;
-
+ ohci_t * ohci;
+ struct list_head * ohci_l;
+
switch (event) {
case APM_SYS_SUSPEND:
case APM_USER_SUSPEND:
if (down) {
- printk(KERN_DEBUG "ohci: received extra suspend event\n");
+ printk(KERN_DEBUG MODSTR "received extra suspend event\n");
break;
}
- for(ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
- ohci = list_entry(ohci_l, struct ohci, ohci_hcd_list);
- OHCI_DEBUG(printk("USB OHCI suspend: %p\n", ohci);)
- writel(0xff, &ohci->regs->control); /* Suspend */
+ for (ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
+ ohci = list_entry (ohci_l, ohci_t, ohci_hcd_list);
+ dbg (KERN_DEBUG MODSTR "USB-Bus suspend: %p\n", ohci);
+ writel (ohci->hc_control = 0xFF, &ohci->regs->control);
}
- wait_ms(10);
+ wait_ms (10);
down = 1;
break;
case APM_NORMAL_RESUME:
case APM_CRITICAL_RESUME:
if (!down) {
- printk(KERN_DEBUG "ohci: received bogus resume event\n");
+ printk (KERN_DEBUG MODSTR "received bogus resume event\n");
break;
}
- for(ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
- ohci = list_entry(ohci_l, struct ohci, ohci_hcd_list);
- OHCI_DEBUG(printk("USB OHCI resume: %p\n", ohci);)
- writel(0x7f, &ohci->regs->control); /* Resume */
- wait_ms(20);
- writel(0xBF, &ohci->regs->control); /* Operational */
+ for (ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
+ ohci = list_entry(ohci_l, ohci_t, ohci_hcd_list);
+ dbg (KERN_DEBUG MODSTR "USB-Bus resume: %p\n", ohci);
+ writel (ohci->hc_control = 0x7F, &ohci->regs->control);
+ }
+ wait_ms (20);
+ for (ohci_l = ohci_hcd_list.next; ohci_l != &ohci_hcd_list; ohci_l = ohci_l->next) {
+ ohci = list_entry (ohci_l, ohci_t, ohci_hcd_list);
+ writel (ohci->hc_control = 0xBF, &ohci->regs->control);
}
down = 0;
break;
@@ -1521,42 +1767,56 @@
}
#endif
+/*-------------------------------------------------------------------------*/
+
#define PCI_CLASS_SERIAL_USB_OHCI 0x0C0310
-int ohci_hcd_init(void)
+int ohci_hcd_init (void)
{
int ret = -ENODEV;
- struct pci_dev *dev = NULL;
+ struct pci_dev * dev = NULL;
- while((dev = pci_find_class(PCI_CLASS_SERIAL_USB_OHCI, dev))) {
- if (start_ohci(dev) >= 0) ret = 0;
+ while ((dev = pci_find_class (PCI_CLASS_SERIAL_USB_OHCI, dev))) {
+ if (hc_start_ohci(dev) >= 0) ret = 0;
}
#ifdef CONFIG_APM
- apm_register_callback(&handle_apm_event);
+ apm_register_callback (&handle_apm_event);
#endif
-
+
+#ifdef CONFIG_PMAC_PBOOK
+ pmu_register_sleep_notifier (&ohci_sleep_notifier);
+#endif
return ret;
}
+/*-------------------------------------------------------------------------*/
+
#ifdef MODULE
-int init_module(void)
+int init_module (void)
{
- return ohci_hcd_init();
+ return ohci_hcd_init ();
}
-void cleanup_module(void)
+/*-------------------------------------------------------------------------*/
+
+void cleanup_module (void)
{
- struct ohci *ohci;
+ ohci_t * ohci;
-# ifdef CONFIG_APM
- apm_unregister_callback(&handle_apm_event);
-# endif
- while(!list_empty(&ohci_hcd_list)) {
- ohci = list_entry(ohci_hcd_list.next, struct ohci, ohci_hcd_list);
- list_del(&ohci->ohci_hcd_list);
- INIT_LIST_HEAD(&ohci->ohci_hcd_list);
- release_ohci(ohci);
+#ifdef CONFIG_APM
+ apm_unregister_callback (&handle_apm_event);
+#endif
+
+#ifdef CONFIG_PMAC_PBOOK
+ pmu_unregister_sleep_notifier (&ohci_sleep_notifier);
+#endif
+
+ while (!list_empty (&ohci_hcd_list)) {
+ ohci = list_entry (ohci_hcd_list.next, ohci_t, ohci_hcd_list);
+ list_del (&ohci->ohci_hcd_list);
+ INIT_LIST_HEAD (&ohci->ohci_hcd_list);
+ hc_release_ohci (ohci);
}
}
#endif //MODULE
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)