rtc_from4.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. /*
  2. * drivers/mtd/nand/rtc_from4.c
  3. *
  4. * Copyright (C) 2004 Red Hat, Inc.
  5. *
  6. * Derived from drivers/mtd/nand/spia.c
  7. * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Overview:
  14. * This is a device driver for the AG-AND flash device found on the
  15. * Renesas Technology Corp. Flash ROM 4-slot interface board (FROM_BOARD4),
  16. * which utilizes the Renesas HN29V1G91T-30 part.
  17. * This chip is a 1 GBibit (128MiB x 8 bits) AG-AND flash device.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/rslib.h>
  24. #include <linux/bitrev.h>
  25. #include <linux/module.h>
  26. #include <linux/mtd/compatmac.h>
  27. #include <linux/mtd/mtd.h>
  28. #include <linux/mtd/nand.h>
  29. #include <linux/mtd/partitions.h>
  30. #include <asm/io.h>
  31. /*
  32. * MTD structure for Renesas board
  33. */
  34. static struct mtd_info *rtc_from4_mtd = NULL;
  35. #define RTC_FROM4_MAX_CHIPS 2
  36. /* HS77x9 processor register defines */
  37. #define SH77X9_BCR1 ((volatile unsigned short *)(0xFFFFFF60))
  38. #define SH77X9_BCR2 ((volatile unsigned short *)(0xFFFFFF62))
  39. #define SH77X9_WCR1 ((volatile unsigned short *)(0xFFFFFF64))
  40. #define SH77X9_WCR2 ((volatile unsigned short *)(0xFFFFFF66))
  41. #define SH77X9_MCR ((volatile unsigned short *)(0xFFFFFF68))
  42. #define SH77X9_PCR ((volatile unsigned short *)(0xFFFFFF6C))
  43. #define SH77X9_FRQCR ((volatile unsigned short *)(0xFFFFFF80))
  44. /*
  45. * Values specific to the Renesas Technology Corp. FROM_BOARD4 (used with HS77x9 processor)
  46. */
  47. /* Address where flash is mapped */
  48. #define RTC_FROM4_FIO_BASE 0x14000000
  49. /* CLE and ALE are tied to address lines 5 & 4, respectively */
  50. #define RTC_FROM4_CLE (1 << 5)
  51. #define RTC_FROM4_ALE (1 << 4)
  52. /* address lines A24-A22 used for chip selection */
  53. #define RTC_FROM4_NAND_ADDR_SLOT3 (0x00800000)
  54. #define RTC_FROM4_NAND_ADDR_SLOT4 (0x00C00000)
  55. #define RTC_FROM4_NAND_ADDR_FPGA (0x01000000)
  56. /* mask address lines A24-A22 used for chip selection */
  57. #define RTC_FROM4_NAND_ADDR_MASK (RTC_FROM4_NAND_ADDR_SLOT3 | RTC_FROM4_NAND_ADDR_SLOT4 | RTC_FROM4_NAND_ADDR_FPGA)
  58. /* FPGA status register for checking device ready (bit zero) */
  59. #define RTC_FROM4_FPGA_SR (RTC_FROM4_NAND_ADDR_FPGA | 0x00000002)
  60. #define RTC_FROM4_DEVICE_READY 0x0001
  61. /* FPGA Reed-Solomon ECC Control register */
  62. #define RTC_FROM4_RS_ECC_CTL (RTC_FROM4_NAND_ADDR_FPGA | 0x00000050)
  63. #define RTC_FROM4_RS_ECC_CTL_CLR (1 << 7)
  64. #define RTC_FROM4_RS_ECC_CTL_GEN (1 << 6)
  65. #define RTC_FROM4_RS_ECC_CTL_FD_E (1 << 5)
  66. /* FPGA Reed-Solomon ECC code base */
  67. #define RTC_FROM4_RS_ECC (RTC_FROM4_NAND_ADDR_FPGA | 0x00000060)
  68. #define RTC_FROM4_RS_ECCN (RTC_FROM4_NAND_ADDR_FPGA | 0x00000080)
  69. /* FPGA Reed-Solomon ECC check register */
  70. #define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070)
  71. #define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7)
  72. #define ERR_STAT_ECC_AVAILABLE 0x20
  73. /* Undefine for software ECC */
  74. #define RTC_FROM4_HWECC 1
  75. /* Define as 1 for no virtual erase blocks (in JFFS2) */
  76. #define RTC_FROM4_NO_VIRTBLOCKS 0
  77. /*
  78. * Module stuff
  79. */
  80. static void __iomem *rtc_from4_fio_base = (void *)P2SEGADDR(RTC_FROM4_FIO_BASE);
  81. static const struct mtd_partition partition_info[] = {
  82. {
  83. .name = "Renesas flash partition 1",
  84. .offset = 0,
  85. .size = MTDPART_SIZ_FULL},
  86. };
  87. #define NUM_PARTITIONS 1
  88. /*
  89. * hardware specific flash bbt decriptors
  90. * Note: this is to allow debugging by disabling
  91. * NAND_BBT_CREATE and/or NAND_BBT_WRITE
  92. *
  93. */
  94. static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' };
  95. static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' };
  96. static struct nand_bbt_descr rtc_from4_bbt_main_descr = {
  97. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  98. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  99. .offs = 40,
  100. .len = 4,
  101. .veroffs = 44,
  102. .maxblocks = 4,
  103. .pattern = bbt_pattern
  104. };
  105. static struct nand_bbt_descr rtc_from4_bbt_mirror_descr = {
  106. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  107. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  108. .offs = 40,
  109. .len = 4,
  110. .veroffs = 44,
  111. .maxblocks = 4,
  112. .pattern = mirror_pattern
  113. };
  114. #ifdef RTC_FROM4_HWECC
  115. /* the Reed Solomon control structure */
  116. static struct rs_control *rs_decoder;
  117. /*
  118. * hardware specific Out Of Band information
  119. */
  120. static struct nand_ecclayout rtc_from4_nand_oobinfo = {
  121. .eccbytes = 32,
  122. .eccpos = {
  123. 0, 1, 2, 3, 4, 5, 6, 7,
  124. 8, 9, 10, 11, 12, 13, 14, 15,
  125. 16, 17, 18, 19, 20, 21, 22, 23,
  126. 24, 25, 26, 27, 28, 29, 30, 31},
  127. .oobfree = {{32, 32}}
  128. };
  129. #endif
  130. /*
  131. * rtc_from4_hwcontrol - hardware specific access to control-lines
  132. * @mtd: MTD device structure
  133. * @cmd: hardware control command
  134. *
  135. * Address lines (A5 and A4) are used to control Command and Address Latch
  136. * Enable on this board, so set the read/write address appropriately.
  137. *
  138. * Chip Enable is also controlled by the Chip Select (CS5) and
  139. * Address lines (A24-A22), so no action is required here.
  140. *
  141. */
  142. static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd,
  143. unsigned int ctrl)
  144. {
  145. struct nand_chip *chip = (mtd->priv);
  146. if (cmd == NAND_CMD_NONE)
  147. return;
  148. if (ctrl & NAND_CLE)
  149. writeb(cmd, chip->IO_ADDR_W | RTC_FROM4_CLE);
  150. else
  151. writeb(cmd, chip->IO_ADDR_W | RTC_FROM4_ALE);
  152. }
  153. /*
  154. * rtc_from4_nand_select_chip - hardware specific chip select
  155. * @mtd: MTD device structure
  156. * @chip: Chip to select (0 == slot 3, 1 == slot 4)
  157. *
  158. * The chip select is based on address lines A24-A22.
  159. * This driver uses flash slots 3 and 4 (A23-A22).
  160. *
  161. */
  162. static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip)
  163. {
  164. struct nand_chip *this = mtd->priv;
  165. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R & ~RTC_FROM4_NAND_ADDR_MASK);
  166. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_NAND_ADDR_MASK);
  167. switch (chip) {
  168. case 0: /* select slot 3 chip */
  169. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT3);
  170. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_NAND_ADDR_SLOT3);
  171. break;
  172. case 1: /* select slot 4 chip */
  173. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT4);
  174. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_NAND_ADDR_SLOT4);
  175. break;
  176. }
  177. }
  178. /*
  179. * rtc_from4_nand_device_ready - hardware specific ready/busy check
  180. * @mtd: MTD device structure
  181. *
  182. * This board provides the Ready/Busy state in the status register
  183. * of the FPGA. Bit zero indicates the RDY(1)/BSY(0) signal.
  184. *
  185. */
  186. static int rtc_from4_nand_device_ready(struct mtd_info *mtd)
  187. {
  188. unsigned short status;
  189. status = *((volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_FPGA_SR));
  190. return (status & RTC_FROM4_DEVICE_READY);
  191. }
  192. /*
  193. * deplete - code to perform device recovery in case there was a power loss
  194. * @mtd: MTD device structure
  195. * @chip: Chip to select (0 == slot 3, 1 == slot 4)
  196. *
  197. * If there was a sudden loss of power during an erase operation, a
  198. * "device recovery" operation must be performed when power is restored
  199. * to ensure correct operation. This routine performs the required steps
  200. * for the requested chip.
  201. *
  202. * See page 86 of the data sheet for details.
  203. *
  204. */
  205. static void deplete(struct mtd_info *mtd, int chip)
  206. {
  207. struct nand_chip *this = mtd->priv;
  208. /* wait until device is ready */
  209. while (!this->dev_ready(mtd)) ;
  210. this->select_chip(mtd, chip);
  211. /* Send the commands for device recovery, phase 1 */
  212. this->cmdfunc(mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000);
  213. this->cmdfunc(mtd, NAND_CMD_DEPLETE2, -1, -1);
  214. /* Send the commands for device recovery, phase 2 */
  215. this->cmdfunc(mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0004);
  216. this->cmdfunc(mtd, NAND_CMD_DEPLETE2, -1, -1);
  217. }
  218. #ifdef RTC_FROM4_HWECC
  219. /*
  220. * rtc_from4_enable_hwecc - hardware specific hardware ECC enable function
  221. * @mtd: MTD device structure
  222. * @mode: I/O mode; read or write
  223. *
  224. * enable hardware ECC for data read or write
  225. *
  226. */
  227. static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
  228. {
  229. volatile unsigned short *rs_ecc_ctl = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CTL);
  230. unsigned short status;
  231. switch (mode) {
  232. case NAND_ECC_READ:
  233. status = RTC_FROM4_RS_ECC_CTL_CLR | RTC_FROM4_RS_ECC_CTL_FD_E;
  234. *rs_ecc_ctl = status;
  235. break;
  236. case NAND_ECC_READSYN:
  237. status = 0x00;
  238. *rs_ecc_ctl = status;
  239. break;
  240. case NAND_ECC_WRITE:
  241. status = RTC_FROM4_RS_ECC_CTL_CLR | RTC_FROM4_RS_ECC_CTL_GEN | RTC_FROM4_RS_ECC_CTL_FD_E;
  242. *rs_ecc_ctl = status;
  243. break;
  244. default:
  245. BUG();
  246. break;
  247. }
  248. }
  249. /*
  250. * rtc_from4_calculate_ecc - hardware specific code to read ECC code
  251. * @mtd: MTD device structure
  252. * @dat: buffer containing the data to generate ECC codes
  253. * @ecc_code ECC codes calculated
  254. *
  255. * The ECC code is calculated by the FPGA. All we have to do is read the values
  256. * from the FPGA registers.
  257. *
  258. * Note: We read from the inverted registers, since data is inverted before
  259. * the code is calculated. So all 0xff data (blank page) results in all 0xff rs code
  260. *
  261. */
  262. static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
  263. {
  264. volatile unsigned short *rs_eccn = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECCN);
  265. unsigned short value;
  266. int i;
  267. for (i = 0; i < 8; i++) {
  268. value = *rs_eccn;
  269. ecc_code[i] = (unsigned char)value;
  270. rs_eccn++;
  271. }
  272. ecc_code[7] |= 0x0f; /* set the last four bits (not used) */
  273. }
  274. /*
  275. * rtc_from4_correct_data - hardware specific code to correct data using ECC code
  276. * @mtd: MTD device structure
  277. * @buf: buffer containing the data to generate ECC codes
  278. * @ecc1 ECC codes read
  279. * @ecc2 ECC codes calculated
  280. *
  281. * The FPGA tells us fast, if there's an error or not. If no, we go back happy
  282. * else we read the ecc results from the fpga and call the rs library to decode
  283. * and hopefully correct the error.
  284. *
  285. */
  286. static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2)
  287. {
  288. int i, j, res;
  289. unsigned short status;
  290. uint16_t par[6], syn[6];
  291. uint8_t ecc[8];
  292. volatile unsigned short *rs_ecc;
  293. status = *((volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CHK));
  294. if (!(status & RTC_FROM4_RS_ECC_CHK_ERROR)) {
  295. return 0;
  296. }
  297. /* Read the syndrom pattern from the FPGA and correct the bitorder */
  298. rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC);
  299. for (i = 0; i < 8; i++) {
  300. ecc[i] = bitrev8(*rs_ecc);
  301. rs_ecc++;
  302. }
  303. /* convert into 6 10bit syndrome fields */
  304. par[5] = rs_decoder->index_of[(((uint16_t) ecc[0] >> 0) & 0x0ff) | (((uint16_t) ecc[1] << 8) & 0x300)];
  305. par[4] = rs_decoder->index_of[(((uint16_t) ecc[1] >> 2) & 0x03f) | (((uint16_t) ecc[2] << 6) & 0x3c0)];
  306. par[3] = rs_decoder->index_of[(((uint16_t) ecc[2] >> 4) & 0x00f) | (((uint16_t) ecc[3] << 4) & 0x3f0)];
  307. par[2] = rs_decoder->index_of[(((uint16_t) ecc[3] >> 6) & 0x003) | (((uint16_t) ecc[4] << 2) & 0x3fc)];
  308. par[1] = rs_decoder->index_of[(((uint16_t) ecc[5] >> 0) & 0x0ff) | (((uint16_t) ecc[6] << 8) & 0x300)];
  309. par[0] = (((uint16_t) ecc[6] >> 2) & 0x03f) | (((uint16_t) ecc[7] << 6) & 0x3c0);
  310. /* Convert to computable syndrome */
  311. for (i = 0; i < 6; i++) {
  312. syn[i] = par[0];
  313. for (j = 1; j < 6; j++)
  314. if (par[j] != rs_decoder->nn)
  315. syn[i] ^= rs_decoder->alpha_to[rs_modnn(rs_decoder, par[j] + i * j)];
  316. /* Convert to index form */
  317. syn[i] = rs_decoder->index_of[syn[i]];
  318. }
  319. /* Let the library code do its magic. */
  320. res = decode_rs8(rs_decoder, (uint8_t *) buf, par, 512, syn, 0, NULL, 0xff, NULL);
  321. if (res > 0) {
  322. DEBUG(MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " "ECC corrected %d errors on read\n", res);
  323. }
  324. return res;
  325. }
  326. /**
  327. * rtc_from4_errstat - perform additional error status checks
  328. * @mtd: MTD device structure
  329. * @this: NAND chip structure
  330. * @state: state or the operation
  331. * @status: status code returned from read status
  332. * @page: startpage inside the chip, must be called with (page & this->pagemask)
  333. *
  334. * Perform additional error status checks on erase and write failures
  335. * to determine if errors are correctable. For this device, correctable
  336. * 1-bit errors on erase and write are considered acceptable.
  337. *
  338. * note: see pages 34..37 of data sheet for details.
  339. *
  340. */
  341. static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this,
  342. int state, int status, int page)
  343. {
  344. int er_stat = 0;
  345. int rtn, retlen;
  346. size_t len;
  347. uint8_t *buf;
  348. int i;
  349. this->cmdfunc(mtd, NAND_CMD_STATUS_CLEAR, -1, -1);
  350. if (state == FL_ERASING) {
  351. for (i = 0; i < 4; i++) {
  352. if (!(status & 1 << (i + 1)))
  353. continue;
  354. this->cmdfunc(mtd, (NAND_CMD_STATUS_ERROR + i + 1),
  355. -1, -1);
  356. rtn = this->read_byte(mtd);
  357. this->cmdfunc(mtd, NAND_CMD_STATUS_RESET, -1, -1);
  358. /* err_ecc_not_avail */
  359. if (!(rtn & ERR_STAT_ECC_AVAILABLE))
  360. er_stat |= 1 << (i + 1);
  361. }
  362. } else if (state == FL_WRITING) {
  363. unsigned long corrected = mtd->ecc_stats.corrected;
  364. /* single bank write logic */
  365. this->cmdfunc(mtd, NAND_CMD_STATUS_ERROR, -1, -1);
  366. rtn = this->read_byte(mtd);
  367. this->cmdfunc(mtd, NAND_CMD_STATUS_RESET, -1, -1);
  368. if (!(rtn & ERR_STAT_ECC_AVAILABLE)) {
  369. /* err_ecc_not_avail */
  370. er_stat |= 1 << 1;
  371. goto out;
  372. }
  373. len = mtd->writesize;
  374. buf = kmalloc(len, GFP_KERNEL);
  375. if (!buf) {
  376. printk(KERN_ERR "rtc_from4_errstat: Out of memory!\n");
  377. er_stat = 1;
  378. goto out;
  379. }
  380. /* recovery read */
  381. rtn = nand_do_read(mtd, page, len, &retlen, buf);
  382. /* if read failed or > 1-bit error corrected */
  383. if (rtn || (mtd->ecc_stats.corrected - corrected) > 1)
  384. er_stat |= 1 << 1;
  385. kfree(buf);
  386. }
  387. out:
  388. rtn = status;
  389. if (er_stat == 0) { /* if ECC is available */
  390. rtn = (status & ~NAND_STATUS_FAIL); /* clear the error bit */
  391. }
  392. return rtn;
  393. }
  394. #endif
  395. /*
  396. * Main initialization routine
  397. */
  398. static int __init rtc_from4_init(void)
  399. {
  400. struct nand_chip *this;
  401. unsigned short bcr1, bcr2, wcr2;
  402. int i;
  403. int ret;
  404. /* Allocate memory for MTD device structure and private data */
  405. rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  406. if (!rtc_from4_mtd) {
  407. printk("Unable to allocate Renesas NAND MTD device structure.\n");
  408. return -ENOMEM;
  409. }
  410. /* Get pointer to private data */
  411. this = (struct nand_chip *)(&rtc_from4_mtd[1]);
  412. /* Initialize structures */
  413. memset(rtc_from4_mtd, 0, sizeof(struct mtd_info));
  414. memset(this, 0, sizeof(struct nand_chip));
  415. /* Link the private data with the MTD structure */
  416. rtc_from4_mtd->priv = this;
  417. rtc_from4_mtd->owner = THIS_MODULE;
  418. /* set area 5 as PCMCIA mode to clear the spec of tDH(Data hold time;9ns min) */
  419. bcr1 = *SH77X9_BCR1 & ~0x0002;
  420. bcr1 |= 0x0002;
  421. *SH77X9_BCR1 = bcr1;
  422. /* set */
  423. bcr2 = *SH77X9_BCR2 & ~0x0c00;
  424. bcr2 |= 0x0800;
  425. *SH77X9_BCR2 = bcr2;
  426. /* set area 5 wait states */
  427. wcr2 = *SH77X9_WCR2 & ~0x1c00;
  428. wcr2 |= 0x1c00;
  429. *SH77X9_WCR2 = wcr2;
  430. /* Set address of NAND IO lines */
  431. this->IO_ADDR_R = rtc_from4_fio_base;
  432. this->IO_ADDR_W = rtc_from4_fio_base;
  433. /* Set address of hardware control function */
  434. this->cmd_ctrl = rtc_from4_hwcontrol;
  435. /* Set address of chip select function */
  436. this->select_chip = rtc_from4_nand_select_chip;
  437. /* command delay time (in us) */
  438. this->chip_delay = 100;
  439. /* return the status of the Ready/Busy line */
  440. this->dev_ready = rtc_from4_nand_device_ready;
  441. #ifdef RTC_FROM4_HWECC
  442. printk(KERN_INFO "rtc_from4_init: using hardware ECC detection.\n");
  443. this->ecc.mode = NAND_ECC_HW_SYNDROME;
  444. this->ecc.size = 512;
  445. this->ecc.bytes = 8;
  446. /* return the status of extra status and ECC checks */
  447. this->errstat = rtc_from4_errstat;
  448. /* set the nand_oobinfo to support FPGA H/W error detection */
  449. this->ecc.layout = &rtc_from4_nand_oobinfo;
  450. this->ecc.hwctl = rtc_from4_enable_hwecc;
  451. this->ecc.calculate = rtc_from4_calculate_ecc;
  452. this->ecc.correct = rtc_from4_correct_data;
  453. /* We could create the decoder on demand, if memory is a concern.
  454. * This way we have it handy, if an error happens
  455. *
  456. * Symbolsize is 10 (bits)
  457. * Primitve polynomial is x^10+x^3+1
  458. * first consecutive root is 0
  459. * primitve element to generate roots = 1
  460. * generator polinomial degree = 6
  461. */
  462. rs_decoder = init_rs(10, 0x409, 0, 1, 6);
  463. if (!rs_decoder) {
  464. printk(KERN_ERR "Could not create a RS decoder\n");
  465. ret = -ENOMEM;
  466. goto err_1;
  467. }
  468. #else
  469. printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n");
  470. this->ecc.mode = NAND_ECC_SOFT;
  471. #endif
  472. /* set the bad block tables to support debugging */
  473. this->bbt_td = &rtc_from4_bbt_main_descr;
  474. this->bbt_md = &rtc_from4_bbt_mirror_descr;
  475. /* Scan to find existence of the device */
  476. if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) {
  477. ret = -ENXIO;
  478. goto err_2;
  479. }
  480. /* Perform 'device recovery' for each chip in case there was a power loss. */
  481. for (i = 0; i < this->numchips; i++) {
  482. deplete(rtc_from4_mtd, i);
  483. }
  484. #if RTC_FROM4_NO_VIRTBLOCKS
  485. /* use a smaller erase block to minimize wasted space when a block is bad */
  486. /* note: this uses eight times as much RAM as using the default and makes */
  487. /* mounts take four times as long. */
  488. rtc_from4_mtd->flags |= MTD_NO_VIRTBLOCKS;
  489. #endif
  490. /* Register the partitions */
  491. ret = add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
  492. if (ret)
  493. goto err_3;
  494. /* Return happy */
  495. return 0;
  496. err_3:
  497. nand_release(rtc_from4_mtd);
  498. err_2:
  499. free_rs(rs_decoder);
  500. err_1:
  501. kfree(rtc_from4_mtd);
  502. return ret;
  503. }
  504. module_init(rtc_from4_init);
  505. /*
  506. * Clean up routine
  507. */
  508. static void __exit rtc_from4_cleanup(void)
  509. {
  510. /* Release resource, unregister partitions */
  511. nand_release(rtc_from4_mtd);
  512. /* Free the MTD device structure */
  513. kfree(rtc_from4_mtd);
  514. #ifdef RTC_FROM4_HWECC
  515. /* Free the reed solomon resources */
  516. if (rs_decoder) {
  517. free_rs(rs_decoder);
  518. }
  519. #endif
  520. }
  521. module_exit(rtc_from4_cleanup);
  522. MODULE_LICENSE("GPL");
  523. MODULE_AUTHOR("d.marlin <dmarlin@redhat.com");
  524. MODULE_DESCRIPTION("Board-specific glue layer for AG-AND flash on Renesas FROM_BOARD4");