impa7.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 partitions[] =
  45. {
  46. {
  47. .name = "FileSystem",
  48. .size = 0x800000,
  49. .offset = 0x00000000
  50. },
  51. };
  52. static int __init init_impa7(void)
  53. {
  54. static const char *rom_probe_types[] = PROBETYPES;
  55. const char **type;
  56. int i;
  57. static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
  58. { WINDOW_ADDR0, WINDOW_SIZE0 },
  59. { WINDOW_ADDR1, WINDOW_SIZE1 },
  60. };
  61. int devicesfound = 0;
  62. for(i=0; i<NUM_FLASHBANKS; i++)
  63. {
  64. printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
  65. pt[i].size, pt[i].addr);
  66. impa7_map[i].phys = pt[i].addr;
  67. impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
  68. if (!impa7_map[i].virt) {
  69. printk(MSG_PREFIX "failed to ioremap\n");
  70. return -EIO;
  71. }
  72. simple_map_init(&impa7_map[i]);
  73. impa7_mtd[i] = 0;
  74. type = rom_probe_types;
  75. for(; !impa7_mtd[i] && *type; type++) {
  76. impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
  77. }
  78. if (impa7_mtd[i]) {
  79. impa7_mtd[i]->owner = THIS_MODULE;
  80. devicesfound++;
  81. mtd_device_parse_register(impa7_mtd[i], NULL, NULL,
  82. partitions,
  83. ARRAY_SIZE(partitions));
  84. }
  85. else
  86. iounmap((void *)impa7_map[i].virt);
  87. }
  88. return devicesfound == 0 ? -ENXIO : 0;
  89. }
  90. static void __exit cleanup_impa7(void)
  91. {
  92. int i;
  93. for (i=0; i<NUM_FLASHBANKS; i++) {
  94. if (impa7_mtd[i]) {
  95. mtd_device_unregister(impa7_mtd[i]);
  96. map_destroy(impa7_mtd[i]);
  97. iounmap((void *)impa7_map[i].virt);
  98. impa7_map[i].virt = 0;
  99. }
  100. }
  101. }
  102. module_init(init_impa7);
  103. module_exit(cleanup_impa7);
  104. MODULE_LICENSE("GPL");
  105. MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
  106. MODULE_DESCRIPTION("MTD map driver for implementa impA7");