blob: a250d61ef3685cdf0943a37e9336a0db3cd1d039 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewec8468f2007-08-05 04:31:18 -05002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang35d23df2012-03-26 21:49:05 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewec8468f2007-08-05 04:31:18 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewec8468f2007-08-05 04:31:18 -05008 */
9
10#include <config.h>
TsiChungLiewec8468f2007-08-05 04:31:18 -050011#include <asm/io.h>
12#include <asm/immap.h>
13
TsiChungLiewaedd3d72007-08-15 15:39:17 -050014#if defined(CONFIG_CMD_NAND)
TsiChungLiewec8468f2007-08-05 04:31:18 -050015#include <nand.h>
16#include <linux/mtd/mtd.h>
Tom Rini3bde7e22021-09-22 14:50:35 -040017#include <linux/mtd/rawnand.h>
TsiChungLiewec8468f2007-08-05 04:31:18 -050018
Stefan Roeseeb8c2942007-08-08 09:54:26 +020019#define SET_CLE 0x10
Stefan Roeseeb8c2942007-08-08 09:54:26 +020020#define SET_ALE 0x08
TsiChungLiewec8468f2007-08-05 04:31:18 -050021
TsiChung Liew476f6bc2008-10-24 12:59:12 +000022static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
TsiChungLiewec8468f2007-08-05 04:31:18 -050023{
Scott Wood17fed142016-05-30 13:57:56 -050024 struct nand_chip *this = mtd_to_nand(mtdinfo);
Tom Rini6a5dccc2022-11-16 13:10:41 -050025 volatile u16 *nCE = (u16 *) CFG_SYS_LATCH_ADDR;
TsiChungLiewec8468f2007-08-05 04:31:18 -050026
William Juul52c07962007-10-31 13:53:06 +010027 if (ctrl & NAND_CTRL_CHANGE) {
TsiChung Liew476f6bc2008-10-24 12:59:12 +000028 ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
William Juul52c07962007-10-31 13:53:06 +010029
TsiChung Liew476f6bc2008-10-24 12:59:12 +000030 IO_ADDR_W &= ~(SET_ALE | SET_CLE);
TsiChungLiewec8468f2007-08-05 04:31:18 -050031
TsiChung Liew476f6bc2008-10-24 12:59:12 +000032 if (ctrl & NAND_NCE)
TsiChung Liew64979662009-03-02 19:16:45 +000033 *nCE &= 0xFFFB;
34 else
TsiChung Liew476f6bc2008-10-24 12:59:12 +000035 *nCE |= 0x0004;
TsiChung Liew64979662009-03-02 19:16:45 +000036
TsiChung Liew476f6bc2008-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;
TsiChungLiewec8468f2007-08-05 04:31:18 -050041
TsiChung Liew476f6bc2008-10-24 12:59:12 +000042 this->IO_ADDR_W = (void *)IO_ADDR_W;
43 }
TsiChungLiewec8468f2007-08-05 04:31:18 -050044
TsiChung Liew476f6bc2008-10-24 12:59:12 +000045 if (cmd != NAND_CMD_NONE)
46 writeb(cmd, this->IO_ADDR_W);
TsiChungLiewec8468f2007-08-05 04:31:18 -050047}
48
49int board_nand_init(struct nand_chip *nand)
50{
Alison Wang35d23df2012-03-26 21:49:05 +000051 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
TsiChungLiewec8468f2007-08-05 04:31:18 -050052
TsiChung Liew476f6bc2008-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 Wang35d23df2012-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);
TsiChungLiewec8468f2007-08-05 04:31:18 -050063
TsiChung Liew64979662009-03-02 19:16:45 +000064 nand->chip_delay = 60;
William Juul52c07962007-10-31 13:53:06 +010065 nand->ecc.mode = NAND_ECC_SOFT;
66 nand->cmd_ctrl = nand_hwcontrol;
TsiChungLiewec8468f2007-08-05 04:31:18 -050067
Stefan Roeseeb8c2942007-08-08 09:54:26 +020068 return 0;
TsiChungLiewec8468f2007-08-05 04:31:18 -050069}
70#endif