ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / ebony.c
1 /*
2  * $Id: ebony.c,v 1.8 2003/06/23 11:48:18 dwmw2 Exp $
3  * 
4  * Mapping for Ebony user flash
5  *
6  * Matt Porter <mporter@mvista.com>
7  *
8  * Copyright 2002 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 <asm/io.h>
25 #include <asm/ibm440.h>
26 #include <platforms/ebony.h>
27
28 static struct mtd_info *flash;
29
30 static struct map_info ebony_small_map = {
31         .name =         "Ebony small flash",
32         .size =         EBONY_SMALL_FLASH_SIZE,
33         .buswidth =     1,
34 };
35
36 static struct map_info ebony_large_map = {
37         .name =         "Ebony large flash",
38         .size =         EBONY_LARGE_FLASH_SIZE,
39         .buswidth =     1,
40 };
41
42 static struct mtd_partition ebony_small_partitions[] = {
43         {
44                 .name =   "OpenBIOS",
45                 .offset = 0x0,
46                 .size =   0x80000,
47         }
48 };
49
50 static struct mtd_partition ebony_large_partitions[] = {
51         {
52                 .name =   "fs",
53                 .offset = 0,
54                 .size =   0x380000,
55         },
56         {
57                 .name =   "firmware",
58                 .offset = 0x380000,
59                 .size =   0x80000,
60         }
61 };
62
63 int __init init_ebony(void)
64 {
65         u8 fpga0_reg;
66         unsigned long fpga0_adr;
67         unsigned long long small_flash_base, large_flash_base;
68
69         fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
70         if (!fpga0_adr)
71                 return -ENOMEM;
72
73         fpga0_reg = readb(fpga0_adr);
74         iounmap64(fpga0_adr);
75
76         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
77                         !EBONY_FLASH_SEL(fpga0_reg))
78                 small_flash_base = EBONY_SMALL_FLASH_HIGH2;
79         else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
80                         EBONY_FLASH_SEL(fpga0_reg))
81                 small_flash_base = EBONY_SMALL_FLASH_HIGH1;
82         else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
83                         !EBONY_FLASH_SEL(fpga0_reg))
84                 small_flash_base = EBONY_SMALL_FLASH_LOW2;
85         else
86                 small_flash_base = EBONY_SMALL_FLASH_LOW1;
87                         
88         if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
89                         !EBONY_ONBRD_FLASH_EN(fpga0_reg))
90                 large_flash_base = EBONY_LARGE_FLASH_LOW;
91         else
92                 large_flash_base = EBONY_LARGE_FLASH_HIGH;
93
94         ebony_small_map.phys = small_flash_base;
95         ebony_small_map.virt =
96                 (unsigned long)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("map_rom", &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 =
118                 (unsigned long)ioremap64(large_flash_base,
119                                          ebony_large_map.size);
120
121         if (!ebony_large_map.virt) {
122                 printk("Failed to ioremap flash\n");
123                 return -EIO;
124         }
125
126         simple_map_init(&ebony_large_map);
127
128         flash = do_map_probe("cfi_probe", &ebony_large_map);
129         if (flash) {
130                 flash->owner = THIS_MODULE;
131                 add_mtd_partitions(flash, ebony_large_partitions,
132                                         ARRAY_SIZE(ebony_large_partitions));
133         } else {
134                 printk("map probe failed for flash\n");
135                 return -ENXIO;
136         }
137
138         return 0;
139 }
140
141 static void __exit cleanup_ebony(void)
142 {
143         if (flash) {
144                 del_mtd_partitions(flash);
145                 map_destroy(flash);
146         }
147
148         if (ebony_small_map.virt) {
149                 iounmap((void *)ebony_small_map.virt);
150                 ebony_small_map.virt = 0;
151         }
152
153         if (ebony_large_map.virt) {
154                 iounmap((void *)ebony_large_map.virt);
155                 ebony_large_map.virt = 0;
156         }
157 }
158
159 module_init(init_ebony);
160 module_exit(cleanup_ebony);
161
162 MODULE_LICENSE("GPL");
163 MODULE_AUTHOR("Matt Porter <mporter@mvista.com>");
164 MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards");