11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* netsc520.c -- MTD map driver for AMD NetSc520 Demonstration Board 21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com) 41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * based on sc520cdp.c by Sysgo Real-Time Solutions GmbH 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify 71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License as published by 81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (at your option) any later version. 101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is distributed in the hope that it will be useful, 121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License for more details. 151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License 171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * along with this program; if not, write to the Free Software 181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * The NetSc520 is a demonstration board for the Elan Sc520 processor available 211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * from AMD. It has a single back of 16 megs of 32-bit Flash ROM and another 221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * 16 megs of SDRAM. 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/module.h> 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/types.h> 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/kernel.h> 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/init.h> 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/io.h> 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mtd/mtd.h> 311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mtd/map.h> 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <linux/mtd/partitions.h> 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** The single, 16 megabyte flash bank is divided into four virtual 371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** partitions. The first partition is 768 KiB and is intended to 381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** store the kernel image loaded by the bootstrap loader. The second 3969f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner** partition is 256 KiB and holds the BIOS image. The third 401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** partition is 14.5 MiB and is intended for the flash file system 411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** image. The last partition is 512 KiB and contains another copy 421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** of the BIOS image and the reset vector. 431da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** 441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** Only the third partition should be mounted. The first partition 451da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** should not be mounted, but it can erased and written to using the 461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** MTD character routines. The second and fourth partitions should 471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** not be touched - it is possible to corrupt the BIOS image by 481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** mounting these partitions, and potentially the board will not be 491da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds** recoverable afterwards. 501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds*/ 511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 5269f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner/* partition_info gives details on the logical partitions that the split the 531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * single flash device into. If the size if zero we use up to the end of the 541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * device. */ 551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct mtd_partition partition_info[]={ 5669f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner { 5769f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .name = "NetSc520 boot kernel", 5869f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .offset = 0, 591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = 0xc0000 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 6169f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner { 6269f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .name = "NetSc520 Low BIOS", 6369f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .offset = 0xc0000, 641da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = 0x40000 651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 6669f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner { 6769f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .name = "NetSc520 file system", 6869f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .offset = 0x100000, 691da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = 0xe80000 701da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 7169f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner { 7269f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .name = "NetSc520 High BIOS", 7369f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner .offset = 0xf80000, 741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = 0x80000 751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds }, 761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 7787d10f3c7954d143e509a2af2bca2a27aeb3114dTobias Klauser#define NUM_PARTITIONS ARRAY_SIZE(partition_info) 781da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WINDOW_SIZE 0x00100000 801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define WINDOW_ADDR 0x00200000 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 821da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct map_info netsc520_map = { 831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .name = "netsc520 Flash Bank", 841da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .size = WINDOW_SIZE, 851da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .bankwidth = 4, 861da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds .phys = WINDOW_ADDR, 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}; 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 8987d10f3c7954d143e509a2af2bca2a27aeb3114dTobias Klauser#define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map) 901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic struct mtd_info *mymtd; 921da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic int __init init_netsc520(void) 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 953ce32f5d12735b11c002057378879b3366f09825Andrew Morton printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n", 963ce32f5d12735b11c002057378879b3366f09825Andrew Morton (unsigned long long)netsc520_map.size, 973ce32f5d12735b11c002057378879b3366f09825Andrew Morton (unsigned long long)netsc520_map.phys); 981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netsc520_map.virt = ioremap_nocache(netsc520_map.phys, netsc520_map.size); 991da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!netsc520_map.virt) { 1011da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds printk("Failed to ioremap_nocache\n"); 1021da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -EIO; 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1041da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds simple_map_init(&netsc520_map); 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mymtd = do_map_probe("cfi_probe", &netsc520_map); 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if(!mymtd) 1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mymtd = do_map_probe("map_ram", &netsc520_map); 1101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if(!mymtd) 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mymtd = do_map_probe("map_rom", &netsc520_map); 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (!mymtd) { 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iounmap(netsc520_map.virt); 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return -ENXIO; 1161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 11769f34c98c1416eb74c55e38a21dbf3e294966514Thomas Gleixner 1181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds mymtd->owner = THIS_MODULE; 119ee0e87b174bb41f0310cf089262bf5dd8f95a212Jamie Iles mtd_device_register(mymtd, partition_info, NUM_PARTITIONS); 1201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds return 0; 1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic void __exit cleanup_netsc520(void) 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{ 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (mymtd) { 126ee0e87b174bb41f0310cf089262bf5dd8f95a212Jamie Iles mtd_device_unregister(mymtd); 1271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds map_destroy(mymtd); 1281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds if (netsc520_map.virt) { 1301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds iounmap(netsc520_map.virt); 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds netsc520_map.virt = NULL; 1321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds } 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds} 1341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_init(init_netsc520); 1361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsmodule_exit(cleanup_netsc520); 1371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_LICENSE("GPL"); 1391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>"); 1401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus TorvaldsMODULE_DESCRIPTION("MTD map driver for AMD NetSc520 Demonstration Board"); 141