2 * vio driver interface to hvc_console.c
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.
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
14 * Additional Author(s):
15 * Ryan S. Arnold <rsa@us.ibm.com>
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.
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.
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
32 #include <linux/types.h>
33 #include <linux/init.h>
35 #include <asm/hvconsole.h>
38 #include <asm/firmware.h>
40 #include "hvc_console.h"
42 char hvc_driver_name
[] = "hvc_console";
44 static struct vio_device_id hvc_driver_table
[] __devinitdata
= {
45 {"serial", "hvterm1"},
48 MODULE_DEVICE_TABLE(vio
, hvc_driver_table
);
50 static int filtered_get_chars(uint32_t vtermno
, char *buf
, int count
)
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.
60 if (count
< SIZE_VIO_GET_CHARS
)
63 got
= hvc_get_chars(vtermno
, buf
, count
);
66 * Work around a HV bug where it gives us a null
67 * after every \r. -- paulus
69 for (i
= 1; i
< got
; ++i
) {
70 if (buf
[i
] == 0 && buf
[i
-1] == '\r') {
73 memmove(&buf
[i
], &buf
[i
+1],
80 static 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
,
88 static int __devinit
hvc_vio_probe(struct vio_dev
*vdev
,
89 const struct vio_device_id
*id
)
91 struct hvc_struct
*hp
;
93 /* probed with invalid parameters. */
97 hp
= hvc_alloc(vdev
->unit_address
, vdev
->irq
, &hvc_get_put_ops
,
101 dev_set_drvdata(&vdev
->dev
, hp
);
106 static int __devexit
hvc_vio_remove(struct vio_dev
*vdev
)
108 struct hvc_struct
*hp
= dev_get_drvdata(&vdev
->dev
);
110 return hvc_remove(hp
);
113 static struct vio_driver hvc_vio_driver
= {
114 .id_table
= hvc_driver_table
,
115 .probe
= hvc_vio_probe
,
116 .remove
= hvc_vio_remove
,
118 .name
= hvc_driver_name
,
119 .owner
= THIS_MODULE
,
123 static int hvc_vio_init(void)
127 if (firmware_has_feature(FW_FEATURE_ISERIES
))
130 /* Register as a vio device to receive callbacks */
131 rc
= vio_register_driver(&hvc_vio_driver
);
135 module_init(hvc_vio_init
); /* after drivers/char/hvc_console.c */
137 static void hvc_vio_exit(void)
139 vio_unregister_driver(&hvc_vio_driver
);
141 module_exit(hvc_vio_exit
);
143 /* the device tree order defines our numbering */
144 static int hvc_find_vtys(void)
146 struct device_node
*vty
;
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
;
153 /* We have statically defined space for only a certain number
154 * of console adapters.
156 if (num_found
>= MAX_NR_HVC_CONSOLES
) {
161 vtermno
= of_get_property(vty
, "reg", NULL
);
165 if (of_device_is_compatible(vty
, "hvterm1")) {
166 hvc_instantiate(*vtermno
, num_found
, &hvc_get_put_ops
);
173 console_initcall(hvc_find_vtys
);