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)
43 #include "spc1920.h" /* led function */
45 #define _NOT_USED_ 0xFFFFFFFF
48 * - inserted loops to achieve long CS low and high Periods (~217ns)
49 * - move cs high 2/4 to the right
51 const uint dsp_table_slow[] =
53 /* single read (offset 0x00 in upm ram) */
54 0x8fffdc04, 0x0fffdc84, 0x0fffdc84, 0x0fffdc00,
55 0x3fffdc04, 0xffffdc84, 0xffffdc84, 0xffffdc05,
57 /* burst read (offset 0x08 in upm ram) */
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_,
61 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63 /* single write (offset 0x18 in upm ram) */
64 0x8fffd004, 0x0fffd084, 0x0fffd084, 0x3fffd000,
65 0xffffd084, 0xffffd084, 0xffffd005, _NOT_USED_,
67 /* burst write (offset 0x20 in upm ram) */
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 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
72 /* refresh (offset 0x30 in upm ram) */
73 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
74 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
75 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
76 /* exception (offset 0x3C in upm ram) */
77 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
80 /* dsp hpi upm ram table
81 * works fine for noninc access, failes on incremental.
82 * - removed first word
84 const uint dsp_table_fast[] =
86 /* single read (offset 0x00 in upm ram) */
87 0x8fffdc04, 0x0fffdc04, 0x0fffdc00, 0x3fffdc04,
88 0xffffdc05, _NOT_USED_, _NOT_USED_, _NOT_USED_,
90 /* burst read (offset 0x08 in upm ram) */
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_,
94 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
96 /* single write (offset 0x18 in upm ram) */
97 0x8fffd004, 0x0fffd004, 0x3fffd000, 0xffffd005,
98 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
100 /* burst write (offset 0x20 in upm ram) */
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 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
105 /* refresh (offset 0x30 in upm ram) */
106 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
107 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
108 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
109 /* exception (offset 0x3C in upm ram) */
110 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
114 #ifdef CONFIG_SPC1920_HPI_TEST
117 #define HPI_TEST_CHUNKSIZE 0x1000
118 #define HPI_TEST_PATTERN 0x00000000
119 #define HPI_TEST_START 0x0
120 #define HPI_TEST_END 0x30000
122 #define TINY_AUTOINC_DATA_SIZE 16 /* 32bit words */
123 #define TINY_AUTOINC_BASE_ADDR 0x0
125 static int hpi_activate(void);
126 static void hpi_inactivate(void);
127 static void dsp_reset(void);
129 static int hpi_write_inc(u32 addr, u32 *data, u32 count);
130 static int hpi_read_inc(u32 addr, u32 *buf, u32 count);
131 static int hpi_write_noinc(u32 addr, u32 data);
132 static u32 hpi_read_noinc(u32 addr);
135 static int hpi_write_addr_test(u32 addr);
136 static int hpi_read_write_test(u32 addr, u32 data);
137 static int hpi_tiny_autoinc_test(void);
138 #endif /* CONFIG_SPC1920_HPI_TEST */
141 /* init the host port interface on UPMA */
144 volatile immap_t *immr = (immap_t *) CFG_IMMR;
145 volatile memctl8xx_t *memctl = &immr->im_memctl;
146 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CFG_SPC1920_PLD_BASE;
148 upmconfig(UPMA, (uint *)dsp_table_slow, sizeof(dsp_table_slow)/sizeof(uint));
151 memctl->memc_mamr = CFG_MAMR;
152 memctl->memc_or3 = CFG_OR3_PRELIM;
153 memctl->memc_br3 = CFG_BR3_PRELIM;
158 /* activate hpi switch*/
159 pld->dsp_hpi_on = 0x1;
166 #ifdef CONFIG_SPC1920_HPI_TEST
167 /* activate the Host Port interface */
168 static int hpi_activate(void)
170 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CFG_SPC1920_PLD_BASE;
173 pld->dsp_hpi_on = 0x1;
177 /* turn on the power EN_DSP_POWER high*/
178 /* currently always on TBD */
180 /* setup hpi control register */
181 HPI_HPIC_1 = (u16) 0x0008;
182 HPI_HPIC_2 = (u16) 0x0008;
189 /* turn off the host port interface */
190 static void hpi_inactivate(void)
192 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CFG_SPC1920_PLD_BASE;
195 pld->dsp_hpi_on = 0x0;
198 /* pld->dsp_reset = 0x0; */
200 /* turn off the power EN_DSP_POWER# high*/
201 /* currently always on TBD */
206 static void dsp_reset(void)
208 volatile spc1920_pld_t *pld = (spc1920_pld_t *) CFG_SPC1920_PLD_BASE;
209 pld->dsp_reset = 0x1;
210 pld->dsp_hpi_on = 0x0;
214 pld->dsp_reset = 0x0;
215 pld->dsp_hpi_on = 0x1;
219 /* write using autoinc (count is number of 32bit words) */
220 static int hpi_write_inc(u32 addr, u32 *data, u32 count)
225 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
226 addr2 = (u16) (addr & 0xffff);
232 debugX(4, "writing from data=0x%x to 0x%x\n", data, (data+count));
234 for(i=0; i<count; i++) {
235 HPI_HPID_INC_1 = (u16) ((data[i] >> 16) & 0xffff);
236 HPI_HPID_INC_2 = (u16) (data[i] & 0xffff);
237 debugX(4, "hpi_write_inc: data1=0x%x, data2=0x%x\n",
238 (u16) ((data[i] >> 16) & 0xffff),
239 (u16) (data[i] & 0xffff));
242 while(data_ptr < (u16*) (data + count)) {
243 HPI_HPID_INC_1 = *(data_ptr++);
244 HPI_HPID_INC_2 = *(data_ptr++);
248 /* return number of bytes written */
253 * read using autoinc (count is number of 32bit words)
255 static int hpi_read_inc(u32 addr, u32 *buf, u32 count)
258 u16 addr1, addr2, data1, data2;
260 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
261 addr2 = (u16) (addr & 0xffff);
267 for(i=0; i<count; i++) {
268 data1 = HPI_HPID_INC_1;
269 data2 = HPI_HPID_INC_2;
270 debugX(4, "hpi_read_inc: data1=0x%x, data2=0x%x\n", data1, data2);
271 buf[i] = (((u32) data1) << 16) | (data2 & 0xffff);
275 while(buf_ptr < (u16*) (buf + count)) {
276 *(buf_ptr++) = HPI_HPID_INC_1;
277 *(buf_ptr++) = HPI_HPID_INC_2;
281 /* return number of bytes read */
286 /* write to non- auto inc regs */
287 static int hpi_write_noinc(u32 addr, u32 data)
290 u16 addr1, addr2, data1, data2;
292 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
293 addr2 = (u16) (addr & 0xffff);
295 /* printf("hpi_write_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
300 data1 = (u16) ((data >> 16) & 0xffff);
301 data2 = (u16) (data & 0xffff);
303 /* printf("hpi_write_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
305 HPI_HPID_NOINC_1 = data1;
306 HPI_HPID_NOINC_2 = data2;
311 /* read from non- auto inc regs */
312 static u32 hpi_read_noinc(u32 addr)
314 u16 addr1, addr2, data1, data2;
317 addr1 = (u16) ((addr >> 16) & 0xffff); /* First HW is most significant */
318 addr2 = (u16) (addr & 0xffff);
323 /* printf("hpi_read_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
325 data1 = HPI_HPID_NOINC_1;
326 data2 = HPI_HPID_NOINC_2;
328 /* printf("hpi_read_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
330 ret = (((u32) data1) << 16) | (data2 & 0xffff);
336 * Host Port Interface Tests
339 #ifndef HPI_TEST_OSZI
340 /* main test function */
344 u32 i, ii, pattern, tmp;
346 pattern = HPI_TEST_PATTERN;
348 u32 test_data[HPI_TEST_CHUNKSIZE];
349 u32 read_data[HPI_TEST_CHUNKSIZE];
351 debugX(2, "hpi_test: activating hpi...");
356 /* Dump the first 1024 bytes
359 for(i=0; i<1024; i+=4) {
361 printf("\n0x%08x: ", i);
362 printf("0x%08x ", hpi_read_noinc(i));
366 /* HPIA read-write test
369 debugX(1, "hpi_test: starting HPIA read-write tests...\n");
370 err |= hpi_write_addr_test(0xdeadc0de);
371 err |= hpi_write_addr_test(0xbeefd00d);
372 err |= hpi_write_addr_test(0xabcd1234);
373 err |= hpi_write_addr_test(0xaaaaaaaa);
375 debugX(1, "hpi_test: HPIA read-write tests: *** FAILED ***\n");
378 debugX(1, "hpi_test: HPIA read-write tests: OK\n");
381 /* read write test using nonincremental data regs
384 debugX(1, "hpi_test: starting nonincremental tests...\n");
385 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
386 err |= hpi_read_write_test(i, pattern);
388 /* stolen from cmd_mem.c */
389 if(pattern & 0x80000000) {
390 pattern = -pattern; /* complement & increment */
394 err |= hpi_read_write_test(i, pattern);
397 debugX(1, "hpi_test: nonincremental tests *** FAILED ***\n");
401 debugX(1, "hpi_test: nonincremental test OK\n");
403 /* read write a chunk of data using nonincremental data regs
406 debugX(1, "hpi_test: starting nonincremental chunk tests...\n");
407 pattern = HPI_TEST_PATTERN;
408 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
409 hpi_write_noinc(i, pattern);
411 /* stolen from cmd_mem.c */
412 if(pattern & 0x80000000) {
413 pattern = -pattern; /* complement & increment */
418 pattern = HPI_TEST_PATTERN;
419 for(i=HPI_TEST_START; i<HPI_TEST_END; i+=4) {
420 tmp = hpi_read_noinc(i);
423 debugX(1, "hpi_test: noninc chunk test *** FAILED *** @ 0x%x, written=0x%x, read=0x%x\n", i, pattern, tmp);
426 /* stolen from cmd_mem.c */
427 if(pattern & 0x80000000) {
428 pattern = -pattern; /* complement & increment */
435 debugX(1, "hpi_test: nonincremental chunk test OK\n");
439 /* small verbose test using autoinc and nonautoinc to compare
442 debugX(1, "hpi_test: tiny_autoinc_test...\n");
443 hpi_tiny_autoinc_test();
444 debugX(1, "hpi_test: tiny_autoinc_test done\n");
445 #endif /* DO_TINY_TEST */
448 /* $%& write a chunk of data using the autoincremental regs
451 debugX(1, "hpi_test: starting autoinc test %d chunks with 0x%x bytes...\n",
452 ((HPI_TEST_END - HPI_TEST_START) / HPI_TEST_CHUNKSIZE),
455 for(i=HPI_TEST_START;
456 i < ((HPI_TEST_END - HPI_TEST_START) / HPI_TEST_CHUNKSIZE);
458 /* generate the pattern data */
459 debugX(3, "generating pattern data: ");
460 for(ii = 0; ii < HPI_TEST_CHUNKSIZE; ii++) {
461 debugX(3, "0x%x ", pattern);
463 test_data[ii] = pattern;
464 read_data[ii] = 0x0; /* zero to be sure */
466 /* stolen from cmd_mem.c */
467 if(pattern & 0x80000000) {
468 pattern = -pattern; /* complement & increment */
475 debugX(2, "Writing autoinc data @ 0x%x\n", i);
476 hpi_write_inc(i, test_data, HPI_TEST_CHUNKSIZE);
478 debugX(2, "Reading autoinc data @ 0x%x\n", i);
479 hpi_read_inc(i, read_data, HPI_TEST_CHUNKSIZE);
482 for(ii = 0; ii < HPI_TEST_CHUNKSIZE; ii++) {
483 debugX(3, "hpi_test_autoinc: @ 0x%x, written=0x%x, read=0x%x", i+ii, test_data[ii], read_data[ii]);
484 if(read_data[ii] != test_data[ii]) {
485 debugX(0, "hpi_test: autoinc test @ 0x%x, written=0x%x, read=0x%x *** FAILED ***\n", i+ii, test_data[ii], read_data[ii]);
490 debugX(1, "hpi_test: autoinc test OK\n");
494 #else /* HPI_TEST_OSZI */
498 u32 read_data[TINY_AUTOINC_DATA_SIZE];
500 unsigned int dummy_data[TINY_AUTOINC_DATA_SIZE] = {
501 0x11112222, 0x33334444, 0x55556666, 0x77778888,
502 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
503 0x00010002, 0x00030004, 0x00050006, 0x00070008,
504 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
507 debugX(0, "hpi_test: activating hpi...");
513 debugX(0, " writing to autoinc...\n");
514 hpi_write_inc(TINY_AUTOINC_BASE_ADDR,
515 dummy_data, TINY_AUTOINC_DATA_SIZE);
517 debugX(0, " reading from autoinc...\n");
518 hpi_read_inc(TINY_AUTOINC_BASE_ADDR,
519 read_data, TINY_AUTOINC_DATA_SIZE);
521 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++) {
522 debugX(0, " written=0x%x, read(inc)=0x%x\n",
523 dummy_data[i], read_data[i]);
532 /* test if Host Port Address Register can be written correctly */
533 static int hpi_write_addr_test(u32 addr)
537 HPI_HPIA_1 = ((u16) (addr >> 16)); /* First HW is most significant */
538 HPI_HPIA_2 = ((u16) addr);
540 read_back = (((u32) HPI_HPIA_1)<<16) | ((u32) HPI_HPIA_2);
542 if(read_back == addr) {
543 debugX(2, " hpi_write_addr_test OK: written=0x%x, read=0x%x\n",
547 debugX(0, " hpi_write_addr_test *** FAILED ***: written=0x%x, read=0x%x\n",
555 /* test if a simple read/write sequence succeeds */
556 static int hpi_read_write_test(u32 addr, u32 data)
560 hpi_write_noinc(addr, data);
561 read_back = hpi_read_noinc(addr);
563 if(read_back == data) {
564 debugX(2, " hpi_read_write_test: OK, addr=0x%x written=0x%x, read=0x%x\n", addr, data, read_back);
567 debugX(0, " hpi_read_write_test: *** FAILED ***, addr=0x%x written=0x%x, read=0x%x\n", addr, data, read_back);
574 static int hpi_tiny_autoinc_test(void)
577 u32 read_data[TINY_AUTOINC_DATA_SIZE];
578 u32 read_data_noinc[TINY_AUTOINC_DATA_SIZE];
580 unsigned int dummy_data[TINY_AUTOINC_DATA_SIZE] = {
581 0x11112222, 0x33334444, 0x55556666, 0x77778888,
582 0x9999aaaa, 0xbbbbcccc, 0xddddeeee, 0xffff1111,
583 0x00010002, 0x00030004, 0x00050006, 0x00070008,
584 0x0009000a, 0x000b000c, 0x000d000e, 0x000f0001
587 printf(" writing to autoinc...\n");
588 hpi_write_inc(TINY_AUTOINC_BASE_ADDR, dummy_data, TINY_AUTOINC_DATA_SIZE);
590 printf(" reading from autoinc...\n");
591 hpi_read_inc(TINY_AUTOINC_BASE_ADDR, read_data, TINY_AUTOINC_DATA_SIZE);
593 printf(" reading from noinc for comparison...\n");
594 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++)
595 read_data_noinc[i] = hpi_read_noinc(TINY_AUTOINC_BASE_ADDR+i*4);
597 for(i=0; i < (TINY_AUTOINC_DATA_SIZE); i++) {
598 printf(" written=0x%x, read(inc)=0x%x, read(noinc)=0x%x\n",
599 dummy_data[i], read_data[i], read_data_noinc[i]);
604 #endif /* CONFIG_SPC1920_HPI_TEST */