uart-16550.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * 16550 compatible uart based serial debug support for zboot
  3. */
  4. #include <linux/types.h>
  5. #include <linux/serial_reg.h>
  6. #include <linux/init.h>
  7. #include <asm/addrspace.h>
  8. #if defined(CONFIG_MACH_LOONGSON) || defined(CONFIG_MIPS_MALTA)
  9. #define UART_BASE 0x1fd003f8
  10. #define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset))
  11. #endif
  12. #ifdef CONFIG_AR7
  13. #include <ar7.h>
  14. #define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset))
  15. #endif
  16. #ifdef CONFIG_MACH_JZ4740
  17. #define UART0_BASE 0xB0030000
  18. #define PORT(offset) (UART0_BASE + (4 * offset))
  19. #endif
  20. #ifdef CONFIG_CPU_XLR
  21. #define UART0_BASE 0x1EF14000
  22. #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset))
  23. #define IOTYPE unsigned int
  24. #endif
  25. #ifdef CONFIG_CPU_XLP
  26. #define UART0_BASE 0x18030100
  27. #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset))
  28. #define IOTYPE unsigned int
  29. #endif
  30. #ifndef IOTYPE
  31. #define IOTYPE char
  32. #endif
  33. #ifndef PORT
  34. #error please define the serial port address for your own machine
  35. #endif
  36. static inline unsigned int serial_in(int offset)
  37. {
  38. return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
  39. }
  40. static inline void serial_out(int offset, int value)
  41. {
  42. *((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
  43. }
  44. void putc(char c)
  45. {
  46. int timeout = 1000000;
  47. while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
  48. ;
  49. serial_out(UART_TX, c);
  50. }