rtc_from4.c 18 KB

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