2 * $Id: ocelot.c,v 1.17 2005/11/07 11:14:27 gleixner Exp $
4 * Flash on Momenco Ocelot
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/map.h>
14 #include <linux/mtd/partitions.h>
16 #define OCELOT_PLD 0x2c000000
17 #define FLASH_WINDOW_ADDR 0x2fc00000
18 #define FLASH_WINDOW_SIZE 0x00080000
19 #define FLASH_BUSWIDTH 1
20 #define NVRAM_WINDOW_ADDR 0x2c800000
21 #define NVRAM_WINDOW_SIZE 0x00007FF0
22 #define NVRAM_BUSWIDTH 1
24 static unsigned int cacheflush
= 0;
26 static struct mtd_info
*flash_mtd
;
27 static struct mtd_info
*nvram_mtd
;
29 static void ocelot_ram_write(struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
31 struct map_info
*map
= mtd
->priv
;
34 /* If we use memcpy, it does word-wide writes. Even though we told the
35 GT64120A that it's an 8-bit wide region, word-wide writes don't work.
36 We end up just writing the first byte of the four to all four bytes.
37 So we have this loop instead */
40 __raw_writeb(*(unsigned char *) from
, map
->virt
+ to
);
47 static struct mtd_partition
*parsed_parts
;
49 struct map_info ocelot_flash_map
= {
50 .name
= "Ocelot boot flash",
51 .size
= FLASH_WINDOW_SIZE
,
52 .bankwidth
= FLASH_BUSWIDTH
,
53 .phys
= FLASH_WINDOW_ADDR
,
56 struct map_info ocelot_nvram_map
= {
57 .name
= "Ocelot NVRAM",
58 .size
= NVRAM_WINDOW_SIZE
,
59 .bankwidth
= NVRAM_BUSWIDTH
,
60 .phys
= NVRAM_WINDOW_ADDR
,
63 static const char *probes
[] = { "RedBoot", NULL
};
65 static int __init
init_ocelot_maps(void)
69 unsigned char brd_status
;
71 printk(KERN_INFO
"Momenco Ocelot MTD mappings: Flash 0x%x at 0x%x, NVRAM 0x%x at 0x%x\n",
72 FLASH_WINDOW_SIZE
, FLASH_WINDOW_ADDR
, NVRAM_WINDOW_SIZE
, NVRAM_WINDOW_ADDR
);
74 /* First check whether the flash jumper is present */
75 pld
= ioremap(OCELOT_PLD
, 0x10);
77 printk(KERN_NOTICE
"Failed to ioremap Ocelot PLD\n");
80 brd_status
= readb(pld
+4);
83 /* Now ioremap the NVRAM space */
84 ocelot_nvram_map
.virt
= ioremap_nocache(NVRAM_WINDOW_ADDR
, NVRAM_WINDOW_SIZE
);
85 if (!ocelot_nvram_map
.virt
) {
86 printk(KERN_NOTICE
"Failed to ioremap Ocelot NVRAM space\n");
90 simple_map_init(&ocelot_nvram_map
);
92 /* And do the RAM probe on it to get an MTD device */
93 nvram_mtd
= do_map_probe("map_ram", &ocelot_nvram_map
);
95 printk("NVRAM probe failed\n");
98 nvram_mtd
->owner
= THIS_MODULE
;
99 nvram_mtd
->erasesize
= 16;
100 /* Override the write() method */
101 nvram_mtd
->write
= ocelot_ram_write
;
103 /* Now map the flash space */
104 ocelot_flash_map
.virt
= ioremap_nocache(FLASH_WINDOW_ADDR
, FLASH_WINDOW_SIZE
);
105 if (!ocelot_flash_map
.virt
) {
106 printk(KERN_NOTICE
"Failed to ioremap Ocelot flash space\n");
109 /* Now the cached version */
110 ocelot_flash_map
.cached
= (unsigned long)__ioremap(FLASH_WINDOW_ADDR
, FLASH_WINDOW_SIZE
, 0);
112 simple_map_init(&ocelot_flash_map
);
114 /* Only probe for flash if the write jumper is present */
115 if (brd_status
& 0x40) {
116 flash_mtd
= do_map_probe("jedec", &ocelot_flash_map
);
118 printk(KERN_NOTICE
"Ocelot flash write jumper not present. Treating as ROM\n");
120 /* If that failed or the jumper's absent, pretend it's ROM */
122 flash_mtd
= do_map_probe("map_rom", &ocelot_flash_map
);
123 /* If we're treating it as ROM, set the erase size */
125 flash_mtd
->erasesize
= 0x10000;
130 add_mtd_device(nvram_mtd
);
132 flash_mtd
->owner
= THIS_MODULE
;
133 nr_parts
= parse_mtd_partitions(flash_mtd
, probes
, &parsed_parts
, 0);
136 add_mtd_partitions(flash_mtd
, parsed_parts
, nr_parts
);
138 add_mtd_device(flash_mtd
);
143 iounmap((void *)ocelot_flash_map
.virt
);
144 if (ocelot_flash_map
.cached
)
145 iounmap((void *)ocelot_flash_map
.cached
);
147 map_destroy(nvram_mtd
);
149 iounmap((void *)ocelot_nvram_map
.virt
);
154 static void __exit
cleanup_ocelot_maps(void)
156 del_mtd_device(nvram_mtd
);
157 map_destroy(nvram_mtd
);
158 iounmap((void *)ocelot_nvram_map
.virt
);
161 del_mtd_partitions(flash_mtd
);
163 del_mtd_device(flash_mtd
);
164 map_destroy(flash_mtd
);
165 iounmap((void *)ocelot_flash_map
.virt
);
166 if (ocelot_flash_map
.cached
)
167 iounmap((void *)ocelot_flash_map
.cached
);
170 module_init(init_ocelot_maps
);
171 module_exit(cleanup_ocelot_maps
);
173 MODULE_LICENSE("GPL");
174 MODULE_AUTHOR("Red Hat, Inc. - David Woodhouse <dwmw2@cambridge.redhat.com>");
175 MODULE_DESCRIPTION("MTD map driver for Momenco Ocelot board");