hvc_dcc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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("mrc p14, 0, %0, c0, c1, 0 @ read comms ctrl reg"
  32. : "=r" (__ret) : : "cc");
  33. return __ret;
  34. }
  35. #if defined(CONFIG_CPU_V7)
  36. static inline char __dcc_getchar(void)
  37. {
  38. char __c;
  39. asm("get_wait: mrc p14, 0, pc, c0, c1, 0 \n\
  40. bne get_wait \n\
  41. mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
  42. : "=r" (__c) : : "cc");
  43. return __c;
  44. }
  45. #else
  46. static inline char __dcc_getchar(void)
  47. {
  48. char __c;
  49. asm("mrc p14, 0, %0, c0, c5, 0 @ read comms data reg"
  50. : "=r" (__c));
  51. return __c;
  52. }
  53. #endif
  54. #if defined(CONFIG_CPU_V7)
  55. static inline void __dcc_putchar(char c)
  56. {
  57. asm("put_wait: mrc p14, 0, pc, c0, c1, 0 \n\
  58. bcs put_wait \n\
  59. mcr p14, 0, %0, c0, c5, 0 "
  60. : : "r" (c) : "cc");
  61. }
  62. #else
  63. static inline void __dcc_putchar(char c)
  64. {
  65. asm("mcr p14, 0, %0, c0, c5, 0 @ write a char"
  66. : /* no output register */
  67. : "r" (c));
  68. }
  69. #endif
  70. static int hvc_dcc_put_chars(uint32_t vt, const char *buf, int count)
  71. {
  72. int i;
  73. for (i = 0; i < count; i++) {
  74. while (__dcc_getstatus() & DCC_STATUS_TX)
  75. cpu_relax();
  76. __dcc_putchar((char)(buf[i] & 0xFF));
  77. }
  78. return count;
  79. }
  80. static int hvc_dcc_get_chars(uint32_t vt, char *buf, int count)
  81. {
  82. int i;
  83. for (i = 0; i < count; ++i) {
  84. int c = -1;
  85. if (__dcc_getstatus() & DCC_STATUS_RX)
  86. c = __dcc_getchar();
  87. if (c < 0)
  88. break;
  89. buf[i] = c;
  90. }
  91. return i;
  92. }
  93. static const struct hv_ops hvc_dcc_get_put_ops = {
  94. .get_chars = hvc_dcc_get_chars,
  95. .put_chars = hvc_dcc_put_chars,
  96. };
  97. static int __init hvc_dcc_console_init(void)
  98. {
  99. hvc_instantiate(0, 0, &hvc_dcc_get_put_ops);
  100. return 0;
  101. }
  102. console_initcall(hvc_dcc_console_init);
  103. static int __init hvc_dcc_init(void)
  104. {
  105. hvc_alloc(0, 0, &hvc_dcc_get_put_ops, 128);
  106. return 0;
  107. }
  108. device_initcall(hvc_dcc_init);