blob: 4c30d5100181339984f155c50ca4744bb80b4e99 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiew1ac559d2008-01-14 17:19:54 -06002/*
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.
TsiChungLiew1ac559d2008-01-14 17:19:54 -06007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiew1ac559d2008-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
TsiChungLiew1ac559d2008-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
TsiChungLiew1ac559d2008-01-14 17:19:54 -060020#define SET_ALE 0x08
TsiChungLiew1ac559d2008-01-14 17:19:54 -060021
Scott Woodf64cb652008-08-13 17:53:48 -050022static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
TsiChungLiew1ac559d2008-01-14 17:19:54 -060023{
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;
TsiChungLiew1ac559d2008-01-14 17:19:54 -060026
Scott Woodf64cb652008-08-13 17:53:48 -050027 if (ctrl & NAND_CTRL_CHANGE) {
28 ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
Scott Woodf64cb652008-08-13 17:53:48 -050029
TsiChung Liewe4f69d12008-10-24 12:59:12 +000030 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
Scott Woodf64cb652008-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;
41
Scott Woodf64cb652008-08-13 17:53:48 -050042 this->IO_ADDR_W = (void *)IO_ADDR_W;
43
TsiChungLiew1ac559d2008-01-14 17:19:54 -060044 }
TsiChungLiew1ac559d2008-01-14 17:19:54 -060045
Scott Woodf64cb652008-08-13 17:53:48 -050046 if (cmd != NAND_CMD_NONE)
47 writeb(cmd, this->IO_ADDR_W);
TsiChungLiew1ac559d2008-01-14 17:19:54 -060048}
49
50int board_nand_init(struct nand_chip *nand)
51{
Alison Wangaa0d99f2012-03-26 21:49:05 +000052 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
53 fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
TsiChungLiew1ac559d2008-01-14 17:19:54 -060054
Alison Wangaa0d99f2012-03-26 21:49:05 +000055 clrbits_be32(&fbcs->csmr2, FBCS_CSMR_WP);
TsiChungLiew1ac559d2008-01-14 17:19:54 -060056
TsiChung Liewe4f69d12008-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 Wangaa0d99f2012-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);
TsiChungLiew1ac559d2008-01-14 17:19:54 -060067
TsiChung Liew9017d932009-03-02 19:16:45 +000068 nand->chip_delay = 60;
Scott Woodf64cb652008-08-13 17:53:48 -050069 nand->ecc.mode = NAND_ECC_SOFT;
70 nand->cmd_ctrl = nand_hwcontrol;
TsiChungLiew1ac559d2008-01-14 17:19:54 -060071
72 return 0;
73}
74#endif