1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <common.h>
28
29#if defined(CONFIG_CMD_NAND)
30
31#include <asm/processor.h>
32#include <nand.h>
33
34struct alpr_ndfc_regs {
35 u8 cmd[4];
36 u8 addr_wait;
37 u8 term;
38 u8 dummy;
39 u8 dummy2;
40 u8 data;
41};
42
43static u8 hwctl;
44static struct alpr_ndfc_regs *alpr_ndfc = NULL;
45
46#define readb(addr) (u8)(*(volatile u8 *)(addr))
47#define writeb(d,addr) *(volatile u8 *)(addr) = ((u8)(d))
48
49
50
51
52
53
54
55
56
57
58
59static void alpr_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
60{
61 struct nand_chip *this = mtd->priv;
62
63 if (ctrl & NAND_CTRL_CHANGE) {
64 if ( ctrl & NAND_CLE )
65 hwctl |= 0x1;
66 else
67 hwctl &= ~0x1;
68 if ( ctrl & NAND_ALE )
69 hwctl |= 0x2;
70 else
71 hwctl &= ~0x2;
72 if ( (ctrl & NAND_NCE) != NAND_NCE)
73 writeb(0x00, &(alpr_ndfc->term));
74 }
75 if (cmd != NAND_CMD_NONE)
76 writeb(cmd, this->IO_ADDR_W);
77}
78
79static u_char alpr_nand_read_byte(struct mtd_info *mtd)
80{
81 return readb(&(alpr_ndfc->data));
82}
83
84static void alpr_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
85{
86 struct nand_chip *nand = mtd->priv;
87 int i;
88
89 for (i = 0; i < len; i++) {
90 if (hwctl & 0x1)
91
92
93
94
95 writeb(buf[i], nand->IO_ADDR_W);
96 else if (hwctl & 0x2)
97 writeb(buf[i], &(alpr_ndfc->addr_wait));
98 else
99 writeb(buf[i], &(alpr_ndfc->data));
100 }
101}
102
103static void alpr_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
104{
105 int i;
106
107 for (i = 0; i < len; i++) {
108 buf[i] = readb(&(alpr_ndfc->data));
109 }
110}
111
112static int alpr_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len)
113{
114 int i;
115
116 for (i = 0; i < len; i++)
117 if (buf[i] != readb(&(alpr_ndfc->data)))
118 return i;
119
120 return 0;
121}
122
123static int alpr_nand_dev_ready(struct mtd_info *mtd)
124{
125 volatile u_char val;
126
127
128
129
130 val = readb(&(alpr_ndfc->addr_wait));
131
132
133
134
135 return 1;
136}
137
138int board_nand_init(struct nand_chip *nand)
139{
140 alpr_ndfc = (struct alpr_ndfc_regs *)CONFIG_SYS_NAND_BASE;
141
142 nand->ecc.mode = NAND_ECC_SOFT;
143
144
145 nand->cmd_ctrl = alpr_nand_hwcontrol;
146 nand->read_byte = alpr_nand_read_byte;
147 nand->write_buf = alpr_nand_write_buf;
148 nand->read_buf = alpr_nand_read_buf;
149 nand->verify_buf = alpr_nand_verify_buf;
150 nand->dev_ready = alpr_nand_dev_ready;
151
152 return 0;
153}
154#endif
155