blob: 58b8ee51d37802f8bd40fdb5a44ca4cd2e5ef8a3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiew1a33ce62007-08-05 04:31:18 -05002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangaa0d99f2012-03-26 21:49:05 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew1a33ce62007-08-05 04:31:18 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiew1a33ce62007-08-05 04:31:18 -05008 */
9
10#include <config.h>
11#include <common.h>
12#include <asm/io.h>
13#include <asm/immap.h>
14
TsiChungLiewab77bc52007-08-15 15:39:17 -050015#if defined(CONFIG_CMD_NAND)
TsiChungLiew1a33ce62007-08-05 04:31:18 -050016#include <nand.h>
17#include <linux/mtd/mtd.h>
18
Stefan Roese3ba4c2d2007-08-08 09:54:26 +020019#define SET_CLE 0x10
Stefan Roese3ba4c2d2007-08-08 09:54:26 +020020#define SET_ALE 0x08
TsiChungLiew1a33ce62007-08-05 04:31:18 -050021
TsiChung Liewe4f69d12008-10-24 12:59:12 +000022static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
TsiChungLiew1a33ce62007-08-05 04:31:18 -050023{
Scott Wood17cb4b82016-05-30 13:57:56 -050024 struct nand_chip *this = mtd_to_nand(mtdinfo);
TsiChung Liewe4f69d12008-10-24 12:59:12 +000025 volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050026
William Juulcfa460a2007-10-31 13:53:06 +010027 if (ctrl & NAND_CTRL_CHANGE) {
TsiChung Liewe4f69d12008-10-24 12:59:12 +000028 ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
29
30 IO_ADDR_W &= ~(SET_ALE | SET_CLE);
TsiChung Liewe4f69d12008-10-24 12:59:12 +000031
32 if (ctrl & NAND_NCE)
TsiChung Liew9017d932009-03-02 19:16:45 +000033 *nCE &= 0xFFFB;
34 else
TsiChung Liewe4f69d12008-10-24 12:59:12 +000035 *nCE |= 0x0004;
TsiChung Liew9017d932009-03-02 19:16:45 +000036
TsiChung Liewe4f69d12008-10-24 12:59:12 +000037 if (ctrl & NAND_CLE)
38 IO_ADDR_W |= SET_CLE;
39 if (ctrl & NAND_ALE)
40 IO_ADDR_W |= SET_ALE;
41
42 this->IO_ADDR_W = (void *)IO_ADDR_W;
Stefan Roese3ba4c2d2007-08-08 09:54:26 +020043 }
William Juulcfa460a2007-10-31 13:53:06 +010044
45 if (cmd != NAND_CMD_NONE)
46 writeb(cmd, this->IO_ADDR_W);
TsiChungLiew1a33ce62007-08-05 04:31:18 -050047}
48
TsiChungLiew1a33ce62007-08-05 04:31:18 -050049int board_nand_init(struct nand_chip *nand)
50{
Alison Wangaa0d99f2012-03-26 21:49:05 +000051 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050052
TsiChung Liewe4f69d12008-10-24 12:59:12 +000053 /*
54 * set up pin configuration - enabled 2nd output buffer's signals
55 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
56 * to use nCE signal
57 */
Alison Wangaa0d99f2012-03-26 21:49:05 +000058 clrbits_8(&gpio->par_timer, GPIO_PAR_TIN3_TIN3);
59 setbits_8(&gpio->pddr_timer, 0x08);
60 setbits_8(&gpio->ppd_timer, 0x08);
61 out_8(&gpio->pclrr_timer, 0);
62 out_8(&gpio->podr_timer, 0);
TsiChungLiew1a33ce62007-08-05 04:31:18 -050063
TsiChung Liew9017d932009-03-02 19:16:45 +000064 nand->chip_delay = 60;
William Juulcfa460a2007-10-31 13:53:06 +010065 nand->ecc.mode = NAND_ECC_SOFT;
66 nand->cmd_ctrl = nand_hwcontrol;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050067
Stefan Roese3ba4c2d2007-08-08 09:54:26 +020068 return 0;
TsiChungLiew1a33ce62007-08-05 04:31:18 -050069}
70#endif