18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/***************************************************************************** 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci AudioScience HPI driver 58c2ecf20Sopenharmony_ci Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci 88c2ecf20Sopenharmony_ciDebug macros. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci*****************************************************************************/ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#ifndef _HPIDEBUG_H 138c2ecf20Sopenharmony_ci#define _HPIDEBUG_H 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include "hpi_internal.h" 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* Define debugging levels. */ 188c2ecf20Sopenharmony_cienum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */ 198c2ecf20Sopenharmony_ci HPI_DEBUG_LEVEL_WARNING = 1, 208c2ecf20Sopenharmony_ci HPI_DEBUG_LEVEL_NOTICE = 2, 218c2ecf20Sopenharmony_ci HPI_DEBUG_LEVEL_INFO = 3, 228c2ecf20Sopenharmony_ci HPI_DEBUG_LEVEL_DEBUG = 4, 238c2ecf20Sopenharmony_ci HPI_DEBUG_LEVEL_VERBOSE = 5 /* same printk level as DEBUG */ 248c2ecf20Sopenharmony_ci}; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#define HPI_DEBUG_LEVEL_DEFAULT HPI_DEBUG_LEVEL_NOTICE 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* an OS can define an extra flag string that is appended to 298c2ecf20Sopenharmony_ci the start of each message, eg see linux kernel hpios.h */ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#ifdef SOURCEFILE_NAME 328c2ecf20Sopenharmony_ci#define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " " 338c2ecf20Sopenharmony_ci#else 348c2ecf20Sopenharmony_ci#define FILE_LINE __FILE__ ":" __stringify(__LINE__) " " 358c2ecf20Sopenharmony_ci#endif 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#define HPI_DEBUG_ASSERT(expression) \ 388c2ecf20Sopenharmony_ci do { \ 398c2ecf20Sopenharmony_ci if (!(expression)) { \ 408c2ecf20Sopenharmony_ci printk(KERN_ERR FILE_LINE \ 418c2ecf20Sopenharmony_ci "ASSERT " __stringify(expression)); \ 428c2ecf20Sopenharmony_ci } \ 438c2ecf20Sopenharmony_ci } while (0) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define HPI_DEBUG_LOG(level, ...) \ 468c2ecf20Sopenharmony_ci do { \ 478c2ecf20Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \ 488c2ecf20Sopenharmony_ci printk(HPI_DEBUG_FLAG_##level \ 498c2ecf20Sopenharmony_ci FILE_LINE __VA_ARGS__); \ 508c2ecf20Sopenharmony_ci } \ 518c2ecf20Sopenharmony_ci } while (0) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_civoid hpi_debug_init(void); 548c2ecf20Sopenharmony_ciint hpi_debug_level_set(int level); 558c2ecf20Sopenharmony_ciint hpi_debug_level_get(void); 568c2ecf20Sopenharmony_ci/* needed by Linux driver for dynamic debug level changes */ 578c2ecf20Sopenharmony_ciextern int hpi_debug_level; 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_civoid hpi_debug_message(struct hpi_message *phm, char *sz_fileline); 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_civoid hpi_debug_data(u16 *pdata, u32 len); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci#define HPI_DEBUG_DATA(pdata, len) \ 648c2ecf20Sopenharmony_ci do { \ 658c2ecf20Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE) \ 668c2ecf20Sopenharmony_ci hpi_debug_data(pdata, len); \ 678c2ecf20Sopenharmony_ci } while (0) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci#define HPI_DEBUG_MESSAGE(level, phm) \ 708c2ecf20Sopenharmony_ci do { \ 718c2ecf20Sopenharmony_ci if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \ 728c2ecf20Sopenharmony_ci hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \ 738c2ecf20Sopenharmony_ci FILE_LINE __stringify(level)); \ 748c2ecf20Sopenharmony_ci } \ 758c2ecf20Sopenharmony_ci } while (0) 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci#define HPI_DEBUG_RESPONSE(phr) \ 788c2ecf20Sopenharmony_ci do { \ 798c2ecf20Sopenharmony_ci if (((hpi_debug_level >= HPI_DEBUG_LEVEL_DEBUG) && \ 808c2ecf20Sopenharmony_ci (phr->error)) ||\ 818c2ecf20Sopenharmony_ci (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)) \ 828c2ecf20Sopenharmony_ci printk(KERN_DEBUG "HPI_RES%d,%d,%d\n", \ 838c2ecf20Sopenharmony_ci phr->version, phr->error, phr->specific_error); \ 848c2ecf20Sopenharmony_ci } while (0) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#ifndef compile_time_assert 878c2ecf20Sopenharmony_ci#define compile_time_assert(cond, msg) \ 888c2ecf20Sopenharmony_ci typedef char msg[(cond) ? 1 : -1] 898c2ecf20Sopenharmony_ci#endif 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#endif /* _HPIDEBUG_H_ */ 92