autcpu12-nvram.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * NV-RAM memory access on autcpu12
  3. * (C) 2002 Thomas Gleixner (gleixner@autronix.de)
  4. *
  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. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <linux/kernel.h>
  23. #include <linux/ioport.h>
  24. #include <linux/init.h>
  25. #include <asm/io.h>
  26. #include <asm/sizes.h>
  27. #include <mach/hardware.h>
  28. #include <mach/autcpu12.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/map.h>
  31. #include <linux/mtd/partitions.h>
  32. static struct mtd_info *sram_mtd;
  33. struct map_info autcpu12_sram_map = {
  34. .name = "SRAM",
  35. .size = 32768,
  36. .bankwidth = 4,
  37. .phys = 0x12000000,
  38. };
  39. static int __init init_autcpu12_sram (void)
  40. {
  41. int err, save0, save1;
  42. autcpu12_sram_map.virt = ioremap(0x12000000, SZ_128K);
  43. if (!autcpu12_sram_map.virt) {
  44. printk("Failed to ioremap autcpu12 NV-RAM space\n");
  45. err = -EIO;
  46. goto out;
  47. }
  48. simple_map_init(&autcpu_sram_map);
  49. /*
  50. * Check for 32K/128K
  51. * read ofs 0
  52. * read ofs 0x10000
  53. * Write complement to ofs 0x100000
  54. * Read and check result on ofs 0x0
  55. * Restore contents
  56. */
  57. save0 = map_read32(&autcpu12_sram_map,0);
  58. save1 = map_read32(&autcpu12_sram_map,0x10000);
  59. map_write32(&autcpu12_sram_map,~save0,0x10000);
  60. /* if we find this pattern on 0x0, we have 32K size
  61. * restore contents and exit
  62. */
  63. if ( map_read32(&autcpu12_sram_map,0) != save0) {
  64. map_write32(&autcpu12_sram_map,save0,0x0);
  65. goto map;
  66. }
  67. /* We have a 128K found, restore 0x10000 and set size
  68. * to 128K
  69. */
  70. map_write32(&autcpu12_sram_map,save1,0x10000);
  71. autcpu12_sram_map.size = SZ_128K;
  72. map:
  73. sram_mtd = do_map_probe("map_ram", &autcpu12_sram_map);
  74. if (!sram_mtd) {
  75. printk("NV-RAM probe failed\n");
  76. err = -ENXIO;
  77. goto out_ioremap;
  78. }
  79. sram_mtd->owner = THIS_MODULE;
  80. sram_mtd->erasesize = 16;
  81. if (add_mtd_device(sram_mtd)) {
  82. printk("NV-RAM device addition failed\n");
  83. err = -ENOMEM;
  84. goto out_probe;
  85. }
  86. printk("NV-RAM device size %ldKiB registered on AUTCPU12\n",autcpu12_sram_map.size/SZ_1K);
  87. return 0;
  88. out_probe:
  89. map_destroy(sram_mtd);
  90. sram_mtd = 0;
  91. out_ioremap:
  92. iounmap((void *)autcpu12_sram_map.virt);
  93. out:
  94. return err;
  95. }
  96. static void __exit cleanup_autcpu12_maps(void)
  97. {
  98. if (sram_mtd) {
  99. del_mtd_device(sram_mtd);
  100. map_destroy(sram_mtd);
  101. iounmap((void *)autcpu12_sram_map.virt);
  102. }
  103. }
  104. module_init(init_autcpu12_sram);
  105. module_exit(cleanup_autcpu12_maps);
  106. MODULE_AUTHOR("Thomas Gleixner");
  107. MODULE_DESCRIPTION("autcpu12 NV-RAM map driver");
  108. MODULE_LICENSE("GPL");