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

📄 usb-ohci-wmmx.c

📁 S3C2440ARM9开发板的USB驱动程序
💻 C
字号:
/* * linux/drivers/usb/usb-ohci-wmmx.c * BRIEF MODULE DESCRIPTION *	Intel Bulverde on-chip OHCI controller (non-pci) configuration. * * Copyright 2003 MontaVista Software Inc. * Author: MontaVista Software, Inc. *	   source@mvista.com * *  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  SOFTWARE  IS PROVIDED	  ``AS	IS'' AND   ANY	EXPRESS OR IMPLIED *  WARRANTIES,	  INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN *  NO	EVENT  SHALL   THE AUTHOR  BE	 LIABLE FOR ANY	  DIRECT, INDIRECT, *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT *  NOT LIMITED	  TO, PROCUREMENT OF  SUBSTITUTE GOODS	OR SERVICES; LOSS OF *  USE, DATA,	OR PROFITS; OR	BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON *  ANY THEORY OF LIABILITY, WHETHER IN	 CONTRACT, STRICT LIABILITY, OR TORT *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *  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. *//* *  linux/drivers/usb/usb-ohci-wmmx.c * *  The outline of this code was taken from Brad Parkers <brad@heeltoe.com> *  original OHCI driver modifications, and reworked into a cleaner form *  by Russell King <rmk@arm.linux.org.uk>. */#include <linux/module.h>#include <linux/init.h>#include <linux/sched.h>#include <linux/ioport.h>#include <linux/interrupt.h>#include <linux/slab.h>#include <linux/usb.h>#include <linux/pci.h>#include <asm/hardware.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/pci.h>#include "usb-ohci.h"#undef DEBUG#define PMM_NPS_MODE           1#define PMM_GLOBAL_MODE        2#define PMM_PERPORT_MODE       3#define PMM_MIXED_MODE         4int __devinithc_add_ohci(struct pci_dev *dev, int irq, void *membase, unsigned long flags,	    ohci_t **ohci, const char *name, const char *slot_name);extern void hc_remove_ohci(ohci_t *ohci);static ohci_t *wmmx_ohci;/* bogus pci_dev structure */static struct pci_dev bogus_pcidev;#ifdef CONFIG_DPM#include <linux/device.h>static int usb_suspend(struct device * dev, u32 state, u32 level);static int usb_resume(struct device * dev, u32 level);static int usb_scale(struct bus_op_point * op, u32 level);static struct device_driver usb_driver_ldm = {	name:      	"usb-ohci-wmmx",	devclass:  	NULL,	probe:     	NULL,	suspend:   	usb_suspend,	resume:    	usb_resume,	scale:	  	usb_scale,	remove:    	NULL,	constraints:	NULL,};static struct device usb_device_ldm = {	name:		"USB OHCI Host Controller",	bus_id:		"usb-ohci",	driver:		NULL,	power_state:	DPM_POWER_ON,};static void usb_ldm_register(void){	extern void pxasys_driver_register(struct device_driver *driver);	extern void pxasys_device_register(struct device *device);	pxasys_driver_register(&usb_driver_ldm);	pxasys_device_register(&usb_device_ldm);}static void usb_ldm_unregister(void){	extern void pxasys_driver_unregister(struct device_driver *driver);	extern void pxasys_device_unregister(struct device *device);	pxasys_driver_unregister(&usb_driver_ldm);	pxasys_device_unregister(&usb_device_ldm);}static int usb_resume(struct device * dev, u32 level){	extern int ohci_resume(ohci_t *);	int ret = 0;#if defined(DEBUG)	printk("+++: in usb_resume()\n");#endif	switch (level) {	case RESUME_POWER_ON:		/* enable the clock */		CKEN |= CKEN10_USBHOST;				ret = ohci_resume(wmmx_ohci);		break;	}	return ret;}static int usb_suspend(struct device * dev, u32 state, u32 level){	extern int ohci_suspend(ohci_t *, u32);	int ret;	#if defined(DEBUG)	printk("+++: in usb_suspend()\n");#endif	switch (level) {	case SUSPEND_POWER_DOWN:		ret = ohci_suspend(wmmx_ohci, level);		/* disable the clock */		CKEN &= ~CKEN10_USBHOST;		break;	}	return ret;}static int usb_scale(struct bus_op_point * op, u32 level){	/* linux-pm-TODO */	printk("+++: in usb_scale()\n");	return 0;}#endif /* CONFIG_DPM */static void __init board_usb_configure(void){#ifdef CONFIG_ARCH_MAINSTONE	if (machine_is_mainstone()) {	/* setup Port0's GPIO pin. */		set_GPIO_mode(GPIO_ALT_FN_1_IN | 88);  /* GPIO88 - USBHPWR0 */		set_GPIO_mode(GPIO_ALT_FN_2_OUT | 89); /* GPIO89 - USBHPEN0 */		/* Set the Power Control Polarity Low and Power Sense 		   Polarity Low to active low. Supply power to USB ports. */		UHCHR = (UHCHR | UHCHR_PCPL | UHCHR_PSPL) &			~(UHCHR_SSEP1 | UHCHR_SSEP2 | UHCHR_SSEP3 | UHCHR_SSE);	}#else#warning "Your board is not supported."#warning "Board-specific initialization may be required."#endif}static void __init wmmx_ohci_configure(void){	/* start bulverde's USB host clock. */	CKEN |= CKEN10_USBHOST;	UHCHR |= UHCHR_FHR;	udelay(11);	UHCHR &= ~UHCHR_FHR;	/* reset USB Bus Interface */	UHCHR |= UHCHR_FSBIR;	while (UHCHR & UHCHR_FSBIR);	board_usb_configure();#if defined(DEBUG)	printk("USB host VERSION %08x\n", UHCREV);	printk("USB Reset %08x\n", UHCHR);#endif}#define USB_OHCI_OP_PHYS_BASE ((unsigned int)&UHCREV)static int __init wmmx_ohci_select_pmm(int mode, int ports){	switch ( mode ) {	case PMM_NPS_MODE: /* this mode is only for development */		UHCRHDA |= RH_A_NPS;		break; 	case PMM_GLOBAL_MODE:		UHCRHDA &= ~(RH_A_NPS | RH_A_PSM);		break;	case PMM_PERPORT_MODE:		UHCRHDA &= ~RH_A_NPS | RH_A_PSM;		/* Should I use one port*/		{			int i;			for (i = 0; i < ports; i++)				UHCRHDB |= (unsigned int)(1u << (i + 17));		}		break;	case PMM_MIXED_MODE:		printk(KERN_INFO"Currently, do not support this mode %d\n", mode);		break;	default:		printk(KERN_INFO"Invalid mode %d\n", mode );		return -1;	}	return 0;}static int __init wmmx_ohci_init(void){	int ret;	void *ohci_addr;	wmmx_ohci_configure();	ohci_addr = ioremap(UHC_BASE_PHYS, 32*1024);		/*	 * Fill in some fields of the bogus pci_dev.	 */	memset(&bogus_pcidev, 0, sizeof(struct pci_dev));	strcpy(bogus_pcidev.name, "BULVERDE OHCI");	strcpy(bogus_pcidev.slot_name, "builtin");	bogus_pcidev.resource[0].name = "OHCI Operational Registers";	/*	 * Initialise the generic OHCI driver.	 */	ret = hc_add_ohci(&bogus_pcidev, IRQ_USBH1, ohci_addr, 0, &wmmx_ohci,			  "usb-ohci", "wmmx");	/* Select Power Management Mode */	wmmx_ohci_select_pmm(PMM_GLOBAL_MODE, 0);#ifdef CONFIG_DPM	usb_ldm_register();#endif	return ret;}static void __exit wmmx_ohci_exit(void){#ifdef CONFIG_DPM	usb_ldm_unregister();#endif		/* hc_remove_ohci() will release OHCI register VM mapping */	hc_remove_ohci(wmmx_ohci);	/*	 * Stop the USB clock.	 */	CKEN &= ~CKEN10_USBHOST;}module_init(wmmx_ohci_init);module_exit(wmmx_ohci_exit);

⌨️ 快捷键说明

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