blob: 02a64be692da35579113d845da87832e5c895e13 [file] [log] [blame]
Duy Truonge833aca2013-02-12 13:35:08 -08001/* Copyright (c) 2010, The Linux Foundation. All rights reserved.
Daniel Walker16c63f82010-11-30 11:25:39 -08002 *
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));
Stephen Boyd5e3092b2011-10-25 19:19:43 -070044 isb();
Daniel Walker16c63f82010-11-30 11:25:39 -080045
46 return __c;
47}
Daniel Walker16c63f82010-11-30 11:25:39 -080048
Daniel Walker16c63f82010-11-30 11:25:39 -080049static inline void __dcc_putchar(char c)
50{
Stephen Boyda9963202011-02-03 15:48:34 -080051 asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
Daniel Walker16c63f82010-11-30 11:25:39 -080052 : /* no output register */
53 : "r" (c));
Stephen Boyd5e3092b2011-10-25 19:19:43 -070054 isb();
Daniel Walker16c63f82010-11-30 11:25:39 -080055}
Daniel Walker16c63f82010-11-30 11:25:39 -080056
57static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
58{
59 int i;
60
61 for (i = 0; i < count; i++) {
62 while (__dcc_getstatus() & DCC_STATUS_TX)
63 cpu_relax();
64
Stephen Boydbf73bd32011-02-03 15:48:35 -080065 __dcc_putchar(buf[i]);
Daniel Walker16c63f82010-11-30 11:25:39 -080066 }
67
68 return count;
69}
70
71static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
72{
73 int i;
74
Stephen Boydbf73bd32011-02-03 15:48:35 -080075 for (i = 0; i < count; ++i)
Daniel Walker16c63f82010-11-30 11:25:39 -080076 if (__dcc_getstatus() & DCC_STATUS_RX)
Stephen Boydbf73bd32011-02-03 15:48:35 -080077 buf[i] = __dcc_getchar();
78 else
Daniel Walker16c63f82010-11-30 11:25:39 -080079 break;
Daniel Walker16c63f82010-11-30 11:25:39 -080080
81 return i;
82}
83
84static const struct hv_ops hvc_dcc_get_put_ops = {
85 .get_chars = hvc_dcc_get_chars,
86 .put_chars = hvc_dcc_put_chars,
87};
88
89static int __init hvc_dcc_console_init(void)
90{
91 hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
92 return 0;
93}
94console_initcall(hvc_dcc_console_init);
95
96static int __init hvc_dcc_init(void)
97{
98 hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
99 return 0;
100}
101device_initcall(hvc_dcc_init);