3 * Markus Klotzbuecher, DENX Software Engineering, mk@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * Host Port Interface (HPI)
44 #define _NOT_USED_ 0xFFFFFFFF
47 * - inserted loops to achieve long CS low and high Periods (~217ns)
48 * - move cs high 2/4 to the right
50 const uint dsp_table_slow
[] =
52 /* single read (offset 0x00 in upm ram) */
53 0x8fffdc04, 0x0fffdc84, 0x0fffdc84, 0x0fffdc00,
54 0x3fffdc04, 0xffffdc84, 0xffffdc84, 0xffffdc05,
56 /* burst read (offset 0x08 in upm ram) */
57 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
58 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
59 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
60 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
62 /* single write (offset 0x18 in upm ram) */
63 0x8fffd004, 0x0fffd084, 0x0fffd084, 0x3fffd000,
64 0xffffd084, 0xffffd084, 0xffffd005, _NOT_USED_
,
66 /* burst write (offset 0x20 in upm ram) */
67 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
68 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
69 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
70 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
71 /* refresh (offset 0x30 in upm ram) */
72 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
73 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
74 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
75 /* exception (offset 0x3C in upm ram) */
76 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
79 /* dsp hpi upm ram table
80 * works fine for noninc access, failes on incremental.
81 * - removed first word
83 const uint dsp_table_fast
[] =
85 /* single read (offset 0x00 in upm ram) */
86 0x8fffdc04, 0x0fffdc04, 0x0fffdc00, 0x3fffdc04,
87 0xffffdc05, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
89 /* burst read (offset 0x08 in upm ram) */
90 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
91 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
92 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
93 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
95 /* single write (offset 0x18 in upm ram) */
96 0x8fffd004, 0x0fffd004, 0x3fffd000, 0xffffd005,
97 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
99 /* burst write (offset 0x20 in upm ram) */
100 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
101 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
102 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
103 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
104 /* refresh (offset 0x30 in upm ram) */
105 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
106 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
107 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
108 /* exception (offset 0x3C in upm ram) */
109 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
113 #ifdef CONFIG_SPC1920_HPI_TEST
116 #define HPI_TEST_CHUNKSIZE 0x1000
117 #define HPI_TEST_PATTERN 0x00000000
118 #define HPI_TEST_START 0x0
119 #define HPI_TEST_END 0x30000
121 #define TINY_AUTOINC_DATA_SIZE 16 /* 32bit words */
122 #define TINY_AUTOINC_BASE_ADDR 0x0
124 static int hpi_activate(void);
126 static void hpi_inactivate(void);
128 static void dsp_reset(void);
130 static int hpi_write_inc(u32 addr
, u32
*data
, u32 count
);
131 static int hpi_read_inc(u32 addr
, u32
*buf
, u32 count
);
132 static int hpi_write_noinc(u32 addr
, u32 data
);
133 static u32
hpi_read_noinc(u32 addr
);
136 static int hpi_write_addr_test(u32 addr
);
137 static int hpi_read_write_test(u32 addr
, u32 data
);
139 static int hpi_tiny_autoinc_test(void);
140 #endif /* DO_TINY_TEST */
141 #endif /* CONFIG_SPC1920_HPI_TEST */
144 /* init the host port interface on UPMA */
147 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
148 volatile memctl8xx_t
*memctl
= &immr
->im_memctl
;
149 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CFG_SPC1920_PLD_BASE
;
151 upmconfig(UPMA
, (uint
*)dsp_table_slow
, sizeof(dsp_table_slow
)/sizeof(uint
));
154 memctl
->memc_mamr
= CFG_MAMR
;
155 memctl
->memc_or3
= CFG_OR3
;
156 memctl
->memc_br3
= CFG_BR3
;
161 /* activate hpi switch*/
162 pld
->dsp_hpi_on
= 0x1;
169 #ifdef CONFIG_SPC1920_HPI_TEST
170 /* activate the Host Port interface */
171 static int hpi_activate(void)
173 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CFG_SPC1920_PLD_BASE
;
176 pld
->dsp_hpi_on
= 0x1;
180 /* turn on the power EN_DSP_POWER high*/
181 /* currently always on TBD */
183 /* setup hpi control register */
184 HPI_HPIC_1
= (u16
) 0x0008;
185 HPI_HPIC_2
= (u16
) 0x0008;
193 /* turn off the host port interface */
194 static void hpi_inactivate(void)
196 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CFG_SPC1920_PLD_BASE
;
199 pld
->dsp_hpi_on
= 0x0;
202 /* pld->dsp_reset = 0x0; */
204 /* turn off the power EN_DSP_POWER# high*/
205 /* currently always on TBD */
211 static void dsp_reset(void)
213 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CFG_SPC1920_PLD_BASE
;
214 pld
->dsp_reset
= 0x1;
215 pld
->dsp_hpi_on
= 0x0;
219 pld
->dsp_reset
= 0x0;
220 pld
->dsp_hpi_on
= 0x1;
224 /* write using autoinc (count is number of 32bit words) */
225 static int hpi_write_inc(u32 addr
, u32
*data
, u32 count
)
230 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
231 addr2
= (u16
) (addr
& 0xffff);
237 debugX(4, "writing from data=0x%x to 0x%x\n", data
, (data
+count
));
239 for(i
=0; i
<count
; i
++) {
240 HPI_HPID_INC_1
= (u16
) ((data
[i
] >> 16) & 0xffff);
241 HPI_HPID_INC_2
= (u16
) (data
[i
] & 0xffff);
242 debugX(4, "hpi_write_inc: data1=0x%x, data2=0x%x\n",
243 (u16
) ((data
[i
] >> 16) & 0xffff),
244 (u16
) (data
[i
] & 0xffff));
247 while(data_ptr
< (u16
*) (data
+ count
)) {
248 HPI_HPID_INC_1
= *(data_ptr
++);
249 HPI_HPID_INC_2
= *(data_ptr
++);
253 /* return number of bytes written */
258 * read using autoinc (count is number of 32bit words)
260 static int hpi_read_inc(u32 addr
, u32
*buf
, u32 count
)
263 u16 addr1
, addr2
, data1
, data2
;
265 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
266 addr2
= (u16
) (addr
& 0xffff);
272 for(i
=0; i
<count
; i
++) {
273 data1
= HPI_HPID_INC_1
;
274 data2
= HPI_HPID_INC_2
;
275 debugX(4, "hpi_read_inc: data1=0x%x, data2=0x%x\n", data1
, data2
);
276 buf
[i
] = (((u32
) data1
) << 16) | (data2
& 0xffff);
280 while(buf_ptr
< (u16
*) (buf
+ count
)) {
281 *(buf_ptr
++) = HPI_HPID_INC_1
;
282 *(buf_ptr
++) = HPI_HPID_INC_2
;
286 /* return number of bytes read */
291 /* write to non- auto inc regs */
292 static int hpi_write_noinc(u32 addr
, u32 data
)
295 u16 addr1
, addr2
, data1
, data2
;
297 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
298 addr2
= (u16
) (addr
& 0xffff);
300 /* printf("hpi_write_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
305 data1
= (u16
) ((data
>> 16) & 0xffff);
306 data2
= (u16
) (data
& 0xffff);
308 /* printf("hpi_write_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
310 HPI_HPID_NOINC_1
= data1
;
311 HPI_HPID_NOINC_2
= data2
;
316 /* read from non- auto inc regs */
317 static u32
hpi_read_noinc(u32 addr
)
319 u16 addr1
, addr2
, data1
, data2
;
322 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
323 addr2
= (u16
) (addr
& 0xffff);
328 /* printf("hpi_read_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
330 data1
= HPI_HPID_NOINC_1
;
331 data2
= HPI_HPID_NOINC_2
;
333 /* printf("hpi_read_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
335 ret
= (((u32
) data1
) << 16) | (data2
& 0xffff);
341 * Host Port Interface Tests
344 #ifndef HPI_TEST_OSZI
345 /* main test function */
349 u32 i
, ii
, pattern
, tmp
;
351 pattern
= HPI_TEST_PATTERN
;
353 u32 test_data
[HPI_TEST_CHUNKSIZE
];
354 u32 read_data
[HPI_TEST_CHUNKSIZE
];
356 debugX(2, "hpi_test: activating hpi...");
361 /* Dump the first 1024 bytes
364 for(i
=0; i
<1024; i
+=4) {
366 printf("\n0x%08x: ", i
);
367 printf("0x%08x ", hpi_read_noinc(i
));
371 /* HPIA read-write test
374 debugX(1, "hpi_test: starting HPIA read-write tests...\n");
375 err
|= hpi_write_addr_test(0xdeadc0de);
376 err
|= hpi_write_addr_test(0xbeefd00d);
377 err
|= hpi_write_addr_test(0xabcd1234);
378 err
|= hpi_write_addr_test(0xaaaaaaaa);
380 debugX(1, "hpi_test: HPIA read-write tests: *** FAILED ***\n");
383 debugX(1, "hpi_test: HPIA read-write tests: OK\n");
386 /* read write test using nonincremental data regs
389 debugX(1, "hpi_test: starting nonincremental tests...\n");
390 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
391 err
|= hpi_read_write_test(i
, pattern
);
393 /* stolen from cmd_mem.c */
394 if(pattern
& 0x80000000) {
395 pattern
= -pattern
; /* complement & increment */
399 err
|= hpi_read_write_test(i
, pattern
);
402 debugX(1, "hpi_test: nonincremental tests *** FAILED ***\n");
406 debugX(1, "hpi_test: nonincremental test OK\n");
408 /* read write a chunk of data using nonincremental data regs
411 debugX(1, "hpi_test: starting nonincremental chunk tests...\n");
412 pattern
= HPI_TEST_PATTERN
;
413 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
414 hpi_write_noinc(i
, pattern
);
416 /* stolen from cmd_mem.c */
417 if(pattern
& 0x80000000) {
418 pattern
= -pattern
; /* complement & increment */
423 pattern
= HPI_TEST_PATTERN
;
424 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
425 tmp
= hpi_read_noinc(i
);
428 debugX(1, "hpi_test: noninc chunk test *** FAILED *** @ 0x%x, written=0x%x, read=0x%x\n", i
, pattern
, tmp
);
431 /* stolen from cmd_mem.c */
432 if(pattern
& 0x80000000) {
433 pattern
= -pattern
; /* complement & increment */
440 debugX(1, "hpi_test: nonincremental chunk test OK\n");
444 /* small verbose test using autoinc and nonautoinc to compare
447 debugX(1, "hpi_test: tiny_autoinc_test...\n");
448 hpi_tiny_autoinc_test();
449 debugX(1, "hpi_test: tiny_autoinc_test done\n");
450 #endif /* DO_TINY_TEST */
453 /* $%& write a chunk of data using the autoincremental regs
456 debugX(1, "hpi_test: starting autoinc test %d chunks with 0x%x bytes...\n",
457 ((HPI_TEST_END
- HPI_TEST_START
) / HPI_TEST_CHUNKSIZE
),
460 for(i
=HPI_TEST_START
;
461 i
< ((HPI_TEST_END
- HPI_TEST_START
) / HPI_TEST_CHUNKSIZE
);
463 /* generate the pattern data */
464 debugX(3, "generating pattern data: ");
465 for(ii
= 0; ii
< HPI_TEST_CHUNKSIZE
; ii
++) {
466 debugX(3, "0x%x ", pattern
);
468 test_data
[ii
] = pattern
;
469 read_data
[ii
] = 0x0; /* zero to be sure */
471 /* stolen from cmd_mem.c */
472 if(pattern
& 0x80000000) {
473 pattern
= -pattern
; /* complement & increment */
480 debugX(2, "Writing autoinc data @ 0x%x\n", i
);
481 hpi_write_inc(i
, test_data
, HPI_TEST_CHUNKSIZE
);
483 debugX(2, "Reading autoinc data @ 0x%x\n", i
);
484 hpi_read_inc(i
, read_data
, HPI_TEST_CHUNKSIZE
);
487 for(ii
= 0; ii
< HPI_TEST_CHUNKSIZE
; ii
++) {
488 debugX(3, "hpi_test_autoinc: @ 0x%x, written=0x%x, read=0x%x", i
+ii
, test_data
[ii
], read_data
[ii
]);
489 if(read_data
[ii
] != test_data
[ii
]) {
490 debugX(0, "hpi_test: autoinc test @ 0x%x, written=0x%x, read=0x%x *** FAILED ***\n", i
+ii
, test_data
[ii
], read_data
[ii
]);
495 debugX(1, "hpi_test: autoinc test OK\n");
499 #else /* HPI_TEST_OSZI */
503 u32 read_data
[TINY_AUTOINC_DATA_SIZE
];
505 unsigned int dummy_data
[TINY_AUTOINC_DATA_SIZE
] = {
506 0x11112222, 0x33334444, 0x55556666, 0x77778888,
507 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
508 0x00010002, 0x00030004, 0x00050006, 0x00070008,
509 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
512 debugX(0, "hpi_test: activating hpi...");
518 debugX(0, " writing to autoinc...\n");
519 hpi_write_inc(TINY_AUTOINC_BASE_ADDR
,
520 dummy_data
, TINY_AUTOINC_DATA_SIZE
);
522 debugX(0, " reading from autoinc...\n");
523 hpi_read_inc(TINY_AUTOINC_BASE_ADDR
,
524 read_data
, TINY_AUTOINC_DATA_SIZE
);
526 for(i
=0; i
< (TINY_AUTOINC_DATA_SIZE
); i
++) {
527 debugX(0, " written=0x%x, read(inc)=0x%x\n",
528 dummy_data
[i
], read_data
[i
]);
537 /* test if Host Port Address Register can be written correctly */
538 static int hpi_write_addr_test(u32 addr
)
542 HPI_HPIA_1
= ((u16
) (addr
>> 16)); /* First HW is most significant */
543 HPI_HPIA_2
= ((u16
) addr
);
545 read_back
= (((u32
) HPI_HPIA_1
)<<16) | ((u32
) HPI_HPIA_2
);
547 if(read_back
== addr
) {
548 debugX(2, " hpi_write_addr_test OK: written=0x%x, read=0x%x\n",
552 debugX(0, " hpi_write_addr_test *** FAILED ***: written=0x%x, read=0x%x\n",
560 /* test if a simple read/write sequence succeeds */
561 static int hpi_read_write_test(u32 addr
, u32 data
)
565 hpi_write_noinc(addr
, data
);
566 read_back
= hpi_read_noinc(addr
);
568 if(read_back
== data
) {
569 debugX(2, " hpi_read_write_test: OK, addr=0x%x written=0x%x, read=0x%x\n", addr
, data
, read_back
);
572 debugX(0, " hpi_read_write_test: *** FAILED ***, addr=0x%x written=0x%x, read=0x%x\n", addr
, data
, read_back
);
580 static int hpi_tiny_autoinc_test(void)
583 u32 read_data
[TINY_AUTOINC_DATA_SIZE
];
584 u32 read_data_noinc
[TINY_AUTOINC_DATA_SIZE
];
586 unsigned int dummy_data
[TINY_AUTOINC_DATA_SIZE
] = {
587 0x11112222, 0x33334444, 0x55556666, 0x77778888,
588 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
589 0x00010002, 0x00030004, 0x00050006, 0x00070008,
590 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
593 printf(" writing to autoinc...\n");
594 hpi_write_inc(TINY_AUTOINC_BASE_ADDR
, dummy_data
, TINY_AUTOINC_DATA_SIZE
);
596 printf(" reading from autoinc...\n");
597 hpi_read_inc(TINY_AUTOINC_BASE_ADDR
, read_data
, TINY_AUTOINC_DATA_SIZE
);
599 printf(" reading from noinc for comparison...\n");
600 for(i
=0; i
< (TINY_AUTOINC_DATA_SIZE
); i
++)
601 read_data_noinc
[i
] = hpi_read_noinc(TINY_AUTOINC_BASE_ADDR
+i
*4);
603 for(i
=0; i
< (TINY_AUTOINC_DATA_SIZE
); i
++) {
604 printf(" written=0x%x, read(inc)=0x%x, read(noinc)=0x%x\n",
605 dummy_data
[i
], read_data
[i
], read_data_noinc
[i
]);
609 #endif /* DO_TINY_TEST */
611 #endif /* CONFIG_SPC1920_HPI_TEST */