From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v7 1/5] mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform
Date: Fri, 4 Oct 2013 17:30:01 -0500 [thread overview]
Message-ID: <1380925801.7979.51.camel@snotra.buserror.net> (raw)
In-Reply-To: <1380550418-17327-2-git-send-email-pekon@ti.com>
On Mon, 2013-09-30 at 19:43 +0530, Pekon Gupta wrote:
> +Platform specific options
> +=========================
> +
> + CONFIG_NAND_OMAP_ECCSCHEME
> + On OMAP platforms, this specifies NAND ECC scheme.
> + 1 - HAM1_SW 1-bit Hamming code using software library
> + (for legacy devices only)
> + 2 - HAM1_HW 1-bit Hamming code using GPMC hardware engine
> + (for legacy devices only)
> + 3 - BCH4_SW 4-bit BCH code (unsupported)
> + 4 - BCH4_HW 4-bit BCH code (unsupported)
> + 5 - BCH8_SW 8-bit BCH code with
> + - ecc calculation using GPMC hardware engine,
> + - error detection using software library.
> + - requires CONFIG_BCH to enable software BCH library
> + (For legacy device which do not have ELM h/w engine)
> + 6 - BCH8_HW 8-bit BCH code with
> + - ecc calculation using GPMC hardware engine,
> + - error detection using ELM hardware engine.
You should document the symbols, not the numbers that happen to be
assigned to them.
> +/**
> + * omap_select_ecc_scheme - configures driver for particular ecc-scheme
> + * @nand: NAND chip device structure
> + * @ecc_scheme: ecc scheme to configure
> + * @pagesize: number of main-area bytes per page of NAND device
> + * @oobsize: number of OOB/spare bytes per page of NAND device
> + */
> +static int omap_select_ecc_scheme(struct nand_chip *nand, int ecc_scheme,
> + unsigned int pagesize, unsigned int oobsize) {
s/int ecc_scheme/enum omap_ecc ecc_scheme/
> + struct nand_bch_priv *bch = nand->priv;
> + struct nand_ecclayout *ecclayout = nand->ecc.layout;
> + int i;
> +
> + switch (ecc_scheme) {
> + case OMAP_ECC_HAM1_CODE_SW:
> + debug("nand: selected OMAP_ECC_HAM1_CODE_SW\n");
> + nand->ecc.mode = NAND_ECC_SOFT;
> + nand->ecc.layout = NULL;
> + nand->ecc.size = 0;
> + nand->ecc.strength = 1;
> + bch->ecc_scheme = OMAP_ECC_HAM1_CODE_SW;
> + break;
> + case OMAP_ECC_HAM1_CODE_HW:
> + debug("nand: selected OMAP_ECC_HAM1_CODE_HW\n");
> + nand->ecc.mode = NAND_ECC_HW;
> + nand->ecc.strength = 1;
> + nand->ecc.size = 512;
> + nand->ecc.bytes = 3;
> + nand->ecc.hwctl = omap_enable_hwecc;
> + nand->ecc.correct = omap_correct_data;
> + nand->ecc.calculate = omap_calculate_ecc;
> + /* define ecc-layout */
> + ecclayout->eccbytes = nand->ecc.bytes *
> + (pagesize / SECTOR_BYTES);
> + for (i = 0; i < ecclayout->eccbytes; i++)
> + ecclayout->eccpos[i] = i + BADBLOCK_MARKER_LENGTH;
> + ecclayout->oobfree[0].offset = i + BADBLOCK_MARKER_LENGTH;
> + ecclayout->oobfree[0].length = oobsize - ecclayout->eccbytes -
> + BADBLOCK_MARKER_LENGTH;
> + bch->ecc_scheme = OMAP_ECC_HAM1_CODE_HW;
> + break;
> +#ifdef CONFIG_BCH
> + case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
> + debug("nand: selected OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
> + nand->ecc.mode = NAND_ECC_HW;
> + nand->ecc.strength = 8;
> + nand->ecc.size = 512;
> + nand->ecc.bytes = 13;
> + nand->ecc.hwctl = omap_enable_ecc_bch;
> + nand->ecc.correct = omap_correct_data_bch_sw;
> + nand->ecc.calculate = omap_calculate_ecc_bch_sw;
> + /* BCH SW library is used for error detection */
> + bch_priv.control = init_bch(13, 8, 0x201b);
> + if (!bch_priv.control) {
> + printf("nand: error: could not init_bch()\n");
> + return -ENODEV;
> + }
> + bch_priv.type = ECC_BCH8;
> + /* define ecc-layout */
> + ecclayout->eccbytes = nand->ecc.bytes *
> + (pagesize / SECTOR_BYTES);
> + for (i = 0; i < ecclayout->eccbytes; i++)
> + ecclayout->eccpos[i] = i + (oobsize -
> + ecclayout->eccbytes);
> + ecclayout->oobfree[0].offset = BADBLOCK_MARKER_LENGTH;
> + ecclayout->oobfree[0].length = oobsize - ecclayout->eccbytes -
> + BADBLOCK_MARKER_LENGTH;
> + omap_hwecc_init_bch(nand, NAND_ECC_READ);
> + bch->ecc_scheme = OMAP_ECC_BCH8_CODE_HW_DETECTION_SW;
> + break;
> +#endif
> + case OMAP_ECC_BCH8_CODE_HW:
> + debug("nand: selected OMAP_ECC_BCH8_CODE_HW\n");
> + nand->ecc.mode = NAND_ECC_HW;
> + nand->ecc.strength = 8;
> + nand->ecc.size = 512;
> + nand->ecc.bytes = 14;
> + nand->ecc.hwctl = omap_enable_ecc_bch;
> + nand->ecc.correct = omap_correct_data_bch;
> + nand->ecc.calculate = omap_calculate_ecc_bch;
> + nand->ecc.read_page = omap_read_page_bch;
> + /* ELM is used for ECC error detection */
> + elm_init();
> + bch_priv.type = ECC_BCH8;
> + /* define ecc-layout */
> + ecclayout->eccbytes = nand->ecc.bytes *
> + (pagesize / SECTOR_BYTES);
> + for (i = 0; i < ecclayout->eccbytes; i++)
> + ecclayout->eccpos[i] = i + BADBLOCK_MARKER_LENGTH;
> + ecclayout->oobfree[0].offset = i + BADBLOCK_MARKER_LENGTH;
> + ecclayout->oobfree[0].length = oobsize - ecclayout->eccbytes -
> + BADBLOCK_MARKER_LENGTH;
> + bch->ecc_scheme = OMAP_ECC_BCH8_CODE_HW;
> + break;
> + default:
> + debug("nand: error: ecc scheme not enabled or supported\n");
> + return -EINVAL;
> + }
> +
> + /* check if NAND spare/OOB has enough bytes to accomodate ecclayout */
> + if ((ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH) > oobsize) {
> + printf("nand: error: insufficient OOB bytes. require=%d\n", (
> + ecclayout->eccbytes + BADBLOCK_MARKER_LENGTH));
> + return -EINVAL;
> + }
Check this before you make any changes to the current ECC setup.
> + err = omap_select_ecc_scheme(nand, OMAP_ECC_HAM1_CODE_SW,
> + mtd->writesize, mtd->oobsize);
> + }
> + if (err) {
> + printf("nand: error: could not switch ecc, reverting\n");
> + omap_select_ecc_scheme(nand, bch->ecc_scheme,
> + mtd->writesize, mtd->oobsize);
> + return -EINVAL;
> }
You won't need to "revert" here if omap_select_ecc_scheme doesn't damage
anything in error cases.
-Scott
next prev parent reply other threads:[~2013-10-04 22:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-30 14:13 [U-Boot] [PATCH v7 0/5] mtd: nand: omap: optimize and clean-up of OMAP NAND driver Pekon Gupta
2013-09-30 14:13 ` [U-Boot] [PATCH v7 1/5] mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform Pekon Gupta
2013-09-30 15:11 ` Stefan Roese
2013-10-04 22:30 ` Scott Wood [this message]
2013-10-05 6:11 ` Gupta, Pekon
2013-10-08 1:06 ` Scott Wood
2013-10-08 1:59 ` Tom Rini
2013-10-08 5:30 ` Gupta, Pekon
2013-10-08 16:52 ` Scott Wood
2013-10-08 17:38 ` Scott Wood
2013-10-08 19:06 ` Gupta, Pekon
2013-09-30 14:13 ` [U-Boot] [PATCH v7 2/5] mtd: nand: omap: optimize chip->ecc.hwctl() for H/W ECC schemes Pekon Gupta
2013-09-30 14:13 ` [U-Boot] [PATCH v7 3/5] mtd: nand: omap: optimize chip->ecc.calculate() " Pekon Gupta
2013-10-08 17:28 ` Scott Wood
2013-09-30 14:13 ` [U-Boot] [PATCH v7 4/5] mtd: nand: omap: optimized chip->ecc.correct() " Pekon Gupta
2013-10-08 17:35 ` Scott Wood
2013-09-30 14:13 ` [U-Boot] [PATCH v7 5/5] board/ti/am335x/README: update for NAND boot Pekon Gupta
2013-10-04 20:19 ` [U-Boot] [PATCH v7 0/5] mtd: nand: omap: optimize and clean-up of OMAP NAND driver Gupta, Pekon
2013-10-17 17:24 ` Tom Rini
-- strict thread matches above, loose matches on Subject: below --
2013-09-30 17:53 [U-Boot] [PATCH v7 1/5] mtd: nand: omap: enable BCH ECC scheme using ELM for generic platform Gupta, Pekon
2013-09-30 18:31 ` Gupta, Pekon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1380925801.7979.51.camel@snotra.buserror.net \
--to=scottwood@freescale.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox