blob: ad3ca6e819e2f0378e114834c5e9533d8baea06c [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
Wolfgang Denkc80857e2006-07-21 11:56:05 +02002 * (C) Copyright 2000-2006
wdenkfe8c2802002-11-03 00:38:21 +00003 * 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
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200278#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese99644742005-11-29 18:18:21 +0100279#define UART2_BASE CFG_PERIPHERAL_BASE + 0x00000600
280#endif
281
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200282#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || defined(CONFIG_440GR) || defined(CONFIG_440SP) || defined(CONFIG_440SPE)
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
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200312#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || \
313 defined(CONFIG_440GR) || defined(CONFIG_440SP) || \
314 defined(CONFIG_440SPE)
wdenk544e9732004-02-06 23:19:44 +0000315#define UART0_SDR sdr_uart1
316#define UART1_SDR sdr_uart0
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200317#endif /* CONFIG_440GX */
stroese937d6672003-05-23 11:25:57 +0000318#else
319#define ACTING_UART0_BASE UART0_BASE
320#define ACTING_UART1_BASE UART1_BASE
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200321#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || \
322 defined(CONFIG_440GR) || defined(CONFIG_440SP) || \
323 defined(CONFIG_440SPE)
wdenk544e9732004-02-06 23:19:44 +0000324#define UART0_SDR sdr_uart0
325#define UART1_SDR sdr_uart1
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200326#endif /* CONFIG_440GX */
stroese937d6672003-05-23 11:25:57 +0000327#endif
328
329#if defined(CONFIG_405EP) && defined(CFG_EXT_SERIAL_CLOCK)
Wolfgang Denk0ee70772005-09-23 11:05:55 +0200330#error "External serial clock not supported on AMCC PPC405EP!"
wdenkfe8c2802002-11-03 00:38:21 +0000331#endif
332
333#define UART_RBR 0x00
334#define UART_THR 0x00
335#define UART_IER 0x01
336#define UART_IIR 0x02
337#define UART_FCR 0x02
338#define UART_LCR 0x03
339#define UART_MCR 0x04
340#define UART_LSR 0x05
341#define UART_MSR 0x06
342#define UART_SCR 0x07
343#define UART_DLL 0x00
344#define UART_DLM 0x01
345
346/*-----------------------------------------------------------------------------+
347 | Line Status Register.
348 +-----------------------------------------------------------------------------*/
stroese937d6672003-05-23 11:25:57 +0000349/*#define asyncLSRport1 ACTING_UART0_BASE+0x05 */
wdenkfe8c2802002-11-03 00:38:21 +0000350#define asyncLSRDataReady1 0x01
351#define asyncLSROverrunError1 0x02
352#define asyncLSRParityError1 0x04
353#define asyncLSRFramingError1 0x08
354#define asyncLSRBreakInterrupt1 0x10
355#define asyncLSRTxHoldEmpty1 0x20
356#define asyncLSRTxShiftEmpty1 0x40
357#define asyncLSRRxFifoError1 0x80
358
359/*-----------------------------------------------------------------------------+
360 | Miscellanies defines.
361 +-----------------------------------------------------------------------------*/
stroese937d6672003-05-23 11:25:57 +0000362/*#define asyncTxBufferport1 ACTING_UART0_BASE+0x00 */
363/*#define asyncRxBufferport1 ACTING_UART0_BASE+0x00 */
wdenkfe8c2802002-11-03 00:38:21 +0000364
wdenkc35ba4e2004-03-14 22:25:36 +0000365#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000366/*-----------------------------------------------------------------------------+
367 | Fifo
368 +-----------------------------------------------------------------------------*/
369typedef struct {
370 char *rx_buffer;
371 ulong rx_put;
372 ulong rx_get;
373} serial_buffer_t;
374
375volatile static serial_buffer_t buf_info;
376#endif
377
wdenkfe8c2802002-11-03 00:38:21 +0000378#if defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLOCK)
379static void serial_divs (int baudrate, unsigned long *pudiv,
380 unsigned short *pbdiv )
381{
382 sys_info_t sysinfo;
383 unsigned long div; /* total divisor udiv * bdiv */
384 unsigned long umin; /* minimum udiv */
385 unsigned short diff; /* smallest diff */
386 unsigned long udiv; /* best udiv */
387
388 unsigned short idiff; /* current diff */
389 unsigned short ibdiv; /* current bdiv */
390 unsigned long i;
391 unsigned long est; /* current estimate */
392
393 get_sys_info( &sysinfo );
394
395 udiv = 32; /* Assume lowest possible serial clk */
396 div = sysinfo.freqPLB/(16*baudrate); /* total divisor */
397 umin = sysinfo.pllOpbDiv<<1; /* 2 x OPB divisor */
398 diff = 32; /* highest possible */
399
400 /* i is the test udiv value -- start with the largest
401 * possible (32) to minimize serial clock and constrain
402 * search to umin.
403 */
404 for( i = 32; i > umin; i-- ){
405 ibdiv = div/i;
406 est = i * ibdiv;
407 idiff = (est > div) ? (est-div) : (div-est);
408 if( idiff == 0 ){
409 udiv = i;
410 break; /* can't do better */
411 }
412 else if( idiff < diff ){
413 udiv = i; /* best so far */
414 diff = idiff; /* update lowest diff*/
415 }
416 }
417
418 *pudiv = udiv;
419 *pbdiv = div/udiv;
420
421}
422#endif /* defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLK */
423
wdenkfe8c2802002-11-03 00:38:21 +0000424/*
425 * Minimal serial functions needed to use one of the SMC ports
426 * as serial console interface.
427 */
428
429#if defined(CONFIG_440)
wdenk96c7a8c2005-01-09 22:28:56 +0000430#if defined(CONFIG_SERIAL_MULTI)
431int serial_init_dev (unsigned long dev_base)
432#else
433int serial_init(void)
434#endif
wdenkfe8c2802002-11-03 00:38:21 +0000435{
wdenkfe8c2802002-11-03 00:38:21 +0000436 unsigned long reg;
437 unsigned long udiv;
438 unsigned short bdiv;
439 volatile char val;
440#ifdef CFG_EXT_SERIAL_CLOCK
441 unsigned long tmp;
442#endif
443
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200444#if defined(CONFIG_440GX) || defined(CONFIG_440SP) || \
445 defined(CONFIG_440SPE)
wdenk96c7a8c2005-01-09 22:28:56 +0000446#if defined(CONFIG_SERIAL_MULTI)
447 if (UART0_BASE == dev_base) {
448 mfsdr(UART0_SDR,reg);
449 reg &= ~CR0_MASK;
450 } else {
451 mfsdr(UART1_SDR,reg);
452 reg &= ~CR0_MASK;
453 }
454#else
wdenk544e9732004-02-06 23:19:44 +0000455 mfsdr(UART0_SDR,reg);
456 reg &= ~CR0_MASK;
wdenk96c7a8c2005-01-09 22:28:56 +0000457#endif
wdenk544e9732004-02-06 23:19:44 +0000458#else
wdenkfe8c2802002-11-03 00:38:21 +0000459 reg = mfdcr(cntrl0) & ~CR0_MASK;
Stefan Roeseb30f2a12005-08-08 12:42:22 +0200460#endif /* CONFIG_440GX */
wdenkfe8c2802002-11-03 00:38:21 +0000461#ifdef CFG_EXT_SERIAL_CLOCK
462 reg |= CR0_EXTCLK_ENA;
463 udiv = 1;
464 tmp = gd->baudrate * 16;
465 bdiv = (CFG_EXT_SERIAL_CLOCK + tmp / 2) / tmp;
466#else
467 /* For 440, the cpu clock is on divider chain A, UART on divider
468 * chain B ... so cpu clock is irrelevant. Get the "optimized"
469 * values that are subject to the 1/2 opb clock constraint
470 */
471 serial_divs (gd->baudrate, &udiv, &bdiv);
472#endif
473
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200474#if defined(CONFIG_440GX) || defined(CONFIG_440EP) || \
475 defined(CONFIG_440GR) || defined(CONFIG_440SP) || \
476 defined(CONFIG_440SPE)
wdenk544e9732004-02-06 23:19:44 +0000477 reg |= udiv << CR0_UDIV_POS; /* set the UART divisor */
wdenk96c7a8c2005-01-09 22:28:56 +0000478#if defined(CONFIG_SERIAL_MULTI)
479 if (UART0_BASE == dev_base) {
480 mtsdr (UART0_SDR,reg);
481 } else {
482 mtsdr (UART1_SDR,reg);
483 }
484#else
wdenk544e9732004-02-06 23:19:44 +0000485 mtsdr (UART0_SDR,reg);
wdenk96c7a8c2005-01-09 22:28:56 +0000486#endif
wdenk544e9732004-02-06 23:19:44 +0000487#else
wdenkfe8c2802002-11-03 00:38:21 +0000488 reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */
489 mtdcr (cntrl0, reg);
wdenk544e9732004-02-06 23:19:44 +0000490#endif
wdenk96c7a8c2005-01-09 22:28:56 +0000491
492#if defined(CONFIG_SERIAL_MULTI)
493 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
494 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
495 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
496 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
497 out8 (dev_base + UART_FCR, 0x00); /* disable FIFO */
498 out8 (dev_base + UART_MCR, 0x00); /* no modem control DTR RTS */
499 val = in8 (dev_base + UART_LSR); /* clear line status */
500 val = in8 (dev_base + UART_RBR); /* read receive buffer */
501 out8 (dev_base + UART_SCR, 0x00); /* set scratchpad */
502 out8 (dev_base + UART_IER, 0x00); /* set interrupt enable reg */
503#else
stroese937d6672003-05-23 11:25:57 +0000504 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
505 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
506 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
507 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
508 out8 (ACTING_UART0_BASE + UART_FCR, 0x00); /* disable FIFO */
509 out8 (ACTING_UART0_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
510 val = in8 (ACTING_UART0_BASE + UART_LSR); /* clear line status */
511 val = in8 (ACTING_UART0_BASE + UART_RBR); /* read receive buffer */
512 out8 (ACTING_UART0_BASE + UART_SCR, 0x00); /* set scratchpad */
513 out8 (ACTING_UART0_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenk96c7a8c2005-01-09 22:28:56 +0000514#endif
wdenkfe8c2802002-11-03 00:38:21 +0000515 return (0);
516}
517
518#else /* !defined(CONFIG_440) */
519
wdenk96c7a8c2005-01-09 22:28:56 +0000520#if defined(CONFIG_SERIAL_MULTI)
521int serial_init_dev (unsigned long dev_base)
522#else
wdenkfe8c2802002-11-03 00:38:21 +0000523int serial_init (void)
wdenk96c7a8c2005-01-09 22:28:56 +0000524#endif
wdenkfe8c2802002-11-03 00:38:21 +0000525{
wdenkfe8c2802002-11-03 00:38:21 +0000526 unsigned long reg;
527 unsigned long tmp;
528 unsigned long clk;
529 unsigned long udiv;
530 unsigned short bdiv;
531 volatile char val;
532
stroese937d6672003-05-23 11:25:57 +0000533#ifdef CONFIG_405EP
534 reg = mfdcr(cpc0_ucr) & ~(UCR0_MASK | UCR1_MASK);
535 clk = gd->cpu_clk;
536 tmp = CFG_BASE_BAUD * 16;
537 udiv = (clk + tmp / 2) / tmp;
538 if (udiv > UDIV_MAX) /* max. n bits for udiv */
539 udiv = UDIV_MAX;
540 reg |= (udiv) << UCR0_UDIV_POS; /* set the UART divisor */
541 reg |= (udiv) << UCR1_UDIV_POS; /* set the UART divisor */
542 mtdcr (cpc0_ucr, reg);
543#else /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000544 reg = mfdcr(cntrl0) & ~CR0_MASK;
545#ifdef CFG_EXT_SERIAL_CLOCK
546 clk = CFG_EXT_SERIAL_CLOCK;
547 udiv = 1;
548 reg |= CR0_EXTCLK_ENA;
549#else
550 clk = gd->cpu_clk;
551#ifdef CFG_405_UART_ERRATA_59
552 udiv = 31; /* Errata 59: stuck at 31 */
553#else
554 tmp = CFG_BASE_BAUD * 16;
555 udiv = (clk + tmp / 2) / tmp;
stroese937d6672003-05-23 11:25:57 +0000556 if (udiv > UDIV_MAX) /* max. n bits for udiv */
557 udiv = UDIV_MAX;
wdenkfe8c2802002-11-03 00:38:21 +0000558#endif
559#endif
wdenkfe8c2802002-11-03 00:38:21 +0000560 reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */
561 mtdcr (cntrl0, reg);
stroese937d6672003-05-23 11:25:57 +0000562#endif /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000563
564 tmp = gd->baudrate * udiv * 16;
565 bdiv = (clk + tmp / 2) / tmp;
566
wdenk96c7a8c2005-01-09 22:28:56 +0000567#if defined(CONFIG_SERIAL_MULTI)
568 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
569 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
570 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
571 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
572 out8 (dev_base + UART_FCR, 0x00); /* disable FIFO */
573 out8 (dev_base + UART_MCR, 0x00); /* no modem control DTR RTS */
574 val = in8 (dev_base + UART_LSR); /* clear line status */
575 val = in8 (dev_base + UART_RBR); /* read receive buffer */
576 out8 (dev_base + UART_SCR, 0x00); /* set scratchpad */
577 out8 (dev_base + UART_IER, 0x00); /* set interrupt enable reg */
578#else
stroese937d6672003-05-23 11:25:57 +0000579 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
580 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
581 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
582 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
583 out8 (ACTING_UART0_BASE + UART_FCR, 0x00); /* disable FIFO */
584 out8 (ACTING_UART0_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
585 val = in8 (ACTING_UART0_BASE + UART_LSR); /* clear line status */
586 val = in8 (ACTING_UART0_BASE + UART_RBR); /* read receive buffer */
587 out8 (ACTING_UART0_BASE + UART_SCR, 0x00); /* set scratchpad */
588 out8 (ACTING_UART0_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenk96c7a8c2005-01-09 22:28:56 +0000589#endif
wdenkfe8c2802002-11-03 00:38:21 +0000590 return (0);
591}
592
593#endif /* if defined(CONFIG_440) */
594
wdenk96c7a8c2005-01-09 22:28:56 +0000595#if defined(CONFIG_SERIAL_MULTI)
596void serial_setbrg_dev (unsigned long dev_base)
597#else
wdenkfe8c2802002-11-03 00:38:21 +0000598void serial_setbrg (void)
wdenk96c7a8c2005-01-09 22:28:56 +0000599#endif
wdenkfe8c2802002-11-03 00:38:21 +0000600{
wdenkfe8c2802002-11-03 00:38:21 +0000601 unsigned long tmp;
602 unsigned long clk;
603 unsigned long udiv;
604 unsigned short bdiv;
605
606#ifdef CFG_EXT_SERIAL_CLOCK
607 clk = CFG_EXT_SERIAL_CLOCK;
608#else
609 clk = gd->cpu_clk;
610#endif
stroese937d6672003-05-23 11:25:57 +0000611
612#ifdef CONFIG_405EP
613 udiv = ((mfdcr (cpc0_ucr) & UCR0_MASK) >> UCR0_UDIV_POS);
614#else
wdenkfe8c2802002-11-03 00:38:21 +0000615 udiv = ((mfdcr (cntrl0) & 0x3e) >> 1) + 1;
stroese937d6672003-05-23 11:25:57 +0000616#endif /* CONFIG_405EP */
Marian Balakowicz49d0eee2006-06-30 16:30:46 +0200617
618#if !defined(CFG_EXT_SERIAL_CLOCK) && \
619 ( defined(CONFIG_440GX) || defined(CONFIG_440EP) || \
620 defined(CONFIG_440GR) || defined(CONFIG_440SP) || \
621 defined(CONFIG_440SPE) )
622 serial_divs (gd->baudrate, &udiv, &bdiv);
623 tmp = udiv << CR0_UDIV_POS; /* set the UART divisor */
624#if defined(CONFIG_SERIAL_MULTI)
625 if (UART0_BASE == dev_base) {
626 mtsdr (UART0_SDR, tmp);
627 } else {
628 mtsdr (UART1_SDR, tmp);
629 }
630#else
631 mtsdr (UART0_SDR, tmp);
632#endif
633
634#else
635
wdenkfe8c2802002-11-03 00:38:21 +0000636 tmp = gd->baudrate * udiv * 16;
637 bdiv = (clk + tmp / 2) / tmp;
Wolfgang Denkba940932006-07-19 13:50:38 +0200638#endif /* !defined(CFG_EXT_SERIAL_CLOCK) && (...) */
wdenkfe8c2802002-11-03 00:38:21 +0000639
wdenk96c7a8c2005-01-09 22:28:56 +0000640#if defined(CONFIG_SERIAL_MULTI)
641 out8 (dev_base + UART_LCR, 0x80); /* set DLAB bit */
642 out8 (dev_base + UART_DLL, bdiv); /* set baudrate divisor */
643 out8 (dev_base + UART_DLM, bdiv >> 8);/* set baudrate divisor */
644 out8 (dev_base + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
645#else
stroese937d6672003-05-23 11:25:57 +0000646 out8 (ACTING_UART0_BASE + UART_LCR, 0x80); /* set DLAB bit */
647 out8 (ACTING_UART0_BASE + UART_DLL, bdiv); /* set baudrate divisor */
648 out8 (ACTING_UART0_BASE + UART_DLM, bdiv >> 8);/* set baudrate divisor */
649 out8 (ACTING_UART0_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
wdenk96c7a8c2005-01-09 22:28:56 +0000650#endif
wdenkfe8c2802002-11-03 00:38:21 +0000651}
652
wdenk96c7a8c2005-01-09 22:28:56 +0000653#if defined(CONFIG_SERIAL_MULTI)
654void serial_putc_dev (unsigned long dev_base, const char c)
655#else
wdenkfe8c2802002-11-03 00:38:21 +0000656void serial_putc (const char c)
wdenk96c7a8c2005-01-09 22:28:56 +0000657#endif
wdenkfe8c2802002-11-03 00:38:21 +0000658{
659 int i;
660
661 if (c == '\n')
wdenk96c7a8c2005-01-09 22:28:56 +0000662#if defined(CONFIG_SERIAL_MULTI)
663 serial_putc_dev (dev_base, '\r');
664#else
wdenkfe8c2802002-11-03 00:38:21 +0000665 serial_putc ('\r');
wdenk96c7a8c2005-01-09 22:28:56 +0000666#endif
wdenkfe8c2802002-11-03 00:38:21 +0000667
668 /* check THRE bit, wait for transmiter available */
669 for (i = 1; i < 3500; i++) {
wdenk96c7a8c2005-01-09 22:28:56 +0000670#if defined(CONFIG_SERIAL_MULTI)
671 if ((in8 (dev_base + UART_LSR) & 0x20) == 0x20)
672#else
stroese937d6672003-05-23 11:25:57 +0000673 if ((in8 (ACTING_UART0_BASE + UART_LSR) & 0x20) == 0x20)
wdenk96c7a8c2005-01-09 22:28:56 +0000674#endif
wdenkfe8c2802002-11-03 00:38:21 +0000675 break;
676 udelay (100);
677 }
wdenk96c7a8c2005-01-09 22:28:56 +0000678#if defined(CONFIG_SERIAL_MULTI)
679 out8 (dev_base + UART_THR, c); /* put character out */
680#else
stroese937d6672003-05-23 11:25:57 +0000681 out8 (ACTING_UART0_BASE + UART_THR, c); /* put character out */
wdenk96c7a8c2005-01-09 22:28:56 +0000682#endif
wdenkfe8c2802002-11-03 00:38:21 +0000683}
684
wdenk96c7a8c2005-01-09 22:28:56 +0000685#if defined(CONFIG_SERIAL_MULTI)
686void serial_puts_dev (unsigned long dev_base, const char *s)
687#else
wdenkfe8c2802002-11-03 00:38:21 +0000688void serial_puts (const char *s)
wdenk96c7a8c2005-01-09 22:28:56 +0000689#endif
wdenkfe8c2802002-11-03 00:38:21 +0000690{
691 while (*s) {
wdenk96c7a8c2005-01-09 22:28:56 +0000692#if defined(CONFIG_SERIAL_MULTI)
693 serial_putc_dev (dev_base, *s++);
694#else
wdenkfe8c2802002-11-03 00:38:21 +0000695 serial_putc (*s++);
wdenk96c7a8c2005-01-09 22:28:56 +0000696#endif
wdenkfe8c2802002-11-03 00:38:21 +0000697 }
698}
699
wdenk96c7a8c2005-01-09 22:28:56 +0000700#if defined(CONFIG_SERIAL_MULTI)
701int serial_getc_dev (unsigned long dev_base)
702#else
703int serial_getc (void)
704#endif
wdenkfe8c2802002-11-03 00:38:21 +0000705{
706 unsigned char status = 0;
707
708 while (1) {
709#if defined(CONFIG_HW_WATCHDOG)
710 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
711#endif /* CONFIG_HW_WATCHDOG */
wdenk96c7a8c2005-01-09 22:28:56 +0000712#if defined(CONFIG_SERIAL_MULTI)
713 status = in8 (dev_base + UART_LSR);
714#else
stroese937d6672003-05-23 11:25:57 +0000715 status = in8 (ACTING_UART0_BASE + UART_LSR);
wdenk96c7a8c2005-01-09 22:28:56 +0000716#endif
wdenkfe8c2802002-11-03 00:38:21 +0000717 if ((status & asyncLSRDataReady1) != 0x0) {
718 break;
719 }
720 if ((status & ( asyncLSRFramingError1 |
721 asyncLSROverrunError1 |
722 asyncLSRParityError1 |
723 asyncLSRBreakInterrupt1 )) != 0) {
wdenk96c7a8c2005-01-09 22:28:56 +0000724#if defined(CONFIG_SERIAL_MULTI)
725 out8 (dev_base + UART_LSR,
726#else
stroese937d6672003-05-23 11:25:57 +0000727 out8 (ACTING_UART0_BASE + UART_LSR,
wdenk96c7a8c2005-01-09 22:28:56 +0000728#endif
wdenkfe8c2802002-11-03 00:38:21 +0000729 asyncLSRFramingError1 |
730 asyncLSROverrunError1 |
731 asyncLSRParityError1 |
732 asyncLSRBreakInterrupt1);
733 }
734 }
wdenk96c7a8c2005-01-09 22:28:56 +0000735#if defined(CONFIG_SERIAL_MULTI)
736 return (0x000000ff & (int) in8 (dev_base));
737#else
stroese937d6672003-05-23 11:25:57 +0000738 return (0x000000ff & (int) in8 (ACTING_UART0_BASE));
wdenk96c7a8c2005-01-09 22:28:56 +0000739#endif
wdenkfe8c2802002-11-03 00:38:21 +0000740}
741
wdenk96c7a8c2005-01-09 22:28:56 +0000742#if defined(CONFIG_SERIAL_MULTI)
743int serial_tstc_dev (unsigned long dev_base)
744#else
745int serial_tstc (void)
746#endif
wdenkfe8c2802002-11-03 00:38:21 +0000747{
748 unsigned char status;
749
wdenk96c7a8c2005-01-09 22:28:56 +0000750#if defined(CONFIG_SERIAL_MULTI)
751 status = in8 (dev_base + UART_LSR);
752#else
stroese937d6672003-05-23 11:25:57 +0000753 status = in8 (ACTING_UART0_BASE + UART_LSR);
wdenk96c7a8c2005-01-09 22:28:56 +0000754#endif
wdenkfe8c2802002-11-03 00:38:21 +0000755 if ((status & asyncLSRDataReady1) != 0x0) {
756 return (1);
757 }
758 if ((status & ( asyncLSRFramingError1 |
759 asyncLSROverrunError1 |
760 asyncLSRParityError1 |
761 asyncLSRBreakInterrupt1 )) != 0) {
wdenk96c7a8c2005-01-09 22:28:56 +0000762#if defined(CONFIG_SERIAL_MULTI)
763 out8 (dev_base + UART_LSR,
764#else
stroese937d6672003-05-23 11:25:57 +0000765 out8 (ACTING_UART0_BASE + UART_LSR,
wdenk96c7a8c2005-01-09 22:28:56 +0000766#endif
wdenkfe8c2802002-11-03 00:38:21 +0000767 asyncLSRFramingError1 |
768 asyncLSROverrunError1 |
769 asyncLSRParityError1 |
770 asyncLSRBreakInterrupt1);
771 }
772 return 0;
773}
774
wdenkc35ba4e2004-03-14 22:25:36 +0000775#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000776
777void serial_isr (void *arg)
778{
779 int space;
780 int c;
781 const int rx_get = buf_info.rx_get;
782 int rx_put = buf_info.rx_put;
783
784 if (rx_get <= rx_put) {
785 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
786 } else {
787 space = rx_get - rx_put;
788 }
wdenk96c7a8c2005-01-09 22:28:56 +0000789 while (serial_tstc_dev (ACTING_UART0_BASE)) {
790 c = serial_getc_dev (ACTING_UART0_BASE);
wdenkfe8c2802002-11-03 00:38:21 +0000791 if (space) {
792 buf_info.rx_buffer[rx_put++] = c;
793 space--;
794 }
795 if (rx_put == CONFIG_SERIAL_SOFTWARE_FIFO)
796 rx_put = 0;
797 if (space < CONFIG_SERIAL_SOFTWARE_FIFO / 4) {
798 /* Stop flow by setting RTS inactive */
stroese937d6672003-05-23 11:25:57 +0000799 out8 (ACTING_UART0_BASE + UART_MCR,
800 in8 (ACTING_UART0_BASE + UART_MCR) & (0xFF ^ 0x02));
wdenkfe8c2802002-11-03 00:38:21 +0000801 }
802 }
803 buf_info.rx_put = rx_put;
804}
805
806void serial_buffered_init (void)
807{
808 serial_puts ("Switching to interrupt driven serial input mode.\n");
809 buf_info.rx_buffer = malloc (CONFIG_SERIAL_SOFTWARE_FIFO);
810 buf_info.rx_put = 0;
811 buf_info.rx_get = 0;
812
stroese937d6672003-05-23 11:25:57 +0000813 if (in8 (ACTING_UART0_BASE + UART_MSR) & 0x10) {
wdenkfe8c2802002-11-03 00:38:21 +0000814 serial_puts ("Check CTS signal present on serial port: OK.\n");
815 } else {
816 serial_puts ("WARNING: CTS signal not present on serial port.\n");
817 }
818
819 irq_install_handler ( VECNUM_U0 /*UART0 */ /*int vec */ ,
820 serial_isr /*interrupt_handler_t *handler */ ,
821 (void *) &buf_info /*void *arg */ );
822
823 /* Enable "RX Data Available" Interrupt on UART */
stroese937d6672003-05-23 11:25:57 +0000824 /* out8(ACTING_UART0_BASE + UART_IER, in8(ACTING_UART0_BASE + UART_IER) |0x01); */
825 out8 (ACTING_UART0_BASE + UART_IER, 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000826 /* Set DTR active */
stroese937d6672003-05-23 11:25:57 +0000827 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000828 /* Start flow by setting RTS active */
stroese937d6672003-05-23 11:25:57 +0000829 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000830 /* Setup UART FIFO: RX trigger level: 4 byte, Enable FIFO */
stroese937d6672003-05-23 11:25:57 +0000831 out8 (ACTING_UART0_BASE + UART_FCR, (1 << 6) | 1);
wdenkfe8c2802002-11-03 00:38:21 +0000832}
833
834void serial_buffered_putc (const char c)
835{
836 /* Wait for CTS */
837#if defined(CONFIG_HW_WATCHDOG)
stroese937d6672003-05-23 11:25:57 +0000838 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10))
wdenkfe8c2802002-11-03 00:38:21 +0000839 WATCHDOG_RESET ();
840#else
stroese937d6672003-05-23 11:25:57 +0000841 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10));
wdenkfe8c2802002-11-03 00:38:21 +0000842#endif
843 serial_putc (c);
844}
845
846void serial_buffered_puts (const char *s)
847{
848 serial_puts (s);
849}
850
851int serial_buffered_getc (void)
852{
853 int space;
854 int c;
855 int rx_get = buf_info.rx_get;
856 int rx_put;
857
858#if defined(CONFIG_HW_WATCHDOG)
859 while (rx_get == buf_info.rx_put)
860 WATCHDOG_RESET ();
861#else
862 while (rx_get == buf_info.rx_put);
863#endif
864 c = buf_info.rx_buffer[rx_get++];
865 if (rx_get == CONFIG_SERIAL_SOFTWARE_FIFO)
866 rx_get = 0;
867 buf_info.rx_get = rx_get;
868
869 rx_put = buf_info.rx_put;
870 if (rx_get <= rx_put) {
871 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
872 } else {
873 space = rx_get - rx_put;
874 }
875 if (space > CONFIG_SERIAL_SOFTWARE_FIFO / 2) {
876 /* Start flow by setting RTS active */
stroese937d6672003-05-23 11:25:57 +0000877 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000878 }
879
880 return c;
881}
882
883int serial_buffered_tstc (void)
884{
885 return (buf_info.rx_get != buf_info.rx_put) ? 1 : 0;
886}
887
888#endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
889
wdenkfe8c2802002-11-03 00:38:21 +0000890#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
891/*
892 AS HARNOIS : according to CONFIG_KGDB_SER_INDEX kgdb uses serial port
893 number 0 or number 1
894 - if CONFIG_KGDB_SER_INDEX = 1 => serial port number 0 :
895 configuration has been already done
896 - if CONFIG_KGDB_SER_INDEX = 2 => serial port number 1 :
897 configure port 1 for serial I/O with rate = CONFIG_KGDB_BAUDRATE
898*/
899#if (CONFIG_KGDB_SER_INDEX & 2)
900void kgdb_serial_init (void)
901{
wdenkfe8c2802002-11-03 00:38:21 +0000902 volatile char val;
903 unsigned short br_reg;
904
905 get_clocks ();
906 br_reg = (((((gd->cpu_clk / 16) / 18) * 10) / CONFIG_KGDB_BAUDRATE) +
907 5) / 10;
908 /*
909 * Init onboard 16550 UART
910 */
stroese937d6672003-05-23 11:25:57 +0000911 out8 (ACTING_UART1_BASE + UART_LCR, 0x80); /* set DLAB bit */
912 out8 (ACTING_UART1_BASE + UART_DLL, (br_reg & 0x00ff)); /* set divisor for 9600 baud */
913 out8 (ACTING_UART1_BASE + UART_DLM, ((br_reg & 0xff00) >> 8)); /* set divisor for 9600 baud */
914 out8 (ACTING_UART1_BASE + UART_LCR, 0x03); /* line control 8 bits no parity */
915 out8 (ACTING_UART1_BASE + UART_FCR, 0x00); /* disable FIFO */
916 out8 (ACTING_UART1_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
917 val = in8 (ACTING_UART1_BASE + UART_LSR); /* clear line status */
918 val = in8 (ACTING_UART1_BASE + UART_RBR); /* read receive buffer */
919 out8 (ACTING_UART1_BASE + UART_SCR, 0x00); /* set scratchpad */
920 out8 (ACTING_UART1_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenkfe8c2802002-11-03 00:38:21 +0000921}
922
wdenkfe8c2802002-11-03 00:38:21 +0000923void putDebugChar (const char c)
924{
925 if (c == '\n')
926 serial_putc ('\r');
927
stroese937d6672003-05-23 11:25:57 +0000928 out8 (ACTING_UART1_BASE + UART_THR, c); /* put character out */
wdenkfe8c2802002-11-03 00:38:21 +0000929
930 /* check THRE bit, wait for transfer done */
stroese937d6672003-05-23 11:25:57 +0000931 while ((in8 (ACTING_UART1_BASE + UART_LSR) & 0x20) != 0x20);
wdenkfe8c2802002-11-03 00:38:21 +0000932}
933
wdenkfe8c2802002-11-03 00:38:21 +0000934void putDebugStr (const char *s)
935{
936 while (*s) {
937 serial_putc (*s++);
938 }
939}
940
wdenkfe8c2802002-11-03 00:38:21 +0000941int getDebugChar (void)
942{
943 unsigned char status = 0;
944
945 while (1) {
stroese937d6672003-05-23 11:25:57 +0000946 status = in8 (ACTING_UART1_BASE + UART_LSR);
wdenkfe8c2802002-11-03 00:38:21 +0000947 if ((status & asyncLSRDataReady1) != 0x0) {
948 break;
949 }
950 if ((status & ( asyncLSRFramingError1 |
951 asyncLSROverrunError1 |
952 asyncLSRParityError1 |
953 asyncLSRBreakInterrupt1 )) != 0) {
stroese937d6672003-05-23 11:25:57 +0000954 out8 (ACTING_UART1_BASE + UART_LSR,
wdenkfe8c2802002-11-03 00:38:21 +0000955 asyncLSRFramingError1 |
956 asyncLSROverrunError1 |
957 asyncLSRParityError1 |
958 asyncLSRBreakInterrupt1);
959 }
960 }
stroese937d6672003-05-23 11:25:57 +0000961 return (0x000000ff & (int) in8 (ACTING_UART1_BASE));
wdenkfe8c2802002-11-03 00:38:21 +0000962}
963
wdenkfe8c2802002-11-03 00:38:21 +0000964void kgdb_interruptible (int yes)
965{
966 return;
967}
968
969#else /* ! (CONFIG_KGDB_SER_INDEX & 2) */
970
971void kgdb_serial_init (void)
972{
973 serial_printf ("[on serial] ");
974}
975
976void putDebugChar (int c)
977{
978 serial_putc (c);
979}
980
981void putDebugStr (const char *str)
982{
983 serial_puts (str);
984}
985
986int getDebugChar (void)
987{
988 return serial_getc ();
989}
990
991void kgdb_interruptible (int yes)
992{
993 return;
994}
995#endif /* (CONFIG_KGDB_SER_INDEX & 2) */
996#endif /* CFG_CMD_KGDB */
997
wdenk96c7a8c2005-01-09 22:28:56 +0000998
999#if defined(CONFIG_SERIAL_MULTI)
1000int serial0_init(void)
1001{
1002 return (serial_init_dev(UART0_BASE));
1003}
1004
1005int serial1_init(void)
1006{
1007 return (serial_init_dev(UART1_BASE));
1008}
1009void serial0_setbrg (void)
1010{
1011 serial_setbrg_dev(UART0_BASE);
1012}
1013void serial1_setbrg (void)
1014{
1015 serial_setbrg_dev(UART1_BASE);
1016}
1017
1018void serial0_putc(const char c)
1019{
1020 serial_putc_dev(UART0_BASE,c);
1021}
1022
1023void serial1_putc(const char c)
1024{
1025 serial_putc_dev(UART1_BASE, c);
1026}
1027void serial0_puts(const char *s)
1028{
1029 serial_puts_dev(UART0_BASE, s);
1030}
1031
1032void serial1_puts(const char *s)
1033{
1034 serial_puts_dev(UART1_BASE, s);
1035}
1036
1037int serial0_getc(void)
1038{
1039 return(serial_getc_dev(UART0_BASE));
1040}
1041
1042int serial1_getc(void)
1043{
1044 return(serial_getc_dev(UART1_BASE));
1045}
1046int serial0_tstc(void)
1047{
1048 return (serial_tstc_dev(UART0_BASE));
1049}
1050
1051int serial1_tstc(void)
1052{
1053 return (serial_tstc_dev(UART1_BASE));
1054}
1055
1056struct serial_device serial0_device =
1057{
1058 "serial0",
1059 "UART0",
1060 serial0_init,
1061 serial0_setbrg,
1062 serial0_getc,
1063 serial0_tstc,
1064 serial0_putc,
1065 serial0_puts,
1066};
1067
1068struct serial_device serial1_device =
1069{
1070 "serial1",
1071 "UART1",
1072 serial1_init,
1073 serial1_setbrg,
1074 serial1_getc,
1075 serial1_tstc,
1076 serial1_putc,
1077 serial1_puts,
1078};
1079#endif /* CONFIG_SERIAL_MULTI */
1080
wdenkfe8c2802002-11-03 00:38:21 +00001081#endif /* CONFIG_405GP || CONFIG_405CR */