blob: 0e2f0a2f6d67127537a9b5256b744d3ce3cc507e [file] [log] [blame]
Tom Rini037e2e32011-11-18 12:48:07 +00001/*
2 * (C) Copyright 2011
3 * Texas Instruments, <www.ti.com>
4 *
5 * Author :
6 * Tom Rini <trini@ti.com>
7 *
8 * Initial Code from:
9 * Richard Woodruff <r-woodruff2@ti.com>
10 * Jian Zhang <jzhang@ti.com>
11 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020012 * SPDX-License-Identifier: GPL-2.0+
Tom Rini037e2e32011-11-18 12:48:07 +000013 */
14
15#include <common.h>
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020016#include <jffs2/load_kernel.h>
Tom Rini037e2e32011-11-18 12:48:07 +000017#include <linux/mtd/nand.h>
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020018#include <linux/mtd/omap_gpmc.h>
Tom Rini037e2e32011-11-18 12:48:07 +000019#include <asm/io.h>
20#include <asm/arch/sys_proto.h>
21#include <asm/arch/mem.h>
22
Tom Rini037e2e32011-11-18 12:48:07 +000023/*
24 * Many boards will want to know the results of the NAND_CMD_READID command
25 * in order to decide what to do about DDR initialization. This function
26 * allows us to do that very early and to pass those results back to the
27 * board so it can make whatever decisions need to be made.
28 */
Ladislav Michl4852b352016-07-12 20:28:15 +020029int identify_nand_chip(int *mfr, int *id)
Tom Rini037e2e32011-11-18 12:48:07 +000030{
Ladislav Michl4852b352016-07-12 20:28:15 +020031 int loops = 1000;
32
Tom Rini037e2e32011-11-18 12:48:07 +000033 /* Make sure that we have setup GPMC for NAND correctly. */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020034 set_gpmc_cs0(MTD_DEV_TYPE_NAND);
Tom Rini037e2e32011-11-18 12:48:07 +000035
36 sdelay(2000);
37
38 /* Issue a RESET and then READID */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020039 writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd);
40 writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd);
41 while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY)
42 != NAND_STATUS_READY) {
Ladislav Michl4852b352016-07-12 20:28:15 +020043 sdelay(100);
44 if (--loops == 0)
45 return 1;
46 }
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020047 writeb(NAND_CMD_READID, &gpmc_cfg->cs[0].nand_cmd);
Tom Rini037e2e32011-11-18 12:48:07 +000048
49 /* Set the address to read to 0x0 */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020050 writeb(0x0, &gpmc_cfg->cs[0].nand_adr);
Tom Rini037e2e32011-11-18 12:48:07 +000051
52 /* Read off the manufacturer and device id. */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020053 *mfr = readb(&gpmc_cfg->cs[0].nand_dat);
54 *id = readb(&gpmc_cfg->cs[0].nand_dat);
Ladislav Michl4852b352016-07-12 20:28:15 +020055
56 return 0;
Tom Rini037e2e32011-11-18 12:48:07 +000057}