Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 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> |
| 34 | #include <asm/hvconsole.h> |
| 35 | #include <asm/vio.h> |
| 36 | #include <asm/prom.h> |
| 37 | |
| 38 | char hvc_driver_name[] = "hvc_console"; |
| 39 | |
| 40 | static struct vio_device_id hvc_driver_table[] __devinitdata = { |
| 41 | {"serial", "hvterm1"}, |
| 42 | { NULL, } |
| 43 | }; |
| 44 | MODULE_DEVICE_TABLE(vio, hvc_driver_table); |
| 45 | |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame^] | 46 | static struct hv_ops hvc_get_put_ops = { |
| 47 | .get_chars = hvc_get_chars, |
| 48 | .put_chars = hvc_put_chars, |
| 49 | }; |
| 50 | |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 51 | static int __devinit hvc_vio_probe(struct vio_dev *vdev, |
| 52 | const struct vio_device_id *id) |
| 53 | { |
| 54 | struct hvc_struct *hp; |
| 55 | |
| 56 | /* probed with invalid parameters. */ |
| 57 | if (!vdev || !id) |
| 58 | return -EPERM; |
| 59 | |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame^] | 60 | hp = hvc_alloc(vdev->unit_address, vdev->irq, &hvc_get_put_ops); |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 61 | if (IS_ERR(hp)) |
| 62 | return PTR_ERR(hp); |
| 63 | dev_set_drvdata(&vdev->dev, hp); |
| 64 | |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | static int __devexit hvc_vio_remove(struct vio_dev *vdev) |
| 69 | { |
| 70 | struct hvc_struct *hp = dev_get_drvdata(&vdev->dev); |
| 71 | |
| 72 | return hvc_remove(hp); |
| 73 | } |
| 74 | |
| 75 | static struct vio_driver hvc_vio_driver = { |
| 76 | .name = hvc_driver_name, |
| 77 | .id_table = hvc_driver_table, |
| 78 | .probe = hvc_vio_probe, |
| 79 | .remove = hvc_vio_remove, |
| 80 | .driver = { |
| 81 | .owner = THIS_MODULE, |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | static int hvc_vio_init(void) |
| 86 | { |
| 87 | int rc; |
| 88 | |
| 89 | /* Register as a vio device to receive callbacks */ |
| 90 | rc = vio_register_driver(&hvc_vio_driver); |
| 91 | |
| 92 | return rc; |
| 93 | } |
| 94 | module_init(hvc_vio_init); /* after drivers/char/hvc_console.c */ |
| 95 | |
| 96 | static void hvc_vio_exit(void) |
| 97 | { |
| 98 | vio_unregister_driver(&hvc_vio_driver); |
| 99 | } |
| 100 | module_exit(hvc_vio_exit); |
| 101 | |
| 102 | /* the device tree order defines our numbering */ |
| 103 | static int hvc_find_vtys(void) |
| 104 | { |
| 105 | struct device_node *vty; |
| 106 | int num_found = 0; |
| 107 | |
| 108 | for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL; |
| 109 | vty = of_find_node_by_name(vty, "vty")) { |
| 110 | uint32_t *vtermno; |
| 111 | |
| 112 | /* We have statically defined space for only a certain number |
| 113 | * of console adapters. |
| 114 | */ |
| 115 | if (num_found >= MAX_NR_HVC_CONSOLES) |
| 116 | break; |
| 117 | |
| 118 | vtermno = (uint32_t *)get_property(vty, "reg", NULL); |
| 119 | if (!vtermno) |
| 120 | continue; |
| 121 | |
| 122 | if (device_is_compatible(vty, "hvterm1")) { |
Milton Miller | 030ffad | 2005-07-07 17:56:25 -0700 | [diff] [blame^] | 123 | hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops); |
Milton Miller | acad955 | 2005-07-07 17:56:24 -0700 | [diff] [blame] | 124 | ++num_found; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return num_found; |
| 129 | } |
| 130 | console_initcall(hvc_find_vtys); |