blob: 4c30d5100181339984f155c50ca4744bb80b4e99 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewf7d060c2008-01-14 17:19:54 -06002/*
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.
TsiChungLiewf7d060c2008-01-14 17:19:54 -06007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewf7d060c2008-01-14 17:19:54 -06008 */
9
10#include <config.h>
11#include <common.h>
12#include <asm/io.h>
13#include <asm/immap.h>
14
TsiChungLiewf7d060c2008-01-14 17:19:54 -060015#if defined(CONFIG_CMD_NAND)
16#include <nand.h>
17#include <linux/mtd/mtd.h>
18
19#define SET_CLE 0x10
TsiChungLiewf7d060c2008-01-14 17:19:54 -060020#define SET_ALE 0x08
TsiChungLiewf7d060c2008-01-14 17:19:54 -060021
Scott Woodfdda9462008-08-13 17:53:48 -050022static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
TsiChungLiewf7d060c2008-01-14 17:19:54 -060023{
Scott Wood17fed142016-05-30 13:57:56 -050024 struct nand_chip *this = mtd_to_nand(mtdinfo);
TsiChung Liew476f6bc2008-10-24 12:59:12 +000025 volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060026
Scott Woodfdda9462008-08-13 17:53:48 -050027 if (ctrl & NAND_CTRL_CHANGE) {
28 ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060029
TsiChung Liew476f6bc2008-10-24 12:59:12 +000030 IO_ADDR_W &= ~(SET_ALE | SET_CLE);
TsiChung Liew476f6bc2008-10-24 12:59:12 +000031
32 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
Scott Woodfdda9462008-08-13 17:53:48 -050037 if (ctrl & NAND_CLE)
38 IO_ADDR_W |= SET_CLE;
39 if (ctrl & NAND_ALE)
40 IO_ADDR_W |= SET_ALE;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060041
Scott Woodfdda9462008-08-13 17:53:48 -050042 this->IO_ADDR_W = (void *)IO_ADDR_W;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060043
Scott Woodfdda9462008-08-13 17:53:48 -050044 }
45
46 if (cmd != NAND_CMD_NONE)
47 writeb(cmd, this->IO_ADDR_W);
TsiChungLiewf7d060c2008-01-14 17:19:54 -060048}
49
50int board_nand_init(struct nand_chip *nand)
51{
Alison Wang35d23df2012-03-26 21:49:05 +000052 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
53 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060054
Alison Wang35d23df2012-03-26 21:49:05 +000055 clrbits_be32(&fbcs->csmr2, FBCS_CSMR_WP);
TsiChungLiewf7d060c2008-01-14 17:19:54 -060056
TsiChung Liew476f6bc2008-10-24 12:59:12 +000057 /*
58 * set up pin configuration - enabled 2nd output buffer's signals
59 * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
60 * to use nCE signal
61 */
Alison Wang35d23df2012-03-26 21:49:05 +000062 clrbits_8(&gpio->par_timer, GPIO_PAR_TIN3_TIN3);
63 setbits_8(&gpio->pddr_timer, 0x08);
64 setbits_8(&gpio->ppd_timer, 0x08);
65 out_8(&gpio->pclrr_timer, 0);
66 out_8(&gpio->podr_timer, 0);
TsiChungLiewf7d060c2008-01-14 17:19:54 -060067
TsiChung Liew64979662009-03-02 19:16:45 +000068 nand->chip_delay = 60;
Scott Woodfdda9462008-08-13 17:53:48 -050069 nand->ecc.mode = NAND_ECC_SOFT;
70 nand->cmd_ctrl = nand_hwcontrol;
TsiChungLiewf7d060c2008-01-14 17:19:54 -060071
72 return 0;
73}
74#endif