2 * serial.c -- KS8695 serial driver
4 * (C) Copyright 2004, Greg Ungerer <greg.ungerer@opengear.com>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/platform.h>
12 #include <linux/compiler.h>
14 #ifndef CONFIG_SERIAL1
15 #error "Bad: you didn't configure serial ..."
18 DECLARE_GLOBAL_DATA_PTR;
21 * Define the UART hardware register access structure.
24 unsigned int RX; /* 0x00 - Receive data (r) */
25 unsigned int TX; /* 0x04 - Transmit data (w) */
26 unsigned int FCR; /* 0x08 - Fifo Control (r/w) */
27 unsigned int LCR; /* 0x0c - Line Control (r/w) */
28 unsigned int MCR; /* 0x10 - Modem Control (r/w) */
29 unsigned int LSR; /* 0x14 - Line Status (r/w) */
30 unsigned int MSR; /* 0x18 - Modem Status (r/w) */
31 unsigned int BD; /* 0x1c - Baud Rate (r/w) */
32 unsigned int SR; /* 0x20 - Status (r/w) */
35 #define KS8695_UART_ADDR ((void *) (KS8695_IO_BASE + KS8695_UART_RX_BUFFER))
36 #define KS8695_UART_CLK 25000000
40 * Under some circumstances we want to be "quiet" and not issue any
41 * serial output - though we want u-boot to otherwise work and behave
42 * the same. By default be noisy.
44 int serial_console = 1;
47 static void ks8695_serial_setbrg(void)
49 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
51 /* Set to global baud rate and 8 data bits, no parity, 1 stop bit*/
52 uartp->BD = KS8695_UART_CLK / gd->baudrate;
53 uartp->LCR = KS8695_UART_LINEC_WLEN8;
56 static int ks8695_serial_init(void)
63 static void ks8695_serial_raw_putc(const char c)
65 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
68 for (i = 0; (i < 0x100000); i++) {
69 if (uartp->LSR & KS8695_UART_LINES_TXFE)
76 static void ks8695_serial_putc(const char c)
79 ks8695_serial_raw_putc(c);
81 ks8695_serial_raw_putc('\r');
85 static int ks8695_serial_tstc(void)
87 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
89 return ((uartp->LSR & KS8695_UART_LINES_RXFE) ? 1 : 0);
93 static int ks8695_serial_getc(void)
95 volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
97 while ((uartp->LSR & KS8695_UART_LINES_RXFE) == 0)
102 static struct serial_device ks8695_serial_drv = {
103 .name = "ks8695_serial",
104 .start = ks8695_serial_init,
106 .setbrg = ks8695_serial_setbrg,
107 .putc = ks8695_serial_putc,
108 .puts = default_serial_puts,
109 .getc = ks8695_serial_getc,
110 .tstc = ks8695_serial_tstc,
113 void ks8695_serial_initialize(void)
115 serial_register(&ks8695_serial_drv);
118 __weak struct serial_device *default_serial_console(void)
120 return &ks8695_serial_drv;