wr_sbc82xx_flash.c 3.9 KB

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