uart-16550.c 1.3 KB

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