ocotea.c 3.3 KB

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