blob: c593837ad6319df99cf81be9303980352825a76c [file] [log] [blame]
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +01001/*
2 * (C) Copyright 2006
3 * Markus Klotzbuecher, DENX Software Engineering, mk@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +01006 */
7
8/*
9 * Host Port Interface (HPI)
10 */
11
12/* debug levels:
13 * 0 : errors
14 * 1 : usefull info
15 * 2 : lots of info
16 * 3 : noisy
17 */
18
19#define DEBUG 0
20
21#include <config.h>
22#include <common.h>
23#include <mpc8xx.h>
24
25#include "pld.h"
26#include "hpi.h"
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +010027
28#define _NOT_USED_ 0xFFFFFFFF
29
30/* original table:
31 * - inserted loops to achieve long CS low and high Periods (~217ns)
32 * - move cs high 2/4 to the right
33 */
34const uint dsp_table_slow[] =
35{
36 /* single read (offset 0x00 in upm ram) */
37 0x8fffdc04, 0x0fffdc84, 0x0fffdc84, 0x0fffdc00,
38 0x3fffdc04, 0xffffdc84, 0xffffdc84, 0xffffdc05,
39
40 /* burst read (offset 0x08 in upm ram) */
41 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
42 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
43 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
44 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
45
46 /* single write (offset 0x18 in upm ram) */
47 0x8fffd004, 0x0fffd084, 0x0fffd084, 0x3fffd000,
48 0xffffd084, 0xffffd084, 0xffffd005, _NOT_USED_,
49
50 /* burst write (offset 0x20 in upm ram) */
51 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
52 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
53 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
54 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
55 /* refresh (offset 0x30 in upm ram) */
56 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
57 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
58 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
59 /* exception (offset 0x3C in upm ram) */
60 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
61};
62
63/* dsp hpi upm ram table
64 * works fine for noninc access, failes on incremental.
65 * - removed first word
66 */
67const uint dsp_table_fast[] =
68{
69 /* single read (offset 0x00 in upm ram) */
70 0x8fffdc04, 0x0fffdc04, 0x0fffdc00, 0x3fffdc04,
71 0xffffdc05, _NOT_USED_, _NOT_USED_, _NOT_USED_,
72
73 /* burst read (offset 0x08 in upm ram) */
74 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
75 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
76 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
77 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
78
79 /* single write (offset 0x18 in upm ram) */
80 0x8fffd004, 0x0fffd004, 0x3fffd000, 0xffffd005,
81 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
82
83 /* burst write (offset 0x20 in upm ram) */
84 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
85 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
86 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
87 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
88 /* refresh (offset 0x30 in upm ram) */
89 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
90 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
91 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
92 /* exception (offset 0x3C in upm ram) */
93 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
94};
95
96
97#ifdef CONFIG_SPC1920_HPI_TEST
98#undef HPI_TEST_OSZI
99
100#define HPI_TEST_CHUNKSIZE 0x1000
101#define HPI_TEST_PATTERN 0x00000000
102#define HPI_TEST_START 0x0
103#define HPI_TEST_END 0x30000
104
105#define TINY_AUTOINC_DATA_SIZE 16 /* 32bit words */
106#define TINY_AUTOINC_BASE_ADDR 0x0
107
108static int hpi_activate(void);
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200109#if 0
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100110static void hpi_inactivate(void);
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200111#endif
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100112static void dsp_reset(void);
113
114static int hpi_write_inc(u32 addr, u32 *data, u32 count);
115static int hpi_read_inc(u32 addr, u32 *buf, u32 count);
116static int hpi_write_noinc(u32 addr, u32 data);
117static u32 hpi_read_noinc(u32 addr);
118
119int hpi_test(void);
120static int hpi_write_addr_test(u32 addr);
121static int hpi_read_write_test(u32 addr, u32 data);
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200122#ifdef DO_TINY_TEST
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100123static int hpi_tiny_autoinc_test(void);
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200124#endif /* DO_TINY_TEST */
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100125#endif /* CONFIG_SPC1920_HPI_TEST */
126
127
128/* init the host port interface on UPMA */
129int hpi_init(void)
130{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200131 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100132 volatile memctl8xx_t *memctl = &immr->im_memctl;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100134
135 upmconfig(UPMA, (uint *)dsp_table_slow, sizeof(dsp_table_slow)/sizeof(uint));
136 udelay(100);
137
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200138 memctl->memc_mamr = CONFIG_SYS_MAMR;
139 memctl->memc_or3 = CONFIG_SYS_OR3;
140 memctl->memc_br3 = CONFIG_SYS_BR3;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100141
142 /* reset dsp */
143 dsp_reset();
144
145 /* activate hpi switch*/
146 pld->dsp_hpi_on = 0x1;
147
148 udelay(100);
149
150 return 0;
151}
152
153#ifdef CONFIG_SPC1920_HPI_TEST
154/* activate the Host Port interface */
155static int hpi_activate(void)
156{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200157 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100158
159 /* turn on hpi */
160 pld->dsp_hpi_on = 0x1;
161
162 udelay(5);
163
164 /* turn on the power EN_DSP_POWER high*/
165 /* currently always on TBD */
166
167 /* setup hpi control register */
168 HPI_HPIC_1 = (u16) 0x0008;
169 HPI_HPIC_2 = (u16) 0x0008;
170
171 udelay(100);
172
173 return 0;
174}
175
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200176#if 0
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100177/* turn off the host port interface */
178static void hpi_inactivate(void)
179{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200180 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100181
182 /* deactivate hpi */
183 pld->dsp_hpi_on = 0x0;
184
185 /* reset the dsp */
186 /* pld->dsp_reset = 0x0; */
187
188 /* turn off the power EN_DSP_POWER# high*/
189 /* currently always on TBD */
190
191}
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200192#endif
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100193
194/* reset the DSP */
195static void dsp_reset(void)
196{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200197 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE;
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100198 pld->dsp_reset = 0x1;
199 pld->dsp_hpi_on = 0x0;
200
201 udelay(300000);
202
203 pld->dsp_reset = 0x0;
204 pld->dsp_hpi_on = 0x1;
205}
206
207
208/* write using autoinc (count is number of 32bit words) */
209static int hpi_write_inc(u32 addr, u32 *data, u32 count)
210{
211 int i;
212 u16 addr1, addr2;
213
214 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
215 addr2 = (u16) (addr & 0xffff);
216
217 /* write address */
218 HPI_HPIA_1 = addr1;
219 HPI_HPIA_2 = addr2;
220
Marek Vasut75753692011-10-24 23:41:41 +0000221 debug("writing from data=0x%lx to 0x%lx\n",
Wolfgang Denk9b55a252008-07-11 01:16:00 +0200222 (ulong)data, (ulong)(data+count));
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100223
224 for(i=0; i<count; i++) {
225 HPI_HPID_INC_1 = (u16) ((data[i] >> 16) & 0xffff);
226 HPI_HPID_INC_2 = (u16) (data[i] & 0xffff);
Marek Vasut75753692011-10-24 23:41:41 +0000227 debug("hpi_write_inc: data1=0x%x, data2=0x%x\n",
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100228 (u16) ((data[i] >> 16) & 0xffff),
229 (u16) (data[i] & 0xffff));
230 }
231#if 0
232 while(data_ptr < (u16*) (data + count)) {
233 HPI_HPID_INC_1 = *(data_ptr++);
234 HPI_HPID_INC_2 = *(data_ptr++);
235 }
236#endif
237
238 /* return number of bytes written */
239 return count;
240}
241
242/*
243 * read using autoinc (count is number of 32bit words)
244 */
245static int hpi_read_inc(u32 addr, u32 *buf, u32 count)
246{
247 int i;
248 u16 addr1, addr2, data1, data2;
249
250 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
251 addr2 = (u16) (addr & 0xffff);
252
253 /* write address */
254 HPI_HPIA_1 = addr1;
255 HPI_HPIA_2 = addr2;
256
257 for(i=0; i<count; i++) {
258 data1 = HPI_HPID_INC_1;
259 data2 = HPI_HPID_INC_2;
Marek Vasut75753692011-10-24 23:41:41 +0000260 debug("hpi_read_inc: data1=0x%x, data2=0x%x\n", data1, data2);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100261 buf[i] = (((u32) data1) << 16) | (data2 & 0xffff);
262 }
263
264#if 0
265 while(buf_ptr < (u16*) (buf + count)) {
266 *(buf_ptr++) = HPI_HPID_INC_1;
267 *(buf_ptr++) = HPI_HPID_INC_2;
268 }
269#endif
270
271 /* return number of bytes read */
272 return count;
273}
274
275
276/* write to non- auto inc regs */
277static int hpi_write_noinc(u32 addr, u32 data)
278{
279
280 u16 addr1, addr2, data1, data2;
281
282 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
283 addr2 = (u16) (addr & 0xffff);
284
285 /* printf("hpi_write_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
286
287 HPI_HPIA_1 = addr1;
288 HPI_HPIA_2 = addr2;
289
290 data1 = (u16) ((data >> 16) & 0xffff);
291 data2 = (u16) (data & 0xffff);
292
293 /* printf("hpi_write_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
294
295 HPI_HPID_NOINC_1 = data1;
296 HPI_HPID_NOINC_2 = data2;
297
298 return 0;
299}
300
301/* read from non- auto inc regs */
302static u32 hpi_read_noinc(u32 addr)
303{
304 u16 addr1, addr2, data1, data2;
305 u32 ret;
306
307 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
308 addr2 = (u16) (addr & 0xffff);
309
310 HPI_HPIA_1 = addr1;
311 HPI_HPIA_2 = addr2;
312
313 /* printf("hpi_read_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
314
315 data1 = HPI_HPID_NOINC_1;
316 data2 = HPI_HPID_NOINC_2;
317
318 /* printf("hpi_read_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
319
320 ret = (((u32) data1) << 16) | (data2 & 0xffff);
321 return ret;
322
323}
324
325/*
326 * Host Port Interface Tests
327 */
328
329#ifndef HPI_TEST_OSZI
330/* main test function */
331int hpi_test(void)
332{
333 int err = 0;
334 u32 i, ii, pattern, tmp;
335
336 pattern = HPI_TEST_PATTERN;
337
338 u32 test_data[HPI_TEST_CHUNKSIZE];
339 u32 read_data[HPI_TEST_CHUNKSIZE];
340
Marek Vasut75753692011-10-24 23:41:41 +0000341 debug("hpi_test: activating hpi...");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100342 hpi_activate();
Marek Vasut75753692011-10-24 23:41:41 +0000343 debug("OK.\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100344
345#if 0
346 /* Dump the first 1024 bytes
347 *
348 */
349 for(i=0; i<1024; i+=4) {
350 if(i%16==0)
351 printf("\n0x%08x: ", i);
352 printf("0x%08x ", hpi_read_noinc(i));
353 }
354#endif
355
356 /* HPIA read-write test
357 *
358 */
Marek Vasut75753692011-10-24 23:41:41 +0000359 debug("hpi_test: starting HPIA read-write tests...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100360 err |= hpi_write_addr_test(0xdeadc0de);
361 err |= hpi_write_addr_test(0xbeefd00d);
362 err |= hpi_write_addr_test(0xabcd1234);
363 err |= hpi_write_addr_test(0xaaaaaaaa);
364 if(err) {
Marek Vasut75753692011-10-24 23:41:41 +0000365 debug("hpi_test: HPIA read-write tests: *** FAILED ***\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100366 return -1;
367 }
Marek Vasut75753692011-10-24 23:41:41 +0000368 debug("hpi_test: HPIA read-write tests: OK\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100369
370
371 /* read write test using nonincremental data regs
372 *
373 */
Marek Vasut75753692011-10-24 23:41:41 +0000374 debug("hpi_test: starting nonincremental tests...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100375 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
376 err |= hpi_read_write_test(i, pattern);
377
378 /* stolen from cmd_mem.c */
379 if(pattern & 0x80000000) {
380 pattern = -pattern; /* complement & increment */
381 } else {
382 pattern = ~pattern;
383 }
384 err |= hpi_read_write_test(i, pattern);
385
386 if(err) {
Marek Vasut75753692011-10-24 23:41:41 +0000387 debug("hpi_test: nonincremental tests *** FAILED ***\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100388 return -1;
389 }
390 }
Marek Vasut75753692011-10-24 23:41:41 +0000391 debug("hpi_test: nonincremental test OK\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100392
393 /* read write a chunk of data using nonincremental data regs
394 *
395 */
Marek Vasut75753692011-10-24 23:41:41 +0000396 debug("hpi_test: starting nonincremental chunk tests...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100397 pattern = HPI_TEST_PATTERN;
398 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
399 hpi_write_noinc(i, pattern);
400
401 /* stolen from cmd_mem.c */
402 if(pattern & 0x80000000) {
403 pattern = -pattern; /* complement & increment */
404 } else {
405 pattern = ~pattern;
406 }
407 }
408 pattern = HPI_TEST_PATTERN;
409 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
410 tmp = hpi_read_noinc(i);
411
412 if(tmp != pattern) {
Marek Vasut75753692011-10-24 23:41:41 +0000413 debug("hpi_test: noninc chunk test *** FAILED *** @ 0x%x, written=0x%x, read=0x%x\n", i, pattern, tmp);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100414 err = -1;
415 }
416 /* stolen from cmd_mem.c */
417 if(pattern & 0x80000000) {
418 pattern = -pattern; /* complement & increment */
419 } else {
420 pattern = ~pattern;
421 }
422 }
423 if(err)
424 return -1;
Marek Vasut75753692011-10-24 23:41:41 +0000425 debug("hpi_test: nonincremental chunk test OK\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100426
427
428#ifdef DO_TINY_TEST
429 /* small verbose test using autoinc and nonautoinc to compare
430 *
431 */
Marek Vasut75753692011-10-24 23:41:41 +0000432 debug("hpi_test: tiny_autoinc_test...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100433 hpi_tiny_autoinc_test();
Marek Vasut75753692011-10-24 23:41:41 +0000434 debug("hpi_test: tiny_autoinc_test done\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100435#endif /* DO_TINY_TEST */
436
437
438 /* $%& write a chunk of data using the autoincremental regs
439 *
440 */
Marek Vasut75753692011-10-24 23:41:41 +0000441 debug("hpi_test: starting autoinc test %d chunks with 0x%x bytes...\n",
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100442 ((HPI_TEST_END - HPI_TEST_START) / HPI_TEST_CHUNKSIZE),
443 HPI_TEST_CHUNKSIZE);
444
445 for(i=HPI_TEST_START;
446 i < ((HPI_TEST_END - HPI_TEST_START) / HPI_TEST_CHUNKSIZE);
447 i++) {
448 /* generate the pattern data */
Marek Vasut75753692011-10-24 23:41:41 +0000449 debug("generating pattern data: ");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100450 for(ii = 0; ii < HPI_TEST_CHUNKSIZE; ii++) {
Marek Vasut75753692011-10-24 23:41:41 +0000451 debug("0x%x ", pattern);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100452
453 test_data[ii] = pattern;
454 read_data[ii] = 0x0; /* zero to be sure */
455
456 /* stolen from cmd_mem.c */
457 if(pattern & 0x80000000) {
458 pattern = -pattern; /* complement & increment */
459 } else {
460 pattern = ~pattern;
461 }
462 }
Marek Vasut75753692011-10-24 23:41:41 +0000463 debug("done\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100464
Marek Vasut75753692011-10-24 23:41:41 +0000465 debug("Writing autoinc data @ 0x%x\n", i);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100466 hpi_write_inc(i, test_data, HPI_TEST_CHUNKSIZE);
467
Marek Vasut75753692011-10-24 23:41:41 +0000468 debug("Reading autoinc data @ 0x%x\n", i);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100469 hpi_read_inc(i, read_data, HPI_TEST_CHUNKSIZE);
470
471 /* compare */
472 for(ii = 0; ii < HPI_TEST_CHUNKSIZE; ii++) {
Marek Vasut75753692011-10-24 23:41:41 +0000473 debug("hpi_test_autoinc: @ 0x%x, written=0x%x, read=0x%x", i+ii, test_data[ii], read_data[ii]);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100474 if(read_data[ii] != test_data[ii]) {
Marek Vasut75753692011-10-24 23:41:41 +0000475 debug("hpi_test: autoinc test @ 0x%x, written=0x%x, read=0x%x *** FAILED ***\n", i+ii, test_data[ii], read_data[ii]);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100476 return -1;
477 }
478 }
479 }
Marek Vasut75753692011-10-24 23:41:41 +0000480 debug("hpi_test: autoinc test OK\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100481
482 return 0;
483}
484#else /* HPI_TEST_OSZI */
485int hpi_test(void)
486{
487 int i;
488 u32 read_data[TINY_AUTOINC_DATA_SIZE];
489
490 unsigned int dummy_data[TINY_AUTOINC_DATA_SIZE] = {
491 0x11112222, 0x33334444, 0x55556666, 0x77778888,
492 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
493 0x00010002, 0x00030004, 0x00050006, 0x00070008,
494 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
495 };
496
Marek Vasut75753692011-10-24 23:41:41 +0000497 debug("hpi_test: activating hpi...");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100498 hpi_activate();
Marek Vasut75753692011-10-24 23:41:41 +0000499 debug("OK.\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100500
501 while(1) {
502 led9(1);
Marek Vasut75753692011-10-24 23:41:41 +0000503 debug(" writing to autoinc...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100504 hpi_write_inc(TINY_AUTOINC_BASE_ADDR,
505 dummy_data, TINY_AUTOINC_DATA_SIZE);
506
Marek Vasut75753692011-10-24 23:41:41 +0000507 debug(" reading from autoinc...\n");
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100508 hpi_read_inc(TINY_AUTOINC_BASE_ADDR,
509 read_data, TINY_AUTOINC_DATA_SIZE);
510
511 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++) {
Marek Vasut75753692011-10-24 23:41:41 +0000512 debug(" written=0x%x, read(inc)=0x%x\n",
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100513 dummy_data[i], read_data[i]);
514 }
515 led9(0);
516 udelay(2000000);
517 }
518 return 0;
519}
520#endif
521
522/* test if Host Port Address Register can be written correctly */
523static int hpi_write_addr_test(u32 addr)
524{
525 u32 read_back;
526 /* write address */
527 HPI_HPIA_1 = ((u16) (addr >> 16)); /* First HW is most significant */
528 HPI_HPIA_2 = ((u16) addr);
529
530 read_back = (((u32) HPI_HPIA_1)<<16) | ((u32) HPI_HPIA_2);
531
532 if(read_back == addr) {
Marek Vasut75753692011-10-24 23:41:41 +0000533 debug(" hpi_write_addr_test OK: written=0x%x, read=0x%x\n",
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100534 addr, read_back);
535 return 0;
536 } else {
Marek Vasut75753692011-10-24 23:41:41 +0000537 debug(" hpi_write_addr_test *** FAILED ***: written=0x%x, read=0x%x\n",
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100538 addr, read_back);
539 return -1;
540 }
541
542 return 0;
543}
544
545/* test if a simple read/write sequence succeeds */
546static int hpi_read_write_test(u32 addr, u32 data)
547{
548 u32 read_back;
549
550 hpi_write_noinc(addr, data);
551 read_back = hpi_read_noinc(addr);
552
553 if(read_back == data) {
Marek Vasut75753692011-10-24 23:41:41 +0000554 debug(" hpi_read_write_test: OK, addr=0x%x written=0x%x, read=0x%x\n", addr, data, read_back);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100555 return 0;
556 } else {
Marek Vasut75753692011-10-24 23:41:41 +0000557 debug(" hpi_read_write_test: *** FAILED ***, addr=0x%x written=0x%x, read=0x%x\n", addr, data, read_back);
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100558 return -1;
559 }
560
561 return 0;
562}
563
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200564#ifdef DO_TINY_TEST
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100565static int hpi_tiny_autoinc_test(void)
566{
567 int i;
568 u32 read_data[TINY_AUTOINC_DATA_SIZE];
569 u32 read_data_noinc[TINY_AUTOINC_DATA_SIZE];
570
571 unsigned int dummy_data[TINY_AUTOINC_DATA_SIZE] = {
572 0x11112222, 0x33334444, 0x55556666, 0x77778888,
573 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
574 0x00010002, 0x00030004, 0x00050006, 0x00070008,
575 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
576 };
577
578 printf(" writing to autoinc...\n");
579 hpi_write_inc(TINY_AUTOINC_BASE_ADDR, dummy_data, TINY_AUTOINC_DATA_SIZE);
580
581 printf(" reading from autoinc...\n");
582 hpi_read_inc(TINY_AUTOINC_BASE_ADDR, read_data, TINY_AUTOINC_DATA_SIZE);
583
584 printf(" reading from noinc for comparison...\n");
585 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++)
586 read_data_noinc[i] = hpi_read_noinc(TINY_AUTOINC_BASE_ADDR+i*4);
587
588 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++) {
589 printf(" written=0x%x, read(inc)=0x%x, read(noinc)=0x%x\n",
590 dummy_data[i], read_data[i], read_data_noinc[i]);
591 }
592 return 0;
593}
Wolfgang Denkcdd917a2007-08-02 00:48:45 +0200594#endif /* DO_TINY_TEST */
Markus Klotzbuecherd28707d2007-01-09 14:57:10 +0100595
596#endif /* CONFIG_SPC1920_HPI_TEST */