edb7312.c 3.3 KB

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