ocelot.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * $Id: ocelot.c,v 1.17 2005/11/07 11:14:27 gleixner Exp $
  3. *
  4. * Flash on Momenco Ocelot
  5. */
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <asm/io.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/map.h>
  13. #include <linux/mtd/partitions.h>
  14. #define OCELOT_PLD 0x2c000000
  15. #define FLASH_WINDOW_ADDR 0x2fc00000
  16. #define FLASH_WINDOW_SIZE 0x00080000
  17. #define FLASH_BUSWIDTH 1
  18. #define NVRAM_WINDOW_ADDR 0x2c800000
  19. #define NVRAM_WINDOW_SIZE 0x00007FF0
  20. #define NVRAM_BUSWIDTH 1
  21. static unsigned int cacheflush = 0;
  22. static struct mtd_info *flash_mtd;
  23. static struct mtd_info *nvram_mtd;
  24. static void ocelot_ram_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
  25. {
  26. struct map_info *map = mtd->priv;
  27. size_t done = 0;
  28. /* If we use memcpy, it does word-wide writes. Even though we told the
  29. GT64120A that it's an 8-bit wide region, word-wide writes don't work.
  30. We end up just writing the first byte of the four to all four bytes.
  31. So we have this loop instead */
  32. *retlen = len;
  33. while(len) {
  34. __raw_writeb(*(unsigned char *) from, map->virt + to);
  35. from++;
  36. to++;
  37. len--;
  38. }
  39. }
  40. static struct mtd_partition *parsed_parts;
  41. struct map_info ocelot_flash_map = {
  42. .name = "Ocelot boot flash",
  43. .size = FLASH_WINDOW_SIZE,
  44. .bankwidth = FLASH_BUSWIDTH,
  45. .phys = FLASH_WINDOW_ADDR,
  46. };
  47. struct map_info ocelot_nvram_map = {
  48. .name = "Ocelot NVRAM",
  49. .size = NVRAM_WINDOW_SIZE,
  50. .bankwidth = NVRAM_BUSWIDTH,
  51. .phys = NVRAM_WINDOW_ADDR,
  52. };
  53. static const char *probes[] = { "RedBoot", NULL };
  54. static int __init init_ocelot_maps(void)
  55. {
  56. void *pld;
  57. int nr_parts;
  58. unsigned char brd_status;
  59. printk(KERN_INFO "Momenco Ocelot MTD mappings: Flash 0x%x at 0x%x, NVRAM 0x%x at 0x%x\n",
  60. FLASH_WINDOW_SIZE, FLASH_WINDOW_ADDR, NVRAM_WINDOW_SIZE, NVRAM_WINDOW_ADDR);
  61. /* First check whether the flash jumper is present */
  62. pld = ioremap(OCELOT_PLD, 0x10);
  63. if (!pld) {
  64. printk(KERN_NOTICE "Failed to ioremap Ocelot PLD\n");
  65. return -EIO;
  66. }
  67. brd_status = readb(pld+4);
  68. iounmap(pld);
  69. /* Now ioremap the NVRAM space */
  70. ocelot_nvram_map.virt = ioremap_nocache(NVRAM_WINDOW_ADDR, NVRAM_WINDOW_SIZE);
  71. if (!ocelot_nvram_map.virt) {
  72. printk(KERN_NOTICE "Failed to ioremap Ocelot NVRAM space\n");
  73. return -EIO;
  74. }
  75. simple_map_init(&ocelot_nvram_map);
  76. /* And do the RAM probe on it to get an MTD device */
  77. nvram_mtd = do_map_probe("map_ram", &ocelot_nvram_map);
  78. if (!nvram_mtd) {
  79. printk("NVRAM probe failed\n");
  80. goto fail_1;
  81. }
  82. nvram_mtd->owner = THIS_MODULE;
  83. nvram_mtd->erasesize = 16;
  84. /* Override the write() method */
  85. nvram_mtd->write = ocelot_ram_write;
  86. /* Now map the flash space */
  87. ocelot_flash_map.virt = ioremap_nocache(FLASH_WINDOW_ADDR, FLASH_WINDOW_SIZE);
  88. if (!ocelot_flash_map.virt) {
  89. printk(KERN_NOTICE "Failed to ioremap Ocelot flash space\n");
  90. goto fail_2;
  91. }
  92. /* Now the cached version */
  93. ocelot_flash_map.cached = (unsigned long)__ioremap(FLASH_WINDOW_ADDR, FLASH_WINDOW_SIZE, 0);
  94. simple_map_init(&ocelot_flash_map);
  95. /* Only probe for flash if the write jumper is present */
  96. if (brd_status & 0x40) {
  97. flash_mtd = do_map_probe("jedec", &ocelot_flash_map);
  98. } else {
  99. printk(KERN_NOTICE "Ocelot flash write jumper not present. Treating as ROM\n");
  100. }
  101. /* If that failed or the jumper's absent, pretend it's ROM */
  102. if (!flash_mtd) {
  103. flash_mtd = do_map_probe("map_rom", &ocelot_flash_map);
  104. /* If we're treating it as ROM, set the erase size */
  105. if (flash_mtd)
  106. flash_mtd->erasesize = 0x10000;
  107. }
  108. if (!flash_mtd)
  109. goto fail3;
  110. add_mtd_device(nvram_mtd);
  111. flash_mtd->owner = THIS_MODULE;
  112. nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0);
  113. if (nr_parts > 0)
  114. add_mtd_partitions(flash_mtd, parsed_parts, nr_parts);
  115. else
  116. add_mtd_device(flash_mtd);
  117. return 0;
  118. fail3:
  119. iounmap((void *)ocelot_flash_map.virt);
  120. if (ocelot_flash_map.cached)
  121. iounmap((void *)ocelot_flash_map.cached);
  122. fail_2:
  123. map_destroy(nvram_mtd);
  124. fail_1:
  125. iounmap((void *)ocelot_nvram_map.virt);
  126. return -ENXIO;
  127. }
  128. static void __exit cleanup_ocelot_maps(void)
  129. {
  130. del_mtd_device(nvram_mtd);
  131. map_destroy(nvram_mtd);
  132. iounmap((void *)ocelot_nvram_map.virt);
  133. if (parsed_parts)
  134. del_mtd_partitions(flash_mtd);
  135. else
  136. del_mtd_device(flash_mtd);
  137. map_destroy(flash_mtd);
  138. iounmap((void *)ocelot_flash_map.virt);
  139. if (ocelot_flash_map.cached)
  140. iounmap((void *)ocelot_flash_map.cached);
  141. }
  142. module_init(init_ocelot_maps);
  143. module_exit(cleanup_ocelot_maps);
  144. MODULE_LICENSE("GPL");
  145. MODULE_AUTHOR("Red Hat, Inc. - David Woodhouse <dwmw2@cambridge.redhat.com>");
  146. MODULE_DESCRIPTION("MTD map driver for Momenco Ocelot board");