public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 4/7] jz4740 nand driver
Date: Mon, 7 Mar 2011 17:44:36 -0600	[thread overview]
Message-ID: <20110307174436.6b4c8b21@schlenkerla> (raw)
In-Reply-To: <1298876234-28115-5-git-send-email-xiangfu@openmobilefree.net>

On Mon, 28 Feb 2011 14:57:11 +0800
Xiangfu Liu <xiangfu@openmobilefree.net> wrote:

> +static int jz_nand_rs_correct_data(struct mtd_info *mtd, u_char *dat,
> +				   u_char *read_ecc, u_char *calc_ecc)
> +{
> +	int k;
> +	uint32_t errcnt, index, mask, status;
> +	volatile u8 *paraddr = (volatile u8 *) &emc->nfpar[0];
> +
> +	/* Set PAR values */
> +	static uint8_t all_ff_ecc[] = 
> +		{0xcd, 0x9d, 0x90, 0x58, 0xf4, 0x8b, 0xff, 0xb7, 0x6f};

const?

> +
> +	if (read_ecc[0] == 0xff && read_ecc[1] == 0xff &&
> +	    read_ecc[2] == 0xff && read_ecc[3] == 0xff &&
> +	    read_ecc[4] == 0xff && read_ecc[5] == 0xff &&
> +	    read_ecc[6] == 0xff && read_ecc[7] == 0xff &&
> +	    read_ecc[8] == 0xff) {
> +		for (k = 0; k < 9; k++)
> +			writeb(all_ff_ecc[k], (paraddr + k));
> +	} else {
> +		for (k = 0; k < 9; k++)
> +			writeb(read_ecc[k], (paraddr + k));
> +	}

Wouldn't it be simpler  to do:

writeb(..., &emc->nfpar[k]);

And don't use volatile.

> +	/* Set PRDY */
> +	writel(readl(&emc->nfecr) | EMC_NFECR_PRDY, &emc->nfecr);
> +
> +	/* Wait for completion */
> +	do {
> +		status = readl(&emc->nfints);
> +	} while (!(status & EMC_NFINTS_DECF));
> +
> +	/* disable ecc */
> +	writel(readl(&emc->nfecr) & ~EMC_NFECR_ECCE, &emc->nfecr);
> +
> +	/* Check decoding */
> +	if (!(status & EMC_NFINTS_ERR))
> +		return 0;
> +
> +	if (status & EMC_NFINTS_UNCOR) {
> +		printf("uncorrectable ecc\n");
> +		return -1;
> +	}
> +
> +	errcnt = (status & EMC_NFINTS_ERRCNT_MASK) >> EMC_NFINTS_ERRCNT_BIT;
> +

> +#ifdef CONFIG_NAND_SPL
> +       return 0;
> +#endif

Spaces should be a tab.

> +	switch (errcnt) {
> +	case 4:
> +		index = (readl(&emc->nferr[3]) & EMC_NFERR_INDEX_MASK) >>
> +			EMC_NFERR_INDEX_BIT;
> +		mask = (readl(&emc->nferr[3]) & EMC_NFERR_MASK_MASK) >> 
> +			EMC_NFERR_MASK_BIT;
> +		jz_rs_correct(dat, index, mask);
> +	case 3:
> +		index = (readl(&emc->nferr[2]) & EMC_NFERR_INDEX_MASK) >>
> +			EMC_NFERR_INDEX_BIT;
> +		mask = (readl(&emc->nferr[2]) & EMC_NFERR_MASK_MASK) >> 
> +			EMC_NFERR_MASK_BIT;
> +		jz_rs_correct(dat, index, mask);
> +	case 2:
> +		index = (readl(&emc->nferr[1]) & EMC_NFERR_INDEX_MASK) >> 
> +			EMC_NFERR_INDEX_BIT;
> +		mask = (readl(&emc->nferr[1]) & EMC_NFERR_MASK_MASK) >> 
> +			EMC_NFERR_MASK_BIT;
> +		jz_rs_correct(dat, index, mask);
> +	case 1:
> +		index = (readl(&emc->nferr[0]) & EMC_NFERR_INDEX_MASK) >>
> +			EMC_NFERR_INDEX_BIT;
> +		mask = (readl(&emc->nferr[0]) & EMC_NFERR_MASK_MASK) >>
> +			EMC_NFERR_MASK_BIT;
> +		jz_rs_correct(dat, index, mask);
> +	default:
> +		break;
> +	}
> +
> +	return errcnt;

You don't do ECC correction in SPL?  Can it not fit?

> +/*
> + * Main initialization routine
> + */
> +int board_nand_init(struct nand_chip *nand)
> +{
> +#ifdef CONFIG_NAND_SPL
> +extern void pll_init(void);
> +extern void sdram_init(void);
> +extern int serial_init(void);

Externs should go in header files.

> +	__gpio_as_sdram_16bit_4720();
> +	__gpio_as_uart0();
> +
> +	pll_init();
> +	serial_init();
> +	sdram_init();

> +#if defined(CONFIG_QI_LB60)
> +#define KEY_U_OUT       (32 * 2 + 16)
> +#define KEY_U_IN        (32 * 3 + 19)
> +	__gpio_as_input(KEY_U_IN);
> +	__gpio_enable_pull(KEY_U_IN);
> +	__gpio_as_output(KEY_U_OUT);
> +	__gpio_clear_pin(KEY_U_OUT);
> +
> +	if (__gpio_get_pin(KEY_U_IN) == 0)
> +		usb_boot();
> +#endif
> +#endif

This stuff does not belong in the NAND driver; it belongs under your board
or cpu directory.

> +	uint32_t reg;
> +
> +	reg = readl(&emc->nfcsr); 
> +	reg |= EMC_NFCSR_NFE1;	/* EMC setup, Set NFE bit */
> +	writel(reg, &emc->nfcsr); 
> +
> +	writel(EMC_SMCR1_OPT_NAND, &emc->smcr[1]);
> +
> +	nand->IO_ADDR_R		= JZ_NAND_DATA_ADDR;
> +	nand->IO_ADDR_W		= JZ_NAND_DATA_ADDR;
> +	nand->cmd_ctrl		= jz_nand_cmd_ctrl;
> +	nand->dev_ready		= jz_nand_device_ready;
> +#ifdef CONFIG_NAND_SPL
> +	nand->read_byte		= nand_read_byte;
> +	nand->read_buf		= nand_read_buf;
> +#endif
> +	nand->ecc.hwctl		= jz_nand_hwctl;
> +	nand->ecc.correct	= jz_nand_rs_correct_data;
> +	nand->ecc.calculate	= jz_nand_rs_calculate_ecc;
> +	nand->ecc.mode		= NAND_ECC_HW_OOB_FIRST;
> +	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
> +	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
> +	nand->ecc.layout	= &qi_lb60_ecclayout_2gb;
> +	nand->chip_delay	= 50;

You don't set nand->options...

Don't you want a bad block table?

-Scott

  parent reply	other threads:[~2011-03-07 23:44 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-28  6:57 [U-Boot] [PATCH v6 0/7] those series patches for add ben nanonote board Xiangfu Liu
2011-02-28  6:57 ` [U-Boot] [PATCH v6 1/7] those files are jz4740 base files Xiangfu Liu
2011-02-28  6:57   ` [U-Boot] [PATCH v6 2/7] this is jz4740 head file Xiangfu Liu
2011-02-28  6:57     ` [U-Boot] [PATCH v6 3/7] jz4740 nand spl files Xiangfu Liu
2011-02-28  6:57       ` [U-Boot] [PATCH v6 4/7] jz4740 nand driver Xiangfu Liu
2011-02-28  6:57         ` [U-Boot] [PATCH v6 5/7] add Ben NanoNote board Xiangfu Liu
2011-02-28  6:57           ` [U-Boot] [PATCH v6 6/7] add entry to MAINTAINERS and boards.cfg Xiangfu Liu
2011-02-28  6:57             ` [U-Boot] [PATCH v6 7/7] modify files for ben nanonote board Xiangfu Liu
2011-03-15  3:16               ` Shinya Kuribayashi
2011-03-25  9:06                 ` Xiangfu Liu
2011-03-07 23:44         ` Scott Wood [this message]
2011-03-22  8:11           ` [U-Boot] [PATCH v6 4/7] jz4740 nand driver Xiangfu Liu
2011-03-22 16:10             ` Scott Wood
2011-04-26 14:44               ` Xiangfu Liu
2011-03-25  9:17           ` Xiangfu Liu
2011-03-25 16:04             ` Scott Wood
2011-04-26 14:45               ` Xiangfu Liu
2011-03-15  2:27     ` [U-Boot] [PATCH v6 2/7] this is jz4740 head file Shinya Kuribayashi
2011-03-22  8:06       ` Xiangfu Liu
2011-03-15  2:26   ` [U-Boot] [PATCH v6 1/7] those files are jz4740 base files Shinya Kuribayashi
2011-03-22  8:06     ` Xiangfu Liu
2011-03-15  2:38   ` Shinya Kuribayashi
2011-03-22  8:05     ` Xiangfu Liu

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=20110307174436.6b4c8b21@schlenkerla \
    --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