]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mtd/maps/cdb89712.c
d7bc4299b19c6b6d404dba070f342e329673a0a8
[linux-2.6-omap-h63xx.git] / drivers / mtd / maps / cdb89712.c
1 /*
2  * Flash on Cirrus CDB89712
3  *
4  */
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>
12 #include <mach/hardware.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/map.h>
15 #include <linux/mtd/partitions.h>
16
17
18 #define FLASH_START      0x00000000
19 #define FLASH_SIZE       0x800000
20 #define FLASH_WIDTH      4
21
22 static struct mtd_info *flash_mtd;
23
24 struct map_info cdb89712_flash_map = {
25         .name = "flash",
26         .size = FLASH_SIZE,
27         .bankwidth = FLASH_WIDTH,
28         .phys = FLASH_START,
29 };
30
31 struct 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
38 static int __init init_cdb89712_flash (void)
39 {
40         int err;
41
42         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         }
47
48         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;
68
69         if (add_mtd_device(flash_mtd)) {
70                 printk("FLASH device addition failed\n");
71                 err = -ENOMEM;
72                 goto out_probe;
73         }
74
75         return 0;
76
77 out_probe:
78         map_destroy(flash_mtd);
79         flash_mtd = 0;
80 out_ioremap:
81         iounmap((void *)cdb89712_flash_map.virt);
82 out_resource:
83         release_resource (&cdb89712_flash_resource);
84 out:
85         return err;
86 }
87
88
89
90
91
92 static struct mtd_info *sram_mtd;
93
94 struct map_info cdb89712_sram_map = {
95         .name = "SRAM",
96         .size = SRAM_SIZE,
97         .bankwidth = SRAM_WIDTH,
98         .phys = SRAM_START,
99 };
100
101 struct 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
108 static int __init init_cdb89712_sram (void)
109 {
110         int err;
111
112         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         }
117
118         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;
134
135         if (add_mtd_device(sram_mtd)) {
136                 printk("SRAM device addition failed\n");
137                 err = -ENOMEM;
138                 goto out_probe;
139         }
140
141         return 0;
142
143 out_probe:
144         map_destroy(sram_mtd);
145         sram_mtd = 0;
146 out_ioremap:
147         iounmap((void *)cdb89712_sram_map.virt);
148 out_resource:
149         release_resource (&cdb89712_sram_resource);
150 out:
151         return err;
152 }
153
154
155
156
157
158
159
160 static struct mtd_info *bootrom_mtd;
161
162 struct map_info cdb89712_bootrom_map = {
163         .name = "BootROM",
164         .size = BOOTROM_SIZE,
165         .bankwidth = BOOTROM_WIDTH,
166         .phys = BOOTROM_START,
167 };
168
169 struct 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
176 static int __init init_cdb89712_bootrom (void)
177 {
178         int err;
179
180         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         }
185
186         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;
202
203         if (add_mtd_device(bootrom_mtd)) {
204                 printk("BootROM device addition failed\n");
205                 err = -ENOMEM;
206                 goto out_probe;
207         }
208
209         return 0;
210
211 out_probe:
212         map_destroy(bootrom_mtd);
213         bootrom_mtd = 0;
214 out_ioremap:
215         iounmap((void *)cdb89712_bootrom_map.virt);
216 out_resource:
217         release_resource (&cdb89712_bootrom_resource);
218 out:
219         return err;
220 }
221
222
223
224
225
226 static int __init init_cdb89712_maps(void)
227 {
228
229         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",
230                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();
235
236         return 0;
237 }
238
239
240 static 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         }
248
249         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
264 module_init(init_cdb89712_maps);
265 module_exit(cleanup_cdb89712_maps);
266
267 MODULE_AUTHOR("Ray L");
268 MODULE_DESCRIPTION("ARM CDB89712 map driver");
269 MODULE_LICENSE("GPL");