hvc_vio.c 3.3 KB

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