serial.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* Unit-specific 8250 serial ports
  2. *
  3. * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef _ASM_UNIT_SERIAL_H
  12. #define _ASM_UNIT_SERIAL_H
  13. #include <asm/cpu-regs.h>
  14. #include <proc/irq.h>
  15. #include <unit/fpga-regs.h>
  16. #include <linux/serial_reg.h>
  17. #define SERIAL_PORT0_BASE_ADDRESS 0xA8200000
  18. #define SERIAL_IRQ XIRQ1 /* single serial (TL16C550C) (Lo) */
  19. /*
  20. * The ASB2364 has an 12.288 MHz clock
  21. * for your UART.
  22. *
  23. * It'd be nice if someone built a serial card with a 24.576 MHz
  24. * clock, since the 16550A is capable of handling a top speed of 1.5
  25. * megabits/second; but this requires the faster clock.
  26. */
  27. #define BASE_BAUD (12288000 / 16)
  28. /*
  29. * dispose of the /dev/ttyS0 and /dev/ttyS1 serial ports
  30. */
  31. #ifndef CONFIG_GDBSTUB_ON_TTYSx
  32. #define SERIAL_PORT_DFNS \
  33. { \
  34. .baud_base = BASE_BAUD, \
  35. .irq = SERIAL_IRQ, \
  36. .flags = STD_COM_FLAGS, \
  37. .iomem_base = (u8 *) SERIAL_PORT0_BASE_ADDRESS, \
  38. .iomem_reg_shift = 1, \
  39. .io_type = SERIAL_IO_MEM, \
  40. },
  41. #ifndef __ASSEMBLY__
  42. static inline void __debug_to_serial(const char *p, int n)
  43. {
  44. }
  45. #endif /* !__ASSEMBLY__ */
  46. #else /* CONFIG_GDBSTUB_ON_TTYSx */
  47. #define SERIAL_PORT_DFNS /* stolen by gdb-stub */
  48. #if defined(CONFIG_GDBSTUB_ON_TTYS0)
  49. #define GDBPORT_SERIAL_RX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX * 2, u8)
  50. #define GDBPORT_SERIAL_TX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX * 2, u8)
  51. #define GDBPORT_SERIAL_DLL __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 2, u8)
  52. #define GDBPORT_SERIAL_DLM __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 2, u8)
  53. #define GDBPORT_SERIAL_IER __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 2, u8)
  54. #define GDBPORT_SERIAL_IIR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 2, u8)
  55. #define GDBPORT_SERIAL_FCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 2, u8)
  56. #define GDBPORT_SERIAL_LCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 2, u8)
  57. #define GDBPORT_SERIAL_MCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 2, u8)
  58. #define GDBPORT_SERIAL_LSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 2, u8)
  59. #define GDBPORT_SERIAL_MSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 2, u8)
  60. #define GDBPORT_SERIAL_SCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 2, u8)
  61. #define GDBPORT_SERIAL_IRQ SERIAL_IRQ
  62. #elif defined(CONFIG_GDBSTUB_ON_TTYS1)
  63. #error The ASB2364 does not have a /dev/ttyS1
  64. #endif
  65. #ifndef __ASSEMBLY__
  66. static inline void __debug_to_serial(const char *p, int n)
  67. {
  68. char ch;
  69. #define LSR_WAIT_FOR(STATE) \
  70. do {} while (!(GDBPORT_SERIAL_LSR & UART_LSR_##STATE))
  71. #define FLOWCTL_QUERY(LINE) \
  72. ({ GDBPORT_SERIAL_MSR & UART_MSR_##LINE; })
  73. #define FLOWCTL_WAIT_FOR(LINE) \
  74. do {} while (!(GDBPORT_SERIAL_MSR & UART_MSR_##LINE))
  75. #define FLOWCTL_CLEAR(LINE) \
  76. do { GDBPORT_SERIAL_MCR &= ~UART_MCR_##LINE; } while (0)
  77. #define FLOWCTL_SET(LINE) \
  78. do { GDBPORT_SERIAL_MCR |= UART_MCR_##LINE; } while (0)
  79. FLOWCTL_SET(DTR);
  80. for (; n > 0; n--) {
  81. LSR_WAIT_FOR(THRE);
  82. FLOWCTL_WAIT_FOR(CTS);
  83. ch = *p++;
  84. if (ch == 0x0a) {
  85. GDBPORT_SERIAL_TX = 0x0d;
  86. LSR_WAIT_FOR(THRE);
  87. FLOWCTL_WAIT_FOR(CTS);
  88. }
  89. GDBPORT_SERIAL_TX = ch;
  90. }
  91. FLOWCTL_CLEAR(DTR);
  92. }
  93. #endif /* !__ASSEMBLY__ */
  94. #endif /* CONFIG_GDBSTUB_ON_TTYSx */
  95. #define SERIAL_INITIALIZE \
  96. do { \
  97. /* release reset */ \
  98. ASB2364_FPGA_REG_RESET_UART = 0x0001; \
  99. SyncExBus(); \
  100. } while (0)
  101. #define SERIAL_CHECK_INTERRUPT \
  102. do { \
  103. if ((ASB2364_FPGA_REG_IRQ_UART & 0x0001) == 0x0001) { \
  104. return IRQ_NONE; \
  105. } \
  106. } while (0)
  107. #define SERIAL_CLEAR_INTERRUPT \
  108. do { \
  109. ASB2364_FPGA_REG_IRQ_UART = 0x0001; \
  110. SyncExBus(); \
  111. } while (0)
  112. #define SERIAL_SET_INT_MASK \
  113. do { \
  114. ASB2364_FPGA_REG_MASK_UART = 0x0001; \
  115. SyncExBus(); \
  116. } while (0)
  117. #define SERIAL_CLEAR_INT_MASK \
  118. do { \
  119. ASB2364_FPGA_REG_MASK_UART = 0x0000; \
  120. SyncExBus(); \
  121. } while (0)
  122. #endif /* _ASM_UNIT_SERIAL_H */