ia64/linux-2.6.18-xen.hg

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/drivers/mtd/maps/autcpu12-nvram.c	Wed Apr 11 14:15:44 2007 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +/*
     1.5 + * NV-RAM memory access on autcpu12
     1.6 + * (C) 2002 Thomas Gleixner (gleixner@autronix.de)
     1.7 + *
     1.8 + * $Id: autcpu12-nvram.c,v 1.9 2005/11/07 11:14:26 gleixner Exp $
     1.9 + *
    1.10 + * This program is free software; you can redistribute it and/or modify
    1.11 + * it under the terms of the GNU General Public License as published by
    1.12 + * the Free Software Foundation; either version 2 of the License, or
    1.13 + * (at your option) any later version.
    1.14 + *
    1.15 + * This program is distributed in the hope that it will be useful,
    1.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 + * GNU General Public License for more details.
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License
    1.21 + * along with this program; if not, write to the Free Software
    1.22 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.23 + *
    1.24 + */
    1.25 +
    1.26 +#include <linux/module.h>
    1.27 +#include <linux/types.h>
    1.28 +#include <linux/kernel.h>
    1.29 +#include <linux/ioport.h>
    1.30 +#include <linux/init.h>
    1.31 +#include <asm/io.h>
    1.32 +#include <asm/sizes.h>
    1.33 +#include <asm/hardware.h>
    1.34 +#include <asm/arch/autcpu12.h>
    1.35 +#include <linux/mtd/mtd.h>
    1.36 +#include <linux/mtd/map.h>
    1.37 +#include <linux/mtd/partitions.h>
    1.38 +
    1.39 +
    1.40 +static struct mtd_info *sram_mtd;
    1.41 +
    1.42 +struct map_info autcpu12_sram_map = {
    1.43 +	.name = "SRAM",
    1.44 +	.size = 32768,
    1.45 +	.bankwidth = 4,
    1.46 +	.phys = 0x12000000,
    1.47 +};
    1.48 +
    1.49 +static int __init init_autcpu12_sram (void)
    1.50 +{
    1.51 +	int err, save0, save1;
    1.52 +
    1.53 +	autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K);
    1.54 +	if (!autcpu12_sram_map.virt) {
    1.55 +		printk("Failed to ioremap autcpu12 NV-RAM space\n");
    1.56 +		err = -EIO;
    1.57 +		goto out;
    1.58 +	}
    1.59 +	simple_map_init(&autcpu_sram_map);
    1.60 +
    1.61 +	/*
    1.62 +	 * Check for 32K/128K
    1.63 +	 * read ofs 0
    1.64 +	 * read ofs 0x10000
    1.65 +	 * Write complement to ofs 0x100000
    1.66 +	 * Read	and check result on ofs 0x0
    1.67 +	 * Restore contents
    1.68 +	 */
    1.69 +	save0 = map_read32(&autcpu12_sram_map,0);
    1.70 +	save1 = map_read32(&autcpu12_sram_map,0x10000);
    1.71 +	map_write32(&autcpu12_sram_map,~save0,0x10000);
    1.72 +	/* if we find this pattern on 0x0, we have 32K size
    1.73 +	 * restore contents and exit
    1.74 +	 */
    1.75 +	if ( map_read32(&autcpu12_sram_map,0) != save0) {
    1.76 +		map_write32(&autcpu12_sram_map,save0,0x0);
    1.77 +		goto map;
    1.78 +	}
    1.79 +	/* We have a 128K found, restore 0x10000 and set size
    1.80 +	 * to 128K
    1.81 +	 */
    1.82 +	map_write32(&autcpu12_sram_map,save1,0x10000);
    1.83 +	autcpu12_sram_map.size = SZ_128K;
    1.84 +
    1.85 +map:
    1.86 +	sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map);
    1.87 +	if (!sram_mtd) {
    1.88 +		printk("NV-RAM probe failed\n");
    1.89 +		err = -ENXIO;
    1.90 +		goto out_ioremap;
    1.91 +	}
    1.92 +
    1.93 +	sram_mtd->owner = THIS_MODULE;
    1.94 +	sram_mtd->erasesize = 16;
    1.95 +
    1.96 +	if (add_mtd_device(sram_mtd)) {
    1.97 +		printk("NV-RAM device addition failed\n");
    1.98 +		err = -ENOMEM;
    1.99 +		goto out_probe;
   1.100 +	}
   1.101 +
   1.102 +	printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);
   1.103 +
   1.104 +	return 0;
   1.105 +
   1.106 +out_probe:
   1.107 +	map_destroy(sram_mtd);
   1.108 +	sram_mtd = 0;
   1.109 +
   1.110 +out_ioremap:
   1.111 +	iounmap((void *)autcpu12_sram_map.virt);
   1.112 +out:
   1.113 +	return err;
   1.114 +}
   1.115 +
   1.116 +static void __exit cleanup_autcpu12_maps(void)
   1.117 +{
   1.118 +	if (sram_mtd) {
   1.119 +		del_mtd_device(sram_mtd);
   1.120 +		map_destroy(sram_mtd);
   1.121 +		iounmap((void *)autcpu12_sram_map.virt);
   1.122 +	}
   1.123 +}
   1.124 +
   1.125 +module_init(init_autcpu12_sram);
   1.126 +module_exit(cleanup_autcpu12_maps);
   1.127 +
   1.128 +MODULE_AUTHOR("Thomas Gleixner");
   1.129 +MODULE_DESCRIPTION("autcpu12 NV-RAM map driver");
   1.130 +MODULE_LICENSE("GPL");