solutionengine.c 3.5 KB

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