tools/build-R2_19_3/fsboot/cbl/nand/nand_base.c File Reference

#include <axisrfl/mtd.h>
#include <axisrfl/mtd_nand.h>
#include <axisrfl/nand_ecc.h>
#include <axisrfl/funcs.h>
#include <bitops.h>
#include <hal_intr.h>
#include <string.h>
#include <axisrfl/linuxerr.h>

Include dependency graph for nand_base.c:

Go to the source code of this file.

Defines

#define dprintf   if(0)printf
#define udelay(x)   HAL_DELAY_US(x)
#define nop()   __asm__("nop")
#define ndelay(x)
#define GPIO_SYNC   0
#define DEBUG(n, args...)   do { } while(0)
#define D(x)   x
#define nand_verify_pages(...)   (0)
#define NOTALIGNED(x)   (x & (mtd->oobblock-1)) != 0
#define BBT_PAGE_MASK   0xffffff3f

Functions

static void nand_write_buf (struct mtd_info *mtd, const u_char *buf, int len)
static void nand_read_buf (struct mtd_info *mtd, u_char *buf, int len)
static int nand_verify_buf (struct mtd_info *mtd, const u_char *buf, int len)
static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel)
static int nand_read_oob (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
static void nand_release_device (struct mtd_info *mtd)
static u_char nand_read_byte (struct mtd_info *mtd)
static void nand_write_byte (struct mtd_info *mtd, u_char byte)
static u16 nand_read_word (struct mtd_info *mtd)
static void nand_write_word (struct mtd_info *mtd, u16 word)
static void nand_select_chip (struct mtd_info *mtd, int chip)
static int nand_block_bad (struct mtd_info *mtd, loff_t ofs, int getchip)
static int nand_block_checkbad (struct mtd_info *mtd, loff_t ofs, int getchip, int allowbbt)
static void nand_wait_ready (struct mtd_info *mtd)
char * command_str (unsigned cmd)
static void nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr)
static void nand_command_lp (struct mtd_info *mtd, unsigned command, int column, int page_addr)
static int nand_wait (struct mtd_info *mtd, struct nand_chip *this, int state)
int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *oob_buf, struct nand_oobinfo *oobsel, int flags)
int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len, size_t ooblen)
static int nand_block_isbad (struct mtd_info *mtd, loff_t ofs)
int nand_scan (struct mtd_info *mtd, int maxchips)

Variables

static struct nand_oobinfo nand_oob_8
static struct nand_oobinfo nand_oob_16
static struct nand_oobinfo nand_oob_64


Define Documentation

#define BBT_PAGE_MASK   0xffffff3f

nand_erase - [MTD Interface] erase block(s) : MTD device structure : erase instruction

Erase one ore more blocks

Definition at line 2288 of file nand_base.c.

#define D ( x   )     x

Definition at line 125 of file nand_base.c.

#define DEBUG ( n,
args...   )     do { } while(0)

Definition at line 123 of file nand_base.c.

#define dprintf   if(0)printf

Definition at line 74 of file nand_base.c.

#define GPIO_SYNC   0

Definition at line 120 of file nand_base.c.

#define nand_verify_pages ( ...   )     (0)

Definition at line 208 of file nand_base.c.

Referenced by nand_wait().

#define ndelay ( x   ) 

Value:

do { nop(); nop(); nop(); nop(); \
                       nop(); nop(); nop(); nop(); } while (0)

Definition at line 117 of file nand_base.c.

 
#define nop (  )     __asm__("nop")

Definition at line 115 of file nand_base.c.

#define NOTALIGNED ( x   )     (x & (mtd->oobblock-1)) != 0

nand_prepare_oobbuf - [GENERIC] Prepare the out of band buffer : MTD device structure : buffer given by fs driver : out of band selection structre : 1 = place given buffer into the oob bytes : number of pages to prepare

Return: 1. Filesystem buffer available and autoplacement is off, return filesystem buffer 2. No filesystem buffer or autoplace is off, return internal buffer 3. Filesystem buffer is given and autoplace selected put data from fs buffer into internal buffer and retrun internal buffer

Note: The internal buffer is filled with 0xff. This must be done only once, when no autoplacement happens Autoplacement sets the buffer dirty flag, which forces the 0xff fill before using the buffer again.

Definition at line 1759 of file nand_base.c.

#define udelay ( x   )     HAL_DELAY_US(x)

Definition at line 113 of file nand_base.c.


Function Documentation

char* command_str ( unsigned  cmd  ) 

Definition at line 649 of file nand_base.c.

Referenced by nand_command().

static int nand_block_bad ( struct mtd_info mtd,
loff_t  ofs,
int  getchip 
) [static]

nand_block_bad - [DEFAULT] Read bad block marker from the chip : MTD device structure : offset from device start : 0, if the chip is already selected

Check, if the block is bad.

Definition at line 502 of file nand_base.c.

References nand_chip::cmdfunc, cpu_to_le16, dprintf, FL_READING, mtd_info::ignore_bad, int, NAND_BUSWIDTH_16, NAND_CMD_READOOB, nand_get_device(), nand_release_device(), mtd_info::priv, and nand_chip::select_chip.

static int nand_block_checkbad ( struct mtd_info mtd,
loff_t  ofs,
int  getchip,
int  allowbbt 
) [static]

nand_block_checkbad - [GENERIC] Check if a block is marked bad : MTD device structure : offset from device start : 0, if the chip is already selected : 1, if its allowed to access the bbt area

Check, if the block is bad. Either by reading the bad block table or calling of the scan function.

Definition at line 616 of file nand_base.c.

References nand_chip::block_bad, BUG, D, dprintf, nand_isbad_bbt(), printk, and mtd_info::priv.

static int nand_block_isbad ( struct mtd_info mtd,
loff_t  ofs 
) [static]

nand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad : MTD device structure : offset relative to mtd start

Definition at line 2506 of file nand_base.c.

References dprintf, nand_block_checkbad(), and mtd_info::size.

static void nand_command ( struct mtd_info mtd,
unsigned  command,
int  column,
int  page_addr 
) [static]

nand_command - [DEFAULT] Send command to NAND device : MTD device structure : the command to be sent : the column address for this command, -1 if none : the page address for this command, -1 if none

Send command to NAND device. This function is used for small page devices (256/512 Bytes per page)

Definition at line 684 of file nand_base.c.

References command_str(), dprintf, nand_chip::hwcontrol, NAND_BUSWIDTH_16, NAND_CMD_ERASE1, NAND_CMD_ERASE2, NAND_CMD_PAGEPROG, NAND_CMD_READ0, NAND_CMD_READ1, NAND_CMD_READOOB, NAND_CMD_RESET, NAND_CMD_SEQIN, NAND_CMD_STATUS, NAND_CTL_CLRALE, NAND_CTL_CLRCLE, NAND_CTL_SETALE, NAND_CTL_SETCLE, NAND_STATUS_READY, nand_wait_ready(), ndelay, mtd_info::oobblock, mtd_info::priv, udelay, and nand_chip::write_byte.

static void nand_command_lp ( struct mtd_info mtd,
unsigned  command,
int  column,
int  page_addr 
) [static]

nand_command_lp - [DEFAULT] Send command to NAND large page device : MTD device structure : the command to be sent : the column address for this command, -1 if none : the page address for this command, -1 if none

Send command to NAND device. This is the version for the new large page devices We dont have the seperate regions as we have in the small page devices. We must emulate NAND_CMD_READOOB to keep the code compatible.

Definition at line 794 of file nand_base.c.

References nand_chip::hwcontrol, NAND_BUSWIDTH_16, NAND_CMD_CACHEDPROG, NAND_CMD_DEPLETE1, NAND_CMD_ERASE1, NAND_CMD_ERASE2, NAND_CMD_PAGEPROG, NAND_CMD_READ0, NAND_CMD_READOOB, NAND_CMD_READSTART, NAND_CMD_RESET, NAND_CMD_SEQIN, NAND_CMD_STATUS, NAND_CMD_STATUS_ERROR, NAND_CMD_STATUS_ERROR0, NAND_CMD_STATUS_ERROR1, NAND_CMD_STATUS_ERROR2, NAND_CMD_STATUS_ERROR3, NAND_CTL_CLRALE, NAND_CTL_CLRCLE, NAND_CTL_SETALE, NAND_CTL_SETCLE, NAND_STATUS_READY, nand_wait_ready(), ndelay, mtd_info::oobblock, mtd_info::priv, udelay, and nand_chip::write_byte.

int nand_do_read_ecc ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char *  buf,
u_char *  oob_buf,
struct nand_oobinfo oobsel,
int  flags 
)

nand_do_read_ecc - [MTD Interface] Read data with ECC : MTD device structure : offset to read from : number of bytes to read : pointer to variable to store the number of read bytes : the databuffer to put data : filesystem supplied oob data buffer (can be NULL) : oob selection structure : flag to indicate if nand_get_device/nand_release_device should be preformed and how many corrected error bits are acceptable: bits 0..7 - number of tolerable errors bit 8 - 0 == do not get/release chip, 1 == get/release chip

NAND read with ECC

Definition at line 1284 of file nand_base.c.

References nand_chip::autooob, nand_chip::calculate_ecc, nand_chip::cmdfunc, nand_chip::correct_data, D, data_buf, nand_chip::data_poi, DEBUG, nand_chip::ecc, nand_oobinfo::eccbytes, nand_chip::eccbytes, nand_chip::eccmode, nand_oobinfo::eccpos, nand_chip::eccsize, nand_chip::eccsteps, nand_chip::enable_hwecc, FL_READING, HZ, jiffies, memcpy(), MTD_DEBUG_LEVEL0, MTD_DEBUG_LEVEL3, MTD_NANDECC_AUTOPL_USR, MTD_NANDECC_AUTOPLACE, MTD_NANDECC_PLACE, NAND_CANAUTOINCR, NAND_CMD_READ0, NAND_ECC_NONE, NAND_ECC_READ, NAND_ECC_READSYN, NAND_ECC_SOFT, nand_get_device(), NAND_GET_DEVICE, NAND_HWECC_SYNDROME, nand_release_device(), nand_wait_ready(), num, mtd_info::oobblock, nand_oobinfo::oobfree, mtd_info::oobsize, nand_chip::page_shift, nand_chip::pagebuf, nand_chip::pagemask, nand_chip::phys_erase_shift, printk, mtd_info::priv, read, nand_chip::read_buf, nand_chip::select_chip, mtd_info::size, udelay, and nand_oobinfo::useecc.

Referenced by nand_read(), and nand_read_ecc().

static int nand_get_device ( struct nand_chip this,
struct mtd_info mtd,
int  new_state 
) [static]

nand_get_device - [GENERIC] Get chip for selected access : the nand chip descriptor : MTD device structure : the state which is requested

Get the device and lock it for exclusive access

Definition at line 906 of file nand_base.c.

References nand_hw_control::active, add_wait_queue, nand_chip::chip_lock, nand_chip::controller, DECLARE_WAITQUEUE, FL_PM_SUSPENDED, FL_READY, nand_hw_control::lock, remove_wait_queue, schedule, set_current_state, spin_lock, spin_unlock, spinlock_t, nand_chip::state, state, TASK_UNINTERRUPTIBLE, wait_queue_head_t, nand_hw_control::wq, and nand_chip::wq.

static int nand_read ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char *  buf 
) [static]

nand_read - [MTD Interface] MTD compability function for nand_do_read_ecc : MTD device structure : offset to read from : number of bytes to read : pointer to variable to store the number of read bytes : the databuffer to put data

This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL and flags = 0xff

Definition at line 1240 of file nand_base.c.

References nand_do_read_ecc(), and mtd_info::oobinfo.

static void nand_read_buf ( struct mtd_info mtd,
u_char *  buf,
int  len 
) [static]

nand_read_buf - [DEFAULT] read chip data into buffer : MTD device structure : buffer to store date : number of bytes to read

Default read function for 8bit buswith

Definition at line 396 of file nand_base.c.

References dprintf, mtd_info::priv, and readb().

static u_char nand_read_byte ( struct mtd_info mtd  )  [static]

nand_read_byte - [DEFAULT] read one byte from the chip : MTD device structure

Default read function for 8bit buswith

Definition at line 250 of file nand_base.c.

References dprintf, mtd_info::priv, and readb().

static int nand_read_ecc ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char *  buf,
u_char *  oob_buf,
struct nand_oobinfo oobsel 
) [static]

nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc : MTD device structure : offset to read from : number of bytes to read : pointer to variable to store the number of read bytes : the databuffer to put data : filesystem supplied oob data buffer : oob selection structure

This function simply calls nand_do_read_ecc with flags = 0xff

Definition at line 1258 of file nand_base.c.

References nand_do_read_ecc(), and mtd_info::oobinfo.

static int nand_read_oob ( struct mtd_info mtd,
loff_t  from,
size_t  len,
size_t *  retlen,
u_char *  buf 
) [static]

nand_read_oob - [MTD Interface] NAND read out-of-band : MTD device structure : offset to read from : number of bytes to read : pointer to variable to store the number of read bytes : the databuffer to put data

NAND read out-of-band data from the spare area

Definition at line 1550 of file nand_base.c.

References nand_chip::chip_delay, nand_chip::chip_shift, nand_chip::cmdfunc, DEBUG, nand_chip::dev_ready, FL_READING, min_t, MTD_DEBUG_LEVEL0, MTD_DEBUG_LEVEL3, NAND_CANAUTOINCR, NAND_CMD_READOOB, nand_get_device(), nand_release_device(), nand_wait_ready(), mtd_info::oobsize, nand_chip::page_shift, nand_chip::pagemask, nand_chip::phys_erase_shift, mtd_info::priv, nand_chip::read_buf, nand_chip::select_chip, mtd_info::size, and udelay.

int nand_read_raw ( struct mtd_info mtd,
uint8_t *  buf,
loff_t  from,
size_t  len,
size_t  ooblen 
)

nand_read_raw - [GENERIC] Read raw data including oob into buffer : MTD device structure : temporary buffer : offset to read from : number of bytes to read : number of oob data bytes to read

Read raw data including oob into buffer

Definition at line 1644 of file nand_base.c.

References nand_chip::chip_delay, nand_chip::chip_shift, nand_chip::cmdfunc, DEBUG, nand_chip::dev_ready, dprintf, FL_READING, int, MTD_DEBUG_LEVEL0, NAND_CANAUTOINCR, NAND_CMD_READ0, nand_get_device(), nand_release_device(), nand_wait_ready(), mtd_info::oobblock, mtd_info::oobsize, nand_chip::page_shift, nand_chip::pagemask, nand_chip::phys_erase_shift, mtd_info::priv, nand_chip::read_buf, nand_chip::select_chip, mtd_info::size, and udelay.

Referenced by read_abs_bbts(), and search_bbt().

static u16 nand_read_word ( struct mtd_info mtd  )  [static]

nand_read_word - [DEFAULT] read one word from the chip : MTD device structure

Default read function for 16bit buswith without endianess conversion

Definition at line 323 of file nand_base.c.

References mtd_info::priv, and readw().

static void nand_release_device ( struct mtd_info mtd  )  [static]

nand_release_device - [GENERIC] release chip : MTD device structure

Deselect, release chip lock and wake up anyone waiting on the device

Definition at line 219 of file nand_base.c.

References nand_hw_control::active, nand_chip::controller, FL_READY, mtd_info::priv, nand_chip::select_chip, spin_lock, spin_unlock, state, and wake_up.

int nand_scan ( struct mtd_info mtd,
int  maxchips 
)

nand_scan - [NAND Interface] Scan for the NAND device : MTD device structure : Number of chips to scan for

This fills out all the not initialized function pointers with the defaults. The flash ID is read and the mtd/chip structures are filled with the appropriate values. Buffers are allocated if they are not provided by the board driver

Definition at line 2584 of file nand_base.c.

References nand_chip::autooob, nand_chip::badblockpos, nand_chip::bbt_erase_shift, nand_chip::block_bad, nand_chip::block_markbad, BUG, nand_chip::calculate_ecc, caller_is_module, nand_chip::chip_delay, nand_chip::chip_shift, nand_flash_dev::chipsize, nand_chip::chipsize, nand_chip::cmdfunc, nand_chip::correct_data, D, data_buf, nand_chip::data_buf, dprintf, nand_chip::eccbytes, nand_chip::eccmode, nand_chip::eccsize, nand_chip::erase_cmd, nand_flash_dev::erasesize, mtd_info::erasesize, free(), nand_manufacturers::id, malloc(), memset(), multi_erase_cmd(), name, mtd_info::name, nand_flash_dev::name, NAND_4PAGE_ARRAY, nand_block_bad(), NAND_BUSWIDTH_16, nand_calculate_ecc(), NAND_CHIPOPTIONS_MSK, NAND_CMD_READID, nand_command(), nand_command_lp(), nand_correct_data(), NAND_DATABUF_ALLOC, nand_default_bbt(), nand_default_block_markbad, NAND_ECC_HW12_2048, NAND_ECC_SOFT, nand_flash_ids, NAND_HWECC_SUPPORT, NAND_LARGE_BADBLOCK_POS, nand_manuf_ids, NAND_MFR_SAMSUNG, NAND_NO_AUTOINCR, nand_oob_16, nand_oob_64, nand_oob_8, NAND_OOBBUF_ALLOC, nand_read_buf(), nand_read_buf16(), nand_read_byte(), nand_read_byte16(), nand_read_word(), NAND_SAMSUNG_LP_OPTIONS, nand_scan_ident(), nand_scan_tail(), nand_select_chip(), NAND_SMALL_BADBLOCK_POS, nand_verify_buf(), nand_verify_buf16(), nand_wait(), nand_write_buf(), nand_write_buf16(), nand_write_byte(), nand_write_byte16(), nand_write_word(), nand_chip::numchips, nand_chip::oob_buf, mtd_info::oobavail, mtd_info::oobblock, nand_oobinfo::oobfree, mtd_info::oobsize, nand_flash_dev::options, nand_chip::options, mtd_info::owner, nand_chip::page_shift, nand_flash_dev::pagesize, nand_chip::phys_erase_shift, printk, mtd_info::priv, nand_chip::read_buf, nand_chip::read_byte, nand_chip::read_word, nand_chip::scan_bbt, nand_chip::select_chip, single_erase_cmd(), mtd_info::size, nand_chip::verify_buf, nand_chip::waitfunc, nand_chip::write_buf, nand_chip::write_byte, and nand_chip::write_word.

static void nand_select_chip ( struct mtd_info mtd,
int  chip 
) [static]

nand_select_chip - [DEFAULT] control CE line : MTD device structure : chipnumber to select, -1 for deselect

Default select function for 1 chip devices.

Definition at line 350 of file nand_base.c.

References BUG, D, nand_chip::hwcontrol, NAND_CTL_CLRNCE, NAND_CTL_SETNCE, printk, and mtd_info::priv.

static int nand_verify_buf ( struct mtd_info mtd,
const u_char *  buf,
int  len 
) [static]

nand_verify_buf - [DEFAULT] Verify chip data against buffer : MTD device structure : buffer containing the data to compare : number of bytes to compare

Default verify function for 8bit buswith

Definition at line 415 of file nand_base.c.

References mtd_info::priv, and readb().

static int nand_wait ( struct mtd_info mtd,
struct nand_chip this,
int  state 
) [static]

nand_wait - [DEFAULT] wait until the command is done : MTD device structure : NAND chip structure : state to select the max. timeout value

Wait for command done. This applies to erase and program only Erase can take up to 400ms and program up to 20ms according to general NAND and SmartMedia specs

Definition at line 958 of file nand_base.c.

References nand_chip::calculate_ecc, nand_chip::chip_delay, nand_chip::cmdfunc, cond_resched, D, nand_chip::data_poi, DEBUG, nand_chip::dev_ready, dprintf, nand_oobinfo::eccbytes, nand_chip::eccbytes, nand_chip::eccmode, nand_oobinfo::eccpos, nand_chip::eccsize, nand_chip::eccsteps, nand_chip::enable_hwecc, nand_chip::errstat, FL_ERASING, FL_WRITING, HZ, int, jiffies, MTD_DEBUG_LEVEL0, MTD_NANDECC_OFF, NAND_CANAUTOINCR, NAND_CMD_CACHEDPROG, NAND_CMD_PAGEPROG, NAND_CMD_READ0, NAND_CMD_RESET, NAND_CMD_SEQIN, NAND_CMD_STATUS, NAND_CMD_STATUS_MULTI, NAND_ECC_NONE, NAND_ECC_SOFT, NAND_ECC_WRITE, NAND_HWECC_SYNDROME, NAND_IS_AND, NAND_STATUS_FAIL, NAND_STATUS_READY, nand_verify_pages, nand_wait_ready(), nand_write_page(), ndelay, nand_chip::oob_buf, oob_buf, mtd_info::oobblock, mtd_info::oobsize, nand_chip::options, printk, nand_chip::read_buf, nand_chip::read_byte, nand_chip::state, time_before, udelay, nand_oobinfo::useecc, nand_chip::verify_buf, nand_chip::waitfunc, and nand_chip::write_buf.

static void nand_wait_ready ( struct mtd_info mtd  )  [static]

Definition at line 637 of file nand_base.c.

References mtd_info::priv.

static void nand_write_buf ( struct mtd_info mtd,
const u_char *  buf,
int  len 
) [static]

nand_write_buf - [DEFAULT] write buffer to chip : MTD device structure : data buffer : number of bytes to write

Default write function for 8bit buswith

Definition at line 375 of file nand_base.c.

References dprintf, mtd_info::priv, and writeb().

static void nand_write_byte ( struct mtd_info mtd,
u_char  byte 
) [static]

nand_write_byte - [DEFAULT] write one byte to the chip : MTD device structure : pointer to data byte to write

Default write function for 8-bit buswidth

Definition at line 266 of file nand_base.c.

References dprintf, mtd_info::priv, readb(), void(), and writeb().

static void nand_write_word ( struct mtd_info mtd,
u16  word 
) [static]

nand_write_word - [DEFAULT] write one word to the chip : MTD device structure : data word to write

Default write function for 16bit buswith without endianess conversion

Definition at line 337 of file nand_base.c.

References mtd_info::priv, and writew().


Variable Documentation

struct nand_oobinfo nand_oob_16 [static]

Initial value:

 {
        .useecc = MTD_NANDECC_AUTOPLACE,
        .eccbytes = 6,
        .eccpos = {0, 1, 2, 3, 6, 7},
        .oobfree = { {8, 8} }
}

Definition at line 135 of file nand_base.c.

struct nand_oobinfo nand_oob_64 [static]

Initial value:

 {
        .useecc = MTD_NANDECC_AUTOPLACE,
        .eccbytes = 24,
        .eccpos = {
                40, 41, 42, 43, 44, 45, 46, 47,
                48, 49, 50, 51, 52, 53, 54, 55,
                56, 57, 58, 59, 60, 61, 62, 63},
        .oobfree = { {2, 38} }
}

Definition at line 142 of file nand_base.c.

struct nand_oobinfo nand_oob_8 [static]

Initial value:

 {
        .useecc = MTD_NANDECC_AUTOPLACE,
        .eccbytes = 3,
        .eccpos = {0, 1, 2},
        .oobfree = { {3, 2}, {6, 2} }
}

Definition at line 128 of file nand_base.c.


Generated on Fri Nov 28 00:08:22 2008 for elphel by  doxygen 1.5.1