2 * Copyright (C) 2004-2007 ARM Limited.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * As a special exception, if other files instantiate templates or use macros
19 * or inline functions from this file, or you compile this file and link it
20 * with other works to produce a work based on this file, this file does not
21 * by itself cause the resulting work to be covered by the GNU General Public
22 * License. However the source code for this file must still be made available
23 * in accordance with section (3) of the GNU General Public License.
25 * This exception does not invalidate any other reasons why a work based on
26 * this file might be covered by the GNU General Public License.
32 #define DCC_ARM9_RBIT (1 << 0)
33 #define DCC_ARM9_WBIT (1 << 1)
34 #define DCC_ARM11_RBIT (1 << 30)
35 #define DCC_ARM11_WBIT (1 << 29)
37 #define read_core_id(x) do { \
38 __asm__ ("mrc p15, 0, %0, c0, c0, 0\n" : "=r" (x)); \
39 x = (x >> 4) & 0xFFF; \
45 #define write_arm9_dcc(x) \
46 __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
48 #define read_arm9_dcc(x) \
49 __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
51 #define status_arm9_dcc(x) \
52 __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
54 #define can_read_arm9_dcc(x) do { \
59 #define can_write_arm9_dcc(x) do { \
68 #define write_arm11_dcc(x) \
69 __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
71 #define read_arm11_dcc(x) \
72 __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
74 #define status_arm11_dcc(x) \
75 __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
77 #define can_read_arm11_dcc(x) do { \
78 status_arm11_dcc(x); \
79 x &= DCC_ARM11_RBIT; \
82 #define can_write_arm11_dcc(x) do { \
83 status_arm11_dcc(x); \
84 x &= DCC_ARM11_WBIT; \
88 #define TIMEOUT_COUNT 0x4000000
93 } arm_type = arm9_and_earlier;
95 #ifndef CONFIG_ARM_DCC_MULTI
96 #define arm_dcc_init serial_init
97 void serial_setbrg(void) {}
98 #define arm_dcc_getc serial_getc
99 #define arm_dcc_putc serial_putc
100 #define arm_dcc_puts serial_puts
101 #define arm_dcc_tstc serial_tstc
104 int arm_dcc_init(void)
106 register unsigned int id;
111 arm_type = arm11_and_later;
113 arm_type = arm9_and_earlier;
118 int arm_dcc_getc(void)
121 register unsigned int reg;
124 case arm11_and_later:
126 can_read_arm11_dcc(reg);
131 case arm9_and_earlier:
134 can_read_arm9_dcc(reg);
143 void arm_dcc_putc(char ch)
145 register unsigned int reg;
146 unsigned int timeout_count = TIMEOUT_COUNT;
149 case arm11_and_later:
150 while (--timeout_count) {
151 can_write_arm11_dcc(reg);
155 if (timeout_count == 0)
161 case arm9_and_earlier:
163 while (--timeout_count) {
164 can_write_arm9_dcc(reg);
168 if (timeout_count == 0)
176 void arm_dcc_puts(const char *s)
182 int arm_dcc_tstc(void)
184 register unsigned int reg;
187 case arm11_and_later:
188 can_read_arm11_dcc(reg);
190 case arm9_and_earlier:
192 can_read_arm9_dcc(reg);
199 #ifdef CONFIG_ARM_DCC_MULTI
200 static device_t arm_dcc_dev;
202 int drv_arm_dcc_init(void)
206 /* Device initialization */
207 memset(&arm_dcc_dev, 0, sizeof(arm_dcc_dev));
209 strcpy(arm_dcc_dev.name, "dcc");
210 arm_dcc_dev.ext = 0; /* No extensions */
211 arm_dcc_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
212 arm_dcc_dev.tstc = arm_dcc_tstc; /* 'tstc' function */
213 arm_dcc_dev.getc = arm_dcc_getc; /* 'getc' function */
214 arm_dcc_dev.putc = arm_dcc_putc; /* 'putc' function */
215 arm_dcc_dev.puts = arm_dcc_puts; /* 'puts' function */
217 rc = device_register(&arm_dcc_dev);