1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#include <common.h>
16#include <linux/mtd/nand.h>
17#include <asm/io.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/arch/mem.h>
20
21static struct gpmc *gpmc_config = (struct gpmc *)GPMC_BASE;
22
23
24static void nand_command(u8 command)
25{
26 writeb(command, &gpmc_config->cs[0].nand_cmd);
27
28 if (command == NAND_CMD_RESET) {
29 unsigned char ret_val;
30 writeb(NAND_CMD_STATUS, &gpmc_config->cs[0].nand_cmd);
31 do {
32
33 ret_val = readl(&gpmc_config->cs[0].nand_dat);
34 } while ((ret_val & NAND_STATUS_READY) != NAND_STATUS_READY);
35 }
36}
37
38
39
40
41
42
43
44void identify_nand_chip(int *mfr, int *id)
45{
46
47 writel(M_NAND_GPMC_CONFIG1, &gpmc_config->cs[0].config1);
48 writel(M_NAND_GPMC_CONFIG2, &gpmc_config->cs[0].config2);
49 writel(M_NAND_GPMC_CONFIG3, &gpmc_config->cs[0].config3);
50 writel(M_NAND_GPMC_CONFIG4, &gpmc_config->cs[0].config4);
51 writel(M_NAND_GPMC_CONFIG5, &gpmc_config->cs[0].config5);
52 writel(M_NAND_GPMC_CONFIG6, &gpmc_config->cs[0].config6);
53
54
55
56
57
58 writel((GPMC_SIZE_128M << 8) | (GPMC_CS_ENABLE << 6) |
59 ((NAND_BASE >> 24) & GPMC_BASEADDR_MASK),
60 &gpmc_config->cs[0].config7);
61
62 sdelay(2000);
63
64
65 nand_command(NAND_CMD_RESET);
66 nand_command(NAND_CMD_READID);
67
68
69 writeb(0x0, &gpmc_config->cs[0].nand_adr);
70
71
72 *mfr = readb(&gpmc_config->cs[0].nand_dat);
73 *id = readb(&gpmc_config->cs[0].nand_dat);
74}
75