linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / mtd / maps / ocotea.c
1 /*
2  * Mapping for Ocotea user flash
3  *
4  * Matt Porter <mporter@kernel.crashing.org>
5  *
6  * Copyright 2002-2004 MontaVista Software Inc.
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  */
13
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/mtd/partitions.h>
21 #include <linux/config.h>
22 #include <asm/io.h>
23 #include <asm/ibm44x.h>
24 #include <platforms/4xx/ocotea.h>
25
26 static struct mtd_info *flash;
27
28 static struct map_info ocotea_small_map = {
29         .name =         "Ocotea small flash",
30         .size =         OCOTEA_SMALL_FLASH_SIZE,
31         .buswidth =     1,
32 };
33
34 static struct map_info ocotea_large_map = {
35         .name =         "Ocotea large flash",
36         .size =         OCOTEA_LARGE_FLASH_SIZE,
37         .buswidth =     1,
38 };
39
40 static struct mtd_partition ocotea_small_partitions[] = {
41         {
42                 .name =   "pibs",
43                 .offset = 0x0,
44                 .size =   0x100000,
45         }
46 };
47
48 static struct mtd_partition ocotea_large_partitions[] = {
49         {
50                 .name =   "fs",
51                 .offset = 0,
52                 .size =   0x300000,
53         },
54         {
55                 .name =   "firmware",
56                 .offset = 0x300000,
57                 .size =   0x100000,
58         }
59 };
60
61 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
62
63 int __init init_ocotea(void)
64 {
65         u8 fpga0_reg;
66         u8 *fpga0_adr;
67         unsigned long long small_flash_base, large_flash_base;
68
69         fpga0_adr = ioremap64(OCOTEA_FPGA_ADDR, 16);
70         if (!fpga0_adr)
71                 return -ENOMEM;
72
73         fpga0_reg = readb((unsigned long)fpga0_adr);
74         iounmap(fpga0_adr);
75
76         if (OCOTEA_BOOT_LARGE_FLASH(fpga0_reg)) {
77                 small_flash_base = OCOTEA_SMALL_FLASH_HIGH;
78                 large_flash_base = OCOTEA_LARGE_FLASH_LOW;
79         }
80         else {
81                 small_flash_base = OCOTEA_SMALL_FLASH_LOW;
82                 large_flash_base = OCOTEA_LARGE_FLASH_HIGH;
83         }
84
85         ocotea_small_map.phys = small_flash_base;
86         ocotea_small_map.virt = ioremap64(small_flash_base,
87                                          ocotea_small_map.size);
88
89         if (!ocotea_small_map.virt) {
90                 printk("Failed to ioremap flash\n");
91                 return -EIO;
92         }
93
94         simple_map_init(&ocotea_small_map);
95
96         flash = do_map_probe("map_rom", &ocotea_small_map);
97         if (flash) {
98                 flash->owner = THIS_MODULE;
99                 add_mtd_partitions(flash, ocotea_small_partitions,
100                                         NB_OF(ocotea_small_partitions));
101         } else {
102                 printk("map probe failed for flash\n");
103                 return -ENXIO;
104         }
105
106         ocotea_large_map.phys = large_flash_base;
107         ocotea_large_map.virt = ioremap64(large_flash_base,
108                                          ocotea_large_map.size);
109
110         if (!ocotea_large_map.virt) {
111                 printk("Failed to ioremap flash\n");
112                 return -EIO;
113         }
114
115         simple_map_init(&ocotea_large_map);
116
117         flash = do_map_probe("cfi_probe", &ocotea_large_map);
118         if (flash) {
119                 flash->owner = THIS_MODULE;
120                 add_mtd_partitions(flash, ocotea_large_partitions,
121                                         NB_OF(ocotea_large_partitions));
122         } else {
123                 printk("map probe failed for flash\n");
124                 return -ENXIO;
125         }
126
127         return 0;
128 }
129
130 static void __exit cleanup_ocotea(void)
131 {
132         if (flash) {
133                 del_mtd_partitions(flash);
134                 map_destroy(flash);
135         }
136
137         if (ocotea_small_map.virt) {
138                 iounmap((void *)ocotea_small_map.virt);
139                 ocotea_small_map.virt = 0;
140         }
141
142         if (ocotea_large_map.virt) {
143                 iounmap((void *)ocotea_large_map.virt);
144                 ocotea_large_map.virt = 0;
145         }
146 }
147
148 module_init(init_ocotea);
149 module_exit(cleanup_ocotea);
150
151 MODULE_LICENSE("GPL");
152 MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
153 MODULE_DESCRIPTION("MTD map and partitions for IBM 440GX Ocotea boards");