ebony.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Mapping for Ebony user flash
  3. *
  4. * Matt Porter <mporter@kernel.crashing.org>
  5. *
  6. * Copyright 2002-2004 MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/io.h>
  21. #include <asm/ibm44x.h>
  22. #include <platforms/4xx/ebony.h>
  23. static struct mtd_info *flash;
  24. static struct map_info ebony_small_map = {
  25. .name = "Ebony small flash",
  26. .size = EBONY_SMALL_FLASH_SIZE,
  27. .bankwidth = 1,
  28. };
  29. static struct map_info ebony_large_map = {
  30. .name = "Ebony large flash",
  31. .size = EBONY_LARGE_FLASH_SIZE,
  32. .bankwidth = 1,
  33. };
  34. static struct mtd_partition ebony_small_partitions[] = {
  35. {
  36. .name = "OpenBIOS",
  37. .offset = 0x0,
  38. .size = 0x80000,
  39. }
  40. };
  41. static struct mtd_partition ebony_large_partitions[] = {
  42. {
  43. .name = "fs",
  44. .offset = 0,
  45. .size = 0x380000,
  46. },
  47. {
  48. .name = "firmware",
  49. .offset = 0x380000,
  50. .size = 0x80000,
  51. }
  52. };
  53. int __init init_ebony(void)
  54. {
  55. u8 fpga0_reg;
  56. u8 __iomem *fpga0_adr;
  57. unsigned long long small_flash_base, large_flash_base;
  58. fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
  59. if (!fpga0_adr)
  60. return -ENOMEM;
  61. fpga0_reg = readb(fpga0_adr);
  62. iounmap(fpga0_adr);
  63. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  64. !EBONY_FLASH_SEL(fpga0_reg))
  65. small_flash_base = EBONY_SMALL_FLASH_HIGH2;
  66. else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  67. EBONY_FLASH_SEL(fpga0_reg))
  68. small_flash_base = EBONY_SMALL_FLASH_HIGH1;
  69. else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  70. !EBONY_FLASH_SEL(fpga0_reg))
  71. small_flash_base = EBONY_SMALL_FLASH_LOW2;
  72. else
  73. small_flash_base = EBONY_SMALL_FLASH_LOW1;
  74. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  75. !EBONY_ONBRD_FLASH_EN(fpga0_reg))
  76. large_flash_base = EBONY_LARGE_FLASH_LOW;
  77. else
  78. large_flash_base = EBONY_LARGE_FLASH_HIGH;
  79. ebony_small_map.phys = small_flash_base;
  80. ebony_small_map.virt = ioremap64(small_flash_base,
  81. ebony_small_map.size);
  82. if (!ebony_small_map.virt) {
  83. printk("Failed to ioremap flash\n");
  84. return -EIO;
  85. }
  86. simple_map_init(&ebony_small_map);
  87. flash = do_map_probe("jedec_probe", &ebony_small_map);
  88. if (flash) {
  89. flash->owner = THIS_MODULE;
  90. add_mtd_partitions(flash, ebony_small_partitions,
  91. ARRAY_SIZE(ebony_small_partitions));
  92. } else {
  93. printk("map probe failed for flash\n");
  94. iounmap(ebony_small_map.virt);
  95. return -ENXIO;
  96. }
  97. ebony_large_map.phys = large_flash_base;
  98. ebony_large_map.virt = ioremap64(large_flash_base,
  99. ebony_large_map.size);
  100. if (!ebony_large_map.virt) {
  101. printk("Failed to ioremap flash\n");
  102. iounmap(ebony_small_map.virt);
  103. return -EIO;
  104. }
  105. simple_map_init(&ebony_large_map);
  106. flash = do_map_probe("jedec_probe", &ebony_large_map);
  107. if (flash) {
  108. flash->owner = THIS_MODULE;
  109. add_mtd_partitions(flash, ebony_large_partitions,
  110. ARRAY_SIZE(ebony_large_partitions));
  111. } else {
  112. printk("map probe failed for flash\n");
  113. iounmap(ebony_small_map.virt);
  114. iounmap(ebony_large_map.virt);
  115. return -ENXIO;
  116. }
  117. return 0;
  118. }
  119. static void __exit cleanup_ebony(void)
  120. {
  121. if (flash) {
  122. del_mtd_partitions(flash);
  123. map_destroy(flash);
  124. }
  125. if (ebony_small_map.virt) {
  126. iounmap(ebony_small_map.virt);
  127. ebony_small_map.virt = NULL;
  128. }
  129. if (ebony_large_map.virt) {
  130. iounmap(ebony_large_map.virt);
  131. ebony_large_map.virt = NULL;
  132. }
  133. }
  134. module_init(init_ebony);
  135. module_exit(cleanup_ebony);
  136. MODULE_LICENSE("GPL");
  137. MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
  138. MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards");