dsi_parser.h 7.6 KB

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