hvc_udbg.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * udbg interface to hvc_console.c
  3. *
  4. * (C) Copyright David Gibson, IBM Corporation 2008.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/console.h>
  21. #include <linux/delay.h>
  22. #include <linux/err.h>
  23. #include <linux/init.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/types.h>
  26. #include <linux/irq.h>
  27. #include <asm/udbg.h>
  28. #include "hvc_console.h"
  29. struct hvc_struct *hvc_udbg_dev;
  30. static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
  31. {
  32. int i;
  33. for (i = 0; i < count && udbg_putc; i++)
  34. udbg_putc(buf[i]);
  35. return i;
  36. }
  37. static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
  38. {
  39. int i, c;
  40. if (!udbg_getc_poll)
  41. return 0;
  42. for (i = 0; i < count; i++) {
  43. if ((c = udbg_getc_poll()) == -1)
  44. break;
  45. buf[i] = c;
  46. }
  47. return i;
  48. }
  49. static const struct hv_ops hvc_udbg_ops = {
  50. .get_chars = hvc_udbg_get,
  51. .put_chars = hvc_udbg_put,
  52. };
  53. static int __init hvc_udbg_init(void)
  54. {
  55. struct hvc_struct *hp;
  56. if (!udbg_putc)
  57. return -ENODEV;
  58. BUG_ON(hvc_udbg_dev);
  59. hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16);
  60. if (IS_ERR(hp))
  61. return PTR_ERR(hp);
  62. hvc_udbg_dev = hp;
  63. return 0;
  64. }
  65. device_initcall(hvc_udbg_init);
  66. static int __init hvc_udbg_console_init(void)
  67. {
  68. if (!udbg_putc)
  69. return -ENODEV;
  70. hvc_instantiate(0, 0, &hvc_udbg_ops);
  71. add_preferred_console("hvc", 0, NULL);
  72. return 0;
  73. }
  74. console_initcall(hvc_udbg_console_init);