📄 h720x-flash.c
字号:
/* * Flash memory access on Hynix GMS30C7201/HMS30C7202 based * evaluation boards * * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com> * 2003 Thomas Gleixner <tglx@linutronix.de> */#include <linux/config.h>#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/mtd/mtd.h>#include <linux/mtd/map.h>#include <linux/mtd/partitions.h>#include <asm/hardware.h>#include <asm/io.h>static struct mtd_info *mymtd;static __u8 h720x_read8(struct map_info *map, unsigned long ofs){ return readb(map->map_priv_1 + ofs);}static __u16 h720x_read16(struct map_info *map, unsigned long ofs){ return readw(map->map_priv_1 + ofs);}static __u32 h720x_read32(struct map_info *map, unsigned long ofs){ return readl(map->map_priv_1 + ofs);}static void h720x_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len){ memcpy_fromio(to, map->map_priv_1 + from, len);}static void h720x_write8(struct map_info *map, __u8 d, unsigned long adr){ writeb(d, map->map_priv_1 + adr);}static void h720x_write16(struct map_info *map, __u16 d, unsigned long adr){ writew(d, map->map_priv_1 + adr);}static void h720x_write32(struct map_info *map, __u32 d, unsigned long adr){ writel(d, map->map_priv_1 + adr);}static void h720x_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len){ memcpy_toio(map->map_priv_1 + to, from, len);}static struct map_info h720x_map = { name: "H720X", read8: h720x_read8, read16: h720x_read16, read32: h720x_read32, copy_from: h720x_copy_from, write8: h720x_write8, write16: h720x_write16, write32: h720x_write32, copy_to: h720x_copy_to, buswidth: 4, size: FLASH_SIZE};static struct mtd_partition h720x_partitions[] = { { name: "ArMon", size: 0x00080000, offset: 0, mask_flags: MTD_WRITEABLE },{ name: "Env", size: 0x00040000, offset: 0x00080000, mask_flags: MTD_WRITEABLE },{ name: "Kernel", size: 0x00180000, offset: 0x000c0000, mask_flags: MTD_WRITEABLE },{ name: "Ramdisk", size: 0x00400000, offset: 0x00240000, mask_flags: MTD_WRITEABLE },{ name: "jffs2", size: MTDPART_SIZ_FULL, offset: MTDPART_OFS_APPEND }};#define NUM_PARTITIONS (sizeof(h720x_partitions)/sizeof(h720x_partitions[0]))static int nr_mtd_parts;static struct mtd_partition *mtd_parts;/* * Initialize FLASH support */int __init h720x_mtd_init(void){ char *part_type = NULL; h720x_map.map_priv_1 = (unsigned long)ioremap(FLASH_PHYS, FLASH_SIZE); if (!h720x_map.map_priv_1) { printk(KERN_ERR "H720x-MTD: ioremap failed\n"); return -EIO; } // Probe for flash buswidth 4 printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n"); mymtd = do_map_probe("cfi_probe", &h720x_map); if (!mymtd) { printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n"); // Probe for buswidth 2 h720x_map.buswidth = 2; mymtd = do_map_probe("cfi_probe", &h720x_map); } if (mymtd) { mymtd->module = THIS_MODULE;#ifdef CONFIG_MTD_CMDLINE_PARTS nr_mtd_parts = parse_cmdline_partitions(mymtd, &mtd_parts, h720x_map.name); if (nr_mtd_parts > 0) part_type = "command line";#endif if (nr_mtd_parts <= 0) { mtd_parts = h720x_partitions; nr_mtd_parts = NUM_PARTITIONS; part_type = "builtin"; } printk(KERN_INFO "Using %s partition table\n", part_type); add_mtd_partitions(mymtd, mtd_parts, nr_mtd_parts); return 0; } iounmap((void *)h720x_map.map_priv_1); return -ENXIO;}/* * Cleanup */static void __exit h720x_mtd_cleanup(void){ if (mymtd) { del_mtd_partitions(mymtd); map_destroy(mymtd); } /* Free partition info, if commandline partition was used */ if (mtd_parts && (mtd_parts != h720x_partitions)) kfree (mtd_parts); if (h720x_map.map_priv_1) { iounmap((void *)h720x_map.map_priv_1); h720x_map.map_priv_1 = 0; }}module_init(h720x_mtd_init);module_exit(h720x_mtd_cleanup);MODULE_LICENSE("GPL");MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -