edb7312.c 3.3 KB

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