Linux 4.1.16
[linux/fpc-iii.git] / drivers / tty / hvc / hvc_dcc.c
blob809920d80a66da7c08f8cd653451fa2fdcec636e
1 /* Copyright (c) 2010, 2014 The Linux Foundation. All rights reserved.
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.
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.
13 #include <linux/init.h>
15 #include <asm/dcc.h>
16 #include <asm/processor.h>
18 #include "hvc_console.h"
20 /* DCC Status Bits */
21 #define DCC_STATUS_RX (1 << 30)
22 #define DCC_STATUS_TX (1 << 29)
24 static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
26 int i;
28 for (i = 0; i < count; i++) {
29 while (__dcc_getstatus() & DCC_STATUS_TX)
30 cpu_relax();
32 __dcc_putchar(buf[i]);
35 return count;
38 static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
40 int i;
42 for (i = 0; i < count; ++i)
43 if (__dcc_getstatus() & DCC_STATUS_RX)
44 buf[i] = __dcc_getchar();
45 else
46 break;
48 return i;
51 static bool hvc_dcc_check(void)
53 unsigned long time = jiffies + (HZ / 10);
55 /* Write a test character to check if it is handled */
56 __dcc_putchar('\n');
58 while (time_is_after_jiffies(time)) {
59 if (!(__dcc_getstatus() & DCC_STATUS_TX))
60 return true;
63 return false;
66 static const struct hv_ops hvc_dcc_get_put_ops = {
67 .get_chars = hvc_dcc_get_chars,
68 .put_chars = hvc_dcc_put_chars,
71 static int __init hvc_dcc_console_init(void)
73 if (!hvc_dcc_check())
74 return -ENODEV;
76 hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
77 return 0;
79 console_initcall(hvc_dcc_console_init);
81 static int __init hvc_dcc_init(void)
83 if (!hvc_dcc_check())
84 return -ENODEV;
86 hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
87 return 0;
89 device_initcall(hvc_dcc_init);