ocotea.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Mapping for Ocotea 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 <linux/config.h>
  21. #include <asm/io.h>
  22. #include <asm/ibm44x.h>
  23. #include <platforms/4xx/ocotea.h>
  24. static struct mtd_info *flash;
  25. static struct map_info ocotea_small_map = {
  26. .name = "Ocotea small flash",
  27. .size = OCOTEA_SMALL_FLASH_SIZE,
  28. .buswidth = 1,
  29. };
  30. static struct map_info ocotea_large_map = {
  31. .name = "Ocotea large flash",
  32. .size = OCOTEA_LARGE_FLASH_SIZE,
  33. .buswidth = 1,
  34. };
  35. static struct mtd_partition ocotea_small_partitions[] = {
  36. {
  37. .name = "pibs",
  38. .offset = 0x0,
  39. .size = 0x100000,
  40. }
  41. };
  42. static struct mtd_partition ocotea_large_partitions[] = {
  43. {
  44. .name = "fs",
  45. .offset = 0,
  46. .size = 0x300000,
  47. },
  48. {
  49. .name = "firmware",
  50. .offset = 0x300000,
  51. .size = 0x100000,
  52. }
  53. };
  54. int __init init_ocotea(void)
  55. {
  56. u8 fpga0_reg;
  57. u8 *fpga0_adr;
  58. unsigned long long small_flash_base, large_flash_base;
  59. fpga0_adr = ioremap64(OCOTEA_FPGA_ADDR, 16);
  60. if (!fpga0_adr)
  61. return -ENOMEM;
  62. fpga0_reg = readb((unsigned long)fpga0_adr);
  63. iounmap(fpga0_adr);
  64. if (OCOTEA_BOOT_LARGE_FLASH(fpga0_reg)) {
  65. small_flash_base = OCOTEA_SMALL_FLASH_HIGH;
  66. large_flash_base = OCOTEA_LARGE_FLASH_LOW;
  67. }
  68. else {
  69. small_flash_base = OCOTEA_SMALL_FLASH_LOW;
  70. large_flash_base = OCOTEA_LARGE_FLASH_HIGH;
  71. }
  72. ocotea_small_map.phys = small_flash_base;
  73. ocotea_small_map.virt = ioremap64(small_flash_base,
  74. ocotea_small_map.size);
  75. if (!ocotea_small_map.virt) {
  76. printk("Failed to ioremap flash\n");
  77. return -EIO;
  78. }
  79. simple_map_init(&ocotea_small_map);
  80. flash = do_map_probe("map_rom", &ocotea_small_map);
  81. if (flash) {
  82. flash->owner = THIS_MODULE;
  83. add_mtd_partitions(flash, ocotea_small_partitions,
  84. ARRAY_SIZE(ocotea_small_partitions));
  85. } else {
  86. printk("map probe failed for flash\n");
  87. return -ENXIO;
  88. }
  89. ocotea_large_map.phys = large_flash_base;
  90. ocotea_large_map.virt = ioremap64(large_flash_base,
  91. ocotea_large_map.size);
  92. if (!ocotea_large_map.virt) {
  93. printk("Failed to ioremap flash\n");
  94. return -EIO;
  95. }
  96. simple_map_init(&ocotea_large_map);
  97. flash = do_map_probe("cfi_probe", &ocotea_large_map);
  98. if (flash) {
  99. flash->owner = THIS_MODULE;
  100. add_mtd_partitions(flash, ocotea_large_partitions,
  101. ARRAY_SIZE(ocotea_large_partitions));
  102. } else {
  103. printk("map probe failed for flash\n");
  104. return -ENXIO;
  105. }
  106. return 0;
  107. }
  108. static void __exit cleanup_ocotea(void)
  109. {
  110. if (flash) {
  111. del_mtd_partitions(flash);
  112. map_destroy(flash);
  113. }
  114. if (ocotea_small_map.virt) {
  115. iounmap((void *)ocotea_small_map.virt);
  116. ocotea_small_map.virt = 0;
  117. }
  118. if (ocotea_large_map.virt) {
  119. iounmap((void *)ocotea_large_map.virt);
  120. ocotea_large_map.virt = 0;
  121. }
  122. }
  123. module_init(init_ocotea);
  124. module_exit(cleanup_ocotea);
  125. MODULE_LICENSE("GPL");
  126. MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
  127. MODULE_DESCRIPTION("MTD map and partitions for IBM 440GX Ocotea boards");