lubbock-flash.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * $Id: lubbock-flash.c,v 1.19 2004/11/04 13:24:15 gleixner Exp $
  3. *
  4. * Map driver for the Lubbock 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/lubbock.h>
  25. #define ROM_ADDR 0x00000000
  26. #define FLASH_ADDR 0x04000000
  27. #define WINDOW_SIZE 64*1024*1024
  28. static void lubbock_map_inval_cache(struct map_info *map, unsigned long from, ssize_t len)
  29. {
  30. consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
  31. }
  32. static struct map_info lubbock_maps[2] = { {
  33. .size = WINDOW_SIZE,
  34. .phys = 0x00000000,
  35. .inval_cache = lubbock_map_inval_cache,
  36. }, {
  37. .size = WINDOW_SIZE,
  38. .phys = 0x04000000,
  39. .inval_cache = lubbock_map_inval_cache,
  40. } };
  41. static struct mtd_partition lubbock_partitions[] = {
  42. {
  43. .name = "Bootloader",
  44. .size = 0x00040000,
  45. .offset = 0,
  46. .mask_flags = MTD_WRITEABLE /* force read-only */
  47. },{
  48. .name = "Kernel",
  49. .size = 0x00100000,
  50. .offset = 0x00040000,
  51. },{
  52. .name = "Filesystem",
  53. .size = MTDPART_SIZ_FULL,
  54. .offset = 0x00140000
  55. }
  56. };
  57. static struct mtd_info *mymtds[2];
  58. static struct mtd_partition *parsed_parts[2];
  59. static int nr_parsed_parts[2];
  60. static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
  61. static int __init init_lubbock(void)
  62. {
  63. int flashboot = (LUB_CONF_SWITCHES & 1);
  64. int ret = 0, i;
  65. lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth =
  66. (BOOT_DEF & 1) ? 2 : 4;
  67. /* Compensate for the nROMBT switch which swaps the flash banks */
  68. printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
  69. flashboot?"Flash":"ROM", flashboot);
  70. lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
  71. lubbock_maps[flashboot].name = "Lubbock Boot ROM";
  72. for (i = 0; i < 2; i++) {
  73. lubbock_maps[i].virt = ioremap(lubbock_maps[i].phys, WINDOW_SIZE);
  74. if (!lubbock_maps[i].virt) {
  75. printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
  76. if (!ret)
  77. ret = -ENOMEM;
  78. continue;
  79. }
  80. lubbock_maps[i].cached = ioremap_cached(lubbock_maps[i].phys, WINDOW_SIZE);
  81. if (!lubbock_maps[i].cached)
  82. printk(KERN_WARNING "Failed to ioremap cached %s\n", lubbock_maps[i].name);
  83. simple_map_init(&lubbock_maps[i]);
  84. printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n",
  85. lubbock_maps[i].name, lubbock_maps[i].phys,
  86. lubbock_maps[i].bankwidth * 8);
  87. mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
  88. if (!mymtds[i]) {
  89. iounmap((void *)lubbock_maps[i].virt);
  90. if (lubbock_maps[i].cached)
  91. iounmap(lubbock_maps[i].cached);
  92. if (!ret)
  93. ret = -EIO;
  94. continue;
  95. }
  96. mymtds[i]->owner = THIS_MODULE;
  97. ret = parse_mtd_partitions(mymtds[i], probes,
  98. &parsed_parts[i], 0);
  99. if (ret > 0)
  100. nr_parsed_parts[i] = ret;
  101. }
  102. if (!mymtds[0] && !mymtds[1])
  103. return ret;
  104. for (i = 0; i < 2; i++) {
  105. if (!mymtds[i]) {
  106. printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
  107. } else if (nr_parsed_parts[i]) {
  108. add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
  109. } else if (!i) {
  110. printk("Using static partitions on %s\n", lubbock_maps[i].name);
  111. add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions));
  112. } else {
  113. printk("Registering %s as whole device\n", lubbock_maps[i].name);
  114. add_mtd_device(mymtds[i]);
  115. }
  116. }
  117. return 0;
  118. }
  119. static void __exit cleanup_lubbock(void)
  120. {
  121. int i;
  122. for (i = 0; i < 2; i++) {
  123. if (!mymtds[i])
  124. continue;
  125. if (nr_parsed_parts[i] || !i)
  126. del_mtd_partitions(mymtds[i]);
  127. else
  128. del_mtd_device(mymtds[i]);
  129. map_destroy(mymtds[i]);
  130. iounmap((void *)lubbock_maps[i].virt);
  131. if (lubbock_maps[i].cached)
  132. iounmap(lubbock_maps[i].cached);
  133. if (parsed_parts[i])
  134. kfree(parsed_parts[i]);
  135. }
  136. }
  137. module_init(init_lubbock);
  138. module_exit(cleanup_lubbock);
  139. MODULE_LICENSE("GPL");
  140. MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
  141. MODULE_DESCRIPTION("MTD map driver for Intel Lubbock");