]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mtd/maps/cdb89712.c
e5059aa3c724b189613db3ab6a61255a91d2f3be
[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
19
20 static struct mtd_info *flash_mtd;
21
22 struct map_info cdb89712_flash_map = {
23         .name = "flash",
24         .size = FLASH_SIZE,
25         .bankwidth = FLASH_WIDTH,
26         .phys = FLASH_START,
27 };
28
29 struct resource cdb89712_flash_resource = {
30         .name =   "Flash",
31         .start =  FLASH_START,
32         .end =    FLASH_START + FLASH_SIZE - 1,
33         .flags =  IORESOURCE_IO | IORESOURCE_BUSY,
34 };
35
36 static int __init init_cdb89712_flash (void)
37 {
38         int err;
39
40         if (request_resource (&ioport_resource, &cdb89712_flash_resource)) {
41                 printk(KERN_NOTICE "Failed to reserve Cdb89712 FLASH space\n");
42                 err = -EBUSY;
43                 goto out;
44         }
45
46         cdb89712_flash_map.virt = ioremap(FLASH_START, FLASH_SIZE);
47         if (!cdb89712_flash_map.virt) {
48                 printk(KERN_NOTICE "Failed to ioremap Cdb89712 FLASH space\n");
49                 err = -EIO;
50                 goto out_resource;
51         }
52         simple_map_init(&cdb89712_flash_map);
53         flash_mtd = do_map_probe("cfi_probe", &cdb89712_flash_map);
54         if (!flash_mtd) {
55                 flash_mtd = do_map_probe("map_rom", &cdb89712_flash_map);
56                 if (flash_mtd)
57                         flash_mtd->erasesize = 0x10000;
58         }
59         if (!flash_mtd) {
60                 printk("FLASH probe failed\n");
61                 err = -ENXIO;
62                 goto out_ioremap;
63         }
64
65         flash_mtd->owner = THIS_MODULE;
66
67         if (add_mtd_device(flash_mtd)) {
68                 printk("FLASH device addition failed\n");
69                 err = -ENOMEM;
70                 goto out_probe;
71         }
72
73         return 0;
74
75 out_probe:
76         map_destroy(flash_mtd);
77         flash_mtd = 0;
78 out_ioremap:
79         iounmap((void *)cdb89712_flash_map.virt);
80 out_resource:
81         release_resource (&cdb89712_flash_resource);
82 out:
83         return err;
84 }
85
86
87
88
89
90 static struct mtd_info *sram_mtd;
91
92 struct map_info cdb89712_sram_map = {
93         .name = "SRAM",
94         .size = SRAM_SIZE,
95         .bankwidth = SRAM_WIDTH,
96         .phys = SRAM_START,
97 };
98
99 struct resource cdb89712_sram_resource = {
100         .name =   "SRAM",
101         .start =  SRAM_START,
102         .end =    SRAM_START + SRAM_SIZE - 1,
103         .flags =  IORESOURCE_IO | IORESOURCE_BUSY,
104 };
105
106 static int __init init_cdb89712_sram (void)
107 {
108         int err;
109
110         if (request_resource (&ioport_resource, &cdb89712_sram_resource)) {
111                 printk(KERN_NOTICE "Failed to reserve Cdb89712 SRAM space\n");
112                 err = -EBUSY;
113                 goto out;
114         }
115
116         cdb89712_sram_map.virt = ioremap(SRAM_START, SRAM_SIZE);
117         if (!cdb89712_sram_map.virt) {
118                 printk(KERN_NOTICE "Failed to ioremap Cdb89712 SRAM space\n");
119                 err = -EIO;
120                 goto out_resource;
121         }
122         simple_map_init(&cdb89712_sram_map);
123         sram_mtd = do_map_probe("map_ram", &cdb89712_sram_map);
124         if (!sram_mtd) {
125                 printk("SRAM probe failed\n");
126                 err = -ENXIO;
127                 goto out_ioremap;
128         }
129
130         sram_mtd->owner = THIS_MODULE;
131         sram_mtd->erasesize = 16;
132
133         if (add_mtd_device(sram_mtd)) {
134                 printk("SRAM device addition failed\n");
135                 err = -ENOMEM;
136                 goto out_probe;
137         }
138
139         return 0;
140
141 out_probe:
142         map_destroy(sram_mtd);
143         sram_mtd = 0;
144 out_ioremap:
145         iounmap((void *)cdb89712_sram_map.virt);
146 out_resource:
147         release_resource (&cdb89712_sram_resource);
148 out:
149         return err;
150 }
151
152
153
154
155
156
157
158 static struct mtd_info *bootrom_mtd;
159
160 struct map_info cdb89712_bootrom_map = {
161         .name = "BootROM",
162         .size = BOOTROM_SIZE,
163         .bankwidth = BOOTROM_WIDTH,
164         .phys = BOOTROM_START,
165 };
166
167 struct resource cdb89712_bootrom_resource = {
168         .name =   "BootROM",
169         .start =  BOOTROM_START,
170         .end =    BOOTROM_START + BOOTROM_SIZE - 1,
171         .flags =  IORESOURCE_IO | IORESOURCE_BUSY,
172 };
173
174 static int __init init_cdb89712_bootrom (void)
175 {
176         int err;
177
178         if (request_resource (&ioport_resource, &cdb89712_bootrom_resource)) {
179                 printk(KERN_NOTICE "Failed to reserve Cdb89712 BOOTROM space\n");
180                 err = -EBUSY;
181                 goto out;
182         }
183
184         cdb89712_bootrom_map.virt = ioremap(BOOTROM_START, BOOTROM_SIZE);
185         if (!cdb89712_bootrom_map.virt) {
186                 printk(KERN_NOTICE "Failed to ioremap Cdb89712 BootROM space\n");
187                 err = -EIO;
188                 goto out_resource;
189         }
190         simple_map_init(&cdb89712_bootrom_map);
191         bootrom_mtd = do_map_probe("map_rom", &cdb89712_bootrom_map);
192         if (!bootrom_mtd) {
193                 printk("BootROM probe failed\n");
194                 err = -ENXIO;
195                 goto out_ioremap;
196         }
197
198         bootrom_mtd->owner = THIS_MODULE;
199         bootrom_mtd->erasesize = 0x10000;
200
201         if (add_mtd_device(bootrom_mtd)) {
202                 printk("BootROM device addition failed\n");
203                 err = -ENOMEM;
204                 goto out_probe;
205         }
206
207         return 0;
208
209 out_probe:
210         map_destroy(bootrom_mtd);
211         bootrom_mtd = 0;
212 out_ioremap:
213         iounmap((void *)cdb89712_bootrom_map.virt);
214 out_resource:
215         release_resource (&cdb89712_bootrom_resource);
216 out:
217         return err;
218 }
219
220
221
222
223
224 static int __init init_cdb89712_maps(void)
225 {
226
227         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",
228                FLASH_SIZE, FLASH_START, SRAM_SIZE, SRAM_START, BOOTROM_SIZE, BOOTROM_START);
229
230         init_cdb89712_flash();
231         init_cdb89712_sram();
232         init_cdb89712_bootrom();
233
234         return 0;
235 }
236
237
238 static void __exit cleanup_cdb89712_maps(void)
239 {
240         if (sram_mtd) {
241                 del_mtd_device(sram_mtd);
242                 map_destroy(sram_mtd);
243                 iounmap((void *)cdb89712_sram_map.virt);
244                 release_resource (&cdb89712_sram_resource);
245         }
246
247         if (flash_mtd) {
248                 del_mtd_device(flash_mtd);
249                 map_destroy(flash_mtd);
250                 iounmap((void *)cdb89712_flash_map.virt);
251                 release_resource (&cdb89712_flash_resource);
252         }
253
254         if (bootrom_mtd) {
255                 del_mtd_device(bootrom_mtd);
256                 map_destroy(bootrom_mtd);
257                 iounmap((void *)cdb89712_bootrom_map.virt);
258                 release_resource (&cdb89712_bootrom_resource);
259         }
260 }
261
262 module_init(init_cdb89712_maps);
263 module_exit(cleanup_cdb89712_maps);
264
265 MODULE_AUTHOR("Ray L");
266 MODULE_DESCRIPTION("ARM CDB89712 map driver");
267 MODULE_LICENSE("GPL");