impa7.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 int __init init_impa7(void)
  55. {
  56. static const char *rom_probe_types[] = PROBETYPES;
  57. const char **type;
  58. const char *part_type = 0;
  59. int i;
  60. static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
  61. { WINDOW_ADDR0, WINDOW_SIZE0 },
  62. { WINDOW_ADDR1, WINDOW_SIZE1 },
  63. };
  64. int devicesfound = 0;
  65. for(i=0; i<NUM_FLASHBANKS; i++)
  66. {
  67. printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
  68. pt[i].size, pt[i].addr);
  69. impa7_map[i].phys = pt[i].addr;
  70. impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
  71. if (!impa7_map[i].virt) {
  72. printk(MSG_PREFIX "failed to ioremap\n");
  73. return -EIO;
  74. }
  75. simple_map_init(&impa7_map[i]);
  76. impa7_mtd[i] = 0;
  77. type = rom_probe_types;
  78. for(; !impa7_mtd[i] && *type; type++) {
  79. impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
  80. }
  81. if (impa7_mtd[i]) {
  82. impa7_mtd[i]->owner = THIS_MODULE;
  83. devicesfound++;
  84. mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i],
  85. NULL,
  86. &mtd_parts[i],
  87. 0);
  88. if (mtd_parts_nb[i] > 0) {
  89. part_type = "command line";
  90. } else {
  91. mtd_parts[i] = static_partitions;
  92. mtd_parts_nb[i] = ARRAY_SIZE(static_partitions);
  93. part_type = "static";
  94. }
  95. printk(KERN_NOTICE MSG_PREFIX
  96. "using %s partition definition\n",
  97. part_type);
  98. mtd_device_register(impa7_mtd[i],
  99. mtd_parts[i], mtd_parts_nb[i]);
  100. }
  101. else
  102. iounmap((void *)impa7_map[i].virt);
  103. }
  104. return devicesfound == 0 ? -ENXIO : 0;
  105. }
  106. static void __exit cleanup_impa7(void)
  107. {
  108. int i;
  109. for (i=0; i<NUM_FLASHBANKS; i++) {
  110. if (impa7_mtd[i]) {
  111. mtd_device_unregister(impa7_mtd[i]);
  112. map_destroy(impa7_mtd[i]);
  113. iounmap((void *)impa7_map[i].virt);
  114. impa7_map[i].virt = 0;
  115. }
  116. }
  117. }
  118. module_init(init_impa7);
  119. module_exit(cleanup_impa7);
  120. MODULE_LICENSE("GPL");
  121. MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
  122. MODULE_DESCRIPTION("MTD map driver for implementa impA7");