1 /* netsc520.c -- MTD map driver for AMD NetSc520 Demonstration Board
3 * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com)
4 * based on sc520cdp.c by Sysgo Real-Time Solutions GmbH
6 * $Id: netsc520.c,v 1.5 2001/10/02 15:05:14 dwmw2 Exp $
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 * The NetSc520 is a demonstration board for the Elan Sc520 processor available
23 * from AMD. It has a single back of 16 megs of 32-bit Flash ROM and another
27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/kernel.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/map.h>
33 #include <linux/mtd/partitions.h>
37 ** The single, 16 megabyte flash bank is divided into four virtual
38 ** partitions. The first partition is 768 KiB and is intended to
39 ** store the kernel image loaded by the bootstrap loader. The second
40 ** partition is 256 KiB and holds the BIOS image. The third
41 ** partition is 14.5 MiB and is intended for the flash file system
42 ** image. The last partition is 512 KiB and contains another copy
43 ** of the BIOS image and the reset vector.
45 ** Only the third partition should be mounted. The first partition
46 ** should not be mounted, but it can erased and written to using the
47 ** MTD character routines. The second and fourth partitions should
48 ** not be touched - it is possible to corrupt the BIOS image by
49 ** mounting these partitions, and potentially the board will not be
50 ** recoverable afterwards.
53 static __u8 netsc520_read8(struct map_info *map, unsigned long ofs)
55 return readb(map->map_priv_1 + ofs);
58 static __u16 netsc520_read16(struct map_info *map, unsigned long ofs)
60 return readw(map->map_priv_1 + ofs);
63 static __u32 netsc520_read32(struct map_info *map, unsigned long ofs)
65 return readl(map->map_priv_1 + ofs);
68 static void netsc520_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
70 memcpy_fromio(to, (void *)(map->map_priv_1 + from), len);
73 static void netsc520_write8(struct map_info *map, __u8 d, unsigned long adr)
75 writeb(d, map->map_priv_1 + adr);
78 static void netsc520_write16(struct map_info *map, __u16 d, unsigned long adr)
80 writew(d, map->map_priv_1 + adr);
83 static void netsc520_write32(struct map_info *map, __u32 d, unsigned long adr)
85 writel(d, map->map_priv_1 + adr);
88 static void netsc520_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
90 memcpy_toio((void *)(map->map_priv_1 + to), from, len);
93 /* partition_info gives details on the logical partitions that the split the
94 * single flash device into. If the size if zero we use up to the end of the
96 static struct mtd_partition partition_info[]={
98 name: "NetSc520 boot kernel",
103 name: "NetSc520 Low BIOS",
108 name: "NetSc520 file system",
113 name: "NetSc520 High BIOS",
118 #define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0]))
121 * If no idea what is going on here. This is taken from the FlashFX stuff.
126 #define WINDOW_SIZE 0x00100000
127 #define WINDOW_ADDR 0x00200000
129 static struct map_info netsc520_map = {
130 name: "netsc520 Flash Bank",
133 read8: netsc520_read8,
134 read16: netsc520_read16,
135 read32: netsc520_read32,
136 copy_from: netsc520_copy_from,
137 write8: netsc520_write8,
138 write16: netsc520_write16,
139 write32: netsc520_write32,
140 copy_to: netsc520_copy_to,
141 map_priv_2: WINDOW_ADDR
144 #define NUM_FLASH_BANKS (sizeof(netsc520_map)/sizeof(struct map_info))
146 static struct mtd_info *mymtd;
148 static int __init init_netsc520(void)
150 printk(KERN_NOTICE "NetSc520 flash device: %lx at %lx\n", netsc520_map.size, netsc520_map.map_priv_2);
151 netsc520_map.map_priv_1 = (unsigned long)ioremap_nocache(netsc520_map.map_priv_2, netsc520_map.size);
153 if (!netsc520_map.map_priv_1) {
154 printk("Failed to ioremap_nocache\n");
157 mymtd = do_map_probe("cfi_probe", &netsc520_map);
159 mymtd = do_map_probe("map_ram", &netsc520_map);
161 mymtd = do_map_probe("map_rom", &netsc520_map);
164 iounmap((void *)netsc520_map.map_priv_1);
168 mymtd->module = THIS_MODULE;
169 add_mtd_partitions( mymtd, partition_info, NUM_PARTITIONS );
173 static void __exit cleanup_netsc520(void)
176 del_mtd_partitions(mymtd);
179 if (netsc520_map.map_priv_1) {
180 iounmap((void *)netsc520_map.map_priv_1);
181 netsc520_map.map_priv_1 = 0;
185 module_init(init_netsc520);
186 module_exit(cleanup_netsc520);
188 MODULE_LICENSE("GPL");
189 MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>");
190 MODULE_DESCRIPTION("MTD map driver for AMD NetSc520 Demonstration Board");