mtdnand.tmpl 43 KB

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