blob: 08f449c8642481197971af17d3f6913c3e1d2de9 [file] [log] [blame]
wdenkf8cac652002-08-26 22:36:39 +00001/*
2 * (C) Copyright 2000
3 * Rob Taylor, Flying Pig Systems. robt@flyingpig.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#include <common.h>
Marek Vasutc45a14a2012-09-13 12:28:07 +020025#include <serial.h>
26#include <linux/compiler.h>
27
wdenkf8cac652002-08-26 22:36:39 +000028#include "ns16550.h"
29
Wolfgang Denkd87080b2006-03-31 18:32:53 +020030DECLARE_GLOBAL_DATA_PTR;
31
wdenkf8cac652002-08-26 22:36:39 +000032#if CONFIG_CONS_INDEX == 1
33static struct NS16550 *console =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020034 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
wdenkf8cac652002-08-26 22:36:39 +000035#elif CONFIG_CONS_INDEX == 2
36static struct NS16550 *console =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020037 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
wdenkf8cac652002-08-26 22:36:39 +000038#else
39#error no valid console defined
40#endif
41
42extern ulong get_bus_freq (ulong);
43
Marek Vasutc45a14a2012-09-13 12:28:07 +020044static int bmw_serial_init(void)
wdenkf8cac652002-08-26 22:36:39 +000045{
wdenkf8cac652002-08-26 22:36:39 +000046 int clock_divisor = gd->bus_clk / 16 / gd->baudrate;
47
48 NS16550_init (CONFIG_CONS_INDEX - 1, clock_divisor);
49
50 return (0);
51}
52
Marek Vasutc45a14a2012-09-13 12:28:07 +020053static void bmw_serial_putc(const char c)
wdenkf8cac652002-08-26 22:36:39 +000054{
55 if (c == '\n') {
56 serial_putc ('\r');
57 }
58 NS16550_putc (console, c);
59}
60
Marek Vasutc45a14a2012-09-13 12:28:07 +020061static void bmw_serial_puts(const char *s)
wdenkf8cac652002-08-26 22:36:39 +000062{
63 while (*s) {
64 serial_putc (*s++);
65 }
66}
67
68
Marek Vasutc45a14a2012-09-13 12:28:07 +020069static int bmw_serial_getc(void)
wdenkf8cac652002-08-26 22:36:39 +000070{
71 return NS16550_getc (console);
72}
73
Marek Vasutc45a14a2012-09-13 12:28:07 +020074static int bmw_serial_tstc(void)
wdenkf8cac652002-08-26 22:36:39 +000075{
76 return NS16550_tstc (console);
77}
78
Marek Vasutc45a14a2012-09-13 12:28:07 +020079static void bmw_serial_setbrg(void)
wdenkf8cac652002-08-26 22:36:39 +000080{
wdenkf8cac652002-08-26 22:36:39 +000081 int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;
82
83 NS16550_reinit (console, clock_divisor);
84}
Marek Vasutc45a14a2012-09-13 12:28:07 +020085
Marek Vasutc45a14a2012-09-13 12:28:07 +020086static struct serial_device bmw_serial_drv = {
87 .name = "bmw_serial",
88 .start = bmw_serial_init,
89 .stop = NULL,
90 .setbrg = bmw_serial_setbrg,
91 .putc = bmw_serial_putc,
92 .puts = bmw_serial_puts,
93 .getc = bmw_serial_getc,
94 .tstc = bmw_serial_tstc,
95};
96
97void bmw_serial_initialize(void)
98{
99 serial_register(&bmw_serial_drv);
100}
101
102__weak struct serial_device *default_serial_console(void)
103{
104 return &bmw_serial_drv;
105}