2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-02-22 14:49:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004-2007 ARM Limited.
|
|
|
|
* Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
|
2016-02-23 09:02:28 +00:00
|
|
|
* Copyright (C) 2015 - 2016 Xilinx, Inc, Michal Simek
|
2009-02-22 14:49:28 +00:00
|
|
|
*
|
|
|
|
* As a special exception, if other files instantiate templates or use macros
|
|
|
|
* or inline functions from this file, or you compile this file and link it
|
|
|
|
* with other works to produce a work based on this file, this file does not
|
|
|
|
* by itself cause the resulting work to be covered by the GNU General Public
|
|
|
|
* License. However the source code for this file must still be made available
|
|
|
|
* in accordance with section (3) of the GNU General Public License.
|
|
|
|
|
|
|
|
* This exception does not invalidate any other reasons why a work based on
|
|
|
|
* this file might be covered by the GNU General Public License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-02-23 09:02:28 +00:00
|
|
|
#include <dm.h>
|
2013-08-03 19:52:25 +00:00
|
|
|
#include <serial.h>
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2018-08-16 13:13:56 +00:00
|
|
|
#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V7A) || defined(CONFIG_CPU_V7R)
|
2009-02-22 14:49:28 +00:00
|
|
|
/*
|
2015-03-19 17:37:19 +00:00
|
|
|
* ARMV6 & ARMV7
|
2009-02-22 14:49:28 +00:00
|
|
|
*/
|
2009-05-15 21:47:14 +00:00
|
|
|
#define DCC_RBIT (1 << 30)
|
|
|
|
#define DCC_WBIT (1 << 29)
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define write_dcc(x) \
|
|
|
|
__asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define read_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define status_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#elif defined(CONFIG_CPU_XSCALE)
|
|
|
|
/*
|
|
|
|
* XSCALE
|
|
|
|
*/
|
|
|
|
#define DCC_RBIT (1 << 31)
|
|
|
|
#define DCC_WBIT (1 << 28)
|
|
|
|
|
|
|
|
#define write_dcc(x) \
|
|
|
|
__asm__ volatile ("mcr p14, 0, %0, c8, c0, 0\n" : : "r" (x))
|
|
|
|
|
|
|
|
#define read_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c9, c0, 0\n" : "=r" (x))
|
|
|
|
|
|
|
|
#define status_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x))
|
|
|
|
|
2015-05-29 07:54:37 +00:00
|
|
|
#elif defined(CONFIG_CPU_ARMV8)
|
|
|
|
/*
|
|
|
|
* ARMV8
|
|
|
|
*/
|
|
|
|
#define DCC_RBIT (1 << 30)
|
|
|
|
#define DCC_WBIT (1 << 29)
|
|
|
|
|
|
|
|
#define write_dcc(x) \
|
|
|
|
__asm__ volatile ("msr dbgdtrtx_el0, %0\n" : : "r" (x))
|
|
|
|
|
|
|
|
#define read_dcc(x) \
|
|
|
|
__asm__ volatile ("mrs %0, dbgdtrrx_el0\n" : "=r" (x))
|
|
|
|
|
|
|
|
#define status_dcc(x) \
|
|
|
|
__asm__ volatile ("mrs %0, mdccsr_el0\n" : "=r" (x))
|
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#else
|
|
|
|
#define DCC_RBIT (1 << 0)
|
|
|
|
#define DCC_WBIT (1 << 1)
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define write_dcc(x) \
|
|
|
|
__asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define read_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define status_dcc(x) \
|
|
|
|
__asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
|
|
|
|
|
|
|
|
#endif
|
2009-02-22 14:49:28 +00:00
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define can_read_dcc(x) do { \
|
|
|
|
status_dcc(x); \
|
|
|
|
x &= DCC_RBIT; \
|
2009-02-22 14:49:28 +00:00
|
|
|
} while (0);
|
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
#define can_write_dcc(x) do { \
|
|
|
|
status_dcc(x); \
|
|
|
|
x &= DCC_WBIT; \
|
|
|
|
x = (x == 0); \
|
2009-02-22 14:49:28 +00:00
|
|
|
} while (0);
|
|
|
|
|
|
|
|
#define TIMEOUT_COUNT 0x4000000
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
static int arm_dcc_getc(struct udevice *dev)
|
2009-02-22 14:49:28 +00:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
register unsigned int reg;
|
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
do {
|
|
|
|
can_read_dcc(reg);
|
|
|
|
} while (!reg);
|
|
|
|
read_dcc(ch);
|
2009-02-22 14:49:28 +00:00
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
static int arm_dcc_putc(struct udevice *dev, char ch)
|
2009-02-22 14:49:28 +00:00
|
|
|
{
|
|
|
|
register unsigned int reg;
|
|
|
|
unsigned int timeout_count = TIMEOUT_COUNT;
|
|
|
|
|
2009-05-15 21:47:14 +00:00
|
|
|
while (--timeout_count) {
|
|
|
|
can_write_dcc(reg);
|
|
|
|
if (reg)
|
|
|
|
break;
|
2009-02-22 14:49:28 +00:00
|
|
|
}
|
2009-05-15 21:47:14 +00:00
|
|
|
if (timeout_count == 0)
|
2016-02-23 09:02:28 +00:00
|
|
|
return -EAGAIN;
|
2009-05-15 21:47:14 +00:00
|
|
|
else
|
|
|
|
write_dcc(ch);
|
2016-02-23 09:02:28 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-02-22 14:49:28 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
static int arm_dcc_pending(struct udevice *dev, bool input)
|
2009-02-22 14:49:28 +00:00
|
|
|
{
|
|
|
|
register unsigned int reg;
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
if (input) {
|
|
|
|
can_read_dcc(reg);
|
|
|
|
} else {
|
|
|
|
can_write_dcc(reg);
|
|
|
|
}
|
2009-02-22 14:49:28 +00:00
|
|
|
|
|
|
|
return reg;
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
static const struct dm_serial_ops arm_dcc_ops = {
|
|
|
|
.putc = arm_dcc_putc,
|
|
|
|
.pending = arm_dcc_pending,
|
|
|
|
.getc = arm_dcc_getc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id arm_dcc_ids[] = {
|
|
|
|
{ .compatible = "arm,dcc", },
|
|
|
|
{ }
|
|
|
|
};
|
2013-08-03 19:52:25 +00:00
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
U_BOOT_DRIVER(serial_dcc) = {
|
2013-08-03 19:52:25 +00:00
|
|
|
.name = "arm_dcc",
|
2016-02-23 09:02:28 +00:00
|
|
|
.id = UCLASS_SERIAL,
|
|
|
|
.of_match = arm_dcc_ids,
|
|
|
|
.ops = &arm_dcc_ops,
|
2013-08-03 19:52:25 +00:00
|
|
|
};
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
#ifdef CONFIG_DEBUG_UART_ARM_DCC
|
|
|
|
|
|
|
|
#include <debug_uart.h>
|
|
|
|
|
|
|
|
static inline void _debug_uart_init(void)
|
2013-08-03 19:52:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-23 09:02:28 +00:00
|
|
|
static inline void _debug_uart_putc(int ch)
|
2013-01-22 23:40:06 +00:00
|
|
|
{
|
2016-02-23 09:02:28 +00:00
|
|
|
arm_dcc_putc(NULL, ch);
|
2013-01-22 23:40:06 +00:00
|
|
|
}
|
2016-02-23 09:02:28 +00:00
|
|
|
|
|
|
|
DEBUG_UART_FUNCS
|
|
|
|
#endif
|