1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Texas Instruments System Control Interface API 3*91f16700Schasinglulu * Based on Linux and U-Boot implementation 4*91f16700Schasinglulu * 5*91f16700Schasinglulu * Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/ 6*91f16700Schasinglulu * 7*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 8*91f16700Schasinglulu */ 9*91f16700Schasinglulu 10*91f16700Schasinglulu #ifndef TI_SCI_H 11*91f16700Schasinglulu #define TI_SCI_H 12*91f16700Schasinglulu 13*91f16700Schasinglulu #include <stdint.h> 14*91f16700Schasinglulu #include <stdbool.h> 15*91f16700Schasinglulu 16*91f16700Schasinglulu /** 17*91f16700Schasinglulu * Device control operations 18*91f16700Schasinglulu * 19*91f16700Schasinglulu * - ti_sci_device_get - command to request for device managed by TISCI 20*91f16700Schasinglulu * - ti_sci_device_get_exclusive - exclusively request a device 21*91f16700Schasinglulu * - ti_sci_device_idle - Command to idle a device managed by TISCI 22*91f16700Schasinglulu * - ti_sci_device_idle_exclusive - exclusively idle a device 23*91f16700Schasinglulu * - ti_sci_device_put - command to release a device managed by TISCI 24*91f16700Schasinglulu * - ti_sci_device_put_no_wait - release a device without waiting for response 25*91f16700Schasinglulu * - ti_sci_device_is_valid - Is the device valid 26*91f16700Schasinglulu * - ti_sci_device_get_clcnt - Get context loss counter 27*91f16700Schasinglulu * @count: Pointer to Context Loss counter to populate 28*91f16700Schasinglulu * - ti_sci_device_is_idle - Check if the device is requested to be idle 29*91f16700Schasinglulu * @r_state: true if requested to be idle 30*91f16700Schasinglulu * - ti_sci_device_is_stop - Check if the device is requested to be stopped 31*91f16700Schasinglulu * @r_state: true if requested to be stopped 32*91f16700Schasinglulu * @curr_state: true if currently stopped. 33*91f16700Schasinglulu * - ti_sci_device_is_on - Check if the device is requested to be ON 34*91f16700Schasinglulu * @r_state: true if requested to be ON 35*91f16700Schasinglulu * @curr_state: true if currently ON and active 36*91f16700Schasinglulu * - ti_sci_device_is_trans - Check if the device is currently transitioning 37*91f16700Schasinglulu * @curr_state: true if currently transitioning. 38*91f16700Schasinglulu * - ti_sci_device_set_resets - Command to set resets for 39*91f16700Schasinglulu * device managed by TISCI 40*91f16700Schasinglulu * @reset_state: Device specific reset bit field 41*91f16700Schasinglulu * - ti_sci_device_get_resets - Get reset state for device managed by TISCI 42*91f16700Schasinglulu * @reset_state: Pointer to reset state to populate 43*91f16700Schasinglulu * 44*91f16700Schasinglulu * NOTE: for all these functions, the following are generic in nature: 45*91f16700Schasinglulu * @id: Device Identifier 46*91f16700Schasinglulu * Returns 0 for successful request, else returns corresponding error message. 47*91f16700Schasinglulu * 48*91f16700Schasinglulu * Request for the device - NOTE: the client MUST maintain integrity of 49*91f16700Schasinglulu * usage count by balancing get_device with put_device. No refcounting is 50*91f16700Schasinglulu * managed by driver for that purpose. 51*91f16700Schasinglulu */ 52*91f16700Schasinglulu int ti_sci_device_get(uint32_t id); 53*91f16700Schasinglulu int ti_sci_device_get_exclusive(uint32_t id); 54*91f16700Schasinglulu int ti_sci_device_idle(uint32_t id); 55*91f16700Schasinglulu int ti_sci_device_idle_exclusive(uint32_t id); 56*91f16700Schasinglulu int ti_sci_device_put(uint32_t id); 57*91f16700Schasinglulu int ti_sci_device_put_no_wait(uint32_t id); 58*91f16700Schasinglulu int ti_sci_device_is_valid(uint32_t id); 59*91f16700Schasinglulu int ti_sci_device_get_clcnt(uint32_t id, uint32_t *count); 60*91f16700Schasinglulu int ti_sci_device_is_idle(uint32_t id, bool *r_state); 61*91f16700Schasinglulu int ti_sci_device_is_stop(uint32_t id, bool *r_state, bool *curr_state); 62*91f16700Schasinglulu int ti_sci_device_is_on(uint32_t id, bool *r_state, bool *curr_state); 63*91f16700Schasinglulu int ti_sci_device_is_trans(uint32_t id, bool *curr_state); 64*91f16700Schasinglulu int ti_sci_device_set_resets(uint32_t id, uint32_t reset_state); 65*91f16700Schasinglulu int ti_sci_device_get_resets(uint32_t id, uint32_t *reset_state); 66*91f16700Schasinglulu 67*91f16700Schasinglulu /** 68*91f16700Schasinglulu * Clock control operations 69*91f16700Schasinglulu * 70*91f16700Schasinglulu * - ti_sci_clock_get - Get control of a clock from TI SCI 71*91f16700Schasinglulu * @needs_ssc: 'true' iff Spread Spectrum clock is desired 72*91f16700Schasinglulu * @can_change_freq: 'true' iff frequency change is desired 73*91f16700Schasinglulu * @enable_input_term: 'true' iff input termination is desired 74*91f16700Schasinglulu * - ti_sci_clock_idle - Idle a clock which is in our control 75*91f16700Schasinglulu * - ti_sci_clock_put - Release a clock from our control 76*91f16700Schasinglulu * - ti_sci_clock_is_auto - Is the clock being auto managed 77*91f16700Schasinglulu * @req_state: state indicating if the clock is auto managed 78*91f16700Schasinglulu * - ti_sci_clock_is_on - Is the clock ON 79*91f16700Schasinglulu * @req_state: state indicating if the clock is managed by us and enabled 80*91f16700Schasinglulu * @curr_state: state indicating if the clock is ready for operation 81*91f16700Schasinglulu * - ti_sci_clock_is_off - Is the clock OFF 82*91f16700Schasinglulu * @req_state: state indicating if the clock is managed by us and disabled 83*91f16700Schasinglulu * @curr_state: state indicating if the clock is NOT ready for operation 84*91f16700Schasinglulu * - ti_sci_clock_set_parent - Set the clock source of a specific device clock 85*91f16700Schasinglulu * @parent_id: Parent clock identifier to set 86*91f16700Schasinglulu * - ti_sci_clock_get_parent - Get current parent clock source 87*91f16700Schasinglulu * @parent_id: Current clock parent 88*91f16700Schasinglulu * - ti_sci_clock_get_num_parents - Get num parents of the current clk source 89*91f16700Schasinglulu * @num_parents: Returns he number of parents to the current clock. 90*91f16700Schasinglulu * - ti_sci_clock_get_match_freq - Find a good match for frequency 91*91f16700Schasinglulu * @match_freq: Frequency match in Hz response. 92*91f16700Schasinglulu * - ti_sci_clock_set_freq - Set a frequency for clock 93*91f16700Schasinglulu * - ti_sci_clock_get_freq - Get current frequency 94*91f16700Schasinglulu * @freq: Currently frequency in Hz 95*91f16700Schasinglulu * 96*91f16700Schasinglulu * NOTE: for all these functions, the following are generic in nature: 97*91f16700Schasinglulu * @dev_id: Device identifier this request is for 98*91f16700Schasinglulu * @clk_id: Clock identifier for the device for this request. 99*91f16700Schasinglulu * Each device has its own set of clock inputs. This indexes 100*91f16700Schasinglulu * which clock input to modify. 101*91f16700Schasinglulu * @min_freq: The minimum allowable frequency in Hz. This is the minimum 102*91f16700Schasinglulu * allowable programmed frequency and does not account for clock 103*91f16700Schasinglulu * tolerances and jitter. 104*91f16700Schasinglulu * @target_freq: The target clock frequency in Hz. A frequency will be 105*91f16700Schasinglulu * processed as close to this target frequency as possible. 106*91f16700Schasinglulu * @max_freq: The maximum allowable frequency in Hz. This is the maximum 107*91f16700Schasinglulu * allowable programmed frequency and does not account for clock 108*91f16700Schasinglulu * tolerances and jitter. 109*91f16700Schasinglulu * Returns 0 for successful request, else returns corresponding error message. 110*91f16700Schasinglulu * 111*91f16700Schasinglulu * Request for the clock - NOTE: the client MUST maintain integrity of 112*91f16700Schasinglulu * usage count by balancing get_clock with put_clock. No refcounting is 113*91f16700Schasinglulu * managed by driver for that purpose. 114*91f16700Schasinglulu */ 115*91f16700Schasinglulu int ti_sci_clock_get(uint32_t dev_id, uint8_t clk_id, 116*91f16700Schasinglulu bool needs_ssc, bool can_change_freq, 117*91f16700Schasinglulu bool enable_input_term); 118*91f16700Schasinglulu int ti_sci_clock_idle(uint32_t dev_id, uint8_t clk_id); 119*91f16700Schasinglulu int ti_sci_clock_put(uint32_t dev_id, uint8_t clk_id); 120*91f16700Schasinglulu int ti_sci_clock_is_auto(uint32_t dev_id, uint8_t clk_id, 121*91f16700Schasinglulu bool *req_state); 122*91f16700Schasinglulu int ti_sci_clock_is_on(uint32_t dev_id, uint8_t clk_id, 123*91f16700Schasinglulu bool *req_state, bool *curr_state); 124*91f16700Schasinglulu int ti_sci_clock_is_off(uint32_t dev_id, uint8_t clk_id, 125*91f16700Schasinglulu bool *req_state, bool *curr_state); 126*91f16700Schasinglulu int ti_sci_clock_set_parent(uint32_t dev_id, uint8_t clk_id, 127*91f16700Schasinglulu uint8_t parent_id); 128*91f16700Schasinglulu int ti_sci_clock_get_parent(uint32_t dev_id, uint8_t clk_id, 129*91f16700Schasinglulu uint8_t *parent_id); 130*91f16700Schasinglulu int ti_sci_clock_get_num_parents(uint32_t dev_id, uint8_t clk_id, 131*91f16700Schasinglulu uint8_t *num_parents); 132*91f16700Schasinglulu int ti_sci_clock_get_match_freq(uint32_t dev_id, uint8_t clk_id, 133*91f16700Schasinglulu uint64_t min_freq, uint64_t target_freq, 134*91f16700Schasinglulu uint64_t max_freq, uint64_t *match_freq); 135*91f16700Schasinglulu int ti_sci_clock_set_freq(uint32_t dev_id, uint8_t clk_id, 136*91f16700Schasinglulu uint64_t min_freq, uint64_t target_freq, 137*91f16700Schasinglulu uint64_t max_freq); 138*91f16700Schasinglulu int ti_sci_clock_get_freq(uint32_t dev_id, uint8_t clk_id, uint64_t *freq); 139*91f16700Schasinglulu 140*91f16700Schasinglulu /** 141*91f16700Schasinglulu * Core control operations 142*91f16700Schasinglulu * 143*91f16700Schasinglulu * - ti_sci_core_reboot() - Command to request system reset 144*91f16700Schasinglulu * - ti_sci_query_fw_caps() - Get the FW/SoC capabilities 145*91f16700Schasinglulu * @fw_caps: Each bit in fw_caps indicating one FW/SOC capability 146*91f16700Schasinglulu * 147*91f16700Schasinglulu * Return: 0 if all went well, else returns appropriate error value. 148*91f16700Schasinglulu */ 149*91f16700Schasinglulu int ti_sci_core_reboot(void); 150*91f16700Schasinglulu int ti_sci_query_fw_caps(uint64_t *fw_caps); 151*91f16700Schasinglulu 152*91f16700Schasinglulu /** 153*91f16700Schasinglulu * Processor control operations 154*91f16700Schasinglulu * 155*91f16700Schasinglulu * - ti_sci_proc_request - Command to request a physical processor control 156*91f16700Schasinglulu * - ti_sci_proc_release - Command to release a physical processor control 157*91f16700Schasinglulu * - ti_sci_proc_handover - Command to handover a physical processor control to 158*91f16700Schasinglulu * a host in the processor's access control list. 159*91f16700Schasinglulu * @host_id: Host ID to get the control of the processor 160*91f16700Schasinglulu * - ti_sci_proc_set_boot_cfg - Command to set the processor boot configuration flags 161*91f16700Schasinglulu * @config_flags_set: Configuration flags to be set 162*91f16700Schasinglulu * @config_flags_clear: Configuration flags to be cleared. 163*91f16700Schasinglulu * - ti_sci_proc_set_boot_ctrl - Command to set the processor boot control flags 164*91f16700Schasinglulu * @control_flags_set: Control flags to be set 165*91f16700Schasinglulu * @control_flags_clear: Control flags to be cleared 166*91f16700Schasinglulu * - ti_sci_proc_set_boot_ctrl_no_wait - Same as above without waiting for response 167*91f16700Schasinglulu * - ti_sci_proc_auth_boot_image - Command to authenticate and load the image 168*91f16700Schasinglulu * and then set the processor configuration flags. 169*91f16700Schasinglulu * @cert_addr: Memory address at which payload image certificate is located. 170*91f16700Schasinglulu * - ti_sci_proc_get_boot_status - Command to get the processor boot status 171*91f16700Schasinglulu * - ti_sci_proc_wait_boot_status - Command to wait for a processor boot status 172*91f16700Schasinglulu * - ti_sci_proc_wait_boot_status_no_wait - Same as above without waiting for response 173*91f16700Schasinglulu * 174*91f16700Schasinglulu * NOTE: for all these functions, the following are generic in nature: 175*91f16700Schasinglulu * @proc_id: Processor ID 176*91f16700Schasinglulu * Returns 0 for successful request, else returns corresponding error message. 177*91f16700Schasinglulu */ 178*91f16700Schasinglulu int ti_sci_proc_request(uint8_t proc_id); 179*91f16700Schasinglulu int ti_sci_proc_release(uint8_t proc_id); 180*91f16700Schasinglulu int ti_sci_proc_handover(uint8_t proc_id, uint8_t host_id); 181*91f16700Schasinglulu int ti_sci_proc_set_boot_cfg(uint8_t proc_id, uint64_t bootvector, 182*91f16700Schasinglulu uint32_t config_flags_set, 183*91f16700Schasinglulu uint32_t config_flags_clear); 184*91f16700Schasinglulu int ti_sci_proc_set_boot_ctrl(uint8_t proc_id, uint32_t control_flags_set, 185*91f16700Schasinglulu uint32_t control_flags_clear); 186*91f16700Schasinglulu int ti_sci_proc_set_boot_ctrl_no_wait(uint8_t proc_id, 187*91f16700Schasinglulu uint32_t control_flags_set, 188*91f16700Schasinglulu uint32_t control_flags_clear); 189*91f16700Schasinglulu int ti_sci_proc_auth_boot_image(uint8_t proc_id, uint64_t cert_addr); 190*91f16700Schasinglulu int ti_sci_proc_get_boot_status(uint8_t proc_id, uint64_t *bv, 191*91f16700Schasinglulu uint32_t *cfg_flags, 192*91f16700Schasinglulu uint32_t *ctrl_flags, 193*91f16700Schasinglulu uint32_t *sts_flags); 194*91f16700Schasinglulu int ti_sci_proc_wait_boot_status(uint8_t proc_id, uint8_t num_wait_iterations, 195*91f16700Schasinglulu uint8_t num_match_iterations, 196*91f16700Schasinglulu uint8_t delay_per_iteration_us, 197*91f16700Schasinglulu uint8_t delay_before_iterations_us, 198*91f16700Schasinglulu uint32_t status_flags_1_set_all_wait, 199*91f16700Schasinglulu uint32_t status_flags_1_set_any_wait, 200*91f16700Schasinglulu uint32_t status_flags_1_clr_all_wait, 201*91f16700Schasinglulu uint32_t status_flags_1_clr_any_wait); 202*91f16700Schasinglulu int ti_sci_proc_wait_boot_status_no_wait(uint8_t proc_id, 203*91f16700Schasinglulu uint8_t num_wait_iterations, 204*91f16700Schasinglulu uint8_t num_match_iterations, 205*91f16700Schasinglulu uint8_t delay_per_iteration_us, 206*91f16700Schasinglulu uint8_t delay_before_iterations_us, 207*91f16700Schasinglulu uint32_t status_flags_1_set_all_wait, 208*91f16700Schasinglulu uint32_t status_flags_1_set_any_wait, 209*91f16700Schasinglulu uint32_t status_flags_1_clr_all_wait, 210*91f16700Schasinglulu uint32_t status_flags_1_clr_any_wait); 211*91f16700Schasinglulu 212*91f16700Schasinglulu /** 213*91f16700Schasinglulu * System Low Power Operations 214*91f16700Schasinglulu * 215*91f16700Schasinglulu * - ti_sci_enter_sleep - Command to initiate system transition into suspend. 216*91f16700Schasinglulu * @proc_id: Processor ID. 217*91f16700Schasinglulu * @mode: Low power mode to enter. 218*91f16700Schasinglulu * @core_resume_addr: Address that core should be resumed from 219*91f16700Schasinglulu * after low power transition. 220*91f16700Schasinglulu * 221*91f16700Schasinglulu * NOTE: for all these functions, the following are generic in nature: 222*91f16700Schasinglulu * Returns 0 for successful request, else returns corresponding error message. 223*91f16700Schasinglulu */ 224*91f16700Schasinglulu int ti_sci_enter_sleep(uint8_t proc_id, 225*91f16700Schasinglulu uint8_t mode, 226*91f16700Schasinglulu uint64_t core_resume_addr); 227*91f16700Schasinglulu 228*91f16700Schasinglulu /** 229*91f16700Schasinglulu * ti_sci_init() - Basic initialization 230*91f16700Schasinglulu * 231*91f16700Schasinglulu * Return: 0 if all goes good, else appropriate error message. 232*91f16700Schasinglulu */ 233*91f16700Schasinglulu int ti_sci_init(void); 234*91f16700Schasinglulu 235*91f16700Schasinglulu #endif /* TI_SCI_H */ 236