xref: /rk3399_ARM-atf/drivers/ti/ti_sci/ti_sci.h (revision 06bf26bc1f76265237df2303d78a8f475eab703d)
1936afd9fSDhruva Gole /*
2936afd9fSDhruva Gole  * Texas Instruments System Control Interface API
3936afd9fSDhruva Gole  *   Based on Linux and U-Boot implementation
4936afd9fSDhruva Gole  *
5936afd9fSDhruva Gole  * Copyright (C) 2018-2025 Texas Instruments Incorporated - https://www.ti.com/
6936afd9fSDhruva Gole  *
7936afd9fSDhruva Gole  * SPDX-License-Identifier: BSD-3-Clause
8936afd9fSDhruva Gole  */
9936afd9fSDhruva Gole 
10936afd9fSDhruva Gole #ifndef TI_SCI_H
11936afd9fSDhruva Gole #define TI_SCI_H
12936afd9fSDhruva Gole 
13936afd9fSDhruva Gole #include <stdint.h>
14936afd9fSDhruva Gole #include <stdbool.h>
15936afd9fSDhruva Gole 
16936afd9fSDhruva Gole /**
17936afd9fSDhruva Gole  * User exported structures.
18936afd9fSDhruva Gole  *
19936afd9fSDhruva Gole  * The structures in ti_sci_protocol.h are used by the internal drivers.
20936afd9fSDhruva Gole  * These are the structures that are exported for outside use and populated
21936afd9fSDhruva Gole  * by the internal drivers.
22936afd9fSDhruva Gole  *
23936afd9fSDhruva Gole  * struct ti_sci_msg_version - Structure containing version info
24936afd9fSDhruva Gole  *
25936afd9fSDhruva Gole  * @firmware_description: String describing the firmware
26936afd9fSDhruva Gole  * @firmware_revision:	Firmware revision
27936afd9fSDhruva Gole  * @abi_major:		Major version of the ABI that firmware supports
28936afd9fSDhruva Gole  * @abi_minor:		Minor version of the ABI that firmware supports
29936afd9fSDhruva Gole  * @sub_version:	Sub-version number of the firmware
30936afd9fSDhruva Gole  * @patch_version:	Patch-version number of the firmware.
31936afd9fSDhruva Gole  */
32936afd9fSDhruva Gole struct ti_sci_msg_version {
33936afd9fSDhruva Gole #define FIRMWARE_DESCRIPTION_LENGTH 32
34936afd9fSDhruva Gole 	char firmware_description[FIRMWARE_DESCRIPTION_LENGTH];
35936afd9fSDhruva Gole 	uint16_t firmware_revision;
36936afd9fSDhruva Gole 	uint8_t abi_major;
37936afd9fSDhruva Gole 	uint8_t abi_minor;
38936afd9fSDhruva Gole 	uint8_t sub_version;
39936afd9fSDhruva Gole 	uint8_t patch_version;
40936afd9fSDhruva Gole };
41936afd9fSDhruva Gole 
42936afd9fSDhruva Gole /**
43936afd9fSDhruva Gole  * General Message
44936afd9fSDhruva Gole  *
45936afd9fSDhruva Gole  * ti_sci_get_revision - Get the revision of the SCI entity
46936afd9fSDhruva Gole  *			@version: Structure containing the version info
47936afd9fSDhruva Gole  *
48936afd9fSDhruva Gole  **/
49936afd9fSDhruva Gole int ti_sci_get_revision(struct ti_sci_msg_version *version);
50936afd9fSDhruva Gole 
51936afd9fSDhruva Gole /**
52936afd9fSDhruva Gole  * Device control operations
53936afd9fSDhruva Gole  *
54936afd9fSDhruva Gole  * - ti_sci_device_get - command to request for device managed by TISCI
55936afd9fSDhruva Gole  * - ti_sci_device_get_exclusive - exclusively request a device
56936afd9fSDhruva Gole  * - ti_sci_device_idle - Command to idle a device managed by TISCI
57936afd9fSDhruva Gole  * - ti_sci_device_idle_exclusive - exclusively idle a device
58936afd9fSDhruva Gole  * - ti_sci_device_put - command to release a device managed by TISCI
59936afd9fSDhruva Gole  * - ti_sci_device_put_no_wait - release a device without waiting for response
60936afd9fSDhruva Gole  * - ti_sci_device_is_valid - Is the device valid
61936afd9fSDhruva Gole  * - ti_sci_device_get_clcnt - Get context loss counter
62936afd9fSDhruva Gole  *              @count: Pointer to Context Loss counter to populate
63936afd9fSDhruva Gole  * - ti_sci_device_is_idle - Check if the device is requested to be idle
64936afd9fSDhruva Gole  *              @r_state: true if requested to be idle
65936afd9fSDhruva Gole  * - ti_sci_device_is_stop - Check if the device is requested to be stopped
66936afd9fSDhruva Gole  *              @r_state: true if requested to be stopped
67936afd9fSDhruva Gole  *              @curr_state: true if currently stopped.
68936afd9fSDhruva Gole  * - ti_sci_device_is_on - Check if the device is requested to be ON
69936afd9fSDhruva Gole  *              @r_state: true if requested to be ON
70936afd9fSDhruva Gole  *              @curr_state: true if currently ON and active
71936afd9fSDhruva Gole  * - ti_sci_device_is_trans - Check if the device is currently transitioning
72936afd9fSDhruva Gole  *              @curr_state: true if currently transitioning.
73936afd9fSDhruva Gole  * - ti_sci_device_set_resets - Command to set resets for
74936afd9fSDhruva Gole  *                              device managed by TISCI
75936afd9fSDhruva Gole  *              @reset_state: Device specific reset bit field
76936afd9fSDhruva Gole  * - ti_sci_device_get_resets - Get reset state for device managed by TISCI
77936afd9fSDhruva Gole  *              @reset_state: Pointer to reset state to populate
78936afd9fSDhruva Gole  *
79936afd9fSDhruva Gole  * NOTE: for all these functions, the following are generic in nature:
80936afd9fSDhruva Gole  * @id:		Device Identifier
81936afd9fSDhruva Gole  * Returns 0 for successful request, else returns corresponding error message.
82936afd9fSDhruva Gole  *
83936afd9fSDhruva Gole  * Request for the device - NOTE: the client MUST maintain integrity of
84936afd9fSDhruva Gole  * usage count by balancing get_device with put_device. No refcounting is
85936afd9fSDhruva Gole  * managed by driver for that purpose.
86936afd9fSDhruva Gole  */
87936afd9fSDhruva Gole int ti_sci_device_get(uint32_t id);
88936afd9fSDhruva Gole int ti_sci_device_get_exclusive(uint32_t id);
89936afd9fSDhruva Gole int ti_sci_device_idle(uint32_t id);
90936afd9fSDhruva Gole int ti_sci_device_idle_exclusive(uint32_t id);
91936afd9fSDhruva Gole int ti_sci_device_put(uint32_t id);
92936afd9fSDhruva Gole int ti_sci_device_put_no_wait(uint32_t id);
93936afd9fSDhruva Gole int ti_sci_device_is_valid(uint32_t id);
94936afd9fSDhruva Gole int ti_sci_device_get_clcnt(uint32_t id, uint32_t *count);
95936afd9fSDhruva Gole int ti_sci_device_is_idle(uint32_t id, bool *r_state);
96936afd9fSDhruva Gole int ti_sci_device_is_stop(uint32_t id, bool *r_state,  bool *curr_state);
97936afd9fSDhruva Gole int ti_sci_device_is_on(uint32_t id, bool *r_state,  bool *curr_state);
98936afd9fSDhruva Gole int ti_sci_device_is_trans(uint32_t id, bool *curr_state);
99936afd9fSDhruva Gole int ti_sci_device_set_resets(uint32_t id, uint32_t reset_state);
100936afd9fSDhruva Gole int ti_sci_device_get_resets(uint32_t id, uint32_t *reset_state);
101936afd9fSDhruva Gole 
102936afd9fSDhruva Gole /**
103936afd9fSDhruva Gole  * Clock control operations
104936afd9fSDhruva Gole  *
105936afd9fSDhruva Gole  * - ti_sci_clock_get - Get control of a clock from TI SCI
106936afd9fSDhruva Gole  *              @needs_ssc: 'true' iff Spread Spectrum clock is desired
107936afd9fSDhruva Gole  *              @can_change_freq: 'true' iff frequency change is desired
108936afd9fSDhruva Gole  *              @enable_input_term: 'true' iff input termination is desired
109936afd9fSDhruva Gole  * - ti_sci_clock_idle - Idle a clock which is in our control
110936afd9fSDhruva Gole  * - ti_sci_clock_put - Release a clock from our control
111936afd9fSDhruva Gole  * - ti_sci_clock_is_auto - Is the clock being auto managed
112936afd9fSDhruva Gole  *              @req_state: state indicating if the clock is auto managed
113936afd9fSDhruva Gole  * - ti_sci_clock_is_on - Is the clock ON
114936afd9fSDhruva Gole  *              @req_state: state indicating if the clock is managed by us and enabled
115936afd9fSDhruva Gole  *              @curr_state: state indicating if the clock is ready for operation
116936afd9fSDhruva Gole  * - ti_sci_clock_is_off - Is the clock OFF
117936afd9fSDhruva Gole  *              @req_state: state indicating if the clock is managed by us and disabled
118936afd9fSDhruva Gole  *              @curr_state: state indicating if the clock is NOT ready for operation
119936afd9fSDhruva Gole  * - ti_sci_clock_set_parent - Set the clock source of a specific device clock
120936afd9fSDhruva Gole  *              @parent_id: Parent clock identifier to set
121936afd9fSDhruva Gole  * - ti_sci_clock_get_parent - Get current parent clock source
122936afd9fSDhruva Gole  *              @parent_id: Current clock parent
123936afd9fSDhruva Gole  * - ti_sci_clock_get_num_parents - Get num parents of the current clk source
124936afd9fSDhruva Gole  *              @num_parents: Returns he number of parents to the current clock.
125936afd9fSDhruva Gole  * - ti_sci_clock_get_match_freq - Find a good match for frequency
126936afd9fSDhruva Gole  *              @match_freq: Frequency match in Hz response.
127936afd9fSDhruva Gole  * - ti_sci_clock_set_freq - Set a frequency for clock
128936afd9fSDhruva Gole  * - ti_sci_clock_get_freq - Get current frequency
129936afd9fSDhruva Gole  *              @freq: Currently frequency in Hz
130936afd9fSDhruva Gole  *
131936afd9fSDhruva Gole  * NOTE: for all these functions, the following are generic in nature:
132936afd9fSDhruva Gole  * @dev_id:	Device identifier this request is for
133936afd9fSDhruva Gole  * @clk_id:	Clock identifier for the device for this request.
134936afd9fSDhruva Gole  *		Each device has its own set of clock inputs. This indexes
135936afd9fSDhruva Gole  *		which clock input to modify.
136936afd9fSDhruva Gole  * @min_freq:	The minimum allowable frequency in Hz. This is the minimum
137936afd9fSDhruva Gole  *		allowable programmed frequency and does not account for clock
138936afd9fSDhruva Gole  *		tolerances and jitter.
139936afd9fSDhruva Gole  * @target_freq: The target clock frequency in Hz. A frequency will be
140936afd9fSDhruva Gole  *		processed as close to this target frequency as possible.
141936afd9fSDhruva Gole  * @max_freq:	The maximum allowable frequency in Hz. This is the maximum
142936afd9fSDhruva Gole  *		allowable programmed frequency and does not account for clock
143936afd9fSDhruva Gole  *		tolerances and jitter.
144936afd9fSDhruva Gole  * Returns 0 for successful request, else returns corresponding error message.
145936afd9fSDhruva Gole  *
146936afd9fSDhruva Gole  * Request for the clock - NOTE: the client MUST maintain integrity of
147936afd9fSDhruva Gole  * usage count by balancing get_clock with put_clock. No refcounting is
148936afd9fSDhruva Gole  * managed by driver for that purpose.
149936afd9fSDhruva Gole  */
150936afd9fSDhruva Gole int ti_sci_clock_get(uint32_t dev_id, uint8_t clk_id,
151936afd9fSDhruva Gole 		     bool needs_ssc, bool can_change_freq,
152936afd9fSDhruva Gole 		     bool enable_input_term);
153936afd9fSDhruva Gole int ti_sci_clock_idle(uint32_t dev_id, uint8_t clk_id);
154936afd9fSDhruva Gole int ti_sci_clock_put(uint32_t dev_id, uint8_t clk_id);
155936afd9fSDhruva Gole int ti_sci_clock_is_auto(uint32_t dev_id, uint8_t clk_id,
156936afd9fSDhruva Gole 			 bool *req_state);
157936afd9fSDhruva Gole int ti_sci_clock_is_on(uint32_t dev_id, uint8_t clk_id,
158936afd9fSDhruva Gole 		       bool *req_state, bool *curr_state);
159936afd9fSDhruva Gole int ti_sci_clock_is_off(uint32_t dev_id, uint8_t clk_id,
160936afd9fSDhruva Gole 			bool *req_state, bool *curr_state);
161936afd9fSDhruva Gole int ti_sci_clock_set_parent(uint32_t dev_id, uint8_t clk_id,
162936afd9fSDhruva Gole 			    uint8_t parent_id);
163936afd9fSDhruva Gole int ti_sci_clock_get_parent(uint32_t dev_id, uint8_t clk_id,
164936afd9fSDhruva Gole 			    uint8_t *parent_id);
165936afd9fSDhruva Gole int ti_sci_clock_get_num_parents(uint32_t dev_id, uint8_t clk_id,
166936afd9fSDhruva Gole 				 uint8_t *num_parents);
167936afd9fSDhruva Gole int ti_sci_clock_get_match_freq(uint32_t dev_id, uint8_t clk_id,
168936afd9fSDhruva Gole 				uint64_t min_freq, uint64_t target_freq,
169936afd9fSDhruva Gole 				uint64_t max_freq, uint64_t *match_freq);
170936afd9fSDhruva Gole int ti_sci_clock_set_freq(uint32_t dev_id, uint8_t clk_id,
171936afd9fSDhruva Gole 			  uint64_t min_freq, uint64_t target_freq,
172936afd9fSDhruva Gole 			  uint64_t max_freq);
173936afd9fSDhruva Gole int ti_sci_clock_get_freq(uint32_t dev_id, uint8_t clk_id, uint64_t *freq);
174936afd9fSDhruva Gole 
175936afd9fSDhruva Gole /**
176936afd9fSDhruva Gole  * Core control operations
177936afd9fSDhruva Gole  *
178936afd9fSDhruva Gole  * - ti_sci_core_reboot() - Command to request system reset
179936afd9fSDhruva Gole  * - ti_sci_query_fw_caps() - Get the FW/SoC capabilities
180936afd9fSDhruva Gole  *              @fw_caps: Each bit in fw_caps indicating one FW/SOC capability
181936afd9fSDhruva Gole  *
182936afd9fSDhruva Gole  * Return: 0 if all went well, else returns appropriate error value.
183936afd9fSDhruva Gole  */
184936afd9fSDhruva Gole int ti_sci_core_reboot(void);
185936afd9fSDhruva Gole int ti_sci_query_fw_caps(uint64_t *fw_caps);
186936afd9fSDhruva Gole 
187936afd9fSDhruva Gole /**
188936afd9fSDhruva Gole  * Processor control operations
189936afd9fSDhruva Gole  *
190936afd9fSDhruva Gole  * - ti_sci_proc_request - Command to request a physical processor control
191936afd9fSDhruva Gole  * - ti_sci_proc_release - Command to release a physical processor control
192936afd9fSDhruva Gole  * - ti_sci_proc_handover - Command to handover a physical processor control to
193936afd9fSDhruva Gole  *                          a host in the processor's access control list.
194936afd9fSDhruva Gole  *              @host_id: Host ID to get the control of the processor
195936afd9fSDhruva Gole  * - ti_sci_proc_set_boot_cfg - Command to set the processor boot configuration flags
196936afd9fSDhruva Gole  *              @config_flags_set: Configuration flags to be set
197936afd9fSDhruva Gole  *              @config_flags_clear: Configuration flags to be cleared.
198936afd9fSDhruva Gole  * - ti_sci_proc_set_boot_ctrl - Command to set the processor boot control flags
199936afd9fSDhruva Gole  *              @control_flags_set: Control flags to be set
200936afd9fSDhruva Gole  *              @control_flags_clear: Control flags to be cleared
201936afd9fSDhruva Gole  * - ti_sci_proc_set_boot_ctrl_no_wait - Same as above without waiting for response
202936afd9fSDhruva Gole  * - ti_sci_proc_auth_boot_image - Command to authenticate and load the image
203936afd9fSDhruva Gole  *                                 and then set the processor configuration flags.
204936afd9fSDhruva Gole  *              @cert_addr: Memory address at which payload image certificate is located.
205936afd9fSDhruva Gole  * - ti_sci_proc_get_boot_status - Command to get the processor boot status
206936afd9fSDhruva Gole  * - ti_sci_proc_wait_boot_status - Command to wait for a processor boot status
207936afd9fSDhruva Gole  * - ti_sci_proc_wait_boot_status_no_wait - Same as above without waiting for response
208936afd9fSDhruva Gole  *
209936afd9fSDhruva Gole  * NOTE: for all these functions, the following are generic in nature:
210936afd9fSDhruva Gole  * @proc_id:	Processor ID
211936afd9fSDhruva Gole  * Returns 0 for successful request, else returns corresponding error message.
212936afd9fSDhruva Gole  */
213936afd9fSDhruva Gole int ti_sci_proc_request(uint8_t proc_id);
214936afd9fSDhruva Gole int ti_sci_proc_release(uint8_t proc_id);
215936afd9fSDhruva Gole int ti_sci_proc_handover(uint8_t proc_id, uint8_t host_id);
216936afd9fSDhruva Gole int ti_sci_proc_set_boot_cfg(uint8_t proc_id, uint64_t bootvector,
217936afd9fSDhruva Gole 			     uint32_t config_flags_set,
218936afd9fSDhruva Gole 			     uint32_t config_flags_clear);
219936afd9fSDhruva Gole int ti_sci_proc_set_boot_ctrl(uint8_t proc_id, uint32_t control_flags_set,
220936afd9fSDhruva Gole 			      uint32_t control_flags_clear);
221936afd9fSDhruva Gole int ti_sci_proc_set_boot_ctrl_no_wait(uint8_t proc_id,
222936afd9fSDhruva Gole 				      uint32_t control_flags_set,
223936afd9fSDhruva Gole 				      uint32_t control_flags_clear);
224936afd9fSDhruva Gole int ti_sci_proc_auth_boot_image(uint8_t proc_id, uint64_t cert_addr);
225936afd9fSDhruva Gole int ti_sci_proc_get_boot_status(uint8_t proc_id, uint64_t *bv,
226936afd9fSDhruva Gole 				uint32_t *cfg_flags,
227936afd9fSDhruva Gole 				uint32_t *ctrl_flags,
228936afd9fSDhruva Gole 				uint32_t *sts_flags);
229936afd9fSDhruva Gole int ti_sci_proc_wait_boot_status(uint8_t proc_id, uint8_t num_wait_iterations,
230936afd9fSDhruva Gole 				 uint8_t num_match_iterations,
231936afd9fSDhruva Gole 				 uint8_t delay_per_iteration_us,
232936afd9fSDhruva Gole 				 uint8_t delay_before_iterations_us,
233936afd9fSDhruva Gole 				 uint32_t status_flags_1_set_all_wait,
234936afd9fSDhruva Gole 				 uint32_t status_flags_1_set_any_wait,
235936afd9fSDhruva Gole 				 uint32_t status_flags_1_clr_all_wait,
236936afd9fSDhruva Gole 				 uint32_t status_flags_1_clr_any_wait);
237936afd9fSDhruva Gole int ti_sci_proc_wait_boot_status_no_wait(uint8_t proc_id,
238936afd9fSDhruva Gole 					 uint8_t num_wait_iterations,
239936afd9fSDhruva Gole 					 uint8_t num_match_iterations,
240936afd9fSDhruva Gole 					 uint8_t delay_per_iteration_us,
241936afd9fSDhruva Gole 					 uint8_t delay_before_iterations_us,
242936afd9fSDhruva Gole 					 uint32_t status_flags_1_set_all_wait,
243936afd9fSDhruva Gole 					 uint32_t status_flags_1_set_any_wait,
244936afd9fSDhruva Gole 					 uint32_t status_flags_1_clr_all_wait,
245936afd9fSDhruva Gole 					 uint32_t status_flags_1_clr_any_wait);
246936afd9fSDhruva Gole 
247936afd9fSDhruva Gole /**
248936afd9fSDhruva Gole  * System Low Power Operations
249936afd9fSDhruva Gole  *
250936afd9fSDhruva Gole  * - ti_sci_enter_sleep - Command to initiate system transition into suspend.
251936afd9fSDhruva Gole  *		@proc_id: Processor ID.
252936afd9fSDhruva Gole  *		@mode: Low power mode to enter.
253936afd9fSDhruva Gole  *		@core_resume_addr: Address that core should be resumed from
254936afd9fSDhruva Gole  *				   after low power transition.
255936afd9fSDhruva Gole  * - ti_sci_lpm_get_next_sys_mode - Get next LPM system mode
256936afd9fSDhruva Gole  *
257936afd9fSDhruva Gole  * @next_mode:	pointer to a variable that will store the next mode
258936afd9fSDhruva Gole  *
259936afd9fSDhruva Gole  * Return: 0 if all goes well, else appropriate error message
260936afd9fSDhruva Gole  *
261936afd9fSDhruva Gole  * NOTE: for all these functions, the following are generic in nature:
262936afd9fSDhruva Gole  * Returns 0 for successful request, else returns corresponding error message.
263936afd9fSDhruva Gole  */
264936afd9fSDhruva Gole int ti_sci_enter_sleep(uint8_t proc_id,
265936afd9fSDhruva Gole 		       uint8_t mode,
266936afd9fSDhruva Gole 		       uint64_t core_resume_addr);
267936afd9fSDhruva Gole int ti_sci_lpm_get_next_sys_mode(uint8_t *next_mode);
268936afd9fSDhruva Gole 
269*7d3c700fSDhruva Gole /**
270*7d3c700fSDhruva Gole  * Boot Notification
271*7d3c700fSDhruva Gole  * - ti_sci_boot_notification - Wait for a boot notification msg from the
272*7d3c700fSDhruva Gole  *   system-firmware which indicates that it is ready to begin receiving and
273*7d3c700fSDhruva Gole  *   processing TISCI messages.
274*7d3c700fSDhruva Gole  * Returns 0 for successful request, else returns corresponding error message.
275*7d3c700fSDhruva Gole  */
276*7d3c700fSDhruva Gole int ti_sci_boot_notification(void);
277*7d3c700fSDhruva Gole 
278936afd9fSDhruva Gole #endif /* TI_SCI_H */
279