hte.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_HTE_H
  3. #define __LINUX_HTE_H
  4. #include <linux/errno.h>
  5. struct hte_chip;
  6. struct hte_device;
  7. struct of_phandle_args;
  8. /**
  9. * enum hte_edge - HTE line edge flags.
  10. *
  11. * @HTE_EDGE_NO_SETUP: No edge setup. In this case consumer will setup edges,
  12. * for example during request irq call.
  13. * @HTE_RISING_EDGE_TS: Rising edge.
  14. * @HTE_FALLING_EDGE_TS: Falling edge.
  15. *
  16. */
  17. enum hte_edge {
  18. HTE_EDGE_NO_SETUP = 1U << 0,
  19. HTE_RISING_EDGE_TS = 1U << 1,
  20. HTE_FALLING_EDGE_TS = 1U << 2,
  21. };
  22. /**
  23. * enum hte_return - HTE subsystem return values used during callback.
  24. *
  25. * @HTE_CB_HANDLED: The consumer handled the data.
  26. * @HTE_RUN_SECOND_CB: The consumer needs further processing, in that case
  27. * HTE subsystem calls secondary callback provided by the consumer where it
  28. * is allowed to sleep.
  29. */
  30. enum hte_return {
  31. HTE_CB_HANDLED,
  32. HTE_RUN_SECOND_CB,
  33. };
  34. /**
  35. * struct hte_ts_data - HTE timestamp data.
  36. *
  37. * @tsc: Timestamp value.
  38. * @seq: Sequence counter of the timestamps.
  39. * @raw_level: Level of the line at the timestamp if provider supports it,
  40. * -1 otherwise.
  41. */
  42. struct hte_ts_data {
  43. u64 tsc;
  44. u64 seq;
  45. int raw_level;
  46. };
  47. /**
  48. * struct hte_clk_info - Clock source info that HTE provider uses to timestamp.
  49. *
  50. * @hz: Supported clock rate in HZ, for example 1KHz clock = 1000.
  51. * @type: Supported clock type.
  52. */
  53. struct hte_clk_info {
  54. u64 hz;
  55. clockid_t type;
  56. };
  57. /**
  58. * typedef hte_ts_cb_t - HTE timestamp data processing primary callback.
  59. *
  60. * The callback is used to push timestamp data to the client and it is
  61. * not allowed to sleep.
  62. *
  63. * @ts: HW timestamp data.
  64. * @data: Client supplied data.
  65. */
  66. typedef enum hte_return (*hte_ts_cb_t)(struct hte_ts_data *ts, void *data);
  67. /**
  68. * typedef hte_ts_sec_cb_t - HTE timestamp data processing secondary callback.
  69. *
  70. * This is used when the client needs further processing where it is
  71. * allowed to sleep.
  72. *
  73. * @data: Client supplied data.
  74. *
  75. */
  76. typedef enum hte_return (*hte_ts_sec_cb_t)(void *data);
  77. /**
  78. * struct hte_line_attr - Line attributes.
  79. *
  80. * @line_id: The logical ID understood by the consumers and providers.
  81. * @line_data: Line data related to line_id.
  82. * @edge_flags: Edge setup flags.
  83. * @name: Descriptive name of the entity that is being monitored for the
  84. * hardware timestamping. If null, HTE core will construct the name.
  85. *
  86. */
  87. struct hte_line_attr {
  88. u32 line_id;
  89. void *line_data;
  90. unsigned long edge_flags;
  91. const char *name;
  92. };
  93. /**
  94. * struct hte_ts_desc - HTE timestamp descriptor.
  95. *
  96. * This structure is a communication token between consumers to subsystem
  97. * and subsystem to providers.
  98. *
  99. * @attr: The line attributes.
  100. * @hte_data: Subsystem's private data, set by HTE subsystem.
  101. */
  102. struct hte_ts_desc {
  103. struct hte_line_attr attr;
  104. void *hte_data;
  105. };
  106. /**
  107. * struct hte_ops - HTE operations set by providers.
  108. *
  109. * @request: Hook for requesting a HTE timestamp. Returns 0 on success,
  110. * non-zero for failures.
  111. * @release: Hook for releasing a HTE timestamp. Returns 0 on success,
  112. * non-zero for failures.
  113. * @enable: Hook to enable the specified timestamp. Returns 0 on success,
  114. * non-zero for failures.
  115. * @disable: Hook to disable specified timestamp. Returns 0 on success,
  116. * non-zero for failures.
  117. * @get_clk_src_info: Hook to get the clock information the provider uses
  118. * to timestamp. Returns 0 for success and negative error code for failure. On
  119. * success HTE subsystem fills up provided struct hte_clk_info.
  120. *
  121. * xlated_id parameter is used to communicate between HTE subsystem and the
  122. * providers and is translated by the provider.
  123. */
  124. struct hte_ops {
  125. int (*request)(struct hte_chip *chip, struct hte_ts_desc *desc,
  126. u32 xlated_id);
  127. int (*release)(struct hte_chip *chip, struct hte_ts_desc *desc,
  128. u32 xlated_id);
  129. int (*enable)(struct hte_chip *chip, u32 xlated_id);
  130. int (*disable)(struct hte_chip *chip, u32 xlated_id);
  131. int (*get_clk_src_info)(struct hte_chip *chip,
  132. struct hte_clk_info *ci);
  133. };
  134. /**
  135. * struct hte_chip - Abstract HTE chip.
  136. *
  137. * @name: functional name of the HTE IP block.
  138. * @dev: device providing the HTE.
  139. * @ops: callbacks for this HTE.
  140. * @nlines: number of lines/signals supported by this chip.
  141. * @xlate_of: Callback which translates consumer supplied logical ids to
  142. * physical ids, return 0 for the success and negative for the failures.
  143. * It stores (between 0 to @nlines) in xlated_id parameter for the success.
  144. * @xlate_plat: Same as above but for the consumers with no DT node.
  145. * @match_from_linedata: Match HTE device using the line_data.
  146. * @of_hte_n_cells: Number of cells used to form the HTE specifier.
  147. * @gdev: HTE subsystem abstract device, internal to the HTE subsystem.
  148. * @data: chip specific private data.
  149. */
  150. struct hte_chip {
  151. const char *name;
  152. struct device *dev;
  153. const struct hte_ops *ops;
  154. u32 nlines;
  155. int (*xlate_of)(struct hte_chip *gc,
  156. const struct of_phandle_args *args,
  157. struct hte_ts_desc *desc, u32 *xlated_id);
  158. int (*xlate_plat)(struct hte_chip *gc, struct hte_ts_desc *desc,
  159. u32 *xlated_id);
  160. bool (*match_from_linedata)(const struct hte_chip *chip,
  161. const struct hte_ts_desc *hdesc);
  162. u8 of_hte_n_cells;
  163. struct hte_device *gdev;
  164. void *data;
  165. };
  166. #if IS_ENABLED(CONFIG_HTE)
  167. /* HTE APIs for the providers */
  168. int devm_hte_register_chip(struct hte_chip *chip);
  169. int hte_push_ts_ns(const struct hte_chip *chip, u32 xlated_id,
  170. struct hte_ts_data *data);
  171. /* HTE APIs for the consumers */
  172. int hte_init_line_attr(struct hte_ts_desc *desc, u32 line_id,
  173. unsigned long edge_flags, const char *name,
  174. void *data);
  175. int hte_ts_get(struct device *dev, struct hte_ts_desc *desc, int index);
  176. int hte_ts_put(struct hte_ts_desc *desc);
  177. int hte_request_ts_ns(struct hte_ts_desc *desc, hte_ts_cb_t cb,
  178. hte_ts_sec_cb_t tcb, void *data);
  179. int devm_hte_request_ts_ns(struct device *dev, struct hte_ts_desc *desc,
  180. hte_ts_cb_t cb, hte_ts_sec_cb_t tcb, void *data);
  181. int of_hte_req_count(struct device *dev);
  182. int hte_enable_ts(struct hte_ts_desc *desc);
  183. int hte_disable_ts(struct hte_ts_desc *desc);
  184. int hte_get_clk_src_info(const struct hte_ts_desc *desc,
  185. struct hte_clk_info *ci);
  186. #else /* !CONFIG_HTE */
  187. static inline int devm_hte_register_chip(struct hte_chip *chip)
  188. {
  189. return -EOPNOTSUPP;
  190. }
  191. static inline int hte_push_ts_ns(const struct hte_chip *chip,
  192. u32 xlated_id,
  193. const struct hte_ts_data *data)
  194. {
  195. return -EOPNOTSUPP;
  196. }
  197. static inline int hte_init_line_attr(struct hte_ts_desc *desc, u32 line_id,
  198. unsigned long edge_flags,
  199. const char *name, void *data)
  200. {
  201. return -EOPNOTSUPP;
  202. }
  203. static inline int hte_ts_get(struct device *dev, struct hte_ts_desc *desc,
  204. int index)
  205. {
  206. return -EOPNOTSUPP;
  207. }
  208. static inline int hte_ts_put(struct hte_ts_desc *desc)
  209. {
  210. return -EOPNOTSUPP;
  211. }
  212. static inline int hte_request_ts_ns(struct hte_ts_desc *desc, hte_ts_cb_t cb,
  213. hte_ts_sec_cb_t tcb, void *data)
  214. {
  215. return -EOPNOTSUPP;
  216. }
  217. static inline int devm_hte_request_ts_ns(struct device *dev,
  218. struct hte_ts_desc *desc,
  219. hte_ts_cb_t cb,
  220. hte_ts_sec_cb_t tcb,
  221. void *data)
  222. {
  223. return -EOPNOTSUPP;
  224. }
  225. static inline int of_hte_req_count(struct device *dev)
  226. {
  227. return -EOPNOTSUPP;
  228. }
  229. static inline int hte_enable_ts(struct hte_ts_desc *desc)
  230. {
  231. return -EOPNOTSUPP;
  232. }
  233. static inline int hte_disable_ts(struct hte_ts_desc *desc)
  234. {
  235. return -EOPNOTSUPP;
  236. }
  237. static inline int hte_get_clk_src_info(const struct hte_ts_desc *desc,
  238. struct hte_clk_info *ci)
  239. {
  240. return -EOPNOTSUPP;
  241. }
  242. #endif /* !CONFIG_HTE */
  243. #endif