impa7.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Handle mapping of the NOR flash on implementa A7 boards
  4. *
  5. * Copyright 2002 SYSGO Real-Time Solutions GmbH
  6. */
  7. #include <linux/module.h>
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/init.h>
  11. #include <asm/io.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/map.h>
  14. #include <linux/mtd/partitions.h>
  15. #define WINDOW_ADDR0 0x00000000 /* physical properties of flash */
  16. #define WINDOW_SIZE0 0x00800000
  17. #define WINDOW_ADDR1 0x10000000 /* physical properties of flash */
  18. #define WINDOW_SIZE1 0x00800000
  19. #define NUM_FLASHBANKS 2
  20. #define BUSWIDTH 4
  21. #define MSG_PREFIX "impA7:" /* prefix for our printk()'s */
  22. #define MTDID "impa7-%d" /* for mtdparts= partitioning */
  23. static struct mtd_info *impa7_mtd[NUM_FLASHBANKS];
  24. static const char * const rom_probe_types[] = { "jedec_probe", NULL };
  25. static struct map_info impa7_map[NUM_FLASHBANKS] = {
  26. {
  27. .name = "impA7 NOR Flash Bank #0",
  28. .size = WINDOW_SIZE0,
  29. .bankwidth = BUSWIDTH,
  30. },
  31. {
  32. .name = "impA7 NOR Flash Bank #1",
  33. .size = WINDOW_SIZE1,
  34. .bankwidth = BUSWIDTH,
  35. },
  36. };
  37. /*
  38. * MTD partitioning stuff
  39. */
  40. static const struct mtd_partition partitions[] =
  41. {
  42. {
  43. .name = "FileSystem",
  44. .size = 0x800000,
  45. .offset = 0x00000000
  46. },
  47. };
  48. static int __init init_impa7(void)
  49. {
  50. const char * const *type;
  51. int i;
  52. static struct { u_long addr; u_long size; } pt[NUM_FLASHBANKS] = {
  53. { WINDOW_ADDR0, WINDOW_SIZE0 },
  54. { WINDOW_ADDR1, WINDOW_SIZE1 },
  55. };
  56. int devicesfound = 0;
  57. for(i=0; i<NUM_FLASHBANKS; i++)
  58. {
  59. printk(KERN_NOTICE MSG_PREFIX "probing 0x%08lx at 0x%08lx\n",
  60. pt[i].size, pt[i].addr);
  61. impa7_map[i].phys = pt[i].addr;
  62. impa7_map[i].virt = ioremap(pt[i].addr, pt[i].size);
  63. if (!impa7_map[i].virt) {
  64. printk(MSG_PREFIX "failed to ioremap\n");
  65. return -EIO;
  66. }
  67. simple_map_init(&impa7_map[i]);
  68. impa7_mtd[i] = NULL;
  69. type = rom_probe_types;
  70. for(; !impa7_mtd[i] && *type; type++) {
  71. impa7_mtd[i] = do_map_probe(*type, &impa7_map[i]);
  72. }
  73. if (impa7_mtd[i]) {
  74. impa7_mtd[i]->owner = THIS_MODULE;
  75. devicesfound++;
  76. mtd_device_register(impa7_mtd[i], partitions,
  77. ARRAY_SIZE(partitions));
  78. } else {
  79. iounmap((void __iomem *)impa7_map[i].virt);
  80. }
  81. }
  82. return devicesfound == 0 ? -ENXIO : 0;
  83. }
  84. static void __exit cleanup_impa7(void)
  85. {
  86. int i;
  87. for (i=0; i<NUM_FLASHBANKS; i++) {
  88. if (impa7_mtd[i]) {
  89. mtd_device_unregister(impa7_mtd[i]);
  90. map_destroy(impa7_mtd[i]);
  91. iounmap((void __iomem *)impa7_map[i].virt);
  92. impa7_map[i].virt = NULL;
  93. }
  94. }
  95. }
  96. module_init(init_impa7);
  97. module_exit(cleanup_impa7);
  98. MODULE_LICENSE("GPL");
  99. MODULE_AUTHOR("Pavel Bartusek <pba@sysgo.de>");
  100. MODULE_DESCRIPTION("MTD map driver for implementa impA7");