]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/bmw/serial.c
am33xx/ddr_defs.h: rename DDR2/DDR3 defines to their actual part numbers
[karo-tx-uboot.git] / board / bmw / serial.c
1 /*
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>
25 #include <serial.h>
26 #include <linux/compiler.h>
27
28 #include "ns16550.h"
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 #if CONFIG_CONS_INDEX == 1
33 static struct NS16550 *console =
34                 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
35 #elif CONFIG_CONS_INDEX == 2
36 static struct NS16550 *console =
37                 (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500);
38 #else
39 #error no valid console defined
40 #endif
41
42 extern ulong get_bus_freq (ulong);
43
44 static int bmw_serial_init(void)
45 {
46         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
53 static void bmw_serial_putc(const char c)
54 {
55         if (c == '\n') {
56                 serial_putc ('\r');
57         }
58         NS16550_putc (console, c);
59 }
60
61 static void bmw_serial_puts(const char *s)
62 {
63         while (*s) {
64                 serial_putc (*s++);
65         }
66 }
67
68
69 static int bmw_serial_getc(void)
70 {
71         return NS16550_getc (console);
72 }
73
74 static int bmw_serial_tstc(void)
75 {
76         return NS16550_tstc (console);
77 }
78
79 static void bmw_serial_setbrg(void)
80 {
81         int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;
82
83         NS16550_reinit (console, clock_divisor);
84 }
85
86 static 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
97 void 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 }