blob: 9f17bb6c5a9d388714c8822ea412230d918b6b38 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Flash on Cirrus CDB89712
3 *
Thomas Gleixner69f34c92005-11-07 11:15:40 +00004 * $Id: cdb89712.c,v 1.11 2005/11/07 11:14:26 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
7#include <linux/module.h>
8#include <linux/types.h>
9#include <linux/kernel.h>
10#include <linux/ioport.h>
11#include <linux/init.h>
12#include <asm/io.h>
13#include <asm/arch/hardware.h>
14#include <linux/mtd/mtd.h>
15#include <linux/mtd/map.h>
16#include <linux/mtd/partitions.h>
17
18
19
20
21static struct mtd_info *flash_mtd;
22
23struct map_info cdb89712_flash_map = {
24 .name = "flash",
25 .size = FLASH_SIZE,
26 .bankwidth = FLASH_WIDTH,
27 .phys = FLASH_START,
28};
29
30struct resource cdb89712_flash_resource = {
31 .name = "Flash",
32 .start = FLASH_START,
33 .end = FLASH_START + FLASH_SIZE - 1,
34 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
35};
36
37static int __init init_cdb89712_flash (void)
38{
39 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
42 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
43 err = -EBUSY;
44 goto out;
45 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
48 if (!cdb89712_flash_map.virt) {
49 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
50 err = -EIO;
51 goto out_resource;
52 }
53 simple_map_init(&cdb89712_flash_map);
54 flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
55 if (!flash_mtd) {
56 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
57 if (flash_mtd)
58 flash_mtd->erasesize = 0x10000;
59 }
60 if (!flash_mtd) {
61 printk("FLASH probe failed\n");
62 err = -ENXIO;
63 goto out_ioremap;
64 }
65
66 flash_mtd->owner = THIS_MODULE;
Thomas Gleixner69f34c92005-11-07 11:15:40 +000067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 if (add_mtd_device(flash_mtd)) {
69 printk("FLASH device addition failed\n");
70 err = -ENOMEM;
71 goto out_probe;
72 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +000073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return 0;
75
76out_probe:
77 map_destroy(flash_mtd);
78 flash_mtd = 0;
79out_ioremap:
80 iounmap((void *)cdb89712_flash_map.virt);
81out_resource:
82 release_resource (&cdb89712_flash_resource);
83out:
84 return err;
85}
86
87
88
89
90
91static struct mtd_info *sram_mtd;
92
93struct map_info cdb89712_sram_map = {
94 .name = "SRAM",
95 .size = SRAM_SIZE,
96 .bankwidth = SRAM_WIDTH,
97 .phys = SRAM_START,
98};
99
100struct resource cdb89712_sram_resource = {
101 .name = "SRAM",
102 .start = SRAM_START,
103 .end = SRAM_START + SRAM_SIZE - 1,
104 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
105};
106
107static int __init init_cdb89712_sram (void)
108{
109 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
112 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
113 err = -EBUSY;
114 goto out;
115 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
118 if (!cdb89712_sram_map.virt) {
119 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
120 err = -EIO;
121 goto out_resource;
122 }
123 simple_map_init(&cdb89712_sram_map);
124 sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
125 if (!sram_mtd) {
126 printk("SRAM probe failed\n");
127 err = -ENXIO;
128 goto out_ioremap;
129 }
130
131 sram_mtd->owner = THIS_MODULE;
132 sram_mtd->erasesize = 16;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 if (add_mtd_device(sram_mtd)) {
135 printk("SRAM device addition failed\n");
136 err = -ENOMEM;
137 goto out_probe;
138 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 return 0;
141
142out_probe:
143 map_destroy(sram_mtd);
144 sram_mtd = 0;
145out_ioremap:
146 iounmap((void *)cdb89712_sram_map.virt);
147out_resource:
148 release_resource (&cdb89712_sram_resource);
149out:
150 return err;
151}
152
153
154
155
156
157
158
159static struct mtd_info *bootrom_mtd;
160
161struct map_info cdb89712_bootrom_map = {
162 .name = "BootROM",
163 .size = BOOTROM_SIZE,
164 .bankwidth = BOOTROM_WIDTH,
165 .phys = BOOTROM_START,
166};
167
168struct resource cdb89712_bootrom_resource = {
169 .name = "BootROM",
170 .start = BOOTROM_START,
171 .end = BOOTROM_START + BOOTROM_SIZE - 1,
172 .flags = IORESOURCE_IO | IORESOURCE_BUSY,
173};
174
175static int __init init_cdb89712_bootrom (void)
176{
177 int err;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
180 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
181 err = -EBUSY;
182 goto out;
183 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
186 if (!cdb89712_bootrom_map.virt) {
187 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
188 err = -EIO;
189 goto out_resource;
190 }
191 simple_map_init(&cdb89712_bootrom_map);
192 bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
193 if (!bootrom_mtd) {
194 printk("BootROM probe failed\n");
195 err = -ENXIO;
196 goto out_ioremap;
197 }
198
199 bootrom_mtd->owner = THIS_MODULE;
200 bootrom_mtd->erasesize = 0x10000;
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 if (add_mtd_device(bootrom_mtd)) {
203 printk("BootROM device addition failed\n");
204 err = -ENOMEM;
205 goto out_probe;
206 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 return 0;
209
210out_probe:
211 map_destroy(bootrom_mtd);
212 bootrom_mtd = 0;
213out_ioremap:
214 iounmap((void *)cdb89712_bootrom_map.virt);
215out_resource:
216 release_resource (&cdb89712_bootrom_resource);
217out:
218 return err;
219}
220
221
222
223
224
225static int __init init_cdb89712_maps(void)
226{
227
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000228 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 -0700229 FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
230
231 init_cdb89712_flash();
232 init_cdb89712_sram();
233 init_cdb89712_bootrom();
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 return 0;
236}
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239static void __exit cleanup_cdb89712_maps(void)
240{
241 if (sram_mtd) {
242 del_mtd_device(sram_mtd);
243 map_destroy(sram_mtd);
244 iounmap((void *)cdb89712_sram_map.virt);
245 release_resource (&cdb89712_sram_resource);
246 }
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (flash_mtd) {
249 del_mtd_device(flash_mtd);
250 map_destroy(flash_mtd);
251 iounmap((void *)cdb89712_flash_map.virt);
252 release_resource (&cdb89712_flash_resource);
253 }
254
255 if (bootrom_mtd) {
256 del_mtd_device(bootrom_mtd);
257 map_destroy(bootrom_mtd);
258 iounmap((void *)cdb89712_bootrom_map.virt);
259 release_resource (&cdb89712_bootrom_resource);
260 }
261}
262
263module_init(init_cdb89712_maps);
264module_exit(cleanup_cdb89712_maps);
265
266MODULE_AUTHOR("Ray L");
267MODULE_DESCRIPTION("ARM CDB89712 map driver");
268MODULE_LICENSE("GPL");