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