1 /**************************************************************************
5 * Copyright 2015 Samsung Electronics co., Ltd. All Rights Reserved.
7 * Contact: Eunchul Kim <chulspro.kim@samsung.com>,
8 * JinYoung Jeon <jy0.jeon@samsung.com>,
9 * Taeheon Kim <th908.kim@samsung.com>,
10 * YoungJun Cho <yj44.cho@samsung.com>,
11 * SooChan Lim <sc1.lim@samsung.com>,
12 * Boram Park <sc1.lim@samsung.com>
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sub license, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
22 * The above copyright notice and this permission notice (including the
23 * next paragraph) shall be included in all copies or substantial portions
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 **************************************************************************/
42 #include <sys/types.h>
44 #include <tdm_common.h>
54 #if defined(__GNUC__) && __GNUC__ >= 4
55 #define EXTERN __attribute__ ((visibility("default")))
60 #if defined(__GNUC__) && __GNUC__ >= 4
61 #define INTERN __attribute__ ((visibility("hidden")))
66 #if defined(__GNUC__) && __GNUC__ >= 4
67 #define DEPRECATED __attribute__ ((deprecated))
73 #define TDM_RETURN_IF_FAIL(cond) { \
75 TDM_ERR("'%s' failed", #cond); \
79 #define TDM_RETURN_VAL_IF_FAIL(cond, val) { \
81 TDM_ERR("'%s' failed", #cond); \
85 #define TDM_RETURN_VAL_IF_FAIL_WITH_ERROR(cond, error_v, val) { \
87 TDM_ERR("'%s' failed", #cond); \
89 if (error) *error = ret; \
94 #define TDM_WARNING_IF_FAIL(cond) { \
96 TDM_ERR("'%s' failed", #cond); \
98 #define TDM_GOTO_IF_FAIL(cond, dst) { \
100 TDM_ERR("'%s' failed", #cond); \
105 #define TDM_NEVER_GET_HERE() TDM_WRN("** NEVER GET HERE **")
107 #define TDM_SNPRINTF(p, len, fmt, ARG...) \
109 if (p && len && *len > 0) { \
110 int s = snprintf(p, *len, fmt, ##ARG); \
116 #define C(b, m) (((b) >> (m)) & 0xFF)
117 #define B(c, s) ((((unsigned int)(c)) & 0xff) << (s))
118 #define FOURCC(a, b, c, d) (B(d, 24) | B(c, 16) | B(b, 8) | B(a, 0))
119 #define FOURCC_STR(id) C(id, 0), C(id, 8), C(id, 16), C(id, 24)
120 #define FOURCC_ID(str) FOURCC(((char*)str)[0], ((char*)str)[1], ((char*)str)[2], ((char*)str)[3])
123 #define TDM_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
125 struct tdm_type_name {
130 #define TDM_TYPE_NAME_FN(res) \
131 static inline const char * tdm_##res##_str(int type) \
134 for (i = 0; i < TDM_ARRAY_SIZE(tdm_##res##_names); i++) { \
135 if (tdm_##res##_names[i].type == type) \
136 return tdm_##res##_names[i].name; \
138 return "(invalid)"; \
141 static struct tdm_type_name tdm_dpms_names[] = {
142 { TDM_OUTPUT_DPMS_ON, "on" },
143 { TDM_OUTPUT_DPMS_STANDBY, "standby" },
144 { TDM_OUTPUT_DPMS_SUSPEND, "suspend" },
145 { TDM_OUTPUT_DPMS_OFF, "off" },
148 TDM_TYPE_NAME_FN(dpms)
150 static struct tdm_type_name tdm_status_names[] = {
151 { TDM_OUTPUT_CONN_STATUS_DISCONNECTED, "disconnected" },
152 { TDM_OUTPUT_CONN_STATUS_CONNECTED, "connected" },
153 { TDM_OUTPUT_CONN_STATUS_MODE_SETTED, "mode_setted" },
156 TDM_TYPE_NAME_FN(status)
162 #endif /* _TDM_MACRO_H_ */