pb1550-flash.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Flash memory access on Alchemy Pb1550 board
  3. *
  4. * $Id: pb1550-flash.c,v 1.6 2004/11/04 13:24:15 gleixner Exp $
  5. *
  6. * (C) 2004 Embedded Edge, LLC, based on pb1550-flash.c:
  7. * (C) 2003 Pete Popov <ppopov@pacbell.net>
  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. #include <asm/au1000.h>
  20. #include <asm/pb1550.h>
  21. #ifdef DEBUG_RW
  22. #define DBG(x...) printk(x)
  23. #else
  24. #define DBG(x...)
  25. #endif
  26. static unsigned long window_addr;
  27. static unsigned long window_size;
  28. static struct map_info pb1550_map = {
  29. .name = "Pb1550 flash",
  30. };
  31. static unsigned char flash_bankwidth = 4;
  32. /*
  33. * Support only 64MB NOR Flash parts
  34. */
  35. #ifdef PB1550_BOTH_BANKS
  36. /* both banks will be used. Combine the first bank and the first
  37. * part of the second bank together into a single jffs/jffs2
  38. * partition.
  39. */
  40. static struct mtd_partition pb1550_partitions[] = {
  41. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  42. * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
  43. * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
  44. */
  45. {
  46. .name = "User FS",
  47. .size = (0x1FC00000 - 0x18000000),
  48. .offset = 0x0000000
  49. },{
  50. .name = "yamon",
  51. .size = 0x0100000,
  52. .offset = MTDPART_OFS_APPEND,
  53. .mask_flags = MTD_WRITEABLE
  54. },{
  55. .name = "raw kernel",
  56. .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
  57. .offset = MTDPART_OFS_APPEND,
  58. }
  59. };
  60. #elif defined(PB1550_BOOT_ONLY)
  61. static struct mtd_partition pb1550_partitions[] = {
  62. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  63. * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
  64. */
  65. {
  66. .name = "User FS",
  67. .size = 0x03c00000,
  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 yamon env */
  77. .offset = MTDPART_OFS_APPEND,
  78. }
  79. };
  80. #elif defined(PB1550_USER_ONLY)
  81. static struct mtd_partition pb1550_partitions[] = {
  82. /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
  83. * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
  84. */
  85. {
  86. .name = "User FS",
  87. .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
  88. .offset = 0x0000000
  89. },{
  90. .name = "raw kernel",
  91. .size = MTDPART_SIZ_FULL,
  92. .offset = MTDPART_OFS_APPEND,
  93. }
  94. };
  95. #else
  96. #error MTD_PB1550 define combo error /* should never happen */
  97. #endif
  98. #define NB_OF(x) (sizeof(x)/sizeof(x[0]))
  99. static struct mtd_info *mymtd;
  100. /*
  101. * Probe the flash density and setup window address and size
  102. * based on user CONFIG options. There are times when we don't
  103. * want the MTD driver to be probing the boot or user flash,
  104. * so having the option to enable only one bank is important.
  105. */
  106. int setup_flash_params(void)
  107. {
  108. u16 boot_swapboot;
  109. boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) |
  110. ((bcsr->status >> 6) & 0x1);
  111. printk("Pb1550 MTD: boot:swap %d\n", boot_swapboot);
  112. switch (boot_swapboot) {
  113. case 0: /* 512Mbit devices, both enabled */
  114. case 1:
  115. case 8:
  116. case 9:
  117. #if defined(PB1550_BOTH_BANKS)
  118. window_addr = 0x18000000;
  119. window_size = 0x8000000;
  120. #elif defined(PB1550_BOOT_ONLY)
  121. window_addr = 0x1C000000;
  122. window_size = 0x4000000;
  123. #else /* USER ONLY */
  124. window_addr = 0x1E000000;
  125. window_size = 0x4000000;
  126. #endif
  127. break;
  128. case 0xC:
  129. case 0xD:
  130. case 0xE:
  131. case 0xF:
  132. /* 64 MB Boot NOR Flash is disabled */
  133. /* and the start address is moved to 0x0C00000 */
  134. window_addr = 0x0C000000;
  135. window_size = 0x4000000;
  136. default:
  137. printk("Pb1550 MTD: unsupported boot:swap setting\n");
  138. return 1;
  139. }
  140. return 0;
  141. }
  142. int __init pb1550_mtd_init(void)
  143. {
  144. struct mtd_partition *parts;
  145. int nb_parts = 0;
  146. /* Default flash bankwidth */
  147. pb1550_map.bankwidth = flash_bankwidth;
  148. if (setup_flash_params())
  149. return -ENXIO;
  150. /*
  151. * Static partition definition selection
  152. */
  153. parts = pb1550_partitions;
  154. nb_parts = NB_OF(pb1550_partitions);
  155. pb1550_map.size = window_size;
  156. /*
  157. * Now let's probe for the actual flash. Do it here since
  158. * specific machine settings might have been set above.
  159. */
  160. printk(KERN_NOTICE "Pb1550 flash: probing %d-bit flash bus\n",
  161. pb1550_map.bankwidth*8);
  162. pb1550_map.virt = ioremap(window_addr, window_size);
  163. mymtd = do_map_probe("cfi_probe", &pb1550_map);
  164. if (!mymtd) return -ENXIO;
  165. mymtd->owner = THIS_MODULE;
  166. add_mtd_partitions(mymtd, parts, nb_parts);
  167. return 0;
  168. }
  169. static void __exit pb1550_mtd_cleanup(void)
  170. {
  171. if (mymtd) {
  172. del_mtd_partitions(mymtd);
  173. map_destroy(mymtd);
  174. }
  175. }
  176. module_init(pb1550_mtd_init);
  177. module_exit(pb1550_mtd_cleanup);
  178. MODULE_AUTHOR("Embedded Edge, LLC");
  179. MODULE_DESCRIPTION("Pb1550 mtd map driver");
  180. MODULE_LICENSE("GPL");