[U-Boot] [PATCHv2 3/3] 83xx, kmeter1: added NAND support

Signed-off-by: Heiko Schocher hs@denx.de --- - changes since v1: moved the nand driver to drivers/mtd/nand/kmeter1_nand.c as Stefan Roese suggested
drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/kmeter1_nand.c | 153 +++++++++++++++++++++++++++++++++++++++ include/configs/kmeter1.h | 6 ++ 3 files changed, 160 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/kmeter1_nand.c
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index c1325b9..c85e3d5 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -40,6 +40,7 @@ COBJS-$(CONFIG_DRIVER_NAND_BFIN) += bfin_nand.o COBJS-$(CONFIG_NAND_DAVINCI) += davinci_nand.o COBJS-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_nand.o COBJS-$(CONFIG_NAND_FSL_UPM) += fsl_upm.o +COBJS-$(CONFIG_NAND_KMETER1) += kmeter1_nand.o COBJS-$(CONFIG_NAND_MPC5121_NFC) += mpc5121_nfc.o COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o diff --git a/drivers/mtd/nand/kmeter1_nand.c b/drivers/mtd/nand/kmeter1_nand.c new file mode 100644 index 0000000..0675b53 --- /dev/null +++ b/drivers/mtd/nand/kmeter1_nand.c @@ -0,0 +1,153 @@ +/* + * (C) Copyright 2009 + * Heiko Schocher, DENX Software Engineering, hs@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) + +#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(); + } +} + +static int kpn_nand_dev_ready(struct mtd_info *mtd) +{ + kpn_wait_rdy(); + + return 1; +} + +int board_nand_init(struct nand_chip *nand) +{ + nand->ecc.mode = NAND_ECC_SOFT; + + /* Reference hardware control function */ + nand->cmd_ctrl = kpn_nand_hwcontrol; + nand->read_byte = kpn_nand_read_byte; + nand->write_buf = kpn_nand_write_buf; + nand->read_buf = kpn_nand_read_buf; + nand->dev_ready = kpn_nand_dev_ready; + nand->chip_delay = KPN_DEFAULT_CHIP_DELAY; + + /* reset mode register */ + write_mode(KPN_CE1N + KPN_CE2N + KPN_WPN); + return 0; +} +#endif diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h index 811ba88..4de0dfc 100644 --- a/include/configs/kmeter1.h +++ b/include/configs/kmeter1.h @@ -324,6 +324,12 @@ #define CONFIG_SYS_DTT_HYSTERESIS 3 #define CONFIG_SYS_DTT_BUS_NUM (CONFIG_SYS_MAX_I2C_BUS)
+#if defined(CONFIG_CMD_NAND) +#define CONFIG_NAND_KMETER1 +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_BASE CONFIG_SYS_PIGGY_BASE +#endif + #if defined(CONFIG_PCI) #define CONFIG_CMD_PCI #endif

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@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.
+#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).
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@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@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

On Monday 13 July 2009 11:55:15 Heiko Schocher wrote:
+#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 ...)
If some board variants don't enable NAND support, this file should not be compiled then. This should be done via the Makefile. So just set CONFIG_NAND_KMETER1 in the board config header when NAND really is enabled.
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================

Signed-off-by: Heiko Schocher hs@denx.de --- - changes since v1: moved the nand driver to drivers/mtd/nand/kmeter1_nand.c as Stefan Roese suggested
- changes since v2: added comments from Stefan Roese - drivers/mtd/nand/kmeter1_nand.c only gets compiled if CONFIG_NAND_KMETER1 is set in board config file - Fix Coding Style issue
drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/kmeter1_nand.c | 148 +++++++++++++++++++++++++++++++++++++++ include/configs/kmeter1.h | 6 ++ 3 files changed, 155 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/kmeter1_nand.c
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index c1325b9..c85e3d5 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -40,6 +40,7 @@ COBJS-$(CONFIG_DRIVER_NAND_BFIN) += bfin_nand.o COBJS-$(CONFIG_NAND_DAVINCI) += davinci_nand.o COBJS-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_nand.o COBJS-$(CONFIG_NAND_FSL_UPM) += fsl_upm.o +COBJS-$(CONFIG_NAND_KMETER1) += kmeter1_nand.o COBJS-$(CONFIG_NAND_MPC5121_NFC) += mpc5121_nfc.o COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o diff --git a/drivers/mtd/nand/kmeter1_nand.c b/drivers/mtd/nand/kmeter1_nand.c new file mode 100644 index 0000000..7e7b199 --- /dev/null +++ b/drivers/mtd/nand/kmeter1_nand.c @@ -0,0 +1,148 @@ +/* + * (C) Copyright 2009 + * Heiko Schocher, DENX Software Engineering, hs@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> +#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(); +} + +static int kpn_nand_dev_ready(struct mtd_info *mtd) +{ + kpn_wait_rdy(); + + return 1; +} + +int board_nand_init(struct nand_chip *nand) +{ + nand->ecc.mode = NAND_ECC_SOFT; + + /* Reference hardware control function */ + nand->cmd_ctrl = kpn_nand_hwcontrol; + nand->read_byte = kpn_nand_read_byte; + nand->write_buf = kpn_nand_write_buf; + nand->read_buf = kpn_nand_read_buf; + nand->dev_ready = kpn_nand_dev_ready; + nand->chip_delay = KPN_DEFAULT_CHIP_DELAY; + + /* reset mode register */ + write_mode(KPN_CE1N + KPN_CE2N + KPN_WPN); + return 0; +} diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h index 811ba88..4de0dfc 100644 --- a/include/configs/kmeter1.h +++ b/include/configs/kmeter1.h @@ -324,6 +324,12 @@ #define CONFIG_SYS_DTT_HYSTERESIS 3 #define CONFIG_SYS_DTT_BUS_NUM (CONFIG_SYS_MAX_I2C_BUS)
+#if defined(CONFIG_CMD_NAND) +#define CONFIG_NAND_KMETER1 +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_BASE CONFIG_SYS_PIGGY_BASE +#endif + #if defined(CONFIG_PCI) #define CONFIG_CMD_PCI #endif

On Mon, Jul 13, 2009 at 12:15:12PM +0200, Heiko Schocher wrote:
+#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)
No need for volatile when using accessors. If you kept a pointer around instead of casting here, you could reasonably use the accessors directly without needing wrappers...
If this is purely for U-Boot and not shared with Linux we can drop the __iomem.
+static void kpn_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) +{
- u8 reg_val = read_mode();
No tab after "u8".
- if (ctrl & NAND_CTRL_CHANGE) {
if ( ctrl & NAND_NCE)
No space after "(".
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;
If ALE/CLE is sticky in the hardware mode register, you could probably move this under NAND_CTRL_CHANGE and simplify things a little.
diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h index 811ba88..4de0dfc 100644 --- a/include/configs/kmeter1.h +++ b/include/configs/kmeter1.h @@ -324,6 +324,12 @@ #define CONFIG_SYS_DTT_HYSTERESIS 3 #define CONFIG_SYS_DTT_BUS_NUM (CONFIG_SYS_MAX_I2C_BUS)
+#if defined(CONFIG_CMD_NAND) +#define CONFIG_NAND_KMETER1
No tab after #define.
+#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_BASE CONFIG_SYS_PIGGY_BASE +#endif
#if defined(CONFIG_PCI) #define CONFIG_CMD_PCI #endif
This file looks a little different in the current tree (2 rather than CONFIG_SYS_MAX_I2C_BUS), so it wouldn't apply cleanly.
-Scott

Hello Scott
Scott Wood wrote:
On Mon, Jul 13, 2009 at 12:15:12PM +0200, Heiko Schocher wrote:
+#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)
No need for volatile when using accessors. If you kept a pointer around instead of casting here, you could reasonably use the accessors directly without needing wrappers...
If this is purely for U-Boot and not shared with Linux we can drop the __iomem.
OK, I fix it.
+static void kpn_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) +{
- u8 reg_val = read_mode();
No tab after "u8".
- if (ctrl & NAND_CTRL_CHANGE) {
if ( ctrl & NAND_NCE)
No space after "(".
Yep, you are right. Fixed.
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;
If ALE/CLE is sticky in the hardware mode register, you could probably move this under NAND_CTRL_CHANGE and simplify things a little.
I try this out.
diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h index 811ba88..4de0dfc 100644 --- a/include/configs/kmeter1.h +++ b/include/configs/kmeter1.h @@ -324,6 +324,12 @@ #define CONFIG_SYS_DTT_HYSTERESIS 3 #define CONFIG_SYS_DTT_BUS_NUM (CONFIG_SYS_MAX_I2C_BUS)
+#if defined(CONFIG_CMD_NAND) +#define CONFIG_NAND_KMETER1
No tab after #define.
fixed.
+#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_BASE CONFIG_SYS_PIGGY_BASE +#endif
#if defined(CONFIG_PCI) #define CONFIG_CMD_PCI #endif
This file looks a little different in the current tree (2 rather than CONFIG_SYS_MAX_I2C_BUS), so it wouldn't apply cleanly.
Hmm... this is the third patch of a patchset, so it apply cleanly, if the other 2 patches are first applied ... or should I base this patch against current nand-flash tree, because this patch goes through your tree?
thanks for reviewing Heiko

On Fri, Jul 17, 2009 at 07:05:03AM +0200, Heiko Schocher wrote:
Hmm... this is the third patch of a patchset, so it apply cleanly, if the other 2 patches are first applied ... or should I base this patch against current nand-flash tree, because this patch goes through your tree?
Ah, I missed that. It's generally preferred, when possible, to not mix custodians in a single patchset -- if you can separate out the NAND driver into its own standalone patch (that doesn't touch any board configs), that'd be ideal. Otherwise, it'll have to wait until the prerequisite patches are merged (or at least acked) by the relevant custodian.
-Scott

Hello Scott,
Scott Wood wrote:
On Fri, Jul 17, 2009 at 07:05:03AM +0200, Heiko Schocher wrote:
Hmm... this is the third patch of a patchset, so it apply cleanly, if the other 2 patches are first applied ... or should I base this patch against current nand-flash tree, because this patch goes through your tree?
Ah, I missed that. It's generally preferred, when possible, to not mix custodians in a single patchset -- if you can separate out the NAND driver into its own standalone patch (that doesn't touch any board configs), that'd be ideal. Otherwise, it'll have to wait until the
Hmm.. because it is for the kmeter1 (83xx) based board, it touches also this config file ...
prerequisite patches are merged (or at least acked) by the relevant custodian.
I prefer this way. If this is OK for you I can send a new patch, with your suggestions included ...
bye Heiko

Signed-off-by: Heiko Schocher hs@denx.de --- - changes since v1: moved the nand driver to drivers/mtd/nand/kmeter1_nand.c as Stefan Roese suggested
- changes since v2: added comments from Stefan Roese - drivers/mtd/nand/kmeter1_nand.c only gets compiled if CONFIG_NAND_KMETER1 is set in board config file - Fix Coding Style issue
- changes since v3: added comments from Scott Wood - Coding Style issues - simplified accessor defines - simplified kpn_nand_hwcontrol() - rebased against current head
drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/kmeter1_nand.c | 135 +++++++++++++++++++++++++++++++++++++++ include/configs/kmeter1.h | 6 ++ 3 files changed, 142 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/kmeter1_nand.c
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index 89ccec2..d8e137b 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -39,6 +39,7 @@ COBJS-$(CONFIG_NAND_DAVINCI) += davinci_nand.o COBJS-$(CONFIG_NAND_FSL_ELBC) += fsl_elbc_nand.o COBJS-$(CONFIG_NAND_FSL_UPM) += fsl_upm.o COBJS-$(CONFIG_NAND_KIRKWOOD) += kirkwood_nand.o +COBJS-$(CONFIG_NAND_KMETER1) += kmeter1_nand.o COBJS-$(CONFIG_NAND_MPC5121_NFC) += mpc5121_nfc.o COBJS-$(CONFIG_NAND_NDFC) += ndfc.o COBJS-$(CONFIG_NAND_NOMADIK) += nomadik.o diff --git a/drivers/mtd/nand/kmeter1_nand.c b/drivers/mtd/nand/kmeter1_nand.c new file mode 100644 index 0000000..e8e5b7b --- /dev/null +++ b/drivers/mtd/nand/kmeter1_nand.c @@ -0,0 +1,135 @@ +/* + * (C) Copyright 2009 + * Heiko Schocher, DENX Software Engineering, hs@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> +#include <nand.h> +#include <asm/io.h> + +#define CONFIG_NAND_MODE_REG (void *)(CONFIG_SYS_NAND_BASE + 0x20000) +#define CONFIG_NAND_DATA_REG (void *)(CONFIG_SYS_NAND_BASE + 0x30000) + +#define read_mode() in_8(CONFIG_NAND_MODE_REG) +#define write_mode(val) out_8(CONFIG_NAND_MODE_REG, val) +#define read_data() in_8(CONFIG_NAND_DATA_REG) +#define write_data(val) out_8(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) { + 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; + 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) + write_data(cmd); + + /* 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(); +} + +static int kpn_nand_dev_ready(struct mtd_info *mtd) +{ + kpn_wait_rdy(); + + return 1; +} + +int board_nand_init(struct nand_chip *nand) +{ + nand->ecc.mode = NAND_ECC_SOFT; + + /* Reference hardware control function */ + nand->cmd_ctrl = kpn_nand_hwcontrol; + nand->read_byte = kpn_nand_read_byte; + nand->write_buf = kpn_nand_write_buf; + nand->read_buf = kpn_nand_read_buf; + nand->dev_ready = kpn_nand_dev_ready; + nand->chip_delay = KPN_DEFAULT_CHIP_DELAY; + + /* reset mode register */ + write_mode(KPN_CE1N + KPN_CE2N + KPN_WPN); + return 0; +} diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h index 869fd4c..79d8638 100644 --- a/include/configs/kmeter1.h +++ b/include/configs/kmeter1.h @@ -324,6 +324,12 @@ #define CONFIG_SYS_DTT_HYSTERESIS 3 #define CONFIG_SYS_DTT_BUS_NUM (CONFIG_SYS_MAX_I2C_BUS)
+#if defined(CONFIG_CMD_NAND) +#define CONFIG_NAND_KMETER1 +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_BASE CONFIG_SYS_PIGGY_BASE +#endif + #if defined(CONFIG_PCI) #define CONFIG_CMD_PCI #endif

On Tue, Jul 21, 2009 at 05:13:40PM +0200, Heiko Schocher wrote:
Signed-off-by: Heiko Schocher hs@denx.de
Applied to u-boot-nand-flash/next
-Scott
participants (4)
-
Heiko Schocher
-
Heiko Schocher
-
Scott Wood
-
Stefan Roese