lubbock-flash.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * $Id: lubbock-flash.c,v 1.21 2005/11/07 11:14:27 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/slab.h>
  18. #include <linux/dma-mapping.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/lubbock.h>
  26. #define ROM_ADDR 0x00000000
  27. #define FLASH_ADDR 0x04000000
  28. #define WINDOW_SIZE 64*1024*1024
  29. static void lubbock_map_inval_cache(struct map_info *map, unsigned long from, ssize_t len)
  30. {
  31. consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
  32. }
  33. static struct map_info lubbock_maps[2] = { {
  34. .size = WINDOW_SIZE,
  35. .phys = 0x00000000,
  36. .inval_cache = lubbock_map_inval_cache,
  37. }, {
  38. .size = WINDOW_SIZE,
  39. .phys = 0x04000000,
  40. .inval_cache = lubbock_map_inval_cache,
  41. } };
  42. static struct mtd_partition lubbock_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 = 0x00100000,
  51. .offset = 0x00040000,
  52. },{
  53. .name = "Filesystem",
  54. .size = MTDPART_SIZ_FULL,
  55. .offset = 0x00140000
  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_lubbock(void)
  63. {
  64. int flashboot = (LUB_CONF_SWITCHES & 1);
  65. int ret = 0, i;
  66. lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth =
  67. (BOOT_DEF & 1) ? 2 : 4;
  68. /* Compensate for the nROMBT switch which swaps the flash banks */
  69. printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
  70. flashboot?"Flash":"ROM", flashboot);
  71. lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
  72. lubbock_maps[flashboot].name = "Lubbock Boot ROM";
  73. for (i = 0; i < 2; i++) {
  74. lubbock_maps[i].virt = ioremap(lubbock_maps[i].phys, WINDOW_SIZE);
  75. if (!lubbock_maps[i].virt) {
  76. printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
  77. if (!ret)
  78. ret = -ENOMEM;
  79. continue;
  80. }
  81. lubbock_maps[i].cached = ioremap_cached(lubbock_maps[i].phys, WINDOW_SIZE);
  82. if (!lubbock_maps[i].cached)
  83. printk(KERN_WARNING "Failed to ioremap cached %s\n", lubbock_maps[i].name);
  84. simple_map_init(&lubbock_maps[i]);
  85. printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n",
  86. lubbock_maps[i].name, lubbock_maps[i].phys,
  87. lubbock_maps[i].bankwidth * 8);
  88. mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
  89. if (!mymtds[i]) {
  90. iounmap((void *)lubbock_maps[i].virt);
  91. if (lubbock_maps[i].cached)
  92. iounmap(lubbock_maps[i].cached);
  93. if (!ret)
  94. ret = -EIO;
  95. continue;
  96. }
  97. mymtds[i]->owner = THIS_MODULE;
  98. ret = parse_mtd_partitions(mymtds[i], probes,
  99. &parsed_parts[i], 0);
  100. if (ret > 0)
  101. nr_parsed_parts[i] = ret;
  102. }
  103. if (!mymtds[0] && !mymtds[1])
  104. return ret;
  105. for (i = 0; i < 2; i++) {
  106. if (!mymtds[i]) {
  107. printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
  108. } else if (nr_parsed_parts[i]) {
  109. add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
  110. } else if (!i) {
  111. printk("Using static partitions on %s\n", lubbock_maps[i].name);
  112. add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions));
  113. } else {
  114. printk("Registering %s as whole device\n", lubbock_maps[i].name);
  115. add_mtd_device(mymtds[i]);
  116. }
  117. }
  118. return 0;
  119. }
  120. static void __exit cleanup_lubbock(void)
  121. {
  122. int i;
  123. for (i = 0; i < 2; i++) {
  124. if (!mymtds[i])
  125. continue;
  126. if (nr_parsed_parts[i] || !i)
  127. del_mtd_partitions(mymtds[i]);
  128. else
  129. del_mtd_device(mymtds[i]);
  130. map_destroy(mymtds[i]);
  131. iounmap((void *)lubbock_maps[i].virt);
  132. if (lubbock_maps[i].cached)
  133. iounmap(lubbock_maps[i].cached);
  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");