1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29#include <common.h>
30#include <stdio_dev.h>
31
32#if defined(CONFIG_CPU_V6)
33
34
35
36#define DCC_RBIT (1 << 30)
37#define DCC_WBIT (1 << 29)
38
39#define write_dcc(x) \
40 __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
41
42#define read_dcc(x) \
43 __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
44
45#define status_dcc(x) \
46 __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
47
48#elif defined(CONFIG_CPU_XSCALE)
49
50
51
52#define DCC_RBIT (1 << 31)
53#define DCC_WBIT (1 << 28)
54
55#define write_dcc(x) \
56 __asm__ volatile ("mcr p14, 0, %0, c8, c0, 0\n" : : "r" (x))
57
58#define read_dcc(x) \
59 __asm__ volatile ("mrc p14, 0, %0, c9, c0, 0\n" : "=r" (x))
60
61#define status_dcc(x) \
62 __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x))
63
64#else
65#define DCC_RBIT (1 << 0)
66#define DCC_WBIT (1 << 1)
67
68#define write_dcc(x) \
69 __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
70
71#define read_dcc(x) \
72 __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
73
74#define status_dcc(x) \
75 __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
76
77#endif
78
79#define can_read_dcc(x) do { \
80 status_dcc(x); \
81 x &= DCC_RBIT; \
82 } while (0);
83
84#define can_write_dcc(x) do { \
85 status_dcc(x); \
86 x &= DCC_WBIT; \
87 x = (x == 0); \
88 } while (0);
89
90#define TIMEOUT_COUNT 0x4000000
91
92#ifndef CONFIG_ARM_DCC_MULTI
93#define arm_dcc_init serial_init
94void serial_setbrg(void) {}
95#define arm_dcc_getc serial_getc
96#define arm_dcc_putc serial_putc
97#define arm_dcc_puts serial_puts
98#define arm_dcc_tstc serial_tstc
99#endif
100
101int arm_dcc_init(void)
102{
103 return 0;
104}
105
106int arm_dcc_getc(void)
107{
108 int ch;
109 register unsigned int reg;
110
111 do {
112 can_read_dcc(reg);
113 } while (!reg);
114 read_dcc(ch);
115
116 return ch;
117}
118
119void arm_dcc_putc(char ch)
120{
121 register unsigned int reg;
122 unsigned int timeout_count = TIMEOUT_COUNT;
123
124 while (--timeout_count) {
125 can_write_dcc(reg);
126 if (reg)
127 break;
128 }
129 if (timeout_count == 0)
130 return;
131 else
132 write_dcc(ch);
133}
134
135void arm_dcc_puts(const char *s)
136{
137 while (*s)
138 arm_dcc_putc(*s++);
139}
140
141int arm_dcc_tstc(void)
142{
143 register unsigned int reg;
144
145 can_read_dcc(reg);
146
147 return reg;
148}
149
150#ifdef CONFIG_ARM_DCC_MULTI
151static struct stdio_dev arm_dcc_dev;
152
153int drv_arm_dcc_init(void)
154{
155 int rc;
156
157
158 memset(&arm_dcc_dev, 0, sizeof(arm_dcc_dev));
159
160 strcpy(arm_dcc_dev.name, "dcc");
161 arm_dcc_dev.ext = 0;
162 arm_dcc_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
163 arm_dcc_dev.tstc = arm_dcc_tstc;
164 arm_dcc_dev.getc = arm_dcc_getc;
165 arm_dcc_dev.putc = arm_dcc_putc;
166 arm_dcc_dev.puts = arm_dcc_puts;
167
168 return stdio_register(&arm_dcc_dev);
169}
170#endif
171