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

📄 usb.c

📁 Linux Kernel 2.6.9 for OMAP1710
💻 C
字号:
/* * arch/arm/mach-omap2/usb.c -- platform level USB initialization * * Copyright (C) 2004 Texas Instruments, Inc. * * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#undef	DEBUG#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/device.h>#include <linux/usb_otg.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/system.h>#include <asm/hardware.h>#include <asm/mach-types.h>#include <asm/arch/mux.h>#include <asm/arch/irqs.h>#include <asm/arch/usb.h>/* These routines should handle the standard chip-specific modes * for usb0/1/2 ports, covering basic mux and transceiver setup. * Call omap_usb_init() once, from INIT_MACHINE(). * * Some board-*.c files will need to set up additional mux options, * like for suspend handling, vbus sensing, GPIOs, and the D+ pullup. *//* TESTED ON: *  - 2420 H4 with Mini-A/B on USB0 *//*-------------------------------------------------------------------------*/#ifdef	CONFIG_ARCH_OMAP_OTGstatic struct otg_transceiver *xceiv;/** * otg_get_transceiver - find the (single) OTG transceiver driver * * Returns the transceiver driver, after getting a refcount to it; or * null if there is no such transceiver.  The caller is responsible for * releasing that count. */struct otg_transceiver *otg_get_transceiver(void){	if (xceiv)		get_device(xceiv->dev);	return xceiv;}EXPORT_SYMBOL(otg_get_transceiver);int otg_set_transceiver(struct otg_transceiver *x){	if (xceiv && x)		return -EBUSY;	xceiv = x;	return 0;}EXPORT_SYMBOL(otg_set_transceiver);#endif/*-------------------------------------------------------------------------*/static u32 __init omap_usb0_init(unsigned nwires, unsigned is_device){	u32	syscon1 = 0;	if (nwires == 0) {		CONTROL_DEVCONF_REG |= USBSTANDBYCTRLE;		return 0;	}	/*	 * VP and VM are needed for all active usb0 configurations.	 * USB0_VP and USB0_VM are always set on 1510, there's no muxing	 * available for them.	 */	if (nwires >= 2 && !cpu_is_omap1510()) {		omap2_cfg_reg(J19_2420_USB0_VP);		omap2_cfg_reg(K20_2420_USB0_VM);	}	omap2_cfg_reg(K18_2420_USB0_DAT);	omap2_cfg_reg(K19_2420_USB0_TXEN);	omap2_cfg_reg(J14_2420_USB0_SE0);	if (nwires != 3)		omap2_cfg_reg(J18_2420_USB0_RCV);	switch (nwires) {	case 3:		syscon1 = 2;		CONTROL_DEVCONF_REG |= USBT0WRMODEI(BIDIR);		break;	case 4:		syscon1 = 1;		CONTROL_DEVCONF_REG |= USBT0WRMODEI(BIDIR);		break;	case 6:		syscon1 = 3;		CONTROL_DEVCONF_REG |= USBT0WRMODEI(UNIDIR);		break;	default:		printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",			0, nwires);	}	return syscon1 << 16;}#if 0/*	Code not used for 2420 on H4, but not cleaned out to allow adding	support for these ports on future OMAP2 boards. Also will help	merging mach-omap and mach-omap2 directories if required in future.*/static u32 __init omap_usb1_init(unsigned nwires){	u32	syscon1 = 0;	if (nwires != 6)		USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB1_UNI_R;	if (nwires == 0)		return 0;	/* external transceiver */	omap_cfg_reg(USB1_TXD);	omap_cfg_reg(USB1_TXEN);	if (cpu_is_omap1510()) {		omap_cfg_reg(USB1_SEO);		omap_cfg_reg(USB1_SPEED);		// SUSP	} else if (cpu_is_omap16xx()) {		omap_cfg_reg(W13_1610_USB1_SE0);		omap_cfg_reg(R13_1610_USB1_SPEED);		// SUSP	} else {		pr_debug("usb unrecognized\n");	}	if (nwires != 3)		omap_cfg_reg(USB1_RCV);	switch (nwires) {	case 3:		syscon1 = 2;		break;	case 4:		syscon1 = 1;		break;	case 6:		syscon1 = 3;		omap_cfg_reg(USB1_VP);		omap_cfg_reg(USB1_VM);		USB_TRANSCEIVER_CTRL_REG |= CONF_USB1_UNI_R;		break;	default:		printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",			1, nwires);	}	return syscon1 << 20;}static u32 __init omap_usb2_init(unsigned nwires, unsigned alt_pingroup){	u32	syscon1 = 0;	if (alt_pingroup)		return 0;	if (nwires != 6)		USB_TRANSCEIVER_CTRL_REG &= ~CONF_USB2_UNI_R;	if (nwires == 0)		return 0;	/* external transceiver */	if (cpu_is_omap1510()) {		omap_cfg_reg(USB2_TXD);		omap_cfg_reg(USB2_TXEN);		omap_cfg_reg(USB2_SEO);		if (nwires != 3)			omap_cfg_reg(USB2_RCV);	} else if (cpu_is_omap16xx()) {		omap_cfg_reg(V6_USB2_TXD);		omap_cfg_reg(W9_USB2_TXEN);		omap_cfg_reg(W5_USB2_SE0);		if (nwires != 3)			omap_cfg_reg(Y5_USB2_RCV);	} else {		pr_debug("usb unrecognized\n");	}	// omap_cfg_reg(USB2_SUSP);	// FIXME omap_cfg_reg(USB2_SPEED);	switch (nwires) {	case 3:		syscon1 = 2;		break;	case 4:		syscon1 = 1;		break;	case 6:		syscon1 = 3;		if (cpu_is_omap1510()) {			omap_cfg_reg(USB2_VP);			omap_cfg_reg(USB2_VM);		} else {			omap_cfg_reg(AA9_USB2_VP);			omap_cfg_reg(R9_USB2_VM);		}		USB_TRANSCEIVER_CTRL_REG |= CONF_USB2_UNI_R;		break;	default:		printk(KERN_ERR "illegal usb%d %d-wire transceiver\n",			2, nwires);	}	return syscon1 << 24;}#endif/*-------------------------------------------------------------------------*/#if	defined(CONFIG_USB_GADGET_OMAP) || \	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) || \	(defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG))static void usb_release(struct device *dev){	/* normally not freed */}#endif#ifdef	CONFIG_USB_GADGET_OMAPstatic struct resource udc_resources[] = {	/* order is significant! */	{		/* registers */		.start		= IO_ADDRESS(UDC_BASE),		.end		= IO_ADDRESS(UDC_BASE + 0xff),		.flags		= IORESOURCE_MEM,	}, {		/* general IRQ */		.start		= INT_USB_IRQ_GEN, //INT_IRQ_75		.flags		= IORESOURCE_IRQ,	}, {		/* PIO IRQ */		.start		= INT_USB_IRQ_NISO, //IINT_IRQ_76		.flags		= IORESOURCE_IRQ,	}, {		/* SOF IRQ */		.start		= INT_USB_IRQ_ISO, //INT_IRQ_77		.flags		= IORESOURCE_IRQ,	},};static u64 udc_dmamask = ~(u32)0;static struct platform_device udc_device = {	.name		= "omap_udc",	.id		= -1,	.dev = {		.release		= usb_release,		.dma_mask		= &udc_dmamask,		.coherent_dma_mask	= 0xffffffff,	},	.num_resources	= ARRAY_SIZE(udc_resources),	.resource	= udc_resources,};#endif#if	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)/* The dmamask must be set for OHCI to work */static u64 ohci_dmamask = ~(u32)0;static struct resource ohci_resources[] = {	{		.start	= IO_ADDRESS(OMAP_OHCI_BASE),		.end	= IO_ADDRESS(OMAP_OHCI_BASE + 0x1ff),		.flags	= IORESOURCE_MEM,	}, {		/* general IRQ */		.start	= INT_USB_IRQ_HGEN, //INT_IRQ_78		.flags	= IORESOURCE_IRQ,	}, {		/* SOF IRQ */  // Not actually used currently		.start	= INT_USB_IRQ_HSOF, //INT_IRQ_79		.flags	= IORESOURCE_IRQ,	},};static struct platform_device ohci_device = {	.name			= "ohci",	.id			= -1,	.dev = {		.release		= usb_release,		.dma_mask		= &ohci_dmamask,		.coherent_dma_mask	= 0xffffffff,	},	.num_resources	= ARRAY_SIZE(ohci_resources),	.resource		= ohci_resources,};#endif#if	defined(CONFIG_USB_OTG) && defined(CONFIG_ARCH_OMAP_OTG)static struct resource otg_resources[] = {	/* order is significant! */	{		.start		= IO_ADDRESS(OTG_BASE),		.end		= IO_ADDRESS(OTG_BASE + 0xff),		.flags		= IORESOURCE_MEM,	}, {		.start		= INT_USB_IRQ_OTG, //IH2_BASE + 8,		.flags		= IORESOURCE_IRQ,	},};static struct platform_device otg_device = {	.name		= "omap_otg",	.id		= -1,	.dev = {		.release		= usb_release,	},	.num_resources	= ARRAY_SIZE(otg_resources),	.resource	= otg_resources,};#endif/*-------------------------------------------------------------------------*/// FIXME correct answer depends on hmc_mode,// as does any nonzero value for config->otg port number#define	is_usb0_device(config)	1/*-------------------------------------------------------------------------*/#ifdef	CONFIG_ARCH_OMAP_OTGvoid __initomap_otg_init(struct omap_usb_config *config){	u32		syscon = OTG_SYSCON_1_REG & 0xffff;	int		status;	int		alt_pingroup = 0;	/* NOTE:  no bus or clock setup (yet?) */	syscon = OTG_SYSCON_1_REG & 0xffff;	if (!(syscon & OTG_RESET_DONE))		pr_debug("USB resets not complete?\n");	// OTG_IRQ_EN_REG = 0;	/* pin muxing and transceiver pinouts */	if (config->pins[0] > 2)	/* alt pingroup 2 */		alt_pingroup = 1;	syscon |= omap_usb0_init(config->pins[0], is_usb0_device(config));//	Not used on 2420 H4 ...//	syscon |= omap_usb1_init(config->pins[1]);//	syscon |= omap_usb2_init(config->pins[2], alt_pingroup);	pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);	OTG_SYSCON_1_REG = syscon;	syscon = config->hmc_mode;	syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;	if (config->otg || config->register_host)		syscon |= UHOST_EN;#ifdef	CONFIG_USB_OTG	if (config->otg)		syscon |= OTG_EN;#endif	pr_debug("OTG_SYSCON_2_REG = %08x\n", syscon);	OTG_SYSCON_2_REG = syscon;	printk("USB: hmc %d", config->hmc_mode);	if (!alt_pingroup)		printk(", usb2 alt %d wires", config->pins[2]);	else if (config->pins[0])		printk(", usb0 %d wires%s", config->pins[0],			is_usb0_device(config) ? " (dev)" : "");	if (config->pins[1])		printk(", usb1 %d wires", config->pins[1]);	if (!alt_pingroup && config->pins[2])		printk(", usb2 %d wires", config->pins[2]);	if (config->otg)		printk(", Mini-AB on usb%d", config->otg - 1);	printk("\n");	/* don't clock unused USB controllers  */	syscon = OTG_SYSCON_1_REG;	syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;#ifdef	CONFIG_USB_GADGET_OMAP	if (config->otg || config->register_dev) {		syscon &= ~DEV_IDLE_EN;		udc_device.dev.platform_data = config;		printk(KERN_DEBUG "platform_device_register(&udc_device);\n");		status = platform_device_register(&udc_device);		if (status)			pr_debug("can't register UDC device, %d\n", status);	}#endif#if	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)	if (config->otg || config->register_host) {		syscon &= ~HST_IDLE_EN;		ohci_device.dev.platform_data = config;		printk(KERN_DEBUG "platform_device_register(&ohci_device);\n");		status = platform_device_register(&ohci_device);		if (status)			pr_debug("can't register OHCI device, %d\n", status);	}#endif#ifdef	CONFIG_USB_OTG	if (config->otg) {		syscon &= ~OTG_IDLE_EN;#ifndef CONFIG_ARCH_OMAP24XX		if (cpu_is_omap730())			otg_resources[1].start = INT_730_USB_OTG;#endif		printk(KERN_DEBUG "platform_device_register(&otg_device);\n");		status = platform_device_register(&otg_device);		// ...	}#endif	pr_debug("OTG_SYSCON_1_REG = %08x\n", syscon);	OTG_SYSCON_1_REG = syscon;	status = 0;}#elsestatic inline void omap_otg_init(struct omap_usb_config *config) {}#endif/*-------------------------------------------------------------------------*/static struct omap_usb_config h4_usb_config __initdata = {	/* usb0 has a Mini-AB port and external isp1301 transceiver */	.otg		= 1,#ifdef	CONFIG_USB_GADGET_OMAP	.hmc_mode	= 0x0,	// 0:dev/otg 1:disabled 2:disabled#elif	defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)	.hmc_mode	= 0x1,	// 0:host|otg 1:disabled 2:disabled#endif	.pins[0]	= 3,};static int __initomap_usb_init(void){	omap_otg_init(&h4_usb_config);	return 0;}subsys_initcall(omap_usb_init);

⌨️ 快捷键说明

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