From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv2 3/3] 83xx, kmeter1: added NAND support
Date: Mon, 13 Jul 2009 11:55:15 +0200 [thread overview]
Message-ID: <4A5B0483.3060407@denx.de> (raw)
In-Reply-To: <200907131120.31201.sr@denx.de>
Hello Stefan,
Stefan Roese wrote:
> On Saturday 11 July 2009 10:19:08 Heiko Schocher wrote:
>> +++ b/drivers/mtd/nand/kmeter1_nand.c
>> @@ -0,0 +1,153 @@
>> +/*
>> + * (C) Copyright 2009
>> + * Heiko Schocher, DENX Software Engineering, hs at denx.de
>> + *
>> + * 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>
>> +
>> +#if defined(CONFIG_CMD_NAND)
>
> This #if shouldn't be necessary.
Hmm.. keymile has per default deactivated NAND support on this board,
so I think it is necessary (or I make this dependence in the board
makefile ...)
>> +#include <nand.h>
>> +#include <asm/io.h>
>> +
>> +#define CONFIG_NAND_MODE_REG (CONFIG_SYS_NAND_BASE + 0x20000)
>> +#define CONFIG_NAND_DATA_REG (CONFIG_SYS_NAND_BASE + 0x30000)
>> +
>> +#define read_mode() in_8((volatile unsigned char __iomem *) \
>> + CONFIG_NAND_MODE_REG)
>> +#define write_mode(val) out_8((volatile unsigned char __iomem *) \
>> + CONFIG_NAND_MODE_REG, val)
>> +#define read_data() in_8((volatile unsigned char __iomem *) \
>> + CONFIG_NAND_DATA_REG)
>> +#define write_data(val) out_8((volatile unsigned char __iomem *) \
>> + CONFIG_NAND_DATA_REG, val)
>> +
>> +#define KPN_RDY2 (1 << 7)
>> +#define KPN_RDY1 (1 << 6)
>> +#define KPN_WPN (1 << 4)
>> +#define KPN_CE2N (1 << 3)
>> +#define KPN_CE1N (1 << 2)
>> +#define KPN_ALE (1 << 1)
>> +#define KPN_CLE (1 << 0)
>> +
>> +#define KPN_DEFAULT_CHIP_DELAY 50
>> +
>> +static int kpn_chip_ready(void)
>> +{
>> + if (read_mode() & KPN_RDY1)
>> + return 1;
>> +
>> + return 0;
>> +}
>> +
>> +static void kpn_wait_rdy(void)
>> +{
>> + int cnt = 1000000;
>> +
>> + while (--cnt && !kpn_chip_ready())
>> + udelay(1);
>> +
>> + if (!cnt)
>> + printf ("timeout while waiting for RDY\n");
>> +}
>> +
>> +static void kpn_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int
>> ctrl) +{
>> + u8 reg_val = read_mode();
>> +
>> + if (ctrl & NAND_CTRL_CHANGE) {
>> + if ( ctrl & NAND_NCE)
>> + reg_val = reg_val & ~KPN_CE1N;
>> + else
>> + reg_val = reg_val | KPN_CE1N;
>> + write_mode(reg_val);
>> + }
>> + if (cmd == NAND_CMD_NONE)
>> + return;
>> +
>> + reg_val = reg_val & ~(KPN_ALE + KPN_CLE);
>> + if (ctrl & NAND_CLE)
>> + reg_val = reg_val | KPN_CLE;
>> + if (ctrl & NAND_ALE)
>> + reg_val = reg_val | KPN_ALE;
>> +
>> + /* select register */
>> + write_mode(reg_val);
>> +
>> + /* write cmd */
>> + write_data(cmd);
>> +
>> + /* deselect register */
>> + reg_val = reg_val & ~(KPN_ALE + KPN_CLE);
>> + write_mode(reg_val);
>> +
>> + /* wait until flash is ready */
>> + kpn_wait_rdy();
>> +}
>> +
>> +static u_char kpn_nand_read_byte(struct mtd_info *mtd)
>> +{
>> + return read_data();
>> +}
>> +
>> +static void kpn_nand_write_buf(struct mtd_info *mtd, const u_char *buf,
>> int len) +{
>> + int i;
>> +
>> + for (i = 0; i < len; i++) {
>> + write_data(buf[i]);
>> + kpn_wait_rdy();
>> + }
>> +}
>> +
>> +static void kpn_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
>> +{
>> + int i;
>> +
>> + for (i = 0; i < len; i++) {
>> + buf[i] = read_data();
>> + }
>
> Nitpicking: The braces are not necessary (single line statement).
Yep, you are right. I fix it.
thanks
bye
Heiko
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
next prev parent reply other threads:[~2009-07-13 9:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-11 8:19 [U-Boot] [PATCHv2 3/3] 83xx, kmeter1: added NAND support Heiko Schocher
2009-07-13 9:20 ` Stefan Roese
2009-07-13 9:55 ` Heiko Schocher [this message]
2009-07-13 9:57 ` Stefan Roese
2009-07-13 10:15 ` [U-Boot] [PATCHv3 " Heiko Schocher
2009-07-16 19:35 ` Scott Wood
2009-07-17 5:05 ` Heiko Schocher
2009-07-17 15:36 ` Scott Wood
2009-07-18 8:43 ` Heiko Schocher
2009-07-21 15:13 ` [U-Boot] [PATCHv4 " Heiko Schocher
2009-08-06 22:08 ` Scott Wood
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=4A5B0483.3060407@denx.de \
--to=hs@denx.de \
--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.