rtc_from4.c 18 KB

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