nand.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * (C) Copyright 2008 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * (C) Copyright 2006
  5. * Thomas Waehner, TQ-System GmbH, thomas.waehner@tqs.de.
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <common.h>
  26. #include <asm/processor.h>
  27. #include <asm/immap_85xx.h>
  28. #include <asm/processor.h>
  29. #include <asm/mmu.h>
  30. #include <asm/io.h>
  31. #include <asm/errno.h>
  32. #include <linux/mtd/mtd.h>
  33. #include <linux/mtd/fsl_upm.h>
  34. #include <ioports.h>
  35. #include <nand.h>
  36. DECLARE_GLOBAL_DATA_PTR;
  37. extern uint get_lbc_clock (void);
  38. /* index of UPM RAM array run pattern for NAND command cycle */
  39. #define CONFIG_SYS_NAN_UPM_WRITE_CMD_OFS 0x08
  40. /* index of UPM RAM array run pattern for NAND address cycle */
  41. #define CONFIG_SYS_NAND_UPM_WRITE_ADDR_OFS 0x10
  42. /* Structure for table with supported UPM timings */
  43. struct upm_freq {
  44. ulong freq;
  45. const u32 *upm_patt;
  46. uchar gpl4_disable;
  47. uchar ehtr;
  48. uchar ead;
  49. };
  50. /* NAND-FLASH UPM tables for TQM85XX according to TQM8548.pq.timing.101.doc */
  51. /* UPM pattern for bus clock = 25 MHz */
  52. static const u32 upm_patt_25[] = {
  53. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  54. /* 0x00 */ 0x0ff32000, 0x0fa32000, 0x3fb32005, 0xfffffc00,
  55. /* 0x04 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  56. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  57. /* 0x08 */ 0x00ff2c30, 0x00ff2c30, 0x0fff2c35, 0xfffffc00,
  58. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  59. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  60. /* 0x10 */ 0x00f3ec30, 0x00f3ec30, 0x0ff3ec35, 0xfffffc00,
  61. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  62. /* UPM Write Single RAM array entry -> NAND Write Data */
  63. /* 0x18 */ 0x00f32c00, 0x00f32c00, 0x0ff32c05, 0xfffffc00,
  64. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  65. /* UPM Write Burst RAM array entry -> unused */
  66. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  67. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  68. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  69. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  70. /* UPM Refresh Timer RAM array entry -> unused */
  71. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  72. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  73. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  74. /* UPM Exception RAM array entry -> unsused */
  75. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  76. };
  77. /* UPM pattern for bus clock = 33.3 MHz */
  78. static const u32 upm_patt_33[] = {
  79. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  80. /* 0x00 */ 0x0ff32000, 0x0fa32100, 0x3fb32005, 0xfffffc00,
  81. /* 0x04 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  82. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  83. /* 0x08 */ 0x00ff2c30, 0x00ff2c30, 0x0fff2c35, 0xfffffc00,
  84. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  85. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  86. /* 0x10 */ 0x00f3ec30, 0x00f3ec30, 0x0ff3ec35, 0xfffffc00,
  87. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  88. /* UPM Write Single RAM array entry -> NAND Write Data */
  89. /* 0x18 */ 0x00f32c00, 0x00f32c00, 0x0ff32c05, 0xfffffc00,
  90. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  91. /* UPM Write Burst RAM array entry -> unused */
  92. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  93. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  94. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  95. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  96. /* UPM Refresh Timer RAM array entry -> unused */
  97. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  98. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  99. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  100. /* UPM Exception RAM array entry -> unsused */
  101. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  102. };
  103. /* UPM pattern for bus clock = 41.7 MHz */
  104. static const u32 upm_patt_42[] = {
  105. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  106. /* 0x00 */ 0x0ff32000, 0x0fa32100, 0x3fb32005, 0xfffffc00,
  107. /* 0x04 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  108. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  109. /* 0x08 */ 0x00ff2c30, 0x00ff2c30, 0x0fff2c35, 0xfffffc00,
  110. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  111. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  112. /* 0x10 */ 0x00f3ec30, 0x00f3ec30, 0x0ff3ec35, 0xfffffc00,
  113. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  114. /* UPM Write Single RAM array entry -> NAND Write Data */
  115. /* 0x18 */ 0x00f32c00, 0x00f32c00, 0x0ff32c05, 0xfffffc00,
  116. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  117. /* UPM Write Burst RAM array entry -> unused */
  118. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  119. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  120. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  121. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  122. /* UPM Refresh Timer RAM array entry -> unused */
  123. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  124. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  125. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  126. /* UPM Exception RAM array entry -> unsused */
  127. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  128. };
  129. /* UPM pattern for bus clock = 50 MHz */
  130. static const u32 upm_patt_50[] = {
  131. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  132. /* 0x00 */ 0x0ff33000, 0x0fa33100, 0x0fa33005, 0xfffffc00,
  133. /* 0x04 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  134. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  135. /* 0x08 */ 0x00ff3d30, 0x00ff3c30, 0x0fff3c35, 0xfffffc00,
  136. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  137. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  138. /* 0x10 */ 0x00f3fd30, 0x00f3fc30, 0x0ff3fc35, 0xfffffc00,
  139. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  140. /* UPM Write Single RAM array entry -> NAND Write Data */
  141. /* 0x18 */ 0x00f33d00, 0x00f33c00, 0x0ff33c05, 0xfffffc00,
  142. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  143. /* UPM Write Burst RAM array entry -> unused */
  144. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  145. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  146. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  147. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  148. /* UPM Refresh Timer RAM array entry -> unused */
  149. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  150. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  151. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  152. /* UPM Exception RAM array entry -> unsused */
  153. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  154. };
  155. /* UPM pattern for bus clock = 66.7 MHz */
  156. static const u32 upm_patt_67[] = {
  157. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  158. /* 0x00 */ 0x0ff33000, 0x0fe33000, 0x0fa33100, 0x0fa33000,
  159. /* 0x04 */ 0x0fa33005, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  160. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  161. /* 0x08 */ 0x00ff3d30, 0x00ff3c30, 0x0fff3c30, 0x0fff3c35,
  162. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  163. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  164. /* 0x10 */ 0x00f3fd30, 0x00f3fc30, 0x0ff3fc30, 0x0ff3fc35,
  165. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  166. /* UPM Write Single RAM array entry -> NAND Write Data */
  167. /* 0x18 */ 0x00f33d00, 0x00f33c00, 0x0ff33c00, 0x0ff33c05,
  168. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  169. /* UPM Write Burst RAM array entry -> unused */
  170. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  171. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  172. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  173. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  174. /* UPM Refresh Timer RAM array entry -> unused */
  175. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  176. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  177. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  178. /* UPM Exception RAM array entry -> unsused */
  179. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  180. };
  181. /* UPM pattern for bus clock = 83.3 MHz */
  182. static const u32 upm_patt_83[] = {
  183. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  184. /* 0x00 */ 0x0ff33000, 0x0fe33000, 0x0fa33100, 0x0fa33000,
  185. /* 0x04 */ 0x0fa33005, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  186. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  187. /* 0x08 */ 0x00ff3e30, 0x00ff3c30, 0x0fff3c30, 0x0fff3c35,
  188. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  189. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  190. /* 0x10 */ 0x00f3fe30, 0x00f3fc30, 0x0ff3fc30, 0x0ff3fc35,
  191. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  192. /* UPM Write Single RAM array entry -> NAND Write Data */
  193. /* 0x18 */ 0x00f33e00, 0x00f33c00, 0x0ff33c00, 0x0ff33c05,
  194. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  195. /* UPM Write Burst RAM array entry -> unused */
  196. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  197. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  198. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  199. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  200. /* UPM Refresh Timer RAM array entry -> unused */
  201. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  202. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  203. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  204. /* UPM Exception RAM array entry -> unsused */
  205. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  206. };
  207. /* UPM pattern for bus clock = 100 MHz */
  208. static const u32 upm_patt_100[] = {
  209. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  210. /* 0x00 */ 0x0ff33100, 0x0fe33000, 0x0fa33200, 0x0fa33000,
  211. /* 0x04 */ 0x0fa33005, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  212. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  213. /* 0x08 */ 0x00ff3f30, 0x00ff3c30, 0x0fff3c30, 0x0fff3c35,
  214. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  215. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  216. /* 0x10 */ 0x00f3ff30, 0x00f3fc30, 0x0ff3fc30, 0x0ff3fc35,
  217. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  218. /* UPM Write Single RAM array entry -> NAND Write Data */
  219. /* 0x18 */ 0x00f33f00, 0x00f33c00, 0x0ff33c00, 0x0ff33c05,
  220. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  221. /* UPM Write Burst RAM array entry -> unused */
  222. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  223. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  224. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  225. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  226. /* UPM Refresh Timer RAM array entry -> unused */
  227. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  228. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  229. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  230. /* UPM Exception RAM array entry -> unsused */
  231. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  232. };
  233. /* UPM pattern for bus clock = 133.3 MHz */
  234. static const u32 upm_patt_133[] = {
  235. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  236. /* 0x00 */ 0x0ff33100, 0x0fe33000, 0x0fa33300, 0x0fa33000,
  237. /* 0x04 */ 0x0fa33000, 0x0fa33005, 0xfffffc00, 0xfffffc00,
  238. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  239. /* 0x08 */ 0x00ff3f30, 0x00ff3d30, 0x0fff3d30, 0x0fff3c35,
  240. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  241. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  242. /* 0x10 */ 0x00f3ff30, 0x00f3fd30, 0x0ff3fd30, 0x0ff3fc35,
  243. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  244. /* UPM Write Single RAM array entry -> NAND Write Data */
  245. /* 0x18 */ 0x00f33f00, 0x00f33d00, 0x0ff33d00, 0x0ff33c05,
  246. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  247. /* UPM Write Burst RAM array entry -> unused */
  248. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  249. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  250. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  251. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  252. /* UPM Refresh Timer RAM array entry -> unused */
  253. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  254. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  255. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  256. /* UPM Exception RAM array entry -> unsused */
  257. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  258. };
  259. /* UPM pattern for bus clock = 166.7 MHz */
  260. static const u32 upm_patt_167[] = {
  261. /* Offset */ /* UPM Read Single RAM array entry -> NAND Read Data */
  262. /* 0x00 */ 0x0ff33200, 0x0fe33000, 0x0fa33300, 0x0fa33300,
  263. /* 0x04 */ 0x0fa33005, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  264. /* UPM Read Burst RAM array entry -> NAND Write CMD */
  265. /* 0x08 */ 0x00ff3f30, 0x00ff3f30, 0x0fff3e30, 0xffff3c35,
  266. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  267. /* UPM Read Burst RAM array entry -> NAND Write ADDR */
  268. /* 0x10 */ 0x00f3ff30, 0x00f3ff30, 0x0ff3fe30, 0x0ff3fc35,
  269. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  270. /* UPM Write Single RAM array entry -> NAND Write Data */
  271. /* 0x18 */ 0x00f33f00, 0x00f33f00, 0x0ff33e00, 0x0ff33c05,
  272. /* 0x1C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  273. /* UPM Write Burst RAM array entry -> unused */
  274. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  275. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  276. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  277. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  278. /* UPM Refresh Timer RAM array entry -> unused */
  279. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  280. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  281. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  282. /* UPM Exception RAM array entry -> unsused */
  283. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  284. };
  285. /* Supported UPM timings */
  286. struct upm_freq upm_freq_table[] = {
  287. /* nominal freq. | ptr to table | GPL4 dis. | EHTR | EAD */
  288. {25000000, upm_patt_25, 1, 0, 0},
  289. {33333333, upm_patt_33, 1, 0, 0},
  290. {41666666, upm_patt_42, 1, 0, 0},
  291. {50000000, upm_patt_50, 0, 0, 0},
  292. {66666666, upm_patt_67, 0, 0, 0},
  293. {83333333, upm_patt_83, 0, 0, 0},
  294. {100000000, upm_patt_100, 0, 1, 1},
  295. {133333333, upm_patt_133, 0, 1, 1},
  296. {166666666, upm_patt_167, 0, 1, 1},
  297. };
  298. #define UPM_FREQS (sizeof(upm_freq_table) / sizeof(struct upm_freq))
  299. volatile const u32 *nand_upm_patt;
  300. /*
  301. * write into UPMB ram
  302. */
  303. static void upmb_write (u_char addr, ulong val)
  304. {
  305. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  306. out_be32 (&lbc->mdr, val);
  307. clrsetbits_be32(&lbc->mbmr, MxMR_MAD_MSK,
  308. MxMR_OP_WARR | (addr & MxMR_MAD_MSK));
  309. /* dummy access to perform write */
  310. out_8 ((void __iomem *)CONFIG_SYS_NAND_BASE, 0);
  311. clrbits_be32(&lbc->mbmr, MxMR_OP_WARR);
  312. }
  313. /*
  314. * Initialize UPM for NAND flash access.
  315. */
  316. static void nand_upm_setup (volatile ccsr_lbc_t *lbc)
  317. {
  318. uint i, j;
  319. uint or3 = CONFIG_SYS_OR3_PRELIM;
  320. uint clock = get_lbc_clock ();
  321. out_be32 (&lbc->br3, 0); /* disable bank and reset all bits */
  322. out_be32 (&lbc->br3, CONFIG_SYS_BR3_PRELIM);
  323. /*
  324. * Search appropriate UPM table for bus clock.
  325. * If the bus clock exceeds a tolerated value, take the UPM timing for
  326. * the next higher supported frequency to ensure that access works
  327. * (even the access may be slower then).
  328. */
  329. for (i = 0; (i < UPM_FREQS) && (clock > upm_freq_table[i].freq); i++)
  330. ;
  331. if (i >= UPM_FREQS)
  332. /* no valid entry found */
  333. /* take last entry with configuration for max. bus clock */
  334. i--;
  335. if (upm_freq_table[i].ehtr) {
  336. /* EHTR must be set due to TQM8548 timing specification */
  337. or3 |= OR_UPM_EHTR;
  338. }
  339. if (upm_freq_table[i].ead)
  340. /* EAD must be set due to TQM8548 timing specification */
  341. or3 |= OR_UPM_EAD;
  342. out_be32 (&lbc->or3, or3);
  343. /* Assign address of table */
  344. nand_upm_patt = upm_freq_table[i].upm_patt;
  345. for (j = 0; j < 64; j++) {
  346. upmb_write (j, *nand_upm_patt);
  347. nand_upm_patt++;
  348. }
  349. /* Put UPM back to normal operation mode */
  350. if (upm_freq_table[i].gpl4_disable)
  351. /* GPL4 must be disabled according to timing specification */
  352. out_be32 (&lbc->mbmr, MxMR_OP_NORM | MxMR_GPL_x4DIS);
  353. return;
  354. }
  355. static struct fsl_upm_nand fun = {
  356. .width = 8,
  357. .upm_cmd_offset = 0x08,
  358. .upm_addr_offset = 0x10,
  359. .upm_mar_chip_offset = CONFIG_SYS_NAND_CS_DIST,
  360. .chip_offset = CONFIG_SYS_NAND_CS_DIST,
  361. .chip_delay = NAND_BIG_DELAY_US,
  362. .wait_flags = FSL_UPM_WAIT_RUN_PATTERN | FSL_UPM_WAIT_WRITE_BUFFER,
  363. };
  364. void board_nand_select_device (struct nand_chip *nand, int chip)
  365. {
  366. }
  367. int board_nand_init (struct nand_chip *nand)
  368. {
  369. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  370. if (!nand_upm_patt)
  371. nand_upm_setup (lbc);
  372. fun.upm.io_addr = nand->IO_ADDR_R;
  373. fun.upm.mxmr = (void __iomem *)&lbc->mbmr;
  374. fun.upm.mdr = (void __iomem *)&lbc->mdr;
  375. fun.upm.mar = (void __iomem *)&lbc->mar;
  376. return fsl_upm_nand_init (nand, &fun);
  377. }