solutionengine.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Flash and EPROM on Hitachi Solution Engine and similar boards.
  3. *
  4. * (C) 2001 Red Hat, Inc.
  5. *
  6. * GPL'd
  7. */
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <asm/io.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/map.h>
  15. #include <linux/mtd/partitions.h>
  16. #include <linux/errno.h>
  17. static struct mtd_info *flash_mtd;
  18. static struct mtd_info *eprom_mtd;
  19. static struct mtd_partition *parsed_parts;
  20. struct map_info soleng_eprom_map = {
  21. .name = "Solution Engine EPROM",
  22. .size = 0x400000,
  23. .bankwidth = 4,
  24. };
  25. struct map_info soleng_flash_map = {
  26. .name = "Solution Engine FLASH",
  27. .size = 0x400000,
  28. .bankwidth = 4,
  29. };
  30. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  31. #ifdef CONFIG_MTD_SUPERH_RESERVE
  32. static struct mtd_partition superh_se_partitions[] = {
  33. /* Reserved for boot code, read-only */
  34. {
  35. .name = "flash_boot",
  36. .offset = 0x00000000,
  37. .size = CONFIG_MTD_SUPERH_RESERVE,
  38. .mask_flags = MTD_WRITEABLE,
  39. },
  40. /* All else is writable (e.g. JFFS) */
  41. {
  42. .name = "Flash FS",
  43. .offset = MTDPART_OFS_NXTBLK,
  44. .size = MTDPART_SIZ_FULL,
  45. }
  46. };
  47. #endif /* CONFIG_MTD_SUPERH_RESERVE */
  48. static int __init init_soleng_maps(void)
  49. {
  50. int nr_parts = 0;
  51. /* First probe at offset 0 */
  52. soleng_flash_map.phys = 0;
  53. soleng_flash_map.virt = (void __iomem *)P2SEGADDR(0);
  54. soleng_eprom_map.phys = 0x01000000;
  55. soleng_eprom_map.virt = (void __iomem *)P1SEGADDR(0x01000000);
  56. simple_map_init(&soleng_eprom_map);
  57. simple_map_init(&soleng_flash_map);
  58. printk(KERN_NOTICE "Probing for flash chips at 0x00000000:\n");
  59. flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map);
  60. if (!flash_mtd) {
  61. /* Not there. Try swapping */
  62. printk(KERN_NOTICE "Probing for flash chips at 0x01000000:\n");
  63. soleng_flash_map.phys = 0x01000000;
  64. soleng_flash_map.virt = P2SEGADDR(0x01000000);
  65. soleng_eprom_map.phys = 0;
  66. soleng_eprom_map.virt = P1SEGADDR(0);
  67. flash_mtd = do_map_probe("cfi_probe", &soleng_flash_map);
  68. if (!flash_mtd) {
  69. /* Eep. */
  70. printk(KERN_NOTICE "Flash chips not detected at either possible location.\n");
  71. return -ENXIO;
  72. }
  73. }
  74. printk(KERN_NOTICE "Solution Engine: Flash at 0x%08lx, EPROM at 0x%08lx\n",
  75. soleng_flash_map.phys & 0x1fffffff,
  76. soleng_eprom_map.phys & 0x1fffffff);
  77. flash_mtd->owner = THIS_MODULE;
  78. eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map);
  79. if (eprom_mtd) {
  80. eprom_mtd->owner = THIS_MODULE;
  81. mtd_device_register(eprom_mtd, NULL, 0);
  82. }
  83. nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0);
  84. #ifdef CONFIG_MTD_SUPERH_RESERVE
  85. if (nr_parts <= 0) {
  86. printk(KERN_NOTICE "Using configured partition at 0x%08x.\n",
  87. CONFIG_MTD_SUPERH_RESERVE);
  88. parsed_parts = superh_se_partitions;
  89. nr_parts = sizeof(superh_se_partitions)/sizeof(*parsed_parts);
  90. }
  91. #endif /* CONFIG_MTD_SUPERH_RESERVE */
  92. if (nr_parts > 0)
  93. mtd_device_register(flash_mtd, parsed_parts, nr_parts);
  94. else
  95. mtd_device_register(flash_mtd, NULL, 0);
  96. return 0;
  97. }
  98. static void __exit cleanup_soleng_maps(void)
  99. {
  100. if (eprom_mtd) {
  101. mtd_device_unregister(eprom_mtd);
  102. map_destroy(eprom_mtd);
  103. }
  104. if (parsed_parts)
  105. mtd_device_unregister(flash_mtd);
  106. else
  107. mtd_device_unregister(flash_mtd);
  108. map_destroy(flash_mtd);
  109. }
  110. module_init(init_soleng_maps);
  111. module_exit(cleanup_soleng_maps);
  112. MODULE_LICENSE("GPL");
  113. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  114. MODULE_DESCRIPTION("MTD map driver for Hitachi SolutionEngine (and similar) boards");