4 * redwood.c - mapper for IBM Redwood-4/5 board.
6 * Copyright 2001 MontaVista Softare Inc.
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.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
28 * History: 12/17/2001 - Armin
29 * migrated to use do_map_probe
33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/kernel.h>
37 #include <linux/mtd/mtd.h>
38 #include <linux/mtd/map.h>
39 #include <linux/mtd/partitions.h>
43 #define WINDOW_ADDR 0xffc00000
44 #define WINDOW_SIZE 0x00400000
46 __u8 redwood_flash_read8(struct map_info *map, unsigned long ofs)
48 return *(__u8 *)(map->map_priv_1 + ofs);
51 __u16 redwood_flash_read16(struct map_info *map, unsigned long ofs)
53 return *(__u16 *)(map->map_priv_1 + ofs);
56 __u32 redwood_flash_read32(struct map_info *map, unsigned long ofs)
58 return *(volatile unsigned int *)(map->map_priv_1 + ofs);
61 void redwood_flash_copy_from(struct map_info *map, void *to,
62 unsigned long from, ssize_t len)
64 memcpy(to, (void *)(map->map_priv_1 + from), len);
67 void redwood_flash_write8(struct map_info *map, __u8 d, unsigned long adr)
69 *(__u8 *)(map->map_priv_1 + adr) = d;
72 void redwood_flash_write16(struct map_info *map, __u16 d, unsigned long adr)
74 *(__u16 *)(map->map_priv_1 + adr) = d;
77 void redwood_flash_write32(struct map_info *map, __u32 d, unsigned long adr)
79 *(__u32 *)(map->map_priv_1 + adr) = d;
82 void redwood_flash_copy_to(struct map_info *map, unsigned long to,
83 const void *from, ssize_t len)
85 memcpy((void *)(map->map_priv_1 + to), from, len);
88 struct map_info redwood_flash_map = {
92 read8: redwood_flash_read8,
93 read16: redwood_flash_read16,
94 read32: redwood_flash_read32,
95 copy_from: redwood_flash_copy_from,
96 write8: redwood_flash_write8,
97 write16: redwood_flash_write16,
98 write32: redwood_flash_write32,
99 copy_to: redwood_flash_copy_to
103 static struct mtd_partition redwood_flash_partitions[] = {
105 name: "Redwood OpenBIOS Vital Product Data",
108 mask_flags: MTD_WRITEABLE /* force read-only */
111 name: "Redwood kernel",
113 size: 0x200000 - 0x10000
116 name: "Redwood OpenBIOS non-volatile storage",
119 mask_flags: MTD_WRITEABLE /* force read-only */
122 name: "Redwood filesystem",
124 size: 0x200000 - (0x10000 + 0x20000)
127 name: "Redwood OpenBIOS",
130 mask_flags: MTD_WRITEABLE /* force read-only */
133 #define NUM_REDWOOD_FLASH_PARTITIONS \
134 (sizeof(redwood_flash_partitions)/sizeof(redwood_flash_partitions[0]))
136 static struct mtd_info *redwood_mtd;
138 int __init init_redwood_flash(void)
140 printk(KERN_NOTICE "redwood: flash mapping: %x at %x\n",
141 WINDOW_SIZE, WINDOW_ADDR);
143 redwood_flash_map.map_priv_1 =
144 (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
146 if (!redwood_flash_map.map_priv_1) {
147 printk("init_redwood_flash: failed to ioremap\n");
151 redwood_mtd = do_map_probe("cfi_probe",&redwood_flash_map);
154 redwood_mtd->module = THIS_MODULE;
155 return add_mtd_partitions(redwood_mtd,
156 redwood_flash_partitions,
157 NUM_REDWOOD_FLASH_PARTITIONS);
163 static void __exit cleanup_redwood_flash(void)
166 del_mtd_partitions(redwood_mtd);
167 iounmap((void *)redwood_flash_map.map_priv_1);
168 map_destroy(redwood_mtd);
172 module_init(init_redwood_flash);
173 module_exit(cleanup_redwood_flash);