dsi_parser.h 6.7 KB

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