blob: 83c947998ed51f81370f21558940dcc92e4a7003 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23/*------------------------------------------------------------------------------+ */
24/*
25 * This source code has been made available to you by IBM on an AS-IS
26 * basis. Anyone receiving this source is licensed under IBM
27 * copyrights to use it in any way he or she deems fit, including
28 * copying it, modifying it, compiling it, and redistributing it either
29 * with or without modifications. No license under IBM patents or
30 * patent applications is to be implied by the copyright license.
31 *
32 * Any user of this software should understand that IBM cannot provide
33 * technical support for this software and will not be responsible for
34 * any consequences resulting from the use of this software.
35 *
36 * Any person who transfers this source code or any derivative work
37 * must include the IBM copyright notice, this paragraph, and the
38 * preceding two paragraphs in the transferred software.
39 *
40 * COPYRIGHT I B M CORPORATION 1995
41 * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
42 */
43/*------------------------------------------------------------------------------- */
wdenk96c7a8c2005-01-09 22:28:56 +000044/*
45 * Travis Sawyer 15 September 2004
46 * Added CONFIG_SERIAL_MULTI support
47 */
wdenkfe8c2802002-11-03 00:38:21 +000048#include <common.h>
49#include <commproc.h>
50#include <asm/processor.h>
51#include <watchdog.h>
52#include "vecnum.h"
53
wdenk96c7a8c2005-01-09 22:28:56 +000054#ifdef CONFIG_SERIAL_MULTI
55#include <serial.h>
56#endif
57
wdenkc35ba4e2004-03-14 22:25:36 +000058#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +000059#include <malloc.h>
60#endif
61
Wolfgang Denk6405a152006-03-31 18:32:53 +020062DECLARE_GLOBAL_DATA_PTR;
63
wdenkfe8c2802002-11-03 00:38:21 +000064/*****************************************************************************/
65#ifdef CONFIG_IOP480
66
67#define SPU_BASE 0x40000000
68
69#define spu_LineStat_rc 0x00 /* Line Status Register (Read/Clear) */
70#define spu_LineStat_w 0x04 /* Line Status Register (Set) */
71#define spu_Handshk_rc 0x08 /* Handshake Status Register (Read/Clear) */
72#define spu_Handshk_w 0x0c /* Handshake Status Register (Set) */
73#define spu_BRateDivh 0x10 /* Baud rate divisor high */
74#define spu_BRateDivl 0x14 /* Baud rate divisor low */
75#define spu_CtlReg 0x18 /* Control Register */
76#define spu_RxCmd 0x1c /* Rx Command Register */
77#define spu_TxCmd 0x20 /* Tx Command Register */
78#define spu_RxBuff 0x24 /* Rx data buffer */
79#define spu_TxBuff 0x24 /* Tx data buffer */
80
81/*-----------------------------------------------------------------------------+
82 | Line Status Register.
83 +-----------------------------------------------------------------------------*/
84#define asyncLSRport1 0x40000000
85#define asyncLSRport1set 0x40000004
86#define asyncLSRDataReady 0x80
87#define asyncLSRFramingError 0x40
88#define asyncLSROverrunError 0x20
89#define asyncLSRParityError 0x10
90#define asyncLSRBreakInterrupt 0x08
91#define asyncLSRTxHoldEmpty 0x04
92#define asyncLSRTxShiftEmpty 0x02
93
94/*-----------------------------------------------------------------------------+
95 | Handshake Status Register.
96 +-----------------------------------------------------------------------------*/
97#define asyncHSRport1 0x40000008
98#define asyncHSRport1set 0x4000000c
99#define asyncHSRDsr 0x80
100#define asyncLSRCts 0x40
101
102/*-----------------------------------------------------------------------------+
103 | Control Register.
104 +-----------------------------------------------------------------------------*/
105#define asyncCRport1 0x40000018
106#define asyncCRNormal 0x00
107#define asyncCRLoopback 0x40
108#define asyncCRAutoEcho 0x80
109#define asyncCRDtr 0x20
110#define asyncCRRts 0x10
111#define asyncCRWordLength7 0x00
112#define asyncCRWordLength8 0x08
113#define asyncCRParityDisable 0x00
114#define asyncCRParityEnable 0x04
115#define asyncCREvenParity 0x00
116#define asyncCROddParity 0x02
117#define asyncCRStopBitsOne 0x00
118#define asyncCRStopBitsTwo 0x01
119#define asyncCRDisableDtrRts 0x00
120
121/*-----------------------------------------------------------------------------+
122 | Receiver Command Register.
123 +-----------------------------------------------------------------------------*/
124#define asyncRCRport1 0x4000001c
125#define asyncRCRDisable 0x00
126#define asyncRCREnable 0x80
127#define asyncRCRIntDisable 0x00
128#define asyncRCRIntEnabled 0x20
129#define asyncRCRDMACh2 0x40
130#define asyncRCRDMACh3 0x60
131#define asyncRCRErrorInt 0x10
132#define asyncRCRPauseEnable 0x08
133
134/*-----------------------------------------------------------------------------+
135 | Transmitter Command Register.
136 +-----------------------------------------------------------------------------*/
137#define asyncTCRport1 0x40000020
138#define asyncTCRDisable 0x00
139#define asyncTCREnable 0x80
140#define asyncTCRIntDisable 0x00
141#define asyncTCRIntEnabled 0x20
142#define asyncTCRDMACh2 0x40
143#define asyncTCRDMACh3 0x60
144#define asyncTCRTxEmpty 0x10
145#define asyncTCRErrorInt 0x08
146#define asyncTCRStopPause 0x04
147#define asyncTCRBreakGen 0x02
148
149/*-----------------------------------------------------------------------------+
150 | Miscellanies defines.
151 +-----------------------------------------------------------------------------*/
152#define asyncTxBufferport1 0x40000024
153#define asyncRxBufferport1 0x40000024
154#define asyncDLABLsbport1 0x40000014
155#define asyncDLABMsbport1 0x40000010
156#define asyncXOFFchar 0x13
157#define asyncXONchar 0x11
158
wdenkfe8c2802002-11-03 00:38:21 +0000159/*
160 * Minimal serial functions needed to use one of the SMC ports
161 * as serial console interface.
162 */
163
164int serial_init (void)
165{
wdenkfe8c2802002-11-03 00:38:21 +0000166 volatile char val;
167 unsigned short br_reg;
168
169 br_reg = ((((CONFIG_CPUCLOCK * 1000000) / 16) / gd->baudrate) - 1);
170
171 /*
172 * Init onboard UART
173 */
174 out8 (SPU_BASE + spu_LineStat_rc, 0x78); /* Clear all bits in Line Status Reg */
175 out8 (SPU_BASE + spu_BRateDivl, (br_reg & 0x00ff)); /* Set baud rate divisor... */
176 out8 (SPU_BASE + spu_BRateDivh, ((br_reg & 0xff00) >> 8)); /* ... */
177 out8 (SPU_BASE + spu_CtlReg, 0x08); /* Set 8 bits, no parity and 1 stop bit */
178 out8 (SPU_BASE + spu_RxCmd, 0xb0); /* Enable Rx */
179 out8 (SPU_BASE + spu_TxCmd, 0x9c); /* Enable Tx */
180 out8 (SPU_BASE + spu_Handshk_rc, 0xff); /* Clear Handshake */
181 val = in8 (SPU_BASE + spu_RxBuff); /* Dummy read, to clear receiver */
182
183 return (0);
184}
185
wdenkfe8c2802002-11-03 00:38:21 +0000186void serial_setbrg (void)
187{
wdenkfe8c2802002-11-03 00:38:21 +0000188 unsigned short br_reg;
189
190 br_reg = ((((CONFIG_CPUCLOCK * 1000000) / 16) / gd->baudrate) - 1);
191
192 out8 (SPU_BASE + spu_BRateDivl, (br_reg & 0x00ff)); /* Set baud rate divisor... */
193 out8 (SPU_BASE + spu_BRateDivh, ((br_reg & 0xff00) >> 8)); /* ... */
194}
195
wdenkfe8c2802002-11-03 00:38:21 +0000196void serial_putc (const char c)
197{
198 if (c == '\n')
199 serial_putc ('\r');
200
201 /* load status from handshake register */
202 if (in8 (SPU_BASE + spu_Handshk_rc) != 00)
203 out8 (SPU_BASE + spu_Handshk_rc, 0xff); /* Clear Handshake */
204
205 out8 (SPU_BASE + spu_TxBuff, c); /* Put char */
206
207 while ((in8 (SPU_BASE + spu_LineStat_rc) & 04) != 04) {
208 if (in8 (SPU_BASE + spu_Handshk_rc) != 00)
209 out8 (SPU_BASE + spu_Handshk_rc, 0xff); /* Clear Handshake */
210 }
211}
212
wdenkfe8c2802002-11-03 00:38:21 +0000213void serial_puts (const char *s)
214{
215 while (*s) {
216 serial_putc (*s++);
217 }
218}
219
wdenkfe8c2802002-11-03 00:38:21 +0000220int serial_getc ()
221{
222 unsigned char status = 0;
223
224 while (1) {
225 status = in8 (asyncLSRport1);
226 if ((status & asyncLSRDataReady) != 0x0) {
227 break;
228 }
229 if ((status & ( asyncLSRFramingError |
230 asyncLSROverrunError |
231 asyncLSRParityError |
232 asyncLSRBreakInterrupt )) != 0) {
233 (void) out8 (asyncLSRport1,
234 asyncLSRFramingError |
235 asyncLSROverrunError |
236 asyncLSRParityError |
237 asyncLSRBreakInterrupt );
238 }
239 }
240 return (0x000000ff & (int) in8 (asyncRxBufferport1));
241}
242
wdenkfe8c2802002-11-03 00:38:21 +0000243int serial_tstc ()
244{
245 unsigned char status;
246
247 status = in8 (asyncLSRport1);
248 if ((status & asyncLSRDataReady) != 0x0) {
249 return (1);
250 }
251 if ((status & ( asyncLSRFramingError |
252 asyncLSROverrunError |
253 asyncLSRParityError |
254 asyncLSRBreakInterrupt )) != 0) {
255 (void) out8 (asyncLSRport1,
256 asyncLSRFramingError |
257 asyncLSROverrunError |
258 asyncLSRParityError |
259 asyncLSRBreakInterrupt);
260 }
261 return 0;
262}
263
264#endif /* CONFIG_IOP480 */
265
wdenkfe8c2802002-11-03 00:38:21 +0000266/*****************************************************************************/
stroese937d6672003-05-23 11:25:57 +0000267#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_440) || defined(CONFIG_405EP)
wdenkfe8c2802002-11-03 00:38:21 +0000268
269#if defined(CONFIG_440)
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200270#if defined(CONFIG_440EP) || defined(CONFIG_440GR)
Stefan Roese326c9712005-08-01 16:41:48 +0200271#define UART0_BASE CFG_PERIPHERAL_BASE + 0x00000300
272#define UART1_BASE CFG_PERIPHERAL_BASE + 0x00000400
273#else
wdenkfe8c2802002-11-03 00:38:21 +0000274#define UART0_BASE CFG_PERIPHERAL_BASE + 0x00000200
275#define UART1_BASE CFG_PERIPHERAL_BASE + 0x00000300
Stefan Roese326c9712005-08-01 16:41:48 +0200276#endif
Stefan Roese99644742005-11-29 18:18:21 +0100277
278#if defined(CONFIG_440SP)
279#define UART2_BASE CFG_PERIPHERAL_BASE + 0x00000600
280#endif
281
282#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000283#define CR0_MASK 0xdfffffff
284#define CR0_EXTCLK_ENA 0x00800000
285#define CR0_UDIV_POS 0
286#else
wdenkfe8c2802002-11-03 00:38:21 +0000287#define CR0_MASK 0x3fff0000
288#define CR0_EXTCLK_ENA 0x00600000
289#define CR0_UDIV_POS 16
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200290#endif /* CONFIG_440GX */
stroese937d6672003-05-23 11:25:57 +0000291#elif defined(CONFIG_405EP)
292#define UART0_BASE 0xef600300
293#define UART1_BASE 0xef600400
294#define UCR0_MASK 0x0000007f
295#define UCR1_MASK 0x00007f00
296#define UCR0_UDIV_POS 0
297#define UCR1_UDIV_POS 8
298#define UDIV_MAX 127
299#else /* CONFIG_405GP || CONFIG_405CR */
wdenkfe8c2802002-11-03 00:38:21 +0000300#define UART0_BASE 0xef600300
301#define UART1_BASE 0xef600400
302#define CR0_MASK 0x00001fff
stroese85d0fec2003-02-17 16:06:06 +0000303#define CR0_EXTCLK_ENA 0x000000c0
wdenkfe8c2802002-11-03 00:38:21 +0000304#define CR0_UDIV_POS 1
stroese937d6672003-05-23 11:25:57 +0000305#define UDIV_MAX 32
306#endif
307
308/* using serial port 0 or 1 as U-Boot console ? */
309#if defined(CONFIG_UART1_CONSOLE)
310#define ACTING_UART0_BASE UART1_BASE
311#define ACTING_UART1_BASE UART0_BASE
Stefan Roese99644742005-11-29 18:18:21 +0100312#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000313#define UART0_SDR sdr_uart1
314#define UART1_SDR sdr_uart0
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200315#endif /* CONFIG_440GX */
stroese937d6672003-05-23 11:25:57 +0000316#else
317#define ACTING_UART0_BASE UART0_BASE
318#define ACTING_UART1_BASE UART1_BASE
Stefan Roese99644742005-11-29 18:18:21 +0100319#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000320#define UART0_SDR sdr_uart0
321#define UART1_SDR sdr_uart1
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200322#endif /* CONFIG_440GX */
stroese937d6672003-05-23 11:25:57 +0000323#endif
324
325#if defined(CONFIG_405EP) && defined(CFG_EXT_SERIAL_CLOCK)
Wolfgang Denk0ee70772005-09-23 11:05:55 +0200326#error "External serial clock not supported on AMCC PPC405EP!"
wdenkfe8c2802002-11-03 00:38:21 +0000327#endif
328
329#define UART_RBR 0x00
330#define UART_THR 0x00
331#define UART_IER 0x01
332#define UART_IIR 0x02
333#define UART_FCR 0x02
334#define UART_LCR 0x03
335#define UART_MCR 0x04
336#define UART_LSR 0x05
337#define UART_MSR 0x06
338#define UART_SCR 0x07
339#define UART_DLL 0x00
340#define UART_DLM 0x01
341
342/*-----------------------------------------------------------------------------+
343 | Line Status Register.
344 +-----------------------------------------------------------------------------*/
stroese937d6672003-05-23 11:25:57 +0000345/*#define asyncLSRport1 ACTING_UART0_BASE+0x05 */
wdenkfe8c2802002-11-03 00:38:21 +0000346#define asyncLSRDataReady1 0x01
347#define asyncLSROverrunError1 0x02
348#define asyncLSRParityError1 0x04
349#define asyncLSRFramingError1 0x08
350#define asyncLSRBreakInterrupt1 0x10
351#define asyncLSRTxHoldEmpty1 0x20
352#define asyncLSRTxShiftEmpty1 0x40
353#define asyncLSRRxFifoError1 0x80
354
355/*-----------------------------------------------------------------------------+
356 | Miscellanies defines.
357 +-----------------------------------------------------------------------------*/
stroese937d6672003-05-23 11:25:57 +0000358/*#define asyncTxBufferport1 ACTING_UART0_BASE+0x00 */
359/*#define asyncRxBufferport1 ACTING_UART0_BASE+0x00 */
wdenkfe8c2802002-11-03 00:38:21 +0000360
wdenkc35ba4e2004-03-14 22:25:36 +0000361#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000362/*-----------------------------------------------------------------------------+
363 | Fifo
364 +-----------------------------------------------------------------------------*/
365typedef struct {
366 char *rx_buffer;
367 ulong rx_put;
368 ulong rx_get;
369} serial_buffer_t;
370
371volatile static serial_buffer_t buf_info;
372#endif
373
wdenkfe8c2802002-11-03 00:38:21 +0000374#if defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLOCK)
375static void serial_divs (int baudrate, unsigned long *pudiv,
376 unsigned short *pbdiv )
377{
378 sys_info_t sysinfo;
379 unsigned long div; /* total divisor udiv * bdiv */
380 unsigned long umin; /* minimum udiv */
381 unsigned short diff; /* smallest diff */
382 unsigned long udiv; /* best udiv */
383
384 unsigned short idiff; /* current diff */
385 unsigned short ibdiv; /* current bdiv */
386 unsigned long i;
387 unsigned long est; /* current estimate */
388
389 get_sys_info( &sysinfo );
390
391 udiv = 32; /* Assume lowest possible serial clk */
392 div = sysinfo.freqPLB/(16*baudrate); /* total divisor */
393 umin = sysinfo.pllOpbDiv<<1; /* 2 x OPB divisor */
394 diff = 32; /* highest possible */
395
396 /* i is the test udiv value -- start with the largest
397 * possible (32) to minimize serial clock and constrain
398 * search to umin.
399 */
400 for( i = 32; i > umin; i-- ){
401 ibdiv = div/i;
402 est = i * ibdiv;
403 idiff = (est > div) ? (est-div) : (div-est);
404 if( idiff == 0 ){
405 udiv = i;
406 break; /* can't do better */
407 }
408 else if( idiff < diff ){
409 udiv = i; /* best so far */
410 diff = idiff; /* update lowest diff*/
411 }
412 }
413
414 *pudiv = udiv;
415 *pbdiv = div/udiv;
416
417}
418#endif /* defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLK */
419
wdenkfe8c2802002-11-03 00:38:21 +0000420/*
421 * Minimal serial functions needed to use one of the SMC ports
422 * as serial console interface.
423 */
424
425#if defined(CONFIG_440)
wdenk96c7a8c2005-01-09 22:28:56 +0000426#if defined(CONFIG_SERIAL_MULTI)
427int serial_init_dev (unsigned long dev_base)
428#else
429int serial_init(void)
430#endif
wdenkfe8c2802002-11-03 00:38:21 +0000431{
wdenkfe8c2802002-11-03 00:38:21 +0000432 unsigned long reg;
433 unsigned long udiv;
434 unsigned short bdiv;
435 volatile char val;
436#ifdef CFG_EXT_SERIAL_CLOCK
437 unsigned long tmp;
438#endif
439
Stefan Roese99644742005-11-29 18:18:21 +0100440#if defined(CONFIG_440GX) || defined(CONFIG_440SP)
wdenk96c7a8c2005-01-09 22:28:56 +0000441#if defined(CONFIG_SERIAL_MULTI)
442 if (UART0_BASE == dev_base) {
443 mfsdr(UART0_SDR,reg);
444 reg &= ~CR0_MASK;
445 } else {
446 mfsdr(UART1_SDR,reg);
447 reg &= ~CR0_MASK;
448 }
449#else
wdenk544e9732004-02-06 23:19:44 +0000450 mfsdr(UART0_SDR,reg);
451 reg &= ~CR0_MASK;
wdenk96c7a8c2005-01-09 22:28:56 +0000452#endif
wdenk544e9732004-02-06 23:19:44 +0000453#else
wdenkfe8c2802002-11-03 00:38:21 +0000454 reg = mfdcr(cntrl0) & ~CR0_MASK;
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200455#endif /* CONFIG_440GX */
wdenkfe8c2802002-11-03 00:38:21 +0000456#ifdef CFG_EXT_SERIAL_CLOCK
457 reg |= CR0_EXTCLK_ENA;
458 udiv = 1;
459 tmp = gd->baudrate * 16;
460 bdiv = (CFG_EXT_SERIAL_CLOCK + tmp / 2) / tmp;
461#else
462 /* For 440, the cpu clock is on divider chain A, UART on divider
463 * chain B ... so cpu clock is irrelevant. Get the "optimized"
464 * values that are subject to the 1/2 opb clock constraint
465 */
466 serial_divs (gd->baudrate, &udiv, &bdiv);
467#endif
468
Stefan Roese99644742005-11-29 18:18:21 +0100469#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP)
wdenk544e9732004-02-06 23:19:44 +0000470 reg |= udiv << CR0_UDIV_POS; /* set the UART divisor */
wdenk96c7a8c2005-01-09 22:28:56 +0000471#if defined(CONFIG_SERIAL_MULTI)
472 if (UART0_BASE == dev_base) {
473 mtsdr (UART0_SDR,reg);
474 } else {
475 mtsdr (UART1_SDR,reg);
476 }
477#else
wdenk544e9732004-02-06 23:19:44 +0000478 mtsdr (UART0_SDR,reg);
wdenk96c7a8c2005-01-09 22:28:56 +0000479#endif
wdenk544e9732004-02-06 23:19:44 +0000480#else
wdenkfe8c2802002-11-03 00:38:21 +0000481 reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */
482 mtdcr (cntrl0, reg);
wdenk544e9732004-02-06 23:19:44 +0000483#endif
wdenk96c7a8c2005-01-09 22:28:56 +0000484
485#if defined(CONFIG_SERIAL_MULTI)
486 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
487 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
488 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
489 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
490 out8 (dev_base + UART_FCR, 0x00); /* disable FIFO */
491 out8 (dev_base + UART_MCR, 0x00); /* no modem control DTR RTS */
492 val = in8 (dev_base + UART_LSR); /* clear line status */
493 val = in8 (dev_base + UART_RBR); /* read receive buffer */
494 out8 (dev_base + UART_SCR, 0x00); /* set scratchpad */
495 out8 (dev_base + UART_IER, 0x00); /* set interrupt enable reg */
496#else
stroese937d6672003-05-23 11:25:57 +0000497 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
498 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
499 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
500 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
501 out8 (ACTING_UART0_BASE + UART_FCR, 0x00); /* disable FIFO */
502 out8 (ACTING_UART0_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
503 val = in8 (ACTING_UART0_BASE + UART_LSR); /* clear line status */
504 val = in8 (ACTING_UART0_BASE + UART_RBR); /* read receive buffer */
505 out8 (ACTING_UART0_BASE + UART_SCR, 0x00); /* set scratchpad */
506 out8 (ACTING_UART0_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenk96c7a8c2005-01-09 22:28:56 +0000507#endif
wdenkfe8c2802002-11-03 00:38:21 +0000508 return (0);
509}
510
511#else /* !defined(CONFIG_440) */
512
wdenk96c7a8c2005-01-09 22:28:56 +0000513#if defined(CONFIG_SERIAL_MULTI)
514int serial_init_dev (unsigned long dev_base)
515#else
wdenkfe8c2802002-11-03 00:38:21 +0000516int serial_init (void)
wdenk96c7a8c2005-01-09 22:28:56 +0000517#endif
wdenkfe8c2802002-11-03 00:38:21 +0000518{
wdenkfe8c2802002-11-03 00:38:21 +0000519 unsigned long reg;
520 unsigned long tmp;
521 unsigned long clk;
522 unsigned long udiv;
523 unsigned short bdiv;
524 volatile char val;
525
stroese937d6672003-05-23 11:25:57 +0000526#ifdef CONFIG_405EP
527 reg = mfdcr(cpc0_ucr) & ~(UCR0_MASK | UCR1_MASK);
528 clk = gd->cpu_clk;
529 tmp = CFG_BASE_BAUD * 16;
530 udiv = (clk + tmp / 2) / tmp;
531 if (udiv > UDIV_MAX) /* max. n bits for udiv */
532 udiv = UDIV_MAX;
533 reg |= (udiv) << UCR0_UDIV_POS; /* set the UART divisor */
534 reg |= (udiv) << UCR1_UDIV_POS; /* set the UART divisor */
535 mtdcr (cpc0_ucr, reg);
536#else /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000537 reg = mfdcr(cntrl0) & ~CR0_MASK;
538#ifdef CFG_EXT_SERIAL_CLOCK
539 clk = CFG_EXT_SERIAL_CLOCK;
540 udiv = 1;
541 reg |= CR0_EXTCLK_ENA;
542#else
543 clk = gd->cpu_clk;
544#ifdef CFG_405_UART_ERRATA_59
545 udiv = 31; /* Errata 59: stuck at 31 */
546#else
547 tmp = CFG_BASE_BAUD * 16;
548 udiv = (clk + tmp / 2) / tmp;
stroese937d6672003-05-23 11:25:57 +0000549 if (udiv > UDIV_MAX) /* max. n bits for udiv */
550 udiv = UDIV_MAX;
wdenkfe8c2802002-11-03 00:38:21 +0000551#endif
552#endif
wdenkfe8c2802002-11-03 00:38:21 +0000553 reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */
554 mtdcr (cntrl0, reg);
stroese937d6672003-05-23 11:25:57 +0000555#endif /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000556
557 tmp = gd->baudrate * udiv * 16;
558 bdiv = (clk + tmp / 2) / tmp;
559
wdenk96c7a8c2005-01-09 22:28:56 +0000560#if defined(CONFIG_SERIAL_MULTI)
561 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
562 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
563 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
564 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
565 out8 (dev_base + UART_FCR, 0x00); /* disable FIFO */
566 out8 (dev_base + UART_MCR, 0x00); /* no modem control DTR RTS */
567 val = in8 (dev_base + UART_LSR); /* clear line status */
568 val = in8 (dev_base + UART_RBR); /* read receive buffer */
569 out8 (dev_base + UART_SCR, 0x00); /* set scratchpad */
570 out8 (dev_base + UART_IER, 0x00); /* set interrupt enable reg */
571#else
stroese937d6672003-05-23 11:25:57 +0000572 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
573 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
574 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
575 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
576 out8 (ACTING_UART0_BASE + UART_FCR, 0x00); /* disable FIFO */
577 out8 (ACTING_UART0_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
578 val = in8 (ACTING_UART0_BASE + UART_LSR); /* clear line status */
579 val = in8 (ACTING_UART0_BASE + UART_RBR); /* read receive buffer */
580 out8 (ACTING_UART0_BASE + UART_SCR, 0x00); /* set scratchpad */
581 out8 (ACTING_UART0_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenk96c7a8c2005-01-09 22:28:56 +0000582#endif
wdenkfe8c2802002-11-03 00:38:21 +0000583 return (0);
584}
585
586#endif /* if defined(CONFIG_440) */
587
wdenk96c7a8c2005-01-09 22:28:56 +0000588#if defined(CONFIG_SERIAL_MULTI)
589void serial_setbrg_dev (unsigned long dev_base)
590#else
wdenkfe8c2802002-11-03 00:38:21 +0000591void serial_setbrg (void)
wdenk96c7a8c2005-01-09 22:28:56 +0000592#endif
wdenkfe8c2802002-11-03 00:38:21 +0000593{
wdenkfe8c2802002-11-03 00:38:21 +0000594 unsigned long tmp;
595 unsigned long clk;
596 unsigned long udiv;
597 unsigned short bdiv;
598
599#ifdef CFG_EXT_SERIAL_CLOCK
600 clk = CFG_EXT_SERIAL_CLOCK;
601#else
602 clk = gd->cpu_clk;
603#endif
stroese937d6672003-05-23 11:25:57 +0000604
605#ifdef CONFIG_405EP
606 udiv = ((mfdcr (cpc0_ucr) & UCR0_MASK) >> UCR0_UDIV_POS);
607#else
wdenkfe8c2802002-11-03 00:38:21 +0000608 udiv = ((mfdcr (cntrl0) & 0x3e) >> 1) + 1;
stroese937d6672003-05-23 11:25:57 +0000609#endif /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000610 tmp = gd->baudrate * udiv * 16;
611 bdiv = (clk + tmp / 2) / tmp;
612
wdenk96c7a8c2005-01-09 22:28:56 +0000613#if defined(CONFIG_SERIAL_MULTI)
614 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
615 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
616 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
617 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
618#else
stroese937d6672003-05-23 11:25:57 +0000619 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
620 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
621 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
622 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
wdenk96c7a8c2005-01-09 22:28:56 +0000623#endif
wdenkfe8c2802002-11-03 00:38:21 +0000624}
625
wdenk96c7a8c2005-01-09 22:28:56 +0000626#if defined(CONFIG_SERIAL_MULTI)
627void serial_putc_dev (unsigned long dev_base, const char c)
628#else
wdenkfe8c2802002-11-03 00:38:21 +0000629void serial_putc (const char c)
wdenk96c7a8c2005-01-09 22:28:56 +0000630#endif
wdenkfe8c2802002-11-03 00:38:21 +0000631{
632 int i;
633
634 if (c == '\n')
wdenk96c7a8c2005-01-09 22:28:56 +0000635#if defined(CONFIG_SERIAL_MULTI)
636 serial_putc_dev (dev_base, '\r');
637#else
wdenkfe8c2802002-11-03 00:38:21 +0000638 serial_putc ('\r');
wdenk96c7a8c2005-01-09 22:28:56 +0000639#endif
wdenkfe8c2802002-11-03 00:38:21 +0000640
641 /* check THRE bit, wait for transmiter available */
642 for (i = 1; i < 3500; i++) {
wdenk96c7a8c2005-01-09 22:28:56 +0000643#if defined(CONFIG_SERIAL_MULTI)
644 if ((in8 (dev_base + UART_LSR) & 0x20) == 0x20)
645#else
stroese937d6672003-05-23 11:25:57 +0000646 if ((in8 (ACTING_UART0_BASE + UART_LSR) & 0x20) == 0x20)
wdenk96c7a8c2005-01-09 22:28:56 +0000647#endif
wdenkfe8c2802002-11-03 00:38:21 +0000648 break;
649 udelay (100);
650 }
wdenk96c7a8c2005-01-09 22:28:56 +0000651#if defined(CONFIG_SERIAL_MULTI)
652 out8 (dev_base + UART_THR, c); /* put character out */
653#else
stroese937d6672003-05-23 11:25:57 +0000654 out8 (ACTING_UART0_BASE + UART_THR, c); /* put character out */
wdenk96c7a8c2005-01-09 22:28:56 +0000655#endif
wdenkfe8c2802002-11-03 00:38:21 +0000656}
657
wdenk96c7a8c2005-01-09 22:28:56 +0000658#if defined(CONFIG_SERIAL_MULTI)
659void serial_puts_dev (unsigned long dev_base, const char *s)
660#else
wdenkfe8c2802002-11-03 00:38:21 +0000661void serial_puts (const char *s)
wdenk96c7a8c2005-01-09 22:28:56 +0000662#endif
wdenkfe8c2802002-11-03 00:38:21 +0000663{
664 while (*s) {
wdenk96c7a8c2005-01-09 22:28:56 +0000665#if defined(CONFIG_SERIAL_MULTI)
666 serial_putc_dev (dev_base, *s++);
667#else
wdenkfe8c2802002-11-03 00:38:21 +0000668 serial_putc (*s++);
wdenk96c7a8c2005-01-09 22:28:56 +0000669#endif
wdenkfe8c2802002-11-03 00:38:21 +0000670 }
671}
672
wdenk96c7a8c2005-01-09 22:28:56 +0000673#if defined(CONFIG_SERIAL_MULTI)
674int serial_getc_dev (unsigned long dev_base)
675#else
676int serial_getc (void)
677#endif
wdenkfe8c2802002-11-03 00:38:21 +0000678{
679 unsigned char status = 0;
680
681 while (1) {
682#if defined(CONFIG_HW_WATCHDOG)
683 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
684#endif /* CONFIG_HW_WATCHDOG */
wdenk96c7a8c2005-01-09 22:28:56 +0000685#if defined(CONFIG_SERIAL_MULTI)
686 status = in8 (dev_base + UART_LSR);
687#else
stroese937d6672003-05-23 11:25:57 +0000688 status = in8 (ACTING_UART0_BASE + UART_LSR);
wdenk96c7a8c2005-01-09 22:28:56 +0000689#endif
wdenkfe8c2802002-11-03 00:38:21 +0000690 if ((status & asyncLSRDataReady1) != 0x0) {
691 break;
692 }
693 if ((status & ( asyncLSRFramingError1 |
694 asyncLSROverrunError1 |
695 asyncLSRParityError1 |
696 asyncLSRBreakInterrupt1 )) != 0) {
wdenk96c7a8c2005-01-09 22:28:56 +0000697#if defined(CONFIG_SERIAL_MULTI)
698 out8 (dev_base + UART_LSR,
699#else
stroese937d6672003-05-23 11:25:57 +0000700 out8 (ACTING_UART0_BASE + UART_LSR,
wdenk96c7a8c2005-01-09 22:28:56 +0000701#endif
wdenkfe8c2802002-11-03 00:38:21 +0000702 asyncLSRFramingError1 |
703 asyncLSROverrunError1 |
704 asyncLSRParityError1 |
705 asyncLSRBreakInterrupt1);
706 }
707 }
wdenk96c7a8c2005-01-09 22:28:56 +0000708#if defined(CONFIG_SERIAL_MULTI)
709 return (0x000000ff & (int) in8 (dev_base));
710#else
stroese937d6672003-05-23 11:25:57 +0000711 return (0x000000ff & (int) in8 (ACTING_UART0_BASE));
wdenk96c7a8c2005-01-09 22:28:56 +0000712#endif
wdenkfe8c2802002-11-03 00:38:21 +0000713}
714
wdenk96c7a8c2005-01-09 22:28:56 +0000715#if defined(CONFIG_SERIAL_MULTI)
716int serial_tstc_dev (unsigned long dev_base)
717#else
718int serial_tstc (void)
719#endif
wdenkfe8c2802002-11-03 00:38:21 +0000720{
721 unsigned char status;
722
wdenk96c7a8c2005-01-09 22:28:56 +0000723#if defined(CONFIG_SERIAL_MULTI)
724 status = in8 (dev_base + UART_LSR);
725#else
stroese937d6672003-05-23 11:25:57 +0000726 status = in8 (ACTING_UART0_BASE + UART_LSR);
wdenk96c7a8c2005-01-09 22:28:56 +0000727#endif
wdenkfe8c2802002-11-03 00:38:21 +0000728 if ((status & asyncLSRDataReady1) != 0x0) {
729 return (1);
730 }
731 if ((status & ( asyncLSRFramingError1 |
732 asyncLSROverrunError1 |
733 asyncLSRParityError1 |
734 asyncLSRBreakInterrupt1 )) != 0) {
wdenk96c7a8c2005-01-09 22:28:56 +0000735#if defined(CONFIG_SERIAL_MULTI)
736 out8 (dev_base + UART_LSR,
737#else
stroese937d6672003-05-23 11:25:57 +0000738 out8 (ACTING_UART0_BASE + UART_LSR,
wdenk96c7a8c2005-01-09 22:28:56 +0000739#endif
wdenkfe8c2802002-11-03 00:38:21 +0000740 asyncLSRFramingError1 |
741 asyncLSROverrunError1 |
742 asyncLSRParityError1 |
743 asyncLSRBreakInterrupt1);
744 }
745 return 0;
746}
747
wdenkc35ba4e2004-03-14 22:25:36 +0000748#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000749
750void serial_isr (void *arg)
751{
752 int space;
753 int c;
754 const int rx_get = buf_info.rx_get;
755 int rx_put = buf_info.rx_put;
756
757 if (rx_get <= rx_put) {
758 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
759 } else {
760 space = rx_get - rx_put;
761 }
wdenk96c7a8c2005-01-09 22:28:56 +0000762 while (serial_tstc_dev (ACTING_UART0_BASE)) {
763 c = serial_getc_dev (ACTING_UART0_BASE);
wdenkfe8c2802002-11-03 00:38:21 +0000764 if (space) {
765 buf_info.rx_buffer[rx_put++] = c;
766 space--;
767 }
768 if (rx_put == CONFIG_SERIAL_SOFTWARE_FIFO)
769 rx_put = 0;
770 if (space < CONFIG_SERIAL_SOFTWARE_FIFO / 4) {
771 /* Stop flow by setting RTS inactive */
stroese937d6672003-05-23 11:25:57 +0000772 out8 (ACTING_UART0_BASE + UART_MCR,
773 in8 (ACTING_UART0_BASE + UART_MCR) & (0xFF ^ 0x02));
wdenkfe8c2802002-11-03 00:38:21 +0000774 }
775 }
776 buf_info.rx_put = rx_put;
777}
778
779void serial_buffered_init (void)
780{
781 serial_puts ("Switching to interrupt driven serial input mode.\n");
782 buf_info.rx_buffer = malloc (CONFIG_SERIAL_SOFTWARE_FIFO);
783 buf_info.rx_put = 0;
784 buf_info.rx_get = 0;
785
stroese937d6672003-05-23 11:25:57 +0000786 if (in8 (ACTING_UART0_BASE + UART_MSR) & 0x10) {
wdenkfe8c2802002-11-03 00:38:21 +0000787 serial_puts ("Check CTS signal present on serial port: OK.\n");
788 } else {
789 serial_puts ("WARNING: CTS signal not present on serial port.\n");
790 }
791
792 irq_install_handler ( VECNUM_U0 /*UART0 */ /*int vec */ ,
793 serial_isr /*interrupt_handler_t *handler */ ,
794 (void *) &buf_info /*void *arg */ );
795
796 /* Enable "RX Data Available" Interrupt on UART */
stroese937d6672003-05-23 11:25:57 +0000797 /* out8(ACTING_UART0_BASE + UART_IER, in8(ACTING_UART0_BASE + UART_IER) |0x01); */
798 out8 (ACTING_UART0_BASE + UART_IER, 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000799 /* Set DTR active */
stroese937d6672003-05-23 11:25:57 +0000800 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000801 /* Start flow by setting RTS active */
stroese937d6672003-05-23 11:25:57 +0000802 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000803 /* Setup UART FIFO: RX trigger level: 4 byte, Enable FIFO */
stroese937d6672003-05-23 11:25:57 +0000804 out8 (ACTING_UART0_BASE + UART_FCR, (1 << 6) | 1);
wdenkfe8c2802002-11-03 00:38:21 +0000805}
806
807void serial_buffered_putc (const char c)
808{
809 /* Wait for CTS */
810#if defined(CONFIG_HW_WATCHDOG)
stroese937d6672003-05-23 11:25:57 +0000811 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10))
wdenkfe8c2802002-11-03 00:38:21 +0000812 WATCHDOG_RESET ();
813#else
stroese937d6672003-05-23 11:25:57 +0000814 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10));
wdenkfe8c2802002-11-03 00:38:21 +0000815#endif
816 serial_putc (c);
817}
818
819void serial_buffered_puts (const char *s)
820{
821 serial_puts (s);
822}
823
824int serial_buffered_getc (void)
825{
826 int space;
827 int c;
828 int rx_get = buf_info.rx_get;
829 int rx_put;
830
831#if defined(CONFIG_HW_WATCHDOG)
832 while (rx_get == buf_info.rx_put)
833 WATCHDOG_RESET ();
834#else
835 while (rx_get == buf_info.rx_put);
836#endif
837 c = buf_info.rx_buffer[rx_get++];
838 if (rx_get == CONFIG_SERIAL_SOFTWARE_FIFO)
839 rx_get = 0;
840 buf_info.rx_get = rx_get;
841
842 rx_put = buf_info.rx_put;
843 if (rx_get <= rx_put) {
844 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
845 } else {
846 space = rx_get - rx_put;
847 }
848 if (space > CONFIG_SERIAL_SOFTWARE_FIFO / 2) {
849 /* Start flow by setting RTS active */
stroese937d6672003-05-23 11:25:57 +0000850 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000851 }
852
853 return c;
854}
855
856int serial_buffered_tstc (void)
857{
858 return (buf_info.rx_get != buf_info.rx_put) ? 1 : 0;
859}
860
861#endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
862
wdenkfe8c2802002-11-03 00:38:21 +0000863#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
864/*
865 AS HARNOIS : according to CONFIG_KGDB_SER_INDEX kgdb uses serial port
866 number 0 or number 1
867 - if CONFIG_KGDB_SER_INDEX = 1 => serial port number 0 :
868 configuration has been already done
869 - if CONFIG_KGDB_SER_INDEX = 2 => serial port number 1 :
870 configure port 1 for serial I/O with rate = CONFIG_KGDB_BAUDRATE
871*/
872#if (CONFIG_KGDB_SER_INDEX & 2)
873void kgdb_serial_init (void)
874{
wdenkfe8c2802002-11-03 00:38:21 +0000875 volatile char val;
876 unsigned short br_reg;
877
878 get_clocks ();
879 br_reg = (((((gd->cpu_clk / 16) / 18) * 10) / CONFIG_KGDB_BAUDRATE) +
880 5) / 10;
881 /*
882 * Init onboard 16550 UART
883 */
stroese937d6672003-05-23 11:25:57 +0000884 out8 (ACTING_UART1_BASE + UART_LCR, 0x80); /* set DLAB bit */
885 out8 (ACTING_UART1_BASE + UART_DLL, (br_reg & 0x00ff)); /* set divisor for 9600 baud */
886 out8 (ACTING_UART1_BASE + UART_DLM, ((br_reg & 0xff00) >> 8)); /* set divisor for 9600 baud */
887 out8 (ACTING_UART1_BASE + UART_LCR, 0x03); /* line control 8 bits no parity */
888 out8 (ACTING_UART1_BASE + UART_FCR, 0x00); /* disable FIFO */
889 out8 (ACTING_UART1_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
890 val = in8 (ACTING_UART1_BASE + UART_LSR); /* clear line status */
891 val = in8 (ACTING_UART1_BASE + UART_RBR); /* read receive buffer */
892 out8 (ACTING_UART1_BASE + UART_SCR, 0x00); /* set scratchpad */
893 out8 (ACTING_UART1_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenkfe8c2802002-11-03 00:38:21 +0000894}
895
wdenkfe8c2802002-11-03 00:38:21 +0000896void putDebugChar (const char c)
897{
898 if (c == '\n')
899 serial_putc ('\r');
900
stroese937d6672003-05-23 11:25:57 +0000901 out8 (ACTING_UART1_BASE + UART_THR, c); /* put character out */
wdenkfe8c2802002-11-03 00:38:21 +0000902
903 /* check THRE bit, wait for transfer done */
stroese937d6672003-05-23 11:25:57 +0000904 while ((in8 (ACTING_UART1_BASE + UART_LSR) & 0x20) != 0x20);
wdenkfe8c2802002-11-03 00:38:21 +0000905}
906
wdenkfe8c2802002-11-03 00:38:21 +0000907void putDebugStr (const char *s)
908{
909 while (*s) {
910 serial_putc (*s++);
911 }
912}
913
wdenkfe8c2802002-11-03 00:38:21 +0000914int getDebugChar (void)
915{
916 unsigned char status = 0;
917
918 while (1) {
stroese937d6672003-05-23 11:25:57 +0000919 status = in8 (ACTING_UART1_BASE + UART_LSR);
wdenkfe8c2802002-11-03 00:38:21 +0000920 if ((status & asyncLSRDataReady1) != 0x0) {
921 break;
922 }
923 if ((status & ( asyncLSRFramingError1 |
924 asyncLSROverrunError1 |
925 asyncLSRParityError1 |
926 asyncLSRBreakInterrupt1 )) != 0) {
stroese937d6672003-05-23 11:25:57 +0000927 out8 (ACTING_UART1_BASE + UART_LSR,
wdenkfe8c2802002-11-03 00:38:21 +0000928 asyncLSRFramingError1 |
929 asyncLSROverrunError1 |
930 asyncLSRParityError1 |
931 asyncLSRBreakInterrupt1);
932 }
933 }
stroese937d6672003-05-23 11:25:57 +0000934 return (0x000000ff & (int) in8 (ACTING_UART1_BASE));
wdenkfe8c2802002-11-03 00:38:21 +0000935}
936
wdenkfe8c2802002-11-03 00:38:21 +0000937void kgdb_interruptible (int yes)
938{
939 return;
940}
941
942#else /* ! (CONFIG_KGDB_SER_INDEX & 2) */
943
944void kgdb_serial_init (void)
945{
946 serial_printf ("[on serial] ");
947}
948
949void putDebugChar (int c)
950{
951 serial_putc (c);
952}
953
954void putDebugStr (const char *str)
955{
956 serial_puts (str);
957}
958
959int getDebugChar (void)
960{
961 return serial_getc ();
962}
963
964void kgdb_interruptible (int yes)
965{
966 return;
967}
968#endif /* (CONFIG_KGDB_SER_INDEX & 2) */
969#endif /* CFG_CMD_KGDB */
970
wdenk96c7a8c2005-01-09 22:28:56 +0000971
972#if defined(CONFIG_SERIAL_MULTI)
973int serial0_init(void)
974{
975 return (serial_init_dev(UART0_BASE));
976}
977
978int serial1_init(void)
979{
980 return (serial_init_dev(UART1_BASE));
981}
982void serial0_setbrg (void)
983{
984 serial_setbrg_dev(UART0_BASE);
985}
986void serial1_setbrg (void)
987{
988 serial_setbrg_dev(UART1_BASE);
989}
990
991void serial0_putc(const char c)
992{
993 serial_putc_dev(UART0_BASE,c);
994}
995
996void serial1_putc(const char c)
997{
998 serial_putc_dev(UART1_BASE, c);
999}
1000void serial0_puts(const char *s)
1001{
1002 serial_puts_dev(UART0_BASE, s);
1003}
1004
1005void serial1_puts(const char *s)
1006{
1007 serial_puts_dev(UART1_BASE, s);
1008}
1009
1010int serial0_getc(void)
1011{
1012 return(serial_getc_dev(UART0_BASE));
1013}
1014
1015int serial1_getc(void)
1016{
1017 return(serial_getc_dev(UART1_BASE));
1018}
1019int serial0_tstc(void)
1020{
1021 return (serial_tstc_dev(UART0_BASE));
1022}
1023
1024int serial1_tstc(void)
1025{
1026 return (serial_tstc_dev(UART1_BASE));
1027}
1028
1029struct serial_device serial0_device =
1030{
1031 "serial0",
1032 "UART0",
1033 serial0_init,
1034 serial0_setbrg,
1035 serial0_getc,
1036 serial0_tstc,
1037 serial0_putc,
1038 serial0_puts,
1039};
1040
1041struct serial_device serial1_device =
1042{
1043 "serial1",
1044 "UART1",
1045 serial1_init,
1046 serial1_setbrg,
1047 serial1_getc,
1048 serial1_tstc,
1049 serial1_putc,
1050 serial1_puts,
1051};
1052#endif /* CONFIG_SERIAL_MULTI */
1053
wdenkfe8c2802002-11-03 00:38:21 +00001054#endif /* CONFIG_405GP || CONFIG_405CR */