Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / mtd / maps / walnut.c
1 /*
2  * $Id: walnut.c,v 1.3 2005/11/07 11:14:29 gleixner Exp $
3  *
4  * Mapping for Walnut flash
5  * (used ebony.c as a "framework")
6  *
7  * Heikki Lindholm <holindho@infradead.org>
8  *
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/ibm4xx.h>
26 #include <platforms/4xx/walnut.h>
27
28 /* these should be in platforms/4xx/walnut.h ? */
29 #define WALNUT_FLASH_ONBD_N(x)          (x & 0x02)
30 #define WALNUT_FLASH_SRAM_SEL(x)        (x & 0x01)
31 #define WALNUT_FLASH_LOW                0xFFF00000
32 #define WALNUT_FLASH_HIGH               0xFFF80000
33 #define WALNUT_FLASH_SIZE               0x80000
34
35 static struct mtd_info *flash;
36
37 static struct map_info walnut_map = {
38         .name =         "Walnut flash",
39         .size =         WALNUT_FLASH_SIZE,
40         .bankwidth =    1,
41 };
42
43 /* Actually, OpenBIOS is the last 128 KiB of the flash - better
44  * partitioning could be made */
45 static struct mtd_partition walnut_partitions[] = {
46         {
47                 .name =   "OpenBIOS",
48                 .offset = 0x0,
49                 .size =   WALNUT_FLASH_SIZE,
50                 /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */
51         }
52 };
53
54 int __init init_walnut(void)
55 {
56         u8 fpga_brds1;
57         void *fpga_brds1_adr;
58         void *fpga_status_adr;
59         unsigned long flash_base;
60
61         /* this should already be mapped (platform/4xx/walnut.c) */
62         fpga_status_adr = ioremap(WALNUT_FPGA_BASE, 8);
63         if (!fpga_status_adr)
64                 return -ENOMEM;
65
66         fpga_brds1_adr = fpga_status_adr+5;
67         fpga_brds1 = readb(fpga_brds1_adr);
68         /* iounmap(fpga_status_adr); */
69
70         if (WALNUT_FLASH_ONBD_N(fpga_brds1)) {
71                 printk("The on-board flash is disabled (U79 sw 5)!");
72                 return -EIO;
73         }
74         if (WALNUT_FLASH_SRAM_SEL(fpga_brds1))
75                 flash_base = WALNUT_FLASH_LOW;
76         else
77                 flash_base = WALNUT_FLASH_HIGH;
78
79         walnut_map.phys = flash_base;
80         walnut_map.virt =
81                 (void __iomem *)ioremap(flash_base, walnut_map.size);
82
83         if (!walnut_map.virt) {
84                 printk("Failed to ioremap flash.\n");
85                 return -EIO;
86         }
87
88         simple_map_init(&walnut_map);
89
90         flash = do_map_probe("jedec_probe", &walnut_map);
91         if (flash) {
92                 flash->owner = THIS_MODULE;
93                 add_mtd_partitions(flash, walnut_partitions,
94                                         ARRAY_SIZE(walnut_partitions));
95         } else {
96                 printk("map probe failed for flash\n");
97                 return -ENXIO;
98         }
99
100         return 0;
101 }
102
103 static void __exit cleanup_walnut(void)
104 {
105         if (flash) {
106                 del_mtd_partitions(flash);
107                 map_destroy(flash);
108         }
109
110         if (walnut_map.virt) {
111                 iounmap((void *)walnut_map.virt);
112                 walnut_map.virt = 0;
113         }
114 }
115
116 module_init(init_walnut);
117 module_exit(cleanup_walnut);
118
119 MODULE_LICENSE("GPL");
120 MODULE_AUTHOR("Heikki Lindholm <holindho@infradead.org>");
121 MODULE_DESCRIPTION("MTD map and partitions for IBM 405GP Walnut boards");