dbg_io.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * kgdb debug routines for SiByte boards.
  3. *
  4. * Copyright (C) 2001 MontaVista Software Inc.
  5. * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. /* -------------------- BEGINNING OF CONFIG --------------------- */
  14. #include <linux/delay.h>
  15. #include <asm/io.h>
  16. #include <asm/sibyte/sb1250.h>
  17. #include <asm/sibyte/sb1250_regs.h>
  18. #include <asm/sibyte/sb1250_uart.h>
  19. #include <asm/sibyte/sb1250_int.h>
  20. #include <asm/addrspace.h>
  21. /*
  22. * We use the second serial port for kgdb traffic.
  23. * 115200, 8, N, 1.
  24. */
  25. #define BAUD_RATE 115200
  26. #define CLK_DIVISOR V_DUART_BAUD_RATE(BAUD_RATE)
  27. #define DATA_BITS V_DUART_BITS_PER_CHAR_8 /* or 7 */
  28. #define PARITY V_DUART_PARITY_MODE_NONE /* or even */
  29. #define STOP_BITS M_DUART_STOP_BIT_LEN_1 /* or 2 */
  30. static int duart_initialized = 0; /* 0: need to be init'ed by kgdb */
  31. /* -------------------- END OF CONFIG --------------------- */
  32. extern int kgdb_port;
  33. #define duart_out(reg, val) csr_out32(val, IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  34. #define duart_in(reg) csr_in32(IOADDR(A_DUART_CHANREG(kgdb_port,reg)))
  35. void putDebugChar(unsigned char c);
  36. unsigned char getDebugChar(void);
  37. static void
  38. duart_init(int clk_divisor, int data, int parity, int stop)
  39. {
  40. duart_out(R_DUART_MODE_REG_1, data | parity);
  41. duart_out(R_DUART_MODE_REG_2, stop);
  42. duart_out(R_DUART_CLK_SEL, clk_divisor);
  43. duart_out(R_DUART_CMD, M_DUART_RX_EN | M_DUART_TX_EN); /* enable rx and tx */
  44. }
  45. void
  46. putDebugChar(unsigned char c)
  47. {
  48. if (!duart_initialized) {
  49. duart_initialized = 1;
  50. duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
  51. }
  52. while ((duart_in(R_DUART_STATUS) & M_DUART_TX_RDY) == 0);
  53. duart_out(R_DUART_TX_HOLD, c);
  54. }
  55. unsigned char
  56. getDebugChar(void)
  57. {
  58. if (!duart_initialized) {
  59. duart_initialized = 1;
  60. duart_init(CLK_DIVISOR, DATA_BITS, PARITY, STOP_BITS);
  61. }
  62. while ((duart_in(R_DUART_STATUS) & M_DUART_RX_RDY) == 0) ;
  63. return duart_in(R_DUART_RX_HOLD);
  64. }