Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 2 | /* |
| 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 Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 14 | #include <jffs2/load_kernel.h> |
Masahiro Yamada | 2b7a873 | 2017-11-30 13:45:24 +0900 | [diff] [blame] | 15 | #include <linux/mtd/rawnand.h> |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 16 | #include <linux/mtd/omap_gpmc.h> |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | #include <asm/arch/sys_proto.h> |
| 19 | #include <asm/arch/mem.h> |
| 20 | |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 21 | /* |
| 22 | * Many boards will want to know the results of the NAND_CMD_READID command |
| 23 | * in order to decide what to do about DDR initialization. This function |
| 24 | * allows us to do that very early and to pass those results back to the |
| 25 | * board so it can make whatever decisions need to be made. |
| 26 | */ |
Ladislav Michl | 4852b35 | 2016-07-12 20:28:15 +0200 | [diff] [blame] | 27 | int identify_nand_chip(int *mfr, int *id) |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 28 | { |
Ladislav Michl | 4852b35 | 2016-07-12 20:28:15 +0200 | [diff] [blame] | 29 | int loops = 1000; |
| 30 | |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 31 | /* Make sure that we have setup GPMC for NAND correctly. */ |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 32 | set_gpmc_cs0(MTD_DEV_TYPE_NAND); |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 33 | |
| 34 | sdelay(2000); |
| 35 | |
| 36 | /* Issue a RESET and then READID */ |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 37 | writeb(NAND_CMD_RESET, &gpmc_cfg->cs[0].nand_cmd); |
| 38 | writeb(NAND_CMD_STATUS, &gpmc_cfg->cs[0].nand_cmd); |
| 39 | while ((readl(&gpmc_cfg->cs[0].nand_dat) & NAND_STATUS_READY) |
| 40 | != NAND_STATUS_READY) { |
Ladislav Michl | 4852b35 | 2016-07-12 20:28:15 +0200 | [diff] [blame] | 41 | sdelay(100); |
| 42 | if (--loops == 0) |
| 43 | return 1; |
| 44 | } |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 45 | writeb(NAND_CMD_READID, &gpmc_cfg->cs[0].nand_cmd); |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 46 | |
| 47 | /* Set the address to read to 0x0 */ |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 48 | writeb(0x0, &gpmc_cfg->cs[0].nand_adr); |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 49 | |
| 50 | /* Read off the manufacturer and device id. */ |
Ladislav Michl | fe4bc3d | 2016-07-12 20:28:18 +0200 | [diff] [blame] | 51 | *mfr = readb(&gpmc_cfg->cs[0].nand_dat); |
| 52 | *id = readb(&gpmc_cfg->cs[0].nand_dat); |
Ladislav Michl | 4852b35 | 2016-07-12 20:28:15 +0200 | [diff] [blame] | 53 | |
| 54 | return 0; |
Tom Rini | 037e2e3 | 2011-11-18 12:48:07 +0000 | [diff] [blame] | 55 | } |