2 * Flash memory access on IDT 79S334 boards
4 * (C) 2001 Pete Popov <ppopov@mvista.com>
6 * $Id: 79s334-flash.c,v 1.1.1.1 2005/04/11 02:50:26 jack Exp $
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/map.h>
16 #include <linux/mtd/partitions.h>
19 //#include <asm/au1000.h>
22 #define DBG(x...) printk(x)
27 #define WINDOW_ADDR 0x1FC00000
28 #define WINDOW_SIZE 0x400000
30 __u8 physmap_read8(struct map_info *map, unsigned long ofs)
33 ret = readb(map->map_priv_1 + ofs);
34 DBG("read8 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
38 __u16 physmap_read16(struct map_info *map, unsigned long ofs)
41 ret = readw(map->map_priv_1 + ofs);
42 DBG("read16 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
46 __u32 physmap_read32(struct map_info *map, unsigned long ofs)
49 ret = readl(map->map_priv_1 + ofs);
50 DBG("read32 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
54 void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
56 DBG("physmap_copy from %x to %x\n", (unsigned)from, (unsigned)to);
57 memcpy_fromio(to, map->map_priv_1 + from, len);
60 void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
62 DBG("write8 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
63 writeb(d, map->map_priv_1 + adr);
67 void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
69 DBG("write16 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
70 writew(d, map->map_priv_1 + adr);
74 void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
76 DBG("write32 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
77 writel(d, map->map_priv_1 + adr);
81 void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
83 DBG("physmap_copy_to %x from %x\n", (unsigned)to, (unsigned)from);
84 memcpy_toio(map->map_priv_1 + to, from, len);
89 static struct map_info idt79s334_map = {
90 name: "idt79s334 flash",
92 read16: physmap_read16,
93 read32: physmap_read32,
94 copy_from: physmap_copy_from,
95 write8: physmap_write8,
96 write16: physmap_write16,
97 write32: physmap_write32,
98 copy_to: physmap_copy_to,
100 //map_priv_1: WINDOW_ADDR,
104 static unsigned long flash_size = 0x00400000;
105 static unsigned char flash_buswidth = 2;
106 static struct mtd_partition idt79s334_partitions[] = {
115 mask_flags: MTD_WRITEABLE
160 #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
162 static struct mtd_partition *parsed_parts;
163 static struct mtd_info *mymtd;
165 int __init idt79s334_mtd_init(void)
167 struct mtd_partition *parts;
171 /* Default flash buswidth */
172 idt79s334_map.buswidth = flash_buswidth;
175 * Static partition definition selection
177 part_type = "static";
178 parts = idt79s334_partitions;
179 nb_parts = NB_OF(idt79s334_partitions);
180 idt79s334_map.size = flash_size;
183 * Now let's probe for the actual flash. Do it here since
184 * specific machine settings might have been set above.
186 printk(KERN_NOTICE "idt79s334 flash: probing %d-bit flash bus\n",
187 idt79s334_map.buswidth*8);
188 idt79s334_map.map_priv_1 =
189 (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
190 mymtd = do_map_probe("cfi_probe", &idt79s334_map);
191 if (!mymtd) return -ENXIO;
192 mymtd->module = THIS_MODULE;
194 add_mtd_partitions(mymtd, parts, nb_parts);
198 static void __exit idt79s334_mtd_cleanup(void)
201 del_mtd_partitions(mymtd);
208 module_init(idt79s334_mtd_init);
209 module_exit(idt79s334_mtd_cleanup);
211 MODULE_AUTHOR("Pete Popov");
212 MODULE_DESCRIPTION("idt79s334 CFI map driver");
213 MODULE_LICENSE("GPL");