blob: c29cbf87ea0c9ea3279161c76bd0ee254cb5fd50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Flash on Cirrus CDB89712
3 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 */
5
6#include <linux/module.h>
7#include <linux/types.h>
8#include <linux/kernel.h>
9#include <linux/ioport.h>
10#include <linux/init.h>
11#include <asm/io.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010012#include <mach/hardware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/mtd/mtd.h>
14#include <linux/mtd/map.h>
15#include <linux/mtd/partitions.h>
16
Russell King8959dab2008-11-13 15:02:41 +000017/* dynamic ioremap() areas */
Russell Kingd9a682a2008-11-13 14:53:08 +000018#define FLASH_START 0x00000000
19#define FLASH_SIZE 0x800000
20#define FLASH_WIDTH 4
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Russell King8959dab2008-11-13 15:02:41 +000022#define SRAM_START 0x60000000
23#define SRAM_SIZE 0xc000
24#define SRAM_WIDTH 4
25
26#define BOOTROM_START 0x70000000
27#define BOOTROM_SIZE 0x80
28#define BOOTROM_WIDTH 4
29
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static struct mtd_info *flash_mtd;
32
33struct map_info cdb89712_flash_map = {
34 .name = "flash",
35 .size = FLASH_SIZE,
36 .bankwidth = FLASH_WIDTH,
37 .phys = FLASH_START,
38};
39
40struct resource cdb89712_flash_resource = {
41 .name = "Flash",
42 .start = FLASH_START,
43 .end = FLASH_START + FLASH_SIZE - 1,
44 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
45};
46
47static int __init init_cdb89712_flash (void)
48{
49 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
52 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
53 err = -EBUSY;
54 goto out;
55 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
58 if (!cdb89712_flash_map.virt) {
59 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
60 err = -EIO;
61 goto out_resource;
62 }
63 simple_map_init(&cdb89712_flash_map);
64 flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
65 if (!flash_mtd) {
66 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
67 if (flash_mtd)
68 flash_mtd->erasesize = 0x10000;
69 }
70 if (!flash_mtd) {
71 printk("FLASH probe failed\n");
72 err = -ENXIO;
73 goto out_ioremap;
74 }
75
76 flash_mtd->owner = THIS_MODULE;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000077
Jamie Ilesee0e87b2011-05-23 10:23:40 +010078 if (mtd_device_register(flash_mtd, NULL, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 printk("FLASH device addition failed\n");
80 err = -ENOMEM;
81 goto out_probe;
82 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 return 0;
85
86out_probe:
87 map_destroy(flash_mtd);
88 flash_mtd = 0;
89out_ioremap:
90 iounmap((void *)cdb89712_flash_map.virt);
91out_resource:
92 release_resource (&cdb89712_flash_resource);
93out:
94 return err;
95}
96
97
98
99
100
101static struct mtd_info *sram_mtd;
102
103struct map_info cdb89712_sram_map = {
104 .name = "SRAM",
105 .size = SRAM_SIZE,
106 .bankwidth = SRAM_WIDTH,
107 .phys = SRAM_START,
108};
109
110struct resource cdb89712_sram_resource = {
111 .name = "SRAM",
112 .start = SRAM_START,
113 .end = SRAM_START + SRAM_SIZE - 1,
114 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
115};
116
117static int __init init_cdb89712_sram (void)
118{
119 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
122 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
123 err = -EBUSY;
124 goto out;
125 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
128 if (!cdb89712_sram_map.virt) {
129 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
130 err = -EIO;
131 goto out_resource;
132 }
133 simple_map_init(&cdb89712_sram_map);
134 sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
135 if (!sram_mtd) {
136 printk("SRAM probe failed\n");
137 err = -ENXIO;
138 goto out_ioremap;
139 }
140
141 sram_mtd->owner = THIS_MODULE;
142 sram_mtd->erasesize = 16;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000143
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100144 if (mtd_device_register(sram_mtd, NULL, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 printk("SRAM device addition failed\n");
146 err = -ENOMEM;
147 goto out_probe;
148 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return 0;
151
152out_probe:
153 map_destroy(sram_mtd);
154 sram_mtd = 0;
155out_ioremap:
156 iounmap((void *)cdb89712_sram_map.virt);
157out_resource:
158 release_resource (&cdb89712_sram_resource);
159out:
160 return err;
161}
162
163
164
165
166
167
168
169static struct mtd_info *bootrom_mtd;
170
171struct map_info cdb89712_bootrom_map = {
172 .name = "BootROM",
173 .size = BOOTROM_SIZE,
174 .bankwidth = BOOTROM_WIDTH,
175 .phys = BOOTROM_START,
176};
177
178struct resource cdb89712_bootrom_resource = {
179 .name = "BootROM",
180 .start = BOOTROM_START,
181 .end = BOOTROM_START + BOOTROM_SIZE - 1,
182 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
183};
184
185static int __init init_cdb89712_bootrom (void)
186{
187 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
190 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
191 err = -EBUSY;
192 goto out;
193 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
196 if (!cdb89712_bootrom_map.virt) {
197 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
198 err = -EIO;
199 goto out_resource;
200 }
201 simple_map_init(&cdb89712_bootrom_map);
202 bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
203 if (!bootrom_mtd) {
204 printk("BootROM probe failed\n");
205 err = -ENXIO;
206 goto out_ioremap;
207 }
208
209 bootrom_mtd->owner = THIS_MODULE;
210 bootrom_mtd->erasesize = 0x10000;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000211
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100212 if (mtd_device_register(bootrom_mtd, NULL, 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 printk("BootROM device addition failed\n");
214 err = -ENOMEM;
215 goto out_probe;
216 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 return 0;
219
220out_probe:
221 map_destroy(bootrom_mtd);
222 bootrom_mtd = 0;
223out_ioremap:
224 iounmap((void *)cdb89712_bootrom_map.virt);
225out_resource:
226 release_resource (&cdb89712_bootrom_resource);
227out:
228 return err;
229}
230
231
232
233
234
235static int __init init_cdb89712_maps(void)
236{
237
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000238 printk(KERN_INFO "Cirrus CDB89712 MTD mappings:\n Flash 0x%x at 0x%x\n SRAM 0x%x at 0x%x\n BootROM 0x%x at 0x%x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
240
241 init_cdb89712_flash();
242 init_cdb89712_sram();
243 init_cdb89712_bootrom();
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return 0;
246}
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249static void __exit cleanup_cdb89712_maps(void)
250{
251 if (sram_mtd) {
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100252 mtd_device_unregister(sram_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 map_destroy(sram_mtd);
254 iounmap((void *)cdb89712_sram_map.virt);
255 release_resource (&cdb89712_sram_resource);
256 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (flash_mtd) {
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100259 mtd_device_unregister(flash_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 map_destroy(flash_mtd);
261 iounmap((void *)cdb89712_flash_map.virt);
262 release_resource (&cdb89712_flash_resource);
263 }
264
265 if (bootrom_mtd) {
Jamie Ilesee0e87b2011-05-23 10:23:40 +0100266 mtd_device_unregister(bootrom_mtd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 map_destroy(bootrom_mtd);
268 iounmap((void *)cdb89712_bootrom_map.virt);
269 release_resource (&cdb89712_bootrom_resource);
270 }
271}
272
273module_init(init_cdb89712_maps);
274module_exit(cleanup_cdb89712_maps);
275
276MODULE_AUTHOR("Ray L");
277MODULE_DESCRIPTION("ARM CDB89712 map driver");
278MODULE_LICENSE("GPL");