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