hpidebug.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*****************************************************************************
  3. AudioScience HPI driver
  4. Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
  5. Debug macros.
  6. *****************************************************************************/
  7. #ifndef _HPIDEBUG_H
  8. #define _HPIDEBUG_H
  9. #include "hpi_internal.h"
  10. /* Define debugging levels. */
  11. enum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */
  12. HPI_DEBUG_LEVEL_WARNING = 1,
  13. HPI_DEBUG_LEVEL_NOTICE = 2,
  14. HPI_DEBUG_LEVEL_INFO = 3,
  15. HPI_DEBUG_LEVEL_DEBUG = 4,
  16. HPI_DEBUG_LEVEL_VERBOSE = 5 /* same printk level as DEBUG */
  17. };
  18. #define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE
  19. /* an OS can define an extra flag string that is appended to
  20. the start of each message, eg see linux kernel hpios.h */
  21. #ifdef SOURCEFILE_NAME
  22. #undef FILE_LINE
  23. #define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " "
  24. #endif
  25. #define HPI_DEBUG_ASSERT(expression) \
  26. do { \
  27. if (!(expression)) { \
  28. printk(KERN_ERR FILE_LINE \
  29. " ASSERT " __stringify(expression)); \
  30. } \
  31. } while (0)
  32. #define HPI_DEBUG_LOG(level, ...) \
  33. do { \
  34. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  35. printk(HPI_DEBUG_FLAG_##level \
  36. FILE_LINE " " __VA_ARGS__); \
  37. } \
  38. } while (0)
  39. void hpi_debug_init(void);
  40. int hpi_debug_level_set(int level);
  41. int hpi_debug_level_get(void);
  42. /* needed by Linux driver for dynamic debug level changes */
  43. extern int hpi_debug_level;
  44. void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);
  45. void hpi_debug_data(u16 *pdata, u32 len);
  46. #define HPI_DEBUG_DATA(pdata, len) \
  47. do { \
  48. if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
  49. hpi_debug_data(pdata, len); \
  50. } while (0)
  51. #define HPI_DEBUG_MESSAGE(level, phm) \
  52. do { \
  53. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  54. hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
  55. FILE_LINE " " __stringify(level)); \
  56. } \
  57. } while (0)
  58. #define HPI_DEBUG_RESPONSE(phr) \
  59. do { \
  60. if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \
  61. (phr->error)) ||\
  62. (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \
  63. printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \
  64. phr->version, phr->error, phr->specific_error); \
  65. } while (0)
  66. #ifndef compile_time_assert
  67. #define compile_time_assert(cond, msg) \
  68. typedef char msg[(cond) ? 1 : -1]
  69. #endif
  70. #endif /* _HPIDEBUG_H_ */