autcpu12-nvram.c 3.1 KB

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