omap_nor.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 196 行

C
196
字号
/* * Flash memory support for various TI OMAP boards * * Copyright (C) 2001-2002 MontaVista Software Inc. * Copyright (C) 2003-2004 Texas Instruments * Copyright (C) 2004 Nokia Corporation  * *	Assembled using driver code copyright the companies above *	and written by David Brownell, Jian Zhang <jzhang@ti.com>, * 	Tony Lindgren <tony@atomide.com> and others. * * 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. */#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/ioport.h>#include <linux/mtd/mtd.h>#include <linux/mtd/map.h>#include <linux/mtd/partitions.h>#include <asm/io.h>#include <asm/hardware.h>#include <asm/mach-types.h>#include <asm/arch/tc.h>#define	MODULE_NAME	"omap_nor"#ifdef CONFIG_MTD_PARTITIONS/* only bootable devices have a default partitioning */static struct mtd_partition boot_partitions[] = {	/* bootloader (U-Boot, etc) in first sector */	{	      .name		= "bootloader",	      .offset		= 0,	      .size		= SZ_128K,	      .mask_flags	= MTD_WRITEABLE, /* force read-only */	},	/* bootloader params in the next sector */	{	      .name		= "params",	      .offset		= MTDPART_OFS_APPEND,	      .size		= SZ_128K,	      .mask_flags	= 0, 	},	/* kernel */	{	      .name		= "kernel",	      .offset		= MTDPART_OFS_APPEND,	      .size		= SZ_2M,	      .mask_flags	= 0	},#ifdef	CONFIG_MACH_OMAP_INNOVATOR	/* rest of flash1 is a file system */	{	      .name		= "rootfs",	      .offset		= MTDPART_OFS_APPEND,	      .size		= SZ_16M - SZ_2M - 2 * SZ_128K,	      .mask_flags	= 0	},#endif	/* file system */	{	      .name		= "filesystem",	      .offset		= MTDPART_OFS_APPEND,	      .size		= MTDPART_SIZ_FULL,	      .mask_flags	= 0	}};static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };static struct mtd_partition *parts;#endifstatic void omap_set_vpp(struct map_info *map, int enable){	static int	count;	if (enable) {		if (count++ == 0)			OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP;	} else {		if (--count == 0)			OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP;	}}static struct map_info omap_map = {	.bankwidth	= 2,	.set_vpp	= omap_set_vpp,};static struct mtd_info *mymtd;static int __init probe_nor(char *name, u32 phys, u32 size, int bootable){	int	tmp = -EBUSY;	if (!request_mem_region(phys, size, name))		return tmp;	omap_map.name = name;	omap_map.phys = phys;	omap_map.size = size;	omap_map.virt = ioremap(phys, size);	simple_map_init(&omap_map);	mymtd = do_map_probe("cfi_probe", &omap_map);	if (!mymtd) {		release_mem_region(phys, size);		iounmap(omap_map.virt);		return -EIO;	}	mymtd->owner = THIS_MODULE;#ifdef CONFIG_MTD_PARTITIONS	tmp = parse_mtd_partitions(mymtd, part_probes, &parts, 0);	if (tmp > 0)		add_mtd_partitions(mymtd, parts, tmp);	else if (tmp < 0 && bootable)		add_mtd_partitions(mymtd, boot_partitions, 				   ARRAY_SIZE(boot_partitions));	else#endif		add_mtd_device(mymtd);	return 0;}static int __init init_omap_nor(void){	int ret = -ENODEV;	/* By now BM is cleared, so CS3 will never be at address 0 */	if (machine_is_omap_innovator())		ret = probe_nor(MODULE_NAME "_cs0", 0, SZ_32M, 1);	else		ret = probe_nor(MODULE_NAME "_cs3",				OMAP_CS3_PHYS, OMAP_CS3_SIZE, 1);	/* H2/H3 "NAND boot" puts NOR at CS2B, NAND at CS3 */	if (ret < 0 && (machine_is_omap_h2() || machine_is_omap_h3()))		ret = probe_nor(MODULE_NAME "_cs2b",				OMAP_CS2B_PHYS, OMAP_CS2B_SIZE, 0);	return ret;}static void __exit cleanup_omap_nor(void){#ifdef CONFIG_MTD_PARTITIONS	if (parts)		del_mtd_partitions(mymtd);	else#endif		del_mtd_device(mymtd);	map_destroy(mymtd);	release_mem_region(omap_map.phys, omap_map.size);	iounmap((void *) omap_map.virt);#ifdef CONFIG_MTD_PARTITIONS	if (parts)		kfree(parts);#endif}module_init(init_omap_nor);module_exit(cleanup_omap_nor);MODULE_LICENSE("GPL");MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");

⌨️ 快捷键说明

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