edb7312.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Handle mapping of the NOR flash on Cogent EDB7312 boards
  3. *
  4. * Copyright 2002 SYSGO Real-Time Solutions GmbH
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  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. #ifdef CONFIG_MTD_PARTITIONS
  18. #include <linux/mtd/partitions.h>
  19. #endif
  20. #define WINDOW_ADDR 0x00000000 /* physical properties of flash */
  21. #define WINDOW_SIZE 0x01000000
  22. #define BUSWIDTH 2
  23. #define FLASH_BLOCKSIZE_MAIN 0x20000
  24. #define FLASH_NUMBLOCKS_MAIN 128
  25. /* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
  26. #define PROBETYPES { "cfi_probe", NULL }
  27. #define MSG_PREFIX "EDB7312-NOR:" /* prefix for our printk()'s */
  28. #define MTDID "edb7312-nor" /* for mtdparts= partitioning */
  29. static struct mtd_info *mymtd;
  30. struct map_info edb7312nor_map = {
  31. .name = "NOR flash on EDB7312",
  32. .size = WINDOW_SIZE,
  33. .bankwidth = BUSWIDTH,
  34. .phys = WINDOW_ADDR,
  35. };
  36. #ifdef CONFIG_MTD_PARTITIONS
  37. /*
  38. * MTD partitioning stuff
  39. */
  40. static struct mtd_partition static_partitions[3] =
  41. {
  42. {
  43. .name = "ARMboot",
  44. .size = 0x40000,
  45. .offset = 0
  46. },
  47. {
  48. .name = "Kernel",
  49. .size = 0x200000,
  50. .offset = 0x40000
  51. },
  52. {
  53. .name = "RootFS",
  54. .size = 0xDC0000,
  55. .offset = 0x240000
  56. },
  57. };
  58. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  59. #endif
  60. static int mtd_parts_nb = 0;
  61. static struct mtd_partition *mtd_parts = 0;
  62. int __init init_edb7312nor(void)
  63. {
  64. static const char *rom_probe_types[] = PROBETYPES;
  65. const char **type;
  66. const char *part_type = 0;
  67. printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08x\n",
  68. WINDOW_SIZE, WINDOW_ADDR);
  69. edb7312nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
  70. if (!edb7312nor_map.virt) {
  71. printk(MSG_PREFIX "failed to ioremap\n");
  72. return -EIO;
  73. }
  74. simple_map_init(&edb7312nor_map);
  75. mymtd = 0;
  76. type = rom_probe_types;
  77. for(; !mymtd && *type; type++) {
  78. mymtd = do_map_probe(*type, &edb7312nor_map);
  79. }
  80. if (mymtd) {
  81. mymtd->owner = THIS_MODULE;
  82. #ifdef CONFIG_MTD_PARTITIONS
  83. mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
  84. if (mtd_parts_nb > 0)
  85. part_type = "detected";
  86. if (mtd_parts_nb == 0)
  87. {
  88. mtd_parts = static_partitions;
  89. mtd_parts_nb = ARRAY_SIZE(static_partitions);
  90. part_type = "static";
  91. }
  92. #endif
  93. add_mtd_device(mymtd);
  94. if (mtd_parts_nb == 0)
  95. printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
  96. else
  97. {
  98. printk(KERN_NOTICE MSG_PREFIX
  99. "using %s partition definition\n", part_type);
  100. add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
  101. }
  102. return 0;
  103. }
  104. iounmap((void *)edb7312nor_map.virt);
  105. return -ENXIO;
  106. }
  107. static void __exit cleanup_edb7312nor(void)
  108. {
  109. if (mymtd) {
  110. del_mtd_device(mymtd);
  111. map_destroy(mymtd);
  112. }
  113. if (edb7312nor_map.virt) {
  114. iounmap((void *)edb7312nor_map.virt);
  115. edb7312nor_map.virt = 0;
  116. }
  117. }
  118. module_init(init_edb7312nor);
  119. module_exit(cleanup_edb7312nor);
  120. MODULE_LICENSE("GPL");
  121. MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
  122. MODULE_DESCRIPTION("Generic configurable MTD map driver");