Blame view
drivers/serial/arm_dcc.c
3.64 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0 |
4f5728987 arm: add uart dcc... |
2 3 4 |
/* * Copyright (C) 2004-2007 ARM Limited. * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> |
966bfa734 serial: dcc: Move... |
5 |
* Copyright (C) 2015 - 2016 Xilinx, Inc, Michal Simek |
4f5728987 arm: add uart dcc... |
6 |
* |
4f5728987 arm: add uart dcc... |
7 8 9 10 11 12 13 14 15 16 17 18 |
* 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> |
966bfa734 serial: dcc: Move... |
19 |
#include <dm.h> |
a168d3af5 serial: arm_dcc: ... |
20 |
#include <serial.h> |
4f5728987 arm: add uart dcc... |
21 |
|
5f133bb7c serial: arm_dcc: ... |
22 |
#if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V7A) || defined(CONFIG_CPU_V7R) |
4f5728987 arm: add uart dcc... |
23 |
/* |
fd602c563 fix ARM DCC suppo... |
24 |
* ARMV6 & ARMV7 |
4f5728987 arm: add uart dcc... |
25 |
*/ |
66e8f9da6 arm/dcc: use stat... |
26 27 |
#define DCC_RBIT (1 << 30) #define DCC_WBIT (1 << 29) |
4f5728987 arm: add uart dcc... |
28 |
|
66e8f9da6 arm/dcc: use stat... |
29 30 31 |
#define write_dcc(x) \ __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0 " : : "r" (x)) |
4f5728987 arm: add uart dcc... |
32 |
|
66e8f9da6 arm/dcc: use stat... |
33 34 35 |
#define read_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0 " : "=r" (x)) |
4f5728987 arm: add uart dcc... |
36 |
|
66e8f9da6 arm/dcc: use stat... |
37 38 39 |
#define status_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0 " : "=r" (x)) |
4f5728987 arm: add uart dcc... |
40 |
|
65a76d4f9 arm/dcc: add xsca... |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#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 " : : "r" (x)) #define read_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c9, c0, 0 " : "=r" (x)) #define status_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0 " : "=r" (x)) |
e05412f5e arm: dcc: Add uar... |
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#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 " : : "r" (x)) #define read_dcc(x) \ __asm__ volatile ("mrs %0, dbgdtrrx_el0 " : "=r" (x)) #define status_dcc(x) \ __asm__ volatile ("mrs %0, mdccsr_el0 " : "=r" (x)) |
66e8f9da6 arm/dcc: use stat... |
77 78 79 |
#else #define DCC_RBIT (1 << 0) #define DCC_WBIT (1 << 1) |
4f5728987 arm: add uart dcc... |
80 |
|
66e8f9da6 arm/dcc: use stat... |
81 82 83 |
#define write_dcc(x) \ __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0 " : : "r" (x)) |
4f5728987 arm: add uart dcc... |
84 |
|
66e8f9da6 arm/dcc: use stat... |
85 86 87 |
#define read_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0 " : "=r" (x)) |
4f5728987 arm: add uart dcc... |
88 |
|
66e8f9da6 arm/dcc: use stat... |
89 90 91 92 93 |
#define status_dcc(x) \ __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0 " : "=r" (x)) #endif |
4f5728987 arm: add uart dcc... |
94 |
|
66e8f9da6 arm/dcc: use stat... |
95 96 97 |
#define can_read_dcc(x) do { \ status_dcc(x); \ x &= DCC_RBIT; \ |
4f5728987 arm: add uart dcc... |
98 |
} while (0); |
66e8f9da6 arm/dcc: use stat... |
99 100 101 102 |
#define can_write_dcc(x) do { \ status_dcc(x); \ x &= DCC_WBIT; \ x = (x == 0); \ |
4f5728987 arm: add uart dcc... |
103 104 105 |
} while (0); #define TIMEOUT_COUNT 0x4000000 |
966bfa734 serial: dcc: Move... |
106 |
static int arm_dcc_getc(struct udevice *dev) |
4f5728987 arm: add uart dcc... |
107 108 109 |
{ int ch; register unsigned int reg; |
66e8f9da6 arm/dcc: use stat... |
110 111 112 113 |
do { can_read_dcc(reg); } while (!reg); read_dcc(ch); |
4f5728987 arm: add uart dcc... |
114 115 116 |
return ch; } |
966bfa734 serial: dcc: Move... |
117 |
static int arm_dcc_putc(struct udevice *dev, char ch) |
4f5728987 arm: add uart dcc... |
118 119 120 |
{ register unsigned int reg; unsigned int timeout_count = TIMEOUT_COUNT; |
66e8f9da6 arm/dcc: use stat... |
121 122 123 124 |
while (--timeout_count) { can_write_dcc(reg); if (reg) break; |
4f5728987 arm: add uart dcc... |
125 |
} |
66e8f9da6 arm/dcc: use stat... |
126 |
if (timeout_count == 0) |
966bfa734 serial: dcc: Move... |
127 |
return -EAGAIN; |
66e8f9da6 arm/dcc: use stat... |
128 129 |
else write_dcc(ch); |
966bfa734 serial: dcc: Move... |
130 131 |
return 0; |
4f5728987 arm: add uart dcc... |
132 |
} |
966bfa734 serial: dcc: Move... |
133 |
static int arm_dcc_pending(struct udevice *dev, bool input) |
4f5728987 arm: add uart dcc... |
134 135 |
{ register unsigned int reg; |
966bfa734 serial: dcc: Move... |
136 137 138 139 140 |
if (input) { can_read_dcc(reg); } else { can_write_dcc(reg); } |
4f5728987 arm: add uart dcc... |
141 142 143 |
return reg; } |
966bfa734 serial: dcc: Move... |
144 145 146 147 148 149 150 151 152 153 |
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", }, { } }; |
a168d3af5 serial: arm_dcc: ... |
154 |
|
966bfa734 serial: dcc: Move... |
155 |
U_BOOT_DRIVER(serial_dcc) = { |
a168d3af5 serial: arm_dcc: ... |
156 |
.name = "arm_dcc", |
966bfa734 serial: dcc: Move... |
157 158 159 |
.id = UCLASS_SERIAL, .of_match = arm_dcc_ids, .ops = &arm_dcc_ops, |
a168d3af5 serial: arm_dcc: ... |
160 |
}; |
966bfa734 serial: dcc: Move... |
161 162 163 164 165 |
#ifdef CONFIG_DEBUG_UART_ARM_DCC #include <debug_uart.h> static inline void _debug_uart_init(void) |
a168d3af5 serial: arm_dcc: ... |
166 |
{ |
a168d3af5 serial: arm_dcc: ... |
167 |
} |
966bfa734 serial: dcc: Move... |
168 |
static inline void _debug_uart_putc(int ch) |
e70fb539a serial: arm_dcc: ... |
169 |
{ |
966bfa734 serial: dcc: Move... |
170 |
arm_dcc_putc(NULL, ch); |
e70fb539a serial: arm_dcc: ... |
171 |
} |
966bfa734 serial: dcc: Move... |
172 173 174 |
DEBUG_UART_FUNCS #endif |