dsi_parser.h 8.2 KB

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