mainstone-flash.c 4.4 KB

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