linux/drivers/staging/rts5139/trace.h
<<
>>
Prefs
   1/* Driver for Realtek RTS51xx USB card reader
   2 * Header file
   3 *
   4 * Copyright(c) 2009 Realtek Semiconductor Corp. All rights reserved.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms of the GNU General Public License as published by the
   8 * Free Software Foundation; either version 2, or (at your option) any
   9 * later version.
  10 *
  11 * This program is distributed in the hope that it will be useful, but
  12 * WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14 * General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU General Public License along
  17 * with this program; if not, see <http://www.gnu.org/licenses/>.
  18 *
  19 * Author:
  20 *   wwang (wei_wang@realsil.com.cn)
  21 *   No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
  22 * Maintainer:
  23 *   Edwin Rong (edwin_rong@realsil.com.cn)
  24 *   No. 450, Shenhu Road, Suzhou Industry Park, Suzhou, China
  25 */
  26
  27#ifndef __RTS51X_TRACE_H
  28#define __RTS51X_TRACE_H
  29
  30#include "debug.h"
  31
  32#define _MSG_TRACE
  33
  34#ifdef _MSG_TRACE
  35static inline char *filename(char *path)
  36{
  37        char *ptr;
  38
  39        if (path == NULL)
  40                return NULL;
  41
  42        ptr = path;
  43
  44        while (*ptr != '\0') {
  45                if ((*ptr == '\\') || (*ptr == '/'))
  46                        path = ptr + 1;
  47                ptr++;
  48        }
  49
  50        return path;
  51}
  52
  53#define TRACE_RET(chip, ret)                                            \
  54do {                                                                    \
  55        char *_file = filename((char *)__FILE__);                       \
  56        RTS51X_DEBUGP("[%s][%s]:[%d]\n", _file, __func__, __LINE__);    \
  57        (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__);      \
  58        strncpy((chip)->trace_msg[(chip)->msg_idx].func,                \
  59                        __func__, MSG_FUNC_LEN-1);                      \
  60        strncpy((chip)->trace_msg[(chip)->msg_idx].file,                \
  61                        _file, MSG_FILE_LEN-1);                         \
  62        get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf,\
  63                        TIME_VAL_LEN);  \
  64        (chip)->trace_msg[(chip)->msg_idx].valid = 1;                   \
  65        (chip)->msg_idx++;                                              \
  66        if ((chip)->msg_idx >= TRACE_ITEM_CNT) {                        \
  67                (chip)->msg_idx = 0;                                    \
  68        }                                                               \
  69        return ret;                                                     \
  70} while (0)
  71
  72#define TRACE_GOTO(chip, label)                                         \
  73do {                                                                    \
  74        char *_file = filename((char *)__FILE__);                       \
  75        RTS51X_DEBUGP("[%s][%s]:[%d]\n", _file, __func__, __LINE__);    \
  76        (chip)->trace_msg[(chip)->msg_idx].line = (u16)(__LINE__);      \
  77        strncpy((chip)->trace_msg[(chip)->msg_idx].func,                \
  78                        __func__, MSG_FUNC_LEN-1);                      \
  79        strncpy((chip)->trace_msg[(chip)->msg_idx].file,                \
  80                        _file, MSG_FILE_LEN-1);                         \
  81        get_current_time((chip)->trace_msg[(chip)->msg_idx].timeval_buf,\
  82                        TIME_VAL_LEN);                                  \
  83        (chip)->trace_msg[(chip)->msg_idx].valid = 1;                   \
  84        (chip)->msg_idx++;                                              \
  85        if ((chip)->msg_idx >= TRACE_ITEM_CNT) {                        \
  86                (chip)->msg_idx = 0;                                    \
  87        }                                                               \
  88        goto label;                                                     \
  89} while (0)
  90#else
  91#define TRACE_RET(chip, ret)    return (ret)
  92#define TRACE_GOTO(chip, label) goto label
  93#endif
  94
  95#ifdef CONFIG_RTS5139_DEBUG
  96static inline void rts51x_dump(u8 *buf, int buf_len)
  97{
  98        int i;
  99        u8 tmp[16] = { 0 };
 100        u8 *_ptr = buf;
 101
 102        for (i = 0; i < ((buf_len) / 16); i++) {
 103                RTS51X_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x "
 104                               "%02x %02x %02x %02x %02x %02x %02x %02x\n",
 105                               _ptr[0], _ptr[1], _ptr[2], _ptr[3], _ptr[4],
 106                               _ptr[5], _ptr[6], _ptr[7], _ptr[8], _ptr[9],
 107                               _ptr[10], _ptr[11], _ptr[12], _ptr[13], _ptr[14],
 108                               _ptr[15]);
 109                _ptr += 16;
 110        }
 111        if ((buf_len) % 16) {
 112                memcpy(tmp, _ptr, (buf_len) % 16);
 113                _ptr = tmp;
 114                RTS51X_DEBUGP("%02x %02x %02x %02x %02x %02x %02x %02x "
 115                               "%02x %02x %02x %02x %02x %02x %02x %02x\n",
 116                               _ptr[0], _ptr[1], _ptr[2], _ptr[3], _ptr[4],
 117                               _ptr[5], _ptr[6], _ptr[7], _ptr[8], _ptr[9],
 118                               _ptr[10], _ptr[11], _ptr[12], _ptr[13], _ptr[14],
 119                               _ptr[15]);
 120        }
 121}
 122
 123#define RTS51X_DUMP(buf, buf_len)       \
 124                rts51x_dump((u8 *)(buf), (buf_len))
 125
 126#define CATCH_TRIGGER(chip)                                     \
 127do {                                                            \
 128        rts51x_ep0_write_register((chip), 0xFC31, 0x01, 0x01);  \
 129        RTS51X_DEBUGP("Catch trigger!\n");                      \
 130} while (0)
 131
 132#else
 133#define RTS51X_DUMP(buf, buf_len)
 134#define CATCH_TRIGGER(chip)
 135#endif
 136
 137#endif /* __RTS51X_TRACE_H */
 138
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.