wr_sbc82xx_flash.c 4.1 KB

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