162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/***************************************************************************** 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci AudioScience HPI driver 562306a36Sopenharmony_ci Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciDebug macros. 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci*****************************************************************************/ 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#ifndef _HPIDEBUG_H 1362306a36Sopenharmony_ci#define _HPIDEBUG_H 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include "hpi_internal.h" 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/* Define debugging levels. */ 1862306a36Sopenharmony_cienum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */ 1962306a36Sopenharmony_ci HPI_DEBUG_LEVEL_WARNING = 1, 2062306a36Sopenharmony_ci HPI_DEBUG_LEVEL_NOTICE = 2, 2162306a36Sopenharmony_ci HPI_DEBUG_LEVEL_INFO = 3, 2262306a36Sopenharmony_ci HPI_DEBUG_LEVEL_DEBUG = 4, 2362306a36Sopenharmony_ci HPI_DEBUG_LEVEL_VERBOSE = 5 /* same printk level as DEBUG */ 2462306a36Sopenharmony_ci}; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci#define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* an OS can define an extra flag string that is appended to 2962306a36Sopenharmony_ci the start of each message, eg see linux kernel hpios.h */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#ifdef SOURCEFILE_NAME 3262306a36Sopenharmony_ci#define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " " 3362306a36Sopenharmony_ci#else 3462306a36Sopenharmony_ci#define FILE_LINE __FILE__ ":" __stringify(__LINE__) " " 3562306a36Sopenharmony_ci#endif 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define HPI_DEBUG_ASSERT(expression) \ 3862306a36Sopenharmony_ci do { \ 3962306a36Sopenharmony_ci if (!(expression)) { \ 4062306a36Sopenharmony_ci printk(KERN_ERR FILE_LINE \ 4162306a36Sopenharmony_ci "ASSERT " __stringify(expression)); \ 4262306a36Sopenharmony_ci } \ 4362306a36Sopenharmony_ci } while (0) 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define HPI_DEBUG_LOG(level, ...) \ 4662306a36Sopenharmony_ci do { \ 4762306a36Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \ 4862306a36Sopenharmony_ci printk(HPI_DEBUG_FLAG_##level \ 4962306a36Sopenharmony_ci FILE_LINE __VA_ARGS__); \ 5062306a36Sopenharmony_ci } \ 5162306a36Sopenharmony_ci } while (0) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_civoid hpi_debug_init(void); 5462306a36Sopenharmony_ciint hpi_debug_level_set(int level); 5562306a36Sopenharmony_ciint hpi_debug_level_get(void); 5662306a36Sopenharmony_ci/* needed by Linux driver for dynamic debug level changes */ 5762306a36Sopenharmony_ciextern int hpi_debug_level; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_civoid hpi_debug_message(struct hpi_message *phm, char *sz_fileline); 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_civoid hpi_debug_data(u16 *pdata, u32 len); 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define HPI_DEBUG_DATA(pdata, len) \ 6462306a36Sopenharmony_ci do { \ 6562306a36Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \ 6662306a36Sopenharmony_ci hpi_debug_data(pdata, len); \ 6762306a36Sopenharmony_ci } while (0) 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#define HPI_DEBUG_MESSAGE(level, phm) \ 7062306a36Sopenharmony_ci do { \ 7162306a36Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \ 7262306a36Sopenharmony_ci hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \ 7362306a36Sopenharmony_ci FILE_LINE __stringify(level)); \ 7462306a36Sopenharmony_ci } \ 7562306a36Sopenharmony_ci } while (0) 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci#define HPI_DEBUG_RESPONSE(phr) \ 7862306a36Sopenharmony_ci do { \ 7962306a36Sopenharmony_ci if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \ 8062306a36Sopenharmony_ci (phr->error)) ||\ 8162306a36Sopenharmony_ci (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \ 8262306a36Sopenharmony_ci printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \ 8362306a36Sopenharmony_ci phr->version, phr->error, phr->specific_error); \ 8462306a36Sopenharmony_ci } while (0) 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci#ifndef compile_time_assert 8762306a36Sopenharmony_ci#define compile_time_assert(cond, msg) \ 8862306a36Sopenharmony_ci typedef char msg[(cond) ? 1 : -1] 8962306a36Sopenharmony_ci#endif 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#endif /* _HPIDEBUG_H_ */ 92