hvc_dcc.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. */
  17. #include <linux/console.h>
  18. #include <linux/delay.h>
  19. #include <linux/err.h>
  20. #include <linux/init.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/types.h>
  23. #include <asm/processor.h>
  24. #include "hvc_console.h"
  25. /* DCC Status Bits */
  26. #define DCC_STATUS_RX (1 << 30)
  27. #define DCC_STATUS_TX (1 << 29)
  28. static inline u32 __dcc_getstatus(void)
  29. {
  30. u32 __ret;
  31. asm volatile("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
  32. : "=r" (__ret) : : "cc");
  33. return __ret;
  34. }
  35. static inline char __dcc_getchar(void)
  36. {
  37. char __c;
  38. asm volatile("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
  39. : "=r" (__c));
  40. return __c;
  41. }
  42. static inline void __dcc_putchar(char c)
  43. {
  44. asm volatile("mcr p14, 0, %0, c0, c5, 0 @ write a char"
  45. : /* no output register */
  46. : "r" (c));
  47. }
  48. static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
  49. {
  50. int i;
  51. for (i = 0; i < count; i++) {
  52. while (__dcc_getstatus() & DCC_STATUS_TX)
  53. cpu_relax();
  54. __dcc_putchar(buf[i]);
  55. }
  56. return count;
  57. }
  58. static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
  59. {
  60. int i;
  61. for (i = 0; i < count; ++i)
  62. if (__dcc_getstatus() & DCC_STATUS_RX)
  63. buf[i] = __dcc_getchar();
  64. else
  65. break;
  66. return i;
  67. }
  68. static const struct hv_ops hvc_dcc_get_put_ops = {
  69. .get_chars = hvc_dcc_get_chars,
  70. .put_chars = hvc_dcc_put_chars,
  71. };
  72. static int __init hvc_dcc_console_init(void)
  73. {
  74. hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
  75. return 0;
  76. }
  77. console_initcall(hvc_dcc_console_init);
  78. static int __init hvc_dcc_init(void)
  79. {
  80. hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
  81. return 0;
  82. }
  83. device_initcall(hvc_dcc_init);