2
* Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation.
13
DECLARE_GLOBAL_DATA_PTR;
15
struct arc_serial_regs {
26
/* Bit definitions of STATUS register */
27
#define UART_RXEMPTY (1 << 5)
28
#define UART_OVERFLOW_ERR (1 << 1)
29
#define UART_TXEMPTY (1 << 7)
31
struct arc_serial_regs *regs;
33
static void arc_serial_setbrg(void)
38
gd->baudrate = CONFIG_BAUDRATE;
40
arc_console_baud = gd->cpu_clk / (gd->baudrate * 4) - 1;
41
writeb(arc_console_baud & 0xff, ®s->baudl);
45
* UART ISS(Instruction Set simulator) emulation has a subtle bug:
46
* A existing value of Baudh = 0 is used as a indication to startup
47
* it's internal state machine.
48
* Thus if baudh is set to 0, 2 times, it chokes.
49
* This happens with BAUD=115200 and the formaula above
50
* Until that is fixed, when running on ISS, we will set baudh to !0
52
if (gd->arch.running_on_hw)
53
writeb((arc_console_baud & 0xff00) >> 8, ®s->baudh);
55
writeb(1, ®s->baudh);
57
writeb((arc_console_baud & 0xff00) >> 8, ®s->baudh);
61
static int arc_serial_init(void)
63
regs = (struct arc_serial_regs *)CONFIG_ARC_UART_BASE;
68
static void arc_serial_putc(const char c)
71
arc_serial_putc('\r');
73
while (!(readb(®s->status) & UART_TXEMPTY))
76
writeb(c, ®s->data);
79
static int arc_serial_tstc(void)
81
return !(readb(®s->status) & UART_RXEMPTY);
84
static int arc_serial_getc(void)
86
while (!arc_serial_tstc())
89
/* Check for overflow errors */
90
if (readb(®s->status) & UART_OVERFLOW_ERR)
93
return readb(®s->data) & 0xFF;
96
static struct serial_device arc_serial_drv = {
98
.start = arc_serial_init,
100
.setbrg = arc_serial_setbrg,
101
.putc = arc_serial_putc,
102
.puts = default_serial_puts,
103
.getc = arc_serial_getc,
104
.tstc = arc_serial_tstc,
107
void arc_serial_initialize(void)
109
serial_register(&arc_serial_drv);
112
__weak struct serial_device *default_serial_console(void)
114
return &arc_serial_drv;