aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/onenand
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@cruncher.tec.linutronix.de>2006-05-28 21:26:58 -0400
committerThomas Gleixner <tglx@cruncher.tec.linutronix.de>2006-05-29 09:06:51 -0400
commit8593fbc68b0df1168995de76d1af38eb62fd6b62 (patch)
treedd244def53d2be4f1fbff9f74eac404fab8e240f /drivers/mtd/onenand
parentf4a43cfcecfcaeeaa40a9dbc1d1378298c22446e (diff)
[MTD] Rework the out of band handling completely
Hopefully the last iteration on this! The handling of out of band data on NAND was accompanied by tons of fruitless discussions and halfarsed patches to make it work for a particular problem. Sufficiently annoyed by I all those "I know it better" mails and the resonable amount of discarded "it solves my problem" patches, I finally decided to go for the big rework. After removing the _ecc variants of mtd read/write functions the solution to satisfy the various requirements was to refactor the read/write _oob functions in mtd. The major change is that read/write_oob now takes a pointer to an operation descriptor structure "struct mtd_oob_ops".instead of having a function with at least seven arguments. read/write_oob which should probably renamed to a more descriptive name, can do the following tasks: - read/write out of band data - read/write data content and out of band data - read/write raw data content and out of band data (ecc disabled) struct mtd_oob_ops has a mode field, which determines the oob handling mode. Aside of the MTD_OOB_RAW mode, which is intended to be especially for diagnostic purposes and some internal functions e.g. bad block table creation, the other two modes are for mtd clients: MTD_OOB_PLACE puts/gets the given oob data exactly to/from the place which is described by the ooboffs and ooblen fields of the mtd_oob_ops strcuture. It's up to the caller to make sure that the byte positions are not used by the ECC placement algorithms. MTD_OOB_AUTO puts/gets the given oob data automaticaly to/from the places in the out of band area which are described by the oobfree tuples in the ecclayout data structre which is associated to the devicee. The decision whether data plus oob or oob only handling is done depends on the setting of the datbuf member of the data structure. When datbuf == NULL then the internal read/write_oob functions are selected, otherwise the read/write data routines are invoked. Tested on a few platforms with all variants. Please be aware of possible regressions for your particular device / application scenario Disclaimer: Any whining will be ignored from those who just contributed "hot air blurb" and never sat down to tackle the underlying problem of the mess in the NAND driver grown over time and the big chunk of work to fix up the existing users. The problem was not the holiness of the existing MTD interfaces. The problems was the lack of time to go for the big overhaul. It's easy to add more mess to the existing one, but it takes alot of effort to go for a real solution. Improvements and bugfixes are welcome! Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'drivers/mtd/onenand')
-rw-r--r--drivers/mtd/onenand/onenand_base.c46
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c7
2 files changed, 43 insertions, 10 deletions
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index a0d3f011c0f2..84ec40d25438 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -671,7 +671,7 @@ out:
671} 671}
672 672
673/** 673/**
674 * onenand_read_oob - [MTD Interface] OneNAND read out-of-band 674 * onenand_do_read_oob - [MTD Interface] OneNAND read out-of-band
675 * @param mtd MTD device structure 675 * @param mtd MTD device structure
676 * @param from offset to read from 676 * @param from offset to read from
677 * @param len number of bytes to read 677 * @param len number of bytes to read
@@ -680,8 +680,8 @@ out:
680 * 680 *
681 * OneNAND read out-of-band data from the spare area 681 * OneNAND read out-of-band data from the spare area
682 */ 682 */
683static int onenand_read_oob(struct mtd_info *mtd, loff_t from, size_t len, 683int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
684 size_t *retlen, u_char *buf) 684 size_t *retlen, u_char *buf)
685{ 685{
686 struct onenand_chip *this = mtd->priv; 686 struct onenand_chip *this = mtd->priv;
687 int read = 0, thislen, column; 687 int read = 0, thislen, column;
@@ -744,6 +744,21 @@ out:
744 return ret; 744 return ret;
745} 745}
746 746
747/**
748 * onenand_read_oob - [MTD Interface] NAND write data and/or out-of-band
749 * @mtd: MTD device structure
750 * @from: offset to read from
751 * @ops: oob operation description structure
752 */
753static int onenand_read_oob(struct mtd_info *mtd, loff_t from,
754 struct mtd_oob_ops *ops)
755{
756 BUG_ON(ops->mode != MTD_OOB_PLACE);
757
758 return onenand_do_read_oob(mtd, from + ops->ooboffs, ops->len,
759 &ops->retlen, ops->oobbuf);
760}
761
747#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE 762#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
748/** 763/**
749 * onenand_verify_oob - [GENERIC] verify the oob contents after a write 764 * onenand_verify_oob - [GENERIC] verify the oob contents after a write
@@ -894,7 +909,7 @@ out:
894} 909}
895 910
896/** 911/**
897 * onenand_write_oob - [MTD Interface] OneNAND write out-of-band 912 * onenand_do_write_oob - [Internal] OneNAND write out-of-band
898 * @param mtd MTD device structure 913 * @param mtd MTD device structure
899 * @param to offset to write to 914 * @param to offset to write to
900 * @param len number of bytes to write 915 * @param len number of bytes to write
@@ -903,8 +918,8 @@ out:
903 * 918 *
904 * OneNAND write out-of-band 919 * OneNAND write out-of-band
905 */ 920 */
906static int onenand_write_oob(struct mtd_info *mtd, loff_t to, size_t len, 921static int onenand_do_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
907 size_t *retlen, const u_char *buf) 922 size_t *retlen, const u_char *buf)
908{ 923{
909 struct onenand_chip *this = mtd->priv; 924 struct onenand_chip *this = mtd->priv;
910 int column, ret = 0; 925 int column, ret = 0;
@@ -973,6 +988,21 @@ out:
973} 988}
974 989
975/** 990/**
991 * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band
992 * @mtd: MTD device structure
993 * @from: offset to read from
994 * @ops: oob operation description structure
995 */
996static int onenand_write_oob(struct mtd_info *mtd, loff_t to,
997 struct mtd_oob_ops *ops)
998{
999 BUG_ON(ops->mode != MTD_OOB_PLACE);
1000
1001 return onenand_do_write_oob(mtd, to + ops->ooboffs, ops->len,
1002 &ops->retlen, ops->oobbuf);
1003}
1004
1005/**
976 * onenand_block_checkbad - [GENERIC] Check if a block is marked bad 1006 * onenand_block_checkbad - [GENERIC] Check if a block is marked bad
977 * @param mtd MTD device structure 1007 * @param mtd MTD device structure
978 * @param ofs offset from device start 1008 * @param ofs offset from device start
@@ -1138,7 +1168,7 @@ static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs)
1138 1168
1139 /* We write two bytes, so we dont have to mess with 16 bit access */ 1169 /* We write two bytes, so we dont have to mess with 16 bit access */
1140 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01); 1170 ofs += mtd->oobsize + (bbm->badblockpos & ~0x01);
1141 return mtd->write_oob(mtd, ofs , 2, &retlen, buf); 1171 return onenand_do_write_oob(mtd, ofs , 2, &retlen, buf);
1142} 1172}
1143 1173
1144/** 1174/**
@@ -1328,7 +1358,7 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len,
1328 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); 1358 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0);
1329 this->wait(mtd, FL_OTPING); 1359 this->wait(mtd, FL_OTPING);
1330 1360
1331 ret = mtd->write_oob(mtd, from, len, retlen, buf); 1361 ret = onenand_do_write_oob(mtd, from, len, retlen, buf);
1332 1362
1333 /* Exit OTP access mode */ 1363 /* Exit OTP access mode */
1334 this->command(mtd, ONENAND_CMD_RESET, 0, 0); 1364 this->command(mtd, ONENAND_CMD_RESET, 0, 0);
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index aafd7c2f7802..1b00dac3d7d6 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -17,6 +17,9 @@
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19 19
20extern int onenand_do_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
21 size_t *retlen, u_char *buf);
22
20/** 23/**
21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
22 * @param buf the buffer to search 25 * @param buf the buffer to search
@@ -87,8 +90,8 @@ static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
87 90
88 /* No need to read pages fully, 91 /* No need to read pages fully,
89 * just read required OOB bytes */ 92 * just read required OOB bytes */
90 ret = mtd->read_oob(mtd, from + j * mtd->writesize + bd->offs, 93 ret = onenand_do_read_oob(mtd, from + j * mtd->writesize + bd->offs,
91 readlen, &retlen, &buf[0]); 94 readlen, &retlen, &buf[0]);
92 95
93 if (ret) 96 if (ret)
94 return ret; 97 return ret;