blob: 84a0b0ade931956883cc639a9b820ef08d502a31 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tom Rini037e2e32011-11-18 12:48:07 +00002/*
3 * (C) Copyright 2011
4 * Texas Instruments, <www.ti.com>
5 *
6 * Author :
7 * Tom Rini <trini@ti.com>
8 *
9 * Initial Code from:
10 * Richard Woodruff <r-woodruff2@ti.com>
11 * Jian Zhang <jzhang@ti.com>
Tom Rini037e2e32011-11-18 12:48:07 +000012 */
13
14#include <common.h>
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020015#include <jffs2/load_kernel.h>
Masahiro Yamada2b7a8732017-11-30 13:45:24 +090016#include <linux/mtd/rawnand.h>
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020017#include <linux/mtd/omap_gpmc.h>
Tom Rini037e2e32011-11-18 12:48:07 +000018#include <asm/io.h>
19#include <asm/arch/sys_proto.h>
20#include <asm/arch/mem.h>
21
Tom Rini037e2e32011-11-18 12:48:07 +000022/*
23 * Many boards will want to know the results of the NAND_CMD_READID command
24 * in order to decide what to do about DDR initialization. This function
25 * allows us to do that very early and to pass those results back to the
26 * board so it can make whatever decisions need to be made.
27 */
Ladislav Michl4852b352016-07-12 20:28:15 +020028int identify_nand_chip(int *mfr, int *id)
Tom Rini037e2e32011-11-18 12:48:07 +000029{
Ladislav Michl4852b352016-07-12 20:28:15 +020030 int loops = 1000;
31
Tom Rini037e2e32011-11-18 12:48:07 +000032 /* Make sure that we have setup GPMC for NAND correctly. */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020033 set_gpmc_cs0(MTD_DEV_TYPE_NAND);
Tom Rini037e2e32011-11-18 12:48:07 +000034
35 sdelay(2000);
36
37 /* Issue a RESET and then READID */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020038 writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd);
39 writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd);
40 while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY)
41 != NAND_STATUS_READY) {
Ladislav Michl4852b352016-07-12 20:28:15 +020042 sdelay(100);
43 if (--loops == 0)
44 return 1;
45 }
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020046 writeb(NAND_CMD_READID, &gpmc_cfg->cs[0].nand_cmd);
Tom Rini037e2e32011-11-18 12:48:07 +000047
48 /* Set the address to read to 0x0 */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020049 writeb(0x0, &gpmc_cfg->cs[0].nand_adr);
Tom Rini037e2e32011-11-18 12:48:07 +000050
51 /* Read off the manufacturer and device id. */
Ladislav Michlfe4bc3d2016-07-12 20:28:18 +020052 *mfr = readb(&gpmc_cfg->cs[0].nand_dat);
53 *id = readb(&gpmc_cfg->cs[0].nand_dat);
Ladislav Michl4852b352016-07-12 20:28:15 +020054
55 return 0;
Tom Rini037e2e32011-11-18 12:48:07 +000056}