uart-16550.c 970 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #ifndef PORT
  21. #error please define the serial port address for your own machine
  22. #endif
  23. static inline unsigned int serial_in(int offset)
  24. {
  25. return *((char *)PORT(offset));
  26. }
  27. static inline void serial_out(int offset, int value)
  28. {
  29. *((char *)PORT(offset)) = value;
  30. }
  31. void putc(char c)
  32. {
  33. int timeout = 1024;
  34. while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
  35. ;
  36. serial_out(UART_TX, c);
  37. }