tty: hvc: Remove redundant license text
[linux/fpc-iii.git] / drivers / tty / hvc / hvc_tile.c
blobb517c0661abb509f52d4c73008d31a21ea10d5c2
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2010 Tilera Corporation. All Rights Reserved.
5 * Tilera TILE Processor hypervisor console
6 */
8 #include <linux/console.h>
9 #include <linux/delay.h>
10 #include <linux/err.h>
11 #include <linux/init.h>
12 #include <linux/interrupt.h>
13 #include <linux/irq.h>
14 #include <linux/moduleparam.h>
15 #include <linux/platform_device.h>
16 #include <linux/types.h>
18 #include <asm/setup.h>
19 #include <arch/sim_def.h>
21 #include <hv/hypervisor.h>
23 #include "hvc_console.h"
25 static int use_sim_console;
26 static int __init sim_console(char *str)
28 use_sim_console = 1;
29 return 0;
31 early_param("sim_console", sim_console);
33 int tile_console_write(const char *buf, int count)
35 if (unlikely(use_sim_console)) {
36 int i;
37 for (i = 0; i < count; ++i)
38 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
39 (buf[i] << _SIM_CONTROL_OPERATOR_BITS));
40 __insn_mtspr(SPR_SIM_CONTROL, SIM_CONTROL_PUTC |
41 (SIM_PUTC_FLUSH_BINARY <<
42 _SIM_CONTROL_OPERATOR_BITS));
43 return 0;
44 } else {
45 /* Translate 0 bytes written to EAGAIN for hvc_console_print. */
46 return hv_console_write((HV_VirtAddr)buf, count) ?: -EAGAIN;
50 static int hvc_tile_put_chars(uint32_t vt, const char *buf, int count)
52 return tile_console_write(buf, count);
55 static int hvc_tile_get_chars(uint32_t vt, char *buf, int count)
57 int i, c;
59 for (i = 0; i < count; ++i) {
60 c = hv_console_read_if_ready();
61 if (c < 0)
62 break;
63 buf[i] = c;
66 return i;
69 #ifdef __tilegx__
71 * IRQ based callbacks.
73 static int hvc_tile_notifier_add_irq(struct hvc_struct *hp, int irq)
75 int rc;
76 int cpu = raw_smp_processor_id(); /* Choose an arbitrary cpu */
77 HV_Coord coord = { .x = cpu_x(cpu), .y = cpu_y(cpu) };
79 rc = notifier_add_irq(hp, irq);
80 if (rc)
81 return rc;
84 * Request that the hypervisor start sending us interrupts.
85 * If the hypervisor returns an error, we still return 0, so that
86 * we can fall back to polling.
88 if (hv_console_set_ipi(KERNEL_PL, irq, coord) < 0)
89 notifier_del_irq(hp, irq);
91 return 0;
94 static void hvc_tile_notifier_del_irq(struct hvc_struct *hp, int irq)
96 HV_Coord coord = { 0, 0 };
98 /* Tell the hypervisor to stop sending us interrupts. */
99 hv_console_set_ipi(KERNEL_PL, -1, coord);
101 notifier_del_irq(hp, irq);
104 static void hvc_tile_notifier_hangup_irq(struct hvc_struct *hp, int irq)
106 hvc_tile_notifier_del_irq(hp, irq);
108 #endif
110 static const struct hv_ops hvc_tile_get_put_ops = {
111 .get_chars = hvc_tile_get_chars,
112 .put_chars = hvc_tile_put_chars,
113 #ifdef __tilegx__
114 .notifier_add = hvc_tile_notifier_add_irq,
115 .notifier_del = hvc_tile_notifier_del_irq,
116 .notifier_hangup = hvc_tile_notifier_hangup_irq,
117 #endif
121 #ifdef __tilegx__
122 static int hvc_tile_probe(struct platform_device *pdev)
124 struct hvc_struct *hp;
125 int tile_hvc_irq;
127 /* Create our IRQ and register it. */
128 tile_hvc_irq = irq_alloc_hwirq(-1);
129 if (!tile_hvc_irq)
130 return -ENXIO;
132 tile_irq_activate(tile_hvc_irq, TILE_IRQ_PERCPU);
133 hp = hvc_alloc(0, tile_hvc_irq, &hvc_tile_get_put_ops, 128);
134 if (IS_ERR(hp)) {
135 irq_free_hwirq(tile_hvc_irq);
136 return PTR_ERR(hp);
138 dev_set_drvdata(&pdev->dev, hp);
140 return 0;
143 static int hvc_tile_remove(struct platform_device *pdev)
145 int rc;
146 struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
148 rc = hvc_remove(hp);
149 if (rc == 0)
150 irq_free_hwirq(hp->data);
152 return rc;
155 static void hvc_tile_shutdown(struct platform_device *pdev)
157 struct hvc_struct *hp = dev_get_drvdata(&pdev->dev);
159 hvc_tile_notifier_del_irq(hp, hp->data);
162 static struct platform_device hvc_tile_pdev = {
163 .name = "hvc-tile",
164 .id = 0,
167 static struct platform_driver hvc_tile_driver = {
168 .probe = hvc_tile_probe,
169 .remove = hvc_tile_remove,
170 .shutdown = hvc_tile_shutdown,
171 .driver = {
172 .name = "hvc-tile",
175 #endif
177 static int __init hvc_tile_console_init(void)
179 hvc_instantiate(0, 0, &hvc_tile_get_put_ops);
180 add_preferred_console("hvc", 0, NULL);
181 return 0;
183 console_initcall(hvc_tile_console_init);
185 static int __init hvc_tile_init(void)
187 #ifndef __tilegx__
188 struct hvc_struct *hp;
189 hp = hvc_alloc(0, 0, &hvc_tile_get_put_ops, 128);
190 return PTR_ERR_OR_ZERO(hp);
191 #else
192 platform_device_register(&hvc_tile_pdev);
193 return platform_driver_register(&hvc_tile_driver);
194 #endif
196 device_initcall(hvc_tile_init);