wh5307 mtd maps 下 样例 点击:729 | 回复:0



gongkongedit

    
  • 精华:1099帖
  • 求助:0帖
  • 帖子:14392帖 | 54470回
  • 年度积分:0
  • 历史总积分:622
  • 注册:2008年9月08日
发表于:2004-02-25 16:29:00
楼主
/* * Normal mappings of chips on wh5307 in physical memory */ #include #include #include #include #include #include #include #include #define WINDOW_ADDR 0xf0000000 #define WINDOW_SIZE 0x200000 #define BUSWIDTH 2 static struct mtd_info *whmtd; __u8 wh5307_read8(struct map_info *map, unsigned long ofs) { return __raw_readb(map->map_priv_1 + ofs); } __u16 wh5307_read16(struct map_info *map, unsigned long ofs) { return __raw_readw(map->map_priv_1 + ofs); } __u32 wh5307_read32(struct map_info *map, unsigned long ofs) { return __raw_readl(map->map_priv_1 + ofs); } void wh5307_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) { memcpy(to, (void *)(map->map_priv_1 + from), len); } void wh5307_write8(struct map_info *map, __u8 d, unsigned long adr) { __raw_writeb(d, map->map_priv_1 + adr); } void wh5307_write16(struct map_info *map, __u16 d, unsigned long adr) { __raw_writew(d, map->map_priv_1 + adr); } void wh5307_write32(struct map_info *map, __u32 d, unsigned long adr) { __raw_writel(d, map->map_priv_1 + adr); } void wh5307_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) { memcpy((void *)(map->map_priv_1 + to), from, len); } struct map_info wh5307_map = { name: "wh5307 flash device", size: WINDOW_SIZE, buswidth: BUSWIDTH, read8: wh5307_read8, read16: wh5307_read16, read32: wh5307_read32, copy_from: wh5307_copy_from, write8: wh5307_write8, write16: wh5307_write16, write32: wh5307_write32, copy_to: wh5307_copy_to }; static struct mtd_partition wh5307_partitions[] = { { name: "reserved for kennel (1.5M)", size: 0x180000, offset: 0x0, mask_flags: MTD_WRITEABLE }, { name: "used for jffs2 (512k)", size: 0x80000, offset: 0x180000 } }; int __init init_wh5307(void) { printk(KERN_NOTICE "wh5307 flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR); wh5307_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE); if (!wh5307_map.map_priv_1) { printk("Failed to ioremap\n"); return -EIO; } whmtd = do_map_probe("jedec_probe", &wh5307_map); if (whmtd) { whmtd->module = THIS_MODULE; whmtd->erasesize = 0x1000; return add_mtd_partitions(whmtd, wh5307_partitions, sizeof(wh5307_partitions) / sizeof(struct mtd_partition)); } iounmap((void *)wh5307_map.map_priv_1); return -ENXIO; } static void __exit cleanup_wh5307(void) { if (whmtd) { del_mtd_partitions(whmtd); map_destroy(whmtd); } if (wh5307_map.map_priv_1) { iounmap((void *)wh5307_map.map_priv_1); wh5307_map.map_priv_1 = 0; } } module_init(init_wh5307); module_exit(cleanup_wh5307);


热门招聘
相关主题

官方公众号

智造工程师