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