solutionengine.c 3.4 KB

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