summaryrefstree
path: root/kernel/techpack/display/msm/dsi/dsi_parser.h
blob: 949de1b4b02efb26f21beb672f9eadf78407e784 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
 */

#ifndef _DSI_PARSER_H_
#define _DSI_PARSER_H_

#include <linux/of.h>
#include <linux/of_gpio.h>

#ifdef CONFIG_DSI_PARSER
void *dsi_parser_get(struct device *dev);
void dsi_parser_put(void *data);
int dsi_parser_dbg_init(void *parser, struct dentry *dir);
void *dsi_parser_get_head_node(void *parser,
		const u8 *data, u32 size);

const void *dsi_parser_get_property(const struct device_node *np,
			const char *name, int *lenp);
bool dsi_parser_read_bool(const struct device_node *np,
			const char *propname);
int dsi_parser_read_u64(const struct device_node *np, const char *propname,
			 u64 *out_value);
int dsi_parser_read_u32(const struct device_node *np,
			const char *propname, u32 *out_value);
int dsi_parser_read_u32_array(const struct device_node *np,
			const char *propname,
			u32 *out_values, size_t sz);
int dsi_parser_read_string(const struct device_node *np,
			const char *propname, const char **out_string);
struct device_node *dsi_parser_get_child_by_name(const struct device_node *node,
				const char *name);
int dsi_parser_get_child_count(const struct device_node *np);
struct property *dsi_parser_find_property(const struct device_node *np,
			const char *name, int *lenp);
struct device_node *dsi_parser_get_next_child(const struct device_node *np,
	struct device_node *prev);
int dsi_parser_count_u32_elems(const struct device_node *np,
				const char *propname);
int dsi_parser_count_strings(const struct device_node *np,
			    const char *propname);
int dsi_parser_read_string_index(const struct device_node *np,
				const char *propname,
				int index, const char **output);
int dsi_parser_get_named_gpio(struct device_node *np,
				const char *propname, int index);
#else /* CONFIG_DSI_PARSER */
static inline void *dsi_parser_get(struct device *dev)
{
	return NULL;
}

static inline void dsi_parser_put(void *data)
{
}

static inline int dsi_parser_dbg_init(void *parser, struct dentry *dir)
{
	return -ENODEV;
}

static inline void *dsi_parser_get_head_node(void *parser,
		const u8 *data, u32 size)
{
	return NULL;
}

static inline const void *dsi_parser_get_property(const struct device_node *np,
			const char *name, int *lenp)
{
	return NULL;
}

static inline bool dsi_parser_read_bool(const struct device_node *np,
			const char *propname)
{
	return false;
}

static inline int dsi_parser_read_u64(const struct device_node *np,
			const char *propname, u64 *out_value)
{
	return -ENODEV;
}

static inline int dsi_parser_read_u32(const struct device_node *np,
			const char *propname, u32 *out_value)
{
	return -ENODEV;
}

static inline int dsi_parser_read_u32_array(const struct device_node *np,
			const char *propname, u32 *out_values, size_t sz)
{
	return -ENODEV;
}

static inline int dsi_parser_read_string(const struct device_node *np,
			const char *propname, const char **out_string)
{
	return -ENODEV;
}

static inline struct device_node *dsi_parser_get_child_by_name(
				const struct device_node *node,
				const char *name)
{
	return NULL;
}

static inline int dsi_parser_get_child_count(const struct device_node *np)
{
	return -ENODEV;
}

static inline struct property *dsi_parser_find_property(
			const struct device_node *np,
			const char *name, int *lenp)
{
	return NULL;
}

static inline struct device_node *dsi_parser_get_next_child(
				const struct device_node *np,
				struct device_node *prev)
{
	return NULL;
}

static inline int dsi_parser_count_u32_elems(const struct device_node *np,
				const char *propname)
{
	return -ENODEV;
}

static inline int dsi_parser_count_strings(const struct device_node *np,
			    const char *propname)
{
	return -ENODEV;
}

static inline int dsi_parser_read_string_index(const struct device_node *np,
				const char *propname,
				int index, const char **output)
{
	return -ENODEV;
}

static inline int dsi_parser_get_named_gpio(struct device_node *np,
				const char *propname, int index)
{
	return -ENODEV;
}

#endif /* CONFIG_DSI_PARSER */

#define dsi_for_each_child_node(parent, child) \
	for (child = utils->get_next_child(parent, NULL); \
	     child != NULL; \
	     child = utils->get_next_child(parent, child))

struct dsi_parser_utils {
	void *data;
	struct device_node *node;

	const void *(*get_property)(const struct device_node *np,
			const char *name, int *lenp);
	int (*read_u64)(const struct device_node *np,
			const char *propname, u64 *out_value);
	int (*read_u32)(const struct device_node *np,
			const char *propname, u32 *out_value);
	bool (*read_bool)(const struct device_node *np,
			 const char *propname);
	int (*read_u32_array)(const struct device_node *np,
			const char *propname, u32 *out_values, size_t sz);
	int (*read_string)(const struct device_node *np, const char *propname,
				const char **out_string);
	struct device_node *(*get_child_by_name)(
				const struct device_node *node,
				const char *name);
	int (*get_child_count)(const struct device_node *np);
	struct property *(*find_property)(const struct device_node *np,
			const char *name, int *lenp);
	struct device_node *(*get_next_child)(const struct device_node *np,
		struct device_node *prev);
	int (*count_u32_elems)(const struct device_node *np,
		const char *propname);
	int (*get_named_gpio)(struct device_node *np,
				const char *propname, int index);
	int (*get_available_child_count)(const struct device_node *np);
};

static inline struct dsi_parser_utils *dsi_parser_get_of_utils(void)
{
	static struct dsi_parser_utils of_utils = {
		.get_property = of_get_property,
		.read_bool = of_property_read_bool,
		.read_u64 = of_property_read_u64,
		.read_u32 = of_property_read_u32,
		.read_u32_array = of_property_read_u32_array,
		.read_string = of_property_read_string,
		.get_child_by_name = of_get_child_by_name,
		.get_child_count = of_get_child_count,
		.get_available_child_count = of_get_available_child_count,
		.find_property = of_find_property,
		.get_next_child = of_get_next_child,
		.count_u32_elems = of_property_count_u32_elems,
		.get_named_gpio = of_get_named_gpio,
	};

	return &of_utils;
}

static inline struct dsi_parser_utils *dsi_parser_get_parser_utils(void)
{
	static struct dsi_parser_utils parser_utils = {
		.get_property = dsi_parser_get_property,
		.read_bool = dsi_parser_read_bool,
		.read_u64 = dsi_parser_read_u64,
		.read_u32 = dsi_parser_read_u32,
		.read_u32_array = dsi_parser_read_u32_array,
		.read_string = dsi_parser_read_string,
		.get_child_by_name = dsi_parser_get_child_by_name,
		.get_child_count = dsi_parser_get_child_count,
		.get_available_child_count = dsi_parser_get_child_count,
		.find_property = dsi_parser_find_property,
		.get_next_child = dsi_parser_get_next_child,
		.count_u32_elems = dsi_parser_count_u32_elems,
		.get_named_gpio = dsi_parser_get_named_gpio,
	};

	return &parser_utils;
}
#endif