rtc_from4.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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.7 2004/11/04 12:53:10 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/module.h>
  27. #include <linux/mtd/compatmac.h>
  28. #include <linux/mtd/mtd.h>
  29. #include <linux/mtd/nand.h>
  30. #include <linux/mtd/partitions.h>
  31. #include <asm/io.h>
  32. /*
  33. * MTD structure for Renesas board
  34. */
  35. static struct mtd_info *rtc_from4_mtd = NULL;
  36. #define RTC_FROM4_MAX_CHIPS 2
  37. /* HS77x9 processor register defines */
  38. #define SH77X9_BCR1 ((volatile unsigned short *)(0xFFFFFF60))
  39. #define SH77X9_BCR2 ((volatile unsigned short *)(0xFFFFFF62))
  40. #define SH77X9_WCR1 ((volatile unsigned short *)(0xFFFFFF64))
  41. #define SH77X9_WCR2 ((volatile unsigned short *)(0xFFFFFF66))
  42. #define SH77X9_MCR ((volatile unsigned short *)(0xFFFFFF68))
  43. #define SH77X9_PCR ((volatile unsigned short *)(0xFFFFFF6C))
  44. #define SH77X9_FRQCR ((volatile unsigned short *)(0xFFFFFF80))
  45. /*
  46. * Values specific to the Renesas Technology Corp. FROM_BOARD4 (used with HS77x9 processor)
  47. */
  48. /* Address where flash is mapped */
  49. #define RTC_FROM4_FIO_BASE 0x14000000
  50. /* CLE and ALE are tied to address lines 5 & 4, respectively */
  51. #define RTC_FROM4_CLE (1 << 5)
  52. #define RTC_FROM4_ALE (1 << 4)
  53. /* address lines A24-A22 used for chip selection */
  54. #define RTC_FROM4_NAND_ADDR_SLOT3 (0x00800000)
  55. #define RTC_FROM4_NAND_ADDR_SLOT4 (0x00C00000)
  56. #define RTC_FROM4_NAND_ADDR_FPGA (0x01000000)
  57. /* mask address lines A24-A22 used for chip selection */
  58. #define RTC_FROM4_NAND_ADDR_MASK (RTC_FROM4_NAND_ADDR_SLOT3 | RTC_FROM4_NAND_ADDR_SLOT4 | RTC_FROM4_NAND_ADDR_FPGA)
  59. /* FPGA status register for checking device ready (bit zero) */
  60. #define RTC_FROM4_FPGA_SR (RTC_FROM4_NAND_ADDR_FPGA | 0x00000002)
  61. #define RTC_FROM4_DEVICE_READY 0x0001
  62. /* FPGA Reed-Solomon ECC Control register */
  63. #define RTC_FROM4_RS_ECC_CTL (RTC_FROM4_NAND_ADDR_FPGA | 0x00000050)
  64. #define RTC_FROM4_RS_ECC_CTL_CLR (1 << 7)
  65. #define RTC_FROM4_RS_ECC_CTL_GEN (1 << 6)
  66. #define RTC_FROM4_RS_ECC_CTL_FD_E (1 << 5)
  67. /* FPGA Reed-Solomon ECC code base */
  68. #define RTC_FROM4_RS_ECC (RTC_FROM4_NAND_ADDR_FPGA | 0x00000060)
  69. #define RTC_FROM4_RS_ECCN (RTC_FROM4_NAND_ADDR_FPGA | 0x00000080)
  70. /* FPGA Reed-Solomon ECC check register */
  71. #define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070)
  72. #define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7)
  73. /* Undefine for software ECC */
  74. #define RTC_FROM4_HWECC 1
  75. /*
  76. * Module stuff
  77. */
  78. static void __iomem *rtc_from4_fio_base = P2SEGADDR(RTC_FROM4_FIO_BASE);
  79. const static struct mtd_partition partition_info[] = {
  80. {
  81. .name = "Renesas flash partition 1",
  82. .offset = 0,
  83. .size = MTDPART_SIZ_FULL
  84. },
  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_oobinfo rtc_from4_nand_oobinfo = {
  120. .useecc = MTD_NANDECC_AUTOPLACE,
  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. /* Aargh. I missed the reversed bit order, when I
  130. * was talking to Renesas about the FPGA.
  131. *
  132. * The table is used for bit reordering and inversion
  133. * of the ecc byte which we get from the FPGA
  134. */
  135. static uint8_t revbits[256] = {
  136. 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
  137. 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
  138. 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
  139. 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
  140. 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
  141. 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
  142. 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
  143. 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
  144. 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
  145. 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
  146. 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
  147. 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
  148. 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
  149. 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
  150. 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
  151. 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
  152. 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
  153. 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
  154. 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
  155. 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
  156. 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
  157. 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
  158. 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
  159. 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
  160. 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
  161. 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
  162. 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
  163. 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
  164. 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
  165. 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
  166. 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
  167. 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff,
  168. };
  169. #endif
  170. /*
  171. * rtc_from4_hwcontrol - hardware specific access to control-lines
  172. * @mtd: MTD device structure
  173. * @cmd: hardware control command
  174. *
  175. * Address lines (A5 and A4) are used to control Command and Address Latch
  176. * Enable on this board, so set the read/write address appropriately.
  177. *
  178. * Chip Enable is also controlled by the Chip Select (CS5) and
  179. * Address lines (A24-A22), so no action is required here.
  180. *
  181. */
  182. static void rtc_from4_hwcontrol(struct mtd_info *mtd, int cmd)
  183. {
  184. struct nand_chip* this = (struct nand_chip *) (mtd->priv);
  185. switch(cmd) {
  186. case NAND_CTL_SETCLE:
  187. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_CLE);
  188. break;
  189. case NAND_CTL_CLRCLE:
  190. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_CLE);
  191. break;
  192. case NAND_CTL_SETALE:
  193. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_ALE);
  194. break;
  195. case NAND_CTL_CLRALE:
  196. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_ALE);
  197. break;
  198. case NAND_CTL_SETNCE:
  199. break;
  200. case NAND_CTL_CLRNCE:
  201. break;
  202. }
  203. }
  204. /*
  205. * rtc_from4_nand_select_chip - hardware specific chip select
  206. * @mtd: MTD device structure
  207. * @chip: Chip to select (0 == slot 3, 1 == slot 4)
  208. *
  209. * The chip select is based on address lines A24-A22.
  210. * This driver uses flash slots 3 and 4 (A23-A22).
  211. *
  212. */
  213. static void rtc_from4_nand_select_chip(struct mtd_info *mtd, int chip)
  214. {
  215. struct nand_chip *this = mtd->priv;
  216. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R & ~RTC_FROM4_NAND_ADDR_MASK);
  217. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W & ~RTC_FROM4_NAND_ADDR_MASK);
  218. switch(chip) {
  219. case 0: /* select slot 3 chip */
  220. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT3);
  221. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_NAND_ADDR_SLOT3);
  222. break;
  223. case 1: /* select slot 4 chip */
  224. this->IO_ADDR_R = (void __iomem *)((unsigned long)this->IO_ADDR_R | RTC_FROM4_NAND_ADDR_SLOT4);
  225. this->IO_ADDR_W = (void __iomem *)((unsigned long)this->IO_ADDR_W | RTC_FROM4_NAND_ADDR_SLOT4);
  226. break;
  227. }
  228. }
  229. /*
  230. * rtc_from4_nand_device_ready - hardware specific ready/busy check
  231. * @mtd: MTD device structure
  232. *
  233. * This board provides the Ready/Busy state in the status register
  234. * of the FPGA. Bit zero indicates the RDY(1)/BSY(0) signal.
  235. *
  236. */
  237. static int rtc_from4_nand_device_ready(struct mtd_info *mtd)
  238. {
  239. unsigned short status;
  240. status = *((volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_FPGA_SR));
  241. return (status & RTC_FROM4_DEVICE_READY);
  242. }
  243. #ifdef RTC_FROM4_HWECC
  244. /*
  245. * rtc_from4_enable_hwecc - hardware specific hardware ECC enable function
  246. * @mtd: MTD device structure
  247. * @mode: I/O mode; read or write
  248. *
  249. * enable hardware ECC for data read or write
  250. *
  251. */
  252. static void rtc_from4_enable_hwecc(struct mtd_info *mtd, int mode)
  253. {
  254. volatile unsigned short * rs_ecc_ctl = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CTL);
  255. unsigned short status;
  256. switch (mode) {
  257. case NAND_ECC_READ :
  258. status = RTC_FROM4_RS_ECC_CTL_CLR
  259. | RTC_FROM4_RS_ECC_CTL_FD_E;
  260. *rs_ecc_ctl = status;
  261. break;
  262. case NAND_ECC_READSYN :
  263. status = 0x00;
  264. *rs_ecc_ctl = status;
  265. break;
  266. case NAND_ECC_WRITE :
  267. status = RTC_FROM4_RS_ECC_CTL_CLR
  268. | RTC_FROM4_RS_ECC_CTL_GEN
  269. | RTC_FROM4_RS_ECC_CTL_FD_E;
  270. *rs_ecc_ctl = status;
  271. break;
  272. default:
  273. BUG();
  274. break;
  275. }
  276. }
  277. /*
  278. * rtc_from4_calculate_ecc - hardware specific code to read ECC code
  279. * @mtd: MTD device structure
  280. * @dat: buffer containing the data to generate ECC codes
  281. * @ecc_code ECC codes calculated
  282. *
  283. * The ECC code is calculated by the FPGA. All we have to do is read the values
  284. * from the FPGA registers.
  285. *
  286. * Note: We read from the inverted registers, since data is inverted before
  287. * the code is calculated. So all 0xff data (blank page) results in all 0xff rs code
  288. *
  289. */
  290. static void rtc_from4_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code)
  291. {
  292. volatile unsigned short * rs_eccn = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECCN);
  293. unsigned short value;
  294. int i;
  295. for (i = 0; i < 8; i++) {
  296. value = *rs_eccn;
  297. ecc_code[i] = (unsigned char)value;
  298. rs_eccn++;
  299. }
  300. ecc_code[7] |= 0x0f; /* set the last four bits (not used) */
  301. }
  302. /*
  303. * rtc_from4_correct_data - hardware specific code to correct data using ECC code
  304. * @mtd: MTD device structure
  305. * @buf: buffer containing the data to generate ECC codes
  306. * @ecc1 ECC codes read
  307. * @ecc2 ECC codes calculated
  308. *
  309. * The FPGA tells us fast, if there's an error or not. If no, we go back happy
  310. * else we read the ecc results from the fpga and call the rs library to decode
  311. * and hopefully correct the error
  312. *
  313. * For now I use the code, which we read from the FLASH to use the RS lib,
  314. * as the syndrom conversion has a unresolved issue.
  315. */
  316. static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2)
  317. {
  318. int i, j, res;
  319. unsigned short status;
  320. uint16_t par[6], syn[6], tmp;
  321. uint8_t ecc[8];
  322. volatile unsigned short *rs_ecc;
  323. status = *((volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC_CHK));
  324. if (!(status & RTC_FROM4_RS_ECC_CHK_ERROR)) {
  325. return 0;
  326. }
  327. /* Read the syndrom pattern from the FPGA and correct the bitorder */
  328. rs_ecc = (volatile unsigned short *)(rtc_from4_fio_base + RTC_FROM4_RS_ECC);
  329. for (i = 0; i < 8; i++) {
  330. ecc[i] = revbits[(*rs_ecc) & 0xFF];
  331. rs_ecc++;
  332. }
  333. /* convert into 6 10bit syndrome fields */
  334. par[5] = rs_decoder->index_of[(((uint16_t)ecc[0] >> 0) & 0x0ff) |
  335. (((uint16_t)ecc[1] << 8) & 0x300)];
  336. par[4] = rs_decoder->index_of[(((uint16_t)ecc[1] >> 2) & 0x03f) |
  337. (((uint16_t)ecc[2] << 6) & 0x3c0)];
  338. par[3] = rs_decoder->index_of[(((uint16_t)ecc[2] >> 4) & 0x00f) |
  339. (((uint16_t)ecc[3] << 4) & 0x3f0)];
  340. par[2] = rs_decoder->index_of[(((uint16_t)ecc[3] >> 6) & 0x003) |
  341. (((uint16_t)ecc[4] << 2) & 0x3fc)];
  342. par[1] = rs_decoder->index_of[(((uint16_t)ecc[5] >> 0) & 0x0ff) |
  343. (((uint16_t)ecc[6] << 8) & 0x300)];
  344. par[0] = (((uint16_t)ecc[6] >> 2) & 0x03f) | (((uint16_t)ecc[7] << 6) & 0x3c0);
  345. /* Convert to computable syndrome */
  346. for (i = 0; i < 6; i++) {
  347. syn[i] = par[0];
  348. for (j = 1; j < 6; j++)
  349. if (par[j] != rs_decoder->nn)
  350. syn[i] ^= rs_decoder->alpha_to[rs_modnn(rs_decoder, par[j] + i * j)];
  351. /* Convert to index form */
  352. syn[i] = rs_decoder->index_of[syn[i]];
  353. }
  354. /* Let the library code do its magic.*/
  355. res = decode_rs8(rs_decoder, buf, par, 512, syn, 0, NULL, 0xff, NULL);
  356. if (res > 0) {
  357. DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: "
  358. "ECC corrected %d errors on read\n", res);
  359. }
  360. return res;
  361. }
  362. #endif
  363. /*
  364. * Main initialization routine
  365. */
  366. int __init rtc_from4_init (void)
  367. {
  368. struct nand_chip *this;
  369. unsigned short bcr1, bcr2, wcr2;
  370. /* Allocate memory for MTD device structure and private data */
  371. rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip),
  372. GFP_KERNEL);
  373. if (!rtc_from4_mtd) {
  374. printk ("Unable to allocate Renesas NAND MTD device structure.\n");
  375. return -ENOMEM;
  376. }
  377. /* Get pointer to private data */
  378. this = (struct nand_chip *) (&rtc_from4_mtd[1]);
  379. /* Initialize structures */
  380. memset((char *) rtc_from4_mtd, 0, sizeof(struct mtd_info));
  381. memset((char *) this, 0, sizeof(struct nand_chip));
  382. /* Link the private data with the MTD structure */
  383. rtc_from4_mtd->priv = this;
  384. /* set area 5 as PCMCIA mode to clear the spec of tDH(Data hold time;9ns min) */
  385. bcr1 = *SH77X9_BCR1 & ~0x0002;
  386. bcr1 |= 0x0002;
  387. *SH77X9_BCR1 = bcr1;
  388. /* set */
  389. bcr2 = *SH77X9_BCR2 & ~0x0c00;
  390. bcr2 |= 0x0800;
  391. *SH77X9_BCR2 = bcr2;
  392. /* set area 5 wait states */
  393. wcr2 = *SH77X9_WCR2 & ~0x1c00;
  394. wcr2 |= 0x1c00;
  395. *SH77X9_WCR2 = wcr2;
  396. /* Set address of NAND IO lines */
  397. this->IO_ADDR_R = rtc_from4_fio_base;
  398. this->IO_ADDR_W = rtc_from4_fio_base;
  399. /* Set address of hardware control function */
  400. this->hwcontrol = rtc_from4_hwcontrol;
  401. /* Set address of chip select function */
  402. this->select_chip = rtc_from4_nand_select_chip;
  403. /* command delay time (in us) */
  404. this->chip_delay = 100;
  405. /* return the status of the Ready/Busy line */
  406. this->dev_ready = rtc_from4_nand_device_ready;
  407. #ifdef RTC_FROM4_HWECC
  408. printk(KERN_INFO "rtc_from4_init: using hardware ECC detection.\n");
  409. this->eccmode = NAND_ECC_HW8_512;
  410. this->options |= NAND_HWECC_SYNDROME;
  411. /* set the nand_oobinfo to support FPGA H/W error detection */
  412. this->autooob = &rtc_from4_nand_oobinfo;
  413. this->enable_hwecc = rtc_from4_enable_hwecc;
  414. this->calculate_ecc = rtc_from4_calculate_ecc;
  415. this->correct_data = rtc_from4_correct_data;
  416. #else
  417. printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n");
  418. this->eccmode = NAND_ECC_SOFT;
  419. #endif
  420. /* set the bad block tables to support debugging */
  421. this->bbt_td = &rtc_from4_bbt_main_descr;
  422. this->bbt_md = &rtc_from4_bbt_mirror_descr;
  423. /* Scan to find existence of the device */
  424. if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) {
  425. kfree(rtc_from4_mtd);
  426. return -ENXIO;
  427. }
  428. /* Register the partitions */
  429. add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
  430. #ifdef RTC_FROM4_HWECC
  431. /* We could create the decoder on demand, if memory is a concern.
  432. * This way we have it handy, if an error happens
  433. *
  434. * Symbolsize is 10 (bits)
  435. * Primitve polynomial is x^10+x^3+1
  436. * first consecutive root is 0
  437. * primitve element to generate roots = 1
  438. * generator polinomial degree = 6
  439. */
  440. rs_decoder = init_rs(10, 0x409, 0, 1, 6);
  441. if (!rs_decoder) {
  442. printk (KERN_ERR "Could not create a RS decoder\n");
  443. nand_release(rtc_from4_mtd);
  444. kfree(rtc_from4_mtd);
  445. return -ENOMEM;
  446. }
  447. #endif
  448. /* Return happy */
  449. return 0;
  450. }
  451. module_init(rtc_from4_init);
  452. /*
  453. * Clean up routine
  454. */
  455. #ifdef MODULE
  456. static void __exit rtc_from4_cleanup (void)
  457. {
  458. /* Release resource, unregister partitions */
  459. nand_release(rtc_from4_mtd);
  460. /* Free the MTD device structure */
  461. kfree (rtc_from4_mtd);
  462. #ifdef RTC_FROM4_HWECC
  463. /* Free the reed solomon resources */
  464. if (rs_decoder) {
  465. free_rs(rs_decoder);
  466. }
  467. #endif
  468. }
  469. module_exit(rtc_from4_cleanup);
  470. #endif
  471. MODULE_LICENSE("GPL");
  472. MODULE_AUTHOR("d.marlin <dmarlin@redhat.com");
  473. MODULE_DESCRIPTION("Board-specific glue layer for AG-AND flash on Renesas FROM_BOARD4");