wr_sbc82xx_flash.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Map for flash chips on Wind River PowerQUICC II SBC82xx board.
  3. *
  4. * Copyright (C) 2004 Red Hat, Inc.
  5. *
  6. * Author: David Woodhouse <dwmw2@infradead.org>
  7. *
  8. */
  9. #include <linux/module.h>
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <asm/io.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/map.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <asm/immap_cpm2.h>
  19. static struct mtd_info *sbcmtd[3];
  20. static struct mtd_partition *sbcmtd_parts[3];
  21. struct map_info sbc82xx_flash_map[3] = {
  22. {.name = "Boot flash"},
  23. {.name = "Alternate boot flash"},
  24. {.name = "User flash"}
  25. };
  26. static struct mtd_partition smallflash_parts[] = {
  27. {
  28. .name = "space",
  29. .size = 0x100000,
  30. .offset = 0,
  31. }, {
  32. .name = "bootloader",
  33. .size = MTDPART_SIZ_FULL,
  34. .offset = MTDPART_OFS_APPEND,
  35. }
  36. };
  37. static struct mtd_partition bigflash_parts[] = {
  38. {
  39. .name = "bootloader",
  40. .size = 0x00100000,
  41. .offset = 0,
  42. }, {
  43. .name = "file system",
  44. .size = 0x01f00000,
  45. .offset = MTDPART_OFS_APPEND,
  46. }, {
  47. .name = "boot config",
  48. .size = 0x00100000,
  49. .offset = MTDPART_OFS_APPEND,
  50. }, {
  51. .name = "space",
  52. .size = 0x01f00000,
  53. .offset = MTDPART_OFS_APPEND,
  54. }
  55. };
  56. static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
  57. #define init_sbc82xx_one_flash(map, br, or) \
  58. do { \
  59. (map).phys = (br & 1) ? (br & 0xffff8000) : 0; \
  60. (map).size = (br & 1) ? (~(or & 0xffff8000) + 1) : 0; \
  61. switch (br & 0x00001800) { \
  62. case 0x00000000: \
  63. case 0x00000800: (map).bankwidth = 1; break; \
  64. case 0x00001000: (map).bankwidth = 2; break; \
  65. case 0x00001800: (map).bankwidth = 4; break; \
  66. } \
  67. } while (0);
  68. static int __init init_sbc82xx_flash(void)
  69. {
  70. volatile memctl_cpm2_t *mc = &cpm2_immr->im_memctl;
  71. int bigflash;
  72. int i;
  73. #ifdef CONFIG_SBC8560
  74. mc = ioremap(0xff700000 + 0x5000, sizeof(memctl_cpm2_t));
  75. #else
  76. mc = &cpm2_immr->im_memctl;
  77. #endif
  78. bigflash = 1;
  79. if ((mc->memc_br0 & 0x00001800) == 0x00001800)
  80. bigflash = 0;
  81. init_sbc82xx_one_flash(sbc82xx_flash_map[0], mc->memc_br0, mc->memc_or0);
  82. init_sbc82xx_one_flash(sbc82xx_flash_map[1], mc->memc_br6, mc->memc_or6);
  83. init_sbc82xx_one_flash(sbc82xx_flash_map[2], mc->memc_br1, mc->memc_or1);
  84. #ifdef CONFIG_SBC8560
  85. iounmap((void *) mc);
  86. #endif
  87. for (i=0; i<3; i++) {
  88. int8_t flashcs[3] = { 0, 6, 1 };
  89. int nr_parts;
  90. printk(KERN_NOTICE "PowerQUICC II %s (%ld MiB on CS%d",
  91. sbc82xx_flash_map[i].name,
  92. (sbc82xx_flash_map[i].size >> 20),
  93. flashcs[i]);
  94. if (!sbc82xx_flash_map[i].phys) {
  95. /* We know it can't be at zero. */
  96. printk("): disabled by bootloader.\n");
  97. continue;
  98. }
  99. printk(" at %08lx)\n", sbc82xx_flash_map[i].phys);
  100. sbc82xx_flash_map[i].virt = ioremap(sbc82xx_flash_map[i].phys, sbc82xx_flash_map[i].size);
  101. if (!sbc82xx_flash_map[i].virt) {
  102. printk("Failed to ioremap\n");
  103. continue;
  104. }
  105. simple_map_init(&sbc82xx_flash_map[i]);
  106. sbcmtd[i] = do_map_probe("cfi_probe", &sbc82xx_flash_map[i]);
  107. if (!sbcmtd[i])
  108. continue;
  109. sbcmtd[i]->owner = THIS_MODULE;
  110. nr_parts = parse_mtd_partitions(sbcmtd[i], part_probes,
  111. &sbcmtd_parts[i], 0);
  112. if (nr_parts > 0) {
  113. mtd_device_register(sbcmtd[i], sbcmtd_parts[i],
  114. nr_parts);
  115. continue;
  116. }
  117. /* No partitioning detected. Use default */
  118. if (i == 2) {
  119. mtd_device_register(sbcmtd[i], NULL, 0);
  120. } else if (i == bigflash) {
  121. mtd_device_register(sbcmtd[i], bigflash_parts,
  122. ARRAY_SIZE(bigflash_parts));
  123. } else {
  124. mtd_device_register(sbcmtd[i], smallflash_parts,
  125. ARRAY_SIZE(smallflash_parts));
  126. }
  127. }
  128. return 0;
  129. }
  130. static void __exit cleanup_sbc82xx_flash(void)
  131. {
  132. int i;
  133. for (i=0; i<3; i++) {
  134. if (!sbcmtd[i])
  135. continue;
  136. if (i<2 || sbcmtd_parts[i])
  137. mtd_device_unregister(sbcmtd[i]);
  138. else
  139. mtd_device_unregister(sbcmtd[i]);
  140. kfree(sbcmtd_parts[i]);
  141. map_destroy(sbcmtd[i]);
  142. iounmap((void *)sbc82xx_flash_map[i].virt);
  143. sbc82xx_flash_map[i].virt = 0;
  144. }
  145. }
  146. module_init(init_sbc82xx_flash);
  147. module_exit(cleanup_sbc82xx_flash);
  148. MODULE_LICENSE("GPL");
  149. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  150. MODULE_DESCRIPTION("Flash map driver for WindRiver PowerQUICC II");