PCI: add Broadcom 5708S to VPD length quirk
[linux-2.6/verdex.git] / drivers / mtd / maps / walnut.c
blobe243476c8171e114ac0f9b254f7f0b932e6e3e5c
1 /*
2 * Mapping for Walnut flash
3 * (used ebony.c as a "framework")
5 * Heikki Lindholm <holindho@infradead.org>
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.
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 <asm/io.h>
22 #include <asm/ibm4xx.h>
23 #include <platforms/4xx/walnut.h>
25 /* these should be in platforms/4xx/walnut.h ? */
26 #define WALNUT_FLASH_ONBD_N(x) (x & 0x02)
27 #define WALNUT_FLASH_SRAM_SEL(x) (x & 0x01)
28 #define WALNUT_FLASH_LOW 0xFFF00000
29 #define WALNUT_FLASH_HIGH 0xFFF80000
30 #define WALNUT_FLASH_SIZE 0x80000
32 static struct mtd_info *flash;
34 static struct map_info walnut_map = {
35 .name = "Walnut flash",
36 .size = WALNUT_FLASH_SIZE,
37 .bankwidth = 1,
40 /* Actually, OpenBIOS is the last 128 KiB of the flash - better
41 * partitioning could be made */
42 static struct mtd_partition walnut_partitions[] = {
44 .name = "OpenBIOS",
45 .offset = 0x0,
46 .size = WALNUT_FLASH_SIZE,
47 /*.mask_flags = MTD_WRITEABLE, */ /* force read-only */
51 int __init init_walnut(void)
53 u8 fpga_brds1;
54 void *fpga_brds1_adr;
55 void *fpga_status_adr;
56 unsigned long flash_base;
58 /* this should already be mapped (platform/4xx/walnut.c) */
59 fpga_status_adr = ioremap(WALNUT_FPGA_BASE, 8);
60 if (!fpga_status_adr)
61 return -ENOMEM;
63 fpga_brds1_adr = fpga_status_adr+5;
64 fpga_brds1 = readb(fpga_brds1_adr);
65 /* iounmap(fpga_status_adr); */
67 if (WALNUT_FLASH_ONBD_N(fpga_brds1)) {
68 printk("The on-board flash is disabled (U79 sw 5)!");
69 iounmap(fpga_status_adr);
70 return -EIO;
72 if (WALNUT_FLASH_SRAM_SEL(fpga_brds1))
73 flash_base = WALNUT_FLASH_LOW;
74 else
75 flash_base = WALNUT_FLASH_HIGH;
77 walnut_map.phys = flash_base;
78 walnut_map.virt =
79 (void __iomem *)ioremap(flash_base, walnut_map.size);
81 if (!walnut_map.virt) {
82 printk("Failed to ioremap flash.\n");
83 iounmap(fpga_status_adr);
84 return -EIO;
87 simple_map_init(&walnut_map);
89 flash = do_map_probe("jedec_probe", &walnut_map);
90 if (flash) {
91 flash->owner = THIS_MODULE;
92 add_mtd_partitions(flash, walnut_partitions,
93 ARRAY_SIZE(walnut_partitions));
94 } else {
95 printk("map probe failed for flash\n");
96 iounmap(fpga_status_adr);
97 return -ENXIO;
100 iounmap(fpga_status_adr);
101 return 0;
104 static void __exit cleanup_walnut(void)
106 if (flash) {
107 del_mtd_partitions(flash);
108 map_destroy(flash);
111 if (walnut_map.virt) {
112 iounmap((void *)walnut_map.virt);
113 walnut_map.virt = 0;
117 module_init(init_walnut);
118 module_exit(cleanup_walnut);
120 MODULE_LICENSE("GPL");
121 MODULE_AUTHOR("Heikki Lindholm <holindho@infradead.org>");
122 MODULE_DESCRIPTION("MTD map and partitions for IBM 405GP Walnut boards");