db1x00-flash.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Flash memory access on Alchemy Db1xxx boards
  3. *
  4. * $Id: db1x00-flash.c,v 1.6 2004/11/04 13:24:14 gleixner Exp $
  5. *
  6. * (C) 2003 Pete Popov <ppopov@embeddedalley.com>
  7. *
  8. */
  9. #include <linux/config.h>
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/map.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/io.h>
  18. #ifdef DEBUG_RW
  19. #define DBG(x...) printk(x)
  20. #else
  21. #define DBG(x...)
  22. #endif
  23. /* MTD CONFIG OPTIONS */
  24. #if defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
  25. #define DB1X00_BOTH_BANKS
  26. #elif defined(CONFIG_MTD_DB1X00_BOOT) && !defined(CONFIG_MTD_DB1X00_USER)
  27. #define DB1X00_BOOT_ONLY
  28. #elif !defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER)
  29. #define DB1X00_USER_ONLY
  30. #endif
  31. static unsigned long window_addr;
  32. static unsigned long window_size;
  33. static unsigned long flash_size;
  34. static unsigned short *bcsr = (unsigned short *)0xAE000000;
  35. static unsigned char flash_bankwidth = 4;
  36. /*
  37. * The Db1x boards support different flash densities. We setup
  38. * the mtd_partition structures below for default of 64Mbit
  39. * flash densities, and override the partitions sizes, if
  40. * necessary, after we check the board status register.
  41. */
  42. #ifdef DB1X00_BOTH_BANKS
  43. /* both banks will be used. Combine the first bank and the first
  44. * part of the second bank together into a single jffs/jffs2
  45. * partition.
  46. */
  47. static struct mtd_partition db1x00_partitions[] = {
  48. {
  49. .name = "User FS",
  50. .size = 0x1c00000,
  51. .offset = 0x0000000
  52. },{
  53. .name = "yamon",
  54. .size = 0x0100000,
  55. .offset = MTDPART_OFS_APPEND,
  56. .mask_flags = MTD_WRITEABLE
  57. },{
  58. .name = "raw kernel",
  59. .size = (0x300000-0x40000), /* last 256KB is env */
  60. .offset = MTDPART_OFS_APPEND,
  61. }
  62. };
  63. #elif defined(DB1X00_BOOT_ONLY)
  64. static struct mtd_partition db1x00_partitions[] = {
  65. {
  66. .name = "User FS",
  67. .size = 0x00c00000,
  68. .offset = 0x0000000
  69. },{
  70. .name = "yamon",
  71. .size = 0x0100000,
  72. .offset = MTDPART_OFS_APPEND,
  73. .mask_flags = MTD_WRITEABLE
  74. },{
  75. .name = "raw kernel",
  76. .size = (0x300000-0x40000), /* last 256KB is env */
  77. .offset = MTDPART_OFS_APPEND,
  78. }
  79. };
  80. #elif defined(DB1X00_USER_ONLY)
  81. static struct mtd_partition db1x00_partitions[] = {
  82. {
  83. .name = "User FS",
  84. .size = 0x0e00000,
  85. .offset = 0x0000000
  86. },{
  87. .name = "raw kernel",
  88. .size = MTDPART_SIZ_FULL,
  89. .offset = MTDPART_OFS_APPEND,
  90. }
  91. };
  92. #else
  93. #error MTD_DB1X00 define combo error /* should never happen */
  94. #endif
  95. #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
  96. #define NAME "Db1x00 Linux Flash"
  97. static struct map_info db1xxx_mtd_map = {
  98. .name = NAME,
  99. };
  100. static struct mtd_partition *parsed_parts;
  101. static struct mtd_info *db1xxx_mtd;
  102. /*
  103. * Probe the flash density and setup window address and size
  104. * based on user CONFIG options. There are times when we don't
  105. * want the MTD driver to be probing the boot or user flash,
  106. * so having the option to enable only one bank is important.
  107. */
  108. int setup_flash_params(void)
  109. {
  110. switch ((bcsr[2] >> 14) & 0x3) {
  111. case 0: /* 64Mbit devices */
  112. flash_size = 0x800000; /* 8MB per part */
  113. #if defined(DB1X00_BOTH_BANKS)
  114. window_addr = 0x1E000000;
  115. window_size = 0x2000000;
  116. #elif defined(DB1X00_BOOT_ONLY)
  117. window_addr = 0x1F000000;
  118. window_size = 0x1000000;
  119. #else /* USER ONLY */
  120. window_addr = 0x1E000000;
  121. window_size = 0x1000000;
  122. #endif
  123. break;
  124. case 1:
  125. /* 128 Mbit devices */
  126. flash_size = 0x1000000; /* 16MB per part */
  127. #if defined(DB1X00_BOTH_BANKS)
  128. window_addr = 0x1C000000;
  129. window_size = 0x4000000;
  130. /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
  131. db1x00_partitions[0].size = 0x3C00000;
  132. #elif defined(DB1X00_BOOT_ONLY)
  133. window_addr = 0x1E000000;
  134. window_size = 0x2000000;
  135. /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
  136. db1x00_partitions[0].size = 0x1C00000;
  137. #else /* USER ONLY */
  138. window_addr = 0x1C000000;
  139. window_size = 0x2000000;
  140. /* USERFS from 0x1C00 0000 to 0x1DE00000 */
  141. db1x00_partitions[0].size = 0x1DE0000;
  142. #endif
  143. break;
  144. case 2:
  145. /* 256 Mbit devices */
  146. flash_size = 0x4000000; /* 64MB per part */
  147. #if defined(DB1X00_BOTH_BANKS)
  148. return 1;
  149. #elif defined(DB1X00_BOOT_ONLY)
  150. /* Boot ROM flash bank only; no user bank */
  151. window_addr = 0x1C000000;
  152. window_size = 0x4000000;
  153. /* USERFS from 0x1C00 0000 to 0x1FC00000 */
  154. db1x00_partitions[0].size = 0x3C00000;
  155. #else /* USER ONLY */
  156. return 1;
  157. #endif
  158. break;
  159. default:
  160. return 1;
  161. }
  162. db1xxx_mtd_map.size = window_size;
  163. db1xxx_mtd_map.bankwidth = flash_bankwidth;
  164. db1xxx_mtd_map.phys = window_addr;
  165. db1xxx_mtd_map.bankwidth = flash_bankwidth;
  166. return 0;
  167. }
  168. int __init db1x00_mtd_init(void)
  169. {
  170. struct mtd_partition *parts;
  171. int nb_parts = 0;
  172. if (setup_flash_params())
  173. return -ENXIO;
  174. /*
  175. * Static partition definition selection
  176. */
  177. parts = db1x00_partitions;
  178. nb_parts = NB_OF(db1x00_partitions);
  179. /*
  180. * Now let's probe for the actual flash. Do it here since
  181. * specific machine settings might have been set above.
  182. */
  183. printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n",
  184. db1xxx_mtd_map.bankwidth*8);
  185. db1xxx_mtd_map.virt = ioremap(window_addr, window_size);
  186. db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map);
  187. if (!db1xxx_mtd) return -ENXIO;
  188. db1xxx_mtd->owner = THIS_MODULE;
  189. add_mtd_partitions(db1xxx_mtd, parts, nb_parts);
  190. return 0;
  191. }
  192. static void __exit db1x00_mtd_cleanup(void)
  193. {
  194. if (db1xxx_mtd) {
  195. del_mtd_partitions(db1xxx_mtd);
  196. map_destroy(db1xxx_mtd);
  197. if (parsed_parts)
  198. kfree(parsed_parts);
  199. }
  200. }
  201. module_init(db1x00_mtd_init);
  202. module_exit(db1x00_mtd_cleanup);
  203. MODULE_AUTHOR("Pete Popov");
  204. MODULE_DESCRIPTION("Db1x00 mtd map driver");
  205. MODULE_LICENSE("GPL");