Setting up repository
[linux-libre-firmware.git] / carl9170fw / carlfw / include / printf.h
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * printf and his friends...
5  *
6  * Copyright (c) 2000-2005 ZyDAS Technology Corporation
7  * Copyright (c) 2007-2009 Atheros Communications, Inc.
8  * Copyright    2009    Johannes Berg <johannes@sipsolutions.net>
9  * Copyright 2009-2011  Christian Lamparter <chunkeey@googlemail.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #ifndef __CARL9170FW_PRINTF_H
27 #define __CARL9170FW_PRINTF_H
28
29 #include <stdarg.h>
30 #include <string.h>
31 #include "config.h"
32 #include "carl9170.h"
33 #include "uart.h"
34 #include "fwcmd.h"
35
36 #ifdef CONFIG_CARL9170FW_PRINTF
37 void __attribute__((format (printf, 1, 2))) tfp_printf(const char *fmt, ...);
38
39 #define printf tfp_printf
40
41 #else
42 void __attribute__((format (printf, 1, 2))) min_printf(const char *fmt, ...);
43
44 #define printf min_printf
45 #endif /* CONFIG_CARL9170FW_PRINTF */
46
47 #define PRINT(fmt, args...)                                             \
48         do {                                                            \
49                 printf(fmt, ## args);                                   \
50         } while (0)
51
52 #define INFO(fmt, args...)      PRINT(fmt, ## args)
53
54 #define ERR(fmt, args...)       PRINT(CARL9170_ERR_MAGIC fmt, ## args)
55
56 #ifdef CONFIG_CARL9170FW_DEBUG
57 #define DBG(fmt, args...)       PRINT(fmt, ## args)
58 #else
59 #define DBG(...)                do { } while (0);
60 #endif
61
62 /*
63  * NB: even though the MACRO is called "stall". It isn't supposed
64  * to stall since this will render the device unresponsive, until
65  * someone pulls the plug.
66  */
67 #define STALL()
68
69 #define BUG(fmt, args...)                                               \
70         do {                                                            \
71                 PRINT(CARL9170_BUG_MAGIC" %s()@%d \"" fmt "\"" ,        \
72                       __func__, __LINE__, ## args);                     \
73                 STALL()                                                 \
74         } while (0);
75
76 #define BUG_ON(condition)                                               \
77         ({                                                              \
78                 int __ret = !!(condition);                              \
79                 if (unlikely(!!(__ret)))                                \
80                         BUG(#condition);                                \
81                 (__ret);                                                \
82         })
83
84 static inline __inline void putcharacter(const char c __unused)
85 {
86 #ifdef CONFIG_CARL9170FW_DEBUG_USB
87         usb_putc(c);
88 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
89
90 #ifdef CONFIG_CARL9170FW_DEBUG_UART
91         uart_putc(c);
92 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
93 }
94
95 static inline __inline void print_hex_dump(const void *buf __unused, int len __unused)
96 {
97 #ifdef CONFIG_CARL9170FW_DEBUG_USB
98         usb_print_hex_dump(buf, len);
99 #endif /* CONFIG_CARL9170FW_DEBUG_USB */
100
101 #ifdef CONFIG_CARL9170FW_DEBUG_UART
102         uart_print_hex_dump(buf, len);
103 #endif /* CONFIG_CARL9170FW_DEBUG_UART */
104 }
105
106 #endif /* __CARL9170FW_PRINTF_H */
107