Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1286046
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 17/23] mtd: nand: implement the default mtd_ooblayout_ops |
| Date | 2015-12-07 23:40 +0100 |
| Message-ID | <qDcBQ-2jb-13@gated-at.bofh.it> (permalink) |
| References | <qDcs9-2fH-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
Replace the default nand_ecclayout definitions for large and small page
devices with the equivalent mtd_ooblayout_ops.
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
drivers/mtd/nand/nand_base.c | 138 +++++++++++++++++++++++++++----------------
include/linux/mtd/nand.h | 3 +
2 files changed, 90 insertions(+), 51 deletions(-)
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 2b334cf..6440c5d 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -48,50 +48,6 @@
#include <linux/mtd/partitions.h>
#include <linux/of_mtd.h>
-/* Define default oob placement schemes for large and small page devices */
-static struct nand_ecclayout nand_oob_8 = {
- .eccbytes = 3,
- .eccpos = {0, 1, 2},
- .oobfree = {
- {.offset = 3,
- .length = 2},
- {.offset = 6,
- .length = 2} }
-};
-
-static struct nand_ecclayout nand_oob_16 = {
- .eccbytes = 6,
- .eccpos = {0, 1, 2, 3, 6, 7},
- .oobfree = {
- {.offset = 8,
- . length = 8} }
-};
-
-static struct nand_ecclayout nand_oob_64 = {
- .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 = {
- {.offset = 2,
- .length = 38} }
-};
-
-static struct nand_ecclayout nand_oob_128 = {
- .eccbytes = 48,
- .eccpos = {
- 80, 81, 82, 83, 84, 85, 86, 87,
- 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103,
- 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127},
- .oobfree = {
- {.offset = 2,
- .length = 78} }
-};
-
static int nand_get_device(struct mtd_info *mtd, int new_state);
static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
@@ -103,6 +59,83 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
*/
DEFINE_LED_TRIGGER(nand_led_trigger);
+/* Define default oob placement schemes for large and small page devices */
+static int nand_ooblayout_eccpos_sp(struct mtd_info *mtd, int eccbyte)
+{
+ struct nand_chip *chip = mtd->priv;
+ struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+ if (eccbyte >= ecc->bytes * ecc->steps)
+ return -ERANGE;
+
+ if (eccbyte < 4)
+ return eccbyte;
+
+ return eccbyte + 2;
+}
+
+static int nand_ooblayout_oobfree_sp(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+ if (section > 1)
+ return -ERANGE;
+
+ if (mtd->oobsize == 16) {
+ if (section)
+ return -ERANGE;
+
+ oobfree->length = 8;
+ oobfree->offset = 8;
+ } else {
+ oobfree->length = 2;
+ if (!section)
+ oobfree->offset = 3;
+ else
+ oobfree->offset = 6;
+ }
+
+ return 0;
+}
+
+const struct mtd_ooblayout_ops nand_ooblayout_sp_ops = {
+ .eccpos = nand_ooblayout_eccpos_sp,
+ .oobfree = nand_ooblayout_oobfree_sp,
+};
+EXPORT_SYMBOL_GPL(nand_ooblayout_sp_ops);
+
+static int nand_ooblayout_eccpos_lp(struct mtd_info *mtd, int eccbyte)
+{
+ struct nand_chip *chip = mtd->priv;
+ struct nand_ecc_ctrl *ecc = &chip->ecc;
+ int eccbytes = ecc->bytes * ecc->steps;
+
+ if (eccbyte >= eccbytes)
+ return -ERANGE;
+
+ return mtd->oobsize - eccbytes + eccbyte;
+}
+
+static int nand_ooblayout_oobfree_lp(struct mtd_info *mtd, int section,
+ struct nand_oobfree *oobfree)
+{
+ struct nand_chip *chip = mtd->priv;
+ struct nand_ecc_ctrl *ecc = &chip->ecc;
+
+ if (section)
+ return -ERANGE;
+
+ oobfree->length = mtd->oobsize - (ecc->bytes * ecc->steps) - 2;
+ oobfree->offset = 2;
+
+ return 0;
+}
+
+const struct mtd_ooblayout_ops nand_ooblayout_lp_ops = {
+ .eccpos = nand_ooblayout_eccpos_lp,
+ .oobfree = nand_ooblayout_oobfree_lp,
+};
+EXPORT_SYMBOL_GPL(nand_ooblayout_lp_ops);
+
static int check_offs_len(struct mtd_info *mtd,
loff_t ofs, uint64_t len)
{
@@ -4115,21 +4148,24 @@ int nand_scan_tail(struct mtd_info *mtd)
chip->oob_poi = chip->buffers->databuf + mtd->writesize;
/*
+ * Set the provided ECC layout. If ecc->layout is NULL, the MTD core
+ * will just leave mtd->ooblayout to NULL, if it's not NULL, it will
+ * set ->ooblayout to the default ecclayout wrapper.
+ */
+ mtd_set_ecclayout(mtd, ecc->layout);
+
+ /*
* If no default placement scheme is given, select an appropriate one.
*/
- if (!ecc->layout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
+ if (!mtd->ooblayout && (ecc->mode != NAND_ECC_SOFT_BCH)) {
switch (mtd->oobsize) {
case 8:
- ecc->layout = &nand_oob_8;
- break;
case 16:
- ecc->layout = &nand_oob_16;
+ mtd_set_ooblayout(mtd, &nand_ooblayout_sp_ops);
break;
case 64:
- ecc->layout = &nand_oob_64;
- break;
case 128:
- ecc->layout = &nand_oob_128;
+ mtd_set_ooblayout(mtd, &nand_ooblayout_lp_ops);
break;
default:
pr_warn("No oob scheme defined for oobsize %d\n",
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index cbedcb0..9ba9daba 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -719,6 +719,9 @@ struct nand_chip {
void *priv;
};
+extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops;
+extern const struct mtd_ooblayout_ops nand_ooblayout_lp_ops;
+
static inline void nand_set_flash_node(struct nand_chip *chip,
struct device_node *np)
{
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/23] mtd: rework ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 15/23] mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 21/23] staging: mt29f_spinand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
Re: [linux-sunxi] [PATCH 21/23] staging: mt29f_spinand: switch to mtd_ooblayout_ops Julian Calaby <julian.calaby@gmail.com> - 2015-12-08 01:10 +0100
Re: [linux-sunxi] [PATCH 21/23] staging: mt29f_spinand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-08 09:50 +0100
[PATCH 03/23] mtd: nftl: kill unused oobinfo field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 20/23] mtd: onenand: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 01/23] mtd: kill the ecclayout->oobavail field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
Re: [linux-sunxi] [PATCH 01/23] mtd: kill the ecclayout->oobavail field Priit Laes <plaes@plaes.org> - 2015-12-08 07:50 +0100
Re: [linux-sunxi] [PATCH 01/23] mtd: kill the ecclayout->oobavail field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-08 09:20 +0100
[PATCH 23/23] mtd: kill the nand_ecclayout struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 12/23] mtd: use mtd_eccpos() and mtd_oobfree() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
Re: [PATCH 12/23] mtd: use mtd_eccpos() and mtd_oobfree() where appropriate kbuild test robot <lkp@intel.com> - 2015-12-08 00:40 +0100
[PATCH 11/23] mtd: add mtd_eccpos(), mtd_oobfree() and mtd_eccbytes() helper functions Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 22/23] mtd: nand: kill layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 18/23] mtd: nand: bch: switch to nand_ecclayout_pos Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 07/23] staging: mt29f_spinand: kill unused ecclayout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
[PATCH 09/23] mtd: nand: vf610: remove useless mtd->ecclayout assignment Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:30 +0100
Re: [PATCH 09/23] mtd: nand: vf610: remove useless mtd->ecclayout assignment Stefan Agner <stefan@agner.ch> - 2015-12-07 23:50 +0100
[PATCH 10/23] mtd: nand: simplify nand_bch_init() usage Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 17/23] mtd: nand: implement the default mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 06/23] mtd: nand: kill unused ->ecclayout field in platform_nand_chip struct Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 08/23] mtd: nand: lpc32xx_mlc: fix ecc.size Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 05/23] mtd: nand: jz4770: kill the ->ecc_layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
Re: [PATCH 05/23] mtd: nand: jz4770: kill the ->ecc_layout field Harvey Hunt <harvey.hunt@imgtec.com> - 2015-12-08 11:40 +0100
Re: [PATCH 05/23] mtd: nand: jz4770: kill the ->ecc_layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-08 11:40 +0100
[PATCH 04/23] mtd: nand: s3c2410: kill the ->ecc_layout field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
Re: [PATCH 04/23] mtd: nand: s3c2410: kill the ->ecc_layout field Krzysztof Kozlowski <k.kozlowski@samsung.com> - 2015-12-08 01:40 +0100
[PATCH 13/23] mtd: add mtd_set_ecclayout() helper function Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 02/23] mtd: inftl: kill unused oobinfo field Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 16/23] mtd: docg3: switch to mtd_ooblayout_ops Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
[PATCH 14/23] mtd: use mtd_set_ecclayout() where appropriate Boris Brezillon <boris.brezillon@free-electrons.com> - 2015-12-07 23:40 +0100
Re: [PATCH 19/23] mtd: nand: switch all drivers to mtd_ooblayout_ops Ralf Baechle <ralf@linux-mips.org> - 2015-12-08 11:20 +0100
csiph-web