Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 1 | /* |
Venkatesh Yadav Abbarapu | 95ecd45 | 2019-12-10 22:16:36 -0500 | [diff] [blame] | 2 | * Copyright (c) 2019-2020, Xilinx, Inc. All rights reserved. |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Versal system level PM-API functions and communication with PMC via |
| 9 | * IPI interrupts |
| 10 | */ |
| 11 | |
| 12 | #include <pm_common.h> |
| 13 | #include <pm_ipi.h> |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 15 | #include "pm_api_sys.h" |
| 16 | #include "pm_client.h" |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 17 | #include "pm_defs.h" |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 18 | |
| 19 | /********************************************************************* |
| 20 | * Target module IDs macros |
| 21 | ********************************************************************/ |
| 22 | #define LIBPM_MODULE_ID 0x2 |
| 23 | #define LOADER_MODULE_ID 0x7 |
| 24 | |
Saeed Nowshadi | c5a1bda | 2019-12-08 23:35:35 -0800 | [diff] [blame] | 25 | /* default shutdown/reboot scope is system(2) */ |
| 26 | static unsigned int pm_shutdown_scope = XPM_SHUTDOWN_SUBTYPE_RST_SYSTEM; |
| 27 | |
| 28 | /** |
| 29 | * pm_get_shutdown_scope() - Get the currently set shutdown scope |
| 30 | * |
| 31 | * @return Shutdown scope value |
| 32 | */ |
| 33 | unsigned int pm_get_shutdown_scope(void) |
| 34 | { |
| 35 | return pm_shutdown_scope; |
| 36 | } |
| 37 | |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 38 | /** |
| 39 | * Assigning of argument values into array elements. |
| 40 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 41 | #define PM_PACK_PAYLOAD1(pl, mid, flag, arg0) { \ |
| 42 | pl[0] = (uint32_t)((uint32_t)((arg0) & 0xFF) | (mid << 8) | ((flag) << 24)); \ |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 43 | } |
| 44 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 45 | #define PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1) { \ |
| 46 | pl[1] = (uint32_t)(arg1); \ |
| 47 | PM_PACK_PAYLOAD1(pl, mid, flag, arg0); \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 50 | #define PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2) { \ |
| 51 | pl[2] = (uint32_t)(arg2); \ |
| 52 | PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1); \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 55 | #define PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3) { \ |
| 56 | pl[3] = (uint32_t)(arg3); \ |
| 57 | PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2); \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 60 | #define PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4) { \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 61 | pl[4] = (uint32_t)(arg4); \ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 62 | PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3); \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 65 | #define PM_PACK_PAYLOAD6(pl, mid, flag, arg0, arg1, arg2, arg3, arg4, arg5) { \ |
| 66 | pl[5] = (uint32_t)(arg5); \ |
| 67 | PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4); \ |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 70 | /* PM API functions */ |
| 71 | |
| 72 | /** |
| 73 | * pm_get_api_version() - Get version number of PMC PM firmware |
| 74 | * @version Returns 32-bit version number of PMC Power Management Firmware |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 75 | * @flag 0 - Call from secure source |
| 76 | * 1 - Call from non-secure source |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 77 | * |
| 78 | * @return Returns status, either success or error+reason |
| 79 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 80 | enum pm_ret_status pm_get_api_version(unsigned int *version, uint32_t flag) |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 81 | { |
| 82 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 83 | |
| 84 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 85 | PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_API_VERSION); |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 86 | return pm_ipi_send_sync(primary_proc, payload, version, 1); |
| 87 | } |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 88 | |
| 89 | /** |
Ravi Patel | 476b5b1 | 2019-08-12 03:10:10 -0700 | [diff] [blame] | 90 | * pm_init_finalize() - Call to notify PMC PM firmware that master has power |
| 91 | * management enabled and that it has finished its |
| 92 | * initialization |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 93 | * @flag 0 - Call from secure source |
| 94 | * 1 - Call from non-secure source |
Ravi Patel | 476b5b1 | 2019-08-12 03:10:10 -0700 | [diff] [blame] | 95 | * |
| 96 | * @return Status returned by the PMU firmware |
| 97 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 98 | enum pm_ret_status pm_init_finalize(uint32_t flag) |
Ravi Patel | 476b5b1 | 2019-08-12 03:10:10 -0700 | [diff] [blame] | 99 | { |
| 100 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 101 | |
| 102 | /* Send request to the PMU */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 103 | PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_INIT_FINALIZE); |
Ravi Patel | 476b5b1 | 2019-08-12 03:10:10 -0700 | [diff] [blame] | 104 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 105 | } |
| 106 | |
| 107 | /** |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 108 | * pm_self_suspend() - PM call for processor to suspend itself |
| 109 | * @nid Node id of the processor or subsystem |
| 110 | * @latency Requested maximum wakeup latency (not supported) |
| 111 | * @state Requested state |
| 112 | * @address Resume address |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 113 | * @flag 0 - Call from secure source |
| 114 | * 1 - Call from non-secure source |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 115 | * |
| 116 | * This is a blocking call, it will return only once PMU has responded. |
| 117 | * On a wakeup, resume address will be automatically set by PMU. |
| 118 | * |
| 119 | * @return Returns status, either success or error+reason |
| 120 | */ |
| 121 | enum pm_ret_status pm_self_suspend(uint32_t nid, |
| 122 | unsigned int latency, |
| 123 | unsigned int state, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 124 | uintptr_t address, uint32_t flag) |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 125 | { |
| 126 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 127 | unsigned int cpuid = plat_my_core_pos(); |
| 128 | const struct pm_proc *proc = pm_get_proc(cpuid); |
| 129 | |
| 130 | if (!proc) { |
| 131 | WARN("Failed to get proc %d\n", cpuid); |
| 132 | return PM_RET_ERROR_INTERNAL; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Do client specific suspend operations |
| 137 | * (e.g. set powerdown request bit) |
| 138 | */ |
| 139 | pm_client_suspend(proc, state); |
| 140 | |
| 141 | /* Send request to the PLM */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 142 | PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, flag, PM_SELF_SUSPEND, |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 143 | proc->node_id, latency, state, address, |
| 144 | (address >> 32)); |
| 145 | return pm_ipi_send_sync(proc, payload, NULL, 0); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * pm_abort_suspend() - PM call to announce that a prior suspend request |
| 150 | * is to be aborted. |
| 151 | * @reason Reason for the abort |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 152 | * @flag 0 - Call from secure source |
| 153 | * 1 - Call from non-secure source |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 154 | * |
| 155 | * Calling PU expects the PMU to abort the initiated suspend procedure. |
| 156 | * This is a non-blocking call without any acknowledge. |
| 157 | * |
| 158 | * @return Returns status, either success or error+reason |
| 159 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 160 | enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason, uint32_t flag) |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 161 | { |
| 162 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 163 | |
| 164 | /* |
| 165 | * Do client specific abort suspend operations |
| 166 | * (e.g. enable interrupts and clear powerdown request bit) |
| 167 | */ |
| 168 | pm_client_abort_suspend(); |
| 169 | |
| 170 | /* Send request to the PLM */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 171 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_ABORT_SUSPEND, |
| 172 | reason, primary_proc->node_id); |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 173 | return pm_ipi_send(primary_proc, payload); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * pm_req_suspend() - PM call to request for another PU or subsystem to |
| 178 | * be suspended gracefully. |
| 179 | * @target Node id of the targeted PU or subsystem |
| 180 | * @ack Flag to specify whether acknowledge is requested |
| 181 | * @latency Requested wakeup latency (not supported) |
| 182 | * @state Requested state (not supported) |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 183 | * @flag 0 - Call from secure source |
| 184 | * 1 - Call from non-secure source |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 185 | * |
| 186 | * @return Returns status, either success or error+reason |
| 187 | */ |
| 188 | enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 189 | unsigned int latency, unsigned int state, |
| 190 | uint32_t flag) |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 191 | { |
| 192 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 193 | |
| 194 | /* Send request to the PMU */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 195 | PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_REQ_SUSPEND, target, |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 196 | latency, state); |
| 197 | if (ack == IPI_BLOCKING) |
| 198 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 199 | else |
| 200 | return pm_ipi_send(primary_proc, payload); |
| 201 | } |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 202 | |
| 203 | /** |
Tejas Patel | 49cd871 | 2019-01-23 14:18:51 +0530 | [diff] [blame] | 204 | * pm_req_wakeup() - PM call for processor to wake up selected processor |
| 205 | * or subsystem |
| 206 | * @target Device ID of the processor or subsystem to wake up |
| 207 | * @set_address Resume address presence indicator |
| 208 | * 1 - resume address specified, 0 - otherwise |
| 209 | * @address Resume address |
| 210 | * @ack Flag to specify whether acknowledge requested |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 211 | * @flag 0 - Call from secure source |
| 212 | * 1 - Call from non-secure source |
Tejas Patel | 49cd871 | 2019-01-23 14:18:51 +0530 | [diff] [blame] | 213 | * |
| 214 | * This API function is either used to power up another APU core for SMP |
| 215 | * (by PSCI) or to power up an entirely different PU or subsystem, such |
| 216 | * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be |
| 217 | * automatically set by PMC. |
| 218 | * |
| 219 | * @return Returns status, either success or error+reason |
| 220 | */ |
| 221 | enum pm_ret_status pm_req_wakeup(uint32_t target, uint32_t set_address, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 222 | uintptr_t address, uint8_t ack, uint32_t flag) |
Tejas Patel | 49cd871 | 2019-01-23 14:18:51 +0530 | [diff] [blame] | 223 | { |
| 224 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 225 | |
| 226 | /* Send request to the PMC to perform the wake of the PU */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 227 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQ_WAKEUP, target, |
Tejas Patel | 49cd871 | 2019-01-23 14:18:51 +0530 | [diff] [blame] | 228 | set_address, address, ack); |
| 229 | |
| 230 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 231 | } |
| 232 | |
| 233 | /** |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 234 | * pm_request_device() - Request a device |
| 235 | * @device_id Device ID |
| 236 | * @capabilities Requested capabilities for the device |
| 237 | * @qos Required Quality of Service |
| 238 | * @ack Flag to specify whether acknowledge requested |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 239 | * @flag 0 - Call from secure source |
| 240 | * 1 - Call from non-secure source |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 241 | * |
| 242 | * @return Returns status, either success or error+reason |
| 243 | */ |
| 244 | enum pm_ret_status pm_request_device(uint32_t device_id, uint32_t capabilities, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 245 | uint32_t qos, uint32_t ack, uint32_t flag) |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 246 | { |
| 247 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 248 | |
| 249 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 250 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQUEST_DEVICE, |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 251 | device_id, capabilities, qos, ack); |
| 252 | |
| 253 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * pm_release_device() - Release a device |
| 258 | * @device_id Device ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 259 | * @flag 0 - Call from secure source |
| 260 | * 1 - Call from non-secure source |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 261 | * |
| 262 | * @return Returns status, either success or error+reason |
| 263 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 264 | enum pm_ret_status pm_release_device(uint32_t device_id, uint32_t flag) |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 265 | { |
| 266 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 267 | |
| 268 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 269 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RELEASE_DEVICE, |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 270 | device_id); |
| 271 | |
| 272 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * pm_set_requirement() - Set requirement for the device |
| 277 | * @device_id Device ID |
| 278 | * @capabilities Requested capabilities for the device |
| 279 | * @latency Requested maximum latency |
| 280 | * @qos Required Quality of Service |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 281 | * @flag 0 - Call from secure source |
| 282 | * 1 - Call from non-secure source |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 283 | * |
| 284 | * @return Returns status, either success or error+reason |
| 285 | */ |
| 286 | enum pm_ret_status pm_set_requirement(uint32_t device_id, uint32_t capabilities, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 287 | uint32_t latency, uint32_t qos, |
| 288 | uint32_t flag) |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 289 | { |
| 290 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 291 | |
| 292 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 293 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_SET_REQUIREMENT, |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 294 | device_id, capabilities, latency, qos); |
| 295 | |
| 296 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * pm_get_device_status() - Get device's status |
| 301 | * @device_id Device ID |
| 302 | * @response Buffer to store device status response |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 303 | * @flag 0 - Call from secure source |
| 304 | * 1 - Call from non-secure source |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 305 | * |
| 306 | * @return Returns status, either success or error+reason |
| 307 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 308 | enum pm_ret_status pm_get_device_status(uint32_t device_id, uint32_t *response, |
| 309 | uint32_t flag) |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 310 | { |
| 311 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 312 | |
| 313 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 314 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_GET_DEVICE_STATUS, |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 315 | device_id); |
| 316 | |
| 317 | return pm_ipi_send_sync(primary_proc, payload, response, 3); |
| 318 | } |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * pm_reset_assert() - Assert/De-assert reset |
| 322 | * @reset Reset ID |
| 323 | * @assert Assert (1) or de-assert (0) |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 324 | * @flag 0 - Call from secure source |
| 325 | * 1 - Call from non-secure source |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 326 | * |
| 327 | * @return Returns status, either success or error+reason |
| 328 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 329 | enum pm_ret_status pm_reset_assert(uint32_t reset, bool assert, uint32_t flag) |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 330 | { |
| 331 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 332 | |
| 333 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 334 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT, reset, |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 335 | assert); |
| 336 | |
| 337 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 338 | } |
| 339 | |
| 340 | /** |
| 341 | * pm_reset_get_status() - Get current status of a reset line |
| 342 | * @reset Reset ID |
| 343 | * @status Returns current status of selected reset ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 344 | * @flag 0 - Call from secure source |
| 345 | * 1 - Call from non-secure source |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 346 | * |
| 347 | * @return Returns status, either success or error+reason |
| 348 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 349 | enum pm_ret_status pm_reset_get_status(uint32_t reset, uint32_t *status, |
| 350 | uint32_t flag) |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 351 | { |
| 352 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 353 | |
| 354 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 355 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT, |
| 356 | reset); |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame] | 357 | |
| 358 | return pm_ipi_send_sync(primary_proc, payload, status, 1); |
| 359 | } |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 360 | |
| 361 | /** |
Rajan Vaja | 649e924 | 2019-03-04 11:09:40 +0530 | [diff] [blame] | 362 | * pm_get_callbackdata() - Read from IPI response buffer |
| 363 | * @data - array of PAYLOAD_ARG_CNT elements |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 364 | * @flag - 0 - Call from secure source |
| 365 | * 1 - Call from non-secure source |
Rajan Vaja | 649e924 | 2019-03-04 11:09:40 +0530 | [diff] [blame] | 366 | * |
| 367 | * Read value from ipi buffer response buffer. |
| 368 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 369 | void pm_get_callbackdata(uint32_t *data, size_t count, uint32_t flag) |
Rajan Vaja | 649e924 | 2019-03-04 11:09:40 +0530 | [diff] [blame] | 370 | { |
| 371 | /* Return if interrupt is not from PMU */ |
| 372 | if (!pm_ipi_irq_status(primary_proc)) |
| 373 | return; |
| 374 | |
| 375 | pm_ipi_buff_read_callb(data, count); |
| 376 | pm_ipi_irq_clear(primary_proc); |
| 377 | } |
| 378 | |
| 379 | /** |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 380 | * pm_pinctrl_request() - Request a pin |
| 381 | * @pin Pin ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 382 | * @flag 0 - Call from secure source |
| 383 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 384 | * |
| 385 | * @return Returns status, either success or error+reason |
| 386 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 387 | enum pm_ret_status pm_pinctrl_request(uint32_t pin, uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 388 | { |
| 389 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 390 | |
| 391 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 392 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_REQUEST, |
| 393 | pin); |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 394 | |
| 395 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * pm_pinctrl_release() - Release a pin |
| 400 | * @pin Pin ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 401 | * @flag 0 - Call from secure source |
| 402 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 403 | * |
| 404 | * @return Returns status, either success or error+reason |
| 405 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 406 | enum pm_ret_status pm_pinctrl_release(uint32_t pin, uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 407 | { |
| 408 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 409 | |
| 410 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 411 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_RELEASE, |
| 412 | pin); |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 413 | |
| 414 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * pm_pinctrl_set_function() - Set pin function |
| 419 | * @pin Pin ID |
| 420 | * @function Function ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 421 | * @flag 0 - Call from secure source |
| 422 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 423 | * |
| 424 | * @return Returns status, either success or error+reason |
| 425 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 426 | enum pm_ret_status pm_pinctrl_set_function(uint32_t pin, uint32_t function, |
| 427 | uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 428 | { |
| 429 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 430 | |
| 431 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 432 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, |
| 433 | PM_PINCTRL_SET_FUNCTION, pin, function) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 434 | |
| 435 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * pm_pinctrl_get_function() - Get function set on the pin |
| 440 | * @pin Pin ID |
| 441 | * @function Function set on the pin |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 442 | * @flag 0 - Call from secure source |
| 443 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 444 | * |
| 445 | * @return Returns status, either success or error+reason |
| 446 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 447 | enum pm_ret_status pm_pinctrl_get_function(uint32_t pin, uint32_t *function, |
| 448 | uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 449 | { |
| 450 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 451 | |
| 452 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 453 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, |
| 454 | PM_PINCTRL_SET_FUNCTION, pin); |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 455 | |
| 456 | return pm_ipi_send_sync(primary_proc, payload, function, 1); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * pm_pinctrl_set_pin_param() - Set configuration parameter for the pin |
| 461 | * @pin Pin ID |
| 462 | * @param Parameter ID |
| 463 | * @value Parameter value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 464 | * @flag 0 - Call from secure source |
| 465 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 466 | * |
| 467 | * @return Returns status, either success or error+reason |
| 468 | */ |
| 469 | enum pm_ret_status pm_pinctrl_set_pin_param(uint32_t pin, uint32_t param, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 470 | uint32_t value, uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 471 | { |
| 472 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 473 | |
| 474 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 475 | PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, |
| 476 | PM_PINCTRL_CONFIG_PARAM_SET, pin, param, value); |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 477 | |
| 478 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * pm_pinctrl_get_pin_param() - Get configuration parameter value for the pin |
| 483 | * @pin Pin ID |
| 484 | * @param Parameter ID |
| 485 | * @value Buffer to store parameter value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 486 | * @flag 0 - Call from secure source |
| 487 | * 1 - Call from non-secure source |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 488 | * |
| 489 | * @return Returns status, either success or error+reason |
| 490 | */ |
| 491 | enum pm_ret_status pm_pinctrl_get_pin_param(uint32_t pin, uint32_t param, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 492 | uint32_t *value, uint32_t flag) |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 493 | { |
| 494 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 495 | |
| 496 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 497 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, |
| 498 | PM_PINCTRL_CONFIG_PARAM_GET, pin, param); |
Tejas Patel | 20e9202 | 2019-01-08 01:46:39 -0800 | [diff] [blame] | 499 | |
| 500 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 501 | } |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * pm_clock_enable() - Enable the clock |
| 505 | * @clk_id Clock ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 506 | * @flag 0 - Call from secure source |
| 507 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 508 | * |
| 509 | * @return Returns status, either success or error+reason |
| 510 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 511 | enum pm_ret_status pm_clock_enable(uint32_t clk_id, uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 512 | { |
| 513 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 514 | |
| 515 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 516 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_ENABLE, |
| 517 | clk_id); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 518 | |
| 519 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * pm_clock_disable() - Disable the clock |
| 524 | * @clk_id Clock ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 525 | * @flag 0 - Call from secure source |
| 526 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 527 | * |
| 528 | * @return Returns status, either success or error+reason |
| 529 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 530 | enum pm_ret_status pm_clock_disable(uint32_t clk_id, uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 531 | { |
| 532 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 533 | |
| 534 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 535 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_DISABLE, |
| 536 | clk_id); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 537 | |
| 538 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * pm_clock_get_state() - Get clock status |
| 543 | * @clk_id Clock ID |
| 544 | * @state: Buffer to store clock status (1: Enabled, 0:Disabled) |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 545 | * @flag 0 - Call from secure source |
| 546 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 547 | * |
| 548 | * @return Returns status, either success or error+reason |
| 549 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 550 | enum pm_ret_status pm_clock_get_state(uint32_t clk_id, uint32_t *state, |
| 551 | uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 552 | { |
| 553 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 554 | |
| 555 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 556 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETSTATE, |
| 557 | clk_id); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 558 | |
| 559 | return pm_ipi_send_sync(primary_proc, payload, state, 1); |
| 560 | } |
| 561 | |
| 562 | /** |
| 563 | * pm_clock_set_divider() - Set divider for the clock |
| 564 | * @clk_id Clock ID |
| 565 | * @divider Divider value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 566 | * @flag 0 - Call from secure source |
| 567 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 568 | * |
| 569 | * @return Returns status, either success or error+reason |
| 570 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 571 | enum pm_ret_status pm_clock_set_divider(uint32_t clk_id, uint32_t divider, |
| 572 | uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 573 | { |
| 574 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 575 | |
| 576 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 577 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETDIVIDER, |
| 578 | clk_id, divider); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 579 | |
| 580 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * pm_clock_get_divider() - Get divider value for the clock |
| 585 | * @clk_id Clock ID |
| 586 | * @divider: Buffer to store clock divider value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 587 | * @flag 0 - Call from secure source |
| 588 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 589 | * |
| 590 | * @return Returns status, either success or error+reason |
| 591 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 592 | enum pm_ret_status pm_clock_get_divider(uint32_t clk_id, uint32_t *divider, |
| 593 | uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 594 | { |
| 595 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 596 | |
| 597 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 598 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETDIVIDER, |
| 599 | clk_id); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 600 | |
| 601 | return pm_ipi_send_sync(primary_proc, payload, divider, 1); |
| 602 | } |
| 603 | |
| 604 | /** |
| 605 | * pm_clock_set_parent() - Set parent for the clock |
| 606 | * @clk_id Clock ID |
| 607 | * @parent Parent ID |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 608 | * @flag 0 - Call from secure source |
| 609 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 610 | * |
| 611 | * @return Returns status, either success or error+reason |
| 612 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 613 | enum pm_ret_status pm_clock_set_parent(uint32_t clk_id, uint32_t parent, |
| 614 | uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 615 | { |
| 616 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 617 | |
| 618 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 619 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETPARENT, |
| 620 | clk_id, parent); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 621 | |
| 622 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * pm_clock_get_parent() - Get parent value for the clock |
| 627 | * @clk_id Clock ID |
| 628 | * @parent: Buffer to store clock parent value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 629 | * @flag 0 - Call from secure source |
| 630 | * 1 - Call from non-secure source |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 631 | * |
| 632 | * @return Returns status, either success or error+reason |
| 633 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 634 | enum pm_ret_status pm_clock_get_parent(uint32_t clk_id, uint32_t *parent, |
| 635 | uint32_t flag) |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 636 | { |
| 637 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 638 | |
| 639 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 640 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETPARENT, |
| 641 | clk_id); |
Tejas Patel | 1f56fb1 | 2019-01-08 01:46:40 -0800 | [diff] [blame] | 642 | |
| 643 | return pm_ipi_send_sync(primary_proc, payload, parent, 1); |
| 644 | } |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 645 | /** |
| 646 | * pm_clock_get_rate() - Get the rate value for the clock |
| 647 | * @clk_id Clock ID |
| 648 | * @rate: Buffer to store clock rate value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 649 | * @flag 0 - Call from secure source |
| 650 | * 1 - Call from non-secure source |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 651 | * |
| 652 | * @return Returns status, either success or error+reason |
| 653 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 654 | enum pm_ret_status pm_clock_get_rate(uint32_t clk_id, uint32_t *clk_rate, |
| 655 | uint32_t flag) |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 656 | { |
| 657 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 658 | |
| 659 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 660 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETRATE, |
| 661 | clk_id); |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 662 | |
| 663 | return pm_ipi_send_sync(primary_proc, payload, clk_rate, 2); |
| 664 | } |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 665 | |
| 666 | /** |
| 667 | * pm_pll_set_param() - Set PLL parameter |
| 668 | * @clk_id PLL clock ID |
| 669 | * @param PLL parameter ID |
| 670 | * @value Value to set for PLL parameter |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 671 | * @flag 0 - Call from secure source |
| 672 | * 1 - Call from non-secure source |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 673 | * |
| 674 | * @return Returns status, either success or error+reason |
| 675 | */ |
| 676 | enum pm_ret_status pm_pll_set_param(uint32_t clk_id, uint32_t param, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 677 | uint32_t value, uint32_t flag) |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 678 | { |
| 679 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 680 | |
| 681 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 682 | PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_PARAMETER, |
| 683 | clk_id, param, value); |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 684 | |
| 685 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 686 | } |
| 687 | |
| 688 | /** |
| 689 | * pm_pll_get_param() - Get PLL parameter value |
| 690 | * @clk_id PLL clock ID |
| 691 | * @param PLL parameter ID |
| 692 | * @value: Buffer to store PLL parameter value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 693 | * @flag 0 - Call from secure source |
| 694 | * 1 - Call from non-secure source |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 695 | * |
| 696 | * @return Returns status, either success or error+reason |
| 697 | */ |
| 698 | enum pm_ret_status pm_pll_get_param(uint32_t clk_id, uint32_t param, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 699 | uint32_t *value, uint32_t flag) |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 700 | { |
| 701 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 702 | |
| 703 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 704 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_PARAMETER, |
| 705 | clk_id, param); |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 706 | |
| 707 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 708 | } |
| 709 | |
| 710 | /** |
| 711 | * pm_pll_set_mode() - Set PLL mode |
| 712 | * @clk_id PLL clock ID |
| 713 | * @mode PLL mode |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 714 | * @flag 0 - Call from secure source |
| 715 | * 1 - Call from non-secure source |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 716 | * |
| 717 | * @return Returns status, either success or error+reason |
| 718 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 719 | enum pm_ret_status pm_pll_set_mode(uint32_t clk_id, uint32_t mode, |
| 720 | uint32_t flag) |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 721 | { |
| 722 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 723 | |
| 724 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 725 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_MODE, |
| 726 | clk_id, mode); |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 727 | |
| 728 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * pm_pll_get_mode() - Get PLL mode |
| 733 | * @clk_id PLL clock ID |
| 734 | * @mode: Buffer to store PLL mode |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 735 | * @flag 0 - Call from secure source |
| 736 | * 1 - Call from non-secure source |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 737 | * |
| 738 | * @return Returns status, either success or error+reason |
| 739 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 740 | enum pm_ret_status pm_pll_get_mode(uint32_t clk_id, uint32_t *mode, |
| 741 | uint32_t flag) |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 742 | { |
| 743 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 744 | |
| 745 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 746 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_MODE, |
| 747 | clk_id); |
Tejas Patel | 023116d | 2019-01-08 01:46:41 -0800 | [diff] [blame] | 748 | |
| 749 | return pm_ipi_send_sync(primary_proc, payload, mode, 1); |
| 750 | } |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * pm_force_powerdown() - PM call to request for another PU or subsystem to |
| 754 | * be powered down forcefully |
| 755 | * @target Device ID of the PU node to be forced powered down. |
| 756 | * @ack Flag to specify whether acknowledge is requested |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 757 | * @flag 0 - Call from secure source |
| 758 | * 1 - Call from non-secure source |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 759 | * |
| 760 | * @return Returns status, either success or error+reason |
| 761 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 762 | enum pm_ret_status pm_force_powerdown(uint32_t target, uint8_t ack, |
| 763 | uint32_t flag) |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 764 | { |
| 765 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 766 | |
| 767 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 768 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_FORCE_POWERDOWN, |
| 769 | target, ack); |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 770 | |
| 771 | if (ack == IPI_BLOCKING) |
| 772 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 773 | else |
| 774 | return pm_ipi_send(primary_proc, payload); |
| 775 | } |
| 776 | |
| 777 | /** |
| 778 | * pm_system_shutdown() - PM call to request a system shutdown or restart |
Saeed Nowshadi | c5a1bda | 2019-12-08 23:35:35 -0800 | [diff] [blame] | 779 | * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 780 | * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 781 | * @flag 0 - Call from secure source |
| 782 | * 1 - Call from non-secure source |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 783 | * |
| 784 | * @return Returns status, either success or error+reason |
| 785 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 786 | enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype, |
| 787 | uint32_t flag) |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 788 | { |
| 789 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 790 | |
Saeed Nowshadi | c5a1bda | 2019-12-08 23:35:35 -0800 | [diff] [blame] | 791 | if (type == XPM_SHUTDOWN_TYPE_SETSCOPE_ONLY) { |
| 792 | /* Setting scope for subsequent PSCI reboot or shutdown */ |
| 793 | pm_shutdown_scope = subtype; |
| 794 | return PM_RET_SUCCESS; |
| 795 | } |
| 796 | |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 797 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 798 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SYSTEM_SHUTDOWN, |
| 799 | type, subtype); |
Tejas Patel | 6b28225 | 2019-01-10 03:03:47 -0800 | [diff] [blame] | 800 | |
| 801 | return pm_ipi_send_non_blocking(primary_proc, payload); |
| 802 | } |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 803 | |
| 804 | /** |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 805 | * pm_query_data() - PM API for querying firmware data |
| 806 | * @qid The type of data to query |
| 807 | * @arg1 Argument 1 to requested query data call |
| 808 | * @arg2 Argument 2 to requested query data call |
| 809 | * @arg3 Argument 3 to requested query data call |
| 810 | * @data Returned output data |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 811 | * @flag 0 - Call from secure source |
| 812 | * 1 - Call from non-secure source |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 813 | * |
| 814 | * This function returns requested data. |
| 815 | */ |
| 816 | enum pm_ret_status pm_query_data(uint32_t qid, uint32_t arg1, uint32_t arg2, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 817 | uint32_t arg3, uint32_t *data, uint32_t flag) |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 818 | { |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 819 | uint32_t ret; |
| 820 | uint32_t version; |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 821 | uint32_t payload[PAYLOAD_ARG_CNT]; |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 822 | uint32_t fw_api_version; |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 823 | |
| 824 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 825 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_QUERY_DATA, qid, |
| 826 | arg1, arg2, arg3); |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 827 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 828 | ret = pm_feature_check(PM_QUERY_DATA, &version, flag); |
Manish Pandey | 3bc1bea | 2020-12-10 10:48:22 +0000 | [diff] [blame] | 829 | if (PM_RET_SUCCESS == ret) { |
Rajan Vaja | 030620d | 2020-11-23 04:13:54 -0800 | [diff] [blame] | 830 | fw_api_version = version & 0xFFFF ; |
| 831 | if ((2U == fw_api_version) && |
| 832 | ((XPM_QID_CLOCK_GET_NAME == qid) || |
| 833 | (XPM_QID_PINCTRL_GET_FUNCTION_NAME == qid))) { |
| 834 | ret = pm_ipi_send_sync(primary_proc, payload, data, 8); |
| 835 | ret = data[0]; |
| 836 | data[0] = data[1]; |
| 837 | data[1] = data[2]; |
| 838 | data[2] = data[3]; |
| 839 | } else { |
| 840 | ret = pm_ipi_send_sync(primary_proc, payload, data, 4); |
| 841 | } |
| 842 | } |
| 843 | return ret; |
Tejas Patel | a3e34ad | 2019-02-01 17:25:19 +0530 | [diff] [blame] | 844 | } |
| 845 | /** |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 846 | * pm_api_ioctl() - PM IOCTL API for device control and configs |
| 847 | * @device_id Device ID |
| 848 | * @ioctl_id ID of the requested IOCTL |
| 849 | * @arg1 Argument 1 to requested IOCTL call |
| 850 | * @arg2 Argument 2 to requested IOCTL call |
| 851 | * @value Returned output value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 852 | * @flag 0 - Call from secure source |
| 853 | * 1 - Call from non-secure source |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 854 | * |
| 855 | * This function calls IOCTL to firmware for device control and configuration. |
| 856 | * |
| 857 | * @return Returns status, either success or error+reason |
| 858 | */ |
| 859 | enum pm_ret_status pm_api_ioctl(uint32_t device_id, uint32_t ioctl_id, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 860 | uint32_t arg1, uint32_t arg2, uint32_t *value, |
| 861 | uint32_t flag) |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 862 | { |
| 863 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 864 | |
| 865 | switch (ioctl_id) { |
| 866 | case IOCTL_SET_PLL_FRAC_MODE: |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 867 | return pm_pll_set_mode(arg1, arg2, flag); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 868 | case IOCTL_GET_PLL_FRAC_MODE: |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 869 | return pm_pll_get_mode(arg1, value, flag); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 870 | case IOCTL_SET_PLL_FRAC_DATA: |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 871 | return pm_pll_set_param(arg1, PM_PLL_PARAM_DATA, arg2, flag); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 872 | case IOCTL_GET_PLL_FRAC_DATA: |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 873 | return pm_pll_get_param(arg1, PM_PLL_PARAM_DATA, value, flag); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 874 | default: |
| 875 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 876 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_IOCTL, |
| 877 | device_id, ioctl_id, arg1, arg2); |
Tejas Patel | 9141f44 | 2019-01-10 03:03:48 -0800 | [diff] [blame] | 878 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 879 | } |
| 880 | } |
Tejas Patel | db81205 | 2019-01-23 14:18:53 +0530 | [diff] [blame] | 881 | |
| 882 | /** |
| 883 | * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended |
| 884 | * @target Device id of the targeted PU or subsystem |
| 885 | * @wkup_node Device id of the wakeup peripheral |
| 886 | * @enable Enable or disable the specified peripheral as wake source |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 887 | * @flag 0 - Call from secure source |
| 888 | * 1 - Call from non-secure source |
Tejas Patel | db81205 | 2019-01-23 14:18:53 +0530 | [diff] [blame] | 889 | * |
| 890 | * @return Returns status, either success or error+reason |
| 891 | */ |
| 892 | enum pm_ret_status pm_set_wakeup_source(uint32_t target, uint32_t wkup_device, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 893 | uint8_t enable, uint32_t flag) |
Tejas Patel | db81205 | 2019-01-23 14:18:53 +0530 | [diff] [blame] | 894 | { |
| 895 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 896 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 897 | PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_SET_WAKEUP_SOURCE, |
| 898 | target, wkup_device, enable); |
Tejas Patel | db81205 | 2019-01-23 14:18:53 +0530 | [diff] [blame] | 899 | return pm_ipi_send(primary_proc, payload); |
| 900 | } |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 901 | |
| 902 | /** |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 903 | * pm_get_chipid() - Read silicon ID registers |
| 904 | * @value Buffer for return values. Must be large enough |
| 905 | * to hold 8 bytes. |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 906 | * @flag 0 - Call from secure source |
| 907 | * 1 - Call from non-secure source |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 908 | * |
| 909 | * @return Returns silicon ID registers |
| 910 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 911 | enum pm_ret_status pm_get_chipid(uint32_t *value, uint32_t flag) |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 912 | { |
| 913 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 914 | |
| 915 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 916 | PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_CHIPID); |
Ravi Patel | bd4aa5a | 2019-08-12 03:17:54 -0700 | [diff] [blame] | 917 | |
| 918 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 919 | } |
| 920 | |
| 921 | /** |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 922 | * pm_feature_check() - Returns the supported API version if supported |
| 923 | * @api_id API ID to check |
| 924 | * @value Returned supported API version |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 925 | * @flag 0 - Call from secure source |
| 926 | * 1 - Call from non-secure source |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 927 | * |
| 928 | * @return Returns status, either success or error+reason |
| 929 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 930 | enum pm_ret_status pm_feature_check(uint32_t api_id, unsigned int *version, |
| 931 | uint32_t flag) |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 932 | { |
| 933 | uint32_t payload[PAYLOAD_ARG_CNT], fw_api_version; |
| 934 | uint32_t status; |
| 935 | |
| 936 | switch (api_id) { |
| 937 | case PM_GET_CALLBACK_DATA: |
| 938 | case PM_GET_TRUSTZONE_VERSION: |
Rajan Vaja | ad1ffff | 2021-01-20 00:53:45 -0800 | [diff] [blame] | 939 | case PM_LOAD_PDI: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 940 | *version = (PM_API_BASE_VERSION << 16); |
| 941 | return PM_RET_SUCCESS; |
| 942 | case PM_GET_API_VERSION: |
| 943 | case PM_GET_DEVICE_STATUS: |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 944 | case PM_GET_OP_CHARACTERISTIC: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 945 | case PM_REQ_SUSPEND: |
| 946 | case PM_SELF_SUSPEND: |
| 947 | case PM_FORCE_POWERDOWN: |
| 948 | case PM_ABORT_SUSPEND: |
| 949 | case PM_REQ_WAKEUP: |
| 950 | case PM_SET_WAKEUP_SOURCE: |
| 951 | case PM_SYSTEM_SHUTDOWN: |
| 952 | case PM_REQUEST_DEVICE: |
| 953 | case PM_RELEASE_DEVICE: |
| 954 | case PM_SET_REQUIREMENT: |
| 955 | case PM_RESET_ASSERT: |
| 956 | case PM_RESET_GET_STATUS: |
Venkatesh Yadav Abbarapu | 95ecd45 | 2019-12-10 22:16:36 -0500 | [diff] [blame] | 957 | case PM_GET_CHIPID: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 958 | case PM_PINCTRL_REQUEST: |
| 959 | case PM_PINCTRL_RELEASE: |
| 960 | case PM_PINCTRL_GET_FUNCTION: |
| 961 | case PM_PINCTRL_SET_FUNCTION: |
| 962 | case PM_PINCTRL_CONFIG_PARAM_GET: |
| 963 | case PM_PINCTRL_CONFIG_PARAM_SET: |
| 964 | case PM_IOCTL: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 965 | case PM_CLOCK_ENABLE: |
| 966 | case PM_CLOCK_DISABLE: |
| 967 | case PM_CLOCK_GETSTATE: |
| 968 | case PM_CLOCK_SETDIVIDER: |
| 969 | case PM_CLOCK_GETDIVIDER: |
| 970 | case PM_CLOCK_SETPARENT: |
| 971 | case PM_CLOCK_GETPARENT: |
Tejas Patel | 84275bf | 2020-09-01 04:43:53 -0700 | [diff] [blame] | 972 | case PM_CLOCK_GETRATE: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 973 | case PM_PLL_SET_PARAMETER: |
| 974 | case PM_PLL_GET_PARAMETER: |
| 975 | case PM_PLL_SET_MODE: |
| 976 | case PM_PLL_GET_MODE: |
| 977 | case PM_FEATURE_CHECK: |
Ravi Patel | 476b5b1 | 2019-08-12 03:10:10 -0700 | [diff] [blame] | 978 | case PM_INIT_FINALIZE: |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 979 | case PM_SET_MAX_LATENCY: |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 980 | case PM_REGISTER_NOTIFIER: |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 981 | *version = (PM_API_BASE_VERSION << 16); |
| 982 | break; |
Rajan Vaja | ad1ffff | 2021-01-20 00:53:45 -0800 | [diff] [blame] | 983 | case PM_QUERY_DATA: |
| 984 | *version = (PM_API_QUERY_DATA_VERSION << 16); |
| 985 | break; |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 986 | default: |
| 987 | *version = 0U; |
| 988 | return PM_RET_ERROR_NOFEATURE; |
| 989 | } |
| 990 | |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 991 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, |
| 992 | PM_FEATURE_CHECK, api_id); |
Ravi Patel | 22b0b49 | 2019-03-06 12:34:46 +0530 | [diff] [blame] | 993 | |
| 994 | status = pm_ipi_send_sync(primary_proc, payload, &fw_api_version, 1); |
| 995 | if (status != PM_RET_SUCCESS) |
| 996 | return status; |
| 997 | |
| 998 | *version |= fw_api_version; |
| 999 | |
| 1000 | return PM_RET_SUCCESS; |
| 1001 | } |
Jolly Shah | ed05a71 | 2019-03-22 05:33:39 +0530 | [diff] [blame] | 1002 | |
| 1003 | /** |
| 1004 | * pm_load_pdi() - Load the PDI |
| 1005 | * |
| 1006 | * This function provides support to load PDI from linux |
| 1007 | * |
| 1008 | * src: Source device of pdi(DDR, OCM, SD etc) |
| 1009 | * address_low: lower 32-bit Linear memory space address |
| 1010 | * address_high: higher 32-bit Linear memory space address |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1011 | * @flag 0 - Call from secure source |
| 1012 | * 1 - Call from non-secure source |
Jolly Shah | ed05a71 | 2019-03-22 05:33:39 +0530 | [diff] [blame] | 1013 | * |
| 1014 | * @return Returns status, either success or error+reason |
| 1015 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1016 | enum pm_ret_status pm_load_pdi(uint32_t src, uint32_t address_low, |
| 1017 | uint32_t address_high, uint32_t flag) |
Jolly Shah | ed05a71 | 2019-03-22 05:33:39 +0530 | [diff] [blame] | 1018 | { |
| 1019 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1020 | |
| 1021 | /* Send request to the PMU */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1022 | PM_PACK_PAYLOAD4(payload, LOADER_MODULE_ID, flag, PM_LOAD_PDI, src, |
Jolly Shah | ed05a71 | 2019-03-22 05:33:39 +0530 | [diff] [blame] | 1023 | address_high, address_low); |
| 1024 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1025 | } |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 1026 | |
| 1027 | /** |
| 1028 | * pm_get_op_characteristic() - PM call to request operating characteristics |
| 1029 | * of a device |
| 1030 | * @device_id Device id |
| 1031 | * @type Type of the operating characteristic |
| 1032 | * (power, temperature and latency) |
| 1033 | * @result Returns the operating characteristic for the requested device, |
| 1034 | * specified by the type |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1035 | * @flag 0 - Call from secure source |
| 1036 | * 1 - Call from non-secure source |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 1037 | * |
| 1038 | * @return Returns status, either success or error+reason |
| 1039 | */ |
| 1040 | enum pm_ret_status pm_get_op_characteristic(uint32_t device_id, |
| 1041 | enum pm_opchar_type type, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1042 | uint32_t *result, uint32_t flag) |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 1043 | { |
| 1044 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1045 | |
| 1046 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1047 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, |
| 1048 | PM_GET_OP_CHARACTERISTIC, device_id, type); |
Saeed Nowshadi | 2294b42 | 2019-06-03 10:22:35 -0700 | [diff] [blame] | 1049 | return pm_ipi_send_sync(primary_proc, payload, result, 1); |
| 1050 | } |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 1051 | |
| 1052 | /** |
| 1053 | * pm_set_max_latency() - PM call to change in the maximum wake-up latency |
| 1054 | * requirements for a specific device currently |
| 1055 | * used by that CPU. |
| 1056 | * @device_id Device ID |
| 1057 | * @latency Latency value |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1058 | * @flag 0 - Call from secure source |
| 1059 | * 1 - Call from non-secure source |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 1060 | * |
| 1061 | * @return Returns status, either success or error+reason |
| 1062 | */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1063 | enum pm_ret_status pm_set_max_latency(uint32_t device_id, uint32_t latency, |
| 1064 | uint32_t flag) |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 1065 | { |
| 1066 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1067 | |
| 1068 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1069 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SET_MAX_LATENCY, |
Tejas Patel | 5c154e1 | 2020-11-25 01:53:12 -0800 | [diff] [blame] | 1070 | device_id, latency); |
| 1071 | |
| 1072 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1073 | } |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 1074 | |
| 1075 | /** |
| 1076 | * pm_register_notifier() - PM call to register a subsystem to be notified |
| 1077 | * about the device event |
| 1078 | * @device_id Device ID for the Node to which the event is related |
| 1079 | * @event Event in question |
| 1080 | * @wake Wake subsystem upon capturing the event if value 1 |
| 1081 | * @enable Enable the registration for value 1, disable for value 0 |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1082 | * @flag 0 - Call from secure source |
| 1083 | * 1 - Call from non-secure source |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 1084 | * |
| 1085 | * @return Returns status, either success or error+reason |
| 1086 | */ |
| 1087 | enum pm_ret_status pm_register_notifier(uint32_t device_id, uint32_t event, |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1088 | uint32_t wake, uint32_t enable, |
| 1089 | uint32_t flag) |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 1090 | { |
| 1091 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1092 | |
| 1093 | /* Send request to the PMC */ |
Tejas Patel | 18072da | 2021-02-25 20:16:56 -0800 | [diff] [blame] | 1094 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REGISTER_NOTIFIER, |
Tejas Patel | 4201555 | 2020-11-25 01:56:57 -0800 | [diff] [blame] | 1095 | device_id, event, wake, enable); |
| 1096 | |
| 1097 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1098 | } |