2 * $Id: dbox2-flash.c,v 1.4 2001/10/02 15:05:14 dwmw2 Exp $
4 * Nokia / Sagem D-Box 2 flash driver
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/config.h>
16 /* partition_info gives details on the logical partitions that the split the
17 * single flash device into. If the size if zero we use up to the end of the
19 static struct mtd_partition partition_info[]= {{name: "BR bootloader", // raw
22 mask_flags: MTD_WRITEABLE},
23 {name: "PPC bootloader", // flfs
25 offset: MTDPART_OFS_APPEND,
27 {name: "Kernel", // idxfs
29 offset: MTDPART_OFS_APPEND,
31 {name: "System", // jffs
32 size: MTDPART_SIZ_FULL,
33 offset: MTDPART_OFS_APPEND,
36 #define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0]))
38 #define WINDOW_ADDR 0x10000000
39 #define WINDOW_SIZE 0x800000
41 static struct mtd_info *mymtd;
43 __u8 dbox2_flash_read8(struct map_info *map, unsigned long ofs)
45 return __raw_readb(map->map_priv_1 + ofs);
48 __u16 dbox2_flash_read16(struct map_info *map, unsigned long ofs)
50 return __raw_readw(map->map_priv_1 + ofs);
53 __u32 dbox2_flash_read32(struct map_info *map, unsigned long ofs)
55 return __raw_readl(map->map_priv_1 + ofs);
58 void dbox2_flash_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
60 memcpy_fromio(to, map->map_priv_1 + from, len);
63 void dbox2_flash_write8(struct map_info *map, __u8 d, unsigned long adr)
65 __raw_writeb(d, map->map_priv_1 + adr);
69 void dbox2_flash_write16(struct map_info *map, __u16 d, unsigned long adr)
71 __raw_writew(d, map->map_priv_1 + adr);
75 void dbox2_flash_write32(struct map_info *map, __u32 d, unsigned long adr)
77 __raw_writel(d, map->map_priv_1 + adr);
81 void dbox2_flash_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
83 memcpy_toio(map->map_priv_1 + to, from, len);
86 struct map_info dbox2_flash_map = {
87 name: "D-Box 2 flash memory",
90 read8: dbox2_flash_read8,
91 read16: dbox2_flash_read16,
92 read32: dbox2_flash_read32,
93 copy_from: dbox2_flash_copy_from,
94 write8: dbox2_flash_write8,
95 write16: dbox2_flash_write16,
96 write32: dbox2_flash_write32,
97 copy_to: dbox2_flash_copy_to
100 int __init init_dbox2_flash(void)
102 printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR);
103 dbox2_flash_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
105 if (!dbox2_flash_map.map_priv_1) {
106 printk("Failed to ioremap\n");
110 // Probe for dual Intel 28F320 or dual AMD
111 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
113 // Probe for single Intel 28F640
114 dbox2_flash_map.buswidth = 2;
116 mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
120 mymtd->module = THIS_MODULE;
122 /* Create MTD devices for each partition. */
123 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
128 iounmap((void *)dbox2_flash_map.map_priv_1);
132 static void __exit cleanup_dbox2_flash(void)
135 del_mtd_partitions(mymtd);
138 if (dbox2_flash_map.map_priv_1) {
139 iounmap((void *)dbox2_flash_map.map_priv_1);
140 dbox2_flash_map.map_priv_1 = 0;
144 module_init(init_dbox2_flash);
145 module_exit(cleanup_dbox2_flash);
148 MODULE_LICENSE("GPL");
149 MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
150 MODULE_DESCRIPTION("MTD map driver for Nokia/Sagem D-Box 2 board");