blob: 4fc34d6b9fca6d7b41ff44f52912da85532d1b9b [file] [log] [blame]
Prafulla Wadaskar205a0982009-06-29 15:25:18 +05301/*
2 * (C) Copyright 2009
3 * Marvell Semiconductor <www.marvell.com>
4 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar205a0982009-06-29 15:25:18 +05307 */
8
9#include <common.h>
10#include <asm/io.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020011#include <asm/arch/soc.h>
Prafulla Wadaskar205a0982009-06-29 15:25:18 +053012#include <nand.h>
13
14/* NAND Flash Soc registers */
15struct kwnandf_registers {
16 u32 rd_params; /* 0x10418 */
17 u32 wr_param; /* 0x1041c */
18 u8 pad[0x10470 - 0x1041c - 4];
19 u32 ctrl; /* 0x10470 */
20};
21
22static struct kwnandf_registers *nf_reg =
23 (struct kwnandf_registers *)KW_NANDF_BASE;
24
25/*
26 * hardware specific access to control-lines/bits
27 */
28#define NAND_ACTCEBOOT_BIT 0x02
29
30static void kw_nand_hwcontrol(struct mtd_info *mtd, int cmd,
31 unsigned int ctrl)
32{
33 struct nand_chip *nc = mtd->priv;
34 u32 offs;
35
36 if (cmd == NAND_CMD_NONE)
37 return;
38
39 if (ctrl & NAND_CLE)
40 offs = (1 << 0); /* Commands with A[1:0] == 01 */
41 else if (ctrl & NAND_ALE)
42 offs = (1 << 1); /* Addresses with A[1:0] == 10 */
43 else
44 return;
45
46 writeb(cmd, nc->IO_ADDR_W + offs);
47}
48
49void kw_nand_select_chip(struct mtd_info *mtd, int chip)
50{
51 u32 data;
52
53 data = readl(&nf_reg->ctrl);
54 data |= NAND_ACTCEBOOT_BIT;
55 writel(data, &nf_reg->ctrl);
56}
57
58int board_nand_init(struct nand_chip *nand)
59{
60 nand->options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING;
Holger Brunck292221e2014-08-15 10:51:47 +020061#if defined(CONFIG_SYS_NAND_NO_SUBPAGE_WRITE)
62 nand->options |= NAND_NO_SUBPAGE_WRITE;
63#endif
Gerlando Falauto7070b552013-01-15 22:34:28 +000064#if defined(CONFIG_NAND_ECC_BCH)
65 nand->ecc.mode = NAND_ECC_SOFT_BCH;
66#else
Prafulla Wadaskar205a0982009-06-29 15:25:18 +053067 nand->ecc.mode = NAND_ECC_SOFT;
Gerlando Falauto7070b552013-01-15 22:34:28 +000068#endif
Prafulla Wadaskar205a0982009-06-29 15:25:18 +053069 nand->cmd_ctrl = kw_nand_hwcontrol;
Stefan Bigler15680092011-07-18 15:25:11 +020070 nand->chip_delay = 40;
Prafulla Wadaskar205a0982009-06-29 15:25:18 +053071 nand->select_chip = kw_nand_select_chip;
72 return 0;
73}