ocotea.c 3.4 KB

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