hpidebug.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*****************************************************************************
  3. AudioScience HPI driver
  4. Copyright (C) 1997-2011 AudioScience Inc. <[email protected]>
  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. #define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " "
  23. #else
  24. #define FILE_LINE __FILE__ ":" __stringify(__LINE__) " "
  25. #endif
  26. #define HPI_DEBUG_ASSERT(expression) \
  27. do { \
  28. if (!(expression)) { \
  29. printk(KERN_ERR FILE_LINE \
  30. "ASSERT " __stringify(expression)); \
  31. } \
  32. } while (0)
  33. #define HPI_DEBUG_LOG(level, ...) \
  34. do { \
  35. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  36. printk(HPI_DEBUG_FLAG_##level \
  37. FILE_LINE __VA_ARGS__); \
  38. } \
  39. } while (0)
  40. void hpi_debug_init(void);
  41. int hpi_debug_level_set(int level);
  42. int hpi_debug_level_get(void);
  43. /* needed by Linux driver for dynamic debug level changes */
  44. extern int hpi_debug_level;
  45. void hpi_debug_message(struct hpi_message *phm, char *sz_fileline);
  46. void hpi_debug_data(u16 *pdata, u32 len);
  47. #define HPI_DEBUG_DATA(pdata, len) \
  48. do { \
  49. if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \
  50. hpi_debug_data(pdata, len); \
  51. } while (0)
  52. #define HPI_DEBUG_MESSAGE(level, phm) \
  53. do { \
  54. if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
  55. hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
  56. FILE_LINE __stringify(level)); \
  57. } \
  58. } while (0)
  59. #define HPI_DEBUG_RESPONSE(phr) \
  60. do { \
  61. if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \
  62. (phr->error)) ||\
  63. (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \
  64. printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \
  65. phr->version, phr->error, phr->specific_error); \
  66. } while (0)
  67. #ifndef compile_time_assert
  68. #define compile_time_assert(cond, msg) \
  69. typedef char msg[(cond) ? 1 : -1]
  70. #endif
  71. #endif /* _HPIDEBUG_H_ */