Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /* netsc520.c -- MTD map driver for AMD NetSc520 Demonstration Board
0003  *
0004  * Copyright (C) 2001 Mark Langsdorf (mark.langsdorf@amd.com)
0005  *  based on sc520cdp.c by Sysgo Real-Time Solutions GmbH
0006  *
0007  * The NetSc520 is a demonstration board for the Elan Sc520 processor available
0008  * from AMD.  It has a single back of 16 megs of 32-bit Flash ROM and another
0009  * 16 megs of SDRAM.
0010  */
0011 
0012 #include <linux/module.h>
0013 #include <linux/types.h>
0014 #include <linux/kernel.h>
0015 #include <linux/init.h>
0016 #include <asm/io.h>
0017 #include <linux/mtd/mtd.h>
0018 #include <linux/mtd/map.h>
0019 #include <linux/mtd/partitions.h>
0020 
0021 
0022 /*
0023 ** The single, 16 megabyte flash bank is divided into four virtual
0024 ** partitions.  The first partition is 768 KiB and is intended to
0025 ** store the kernel image loaded by the bootstrap loader.  The second
0026 ** partition is 256 KiB and holds the BIOS image.  The third
0027 ** partition is 14.5 MiB and is intended for the flash file system
0028 ** image.  The last partition is 512 KiB and contains another copy
0029 ** of the BIOS image and the reset vector.
0030 **
0031 ** Only the third partition should be mounted.  The first partition
0032 ** should not be mounted, but it can erased and written to using the
0033 ** MTD character routines.  The second and fourth partitions should
0034 ** not be touched - it is possible to corrupt the BIOS image by
0035 ** mounting these partitions, and potentially the board will not be
0036 ** recoverable afterwards.
0037 */
0038 
0039 /* partition_info gives details on the logical partitions that the split the
0040  * single flash device into. If the size if zero we use up to the end of the
0041  * device. */
0042 static const struct mtd_partition partition_info[] = {
0043     {
0044         .name = "NetSc520 boot kernel",
0045         .offset = 0,
0046         .size = 0xc0000
0047     },
0048     {
0049         .name = "NetSc520 Low BIOS",
0050         .offset = 0xc0000,
0051         .size = 0x40000
0052     },
0053     {
0054         .name = "NetSc520 file system",
0055         .offset = 0x100000,
0056         .size = 0xe80000
0057     },
0058     {
0059         .name = "NetSc520 High BIOS",
0060         .offset = 0xf80000,
0061         .size = 0x80000
0062     },
0063 };
0064 #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
0065 
0066 #define WINDOW_SIZE 0x00100000
0067 #define WINDOW_ADDR 0x00200000
0068 
0069 static struct map_info netsc520_map = {
0070     .name = "netsc520 Flash Bank",
0071     .size = WINDOW_SIZE,
0072     .bankwidth = 4,
0073     .phys = WINDOW_ADDR,
0074 };
0075 
0076 #define NUM_FLASH_BANKS ARRAY_SIZE(netsc520_map)
0077 
0078 static struct mtd_info *mymtd;
0079 
0080 static int __init init_netsc520(void)
0081 {
0082     printk(KERN_NOTICE "NetSc520 flash device: 0x%Lx at 0x%Lx\n",
0083             (unsigned long long)netsc520_map.size,
0084             (unsigned long long)netsc520_map.phys);
0085     netsc520_map.virt = ioremap(netsc520_map.phys, netsc520_map.size);
0086 
0087     if (!netsc520_map.virt) {
0088         printk("Failed to ioremap\n");
0089         return -EIO;
0090     }
0091 
0092     simple_map_init(&netsc520_map);
0093 
0094     mymtd = do_map_probe("cfi_probe", &netsc520_map);
0095     if(!mymtd)
0096         mymtd = do_map_probe("map_ram", &netsc520_map);
0097     if(!mymtd)
0098         mymtd = do_map_probe("map_rom", &netsc520_map);
0099 
0100     if (!mymtd) {
0101         iounmap(netsc520_map.virt);
0102         return -ENXIO;
0103     }
0104 
0105     mymtd->owner = THIS_MODULE;
0106     mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
0107     return 0;
0108 }
0109 
0110 static void __exit cleanup_netsc520(void)
0111 {
0112     if (mymtd) {
0113         mtd_device_unregister(mymtd);
0114         map_destroy(mymtd);
0115     }
0116     if (netsc520_map.virt) {
0117         iounmap(netsc520_map.virt);
0118         netsc520_map.virt = NULL;
0119     }
0120 }
0121 
0122 module_init(init_netsc520);
0123 module_exit(cleanup_netsc520);
0124 
0125 MODULE_LICENSE("GPL");
0126 MODULE_AUTHOR("Mark Langsdorf <mark.langsdorf@amd.com>");
0127 MODULE_DESCRIPTION("MTD map driver for AMD NetSc520 Demonstration Board");