dsi_parser.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DSI_PARSER_H_
  6. #define _DSI_PARSER_H_
  7. #include <linux/of.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/version.h>
  10. #ifdef CONFIG_DSI_PARSER
  11. void *dsi_parser_get(struct device *dev);
  12. void dsi_parser_put(void *data);
  13. int dsi_parser_dbg_init(void *parser, struct dentry *dir);
  14. void *dsi_parser_get_head_node(void *parser,
  15. const u8 *data, u32 size);
  16. const void *dsi_parser_get_property(const struct device_node *np,
  17. const char *name, int *lenp);
  18. bool dsi_parser_read_bool(const struct device_node *np,
  19. const char *propname);
  20. int dsi_parser_read_u64(const struct device_node *np, const char *propname,
  21. u64 *out_value);
  22. int dsi_parser_read_u32(const struct device_node *np,
  23. const char *propname, u32 *out_value);
  24. int dsi_parser_read_u32_index(const struct device_node *np,
  25. const char *propname, u32 index, u32 *out_value);
  26. int dsi_parser_read_u32_array(const struct device_node *np,
  27. const char *propname,
  28. u32 *out_values, size_t sz);
  29. int dsi_parser_read_string(const struct device_node *np,
  30. const char *propname, const char **out_string);
  31. struct device_node *dsi_parser_get_child_by_name(const struct device_node *node,
  32. const char *name);
  33. int dsi_parser_get_child_count(const struct device_node *np);
  34. struct property *dsi_parser_find_property(const struct device_node *np,
  35. const char *name, int *lenp);
  36. struct device_node *dsi_parser_get_next_child(const struct device_node *np,
  37. struct device_node *prev);
  38. int dsi_parser_count_u32_elems(const struct device_node *np,
  39. const char *propname);
  40. int dsi_parser_count_strings(const struct device_node *np,
  41. const char *propname);
  42. int dsi_parser_read_string_index(const struct device_node *np,
  43. const char *propname,
  44. int index, const char **output);
  45. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  46. int dsi_parser_get_named_gpio(const struct device_node *np,
  47. const char *propname, int index);
  48. #else
  49. int dsi_parser_get_named_gpio(struct device_node *np,
  50. const char *propname, int index);
  51. #endif
  52. #else /* CONFIG_DSI_PARSER */
  53. static inline void *dsi_parser_get(struct device *dev)
  54. {
  55. return NULL;
  56. }
  57. static inline void dsi_parser_put(void *data)
  58. {
  59. }
  60. static inline int dsi_parser_dbg_init(void *parser, struct dentry *dir)
  61. {
  62. return -ENODEV;
  63. }
  64. static inline void *dsi_parser_get_head_node(void *parser,
  65. const u8 *data, u32 size)
  66. {
  67. return NULL;
  68. }
  69. static inline const void *dsi_parser_get_property(const struct device_node *np,
  70. const char *name, int *lenp)
  71. {
  72. return NULL;
  73. }
  74. static inline bool dsi_parser_read_bool(const struct device_node *np,
  75. const char *propname)
  76. {
  77. return false;
  78. }
  79. static inline int dsi_parser_read_u64(const struct device_node *np,
  80. const char *propname, u64 *out_value)
  81. {
  82. return -ENODEV;
  83. }
  84. static inline int dsi_parser_read_u32(const struct device_node *np,
  85. const char *propname, u32 *out_value)
  86. {
  87. return -ENODEV;
  88. }
  89. static inline int dsi_parser_read_u32_index(const struct device_node *np,
  90. const char *propname, u32 index, u32 *out_value)
  91. {
  92. return -ENODEV;
  93. }
  94. static inline int dsi_parser_read_u32_array(const struct device_node *np,
  95. const char *propname, u32 *out_values, size_t sz)
  96. {
  97. return -ENODEV;
  98. }
  99. static inline int dsi_parser_read_string(const struct device_node *np,
  100. const char *propname, const char **out_string)
  101. {
  102. return -ENODEV;
  103. }
  104. static inline struct device_node *dsi_parser_get_child_by_name(
  105. const struct device_node *node,
  106. const char *name)
  107. {
  108. return NULL;
  109. }
  110. static inline int dsi_parser_get_child_count(const struct device_node *np)
  111. {
  112. return -ENODEV;
  113. }
  114. static inline struct property *dsi_parser_find_property(
  115. const struct device_node *np,
  116. const char *name, int *lenp)
  117. {
  118. return NULL;
  119. }
  120. static inline struct device_node *dsi_parser_get_next_child(
  121. const struct device_node *np,
  122. struct device_node *prev)
  123. {
  124. return NULL;
  125. }
  126. static inline int dsi_parser_count_u32_elems(const struct device_node *np,
  127. const char *propname)
  128. {
  129. return -ENODEV;
  130. }
  131. static inline int dsi_parser_count_strings(const struct device_node *np,
  132. const char *propname)
  133. {
  134. return -ENODEV;
  135. }
  136. static inline int dsi_parser_read_string_index(const struct device_node *np,
  137. const char *propname,
  138. int index, const char **output)
  139. {
  140. return -ENODEV;
  141. }
  142. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  143. static inline int dsi_parser_get_named_gpio(const struct device_node *np,
  144. const char *propname, int index)
  145. {
  146. return -ENODEV;
  147. }
  148. #else
  149. static inline int dsi_parser_get_named_gpio(struct device_node *np,
  150. char *propname, int index)
  151. {
  152. return -ENODEV;
  153. }
  154. #endif
  155. #endif /* CONFIG_DSI_PARSER */
  156. #define dsi_for_each_child_node(parent, child) \
  157. for (child = utils->get_next_child(parent, NULL); \
  158. child != NULL; \
  159. child = utils->get_next_child(parent, child))
  160. struct dsi_parser_utils {
  161. void *data;
  162. struct device_node *node;
  163. const void *(*get_property)(const struct device_node *np,
  164. const char *name, int *lenp);
  165. int (*read_u64)(const struct device_node *np,
  166. const char *propname, u64 *out_value);
  167. int (*read_u32)(const struct device_node *np,
  168. const char *propname, u32 *out_value);
  169. int (*read_u32_index)(const struct device_node *np,
  170. const char *propname, u32 index, u32 *out_value);
  171. bool (*read_bool)(const struct device_node *np,
  172. const char *propname);
  173. int (*read_u32_array)(const struct device_node *np,
  174. const char *propname, u32 *out_values, size_t sz);
  175. int (*read_string)(const struct device_node *np, const char *propname,
  176. const char **out_string);
  177. int (*read_string_index)(const struct device_node *np,
  178. const char *propname,
  179. int index, const char **output);
  180. struct device_node *(*get_child_by_name)(
  181. const struct device_node *node,
  182. const char *name);
  183. int (*get_child_count)(const struct device_node *np);
  184. struct property *(*find_property)(const struct device_node *np,
  185. const char *name, int *lenp);
  186. struct device_node *(*get_next_child)(const struct device_node *np,
  187. struct device_node *prev);
  188. int (*count_u32_elems)(const struct device_node *np,
  189. const char *propname);
  190. int (*count_strings)(const struct device_node *np,
  191. const char *propname);
  192. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0))
  193. int (*get_named_gpio)(const struct device_node *np,
  194. const char *propname, int index);
  195. #else
  196. int (*get_named_gpio)(struct device_node *np,
  197. const char *propname, int index);
  198. #endif
  199. int (*get_available_child_count)(const struct device_node *np);
  200. };
  201. static inline struct dsi_parser_utils *dsi_parser_get_of_utils(void)
  202. {
  203. static struct dsi_parser_utils of_utils = {
  204. .get_property = of_get_property,
  205. .read_bool = of_property_read_bool,
  206. .read_u64 = of_property_read_u64,
  207. .read_u32 = of_property_read_u32,
  208. .read_u32_index = of_property_read_u32_index,
  209. .read_u32_array = of_property_read_u32_array,
  210. .read_string = of_property_read_string,
  211. .read_string_index = of_property_read_string_index,
  212. .get_child_by_name = of_get_child_by_name,
  213. .get_child_count = of_get_child_count,
  214. .get_available_child_count = of_get_available_child_count,
  215. .find_property = of_find_property,
  216. .get_next_child = of_get_next_child,
  217. .count_u32_elems = of_property_count_u32_elems,
  218. .count_strings = of_property_count_strings,
  219. .get_named_gpio = of_get_named_gpio,
  220. };
  221. return &of_utils;
  222. }
  223. static inline struct dsi_parser_utils *dsi_parser_get_parser_utils(void)
  224. {
  225. static struct dsi_parser_utils parser_utils = {
  226. .get_property = dsi_parser_get_property,
  227. .read_bool = dsi_parser_read_bool,
  228. .read_u64 = dsi_parser_read_u64,
  229. .read_u32 = dsi_parser_read_u32,
  230. .read_u32_index = dsi_parser_read_u32_index,
  231. .read_u32_array = dsi_parser_read_u32_array,
  232. .read_string = dsi_parser_read_string,
  233. .read_string_index = dsi_parser_read_string_index,
  234. .get_child_by_name = dsi_parser_get_child_by_name,
  235. .get_child_count = dsi_parser_get_child_count,
  236. .get_available_child_count = dsi_parser_get_child_count,
  237. .find_property = dsi_parser_find_property,
  238. .get_next_child = dsi_parser_get_next_child,
  239. .count_u32_elems = dsi_parser_count_u32_elems,
  240. .count_strings = dsi_parser_count_strings,
  241. .get_named_gpio = dsi_parser_get_named_gpio,
  242. };
  243. return &parser_utils;
  244. }
  245. #endif