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