Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | |
Jon Loeliger | ab3abcb | 2007-07-09 18:45:16 -0500 | [diff] [blame] | 10 | #if defined(CONFIG_CMD_NAND) |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 11 | |
| 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 | |
| 23 | static void *sc3_io_base; |
| 24 | static void *sc3_control_base = (void *)0xEF600700; |
| 25 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 26 | static void sc3_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 27 | { |
William Juul | 5e1dae5 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 28 | struct nand_chip *this = mtd->priv; |
| 29 | if (ctrl & NAND_CTRL_CHANGE) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 30 | if ( ctrl & NAND_CLE ) |
| 31 | set_bit (SC3_NAND_CLE, sc3_control_base); |
| 32 | else |
William Juul | 4cbb651 | 2007-11-08 10:39:53 +0100 | [diff] [blame] | 33 | clear_bit (SC3_NAND_CLE, sc3_control_base); |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 34 | 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 Juul | 4cbb651 | 2007-11-08 10:39:53 +0100 | [diff] [blame] | 41 | clear_bit (SC3_NAND_CE, sc3_control_base); |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 42 | } |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 43 | |
William Juul | 5e1dae5 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 44 | if (cmd != NAND_CMD_NONE) |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 45 | writeb(cmd, this->IO_ADDR_W); |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static 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 | |
| 55 | static void sc3_select_chip(struct mtd_info *mtd, int chip) |
| 56 | { |
| 57 | clear_bit (SC3_NAND_CE, sc3_control_base); |
| 58 | } |
| 59 | |
| 60 | int board_nand_init(struct nand_chip *nand) |
| 61 | { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 62 | nand->ecc.mode = NAND_ECC_SOFT; |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 63 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 64 | sc3_io_base = (void *) CONFIG_SYS_NAND_BASE; |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 65 | /* 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 Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 69 | nand->cmd_ctrl = sc3_nand_hwcontrol; |
Wolfgang Denk | f11033e | 2007-01-15 13:41:04 +0100 | [diff] [blame] | 70 | nand->dev_ready = sc3_nand_dev_ready; |
| 71 | nand->select_chip = sc3_select_chip; |
| 72 | return 0; |
| 73 | } |
| 74 | #endif |