blob: aacd1be630b1800303f1b4cae793bd0bb9b58ef8 [file] [log] [blame]
wdenk3a574cb2005-05-19 22:39:42 +00001/*
2 * serial.c -- KS8695 serial driver
3 *
4 * (C) Copyright 2004, Greg Ungerer <greg.ungerer@opengear.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <common.h>
22#include <asm/arch/platform.h>
23
24#ifndef CONFIG_SERIAL1
25#error "Bad: you didn't configure serial ..."
26#endif
27
Wolfgang Denkd87080b2006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
wdenk3a574cb2005-05-19 22:39:42 +000030/*
31 * Define the UART hardware register access structure.
32 */
33struct ks8695uart {
34 unsigned int RX; /* 0x00 - Receive data (r) */
35 unsigned int TX; /* 0x04 - Transmit data (w) */
36 unsigned int FCR; /* 0x08 - Fifo Control (r/w) */
37 unsigned int LCR; /* 0x0c - Line Control (r/w) */
38 unsigned int MCR; /* 0x10 - Modem Control (r/w) */
39 unsigned int LSR; /* 0x14 - Line Status (r/w) */
40 unsigned int MSR; /* 0x18 - Modem Status (r/w) */
41 unsigned int BD; /* 0x1c - Baud Rate (r/w) */
42 unsigned int SR; /* 0x20 - Status (r/w) */
43};
44
45#define KS8695_UART_ADDR ((void *) (KS8695_IO_BASE + KS8695_UART_RX_BUFFER))
46#define KS8695_UART_CLK 25000000
47
48
49/*
50 * Under some circumstances we want to be "quiet" and not issue any
51 * serial output - though we want u-boot to otherwise work and behave
52 * the same. By default be noisy.
53 */
54int serial_console = 1;
55
56
57void serial_setbrg(void)
58{
wdenk3a574cb2005-05-19 22:39:42 +000059 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
60
61 /* Set to global baud rate and 8 data bits, no parity, 1 stop bit*/
62 uartp->BD = KS8695_UART_CLK / gd->baudrate;
63 uartp->LCR = KS8695_UART_LINEC_WLEN8;
64}
65
66int serial_init(void)
67{
68 serial_console = 1;
69 serial_setbrg();
70 return 0;
71}
72
73void serial_raw_putc(const char c)
74{
75 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
76 int i;
77
78 for (i = 0; (i < 0x100000); i++) {
79 if (uartp->LSR & KS8695_UART_LINES_TXFE)
80 break;
81 }
82
83 uartp->TX = c;
84}
85
86void serial_putc(const char c)
87{
88 if (serial_console) {
89 serial_raw_putc(c);
90 if (c == '\n')
91 serial_raw_putc('\r');
92 }
93}
94
95int serial_tstc(void)
96{
97 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
98 if (serial_console)
99 return ((uartp->LSR & KS8695_UART_LINES_RXFE) ? 1 : 0);
100 return 0;
101}
102
103void serial_puts(const char *s)
104{
105 char c;
106 while ((c = *s++) != 0)
107 serial_putc(c);
108}
109
110int serial_getc(void)
111{
112 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
113
114 while ((uartp->LSR & KS8695_UART_LINES_RXFE) == 0)
115 ;
116 return (uartp->RX);
117}