arm_dcc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (C) 2004-2007 ARM Limited.
  3. * Copyright (C) 2008 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License version 2
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. * As a special exception, if other files instantiate templates or use macros
  19. * or inline functions from this file, or you compile this file and link it
  20. * with other works to produce a work based on this file, this file does not
  21. * by itself cause the resulting work to be covered by the GNU General Public
  22. * License. However the source code for this file must still be made available
  23. * in accordance with section (3) of the GNU General Public License.
  24. * This exception does not invalidate any other reasons why a work based on
  25. * this file might be covered by the GNU General Public License.
  26. */
  27. #include <common.h>
  28. #include <serial.h>
  29. #if defined(CONFIG_CPU_V6)
  30. /*
  31. * ARMV6
  32. */
  33. #define DCC_RBIT (1 << 30)
  34. #define DCC_WBIT (1 << 29)
  35. #define write_dcc(x) \
  36. __asm__ volatile ("mcr p14, 0, %0, c0, c5, 0\n" : : "r" (x))
  37. #define read_dcc(x) \
  38. __asm__ volatile ("mrc p14, 0, %0, c0, c5, 0\n" : "=r" (x))
  39. #define status_dcc(x) \
  40. __asm__ volatile ("mrc p14, 0, %0, c0, c1, 0\n" : "=r" (x))
  41. #elif defined(CONFIG_CPU_XSCALE)
  42. /*
  43. * XSCALE
  44. */
  45. #define DCC_RBIT (1 << 31)
  46. #define DCC_WBIT (1 << 28)
  47. #define write_dcc(x) \
  48. __asm__ volatile ("mcr p14, 0, %0, c8, c0, 0\n" : : "r" (x))
  49. #define read_dcc(x) \
  50. __asm__ volatile ("mrc p14, 0, %0, c9, c0, 0\n" : "=r" (x))
  51. #define status_dcc(x) \
  52. __asm__ volatile ("mrc p14, 0, %0, c14, c0, 0\n" : "=r" (x))
  53. #else
  54. #define DCC_RBIT (1 << 0)
  55. #define DCC_WBIT (1 << 1)
  56. #define write_dcc(x) \
  57. __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
  58. #define read_dcc(x) \
  59. __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
  60. #define status_dcc(x) \
  61. __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
  62. #endif
  63. #define can_read_dcc(x) do { \
  64. status_dcc(x); \
  65. x &= DCC_RBIT; \
  66. } while (0);
  67. #define can_write_dcc(x) do { \
  68. status_dcc(x); \
  69. x &= DCC_WBIT; \
  70. x = (x == 0); \
  71. } while (0);
  72. #define TIMEOUT_COUNT 0x4000000
  73. static int arm_dcc_init(void)
  74. {
  75. return 0;
  76. }
  77. static int arm_dcc_getc(void)
  78. {
  79. int ch;
  80. register unsigned int reg;
  81. do {
  82. can_read_dcc(reg);
  83. } while (!reg);
  84. read_dcc(ch);
  85. return ch;
  86. }
  87. static void arm_dcc_putc(char ch)
  88. {
  89. register unsigned int reg;
  90. unsigned int timeout_count = TIMEOUT_COUNT;
  91. while (--timeout_count) {
  92. can_write_dcc(reg);
  93. if (reg)
  94. break;
  95. }
  96. if (timeout_count == 0)
  97. return;
  98. else
  99. write_dcc(ch);
  100. }
  101. static int arm_dcc_tstc(void)
  102. {
  103. register unsigned int reg;
  104. can_read_dcc(reg);
  105. return reg;
  106. }
  107. static void arm_dcc_setbrg(void)
  108. {
  109. }
  110. static struct serial_device arm_dcc_drv = {
  111. .name = "arm_dcc",
  112. .start = arm_dcc_init,
  113. .stop = NULL,
  114. .setbrg = arm_dcc_setbrg,
  115. .putc = arm_dcc_putc,
  116. .puts = default_serial_puts,
  117. .getc = arm_dcc_getc,
  118. .tstc = arm_dcc_tstc,
  119. };
  120. void arm_dcc_initialize(void)
  121. {
  122. serial_register(&arm_dcc_drv);
  123. }
  124. __weak struct serial_device *default_serial_console(void)
  125. {
  126. return &arm_dcc_drv;
  127. }