edb7312.c 3.2 KB

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