⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ehci-hcd.c

📁 linux2.4.20下的针对三星公司的s3c2410的usb模块驱动代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2000-2002 by David Brownell *  * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#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>#ifdef CONFIG_USB_DEBUG	#define DEBUG#else	#undef DEBUG#endif#include <linux/usb.h>#include "../hcd.h"#include <asm/byteorder.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/unaligned.h>//#undef KERN_DEBUG//#define KERN_DEBUG ""/*-------------------------------------------------------------------------*//* * EHCI hc_driver implementation ... experimental, incomplete. * Based on the final 1.0 register interface specification. * * There are lots of things to help out with here ... notably * everything "periodic", and of course testing with all sorts * of usb 2.0 devices and configurations. * * USB 2.0 shows up in upcoming www.pcmcia.org technology. * First was PCMCIA, like ISA; then CardBus, which is PCI. * Next comes "CardBay", using USB 2.0 signals. * * Contains additional contributions by: *	Brad Hards *	Rory Bolt *	... * * HISTORY: * * 2002-05-07	Some error path cleanups to report better errors; wmb(); *	use non-CVS version id; better iso bandwidth claim. * 2002-04-19	Control/bulk/interrupt submit no longer uses giveback() on *	errors in submit path.  Bugfixes to interrupt scheduling/processing. * 2002-03-05	Initial high-speed ISO support; reduce ITD memory; shift *	more checking to generic hcd framework (db).  Make it work with *	Philips EHCI; reduce PCI traffic; shorten IRQ path (Rory Bolt). * 2002-01-14	Minor cleanup; version synch. * 2002-01-08	Fix roothub handoff of FS/LS to companion controllers. * 2002-01-04	Control/Bulk queuing behaves. * * 2001-12-12	Initial patch version for Linux 2.5.1 kernel. * 2001-June	Works with usb-storage and NEC EHCI on 2.4 */#define DRIVER_VERSION "2002-May-07"#define DRIVER_AUTHOR "David Brownell"#define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"// #define EHCI_VERBOSE_DEBUG// #define have_split_iso/* magic numbers that can affect system performance */#define	EHCI_TUNE_CERR		3	/* 0-3 qtd retries; 0 == don't stop */#define	EHCI_TUNE_RL_HS		0	/* nak throttle; see 4.9 */#define	EHCI_TUNE_RL_TT		0#define	EHCI_TUNE_MULT_HS	1	/* 1-3 transactions/uframe; 4.10.3 */#define	EHCI_TUNE_MULT_TT	1/* Initial IRQ latency:  lower than default */static int log2_irq_thresh = 0;		// 0 to 6MODULE_PARM (log2_irq_thresh, "i");MODULE_PARM_DESC (log2_irq_thresh, "log2 IRQ latency, 1-64 microframes");#define	INTR_MASK (STS_IAA | STS_FATAL | STS_ERR | STS_INT)/*-------------------------------------------------------------------------*/#include "ehci.h"#include "ehci-dbg.c"/*-------------------------------------------------------------------------*//* * hc states include: unknown, halted, ready, running * transitional states are messy just now * trying to avoid "running" unless urbs are active * a "ready" hc can be finishing prefetched work *//* halt a non-running controller */static void ehci_reset (struct ehci_hcd *ehci){	u32	command = readl (&ehci->regs->command);	command |= CMD_RESET;	dbg_cmd (ehci, "reset", command);	writel (command, &ehci->regs->command);	while (readl (&ehci->regs->command) & CMD_RESET)		continue;	ehci->hcd.state = USB_STATE_HALT;}/* idle the controller (from running) */static void ehci_ready (struct ehci_hcd *ehci){	u32	command;#ifdef DEBUG	if (!HCD_IS_RUNNING (ehci->hcd.state))		BUG ();#endif	while (!(readl (&ehci->regs->status) & (STS_ASS | STS_PSS)))		udelay (100);	command = readl (&ehci->regs->command);	command &= ~(CMD_ASE | CMD_IAAD | CMD_PSE);	writel (command, &ehci->regs->command);	// hardware can take 16 microframes to turn off ...	ehci->hcd.state = USB_STATE_READY;}/*-------------------------------------------------------------------------*/#include "ehci-hub.c"#include "ehci-mem.c"#include "ehci-q.c"#include "ehci-sched.c"/*-------------------------------------------------------------------------*/static void ehci_tasklet (unsigned long param);/* called by khubd or root hub init threads */static int ehci_start (struct usb_hcd *hcd){	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);	u32			temp;	struct usb_device	*udev;	int			retval;	u32			hcc_params;	u8                      tempbyte;	// FIXME:  given EHCI 0.96 or later, and a controller with	// the USBLEGSUP/USBLEGCTLSTS extended capability, make sure	// the BIOS doesn't still own this controller.	spin_lock_init (&ehci->lock);	ehci->caps = (struct ehci_caps *) hcd->regs;	ehci->regs = (struct ehci_regs *) (hcd->regs + ehci->caps->length);	dbg_hcs_params (ehci, "ehci_start");	dbg_hcc_params (ehci, "ehci_start");	/* cache this readonly data; minimize PCI reads */	ehci->hcs_params = readl (&ehci->caps->hcs_params);	/*	 * hw default: 1K periodic list heads, one per frame.	 * periodic_size can shrink by USBCMD update if hcc_params allows.	 */	ehci->periodic_size = DEFAULT_I_TDPS;	if ((retval = ehci_mem_init (ehci, SLAB_KERNEL)) < 0)		return retval;	hcc_params = readl (&ehci->caps->hcc_params);	/* controllers may cache some of the periodic schedule ... */	if (HCC_ISOC_CACHE (hcc_params)) 	// full frame cache		ehci->i_thresh = 8;	else					// N microframes cached		ehci->i_thresh = 2 + HCC_ISOC_THRES (hcc_params);	ehci->async = 0;	ehci->reclaim = 0;	ehci->next_uframe = -1;	/* controller state:  unknown --> reset */	/* EHCI spec section 4.1 */	// FIXME require STS_HALT before reset...	ehci_reset (ehci);	writel (INTR_MASK, &ehci->regs->intr_enable);	writel (ehci->periodic_dma, &ehci->regs->frame_list);	/*	 * hcc_params controls whether ehci->regs->segment must (!!!)	 * be used; it constrains QH/ITD/SITD and QTD locations.	 * pci_pool consistent memory always uses segment zero.	 */	if (HCC_64BIT_ADDR (hcc_params)) {		writel (0, &ehci->regs->segment);		/*		 * FIXME Enlarge pci_set_dma_mask() when possible.  The DMA		 * mapping API spec now says that'll affect only single shot		 * mappings, and the pci_pool data will stay safe in seg 0.		 * That's what we want:  no extra copies for USB transfers.		 */		info ("restricting 64bit DMA mappings to segment 0 ...");	}	/* clear interrupt enables, set irq latency */	temp = readl (&ehci->regs->command) & 0xff;	if (log2_irq_thresh < 0 || log2_irq_thresh > 6)	    log2_irq_thresh = 0;	temp |= 1 << (16 + log2_irq_thresh);	// keeping default periodic framelist size	temp &= ~(CMD_IAAD | CMD_ASE | CMD_PSE),	// Philips, Intel, and maybe others need CMD_RUN before the	// root hub will detect new devices (why?); NEC doesn't	temp |= CMD_RUN;	writel (temp, &ehci->regs->command);	dbg_cmd (ehci, "init", temp);	/* set async sleep time = 10 us ... ? */	ehci->tasklet.func = ehci_tasklet;	ehci->tasklet.data = (unsigned long) ehci;	/* wire up the root hub */	hcd->bus->root_hub = udev = usb_alloc_dev (NULL, hcd->bus);	if (!udev) {done2:		ehci_mem_cleanup (ehci);		return -ENOMEM;	}	/*	 * Start, enabling full USB 2.0 functionality ... usb 1.1 devices	 * are explicitly handed to companion controller(s), so no TT is	 * involved with the root hub.	 */	ehci->hcd.state = USB_STATE_READY;	writel (FLAG_CF, &ehci->regs->configured_flag);	readl (&ehci->regs->command);	/* unblock posted write */        /* PCI Serial Bus Release Number is at 0x60 offset */	pci_read_config_byte (hcd->pdev, 0x60, &tempbyte);	temp = readw (&ehci->caps->hci_version);	info ("USB %x.%x support enabled, EHCI rev %x.%2x",	      ((tempbyte & 0xf0)>>4),	      (tempbyte & 0x0f),	       temp >> 8,	       temp & 0xff);	/*	 * From here on, khubd concurrently accesses the root	 * hub; drivers will be talking to enumerated devices.	 *	 * Before this point the HC was idle/ready.  After, khubd	 * and device drivers may start it running.	 */	usb_connect (udev);	udev->speed = USB_SPEED_HIGH;	if (usb_new_device (udev) != 0) {		if (hcd->state == USB_STATE_RUNNING)			ehci_ready (ehci);		while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))			udelay (100);		ehci_reset (ehci);		// usb_disconnect (udev); 		hcd->bus->root_hub = 0;		usb_free_dev (udev); 		retval = -ENODEV;		goto done2;	}	return 0;}/* always called by thread; normally rmmod */static void ehci_stop (struct usb_hcd *hcd){	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);	dbg ("%s: stop", hcd->bus_name);	if (hcd->state == USB_STATE_RUNNING)		ehci_ready (ehci);	while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))		udelay (100);	ehci_reset (ehci);	// root hub is shut down separately (first, when possible)	scan_async (ehci);	if (ehci->next_uframe != -1)		scan_periodic (ehci);	ehci_mem_cleanup (ehci);	dbg_status (ehci, "ehci_stop completed", readl (&ehci->regs->status));}static int ehci_get_frame (struct usb_hcd *hcd){	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);	return (readl (&ehci->regs->frame_index) >> 3) % ehci->periodic_size;}/*-------------------------------------------------------------------------*/#ifdef	CONFIG_PM/* suspend/resume, section 4.3 */static int ehci_suspend (struct usb_hcd *hcd, u32 state){	struct ehci_hcd		*ehci = hcd_to_ehci (hcd);	int			ports;	int			i;	dbg ("%s: suspend to %d", hcd->bus_name, state);	ports = HCS_N_PORTS (ehci->hcs_params);	// FIXME:  This assumes what's probably a D3 level suspend...	// FIXME:  usb wakeup events on this bus should resume the machine.	// pci config register PORTWAKECAP controls which ports can do it;	// bios may have initted the register...	/* suspend each port, then stop the hc */	for (i = 0; i < ports; i++) {		int	temp = readl (&ehci->regs->port_status [i]);		if ((temp & PORT_PE) == 0				|| (temp & PORT_OWNER) != 0)			continue;dbg ("%s: suspend port %d", hcd->bus_name, i);		temp |= PORT_SUSPEND;		writel (temp, &ehci->regs->port_status [i]);	}	if (hcd->state == USB_STATE_RUNNING)		ehci_ready (ehci);	while (readl (&ehci->regs->status) & (STS_ASS | STS_PSS))		udelay (100);	writel (readl (&ehci->regs->command) & ~CMD_RUN, &ehci->regs->command);// save pci FLADJ value	/* who tells PCI to reduce power consumption? */	return 0;}static int ehci_resume (struct usb_hcd *hcd){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -