impa7.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Handle mapping of the NOR flash on implementa A7 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_ADDR0 0x00000000 /* physical properties of flash */
  21. #define WINDOW_SIZE0 0x00800000
  22. #define WINDOW_ADDR1 0x10000000 /* physical properties of flash */
  23. #define WINDOW_SIZE1 0x00800000
  24. #define NUM_FLASHBANKS 2
  25. #define BUSWIDTH 4
  26. /* can be { "cfi_probe", "jedec_probe", "map_rom", NULL } */
  27. #define PROBETYPES { "jedec_probe", NULL }
  28. #define MSG_PREFIX "impA7:" /* prefix for our printk()'s */
  29. #define MTDID "impa7-%d" /* for mtdparts= partitioning */
  30. static struct mtd_info *impa7_mtd[NUM_FLASHBANKS];
  31. static struct map_info impa7_map[NUM_FLASHBANKS] = {
  32. {
  33. .name = "impA7 NOR Flash Bank #0",
  34. .size = WINDOW_SIZE0,
  35. .bankwidth = BUSWIDTH,
  36. },
  37. {
  38. .name = "impA7 NOR Flash Bank #1",
  39. .size = WINDOW_SIZE1,
  40. .bankwidth = BUSWIDTH,
  41. },
  42. };
  43. #ifdef CONFIG_MTD_PARTITIONS
  44. /*
  45. * MTD partitioning stuff
  46. */
  47. static struct mtd_partition static_partitions[] =
  48. {
  49. {
  50. .name = "FileSystem",
  51. .size = 0x800000,
  52. .offset = 0x00000000
  53. },
  54. };
  55. static int mtd_parts_nb[NUM_FLASHBANKS];
  56. static struct mtd_partition *mtd_parts[NUM_FLASHBANKS];
  57. #endif
  58. static const char *probes[] = { "cmdlinepart", NULL };
  59. int __init init_impa7(void)
  60. {
  61. static const char *rom_probe_types[] = PROBETYPES;
  62. const char **type;
  63. const char *part_type = 0;
  64. int i;
  65. static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
  66. { WINDOW_ADDR0, WINDOW_SIZE0 },
  67. { WINDOW_ADDR1, WINDOW_SIZE1 },
  68. };
  69. int devicesfound = 0;
  70. for(i=0; i<NUM_FLASHBANKS; i++)
  71. {
  72. printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
  73. pt[i].size, pt[i].addr);
  74. impa7_map[i].phys = pt[i].addr;
  75. impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
  76. if (!impa7_map[i].virt) {
  77. printk(MSG_PREFIX "failed to ioremap\n");
  78. return -EIO;
  79. }
  80. simple_map_init(&impa7_map[i]);
  81. impa7_mtd[i] = 0;
  82. type = rom_probe_types;
  83. for(; !impa7_mtd[i] && *type; type++) {
  84. impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
  85. }
  86. if (impa7_mtd[i]) {
  87. impa7_mtd[i]->owner = THIS_MODULE;
  88. devicesfound++;
  89. #ifdef CONFIG_MTD_PARTITIONS
  90. mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i],
  91. probes,
  92. &mtd_parts[i],
  93. 0);
  94. if (mtd_parts_nb[i] > 0) {
  95. part_type = "command line";
  96. } else {
  97. mtd_parts[i] = static_partitions;
  98. mtd_parts_nb[i] = ARRAY_SIZE(static_partitions);
  99. part_type = "static";
  100. }
  101. printk(KERN_NOTICE MSG_PREFIX
  102. "using %s partition definition\n",
  103. part_type);
  104. add_mtd_partitions(impa7_mtd[i],
  105. mtd_parts[i], mtd_parts_nb[i]);
  106. #else
  107. add_mtd_device(impa7_mtd[i]);
  108. #endif
  109. }
  110. else
  111. iounmap((void *)impa7_map[i].virt);
  112. }
  113. return devicesfound == 0 ? -ENXIO : 0;
  114. }
  115. static void __exit cleanup_impa7(void)
  116. {
  117. int i;
  118. for (i=0; i<NUM_FLASHBANKS; i++) {
  119. if (impa7_mtd[i]) {
  120. #ifdef CONFIG_MTD_PARTITIONS
  121. del_mtd_partitions(impa7_mtd[i]);
  122. #else
  123. del_mtd_device(impa7_mtd[i]);
  124. #endif
  125. map_destroy(impa7_mtd[i]);
  126. iounmap((void *)impa7_map[i].virt);
  127. impa7_map[i].virt = 0;
  128. }
  129. }
  130. }
  131. module_init(init_impa7);
  132. module_exit(cleanup_impa7);
  133. MODULE_LICENSE("GPL");
  134. MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
  135. MODULE_DESCRIPTION("MTD map driver for implementa impA7");