blob: d7bc4299b19c6b6d404dba070f342e329673a0a8 [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
17
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
22static struct mtd_info *flash_mtd;
23
24struct map_info cdb89712_flash_map = {
25 .name = "flash",
26 .size = FLASH_SIZE,
27 .bankwidth = FLASH_WIDTH,
28 .phys = FLASH_START,
29};
30
31struct resource cdb89712_flash_resource = {
32 .name = "Flash",
33 .start = FLASH_START,
34 .end = FLASH_START + FLASH_SIZE - 1,
35 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
36};
37
38static int __init init_cdb89712_flash (void)
39{
40 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
43 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
44 err = -EBUSY;
45 goto out;
46 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
49 if (!cdb89712_flash_map.virt) {
50 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
51 err = -EIO;
52 goto out_resource;
53 }
54 simple_map_init(&cdb89712_flash_map);
55 flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
56 if (!flash_mtd) {
57 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
58 if (flash_mtd)
59 flash_mtd->erasesize = 0x10000;
60 }
61 if (!flash_mtd) {
62 printk("FLASH probe failed\n");
63 err = -ENXIO;
64 goto out_ioremap;
65 }
66
67 flash_mtd->owner = THIS_MODULE;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 if (add_mtd_device(flash_mtd)) {
70 printk("FLASH device addition failed\n");
71 err = -ENOMEM;
72 goto out_probe;
73 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 return 0;
76
77out_probe:
78 map_destroy(flash_mtd);
79 flash_mtd = 0;
80out_ioremap:
81 iounmap((void *)cdb89712_flash_map.virt);
82out_resource:
83 release_resource (&cdb89712_flash_resource);
84out:
85 return err;
86}
87
88
89
90
91
92static struct mtd_info *sram_mtd;
93
94struct map_info cdb89712_sram_map = {
95 .name = "SRAM",
96 .size = SRAM_SIZE,
97 .bankwidth = SRAM_WIDTH,
98 .phys = SRAM_START,
99};
100
101struct resource cdb89712_sram_resource = {
102 .name = "SRAM",
103 .start = SRAM_START,
104 .end = SRAM_START + SRAM_SIZE - 1,
105 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
106};
107
108static int __init init_cdb89712_sram (void)
109{
110 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
113 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
114 err = -EBUSY;
115 goto out;
116 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
119 if (!cdb89712_sram_map.virt) {
120 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
121 err = -EIO;
122 goto out_resource;
123 }
124 simple_map_init(&cdb89712_sram_map);
125 sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
126 if (!sram_mtd) {
127 printk("SRAM probe failed\n");
128 err = -ENXIO;
129 goto out_ioremap;
130 }
131
132 sram_mtd->owner = THIS_MODULE;
133 sram_mtd->erasesize = 16;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 if (add_mtd_device(sram_mtd)) {
136 printk("SRAM device addition failed\n");
137 err = -ENOMEM;
138 goto out_probe;
139 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 return 0;
142
143out_probe:
144 map_destroy(sram_mtd);
145 sram_mtd = 0;
146out_ioremap:
147 iounmap((void *)cdb89712_sram_map.virt);
148out_resource:
149 release_resource (&cdb89712_sram_resource);
150out:
151 return err;
152}
153
154
155
156
157
158
159
160static struct mtd_info *bootrom_mtd;
161
162struct map_info cdb89712_bootrom_map = {
163 .name = "BootROM",
164 .size = BOOTROM_SIZE,
165 .bankwidth = BOOTROM_WIDTH,
166 .phys = BOOTROM_START,
167};
168
169struct resource cdb89712_bootrom_resource = {
170 .name = "BootROM",
171 .start = BOOTROM_START,
172 .end = BOOTROM_START + BOOTROM_SIZE - 1,
173 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
174};
175
176static int __init init_cdb89712_bootrom (void)
177{
178 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
181 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
182 err = -EBUSY;
183 goto out;
184 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
187 if (!cdb89712_bootrom_map.virt) {
188 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
189 err = -EIO;
190 goto out_resource;
191 }
192 simple_map_init(&cdb89712_bootrom_map);
193 bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
194 if (!bootrom_mtd) {
195 printk("BootROM probe failed\n");
196 err = -ENXIO;
197 goto out_ioremap;
198 }
199
200 bootrom_mtd->owner = THIS_MODULE;
201 bootrom_mtd->erasesize = 0x10000;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (add_mtd_device(bootrom_mtd)) {
204 printk("BootROM device addition failed\n");
205 err = -ENOMEM;
206 goto out_probe;
207 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return 0;
210
211out_probe:
212 map_destroy(bootrom_mtd);
213 bootrom_mtd = 0;
214out_ioremap:
215 iounmap((void *)cdb89712_bootrom_map.virt);
216out_resource:
217 release_resource (&cdb89712_bootrom_resource);
218out:
219 return err;
220}
221
222
223
224
225
226static int __init init_cdb89712_maps(void)
227{
228
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000229 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 -0700230 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
231
232 init_cdb89712_flash();
233 init_cdb89712_sram();
234 init_cdb89712_bootrom();
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 return 0;
237}
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240static void __exit cleanup_cdb89712_maps(void)
241{
242 if (sram_mtd) {
243 del_mtd_device(sram_mtd);
244 map_destroy(sram_mtd);
245 iounmap((void *)cdb89712_sram_map.virt);
246 release_resource (&cdb89712_sram_resource);
247 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 if (flash_mtd) {
250 del_mtd_device(flash_mtd);
251 map_destroy(flash_mtd);
252 iounmap((void *)cdb89712_flash_map.virt);
253 release_resource (&cdb89712_flash_resource);
254 }
255
256 if (bootrom_mtd) {
257 del_mtd_device(bootrom_mtd);
258 map_destroy(bootrom_mtd);
259 iounmap((void *)cdb89712_bootrom_map.virt);
260 release_resource (&cdb89712_bootrom_resource);
261 }
262}
263
264module_init(init_cdb89712_maps);
265module_exit(cleanup_cdb89712_maps);
266
267MODULE_AUTHOR("Ray L");
268MODULE_DESCRIPTION("ARM CDB89712 map driver");
269MODULE_LICENSE("GPL");