xhyper255.c

来自「linux嵌入式课程实践中的一个关于声卡驱动程序 。」· C语言 代码 · 共 192 行

C
192
字号
#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 WINDOW_ADDR 	0#ifdef CONFIG_ARCH_XHYPER255B#define WINDOW_SIZE 	32*1024*1024#define BUSWIDTH 	4#elif defined(CONFIG_ARCH_XHYPER255A)#define WINDOW_SIZE     16*1024*1024 //FLASH_16MB#define BUSWIDTH        2 //16bit#endifstatic __u8 xhyper255_read8(struct map_info *map, unsigned long ofs){	return *(__u8 *)(map->map_priv_1 + ofs);}static __u16 xhyper255_read16(struct map_info *map, unsigned long ofs){	return *(__u16 *)(map->map_priv_1 + ofs);}static __u32 xhyper255_read32(struct map_info *map, unsigned long ofs){	return *(__u32 *)(map->map_priv_1 + ofs);}static void xhyper255_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len){	memcpy(to, (void *)(map->map_priv_1 + from), len);}static void xhyper255_write8(struct map_info *map, __u8 d, unsigned long adr){	*(__u8 *)(map->map_priv_1 + adr) = d;}static void xhyper255_write16(struct map_info *map, __u16 d, unsigned long adr){	*(__u16 *)(map->map_priv_1 + adr) = d;}static void xhyper255_write32(struct map_info *map, __u32 d, unsigned long adr){	*(__u32 *)(map->map_priv_1 + adr) = d;}static void xhyper255_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len){	memcpy((void *)(map->map_priv_1 + to), from, len);}static struct map_info xhyper255_map = {	name: "X-Hyper255 Flash",	size: WINDOW_SIZE,	buswidth: BUSWIDTH,	read8:		xhyper255_read8,	read16:		xhyper255_read16,	read32:		xhyper255_read32,	copy_from:	xhyper255_copy_from,	write8:		xhyper255_write8,	write16:	xhyper255_write16,	write32:	xhyper255_write32,	copy_to:	xhyper255_copy_to};static struct mtd_partition xhyper255_partitions[] = {#ifdef CONFIG_ARCH_XHYPER255B			{		name:		"Bootloader",		size:		0x00040000,		offset:		0,		mask_flags:	MTD_WRITEABLE  /* force read-only */	},{		name:		"Partition Tables",		size:		0x00080000,		offset:		0x00040000,	},{		name:		"Kernel",		size:		0x00200000,		offset:		0x000C0000,	},{		name:		"Filesystem",		size:		WINDOW_SIZE-0x002C0000, //MTDPART_SIZ_FULL,		offset:		0x002C0000	}#elif defined(CONFIG_ARCH_XHYPER255A)        {                name:           "Bootloader",                size:           0x00040000,                offset:         0,                mask_flags:     MTD_WRITEABLE  /* force read-only */        },{		name:           "Partition Tables",		size:           0x00080000,		offset:         0x00040000,	},{                name:           "Kernel",                size:           0x00100000,                offset:         0x000C0000,        },{                name:           "Filesystem",                size:           WINDOW_SIZE-0x001C0000, //MTDPART_SIZ_FULL,                offset:         0x001C0000        }	#endif};#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_xhyper255(void){	struct mtd_partition *parts;	int nb_parts = 0;	int parsed_nr_parts = 0;	char *part_type = "static";	printk("Probing X-Hyper250 Flash at physical address 0x%08x\n", WINDOW_ADDR);	xhyper255_map.map_priv_1 = (unsigned long)__ioremap(WINDOW_ADDR, WINDOW_SIZE, 0);	if (!xhyper255_map.map_priv_1) {		printk("Failed to ioremap\n");		return -EIO;	}	mymtd = do_map_probe("cfi_probe", &xhyper255_map);	if (!mymtd) {		iounmap((void *)xhyper255_map.map_priv_1);		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 = xhyper255_partitions;		nb_parts = NB_OF(xhyper255_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_xhyper255(void){	if (mymtd) {		del_mtd_partitions(mymtd);		map_destroy(mymtd);		if (parsed_parts)			kfree(parsed_parts);	}	if (xhyper255_map.map_priv_1)		iounmap((void *)xhyper255_map.map_priv_1);	return;}module_init(init_xhyper255);module_exit(cleanup_xhyper255);

⌨️ 快捷键说明

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