From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 2/8] lpc32xx: mtd: nand: add MLC NAND controller
Date: Mon, 9 Mar 2015 18:51:03 -0500 [thread overview]
Message-ID: <1425945063.4698.196.camel@freescale.com> (raw)
In-Reply-To: <1425538018-10154-3-git-send-email-albert.aribaud@3adev.fr>
On Thu, 2015-03-05 at 07:46 +0100, Albert ARIBAUD (3ADEV) wrote:
> diff --git a/drivers/mtd/nand/lpc32xx_nand_mlc.c b/drivers/mtd/nand/lpc32xx_nand_mlc.c
> new file mode 100644
> index 0000000..cb23972
> --- /dev/null
> +++ b/drivers/mtd/nand/lpc32xx_nand_mlc.c
> @@ -0,0 +1,589 @@
> +/*
> + * LPC32xx MLC NAND flash controller driver
> + *
> + * (C) Copyright 2014 3ADEV <http://3adev.com>
> + * Written by Albert ARIBAUD <albert.aribaud@3adev.fr>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + *
> + * NOTE:
> + *
> + * The MLC NAND flash controller provides hardware Reed-Solomon ECC
> + * covering in- and out-of-band data together. Therefore, in- and out-
> + * of-band data must be written together in order to have a valid ECC.
> + *
> + * Consequently, pages with meaningful in-band data are written with
> + * blank (all-ones) out-of-band data and a valid ECC, and any later
> + * out-of-band data write will void the ECC.
> + *
> + * Therefore, code which reads such late-written out-of-band data
> + * should not rely on the ECC validity.
> + */
When are you expecting later out-of-band writes?
> +static struct lpc32xx_nand_mlc_registers *lpc32xx_nand_mlc_registers
> + = (struct lpc32xx_nand_mlc_registers *)MLC_NAND_BASE;
__iomem
> + unsigned int ctrl)
> +{
> + if (cmd == NAND_CMD_NONE)
> + return;
> +
> + if (ctrl & NAND_CLE)
> + writeb(cmd & 0Xff, &lpc32xx_nand_mlc_registers->cmd);
> + else if (ctrl & NAND_ALE)
> + writeb(cmd & 0Xff, &lpc32xx_nand_mlc_registers->addr);
> + else
> + return;
> +}
That last return is superfluous.
> +/**
> + * ECC layout -- this is needed whatever ECC mode we are using.
> + * In a 2KB (4*512B) page, R/S codes occupy 40 (4*10) bytes.
> + * To make U-Boot's life easier, we pack 'useable' OOB at the
> + * front and R/S ECC at the back.
> + */
> +
> +static struct nand_ecclayout lpc32xx_largepage_ecclayout = {
> + .eccbytes = 40,
> + .eccpos = {24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
> + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
> + 44, 45, 46, 47, 48, 48, 50, 51, 52, 53,
> + 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
> + },
> + .oobfree = {
> + {
> + .offset = 0,
> + .length = 24
> + },
> + }
> +};
Is offset zero really free? Where does the bad block marker go?
> + for (i = 0; i < 4; i++) {
> + /* start data input */
> + oob[6*i] = ((0xfe << i) & 0xff);
> + oob[6*i+5] = ((0x7f >> i) & 0xff);
> + chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x200+0x210*i, page);
> + /* copy 6 non-ECC out-of-band bytes directly into NAND */
> + memcpy(lpc32xx_nand_mlc_registers->data, oob+6*i, 6);
Lots of magic numbers...
> + /* wait for NAND to return to ready state */
> + while (!(readl(&lpc32xx_nand_mlc_registers->isr)
> + & ISR_NAND_READY))
> + ;
Timeout?
> + }
> + return 0;
> +}
> +
> +/**
> + * lpc32xx_waitfunc - wait until a command is done
> + * @mtd: MTD device structure
> + * @chip: NAND chip structure
> + *
> + * Wait for controller and FLASH to both be ready.
> + */
> +
> +static int lpc32xx_waitfunc(struct mtd_info *mtd, struct nand_chip *chip)
> +{
> + /* FIXME: put a time-out here */
> + int status;
> + /* wait until both controller and NAND are ready */
> + do {
> + status = readl(&lpc32xx_nand_mlc_registers->isr);
> + } while ((status & (ISR_CONTROLLER_READY || ISR_NAND_READY))
> + != (ISR_CONTROLLER_READY || ISR_NAND_READY));
Timeout? Etc.
> +/*
> + * Initialize the controller
> + */
> +
> +int board_nand_init(struct nand_chip *nand)
> +{
It'd be nice if new NAND drivers used CONFIG_SYS_NAND_SELF_INIT.
> +
> + /* BBT options: read from last two pages, don't write */
> + nand->bbt_options |= NAND_BBT_USE_FLASH | NAND_BBT_LASTBLOCK
> + | NAND_BBT_SCANLASTPAGE | NAND_BBT_SCAN2NDPAGE
> + | NAND_BBT_WRITE;
Don't write?
> +#define LARGE_PAGE_SIZE 2048
> +
> +int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
> +{
> + unsigned int page = offs / LARGE_PAGE_SIZE;
> + unsigned int left = (size + LARGE_PAGE_SIZE - 1) / LARGE_PAGE_SIZE;
DIV_ROUND_UP()
> + while (left) {
> + if (read_single_page(dst, page) >= 0) {
> + dst += LARGE_PAGE_SIZE;
> + page++;
> + left--;
> + }
> + }
No bad block skipping?
-Scott
next prev parent reply other threads:[~2015-03-09 23:51 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-05 6:46 [U-Boot] [PATCH v3 0/8] Extend LPC32xx functionality and add LPC32xx-based work_92015 board Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 1/8] lpc32xx: add Ethernet support Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 2/8] lpc32xx: mtd: nand: add MLC NAND controller Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 3/8] lpc32xx: i2c: add LPC32xx I2C interface support Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 4/8] lpc32xx: add GPIO support Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 5/8] lpc32xx: add LPC32xx SSP support (SPI mode) Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 6/8] dtt: add ds620 support Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 7/8] lpc32xx: add lpc32xx-spl.bin boot image target Albert ARIBAUD
2015-03-05 6:46 ` [U-Boot] [PATCH v3 8/8] lpc32xx: add support for board work_92105 Albert ARIBAUD
2015-03-09 23:51 ` Scott Wood [this message]
2015-03-10 12:54 ` [U-Boot] [PATCH v3 2/8] lpc32xx: mtd: nand: add MLC NAND controller Albert ARIBAUD
2015-03-10 18:49 ` Scott Wood
2015-03-10 20:33 ` Albert ARIBAUD
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=1425945063.4698.196.camel@freescale.com \
--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