uart-16550.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * 16550 compatible uart based serial debug support for zboot
  4. */
  5. #include <linux/types.h>
  6. #include <linux/serial_reg.h>
  7. #include <asm/addrspace.h>
  8. #if defined(CONFIG_MACH_LOONGSON64) || 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_INGENIC
  17. #define INGENIC_UART_BASE_ADDR (0x10030000 + 0x1000 * CONFIG_ZBOOT_INGENIC_UART)
  18. #define PORT(offset) (CKSEG1ADDR(INGENIC_UART_BASE_ADDR) + (4 * offset))
  19. #endif
  20. #ifndef IOTYPE
  21. #define IOTYPE char
  22. #endif
  23. #ifndef PORT
  24. #error please define the serial port address for your own machine
  25. #endif
  26. static inline unsigned int serial_in(int offset)
  27. {
  28. return *((volatile IOTYPE *)PORT(offset)) & 0xFF;
  29. }
  30. static inline void serial_out(int offset, int value)
  31. {
  32. *((volatile IOTYPE *)PORT(offset)) = value & 0xFF;
  33. }
  34. void putc(char c)
  35. {
  36. int timeout = 1000000;
  37. while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0))
  38. ;
  39. serial_out(UART_TX, c);
  40. }