impa7.c 3.7 KB

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