Merge branch 'release' of git://git.kernel.org/pub/scm/linux/kernel/git/aegl/linux-2.6
[sfrench/cifs-2.6.git] / drivers / mtd / maps / ebony.c
1 /*
2  * $Id: ebony.c,v 1.16 2005/11/07 11:14:26 gleixner Exp $
3  *
4  * Mapping for Ebony user flash
5  *
6  * Matt Porter <mporter@kernel.crashing.org>
7  *
8  * Copyright 2002-2004 MontaVista Software Inc.
9  *
10  * This program is free software; you can redistribute  it and/or modify it
11  * under  the terms of  the GNU General  Public License as published by the
12  * Free Software Foundation;  either version 2 of the  License, or (at your
13  * option) any later version.
14  */
15
16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/init.h>
20 #include <linux/mtd/mtd.h>
21 #include <linux/mtd/map.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/config.h>
24 #include <linux/version.h>
25 #include <asm/io.h>
26 #include <asm/ibm44x.h>
27 #include <platforms/4xx/ebony.h>
28
29 static struct mtd_info *flash;
30
31 static struct map_info ebony_small_map = {
32         .name =         "Ebony small flash",
33         .size =         EBONY_SMALL_FLASH_SIZE,
34         .bankwidth =    1,
35 };
36
37 static struct map_info ebony_large_map = {
38         .name =         "Ebony large flash",
39         .size =         EBONY_LARGE_FLASH_SIZE,
40         .bankwidth =    1,
41 };
42
43 static struct mtd_partition ebony_small_partitions[] = {
44         {
45                 .name =   "OpenBIOS",
46                 .offset = 0x0,
47                 .size =   0x80000,
48         }
49 };
50
51 static struct mtd_partition ebony_large_partitions[] = {
52         {
53                 .name =   "fs",
54                 .offset = 0,
55                 .size =   0x380000,
56         },
57         {
58                 .name =   "firmware",
59                 .offset = 0x380000,
60                 .size =   0x80000,
61         }
62 };
63
64 int __init init_ebony(void)
65 {
66         u8 fpga0_reg;
67         u8 __iomem *fpga0_adr;
68         unsigned long long small_flash_base, large_flash_base;
69
70         fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
71         if (!fpga0_adr)
72                 return -ENOMEM;
73
74         fpga0_reg = readb(fpga0_adr);
75         iounmap(fpga0_adr);
76
77         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
78                         !EBONY_FLASH_SEL(fpga0_reg))
79                 small_flash_base = EBONY_SMALL_FLASH_HIGH2;
80         else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
81                         EBONY_FLASH_SEL(fpga0_reg))
82                 small_flash_base = EBONY_SMALL_FLASH_HIGH1;
83         else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
84                         !EBONY_FLASH_SEL(fpga0_reg))
85                 small_flash_base = EBONY_SMALL_FLASH_LOW2;
86         else
87                 small_flash_base = EBONY_SMALL_FLASH_LOW1;
88
89         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
90                         !EBONY_ONBRD_FLASH_EN(fpga0_reg))
91                 large_flash_base = EBONY_LARGE_FLASH_LOW;
92         else
93                 large_flash_base = EBONY_LARGE_FLASH_HIGH;
94
95         ebony_small_map.phys = small_flash_base;
96         ebony_small_map.virt = ioremap64(small_flash_base,
97                                          ebony_small_map.size);
98
99         if (!ebony_small_map.virt) {
100                 printk("Failed to ioremap flash\n");
101                 return -EIO;
102         }
103
104         simple_map_init(&ebony_small_map);
105
106         flash = do_map_probe("jedec_probe", &ebony_small_map);
107         if (flash) {
108                 flash->owner = THIS_MODULE;
109                 add_mtd_partitions(flash, ebony_small_partitions,
110                                         ARRAY_SIZE(ebony_small_partitions));
111         } else {
112                 printk("map probe failed for flash\n");
113                 return -ENXIO;
114         }
115
116         ebony_large_map.phys = large_flash_base;
117         ebony_large_map.virt = ioremap64(large_flash_base,
118                                          ebony_large_map.size);
119
120         if (!ebony_large_map.virt) {
121                 printk("Failed to ioremap flash\n");
122                 return -EIO;
123         }
124
125         simple_map_init(&ebony_large_map);
126
127         flash = do_map_probe("jedec_probe", &ebony_large_map);
128         if (flash) {
129                 flash->owner = THIS_MODULE;
130                 add_mtd_partitions(flash, ebony_large_partitions,
131                                         ARRAY_SIZE(ebony_large_partitions));
132         } else {
133                 printk("map probe failed for flash\n");
134                 return -ENXIO;
135         }
136
137         return 0;
138 }
139
140 static void __exit cleanup_ebony(void)
141 {
142         if (flash) {
143                 del_mtd_partitions(flash);
144                 map_destroy(flash);
145         }
146
147         if (ebony_small_map.virt) {
148                 iounmap(ebony_small_map.virt);
149                 ebony_small_map.virt = NULL;
150         }
151
152         if (ebony_large_map.virt) {
153                 iounmap(ebony_large_map.virt);
154                 ebony_large_map.virt = NULL;
155         }
156 }
157
158 module_init(init_ebony);
159 module_exit(cleanup_ebony);
160
161 MODULE_LICENSE("GPL");
162 MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
163 MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards");