fsl_ifc_nand.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /* Integrated Flash Controller NAND Machine Driver
  2. *
  3. * Copyright (c) 2012 Freescale Semiconductor, Inc
  4. *
  5. * Authors: Dipen Dudhat <Dipen.Dudhat@freescale.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <malloc.h>
  11. #include <nand.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/nand.h>
  14. #include <linux/mtd/nand_ecc.h>
  15. #include <asm/io.h>
  16. #include <asm/errno.h>
  17. #include <fsl_ifc.h>
  18. #ifndef CONFIG_SYS_FSL_IFC_BANK_COUNT
  19. #define CONFIG_SYS_FSL_IFC_BANK_COUNT 4
  20. #endif
  21. #define MAX_BANKS CONFIG_SYS_FSL_IFC_BANK_COUNT
  22. #define ERR_BYTE 0xFF /* Value returned for read bytes
  23. when read failed */
  24. struct fsl_ifc_ctrl;
  25. /* mtd information per set */
  26. struct fsl_ifc_mtd {
  27. struct nand_chip chip;
  28. struct fsl_ifc_ctrl *ctrl;
  29. struct device *dev;
  30. int bank; /* Chip select bank number */
  31. unsigned int bufnum_mask; /* bufnum = page & bufnum_mask */
  32. u8 __iomem *vbase; /* Chip select base virtual address */
  33. };
  34. /* overview of the fsl ifc controller */
  35. struct fsl_ifc_ctrl {
  36. struct nand_hw_control controller;
  37. struct fsl_ifc_mtd *chips[MAX_BANKS];
  38. /* device info */
  39. struct fsl_ifc *regs;
  40. uint8_t __iomem *addr; /* Address of assigned IFC buffer */
  41. unsigned int cs_nand; /* On which chipsel NAND is connected */
  42. unsigned int page; /* Last page written to / read from */
  43. unsigned int read_bytes; /* Number of bytes read during command */
  44. unsigned int column; /* Saved column from SEQIN */
  45. unsigned int index; /* Pointer to next byte to 'read' */
  46. unsigned int status; /* status read from NEESR after last op */
  47. unsigned int oob; /* Non zero if operating on OOB data */
  48. unsigned int eccread; /* Non zero for a full-page ECC read */
  49. };
  50. static struct fsl_ifc_ctrl *ifc_ctrl;
  51. /* 512-byte page with 4-bit ECC, 8-bit */
  52. static struct nand_ecclayout oob_512_8bit_ecc4 = {
  53. .eccbytes = 8,
  54. .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
  55. .oobfree = { {0, 5}, {6, 2} },
  56. };
  57. /* 512-byte page with 4-bit ECC, 16-bit */
  58. static struct nand_ecclayout oob_512_16bit_ecc4 = {
  59. .eccbytes = 8,
  60. .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
  61. .oobfree = { {2, 6}, },
  62. };
  63. /* 2048-byte page size with 4-bit ECC */
  64. static struct nand_ecclayout oob_2048_ecc4 = {
  65. .eccbytes = 32,
  66. .eccpos = {
  67. 8, 9, 10, 11, 12, 13, 14, 15,
  68. 16, 17, 18, 19, 20, 21, 22, 23,
  69. 24, 25, 26, 27, 28, 29, 30, 31,
  70. 32, 33, 34, 35, 36, 37, 38, 39,
  71. },
  72. .oobfree = { {2, 6}, {40, 24} },
  73. };
  74. /* 4096-byte page size with 4-bit ECC */
  75. static struct nand_ecclayout oob_4096_ecc4 = {
  76. .eccbytes = 64,
  77. .eccpos = {
  78. 8, 9, 10, 11, 12, 13, 14, 15,
  79. 16, 17, 18, 19, 20, 21, 22, 23,
  80. 24, 25, 26, 27, 28, 29, 30, 31,
  81. 32, 33, 34, 35, 36, 37, 38, 39,
  82. 40, 41, 42, 43, 44, 45, 46, 47,
  83. 48, 49, 50, 51, 52, 53, 54, 55,
  84. 56, 57, 58, 59, 60, 61, 62, 63,
  85. 64, 65, 66, 67, 68, 69, 70, 71,
  86. },
  87. .oobfree = { {2, 6}, {72, 56} },
  88. };
  89. /* 4096-byte page size with 8-bit ECC -- requires 218-byte OOB */
  90. static struct nand_ecclayout oob_4096_ecc8 = {
  91. .eccbytes = 128,
  92. .eccpos = {
  93. 8, 9, 10, 11, 12, 13, 14, 15,
  94. 16, 17, 18, 19, 20, 21, 22, 23,
  95. 24, 25, 26, 27, 28, 29, 30, 31,
  96. 32, 33, 34, 35, 36, 37, 38, 39,
  97. 40, 41, 42, 43, 44, 45, 46, 47,
  98. 48, 49, 50, 51, 52, 53, 54, 55,
  99. 56, 57, 58, 59, 60, 61, 62, 63,
  100. 64, 65, 66, 67, 68, 69, 70, 71,
  101. 72, 73, 74, 75, 76, 77, 78, 79,
  102. 80, 81, 82, 83, 84, 85, 86, 87,
  103. 88, 89, 90, 91, 92, 93, 94, 95,
  104. 96, 97, 98, 99, 100, 101, 102, 103,
  105. 104, 105, 106, 107, 108, 109, 110, 111,
  106. 112, 113, 114, 115, 116, 117, 118, 119,
  107. 120, 121, 122, 123, 124, 125, 126, 127,
  108. 128, 129, 130, 131, 132, 133, 134, 135,
  109. },
  110. .oobfree = { {2, 6}, {136, 82} },
  111. };
  112. /* 8192-byte page size with 4-bit ECC */
  113. static struct nand_ecclayout oob_8192_ecc4 = {
  114. .eccbytes = 128,
  115. .eccpos = {
  116. 8, 9, 10, 11, 12, 13, 14, 15,
  117. 16, 17, 18, 19, 20, 21, 22, 23,
  118. 24, 25, 26, 27, 28, 29, 30, 31,
  119. 32, 33, 34, 35, 36, 37, 38, 39,
  120. 40, 41, 42, 43, 44, 45, 46, 47,
  121. 48, 49, 50, 51, 52, 53, 54, 55,
  122. 56, 57, 58, 59, 60, 61, 62, 63,
  123. 64, 65, 66, 67, 68, 69, 70, 71,
  124. 72, 73, 74, 75, 76, 77, 78, 79,
  125. 80, 81, 82, 83, 84, 85, 86, 87,
  126. 88, 89, 90, 91, 92, 93, 94, 95,
  127. 96, 97, 98, 99, 100, 101, 102, 103,
  128. 104, 105, 106, 107, 108, 109, 110, 111,
  129. 112, 113, 114, 115, 116, 117, 118, 119,
  130. 120, 121, 122, 123, 124, 125, 126, 127,
  131. 128, 129, 130, 131, 132, 133, 134, 135,
  132. },
  133. .oobfree = { {2, 6}, {136, 208} },
  134. };
  135. /* 8192-byte page size with 8-bit ECC -- requires 218-byte OOB */
  136. static struct nand_ecclayout oob_8192_ecc8 = {
  137. .eccbytes = 256,
  138. .eccpos = {
  139. 8, 9, 10, 11, 12, 13, 14, 15,
  140. 16, 17, 18, 19, 20, 21, 22, 23,
  141. 24, 25, 26, 27, 28, 29, 30, 31,
  142. 32, 33, 34, 35, 36, 37, 38, 39,
  143. 40, 41, 42, 43, 44, 45, 46, 47,
  144. 48, 49, 50, 51, 52, 53, 54, 55,
  145. 56, 57, 58, 59, 60, 61, 62, 63,
  146. 64, 65, 66, 67, 68, 69, 70, 71,
  147. 72, 73, 74, 75, 76, 77, 78, 79,
  148. 80, 81, 82, 83, 84, 85, 86, 87,
  149. 88, 89, 90, 91, 92, 93, 94, 95,
  150. 96, 97, 98, 99, 100, 101, 102, 103,
  151. 104, 105, 106, 107, 108, 109, 110, 111,
  152. 112, 113, 114, 115, 116, 117, 118, 119,
  153. 120, 121, 122, 123, 124, 125, 126, 127,
  154. 128, 129, 130, 131, 132, 133, 134, 135,
  155. 136, 137, 138, 139, 140, 141, 142, 143,
  156. 144, 145, 146, 147, 148, 149, 150, 151,
  157. 152, 153, 154, 155, 156, 157, 158, 159,
  158. 160, 161, 162, 163, 164, 165, 166, 167,
  159. 168, 169, 170, 171, 172, 173, 174, 175,
  160. 176, 177, 178, 179, 180, 181, 182, 183,
  161. 184, 185, 186, 187, 188, 189, 190, 191,
  162. 192, 193, 194, 195, 196, 197, 198, 199,
  163. 200, 201, 202, 203, 204, 205, 206, 207,
  164. 208, 209, 210, 211, 212, 213, 214, 215,
  165. 216, 217, 218, 219, 220, 221, 222, 223,
  166. 224, 225, 226, 227, 228, 229, 230, 231,
  167. 232, 233, 234, 235, 236, 237, 238, 239,
  168. 240, 241, 242, 243, 244, 245, 246, 247,
  169. 248, 249, 250, 251, 252, 253, 254, 255,
  170. 256, 257, 258, 259, 260, 261, 262, 263,
  171. },
  172. .oobfree = { {2, 6}, {264, 80} },
  173. };
  174. /*
  175. * Generic flash bbt descriptors
  176. */
  177. static u8 bbt_pattern[] = {'B', 'b', 't', '0' };
  178. static u8 mirror_pattern[] = {'1', 't', 'b', 'B' };
  179. static struct nand_bbt_descr bbt_main_descr = {
  180. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  181. NAND_BBT_2BIT | NAND_BBT_VERSION,
  182. .offs = 2, /* 0 on 8-bit small page */
  183. .len = 4,
  184. .veroffs = 6,
  185. .maxblocks = 4,
  186. .pattern = bbt_pattern,
  187. };
  188. static struct nand_bbt_descr bbt_mirror_descr = {
  189. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  190. NAND_BBT_2BIT | NAND_BBT_VERSION,
  191. .offs = 2, /* 0 on 8-bit small page */
  192. .len = 4,
  193. .veroffs = 6,
  194. .maxblocks = 4,
  195. .pattern = mirror_pattern,
  196. };
  197. /*
  198. * Set up the IFC hardware block and page address fields, and the ifc nand
  199. * structure addr field to point to the correct IFC buffer in memory
  200. */
  201. static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
  202. {
  203. struct nand_chip *chip = mtd->priv;
  204. struct fsl_ifc_mtd *priv = chip->priv;
  205. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  206. struct fsl_ifc *ifc = ctrl->regs;
  207. int buf_num;
  208. ctrl->page = page_addr;
  209. /* Program ROW0/COL0 */
  210. ifc_out32(&ifc->ifc_nand.row0, page_addr);
  211. ifc_out32(&ifc->ifc_nand.col0, (oob ? IFC_NAND_COL_MS : 0) | column);
  212. buf_num = page_addr & priv->bufnum_mask;
  213. ctrl->addr = priv->vbase + buf_num * (mtd->writesize * 2);
  214. ctrl->index = column;
  215. /* for OOB data point to the second half of the buffer */
  216. if (oob)
  217. ctrl->index += mtd->writesize;
  218. }
  219. static int is_blank(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
  220. unsigned int bufnum)
  221. {
  222. struct nand_chip *chip = mtd->priv;
  223. struct fsl_ifc_mtd *priv = chip->priv;
  224. u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2);
  225. u32 __iomem *main = (u32 *)addr;
  226. u8 __iomem *oob = addr + mtd->writesize;
  227. int i;
  228. for (i = 0; i < mtd->writesize / 4; i++) {
  229. if (__raw_readl(&main[i]) != 0xffffffff)
  230. return 0;
  231. }
  232. for (i = 0; i < chip->ecc.layout->eccbytes; i++) {
  233. int pos = chip->ecc.layout->eccpos[i];
  234. if (__raw_readb(&oob[pos]) != 0xff)
  235. return 0;
  236. }
  237. return 1;
  238. }
  239. /* returns nonzero if entire page is blank */
  240. static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
  241. u32 *eccstat, unsigned int bufnum)
  242. {
  243. u32 reg = eccstat[bufnum / 4];
  244. int errors;
  245. errors = (reg >> ((3 - bufnum % 4) * 8)) & 15;
  246. return errors;
  247. }
  248. /*
  249. * execute IFC NAND command and wait for it to complete
  250. */
  251. static int fsl_ifc_run_command(struct mtd_info *mtd)
  252. {
  253. struct nand_chip *chip = mtd->priv;
  254. struct fsl_ifc_mtd *priv = chip->priv;
  255. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  256. struct fsl_ifc *ifc = ctrl->regs;
  257. u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
  258. u32 time_start;
  259. u32 eccstat[8] = {0};
  260. int i;
  261. /* set the chip select for NAND Transaction */
  262. ifc_out32(&ifc->ifc_nand.nand_csel, ifc_ctrl->cs_nand);
  263. /* start read/write seq */
  264. ifc_out32(&ifc->ifc_nand.nandseq_strt,
  265. IFC_NAND_SEQ_STRT_FIR_STRT);
  266. /* wait for NAND Machine complete flag or timeout */
  267. time_start = get_timer(0);
  268. while (get_timer(time_start) < timeo) {
  269. ctrl->status = ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  270. if (ctrl->status & IFC_NAND_EVTER_STAT_OPC)
  271. break;
  272. }
  273. ifc_out32(&ifc->ifc_nand.nand_evter_stat, ctrl->status);
  274. if (ctrl->status & IFC_NAND_EVTER_STAT_FTOER)
  275. printf("%s: Flash Time Out Error\n", __func__);
  276. if (ctrl->status & IFC_NAND_EVTER_STAT_WPER)
  277. printf("%s: Write Protect Error\n", __func__);
  278. if (ctrl->eccread) {
  279. int errors;
  280. int bufnum = ctrl->page & priv->bufnum_mask;
  281. int sector = bufnum * chip->ecc.steps;
  282. int sector_end = sector + chip->ecc.steps - 1;
  283. for (i = sector / 4; i <= sector_end / 4; i++) {
  284. if (i >= ARRAY_SIZE(eccstat)) {
  285. printf("%s: eccstat too small for %d\n",
  286. __func__, i);
  287. return -EIO;
  288. }
  289. eccstat[i] = ifc_in32(&ifc->ifc_nand.nand_eccstat[i]);
  290. }
  291. for (i = sector; i <= sector_end; i++) {
  292. errors = check_read_ecc(mtd, ctrl, eccstat, i);
  293. if (errors == 15) {
  294. /*
  295. * Uncorrectable error.
  296. * OK only if the whole page is blank.
  297. *
  298. * We disable ECCER reporting due to erratum
  299. * IFC-A002770 -- so report it now if we
  300. * see an uncorrectable error in ECCSTAT.
  301. */
  302. if (!is_blank(mtd, ctrl, bufnum))
  303. ctrl->status |=
  304. IFC_NAND_EVTER_STAT_ECCER;
  305. break;
  306. }
  307. mtd->ecc_stats.corrected += errors;
  308. }
  309. ctrl->eccread = 0;
  310. }
  311. /* returns 0 on success otherwise non-zero) */
  312. return ctrl->status == IFC_NAND_EVTER_STAT_OPC ? 0 : -EIO;
  313. }
  314. static void fsl_ifc_do_read(struct nand_chip *chip,
  315. int oob,
  316. struct mtd_info *mtd)
  317. {
  318. struct fsl_ifc_mtd *priv = chip->priv;
  319. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  320. struct fsl_ifc *ifc = ctrl->regs;
  321. /* Program FIR/IFC_NAND_FCR0 for Small/Large page */
  322. if (mtd->writesize > 512) {
  323. ifc_out32(&ifc->ifc_nand.nand_fir0,
  324. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  325. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  326. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  327. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP3_SHIFT) |
  328. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP4_SHIFT));
  329. ifc_out32(&ifc->ifc_nand.nand_fir1, 0x0);
  330. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  331. (NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT) |
  332. (NAND_CMD_READSTART << IFC_NAND_FCR0_CMD1_SHIFT));
  333. } else {
  334. ifc_out32(&ifc->ifc_nand.nand_fir0,
  335. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  336. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  337. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  338. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP3_SHIFT));
  339. if (oob)
  340. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  341. NAND_CMD_READOOB << IFC_NAND_FCR0_CMD0_SHIFT);
  342. else
  343. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  344. NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT);
  345. }
  346. }
  347. /* cmdfunc send commands to the IFC NAND Machine */
  348. static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
  349. int column, int page_addr)
  350. {
  351. struct nand_chip *chip = mtd->priv;
  352. struct fsl_ifc_mtd *priv = chip->priv;
  353. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  354. struct fsl_ifc *ifc = ctrl->regs;
  355. /* clear the read buffer */
  356. ctrl->read_bytes = 0;
  357. if (command != NAND_CMD_PAGEPROG)
  358. ctrl->index = 0;
  359. switch (command) {
  360. /* READ0 read the entire buffer to use hardware ECC. */
  361. case NAND_CMD_READ0: {
  362. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  363. set_addr(mtd, 0, page_addr, 0);
  364. ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  365. ctrl->index += column;
  366. if (chip->ecc.mode == NAND_ECC_HW)
  367. ctrl->eccread = 1;
  368. fsl_ifc_do_read(chip, 0, mtd);
  369. fsl_ifc_run_command(mtd);
  370. return;
  371. }
  372. /* READOOB reads only the OOB because no ECC is performed. */
  373. case NAND_CMD_READOOB:
  374. ifc_out32(&ifc->ifc_nand.nand_fbcr, mtd->oobsize - column);
  375. set_addr(mtd, column, page_addr, 1);
  376. ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  377. fsl_ifc_do_read(chip, 1, mtd);
  378. fsl_ifc_run_command(mtd);
  379. return;
  380. /* READID must read all possible bytes while CEB is active */
  381. case NAND_CMD_READID:
  382. case NAND_CMD_PARAM: {
  383. int timing = IFC_FIR_OP_RB;
  384. if (command == NAND_CMD_PARAM)
  385. timing = IFC_FIR_OP_RBCD;
  386. ifc_out32(&ifc->ifc_nand.nand_fir0,
  387. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  388. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  389. (timing << IFC_NAND_FIR0_OP2_SHIFT));
  390. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  391. command << IFC_NAND_FCR0_CMD0_SHIFT);
  392. ifc_out32(&ifc->ifc_nand.row3, column);
  393. /*
  394. * although currently it's 8 bytes for READID, we always read
  395. * the maximum 256 bytes(for PARAM)
  396. */
  397. ifc_out32(&ifc->ifc_nand.nand_fbcr, 256);
  398. ctrl->read_bytes = 256;
  399. set_addr(mtd, 0, 0, 0);
  400. fsl_ifc_run_command(mtd);
  401. return;
  402. }
  403. /* ERASE1 stores the block and page address */
  404. case NAND_CMD_ERASE1:
  405. set_addr(mtd, 0, page_addr, 0);
  406. return;
  407. /* ERASE2 uses the block and page address from ERASE1 */
  408. case NAND_CMD_ERASE2:
  409. ifc_out32(&ifc->ifc_nand.nand_fir0,
  410. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  411. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  412. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP2_SHIFT));
  413. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  414. (NAND_CMD_ERASE1 << IFC_NAND_FCR0_CMD0_SHIFT) |
  415. (NAND_CMD_ERASE2 << IFC_NAND_FCR0_CMD1_SHIFT));
  416. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  417. ctrl->read_bytes = 0;
  418. fsl_ifc_run_command(mtd);
  419. return;
  420. /* SEQIN sets up the addr buffer and all registers except the length */
  421. case NAND_CMD_SEQIN: {
  422. u32 nand_fcr0;
  423. ctrl->column = column;
  424. ctrl->oob = 0;
  425. if (mtd->writesize > 512) {
  426. nand_fcr0 =
  427. (NAND_CMD_SEQIN << IFC_NAND_FCR0_CMD0_SHIFT) |
  428. (NAND_CMD_STATUS << IFC_NAND_FCR0_CMD1_SHIFT) |
  429. (NAND_CMD_PAGEPROG << IFC_NAND_FCR0_CMD2_SHIFT);
  430. ifc_out32(&ifc->ifc_nand.nand_fir0,
  431. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  432. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  433. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  434. (IFC_FIR_OP_WBCD <<
  435. IFC_NAND_FIR0_OP3_SHIFT) |
  436. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP4_SHIFT));
  437. ifc_out32(&ifc->ifc_nand.nand_fir1,
  438. (IFC_FIR_OP_CW1 << IFC_NAND_FIR1_OP5_SHIFT) |
  439. (IFC_FIR_OP_RDSTAT <<
  440. IFC_NAND_FIR1_OP6_SHIFT) |
  441. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP7_SHIFT));
  442. } else {
  443. nand_fcr0 = ((NAND_CMD_PAGEPROG <<
  444. IFC_NAND_FCR0_CMD1_SHIFT) |
  445. (NAND_CMD_SEQIN <<
  446. IFC_NAND_FCR0_CMD2_SHIFT) |
  447. (NAND_CMD_STATUS <<
  448. IFC_NAND_FCR0_CMD3_SHIFT));
  449. ifc_out32(&ifc->ifc_nand.nand_fir0,
  450. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  451. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP1_SHIFT) |
  452. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  453. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP3_SHIFT) |
  454. (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP4_SHIFT));
  455. ifc_out32(&ifc->ifc_nand.nand_fir1,
  456. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR1_OP5_SHIFT) |
  457. (IFC_FIR_OP_CW3 << IFC_NAND_FIR1_OP6_SHIFT) |
  458. (IFC_FIR_OP_RDSTAT <<
  459. IFC_NAND_FIR1_OP7_SHIFT) |
  460. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP8_SHIFT));
  461. if (column >= mtd->writesize)
  462. nand_fcr0 |=
  463. NAND_CMD_READOOB << IFC_NAND_FCR0_CMD0_SHIFT;
  464. else
  465. nand_fcr0 |=
  466. NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT;
  467. }
  468. if (column >= mtd->writesize) {
  469. /* OOB area --> READOOB */
  470. column -= mtd->writesize;
  471. ctrl->oob = 1;
  472. }
  473. ifc_out32(&ifc->ifc_nand.nand_fcr0, nand_fcr0);
  474. set_addr(mtd, column, page_addr, ctrl->oob);
  475. return;
  476. }
  477. /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
  478. case NAND_CMD_PAGEPROG:
  479. if (ctrl->oob)
  480. ifc_out32(&ifc->ifc_nand.nand_fbcr,
  481. ctrl->index - ctrl->column);
  482. else
  483. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  484. fsl_ifc_run_command(mtd);
  485. return;
  486. case NAND_CMD_STATUS:
  487. ifc_out32(&ifc->ifc_nand.nand_fir0,
  488. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  489. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP1_SHIFT));
  490. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  491. NAND_CMD_STATUS << IFC_NAND_FCR0_CMD0_SHIFT);
  492. ifc_out32(&ifc->ifc_nand.nand_fbcr, 1);
  493. set_addr(mtd, 0, 0, 0);
  494. ctrl->read_bytes = 1;
  495. fsl_ifc_run_command(mtd);
  496. /* Chip sometimes reporting write protect even when it's not */
  497. out_8(ctrl->addr, in_8(ctrl->addr) | NAND_STATUS_WP);
  498. return;
  499. case NAND_CMD_RESET:
  500. ifc_out32(&ifc->ifc_nand.nand_fir0,
  501. IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT);
  502. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  503. NAND_CMD_RESET << IFC_NAND_FCR0_CMD0_SHIFT);
  504. fsl_ifc_run_command(mtd);
  505. return;
  506. default:
  507. printf("%s: error, unsupported command 0x%x.\n",
  508. __func__, command);
  509. }
  510. }
  511. /*
  512. * Write buf to the IFC NAND Controller Data Buffer
  513. */
  514. static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  515. {
  516. struct nand_chip *chip = mtd->priv;
  517. struct fsl_ifc_mtd *priv = chip->priv;
  518. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  519. unsigned int bufsize = mtd->writesize + mtd->oobsize;
  520. if (len <= 0) {
  521. printf("%s of %d bytes", __func__, len);
  522. ctrl->status = 0;
  523. return;
  524. }
  525. if ((unsigned int)len > bufsize - ctrl->index) {
  526. printf("%s beyond end of buffer "
  527. "(%d requested, %u available)\n",
  528. __func__, len, bufsize - ctrl->index);
  529. len = bufsize - ctrl->index;
  530. }
  531. memcpy_toio(&ctrl->addr[ctrl->index], buf, len);
  532. ctrl->index += len;
  533. }
  534. /*
  535. * read a byte from either the IFC hardware buffer if it has any data left
  536. * otherwise issue a command to read a single byte.
  537. */
  538. static u8 fsl_ifc_read_byte(struct mtd_info *mtd)
  539. {
  540. struct nand_chip *chip = mtd->priv;
  541. struct fsl_ifc_mtd *priv = chip->priv;
  542. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  543. /* If there are still bytes in the IFC buffer, then use the
  544. * next byte. */
  545. if (ctrl->index < ctrl->read_bytes)
  546. return in_8(&ctrl->addr[ctrl->index++]);
  547. printf("%s beyond end of buffer\n", __func__);
  548. return ERR_BYTE;
  549. }
  550. /*
  551. * Read two bytes from the IFC hardware buffer
  552. * read function for 16-bit buswith
  553. */
  554. static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd)
  555. {
  556. struct nand_chip *chip = mtd->priv;
  557. struct fsl_ifc_mtd *priv = chip->priv;
  558. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  559. uint16_t data;
  560. /*
  561. * If there are still bytes in the IFC buffer, then use the
  562. * next byte.
  563. */
  564. if (ctrl->index < ctrl->read_bytes) {
  565. data = ifc_in16((uint16_t *)&ctrl->
  566. addr[ctrl->index]);
  567. ctrl->index += 2;
  568. return (uint8_t)data;
  569. }
  570. printf("%s beyond end of buffer\n", __func__);
  571. return ERR_BYTE;
  572. }
  573. /*
  574. * Read from the IFC Controller Data Buffer
  575. */
  576. static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  577. {
  578. struct nand_chip *chip = mtd->priv;
  579. struct fsl_ifc_mtd *priv = chip->priv;
  580. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  581. int avail;
  582. if (len < 0)
  583. return;
  584. avail = min((unsigned int)len, ctrl->read_bytes - ctrl->index);
  585. memcpy_fromio(buf, &ctrl->addr[ctrl->index], avail);
  586. ctrl->index += avail;
  587. if (len > avail)
  588. printf("%s beyond end of buffer "
  589. "(%d requested, %d available)\n",
  590. __func__, len, avail);
  591. }
  592. /* This function is called after Program and Erase Operations to
  593. * check for success or failure.
  594. */
  595. static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
  596. {
  597. struct fsl_ifc_mtd *priv = chip->priv;
  598. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  599. struct fsl_ifc *ifc = ctrl->regs;
  600. u32 nand_fsr;
  601. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  602. return NAND_STATUS_FAIL;
  603. /* Use READ_STATUS command, but wait for the device to be ready */
  604. ifc_out32(&ifc->ifc_nand.nand_fir0,
  605. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  606. (IFC_FIR_OP_RDSTAT << IFC_NAND_FIR0_OP1_SHIFT));
  607. ifc_out32(&ifc->ifc_nand.nand_fcr0, NAND_CMD_STATUS <<
  608. IFC_NAND_FCR0_CMD0_SHIFT);
  609. ifc_out32(&ifc->ifc_nand.nand_fbcr, 1);
  610. set_addr(mtd, 0, 0, 0);
  611. ctrl->read_bytes = 1;
  612. fsl_ifc_run_command(mtd);
  613. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  614. return NAND_STATUS_FAIL;
  615. nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr);
  616. /* Chip sometimes reporting write protect even when it's not */
  617. nand_fsr = nand_fsr | NAND_STATUS_WP;
  618. return nand_fsr;
  619. }
  620. static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
  621. uint8_t *buf, int oob_required, int page)
  622. {
  623. struct fsl_ifc_mtd *priv = chip->priv;
  624. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  625. fsl_ifc_read_buf(mtd, buf, mtd->writesize);
  626. fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
  627. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  628. mtd->ecc_stats.failed++;
  629. return 0;
  630. }
  631. /* ECC will be calculated automatically, and errors will be detected in
  632. * waitfunc.
  633. */
  634. static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
  635. const uint8_t *buf, int oob_required)
  636. {
  637. fsl_ifc_write_buf(mtd, buf, mtd->writesize);
  638. fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
  639. return 0;
  640. }
  641. static void fsl_ifc_ctrl_init(void)
  642. {
  643. ifc_ctrl = kzalloc(sizeof(*ifc_ctrl), GFP_KERNEL);
  644. if (!ifc_ctrl)
  645. return;
  646. ifc_ctrl->regs = IFC_BASE_ADDR;
  647. /* clear event registers */
  648. ifc_out32(&ifc_ctrl->regs->ifc_nand.nand_evter_stat, ~0U);
  649. ifc_out32(&ifc_ctrl->regs->ifc_nand.pgrdcmpl_evt_stat, ~0U);
  650. /* Enable error and event for any detected errors */
  651. ifc_out32(&ifc_ctrl->regs->ifc_nand.nand_evter_en,
  652. IFC_NAND_EVTER_EN_OPC_EN |
  653. IFC_NAND_EVTER_EN_PGRDCMPL_EN |
  654. IFC_NAND_EVTER_EN_FTOER_EN |
  655. IFC_NAND_EVTER_EN_WPER_EN);
  656. ifc_out32(&ifc_ctrl->regs->ifc_nand.ncfgr, 0x0);
  657. }
  658. static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip)
  659. {
  660. }
  661. static int fsl_ifc_sram_init(uint32_t ver)
  662. {
  663. struct fsl_ifc *ifc = ifc_ctrl->regs;
  664. uint32_t cs = 0, csor = 0, csor_8k = 0, csor_ext = 0;
  665. uint32_t ncfgr = 0;
  666. u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
  667. u32 time_start;
  668. if (ver > FSL_IFC_V1_1_0) {
  669. ncfgr = ifc_in32(&ifc->ifc_nand.ncfgr);
  670. ifc_out32(&ifc->ifc_nand.ncfgr, ncfgr | IFC_NAND_SRAM_INIT_EN);
  671. /* wait for SRAM_INIT bit to be clear or timeout */
  672. time_start = get_timer(0);
  673. while (get_timer(time_start) < timeo) {
  674. ifc_ctrl->status =
  675. ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  676. if (!(ifc_ctrl->status & IFC_NAND_SRAM_INIT_EN))
  677. return 0;
  678. }
  679. printf("fsl-ifc: Failed to Initialise SRAM\n");
  680. return 1;
  681. }
  682. cs = ifc_ctrl->cs_nand >> IFC_NAND_CSEL_SHIFT;
  683. /* Save CSOR and CSOR_ext */
  684. csor = ifc_in32(&ifc_ctrl->regs->csor_cs[cs].csor);
  685. csor_ext = ifc_in32(&ifc_ctrl->regs->csor_cs[cs].csor_ext);
  686. /* chage PageSize 8K and SpareSize 1K*/
  687. csor_8k = (csor & ~(CSOR_NAND_PGS_MASK)) | 0x0018C000;
  688. ifc_out32(&ifc_ctrl->regs->csor_cs[cs].csor, csor_8k);
  689. ifc_out32(&ifc_ctrl->regs->csor_cs[cs].csor_ext, 0x0000400);
  690. /* READID */
  691. ifc_out32(&ifc->ifc_nand.nand_fir0,
  692. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  693. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  694. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT));
  695. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  696. NAND_CMD_READID << IFC_NAND_FCR0_CMD0_SHIFT);
  697. ifc_out32(&ifc->ifc_nand.row3, 0x0);
  698. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0x0);
  699. /* Program ROW0/COL0 */
  700. ifc_out32(&ifc->ifc_nand.row0, 0x0);
  701. ifc_out32(&ifc->ifc_nand.col0, 0x0);
  702. /* set the chip select for NAND Transaction */
  703. ifc_out32(&ifc->ifc_nand.nand_csel, ifc_ctrl->cs_nand);
  704. /* start read seq */
  705. ifc_out32(&ifc->ifc_nand.nandseq_strt, IFC_NAND_SEQ_STRT_FIR_STRT);
  706. time_start = get_timer(0);
  707. while (get_timer(time_start) < timeo) {
  708. ifc_ctrl->status = ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  709. if (ifc_ctrl->status & IFC_NAND_EVTER_STAT_OPC)
  710. break;
  711. }
  712. if (ifc_ctrl->status != IFC_NAND_EVTER_STAT_OPC) {
  713. printf("fsl-ifc: Failed to Initialise SRAM\n");
  714. return 1;
  715. }
  716. ifc_out32(&ifc->ifc_nand.nand_evter_stat, ifc_ctrl->status);
  717. /* Restore CSOR and CSOR_ext */
  718. ifc_out32(&ifc_ctrl->regs->csor_cs[cs].csor, csor);
  719. ifc_out32(&ifc_ctrl->regs->csor_cs[cs].csor_ext, csor_ext);
  720. return 0;
  721. }
  722. static int fsl_ifc_chip_init(int devnum, u8 *addr)
  723. {
  724. struct mtd_info *mtd = &nand_info[devnum];
  725. struct nand_chip *nand;
  726. struct fsl_ifc_mtd *priv;
  727. struct nand_ecclayout *layout;
  728. uint32_t cspr = 0, csor = 0, ver = 0;
  729. int ret = 0;
  730. if (!ifc_ctrl) {
  731. fsl_ifc_ctrl_init();
  732. if (!ifc_ctrl)
  733. return -1;
  734. }
  735. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  736. if (!priv)
  737. return -ENOMEM;
  738. priv->ctrl = ifc_ctrl;
  739. priv->vbase = addr;
  740. /* Find which chip select it is connected to.
  741. */
  742. for (priv->bank = 0; priv->bank < MAX_BANKS; priv->bank++) {
  743. phys_addr_t phys_addr = virt_to_phys(addr);
  744. cspr = ifc_in32(&ifc_ctrl->regs->cspr_cs[priv->bank].cspr);
  745. csor = ifc_in32(&ifc_ctrl->regs->csor_cs[priv->bank].csor);
  746. if ((cspr & CSPR_V) && (cspr & CSPR_MSEL) == CSPR_MSEL_NAND &&
  747. (cspr & CSPR_BA) == CSPR_PHYS_ADDR(phys_addr)) {
  748. ifc_ctrl->cs_nand = priv->bank << IFC_NAND_CSEL_SHIFT;
  749. break;
  750. }
  751. }
  752. if (priv->bank >= MAX_BANKS) {
  753. printf("%s: address did not match any "
  754. "chip selects\n", __func__);
  755. kfree(priv);
  756. return -ENODEV;
  757. }
  758. nand = &priv->chip;
  759. mtd->priv = nand;
  760. ifc_ctrl->chips[priv->bank] = priv;
  761. /* fill in nand_chip structure */
  762. /* set up function call table */
  763. nand->write_buf = fsl_ifc_write_buf;
  764. nand->read_buf = fsl_ifc_read_buf;
  765. nand->select_chip = fsl_ifc_select_chip;
  766. nand->cmdfunc = fsl_ifc_cmdfunc;
  767. nand->waitfunc = fsl_ifc_wait;
  768. /* set up nand options */
  769. nand->bbt_td = &bbt_main_descr;
  770. nand->bbt_md = &bbt_mirror_descr;
  771. /* set up nand options */
  772. nand->options = NAND_NO_SUBPAGE_WRITE;
  773. nand->bbt_options = NAND_BBT_USE_FLASH;
  774. if (cspr & CSPR_PORT_SIZE_16) {
  775. nand->read_byte = fsl_ifc_read_byte16;
  776. nand->options |= NAND_BUSWIDTH_16;
  777. } else {
  778. nand->read_byte = fsl_ifc_read_byte;
  779. }
  780. nand->controller = &ifc_ctrl->controller;
  781. nand->priv = priv;
  782. nand->ecc.read_page = fsl_ifc_read_page;
  783. nand->ecc.write_page = fsl_ifc_write_page;
  784. /* Hardware generates ECC per 512 Bytes */
  785. nand->ecc.size = 512;
  786. nand->ecc.bytes = 8;
  787. switch (csor & CSOR_NAND_PGS_MASK) {
  788. case CSOR_NAND_PGS_512:
  789. if (nand->options & NAND_BUSWIDTH_16) {
  790. layout = &oob_512_16bit_ecc4;
  791. } else {
  792. layout = &oob_512_8bit_ecc4;
  793. /* Avoid conflict with bad block marker */
  794. bbt_main_descr.offs = 0;
  795. bbt_mirror_descr.offs = 0;
  796. }
  797. nand->ecc.strength = 4;
  798. priv->bufnum_mask = 15;
  799. break;
  800. case CSOR_NAND_PGS_2K:
  801. layout = &oob_2048_ecc4;
  802. nand->ecc.strength = 4;
  803. priv->bufnum_mask = 3;
  804. break;
  805. case CSOR_NAND_PGS_4K:
  806. if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
  807. CSOR_NAND_ECC_MODE_4) {
  808. layout = &oob_4096_ecc4;
  809. nand->ecc.strength = 4;
  810. } else {
  811. layout = &oob_4096_ecc8;
  812. nand->ecc.strength = 8;
  813. nand->ecc.bytes = 16;
  814. }
  815. priv->bufnum_mask = 1;
  816. break;
  817. case CSOR_NAND_PGS_8K:
  818. if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
  819. CSOR_NAND_ECC_MODE_4) {
  820. layout = &oob_8192_ecc4;
  821. nand->ecc.strength = 4;
  822. } else {
  823. layout = &oob_8192_ecc8;
  824. nand->ecc.strength = 8;
  825. nand->ecc.bytes = 16;
  826. }
  827. priv->bufnum_mask = 0;
  828. break;
  829. default:
  830. printf("ifc nand: bad csor %#x: bad page size\n", csor);
  831. return -ENODEV;
  832. }
  833. /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
  834. if (csor & CSOR_NAND_ECC_DEC_EN) {
  835. nand->ecc.mode = NAND_ECC_HW;
  836. nand->ecc.layout = layout;
  837. } else {
  838. nand->ecc.mode = NAND_ECC_SOFT;
  839. }
  840. ver = ifc_in32(&ifc_ctrl->regs->ifc_rev);
  841. if (ver >= FSL_IFC_V1_1_0)
  842. ret = fsl_ifc_sram_init(ver);
  843. if (ret)
  844. return ret;
  845. if (ver >= FSL_IFC_V2_0_0)
  846. priv->bufnum_mask = (priv->bufnum_mask * 2) + 1;
  847. ret = nand_scan_ident(mtd, 1, NULL);
  848. if (ret)
  849. return ret;
  850. ret = nand_scan_tail(mtd);
  851. if (ret)
  852. return ret;
  853. ret = nand_register(devnum);
  854. if (ret)
  855. return ret;
  856. return 0;
  857. }
  858. #ifndef CONFIG_SYS_NAND_BASE_LIST
  859. #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE }
  860. #endif
  861. static unsigned long base_address[CONFIG_SYS_MAX_NAND_DEVICE] =
  862. CONFIG_SYS_NAND_BASE_LIST;
  863. void board_nand_init(void)
  864. {
  865. int i;
  866. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  867. fsl_ifc_chip_init(i, (u8 *)base_address[i]);
  868. }