wr_sbc82xx_flash.c 4.2 KB

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