diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
| commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
| tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /drivers/misc/inv_mpu/log.h | |
| parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) | |
Diffstat (limited to 'drivers/misc/inv_mpu/log.h')
| -rw-r--r-- | drivers/misc/inv_mpu/log.h | 287 |
1 files changed, 287 insertions, 0 deletions
diff --git a/drivers/misc/inv_mpu/log.h b/drivers/misc/inv_mpu/log.h new file mode 100644 index 00000000000..5630602e3ef --- /dev/null +++ b/drivers/misc/inv_mpu/log.h | |||
| @@ -0,0 +1,287 @@ | |||
| 1 | /* | ||
| 2 | $License: | ||
| 3 | Copyright (C) 2011 InvenSense Corporation, All Rights Reserved. | ||
| 4 | |||
| 5 | This program is free software; you can redistribute it and/or modify | ||
| 6 | it under the terms of the GNU General Public License as published by | ||
| 7 | the Free Software Foundation; either version 2 of the License, or | ||
| 8 | (at your option) any later version. | ||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, | ||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | GNU General Public License for more details. | ||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License | ||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 17 | $ | ||
| 18 | */ | ||
| 19 | |||
| 20 | /* | ||
| 21 | * This file incorporates work covered by the following copyright and | ||
| 22 | * permission notice: | ||
| 23 | * | ||
| 24 | * Copyright (C) 2005 The Android Open Source Project | ||
| 25 | * | ||
| 26 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 27 | * you may not use this file except in compliance with the License. | ||
| 28 | * You may obtain a copy of the License at | ||
| 29 | * | ||
| 30 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 31 | * | ||
| 32 | * Unless required by applicable law or agreed to in writing, software | ||
| 33 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 34 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 35 | * See the License for the specific language governing permissions and | ||
| 36 | * limitations under the License. | ||
| 37 | */ | ||
| 38 | |||
| 39 | /* | ||
| 40 | * C/C++ logging functions. See the logging documentation for API details. | ||
| 41 | * | ||
| 42 | * We'd like these to be available from C code (in case we import some from | ||
| 43 | * somewhere), so this has a C interface. | ||
| 44 | * | ||
| 45 | * The output will be correct when the log file is shared between multiple | ||
| 46 | * threads and/or multiple processes so long as the operating system | ||
| 47 | * supports O_APPEND. These calls have mutex-protected data structures | ||
| 48 | * and so are NOT reentrant. Do not use MPL_LOG in a signal handler. | ||
| 49 | */ | ||
| 50 | #ifndef _LIBS_CUTILS_MPL_LOG_H | ||
| 51 | #define _LIBS_CUTILS_MPL_LOG_H | ||
| 52 | |||
| 53 | #include "mltypes.h" | ||
| 54 | #include <stdarg.h> | ||
| 55 | |||
| 56 | |||
| 57 | #include <linux/kernel.h> | ||
| 58 | |||
| 59 | |||
| 60 | /* --------------------------------------------------------------------- */ | ||
| 61 | |||
| 62 | /* | ||
| 63 | * Normally we strip MPL_LOGV (VERBOSE messages) from release builds. | ||
| 64 | * You can modify this (for example with "#define MPL_LOG_NDEBUG 0" | ||
| 65 | * at the top of your source file) to change that behavior. | ||
| 66 | */ | ||
| 67 | #ifndef MPL_LOG_NDEBUG | ||
| 68 | #ifdef NDEBUG | ||
| 69 | #define MPL_LOG_NDEBUG 1 | ||
| 70 | #else | ||
| 71 | #define MPL_LOG_NDEBUG 0 | ||
| 72 | #endif | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #define MPL_LOG_UNKNOWN MPL_LOG_VERBOSE | ||
| 76 | #define MPL_LOG_DEFAULT KERN_DEFAULT | ||
| 77 | #define MPL_LOG_VERBOSE KERN_CONT | ||
| 78 | #define MPL_LOG_DEBUG KERN_NOTICE | ||
| 79 | #define MPL_LOG_INFO KERN_INFO | ||
| 80 | #define MPL_LOG_WARN KERN_WARNING | ||
| 81 | #define MPL_LOG_ERROR KERN_ERR | ||
| 82 | #define MPL_LOG_SILENT MPL_LOG_VERBOSE | ||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | /* | ||
| 87 | * This is the local tag used for the following simplified | ||
| 88 | * logging macros. You can change this preprocessor definition | ||
| 89 | * before using the other macros to change the tag. | ||
| 90 | */ | ||
| 91 | #ifndef MPL_LOG_TAG | ||
| 92 | #define MPL_LOG_TAG | ||
| 93 | #endif | ||
| 94 | |||
| 95 | /* --------------------------------------------------------------------- */ | ||
| 96 | |||
| 97 | /* | ||
| 98 | * Simplified macro to send a verbose log message using the current MPL_LOG_TAG. | ||
| 99 | */ | ||
| 100 | #ifndef MPL_LOGV | ||
| 101 | #if MPL_LOG_NDEBUG | ||
| 102 | #define MPL_LOGV(fmt, ...) \ | ||
| 103 | do { \ | ||
| 104 | if (0) \ | ||
| 105 | MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__);\ | ||
| 106 | } while (0) | ||
| 107 | #else | ||
| 108 | #define MPL_LOGV(fmt, ...) MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
| 109 | #endif | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #ifndef CONDITION | ||
| 113 | #define CONDITION(cond) ((cond) != 0) | ||
| 114 | #endif | ||
| 115 | |||
| 116 | #ifndef MPL_LOGV_IF | ||
| 117 | #if MPL_LOG_NDEBUG | ||
| 118 | #define MPL_LOGV_IF(cond, fmt, ...) \ | ||
| 119 | do { if (0) MPL_LOG(fmt, ##__VA_ARGS__); } while (0) | ||
| 120 | #else | ||
| 121 | #define MPL_LOGV_IF(cond, fmt, ...) \ | ||
| 122 | ((CONDITION(cond)) \ | ||
| 123 | ? MPL_LOG(LOG_VERBOSE, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
| 124 | : (void)0) | ||
| 125 | #endif | ||
| 126 | #endif | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Simplified macro to send a debug log message using the current MPL_LOG_TAG. | ||
| 130 | */ | ||
| 131 | #ifndef MPL_LOGD | ||
| 132 | #define MPL_LOGD(fmt, ...) MPL_LOG(LOG_DEBUG, MPL_LOG_TAG, fmt, ##__VA_ARGS__) | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifndef MPL_LOGD_IF | ||
| 136 | #define MPL_LOGD_IF(cond, fmt, ...) \ | ||
| 137 | ((CONDITION(cond)) \ | ||
| 138 | ? MPL_LOG(LOG_DEBUG, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
| 139 | : (void)0) | ||
| 140 | #endif | ||
| 141 | |||
| 142 | /* | ||
| 143 | * Simplified macro to send an info log message using the current MPL_LOG_TAG. | ||
| 144 | */ | ||
| 145 | #ifndef MPL_LOGI | ||
| 146 | #define MPL_LOGI(fmt, ...) pr_info(KERN_INFO MPL_LOG_TAG fmt, ##__VA_ARGS__) | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #ifndef MPL_LOGI_IF | ||
| 150 | #define MPL_LOGI_IF(cond, fmt, ...) \ | ||
| 151 | ((CONDITION(cond)) \ | ||
| 152 | ? MPL_LOG(LOG_INFO, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
| 153 | : (void)0) | ||
| 154 | #endif | ||
| 155 | |||
| 156 | /* | ||
| 157 | * Simplified macro to send a warning log message using the current MPL_LOG_TAG. | ||
| 158 | */ | ||
| 159 | #ifndef MPL_LOGW | ||
| 160 | #define MPL_LOGW(fmt, ...) printk(KERN_WARNING MPL_LOG_TAG fmt, ##__VA_ARGS__) | ||
| 161 | #endif | ||
| 162 | |||
| 163 | #ifndef MPL_LOGW_IF | ||
| 164 | #define MPL_LOGW_IF(cond, fmt, ...) \ | ||
| 165 | ((CONDITION(cond)) \ | ||
| 166 | ? MPL_LOG(LOG_WARN, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
| 167 | : (void)0) | ||
| 168 | #endif | ||
| 169 | |||
| 170 | /* | ||
| 171 | * Simplified macro to send an error log message using the current MPL_LOG_TAG. | ||
| 172 | */ | ||
| 173 | #ifndef MPL_LOGE | ||
| 174 | #define MPL_LOGE(fmt, ...) printk(KERN_ERR MPL_LOG_TAG fmt, ##__VA_ARGS__) | ||
| 175 | #endif | ||
| 176 | |||
| 177 | #ifndef MPL_LOGE_IF | ||
| 178 | #define MPL_LOGE_IF(cond, fmt, ...) \ | ||
| 179 | ((CONDITION(cond)) \ | ||
| 180 | ? MPL_LOG(LOG_ERROR, MPL_LOG_TAG, fmt, ##__VA_ARGS__) \ | ||
| 181 | : (void)0) | ||
| 182 | #endif | ||
| 183 | |||
| 184 | /* --------------------------------------------------------------------- */ | ||
| 185 | |||
| 186 | /* | ||
| 187 | * Log a fatal error. If the given condition fails, this stops program | ||
| 188 | * execution like a normal assertion, but also generating the given message. | ||
| 189 | * It is NOT stripped from release builds. Note that the condition test | ||
| 190 | * is -inverted- from the normal assert() semantics. | ||
| 191 | */ | ||
| 192 | #define MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ...) \ | ||
| 193 | ((CONDITION(cond)) \ | ||
| 194 | ? ((void)android_printAssert(#cond, MPL_LOG_TAG, \ | ||
| 195 | fmt, ##__VA_ARGS__)) \ | ||
| 196 | : (void)0) | ||
| 197 | |||
| 198 | #define MPL_LOG_ALWAYS_FATAL(fmt, ...) \ | ||
| 199 | (((void)android_printAssert(NULL, MPL_LOG_TAG, fmt, ##__VA_ARGS__))) | ||
| 200 | |||
| 201 | /* | ||
| 202 | * Versions of MPL_LOG_ALWAYS_FATAL_IF and MPL_LOG_ALWAYS_FATAL that | ||
| 203 | * are stripped out of release builds. | ||
| 204 | */ | ||
| 205 | #if MPL_LOG_NDEBUG | ||
| 206 | #define MPL_LOG_FATAL_IF(cond, fmt, ...) \ | ||
| 207 | do { \ | ||
| 208 | if (0) \ | ||
| 209 | MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ##__VA_ARGS__); \ | ||
| 210 | } while (0) | ||
| 211 | #define MPL_LOG_FATAL(fmt, ...) \ | ||
| 212 | do { \ | ||
| 213 | if (0) \ | ||
| 214 | MPL_LOG_ALWAYS_FATAL(fmt, ##__VA_ARGS__) \ | ||
| 215 | } while (0) | ||
| 216 | #else | ||
| 217 | #define MPL_LOG_FATAL_IF(cond, fmt, ...) \ | ||
| 218 | MPL_LOG_ALWAYS_FATAL_IF(cond, fmt, ##__VA_ARGS__) | ||
| 219 | #define MPL_LOG_FATAL(fmt, ...) \ | ||
| 220 | MPL_LOG_ALWAYS_FATAL(fmt, ##__VA_ARGS__) | ||
| 221 | #endif | ||
| 222 | |||
| 223 | /* | ||
| 224 | * Assertion that generates a log message when the assertion fails. | ||
| 225 | * Stripped out of release builds. Uses the current MPL_LOG_TAG. | ||
| 226 | */ | ||
| 227 | #define MPL_LOG_ASSERT(cond, fmt, ...) \ | ||
| 228 | MPL_LOG_FATAL_IF(!(cond), fmt, ##__VA_ARGS__) | ||
| 229 | |||
| 230 | /* --------------------------------------------------------------------- */ | ||
| 231 | |||
| 232 | /* | ||
| 233 | * Basic log message macro. | ||
| 234 | * | ||
| 235 | * Example: | ||
| 236 | * MPL_LOG(MPL_LOG_WARN, NULL, "Failed with error %d", errno); | ||
| 237 | * | ||
| 238 | * The second argument may be NULL or "" to indicate the "global" tag. | ||
| 239 | */ | ||
| 240 | #ifndef MPL_LOG | ||
| 241 | #define MPL_LOG(priority, tag, fmt, ...) \ | ||
| 242 | MPL_LOG_PRI(priority, tag, fmt, ##__VA_ARGS__) | ||
| 243 | #endif | ||
| 244 | |||
| 245 | /* | ||
| 246 | * Log macro that allows you to specify a number for the priority. | ||
| 247 | */ | ||
| 248 | #ifndef MPL_LOG_PRI | ||
| 249 | #define MPL_LOG_PRI(priority, tag, fmt, ...) \ | ||
| 250 | pr_debug(MPL_##priority tag fmt, ##__VA_ARGS__) | ||
| 251 | #endif | ||
| 252 | |||
| 253 | /* | ||
| 254 | * Log macro that allows you to pass in a varargs ("args" is a va_list). | ||
| 255 | */ | ||
| 256 | #ifndef MPL_LOG_PRI_VA | ||
| 257 | /* not allowed in the Kernel because there is no dev_dbg that takes a va_list */ | ||
| 258 | #endif | ||
| 259 | |||
| 260 | /* --------------------------------------------------------------------- */ | ||
| 261 | |||
| 262 | /* | ||
| 263 | * =========================================================================== | ||
| 264 | * | ||
| 265 | * The stuff in the rest of this file should not be used directly. | ||
| 266 | */ | ||
| 267 | |||
| 268 | int _MLPrintLog(int priority, const char *tag, const char *fmt, ...); | ||
| 269 | int _MLPrintVaLog(int priority, const char *tag, const char *fmt, va_list args); | ||
| 270 | /* Final implementation of actual writing to a character device */ | ||
| 271 | int _MLWriteLog(const char *buf, int buflen); | ||
| 272 | |||
| 273 | static inline void __print_result_location(int result, | ||
| 274 | const char *file, | ||
| 275 | const char *func, int line) | ||
| 276 | { | ||
| 277 | MPL_LOGE("%s|%s|%d returning %d\n", file, func, line, result); | ||
| 278 | } | ||
| 279 | |||
| 280 | #define LOG_RESULT_LOCATION(condition) \ | ||
| 281 | do { \ | ||
| 282 | __print_result_location((int)(condition), __FILE__, \ | ||
| 283 | __func__, __LINE__); \ | ||
| 284 | } while (0) | ||
| 285 | |||
| 286 | |||
| 287 | #endif /* _LIBS_CUTILS_MPL_LOG_H */ | ||
