?? edb9307.c
字號(hào):
/* * Handle mapping of the NOR flash on Cirrus Logic EDB9307 boards * * 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. */#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/config.h>#include <linux/reboot.h>#ifdef CONFIG_MTD_PARTITIONS#include <linux/mtd/partitions.h>#endif#ifdef CONFIG_ARCH_EP93XX_CSN0#ifdef CONFIG_ARCH_EP93XX_SYNC_BOOT#define WINDOW_ADDR 0xf0000000#else#define WINDOW_ADDR 0x00000000#endif#endif#ifdef CONFIG_ARCH_EP93XX_CSN1#define WINDOW_ADDR 0x10000000#endif#ifdef CONFIG_ARCH_EP93XX_CSN2#define WINDOW_ADDR 0x20000000#endif#ifdef CONFIG_ARCH_EP93XX_CSN3#define WINDOW_ADDR 0x30000000#endif#ifdef CONFIG_ARCH_EP93XX_CSN6#define WINDOW_ADDR 0x60000000#endif#ifdef CONFIG_ARCH_EP93XX_CSN7#define WINDOW_ADDR 0x70000000#endif#define WINDOW_SIZE 0x02000000#define BUSWIDTH 4/* can be "cfi_probe", "jedec_probe", "map_rom", 0 }; */#define PROBETYPES { "cfi_probe", 0 }#define MSG_PREFIX "EDB9307-NOR:" /* prefix for our printk()'s */#define MTDID "edb9307-nor" /* for mtdparts= partitioning */static struct mtd_info *mymtd;#define MUNG_ADDR(x) ((x & 0xfffe0000) | ((x & 0x00010000) >> 15) | ((x & 0x0000ffff) << 1))__u8 edb9307nor_read8(struct map_info *map, unsigned long ofs){ return __raw_readb(map->map_priv_1 + ofs);}__u16 edb9307nor_read16(struct map_info *map, unsigned long ofs){ return __raw_readw(map->map_priv_1 + ofs);}__u32 edb9307nor_read32(struct map_info *map, unsigned long ofs){ return __raw_readl(map->map_priv_1 + ofs);}void edb9307nor_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len){ memcpy_fromio(to, map->map_priv_1 + from, len);}void edb9307nor_write8(struct map_info *map, __u8 d, unsigned long adr){ __raw_writeb(d, map->map_priv_1 + adr); mb();}void edb9307nor_write16(struct map_info *map, __u16 d, unsigned long adr){ __raw_writew(d, map->map_priv_1 + adr); mb();}void edb9307nor_write32(struct map_info *map, __u32 d, unsigned long adr){ __raw_writel(d, map->map_priv_1 + adr); mb();}void edb9307nor_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len){ memcpy_toio(map->map_priv_1 + to, from, len);}__u8 edb9307nor16_read8(struct map_info *map, unsigned long ofs){ return __raw_readb(map->map_priv_1 + MUNG_ADDR(ofs));}__u16 edb9307nor16_read16(struct map_info *map, unsigned long ofs){ if (ofs == 0x40) return 0; return __raw_readw(map->map_priv_1 + MUNG_ADDR(ofs));}__u32 edb9307nor16_read32(struct map_info *map, unsigned long ofs){ return __raw_readl(map->map_priv_1 + MUNG_ADDR(ofs));}void edb9307nor16_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len){ while (len--) { *(short *)to++ = edb9307nor16_read16(map, from); from += 2; }}void edb9307nor16_write8(struct map_info *map, __u8 d, unsigned long adr){ __raw_writeb(d, map->map_priv_1 + MUNG_ADDR(adr)); mb();}void edb9307nor16_write16(struct map_info *map, __u16 d, unsigned long adr){ __raw_writew(d, map->map_priv_1 + MUNG_ADDR(adr)); mb();}void edb9307nor16_write32(struct map_info *map, __u32 d, unsigned long adr){ __raw_writel(d, map->map_priv_1 + MUNG_ADDR(adr)); mb();}void edb9307nor16_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len){ while (len--) { edb9307nor16_write16(map, *(short *)from++, to); to += 2; }}struct map_info edb9307nor_map = { name: "NOR flash on EDB9307", size: WINDOW_SIZE, buswidth: BUSWIDTH, read8: edb9307nor_read8, read16: edb9307nor_read16, read32: edb9307nor_read32, copy_from: edb9307nor_copy_from, write8: edb9307nor_write8, write16: edb9307nor_write16, write32: edb9307nor_write32, copy_to: edb9307nor_copy_to};#ifdef CONFIG_MTD_PARTITIONS#ifdef CONFIG_MTD_CMDLINE_PARTSint parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);#endif#ifdef CONFIG_MTD_REDBOOT_PARTSextern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts);#endif#endifstatic int mtd_parts_nb = 0;static struct mtd_partition *mtd_parts = 0;static int edb9307nor_reboot(struct notifier_block *this, unsigned long event, void *x){ switch (event) { case SYS_HALT: case SYS_POWER_OFF: case SYS_RESTART: edb9307nor_write32(&edb9307nor_map, 0x00f000f0, 0); edb9307nor_write32(&edb9307nor_map, 0x00ff00ff, 0); default: return NOTIFY_DONE; }}static struct notifier_block edb9307nor_notifier = { edb9307nor_reboot, NULL, 5};int __init init_edb9307nor(void){ static const char *rom_probe_types[] = PROBETYPES; const char **type; const char *part_type = 0; unsigned long config;#ifdef CONFIG_ARCH_EP93XX_CSN0 config = inl(SMCBCR0);#endif#ifdef CONFIG_ARCH_EP93XX_CSN1 config = inl(SMCBCR1);#endif#ifdef CONFIG_ARCH_EP93XX_CSN2 config = inl(SMCBCR2);#endif#ifdef CONFIG_ARCH_EP93XX_CSN3 config = inl(SMCBCR3);#endif#ifdef CONFIG_ARCH_EP93XX_CSN6 config = inl(SMCBCR6);#endif#ifdef CONFIG_ARCH_EP93XX_CSN7 config = inl(SMCBCR7);#endif if ((config & SMCBCR_MW_MASK) == SMCBCR_MW_16) { edb9307nor_map.size >>= 1; edb9307nor_map.buswidth >>= 1; edb9307nor_map.read8 = edb9307nor16_read8; edb9307nor_map.read16 = edb9307nor16_read16; edb9307nor_map.read32 = edb9307nor16_read32; edb9307nor_map.copy_from = edb9307nor16_copy_from; edb9307nor_map.write8 = edb9307nor16_write8; edb9307nor_map.write16 = edb9307nor16_write16; edb9307nor_map.write32 = edb9307nor16_write32; edb9307nor_map.copy_to = edb9307nor16_copy_to; } printk(KERN_NOTICE MSG_PREFIX " 0x%08x at 0x%08x\n", edb9307nor_map.size, WINDOW_ADDR); edb9307nor_map.map_priv_1 = (unsigned long) ioremap(WINDOW_ADDR, edb9307nor_map.size); if (!edb9307nor_map.map_priv_1) { printk(MSG_PREFIX "failed to ioremap\n"); return -EIO; } mymtd = 0; type = rom_probe_types; for(; !mymtd && *type; type++) { mymtd = do_map_probe(*type, &edb9307nor_map); } if (mymtd) { mymtd->module = THIS_MODULE; if ((config & SMCBCR_MW_MASK) == SMCBCR_MW_16) { edb9307nor_map.read8 = edb9307nor_read8; edb9307nor_map.read16 = edb9307nor_read16; edb9307nor_map.read32 = edb9307nor_read32; edb9307nor_map.copy_from = edb9307nor_copy_from; edb9307nor_map.write8 = edb9307nor_write8; edb9307nor_map.write16 = edb9307nor_write16; edb9307nor_map.write32 = edb9307nor_write32; edb9307nor_map.copy_to = edb9307nor_copy_to; }#ifdef CONFIG_MTD_PARTITIONS#ifdef CONFIG_MTD_CMDLINE_PARTS mtd_parts_nb = parse_cmdline_partitions(mymtd, &mtd_parts, MTDID); if (mtd_parts_nb > 0) part_type = "command line";#endif #ifdef CONFIG_MTD_REDBOOT_PARTS if (mtd_parts_nb <= 0) { mtd_parts_nb = parse_redboot_partitions(mymtd, &mtd_parts); if (mtd_parts_nb > 0) { part_type = "RedBoot"; } }#endif#endif add_mtd_device(mymtd); if (mtd_parts_nb <= 0) printk(KERN_NOTICE MSG_PREFIX "no partition info available\n"); else { printk(KERN_NOTICE MSG_PREFIX "using %s partition definition\n", part_type); add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb); } register_reboot_notifier(&edb9307nor_notifier); return 0; } iounmap((void *)edb9307nor_map.map_priv_1); return -ENXIO;}static void __exit cleanup_edb9307nor(void){ if (mymtd) { del_mtd_device(mymtd); map_destroy(mymtd); } if (edb9307nor_map.map_priv_1) { iounmap((void *)edb9307nor_map.map_priv_1); edb9307nor_map.map_priv_1 = 0; }}module_init(init_edb9307nor);module_exit(cleanup_edb9307nor);MODULE_LICENSE("GPL");MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");MODULE_DESCRIPTION("Generic configurable MTD map driver");
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -