impa7.c 3.8 KB

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