arm_dcc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 <devices.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. #ifndef CONFIG_ARM_DCC_MULTI
  74. #define arm_dcc_init serial_init
  75. void serial_setbrg(void) {}
  76. #define arm_dcc_getc serial_getc
  77. #define arm_dcc_putc serial_putc
  78. #define arm_dcc_puts serial_puts
  79. #define arm_dcc_tstc serial_tstc
  80. #endif
  81. int arm_dcc_init(void)
  82. {
  83. return 0;
  84. }
  85. int arm_dcc_getc(void)
  86. {
  87. int ch;
  88. register unsigned int reg;
  89. do {
  90. can_read_dcc(reg);
  91. } while (!reg);
  92. read_dcc(ch);
  93. return ch;
  94. }
  95. void arm_dcc_putc(char ch)
  96. {
  97. register unsigned int reg;
  98. unsigned int timeout_count = TIMEOUT_COUNT;
  99. while (--timeout_count) {
  100. can_write_dcc(reg);
  101. if (reg)
  102. break;
  103. }
  104. if (timeout_count == 0)
  105. return;
  106. else
  107. write_dcc(ch);
  108. }
  109. void arm_dcc_puts(const char *s)
  110. {
  111. while (*s)
  112. arm_dcc_putc(*s++);
  113. }
  114. int arm_dcc_tstc(void)
  115. {
  116. register unsigned int reg;
  117. can_read_dcc(reg);
  118. return reg;
  119. }
  120. #ifdef CONFIG_ARM_DCC_MULTI
  121. static device_t arm_dcc_dev;
  122. int drv_arm_dcc_init(void)
  123. {
  124. int rc;
  125. /* Device initialization */
  126. memset(&arm_dcc_dev, 0, sizeof(arm_dcc_dev));
  127. strcpy(arm_dcc_dev.name, "dcc");
  128. arm_dcc_dev.ext = 0; /* No extensions */
  129. arm_dcc_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
  130. arm_dcc_dev.tstc = arm_dcc_tstc; /* 'tstc' function */
  131. arm_dcc_dev.getc = arm_dcc_getc; /* 'getc' function */
  132. arm_dcc_dev.putc = arm_dcc_putc; /* 'putc' function */
  133. arm_dcc_dev.puts = arm_dcc_puts; /* 'puts' function */
  134. return device_register(&arm_dcc_dev);
  135. }
  136. #endif