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

📄 e28f128.c

📁 ARM9200在LINUX2.4.19下的NORFLASH E28F128的驱动程序,可以直接加载使用
💻 C
字号:
/* * $Id: * * Map driver for the e28f128 developer platform. * * Author:	Nicolas Pitre * Copyright:	(C) 2001 MontaVista Software Inc. *  * Change Data:	2006.11.8 * Change Author: Sun Qigang * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * The sencond flash, address is 0x40000000, size is 16M(32*1024*1024), block is *    0x00020000, chip is intel E28F128J3A(NORFLASH).  */#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <asm/io.h>#include <linux/mtd/mtd.h>#include <linux/mtd/map.h>#include <linux/mtd/partitions.h>#define E28F128_WINDOW_ADDR 	0x40000000#define E28F128_WINDOW_SIZE 	16*1024*1024static __u8 e28f128_read8(struct map_info *map, unsigned long ofs){	return *(__u8 *)(map->map_priv_2 + ofs);}static __u16 e28f128_read16(struct map_info *map, unsigned long ofs){	return *(__u16 *)(map->map_priv_2 + ofs);}static __u32 e28f128_read32(struct map_info *map, unsigned long ofs){	return *(__u32 *)(map->map_priv_2 + ofs);}static void e28f128_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len){	memcpy(to, (void *)(map->map_priv_2 + from), len);}static void e28f128_write8(struct map_info *map, __u8 d, unsigned long adr){	*(__u8 *)(map->map_priv_2 + adr) = d;}static void e28f128_write16(struct map_info *map, __u16 d, unsigned long adr){	*(__u16 *)(map->map_priv_2 + adr) = d;}static void e28f128_write32(struct map_info *map, __u32 d, unsigned long adr){	*(__u32 *)(map->map_priv_2 + adr) = d;}static void e28f128_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len){	memcpy((void *)(map->map_priv_2 + to), from, len);}static struct map_info e28f128_map = {	name: "e28f128 flash",	size: E28F128_WINDOW_SIZE,	read8:		e28f128_read8,	read16:		e28f128_read16,	read32:		e28f128_read32,	copy_from:	e28f128_copy_from,	write8:		e28f128_write8,	write16:	e28f128_write16,	write32:	e28f128_write32,	copy_to:	e28f128_copy_to};static struct mtd_partition e28f128_partitions[] = {	{		name:		"datas",		size:		0x00100000,		offset:		0x0,	},{		name:		"file",		size:		MTDPART_SIZ_FULL,		offset:		0x00100000,	}        /* 2006.11.8 add User mtd, the first flash has 2 mtd, User is jffs2 filesystem. */};#define NB_OF(x)  (sizeof(x)/sizeof(x[0]))static struct mtd_info *mymtd;static struct mtd_partition *parsed_parts;extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts);static int __init init_e28f128(void){	struct mtd_partition *parts;	int nb_parts = 0;	int parsed_nr_parts = 0;	char *part_type = "static"; 	/* Setup MEMC to support CS3=FLASH */  	AT91_SYS->EBI_CSA |= AT91C_EBI_CS3A_SMC;	// Initialization of the Static Memory Controller for Chip Select 3 (0x00003083)--(0x0000328f)        AT91_SYS->EBI_SMC2_CSR[3] = (AT91C_SMC2_NWS & 0x04) | AT91C_SMC2_WSEN | 		(AT91C_SMC2_TDF & 0x200) | AT91C_SMC2_BAT | AT91C_SMC2_DBW;	//e28f128_map.buswidth = (BOOT_DEF & 1) ? 2 : 4;	e28f128_map.buswidth=2;	printk( "Probing e28f128 flash at physical address 0x%08x (%d-bit buswidth)\n",		E28F128_WINDOW_ADDR, e28f128_map.buswidth * 8 );	e28f128_map.map_priv_2 = (unsigned long)ioremap(E28F128_WINDOW_ADDR, E28F128_WINDOW_SIZE);	/* e28f128_map.map_priv_2 = (unsigned long)__ioremap(E28F128_WINDOW_ADDR, E28F128_WINDOW_SIZE, 0); */	if (!e28f128_map.map_priv_2) {		printk("Failed to ioremap\n");		return -EIO;	}	mymtd = do_map_probe("cfi_probe", &e28f128_map);	if (!mymtd) {		iounmap((void *)e28f128_map.map_priv_2);		return -ENXIO;	}	mymtd->module = THIS_MODULE;#ifdef CONFIG_MTD_REDBOOT_PARTS	if (parsed_nr_parts == 0) {		int ret = parse_redboot_partitions(mymtd, &parsed_parts);		if (ret > 0) {			part_type = "RedBoot";			parsed_nr_parts = ret;		}	}#endif	if (parsed_nr_parts > 0) {		parts = parsed_parts;		nb_parts = parsed_nr_parts;	} else {		parts = e28f128_partitions;		nb_parts = NB_OF(e28f128_partitions);	}	if (nb_parts) {		printk(KERN_NOTICE "Using %s partition definition\n", part_type);		add_mtd_partitions(mymtd, parts, nb_parts);	} else {		add_mtd_device(mymtd);	}	return 0;}static void __exit cleanup_e28f128(void){	if (mymtd) {		del_mtd_partitions(mymtd);		map_destroy(mymtd);		if (parsed_parts)			kfree(parsed_parts);	}	if (e28f128_map.map_priv_2)		iounmap((void *)e28f128_map.map_priv_2);	return 0;}module_init(init_e28f128);module_exit(cleanup_e28f128);

⌨️ 快捷键说明

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