2014-06-23 05:40:39 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright 2014 Rockchip Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch/io.h>
|
|
|
|
#include <boot/coreboot_tables.h>
|
|
|
|
#include <console/console.h> /* for __console definition */
|
2014-10-20 22:14:55 +02:00
|
|
|
#include <console/uart.h>
|
2014-06-23 05:40:39 +02:00
|
|
|
#include <drivers/uart/uart8250reg.h>
|
2014-10-20 22:14:55 +02:00
|
|
|
#include <stdint.h>
|
2014-06-23 05:40:39 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: Use DRIVERS_UART_8250MEM driver instead.
|
|
|
|
* There is an issue in the IO call functions where x86 and ARM
|
|
|
|
* ordering is reversed. This 8250MEM driver uses the x86 convention.
|
|
|
|
* This driver can be replaced once the IO calls are sorted.
|
|
|
|
*/
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
struct rk_uart {
|
2014-06-23 05:40:39 +02:00
|
|
|
union {
|
|
|
|
uint32_t thr; /* Transmit holding register. */
|
|
|
|
uint32_t rbr; /* Receive buffer register. */
|
|
|
|
uint32_t dll; /* Divisor latch lsb. */
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint32_t ier; /* Interrupt enable register. */
|
|
|
|
uint32_t dlm; /* Divisor latch msb. */
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
uint32_t iir; /* Interrupt identification register. */
|
|
|
|
uint32_t fcr; /* FIFO control register. */
|
|
|
|
};
|
|
|
|
uint32_t lcr; /* Line control register. */
|
|
|
|
uint32_t mcr; /* Modem control register. */
|
|
|
|
uint32_t lsr; /* Line status register. */
|
|
|
|
uint32_t msr; /* Modem status register. */
|
|
|
|
uint32_t scr;
|
|
|
|
uint32_t reserved1[(0x30 - 0x20) / 4];
|
|
|
|
uint32_t srbr[(0x70 - 0x30) / 4];
|
|
|
|
uint32_t far;
|
|
|
|
uint32_t tfr;
|
|
|
|
uint32_t rfw;
|
|
|
|
uint32_t usr;
|
|
|
|
uint32_t tfl;
|
|
|
|
uint32_t rfl;
|
|
|
|
uint32_t srr;
|
|
|
|
uint32_t srts;
|
|
|
|
uint32_t sbcr;
|
|
|
|
uint32_t sdmam;
|
|
|
|
uint32_t sfe;
|
|
|
|
uint32_t srt;
|
|
|
|
uint32_t stet;
|
|
|
|
uint32_t htx;
|
|
|
|
uint32_t dmasa;
|
|
|
|
uint32_t reserver2[(0xf4 - 0xac) / 4];
|
|
|
|
uint32_t cpr;
|
|
|
|
uint32_t ucv;
|
|
|
|
uint32_t ctr;
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static struct rk_uart * const uart_ptr =
|
2014-06-23 05:40:39 +02:00
|
|
|
(void *)CONFIG_CONSOLE_SERIAL_UART_ADDRESS;
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static void rk_uart_tx_flush(void);
|
|
|
|
static int rk_uart_tst_byte(void);
|
2014-06-23 05:40:39 +02:00
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static void rk_uart_init(void)
|
2014-06-23 05:40:39 +02:00
|
|
|
{
|
|
|
|
/* FIXME: Use a hardcoded divisor for now.
|
|
|
|
* uint16_t divisor = (u16) uart_baudrate_divisor(default_baudrate(),
|
|
|
|
* uart_platform_refclk(), 16)
|
|
|
|
*/
|
|
|
|
const unsigned divisor = 13;
|
|
|
|
const uint8_t line_config = UART8250_LCR_WLS_8; // 8n1
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
rk_uart_tx_flush();
|
2014-06-23 05:40:39 +02:00
|
|
|
|
|
|
|
// Disable interrupts.
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&uart_ptr->ier, 0);
|
2014-06-23 05:40:39 +02:00
|
|
|
// Force DTR and RTS to high.
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&uart_ptr->mcr, UART8250_MCR_DTR | UART8250_MCR_RTS);
|
2014-06-23 05:40:39 +02:00
|
|
|
// Set line configuration, access divisor latches.
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&uart_ptr->lcr, UART8250_LCR_DLAB | line_config);
|
2014-06-23 05:40:39 +02:00
|
|
|
// Set the divisor.
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&uart_ptr->dll, divisor & 0xff);
|
|
|
|
write32(&uart_ptr->dlm, (divisor >> 8) & 0xff);
|
2014-06-23 05:40:39 +02:00
|
|
|
// Hide the divisor latches.
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
write32(&uart_ptr->lcr, line_config);
|
2014-06-23 05:40:39 +02:00
|
|
|
// Enable FIFOs, and clear receive and transmit.
|
2015-02-20 05:19:23 +01:00
|
|
|
write32(&uart_ptr->fcr, UART8250_FCR_FIFO_EN |
|
|
|
|
UART8250_FCR_CLEAR_RCVR | UART8250_FCR_CLEAR_XMIT);
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static void rk_uart_tx_byte(unsigned char data)
|
2014-06-23 05:40:39 +02:00
|
|
|
{
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
while (!(read32(&uart_ptr->lsr) & UART8250_LSR_THRE));
|
|
|
|
write32(&uart_ptr->thr, data);
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static void rk_uart_tx_flush(void)
|
2014-06-23 05:40:39 +02:00
|
|
|
{
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
while (!(read32(&uart_ptr->lsr) & UART8250_LSR_TEMT));
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static unsigned char rk_uart_rx_byte(void)
|
2014-06-23 05:40:39 +02:00
|
|
|
{
|
2016-03-29 07:57:26 +02:00
|
|
|
if (!rk_uart_tst_byte())
|
2014-06-23 05:40:39 +02:00
|
|
|
return 0;
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
return read32(&uart_ptr->rbr);
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
2016-03-29 07:57:26 +02:00
|
|
|
static int rk_uart_tst_byte(void)
|
2014-06-23 05:40:39 +02:00
|
|
|
{
|
arm(64): Globally replace writel(v, a) with write32(a, v)
This patch is a raw application of the following spatch to src/:
@@
expression A, V;
@@
- writel(V, A)
+ write32(A, V)
@@
expression A, V;
@@
- writew(V, A)
+ write16(A, V)
@@
expression A, V;
@@
- writeb(V, A)
+ write8(A, V)
@@
expression A;
@@
- readl(A)
+ read32(A)
@@
expression A;
@@
- readb(A)
+ read8(A)
BRANCH=none
BUG=chromium:444723
TEST=None (depends on next patch)
Change-Id: I5dd96490c85ee2bcbc669f08bc6fff0ecc0f9e27
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Original-Commit-Id: 64f643da95d85954c4d4ea91c34a5c69b9b08eb6
Original-Change-Id: I366a2eb5b3a0df2279ebcce572fe814894791c42
Original-Signed-off-by: Julius Werner <jwerner@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/254864
Reviewed-on: http://review.coreboot.org/9836
Tested-by: build bot (Jenkins)
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
2015-02-19 23:51:15 +01:00
|
|
|
return (read32(&uart_ptr->lsr) & UART8250_LSR_DR) == UART8250_LSR_DR;
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uart_init(int idx)
|
|
|
|
{
|
2016-03-29 07:57:26 +02:00
|
|
|
rk_uart_init();
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char uart_rx_byte(int idx)
|
|
|
|
{
|
2016-03-29 07:57:26 +02:00
|
|
|
return rk_uart_rx_byte();
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uart_tx_byte(int idx, unsigned char data)
|
|
|
|
{
|
2016-03-29 07:57:26 +02:00
|
|
|
rk_uart_tx_byte(data);
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void uart_tx_flush(int idx)
|
|
|
|
{
|
2016-03-29 07:57:26 +02:00
|
|
|
rk_uart_tx_flush();
|
2014-06-23 05:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef __PRE_RAM__
|
|
|
|
void uart_fill_lb(void *data)
|
|
|
|
{
|
|
|
|
struct lb_serial serial;
|
|
|
|
serial.type = LB_SERIAL_TYPE_MEMORY_MAPPED;
|
|
|
|
serial.baseaddr = CONFIG_CONSOLE_SERIAL_UART_ADDRESS;
|
|
|
|
serial.baud = default_baudrate();
|
2016-02-08 20:28:32 +01:00
|
|
|
serial.regwidth = 4;
|
2014-06-23 05:40:39 +02:00
|
|
|
lb_add_serial(&serial, data);
|
|
|
|
|
|
|
|
lb_add_console(LB_TAG_CONSOLE_SERIAL8250MEM, data);
|
|
|
|
}
|
|
|
|
#endif
|