ebony.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * $Id: ebony.c,v 1.15 2004/12/09 18:39:54 holindho 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 <linux/config.h>
  23. #include <linux/version.h>
  24. #include <asm/io.h>
  25. #include <asm/ibm44x.h>
  26. #include <platforms/4xx/ebony.h>
  27. static struct mtd_info *flash;
  28. static struct map_info ebony_small_map = {
  29. .name = "Ebony small flash",
  30. .size = EBONY_SMALL_FLASH_SIZE,
  31. .bankwidth = 1,
  32. };
  33. static struct map_info ebony_large_map = {
  34. .name = "Ebony large flash",
  35. .size = EBONY_LARGE_FLASH_SIZE,
  36. .bankwidth = 1,
  37. };
  38. static struct mtd_partition ebony_small_partitions[] = {
  39. {
  40. .name = "OpenBIOS",
  41. .offset = 0x0,
  42. .size = 0x80000,
  43. }
  44. };
  45. static struct mtd_partition ebony_large_partitions[] = {
  46. {
  47. .name = "fs",
  48. .offset = 0,
  49. .size = 0x380000,
  50. },
  51. {
  52. .name = "firmware",
  53. .offset = 0x380000,
  54. .size = 0x80000,
  55. }
  56. };
  57. int __init init_ebony(void)
  58. {
  59. u8 fpga0_reg;
  60. u8 __iomem *fpga0_adr;
  61. unsigned long long small_flash_base, large_flash_base;
  62. fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
  63. if (!fpga0_adr)
  64. return -ENOMEM;
  65. fpga0_reg = readb(fpga0_adr);
  66. iounmap(fpga0_adr);
  67. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  68. !EBONY_FLASH_SEL(fpga0_reg))
  69. small_flash_base = EBONY_SMALL_FLASH_HIGH2;
  70. else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  71. EBONY_FLASH_SEL(fpga0_reg))
  72. small_flash_base = EBONY_SMALL_FLASH_HIGH1;
  73. else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  74. !EBONY_FLASH_SEL(fpga0_reg))
  75. small_flash_base = EBONY_SMALL_FLASH_LOW2;
  76. else
  77. small_flash_base = EBONY_SMALL_FLASH_LOW1;
  78. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  79. !EBONY_ONBRD_FLASH_EN(fpga0_reg))
  80. large_flash_base = EBONY_LARGE_FLASH_LOW;
  81. else
  82. large_flash_base = EBONY_LARGE_FLASH_HIGH;
  83. ebony_small_map.phys = small_flash_base;
  84. ebony_small_map.virt = ioremap64(small_flash_base,
  85. ebony_small_map.size);
  86. if (!ebony_small_map.virt) {
  87. printk("Failed to ioremap flash\n");
  88. return -EIO;
  89. }
  90. simple_map_init(&ebony_small_map);
  91. flash = do_map_probe("jedec_probe", &ebony_small_map);
  92. if (flash) {
  93. flash->owner = THIS_MODULE;
  94. add_mtd_partitions(flash, ebony_small_partitions,
  95. ARRAY_SIZE(ebony_small_partitions));
  96. } else {
  97. printk("map probe failed for flash\n");
  98. return -ENXIO;
  99. }
  100. ebony_large_map.phys = large_flash_base;
  101. ebony_large_map.virt = ioremap64(large_flash_base,
  102. ebony_large_map.size);
  103. if (!ebony_large_map.virt) {
  104. printk("Failed to ioremap flash\n");
  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. 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");