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