public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH 6/7] NAND: add NAND driver for s3c64xx
Date: Thu, 31 Jul 2008 21:55:19 +0200	[thread overview]
Message-ID: <20080731195519.GA8566@game.jcrosoft.org> (raw)
In-Reply-To: <Pine.LNX.4.64.0807311246100.4832@axis700.grange>

> +/*
> + * (C) Copyright 2006 DENX Software Engineering
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation; either version 2 of
> + * the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +
> +#include <nand.h>
> +#include <s3c6400.h>
> +
> +#include <asm/io.h>
> +
> +#ifdef CONFIG_NAND_SPL
> +#define printf(arg...) do {} while (0)
> +#endif
> +
> +/* Nand flash definition values by jsgood */
> +#define S3C_NAND_CFG_HWECC
Please move to config file
> +#undef	S3C_NAND_DEBUG
please remove
> +
> +#ifdef S3C_NAND_DEBUG
> +/*
> + * Function to print out oob buffer for debugging
> + * Written by jsgood
> + */
> +static void print_oob(const char *header, struct mtd_info *mtd)
> +{
> +	int i;
> +	struct nand_chip *chip = mtd->priv;
> +
> +	printf("%s:\t", header);
> +
> +	for(i = 0; i < 64; i++)
> +		printf("%02x ", chip->oob_poi[i]);
> +
> +	printf("\n");
> +}
> +#endif /* S3C_NAND_DEBUG */
> +
> +#ifdef CONFIG_NAND_SPL
> +static u_char nand_read_byte(struct mtd_info *mtd)
> +{
> +	struct nand_chip *this = mtd->priv;
add an empty line
> +	return readb(this->IO_ADDR_R);
> +}
> +
> +static void nand_write_byte(struct mtd_info *mtd, u_char byte)
> +{
> +	struct nand_chip *this = mtd->priv;
add an empty line
> +	writeb(byte, this->IO_ADDR_W);
> +}
> +
> +static void nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
> +{
> +	int i;
> +	struct nand_chip *this = mtd->priv;
> +
> +	for (i = 0; i < len; i++)
> +		buf[i] = readb(this->IO_ADDR_R);
> +}
> +#endif
> +
> +/*
> + * This function determines whether read data is good or not.
> + * If SLC, must write ecc codes to controller before reading status bit.
> + * If MLC, status bit is already set, so only reading is needed.
> + * If status bit is good, return 0.
> + * If correctable errors occured, do that.
> + * If uncorrectable errors occured, return -1.
> + * Written by jsgood
> + */
> +static int s3c_nand_correct_data(struct mtd_info *mtd, u_char *dat,
> +				 u_char *read_ecc, u_char *calc_ecc)
> +{
> +	int ret = -1;
> +	u_long nfestat0, nfmeccdata0, nfmeccdata1;
> +	u_char err_type;
> +
> +	/* SLC: Write ecc to compare */
> +	nfmeccdata0 = (calc_ecc[1] << 16) | calc_ecc[0];
> +	nfmeccdata1 = (calc_ecc[3] << 16) | calc_ecc[2];
> +	writel(nfmeccdata0, NFMECCDATA0);
> +	writel(nfmeccdata1, NFMECCDATA1);
> +
> +	/* Read ecc status */
> +	nfestat0 = readl(NFESTAT0);
> +	err_type = nfestat0 & 0x3;
> +
> +	switch (err_type) {
> +	case 0: /* No error */
> +		ret = 0;
> +		break;
> +
> +	case 1: /* 1 bit error (Correctable)
> +		   (nfestat0 >> 7) & 0x7ff	:error byte number
> +		   (nfestat0 >> 4) & 0x7	:error bit number */
> +		printf("S3C NAND: 1 bit error detected at byte %ld. Correcting from "
> +		       "0x%02x ", (nfestat0 >> 7) & 0x7ff, dat[(nfestat0 >> 7) & 0x7ff]);
> +		dat[(nfestat0 >> 7) & 0x7ff] ^= (1 << ((nfestat0 >> 4) & 0x7));
> +		printf("to 0x%02x...OK\n", dat[(nfestat0 >> 7) & 0x7ff]);
could use inline or macro to be more readable
> +		ret = 1;
> +		break;
> +
> +	case 2: /* Multiple error */
> +	case 3: /* ECC area error */
> +		printf("S3C NAND: ECC uncorrectable error detected. Not correctable.\n");
> +		ret = -1;
> +		break;
> +	}
> +
> +	return ret;
> +}
> +#endif /* S3C_NAND_CFG_HWECC */
> +
> +/*
> + * Board-specific NAND initialization. The following members of the
> + * argument are board-specific (per include/linux/mtd/nand.h):
> + * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
> + * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
> + * - hwcontrol: hardwarespecific function for accesing control-lines
> + * - dev_ready: hardwarespecific function for  accesing device ready/busy line
> + * - enable_hwecc?: function to enable (reset)  hardware ecc generator. Must
> + *   only be provided if a hardware ECC is available
> + * - eccmode: mode of ecc, see defines
> + * - chip_delay: chip dependent delay for transfering data from array to
> + *   read regs (tR)
> + * - options: various chip options. They can partly be set to inform
> + *   nand_scan about special functionality. See the defines for further
> + *   explanation
> + * Members with a "?" were not set in the merged testing-NAND branch,
> + * so they are not set here either.
> + */
> +#include <linux/mtd/mtd.h>
move to the top
> +int board_nand_init(struct nand_chip *nand)
> +{
> +	NFCONT_REG 		= (NFCONT_REG & ~NFCONT_WP) | NFCONT_ENABLE | 0x6;
> +
> +	nand->IO_ADDR_R		= (void __iomem *)NFDATA;
> +	nand->IO_ADDR_W		= (void __iomem *)NFDATA;
> +	nand->hwcontrol		= s3c_nand_hwcontrol;
> +	nand->dev_ready		= s3c_nand_device_ready;
> +	nand->select_chip	= s3c_nand_select_chip;
> +	nand->options		= 0;

Best Regards,
J.

      parent reply	other threads:[~2008-07-31 19:55 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-31 10:54 [U-Boot-Users] [PATCH 6/7] NAND: add NAND driver for s3c64xx Guennadi Liakhovetski
2008-07-31 14:24 ` Wolfgang Denk
2008-08-01 11:02   ` Guennadi Liakhovetski
2008-08-01 12:28     ` Wolfgang Denk
2008-08-01 13:30       ` [U-Boot-Users] several messages Guennadi Liakhovetski
2008-08-04 10:42       ` [U-Boot-Users] [PATCH 0/7 v2] SMDK6400 support Guennadi Liakhovetski
2008-08-04 10:42         ` [U-Boot-Users] [PATCH 1/7 v2] Add definition for the AM29LV800BB AMD NOR-flash Guennadi Liakhovetski
2008-08-04 10:42         ` [U-Boot-Users] [PATCH 2/7 v2] NAND_CMD_READOOB is not supported by all chips, read OOB with the page instead Guennadi Liakhovetski
2008-08-04 10:43         ` [U-Boot-Users] [PATCH 3/7 v2] ARM: Add arm1176 core with s3c6400 SoC Guennadi Liakhovetski
2008-08-04 10:43         ` [U-Boot-Users] [PATCH 4/7 v2] USB: Add support for OHCI controller on s3c6400 Guennadi Liakhovetski
2008-08-04 10:43         ` [U-Boot-Users] [PATCH 5/7 v2] serial: add s3c64xx serial driver Guennadi Liakhovetski
2008-08-04 10:43         ` [U-Boot-Users] [PATCH 6/7 v2] NAND: add NAND driver for s3c64xx Guennadi Liakhovetski
2008-08-04 10:43         ` [U-Boot-Users] [PATCH 7/7 v2] ARM: Add support for S3C6400 based SMDK6400 board Guennadi Liakhovetski
2008-08-04 11:00         ` [U-Boot-Users] [PATCH 0/7 v2] SMDK6400 support Wolfgang Denk
2008-08-04 12:44         ` [U-Boot-Users] [PATCH 0/7 v3] " Guennadi Liakhovetski
2008-08-04 12:44           ` [U-Boot-Users] [PATCH 1/7 v3] Add definition for the AM29LV800BB AMD NOR-flash Guennadi Liakhovetski
2008-08-04 12:45           ` [U-Boot-Users] [PATCH 2/7 v3] NAND_CMD_READOOB is not supported by all chips, read OOB with the page instead Guennadi Liakhovetski
2008-08-04 22:28             ` Scott Wood
2008-08-05 13:08               ` Guennadi Liakhovetski
2008-08-05 15:01                 ` Scott Wood
2008-08-05 15:25                   ` Guennadi Liakhovetski
2008-08-05 15:37                     ` Scott Wood
2008-08-04 12:45           ` [U-Boot-Users] [PATCH 3/7 v3] ARM: Add arm1176 core with s3c6400 SoC Guennadi Liakhovetski
2008-08-04 20:06             ` [U-Boot-Users] [PATCH 3/7 v4] " Guennadi Liakhovetski
2008-08-04 12:45           ` [U-Boot-Users] [PATCH 4/7 v3] USB: Add support for OHCI controller on s3c6400 Guennadi Liakhovetski
2008-08-04 21:08             ` Jean-Christophe PLAGNIOL-VILLARD
2008-08-04 22:04               ` Guennadi Liakhovetski
2008-08-04 12:45           ` [U-Boot-Users] [PATCH 5/7 v3] serial: add s3c64xx serial driver Guennadi Liakhovetski
2008-08-04 21:19             ` Jean-Christophe PLAGNIOL-VILLARD
2008-08-04 22:08               ` Guennadi Liakhovetski
2008-08-04 22:52                 ` Wolfgang Denk
2008-08-04 12:46           ` [U-Boot-Users] [PATCH 6/7 v3] NAND: add NAND driver for s3c64xx Guennadi Liakhovetski
2008-08-04 22:38             ` Scott Wood
2008-08-04 12:46           ` [U-Boot-Users] [PATCH 7/7 v3] ARM: Add support for S3C6400 based SMDK6400 board Guennadi Liakhovetski
2008-08-04 20:10             ` Guennadi Liakhovetski
2008-07-31 19:55 ` Jean-Christophe PLAGNIOL-VILLARD [this message]

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=20080731195519.GA8566@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.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