9
0
Fork 0

nand: Make write support optional

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2011-04-04 11:24:47 +02:00
parent 779ea89baf
commit eb133335e6
7 changed files with 45 additions and 10 deletions

View File

@ -86,6 +86,7 @@ static ssize_t nand_bb_read(struct cdev *cdev, void *buf, size_t count,
/* Must be a multiple of the largest NAND page size */
#define BB_WRITEBUF_SIZE 4096
#ifdef CONFIG_NAND_WRITE
static int nand_bb_write_buf(struct nand_bb *bb, size_t count)
{
int ret, now;
@ -160,6 +161,7 @@ static int nand_bb_erase(struct cdev *cdev, size_t count, unsigned long offset)
return erase(bb->fd, bb->raw_size, 0);
}
#endif
static int nand_bb_open(struct cdev *cdev, struct filep *f)
{
@ -180,9 +182,10 @@ static int nand_bb_close(struct cdev *cdev, struct filep *f)
{
struct nand_bb *bb = cdev->priv;
#ifdef CONFIG_NAND_WRITE
if (bb->needs_write)
nand_bb_write_buf(bb, bb->offset % BB_WRITEBUF_SIZE);
#endif
bb->open = 0;
free(bb->writebuf);
@ -211,8 +214,10 @@ static struct file_operations nand_bb_ops = {
.open = nand_bb_open,
.close = nand_bb_close,
.read = nand_bb_read,
#ifdef CONFIG_NAND_WRITE
.write = nand_bb_write,
.erase = nand_bb_erase,
#endif
};
/**

View File

@ -8,6 +8,11 @@ menuconfig NAND
if NAND
config NAND_WRITE
bool
default y
prompt "Support writing to Nand"
config NAND_IMX
bool
prompt "i.MX NAND driver"

View File

@ -1,6 +1,7 @@
# Generic NAND options
obj-$(CONFIG_NAND) += nand.o nand_ecc.o nand_hwecc.o nand_swecc.o nand_hwecc_syndrome.o nand_write.o
obj-$(CONFIG_NAND) += nand.o nand_ecc.o nand_hwecc.o nand_swecc.o nand_hwecc_syndrome.o
obj-$(CONFIG_NAND_WRITE) += nand_write.o
obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o
obj-$(CONFIG_NAND) += nand_base.o nand_bbt.o

View File

@ -50,6 +50,7 @@ static ssize_t nand_read(struct cdev *cdev, void* buf, size_t count, ulong offs
#define NOTALIGNED(x) (x & (info->writesize - 1)) != 0
#ifdef CONFIG_NAND_WRITE
static int all_ff(const void *buf, int len)
{
int i;
@ -104,6 +105,7 @@ static ssize_t nand_write(struct cdev* cdev, const void *buf, size_t _count, ulo
out:
return ret ? ret : _count;
}
#endif
static int nand_ioctl(struct cdev *cdev, int request, void *buf)
{
@ -133,6 +135,7 @@ static int nand_ioctl(struct cdev *cdev, int request, void *buf)
return 0;
}
#ifdef CONFIG_NAND_WRITE
static ssize_t nand_erase(struct cdev *cdev, size_t count, unsigned long offset)
{
struct mtd_info *info = cdev->priv;
@ -162,6 +165,8 @@ static ssize_t nand_erase(struct cdev *cdev, size_t count, unsigned long offset)
return 0;
}
#endif
#if 0
static char* mtd_get_size(struct device_d *, struct param_d *param)
{
@ -171,10 +176,12 @@ static char* mtd_get_size(struct device_d *, struct param_d *param)
static struct file_operations nand_ops = {
.read = nand_read,
#ifdef CONFIG_NAND_WRITE
.write = nand_write,
.erase = nand_erase,
#endif
.ioctl = nand_ioctl,
.lseek = dev_lseek_default,
.erase = nand_erase,
};
static ssize_t nand_read_oob(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong flags)

View File

@ -1,8 +1,6 @@
#ifndef __NAND_H
#define __NAND_H
#define CONFIG_NAND_WRITE
int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip,
int page, int sndcmd);
int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip,

View File

@ -1018,10 +1018,12 @@ static void nand_set_defaults(struct nand_chip *chip, int busw)
chip->read_word = nand_read_word;
if (!chip->block_bad)
chip->block_bad = nand_block_bad;
#ifdef CONFIG_NAND_WRITE
if (!chip->block_markbad)
chip->block_markbad = nand_default_block_markbad;
if (!chip->write_buf)
chip->write_buf = busw ? nand_write_buf16 : nand_write_buf;
#endif
if (!chip->read_buf)
chip->read_buf = busw ? nand_read_buf16 : nand_read_buf;
if (!chip->verify_buf)
@ -1175,12 +1177,13 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
if (*maf_id != NAND_MFR_SAMSUNG && !type->pagesize)
chip->options &= ~NAND_SAMSUNG_LP_OPTIONS;
#ifdef CONFIG_NAND_WRITE
/* Check for AND chips with 4 page planes */
if (chip->options & NAND_4PAGE_ARRAY)
chip->erase_cmd = multi_erase_cmd;
else
chip->erase_cmd = single_erase_cmd;
#endif
/* Do not replace user supplied command function ! */
if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
chip->cmdfunc = nand_command_lp;
@ -1303,8 +1306,10 @@ int nand_scan_tail(struct mtd_info *mtd)
}
}
#ifdef CONFIG_NAND_WRITE
if (!chip->write_page)
chip->write_page = nand_write_page;
#endif
/*
* check ECC mode, default to software if 3byte/512byte hardware ECC is
@ -1312,9 +1317,10 @@ int nand_scan_tail(struct mtd_info *mtd)
*/
if (!chip->ecc.read_page_raw)
chip->ecc.read_page_raw = nand_read_page_raw;
#ifdef CONFIG_NAND_WRITE
if (!chip->ecc.write_page_raw)
chip->ecc.write_page_raw = nand_write_page_raw;
#endif
switch (chip->ecc.mode) {
case NAND_ECC_HW:
nand_check_hwecc(mtd, chip);
@ -1334,9 +1340,11 @@ int nand_scan_tail(struct mtd_info *mtd)
printk(KERN_WARNING "NAND_ECC_NONE selected by board driver. "
"This is not recommended !!\n");
chip->ecc.read_page = nand_read_page_raw;
#ifdef CONFIG_NAND_WRITE
chip->ecc.write_page = nand_write_page_raw;
chip->ecc.read_oob = nand_read_oob_std;
chip->ecc.write_oob = nand_write_oob_std;
#endif
chip->ecc.read_oob = nand_read_oob_std;
chip->ecc.size = mtd->writesize;
chip->ecc.bytes = 0;
break;
@ -1398,11 +1406,13 @@ int nand_scan_tail(struct mtd_info *mtd)
/* Fill in remaining MTD driver data */
mtd->type = MTD_NANDFLASH;
mtd->flags = MTD_CAP_NANDFLASH;
#ifdef CONFIG_NAND_WRITE
mtd->erase = nand_erase;
mtd->read = nand_read;
mtd->write = nand_write;
mtd->read_oob = nand_read_oob;
mtd->write_oob = nand_write_oob;
#endif
mtd->read = nand_read;
mtd->read_oob = nand_read_oob;
mtd->lock = NULL;
mtd->unlock = NULL;
mtd->block_isbad = nand_block_isbad;

View File

@ -557,6 +557,7 @@ static int search_read_bbts(struct mtd_info *mtd, uint8_t * buf, struct nand_bbt
* (Re)write the bad block table
*
*/
#ifdef CONFIG_NAND_WRITE
static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
struct nand_bbt_descr *td, struct nand_bbt_descr *md,
int chipsel)
@ -745,6 +746,14 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
"nand_bbt: Error while writing bad block table %d\n", res);
return res;
}
#else
static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
struct nand_bbt_descr *td, struct nand_bbt_descr *md,
int chipsel)
{
return 0;
}
#endif
/**
* nand_memory_bbt - [GENERIC] create a memory based bad block table