kgdb_io.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * BRIEF MODULE DESCRIPTION
  3. * Low level uart routines to directly access a TX[34]927 SIO.
  4. *
  5. * Copyright 2001 MontaVista Software Inc.
  6. * Author: MontaVista Software, Inc.
  7. * ahennessy@mvista.com or source@mvista.com
  8. *
  9. * Based on arch/mips/ddb5xxx/ddb5477/kgdb_io.c
  10. *
  11. * Copyright (C) 2000-2001 Toshiba Corporation
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. *
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  21. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  23. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  24. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  25. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * You should have received a copy of the GNU General Public License along
  30. * with this program; if not, write to the Free Software Foundation, Inc.,
  31. * 675 Mass Ave, Cambridge, MA 02139, USA.
  32. */
  33. #include <asm/jmr3927/jmr3927.h>
  34. #define TIMEOUT 0xffffff
  35. static int remoteDebugInitialized = 0;
  36. static void debugInit(int baud);
  37. int putDebugChar(unsigned char c)
  38. {
  39. int i = 0;
  40. if (!remoteDebugInitialized) {
  41. remoteDebugInitialized = 1;
  42. debugInit(38400);
  43. }
  44. do {
  45. slow_down();
  46. i++;
  47. if (i>TIMEOUT) {
  48. break;
  49. }
  50. } while (!(tx3927_sioptr(0)->cisr & TXx927_SICISR_TXALS));
  51. tx3927_sioptr(0)->tfifo = c;
  52. return 1;
  53. }
  54. unsigned char getDebugChar(void)
  55. {
  56. int i = 0;
  57. int dicr;
  58. char c;
  59. if (!remoteDebugInitialized) {
  60. remoteDebugInitialized = 1;
  61. debugInit(38400);
  62. }
  63. /* diable RX int. */
  64. dicr = tx3927_sioptr(0)->dicr;
  65. tx3927_sioptr(0)->dicr = 0;
  66. do {
  67. slow_down();
  68. i++;
  69. if (i>TIMEOUT) {
  70. break;
  71. }
  72. } while (tx3927_sioptr(0)->disr & TXx927_SIDISR_UVALID)
  73. ;
  74. c = tx3927_sioptr(0)->rfifo;
  75. /* clear RX int. status */
  76. tx3927_sioptr(0)->disr &= ~TXx927_SIDISR_RDIS;
  77. /* enable RX int. */
  78. tx3927_sioptr(0)->dicr = dicr;
  79. return c;
  80. }
  81. static void debugInit(int baud)
  82. {
  83. tx3927_sioptr(0)->lcr = 0x020;
  84. tx3927_sioptr(0)->dicr = 0;
  85. tx3927_sioptr(0)->disr = 0x4100;
  86. tx3927_sioptr(0)->cisr = 0x014;
  87. tx3927_sioptr(0)->fcr = 0;
  88. tx3927_sioptr(0)->flcr = 0x02;
  89. tx3927_sioptr(0)->bgr = ((JMR3927_BASE_BAUD + baud / 2) / baud) |
  90. TXx927_SIBGR_BCLK_T0;
  91. }