ia64/linux-2.6.18-xen.hg

annotate drivers/mtd/maps/autcpu12-nvram.c @ 0:831230e53067

Import 2.6.18 from kernel.org tarball.
author Ian Campbell <ian.campbell@xensource.com>
date Wed Apr 11 14:15:44 2007 +0100 (2007-04-11)
parents
children
rev   line source
ian@0 1 /*
ian@0 2 * NV-RAM memory access on autcpu12
ian@0 3 * (C) 2002 Thomas Gleixner (gleixner@autronix.de)
ian@0 4 *
ian@0 5 * $Id: autcpu12-nvram.c,v 1.9 2005/11/07 11:14:26 gleixner Exp $
ian@0 6 *
ian@0 7 * This program is free software; you can redistribute it and/or modify
ian@0 8 * it under the terms of the GNU General Public License as published by
ian@0 9 * the Free Software Foundation; either version 2 of the License, or
ian@0 10 * (at your option) any later version.
ian@0 11 *
ian@0 12 * This program is distributed in the hope that it will be useful,
ian@0 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ian@0 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ian@0 15 * GNU General Public License for more details.
ian@0 16 *
ian@0 17 * You should have received a copy of the GNU General Public License
ian@0 18 * along with this program; if not, write to the Free Software
ian@0 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ian@0 20 *
ian@0 21 */
ian@0 22
ian@0 23 #include <linux/module.h>
ian@0 24 #include <linux/types.h>
ian@0 25 #include <linux/kernel.h>
ian@0 26 #include <linux/ioport.h>
ian@0 27 #include <linux/init.h>
ian@0 28 #include <asm/io.h>
ian@0 29 #include <asm/sizes.h>
ian@0 30 #include <asm/hardware.h>
ian@0 31 #include <asm/arch/autcpu12.h>
ian@0 32 #include <linux/mtd/mtd.h>
ian@0 33 #include <linux/mtd/map.h>
ian@0 34 #include <linux/mtd/partitions.h>
ian@0 35
ian@0 36
ian@0 37 static struct mtd_info *sram_mtd;
ian@0 38
ian@0 39 struct map_info autcpu12_sram_map = {
ian@0 40 .name = "SRAM",
ian@0 41 .size = 32768,
ian@0 42 .bankwidth = 4,
ian@0 43 .phys = 0x12000000,
ian@0 44 };
ian@0 45
ian@0 46 static int __init init_autcpu12_sram (void)
ian@0 47 {
ian@0 48 int err, save0, save1;
ian@0 49
ian@0 50 autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K);
ian@0 51 if (!autcpu12_sram_map.virt) {
ian@0 52 printk("Failed to ioremap autcpu12 NV-RAM space\n");
ian@0 53 err = -EIO;
ian@0 54 goto out;
ian@0 55 }
ian@0 56 simple_map_init(&autcpu_sram_map);
ian@0 57
ian@0 58 /*
ian@0 59 * Check for 32K/128K
ian@0 60 * read ofs 0
ian@0 61 * read ofs 0x10000
ian@0 62 * Write complement to ofs 0x100000
ian@0 63 * Read and check result on ofs 0x0
ian@0 64 * Restore contents
ian@0 65 */
ian@0 66 save0 = map_read32(&autcpu12_sram_map,0);
ian@0 67 save1 = map_read32(&autcpu12_sram_map,0x10000);
ian@0 68 map_write32(&autcpu12_sram_map,~save0,0x10000);
ian@0 69 /* if we find this pattern on 0x0, we have 32K size
ian@0 70 * restore contents and exit
ian@0 71 */
ian@0 72 if ( map_read32(&autcpu12_sram_map,0) != save0) {
ian@0 73 map_write32(&autcpu12_sram_map,save0,0x0);
ian@0 74 goto map;
ian@0 75 }
ian@0 76 /* We have a 128K found, restore 0x10000 and set size
ian@0 77 * to 128K
ian@0 78 */
ian@0 79 map_write32(&autcpu12_sram_map,save1,0x10000);
ian@0 80 autcpu12_sram_map.size = SZ_128K;
ian@0 81
ian@0 82 map:
ian@0 83 sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map);
ian@0 84 if (!sram_mtd) {
ian@0 85 printk("NV-RAM probe failed\n");
ian@0 86 err = -ENXIO;
ian@0 87 goto out_ioremap;
ian@0 88 }
ian@0 89
ian@0 90 sram_mtd->owner = THIS_MODULE;
ian@0 91 sram_mtd->erasesize = 16;
ian@0 92
ian@0 93 if (add_mtd_device(sram_mtd)) {
ian@0 94 printk("NV-RAM device addition failed\n");
ian@0 95 err = -ENOMEM;
ian@0 96 goto out_probe;
ian@0 97 }
ian@0 98
ian@0 99 printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);
ian@0 100
ian@0 101 return 0;
ian@0 102
ian@0 103 out_probe:
ian@0 104 map_destroy(sram_mtd);
ian@0 105 sram_mtd = 0;
ian@0 106
ian@0 107 out_ioremap:
ian@0 108 iounmap((void *)autcpu12_sram_map.virt);
ian@0 109 out:
ian@0 110 return err;
ian@0 111 }
ian@0 112
ian@0 113 static void __exit cleanup_autcpu12_maps(void)
ian@0 114 {
ian@0 115 if (sram_mtd) {
ian@0 116 del_mtd_device(sram_mtd);
ian@0 117 map_destroy(sram_mtd);
ian@0 118 iounmap((void *)autcpu12_sram_map.virt);
ian@0 119 }
ian@0 120 }
ian@0 121
ian@0 122 module_init(init_autcpu12_sram);
ian@0 123 module_exit(cleanup_autcpu12_maps);
ian@0 124
ian@0 125 MODULE_AUTHOR("Thomas Gleixner");
ian@0 126 MODULE_DESCRIPTION("autcpu12 NV-RAM map driver");
ian@0 127 MODULE_LICENSE("GPL");