📄 usb-ohci.c
字号:
/* * URB OHCI HCD (Host Controller Driver) for USB. * * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at> * (C) Copyright 2000-2001 David Brownell <dbrownell@users.sourceforge.net> * * [ Initialisation is based on Linus' ] * [ uhci code and gregs ohci fragments ] * [ (C) Copyright 1999 Linus Torvalds ] * [ (C) Copyright 1999 Gregory P. Smith] * * * History: * * 2001/09/19 USB_ZERO_PACKET support (Jean Tourrilhes) * 2001/07/17 power management and pmac cleanup (Benjamin Herrenschmidt) * 2001/03/24 td/ed hashing to remove bus_to_virt (Steve Longerbeam); pci_map_single (db) * 2001/03/21 td and dev/ed allocation uses new pci_pool API (db) * 2001/03/07 hcca allocation uses pci_alloc_consistent (Steve Longerbeam) * * 2000/09/26 fixed races in removing the private portion of the urb * 2000/09/07 disable bulk and control lists when unlinking the last * endpoint descriptor in order to avoid unrecoverable errors on * the Lucent chips. (rwc@sgi) * 2000/08/29 use bandwidth claiming hooks (thanks Randy!), fix some * urb unlink probs, indentation fixes * 2000/08/11 various oops fixes mostly affecting iso and cleanup from * device unplugs. * 2000/06/28 use PCI hotplug framework, for better power management * and for Cardbus support (David Brownell) * 2000/earlier: fixes for NEC/Lucent chips; suspend/resume handling * when the controller loses power; handle UE; cleanup; ... * * 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. * v4.0 1999/08/18 * v3.0 1999/06/25 * v2.1 1999/05/09 code clean up * v2.0 1999/05/04 * v1.0 1999/04/27 initial release */ #ifndef __KERNEL__ #define __KERNEL__#endif#ifndef MODULE #define MODULE#endif#include <linux/config.h>#include <linux/module.h>#include <linux/pci.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/ioport.h>#include <linux/sched.h>#include <linux/slab.h>#include <linux/smp_lock.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/timer.h>#include <linux/list.h>#include <linux/interrupt.h> /* for in_interrupt() */#undef DEBUG#include <linux/usb.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/unaligned.h>#define OHCI_USE_NPS // force NoPowerSwitching mode// #define OHCI_VERBOSE_DEBUG /* not always helpful */#include "usb-ohci.h"#ifdef CONFIG_ARCH_S3C2410#ifndef CONFIG_MAX_ROOT_PORTS#define CONFIG_MAX_ROOT_PORTS 1#endif#define S3C2410_MAX_ROOT_PORTS CONFIG_MAX_ROOT_PORTS#define DO_TIMEOUTS 1#endif/* * Version Information */#define DRIVER_VERSION "v5.3"#define DRIVER_AUTHOR "Roman Weissgaerber <weissg@vienna.at>, David Brownell"#define DRIVER_DESC "USB OHCI Host Controller Driver"/* For initializing controller (mask in an HCFS mode too) */#define OHCI_CONTROL_INIT \ (OHCI_CTRL_CBSR & 0x3) | OHCI_CTRL_IE | OHCI_CTRL_PLE#define OHCI_UNLINK_TIMEOUT (HZ / 10)static LIST_HEAD (ohci_hcd_list);static spinlock_t usb_ed_lock = SPIN_LOCK_UNLOCKED;/*-------------------------------------------------------------------------*//* AMD-756 (D2 rev) reports corrupt register contents in some cases. * The erratum (#4) description is incorrect. AMD's workaround waits * till some bits (mostly reserved) are clear; ok for all revs. */#define read_roothub(hc, register, mask) ({ \ u32 temp = readl (&hc->regs->roothub.register); \ if (hc->flags & OHCI_QUIRK_AMD756) \ while (temp & mask) \ temp = readl (&hc->regs->roothub.register); \ temp; })// 读根集线器描述寄存器Astatic u32 roothub_a (struct ohci *hc) { return read_roothub (hc, a, 0xfc0fe000); }// 读根集线器描述寄存器Bstatic inline u32 roothub_b (struct ohci *hc) { return readl (&hc->regs->roothub.b); }// 读根集线器状态寄存器 static inline u32 roothub_status (struct ohci *hc) { return readl (&hc->regs->roothub.status); }// 读根集线器端口状态寄存器 static u32 roothub_portstatus (struct ohci *hc, int i) { return read_roothub (hc, portstatus [i], 0xffe0fce0); }/*-------------------------------------------------------------------------* * URB support functions *-------------------------------------------------------------------------*/ /* free HCD-private data associated with this URB *//*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void urb_free_priv (struct ohci *hc, urb_priv_t * urb_priv){ int i; int last = urb_priv->length - 1; int len; int dir; struct td *td; if (last >= 0) { /* ISOC, BULK, INTR data buffer starts at td 0 * CTRL setup starts at td 0 */ td = urb_priv->td [0]; len = td->urb->transfer_buffer_length, dir = usb_pipeout (td->urb->pipe) ? PCI_DMA_TODEVICE : PCI_DMA_FROMDEVICE; /* unmap CTRL URB setup */ if (usb_pipecontrol (td->urb->pipe)) { pci_unmap_single (hc->ohci_dev, td->data_dma, 8, PCI_DMA_TODEVICE); /* CTRL data buffer starts at td 1 if len > 0 */ if (len && last > 0) td = urb_priv->td [1]; } /* unmap data buffer */ if (len && td->data_dma) pci_unmap_single (hc->ohci_dev, td->data_dma, len, dir); for (i = 0; i <= last; i++) { td = urb_priv->td [i]; if (td) td_free (hc, td); } } kfree (urb_priv);} /*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void urb_rm_priv_locked (urb_t * urb) { urb_priv_t * urb_priv = urb->hcpriv; if (urb_priv) { urb->hcpriv = NULL;#ifdef DO_TIMEOUTS if (urb->timeout) { list_del (&urb->urb_list); urb->timeout -= jiffies; }#endif /* Release int/iso bandwidth */ if (urb->bandwidth) { switch (usb_pipetype(urb->pipe)) { case PIPE_INTERRUPT: usb_release_bandwidth (urb->dev, urb, 0); break; case PIPE_ISOCHRONOUS: usb_release_bandwidth (urb->dev, urb, 1); break; default: break; } } urb_free_priv ((struct ohci *)urb->dev->bus->hcpriv, urb_priv); usb_dec_dev_use (urb->dev); urb->dev = NULL; }}/*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void urb_rm_priv (urb_t * urb){ unsigned long flags; spin_lock_irqsave (&usb_ed_lock, flags); urb_rm_priv_locked (urb); spin_unlock_irqrestore (&usb_ed_lock, flags);}/*-------------------------------------------------------------------------*/ #ifdef DEBUGstatic int sohci_get_current_frame_number (struct usb_device * dev);/* debug| print the main components of an URB * small: 0) header + data packets 1) just header */ /*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void urb_print (urb_t * urb, char * str, int small){ unsigned int pipe= urb->pipe; if (!urb->dev || !urb->dev->bus) { // dbg("%s URB: no dev", str); return; } #ifndef OHCI_VERBOSE_DEBUG if (urb->status != 0)#endif printk("%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);#ifdef OHCI_VERBOSE_DEBUG if (!small) { int i, len; if (usb_pipecontrol (pipe)) { printk ( __FILE__ ": 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 ( __FILE__ ": 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); } } #endif}/* just for debugging; prints non-empty branches of the int ed tree inclusive iso eds*//*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void ep_print_int_eds (ohci_t * ohci, char * str) { int i, j; __u32 * ed_p; for (i= 0; i < 32; i++) { j = 5; ed_p = &(ohci->hcca->int_table [i]); if (*ed_p == 0) continue; printk ( __FILE__ ": %s branch int %2d(%2x):", str, i, i); while (*ed_p != 0 && j--) { ed_t *ed = dma_to_ed (ohci, le32_to_cpup(ed_p)); printk (" ed: %4x;", ed->hwINFO); ed_p = &ed->hwNextED; } printk ("\n"); }}/*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void ohci_dump_intr_mask (char *label, __u32 mask){ printk ("%s: 0x%08x%s%s%s%s%s%s%s%s%s\n", label, mask, (mask & OHCI_INTR_MIE) ? " MIE" : "", (mask & OHCI_INTR_OC) ? " OC" : "", (mask & OHCI_INTR_RHSC) ? " RHSC" : "", (mask & OHCI_INTR_FNO) ? " FNO" : "", (mask & OHCI_INTR_UE) ? " UE" : "", (mask & OHCI_INTR_RD) ? " RD" : "", (mask & OHCI_INTR_SF) ? " SF" : "", (mask & OHCI_INTR_WDH) ? " WDH" : "", (mask & OHCI_INTR_SO) ? " SO" : "" );}/*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void maybe_print_eds (char *label, __u32 value){// if (value) printk ("%s %08x\n", label, value);}/*********************************************************************************************************** Function name: ** Descriptions: ** Input:** Output :** Created by:** Created Date:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -