All of lore.kernel.org
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 09/11] S3C24XX: Add NAND Flash driver
Date: Tue, 18 Sep 2012 13:30:14 -0500	[thread overview]
Message-ID: <1347993014.15284.10@snotra> (raw)
In-Reply-To: <5058BC02.7070705@inov.pt> (from jose.goncalves@inov.pt on Tue Sep 18 13:22:58 2012)

On 09/18/2012 01:22:58 PM, Jos? Miguel Gon?alves wrote:
> On 18-09-2012 19:02, Scott Wood wrote:
>> On 09/18/2012 12:40:36 PM, Jos? Miguel Gon?alves wrote:
>>> +#define TACLS_VAL    7    /* CLE & ALE duration setting (0~7) */
>>> +#define    TWRPH0_VAL    7    /* TWRPH0 duration setting (0~7) */
>>> +#define TWRPH1_VAL    7    /* TWRPH1 duration setting (0~7) */
>> 
>> Please use space, not tab, as a word separator (after the second  
>> #define).
> 
> OK.
> 
>> 
>>> +
>>> +#define MAX_CHIPS    2
>>> +static int nand_cs[MAX_CHIPS] = { 0, 1 };
>> 
>> This needs explanation (and const).  Better would be to use a priv  
>> struct, as discussed before.
>> 
>>> +static void s3c_nand_select_chip(struct mtd_info *mtd, int chip)
>>> +{
>>> +    struct s3c24xx_nand *const nand = s3c24xx_get_base_nand();
>>> +    u_long nfcont;
>> 
>> s/u_long/u32/
> 
> Didn't catch this...

Replace u_long with u32.

>>> +    nfcont = readl(&nand->nfcont);
>>> +
>>> +    switch (chip) {
>>> +    case -1:
>>> +        nfcont |= NFCONT_NCE1 | NFCONT_NCE0;
>>> +        break;
>>> +    case 0:
>>> +        nfcont &= ~NFCONT_NCE0;
>>> +        break;
>>> +    case 1:
>>> +        nfcont &= ~NFCONT_NCE1;
>>> +        break;
>>> +    default:
>>> +        return;
>> 
>> error message on default?
> 
> OK.
> 
>> 
>>> +    }
>>> +
>>> +    writel(nfcont, &nand->nfcont);
>>> +}
>>> +
>>> +/*
>>> + * Hardware specific access to control-lines function
>>> + */
>>> +static void s3c_nand_hwcontrol(struct mtd_info *mtd, int cmd,  
>>> unsigned int ctrl)
>>> +{
>>> +    struct s3c24xx_nand *const nand = s3c24xx_get_base_nand();
>>> +    struct nand_chip *this = mtd->priv;
>>> +
>>> +    if (ctrl & NAND_CTRL_CHANGE) {
>>> +        if (ctrl & NAND_CLE)
>>> +            this->IO_ADDR_W = &nand->nfcmmd;
>>> +        else if (ctrl & NAND_ALE)
>>> +            this->IO_ADDR_W = &nand->nfaddr;
>>> +        else
>>> +            this->IO_ADDR_W = &nand->nfdata;
>>> +        if (ctrl & NAND_NCE)
>>> +            s3c_nand_select_chip(mtd, *(int *)this->priv);
>>> +        else
>>> +            s3c_nand_select_chip(mtd, -1);
>>> +    }
>>> +
>>> +    if (cmd != NAND_CMD_NONE)
>>> +        writeb(cmd, this->IO_ADDR_W);
>>> +}
>> 
>> As discussed earlier, do you really need to mess with IO_ADDR_W or  
>> can you do it the way ndfc.c does?
> 
> I will take a look at ndfc.c.



Most of this driver was copy-paste from s3c64xx.c driver and an older  
patched U-Boot sources from Samsung, so I did not make any real code  
examination after it started to work...
> 
>> 
>> I.e.:
>> 
>> static void s3c_nand_hwcontrol(struct mtd_info *mtd, int cmd,  
>> unsigned int ctrl)
>> {
>>     struct s3c24xx_nand *const nand = s3c24xx_get_base_nand();
>>     struct nand_chip *this = mtd->priv;
>> 
>>     if (cmd == NAND_CMD_NONE)
>>         return;
>> 
>>     if (ctrl & NAND_CLE)
>>         writeb(cmd, &nand->nfcmmd);
>>     else
>>         writeb(cmd, &nand->nfaddr);
>> }

Oh sorry -- the above is missing the NCE part.  Before the  
NAND_CMD_NONE check insert:

	if (ctrl & NAND_CTRL_CHANGE) {
		if (ctrl & NAND_NCE)
			s3c_nand_select_chip(mtd, *(const int  
*)this->priv);
		else
			s3c_nand_select_chip(mtd, -1);
	}



>> 
>>> +/*
>>> + * Board-specific NAND initialization.
>>> + */
>>> +int board_nand_init(struct nand_chip *nand)
>>> +{
>>> +    static int chip_n;
>>> +    struct s3c24xx_nand *const nand_reg = s3c24xx_get_base_nand();
>>> +
>>> +    if (chip_n == 0) {
>>> +        /* Extend NAND timings to the maximum */
>>> +        clrsetbits_le32(&nand_reg->nfconf,
>>> +                NFCONF_TACLS_MASK | NFCONF_TWRPH0_MASK |
>>> +                NFCONF_TWRPH1_MASK,
>>> +                NFCONF_TACLS(TACLS_VAL) |
>>> +                NFCONF_TWRPH0(TWRPH0_VAL) |
>>> +                NFCONF_TWRPH1(TWRPH1_VAL));
>>> +
>>> +        /* Disable chip selects and soft lock, enable controller */
>>> +        clrsetbits_le32(&nand_reg->nfcont, NFCONT_WP,
>>> +                NFCONT_NCE1 | NFCONT_NCE0 | NFCONT_ENABLE);
>>> +    } else if (chip_n >= MAX_CHIPS) {
>>> +        return -ENODEV;
>>> +    }
>>> +
>>> +    nand->IO_ADDR_R = &nand_reg->nfdata;
>>> +    nand->IO_ADDR_W = &nand_reg->nfdata;
>>> +    nand->cmd_ctrl = s3c_nand_hwcontrol;
>>> +    nand->dev_ready = s3c_nand_device_ready;
>>> +    nand->select_chip = s3c_nand_select_chip;
>>> +    nand->options = 0;
>>> +#ifdef CONFIG_SPL_BUILD
>>> +    nand->read_buf = nand_read_buf;
>>> +#endif
>>> +
>>> +#ifdef CONFIG_S3C24XX_NAND_HWECC
>>> +    nand->ecc.hwctl = s3c_nand_enable_hwecc;
>>> +    nand->ecc.calculate = s3c_nand_calculate_ecc;
>>> +    nand->ecc.correct = s3c_nand_correct_data;
>>> +    nand->ecc.mode = NAND_ECC_HW_OOB_FIRST;
>>> +    nand->ecc.size = CONFIG_SYS_NAND_ECCSIZE;
>>> +    nand->ecc.bytes = CONFIG_SYS_NAND_ECCBYTES;
>>> +#else
>>> +    nand->ecc.mode = NAND_ECC_SOFT;
>>> +#endif /* ! CONFIG_S3C24XX_NAND_HWECC */
>>> +
>>> +    nand->priv = nand_cs + chip_n++;
>>> +
>>> +    return 0;
>>> +}
>> 
>> Please consider using the new SELF_INIT mechanism.
>> 
> 
> Can you explain and/or point_to_resources for what this means (I'm a  
> U-Boot newbie)...

See CONFIG_SYS_NAND_SELF_INIT in doc/README.nand

I'd like the old way to be removed at some point.

-Scott

  reply	other threads:[~2012-09-18 18:30 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18 17:40 [U-Boot] [PATCH v3 00/11] S3C24XX: Add support to MINI2416 board José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 01/11] Add configuration option to select printf() inclusion on SPL José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 02/11] S3C24XX: Add core support for Samsung's S3C24XX SoCs José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 03/11] serial: Add support to 4 ports in serial_s3c24x0 José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 04/11] serial: Use a more precise baud rate generation for serial_s3c24x0 José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 05/11] serial: Remove unnecessary delay in serial_s3c24x0 José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 06/11] rtc: Improve rtc_get() on s3c24x0_rtc José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 07/11] rtc: Fix rtc_reset() " José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 08/11] rtc: Don't allow setting unsuported years " José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 09/11] S3C24XX: Add NAND Flash driver José Miguel Gonçalves
2012-09-18 18:02   ` Scott Wood
2012-09-18 18:22     ` José Miguel Gonçalves
2012-09-18 18:30       ` Scott Wood [this message]
2012-09-18 18:48         ` José Miguel Gonçalves
2012-09-18 20:57           ` Scott Wood
2012-09-18 17:40 ` [U-Boot] [PATCH v3 10/11] Add u-boot-pad.bin target to the Makefile José Miguel Gonçalves
2012-09-18 17:40 ` [U-Boot] [PATCH v3 11/11] S3C24XX: Add support to MINI2416 board José Miguel Gonçalves

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=1347993014.15284.10@snotra \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.