1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <ioports.h>
26#include <mpc8260.h>
27
28#include "tqm8272.h"
29
30
31static const uint upmTable67[] =
32{
33
34 0x0fa3f100, 0x0fa3b000, 0x0fa33100, 0x0fa33000,
35 0x0fa33000, 0x0fa33004, 0xfffffc01, 0xfffffc00,
36
37
38 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
39 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
40
41
42 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
43 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
44
45
46 0x00a3fc00, 0x00a3fc00, 0x00a3fc00, 0x00a3fc00,
47 0x0fa3fc00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
48
49
50 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
51 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
52 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
53 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
54
55
56 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
57 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
58 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
59
60
61 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
62};
63
64
65static const uint upmTable100[] =
66{
67
68 0x0fa3f200, 0x0fa3b000, 0x0fa33300, 0x0fa33000,
69 0x0fa33000, 0x0fa33004, 0xfffffc01, 0xfffffc00,
70
71
72 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
73 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
74
75
76 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
77 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
78
79
80 0x00a3ff00, 0x00a3fc00, 0x00a3fc00, 0x0fa3fc00,
81 0x0fa3fc00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
82
83
84 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
85 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
86 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
87 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
88
89
90 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
91 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
92 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
93
94
95 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
96};
97
98
99static const uint upmTable133[] =
100{
101
102 0x0fa3f300, 0x0fa3b000, 0x0fa33300, 0x0fa33000,
103 0x0fa33200, 0x0fa33004, 0xfffffc01, 0xfffffc00,
104
105
106 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
107 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
108
109
110 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
111 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
112
113
114 0x00a3ff00, 0x00a3fc00, 0x00a3fd00, 0x0fa3fc00,
115 0x0fa3fd00, 0x0fa3fc04, 0xfffffc01, 0xfffffc00,
116
117
118 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
119 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
120 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
121 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
122
123
124 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
125 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
126 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
127
128
129 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
130};
131
132static int chipsel = 0;
133
134#if defined(CONFIG_CMD_NAND)
135
136#include <nand.h>
137#include <linux/mtd/mtd.h>
138
139static u8 hwctl = 0;
140
141static void upmnand_write_byte(struct mtd_info *mtdinfo, u_char byte)
142{
143 struct nand_chip *this = mtdinfo->priv;
144 ulong base = (ulong) (this->IO_ADDR_W + chipsel * CONFIG_SYS_NAND_CS_DIST);
145
146 if (hwctl & 0x1) {
147 WRITE_NAND_UPM(byte, base, CONFIG_SYS_NAND_UPM_WRITE_CMD_OFS);
148 } else if (hwctl & 0x2) {
149 WRITE_NAND_UPM(byte, base, CONFIG_SYS_NAND_UPM_WRITE_ADDR_OFS);
150 } else {
151 WRITE_NAND(byte, base);
152 }
153}
154
155static void upmnand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
156{
157 if (ctrl & NAND_CTRL_CHANGE) {
158 if ( ctrl & NAND_CLE )
159 hwctl |= 0x1;
160 else
161 hwctl &= ~0x1;
162 if ( ctrl & NAND_ALE )
163 hwctl |= 0x2;
164 else
165 hwctl &= ~0x2;
166 }
167 if (cmd != NAND_CMD_NONE)
168 upmnand_write_byte (mtd, cmd);
169}
170
171static u_char upmnand_read_byte(struct mtd_info *mtdinfo)
172{
173 struct nand_chip *this = mtdinfo->priv;
174 ulong base = (ulong) (this->IO_ADDR_W + chipsel * CONFIG_SYS_NAND_CS_DIST);
175
176 return READ_NAND(base);
177}
178
179static int tqm8272_dev_ready(struct mtd_info *mtdinfo)
180{
181
182 udelay(12); \
183 return 1;
184}
185
186#ifndef CONFIG_NAND_SPL
187static void tqm8272_read_buf(struct mtd_info *mtdinfo, uint8_t *buf, int len)
188{
189 struct nand_chip *this = mtdinfo->priv;
190 unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CONFIG_SYS_NAND_CS_DIST);
191 int i;
192
193 for (i = 0; i< len; i++)
194 buf[i] = *base;
195}
196
197static void tqm8272_write_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
198{
199 struct nand_chip *this = mtdinfo->priv;
200 unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CONFIG_SYS_NAND_CS_DIST);
201 int i;
202
203 for (i = 0; i< len; i++)
204 *base = buf[i];
205}
206
207static int tqm8272_verify_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
208{
209 struct nand_chip *this = mtdinfo->priv;
210 unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CONFIG_SYS_NAND_CS_DIST);
211 int i;
212
213 for (i = 0; i < len; i++)
214 if (buf[i] != *base)
215 return -1;
216 return 0;
217}
218#endif
219
220void board_nand_select_device(struct nand_chip *nand, int chip)
221{
222 chipsel = chip;
223}
224
225int board_nand_init(struct nand_chip *nand)
226{
227 static int UpmInit = 0;
228 volatile immap_t * immr = (immap_t *)CONFIG_SYS_IMMR;
229 volatile memctl8260_t *memctl = &immr->im_memctl;
230
231 if (hwinf.nand == 0) return -1;
232
233
234 if (UpmInit == 0) {
235 switch (hwinf.busclk_real) {
236 case 100000000:
237 upmconfig (UPMB, (uint *) upmTable100,
238 sizeof (upmTable100) / sizeof (uint));
239 break;
240 case 133333333:
241 upmconfig (UPMB, (uint *) upmTable133,
242 sizeof (upmTable133) / sizeof (uint));
243 break;
244 default:
245 upmconfig (UPMB, (uint *) upmTable67,
246 sizeof (upmTable67) / sizeof (uint));
247 break;
248 }
249 UpmInit = 1;
250 }
251
252
253 memctl->memc_or3 = CONFIG_SYS_NAND_OR;
254 memctl->memc_br3 = CONFIG_SYS_NAND_BR;
255 memctl->memc_mbmr = (MxMR_OP_NORM);
256
257 nand->ecc.mode = NAND_ECC_SOFT;
258
259 nand->cmd_ctrl = upmnand_hwcontrol;
260 nand->read_byte = upmnand_read_byte;
261 nand->dev_ready = tqm8272_dev_ready;
262
263#ifndef CONFIG_NAND_SPL
264 nand->write_buf = tqm8272_write_buf;
265 nand->read_buf = tqm8272_read_buf;
266 nand->verify_buf = tqm8272_verify_buf;
267#endif
268
269
270
271
272 board_nand_select_device(nand, 0);
273 return 0;
274}
275
276#endif
277