blob: a26cd7970f2db185817e37d70fd958d624c00200 [file] [log] [blame]
Wolfgang Denk86370712007-01-15 13:41:04 +01001/*
2 * (C) Copyright 2007
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Wolfgang Denk86370712007-01-15 13:41:04 +01006 */
7
8#include <common.h>
9
Jon Loeligere11c1232007-07-09 18:45:16 -050010#if defined(CONFIG_CMD_NAND)
Wolfgang Denk86370712007-01-15 13:41:04 +010011
12#include <nand.h>
13#include <asm/processor.h>
14
15#define readb(addr) *(volatile u_char *)(addr)
16#define readl(addr) *(volatile u_long *)(addr)
17#define writeb(d,addr) *(volatile u_char *)(addr) = (d)
18
19#define SC3_NAND_ALE 29 /* GPIO PIN 3 */
20#define SC3_NAND_CLE 30 /* GPIO PIN 2 */
21#define SC3_NAND_CE 27 /* GPIO PIN 5 */
22
23static void *sc3_io_base;
24static void *sc3_control_base = (void *)0xEF600700;
25
William Juul52c07962007-10-31 13:53:06 +010026static void sc3_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
Wolfgang Denk86370712007-01-15 13:41:04 +010027{
William Juul9e9c2c12007-11-09 13:32:30 +010028 struct nand_chip *this = mtd->priv;
29 if (ctrl & NAND_CTRL_CHANGE) {
William Juul52c07962007-10-31 13:53:06 +010030 if ( ctrl & NAND_CLE )
31 set_bit (SC3_NAND_CLE, sc3_control_base);
32 else
William Juulb76ec382007-11-08 10:39:53 +010033 clear_bit (SC3_NAND_CLE, sc3_control_base);
William Juul52c07962007-10-31 13:53:06 +010034 if ( ctrl & NAND_ALE )
35 set_bit (SC3_NAND_ALE, sc3_control_base);
36 else
37 clear_bit (SC3_NAND_ALE, sc3_control_base);
38 if ( ctrl & NAND_NCE )
39 set_bit (SC3_NAND_CE, sc3_control_base);
40 else
William Juulb76ec382007-11-08 10:39:53 +010041 clear_bit (SC3_NAND_CE, sc3_control_base);
Wolfgang Denk86370712007-01-15 13:41:04 +010042 }
William Juul52c07962007-10-31 13:53:06 +010043
William Juul9e9c2c12007-11-09 13:32:30 +010044 if (cmd != NAND_CMD_NONE)
William Juul52c07962007-10-31 13:53:06 +010045 writeb(cmd, this->IO_ADDR_W);
Wolfgang Denk86370712007-01-15 13:41:04 +010046}
47
48static int sc3_nand_dev_ready(struct mtd_info *mtd)
49{
50 if (!(readl(sc3_control_base + 0x1C) & 0x4000))
51 return 0;
52 return 1;
53}
54
55static void sc3_select_chip(struct mtd_info *mtd, int chip)
56{
57 clear_bit (SC3_NAND_CE, sc3_control_base);
58}
59
60int board_nand_init(struct nand_chip *nand)
61{
William Juul52c07962007-10-31 13:53:06 +010062 nand->ecc.mode = NAND_ECC_SOFT;
Wolfgang Denk86370712007-01-15 13:41:04 +010063
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 sc3_io_base = (void *) CONFIG_SYS_NAND_BASE;
Wolfgang Denk86370712007-01-15 13:41:04 +010065 /* Set address of NAND IO lines (Using Linear Data Access Region) */
66 nand->IO_ADDR_R = (void __iomem *) sc3_io_base;
67 nand->IO_ADDR_W = (void __iomem *) sc3_io_base;
68 /* Reference hardware control function */
William Juul52c07962007-10-31 13:53:06 +010069 nand->cmd_ctrl = sc3_nand_hwcontrol;
Wolfgang Denk86370712007-01-15 13:41:04 +010070 nand->dev_ready = sc3_nand_dev_ready;
71 nand->select_chip = sc3_select_chip;
72 return 0;
73}
74#endif