impa7.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #define MSG_PREFIX "impA7:" /* prefix for our printk()'s */
  25. #define MTDID "impa7-%d" /* for mtdparts= partitioning */
  26. static struct mtd_info *impa7_mtd[NUM_FLASHBANKS];
  27. static const char * const rom_probe_types[] = { "jedec_probe", NULL };
  28. static struct map_info impa7_map[NUM_FLASHBANKS] = {
  29. {
  30. .name = "impA7 NOR Flash Bank #0",
  31. .size = WINDOW_SIZE0,
  32. .bankwidth = BUSWIDTH,
  33. },
  34. {
  35. .name = "impA7 NOR Flash Bank #1",
  36. .size = WINDOW_SIZE1,
  37. .bankwidth = BUSWIDTH,
  38. },
  39. };
  40. /*
  41. * MTD partitioning stuff
  42. */
  43. static struct mtd_partition partitions[] =
  44. {
  45. {
  46. .name = "FileSystem",
  47. .size = 0x800000,
  48. .offset = 0x00000000
  49. },
  50. };
  51. static int __init init_impa7(void)
  52. {
  53. const char * const *type;
  54. int i;
  55. static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
  56. { WINDOW_ADDR0, WINDOW_SIZE0 },
  57. { WINDOW_ADDR1, WINDOW_SIZE1 },
  58. };
  59. int devicesfound = 0;
  60. for(i=0; i<NUM_FLASHBANKS; i++)
  61. {
  62. printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
  63. pt[i].size, pt[i].addr);
  64. impa7_map[i].phys = pt[i].addr;
  65. impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
  66. if (!impa7_map[i].virt) {
  67. printk(MSG_PREFIX "failed to ioremap\n");
  68. return -EIO;
  69. }
  70. simple_map_init(&impa7_map[i]);
  71. impa7_mtd[i] = NULL;
  72. type = rom_probe_types;
  73. for(; !impa7_mtd[i] && *type; type++) {
  74. impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
  75. }
  76. if (impa7_mtd[i]) {
  77. impa7_mtd[i]->owner = THIS_MODULE;
  78. devicesfound++;
  79. mtd_device_parse_register(impa7_mtd[i], NULL, NULL,
  80. partitions,
  81. ARRAY_SIZE(partitions));
  82. } else {
  83. iounmap((void __iomem *)impa7_map[i].virt);
  84. }
  85. }
  86. return devicesfound == 0 ? -ENXIO : 0;
  87. }
  88. static void __exit cleanup_impa7(void)
  89. {
  90. int i;
  91. for (i=0; i<NUM_FLASHBANKS; i++) {
  92. if (impa7_mtd[i]) {
  93. mtd_device_unregister(impa7_mtd[i]);
  94. map_destroy(impa7_mtd[i]);
  95. iounmap((void __iomem *)impa7_map[i].virt);
  96. impa7_map[i].virt = NULL;
  97. }
  98. }
  99. }
  100. module_init(init_impa7);
  101. module_exit(cleanup_impa7);
  102. MODULE_LICENSE("GPL");
  103. MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
  104. MODULE_DESCRIPTION("MTD map driver for implementa impA7");