debug.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2016 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. */
  6. #ifndef __DEBUG_H__
  7. #define __DEBUG_H__
  8. #include <linux/io.h>
  9. #include <linux/serial_reg.h>
  10. #define DEBUG_UART_BASE 0x54006800
  11. #define UART_SHIFT 2
  12. #define UNIPHIER_UART_TX 0
  13. #define UNIPHIER_UART_LSR (5 * 4)
  14. /* All functions are inline so that they can be called from .secure section. */
  15. #ifdef DEBUG
  16. static inline void debug_putc(int c)
  17. {
  18. void __iomem *base = (void __iomem *)DEBUG_UART_BASE;
  19. while (!(readl(base + UNIPHIER_UART_LSR) & UART_LSR_THRE))
  20. ;
  21. writel(c, base + UNIPHIER_UART_TX);
  22. }
  23. static inline void debug_puts(const char *s)
  24. {
  25. while (*s) {
  26. if (*s == '\n')
  27. debug_putc('\r');
  28. debug_putc(*s++);
  29. }
  30. }
  31. static inline void debug_puth(unsigned long val)
  32. {
  33. int i;
  34. unsigned char c;
  35. for (i = 8; i--; ) {
  36. c = ((val >> (i * 4)) & 0xf);
  37. c += (c >= 10) ? 'a' - 10 : '0';
  38. debug_putc(c);
  39. }
  40. }
  41. #else
  42. static inline void debug_putc(int c)
  43. {
  44. }
  45. static inline void debug_puts(const char *s)
  46. {
  47. }
  48. static inline void debug_puth(unsigned long val)
  49. {
  50. }
  51. #endif
  52. #endif /* __DEBUG_H__ */