blob: f17e06e4ea34cbe10d1f71100d2241d852535861 [file] [log] [blame]
wdenk337f5652004-10-28 00:09:35 +00001/*
2 * (C) Copyright 2004, Freescale, Inc
3 * TsiChung Liew, Tsi-Chung.Liew@freescale.com.
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/*
26 * Minimal serial functions needed to use one of the PSC ports
27 * as serial console interface.
28 */
29
30#include <common.h>
31#include <mpc8220.h>
32
33#if defined (CONFIG_EXTUART_CONSOLE)
34# include <ns16550.h>
35
36# define PADSERIAL_BAUD_115200 0x40
37# define PADSERIAL_BAUD_57600 0x20
38# define PADSERIAL_BAUD_9600 0
39# define PADCARD_FREQ 18432000
40
41const NS16550_t com_port = (NS16550_t) CFG_NS16550_COM1;
42
43int ext_serial_init (void)
44{
45 DECLARE_GLOBAL_DATA_PTR;
46 volatile u8 *dipswitch = (volatile u8 *) (CFG_CPLD_BASE + 0x1002);
47 int baud_divisor;
48
49 /* Find out the baud rate speed on debug card dip switches */
50 if (*dipswitch & PADSERIAL_BAUD_115200)
51 gd->baudrate = 115200;
52 else if (*dipswitch & PADSERIAL_BAUD_57600)
53 gd->baudrate = 57600;
54 else
55 gd->baudrate = 9600;
56
57 /* Debug card frequency */
58 baud_divisor = PADCARD_FREQ / (16 * gd->baudrate);
59
60 NS16550_init (com_port, baud_divisor);
61
62 return (0);
63}
64
65void ext_serial_putc (const char c)
66{
67 if (c == '\n')
68 NS16550_putc (com_port, '\r');
69
70 NS16550_putc (com_port, c);
71}
72
73void ext_serial_puts (const char *s)
74{
75 while (*s) {
76 serial_putc (*s++);
77 }
78}
79
80int ext_serial_getc (void)
81{
82 return NS16550_getc (com_port);
83}
84
85int ext_serial_tstc (void)
86{
87 return NS16550_tstc (com_port);
88}
89
90void ext_serial_setbrg (void)
91{
92 DECLARE_GLOBAL_DATA_PTR;
93
94 volatile u8 *dipswitch = (volatile u8 *) (CFG_CPLD_BASE + 0x1002);
95 int baud_divisor;
96
97 /* Find out the baud rate speed on debug card dip switches */
98 if (*dipswitch & PADSERIAL_BAUD_115200)
99 gd->baudrate = 115200;
100 else if (*dipswitch & PADSERIAL_BAUD_57600)
101 gd->baudrate = 57600;
102 else
103 gd->baudrate = 9600;
104
105 /* Debug card frequency */
106 baud_divisor = PADCARD_FREQ / (16 * gd->baudrate);
107
108 NS16550_reinit (com_port, baud_divisor);
109}
110#endif /* CONFIG_EXTUART_CONSOLE */