puts.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. *
  3. * BRIEF MODULE DESCRIPTION
  4. * Low level uart routines to directly access a TX[34]927 SIO.
  5. *
  6. * Copyright 2001 MontaVista Software Inc.
  7. * Author: MontaVista Software, Inc.
  8. * ahennessy@mvista.com or source@mvista.com
  9. *
  10. * Copyright (C) 2000-2001 Toshiba Corporation
  11. *
  12. * Based on arch/mips/au1000/common/puts.c
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. *
  19. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  20. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  22. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  25. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  28. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * You should have received a copy of the GNU General Public License along
  31. * with this program; if not, write to the Free Software Foundation, Inc.,
  32. * 675 Mass Ave, Cambridge, MA 02139, USA.
  33. */
  34. #include <linux/types.h>
  35. #include <asm/jmr3927/txx927.h>
  36. #include <asm/jmr3927/tx3927.h>
  37. #include <asm/jmr3927/jmr3927.h>
  38. #define TIMEOUT 0xffffff
  39. #define SLOW_DOWN
  40. static const char digits[16] = "0123456789abcdef";
  41. #ifdef SLOW_DOWN
  42. #define slow_down() { int k; for (k=0; k<10000; k++); }
  43. #else
  44. #define slow_down()
  45. #endif
  46. void
  47. putch(const unsigned char c)
  48. {
  49. int i = 0;
  50. do {
  51. slow_down();
  52. i++;
  53. if (i>TIMEOUT) {
  54. break;
  55. }
  56. } while (!(tx3927_sioptr(1)->cisr & TXx927_SICISR_TXALS));
  57. tx3927_sioptr(1)->tfifo = c;
  58. return;
  59. }
  60. unsigned char getch(void)
  61. {
  62. int i = 0;
  63. int dicr;
  64. char c;
  65. /* diable RX int. */
  66. dicr = tx3927_sioptr(1)->dicr;
  67. tx3927_sioptr(1)->dicr = 0;
  68. do {
  69. slow_down();
  70. i++;
  71. if (i>TIMEOUT) {
  72. break;
  73. }
  74. } while (tx3927_sioptr(1)->disr & TXx927_SIDISR_UVALID)
  75. ;
  76. c = tx3927_sioptr(1)->rfifo;
  77. /* clear RX int. status */
  78. tx3927_sioptr(1)->disr &= ~TXx927_SIDISR_RDIS;
  79. /* enable RX int. */
  80. tx3927_sioptr(1)->dicr = dicr;
  81. return c;
  82. }
  83. void
  84. do_jmr3927_led_set(char n)
  85. {
  86. /* and with current leds */
  87. jmr3927_led_and_set(n);
  88. }
  89. void
  90. puts(unsigned char *cp)
  91. {
  92. int i = 0;
  93. while (*cp) {
  94. do {
  95. slow_down();
  96. i++;
  97. if (i>TIMEOUT) {
  98. break;
  99. }
  100. } while (!(tx3927_sioptr(1)->cisr & TXx927_SICISR_TXALS));
  101. tx3927_sioptr(1)->tfifo = *cp++;
  102. }
  103. putch('\r');
  104. putch('\n');
  105. }
  106. void
  107. fputs(unsigned char *cp)
  108. {
  109. int i = 0;
  110. while (*cp) {
  111. do {
  112. slow_down();
  113. i++;
  114. if (i>TIMEOUT) {
  115. break;
  116. }
  117. } while (!(tx3927_sioptr(1)->cisr & TXx927_SICISR_TXALS));
  118. tx3927_sioptr(1)->tfifo = *cp++;
  119. }
  120. }
  121. void
  122. put64(uint64_t ul)
  123. {
  124. int cnt;
  125. unsigned ch;
  126. cnt = 16; /* 16 nibbles in a 64 bit long */
  127. putch('0');
  128. putch('x');
  129. do {
  130. cnt--;
  131. ch = (unsigned char)(ul >> cnt * 4) & 0x0F;
  132. putch(digits[ch]);
  133. } while (cnt > 0);
  134. }
  135. void
  136. put32(unsigned u)
  137. {
  138. int cnt;
  139. unsigned ch;
  140. cnt = 8; /* 8 nibbles in a 32 bit long */
  141. putch('0');
  142. putch('x');
  143. do {
  144. cnt--;
  145. ch = (unsigned char)(u >> cnt * 4) & 0x0F;
  146. putch(digits[ch]);
  147. } while (cnt > 0);
  148. }