1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include <linux/types.h>
33#include <linux/init.h>
34
35#include <asm/hvconsole.h>
36#include <asm/vio.h>
37#include <asm/prom.h>
38#include <asm/firmware.h>
39
40#include "hvc_console.h"
41
42char hvc_driver_name[] = "hvc_console";
43
44static struct vio_device_id hvc_driver_table[] __devinitdata = {
45 {"serial", "hvterm1"},
46 { "", "" }
47};
48MODULE_DEVICE_TABLE(vio, hvc_driver_table);
49
50static int filtered_get_chars(uint32_t vtermno, char *buf, int count)
51{
52 unsigned long got;
53 int i;
54
55
56
57
58
59
60 if (count < SIZE_VIO_GET_CHARS)
61 return -EAGAIN;
62
63 got = hvc_get_chars(vtermno, buf, count);
64
65
66
67
68
69 for (i = 1; i < got; ++i) {
70 if (buf[i] == 0 && buf[i-1] == '\r') {
71 --got;
72 if (i < got)
73 memmove(&buf[i], &buf[i+1],
74 got - i);
75 }
76 }
77 return got;
78}
79
80static struct hv_ops hvc_get_put_ops = {
81 .get_chars = filtered_get_chars,
82 .put_chars = hvc_put_chars,
83 .notifier_add = notifier_add_irq,
84 .notifier_del = notifier_del_irq,
85 .notifier_hangup = notifier_hangup_irq,
86};
87
88static int __devinit hvc_vio_probe(struct vio_dev *vdev,
89 const struct vio_device_id *id)
90{
91 struct hvc_struct *hp;
92
93
94 if (!vdev || !id)
95 return -EPERM;
96
97 hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops,
98 MAX_VIO_PUT_CHARS);
99 if (IS_ERR(hp))
100 return PTR_ERR(hp);
101 dev_set_drvdata(&vdev->dev, hp);
102
103 return 0;
104}
105
106static int __devexit hvc_vio_remove(struct vio_dev *vdev)
107{
108 struct hvc_struct *hp = dev_get_drvdata(&vdev->dev);
109
110 return hvc_remove(hp);
111}
112
113static struct vio_driver hvc_vio_driver = {
114 .id_table = hvc_driver_table,
115 .probe = hvc_vio_probe,
116 .remove = __devexit_p(hvc_vio_remove),
117 .driver = {
118 .name = hvc_driver_name,
119 .owner = THIS_MODULE,
120 }
121};
122
123static int __init hvc_vio_init(void)
124{
125 int rc;
126
127 if (firmware_has_feature(FW_FEATURE_ISERIES))
128 return -EIO;
129
130
131 rc = vio_register_driver(&hvc_vio_driver);
132
133 return rc;
134}
135module_init(hvc_vio_init);
136
137static void __exit hvc_vio_exit(void)
138{
139 vio_unregister_driver(&hvc_vio_driver);
140}
141module_exit(hvc_vio_exit);
142
143
144static int hvc_find_vtys(void)
145{
146 struct device_node *vty;
147 int num_found = 0;
148
149 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
150 vty = of_find_node_by_name(vty, "vty")) {
151 const uint32_t *vtermno;
152
153
154
155
156 if (num_found >= MAX_NR_HVC_CONSOLES) {
157 of_node_put(vty);
158 break;
159 }
160
161 vtermno = of_get_property(vty, "reg", NULL);
162 if (!vtermno)
163 continue;
164
165 if (of_device_is_compatible(vty, "hvterm1")) {
166 hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
167 ++num_found;
168 }
169 }
170
171 return num_found;
172}
173console_initcall(hvc_find_vtys);
174