Commit | Line | Data |
---|---|---|
acad9559 MM |
1 | /* |
2 | * vio driver interface to hvc_console.c | |
3 | * | |
4 | * This code was moved here to allow the remaing code to be reused as a | |
5 | * generic polling mode with semi-reliable transport driver core to the | |
6 | * console and tty subsystems. | |
7 | * | |
8 | * | |
9 | * Copyright (C) 2001 Anton Blanchard <anton@au.ibm.com>, IBM | |
10 | * Copyright (C) 2001 Paul Mackerras <paulus@au.ibm.com>, IBM | |
11 | * Copyright (C) 2004 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp. | |
12 | * Copyright (C) 2004 IBM Corporation | |
13 | * | |
14 | * Additional Author(s): | |
15 | * Ryan S. Arnold <rsa@us.ibm.com> | |
16 | * | |
17 | * This program is free software; you can redistribute it and/or modify | |
18 | * it under the terms of the GNU General Public License as published by | |
19 | * the Free Software Foundation; either version 2 of the License, or | |
20 | * (at your option) any later version. | |
21 | * | |
22 | * This program is distributed in the hope that it will be useful, | |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 | * GNU General Public License for more details. | |
26 | * | |
27 | * You should have received a copy of the GNU General Public License | |
28 | * along with this program; if not, write to the Free Software | |
29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
30 | */ | |
31 | ||
32 | #include <linux/types.h> | |
33 | #include <linux/init.h> | |
45d607ed | 34 | |
acad9559 MM |
35 | #include <asm/hvconsole.h> |
36 | #include <asm/vio.h> | |
37 | #include <asm/prom.h> | |
de0138da | 38 | #include <asm/firmware.h> |
acad9559 | 39 | |
45d607ed RA |
40 | #include "hvc_console.h" |
41 | ||
acad9559 MM |
42 | char hvc_driver_name[] = "hvc_console"; |
43 | ||
44 | static struct vio_device_id hvc_driver_table[] __devinitdata = { | |
45 | {"serial", "hvterm1"}, | |
fb120da6 | 46 | { "", "" } |
acad9559 MM |
47 | }; |
48 | MODULE_DEVICE_TABLE(vio, hvc_driver_table); | |
49 | ||
70b234a4 MM |
50 | static int filtered_get_chars(uint32_t vtermno, char *buf, int count) |
51 | { | |
52 | unsigned long got; | |
53 | int i; | |
54 | ||
45d607ed RA |
55 | /* |
56 | * Vio firmware will read up to SIZE_VIO_GET_CHARS at its own discretion | |
57 | * so we play safe and avoid the situation where got > count which could | |
58 | * overload the flip buffer. | |
59 | */ | |
60 | if (count < SIZE_VIO_GET_CHARS) | |
61 | return -EAGAIN; | |
62 | ||
70b234a4 MM |
63 | got = hvc_get_chars(vtermno, buf, count); |
64 | ||
65 | /* | |
66 | * Work around a HV bug where it gives us a null | |
67 | * after every \r. -- paulus | |
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 | ||
030ffad2 | 80 | static struct hv_ops hvc_get_put_ops = { |
70b234a4 | 81 | .get_chars = filtered_get_chars, |
030ffad2 MM |
82 | .put_chars = hvc_put_chars, |
83 | }; | |
84 | ||
acad9559 MM |
85 | static int __devinit hvc_vio_probe(struct vio_dev *vdev, |
86 | const struct vio_device_id *id) | |
87 | { | |
88 | struct hvc_struct *hp; | |
89 | ||
90 | /* probed with invalid parameters. */ | |
91 | if (!vdev || !id) | |
92 | return -EPERM; | |
93 | ||
4e9e95a3 SR |
94 | hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops, |
95 | MAX_VIO_PUT_CHARS); | |
acad9559 MM |
96 | if (IS_ERR(hp)) |
97 | return PTR_ERR(hp); | |
98 | dev_set_drvdata(&vdev->dev, hp); | |
99 | ||
100 | return 0; | |
101 | } | |
102 | ||
103 | static int __devexit hvc_vio_remove(struct vio_dev *vdev) | |
104 | { | |
105 | struct hvc_struct *hp = dev_get_drvdata(&vdev->dev); | |
106 | ||
107 | return hvc_remove(hp); | |
108 | } | |
109 | ||
110 | static struct vio_driver hvc_vio_driver = { | |
acad9559 MM |
111 | .id_table = hvc_driver_table, |
112 | .probe = hvc_vio_probe, | |
113 | .remove = hvc_vio_remove, | |
114 | .driver = { | |
6fdf5392 | 115 | .name = hvc_driver_name, |
acad9559 MM |
116 | .owner = THIS_MODULE, |
117 | } | |
118 | }; | |
119 | ||
120 | static int hvc_vio_init(void) | |
121 | { | |
122 | int rc; | |
123 | ||
de0138da SR |
124 | if (firmware_has_feature(FW_FEATURE_ISERIES)) |
125 | return -EIO; | |
126 | ||
acad9559 MM |
127 | /* Register as a vio device to receive callbacks */ |
128 | rc = vio_register_driver(&hvc_vio_driver); | |
129 | ||
130 | return rc; | |
131 | } | |
132 | module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */ | |
133 | ||
134 | static void hvc_vio_exit(void) | |
135 | { | |
136 | vio_unregister_driver(&hvc_vio_driver); | |
137 | } | |
138 | module_exit(hvc_vio_exit); | |
139 | ||
140 | /* the device tree order defines our numbering */ | |
141 | static int hvc_find_vtys(void) | |
142 | { | |
143 | struct device_node *vty; | |
144 | int num_found = 0; | |
145 | ||
146 | for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL; | |
147 | vty = of_find_node_by_name(vty, "vty")) { | |
954a46e2 | 148 | const uint32_t *vtermno; |
acad9559 MM |
149 | |
150 | /* We have statically defined space for only a certain number | |
151 | * of console adapters. | |
152 | */ | |
153 | if (num_found >= MAX_NR_HVC_CONSOLES) | |
154 | break; | |
155 | ||
01b2726d | 156 | vtermno = of_get_property(vty, "reg", NULL); |
acad9559 MM |
157 | if (!vtermno) |
158 | continue; | |
159 | ||
55b61fec | 160 | if (of_device_is_compatible(vty, "hvterm1")) { |
030ffad2 | 161 | hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops); |
acad9559 MM |
162 | ++num_found; |
163 | } | |
164 | } | |
165 | ||
166 | return num_found; | |
167 | } | |
168 | console_initcall(hvc_find_vtys); |