MTD NAND Driver Programming Interface
|  | Next

# MTD NAND Driver Programming Interface

### Thomas Gleixner

`<tglx@linutronix.de>`

Copyright © 2004 Thomas Gleixner

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.

Table of Contents

1. Introduction
2. Known Bugs And Assumptions
3. Documentation hints
  Function identifiers [XXX]
  Struct member identifiers [XXX]
4. Basic board driver
  Basic defines
  Partition defines
  Hardware control function
  Device ready function
  Init function
  Exit function
5. Advanced board driver functions
  Multiple chip control
  Hardware ECC support
    Functions and constants
    Hardware ECC with syndrome calculation
  Bad block table support
    Flash based tables
    User defined tables
  Spare area (auto)placement
    Placement defined by fs driver
    Automatic placement
  Spare area autoplacement default schemes
    256 byte pagesize
    512 byte pagesize
    2048 byte pagesize
6. Filesystem support
7. Tools
8. Constants
  Chip option constants
    Constants for chip id table
    Constants for runtime options
  ECC selection constants
  Hardware control related constants
  Bad block table related constants
9. Structures
  struct nand_hw_control — Control structure for hardware controller (e.g ECC generator) shared among independent devices
  struct nand_ecc_ctrl — Control structure for ECC
  struct nand_buffers — buffer structure for read/write
  struct nand_chip — NAND Private Flash Chip Data
  struct nand_flash_dev — NAND Flash Device ID Structure
  struct nand_manufacturers — NAND Flash Manufacturer ID Structure
  struct platform_nand_chip — chip level device structure
  struct platform_nand_ctrl — controller level device structure
  struct platform_nand_data — container structure for platform-specific data
10. Public Functions Provided
  nand_unlock — [REPLACEABLE] unlocks specified locked blocks
  nand_lock — [REPLACEABLE] locks all blocks present in the device
  nand_scan_ident — [NAND Interface] Scan for the NAND device
  nand_scan_tail — [NAND Interface] Scan for the NAND device
  nand_scan — [NAND Interface] Scan for the NAND device
  nand_release — [NAND Interface] Free resources held by the NAND device
  nand_scan_bbt — [NAND Interface] scan, find, read and maybe create bad block table(s)
  __nand_calculate_ecc — [NAND Interface] Calculate 3-byte ECC for 256/512-byte block
  nand_calculate_ecc — [NAND Interface] Calculate 3-byte ECC for 256/512-byte block
  __nand_correct_data — [NAND Interface] Detect and correct bit error(s)
  nand_correct_data — [NAND Interface] Detect and correct bit error(s)
11. Internal Functions Provided
  nand_release_device — [GENERIC] release chip
  nand_read_byte — [DEFAULT] read one byte from the chip
  nand_read_byte16 — [DEFAULT] read one byte endianness aware from the chip nand_read_byte16 - [DEFAULT] read one byte endianness aware from the chip
  nand_read_word — [DEFAULT] read one word from the chip
  nand_select_chip — [DEFAULT] control CE line
  nand_write_buf — [DEFAULT] write buffer to chip
  nand_read_buf — [DEFAULT] read chip data into buffer
  nand_write_buf16 — [DEFAULT] write buffer to chip
  nand_read_buf16 — [DEFAULT] read chip data into buffer
  nand_block_bad — [DEFAULT] Read bad block marker from the chip
  nand_default_block_markbad — [DEFAULT] mark a block bad via bad block marker
  nand_block_markbad_lowlevel — mark a block bad
  nand_check_wp — [GENERIC] check if the chip is write protected
  nand_block_checkbad — [GENERIC] Check if a block is marked bad
  panic_nand_wait_ready — [GENERIC] Wait for the ready pin after commands.
  nand_command — [DEFAULT] Send command to NAND device
  nand_command_lp — [DEFAULT] Send command to NAND large page device
  panic_nand_get_device — [GENERIC] Get chip for selected access
  nand_get_device — [GENERIC] Get chip for selected access
  panic_nand_wait — [GENERIC] wait until the command is done
  nand_wait — [DEFAULT] wait until the command is done
  __nand_unlock — [REPLACEABLE] unlocks specified locked blocks
  nand_read_page_raw — [INTERN] read raw page data without ecc
  nand_read_page_raw_syndrome — [INTERN] read raw page data without ecc
  nand_read_page_swecc — [REPLACEABLE] software ECC based page read function
  nand_read_subpage — [REPLACEABLE] ECC based sub-page read function
  nand_read_page_hwecc — [REPLACEABLE] hardware ECC based page read function
  nand_read_page_hwecc_oob_first — [REPLACEABLE] hw ecc, read oob first
  nand_read_page_syndrome — [REPLACEABLE] hardware ECC syndrome based page read
  nand_transfer_oob — [INTERN] Transfer oob to client buffer
  nand_do_read_ops — [INTERN] Read data with ECC
  nand_read — [MTD Interface] MTD compatibility function for nand_do_read_ecc
  nand_read_oob_std — [REPLACEABLE] the most common OOB data read function
  nand_read_oob_syndrome — [REPLACEABLE] OOB data read function for HW ECC with syndromes
  nand_write_oob_std — [REPLACEABLE] the most common OOB data write function
  nand_write_oob_syndrome — [REPLACEABLE] OOB data write function for HW ECC with syndrome - only for large page flash
  nand_do_read_oob — [INTERN] NAND read out-of-band
  nand_read_oob — [MTD Interface] NAND read data and/or out-of-band
  nand_write_page_raw — [INTERN] raw page write function
  nand_write_page_raw_syndrome — [INTERN] raw page write function
  nand_write_page_swecc — [REPLACEABLE] software ECC based page write function
  nand_write_page_hwecc — [REPLACEABLE] hardware ECC based page write function
  nand_write_subpage_hwecc — [REPLACABLE] hardware ECC based subpage write
  nand_write_page_syndrome — [REPLACEABLE] hardware ECC syndrome based page write
  nand_write_page — [REPLACEABLE] write one page
  nand_fill_oob — [INTERN] Transfer client buffer to oob
  nand_do_write_ops — [INTERN] NAND write with ECC
  panic_nand_write — [MTD Interface] NAND write with ECC
  nand_write — [MTD Interface] NAND write with ECC
  nand_do_write_oob — [MTD Interface] NAND write out-of-band
  nand_write_oob — [MTD Interface] NAND write data and/or out-of-band
  single_erase_cmd — [GENERIC] NAND standard block erase command function
  nand_erase — [MTD Interface] erase block(s)
  nand_erase_nand — [INTERN] erase block(s)
  nand_sync — [MTD Interface] sync
  nand_block_isbad — [MTD Interface] Check if block at offset is bad
  nand_block_markbad — [MTD Interface] Mark block at the given offset as bad
  nand_onfi_set_features — [REPLACEABLE] set features for ONFI nand
  nand_onfi_get_features — [REPLACEABLE] get features for ONFI nand
  nand_suspend — [MTD Interface] Suspend the NAND flash
  nand_resume — [MTD Interface] Resume the NAND flash
  check_pattern — [GENERIC] check if a pattern is in the buffer
  check_short_pattern — [GENERIC] check if a pattern is in the buffer
  add_marker_len — compute the length of the marker in data area
  read_bbt — [GENERIC] Read the bad block table starting from page
  read_abs_bbt — [GENERIC] Read the bad block table starting at a given page
  scan_read_oob — [GENERIC] Scan data+OOB region to buffer
  read_abs_bbts — [GENERIC] Read the bad block table(s) for all chips starting at a given page
  create_bbt — [GENERIC] Create a bad block table by scanning the device
  search_bbt — [GENERIC] scan the device for a specific bad block table
  search_read_bbts — [GENERIC] scan the device for bad block table(s)
  write_bbt — [GENERIC] (Re)write the bad block table
  nand_memory_bbt — [GENERIC] create a memory based bad block table
  check_create — [GENERIC] create and write bbt(s) if necessary
  mark_bbt_region — [GENERIC] mark the bad block table regions
  verify_bbt_descr — verify the bad block description
  nand_update_bbt — update bad block table(s)
  nand_create_badblock_pattern — [INTERN] Creates a BBT descriptor structure
  nand_default_bbt — [NAND Interface] Select a default bad block table for the device
  nand_isbad_bbt — [NAND Interface] Check if a block is bad
  nand_markbad_bbt — [NAND Interface] Mark a block bad in the BBT
12. Credits

|  | Next
|  | Chapter 1. Introduction