2 * NV-RAM memory access on autcpu12
3 * (C) 2002 Thomas Gleixner (gleixner@autronix.de)
5 * $Id: autcpu12-nvram.c,v 1.1 2002/02/22 09:30:24 gleixner Exp $
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/kernel.h>
26 #include <linux/ioport.h>
28 #include <asm/sizes.h>
29 #include <asm/hardware.h>
30 #include <asm/arch/autcpu12.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/map.h>
33 #include <linux/mtd/partitions.h>
35 __u8 autcpu12_read8(struct map_info *map, unsigned long ofs)
37 return __raw_readb(map->map_priv_1 + ofs);
40 __u16 autcpu12_read16(struct map_info *map, unsigned long ofs)
42 return __raw_readw(map->map_priv_1 + ofs);
45 __u32 autcpu12_read32(struct map_info *map, unsigned long ofs)
47 return __raw_readl(map->map_priv_1 + ofs);
50 void autcpu12_write8(struct map_info *map, __u8 d, unsigned long adr)
52 __raw_writeb(d, map->map_priv_1 + adr);
56 void autcpu12_write16(struct map_info *map, __u16 d, unsigned long adr)
58 __raw_writew(d, map->map_priv_1 + adr);
62 void autcpu12_write32(struct map_info *map, __u32 d, unsigned long adr)
64 __raw_writel(d, map->map_priv_1 + adr);
68 void autcpu12_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
70 memcpy_fromio(to, map->map_priv_1 + from, len);
73 void autcpu12_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
76 __raw_writeb(*(unsigned char *) from, map->map_priv_1 + to);
83 static struct mtd_info *sram_mtd;
85 struct map_info autcpu12_sram_map = {
89 read8: autcpu12_read8,
90 read16: autcpu12_read16,
91 read32: autcpu12_read32,
92 copy_from: autcpu12_copy_from,
93 write8: autcpu12_write8,
94 write16: autcpu12_write16,
95 write32: autcpu12_write32,
96 copy_to: autcpu12_copy_to
99 static int __init init_autcpu12_sram (void)
101 int err, save0, save1;
103 autcpu12_sram_map.map_priv_1 = (unsigned long)ioremap(0x12000000, SZ_128K);
104 if (!autcpu12_sram_map.map_priv_1) {
105 printk("Failed to ioremap autcpu12 NV-RAM space\n");
114 * Write complement to ofs 0x100000
115 * Read and check result on ofs 0x0
118 save0 = autcpu12_read32(&autcpu12_sram_map,0);
119 save1 = autcpu12_read32(&autcpu12_sram_map,0x10000);
120 autcpu12_write32(&autcpu12_sram_map,~save0,0x10000);
121 /* if we find this pattern on 0x0, we have 32K size
122 * restore contents and exit
124 if ( autcpu12_read32(&autcpu12_sram_map,0) != save0) {
125 autcpu12_write32(&autcpu12_sram_map,save0,0x0);
128 /* We have a 128K found, restore 0x10000 and set size
131 autcpu12_write32(&autcpu12_sram_map,save1,0x10000);
132 autcpu12_sram_map.size = SZ_128K;
135 sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map);
137 printk("NV-RAM probe failed\n");
142 sram_mtd->module = THIS_MODULE;
143 sram_mtd->erasesize = 16;
145 if (add_mtd_device(sram_mtd)) {
146 printk("NV-RAM device addition failed\n");
151 printk("NV-RAM device size %ldK registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);
156 map_destroy(sram_mtd);
160 iounmap((void *)autcpu12_sram_map.map_priv_1);
165 static void __exit cleanup_autcpu12_maps(void)
168 del_mtd_device(sram_mtd);
169 map_destroy(sram_mtd);
170 iounmap((void *)autcpu12_sram_map.map_priv_1);
174 module_init(init_autcpu12_sram);
175 module_exit(cleanup_autcpu12_maps);
177 MODULE_AUTHOR("Thomas Gleixner");
178 MODULE_DESCRIPTION("autcpu12 NV-RAM map driver");
179 MODULE_LICENSE("GPL");