mtdnand.tmpl 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
  4. <book id="MTD-NAND-Guide">
  5. <bookinfo>
  6. <title>MTD NAND Driver Programming Interface</title>
  7. <authorgroup>
  8. <author>
  9. <firstname>Thomas</firstname>
  10. <surname>Gleixner</surname>
  11. <affiliation>
  12. <address>
  13. <email>tglx@linutronix.de</email>
  14. </address>
  15. </affiliation>
  16. </author>
  17. </authorgroup>
  18. <copyright>
  19. <year>2004</year>
  20. <holder>Thomas Gleixner</holder>
  21. </copyright>
  22. <legalnotice>
  23. <para>
  24. This documentation is free software; you can redistribute
  25. it and/or modify it under the terms of the GNU General Public
  26. License version 2 as published by the Free Software Foundation.
  27. </para>
  28. <para>
  29. This program is distributed in the hope that it will be
  30. useful, but WITHOUT ANY WARRANTY; without even the implied
  31. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  32. See the GNU General Public License for more details.
  33. </para>
  34. <para>
  35. You should have received a copy of the GNU General Public
  36. License along with this program; if not, write to the Free
  37. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  38. MA 02111-1307 USA
  39. </para>
  40. <para>
  41. For more details see the file COPYING in the source
  42. distribution of Linux.
  43. </para>
  44. </legalnotice>
  45. </bookinfo>
  46. <toc></toc>
  47. <chapter id="intro">
  48. <title>Introduction</title>
  49. <para>
  50. The generic NAND driver supports almost all NAND and AG-AND based
  51. chips and connects them to the Memory Technology Devices (MTD)
  52. subsystem of the Linux Kernel.
  53. </para>
  54. <para>
  55. This documentation is provided for developers who want to implement
  56. board drivers or filesystem drivers suitable for NAND devices.
  57. </para>
  58. </chapter>
  59. <chapter id="bugs">
  60. <title>Known Bugs And Assumptions</title>
  61. <para>
  62. None.
  63. </para>
  64. </chapter>
  65. <chapter id="dochints">
  66. <title>Documentation hints</title>
  67. <para>
  68. The function and structure docs are autogenerated. Each function and
  69. struct member has a short description which is marked with an [XXX] identifier.
  70. The following chapters explain the meaning of those identifiers.
  71. </para>
  72. <sect1>
  73. <title>Function identifiers [XXX]</title>
  74. <para>
  75. The functions are marked with [XXX] identifiers in the short
  76. comment. The identifiers explain the usage and scope of the
  77. functions. Following identifiers are used:
  78. </para>
  79. <itemizedlist>
  80. <listitem><para>
  81. [MTD Interface]</para><para>
  82. These functions provide the interface to the MTD kernel API.
  83. They are not replacable and provide functionality
  84. which is complete hardware independent.
  85. </para></listitem>
  86. <listitem><para>
  87. [NAND Interface]</para><para>
  88. These functions are exported and provide the interface to the NAND kernel API.
  89. </para></listitem>
  90. <listitem><para>
  91. [GENERIC]</para><para>
  92. Generic functions are not replacable and provide functionality
  93. which is complete hardware independent.
  94. </para></listitem>
  95. <listitem><para>
  96. [DEFAULT]</para><para>
  97. Default functions provide hardware related functionality which is suitable
  98. for most of the implementations. These functions can be replaced by the
  99. board driver if neccecary. Those functions are called via pointers in the
  100. NAND chip description structure. The board driver can set the functions which
  101. should be replaced by board dependend functions before calling nand_scan().
  102. If the function pointer is NULL on entry to nand_scan() then the pointer
  103. is set to the default function which is suitable for the detected chip type.
  104. </para></listitem>
  105. </itemizedlist>
  106. </sect1>
  107. <sect1>
  108. <title>Struct member identifiers [XXX]</title>
  109. <para>
  110. The struct members are marked with [XXX] identifiers in the
  111. comment. The identifiers explain the usage and scope of the
  112. members. Following identifiers are used:
  113. </para>
  114. <itemizedlist>
  115. <listitem><para>
  116. [INTERN]</para><para>
  117. These members are for NAND driver internal use only and must not be
  118. modified. Most of these values are calculated from the chip geometry
  119. information which is evaluated during nand_scan().
  120. </para></listitem>
  121. <listitem><para>
  122. [REPLACEABLE]</para><para>
  123. Replaceable members hold hardware related functions which can be
  124. provided by the board driver. The board driver can set the functions which
  125. should be replaced by board dependend functions before calling nand_scan().
  126. If the function pointer is NULL on entry to nand_scan() then the pointer
  127. is set to the default function which is suitable for the detected chip type.
  128. </para></listitem>
  129. <listitem><para>
  130. [BOARDSPECIFIC]</para><para>
  131. Board specific members hold hardware related information which must
  132. be provided by the board driver. The board driver must set the function
  133. pointers and datafields before calling nand_scan().
  134. </para></listitem>
  135. <listitem><para>
  136. [OPTIONAL]</para><para>
  137. Optional members can hold information relevant for the board driver. The
  138. generic NAND driver code does not use this information.
  139. </para></listitem>
  140. </itemizedlist>
  141. </sect1>
  142. </chapter>
  143. <chapter id="basicboarddriver">
  144. <title>Basic board driver</title>
  145. <para>
  146. For most boards it will be sufficient to provide just the
  147. basic functions and fill out some really board dependend
  148. members in the nand chip description structure.
  149. See drivers/mtd/nand/skeleton for reference.
  150. </para>
  151. <sect1>
  152. <title>Basic defines</title>
  153. <para>
  154. At least you have to provide a mtd structure and
  155. a storage for the ioremap'ed chip address.
  156. You can allocate the mtd structure using kmalloc
  157. or you can allocate it statically.
  158. In case of static allocation you have to allocate
  159. a nand_chip structure too.
  160. </para>
  161. <para>
  162. Kmalloc based example
  163. </para>
  164. <programlisting>
  165. static struct mtd_info *board_mtd;
  166. static unsigned long baseaddr;
  167. </programlisting>
  168. <para>
  169. Static example
  170. </para>
  171. <programlisting>
  172. static struct mtd_info board_mtd;
  173. static struct nand_chip board_chip;
  174. static unsigned long baseaddr;
  175. </programlisting>
  176. </sect1>
  177. <sect1>
  178. <title>Partition defines</title>
  179. <para>
  180. If you want to divide your device into parititions, then
  181. enable the configuration switch CONFIG_MTD_PARITIONS and define
  182. a paritioning scheme suitable to your board.
  183. </para>
  184. <programlisting>
  185. #define NUM_PARTITIONS 2
  186. static struct mtd_partition partition_info[] = {
  187. { .name = "Flash partition 1",
  188. .offset = 0,
  189. .size = 8 * 1024 * 1024 },
  190. { .name = "Flash partition 2",
  191. .offset = MTDPART_OFS_NEXT,
  192. .size = MTDPART_SIZ_FULL },
  193. };
  194. </programlisting>
  195. </sect1>
  196. <sect1>
  197. <title>Hardware control function</title>
  198. <para>
  199. The hardware control function provides access to the
  200. control pins of the NAND chip(s).
  201. The access can be done by GPIO pins or by address lines.
  202. If you use address lines, make sure that the timing
  203. requirements are met.
  204. </para>
  205. <para>
  206. <emphasis>GPIO based example</emphasis>
  207. </para>
  208. <programlisting>
  209. static void board_hwcontrol(struct mtd_info *mtd, int cmd)
  210. {
  211. switch(cmd){
  212. case NAND_CTL_SETCLE: /* Set CLE pin high */ break;
  213. case NAND_CTL_CLRCLE: /* Set CLE pin low */ break;
  214. case NAND_CTL_SETALE: /* Set ALE pin high */ break;
  215. case NAND_CTL_CLRALE: /* Set ALE pin low */ break;
  216. case NAND_CTL_SETNCE: /* Set nCE pin low */ break;
  217. case NAND_CTL_CLRNCE: /* Set nCE pin high */ break;
  218. }
  219. }
  220. </programlisting>
  221. <para>
  222. <emphasis>Address lines based example.</emphasis> It's assumed that the
  223. nCE pin is driven by a chip select decoder.
  224. </para>
  225. <programlisting>
  226. static void board_hwcontrol(struct mtd_info *mtd, int cmd)
  227. {
  228. struct nand_chip *this = (struct nand_chip *) mtd->priv;
  229. switch(cmd){
  230. case NAND_CTL_SETCLE: this->IO_ADDR_W |= CLE_ADRR_BIT; break;
  231. case NAND_CTL_CLRCLE: this->IO_ADDR_W &amp;= ~CLE_ADRR_BIT; break;
  232. case NAND_CTL_SETALE: this->IO_ADDR_W |= ALE_ADRR_BIT; break;
  233. case NAND_CTL_CLRALE: this->IO_ADDR_W &amp;= ~ALE_ADRR_BIT; break;
  234. }
  235. }
  236. </programlisting>
  237. </sect1>
  238. <sect1>
  239. <title>Device ready function</title>
  240. <para>
  241. If the hardware interface has the ready busy pin of the NAND chip connected to a
  242. GPIO or other accesible I/O pin, this function is used to read back the state of the
  243. pin. The function has no arguments and should return 0, if the device is busy (R/B pin
  244. is low) and 1, if the device is ready (R/B pin is high).
  245. If the hardware interface does not give access to the ready busy pin, then
  246. the function must not be defined and the function pointer this->dev_ready is set to NULL.
  247. </para>
  248. </sect1>
  249. <sect1>
  250. <title>Init function</title>
  251. <para>
  252. The init function allocates memory and sets up all the board
  253. specific parameters and function pointers. When everything
  254. is set up nand_scan() is called. This function tries to
  255. detect and identify then chip. If a chip is found all the
  256. internal data fields are initialized accordingly.
  257. The structure(s) have to be zeroed out first and then filled with the neccecary
  258. information about the device.
  259. </para>
  260. <programlisting>
  261. int __init board_init (void)
  262. {
  263. struct nand_chip *this;
  264. int err = 0;
  265. /* Allocate memory for MTD device structure and private data */
  266. board_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), GFP_KERNEL);
  267. if (!board_mtd) {
  268. printk ("Unable to allocate NAND MTD device structure.\n");
  269. err = -ENOMEM;
  270. goto out;
  271. }
  272. /* Initialize structures */
  273. memset ((char *) board_mtd, 0, sizeof(struct mtd_info) + sizeof(struct nand_chip));
  274. /* map physical adress */
  275. baseaddr = (unsigned long)ioremap(CHIP_PHYSICAL_ADDRESS, 1024);
  276. if(!baseaddr){
  277. printk("Ioremap to access NAND chip failed\n");
  278. err = -EIO;
  279. goto out_mtd;
  280. }
  281. /* Get pointer to private data */
  282. this = (struct nand_chip *) ();
  283. /* Link the private data with the MTD structure */
  284. board_mtd->priv = this;
  285. /* Set address of NAND IO lines */
  286. this->IO_ADDR_R = baseaddr;
  287. this->IO_ADDR_W = baseaddr;
  288. /* Reference hardware control function */
  289. this->hwcontrol = board_hwcontrol;
  290. /* Set command delay time, see datasheet for correct value */
  291. this->chip_delay = CHIP_DEPENDEND_COMMAND_DELAY;
  292. /* Assign the device ready function, if available */
  293. this->dev_ready = board_dev_ready;
  294. this->eccmode = NAND_ECC_SOFT;
  295. /* Scan to find existance of the device */
  296. if (nand_scan (board_mtd, 1)) {
  297. err = -ENXIO;
  298. goto out_ior;
  299. }
  300. add_mtd_partitions(board_mtd, partition_info, NUM_PARTITIONS);
  301. goto out;
  302. out_ior:
  303. iounmap((void *)baseaddr);
  304. out_mtd:
  305. kfree (board_mtd);
  306. out:
  307. return err;
  308. }
  309. module_init(board_init);
  310. </programlisting>
  311. </sect1>
  312. <sect1>
  313. <title>Exit function</title>
  314. <para>
  315. The exit function is only neccecary if the driver is
  316. compiled as a module. It releases all resources which
  317. are held by the chip driver and unregisters the partitions
  318. in the MTD layer.
  319. </para>
  320. <programlisting>
  321. #ifdef MODULE
  322. static void __exit board_cleanup (void)
  323. {
  324. /* Release resources, unregister device */
  325. nand_release (board_mtd);
  326. /* unmap physical adress */
  327. iounmap((void *)baseaddr);
  328. /* Free the MTD device structure */
  329. kfree (board_mtd);
  330. }
  331. module_exit(board_cleanup);
  332. #endif
  333. </programlisting>
  334. </sect1>
  335. </chapter>
  336. <chapter id="boarddriversadvanced">
  337. <title>Advanced board driver functions</title>
  338. <para>
  339. This chapter describes the advanced functionality of the NAND
  340. driver. For a list of functions which can be overridden by the board
  341. driver see the documentation of the nand_chip structure.
  342. </para>
  343. <sect1>
  344. <title>Multiple chip control</title>
  345. <para>
  346. The nand driver can control chip arrays. Therefor the
  347. board driver must provide an own select_chip function. This
  348. function must (de)select the requested chip.
  349. The function pointer in the nand_chip structure must
  350. be set before calling nand_scan(). The maxchip parameter
  351. of nand_scan() defines the maximum number of chips to
  352. scan for. Make sure that the select_chip function can
  353. handle the requested number of chips.
  354. </para>
  355. <para>
  356. The nand driver concatenates the chips to one virtual
  357. chip and provides this virtual chip to the MTD layer.
  358. </para>
  359. <para>
  360. <emphasis>Note: The driver can only handle linear chip arrays
  361. of equally sized chips. There is no support for
  362. parallel arrays which extend the buswidth.</emphasis>
  363. </para>
  364. <para>
  365. <emphasis>GPIO based example</emphasis>
  366. </para>
  367. <programlisting>
  368. static void board_select_chip (struct mtd_info *mtd, int chip)
  369. {
  370. /* Deselect all chips, set all nCE pins high */
  371. GPIO(BOARD_NAND_NCE) |= 0xff;
  372. if (chip >= 0)
  373. GPIO(BOARD_NAND_NCE) &amp;= ~ (1 &lt;&lt; chip);
  374. }
  375. </programlisting>
  376. <para>
  377. <emphasis>Address lines based example.</emphasis>
  378. Its assumed that the nCE pins are connected to an
  379. address decoder.
  380. </para>
  381. <programlisting>
  382. static void board_select_chip (struct mtd_info *mtd, int chip)
  383. {
  384. struct nand_chip *this = (struct nand_chip *) mtd->priv;
  385. /* Deselect all chips */
  386. this->IO_ADDR_R &amp;= ~BOARD_NAND_ADDR_MASK;
  387. this->IO_ADDR_W &amp;= ~BOARD_NAND_ADDR_MASK;
  388. switch (chip) {
  389. case 0:
  390. this->IO_ADDR_R |= BOARD_NAND_ADDR_CHIP0;
  391. this->IO_ADDR_W |= BOARD_NAND_ADDR_CHIP0;
  392. break;
  393. ....
  394. case n:
  395. this->IO_ADDR_R |= BOARD_NAND_ADDR_CHIPn;
  396. this->IO_ADDR_W |= BOARD_NAND_ADDR_CHIPn;
  397. break;
  398. }
  399. }
  400. </programlisting>
  401. </sect1>
  402. <sect1>
  403. <title>Hardware ECC support</title>
  404. <sect2>
  405. <title>Functions and constants</title>
  406. <para>
  407. The nand driver supports three different types of
  408. hardware ECC.
  409. <itemizedlist>
  410. <listitem><para>NAND_ECC_HW3_256</para><para>
  411. Hardware ECC generator providing 3 bytes ECC per
  412. 256 byte.
  413. </para> </listitem>
  414. <listitem><para>NAND_ECC_HW3_512</para><para>
  415. Hardware ECC generator providing 3 bytes ECC per
  416. 512 byte.
  417. </para> </listitem>
  418. <listitem><para>NAND_ECC_HW6_512</para><para>
  419. Hardware ECC generator providing 6 bytes ECC per
  420. 512 byte.
  421. </para> </listitem>
  422. <listitem><para>NAND_ECC_HW8_512</para><para>
  423. Hardware ECC generator providing 6 bytes ECC per
  424. 512 byte.
  425. </para> </listitem>
  426. </itemizedlist>
  427. If your hardware generator has a different functionality
  428. add it at the appropriate place in nand_base.c
  429. </para>
  430. <para>
  431. The board driver must provide following functions:
  432. <itemizedlist>
  433. <listitem><para>enable_hwecc</para><para>
  434. This function is called before reading / writing to
  435. the chip. Reset or initialize the hardware generator
  436. in this function. The function is called with an
  437. argument which let you distinguish between read
  438. and write operations.
  439. </para> </listitem>
  440. <listitem><para>calculate_ecc</para><para>
  441. This function is called after read / write from / to
  442. the chip. Transfer the ECC from the hardware to
  443. the buffer. If the option NAND_HWECC_SYNDROME is set
  444. then the function is only called on write. See below.
  445. </para> </listitem>
  446. <listitem><para>correct_data</para><para>
  447. In case of an ECC error this function is called for
  448. error detection and correction. Return 1 respectively 2
  449. in case the error can be corrected. If the error is
  450. not correctable return -1. If your hardware generator
  451. matches the default algorithm of the nand_ecc software
  452. generator then use the correction function provided
  453. by nand_ecc instead of implementing duplicated code.
  454. </para> </listitem>
  455. </itemizedlist>
  456. </para>
  457. </sect2>
  458. <sect2>
  459. <title>Hardware ECC with syndrome calculation</title>
  460. <para>
  461. Many hardware ECC implementations provide Reed-Solomon
  462. codes and calculate an error syndrome on read. The syndrome
  463. must be converted to a standard Reed-Solomon syndrome
  464. before calling the error correction code in the generic
  465. Reed-Solomon library.
  466. </para>
  467. <para>
  468. The ECC bytes must be placed immidiately after the data
  469. bytes in order to make the syndrome generator work. This
  470. is contrary to the usual layout used by software ECC. The
  471. seperation of data and out of band area is not longer
  472. possible. The nand driver code handles this layout and
  473. the remaining free bytes in the oob area are managed by
  474. the autoplacement code. Provide a matching oob-layout
  475. in this case. See rts_from4.c and diskonchip.c for
  476. implementation reference. In those cases we must also
  477. use bad block tables on FLASH, because the ECC layout is
  478. interferring with the bad block marker positions.
  479. See bad block table support for details.
  480. </para>
  481. </sect2>
  482. </sect1>
  483. <sect1>
  484. <title>Bad block table support</title>
  485. <para>
  486. Most NAND chips mark the bad blocks at a defined
  487. position in the spare area. Those blocks must
  488. not be erased under any circumstances as the bad
  489. block information would be lost.
  490. It is possible to check the bad block mark each
  491. time when the blocks are accessed by reading the
  492. spare area of the first page in the block. This
  493. is time consuming so a bad block table is used.
  494. </para>
  495. <para>
  496. The nand driver supports various types of bad block
  497. tables.
  498. <itemizedlist>
  499. <listitem><para>Per device</para><para>
  500. The bad block table contains all bad block information
  501. of the device which can consist of multiple chips.
  502. </para> </listitem>
  503. <listitem><para>Per chip</para><para>
  504. A bad block table is used per chip and contains the
  505. bad block information for this particular chip.
  506. </para> </listitem>
  507. <listitem><para>Fixed offset</para><para>
  508. The bad block table is located at a fixed offset
  509. in the chip (device). This applies to various
  510. DiskOnChip devices.
  511. </para> </listitem>
  512. <listitem><para>Automatic placed</para><para>
  513. The bad block table is automatically placed and
  514. detected either at the end or at the beginning
  515. of a chip (device)
  516. </para> </listitem>
  517. <listitem><para>Mirrored tables</para><para>
  518. The bad block table is mirrored on the chip (device) to
  519. allow updates of the bad block table without data loss.
  520. </para> </listitem>
  521. </itemizedlist>
  522. </para>
  523. <para>
  524. nand_scan() calls the function nand_default_bbt().
  525. nand_default_bbt() selects appropriate default
  526. bad block table desriptors depending on the chip information
  527. which was retrieved by nand_scan().
  528. </para>
  529. <para>
  530. The standard policy is scanning the device for bad
  531. blocks and build a ram based bad block table which
  532. allows faster access than always checking the
  533. bad block information on the flash chip itself.
  534. </para>
  535. <sect2>
  536. <title>Flash based tables</title>
  537. <para>
  538. It may be desired or neccecary to keep a bad block table in FLASH.
  539. For AG-AND chips this is mandatory, as they have no factory marked
  540. bad blocks. They have factory marked good blocks. The marker pattern
  541. is erased when the block is erased to be reused. So in case of
  542. powerloss before writing the pattern back to the chip this block
  543. would be lost and added to the bad blocks. Therefor we scan the
  544. chip(s) when we detect them the first time for good blocks and
  545. store this information in a bad block table before erasing any
  546. of the blocks.
  547. </para>
  548. <para>
  549. The blocks in which the tables are stored are procteted against
  550. accidental access by marking them bad in the memory bad block
  551. table. The bad block table managment functions are allowed
  552. to circumvernt this protection.
  553. </para>
  554. <para>
  555. The simplest way to activate the FLASH based bad block table support
  556. is to set the option NAND_USE_FLASH_BBT in the option field of
  557. the nand chip structure before calling nand_scan(). For AG-AND
  558. chips is this done by default.
  559. This activates the default FLASH based bad block table functionality
  560. of the NAND driver. The default bad block table options are
  561. <itemizedlist>
  562. <listitem><para>Store bad block table per chip</para></listitem>
  563. <listitem><para>Use 2 bits per block</para></listitem>
  564. <listitem><para>Automatic placement at the end of the chip</para></listitem>
  565. <listitem><para>Use mirrored tables with version numbers</para></listitem>
  566. <listitem><para>Reserve 4 blocks at the end of the chip</para></listitem>
  567. </itemizedlist>
  568. </para>
  569. </sect2>
  570. <sect2>
  571. <title>User defined tables</title>
  572. <para>
  573. User defined tables are created by filling out a
  574. nand_bbt_descr structure and storing the pointer in the
  575. nand_chip structure member bbt_td before calling nand_scan().
  576. If a mirror table is neccecary a second structure must be
  577. created and a pointer to this structure must be stored
  578. in bbt_md inside the nand_chip structure. If the bbt_md
  579. member is set to NULL then only the main table is used
  580. and no scan for the mirrored table is performed.
  581. </para>
  582. <para>
  583. The most important field in the nand_bbt_descr structure
  584. is the options field. The options define most of the
  585. table properties. Use the predefined constants from
  586. nand.h to define the options.
  587. <itemizedlist>
  588. <listitem><para>Number of bits per block</para>
  589. <para>The supported number of bits is 1, 2, 4, 8.</para></listitem>
  590. <listitem><para>Table per chip</para>
  591. <para>Setting the constant NAND_BBT_PERCHIP selects that
  592. a bad block table is managed for each chip in a chip array.
  593. If this option is not set then a per device bad block table
  594. is used.</para></listitem>
  595. <listitem><para>Table location is absolute</para>
  596. <para>Use the option constant NAND_BBT_ABSPAGE and
  597. define the absolute page number where the bad block
  598. table starts in the field pages. If you have selected bad block
  599. tables per chip and you have a multi chip array then the start page
  600. must be given for each chip in the chip array. Note: there is no scan
  601. for a table ident pattern performed, so the fields
  602. pattern, veroffs, offs, len can be left uninitialized</para></listitem>
  603. <listitem><para>Table location is automatically detected</para>
  604. <para>The table can either be located in the first or the last good
  605. blocks of the chip (device). Set NAND_BBT_LASTBLOCK to place
  606. the bad block table at the end of the chip (device). The
  607. bad block tables are marked and identified by a pattern which
  608. is stored in the spare area of the first page in the block which
  609. holds the bad block table. Store a pointer to the pattern
  610. in the pattern field. Further the length of the pattern has to be
  611. stored in len and the offset in the spare area must be given
  612. in the offs member of the nand_bbt_descr stucture. For mirrored
  613. bad block tables different patterns are mandatory.</para></listitem>
  614. <listitem><para>Table creation</para>
  615. <para>Set the option NAND_BBT_CREATE to enable the table creation
  616. if no table can be found during the scan. Usually this is done only
  617. once if a new chip is found. </para></listitem>
  618. <listitem><para>Table write support</para>
  619. <para>Set the option NAND_BBT_WRITE to enable the table write support.
  620. This allows the update of the bad block table(s) in case a block has
  621. to be marked bad due to wear. The MTD interface function block_markbad
  622. is calling the update function of the bad block table. If the write
  623. support is enabled then the table is updated on FLASH.</para>
  624. <para>
  625. Note: Write support should only be enabled for mirrored tables with
  626. version control.
  627. </para></listitem>
  628. <listitem><para>Table version control</para>
  629. <para>Set the option NAND_BBT_VERSION to enable the table version control.
  630. It's highly recommended to enable this for mirrored tables with write
  631. support. It makes sure that the risk of loosing the bad block
  632. table information is reduced to the loss of the information about the
  633. one worn out block which should be marked bad. The version is stored in
  634. 4 consecutive bytes in the spare area of the device. The position of
  635. the version number is defined by the member veroffs in the bad block table
  636. descriptor.</para></listitem>
  637. <listitem><para>Save block contents on write</para>
  638. <para>
  639. In case that the block which holds the bad block table does contain
  640. other useful information, set the option NAND_BBT_SAVECONTENT. When
  641. the bad block table is written then the whole block is read the bad
  642. block table is updated and the block is erased and everything is
  643. written back. If this option is not set only the bad block table
  644. is written and everything else in the block is ignored and erased.
  645. </para></listitem>
  646. <listitem><para>Number of reserved blocks</para>
  647. <para>
  648. For automatic placement some blocks must be reserved for
  649. bad block table storage. The number of reserved blocks is defined
  650. in the maxblocks member of the babd block table description structure.
  651. Reserving 4 blocks for mirrored tables should be a reasonable number.
  652. This also limits the number of blocks which are scanned for the bad
  653. block table ident pattern.
  654. </para></listitem>
  655. </itemizedlist>
  656. </para>
  657. </sect2>
  658. </sect1>
  659. <sect1>
  660. <title>Spare area (auto)placement</title>
  661. <para>
  662. The nand driver implements different possibilities for
  663. placement of filesystem data in the spare area,
  664. <itemizedlist>
  665. <listitem><para>Placement defined by fs driver</para></listitem>
  666. <listitem><para>Automatic placement</para></listitem>
  667. </itemizedlist>
  668. The default placement function is automatic placement. The
  669. nand driver has built in default placement schemes for the
  670. various chiptypes. If due to hardware ECC functionality the
  671. default placement does not fit then the board driver can
  672. provide a own placement scheme.
  673. </para>
  674. <para>
  675. File system drivers can provide a own placement scheme which
  676. is used instead of the default placement scheme.
  677. </para>
  678. <para>
  679. Placement schemes are defined by a nand_oobinfo structure
  680. <programlisting>
  681. struct nand_oobinfo {
  682. int useecc;
  683. int eccbytes;
  684. int eccpos[24];
  685. int oobfree[8][2];
  686. };
  687. </programlisting>
  688. <itemizedlist>
  689. <listitem><para>useecc</para><para>
  690. The useecc member controls the ecc and placement function. The header
  691. file include/mtd/mtd-abi.h contains constants to select ecc and
  692. placement. MTD_NANDECC_OFF switches off the ecc complete. This is
  693. not recommended and available for testing and diagnosis only.
  694. MTD_NANDECC_PLACE selects caller defined placement, MTD_NANDECC_AUTOPLACE
  695. selects automatic placement.
  696. </para></listitem>
  697. <listitem><para>eccbytes</para><para>
  698. The eccbytes member defines the number of ecc bytes per page.
  699. </para></listitem>
  700. <listitem><para>eccpos</para><para>
  701. The eccpos array holds the byte offsets in the spare area where
  702. the ecc codes are placed.
  703. </para></listitem>
  704. <listitem><para>oobfree</para><para>
  705. The oobfree array defines the areas in the spare area which can be
  706. used for automatic placement. The information is given in the format
  707. {offset, size}. offset defines the start of the usable area, size the
  708. length in bytes. More than one area can be defined. The list is terminated
  709. by an {0, 0} entry.
  710. </para></listitem>
  711. </itemizedlist>
  712. </para>
  713. <sect2>
  714. <title>Placement defined by fs driver</title>
  715. <para>
  716. The calling function provides a pointer to a nand_oobinfo
  717. structure which defines the ecc placement. For writes the
  718. caller must provide a spare area buffer along with the
  719. data buffer. The spare area buffer size is (number of pages) *
  720. (size of spare area). For reads the buffer size is
  721. (number of pages) * ((size of spare area) + (number of ecc
  722. steps per page) * sizeof (int)). The driver stores the
  723. result of the ecc check for each tuple in the spare buffer.
  724. The storage sequence is
  725. </para>
  726. <para>
  727. &lt;spare data page 0&gt;&lt;ecc result 0&gt;...&lt;ecc result n&gt;
  728. </para>
  729. <para>
  730. ...
  731. </para>
  732. <para>
  733. &lt;spare data page n&gt;&lt;ecc result 0&gt;...&lt;ecc result n&gt;
  734. </para>
  735. <para>
  736. This is a legacy mode used by YAFFS1.
  737. </para>
  738. <para>
  739. If the spare area buffer is NULL then only the ECC placement is
  740. done according to the given scheme in the nand_oobinfo structure.
  741. </para>
  742. </sect2>
  743. <sect2>
  744. <title>Automatic placement</title>
  745. <para>
  746. Automatic placement uses the built in defaults to place the
  747. ecc bytes in the spare area. If filesystem data have to be stored /
  748. read into the spare area then the calling function must provide a
  749. buffer. The buffer size per page is determined by the oobfree array in
  750. the nand_oobinfo structure.
  751. </para>
  752. <para>
  753. If the spare area buffer is NULL then only the ECC placement is
  754. done according to the default builtin scheme.
  755. </para>
  756. </sect2>
  757. <sect2>
  758. <title>User space placement selection</title>
  759. <para>
  760. All non ecc functions like mtd->read and mtd->write use an internal
  761. structure, which can be set by an ioctl. This structure is preset
  762. to the autoplacement default.
  763. <programlisting>
  764. ioctl (fd, MEMSETOOBSEL, oobsel);
  765. </programlisting>
  766. oobsel is a pointer to a user supplied structure of type
  767. nand_oobconfig. The contents of this structure must match the
  768. criteria of the filesystem, which will be used. See an example in utils/nandwrite.c.
  769. </para>
  770. </sect2>
  771. </sect1>
  772. <sect1>
  773. <title>Spare area autoplacement default schemes</title>
  774. <sect2>
  775. <title>256 byte pagesize</title>
  776. <informaltable><tgroup cols="3"><tbody>
  777. <row>
  778. <entry>Offset</entry>
  779. <entry>Content</entry>
  780. <entry>Comment</entry>
  781. </row>
  782. <row>
  783. <entry>0x00</entry>
  784. <entry>ECC byte 0</entry>
  785. <entry>Error correction code byte 0</entry>
  786. </row>
  787. <row>
  788. <entry>0x01</entry>
  789. <entry>ECC byte 1</entry>
  790. <entry>Error correction code byte 1</entry>
  791. </row>
  792. <row>
  793. <entry>0x02</entry>
  794. <entry>ECC byte 2</entry>
  795. <entry>Error correction code byte 2</entry>
  796. </row>
  797. <row>
  798. <entry>0x03</entry>
  799. <entry>Autoplace 0</entry>
  800. <entry></entry>
  801. </row>
  802. <row>
  803. <entry>0x04</entry>
  804. <entry>Autoplace 1</entry>
  805. <entry></entry>
  806. </row>
  807. <row>
  808. <entry>0x05</entry>
  809. <entry>Bad block marker</entry>
  810. <entry>If any bit in this byte is zero, then this block is bad.
  811. This applies only to the first page in a block. In the remaining
  812. pages this byte is reserved</entry>
  813. </row>
  814. <row>
  815. <entry>0x06</entry>
  816. <entry>Autoplace 2</entry>
  817. <entry></entry>
  818. </row>
  819. <row>
  820. <entry>0x07</entry>
  821. <entry>Autoplace 3</entry>
  822. <entry></entry>
  823. </row>
  824. </tbody></tgroup></informaltable>
  825. </sect2>
  826. <sect2>
  827. <title>512 byte pagesize</title>
  828. <informaltable><tgroup cols="3"><tbody>
  829. <row>
  830. <entry>Offset</entry>
  831. <entry>Content</entry>
  832. <entry>Comment</entry>
  833. </row>
  834. <row>
  835. <entry>0x00</entry>
  836. <entry>ECC byte 0</entry>
  837. <entry>Error correction code byte 0 of the lower 256 Byte data in
  838. this page</entry>
  839. </row>
  840. <row>
  841. <entry>0x01</entry>
  842. <entry>ECC byte 1</entry>
  843. <entry>Error correction code byte 1 of the lower 256 Bytes of data
  844. in this page</entry>
  845. </row>
  846. <row>
  847. <entry>0x02</entry>
  848. <entry>ECC byte 2</entry>
  849. <entry>Error correction code byte 2 of the lower 256 Bytes of data
  850. in this page</entry>
  851. </row>
  852. <row>
  853. <entry>0x03</entry>
  854. <entry>ECC byte 3</entry>
  855. <entry>Error correction code byte 0 of the upper 256 Bytes of data
  856. in this page</entry>
  857. </row>
  858. <row>
  859. <entry>0x04</entry>
  860. <entry>reserved</entry>
  861. <entry>reserved</entry>
  862. </row>
  863. <row>
  864. <entry>0x05</entry>
  865. <entry>Bad block marker</entry>
  866. <entry>If any bit in this byte is zero, then this block is bad.
  867. This applies only to the first page in a block. In the remaining
  868. pages this byte is reserved</entry>
  869. </row>
  870. <row>
  871. <entry>0x06</entry>
  872. <entry>ECC byte 4</entry>
  873. <entry>Error correction code byte 1 of the upper 256 Bytes of data
  874. in this page</entry>
  875. </row>
  876. <row>
  877. <entry>0x07</entry>
  878. <entry>ECC byte 5</entry>
  879. <entry>Error correction code byte 2 of the upper 256 Bytes of data
  880. in this page</entry>
  881. </row>
  882. <row>
  883. <entry>0x08 - 0x0F</entry>
  884. <entry>Autoplace 0 - 7</entry>
  885. <entry></entry>
  886. </row>
  887. </tbody></tgroup></informaltable>
  888. </sect2>
  889. <sect2>
  890. <title>2048 byte pagesize</title>
  891. <informaltable><tgroup cols="3"><tbody>
  892. <row>
  893. <entry>Offset</entry>
  894. <entry>Content</entry>
  895. <entry>Comment</entry>
  896. </row>
  897. <row>
  898. <entry>0x00</entry>
  899. <entry>Bad block marker</entry>
  900. <entry>If any bit in this byte is zero, then this block is bad.
  901. This applies only to the first page in a block. In the remaining
  902. pages this byte is reserved</entry>
  903. </row>
  904. <row>
  905. <entry>0x01</entry>
  906. <entry>Reserved</entry>
  907. <entry>Reserved</entry>
  908. </row>
  909. <row>
  910. <entry>0x02-0x27</entry>
  911. <entry>Autoplace 0 - 37</entry>
  912. <entry></entry>
  913. </row>
  914. <row>
  915. <entry>0x28</entry>
  916. <entry>ECC byte 0</entry>
  917. <entry>Error correction code byte 0 of the first 256 Byte data in
  918. this page</entry>
  919. </row>
  920. <row>
  921. <entry>0x29</entry>
  922. <entry>ECC byte 1</entry>
  923. <entry>Error correction code byte 1 of the first 256 Bytes of data
  924. in this page</entry>
  925. </row>
  926. <row>
  927. <entry>0x2A</entry>
  928. <entry>ECC byte 2</entry>
  929. <entry>Error correction code byte 2 of the first 256 Bytes data in
  930. this page</entry>
  931. </row>
  932. <row>
  933. <entry>0x2B</entry>
  934. <entry>ECC byte 3</entry>
  935. <entry>Error correction code byte 0 of the second 256 Bytes of data
  936. in this page</entry>
  937. </row>
  938. <row>
  939. <entry>0x2C</entry>
  940. <entry>ECC byte 4</entry>
  941. <entry>Error correction code byte 1 of the second 256 Bytes of data
  942. in this page</entry>
  943. </row>
  944. <row>
  945. <entry>0x2D</entry>
  946. <entry>ECC byte 5</entry>
  947. <entry>Error correction code byte 2 of the second 256 Bytes of data
  948. in this page</entry>
  949. </row>
  950. <row>
  951. <entry>0x2E</entry>
  952. <entry>ECC byte 6</entry>
  953. <entry>Error correction code byte 0 of the third 256 Bytes of data
  954. in this page</entry>
  955. </row>
  956. <row>
  957. <entry>0x2F</entry>
  958. <entry>ECC byte 7</entry>
  959. <entry>Error correction code byte 1 of the third 256 Bytes of data
  960. in this page</entry>
  961. </row>
  962. <row>
  963. <entry>0x30</entry>
  964. <entry>ECC byte 8</entry>
  965. <entry>Error correction code byte 2 of the third 256 Bytes of data
  966. in this page</entry>
  967. </row>
  968. <row>
  969. <entry>0x31</entry>
  970. <entry>ECC byte 9</entry>
  971. <entry>Error correction code byte 0 of the fourth 256 Bytes of data
  972. in this page</entry>
  973. </row>
  974. <row>
  975. <entry>0x32</entry>
  976. <entry>ECC byte 10</entry>
  977. <entry>Error correction code byte 1 of the fourth 256 Bytes of data
  978. in this page</entry>
  979. </row>
  980. <row>
  981. <entry>0x33</entry>
  982. <entry>ECC byte 11</entry>
  983. <entry>Error correction code byte 2 of the fourth 256 Bytes of data
  984. in this page</entry>
  985. </row>
  986. <row>
  987. <entry>0x34</entry>
  988. <entry>ECC byte 12</entry>
  989. <entry>Error correction code byte 0 of the fifth 256 Bytes of data
  990. in this page</entry>
  991. </row>
  992. <row>
  993. <entry>0x35</entry>
  994. <entry>ECC byte 13</entry>
  995. <entry>Error correction code byte 1 of the fifth 256 Bytes of data
  996. in this page</entry>
  997. </row>
  998. <row>
  999. <entry>0x36</entry>
  1000. <entry>ECC byte 14</entry>
  1001. <entry>Error correction code byte 2 of the fifth 256 Bytes of data
  1002. in this page</entry>
  1003. </row>
  1004. <row>
  1005. <entry>0x37</entry>
  1006. <entry>ECC byte 15</entry>
  1007. <entry>Error correction code byte 0 of the sixt 256 Bytes of data
  1008. in this page</entry>
  1009. </row>
  1010. <row>
  1011. <entry>0x38</entry>
  1012. <entry>ECC byte 16</entry>
  1013. <entry>Error correction code byte 1 of the sixt 256 Bytes of data
  1014. in this page</entry>
  1015. </row>
  1016. <row>
  1017. <entry>0x39</entry>
  1018. <entry>ECC byte 17</entry>
  1019. <entry>Error correction code byte 2 of the sixt 256 Bytes of data
  1020. in this page</entry>
  1021. </row>
  1022. <row>
  1023. <entry>0x3A</entry>
  1024. <entry>ECC byte 18</entry>
  1025. <entry>Error correction code byte 0 of the seventh 256 Bytes of
  1026. data in this page</entry>
  1027. </row>
  1028. <row>
  1029. <entry>0x3B</entry>
  1030. <entry>ECC byte 19</entry>
  1031. <entry>Error correction code byte 1 of the seventh 256 Bytes of
  1032. data in this page</entry>
  1033. </row>
  1034. <row>
  1035. <entry>0x3C</entry>
  1036. <entry>ECC byte 20</entry>
  1037. <entry>Error correction code byte 2 of the seventh 256 Bytes of
  1038. data in this page</entry>
  1039. </row>
  1040. <row>
  1041. <entry>0x3D</entry>
  1042. <entry>ECC byte 21</entry>
  1043. <entry>Error correction code byte 0 of the eigth 256 Bytes of data
  1044. in this page</entry>
  1045. </row>
  1046. <row>
  1047. <entry>0x3E</entry>
  1048. <entry>ECC byte 22</entry>
  1049. <entry>Error correction code byte 1 of the eigth 256 Bytes of data
  1050. in this page</entry>
  1051. </row>
  1052. <row>
  1053. <entry>0x3F</entry>
  1054. <entry>ECC byte 23</entry>
  1055. <entry>Error correction code byte 2 of the eigth 256 Bytes of data
  1056. in this page</entry>
  1057. </row>
  1058. </tbody></tgroup></informaltable>
  1059. </sect2>
  1060. </sect1>
  1061. </chapter>
  1062. <chapter id="filesystems">
  1063. <title>Filesystem support</title>
  1064. <para>
  1065. The NAND driver provides all neccecary functions for a
  1066. filesystem via the MTD interface.
  1067. </para>
  1068. <para>
  1069. Filesystems must be aware of the NAND pecularities and
  1070. restrictions. One major restrictions of NAND Flash is, that you cannot
  1071. write as often as you want to a page. The consecutive writes to a page,
  1072. before erasing it again, are restricted to 1-3 writes, depending on the
  1073. manufacturers specifications. This applies similar to the spare area.
  1074. </para>
  1075. <para>
  1076. Therefor NAND aware filesystems must either write in page size chunks
  1077. or hold a writebuffer to collect smaller writes until they sum up to
  1078. pagesize. Available NAND aware filesystems: JFFS2, YAFFS.
  1079. </para>
  1080. <para>
  1081. The spare area usage to store filesystem data is controlled by
  1082. the spare area placement functionality which is described in one
  1083. of the earlier chapters.
  1084. </para>
  1085. </chapter>
  1086. <chapter id="tools">
  1087. <title>Tools</title>
  1088. <para>
  1089. The MTD project provides a couple of helpful tools to handle NAND Flash.
  1090. <itemizedlist>
  1091. <listitem><para>flasherase, flasheraseall: Erase and format FLASH partitions</para></listitem>
  1092. <listitem><para>nandwrite: write filesystem images to NAND FLASH</para></listitem>
  1093. <listitem><para>nanddump: dump the contents of a NAND FLASH partitions</para></listitem>
  1094. </itemizedlist>
  1095. </para>
  1096. <para>
  1097. These tools are aware of the NAND restrictions. Please use those tools
  1098. instead of complaining about errors which are caused by non NAND aware
  1099. access methods.
  1100. </para>
  1101. </chapter>
  1102. <chapter id="defines">
  1103. <title>Constants</title>
  1104. <para>
  1105. This chapter describes the constants which might be relevant for a driver developer.
  1106. </para>
  1107. <sect1>
  1108. <title>Chip option constants</title>
  1109. <sect2>
  1110. <title>Constants for chip id table</title>
  1111. <para>
  1112. These constants are defined in nand.h. They are ored together to describe
  1113. the chip functionality.
  1114. <programlisting>
  1115. /* Chip can not auto increment pages */
  1116. #define NAND_NO_AUTOINCR 0x00000001
  1117. /* Buswitdh is 16 bit */
  1118. #define NAND_BUSWIDTH_16 0x00000002
  1119. /* Device supports partial programming without padding */
  1120. #define NAND_NO_PADDING 0x00000004
  1121. /* Chip has cache program function */
  1122. #define NAND_CACHEPRG 0x00000008
  1123. /* Chip has copy back function */
  1124. #define NAND_COPYBACK 0x00000010
  1125. /* AND Chip which has 4 banks and a confusing page / block
  1126. * assignment. See Renesas datasheet for further information */
  1127. #define NAND_IS_AND 0x00000020
  1128. /* Chip has a array of 4 pages which can be read without
  1129. * additional ready /busy waits */
  1130. #define NAND_4PAGE_ARRAY 0x00000040
  1131. </programlisting>
  1132. </para>
  1133. </sect2>
  1134. <sect2>
  1135. <title>Constants for runtime options</title>
  1136. <para>
  1137. These constants are defined in nand.h. They are ored together to describe
  1138. the functionality.
  1139. <programlisting>
  1140. /* Use a flash based bad block table. This option is parsed by the
  1141. * default bad block table function (nand_default_bbt). */
  1142. #define NAND_USE_FLASH_BBT 0x00010000
  1143. /* The hw ecc generator provides a syndrome instead a ecc value on read
  1144. * This can only work if we have the ecc bytes directly behind the
  1145. * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */
  1146. #define NAND_HWECC_SYNDROME 0x00020000
  1147. </programlisting>
  1148. </para>
  1149. </sect2>
  1150. </sect1>
  1151. <sect1>
  1152. <title>ECC selection constants</title>
  1153. <para>
  1154. Use these constants to select the ECC algorithm.
  1155. <programlisting>
  1156. /* No ECC. Usage is not recommended ! */
  1157. #define NAND_ECC_NONE 0
  1158. /* Software ECC 3 byte ECC per 256 Byte data */
  1159. #define NAND_ECC_SOFT 1
  1160. /* Hardware ECC 3 byte ECC per 256 Byte data */
  1161. #define NAND_ECC_HW3_256 2
  1162. /* Hardware ECC 3 byte ECC per 512 Byte data */
  1163. #define NAND_ECC_HW3_512 3
  1164. /* Hardware ECC 6 byte ECC per 512 Byte data */
  1165. #define NAND_ECC_HW6_512 4
  1166. /* Hardware ECC 6 byte ECC per 512 Byte data */
  1167. #define NAND_ECC_HW8_512 6
  1168. </programlisting>
  1169. </para>
  1170. </sect1>
  1171. <sect1>
  1172. <title>Hardware control related constants</title>
  1173. <para>
  1174. These constants describe the requested hardware access function when
  1175. the boardspecific hardware control function is called
  1176. <programlisting>
  1177. /* Select the chip by setting nCE to low */
  1178. #define NAND_CTL_SETNCE 1
  1179. /* Deselect the chip by setting nCE to high */
  1180. #define NAND_CTL_CLRNCE 2
  1181. /* Select the command latch by setting CLE to high */
  1182. #define NAND_CTL_SETCLE 3
  1183. /* Deselect the command latch by setting CLE to low */
  1184. #define NAND_CTL_CLRCLE 4
  1185. /* Select the address latch by setting ALE to high */
  1186. #define NAND_CTL_SETALE 5
  1187. /* Deselect the address latch by setting ALE to low */
  1188. #define NAND_CTL_CLRALE 6
  1189. /* Set write protection by setting WP to high. Not used! */
  1190. #define NAND_CTL_SETWP 7
  1191. /* Clear write protection by setting WP to low. Not used! */
  1192. #define NAND_CTL_CLRWP 8
  1193. </programlisting>
  1194. </para>
  1195. </sect1>
  1196. <sect1>
  1197. <title>Bad block table related constants</title>
  1198. <para>
  1199. These constants describe the options used for bad block
  1200. table descriptors.
  1201. <programlisting>
  1202. /* Options for the bad block table descriptors */
  1203. /* The number of bits used per block in the bbt on the device */
  1204. #define NAND_BBT_NRBITS_MSK 0x0000000F
  1205. #define NAND_BBT_1BIT 0x00000001
  1206. #define NAND_BBT_2BIT 0x00000002
  1207. #define NAND_BBT_4BIT 0x00000004
  1208. #define NAND_BBT_8BIT 0x00000008
  1209. /* The bad block table is in the last good block of the device */
  1210. #define NAND_BBT_LASTBLOCK 0x00000010
  1211. /* The bbt is at the given page, else we must scan for the bbt */
  1212. #define NAND_BBT_ABSPAGE 0x00000020
  1213. /* The bbt is at the given page, else we must scan for the bbt */
  1214. #define NAND_BBT_SEARCH 0x00000040
  1215. /* bbt is stored per chip on multichip devices */
  1216. #define NAND_BBT_PERCHIP 0x00000080
  1217. /* bbt has a version counter at offset veroffs */
  1218. #define NAND_BBT_VERSION 0x00000100
  1219. /* Create a bbt if none axists */
  1220. #define NAND_BBT_CREATE 0x00000200
  1221. /* Search good / bad pattern through all pages of a block */
  1222. #define NAND_BBT_SCANALLPAGES 0x00000400
  1223. /* Scan block empty during good / bad block scan */
  1224. #define NAND_BBT_SCANEMPTY 0x00000800
  1225. /* Write bbt if neccecary */
  1226. #define NAND_BBT_WRITE 0x00001000
  1227. /* Read and write back block contents when writing bbt */
  1228. #define NAND_BBT_SAVECONTENT 0x00002000
  1229. </programlisting>
  1230. </para>
  1231. </sect1>
  1232. </chapter>
  1233. <chapter id="structs">
  1234. <title>Structures</title>
  1235. <para>
  1236. This chapter contains the autogenerated documentation of the structures which are
  1237. used in the NAND driver and might be relevant for a driver developer. Each
  1238. struct member has a short description which is marked with an [XXX] identifier.
  1239. See the chapter "Documentation hints" for an explanation.
  1240. </para>
  1241. !Iinclude/linux/mtd/nand.h
  1242. </chapter>
  1243. <chapter id="pubfunctions">
  1244. <title>Public Functions Provided</title>
  1245. <para>
  1246. This chapter contains the autogenerated documentation of the NAND kernel API functions
  1247. which are exported. Each function has a short description which is marked with an [XXX] identifier.
  1248. See the chapter "Documentation hints" for an explanation.
  1249. </para>
  1250. !Edrivers/mtd/nand/nand_base.c
  1251. !Edrivers/mtd/nand/nand_bbt.c
  1252. !Edrivers/mtd/nand/nand_ecc.c
  1253. </chapter>
  1254. <chapter id="intfunctions">
  1255. <title>Internal Functions Provided</title>
  1256. <para>
  1257. This chapter contains the autogenerated documentation of the NAND driver internal functions.
  1258. Each function has a short description which is marked with an [XXX] identifier.
  1259. See the chapter "Documentation hints" for an explanation.
  1260. The functions marked with [DEFAULT] might be relevant for a board driver developer.
  1261. </para>
  1262. !Idrivers/mtd/nand/nand_base.c
  1263. !Idrivers/mtd/nand/nand_bbt.c
  1264. !Idrivers/mtd/nand/nand_ecc.c
  1265. </chapter>
  1266. <chapter id="credits">
  1267. <title>Credits</title>
  1268. <para>
  1269. The following people have contributed to the NAND driver:
  1270. <orderedlist>
  1271. <listitem><para>Steven J. Hill<email>sjhill@realitydiluted.com</email></para></listitem>
  1272. <listitem><para>David Woodhouse<email>dwmw2@infradead.org</email></para></listitem>
  1273. <listitem><para>Thomas Gleixner<email>tglx@linutronix.de</email></para></listitem>
  1274. </orderedlist>
  1275. A lot of users have provided bugfixes, improvements and helping hands for testing.
  1276. Thanks a lot.
  1277. </para>
  1278. <para>
  1279. The following people have contributed to this document:
  1280. <orderedlist>
  1281. <listitem><para>Thomas Gleixner<email>tglx@linutronix.de</email></para></listitem>
  1282. </orderedlist>
  1283. </para>
  1284. </chapter>
  1285. </book>