ebony.c 3.8 KB

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