blob: 376ca1e5bdeb623b9e42dccde416408c45bceda1 [file] [log] [blame]
wdenkfe8c2802002-11-03 00:38:21 +00001/*
Wolfgang Denkb9365a22006-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/*------------------------------------------------------------------------------- */
wdenkff36fd82005-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
wdenkff36fd82005-01-09 22:28:56 +000054#ifdef CONFIG_SERIAL_MULTI
55#include <serial.h>
56#endif
57
wdenk42dfe7a2004-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 Denkd87080b2006-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/*****************************************************************************/
Stefan Roesee01bd212007-03-21 13:38:59 +0100267#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
268 defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
Stefan Roese887e2ec2006-09-07 11:51:23 +0200269 defined(CONFIG_440)
wdenkfe8c2802002-11-03 00:38:21 +0000270
271#if defined(CONFIG_440)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200272#if defined(CONFIG_440EP) || defined(CONFIG_440GR) || \
273 defined(CONFIG_440EPX) || defined(CONFIG_440GRX)
Stefan Roesec157d8e2005-08-01 16:41:48 +0200274#define UART0_BASE CFG_PERIPHERAL_BASE + 0x00000300
275#define UART1_BASE CFG_PERIPHERAL_BASE + 0x00000400
276#else
wdenkfe8c2802002-11-03 00:38:21 +0000277#define UART0_BASE CFG_PERIPHERAL_BASE + 0x00000200
278#define UART1_BASE CFG_PERIPHERAL_BASE + 0x00000300
Stefan Roesec157d8e2005-08-01 16:41:48 +0200279#endif
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100280
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200281#if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
Stefan Roese6e7fb6e2005-11-29 18:18:21 +0100282#define UART2_BASE CFG_PERIPHERAL_BASE + 0x00000600
283#endif
284
Stefan Roese887e2ec2006-09-07 11:51:23 +0200285#if defined(CONFIG_440GP)
wdenkfe8c2802002-11-03 00:38:21 +0000286#define CR0_MASK 0x3fff0000
287#define CR0_EXTCLK_ENA 0x00600000
288#define CR0_UDIV_POS 16
Stefan Roese887e2ec2006-09-07 11:51:23 +0200289#define UDIV_SUBTRACT 1
290#define UART0_SDR cntrl0
291#define MFREG(a, d) d = mfdcr(a)
292#define MTREG(a, d) mtdcr(a, d)
293#else /* #if defined(CONFIG_440GP) */
294/* all other 440 PPC's access clock divider via sdr register */
295#define CR0_MASK 0xdfffffff
296#define CR0_EXTCLK_ENA 0x00800000
297#define CR0_UDIV_POS 0
298#define UDIV_SUBTRACT 0
299#define UART0_SDR sdr_uart0
300#define UART1_SDR sdr_uart1
301#if defined(CONFIG_440EP) || defined(CONFIG_440EPx) || \
302 defined(CONFIG_440GR) || defined(CONFIG_440GRx) || \
303 defined(CONFIG_440SP) || defined(CONFIG_440SPe)
304#define UART2_SDR sdr_uart2
305#endif
306#if defined(CONFIG_440EP) || defined(CONFIG_440EPx) || \
307 defined(CONFIG_440GR) || defined(CONFIG_440GRx)
308#define UART3_SDR sdr_uart3
309#endif
310#define MFREG(a, d) mfsdr(a, d)
311#define MTREG(a, d) mtsdr(a, d)
312#endif /* #if defined(CONFIG_440GP) */
Stefan Roesee01bd212007-03-21 13:38:59 +0100313#elif defined(CONFIG_405EP) || defined(CONFIG_405EZ)
stroese8749cfb2003-05-23 11:25:57 +0000314#define UART0_BASE 0xef600300
315#define UART1_BASE 0xef600400
316#define UCR0_MASK 0x0000007f
317#define UCR1_MASK 0x00007f00
318#define UCR0_UDIV_POS 0
319#define UCR1_UDIV_POS 8
320#define UDIV_MAX 127
321#else /* CONFIG_405GP || CONFIG_405CR */
wdenkfe8c2802002-11-03 00:38:21 +0000322#define UART0_BASE 0xef600300
323#define UART1_BASE 0xef600400
324#define CR0_MASK 0x00001fff
stroesed7787c62003-02-17 16:06:06 +0000325#define CR0_EXTCLK_ENA 0x000000c0
wdenkfe8c2802002-11-03 00:38:21 +0000326#define CR0_UDIV_POS 1
stroese8749cfb2003-05-23 11:25:57 +0000327#define UDIV_MAX 32
328#endif
329
330/* using serial port 0 or 1 as U-Boot console ? */
331#if defined(CONFIG_UART1_CONSOLE)
332#define ACTING_UART0_BASE UART1_BASE
333#define ACTING_UART1_BASE UART0_BASE
334#else
335#define ACTING_UART0_BASE UART0_BASE
336#define ACTING_UART1_BASE UART1_BASE
Stefan Roese887e2ec2006-09-07 11:51:23 +0200337#endif
338
339#if defined(CONFIG_SERIAL_MULTI)
340#define UART_BASE dev_base
341#else
342#define UART_BASE ACTING_UART0_BASE
stroese8749cfb2003-05-23 11:25:57 +0000343#endif
344
345#if defined(CONFIG_405EP) && defined(CFG_EXT_SERIAL_CLOCK)
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200346#error "External serial clock not supported on AMCC PPC405EP!"
wdenkfe8c2802002-11-03 00:38:21 +0000347#endif
348
349#define UART_RBR 0x00
350#define UART_THR 0x00
351#define UART_IER 0x01
352#define UART_IIR 0x02
353#define UART_FCR 0x02
354#define UART_LCR 0x03
355#define UART_MCR 0x04
356#define UART_LSR 0x05
357#define UART_MSR 0x06
358#define UART_SCR 0x07
359#define UART_DLL 0x00
360#define UART_DLM 0x01
361
362/*-----------------------------------------------------------------------------+
363 | Line Status Register.
364 +-----------------------------------------------------------------------------*/
stroese8749cfb2003-05-23 11:25:57 +0000365/*#define asyncLSRport1 ACTING_UART0_BASE+0x05 */
wdenkfe8c2802002-11-03 00:38:21 +0000366#define asyncLSRDataReady1 0x01
367#define asyncLSROverrunError1 0x02
368#define asyncLSRParityError1 0x04
369#define asyncLSRFramingError1 0x08
370#define asyncLSRBreakInterrupt1 0x10
371#define asyncLSRTxHoldEmpty1 0x20
372#define asyncLSRTxShiftEmpty1 0x40
373#define asyncLSRRxFifoError1 0x80
374
375/*-----------------------------------------------------------------------------+
376 | Miscellanies defines.
377 +-----------------------------------------------------------------------------*/
stroese8749cfb2003-05-23 11:25:57 +0000378/*#define asyncTxBufferport1 ACTING_UART0_BASE+0x00 */
379/*#define asyncRxBufferport1 ACTING_UART0_BASE+0x00 */
wdenkfe8c2802002-11-03 00:38:21 +0000380
wdenk42dfe7a2004-03-14 22:25:36 +0000381#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000382/*-----------------------------------------------------------------------------+
383 | Fifo
384 +-----------------------------------------------------------------------------*/
385typedef struct {
386 char *rx_buffer;
387 ulong rx_put;
388 ulong rx_get;
389} serial_buffer_t;
390
391volatile static serial_buffer_t buf_info;
392#endif
393
wdenkfe8c2802002-11-03 00:38:21 +0000394#if defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLOCK)
395static void serial_divs (int baudrate, unsigned long *pudiv,
Stefan Roesee01bd212007-03-21 13:38:59 +0100396 unsigned short *pbdiv)
wdenkfe8c2802002-11-03 00:38:21 +0000397{
Stefan Roesee01bd212007-03-21 13:38:59 +0100398 sys_info_t sysinfo;
wdenkfe8c2802002-11-03 00:38:21 +0000399 unsigned long div; /* total divisor udiv * bdiv */
400 unsigned long umin; /* minimum udiv */
Stefan Roesee01bd212007-03-21 13:38:59 +0100401 unsigned short diff; /* smallest diff */
402 unsigned long udiv; /* best udiv */
403 unsigned short idiff; /* current diff */
404 unsigned short ibdiv; /* current bdiv */
wdenkfe8c2802002-11-03 00:38:21 +0000405 unsigned long i;
Stefan Roesee01bd212007-03-21 13:38:59 +0100406 unsigned long est; /* current estimate */
wdenkfe8c2802002-11-03 00:38:21 +0000407
Stefan Roesee01bd212007-03-21 13:38:59 +0100408 get_sys_info(&sysinfo);
wdenkfe8c2802002-11-03 00:38:21 +0000409
Stefan Roesee01bd212007-03-21 13:38:59 +0100410 udiv = 32; /* Assume lowest possible serial clk */
411 div = sysinfo.freqPLB / (16 * baudrate); /* total divisor */
412 umin = sysinfo.pllOpbDiv << 1; /* 2 x OPB divisor */
413 diff = 32; /* highest possible */
wdenkfe8c2802002-11-03 00:38:21 +0000414
415 /* i is the test udiv value -- start with the largest
416 * possible (32) to minimize serial clock and constrain
417 * search to umin.
418 */
Stefan Roesee01bd212007-03-21 13:38:59 +0100419 for (i = 32; i > umin; i--) {
420 ibdiv = div / i;
wdenkfe8c2802002-11-03 00:38:21 +0000421 est = i * ibdiv;
422 idiff = (est > div) ? (est-div) : (div-est);
Stefan Roesee01bd212007-03-21 13:38:59 +0100423 if (idiff == 0) {
wdenkfe8c2802002-11-03 00:38:21 +0000424 udiv = i;
425 break; /* can't do better */
Stefan Roesee01bd212007-03-21 13:38:59 +0100426 } else if (idiff < diff) {
wdenkfe8c2802002-11-03 00:38:21 +0000427 udiv = i; /* best so far */
428 diff = idiff; /* update lowest diff*/
429 }
430 }
431
432 *pudiv = udiv;
Stefan Roesee01bd212007-03-21 13:38:59 +0100433 *pbdiv = div / udiv;
434}
wdenkfe8c2802002-11-03 00:38:21 +0000435
Stefan Roesee01bd212007-03-21 13:38:59 +0100436#elif defined(CONFIG_405EZ)
437
438static void serial_divs (int baudrate, unsigned long *pudiv,
439 unsigned short *pbdiv)
440{
441 sys_info_t sysinfo;
442 unsigned long div; /* total divisor udiv * bdiv */
443 unsigned long umin; /* minimum udiv */
444 unsigned short diff; /* smallest diff */
445 unsigned long udiv; /* best udiv */
446 unsigned short idiff; /* current diff */
447 unsigned short ibdiv; /* current bdiv */
448 unsigned long i;
449 unsigned long est; /* current estimate */
450 unsigned long plloutb;
Stefan Roese273db7e2007-08-13 09:05:33 +0200451 unsigned long cpr_pllc;
Stefan Roesee01bd212007-03-21 13:38:59 +0100452 u32 reg;
453
Stefan Roese273db7e2007-08-13 09:05:33 +0200454 /* check the pll feedback source */
455 mfcpr(cprpllc, cpr_pllc);
456
Stefan Roesee01bd212007-03-21 13:38:59 +0100457 get_sys_info(&sysinfo);
458
Stefan Roese429d9572007-08-14 15:03:17 +0200459 plloutb = ((CONFIG_SYS_CLK_FREQ * ((cpr_pllc & PLLC_SRC_MASK) ?
460 sysinfo.pllFwdDivB : sysinfo.pllFwdDiv) * sysinfo.pllFbkDiv) /
Stefan Roese273db7e2007-08-13 09:05:33 +0200461 sysinfo.pllFwdDivB);
Stefan Roesee01bd212007-03-21 13:38:59 +0100462 udiv = 256; /* Assume lowest possible serial clk */
463 div = plloutb / (16 * baudrate); /* total divisor */
464 umin = (plloutb / get_OPB_freq()) << 1; /* 2 x OPB divisor */
465 diff = 256; /* highest possible */
466
467 /* i is the test udiv value -- start with the largest
468 * possible (256) to minimize serial clock and constrain
469 * search to umin.
470 */
471 for (i = 256; i > umin; i--) {
472 ibdiv = div / i;
473 est = i * ibdiv;
474 idiff = (est > div) ? (est-div) : (div-est);
475 if (idiff == 0) {
476 udiv = i;
477 break; /* can't do better */
478 } else if (idiff < diff) {
479 udiv = i; /* best so far */
480 diff = idiff; /* update lowest diff*/
481 }
482 }
483
484 *pudiv = udiv;
485 mfcpr(cprperd0, reg);
486 reg &= ~0x0000ffff;
487 reg |= ((udiv - 0) << 8) | (udiv - 0);
488 mtcpr(cprperd0, reg);
489 *pbdiv = div / udiv;
wdenkfe8c2802002-11-03 00:38:21 +0000490}
Stefan Roese887e2ec2006-09-07 11:51:23 +0200491#endif /* defined(CONFIG_440) && !defined(CFG_EXT_SERIAL_CLK) */
wdenkfe8c2802002-11-03 00:38:21 +0000492
wdenkfe8c2802002-11-03 00:38:21 +0000493/*
494 * Minimal serial functions needed to use one of the SMC ports
495 * as serial console interface.
496 */
497
498#if defined(CONFIG_440)
wdenkff36fd82005-01-09 22:28:56 +0000499#if defined(CONFIG_SERIAL_MULTI)
500int serial_init_dev (unsigned long dev_base)
501#else
502int serial_init(void)
503#endif
wdenkfe8c2802002-11-03 00:38:21 +0000504{
wdenkfe8c2802002-11-03 00:38:21 +0000505 unsigned long reg;
506 unsigned long udiv;
507 unsigned short bdiv;
508 volatile char val;
509#ifdef CFG_EXT_SERIAL_CLOCK
510 unsigned long tmp;
511#endif
512
Stefan Roese887e2ec2006-09-07 11:51:23 +0200513 MFREG(UART0_SDR, reg);
wdenkba56f622004-02-06 23:19:44 +0000514 reg &= ~CR0_MASK;
Stefan Roese887e2ec2006-09-07 11:51:23 +0200515
wdenkfe8c2802002-11-03 00:38:21 +0000516#ifdef CFG_EXT_SERIAL_CLOCK
517 reg |= CR0_EXTCLK_ENA;
518 udiv = 1;
519 tmp = gd->baudrate * 16;
520 bdiv = (CFG_EXT_SERIAL_CLOCK + tmp / 2) / tmp;
521#else
522 /* For 440, the cpu clock is on divider chain A, UART on divider
523 * chain B ... so cpu clock is irrelevant. Get the "optimized"
524 * values that are subject to the 1/2 opb clock constraint
525 */
526 serial_divs (gd->baudrate, &udiv, &bdiv);
527#endif
528
Stefan Roese887e2ec2006-09-07 11:51:23 +0200529 reg |= (udiv - UDIV_SUBTRACT) << CR0_UDIV_POS; /* set the UART divisor */
530
531 /*
532 * Configure input clock to baudrate generator for all
533 * available serial ports here
534 */
535 MTREG(UART0_SDR, reg);
536#if defined(UART1_SDR)
537 MTREG(UART1_SDR, reg);
wdenkff36fd82005-01-09 22:28:56 +0000538#endif
Stefan Roese887e2ec2006-09-07 11:51:23 +0200539#if defined(UART2_SDR)
540 MTREG(UART2_SDR, reg);
541#endif
542#if defined(UART3_SDR)
543 MTREG(UART3_SDR, reg);
wdenkba56f622004-02-06 23:19:44 +0000544#endif
wdenkff36fd82005-01-09 22:28:56 +0000545
Stefan Roese887e2ec2006-09-07 11:51:23 +0200546 out8(UART_BASE + UART_LCR, 0x80); /* set DLAB bit */
547 out8(UART_BASE + UART_DLL, bdiv); /* set baudrate divisor */
548 out8(UART_BASE + UART_DLM, bdiv >> 8); /* set baudrate divisor */
549 out8(UART_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
550 out8(UART_BASE + UART_FCR, 0x00); /* disable FIFO */
551 out8(UART_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
552 val = in8(UART_BASE + UART_LSR); /* clear line status */
553 val = in8(UART_BASE + UART_RBR); /* read receive buffer */
554 out8(UART_BASE + UART_SCR, 0x00); /* set scratchpad */
555 out8(UART_BASE + UART_IER, 0x00); /* set interrupt enable reg */
556
wdenkfe8c2802002-11-03 00:38:21 +0000557 return (0);
558}
559
560#else /* !defined(CONFIG_440) */
561
wdenkff36fd82005-01-09 22:28:56 +0000562#if defined(CONFIG_SERIAL_MULTI)
563int serial_init_dev (unsigned long dev_base)
564#else
wdenkfe8c2802002-11-03 00:38:21 +0000565int serial_init (void)
wdenkff36fd82005-01-09 22:28:56 +0000566#endif
wdenkfe8c2802002-11-03 00:38:21 +0000567{
wdenkfe8c2802002-11-03 00:38:21 +0000568 unsigned long reg;
569 unsigned long tmp;
570 unsigned long clk;
571 unsigned long udiv;
572 unsigned short bdiv;
573 volatile char val;
574
Stefan Roesee01bd212007-03-21 13:38:59 +0100575#if defined(CONFIG_405EZ)
576 serial_divs(gd->baudrate, &udiv, &bdiv);
577 clk = tmp = reg = 0;
578#else
stroese8749cfb2003-05-23 11:25:57 +0000579#ifdef CONFIG_405EP
580 reg = mfdcr(cpc0_ucr) & ~(UCR0_MASK | UCR1_MASK);
581 clk = gd->cpu_clk;
582 tmp = CFG_BASE_BAUD * 16;
583 udiv = (clk + tmp / 2) / tmp;
584 if (udiv > UDIV_MAX) /* max. n bits for udiv */
585 udiv = UDIV_MAX;
586 reg |= (udiv) << UCR0_UDIV_POS; /* set the UART divisor */
587 reg |= (udiv) << UCR1_UDIV_POS; /* set the UART divisor */
588 mtdcr (cpc0_ucr, reg);
589#else /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000590 reg = mfdcr(cntrl0) & ~CR0_MASK;
591#ifdef CFG_EXT_SERIAL_CLOCK
592 clk = CFG_EXT_SERIAL_CLOCK;
593 udiv = 1;
594 reg |= CR0_EXTCLK_ENA;
595#else
596 clk = gd->cpu_clk;
597#ifdef CFG_405_UART_ERRATA_59
598 udiv = 31; /* Errata 59: stuck at 31 */
599#else
600 tmp = CFG_BASE_BAUD * 16;
601 udiv = (clk + tmp / 2) / tmp;
stroese8749cfb2003-05-23 11:25:57 +0000602 if (udiv > UDIV_MAX) /* max. n bits for udiv */
603 udiv = UDIV_MAX;
wdenkfe8c2802002-11-03 00:38:21 +0000604#endif
605#endif
wdenkfe8c2802002-11-03 00:38:21 +0000606 reg |= (udiv - 1) << CR0_UDIV_POS; /* set the UART divisor */
607 mtdcr (cntrl0, reg);
stroese8749cfb2003-05-23 11:25:57 +0000608#endif /* CONFIG_405EP */
wdenkfe8c2802002-11-03 00:38:21 +0000609 tmp = gd->baudrate * udiv * 16;
610 bdiv = (clk + tmp / 2) / tmp;
Stefan Roesee01bd212007-03-21 13:38:59 +0100611#endif /* CONFIG_405EZ */
wdenkfe8c2802002-11-03 00:38:21 +0000612
Stefan Roese887e2ec2006-09-07 11:51:23 +0200613 out8(UART_BASE + UART_LCR, 0x80); /* set DLAB bit */
614 out8(UART_BASE + UART_DLL, bdiv); /* set baudrate divisor */
615 out8(UART_BASE + UART_DLM, bdiv >> 8); /* set baudrate divisor */
616 out8(UART_BASE + UART_LCR, 0x03); /* clear DLAB; set 8 bits, no parity */
617 out8(UART_BASE + UART_FCR, 0x00); /* disable FIFO */
618 out8(UART_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
619 val = in8(UART_BASE + UART_LSR); /* clear line status */
620 val = in8(UART_BASE + UART_RBR); /* read receive buffer */
621 out8(UART_BASE + UART_SCR, 0x00); /* set scratchpad */
622 out8(UART_BASE + UART_IER, 0x00); /* set interrupt enable reg */
623
wdenkfe8c2802002-11-03 00:38:21 +0000624 return (0);
625}
626
627#endif /* if defined(CONFIG_440) */
628
wdenkff36fd82005-01-09 22:28:56 +0000629#if defined(CONFIG_SERIAL_MULTI)
630void serial_setbrg_dev (unsigned long dev_base)
631#else
wdenkfe8c2802002-11-03 00:38:21 +0000632void serial_setbrg (void)
wdenkff36fd82005-01-09 22:28:56 +0000633#endif
wdenkfe8c2802002-11-03 00:38:21 +0000634{
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200635#if defined(CONFIG_SERIAL_MULTI)
Stefan Roese887e2ec2006-09-07 11:51:23 +0200636 serial_init_dev(dev_base);
Marian Balakowicz6c5879f2006-06-30 16:30:46 +0200637#else
Stefan Roese887e2ec2006-09-07 11:51:23 +0200638 serial_init();
wdenkff36fd82005-01-09 22:28:56 +0000639#endif
wdenkfe8c2802002-11-03 00:38:21 +0000640}
641
wdenkff36fd82005-01-09 22:28:56 +0000642#if defined(CONFIG_SERIAL_MULTI)
643void serial_putc_dev (unsigned long dev_base, const char c)
644#else
wdenkfe8c2802002-11-03 00:38:21 +0000645void serial_putc (const char c)
wdenkff36fd82005-01-09 22:28:56 +0000646#endif
wdenkfe8c2802002-11-03 00:38:21 +0000647{
648 int i;
649
650 if (c == '\n')
wdenkff36fd82005-01-09 22:28:56 +0000651#if defined(CONFIG_SERIAL_MULTI)
652 serial_putc_dev (dev_base, '\r');
653#else
wdenkfe8c2802002-11-03 00:38:21 +0000654 serial_putc ('\r');
wdenkff36fd82005-01-09 22:28:56 +0000655#endif
wdenkfe8c2802002-11-03 00:38:21 +0000656
657 /* check THRE bit, wait for transmiter available */
658 for (i = 1; i < 3500; i++) {
Stefan Roese887e2ec2006-09-07 11:51:23 +0200659 if ((in8 (UART_BASE + UART_LSR) & 0x20) == 0x20)
wdenkfe8c2802002-11-03 00:38:21 +0000660 break;
661 udelay (100);
662 }
Stefan Roese887e2ec2006-09-07 11:51:23 +0200663 out8 (UART_BASE + UART_THR, c); /* put character out */
wdenkfe8c2802002-11-03 00:38:21 +0000664}
665
wdenkff36fd82005-01-09 22:28:56 +0000666#if defined(CONFIG_SERIAL_MULTI)
667void serial_puts_dev (unsigned long dev_base, const char *s)
668#else
wdenkfe8c2802002-11-03 00:38:21 +0000669void serial_puts (const char *s)
wdenkff36fd82005-01-09 22:28:56 +0000670#endif
wdenkfe8c2802002-11-03 00:38:21 +0000671{
672 while (*s) {
wdenkff36fd82005-01-09 22:28:56 +0000673#if defined(CONFIG_SERIAL_MULTI)
674 serial_putc_dev (dev_base, *s++);
675#else
wdenkfe8c2802002-11-03 00:38:21 +0000676 serial_putc (*s++);
wdenkff36fd82005-01-09 22:28:56 +0000677#endif
wdenkfe8c2802002-11-03 00:38:21 +0000678 }
679}
680
wdenkff36fd82005-01-09 22:28:56 +0000681#if defined(CONFIG_SERIAL_MULTI)
682int serial_getc_dev (unsigned long dev_base)
683#else
684int serial_getc (void)
685#endif
wdenkfe8c2802002-11-03 00:38:21 +0000686{
687 unsigned char status = 0;
688
689 while (1) {
690#if defined(CONFIG_HW_WATCHDOG)
691 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
692#endif /* CONFIG_HW_WATCHDOG */
Stefan Roese887e2ec2006-09-07 11:51:23 +0200693 status = in8 (UART_BASE + UART_LSR);
wdenkfe8c2802002-11-03 00:38:21 +0000694 if ((status & asyncLSRDataReady1) != 0x0) {
695 break;
696 }
697 if ((status & ( asyncLSRFramingError1 |
698 asyncLSROverrunError1 |
699 asyncLSRParityError1 |
700 asyncLSRBreakInterrupt1 )) != 0) {
Stefan Roese887e2ec2006-09-07 11:51:23 +0200701 out8 (UART_BASE + UART_LSR,
wdenkfe8c2802002-11-03 00:38:21 +0000702 asyncLSRFramingError1 |
703 asyncLSROverrunError1 |
704 asyncLSRParityError1 |
705 asyncLSRBreakInterrupt1);
706 }
707 }
Stefan Roese887e2ec2006-09-07 11:51:23 +0200708 return (0x000000ff & (int) in8 (UART_BASE));
wdenkfe8c2802002-11-03 00:38:21 +0000709}
710
wdenkff36fd82005-01-09 22:28:56 +0000711#if defined(CONFIG_SERIAL_MULTI)
712int serial_tstc_dev (unsigned long dev_base)
713#else
714int serial_tstc (void)
715#endif
wdenkfe8c2802002-11-03 00:38:21 +0000716{
717 unsigned char status;
718
Stefan Roese887e2ec2006-09-07 11:51:23 +0200719 status = in8 (UART_BASE + UART_LSR);
wdenkfe8c2802002-11-03 00:38:21 +0000720 if ((status & asyncLSRDataReady1) != 0x0) {
721 return (1);
722 }
723 if ((status & ( asyncLSRFramingError1 |
724 asyncLSROverrunError1 |
725 asyncLSRParityError1 |
726 asyncLSRBreakInterrupt1 )) != 0) {
Stefan Roese887e2ec2006-09-07 11:51:23 +0200727 out8 (UART_BASE + UART_LSR,
wdenkfe8c2802002-11-03 00:38:21 +0000728 asyncLSRFramingError1 |
729 asyncLSROverrunError1 |
730 asyncLSRParityError1 |
731 asyncLSRBreakInterrupt1);
732 }
733 return 0;
734}
735
wdenk42dfe7a2004-03-14 22:25:36 +0000736#ifdef CONFIG_SERIAL_SOFTWARE_FIFO
wdenkfe8c2802002-11-03 00:38:21 +0000737
738void serial_isr (void *arg)
739{
740 int space;
741 int c;
742 const int rx_get = buf_info.rx_get;
743 int rx_put = buf_info.rx_put;
744
745 if (rx_get <= rx_put) {
746 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
747 } else {
748 space = rx_get - rx_put;
749 }
wdenkff36fd82005-01-09 22:28:56 +0000750 while (serial_tstc_dev (ACTING_UART0_BASE)) {
751 c = serial_getc_dev (ACTING_UART0_BASE);
wdenkfe8c2802002-11-03 00:38:21 +0000752 if (space) {
753 buf_info.rx_buffer[rx_put++] = c;
754 space--;
755 }
756 if (rx_put == CONFIG_SERIAL_SOFTWARE_FIFO)
757 rx_put = 0;
758 if (space < CONFIG_SERIAL_SOFTWARE_FIFO / 4) {
759 /* Stop flow by setting RTS inactive */
stroese8749cfb2003-05-23 11:25:57 +0000760 out8 (ACTING_UART0_BASE + UART_MCR,
761 in8 (ACTING_UART0_BASE + UART_MCR) & (0xFF ^ 0x02));
wdenkfe8c2802002-11-03 00:38:21 +0000762 }
763 }
764 buf_info.rx_put = rx_put;
765}
766
767void serial_buffered_init (void)
768{
769 serial_puts ("Switching to interrupt driven serial input mode.\n");
770 buf_info.rx_buffer = malloc (CONFIG_SERIAL_SOFTWARE_FIFO);
771 buf_info.rx_put = 0;
772 buf_info.rx_get = 0;
773
stroese8749cfb2003-05-23 11:25:57 +0000774 if (in8 (ACTING_UART0_BASE + UART_MSR) & 0x10) {
wdenkfe8c2802002-11-03 00:38:21 +0000775 serial_puts ("Check CTS signal present on serial port: OK.\n");
776 } else {
777 serial_puts ("WARNING: CTS signal not present on serial port.\n");
778 }
779
780 irq_install_handler ( VECNUM_U0 /*UART0 */ /*int vec */ ,
781 serial_isr /*interrupt_handler_t *handler */ ,
782 (void *) &buf_info /*void *arg */ );
783
784 /* Enable "RX Data Available" Interrupt on UART */
stroese8749cfb2003-05-23 11:25:57 +0000785 /* out8(ACTING_UART0_BASE + UART_IER, in8(ACTING_UART0_BASE + UART_IER) |0x01); */
786 out8 (ACTING_UART0_BASE + UART_IER, 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000787 /* Set DTR active */
stroese8749cfb2003-05-23 11:25:57 +0000788 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x01);
wdenkfe8c2802002-11-03 00:38:21 +0000789 /* Start flow by setting RTS active */
stroese8749cfb2003-05-23 11:25:57 +0000790 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000791 /* Setup UART FIFO: RX trigger level: 4 byte, Enable FIFO */
stroese8749cfb2003-05-23 11:25:57 +0000792 out8 (ACTING_UART0_BASE + UART_FCR, (1 << 6) | 1);
wdenkfe8c2802002-11-03 00:38:21 +0000793}
794
795void serial_buffered_putc (const char c)
796{
797 /* Wait for CTS */
798#if defined(CONFIG_HW_WATCHDOG)
stroese8749cfb2003-05-23 11:25:57 +0000799 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10))
wdenkfe8c2802002-11-03 00:38:21 +0000800 WATCHDOG_RESET ();
801#else
stroese8749cfb2003-05-23 11:25:57 +0000802 while (!(in8 (ACTING_UART0_BASE + UART_MSR) & 0x10));
wdenkfe8c2802002-11-03 00:38:21 +0000803#endif
804 serial_putc (c);
805}
806
807void serial_buffered_puts (const char *s)
808{
809 serial_puts (s);
810}
811
812int serial_buffered_getc (void)
813{
814 int space;
815 int c;
816 int rx_get = buf_info.rx_get;
817 int rx_put;
818
819#if defined(CONFIG_HW_WATCHDOG)
820 while (rx_get == buf_info.rx_put)
821 WATCHDOG_RESET ();
822#else
823 while (rx_get == buf_info.rx_put);
824#endif
825 c = buf_info.rx_buffer[rx_get++];
826 if (rx_get == CONFIG_SERIAL_SOFTWARE_FIFO)
827 rx_get = 0;
828 buf_info.rx_get = rx_get;
829
830 rx_put = buf_info.rx_put;
831 if (rx_get <= rx_put) {
832 space = CONFIG_SERIAL_SOFTWARE_FIFO - (rx_put - rx_get);
833 } else {
834 space = rx_get - rx_put;
835 }
836 if (space > CONFIG_SERIAL_SOFTWARE_FIFO / 2) {
837 /* Start flow by setting RTS active */
stroese8749cfb2003-05-23 11:25:57 +0000838 out8 (ACTING_UART0_BASE + UART_MCR, in8 (ACTING_UART0_BASE + UART_MCR) | 0x02);
wdenkfe8c2802002-11-03 00:38:21 +0000839 }
840
841 return c;
842}
843
844int serial_buffered_tstc (void)
845{
846 return (buf_info.rx_get != buf_info.rx_put) ? 1 : 0;
847}
848
849#endif /* CONFIG_SERIAL_SOFTWARE_FIFO */
850
wdenkfe8c2802002-11-03 00:38:21 +0000851#if (CONFIG_COMMANDS & CFG_CMD_KGDB)
852/*
853 AS HARNOIS : according to CONFIG_KGDB_SER_INDEX kgdb uses serial port
854 number 0 or number 1
855 - if CONFIG_KGDB_SER_INDEX = 1 => serial port number 0 :
856 configuration has been already done
857 - if CONFIG_KGDB_SER_INDEX = 2 => serial port number 1 :
858 configure port 1 for serial I/O with rate = CONFIG_KGDB_BAUDRATE
859*/
860#if (CONFIG_KGDB_SER_INDEX & 2)
861void kgdb_serial_init (void)
862{
wdenkfe8c2802002-11-03 00:38:21 +0000863 volatile char val;
864 unsigned short br_reg;
865
866 get_clocks ();
867 br_reg = (((((gd->cpu_clk / 16) / 18) * 10) / CONFIG_KGDB_BAUDRATE) +
868 5) / 10;
869 /*
870 * Init onboard 16550 UART
871 */
stroese8749cfb2003-05-23 11:25:57 +0000872 out8 (ACTING_UART1_BASE + UART_LCR, 0x80); /* set DLAB bit */
873 out8 (ACTING_UART1_BASE + UART_DLL, (br_reg & 0x00ff)); /* set divisor for 9600 baud */
874 out8 (ACTING_UART1_BASE + UART_DLM, ((br_reg & 0xff00) >> 8)); /* set divisor for 9600 baud */
875 out8 (ACTING_UART1_BASE + UART_LCR, 0x03); /* line control 8 bits no parity */
876 out8 (ACTING_UART1_BASE + UART_FCR, 0x00); /* disable FIFO */
877 out8 (ACTING_UART1_BASE + UART_MCR, 0x00); /* no modem control DTR RTS */
878 val = in8 (ACTING_UART1_BASE + UART_LSR); /* clear line status */
879 val = in8 (ACTING_UART1_BASE + UART_RBR); /* read receive buffer */
880 out8 (ACTING_UART1_BASE + UART_SCR, 0x00); /* set scratchpad */
881 out8 (ACTING_UART1_BASE + UART_IER, 0x00); /* set interrupt enable reg */
wdenkfe8c2802002-11-03 00:38:21 +0000882}
883
wdenkfe8c2802002-11-03 00:38:21 +0000884void putDebugChar (const char c)
885{
886 if (c == '\n')
887 serial_putc ('\r');
888
stroese8749cfb2003-05-23 11:25:57 +0000889 out8 (ACTING_UART1_BASE + UART_THR, c); /* put character out */
wdenkfe8c2802002-11-03 00:38:21 +0000890
891 /* check THRE bit, wait for transfer done */
stroese8749cfb2003-05-23 11:25:57 +0000892 while ((in8 (ACTING_UART1_BASE + UART_LSR) & 0x20) != 0x20);
wdenkfe8c2802002-11-03 00:38:21 +0000893}
894
wdenkfe8c2802002-11-03 00:38:21 +0000895void putDebugStr (const char *s)
896{
897 while (*s) {
898 serial_putc (*s++);
899 }
900}
901
wdenkfe8c2802002-11-03 00:38:21 +0000902int getDebugChar (void)
903{
904 unsigned char status = 0;
905
906 while (1) {
stroese8749cfb2003-05-23 11:25:57 +0000907 status = in8 (ACTING_UART1_BASE + UART_LSR);
wdenkfe8c2802002-11-03 00:38:21 +0000908 if ((status & asyncLSRDataReady1) != 0x0) {
909 break;
910 }
911 if ((status & ( asyncLSRFramingError1 |
912 asyncLSROverrunError1 |
913 asyncLSRParityError1 |
914 asyncLSRBreakInterrupt1 )) != 0) {
stroese8749cfb2003-05-23 11:25:57 +0000915 out8 (ACTING_UART1_BASE + UART_LSR,
wdenkfe8c2802002-11-03 00:38:21 +0000916 asyncLSRFramingError1 |
917 asyncLSROverrunError1 |
918 asyncLSRParityError1 |
919 asyncLSRBreakInterrupt1);
920 }
921 }
stroese8749cfb2003-05-23 11:25:57 +0000922 return (0x000000ff & (int) in8 (ACTING_UART1_BASE));
wdenkfe8c2802002-11-03 00:38:21 +0000923}
924
wdenkfe8c2802002-11-03 00:38:21 +0000925void kgdb_interruptible (int yes)
926{
927 return;
928}
929
930#else /* ! (CONFIG_KGDB_SER_INDEX & 2) */
931
932void kgdb_serial_init (void)
933{
934 serial_printf ("[on serial] ");
935}
936
937void putDebugChar (int c)
938{
939 serial_putc (c);
940}
941
942void putDebugStr (const char *str)
943{
944 serial_puts (str);
945}
946
947int getDebugChar (void)
948{
949 return serial_getc ();
950}
951
952void kgdb_interruptible (int yes)
953{
954 return;
955}
956#endif /* (CONFIG_KGDB_SER_INDEX & 2) */
957#endif /* CFG_CMD_KGDB */
958
wdenkff36fd82005-01-09 22:28:56 +0000959
960#if defined(CONFIG_SERIAL_MULTI)
961int serial0_init(void)
962{
963 return (serial_init_dev(UART0_BASE));
964}
965
966int serial1_init(void)
967{
968 return (serial_init_dev(UART1_BASE));
969}
970void serial0_setbrg (void)
971{
972 serial_setbrg_dev(UART0_BASE);
973}
974void serial1_setbrg (void)
975{
976 serial_setbrg_dev(UART1_BASE);
977}
978
979void serial0_putc(const char c)
980{
981 serial_putc_dev(UART0_BASE,c);
982}
983
984void serial1_putc(const char c)
985{
986 serial_putc_dev(UART1_BASE, c);
987}
988void serial0_puts(const char *s)
989{
990 serial_puts_dev(UART0_BASE, s);
991}
992
993void serial1_puts(const char *s)
994{
995 serial_puts_dev(UART1_BASE, s);
996}
997
998int serial0_getc(void)
999{
1000 return(serial_getc_dev(UART0_BASE));
1001}
1002
1003int serial1_getc(void)
1004{
1005 return(serial_getc_dev(UART1_BASE));
1006}
1007int serial0_tstc(void)
1008{
1009 return (serial_tstc_dev(UART0_BASE));
1010}
1011
1012int serial1_tstc(void)
1013{
1014 return (serial_tstc_dev(UART1_BASE));
1015}
1016
1017struct serial_device serial0_device =
1018{
1019 "serial0",
1020 "UART0",
1021 serial0_init,
1022 serial0_setbrg,
1023 serial0_getc,
1024 serial0_tstc,
1025 serial0_putc,
1026 serial0_puts,
1027};
1028
1029struct serial_device serial1_device =
1030{
1031 "serial1",
1032 "UART1",
1033 serial1_init,
1034 serial1_setbrg,
1035 serial1_getc,
1036 serial1_tstc,
1037 serial1_putc,
1038 serial1_puts,
1039};
1040#endif /* CONFIG_SERIAL_MULTI */
1041
wdenkfe8c2802002-11-03 00:38:21 +00001042#endif /* CONFIG_405GP || CONFIG_405CR */