arm_dcc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #else
  42. #define DCC_RBIT (1 << 0)
  43. #define DCC_WBIT (1 << 1)
  44. #define write_dcc(x) \
  45. __asm__ volatile ("mcr p14, 0, %0, c1, c0, 0\n" : : "r" (x))
  46. #define read_dcc(x) \
  47. __asm__ volatile ("mrc p14, 0, %0, c1, c0, 0\n" : "=r" (x))
  48. #define status_dcc(x) \
  49. __asm__ volatile ("mrc p14, 0, %0, c0, c0, 0\n" : "=r" (x))
  50. #endif
  51. #define can_read_dcc(x) do { \
  52. status_dcc(x); \
  53. x &= DCC_RBIT; \
  54. } while (0);
  55. #define can_write_dcc(x) do { \
  56. status_dcc(x); \
  57. x &= DCC_WBIT; \
  58. x = (x == 0); \
  59. } while (0);
  60. #define TIMEOUT_COUNT 0x4000000
  61. #ifndef CONFIG_ARM_DCC_MULTI
  62. #define arm_dcc_init serial_init
  63. void serial_setbrg(void) {}
  64. #define arm_dcc_getc serial_getc
  65. #define arm_dcc_putc serial_putc
  66. #define arm_dcc_puts serial_puts
  67. #define arm_dcc_tstc serial_tstc
  68. #endif
  69. int arm_dcc_init(void)
  70. {
  71. return 0;
  72. }
  73. int arm_dcc_getc(void)
  74. {
  75. int ch;
  76. register unsigned int reg;
  77. do {
  78. can_read_dcc(reg);
  79. } while (!reg);
  80. read_dcc(ch);
  81. return ch;
  82. }
  83. void arm_dcc_putc(char ch)
  84. {
  85. register unsigned int reg;
  86. unsigned int timeout_count = TIMEOUT_COUNT;
  87. while (--timeout_count) {
  88. can_write_dcc(reg);
  89. if (reg)
  90. break;
  91. }
  92. if (timeout_count == 0)
  93. return;
  94. else
  95. write_dcc(ch);
  96. }
  97. void arm_dcc_puts(const char *s)
  98. {
  99. while (*s)
  100. arm_dcc_putc(*s++);
  101. }
  102. int arm_dcc_tstc(void)
  103. {
  104. register unsigned int reg;
  105. can_read_dcc(reg);
  106. return reg;
  107. }
  108. #ifdef CONFIG_ARM_DCC_MULTI
  109. static device_t arm_dcc_dev;
  110. int drv_arm_dcc_init(void)
  111. {
  112. int rc;
  113. /* Device initialization */
  114. memset(&arm_dcc_dev, 0, sizeof(arm_dcc_dev));
  115. strcpy(arm_dcc_dev.name, "dcc");
  116. arm_dcc_dev.ext = 0; /* No extensions */
  117. arm_dcc_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
  118. arm_dcc_dev.tstc = arm_dcc_tstc; /* 'tstc' function */
  119. arm_dcc_dev.getc = arm_dcc_getc; /* 'getc' function */
  120. arm_dcc_dev.putc = arm_dcc_putc; /* 'putc' function */
  121. arm_dcc_dev.puts = arm_dcc_puts; /* 'puts' function */
  122. return device_register(&arm_dcc_dev);
  123. }
  124. #endif