debug.h 1.1 KB

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