serial.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* ASB2305-specific 8250 serial ports
  2. *
  3. * Copyright (C) 2007 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 Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, 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 <linux/serial_reg.h>
  16. #define SERIAL_PORT0_BASE_ADDRESS 0xA6FB0000
  17. #define ASB2305_DEBUG_MCR __SYSREG(0xA6FB0000 + UART_MCR * 2, u8)
  18. #define SERIAL_IRQ XIRQ0 /* Dual serial (PC16552) (Hi) */
  19. /*
  20. * The ASB2305 has an 18.432 MHz clock the UART
  21. */
  22. #define BASE_BAUD (18432000 / 16)
  23. /*
  24. * dispose of the /dev/ttyS0 serial port
  25. */
  26. #ifndef CONFIG_GDBSTUB_ON_TTYSx
  27. #define SERIAL_PORT_DFNS \
  28. { \
  29. .baud_base = BASE_BAUD, \
  30. .irq = SERIAL_IRQ, \
  31. .flags = STD_COM_FLAGS, \
  32. .iomem_base = (u8 *) SERIAL_PORT0_BASE_ADDRESS, \
  33. .iomem_reg_shift = 2, \
  34. .io_type = SERIAL_IO_MEM, \
  35. },
  36. #ifndef __ASSEMBLY__
  37. static inline void __debug_to_serial(const char *p, int n)
  38. {
  39. }
  40. #endif /* !__ASSEMBLY__ */
  41. #else /* CONFIG_GDBSTUB_ON_TTYSx */
  42. #define SERIAL_PORT_DFNS /* stolen by gdb-stub */
  43. #if defined(CONFIG_GDBSTUB_ON_TTYS0)
  44. #define GDBPORT_SERIAL_RX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX * 4, u8)
  45. #define GDBPORT_SERIAL_TX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX * 4, u8)
  46. #define GDBPORT_SERIAL_DLL __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 4, u8)
  47. #define GDBPORT_SERIAL_DLM __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 4, u8)
  48. #define GDBPORT_SERIAL_IER __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 4, u8)
  49. #define GDBPORT_SERIAL_IIR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 4, u8)
  50. #define GDBPORT_SERIAL_FCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 4, u8)
  51. #define GDBPORT_SERIAL_LCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 4, u8)
  52. #define GDBPORT_SERIAL_MCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8)
  53. #define GDBPORT_SERIAL_LSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8)
  54. #define GDBPORT_SERIAL_MSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8)
  55. #define GDBPORT_SERIAL_SCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 4, u8)
  56. #define GDBPORT_SERIAL_IRQ SERIAL_IRQ
  57. #elif defined(CONFIG_GDBSTUB_ON_TTYS1)
  58. #error The ASB2305 doesnt have a /dev/ttyS1
  59. #endif
  60. #ifndef __ASSEMBLY__
  61. #define TTYS0_TX __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX * 4, u8)
  62. #define TTYS0_MCR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8)
  63. #define TTYS0_LSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8)
  64. #define TTYS0_MSR __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8)
  65. #define LSR_WAIT_FOR(STATE) \
  66. do { \
  67. while (!(TTYS0_LSR & UART_LSR_##STATE)) {} \
  68. } while (0)
  69. #define FLOWCTL_WAIT_FOR(LINE) \
  70. do { \
  71. while (!(TTYS0_MSR & UART_MSR_##LINE)) {} \
  72. } while (0)
  73. #define FLOWCTL_CLEAR(LINE) \
  74. do { \
  75. TTYS0_MCR &= ~UART_MCR_##LINE; \
  76. } while (0)
  77. #define FLOWCTL_SET(LINE) \
  78. do { \
  79. TTYS0_MCR |= UART_MCR_##LINE; \
  80. } while (0)
  81. #define FLOWCTL_QUERY(LINE) ({ TTYS0_MSR & UART_MSR_##LINE; })
  82. static inline void __debug_to_serial(const char *p, int n)
  83. {
  84. char ch;
  85. FLOWCTL_SET(DTR);
  86. for (; n > 0; n--) {
  87. LSR_WAIT_FOR(THRE);
  88. FLOWCTL_WAIT_FOR(CTS);
  89. ch = *p++;
  90. if (ch == 0x0a) {
  91. TTYS0_TX = 0x0d;
  92. LSR_WAIT_FOR(THRE);
  93. FLOWCTL_WAIT_FOR(CTS);
  94. }
  95. TTYS0_TX = ch;
  96. }
  97. FLOWCTL_CLEAR(DTR);
  98. }
  99. #endif /* !__ASSEMBLY__ */
  100. #endif /* CONFIG_GDBSTUB_ON_TTYSx */
  101. #endif /* _ASM_UNIT_SERIAL_H */