1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Texas Instruments System Control Interface Protocol
4  * Based on include/linux/soc/ti/ti_sci_protocol.h from Linux.
5  *
6  * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
7  *	Nishanth Menon
8  *	Lokesh Vutla <lokeshvutla@ti.com>
9  */
10 
11 #ifndef __TISCI_PROTOCOL_H
12 #define __TISCI_PROTOCOL_H
13 
14 /**
15  * struct ti_sci_version_info - version information structure
16  * @abi_major:	Major ABI version. Change here implies risk of backward
17  *		compatibility break.
18  * @abi_minor:	Minor ABI version. Change here implies new feature addition,
19  *		or compatible change in ABI.
20  * @firmware_revision:	Firmware revision (not usually used).
21  * @firmware_description: Firmware description (not usually used).
22  */
23 struct ti_sci_version_info {
24 	u8 abi_major;
25 	u8 abi_minor;
26 	u16 firmware_revision;
27 	char firmware_description[32];
28 };
29 
30 struct ti_sci_handle;
31 
32 /**
33  * struct ti_sci_board_ops - Board config operations
34  * @board_config: Command to set the board configuration
35  *		  Returns 0 for successful exclusive request, else returns
36  *		  corresponding error message.
37  * @board_config_rm: Command to set the board resource management
38  *		  configuration
39  *		  Returns 0 for successful exclusive request, else returns
40  *		  corresponding error message.
41  * @board_config_security: Command to set the board security configuration
42  *		  Returns 0 for successful exclusive request, else returns
43  *		  corresponding error message.
44  * @board_config_pm: Command to trigger and set the board power and clock
45  *		  management related configuration
46  *		  Returns 0 for successful exclusive request, else returns
47  *		  corresponding error message.
48  */
49 struct ti_sci_board_ops {
50 	int (*board_config)(const struct ti_sci_handle *handle,
51 			    u64 addr, u32 size);
52 	int (*board_config_rm)(const struct ti_sci_handle *handle,
53 			       u64 addr, u32 size);
54 	int (*board_config_security)(const struct ti_sci_handle *handle,
55 				     u64 addr, u32 size);
56 	int (*board_config_pm)(const struct ti_sci_handle *handle,
57 			       u64 addr, u32 size);
58 };
59 
60 /**
61  * struct ti_sci_dev_ops - Device control operations
62  * @get_device: Command to request for device managed by TISCI
63  *		Returns 0 for successful exclusive request, else returns
64  *		corresponding error message.
65  * @idle_device: Command to idle a device managed by TISCI
66  *		Returns 0 for successful exclusive request, else returns
67  *		corresponding error message.
68  * @put_device:	Command to release a device managed by TISCI
69  *		Returns 0 for successful release, else returns corresponding
70  *		error message.
71  * @is_valid:	Check if the device ID is a valid ID.
72  *		Returns 0 if the ID is valid, else returns corresponding error.
73  * @get_context_loss_count: Command to retrieve context loss counter - this
74  *		increments every time the device looses context. Overflow
75  *		is possible.
76  *		- count: pointer to u32 which will retrieve counter
77  *		Returns 0 for successful information request and count has
78  *		proper data, else returns corresponding error message.
79  * @is_idle:	Reports back about device idle state
80  *		- req_state: Returns requested idle state
81  *		Returns 0 for successful information request and req_state and
82  *		current_state has proper data, else returns corresponding error
83  *		message.
84  * @is_stop:	Reports back about device stop state
85  *		- req_state: Returns requested stop state
86  *		- current_state: Returns current stop state
87  *		Returns 0 for successful information request and req_state and
88  *		current_state has proper data, else returns corresponding error
89  *		message.
90  * @is_on:	Reports back about device ON(or active) state
91  *		- req_state: Returns requested ON state
92  *		- current_state: Returns current ON state
93  *		Returns 0 for successful information request and req_state and
94  *		current_state has proper data, else returns corresponding error
95  *		message.
96  * @is_transitioning: Reports back if the device is in the middle of transition
97  *		of state.
98  *		-current_state: Returns 'true' if currently transitioning.
99  * @set_device_resets: Command to configure resets for device managed by TISCI.
100  *		-reset_state: Device specific reset bit field
101  *		Returns 0 for successful request, else returns
102  *		corresponding error message.
103  * @get_device_resets: Command to read state of resets for device managed
104  *		by TISCI.
105  *		-reset_state: pointer to u32 which will retrieve resets
106  *		Returns 0 for successful request, else returns
107  *		corresponding error message.
108  *
109  * NOTE: for all these functions, the following parameters are generic in
110  * nature:
111  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
112  * -id:		Device Identifier
113  *
114  * Request for the device - NOTE: the client MUST maintain integrity of
115  * usage count by balancing get_device with put_device. No refcounting is
116  * managed by driver for that purpose.
117  */
118 struct ti_sci_dev_ops {
119 	int (*get_device)(const struct ti_sci_handle *handle, u32 id);
120 	int (*idle_device)(const struct ti_sci_handle *handle, u32 id);
121 	int (*put_device)(const struct ti_sci_handle *handle, u32 id);
122 	int (*is_valid)(const struct ti_sci_handle *handle, u32 id);
123 	int (*get_context_loss_count)(const struct ti_sci_handle *handle,
124 				      u32 id, u32 *count);
125 	int (*is_idle)(const struct ti_sci_handle *handle, u32 id,
126 		       bool *requested_state);
127 	int (*is_stop)(const struct ti_sci_handle *handle, u32 id,
128 		       bool *req_state, bool *current_state);
129 	int (*is_on)(const struct ti_sci_handle *handle, u32 id,
130 		     bool *req_state, bool *current_state);
131 	int (*is_transitioning)(const struct ti_sci_handle *handle, u32 id,
132 				bool *current_state);
133 	int (*set_device_resets)(const struct ti_sci_handle *handle, u32 id,
134 				 u32 reset_state);
135 	int (*get_device_resets)(const struct ti_sci_handle *handle, u32 id,
136 				 u32 *reset_state);
137 };
138 
139 /**
140  * struct ti_sci_clk_ops - Clock control operations
141  * @get_clock:	Request for activation of clock and manage by processor
142  *		- needs_ssc: 'true' if Spread Spectrum clock is desired.
143  *		- can_change_freq: 'true' if frequency change is desired.
144  *		- enable_input_term: 'true' if input termination is desired.
145  * @idle_clock:	Request for Idling a clock managed by processor
146  * @put_clock:	Release the clock to be auto managed by TISCI
147  * @is_auto:	Is the clock being auto managed
148  *		- req_state: state indicating if the clock is auto managed
149  * @is_on:	Is the clock ON
150  *		- req_state: if the clock is requested to be forced ON
151  *		- current_state: if the clock is currently ON
152  * @is_off:	Is the clock OFF
153  *		- req_state: if the clock is requested to be forced OFF
154  *		- current_state: if the clock is currently Gated
155  * @set_parent:	Set the clock source of a specific device clock
156  *		- parent_id: Parent clock identifier to set.
157  * @get_parent:	Get the current clock source of a specific device clock
158  *		- parent_id: Parent clock identifier which is the parent.
159  * @get_num_parents: Get the number of parents of the current clock source
160  *		- num_parents: returns the number of parent clocks.
161  * @get_best_match_freq: Find a best matching frequency for a frequency
162  *		range.
163  *		- match_freq: Best matching frequency in Hz.
164  * @set_freq:	Set the Clock frequency
165  * @get_freq:	Get the Clock frequency
166  *		- current_freq: Frequency in Hz that the clock is at.
167  *
168  * NOTE: for all these functions, the following parameters are generic in
169  * nature:
170  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
171  * -did:	Device identifier this request is for
172  * -cid:	Clock identifier for the device for this request.
173  *		Each device has it's own set of clock inputs. This indexes
174  *		which clock input to modify.
175  * -min_freq:	The minimum allowable frequency in Hz. This is the minimum
176  *		allowable programmed frequency and does not account for clock
177  *		tolerances and jitter.
178  * -target_freq: The target clock frequency in Hz. A frequency will be
179  *		processed as close to this target frequency as possible.
180  * -max_freq:	The maximum allowable frequency in Hz. This is the maximum
181  *		allowable programmed frequency and does not account for clock
182  *		tolerances and jitter.
183  *
184  * Request for the clock - NOTE: the client MUST maintain integrity of
185  * usage count by balancing get_clock with put_clock. No refcounting is
186  * managed by driver for that purpose.
187  */
188 struct ti_sci_clk_ops {
189 	int (*get_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid,
190 			 bool needs_ssc, bool can_change_freq,
191 			 bool enable_input_term);
192 	int (*idle_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid);
193 	int (*put_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid);
194 	int (*is_auto)(const struct ti_sci_handle *handle, u32 did, u8 cid,
195 		       bool *req_state);
196 	int (*is_on)(const struct ti_sci_handle *handle, u32 did, u8 cid,
197 		     bool *req_state, bool *current_state);
198 	int (*is_off)(const struct ti_sci_handle *handle, u32 did, u8 cid,
199 		      bool *req_state, bool *current_state);
200 	int (*set_parent)(const struct ti_sci_handle *handle, u32 did, u8 cid,
201 			  u8 parent_id);
202 	int (*get_parent)(const struct ti_sci_handle *handle, u32 did, u8 cid,
203 			  u8 *parent_id);
204 	int (*get_num_parents)(const struct ti_sci_handle *handle, u32 did,
205 			       u8 cid, u8 *num_parents);
206 	int (*get_best_match_freq)(const struct ti_sci_handle *handle, u32 did,
207 				   u8 cid, u64 min_freq, u64 target_freq,
208 				   u64 max_freq, u64 *match_freq);
209 	int (*set_freq)(const struct ti_sci_handle *handle, u32 did, u8 cid,
210 			u64 min_freq, u64 target_freq, u64 max_freq);
211 	int (*get_freq)(const struct ti_sci_handle *handle, u32 did, u8 cid,
212 			u64 *current_freq);
213 };
214 
215 /**
216  * struct ti_sci_core_ops - SoC Core Operations
217  * @reboot_device: Reboot the SoC
218  *		Returns 0 for successful request(ideally should never return),
219  *		else returns corresponding error value.
220  */
221 struct ti_sci_core_ops {
222 	int (*reboot_device)(const struct ti_sci_handle *handle);
223 };
224 
225 /**
226  * struct ti_sci_proc_ops - Processor specific operations.
227  *
228  * @proc_request: Request for controlling a physical processor.
229  *		The requesting host should be in the processor access list.
230  * @proc_release: Relinquish a physical processor control
231  * @proc_handover: Handover a physical processor control to another host
232  *		   in the permitted list.
233  * @set_proc_boot_cfg: Base configuration of the processor
234  * @set_proc_boot_ctrl: Setup limited control flags in specific cases.
235  * @proc_auth_boot_image:
236  * @get_proc_boot_status: Get the state of physical processor
237  *
238  * NOTE: for all these functions, the following parameters are generic in
239  * nature:
240  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
241  * -pid:	Processor ID
242  *
243  */
244 struct ti_sci_proc_ops {
245 	int (*proc_request)(const struct ti_sci_handle *handle, u8 pid);
246 	int (*proc_release)(const struct ti_sci_handle *handle, u8 pid);
247 	int (*proc_handover)(const struct ti_sci_handle *handle, u8 pid,
248 			     u8 hid);
249 	int (*set_proc_boot_cfg)(const struct ti_sci_handle *handle, u8 pid,
250 				 u64 bv, u32 cfg_set, u32 cfg_clr);
251 	int (*set_proc_boot_ctrl)(const struct ti_sci_handle *handle, u8 pid,
252 				  u32 ctrl_set, u32 ctrl_clr);
253 	int (*proc_auth_boot_image)(const struct ti_sci_handle *handle, u8 pid,
254 				    u64 caddr);
255 	int (*get_proc_boot_status)(const struct ti_sci_handle *handle, u8 pid,
256 				    u64 *bv, u32 *cfg_flags, u32 *ctrl_flags,
257 				    u32 *sts_flags);
258 };
259 
260 /**
261  * struct ti_sci_ops - Function support for TI SCI
262  * @board_ops:	Miscellaneous operations
263  * @dev_ops:	Device specific operations
264  * @clk_ops:	Clock specific operations
265  * @core_ops:	Core specific operations
266  * @proc_ops:	Processor specific operations
267  */
268 struct ti_sci_ops {
269 	struct ti_sci_board_ops board_ops;
270 	struct ti_sci_dev_ops dev_ops;
271 	struct ti_sci_clk_ops clk_ops;
272 	struct ti_sci_core_ops core_ops;
273 	struct ti_sci_proc_ops proc_ops;
274 };
275 
276 /**
277  * struct ti_sci_handle - Handle returned to TI SCI clients for usage.
278  * @ops:	operations that are made available to TI SCI clients
279  * @version:	structure containing version information
280  */
281 struct ti_sci_handle {
282 	struct ti_sci_ops ops;
283 	struct ti_sci_version_info version;
284 };
285 
286 #if IS_ENABLED(CONFIG_TI_SCI_PROTOCOL)
287 
288 const struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *dev);
289 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev);
290 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
291 						  const char *property);
292 
293 #else	/* CONFIG_TI_SCI_PROTOCOL */
294 
295 static inline
ti_sci_get_handle_from_sysfw(struct udevice * dev)296 const struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *dev)
297 {
298 	return ERR_PTR(-EINVAL);
299 }
300 
ti_sci_get_handle(struct udevice * dev)301 static inline const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
302 {
303 	return ERR_PTR(-EINVAL);
304 }
305 
306 static inline
ti_sci_get_by_phandle(struct udevice * dev,const char * property)307 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
308 						  const char *property)
309 {
310 	return ERR_PTR(-EINVAL);
311 }
312 #endif	/* CONFIG_TI_SCI_PROTOCOL */
313 
314 #endif	/* __TISCI_PROTOCOL_H */
315