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,
27 * Minimal serial functions needed to use one of the SCC ports
28 * as serial console interface.
33 #include <asm/cpm_8260.h>
35 #if defined(CONFIG_CONS_ON_SCC)
37 #if CONFIG_CONS_INDEX == 1 /* Console on SCC1 */
40 #define PROFF_SCC PROFF_SCC1
41 #define CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
42 CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
43 #define CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
44 #define CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
45 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
47 #elif CONFIG_CONS_INDEX == 2 /* Console on SCC2 */
50 #define PROFF_SCC PROFF_SCC2
51 #define CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
52 CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
53 #define CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
54 #define CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
55 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
57 #elif CONFIG_CONS_INDEX == 3 /* Console on SCC3 */
60 #define PROFF_SCC PROFF_SCC3
61 #define CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
62 CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
63 #define CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
64 #define CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
65 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
67 #elif CONFIG_CONS_INDEX == 4 /* Console on SCC4 */
70 #define PROFF_SCC PROFF_SCC4
71 #define CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
72 CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
73 #define CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
74 #define CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
75 #define CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
79 #error "console not correctly defined"
83 int serial_init (void)
85 volatile immap_t *im = (immap_t *)CFG_IMMR;
87 volatile scc_uart_t *up;
88 volatile cbd_t *tbdf, *rbdf;
89 volatile cpm8260_t *cp = &(im->im_cpm);
92 /* initialize pointers to SCC */
94 sp = (scc_t *) &(im->im_scc[SCC_INDEX]);
95 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
97 /* Disable transmitter/receiver.
99 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
101 /* put the SCC channel into NMSI (non multiplexd serial interface)
102 * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
104 im->im_cpmux.cmx_scr = (im->im_cpmux.cmx_scr&~CMXSCR_MASK)|CMXSCR_VALUE;
106 /* Set up the baud rate generator.
110 /* Allocate space for two buffer descriptors in the DP ram.
111 * damm: allocating space after the two buffers for rx/tx data
114 dpaddr = m8260_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
116 /* Set the physical address of the host memory buffers in
117 * the buffer descriptors.
119 rbdf = (cbd_t *)&im->im_dprambase[dpaddr];
120 rbdf->cbd_bufaddr = (uint) (rbdf+2);
121 rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
123 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
124 tbdf->cbd_sc = BD_SC_WRAP;
126 /* Set up the uart parameters in the parameter ram.
128 up->scc_genscc.scc_rbase = dpaddr;
129 up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
130 up->scc_genscc.scc_rfcr = CPMFCR_EB;
131 up->scc_genscc.scc_tfcr = CPMFCR_EB;
132 up->scc_genscc.scc_mrblr = 1;
142 up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
143 up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
144 up->scc_rccm = 0xc0ff;
146 /* Mask all interrupts and remove anything pending.
149 sp->scc_scce = 0xffff;
151 /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
153 sp->scc_gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
155 SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
157 /* Set CTS flow control, 1 stop bit, 8 bit character length,
158 * normal async UART mode, no parity
160 sp->scc_psmr = SCU_PSMR_FLC | SCU_PSMR_CL;
162 /* execute the "Init Rx and Tx params" CP command.
165 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
168 cp->cp_cpcr = mk_cr_cmd(CPM_CR_SCC_PAGE, CPM_CR_SCC_SBLOCK,
169 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
171 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
174 /* Enable transmitter/receiver.
176 sp->scc_gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
184 DECLARE_GLOBAL_DATA_PTR;
186 #if defined(CONFIG_CONS_USE_EXTC)
187 m8260_cpm_extcbrg(SCC_INDEX, gd->baudrate,
188 CONFIG_CONS_EXTC_RATE, CONFIG_CONS_EXTC_PINSEL);
190 m8260_cpm_setbrg(SCC_INDEX, gd->baudrate);
195 serial_putc(const char c)
197 volatile scc_uart_t *up;
198 volatile cbd_t *tbdf;
199 volatile immap_t *im;
204 im = (immap_t *)CFG_IMMR;
205 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
206 tbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_tbase];
208 /* Wait for last character to go.
210 while (tbdf->cbd_sc & BD_SC_READY)
213 /* Load the character into the transmit buffer.
215 *(volatile char *)tbdf->cbd_bufaddr = c;
216 tbdf->cbd_datlen = 1;
217 tbdf->cbd_sc |= BD_SC_READY;
221 serial_puts (const char *s)
231 volatile cbd_t *rbdf;
232 volatile scc_uart_t *up;
233 volatile immap_t *im;
236 im = (immap_t *)CFG_IMMR;
237 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
238 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
240 /* Wait for character to show up.
242 while (rbdf->cbd_sc & BD_SC_EMPTY)
245 /* Grab the char and clear the buffer again.
247 c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
248 rbdf->cbd_sc |= BD_SC_EMPTY;
256 volatile cbd_t *rbdf;
257 volatile scc_uart_t *up;
258 volatile immap_t *im;
260 im = (immap_t *)CFG_IMMR;
261 up = (scc_uart_t *)&im->im_dprambase[PROFF_SCC];
262 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
264 return ((rbdf->cbd_sc & BD_SC_EMPTY) == 0);
267 #endif /* CONFIG_CONS_ON_SCC */
269 #if defined(CONFIG_KGDB_ON_SCC)
271 #if defined(CONFIG_CONS_ON_SCC) && CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
272 #error Whoops! serial console and kgdb are on the same scc serial port
275 #if CONFIG_KGDB_INDEX == 1 /* KGDB Port on SCC1 */
277 #define KGDB_SCC_INDEX 0
278 #define KGDB_PROFF_SCC PROFF_SCC1
279 #define KGDB_CMXSCR_MASK (CMXSCR_GR1|CMXSCR_SC1|\
280 CMXSCR_RS1CS_MSK|CMXSCR_TS1CS_MSK)
281 #define KGDB_CMXSCR_VALUE (CMXSCR_RS1CS_BRG1|CMXSCR_TS1CS_BRG1)
282 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC1_PAGE
283 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC1_SBLOCK
285 #elif CONFIG_KGDB_INDEX == 2 /* KGDB Port on SCC2 */
287 #define KGDB_SCC_INDEX 1
288 #define KGDB_PROFF_SCC PROFF_SCC2
289 #define KGDB_CMXSCR_MASK (CMXSCR_GR2|CMXSCR_SC2|\
290 CMXSCR_RS2CS_MSK|CMXSCR_TS2CS_MSK)
291 #define KGDB_CMXSCR_VALUE (CMXSCR_RS2CS_BRG2|CMXSCR_TS2CS_BRG2)
292 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC2_PAGE
293 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC2_SBLOCK
295 #elif CONFIG_KGDB_INDEX == 3 /* KGDB Port on SCC3 */
297 #define KGDB_SCC_INDEX 2
298 #define KGDB_PROFF_SCC PROFF_SCC3
299 #define KGDB_CMXSCR_MASK (CMXSCR_GR3|CMXSCR_SC3|\
300 CMXSCR_RS3CS_MSK|CMXSCR_TS3CS_MSK)
301 #define KGDB_CMXSCR_VALUE (CMXSCR_RS3CS_BRG3|CMXSCR_TS3CS_BRG3)
302 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC3_PAGE
303 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC3_SBLOCK
305 #elif CONFIG_KGDB_INDEX == 4 /* KGDB Port on SCC4 */
307 #define KGDB_SCC_INDEX 3
308 #define KGDB_PROFF_SCC PROFF_SCC4
309 #define KGDB_CMXSCR_MASK (CMXSCR_GR4|CMXSCR_SC4|\
310 CMXSCR_RS4CS_MSK|CMXSCR_TS4CS_MSK)
311 #define KGDB_CMXSCR_VALUE (CMXSCR_RS4CS_BRG4|CMXSCR_TS4CS_BRG4)
312 #define KGDB_CPM_CR_SCC_PAGE CPM_CR_SCC4_PAGE
313 #define KGDB_CPM_CR_SCC_SBLOCK CPM_CR_SCC4_SBLOCK
317 #error "kgdb serial port not correctly defined"
322 kgdb_serial_init (void)
324 volatile immap_t *im = (immap_t *)CFG_IMMR;
326 volatile scc_uart_t *up;
327 volatile cbd_t *tbdf, *rbdf;
328 volatile cpm8260_t *cp = &(im->im_cpm);
329 uint dpaddr, speed = CONFIG_KGDB_BAUDRATE;
332 if ((s = getenv("kgdbrate")) != NULL && *s != '\0') {
333 ulong rate = simple_strtoul(s, &e, 10);
334 if (e > s && *e == '\0')
338 /* initialize pointers to SCC */
340 sp = (scc_t *) &(im->im_scc[KGDB_SCC_INDEX]);
341 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
343 /* Disable transmitter/receiver.
345 sp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
347 /* put the SCC channel into NMSI (non multiplexd serial interface)
348 * mode and wire the selected SCC Tx and Rx clocks to BRGx (15-15).
350 im->im_cpmux.cmx_scr = \
351 (im->im_cpmux.cmx_scr & ~KGDB_CMXSCR_MASK) | KGDB_CMXSCR_VALUE;
353 /* Set up the baud rate generator.
355 #if defined(CONFIG_KGDB_USE_EXTC)
356 m8260_cpm_extcbrg(KGDB_SCC_INDEX, speed,
357 CONFIG_KGDB_EXTC_RATE, CONFIG_KGDB_EXTC_PINSEL);
359 m8260_cpm_setbrg(KGDB_SCC_INDEX, speed);
362 /* Allocate space for two buffer descriptors in the DP ram.
363 * damm: allocating space after the two buffers for rx/tx data
366 dpaddr = m8260_cpm_dpalloc((2 * sizeof (cbd_t)) + 2, 16);
368 /* Set the physical address of the host memory buffers in
369 * the buffer descriptors.
371 rbdf = (cbd_t *)&im->im_dprambase[dpaddr];
372 rbdf->cbd_bufaddr = (uint) (rbdf+2);
373 rbdf->cbd_sc = BD_SC_EMPTY | BD_SC_WRAP;
375 tbdf->cbd_bufaddr = ((uint) (rbdf+2)) + 1;
376 tbdf->cbd_sc = BD_SC_WRAP;
378 /* Set up the uart parameters in the parameter ram.
380 up->scc_genscc.scc_rbase = dpaddr;
381 up->scc_genscc.scc_tbase = dpaddr+sizeof(cbd_t);
382 up->scc_genscc.scc_rfcr = CPMFCR_EB;
383 up->scc_genscc.scc_tfcr = CPMFCR_EB;
384 up->scc_genscc.scc_mrblr = 1;
394 up->scc_char1 = up->scc_char2 = up->scc_char3 = up->scc_char4 = 0x8000;
395 up->scc_char5 = up->scc_char6 = up->scc_char7 = up->scc_char8 = 0x8000;
396 up->scc_rccm = 0xc0ff;
398 /* Mask all interrupts and remove anything pending.
401 sp->scc_scce = 0xffff;
403 /* Set 8 bit FIFO, 16 bit oversampling and UART mode.
405 sp->scc_gsmrh = SCC_GSMRH_RFW; /* 8 bit FIFO */
407 SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16 | SCC_GSMRL_MODE_UART;
409 /* Set CTS flow control, 1 stop bit, 8 bit character length,
410 * normal async UART mode, no parity
412 sp->scc_psmr = SCU_PSMR_FLC | SCU_PSMR_CL;
414 /* execute the "Init Rx and Tx params" CP command.
417 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
420 cp->cp_cpcr = mk_cr_cmd(KGDB_CPM_CR_SCC_PAGE, KGDB_CPM_CR_SCC_SBLOCK,
421 0, CPM_CR_INIT_TRX) | CPM_CR_FLG;
423 while (cp->cp_cpcr & CPM_CR_FLG) /* wait if cp is busy */
426 /* Enable transmitter/receiver.
428 sp->scc_gsmrl |= SCC_GSMRL_ENR | SCC_GSMRL_ENT;
430 printf("SCC%d at %dbps ", CONFIG_KGDB_INDEX, speed);
434 putDebugChar(const char c)
436 volatile scc_uart_t *up;
437 volatile cbd_t *tbdf;
438 volatile immap_t *im;
443 im = (immap_t *)CFG_IMMR;
444 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
445 tbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_tbase];
447 /* Wait for last character to go.
449 while (tbdf->cbd_sc & BD_SC_READY)
452 /* Load the character into the transmit buffer.
454 *(volatile char *)tbdf->cbd_bufaddr = c;
455 tbdf->cbd_datlen = 1;
456 tbdf->cbd_sc |= BD_SC_READY;
460 putDebugStr (const char *s)
470 volatile cbd_t *rbdf;
471 volatile scc_uart_t *up;
472 volatile immap_t *im;
475 im = (immap_t *)CFG_IMMR;
476 up = (scc_uart_t *)&im->im_dprambase[KGDB_PROFF_SCC];
477 rbdf = (cbd_t *)&im->im_dprambase[up->scc_genscc.scc_rbase];
479 /* Wait for character to show up.
481 while (rbdf->cbd_sc & BD_SC_EMPTY)
484 /* Grab the char and clear the buffer again.
486 c = *(volatile unsigned char *)rbdf->cbd_bufaddr;
487 rbdf->cbd_sc |= BD_SC_EMPTY;
493 kgdb_interruptible(int yes)
498 #endif /* CONFIG_KGDB_ON_SCC */