ocotea.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
  55. int __init init_ocotea(void)
  56. {
  57. u8 fpga0_reg;
  58. u8 *fpga0_adr;
  59. unsigned long long small_flash_base, large_flash_base;
  60. fpga0_adr = ioremap64(OCOTEA_FPGA_ADDR, 16);
  61. if (!fpga0_adr)
  62. return -ENOMEM;
  63. fpga0_reg = readb((unsigned long)fpga0_adr);
  64. iounmap(fpga0_adr);
  65. if (OCOTEA_BOOT_LARGE_FLASH(fpga0_reg)) {
  66. small_flash_base = OCOTEA_SMALL_FLASH_HIGH;
  67. large_flash_base = OCOTEA_LARGE_FLASH_LOW;
  68. }
  69. else {
  70. small_flash_base = OCOTEA_SMALL_FLASH_LOW;
  71. large_flash_base = OCOTEA_LARGE_FLASH_HIGH;
  72. }
  73. ocotea_small_map.phys = small_flash_base;
  74. ocotea_small_map.virt = ioremap64(small_flash_base,
  75. ocotea_small_map.size);
  76. if (!ocotea_small_map.virt) {
  77. printk("Failed to ioremap flash\n");
  78. return -EIO;
  79. }
  80. simple_map_init(&ocotea_small_map);
  81. flash = do_map_probe("map_rom", &ocotea_small_map);
  82. if (flash) {
  83. flash->owner = THIS_MODULE;
  84. add_mtd_partitions(flash, ocotea_small_partitions,
  85. NB_OF(ocotea_small_partitions));
  86. } else {
  87. printk("map probe failed for flash\n");
  88. return -ENXIO;
  89. }
  90. ocotea_large_map.phys = large_flash_base;
  91. ocotea_large_map.virt = ioremap64(large_flash_base,
  92. ocotea_large_map.size);
  93. if (!ocotea_large_map.virt) {
  94. printk("Failed to ioremap flash\n");
  95. return -EIO;
  96. }
  97. simple_map_init(&ocotea_large_map);
  98. flash = do_map_probe("cfi_probe", &ocotea_large_map);
  99. if (flash) {
  100. flash->owner = THIS_MODULE;
  101. add_mtd_partitions(flash, ocotea_large_partitions,
  102. NB_OF(ocotea_large_partitions));
  103. } else {
  104. printk("map probe failed for flash\n");
  105. return -ENXIO;
  106. }
  107. return 0;
  108. }
  109. static void __exit cleanup_ocotea(void)
  110. {
  111. if (flash) {
  112. del_mtd_partitions(flash);
  113. map_destroy(flash);
  114. }
  115. if (ocotea_small_map.virt) {
  116. iounmap((void *)ocotea_small_map.virt);
  117. ocotea_small_map.virt = 0;
  118. }
  119. if (ocotea_large_map.virt) {
  120. iounmap((void *)ocotea_large_map.virt);
  121. ocotea_large_map.virt = 0;
  122. }
  123. }
  124. module_init(init_ocotea);
  125. module_exit(cleanup_ocotea);
  126. MODULE_LICENSE("GPL");
  127. MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
  128. MODULE_DESCRIPTION("MTD map and partitions for IBM 440GX Ocotea boards");