2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-11-18 12:48:07 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2011
|
|
|
|
* Texas Instruments, <www.ti.com>
|
|
|
|
*
|
|
|
|
* Author :
|
|
|
|
* Tom Rini <trini@ti.com>
|
|
|
|
*
|
|
|
|
* Initial Code from:
|
|
|
|
* Richard Woodruff <r-woodruff2@ti.com>
|
|
|
|
* Jian Zhang <jzhang@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-07-12 18:28:18 +00:00
|
|
|
#include <jffs2/load_kernel.h>
|
2017-11-30 04:45:24 +00:00
|
|
|
#include <linux/mtd/rawnand.h>
|
2016-07-12 18:28:18 +00:00
|
|
|
#include <linux/mtd/omap_gpmc.h>
|
2011-11-18 12:48:07 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
#include <asm/arch/mem.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Many boards will want to know the results of the NAND_CMD_READID command
|
|
|
|
* in order to decide what to do about DDR initialization. This function
|
|
|
|
* allows us to do that very early and to pass those results back to the
|
|
|
|
* board so it can make whatever decisions need to be made.
|
|
|
|
*/
|
2016-07-12 18:28:15 +00:00
|
|
|
int identify_nand_chip(int *mfr, int *id)
|
2011-11-18 12:48:07 +00:00
|
|
|
{
|
2016-07-12 18:28:15 +00:00
|
|
|
int loops = 1000;
|
|
|
|
|
2011-11-18 12:48:07 +00:00
|
|
|
/* Make sure that we have setup GPMC for NAND correctly. */
|
2016-07-12 18:28:18 +00:00
|
|
|
set_gpmc_cs0(MTD_DEV_TYPE_NAND);
|
2011-11-18 12:48:07 +00:00
|
|
|
|
|
|
|
sdelay(2000);
|
|
|
|
|
|
|
|
/* Issue a RESET and then READID */
|
2016-07-12 18:28:18 +00:00
|
|
|
writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd);
|
|
|
|
writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd);
|
|
|
|
while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY)
|
|
|
|
!= NAND_STATUS_READY) {
|
2016-07-12 18:28:15 +00:00
|
|
|
sdelay(100);
|
|
|
|
if (--loops == 0)
|
|
|
|
return 1;
|
|
|
|
}
|
2016-07-12 18:28:18 +00:00
|
|
|
writeb(NAND_CMD_READID, &gpmc_cfg->cs[0].nand_cmd);
|
2011-11-18 12:48:07 +00:00
|
|
|
|
|
|
|
/* Set the address to read to 0x0 */
|
2016-07-12 18:28:18 +00:00
|
|
|
writeb(0x0, &gpmc_cfg->cs[0].nand_adr);
|
2011-11-18 12:48:07 +00:00
|
|
|
|
|
|
|
/* Read off the manufacturer and device id. */
|
2016-07-12 18:28:18 +00:00
|
|
|
*mfr = readb(&gpmc_cfg->cs[0].nand_dat);
|
|
|
|
*id = readb(&gpmc_cfg->cs[0].nand_dat);
|
2016-07-12 18:28:15 +00:00
|
|
|
|
|
|
|
return 0;
|
2011-11-18 12:48:07 +00:00
|
|
|
}
|