wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 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> |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 25 | #include <serial.h> |
| 26 | #include <linux/compiler.h> |
| 27 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 28 | #include "ns16550.h" |
| 29 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 32 | #if CONFIG_CONS_INDEX == 1 |
| 33 | static struct NS16550 *console = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 34 | (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 35 | #elif CONFIG_CONS_INDEX == 2 |
| 36 | static struct NS16550 *console = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | (struct NS16550 *) (CONFIG_SYS_EUMB_ADDR + 0x4500); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 38 | #else |
| 39 | #error no valid console defined |
| 40 | #endif |
| 41 | |
| 42 | extern ulong get_bus_freq (ulong); |
| 43 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 44 | static int bmw_serial_init(void) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 45 | { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 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 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 53 | static void bmw_serial_putc(const char c) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 54 | { |
| 55 | if (c == '\n') { |
| 56 | serial_putc ('\r'); |
| 57 | } |
| 58 | NS16550_putc (console, c); |
| 59 | } |
| 60 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 61 | static void bmw_serial_puts(const char *s) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 62 | { |
| 63 | while (*s) { |
| 64 | serial_putc (*s++); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 69 | static int bmw_serial_getc(void) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 70 | { |
| 71 | return NS16550_getc (console); |
| 72 | } |
| 73 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 74 | static int bmw_serial_tstc(void) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 75 | { |
| 76 | return NS16550_tstc (console); |
| 77 | } |
| 78 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 79 | static void bmw_serial_setbrg(void) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 80 | { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 81 | int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate; |
| 82 | |
| 83 | NS16550_reinit (console, clock_divisor); |
| 84 | } |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 85 | |
Marek Vasut | bf5314b | 2012-09-13 12:28:07 +0200 | [diff] [blame] | 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 | } |