3 * Markus Klotzbuecher, DENX Software Engineering, mk@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
9 * Host Port Interface (HPI)
28 #define _NOT_USED_ 0xFFFFFFFF
31 * - inserted loops to achieve long CS low and high Periods (~217ns)
32 * - move cs high 2/4 to the right
34 const uint dsp_table_slow
[] =
36 /* single read (offset 0x00 in upm ram) */
37 0x8fffdc04, 0x0fffdc84, 0x0fffdc84, 0x0fffdc00,
38 0x3fffdc04, 0xffffdc84, 0xffffdc84, 0xffffdc05,
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_
,
46 /* single write (offset 0x18 in upm ram) */
47 0x8fffd004, 0x0fffd084, 0x0fffd084, 0x3fffd000,
48 0xffffd084, 0xffffd084, 0xffffd005, _NOT_USED_
,
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_
,
63 /* dsp hpi upm ram table
64 * works fine for noninc access, failes on incremental.
65 * - removed first word
67 const uint dsp_table_fast
[] =
69 /* single read (offset 0x00 in upm ram) */
70 0x8fffdc04, 0x0fffdc04, 0x0fffdc00, 0x3fffdc04,
71 0xffffdc05, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
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_
,
79 /* single write (offset 0x18 in upm ram) */
80 0x8fffd004, 0x0fffd004, 0x3fffd000, 0xffffd005,
81 _NOT_USED_
, _NOT_USED_
, _NOT_USED_
, _NOT_USED_
,
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_
,
97 #ifdef CONFIG_SPC1920_HPI_TEST
100 #define HPI_TEST_CHUNKSIZE 0x1000
101 #define HPI_TEST_PATTERN 0x00000000
102 #define HPI_TEST_START 0x0
103 #define HPI_TEST_END 0x30000
105 #define TINY_AUTOINC_DATA_SIZE 16 /* 32bit words */
106 #define TINY_AUTOINC_BASE_ADDR 0x0
108 static int hpi_activate(void);
110 static void hpi_inactivate(void);
112 static void dsp_reset(void);
114 static int hpi_write_inc(u32 addr
, u32
*data
, u32 count
);
115 static int hpi_read_inc(u32 addr
, u32
*buf
, u32 count
);
116 static int hpi_write_noinc(u32 addr
, u32 data
);
117 static u32
hpi_read_noinc(u32 addr
);
120 static int hpi_write_addr_test(u32 addr
);
121 static int hpi_read_write_test(u32 addr
, u32 data
);
123 static int hpi_tiny_autoinc_test(void);
124 #endif /* DO_TINY_TEST */
125 #endif /* CONFIG_SPC1920_HPI_TEST */
128 /* init the host port interface on UPMA */
131 volatile immap_t
*immr
= (immap_t
*) CONFIG_SYS_IMMR
;
132 volatile memctl8xx_t
*memctl
= &immr
->im_memctl
;
133 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CONFIG_SYS_SPC1920_PLD_BASE
;
135 upmconfig(UPMA
, (uint
*)dsp_table_slow
, sizeof(dsp_table_slow
)/sizeof(uint
));
138 memctl
->memc_mamr
= CONFIG_SYS_MAMR
;
139 memctl
->memc_or3
= CONFIG_SYS_OR3
;
140 memctl
->memc_br3
= CONFIG_SYS_BR3
;
145 /* activate hpi switch*/
146 pld
->dsp_hpi_on
= 0x1;
153 #ifdef CONFIG_SPC1920_HPI_TEST
154 /* activate the Host Port interface */
155 static int hpi_activate(void)
157 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CONFIG_SYS_SPC1920_PLD_BASE
;
160 pld
->dsp_hpi_on
= 0x1;
164 /* turn on the power EN_DSP_POWER high*/
165 /* currently always on TBD */
167 /* setup hpi control register */
168 HPI_HPIC_1
= (u16
) 0x0008;
169 HPI_HPIC_2
= (u16
) 0x0008;
177 /* turn off the host port interface */
178 static void hpi_inactivate(void)
180 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CONFIG_SYS_SPC1920_PLD_BASE
;
183 pld
->dsp_hpi_on
= 0x0;
186 /* pld->dsp_reset = 0x0; */
188 /* turn off the power EN_DSP_POWER# high*/
189 /* currently always on TBD */
195 static void dsp_reset(void)
197 volatile spc1920_pld_t
*pld
= (spc1920_pld_t
*) CONFIG_SYS_SPC1920_PLD_BASE
;
198 pld
->dsp_reset
= 0x1;
199 pld
->dsp_hpi_on
= 0x0;
203 pld
->dsp_reset
= 0x0;
204 pld
->dsp_hpi_on
= 0x1;
208 /* write using autoinc (count is number of 32bit words) */
209 static int hpi_write_inc(u32 addr
, u32
*data
, u32 count
)
214 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
215 addr2
= (u16
) (addr
& 0xffff);
221 debug("writing from data=0x%lx to 0x%lx\n",
222 (ulong
)data
, (ulong
)(data
+count
));
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);
227 debug("hpi_write_inc: data1=0x%x, data2=0x%x\n",
228 (u16
) ((data
[i
] >> 16) & 0xffff),
229 (u16
) (data
[i
] & 0xffff));
232 while(data_ptr
< (u16
*) (data
+ count
)) {
233 HPI_HPID_INC_1
= *(data_ptr
++);
234 HPI_HPID_INC_2
= *(data_ptr
++);
238 /* return number of bytes written */
243 * read using autoinc (count is number of 32bit words)
245 static int hpi_read_inc(u32 addr
, u32
*buf
, u32 count
)
248 u16 addr1
, addr2
, data1
, data2
;
250 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
251 addr2
= (u16
) (addr
& 0xffff);
257 for(i
=0; i
<count
; i
++) {
258 data1
= HPI_HPID_INC_1
;
259 data2
= HPI_HPID_INC_2
;
260 debug("hpi_read_inc: data1=0x%x, data2=0x%x\n", data1
, data2
);
261 buf
[i
] = (((u32
) data1
) << 16) | (data2
& 0xffff);
265 while(buf_ptr
< (u16
*) (buf
+ count
)) {
266 *(buf_ptr
++) = HPI_HPID_INC_1
;
267 *(buf_ptr
++) = HPI_HPID_INC_2
;
271 /* return number of bytes read */
276 /* write to non- auto inc regs */
277 static int hpi_write_noinc(u32 addr
, u32 data
)
280 u16 addr1
, addr2
, data1
, data2
;
282 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
283 addr2
= (u16
) (addr
& 0xffff);
285 /* printf("hpi_write_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
290 data1
= (u16
) ((data
>> 16) & 0xffff);
291 data2
= (u16
) (data
& 0xffff);
293 /* printf("hpi_write_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
295 HPI_HPID_NOINC_1
= data1
;
296 HPI_HPID_NOINC_2
= data2
;
301 /* read from non- auto inc regs */
302 static u32
hpi_read_noinc(u32 addr
)
304 u16 addr1
, addr2
, data1
, data2
;
307 addr1
= (u16
) ((addr
>> 16) & 0xffff); /* First HW is most significant */
308 addr2
= (u16
) (addr
& 0xffff);
313 /* printf("hpi_read_noinc: addr1=0x%x, addr2=0x%x\n", addr1, addr2); */
315 data1
= HPI_HPID_NOINC_1
;
316 data2
= HPI_HPID_NOINC_2
;
318 /* printf("hpi_read_noinc: data1=0x%x, data2=0x%x\n", data1, data2); */
320 ret
= (((u32
) data1
) << 16) | (data2
& 0xffff);
326 * Host Port Interface Tests
329 #ifndef HPI_TEST_OSZI
330 /* main test function */
334 u32 i
, ii
, pattern
, tmp
;
336 pattern
= HPI_TEST_PATTERN
;
338 u32 test_data
[HPI_TEST_CHUNKSIZE
];
339 u32 read_data
[HPI_TEST_CHUNKSIZE
];
341 debug("hpi_test: activating hpi...");
346 /* Dump the first 1024 bytes
349 for(i
=0; i
<1024; i
+=4) {
351 printf("\n0x%08x: ", i
);
352 printf("0x%08x ", hpi_read_noinc(i
));
356 /* HPIA read-write test
359 debug("hpi_test: starting HPIA read-write tests...\n");
360 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);
365 debug("hpi_test: HPIA read-write tests: *** FAILED ***\n");
368 debug("hpi_test: HPIA read-write tests: OK\n");
371 /* read write test using nonincremental data regs
374 debug("hpi_test: starting nonincremental tests...\n");
375 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
376 err
|= hpi_read_write_test(i
, pattern
);
378 /* stolen from cmd_mem.c */
379 if(pattern
& 0x80000000) {
380 pattern
= -pattern
; /* complement & increment */
384 err
|= hpi_read_write_test(i
, pattern
);
387 debug("hpi_test: nonincremental tests *** FAILED ***\n");
391 debug("hpi_test: nonincremental test OK\n");
393 /* read write a chunk of data using nonincremental data regs
396 debug("hpi_test: starting nonincremental chunk tests...\n");
397 pattern
= HPI_TEST_PATTERN
;
398 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
399 hpi_write_noinc(i
, pattern
);
401 /* stolen from cmd_mem.c */
402 if(pattern
& 0x80000000) {
403 pattern
= -pattern
; /* complement & increment */
408 pattern
= HPI_TEST_PATTERN
;
409 for(i
=HPI_TEST_START
; i
<HPI_TEST_END
; i
+=4) {
410 tmp
= hpi_read_noinc(i
);
413 debug("hpi_test: noninc chunk test *** FAILED *** @ 0x%x, written=0x%x, read=0x%x\n", i
, pattern
, tmp
);
416 /* stolen from cmd_mem.c */
417 if(pattern
& 0x80000000) {
418 pattern
= -pattern
; /* complement & increment */
425 debug("hpi_test: nonincremental chunk test OK\n");
429 /* small verbose test using autoinc and nonautoinc to compare
432 debug("hpi_test: tiny_autoinc_test...\n");
433 hpi_tiny_autoinc_test();
434 debug("hpi_test: tiny_autoinc_test done\n");
435 #endif /* DO_TINY_TEST */
438 /* $%& write a chunk of data using the autoincremental regs
441 debug("hpi_test: starting autoinc test %d chunks with 0x%x bytes...\n",
442 ((HPI_TEST_END
- HPI_TEST_START
) / HPI_TEST_CHUNKSIZE
),
445 for(i
=HPI_TEST_START
;
446 i
< ((HPI_TEST_END
- HPI_TEST_START
) / HPI_TEST_CHUNKSIZE
);
448 /* generate the pattern data */
449 debug("generating pattern data: ");
450 for(ii
= 0; ii
< HPI_TEST_CHUNKSIZE
; ii
++) {
451 debug("0x%x ", pattern
);
453 test_data
[ii
] = pattern
;
454 read_data
[ii
] = 0x0; /* zero to be sure */
456 /* stolen from cmd_mem.c */
457 if(pattern
& 0x80000000) {
458 pattern
= -pattern
; /* complement & increment */
465 debug("Writing autoinc data @ 0x%x\n", i
);
466 hpi_write_inc(i
, test_data
, HPI_TEST_CHUNKSIZE
);
468 debug("Reading autoinc data @ 0x%x\n", i
);
469 hpi_read_inc(i
, read_data
, HPI_TEST_CHUNKSIZE
);
472 for(ii
= 0; ii
< HPI_TEST_CHUNKSIZE
; ii
++) {
473 debug("hpi_test_autoinc: @ 0x%x, written=0x%x, read=0x%x", i
+ii
, test_data
[ii
], read_data
[ii
]);
474 if(read_data
[ii
] != test_data
[ii
]) {
475 debug("hpi_test: autoinc test @ 0x%x, written=0x%x, read=0x%x *** FAILED ***\n", i
+ii
, test_data
[ii
], read_data
[ii
]);
480 debug("hpi_test: autoinc test OK\n");
484 #else /* HPI_TEST_OSZI */
488 u32 read_data
[TINY_AUTOINC_DATA_SIZE
];
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
497 debug("hpi_test: activating hpi...");
503 debug(" writing to autoinc...\n");
504 hpi_write_inc(TINY_AUTOINC_BASE_ADDR
,
505 dummy_data
, TINY_AUTOINC_DATA_SIZE
);
507 debug(" reading from autoinc...\n");
508 hpi_read_inc(TINY_AUTOINC_BASE_ADDR
,
509 read_data
, TINY_AUTOINC_DATA_SIZE
);
511 for(i
=0; i
< (TINY_AUTOINC_DATA_SIZE
); i
++) {
512 debug(" written=0x%x, read(inc)=0x%x\n",
513 dummy_data
[i
], read_data
[i
]);
522 /* test if Host Port Address Register can be written correctly */
523 static int hpi_write_addr_test(u32 addr
)
527 HPI_HPIA_1
= ((u16
) (addr
>> 16)); /* First HW is most significant */
528 HPI_HPIA_2
= ((u16
) addr
);
530 read_back
= (((u32
) HPI_HPIA_1
)<<16) | ((u32
) HPI_HPIA_2
);
532 if(read_back
== addr
) {
533 debug(" hpi_write_addr_test OK: written=0x%x, read=0x%x\n",
537 debug(" hpi_write_addr_test *** FAILED ***: written=0x%x, read=0x%x\n",
545 /* test if a simple read/write sequence succeeds */
546 static int hpi_read_write_test(u32 addr
, u32 data
)
550 hpi_write_noinc(addr
, data
);
551 read_back
= hpi_read_noinc(addr
);
553 if(read_back
== data
) {
554 debug(" hpi_read_write_test: OK, addr=0x%x written=0x%x, read=0x%x\n", addr
, data
, read_back
);
557 debug(" hpi_read_write_test: *** FAILED ***, addr=0x%x written=0x%x, read=0x%x\n", addr
, data
, read_back
);
565 static int hpi_tiny_autoinc_test(void)
568 u32 read_data
[TINY_AUTOINC_DATA_SIZE
];
569 u32 read_data_noinc
[TINY_AUTOINC_DATA_SIZE
];
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
578 printf(" writing to autoinc...\n");
579 hpi_write_inc(TINY_AUTOINC_BASE_ADDR
, dummy_data
, TINY_AUTOINC_DATA_SIZE
);
581 printf(" reading from autoinc...\n");
582 hpi_read_inc(TINY_AUTOINC_BASE_ADDR
, read_data
, TINY_AUTOINC_DATA_SIZE
);
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);
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
]);
594 #endif /* DO_TINY_TEST */
596 #endif /* CONFIG_SPC1920_HPI_TEST */