alchemy-flash.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Flash memory access on AMD Alchemy evaluation boards
  3. *
  4. * $Id: alchemy-flash.c,v 1.2 2005/11/07 11:14:26 gleixner Exp $
  5. *
  6. * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
  7. *
  8. */
  9. #include <linux/init.h>
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/map.h>
  15. #include <linux/mtd/partitions.h>
  16. #include <asm/io.h>
  17. #ifdef DEBUG_RW
  18. #define DBG(x...) printk(x)
  19. #else
  20. #define DBG(x...)
  21. #endif
  22. #ifdef CONFIG_MIPS_PB1000
  23. #define BOARD_MAP_NAME "Pb1000 Flash"
  24. #define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
  25. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  26. #endif
  27. #ifdef CONFIG_MIPS_PB1500
  28. #define BOARD_MAP_NAME "Pb1500 Flash"
  29. #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
  30. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  31. #endif
  32. #ifdef CONFIG_MIPS_PB1100
  33. #define BOARD_MAP_NAME "Pb1100 Flash"
  34. #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
  35. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  36. #endif
  37. #ifdef CONFIG_MIPS_PB1550
  38. #define BOARD_MAP_NAME "Pb1550 Flash"
  39. #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
  40. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  41. #endif
  42. #ifdef CONFIG_MIPS_PB1200
  43. #define BOARD_MAP_NAME "Pb1200 Flash"
  44. #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
  45. #define BOARD_FLASH_WIDTH 2 /* 16-bits */
  46. #endif
  47. #ifdef CONFIG_MIPS_DB1000
  48. #define BOARD_MAP_NAME "Db1000 Flash"
  49. #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
  50. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  51. #endif
  52. #ifdef CONFIG_MIPS_DB1500
  53. #define BOARD_MAP_NAME "Db1500 Flash"
  54. #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
  55. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  56. #endif
  57. #ifdef CONFIG_MIPS_DB1100
  58. #define BOARD_MAP_NAME "Db1100 Flash"
  59. #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
  60. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  61. #endif
  62. #ifdef CONFIG_MIPS_DB1550
  63. #define BOARD_MAP_NAME "Db1550 Flash"
  64. #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
  65. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  66. #endif
  67. #ifdef CONFIG_MIPS_DB1200
  68. #define BOARD_MAP_NAME "Db1200 Flash"
  69. #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
  70. #define BOARD_FLASH_WIDTH 2 /* 16-bits */
  71. #endif
  72. #ifdef CONFIG_MIPS_HYDROGEN3
  73. #define BOARD_MAP_NAME "Hydrogen3 Flash"
  74. #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
  75. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  76. #define USE_LOCAL_ACCESSORS /* why? */
  77. #endif
  78. #ifdef CONFIG_MIPS_BOSPORUS
  79. #define BOARD_MAP_NAME "Bosporus Flash"
  80. #define BOARD_FLASH_SIZE 0x01000000 /* 16MB */
  81. #define BOARD_FLASH_WIDTH 2 /* 16-bits */
  82. #endif
  83. #ifdef CONFIG_MIPS_MIRAGE
  84. #define BOARD_MAP_NAME "Mirage Flash"
  85. #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
  86. #define BOARD_FLASH_WIDTH 4 /* 32-bits */
  87. #define USE_LOCAL_ACCESSORS /* why? */
  88. #endif
  89. static struct map_info alchemy_map = {
  90. .name = BOARD_MAP_NAME,
  91. };
  92. static struct mtd_partition alchemy_partitions[] = {
  93. {
  94. .name = "User FS",
  95. .size = BOARD_FLASH_SIZE - 0x00400000,
  96. .offset = 0x0000000
  97. },{
  98. .name = "YAMON",
  99. .size = 0x0100000,
  100. .offset = MTDPART_OFS_APPEND,
  101. .mask_flags = MTD_WRITEABLE
  102. },{
  103. .name = "raw kernel",
  104. .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
  105. .offset = MTDPART_OFS_APPEND,
  106. }
  107. };
  108. static struct mtd_info *mymtd;
  109. int __init alchemy_mtd_init(void)
  110. {
  111. struct mtd_partition *parts;
  112. int nb_parts = 0;
  113. unsigned long window_addr;
  114. unsigned long window_size;
  115. /* Default flash buswidth */
  116. alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
  117. window_addr = 0x20000000 - BOARD_FLASH_SIZE;
  118. window_size = BOARD_FLASH_SIZE;
  119. #ifdef CONFIG_MIPS_MIRAGE_WHY
  120. /* Boot ROM flash bank only; no user bank */
  121. window_addr = 0x1C000000;
  122. window_size = 0x04000000;
  123. /* USERFS from 0x1C00 0000 to 0x1FC00000 */
  124. alchemy_partitions[0].size = 0x03C00000;
  125. #endif
  126. /*
  127. * Static partition definition selection
  128. */
  129. parts = alchemy_partitions;
  130. nb_parts = ARRAY_SIZE(alchemy_partitions);
  131. alchemy_map.size = window_size;
  132. /*
  133. * Now let's probe for the actual flash. Do it here since
  134. * specific machine settings might have been set above.
  135. */
  136. printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
  137. alchemy_map.bankwidth*8);
  138. alchemy_map.virt = ioremap(window_addr, window_size);
  139. mymtd = do_map_probe("cfi_probe", &alchemy_map);
  140. if (!mymtd) {
  141. iounmap(alchemy_map.virt);
  142. return -ENXIO;
  143. }
  144. mymtd->owner = THIS_MODULE;
  145. add_mtd_partitions(mymtd, parts, nb_parts);
  146. return 0;
  147. }
  148. static void __exit alchemy_mtd_cleanup(void)
  149. {
  150. if (mymtd) {
  151. del_mtd_partitions(mymtd);
  152. map_destroy(mymtd);
  153. iounmap(alchemy_map.virt);
  154. }
  155. }
  156. module_init(alchemy_mtd_init);
  157. module_exit(alchemy_mtd_cleanup);
  158. MODULE_AUTHOR("Embedded Alley Solutions, Inc");
  159. MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver");
  160. MODULE_LICENSE("GPL");