3 * Wolfgang Denk, DENX Software Engineering, wd@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,
29 * The Serial Management Controllers (SMC) and the Serial Communication
30 * Controllers (SCC) listed in ctlr_list array below are tested in
31 * the loopback UART mode.
32 * The controllers are configured accordingly and several characters
33 * are transmitted. The configurable test parameters are:
34 * MIN_PACKET_LENGTH - minimum size of packet to transmit
35 * MAX_PACKET_LENGTH - maximum size of packet to transmit
36 * TEST_NUM - number of tests
42 #if CONFIG_POST & CFG_POST_UART
43 #if defined(CONFIG_8xx)
45 #elif defined(CONFIG_MPC8260)
46 #include <asm/cpm_8260.h>
48 #error "Apparently a bad configuration, please fix."
56 /* The list of controllers to test */
57 #if defined(CONFIG_MPC823)
58 static int ctlr_list[][2] =
59 { {CTLR_SMC, 0}, {CTLR_SMC, 1}, {CTLR_SCC, 1} };
61 static int ctlr_list[][2] = { };
64 #define CTRL_LIST_SIZE (sizeof(ctlr_list) / sizeof(ctlr_list[0]))
67 void (*init) (int index);
68 void (*halt) (int index);
69 void (*putc) (int index, const char c);
70 int (*getc) (int index);
73 static char *ctlr_name[2] = { "SMC", "SCC" };
75 static int proff_smc[] = { PROFF_SMC1, PROFF_SMC2 };
76 static int proff_scc[] =
77 { PROFF_SCC1, PROFF_SCC2, PROFF_SCC3, PROFF_SCC4 };
83 static void smc_init (int smc_index)
85 DECLARE_GLOBAL_DATA_PTR;
87 static int cpm_cr_ch[] = { CPM_CR_CH_SMC1, CPM_CR_CH_SMC2 };
89 volatile immap_t *im = (immap_t *) CFG_IMMR;
91 volatile smc_uart_t *up;
92 volatile cbd_t *tbdf, *rbdf;
93 volatile cpm8xx_t *cp = &(im->im_cpm);
96 /* initialize pointers to SMC */
98 sp = (smc_t *) & (cp->cp_smc[smc_index]);
99 up = (smc_uart_t *) & cp->cp_dparam[proff_smc[smc_index]];
101 /* Disable transmitter/receiver.
103 sp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
107 im->im_siu_conf.sc_sdcr = 1;
109 /* clear error conditions */
111 im->im_sdma.sdma_sdsr = CFG_SDSR;
113 im->im_sdma.sdma_sdsr = 0x83;
116 /* clear SDMA interrupt mask */
118 im->im_sdma.sdma_sdmr = CFG_SDMR;
120 im->im_sdma.sdma_sdmr = 0x00;
123 #if defined(CONFIG_FADS)
126 ~(smc_index == 1 ? BCSR1_RS232EN_1 : BCSR1_RS232EN_2);
129 #if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
130 /* Enable Monitor Port Transceiver */
131 *((uchar *) BCSR0) |= BCSR0_ENMONXCVR;
134 /* Set the physical address of the host memory buffers in
135 * the buffer descriptors.
138 #ifdef CFG_ALLOC_DPRAM
139 dpaddr = dpram_alloc_align (sizeof (cbd_t) * 2 + 2, 8);
141 dpaddr = CPM_POST_BASE;
144 /* Allocate space for two buffer descriptors in the DP ram.
145 * For now, this address seems OK, but it may have to
146 * change with newer versions of the firmware.
147 * damm: allocating space after the two buffers for rx/tx data
150 rbdf = (cbd_t *) & cp->cp_dpmem[dpaddr];
151 rbdf->cbd_bufaddr = (uint) (rbdf + 2);
154 tbdf->cbd_bufaddr = ((uint) (rbdf + 2)) + 1;
157 /* Set up the uart parameters in the parameter ram.
159 up->smc_rbase = dpaddr;
160 up->smc_tbase = dpaddr + sizeof (cbd_t);
161 up->smc_rfcr = SMC_EB;
162 up->smc_tfcr = SMC_EB;
164 #if defined(CONFIG_MBX)
165 board_serial_init ();
168 /* Set UART mode, 8 bit, no parity, one stop.
169 * Enable receive and transmit.
170 * Set local loopback mode.
172 sp->smc_smcmr = smcr_mk_clen (9) | SMCMR_SM_UART | (ushort) 0x0004;
174 /* Mask all interrupts and remove anything pending.
179 /* Set up the baud rate generator.
181 cp->cp_simode = 0x00000000;
184 (((gd->cpu_clk / 16 / gd->baudrate) -
185 1) << 1) | CPM_BRG_EN;
187 /* Make the first buffer the only buffer.
189 tbdf->cbd_sc |= BD_SC_WRAP;
190 rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
192 /* Single character receive.
197 /* Initialize Tx/Rx parameters.
200 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
204 mk_cr_cmd (cpm_cr_ch[smc_index], CPM_CR_INIT_TRX) | CPM_CR_FLG;
206 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
209 /* Enable transmitter/receiver.
211 sp->smc_smcmr |= SMCMR_REN | SMCMR_TEN;
214 static void smc_halt(int smc_index)
218 static void smc_putc (int smc_index, const char c)
220 volatile cbd_t *tbdf;
222 volatile smc_uart_t *up;
223 volatile immap_t *im = (immap_t *) CFG_IMMR;
224 volatile cpm8xx_t *cpmp = &(im->im_cpm);
226 up = (smc_uart_t *) & cpmp->cp_dparam[proff_smc[smc_index]];
228 tbdf = (cbd_t *) & cpmp->cp_dpmem[up->smc_tbase];
230 /* Wait for last character to go.
233 buf = (char *) tbdf->cbd_bufaddr;
236 while (tbdf->cbd_sc & BD_SC_READY)
241 tbdf->cbd_datlen = 1;
242 tbdf->cbd_sc |= BD_SC_READY;
245 while (tbdf->cbd_sc & BD_SC_READY)
250 static int smc_getc (int smc_index)
252 volatile cbd_t *rbdf;
253 volatile unsigned char *buf;
254 volatile smc_uart_t *up;
255 volatile immap_t *im = (immap_t *) CFG_IMMR;
256 volatile cpm8xx_t *cpmp = &(im->im_cpm);
260 up = (smc_uart_t *) & cpmp->cp_dparam[proff_smc[smc_index]];
262 rbdf = (cbd_t *) & cpmp->cp_dpmem[up->smc_rbase];
264 /* Wait for character to show up.
266 buf = (unsigned char *) rbdf->cbd_bufaddr;
268 while (rbdf->cbd_sc & BD_SC_EMPTY);
270 for (i = 100; i > 0; i--) {
271 if (!(rbdf->cbd_sc & BD_SC_EMPTY))
280 rbdf->cbd_sc |= BD_SC_EMPTY;
289 static void scc_init (int scc_index)
291 DECLARE_GLOBAL_DATA_PTR;
293 static int cpm_cr_ch[] = {
300 volatile immap_t *im = (immap_t *) CFG_IMMR;
302 volatile scc_uart_t *up;
303 volatile cbd_t *tbdf, *rbdf;
304 volatile cpm8xx_t *cp = &(im->im_cpm);
307 /* initialize pointers to SCC */
309 sp = (scc_t *) & (cp->cp_scc[scc_index]);
310 up = (scc_uart_t *) & cp->cp_dparam[proff_scc[scc_index]];
312 /* Disable transmitter/receiver.
314 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
317 /* Allocate space for two buffer descriptors in the DP ram.
320 #ifdef CFG_ALLOC_DPRAM
321 dpaddr = dpram_alloc_align (sizeof (cbd_t) * 2 + 2, 8);
323 dpaddr = CPM_POST_BASE;
328 im->im_siu_conf.sc_sdcr = 0x0001;
330 /* Set the physical address of the host memory buffers in
331 * the buffer descriptors.
334 rbdf = (cbd_t *) & cp->cp_dpmem[dpaddr];
335 rbdf->cbd_bufaddr = (uint) (rbdf + 2);
338 tbdf->cbd_bufaddr = ((uint) (rbdf + 2)) + 1;
341 /* Set up the baud rate generator.
343 cp->cp_sicr &= ~(0x000000FF << (8 * scc_index));
344 /* no |= needed, since BRG1 is 000 */
347 (((gd->cpu_clk / 16 / gd->baudrate) -
348 1) << 1) | CPM_BRG_EN;
350 /* Set up the uart parameters in the parameter ram.
352 up->scc_genscc.scc_rbase = dpaddr;
353 up->scc_genscc.scc_tbase = dpaddr + sizeof (cbd_t);
355 /* Initialize Tx/Rx parameters.
357 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
360 mk_cr_cmd (cpm_cr_ch[scc_index], CPM_CR_INIT_TRX) | CPM_CR_FLG;
362 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
365 up->scc_genscc.scc_rfcr = SCC_EB | 0x05;
366 up->scc_genscc.scc_tfcr = SCC_EB | 0x05;
368 up->scc_genscc.scc_mrblr = 1; /* Single character receive */
369 up->scc_maxidl = 0; /* disable max idle */
370 up->scc_brkcr = 1; /* send one break character on stop TX */
378 up->scc_char1 = 0x8000;
379 up->scc_char2 = 0x8000;
380 up->scc_char3 = 0x8000;
381 up->scc_char4 = 0x8000;
382 up->scc_char5 = 0x8000;
383 up->scc_char6 = 0x8000;
384 up->scc_char7 = 0x8000;
385 up->scc_char8 = 0x8000;
386 up->scc_rccm = 0xc0ff;
388 /* Set low latency / small fifo.
390 sp->scc_gsmrh = SCC_GSMRH_RFW;
394 sp->scc_gsmrl &= ~0xF;
395 sp->scc_gsmrl |= SCC_GSMRL_MODE_UART;
397 /* Set local loopback mode.
399 sp->scc_gsmrl &= ~SCC_GSMRL_DIAG_LE;
400 sp->scc_gsmrl |= SCC_GSMRL_DIAG_LOOP;
402 /* Set clock divider 16 on Tx and Rx
404 sp->scc_gsmrl |= (SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
406 sp->scc_psmr |= SCU_PSMR_CL;
408 /* Mask all interrupts and remove anything pending.
411 sp->scc_scce = 0xffff;
412 sp->scc_dsr = 0x7e7e;
413 sp->scc_psmr = 0x3000;
415 /* Make the first buffer the only buffer.
417 tbdf->cbd_sc |= BD_SC_WRAP;
418 rbdf->cbd_sc |= BD_SC_EMPTY | BD_SC_WRAP;
420 /* Enable transmitter/receiver.
422 sp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
425 static void scc_halt(int scc_index)
427 volatile immap_t *im = (immap_t *) CFG_IMMR;
428 volatile cpm8xx_t *cp = &(im->im_cpm);
429 volatile scc_t *sp = (scc_t *) & (cp->cp_scc[scc_index]);
431 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT | SCC_GSMRL_DIAG_LE);
434 static void scc_putc (int scc_index, const char c)
436 volatile cbd_t *tbdf;
438 volatile scc_uart_t *up;
439 volatile immap_t *im = (immap_t *) CFG_IMMR;
440 volatile cpm8xx_t *cpmp = &(im->im_cpm);
442 up = (scc_uart_t *) & cpmp->cp_dparam[proff_scc[scc_index]];
444 tbdf = (cbd_t *) & cpmp->cp_dpmem[up->scc_genscc.scc_tbase];
446 /* Wait for last character to go.
449 buf = (char *) tbdf->cbd_bufaddr;
452 while (tbdf->cbd_sc & BD_SC_READY)
457 tbdf->cbd_datlen = 1;
458 tbdf->cbd_sc |= BD_SC_READY;
461 while (tbdf->cbd_sc & BD_SC_READY)
466 static int scc_getc (int scc_index)
468 volatile cbd_t *rbdf;
469 volatile unsigned char *buf;
470 volatile scc_uart_t *up;
471 volatile immap_t *im = (immap_t *) CFG_IMMR;
472 volatile cpm8xx_t *cpmp = &(im->im_cpm);
476 up = (scc_uart_t *) & cpmp->cp_dparam[proff_scc[scc_index]];
478 rbdf = (cbd_t *) & cpmp->cp_dpmem[up->scc_genscc.scc_rbase];
480 /* Wait for character to show up.
482 buf = (unsigned char *) rbdf->cbd_bufaddr;
484 while (rbdf->cbd_sc & BD_SC_EMPTY);
486 for (i = 100; i > 0; i--) {
487 if (!(rbdf->cbd_sc & BD_SC_EMPTY))
496 rbdf->cbd_sc |= BD_SC_EMPTY;
505 static int test_ctlr (int ctlr, int index)
508 char test_str[] = "*** UART Test String ***\r\n";
511 ctlr_proc[ctlr].init (index);
513 for (i = 0; i < sizeof (test_str) - 1; i++) {
514 ctlr_proc[ctlr].putc (index, test_str[i]);
515 if (ctlr_proc[ctlr].getc (index) != test_str[i])
522 ctlr_proc[ctlr].halt (index);
525 post_log ("uart %s%d test failed\n",
526 ctlr_name[ctlr], index + 1);
532 int uart_post_test (int flags)
537 ctlr_proc[CTLR_SMC].init = smc_init;
538 ctlr_proc[CTLR_SMC].halt = smc_halt;
539 ctlr_proc[CTLR_SMC].putc = smc_putc;
540 ctlr_proc[CTLR_SMC].getc = smc_getc;
542 ctlr_proc[CTLR_SCC].init = scc_init;
543 ctlr_proc[CTLR_SCC].halt = scc_halt;
544 ctlr_proc[CTLR_SCC].putc = scc_putc;
545 ctlr_proc[CTLR_SCC].getc = scc_getc;
547 for (i = 0; i < CTRL_LIST_SIZE; i++) {
548 if (test_ctlr (ctlr_list[i][0], ctlr_list[i][1]) != 0) {
553 #if !defined(CONFIG_8xx_CONS_NONE)
554 serial_reinit_all ();
560 #endif /* CONFIG_POST & CFG_POST_UART */
562 #endif /* CONFIG_POST */