ebony.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 <linux/config.h>
  23. #include <asm/io.h>
  24. #include <asm/ibm44x.h>
  25. #include <platforms/4xx/ebony.h>
  26. static struct mtd_info *flash;
  27. static struct map_info ebony_small_map = {
  28. .name = "Ebony small flash",
  29. .size = EBONY_SMALL_FLASH_SIZE,
  30. .bankwidth = 1,
  31. };
  32. static struct map_info ebony_large_map = {
  33. .name = "Ebony large flash",
  34. .size = EBONY_LARGE_FLASH_SIZE,
  35. .bankwidth = 1,
  36. };
  37. static struct mtd_partition ebony_small_partitions[] = {
  38. {
  39. .name = "OpenBIOS",
  40. .offset = 0x0,
  41. .size = 0x80000,
  42. }
  43. };
  44. static struct mtd_partition ebony_large_partitions[] = {
  45. {
  46. .name = "fs",
  47. .offset = 0,
  48. .size = 0x380000,
  49. },
  50. {
  51. .name = "firmware",
  52. .offset = 0x380000,
  53. .size = 0x80000,
  54. }
  55. };
  56. int __init init_ebony(void)
  57. {
  58. u8 fpga0_reg;
  59. u8 __iomem *fpga0_adr;
  60. unsigned long long small_flash_base, large_flash_base;
  61. fpga0_adr = ioremap64(EBONY_FPGA_ADDR, 16);
  62. if (!fpga0_adr)
  63. return -ENOMEM;
  64. fpga0_reg = readb(fpga0_adr);
  65. iounmap(fpga0_adr);
  66. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  67. !EBONY_FLASH_SEL(fpga0_reg))
  68. small_flash_base = EBONY_SMALL_FLASH_HIGH2;
  69. else if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  70. EBONY_FLASH_SEL(fpga0_reg))
  71. small_flash_base = EBONY_SMALL_FLASH_HIGH1;
  72. else if (!EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  73. !EBONY_FLASH_SEL(fpga0_reg))
  74. small_flash_base = EBONY_SMALL_FLASH_LOW2;
  75. else
  76. small_flash_base = EBONY_SMALL_FLASH_LOW1;
  77. if (EBONY_BOOT_SMALL_FLASH(fpga0_reg) &&
  78. !EBONY_ONBRD_FLASH_EN(fpga0_reg))
  79. large_flash_base = EBONY_LARGE_FLASH_LOW;
  80. else
  81. large_flash_base = EBONY_LARGE_FLASH_HIGH;
  82. ebony_small_map.phys = small_flash_base;
  83. ebony_small_map.virt = ioremap64(small_flash_base,
  84. ebony_small_map.size);
  85. if (!ebony_small_map.virt) {
  86. printk("Failed to ioremap flash\n");
  87. return -EIO;
  88. }
  89. simple_map_init(&ebony_small_map);
  90. flash = do_map_probe("jedec_probe", &ebony_small_map);
  91. if (flash) {
  92. flash->owner = THIS_MODULE;
  93. add_mtd_partitions(flash, ebony_small_partitions,
  94. ARRAY_SIZE(ebony_small_partitions));
  95. } else {
  96. printk("map probe failed for flash\n");
  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. return -EIO;
  105. }
  106. simple_map_init(&ebony_large_map);
  107. flash = do_map_probe("jedec_probe", &ebony_large_map);
  108. if (flash) {
  109. flash->owner = THIS_MODULE;
  110. add_mtd_partitions(flash, ebony_large_partitions,
  111. ARRAY_SIZE(ebony_large_partitions));
  112. } else {
  113. printk("map probe failed for flash\n");
  114. return -ENXIO;
  115. }
  116. return 0;
  117. }
  118. static void __exit cleanup_ebony(void)
  119. {
  120. if (flash) {
  121. del_mtd_partitions(flash);
  122. map_destroy(flash);
  123. }
  124. if (ebony_small_map.virt) {
  125. iounmap(ebony_small_map.virt);
  126. ebony_small_map.virt = NULL;
  127. }
  128. if (ebony_large_map.virt) {
  129. iounmap(ebony_large_map.virt);
  130. ebony_large_map.virt = NULL;
  131. }
  132. }
  133. module_init(init_ebony);
  134. module_exit(cleanup_ebony);
  135. MODULE_LICENSE("GPL");
  136. MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
  137. MODULE_DESCRIPTION("MTD map and partitions for IBM 440GP Ebony boards");