db1550-flash.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Flash memory access on Alchemy Db1550 board
  3. *
  4. * $Id: db1550-flash.c,v 1.7 2004/11/04 13:24:14 gleixner Exp $
  5. *
  6. * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c:
  7. * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mtd/mtd.h>
  16. #include <linux/mtd/map.h>
  17. #include <linux/mtd/partitions.h>
  18. #include <asm/io.h>
  19. #ifdef DEBUG_RW
  20. #define DBG(x...) printk(x)
  21. #else
  22. #define DBG(x...)
  23. #endif
  24. static unsigned long window_addr;
  25. static unsigned long window_size;
  26. static struct map_info db1550_map = {
  27. .name = "Db1550 flash",
  28. };
  29. static unsigned char flash_bankwidth = 4;
  30. /*
  31. * Support only 64MB NOR Flash parts
  32. */
  33. #if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
  34. #define DB1550_BOTH_BANKS
  35. #elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER)
  36. #define DB1550_BOOT_ONLY
  37. #elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
  38. #define DB1550_USER_ONLY
  39. #endif
  40. #ifdef DB1550_BOTH_BANKS
  41. /* both banks will be used. Combine the first bank and the first
  42. * part of the second bank together into a single jffs/jffs2
  43. * partition.
  44. */
  45. static struct mtd_partition db1550_partitions[] = {
  46. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  47. * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
  48. * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
  49. */
  50. {
  51. .name = "User FS",
  52. .size = (0x1FC00000 - 0x18000000),
  53. .offset = 0x0000000
  54. },{
  55. .name = "yamon",
  56. .size = 0x0100000,
  57. .offset = MTDPART_OFS_APPEND,
  58. .mask_flags = MTD_WRITEABLE
  59. },{
  60. .name = "raw kernel",
  61. .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
  62. .offset = MTDPART_OFS_APPEND,
  63. }
  64. };
  65. #elif defined(DB1550_BOOT_ONLY)
  66. static struct mtd_partition db1550_partitions[] = {
  67. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  68. * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
  69. */
  70. {
  71. .name = "User FS",
  72. .size = 0x03c00000,
  73. .offset = 0x0000000
  74. },{
  75. .name = "yamon",
  76. .size = 0x0100000,
  77. .offset = MTDPART_OFS_APPEND,
  78. .mask_flags = MTD_WRITEABLE
  79. },{
  80. .name = "raw kernel",
  81. .size = (0x300000-0x40000), /* last 256KB is yamon env */
  82. .offset = MTDPART_OFS_APPEND,
  83. }
  84. };
  85. #elif defined(DB1550_USER_ONLY)
  86. static struct mtd_partition db1550_partitions[] = {
  87. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  88. * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
  89. */
  90. {
  91. .name = "User FS",
  92. .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
  93. .offset = 0x0000000
  94. },{
  95. .name = "raw kernel",
  96. .size = MTDPART_SIZ_FULL,
  97. .offset = MTDPART_OFS_APPEND,
  98. }
  99. };
  100. #else
  101. #error MTD_DB1550 define combo error /* should never happen */
  102. #endif
  103. #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
  104. static struct mtd_info *mymtd;
  105. /*
  106. * Probe the flash density and setup window address and size
  107. * based on user CONFIG options. There are times when we don't
  108. * want the MTD driver to be probing the boot or user flash,
  109. * so having the option to enable only one bank is important.
  110. */
  111. int setup_flash_params(void)
  112. {
  113. #if defined(DB1550_BOTH_BANKS)
  114. window_addr = 0x18000000;
  115. window_size = 0x8000000;
  116. #elif defined(DB1550_BOOT_ONLY)
  117. window_addr = 0x1C000000;
  118. window_size = 0x4000000;
  119. #else /* USER ONLY */
  120. window_addr = 0x18000000;
  121. window_size = 0x4000000;
  122. #endif
  123. return 0;
  124. }
  125. int __init db1550_mtd_init(void)
  126. {
  127. struct mtd_partition *parts;
  128. int nb_parts = 0;
  129. /* Default flash bankwidth */
  130. db1550_map.bankwidth = flash_bankwidth;
  131. if (setup_flash_params())
  132. return -ENXIO;
  133. /*
  134. * Static partition definition selection
  135. */
  136. parts = db1550_partitions;
  137. nb_parts = NB_OF(db1550_partitions);
  138. db1550_map.size = window_size;
  139. /*
  140. * Now let's probe for the actual flash. Do it here since
  141. * specific machine settings might have been set above.
  142. */
  143. printk(KERN_NOTICE "Db1550 flash: probing %d-bit flash bus\n",
  144. db1550_map.bankwidth*8);
  145. db1550_map.virt = ioremap(window_addr, window_size);
  146. mymtd = do_map_probe("cfi_probe", &db1550_map);
  147. if (!mymtd) return -ENXIO;
  148. mymtd->owner = THIS_MODULE;
  149. add_mtd_partitions(mymtd, parts, nb_parts);
  150. return 0;
  151. }
  152. static void __exit db1550_mtd_cleanup(void)
  153. {
  154. if (mymtd) {
  155. del_mtd_partitions(mymtd);
  156. map_destroy(mymtd);
  157. iounmap((void *) db1550_map.virt);
  158. }
  159. }
  160. module_init(db1550_mtd_init);
  161. module_exit(db1550_mtd_cleanup);
  162. MODULE_AUTHOR("Embedded Edge, LLC");
  163. MODULE_DESCRIPTION("Db1550 mtd map driver");
  164. MODULE_LICENSE("GPL");