blob: 7ff13123fc2b0ffa2f8404cf000bc0bad3bbfb53 [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.
Daniel Walker16c63f82010-11-30 11:25:39 -080011 */
12
13#include <linux/console.h>
14#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/moduleparam.h>
18#include <linux/types.h>
19
20#include <asm/processor.h>
21
22#include "hvc_console.h"
23
24/* DCC Status Bits */
25#define DCC_STATUS_RX (1 << 30)
26#define DCC_STATUS_TX (1 << 29)
27
28static inline u32 __dcc_getstatus(void)
29{
30 u32 __ret;
Stephen Boyda9963202011-02-03 15:48:34 -080031 asm volatile("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
Daniel Walker16c63f82010-11-30 11:25:39 -080032 : "=r" (__ret) : : "cc");
33
34 return __ret;
35}
36
37
Daniel Walker16c63f82010-11-30 11:25:39 -080038static inline char __dcc_getchar(void)
39{
40 char __c;
41
Stephen Boyda9963202011-02-03 15:48:34 -080042 asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
Daniel Walker16c63f82010-11-30 11:25:39 -080043 : "=r" (__c));
44
45 return __c;
46}
Daniel Walker16c63f82010-11-30 11:25:39 -080047
Daniel Walker16c63f82010-11-30 11:25:39 -080048static inline void __dcc_putchar(char c)
49{
Stephen Boyda9963202011-02-03 15:48:34 -080050 asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
Daniel Walker16c63f82010-11-30 11:25:39 -080051 : /* no output register */
52 : "r" (c));
53}
Daniel Walker16c63f82010-11-30 11:25:39 -080054
55static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
56{
57 int i;
58
59 for (i = 0; i < count; i++) {
60 while (__dcc_getstatus() & DCC_STATUS_TX)
61 cpu_relax();
62
Stephen Boydbf73bd32011-02-03 15:48:35 -080063 __dcc_putchar(buf[i]);
Daniel Walker16c63f82010-11-30 11:25:39 -080064 }
65
66 return count;
67}
68
69static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
70{
71 int i;
72
Stephen Boydbf73bd32011-02-03 15:48:35 -080073 for (i = 0; i < count; ++i)
Daniel Walker16c63f82010-11-30 11:25:39 -080074 if (__dcc_getstatus() & DCC_STATUS_RX)
Stephen Boydbf73bd32011-02-03 15:48:35 -080075 buf[i] = __dcc_getchar();
76 else
Daniel Walker16c63f82010-11-30 11:25:39 -080077 break;
Daniel Walker16c63f82010-11-30 11:25:39 -080078
79 return i;
80}
81
82static const struct hv_ops hvc_dcc_get_put_ops = {
83 .get_chars = hvc_dcc_get_chars,
84 .put_chars = hvc_dcc_put_chars,
85};
86
87static int __init hvc_dcc_console_init(void)
88{
89 hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
90 return 0;
91}
92console_initcall(hvc_dcc_console_init);
93
94static int __init hvc_dcc_init(void)
95{
96 hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
97 return 0;
98}
99device_initcall(hvc_dcc_init);