impa7.c 3.5 KB

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