wdenk | 78f6622 | 2002-08-27 10:27:51 +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> |
| 25 | |
| 26 | #ifdef CFG_NS16550_SERIAL |
| 27 | |
| 28 | #include <ns16550.h> |
| 29 | #ifdef CFG_NS87308 |
| 30 | #include <ns87308.h> |
| 31 | #endif |
| 32 | |
| 33 | #if CONFIG_CONS_INDEX == 1 |
| 34 | static NS16550_t console = (NS16550_t) CFG_NS16550_COM1; |
| 35 | #elif CONFIG_CONS_INDEX == 2 |
| 36 | static NS16550_t console = (NS16550_t) CFG_NS16550_COM2; |
| 37 | #elif CONFIG_CONS_INDEX == 3 |
| 38 | static NS16550_t console = (NS16550_t) CFG_NS16550_COM3; |
| 39 | #elif CONFIG_CONS_INDEX == 4 |
| 40 | static NS16550_t console = (NS16550_t) CFG_NS16550_COM4; |
| 41 | #else |
| 42 | #error no valid console defined |
| 43 | #endif |
| 44 | |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 45 | static int calc_divisor (void) |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 46 | { |
| 47 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_OMAP1510 |
| 49 | /* If can't cleanly clock 115200 set div to 1 */ |
| 50 | if ((CFG_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { |
| 51 | console->osc_12m_sel = OSC_12M_SEL; /* enable 6.5 * divisor */ |
| 52 | return (1); /* return 1 for base divisor */ |
| 53 | } |
wdenk | 2535d60 | 2003-07-17 23:16:40 +0000 | [diff] [blame] | 54 | console->osc_12m_sel = 0; /* clear if previsouly set */ |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 55 | #endif |
wdenk | 6f21347 | 2003-08-29 22:00:43 +0000 | [diff] [blame] | 56 | #ifdef CONFIG_OMAP1610 |
| 57 | /* If can't cleanly clock 115200 set div to 1 */ |
| 58 | if ((CFG_NS16550_CLK == 48000000) && (gd->baudrate == 115200)) { |
| 59 | return (26); /* return 26 for base divisor */ |
| 60 | } |
| 61 | #endif |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame^] | 62 | |
| 63 | #ifdef CONFIG_APTIX |
| 64 | #define MODE_X_DIV 13 |
| 65 | #else |
| 66 | #define MODE_X_DIV 16 |
| 67 | #endif |
| 68 | return (CFG_NS16550_CLK / MODE_X_DIV / gd->baudrate); |
| 69 | |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 70 | } |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 71 | |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 72 | int serial_init (void) |
| 73 | { |
| 74 | int clock_divisor = calc_divisor(); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 75 | |
| 76 | #ifdef CFG_NS87308 |
| 77 | initialise_ns87308(); |
| 78 | #endif |
| 79 | |
| 80 | NS16550_init(console, clock_divisor); |
| 81 | |
| 82 | return (0); |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | serial_putc(const char c) |
| 87 | { |
| 88 | if (c == '\n') |
| 89 | NS16550_putc(console, '\r'); |
| 90 | |
| 91 | NS16550_putc(console, c); |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | serial_puts (const char *s) |
| 96 | { |
| 97 | while (*s) { |
| 98 | serial_putc (*s++); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | |
| 103 | int |
| 104 | serial_getc(void) |
| 105 | { |
| 106 | return NS16550_getc(console); |
| 107 | } |
| 108 | |
| 109 | int |
| 110 | serial_tstc(void) |
| 111 | { |
| 112 | return NS16550_tstc(console); |
| 113 | } |
| 114 | |
| 115 | void |
| 116 | serial_setbrg (void) |
| 117 | { |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 118 | int clock_divisor; |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 119 | |
wdenk | 2e5983d | 2003-07-15 20:04:06 +0000 | [diff] [blame] | 120 | clock_divisor = calc_divisor(); |
wdenk | 78f6622 | 2002-08-27 10:27:51 +0000 | [diff] [blame] | 121 | NS16550_reinit(console, clock_divisor); |
| 122 | } |
| 123 | |
| 124 | #endif |