3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
7 * Hacked for MPC8260 by Murray.Jensen@cmst.csiro.au, 19-Oct-00.
11 * Minimal serial functions needed to use one of the SCC ports
12 * as serial console interface.
17 #include <asm/cpm_8260.h>
19 #include <linux/compiler.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 #if defined(CONFIG_CONS_ON_SCC)
25 #if CONFIG_CONS_INDEX == 1 /* Console on SCC1 */
28 #define PROFF_SCC PROFF_SCC1
29 #define CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
30 CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
31 #define CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
32 #define CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
33 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
35 #elif CONFIG_CONS_INDEX == 2 /* Console on SCC2 */
38 #define PROFF_SCC PROFF_SCC2
39 #define CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
40 CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
41 #define CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
42 #define CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
43 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
45 #elif CONFIG_CONS_INDEX == 3 /* Console on SCC3 */
48 #define PROFF_SCC PROFF_SCC3
49 #define CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
50 CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
51 #define CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
52 #define CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
53 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
55 #elif CONFIG_CONS_INDEX == 4 /* Console on SCC4 */
58 #define PROFF_SCC PROFF_SCC4
59 #define CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
60 CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
61 #define CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
62 #define CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
63 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
67 #error "console not correctly defined"
71 static int mpc8260_scc_serial_init(void)
73 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
75 volatile scc_uart_t *up;
76 volatile cbd_t *tbdf, *rbdf;
77 volatile cpm8260_t *cp = &(im->im_cpm);
80 /* initialize pointers to SCC */
82 sp = (scc_t *) &(im->im_scc[SCC_INDEX]);
83 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
85 /* Disable transmitter/receiver.
87 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
89 /* put the SCC channel into NMSI (non multiplexd serial interface)
90 * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
92 im->im_cpmux.cmx_scr = (im->im_cpmux.cmx_scr&~CMXSCR_MASK)|CMXSCR_VALUE;
94 /* Set up the baud rate generator.
98 /* Allocate space for two buffer descriptors in the DP ram.
99 * damm: allocating space after the two buffers for rx/tx data
102 dpaddr = m8260_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
104 /* Set the physical address of the host memory buffers in
105 * the buffer descriptors.
107 rbdf = (cbd_t *)&im->im_dprambase[dpaddr];
108 rbdf->cbd_bufaddr = (uint) (rbdf+2);
109 rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
111 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
112 tbdf->cbd_sc = BD_SC_WRAP;
114 /* Set up the uart parameters in the parameter ram.
116 up->scc_genscc.scc_rbase = dpaddr;
117 up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
118 up->scc_genscc.scc_rfcr = CPMFCR_EB;
119 up->scc_genscc.scc_tfcr = CPMFCR_EB;
120 up->scc_genscc.scc_mrblr = 1;
130 up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
131 up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
132 up->scc_rccm = 0xc0ff;
134 /* Mask all interrupts and remove anything pending.
137 sp->scc_scce = 0xffff;
139 /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
141 sp->scc_gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
143 SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
145 /* Set CTS flow control, 1 stop bit, 8 bit character length,
146 * normal async UART mode, no parity
148 sp->scc_psmr = SCU_PSMR_FLC | SCU_PSMR_CL;
150 /* execute the "Init Rx and Tx params" CP command.
153 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
156 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SCC_PAGE, CPM_CR_SCC_SBLOCK,
157 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
159 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
162 /* Enable transmitter/receiver.
164 sp->scc_gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
169 static void mpc8260_scc_serial_setbrg(void)
171 #if defined(CONFIG_CONS_USE_EXTC)
172 m8260_cpm_extcbrg(SCC_INDEX, gd->baudrate,
173 CONFIG_CONS_EXTC_RATE, CONFIG_CONS_EXTC_PINSEL);
175 m8260_cpm_setbrg(SCC_INDEX, gd->baudrate);
179 static void mpc8260_scc_serial_putc(const char c)
181 volatile scc_uart_t *up;
182 volatile cbd_t *tbdf;
183 volatile immap_t *im;
188 im = (immap_t *)CONFIG_SYS_IMMR;
189 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
190 tbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_tbase];
192 /* Wait for last character to go.
194 while (tbdf->cbd_sc & BD_SC_READY)
197 /* Load the character into the transmit buffer.
199 *(volatile char *)tbdf->cbd_bufaddr = c;
200 tbdf->cbd_datlen = 1;
201 tbdf->cbd_sc |= BD_SC_READY;
204 static int mpc8260_scc_serial_getc(void)
206 volatile cbd_t *rbdf;
207 volatile scc_uart_t *up;
208 volatile immap_t *im;
211 im = (immap_t *)CONFIG_SYS_IMMR;
212 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
213 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
215 /* Wait for character to show up.
217 while (rbdf->cbd_sc & BD_SC_EMPTY)
220 /* Grab the char and clear the buffer again.
222 c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
223 rbdf->cbd_sc |= BD_SC_EMPTY;
228 static int mpc8260_scc_serial_tstc(void)
230 volatile cbd_t *rbdf;
231 volatile scc_uart_t *up;
232 volatile immap_t *im;
234 im = (immap_t *)CONFIG_SYS_IMMR;
235 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
236 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
238 return ((rbdf->cbd_sc & BD_SC_EMPTY) == 0);
241 static struct serial_device mpc8260_scc_serial_drv = {
242 .name = "mpc8260_scc_uart",
243 .start = mpc8260_scc_serial_init,
245 .setbrg = mpc8260_scc_serial_setbrg,
246 .putc = mpc8260_scc_serial_putc,
247 .puts = default_serial_puts,
248 .getc = mpc8260_scc_serial_getc,
249 .tstc = mpc8260_scc_serial_tstc,
252 void mpc8260_scc_serial_initialize(void)
254 serial_register(&mpc8260_scc_serial_drv);
257 __weak struct serial_device *default_serial_console(void)
259 return &mpc8260_scc_serial_drv;
261 #endif /* CONFIG_CONS_ON_SCC */
263 #if defined(CONFIG_KGDB_ON_SCC)
265 #if defined(CONFIG_CONS_ON_SCC) && CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
266 #error Whoops! serial console and kgdb are on the same scc serial port
269 #if CONFIG_KGDB_INDEX == 1 /* KGDB Port on SCC1 */
271 #define KGDB_SCC_INDEX 0
272 #define KGDB_PROFF_SCC PROFF_SCC1
273 #define KGDB_CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
274 CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
275 #define KGDB_CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
276 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
277 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
279 #elif CONFIG_KGDB_INDEX == 2 /* KGDB Port on SCC2 */
281 #define KGDB_SCC_INDEX 1
282 #define KGDB_PROFF_SCC PROFF_SCC2
283 #define KGDB_CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
284 CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
285 #define KGDB_CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
286 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
287 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
289 #elif CONFIG_KGDB_INDEX == 3 /* KGDB Port on SCC3 */
291 #define KGDB_SCC_INDEX 2
292 #define KGDB_PROFF_SCC PROFF_SCC3
293 #define KGDB_CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
294 CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
295 #define KGDB_CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
296 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
297 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
299 #elif CONFIG_KGDB_INDEX == 4 /* KGDB Port on SCC4 */
301 #define KGDB_SCC_INDEX 3
302 #define KGDB_PROFF_SCC PROFF_SCC4
303 #define KGDB_CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
304 CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
305 #define KGDB_CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
306 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
307 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
311 #error "kgdb serial port not correctly defined"
316 kgdb_serial_init (void)
318 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
320 volatile scc_uart_t *up;
321 volatile cbd_t *tbdf, *rbdf;
322 volatile cpm8260_t *cp = &(im->im_cpm);
323 uint dpaddr, speed = CONFIG_KGDB_BAUDRATE;
326 if ((s = getenv("kgdbrate")) != NULL && *s != '\0') {
327 ulong rate = simple_strtoul(s, &e, 10);
328 if (e > s && *e == '\0')
332 /* initialize pointers to SCC */
334 sp = (scc_t *) &(im->im_scc[KGDB_SCC_INDEX]);
335 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
337 /* Disable transmitter/receiver.
339 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
341 /* put the SCC channel into NMSI (non multiplexd serial interface)
342 * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
344 im->im_cpmux.cmx_scr = \
345 (im->im_cpmux.cmx_scr & ~KGDB_CMXSCR_MASK) | KGDB_CMXSCR_VALUE;
347 /* Set up the baud rate generator.
349 #if defined(CONFIG_KGDB_USE_EXTC)
350 m8260_cpm_extcbrg(KGDB_SCC_INDEX, speed,
351 CONFIG_KGDB_EXTC_RATE, CONFIG_KGDB_EXTC_PINSEL);
353 m8260_cpm_setbrg(KGDB_SCC_INDEX, speed);
356 /* Allocate space for two buffer descriptors in the DP ram.
357 * damm: allocating space after the two buffers for rx/tx data
360 dpaddr = m8260_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
362 /* Set the physical address of the host memory buffers in
363 * the buffer descriptors.
365 rbdf = (cbd_t *)&im->im_dprambase[dpaddr];
366 rbdf->cbd_bufaddr = (uint) (rbdf+2);
367 rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
369 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
370 tbdf->cbd_sc = BD_SC_WRAP;
372 /* Set up the uart parameters in the parameter ram.
374 up->scc_genscc.scc_rbase = dpaddr;
375 up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
376 up->scc_genscc.scc_rfcr = CPMFCR_EB;
377 up->scc_genscc.scc_tfcr = CPMFCR_EB;
378 up->scc_genscc.scc_mrblr = 1;
388 up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
389 up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
390 up->scc_rccm = 0xc0ff;
392 /* Mask all interrupts and remove anything pending.
395 sp->scc_scce = 0xffff;
397 /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
399 sp->scc_gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
401 SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
403 /* Set CTS flow control, 1 stop bit, 8 bit character length,
404 * normal async UART mode, no parity
406 sp->scc_psmr = SCU_PSMR_FLC | SCU_PSMR_CL;
408 /* execute the "Init Rx and Tx params" CP command.
411 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
414 cp->cp_cpcr = mk_cr_cmd(KGDB_CPM_CR_SCC_PAGE, KGDB_CPM_CR_SCC_SBLOCK,
415 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
417 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
420 /* Enable transmitter/receiver.
422 sp->scc_gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
424 printf("SCC%d at %dbps ", CONFIG_KGDB_INDEX, speed);
428 putDebugChar(const char c)
430 volatile scc_uart_t *up;
431 volatile cbd_t *tbdf;
432 volatile immap_t *im;
437 im = (immap_t *)CONFIG_SYS_IMMR;
438 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
439 tbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_tbase];
441 /* Wait for last character to go.
443 while (tbdf->cbd_sc & BD_SC_READY)
446 /* Load the character into the transmit buffer.
448 *(volatile char *)tbdf->cbd_bufaddr = c;
449 tbdf->cbd_datlen = 1;
450 tbdf->cbd_sc |= BD_SC_READY;
454 putDebugStr (const char *s)
464 volatile cbd_t *rbdf;
465 volatile scc_uart_t *up;
466 volatile immap_t *im;
469 im = (immap_t *)CONFIG_SYS_IMMR;
470 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
471 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
473 /* Wait for character to show up.
475 while (rbdf->cbd_sc & BD_SC_EMPTY)
478 /* Grab the char and clear the buffer again.
480 c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
481 rbdf->cbd_sc |= BD_SC_EMPTY;
487 kgdb_interruptible(int yes)
492 #endif /* CONFIG_KGDB_ON_SCC */