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