blob: ad23cc8082a07633ff4730e4627704dfcf174eb9 [file] [log] [blame]
Daniel Walker16c63f82010-11-30 11:25:39 -08001/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include <linux/console.h>
19#include <linux/delay.h>
20#include <linux/err.h>
21#include <linux/init.h>
22#include <linux/moduleparam.h>
23#include <linux/types.h>
24
25#include <asm/processor.h>
26
27#include "hvc_console.h"
28
29/* DCC Status Bits */
30#define DCC_STATUS_RX (1 << 30)
31#define DCC_STATUS_TX (1 << 29)
32
33static inline u32 __dcc_getstatus(void)
34{
35 u32 __ret;
Stephen Boyda9963202011-02-03 15:48:34 -080036 asm volatile("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
Daniel Walker16c63f82010-11-30 11:25:39 -080037 : "=r" (__ret) : : "cc");
38
39 return __ret;
40}
41
42
43#if defined(CONFIG_CPU_V7)
44static inline char __dcc_getchar(void)
45{
46 char __c;
47
Stephen Boyda9963202011-02-03 15:48:34 -080048 asm volatile("get_wait: mrc p14, 0, pc, c0, c1, 0 \n\
Daniel Walker16c63f82010-11-30 11:25:39 -080049 bne get_wait \n\
50 mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
51 : "=r" (__c) : : "cc");
52
53 return __c;
54}
55#else
56static inline char __dcc_getchar(void)
57{
58 char __c;
59
Stephen Boyda9963202011-02-03 15:48:34 -080060 asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
Daniel Walker16c63f82010-11-30 11:25:39 -080061 : "=r" (__c));
62
63 return __c;
64}
65#endif
66
67#if defined(CONFIG_CPU_V7)
68static inline void __dcc_putchar(char c)
69{
Stephen Boyda9963202011-02-03 15:48:34 -080070 asm volatile("put_wait: mrc p14, 0, pc, c0, c1, 0 \n\
Daniel Walker16c63f82010-11-30 11:25:39 -080071 bcs put_wait \n\
72 mcr p14, 0, %0, c0, c5, 0 "
73 : : "r" (c) : "cc");
74}
75#else
76static inline void __dcc_putchar(char c)
77{
Stephen Boyda9963202011-02-03 15:48:34 -080078 asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
Daniel Walker16c63f82010-11-30 11:25:39 -080079 : /* no output register */
80 : "r" (c));
81}
82#endif
83
84static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
85{
86 int i;
87
88 for (i = 0; i < count; i++) {
89 while (__dcc_getstatus() & DCC_STATUS_TX)
90 cpu_relax();
91
Stephen Boydbf73bd32011-02-03 15:48:35 -080092 __dcc_putchar(buf[i]);
Daniel Walker16c63f82010-11-30 11:25:39 -080093 }
94
95 return count;
96}
97
98static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
99{
100 int i;
101
Stephen Boydbf73bd32011-02-03 15:48:35 -0800102 for (i = 0; i < count; ++i)
Daniel Walker16c63f82010-11-30 11:25:39 -0800103 if (__dcc_getstatus() & DCC_STATUS_RX)
Stephen Boydbf73bd32011-02-03 15:48:35 -0800104 buf[i] = __dcc_getchar();
105 else
Daniel Walker16c63f82010-11-30 11:25:39 -0800106 break;
Daniel Walker16c63f82010-11-30 11:25:39 -0800107
108 return i;
109}
110
111static const struct hv_ops hvc_dcc_get_put_ops = {
112 .get_chars = hvc_dcc_get_chars,
113 .put_chars = hvc_dcc_put_chars,
114};
115
116static int __init hvc_dcc_console_init(void)
117{
118 hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
119 return 0;
120}
121console_initcall(hvc_dcc_console_init);
122
123static int __init hvc_dcc_init(void)
124{
125 hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
126 return 0;
127}
128device_initcall(hvc_dcc_init);