mainstone-flash.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * $Id: $
  3. *
  4. * Map driver for the Mainstone developer platform.
  5. *
  6. * Author: Nicolas Pitre
  7. * Copyright: (C) 2001 MontaVista Software Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/init.h>
  17. #include <linux/dma-mapping.h>
  18. #include <linux/mtd/mtd.h>
  19. #include <linux/mtd/map.h>
  20. #include <linux/mtd/partitions.h>
  21. #include <asm/io.h>
  22. #include <asm/hardware.h>
  23. #include <asm/arch/pxa-regs.h>
  24. #include <asm/arch/mainstone.h>
  25. #define ROM_ADDR 0x00000000
  26. #define FLASH_ADDR 0x04000000
  27. #define WINDOW_SIZE 0x04000000
  28. static void mainstone_map_inval_cache(struct map_info *map, unsigned long from,
  29. ssize_t len)
  30. {
  31. consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
  32. }
  33. static struct map_info mainstone_maps[2] = { {
  34. .size = WINDOW_SIZE,
  35. .phys = PXA_CS0_PHYS,
  36. .inval_cache = mainstone_map_inval_cache,
  37. }, {
  38. .size = WINDOW_SIZE,
  39. .phys = PXA_CS1_PHYS,
  40. .inval_cache = mainstone_map_inval_cache,
  41. } };
  42. static struct mtd_partition mainstone_partitions[] = {
  43. {
  44. .name = "Bootloader",
  45. .size = 0x00040000,
  46. .offset = 0,
  47. .mask_flags = MTD_WRITEABLE /* force read-only */
  48. },{
  49. .name = "Kernel",
  50. .size = 0x00400000,
  51. .offset = 0x00040000,
  52. },{
  53. .name = "Filesystem",
  54. .size = MTDPART_SIZ_FULL,
  55. .offset = 0x00440000
  56. }
  57. };
  58. static struct mtd_info *mymtds[2];
  59. static struct mtd_partition *parsed_parts[2];
  60. static int nr_parsed_parts[2];
  61. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  62. static int __init init_mainstone(void)
  63. {
  64. int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */
  65. int ret = 0, i;
  66. mainstone_maps[0].bankwidth = (BOOT_DEF & 1) ? 2 : 4;
  67. mainstone_maps[1].bankwidth = 4;
  68. /* Compensate for SW7 which swaps the flash banks */
  69. mainstone_maps[SW7].name = "processor flash";
  70. mainstone_maps[SW7 ^ 1].name = "main board flash";
  71. printk(KERN_NOTICE "Mainstone configured to boot from %s\n",
  72. mainstone_maps[0].name);
  73. for (i = 0; i < 2; i++) {
  74. mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys,
  75. WINDOW_SIZE);
  76. if (!mainstone_maps[i].virt) {
  77. printk(KERN_WARNING "Failed to ioremap %s\n",
  78. mainstone_maps[i].name);
  79. if (!ret)
  80. ret = -ENOMEM;
  81. continue;
  82. }
  83. mainstone_maps[i].cached =
  84. ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE);
  85. if (!mainstone_maps[i].cached)
  86. printk(KERN_WARNING "Failed to ioremap cached %s\n",
  87. mainstone_maps[i].name);
  88. simple_map_init(&mainstone_maps[i]);
  89. printk(KERN_NOTICE
  90. "Probing %s at physical address 0x%08lx"
  91. " (%d-bit bankwidth)\n",
  92. mainstone_maps[i].name, mainstone_maps[i].phys,
  93. mainstone_maps[i].bankwidth * 8);
  94. mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]);
  95. if (!mymtds[i]) {
  96. iounmap((void *)mainstone_maps[i].virt);
  97. if (mainstone_maps[i].cached)
  98. iounmap(mainstone_maps[i].cached);
  99. if (!ret)
  100. ret = -EIO;
  101. continue;
  102. }
  103. mymtds[i]->owner = THIS_MODULE;
  104. ret = parse_mtd_partitions(mymtds[i], probes,
  105. &parsed_parts[i], 0);
  106. if (ret > 0)
  107. nr_parsed_parts[i] = ret;
  108. }
  109. if (!mymtds[0] && !mymtds[1])
  110. return ret;
  111. for (i = 0; i < 2; i++) {
  112. if (!mymtds[i]) {
  113. printk(KERN_WARNING "%s is absent. Skipping\n",
  114. mainstone_maps[i].name);
  115. } else if (nr_parsed_parts[i]) {
  116. add_mtd_partitions(mymtds[i], parsed_parts[i],
  117. nr_parsed_parts[i]);
  118. } else if (!i) {
  119. printk("Using static partitions on %s\n",
  120. mainstone_maps[i].name);
  121. add_mtd_partitions(mymtds[i], mainstone_partitions,
  122. ARRAY_SIZE(mainstone_partitions));
  123. } else {
  124. printk("Registering %s as whole device\n",
  125. mainstone_maps[i].name);
  126. add_mtd_device(mymtds[i]);
  127. }
  128. }
  129. return 0;
  130. }
  131. static void __exit cleanup_mainstone(void)
  132. {
  133. int i;
  134. for (i = 0; i < 2; i++) {
  135. if (!mymtds[i])
  136. continue;
  137. if (nr_parsed_parts[i] || !i)
  138. del_mtd_partitions(mymtds[i]);
  139. else
  140. del_mtd_device(mymtds[i]);
  141. map_destroy(mymtds[i]);
  142. iounmap((void *)mainstone_maps[i].virt);
  143. if (mainstone_maps[i].cached)
  144. iounmap(mainstone_maps[i].cached);
  145. kfree(parsed_parts[i]);
  146. }
  147. }
  148. module_init(init_mainstone);
  149. module_exit(cleanup_mainstone);
  150. MODULE_LICENSE("GPL");
  151. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  152. MODULE_DESCRIPTION("MTD map driver for Intel Mainstone");