]> Git Repo - u-boot.git/blame - drivers/serial/arm_dcc.c
Merge branch 'master' of git://git.denx.de/u-boot-sunxi
[u-boot.git] / drivers / serial / arm_dcc.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0
4f572898
JCPV
2/*
3 * Copyright (C) 2004-2007 ARM Limited.
4 * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <[email protected]>
966bfa73 5 * Copyright (C) 2015 - 2016 Xilinx, Inc, Michal Simek
4f572898 6 *
4f572898
JCPV
7 * As a special exception, if other files instantiate templates or use macros
8 * or inline functions from this file, or you compile this file and link it
9 * with other works to produce a work based on this file, this file does not
10 * by itself cause the resulting work to be covered by the GNU General Public
11 * License. However the source code for this file must still be made available
12 * in accordance with section (3) of the GNU General Public License.
13
14 * This exception does not invalidate any other reasons why a work based on
15 * this file might be covered by the GNU General Public License.
16 */
17
18#include <common.h>
966bfa73 19#include <dm.h>
a168d3af 20#include <serial.h>
4f572898 21
acf15001 22#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V7A)
4f572898 23/*
fd602c56 24 * ARMV6 & ARMV7
4f572898 25 */
66e8f9da
JCPV
26#define DCC_RBIT (1 << 30)
27#define DCC_WBIT (1 << 29)
4f572898 28
66e8f9da
JCPV
29#define write_dcc(x) \
30 __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
4f572898 31
66e8f9da
JCPV
32#define read_dcc(x) \
33 __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
4f572898 34
66e8f9da
JCPV
35#define status_dcc(x) \
36 __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
4f572898 37
65a76d4f
JCPV
38#elif defined(CONFIG_CPU_XSCALE)
39/*
40 * XSCALE
41 */
42#define DCC_RBIT (1 << 31)
43#define DCC_WBIT (1 << 28)
44
45#define write_dcc(x) \
46 __asm__ volatile ("mcr p14, 0, %0, c8, c0, 0\n" : : "r" (x))
47
48#define read_dcc(x) \
49 __asm__ volatile ("mrc p14, 0, %0, c9, c0, 0\n" : "=r" (x))
50
51#define status_dcc(x) \
52 __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x))
53
e05412f5
SDPP
54#elif defined(CONFIG_CPU_ARMV8)
55/*
56 * ARMV8
57 */
58#define DCC_RBIT (1 << 30)
59#define DCC_WBIT (1 << 29)
60
61#define write_dcc(x) \
62 __asm__ volatile ("msr dbgdtrtx_el0, %0\n" : : "r" (x))
63
64#define read_dcc(x) \
65 __asm__ volatile ("mrs %0, dbgdtrrx_el0\n" : "=r" (x))
66
67#define status_dcc(x) \
68 __asm__ volatile ("mrs %0, mdccsr_el0\n" : "=r" (x))
69
66e8f9da
JCPV
70#else
71#define DCC_RBIT (1 << 0)
72#define DCC_WBIT (1 << 1)
4f572898 73
66e8f9da
JCPV
74#define write_dcc(x) \
75 __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
4f572898 76
66e8f9da
JCPV
77#define read_dcc(x) \
78 __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
4f572898 79
66e8f9da
JCPV
80#define status_dcc(x) \
81 __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
82
83#endif
4f572898 84
66e8f9da
JCPV
85#define can_read_dcc(x) do { \
86 status_dcc(x); \
87 x &= DCC_RBIT; \
4f572898
JCPV
88 } while (0);
89
66e8f9da
JCPV
90#define can_write_dcc(x) do { \
91 status_dcc(x); \
92 x &= DCC_WBIT; \
93 x = (x == 0); \
4f572898
JCPV
94 } while (0);
95
96#define TIMEOUT_COUNT 0x4000000
97
966bfa73 98static int arm_dcc_getc(struct udevice *dev)
4f572898
JCPV
99{
100 int ch;
101 register unsigned int reg;
102
66e8f9da
JCPV
103 do {
104 can_read_dcc(reg);
105 } while (!reg);
106 read_dcc(ch);
4f572898
JCPV
107
108 return ch;
109}
110
966bfa73 111static int arm_dcc_putc(struct udevice *dev, char ch)
4f572898
JCPV
112{
113 register unsigned int reg;
114 unsigned int timeout_count = TIMEOUT_COUNT;
115
66e8f9da
JCPV
116 while (--timeout_count) {
117 can_write_dcc(reg);
118 if (reg)
119 break;
4f572898 120 }
66e8f9da 121 if (timeout_count == 0)
966bfa73 122 return -EAGAIN;
66e8f9da
JCPV
123 else
124 write_dcc(ch);
966bfa73
MS
125
126 return 0;
4f572898
JCPV
127}
128
966bfa73 129static int arm_dcc_pending(struct udevice *dev, bool input)
4f572898
JCPV
130{
131 register unsigned int reg;
132
966bfa73
MS
133 if (input) {
134 can_read_dcc(reg);
135 } else {
136 can_write_dcc(reg);
137 }
4f572898
JCPV
138
139 return reg;
140}
141
966bfa73
MS
142static const struct dm_serial_ops arm_dcc_ops = {
143 .putc = arm_dcc_putc,
144 .pending = arm_dcc_pending,
145 .getc = arm_dcc_getc,
146};
147
148static const struct udevice_id arm_dcc_ids[] = {
149 { .compatible = "arm,dcc", },
150 { }
151};
a168d3af 152
966bfa73 153U_BOOT_DRIVER(serial_dcc) = {
a168d3af 154 .name = "arm_dcc",
966bfa73
MS
155 .id = UCLASS_SERIAL,
156 .of_match = arm_dcc_ids,
157 .ops = &arm_dcc_ops,
158 .flags = DM_FLAG_PRE_RELOC,
a168d3af
JT
159};
160
966bfa73
MS
161#ifdef CONFIG_DEBUG_UART_ARM_DCC
162
163#include <debug_uart.h>
164
165static inline void _debug_uart_init(void)
a168d3af 166{
a168d3af
JT
167}
168
966bfa73 169static inline void _debug_uart_putc(int ch)
e70fb539 170{
966bfa73 171 arm_dcc_putc(NULL, ch);
e70fb539 172}
966bfa73
MS
173
174DEBUG_UART_FUNCS
175#endif
This page took 0.290971 seconds and 4 git commands to generate.