Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 1 | /* |
Michal Simek | 2a47faa | 2023-04-14 08:43:51 +0200 | [diff] [blame] | 2 | * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved. |
Michal Simek | d4ff272 | 2023-04-20 08:01:03 +0200 | [diff] [blame] | 3 | * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 4 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 5 | * SPDX-License-Identifier: BSD-3-Clause |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * ZynqMP system level PM-API functions and communication with PMU via |
| 10 | * IPI interrupts |
| 11 | */ |
| 12 | |
| 13 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
| 15 | |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 16 | #include "pm_api_clock.h" |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 17 | #include "pm_api_ioctl.h" |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 18 | #include "pm_api_pinctrl.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 19 | #include "pm_client.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 20 | #include "pm_common.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 21 | #include "pm_ipi.h" |
Jay Buddhabhatti | 26e138a | 2022-12-21 23:03:35 -0800 | [diff] [blame] | 22 | #include "zynqmp_pm_api_sys.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 23 | |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 24 | #define PM_QUERY_FEATURE_BITMASK ( \ |
| 25 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_NAME) | \ |
| 26 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_TOPOLOGY) | \ |
| 27 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS) | \ |
| 28 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_PARENTS) | \ |
| 29 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_ATTRIBUTES) | \ |
| 30 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_PINS) | \ |
| 31 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_FUNCTIONS) | \ |
| 32 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS) | \ |
| 33 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_FUNCTION_NAME) | \ |
| 34 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_FUNCTION_GROUPS) | \ |
| 35 | (1ULL << (uint64_t)PM_QID_PINCTRL_GET_PIN_GROUPS) | \ |
| 36 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_NUM_CLOCKS) | \ |
| 37 | (1ULL << (uint64_t)PM_QID_CLOCK_GET_MAX_DIVISOR)) |
| 38 | |
| 39 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 40 | * typedef eemi_api_dependency - Dependent EEMI APIs which are implemented |
| 41 | * on both the TF-A and firmware. |
| 42 | * @id: EEMI API id or IOCTL id to be checked. |
| 43 | * @api_id: Dependent EEMI API. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 44 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 45 | */ |
| 46 | typedef struct __attribute__((packed)) { |
| 47 | uint8_t id; |
| 48 | uint8_t api_id; |
| 49 | } eemi_api_dependency; |
| 50 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 51 | /* Dependent APIs for TF-A to check their version from firmware */ |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 52 | static const eemi_api_dependency api_dep_table[] = { |
| 53 | { |
| 54 | .id = PM_SELF_SUSPEND, |
| 55 | .api_id = PM_SELF_SUSPEND, |
| 56 | }, |
| 57 | { |
| 58 | .id = PM_REQ_WAKEUP, |
| 59 | .api_id = PM_REQ_WAKEUP, |
| 60 | }, |
| 61 | { |
| 62 | .id = PM_ABORT_SUSPEND, |
| 63 | .api_id = PM_ABORT_SUSPEND, |
| 64 | }, |
| 65 | { |
| 66 | .id = PM_SET_WAKEUP_SOURCE, |
| 67 | .api_id = PM_SET_WAKEUP_SOURCE, |
| 68 | }, |
| 69 | { |
| 70 | .id = PM_SYSTEM_SHUTDOWN, |
| 71 | .api_id = PM_SYSTEM_SHUTDOWN, |
| 72 | }, |
| 73 | { |
| 74 | .id = PM_GET_API_VERSION, |
| 75 | .api_id = PM_GET_API_VERSION, |
| 76 | }, |
| 77 | { |
| 78 | .id = PM_CLOCK_ENABLE, |
| 79 | .api_id = PM_PLL_SET_MODE, |
| 80 | }, |
| 81 | { |
| 82 | .id = PM_CLOCK_ENABLE, |
| 83 | .api_id = PM_CLOCK_ENABLE, |
| 84 | }, |
| 85 | { |
| 86 | .id = PM_CLOCK_DISABLE, |
| 87 | .api_id = PM_PLL_SET_MODE, |
| 88 | }, |
| 89 | { |
| 90 | .id = PM_CLOCK_DISABLE, |
| 91 | .api_id = PM_CLOCK_DISABLE, |
| 92 | }, |
| 93 | { |
| 94 | .id = PM_CLOCK_GETSTATE, |
| 95 | .api_id = PM_PLL_GET_MODE, |
| 96 | }, |
| 97 | { |
| 98 | .id = PM_CLOCK_GETSTATE, |
| 99 | .api_id = PM_CLOCK_GETSTATE, |
| 100 | }, |
| 101 | { |
| 102 | .id = PM_CLOCK_SETDIVIDER, |
| 103 | .api_id = PM_PLL_SET_PARAMETER, |
| 104 | }, |
| 105 | { |
| 106 | .id = PM_CLOCK_SETDIVIDER, |
| 107 | .api_id = PM_CLOCK_SETDIVIDER, |
| 108 | }, |
| 109 | { |
| 110 | .id = PM_CLOCK_GETDIVIDER, |
| 111 | .api_id = PM_PLL_GET_PARAMETER, |
| 112 | }, |
| 113 | { |
| 114 | .id = PM_CLOCK_GETDIVIDER, |
| 115 | .api_id = PM_CLOCK_GETDIVIDER, |
| 116 | }, |
| 117 | { |
| 118 | .id = PM_CLOCK_SETPARENT, |
| 119 | .api_id = PM_PLL_SET_PARAMETER, |
| 120 | }, |
| 121 | { |
| 122 | .id = PM_CLOCK_SETPARENT, |
| 123 | .api_id = PM_CLOCK_SETPARENT, |
| 124 | }, |
| 125 | { |
| 126 | .id = PM_CLOCK_GETPARENT, |
| 127 | .api_id = PM_PLL_GET_PARAMETER, |
| 128 | }, |
| 129 | { |
| 130 | .id = PM_CLOCK_GETPARENT, |
| 131 | .api_id = PM_CLOCK_GETPARENT, |
| 132 | }, |
| 133 | { |
| 134 | .id = PM_PLL_SET_PARAMETER, |
| 135 | .api_id = PM_PLL_SET_PARAMETER, |
| 136 | }, |
| 137 | { |
| 138 | .id = PM_PLL_GET_PARAMETER, |
| 139 | .api_id = PM_PLL_GET_PARAMETER, |
| 140 | }, |
| 141 | { |
| 142 | .id = PM_PLL_SET_MODE, |
| 143 | .api_id = PM_PLL_SET_MODE, |
| 144 | }, |
| 145 | { |
| 146 | .id = PM_PLL_GET_MODE, |
| 147 | .api_id = PM_PLL_GET_MODE, |
| 148 | }, |
| 149 | { |
| 150 | .id = PM_REGISTER_ACCESS, |
| 151 | .api_id = PM_MMIO_WRITE, |
| 152 | }, |
| 153 | { |
| 154 | .id = PM_REGISTER_ACCESS, |
| 155 | .api_id = PM_MMIO_READ, |
| 156 | }, |
| 157 | { |
| 158 | .id = PM_FEATURE_CHECK, |
| 159 | .api_id = PM_FEATURE_CHECK, |
| 160 | }, |
| 161 | { |
| 162 | .id = IOCTL_SET_TAPDELAY_BYPASS, |
| 163 | .api_id = PM_MMIO_WRITE, |
| 164 | }, |
| 165 | { |
| 166 | .id = IOCTL_SET_SGMII_MODE, |
| 167 | .api_id = PM_MMIO_WRITE, |
| 168 | }, |
| 169 | { |
| 170 | .id = IOCTL_SD_DLL_RESET, |
| 171 | .api_id = PM_MMIO_WRITE, |
| 172 | }, |
| 173 | { |
| 174 | .id = IOCTL_SET_SD_TAPDELAY, |
| 175 | .api_id = PM_MMIO_WRITE, |
| 176 | }, |
| 177 | { |
| 178 | .id = IOCTL_SET_SD_TAPDELAY, |
| 179 | .api_id = PM_MMIO_READ, |
| 180 | }, |
| 181 | { |
| 182 | .id = IOCTL_SET_PLL_FRAC_DATA, |
| 183 | .api_id = PM_PLL_SET_PARAMETER, |
| 184 | }, |
| 185 | { |
| 186 | .id = IOCTL_GET_PLL_FRAC_DATA, |
| 187 | .api_id = PM_PLL_GET_PARAMETER, |
| 188 | }, |
| 189 | { |
| 190 | .id = IOCTL_WRITE_GGS, |
| 191 | .api_id = PM_MMIO_WRITE, |
| 192 | }, |
| 193 | { |
| 194 | .id = IOCTL_READ_GGS, |
| 195 | .api_id = PM_MMIO_READ, |
| 196 | }, |
| 197 | { |
| 198 | .id = IOCTL_WRITE_PGGS, |
| 199 | .api_id = PM_MMIO_WRITE, |
| 200 | }, |
| 201 | { |
| 202 | .id = IOCTL_READ_PGGS, |
| 203 | .api_id = PM_MMIO_READ, |
| 204 | }, |
| 205 | { |
| 206 | .id = IOCTL_ULPI_RESET, |
| 207 | .api_id = PM_MMIO_WRITE, |
| 208 | }, |
| 209 | { |
| 210 | .id = IOCTL_SET_BOOT_HEALTH_STATUS, |
| 211 | .api_id = PM_MMIO_WRITE, |
| 212 | }, |
| 213 | { |
| 214 | .id = IOCTL_AFI, |
| 215 | .api_id = PM_MMIO_WRITE, |
| 216 | }, |
| 217 | }; |
| 218 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 219 | /* Expected firmware API version to TF-A */ |
| 220 | static const uint8_t tfa_expected_ver_id[] = { |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 221 | [PM_SELF_SUSPEND] = FW_API_BASE_VERSION, |
| 222 | [PM_REQ_WAKEUP] = FW_API_BASE_VERSION, |
| 223 | [PM_ABORT_SUSPEND] = FW_API_BASE_VERSION, |
| 224 | [PM_SET_WAKEUP_SOURCE] = FW_API_BASE_VERSION, |
| 225 | [PM_SYSTEM_SHUTDOWN] = FW_API_BASE_VERSION, |
| 226 | [PM_GET_API_VERSION] = FW_API_BASE_VERSION, |
| 227 | [PM_PLL_SET_MODE] = FW_API_BASE_VERSION, |
| 228 | [PM_PLL_GET_MODE] = FW_API_BASE_VERSION, |
| 229 | [PM_CLOCK_ENABLE] = FW_API_BASE_VERSION, |
| 230 | [PM_CLOCK_DISABLE] = FW_API_BASE_VERSION, |
| 231 | [PM_CLOCK_GETSTATE] = FW_API_BASE_VERSION, |
| 232 | [PM_PLL_SET_PARAMETER] = FW_API_BASE_VERSION, |
| 233 | [PM_PLL_GET_PARAMETER] = FW_API_BASE_VERSION, |
| 234 | [PM_CLOCK_SETDIVIDER] = FW_API_BASE_VERSION, |
| 235 | [PM_CLOCK_GETDIVIDER] = FW_API_BASE_VERSION, |
| 236 | [PM_CLOCK_SETPARENT] = FW_API_BASE_VERSION, |
| 237 | [PM_CLOCK_GETPARENT] = FW_API_BASE_VERSION, |
| 238 | [PM_MMIO_WRITE] = FW_API_BASE_VERSION, |
| 239 | [PM_MMIO_READ] = FW_API_BASE_VERSION, |
| 240 | [PM_FEATURE_CHECK] = FW_API_VERSION_2, |
| 241 | }; |
| 242 | |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 243 | /* default shutdown/reboot scope is system(2) */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 244 | static uint32_t pm_shutdown_scope = PMF_SHUTDOWN_SUBTYPE_SYSTEM; |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 245 | |
| 246 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 247 | * pm_get_shutdown_scope() - Get the currently set shutdown scope. |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 248 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 249 | * Return: Shutdown scope value. |
| 250 | * |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 251 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 252 | uint32_t pm_get_shutdown_scope(void) |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 253 | { |
| 254 | return pm_shutdown_scope; |
| 255 | } |
| 256 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 257 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 258 | * pm_self_suspend() - PM call for processor to suspend itself. |
| 259 | * @nid: Node id of the processor or subsystem. |
| 260 | * @latency: Requested maximum wakeup latency (not supported). |
| 261 | * @state: Requested state. |
| 262 | * @address: Resume address. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 263 | * |
| 264 | * This is a blocking call, it will return only once PMU has responded. |
| 265 | * On a wakeup, resume address will be automatically set by PMU. |
| 266 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 267 | * Return: Returns status, either success or error+reason. |
| 268 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 269 | */ |
| 270 | enum pm_ret_status pm_self_suspend(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 271 | uint32_t latency, |
| 272 | uint32_t state, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 273 | uintptr_t address) |
| 274 | { |
| 275 | uint32_t payload[PAYLOAD_ARG_CNT]; |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 276 | uint32_t cpuid = plat_my_core_pos(); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 277 | const struct pm_proc *proc = pm_get_proc(cpuid); |
| 278 | |
| 279 | /* |
| 280 | * Do client specific suspend operations |
| 281 | * (e.g. set powerdown request bit) |
| 282 | */ |
Filip Drazic | 4c0765a | 2016-07-26 12:11:33 +0200 | [diff] [blame] | 283 | pm_client_suspend(proc, state); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 284 | /* Send request to the PMU */ |
| 285 | PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency, |
| 286 | state, address, (address >> 32)); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 287 | return pm_ipi_send_sync(proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /** |
| 291 | * pm_req_suspend() - PM call to request for another PU or subsystem to |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 292 | * be suspended gracefully. |
| 293 | * @target: Node id of the targeted PU or subsystem. |
| 294 | * @ack: Flag to specify whether acknowledge is requested. |
| 295 | * @latency: Requested wakeup latency (not supported). |
| 296 | * @state: Requested state (not supported). |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 297 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 298 | * Return: Returns status, either success or error+reason. |
| 299 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 300 | */ |
| 301 | enum pm_ret_status pm_req_suspend(enum pm_node_id target, |
| 302 | enum pm_request_ack ack, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 303 | uint32_t latency, uint32_t state) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 304 | { |
| 305 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 306 | |
| 307 | /* Send request to the PMU */ |
| 308 | PM_PACK_PAYLOAD5(payload, PM_REQ_SUSPEND, target, ack, latency, state); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 309 | if (ack == REQ_ACK_BLOCKING) { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 310 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 311 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 312 | return pm_ipi_send(primary_proc, payload); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 313 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | /** |
| 317 | * pm_req_wakeup() - PM call for processor to wake up selected processor |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 318 | * or subsystem. |
| 319 | * @target: Node id of the processor or subsystem to wake up. |
| 320 | * @ack: Flag to specify whether acknowledge requested. |
| 321 | * @set_address: Resume address presence indicator. |
| 322 | * 1 resume address specified, 0 otherwise. |
| 323 | * @address: Resume address. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 324 | * |
| 325 | * This API function is either used to power up another APU core for SMP |
| 326 | * (by PSCI) or to power up an entirely different PU or subsystem, such |
| 327 | * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be |
| 328 | * automatically set by PMU. |
| 329 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 330 | * Return: Returns status, either success or error+reason. |
| 331 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 332 | */ |
| 333 | enum pm_ret_status pm_req_wakeup(enum pm_node_id target, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 334 | uint32_t set_address, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 335 | uintptr_t address, |
| 336 | enum pm_request_ack ack) |
| 337 | { |
| 338 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 339 | uint64_t encoded_address; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 340 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 341 | |
| 342 | /* encode set Address into 1st bit of address */ |
| 343 | encoded_address = address; |
| 344 | encoded_address |= !!set_address; |
| 345 | |
| 346 | /* Send request to the PMU to perform the wake of the PU */ |
| 347 | PM_PACK_PAYLOAD5(payload, PM_REQ_WAKEUP, target, encoded_address, |
| 348 | encoded_address >> 32, ack); |
| 349 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 350 | if (ack == REQ_ACK_BLOCKING) { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 351 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 352 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 353 | return pm_ipi_send(primary_proc, payload); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 354 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
| 358 | * pm_force_powerdown() - PM call to request for another PU or subsystem to |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 359 | * be powered down forcefully. |
| 360 | * @target: Node id of the targeted PU or subsystem. |
| 361 | * @ack: Flag to specify whether acknowledge is requested. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 362 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 363 | * Return: Returns status, either success or error+reason. |
| 364 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 365 | */ |
| 366 | enum pm_ret_status pm_force_powerdown(enum pm_node_id target, |
| 367 | enum pm_request_ack ack) |
| 368 | { |
| 369 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 370 | |
| 371 | /* Send request to the PMU */ |
| 372 | PM_PACK_PAYLOAD3(payload, PM_FORCE_POWERDOWN, target, ack); |
| 373 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 374 | if (ack == REQ_ACK_BLOCKING) { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 375 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 376 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 377 | return pm_ipi_send(primary_proc, payload); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 378 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | /** |
| 382 | * pm_abort_suspend() - PM call to announce that a prior suspend request |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 383 | * is to be aborted. |
| 384 | * @reason: Reason for the abort. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 385 | * |
| 386 | * Calling PU expects the PMU to abort the initiated suspend procedure. |
| 387 | * This is a non-blocking call without any acknowledge. |
| 388 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 389 | * Return: Returns status, either success or error+reason |
| 390 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 391 | */ |
| 392 | enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason) |
| 393 | { |
| 394 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 395 | |
| 396 | /* |
| 397 | * Do client specific abort suspend operations |
| 398 | * (e.g. enable interrupts and clear powerdown request bit) |
| 399 | */ |
| 400 | pm_client_abort_suspend(); |
| 401 | /* Send request to the PMU */ |
| 402 | /* TODO: allow passing the node ID of the affected CPU */ |
| 403 | PM_PACK_PAYLOAD3(payload, PM_ABORT_SUSPEND, reason, |
| 404 | primary_proc->node_id); |
Abhyuday Godhasara | 0d9b765 | 2021-06-24 05:49:04 -0700 | [diff] [blame] | 405 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 409 | * pm_set_wakeup_source() - PM call to specify the wakeup source while |
| 410 | * suspended. |
| 411 | * @target: Node id of the targeted PU or subsystem. |
| 412 | * @wkup_node: Node id of the wakeup peripheral. |
| 413 | * @enable: Enable or disable the specified peripheral as wake source. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 414 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 415 | * Return: Returns status, either success or error+reason. |
| 416 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 417 | */ |
| 418 | enum pm_ret_status pm_set_wakeup_source(enum pm_node_id target, |
| 419 | enum pm_node_id wkup_node, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 420 | uint32_t enable) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 421 | { |
| 422 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 423 | |
| 424 | PM_PACK_PAYLOAD4(payload, PM_SET_WAKEUP_SOURCE, target, wkup_node, |
| 425 | enable); |
Abhyuday Godhasara | 0d9b765 | 2021-06-24 05:49:04 -0700 | [diff] [blame] | 426 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 430 | * pm_system_shutdown() - PM call to request a system shutdown or restart. |
| 431 | * @type: Shutdown or restart? 0=shutdown, 1=restart, 2=setscope. |
| 432 | * @subtype: Scope: 0=APU-subsystem, 1=PS, 2=system. |
| 433 | * |
| 434 | * Return: Returns status, either success or error+reason. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 435 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 436 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 437 | enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 438 | { |
| 439 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 440 | |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 441 | if (type == PMF_SHUTDOWN_TYPE_SETSCOPE_ONLY) { |
| 442 | /* Setting scope for subsequent PSCI reboot or shutdown */ |
| 443 | pm_shutdown_scope = subtype; |
| 444 | return PM_RET_SUCCESS; |
| 445 | } |
| 446 | |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 447 | PM_PACK_PAYLOAD3(payload, PM_SYSTEM_SHUTDOWN, type, subtype); |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 448 | return pm_ipi_send_non_blocking(primary_proc, payload); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* APIs for managing PM slaves: */ |
| 452 | |
| 453 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 454 | * pm_req_node() - PM call to request a node with specific capabilities. |
| 455 | * @nid: Node id of the slave. |
| 456 | * @capabilities: Requested capabilities of the slave. |
| 457 | * @qos: Quality of service (not supported). |
| 458 | * @ack: Flag to specify whether acknowledge is requested. |
| 459 | * |
| 460 | * Return: Returns status, either success or error+reason. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 461 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 462 | */ |
| 463 | enum pm_ret_status pm_req_node(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 464 | uint32_t capabilities, |
| 465 | uint32_t qos, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 466 | enum pm_request_ack ack) |
| 467 | { |
| 468 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 469 | |
| 470 | PM_PACK_PAYLOAD5(payload, PM_REQ_NODE, nid, capabilities, qos, ack); |
| 471 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 472 | if (ack == REQ_ACK_BLOCKING) { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 473 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 474 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 475 | return pm_ipi_send(primary_proc, payload); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 476 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 480 | * pm_set_requirement() - PM call to set requirement for PM slaves. |
| 481 | * @nid: Node id of the slave. |
| 482 | * @capabilities: Requested capabilities of the slave. |
| 483 | * @qos: Quality of service (not supported). |
| 484 | * @ack: Flag to specify whether acknowledge is requested. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 485 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 486 | * This API function is to be used for slaves a PU already has requested. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 487 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 488 | * Return: Returns status, either success or error+reason. |
| 489 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 490 | */ |
| 491 | enum pm_ret_status pm_set_requirement(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 492 | uint32_t capabilities, |
| 493 | uint32_t qos, |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 494 | enum pm_request_ack ack) |
| 495 | { |
| 496 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 497 | |
| 498 | PM_PACK_PAYLOAD5(payload, PM_SET_REQUIREMENT, nid, capabilities, qos, |
| 499 | ack); |
| 500 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 501 | if (ack == REQ_ACK_BLOCKING) { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 502 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 503 | } else { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 504 | return pm_ipi_send(primary_proc, payload); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 505 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 506 | } |
| 507 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 508 | /* Miscellaneous API functions */ |
| 509 | |
| 510 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 511 | * pm_get_api_version() - Get version number of PMU PM firmware. |
| 512 | * @version: Returns 32-bit version number of PMU Power Management Firmware. |
| 513 | * |
| 514 | * Return: Returns status, either success or error+reason. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 515 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 516 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 517 | enum pm_ret_status pm_get_api_version(uint32_t *version) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 518 | { |
| 519 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 520 | |
| 521 | /* Send request to the PMU */ |
| 522 | PM_PACK_PAYLOAD1(payload, PM_GET_API_VERSION); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 523 | return pm_ipi_send_sync(primary_proc, payload, version, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 527 | * pm_get_node_status() - PM call to request a node's current status. |
| 528 | * @nid: Node id. |
| 529 | * @ret_buff: Buffer for the return values |
| 530 | * [0] - Current power state of the node |
| 531 | * [1] - Current requirements for the node (slave nodes only) |
| 532 | * [2] - Current usage status for the node (slave nodes only) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 533 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 534 | * Return: Returns status, either success or error+reason. |
| 535 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 536 | */ |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 537 | enum pm_ret_status pm_get_node_status(enum pm_node_id nid, |
| 538 | uint32_t *ret_buff) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 539 | { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 540 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 541 | |
| 542 | PM_PACK_PAYLOAD2(payload, PM_GET_NODE_STATUS, nid); |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 543 | return pm_ipi_send_sync(primary_proc, payload, ret_buff, 3); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 544 | } |
| 545 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 546 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 547 | * pm_mmio_write() - Perform write to protected mmio. |
| 548 | * @address: Address to write to. |
| 549 | * @mask: Mask to apply. |
| 550 | * @value: Value to write. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 551 | * |
| 552 | * This function provides access to PM-related control registers |
| 553 | * that may not be directly accessible by a particular PU. |
| 554 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 555 | * Return: Returns status, either success or error+reason. |
| 556 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 557 | */ |
| 558 | enum pm_ret_status pm_mmio_write(uintptr_t address, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 559 | uint32_t mask, |
| 560 | uint32_t value) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 561 | { |
| 562 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 563 | |
| 564 | /* Send request to the PMU */ |
| 565 | PM_PACK_PAYLOAD4(payload, PM_MMIO_WRITE, address, mask, value); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 566 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 570 | * pm_mmio_read() - Read value from protected mmio. |
| 571 | * @address: Address to write to. |
| 572 | * @value: Value to write. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 573 | * |
| 574 | * This function provides access to PM-related control registers |
| 575 | * that may not be directly accessible by a particular PU. |
| 576 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 577 | * Return: Returns status, either success or error+reason. |
| 578 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 579 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 580 | enum pm_ret_status pm_mmio_read(uintptr_t address, uint32_t *value) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 581 | { |
| 582 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 583 | |
| 584 | /* Send request to the PMU */ |
| 585 | PM_PACK_PAYLOAD2(payload, PM_MMIO_READ, address); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 586 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 587 | } |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 588 | |
| 589 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 590 | * pm_fpga_load() - Load the bitstream into the PL. This function provides |
| 591 | * access to the xilfpga library to load the Bit-stream |
| 592 | * into PL. |
| 593 | * @address_low: lower 32-bit Linear memory space address. |
| 594 | * @address_high: higher 32-bit Linear memory space address. |
| 595 | * @size: Number of 32bit words. |
| 596 | * @flags: Additional flags or settings for the fpga operation. |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 597 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 598 | * Return: Returns status, either success or error+reason. |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 599 | * |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 600 | */ |
| 601 | enum pm_ret_status pm_fpga_load(uint32_t address_low, |
| 602 | uint32_t address_high, |
| 603 | uint32_t size, |
| 604 | uint32_t flags) |
| 605 | { |
| 606 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 607 | |
| 608 | /* Send request to the PMU */ |
| 609 | PM_PACK_PAYLOAD5(payload, PM_FPGA_LOAD, address_high, address_low, |
| 610 | size, flags); |
Siva Durga Prasad Paladugu | bf83b9c | 2018-02-07 13:13:01 +0530 | [diff] [blame] | 611 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 615 | * pm_fpga_get_status() - Read value from fpga status register. |
| 616 | * @value: Value to read. |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 617 | * |
| 618 | * This function provides access to the xilfpga library to get |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 619 | * the fpga status. |
| 620 | * |
| 621 | * Return: Returns status, either success or error+reason. |
| 622 | * |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 623 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 624 | enum pm_ret_status pm_fpga_get_status(uint32_t *value) |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 625 | { |
| 626 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 627 | |
| 628 | /* Send request to the PMU */ |
| 629 | PM_PACK_PAYLOAD1(payload, PM_FPGA_GET_STATUS); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 630 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 631 | } |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 632 | |
| 633 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 634 | * pm_get_chipid() - Read silicon ID registers. |
| 635 | * @value: Buffer for return values. Must be large enough to hold 8 bytes. |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 636 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 637 | * Return: Returns silicon ID registers. |
| 638 | * |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 639 | */ |
| 640 | enum pm_ret_status pm_get_chipid(uint32_t *value) |
| 641 | { |
| 642 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 643 | |
| 644 | /* Send request to the PMU */ |
| 645 | PM_PACK_PAYLOAD1(payload, PM_GET_CHIPID); |
| 646 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 647 | } |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 648 | |
| 649 | /** |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 650 | * pm_secure_rsaaes() - Load the secure images. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 651 | * @address_low: lower 32-bit Linear memory space address. |
| 652 | * @address_high: higher 32-bit Linear memory space address. |
| 653 | * @size: Number of 32bit words. |
| 654 | * @flags: Additional flags or settings for the fpga operation. |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 655 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 656 | * This function provides access to the xilsecure library to load the |
| 657 | * authenticated, encrypted, and authenticated/encrypted images. |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 658 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 659 | * Return: Returns status, either success or error+reason. |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 660 | * |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 661 | */ |
| 662 | enum pm_ret_status pm_secure_rsaaes(uint32_t address_low, |
| 663 | uint32_t address_high, |
| 664 | uint32_t size, |
| 665 | uint32_t flags) |
| 666 | { |
| 667 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 668 | |
| 669 | /* Send request to the PMU */ |
| 670 | PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA_AES, address_high, address_low, |
| 671 | size, flags); |
| 672 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 673 | } |
| 674 | |
| 675 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 676 | * pm_aes_engine() - Aes data blob encryption/decryption. |
| 677 | * @address_low: lower 32-bit address of the AesParams structure. |
| 678 | * @address_high: higher 32-bit address of the AesParams structure. |
| 679 | * @value: Returned output value. |
| 680 | * |
Siva Durga Prasad Paladugu | 8bd905b | 2018-09-04 18:05:50 +0530 | [diff] [blame] | 681 | * This function provides access to the xilsecure library to |
| 682 | * encrypt/decrypt data blobs. |
| 683 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 684 | * Return: Returns status, either success or error+reason. |
Siva Durga Prasad Paladugu | 8bd905b | 2018-09-04 18:05:50 +0530 | [diff] [blame] | 685 | * |
Siva Durga Prasad Paladugu | 8bd905b | 2018-09-04 18:05:50 +0530 | [diff] [blame] | 686 | */ |
| 687 | enum pm_ret_status pm_aes_engine(uint32_t address_high, |
| 688 | uint32_t address_low, |
| 689 | uint32_t *value) |
| 690 | { |
| 691 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 692 | |
| 693 | /* Send request to the PMU */ |
| 694 | PM_PACK_PAYLOAD3(payload, PM_SECURE_AES, address_high, address_low); |
| 695 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 696 | } |
| 697 | |
| 698 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 699 | * pm_get_callbackdata() - Read from IPI response buffer. |
| 700 | * @data: array of PAYLOAD_ARG_CNT elements. |
| 701 | * @count: Number of values to return. |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 702 | * |
| 703 | * Read value from ipi buffer response buffer. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 704 | * Return: Returns status, either success or error. |
| 705 | * |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 706 | */ |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 707 | enum pm_ret_status pm_get_callbackdata(uint32_t *data, size_t count) |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 708 | { |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 709 | enum pm_ret_status ret = PM_RET_SUCCESS; |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 710 | /* Return if interrupt is not from PMU */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 711 | if (!pm_ipi_irq_status(primary_proc)) { |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 712 | return ret; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 713 | } |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 714 | |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 715 | ret = pm_ipi_buff_read_callb(data, count); |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 716 | pm_ipi_irq_clear(primary_proc); |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 717 | return ret; |
Rajan Vaja | 02d1842 | 2019-03-04 11:09:39 +0530 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 721 | * pm_ioctl() - PM IOCTL API for device control and configs. |
| 722 | * @nid: Node ID of the device. |
| 723 | * @ioctl_id: ID of the requested IOCTL. |
| 724 | * @arg1: Argument 1 to requested IOCTL call. |
| 725 | * @arg2: Argument 2 to requested IOCTL call. |
| 726 | * @value: Returned output value. |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 727 | * |
| 728 | * This function calls IOCTL to firmware for device control and configuration. |
| 729 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 730 | * Return: Returns status, either success or error+reason. |
| 731 | * |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 732 | */ |
| 733 | enum pm_ret_status pm_ioctl(enum pm_node_id nid, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 734 | uint32_t ioctl_id, |
| 735 | uint32_t arg1, |
| 736 | uint32_t arg2, |
| 737 | uint32_t *value) |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 738 | { |
| 739 | return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value); |
| 740 | } |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 741 | |
| 742 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 743 | * fw_api_version() - Returns API version implemented in firmware. |
| 744 | * @id: API ID to check. |
| 745 | * @version: Returned supported API version. |
| 746 | * @len: Number of words to be returned. |
| 747 | * |
| 748 | * Return: Returns status, either success or error+reason. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 749 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 750 | */ |
| 751 | static enum pm_ret_status fw_api_version(uint32_t id, uint32_t *version, |
| 752 | uint32_t len) |
| 753 | { |
| 754 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 755 | |
| 756 | PM_PACK_PAYLOAD2(payload, PM_FEATURE_CHECK, id); |
| 757 | return pm_ipi_send_sync(primary_proc, payload, version, len); |
| 758 | } |
| 759 | |
| 760 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 761 | * check_api_dependency() - API to check dependent EEMI API version. |
| 762 | * @id: EEMI API ID to check. |
| 763 | * |
| 764 | * Return: Returns status, either success or error+reason. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 765 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 766 | */ |
| 767 | enum pm_ret_status check_api_dependency(uint8_t id) |
| 768 | { |
| 769 | uint8_t i; |
| 770 | uint32_t version; |
| 771 | int ret; |
| 772 | |
| 773 | for (i = 0U; i < ARRAY_SIZE(api_dep_table); i++) { |
| 774 | if (api_dep_table[i].id == id) { |
| 775 | if (api_dep_table[i].api_id == 0U) { |
| 776 | break; |
| 777 | } |
| 778 | |
| 779 | ret = fw_api_version(api_dep_table[i].api_id, |
| 780 | &version, 1); |
| 781 | if (ret != PM_RET_SUCCESS) { |
| 782 | return ret; |
| 783 | } |
| 784 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 785 | /* Check if fw version matches TF-A expected version */ |
| 786 | if (version != tfa_expected_ver_id[api_dep_table[i].api_id]) { |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 787 | return PM_RET_ERROR_NOTSUPPORTED; |
| 788 | } |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | return PM_RET_SUCCESS; |
| 793 | } |
| 794 | |
| 795 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 796 | * feature_check_tfa() - These are API's completely implemented in TF-A. |
| 797 | * @api_id: API ID to check. |
| 798 | * @version: Returned supported API version. |
| 799 | * @bit_mask: Returned supported IOCTL id version. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 800 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 801 | * Return: Returns status, either success or error+reason. |
| 802 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 803 | */ |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 804 | static enum pm_ret_status feature_check_tfa(uint32_t api_id, uint32_t *version, |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 805 | uint32_t *bit_mask) |
| 806 | { |
| 807 | switch (api_id) { |
| 808 | case PM_QUERY_DATA: |
Ronak Jain | 11b084a | 2023-02-13 04:48:06 -0800 | [diff] [blame] | 809 | *version = TFA_API_QUERY_DATA_VERSION; |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 810 | bit_mask[0] = (uint32_t)(PM_QUERY_FEATURE_BITMASK); |
| 811 | bit_mask[1] = (uint32_t)(PM_QUERY_FEATURE_BITMASK >> 32); |
| 812 | return PM_RET_SUCCESS; |
| 813 | case PM_GET_CALLBACK_DATA: |
| 814 | case PM_GET_TRUSTZONE_VERSION: |
| 815 | case PM_SET_SUSPEND_MODE: |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 816 | *version = TFA_API_BASE_VERSION; |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 817 | return PM_RET_SUCCESS; |
| 818 | default: |
| 819 | return PM_RET_ERROR_NO_FEATURE; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 824 | * get_tfa_version_for_partial_apis() - Return TF-A version for partially. |
| 825 | * implemented APIs |
| 826 | * @api_id: API ID to check. |
| 827 | * @version: Returned supported API version. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 828 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 829 | * Return: Returns status, either success or error+reason. |
| 830 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 831 | */ |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 832 | static enum pm_ret_status get_tfa_version_for_partial_apis(uint32_t api_id, |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 833 | uint32_t *version) |
| 834 | { |
| 835 | switch (api_id) { |
| 836 | case PM_SELF_SUSPEND: |
| 837 | case PM_REQ_WAKEUP: |
| 838 | case PM_ABORT_SUSPEND: |
| 839 | case PM_SET_WAKEUP_SOURCE: |
| 840 | case PM_SYSTEM_SHUTDOWN: |
| 841 | case PM_GET_API_VERSION: |
| 842 | case PM_CLOCK_ENABLE: |
| 843 | case PM_CLOCK_DISABLE: |
| 844 | case PM_CLOCK_GETSTATE: |
| 845 | case PM_CLOCK_SETDIVIDER: |
| 846 | case PM_CLOCK_GETDIVIDER: |
| 847 | case PM_CLOCK_SETPARENT: |
| 848 | case PM_CLOCK_GETPARENT: |
| 849 | case PM_PLL_SET_PARAMETER: |
| 850 | case PM_PLL_GET_PARAMETER: |
| 851 | case PM_PLL_SET_MODE: |
| 852 | case PM_PLL_GET_MODE: |
| 853 | case PM_REGISTER_ACCESS: |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 854 | *version = TFA_API_BASE_VERSION; |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 855 | return PM_RET_SUCCESS; |
| 856 | case PM_FEATURE_CHECK: |
| 857 | *version = FW_API_VERSION_2; |
| 858 | return PM_RET_SUCCESS; |
| 859 | default: |
| 860 | return PM_RET_ERROR_ARGS; |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | /** |
| 865 | * feature_check_partial() - These are API's partially implemented in |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 866 | * TF-A and firmware both. |
| 867 | * @api_id: API ID to check. |
| 868 | * @version: Returned supported API version. |
| 869 | * |
| 870 | * Return: Returns status, either success or error+reason. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 871 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 872 | */ |
| 873 | static enum pm_ret_status feature_check_partial(uint32_t api_id, |
| 874 | uint32_t *version) |
| 875 | { |
| 876 | uint32_t status; |
| 877 | |
| 878 | switch (api_id) { |
| 879 | case PM_SELF_SUSPEND: |
| 880 | case PM_REQ_WAKEUP: |
| 881 | case PM_ABORT_SUSPEND: |
| 882 | case PM_SET_WAKEUP_SOURCE: |
| 883 | case PM_SYSTEM_SHUTDOWN: |
| 884 | case PM_GET_API_VERSION: |
| 885 | case PM_CLOCK_ENABLE: |
| 886 | case PM_CLOCK_DISABLE: |
| 887 | case PM_CLOCK_GETSTATE: |
| 888 | case PM_CLOCK_SETDIVIDER: |
| 889 | case PM_CLOCK_GETDIVIDER: |
| 890 | case PM_CLOCK_SETPARENT: |
| 891 | case PM_CLOCK_GETPARENT: |
| 892 | case PM_PLL_SET_PARAMETER: |
| 893 | case PM_PLL_GET_PARAMETER: |
| 894 | case PM_PLL_SET_MODE: |
| 895 | case PM_PLL_GET_MODE: |
| 896 | case PM_REGISTER_ACCESS: |
| 897 | case PM_FEATURE_CHECK: |
| 898 | status = check_api_dependency(api_id); |
| 899 | if (status != PM_RET_SUCCESS) { |
| 900 | return status; |
| 901 | } |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 902 | return get_tfa_version_for_partial_apis(api_id, version); |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 903 | default: |
| 904 | return PM_RET_ERROR_NO_FEATURE; |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 909 | * pm_feature_check() - Returns the supported API version if supported. |
| 910 | * @api_id: API ID to check. |
| 911 | * @version: Returned supported API version. |
| 912 | * @bit_mask: Returned supported IOCTL id version. |
| 913 | * @len: Number of bytes to be returned in bit_mask variable. |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 914 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 915 | * Return: Returns status, either success or error+reason. |
| 916 | * |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 917 | */ |
| 918 | enum pm_ret_status pm_feature_check(uint32_t api_id, uint32_t *version, |
| 919 | uint32_t *bit_mask, uint8_t len) |
| 920 | { |
| 921 | uint32_t ret_payload[PAYLOAD_ARG_CNT] = {0U}; |
| 922 | uint32_t status; |
| 923 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 924 | /* Get API version implemented in TF-A */ |
| 925 | status = feature_check_tfa(api_id, version, bit_mask); |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 926 | if (status != PM_RET_ERROR_NO_FEATURE) { |
| 927 | return status; |
| 928 | } |
| 929 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 930 | /* Get API version implemented by firmware and TF-A both */ |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 931 | status = feature_check_partial(api_id, version); |
| 932 | if (status != PM_RET_ERROR_NO_FEATURE) { |
| 933 | return status; |
| 934 | } |
| 935 | |
| 936 | /* Get API version implemented by firmware */ |
| 937 | status = fw_api_version(api_id, ret_payload, 3); |
| 938 | /* IOCTL call may return failure whose ID is not implemented in |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 939 | * firmware but implemented in TF-A |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 940 | */ |
| 941 | if ((api_id != PM_IOCTL) && (status != PM_RET_SUCCESS)) { |
| 942 | return status; |
| 943 | } |
| 944 | |
| 945 | *version = ret_payload[0]; |
| 946 | |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 947 | /* Update IOCTL bit mask which are implemented in TF-A */ |
Ronak Jain | c443e80 | 2023-02-22 04:28:02 -0800 | [diff] [blame] | 948 | if ((api_id == PM_IOCTL) || (api_id == PM_GET_OP_CHARACTERISTIC)) { |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 949 | if (len < 2) { |
| 950 | return PM_RET_ERROR_ARGS; |
| 951 | } |
| 952 | bit_mask[0] = ret_payload[1]; |
| 953 | bit_mask[1] = ret_payload[2]; |
Ronak Jain | c443e80 | 2023-02-22 04:28:02 -0800 | [diff] [blame] | 954 | if (api_id == PM_IOCTL) { |
Prasad Kummari | e078311 | 2023-04-26 11:02:07 +0530 | [diff] [blame] | 955 | /* Get IOCTL's implemented by TF-A */ |
| 956 | status = tfa_ioctl_bitmask(bit_mask); |
Ronak Jain | c443e80 | 2023-02-22 04:28:02 -0800 | [diff] [blame] | 957 | } |
Ronak Jain | 325bad1 | 2021-12-21 01:39:59 -0800 | [diff] [blame] | 958 | } else { |
| 959 | /* Requires for MISRA */ |
| 960 | } |
| 961 | |
| 962 | return status; |
| 963 | } |
| 964 | |
| 965 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 966 | * pm_clock_get_max_divisor - PM call to get max divisor. |
| 967 | * @clock_id: Clock ID. |
| 968 | * @div_type: Divisor ID (TYPE_DIV1 or TYPE_DIV2). |
| 969 | * @max_div: Maximum supported divisor. |
Rajan Vaja | b34deca | 2019-03-20 01:13:21 +0530 | [diff] [blame] | 970 | * |
| 971 | * This function is used by master to get maximum supported value. |
| 972 | * |
| 973 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 974 | * |
Rajan Vaja | b34deca | 2019-03-20 01:13:21 +0530 | [diff] [blame] | 975 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 976 | static enum pm_ret_status pm_clock_get_max_divisor(uint32_t clock_id, |
Rajan Vaja | b34deca | 2019-03-20 01:13:21 +0530 | [diff] [blame] | 977 | uint8_t div_type, |
| 978 | uint32_t *max_div) |
| 979 | { |
| 980 | return pm_api_clock_get_max_divisor(clock_id, div_type, max_div); |
| 981 | } |
| 982 | |
| 983 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 984 | * pm_clock_get_num_clocks - PM call to request number of clocks. |
| 985 | * @nclocks: Number of clocks. |
Rajan Vaja | da95940 | 2018-07-20 03:16:27 -0700 | [diff] [blame] | 986 | * |
| 987 | * This function is used by master to get number of clocks. |
| 988 | * |
| 989 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 990 | * |
Rajan Vaja | da95940 | 2018-07-20 03:16:27 -0700 | [diff] [blame] | 991 | */ |
| 992 | static enum pm_ret_status pm_clock_get_num_clocks(uint32_t *nclocks) |
| 993 | { |
| 994 | return pm_api_clock_get_num_clocks(nclocks); |
| 995 | } |
| 996 | |
| 997 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 998 | * pm_clock_get_name() - PM call to request a clock's name. |
| 999 | * @clock_id: Clock ID. |
| 1000 | * @name: Name of clock (max 16 bytes). |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1001 | * |
| 1002 | * This function is used by master to get nmae of clock specified |
| 1003 | * by given clock ID. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1004 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1005 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1006 | static void pm_clock_get_name(uint32_t clock_id, char *name) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1007 | { |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1008 | pm_api_clock_get_name(clock_id, name); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1012 | * pm_clock_get_topology() - PM call to request a clock's topology. |
| 1013 | * @clock_id: Clock ID. |
| 1014 | * @index: Topology index for next toplogy node. |
| 1015 | * @topology: Buffer to store nodes in topology and flags. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1016 | * |
| 1017 | * This function is used by master to get topology information for the |
| 1018 | * clock specified by given clock ID. Each response would return 3 |
| 1019 | * topology nodes. To get next nodes, caller needs to call this API with |
| 1020 | * index of next node. Index starts from 0. |
| 1021 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1022 | * Return: Returns status, either success or error+reason. |
| 1023 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1024 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1025 | static enum pm_ret_status pm_clock_get_topology(uint32_t clock_id, |
| 1026 | uint32_t index, |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1027 | uint32_t *topology) |
| 1028 | { |
| 1029 | return pm_api_clock_get_topology(clock_id, index, topology); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * pm_clock_get_fixedfactor_params() - PM call to request a clock's fixed factor |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1034 | * parameters for fixed clock. |
| 1035 | * @clock_id: Clock ID. |
| 1036 | * @mul: Multiplication value. |
| 1037 | * @div: Divisor value. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1038 | * |
| 1039 | * This function is used by master to get fixed factor parameers for the |
| 1040 | * fixed clock. This API is application only for the fixed clock. |
| 1041 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1042 | * Return: Returns status, either success or error+reason. |
| 1043 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1044 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1045 | static enum pm_ret_status pm_clock_get_fixedfactor_params(uint32_t clock_id, |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1046 | uint32_t *mul, |
| 1047 | uint32_t *div) |
| 1048 | { |
| 1049 | return pm_api_clock_get_fixedfactor_params(clock_id, mul, div); |
| 1050 | } |
| 1051 | |
| 1052 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1053 | * pm_clock_get_parents() - PM call to request a clock's first 3 parents. |
| 1054 | * @clock_id: Clock ID. |
| 1055 | * @index: Index of next parent. |
| 1056 | * @parents: Parents of the given clock. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1057 | * |
| 1058 | * This function is used by master to get clock's parents information. |
| 1059 | * This API will return 3 parents with a single response. To get other |
| 1060 | * parents, master should call same API in loop with new parent index |
| 1061 | * till error is returned. |
| 1062 | * |
| 1063 | * E.g First call should have index 0 which will return parents 0, 1 and |
| 1064 | * 2. Next call, index should be 3 which will return parent 3,4 and 5 and |
| 1065 | * so on. |
| 1066 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1067 | * Return: Returns status, either success or error+reason. |
| 1068 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1069 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1070 | static enum pm_ret_status pm_clock_get_parents(uint32_t clock_id, |
| 1071 | uint32_t index, |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1072 | uint32_t *parents) |
| 1073 | { |
| 1074 | return pm_api_clock_get_parents(clock_id, index, parents); |
| 1075 | } |
| 1076 | |
| 1077 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1078 | * pm_clock_get_attributes() - PM call to request a clock's attributes. |
| 1079 | * @clock_id: Clock ID. |
| 1080 | * @attr: Clock attributes. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1081 | * |
| 1082 | * This function is used by master to get clock's attributes |
| 1083 | * (e.g. valid, clock type, etc). |
| 1084 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1085 | * Return: Returns status, either success or error+reason. |
| 1086 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1087 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1088 | static enum pm_ret_status pm_clock_get_attributes(uint32_t clock_id, |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1089 | uint32_t *attr) |
| 1090 | { |
| 1091 | return pm_api_clock_get_attributes(clock_id, attr); |
| 1092 | } |
| 1093 | |
| 1094 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1095 | * pm_clock_gate() - Configure clock gate. |
| 1096 | * @clock_id: Id of the clock to be configured. |
| 1097 | * @enable: Flag 0=disable (gate the clock), !0=enable (activate the clock). |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1098 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1099 | * Return: Error if an argument is not valid or status as returned by the |
| 1100 | * PM controller (PMU). |
| 1101 | * |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1102 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1103 | static enum pm_ret_status pm_clock_gate(uint32_t clock_id, |
| 1104 | uint8_t enable) |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1105 | { |
| 1106 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1107 | enum pm_ret_status status; |
| 1108 | enum pm_api_id api_id; |
| 1109 | |
| 1110 | /* Check if clock ID is valid and return an error if it is not */ |
| 1111 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1112 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1113 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1114 | } |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1115 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1116 | if (enable) { |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1117 | api_id = PM_CLOCK_ENABLE; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1118 | } else { |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1119 | api_id = PM_CLOCK_DISABLE; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1120 | } |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1121 | |
| 1122 | /* Send request to the PMU */ |
| 1123 | PM_PACK_PAYLOAD2(payload, api_id, clock_id); |
Mirela Simonovic | 64514a7 | 2018-08-24 17:09:07 +0200 | [diff] [blame] | 1124 | status = pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1125 | |
| 1126 | /* If action fails due to the lack of permissions filter the error */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1127 | if (status == PM_RET_ERROR_ACCESS) { |
Mirela Simonovic | 64514a7 | 2018-08-24 17:09:07 +0200 | [diff] [blame] | 1128 | status = PM_RET_SUCCESS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1129 | } |
Mirela Simonovic | 64514a7 | 2018-08-24 17:09:07 +0200 | [diff] [blame] | 1130 | |
| 1131 | return status; |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1135 | * pm_clock_enable() - Enable the clock for given id. |
| 1136 | * @clock_id: Id of the clock to be enabled. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1137 | * |
| 1138 | * This function is used by master to enable the clock |
| 1139 | * including peripherals and PLL clocks. |
| 1140 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1141 | * Return: Error if an argument is not valid or status as returned by the |
| 1142 | * pm_clock_gate. |
| 1143 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1144 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1145 | enum pm_ret_status pm_clock_enable(uint32_t clock_id) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1146 | { |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1147 | struct pm_pll *pll; |
| 1148 | |
| 1149 | /* First try to handle it as a PLL */ |
| 1150 | pll = pm_clock_get_pll(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1151 | if (pll) { |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1152 | return pm_clock_pll_enable(pll); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1153 | } |
Jolly Shah | a520980 | 2019-01-04 11:45:59 -0800 | [diff] [blame] | 1154 | |
| 1155 | /* It's an on-chip clock, PMU should configure clock's gate */ |
| 1156 | return pm_clock_gate(clock_id, 1); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1160 | * pm_clock_disable - Disable the clock for given id. |
| 1161 | * @clock_id: Id of the clock to be disable. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1162 | * |
| 1163 | * This function is used by master to disable the clock |
| 1164 | * including peripherals and PLL clocks. |
| 1165 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1166 | * Return: Error if an argument is not valid or status as returned by the |
| 1167 | * pm_clock_gate |
| 1168 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1169 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1170 | enum pm_ret_status pm_clock_disable(uint32_t clock_id) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1171 | { |
Jolly Shah | a9057a0 | 2019-01-02 12:54:40 -0800 | [diff] [blame] | 1172 | struct pm_pll *pll; |
| 1173 | |
| 1174 | /* First try to handle it as a PLL */ |
| 1175 | pll = pm_clock_get_pll(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1176 | if (pll) { |
Jolly Shah | a9057a0 | 2019-01-02 12:54:40 -0800 | [diff] [blame] | 1177 | return pm_clock_pll_disable(pll); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1178 | } |
Jolly Shah | a9057a0 | 2019-01-02 12:54:40 -0800 | [diff] [blame] | 1179 | |
| 1180 | /* It's an on-chip clock, PMU should configure clock's gate */ |
| 1181 | return pm_clock_gate(clock_id, 0); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1185 | * pm_clock_getstate - Get the clock state for given id. |
| 1186 | * @clock_id: Id of the clock to be queried. |
| 1187 | * @state: 1/0 (Enabled/Disabled). |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1188 | * |
| 1189 | * This function is used by master to get the state of clock |
| 1190 | * including peripherals and PLL clocks. |
| 1191 | * |
| 1192 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1193 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1194 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1195 | enum pm_ret_status pm_clock_getstate(uint32_t clock_id, |
| 1196 | uint32_t *state) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1197 | { |
Jolly Shah | 99e8ac9 | 2019-01-02 12:55:41 -0800 | [diff] [blame] | 1198 | struct pm_pll *pll; |
| 1199 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1200 | enum pm_ret_status status; |
| 1201 | |
| 1202 | /* First try to handle it as a PLL */ |
| 1203 | pll = pm_clock_get_pll(clock_id); |
| 1204 | if (pll) |
| 1205 | return pm_clock_pll_get_state(pll, state); |
| 1206 | |
| 1207 | /* Check if clock ID is a valid on-chip clock */ |
| 1208 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1209 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 99e8ac9 | 2019-01-02 12:55:41 -0800 | [diff] [blame] | 1210 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1211 | } |
Jolly Shah | 99e8ac9 | 2019-01-02 12:55:41 -0800 | [diff] [blame] | 1212 | |
| 1213 | /* Send request to the PMU */ |
| 1214 | PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETSTATE, clock_id); |
| 1215 | return pm_ipi_send_sync(primary_proc, payload, state, 1); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1219 | * pm_clock_setdivider - Set the clock divider for given id. |
| 1220 | * @clock_id: Id of the clock. |
| 1221 | * @divider: divider value. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1222 | * |
| 1223 | * This function is used by master to set divider for any clock |
| 1224 | * to achieve desired rate. |
| 1225 | * |
| 1226 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1227 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1228 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1229 | enum pm_ret_status pm_clock_setdivider(uint32_t clock_id, |
| 1230 | uint32_t divider) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1231 | { |
Jolly Shah | 8b4c4c7 | 2019-01-04 11:49:46 -0800 | [diff] [blame] | 1232 | enum pm_ret_status status; |
| 1233 | enum pm_node_id nid; |
| 1234 | enum pm_clock_div_id div_id; |
| 1235 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1236 | const uint32_t div0 = 0xFFFF0000; |
| 1237 | const uint32_t div1 = 0x0000FFFF; |
| 1238 | uint32_t val; |
| 1239 | |
| 1240 | /* Get PLL node ID using PLL clock ID */ |
| 1241 | status = pm_clock_get_pll_node_id(clock_id, &nid); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1242 | if (status == PM_RET_SUCCESS) { |
Jolly Shah | 8b4c4c7 | 2019-01-04 11:49:46 -0800 | [diff] [blame] | 1243 | return pm_pll_set_parameter(nid, PM_PLL_PARAM_FBDIV, divider); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1244 | } |
Jolly Shah | 8b4c4c7 | 2019-01-04 11:49:46 -0800 | [diff] [blame] | 1245 | |
| 1246 | /* Check if clock ID is a valid on-chip clock */ |
| 1247 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1248 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 8b4c4c7 | 2019-01-04 11:49:46 -0800 | [diff] [blame] | 1249 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1250 | } |
Jolly Shah | 8b4c4c7 | 2019-01-04 11:49:46 -0800 | [diff] [blame] | 1251 | |
| 1252 | if (div0 == (divider & div0)) { |
| 1253 | div_id = PM_CLOCK_DIV0_ID; |
| 1254 | val = divider & ~div0; |
| 1255 | } else if (div1 == (divider & div1)) { |
| 1256 | div_id = PM_CLOCK_DIV1_ID; |
| 1257 | val = (divider & ~div1) >> 16; |
| 1258 | } else { |
| 1259 | return PM_RET_ERROR_ARGS; |
| 1260 | } |
| 1261 | |
| 1262 | /* Send request to the PMU */ |
| 1263 | PM_PACK_PAYLOAD4(payload, PM_CLOCK_SETDIVIDER, clock_id, div_id, val); |
| 1264 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
| 1267 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1268 | * pm_clock_getdivider - Get the clock divider for given id. |
| 1269 | * @clock_id: Id of the clock. |
| 1270 | * @divider: divider value. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1271 | * |
| 1272 | * This function is used by master to get divider values |
| 1273 | * for any clock. |
| 1274 | * |
| 1275 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1276 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1277 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1278 | enum pm_ret_status pm_clock_getdivider(uint32_t clock_id, |
| 1279 | uint32_t *divider) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1280 | { |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1281 | enum pm_ret_status status; |
| 1282 | enum pm_node_id nid; |
| 1283 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1284 | uint32_t val; |
| 1285 | |
| 1286 | /* Get PLL node ID using PLL clock ID */ |
| 1287 | status = pm_clock_get_pll_node_id(clock_id, &nid); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1288 | if (status == PM_RET_SUCCESS) { |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1289 | return pm_pll_get_parameter(nid, PM_PLL_PARAM_FBDIV, divider); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1290 | } |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1291 | |
| 1292 | /* Check if clock ID is a valid on-chip clock */ |
| 1293 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1294 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1295 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1296 | } |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1297 | |
| 1298 | if (pm_clock_has_div(clock_id, PM_CLOCK_DIV0_ID)) { |
| 1299 | /* Send request to the PMU to get div0 */ |
| 1300 | PM_PACK_PAYLOAD3(payload, PM_CLOCK_GETDIVIDER, clock_id, |
| 1301 | PM_CLOCK_DIV0_ID); |
| 1302 | status = pm_ipi_send_sync(primary_proc, payload, &val, 1); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1303 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1304 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1305 | } |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1306 | *divider = val; |
| 1307 | } |
| 1308 | |
| 1309 | if (pm_clock_has_div(clock_id, PM_CLOCK_DIV1_ID)) { |
| 1310 | /* Send request to the PMU to get div1 */ |
| 1311 | PM_PACK_PAYLOAD3(payload, PM_CLOCK_GETDIVIDER, clock_id, |
| 1312 | PM_CLOCK_DIV1_ID); |
| 1313 | status = pm_ipi_send_sync(primary_proc, payload, &val, 1); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1314 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1315 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1316 | } |
Jolly Shah | 4dd1176 | 2019-01-04 11:53:37 -0800 | [diff] [blame] | 1317 | *divider |= val << 16; |
| 1318 | } |
| 1319 | |
| 1320 | return status; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1324 | * pm_clock_setparent - Set the clock parent for given id. |
| 1325 | * @clock_id: Id of the clock. |
| 1326 | * @parent_index: Index of the parent clock into clock's parents array. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1327 | * |
| 1328 | * This function is used by master to set parent for any clock. |
| 1329 | * |
| 1330 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1331 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1332 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1333 | enum pm_ret_status pm_clock_setparent(uint32_t clock_id, |
| 1334 | uint32_t parent_index) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1335 | { |
Jolly Shah | 407fc0a | 2019-01-04 11:57:40 -0800 | [diff] [blame] | 1336 | struct pm_pll *pll; |
| 1337 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1338 | enum pm_ret_status status; |
| 1339 | |
| 1340 | /* First try to handle it as a PLL */ |
| 1341 | pll = pm_clock_get_pll_by_related_clk(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1342 | if (pll) { |
Jolly Shah | 407fc0a | 2019-01-04 11:57:40 -0800 | [diff] [blame] | 1343 | return pm_clock_pll_set_parent(pll, clock_id, parent_index); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1344 | } |
Jolly Shah | 407fc0a | 2019-01-04 11:57:40 -0800 | [diff] [blame] | 1345 | |
| 1346 | /* Check if clock ID is a valid on-chip clock */ |
| 1347 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1348 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 407fc0a | 2019-01-04 11:57:40 -0800 | [diff] [blame] | 1349 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1350 | } |
Jolly Shah | 407fc0a | 2019-01-04 11:57:40 -0800 | [diff] [blame] | 1351 | |
| 1352 | /* Send request to the PMU */ |
| 1353 | PM_PACK_PAYLOAD3(payload, PM_CLOCK_SETPARENT, clock_id, parent_index); |
| 1354 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1358 | * pm_clock_getparent - Get the clock parent for given id. |
| 1359 | * @clock_id: Id of the clock. |
| 1360 | * @parent_index: parent index. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1361 | * |
| 1362 | * This function is used by master to get parent index |
| 1363 | * for any clock. |
| 1364 | * |
| 1365 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1366 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1367 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1368 | enum pm_ret_status pm_clock_getparent(uint32_t clock_id, |
| 1369 | uint32_t *parent_index) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1370 | { |
Jolly Shah | 7c8e79c | 2019-01-02 13:44:25 -0800 | [diff] [blame] | 1371 | struct pm_pll *pll; |
| 1372 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1373 | enum pm_ret_status status; |
| 1374 | |
| 1375 | /* First try to handle it as a PLL */ |
| 1376 | pll = pm_clock_get_pll_by_related_clk(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1377 | if (pll) { |
Jolly Shah | 7c8e79c | 2019-01-02 13:44:25 -0800 | [diff] [blame] | 1378 | return pm_clock_pll_get_parent(pll, clock_id, parent_index); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1379 | } |
Jolly Shah | 7c8e79c | 2019-01-02 13:44:25 -0800 | [diff] [blame] | 1380 | |
| 1381 | /* Check if clock ID is a valid on-chip clock */ |
| 1382 | status = pm_clock_id_is_valid(clock_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1383 | if (status != PM_RET_SUCCESS) { |
Jolly Shah | 7c8e79c | 2019-01-02 13:44:25 -0800 | [diff] [blame] | 1384 | return status; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1385 | } |
Jolly Shah | 7c8e79c | 2019-01-02 13:44:25 -0800 | [diff] [blame] | 1386 | |
| 1387 | /* Send request to the PMU */ |
| 1388 | PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETPARENT, clock_id); |
| 1389 | return pm_ipi_send_sync(primary_proc, payload, parent_index, 1); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1393 | * pm_pinctrl_get_num_pins - PM call to request number of pins. |
| 1394 | * @npins: Number of pins. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1395 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1396 | * This function is used by master to get number of pins. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1397 | * |
| 1398 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1399 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1400 | */ |
| 1401 | static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins) |
| 1402 | { |
| 1403 | return pm_api_pinctrl_get_num_pins(npins); |
| 1404 | } |
| 1405 | |
| 1406 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1407 | * pm_pinctrl_get_num_functions - PM call to request number of functions. |
| 1408 | * @nfuncs: Number of functions. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1409 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1410 | * This function is used by master to get number of functions. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1411 | * |
| 1412 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1413 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1414 | */ |
| 1415 | static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs) |
| 1416 | { |
| 1417 | return pm_api_pinctrl_get_num_functions(nfuncs); |
| 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * pm_pinctrl_get_num_function_groups - PM call to request number of |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1422 | * function groups. |
| 1423 | * @fid: Id of function. |
| 1424 | * @ngroups: Number of function groups. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1425 | * |
| 1426 | * This function is used by master to get number of function groups specified |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1427 | * by given function Id. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1428 | * |
| 1429 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1430 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1431 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1432 | static enum pm_ret_status pm_pinctrl_get_num_function_groups(uint32_t fid, |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1433 | uint32_t *ngroups) |
| 1434 | { |
| 1435 | return pm_api_pinctrl_get_num_func_groups(fid, ngroups); |
| 1436 | } |
| 1437 | |
| 1438 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1439 | * pm_pinctrl_get_function_name - PM call to request function name. |
| 1440 | * @fid: Id of function. |
| 1441 | * @name: Name of function. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1442 | * |
| 1443 | * This function is used by master to get name of function specified |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1444 | * by given function Id. |
| 1445 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1446 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1447 | static void pm_pinctrl_get_function_name(uint32_t fid, char *name) |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1448 | { |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1449 | pm_api_pinctrl_get_function_name(fid, name); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1453 | * pm_pinctrl_get_function_groups - PM call to request function groups. |
| 1454 | * @fid: Id of function. |
| 1455 | * @index: Index of next function groups. |
| 1456 | * @groups: Function groups. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1457 | * |
| 1458 | * This function is used by master to get function groups specified |
| 1459 | * by given function Id. This API will return 6 function groups with |
| 1460 | * a single response. To get other function groups, master should call |
| 1461 | * same API in loop with new function groups index till error is returned. |
| 1462 | * |
| 1463 | * E.g First call should have index 0 which will return function groups |
| 1464 | * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return |
| 1465 | * function groups 6, 7, 8, 9, 10 and 11 and so on. |
| 1466 | * |
| 1467 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1468 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1469 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1470 | static enum pm_ret_status pm_pinctrl_get_function_groups(uint32_t fid, |
| 1471 | uint32_t index, |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1472 | uint16_t *groups) |
| 1473 | { |
| 1474 | return pm_api_pinctrl_get_function_groups(fid, index, groups); |
| 1475 | } |
| 1476 | |
| 1477 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1478 | * pm_pinctrl_get_pin_groups - PM call to request pin groups. |
| 1479 | * @pin_id: Id of pin. |
| 1480 | * @index: Index of next pin groups. |
| 1481 | * @groups: pin groups. |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1482 | * |
| 1483 | * This function is used by master to get pin groups specified |
| 1484 | * by given pin Id. This API will return 6 pin groups with |
| 1485 | * a single response. To get other pin groups, master should call |
| 1486 | * same API in loop with new pin groups index till error is returned. |
| 1487 | * |
| 1488 | * E.g First call should have index 0 which will return pin groups |
| 1489 | * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return |
| 1490 | * pin groups 6, 7, 8, 9, 10 and 11 and so on. |
| 1491 | * |
| 1492 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1493 | * |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1494 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1495 | static enum pm_ret_status pm_pinctrl_get_pin_groups(uint32_t pin_id, |
| 1496 | uint32_t index, |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1497 | uint16_t *groups) |
| 1498 | { |
| 1499 | return pm_api_pinctrl_get_pin_groups(pin_id, index, groups); |
| 1500 | } |
| 1501 | |
| 1502 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1503 | * pm_query_data() - PM API for querying firmware data. |
| 1504 | * @qid: represents the query identifiers for PM. |
| 1505 | * @arg1: Argument 1 to requested IOCTL call. |
| 1506 | * @arg2: Argument 2 to requested IOCTL call. |
| 1507 | * @arg3: Argument 3 to requested IOCTL call. |
| 1508 | * @data: Returned output data. |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1509 | * |
| 1510 | * This function returns requested data. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1511 | * |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1512 | */ |
Jay Buddhabhatti | 5b9f391 | 2023-02-02 22:34:03 -0800 | [diff] [blame] | 1513 | void pm_query_data(enum pm_query_ids qid, uint32_t arg1, uint32_t arg2, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1514 | uint32_t arg3, uint32_t *data) |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1515 | { |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1516 | switch (qid) { |
| 1517 | case PM_QID_CLOCK_GET_NAME: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1518 | pm_clock_get_name(arg1, (char *)data); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1519 | break; |
| 1520 | case PM_QID_CLOCK_GET_TOPOLOGY: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1521 | data[0] = pm_clock_get_topology(arg1, arg2, &data[1]); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1522 | break; |
| 1523 | case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1524 | data[0] = pm_clock_get_fixedfactor_params(arg1, &data[1], |
| 1525 | &data[2]); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1526 | break; |
| 1527 | case PM_QID_CLOCK_GET_PARENTS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1528 | data[0] = pm_clock_get_parents(arg1, arg2, &data[1]); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1529 | break; |
| 1530 | case PM_QID_CLOCK_GET_ATTRIBUTES: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1531 | data[0] = pm_clock_get_attributes(arg1, &data[1]); |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1532 | break; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1533 | case PM_QID_PINCTRL_GET_NUM_PINS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1534 | data[0] = pm_pinctrl_get_num_pins(&data[1]); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1535 | break; |
| 1536 | case PM_QID_PINCTRL_GET_NUM_FUNCTIONS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1537 | data[0] = pm_pinctrl_get_num_functions(&data[1]); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1538 | break; |
| 1539 | case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1540 | data[0] = pm_pinctrl_get_num_function_groups(arg1, &data[1]); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1541 | break; |
| 1542 | case PM_QID_PINCTRL_GET_FUNCTION_NAME: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1543 | pm_pinctrl_get_function_name(arg1, (char *)data); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1544 | break; |
| 1545 | case PM_QID_PINCTRL_GET_FUNCTION_GROUPS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1546 | data[0] = pm_pinctrl_get_function_groups(arg1, arg2, |
| 1547 | (uint16_t *)&data[1]); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1548 | break; |
| 1549 | case PM_QID_PINCTRL_GET_PIN_GROUPS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1550 | data[0] = pm_pinctrl_get_pin_groups(arg1, arg2, |
| 1551 | (uint16_t *)&data[1]); |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1552 | break; |
Rajan Vaja | da95940 | 2018-07-20 03:16:27 -0700 | [diff] [blame] | 1553 | case PM_QID_CLOCK_GET_NUM_CLOCKS: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1554 | data[0] = pm_clock_get_num_clocks(&data[1]); |
Rajan Vaja | da95940 | 2018-07-20 03:16:27 -0700 | [diff] [blame] | 1555 | break; |
Rajan Vaja | b34deca | 2019-03-20 01:13:21 +0530 | [diff] [blame] | 1556 | |
| 1557 | case PM_QID_CLOCK_GET_MAX_DIVISOR: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1558 | data[0] = pm_clock_get_max_divisor(arg1, arg2, &data[1]); |
Rajan Vaja | b34deca | 2019-03-20 01:13:21 +0530 | [diff] [blame] | 1559 | break; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1560 | default: |
Rajan Vaja | cd82568 | 2020-11-23 21:33:39 -0800 | [diff] [blame] | 1561 | data[0] = PM_RET_ERROR_ARGS; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1562 | WARN("Unimplemented query service call: 0x%x\n", qid); |
Venkatesh Yadav Abbarapu | 41886f7 | 2022-04-29 15:17:13 +0530 | [diff] [blame] | 1563 | break; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1564 | } |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1565 | } |
Siva Durga Prasad Paladugu | f3994cc | 2018-05-01 11:12:55 +0530 | [diff] [blame] | 1566 | |
| 1567 | enum pm_ret_status pm_sha_hash(uint32_t address_high, |
| 1568 | uint32_t address_low, |
| 1569 | uint32_t size, |
| 1570 | uint32_t flags) |
| 1571 | { |
| 1572 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1573 | |
| 1574 | /* Send request to the PMU */ |
| 1575 | PM_PACK_PAYLOAD5(payload, PM_SECURE_SHA, address_high, address_low, |
| 1576 | size, flags); |
| 1577 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1578 | } |
| 1579 | |
| 1580 | enum pm_ret_status pm_rsa_core(uint32_t address_high, |
| 1581 | uint32_t address_low, |
| 1582 | uint32_t size, |
| 1583 | uint32_t flags) |
| 1584 | { |
| 1585 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1586 | |
| 1587 | /* Send request to the PMU */ |
| 1588 | PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA, address_high, address_low, |
| 1589 | size, flags); |
| 1590 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1591 | } |
Siva Durga Prasad Paladugu | a4ed4b2 | 2018-04-30 20:06:58 +0530 | [diff] [blame] | 1592 | |
| 1593 | enum pm_ret_status pm_secure_image(uint32_t address_low, |
| 1594 | uint32_t address_high, |
| 1595 | uint32_t key_lo, |
| 1596 | uint32_t key_hi, |
| 1597 | uint32_t *value) |
| 1598 | { |
| 1599 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1600 | |
| 1601 | /* Send request to the PMU */ |
| 1602 | PM_PACK_PAYLOAD5(payload, PM_SECURE_IMAGE, address_high, address_low, |
| 1603 | key_hi, key_lo); |
| 1604 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 1605 | } |
Siva Durga Prasad Paladugu | 7c6516a | 2018-09-04 17:41:34 +0530 | [diff] [blame] | 1606 | |
| 1607 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1608 | * pm_fpga_read - Perform the fpga configuration readback. |
| 1609 | * @reg_numframes: Configuration register offset (or) Number of frames to read. |
| 1610 | * @address_low: lower 32-bit Linear memory space address. |
| 1611 | * @address_high: higher 32-bit Linear memory space address. |
| 1612 | * @readback_type: Type of fpga readback operation. |
| 1613 | * 0 -- Configuration Register readback. |
| 1614 | * 1 -- Configuration Data readback. |
| 1615 | * @value: Value to read. |
Siva Durga Prasad Paladugu | 7c6516a | 2018-09-04 17:41:34 +0530 | [diff] [blame] | 1616 | * |
| 1617 | * This function provides access to the xilfpga library to read |
| 1618 | * the PL configuration. |
| 1619 | * |
| 1620 | * Return: Returns status, either success or error+reason. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1621 | * |
Siva Durga Prasad Paladugu | 7c6516a | 2018-09-04 17:41:34 +0530 | [diff] [blame] | 1622 | */ |
| 1623 | enum pm_ret_status pm_fpga_read(uint32_t reg_numframes, |
| 1624 | uint32_t address_low, |
| 1625 | uint32_t address_high, |
| 1626 | uint32_t readback_type, |
| 1627 | uint32_t *value) |
| 1628 | { |
| 1629 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1630 | |
| 1631 | /* Send request to the PMU */ |
| 1632 | PM_PACK_PAYLOAD5(payload, PM_FPGA_READ, reg_numframes, address_low, |
| 1633 | address_high, readback_type); |
| 1634 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 1635 | } |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1636 | |
| 1637 | /* |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1638 | * pm_pll_set_parameter() - Set the PLL parameter value. |
| 1639 | * @nid: Node id of the target PLL. |
| 1640 | * @param_id: ID of the PLL parameter. |
| 1641 | * @value: Parameter value to be set. |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1642 | * |
| 1643 | * Setting the parameter will have physical effect once the PLL mode is set to |
| 1644 | * integer or fractional. |
| 1645 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1646 | * Return: Error if an argument is not valid or status as returned by the |
| 1647 | * PM controller (PMU). |
| 1648 | * |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1649 | */ |
| 1650 | enum pm_ret_status pm_pll_set_parameter(enum pm_node_id nid, |
| 1651 | enum pm_pll_param param_id, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1652 | uint32_t value) |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1653 | { |
| 1654 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1655 | |
| 1656 | /* Check if given node ID is a PLL node */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1657 | if (nid < NODE_APLL || nid > NODE_IOPLL) { |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1658 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1659 | } |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1660 | |
| 1661 | /* Check if parameter ID is valid and return an error if it's not */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1662 | if (param_id >= PM_PLL_PARAM_MAX) { |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1663 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1664 | } |
Jolly Shah | a7cc5ee | 2019-01-02 12:27:00 -0800 | [diff] [blame] | 1665 | |
| 1666 | /* Send request to the PMU */ |
| 1667 | PM_PACK_PAYLOAD4(payload, PM_PLL_SET_PARAMETER, nid, param_id, value); |
| 1668 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1669 | } |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1670 | |
| 1671 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1672 | * pm_pll_get_parameter() - Get the PLL parameter value. |
| 1673 | * @nid: Node id of the target PLL. |
| 1674 | * @param_id: ID of the PLL parameter. |
| 1675 | * @value: Location to store the parameter value. |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1676 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1677 | * Return: Error if an argument is not valid or status as returned by the |
| 1678 | * PM controller (PMU). |
| 1679 | * |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1680 | */ |
| 1681 | enum pm_ret_status pm_pll_get_parameter(enum pm_node_id nid, |
| 1682 | enum pm_pll_param param_id, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1683 | uint32_t *value) |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1684 | { |
| 1685 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1686 | |
| 1687 | /* Check if given node ID is a PLL node */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1688 | if (nid < NODE_APLL || nid > NODE_IOPLL) { |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1689 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1690 | } |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1691 | |
| 1692 | /* Check if parameter ID is valid and return an error if it's not */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1693 | if (param_id >= PM_PLL_PARAM_MAX) { |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1694 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1695 | } |
Jolly Shah | cb2f45d | 2019-01-04 11:28:38 -0800 | [diff] [blame] | 1696 | |
| 1697 | /* Send request to the PMU */ |
| 1698 | PM_PACK_PAYLOAD3(payload, PM_PLL_GET_PARAMETER, nid, param_id); |
| 1699 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 1700 | } |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1701 | |
| 1702 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1703 | * pm_pll_set_mode() - Set the PLL mode. |
| 1704 | * @nid: Node id of the target PLL. |
| 1705 | * @mode: PLL mode to be set. |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1706 | * |
| 1707 | * If reset mode is set the PM controller will first bypass the PLL and then |
| 1708 | * assert the reset. If integer or fractional mode is set the PM controller will |
| 1709 | * ensure that the complete PLL programming sequence is satisfied. After this |
| 1710 | * function returns success the PLL is locked and its bypass is deasserted. |
| 1711 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1712 | * Return: Error if an argument is not valid or status as returned by the |
| 1713 | * PM controller (PMU). |
| 1714 | * |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1715 | */ |
| 1716 | enum pm_ret_status pm_pll_set_mode(enum pm_node_id nid, enum pm_pll_mode mode) |
| 1717 | { |
| 1718 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1719 | |
| 1720 | /* Check if given node ID is a PLL node */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1721 | if (nid < NODE_APLL || nid > NODE_IOPLL) { |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1722 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1723 | } |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1724 | |
| 1725 | /* Check if PLL mode is valid */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1726 | if (mode >= PM_PLL_MODE_MAX) { |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1727 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1728 | } |
Jolly Shah | 1f0d585 | 2019-01-04 11:32:31 -0800 | [diff] [blame] | 1729 | |
| 1730 | /* Send request to the PMU */ |
| 1731 | PM_PACK_PAYLOAD3(payload, PM_PLL_SET_MODE, nid, mode); |
| 1732 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1733 | } |
Jolly Shah | 141421e | 2019-01-04 11:35:48 -0800 | [diff] [blame] | 1734 | |
| 1735 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1736 | * pm_pll_get_mode() - Get the PLL mode. |
| 1737 | * @nid: Node id of the target PLL. |
| 1738 | * @mode: Location to store the mode of the PLL. |
Jolly Shah | 141421e | 2019-01-04 11:35:48 -0800 | [diff] [blame] | 1739 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1740 | * Return: Error if an argument is not valid or status as returned by the |
| 1741 | * PM controller (PMU). |
| 1742 | * |
Jolly Shah | 141421e | 2019-01-04 11:35:48 -0800 | [diff] [blame] | 1743 | */ |
| 1744 | enum pm_ret_status pm_pll_get_mode(enum pm_node_id nid, enum pm_pll_mode *mode) |
| 1745 | { |
| 1746 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1747 | |
| 1748 | /* Check if given node ID is a PLL node */ |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1749 | if (nid < NODE_APLL || nid > NODE_IOPLL) { |
Jolly Shah | 141421e | 2019-01-04 11:35:48 -0800 | [diff] [blame] | 1750 | return PM_RET_ERROR_ARGS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1751 | } |
Jolly Shah | 141421e | 2019-01-04 11:35:48 -0800 | [diff] [blame] | 1752 | |
| 1753 | /* Send request to the PMU */ |
| 1754 | PM_PACK_PAYLOAD2(payload, PM_PLL_GET_MODE, nid); |
| 1755 | return pm_ipi_send_sync(primary_proc, payload, mode, 1); |
| 1756 | } |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1757 | |
| 1758 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1759 | * pm_register_access() - PM API for register read/write access data. |
| 1760 | * @register_access_id: Register_access_id which says register read/write. |
| 1761 | * @address: Address of the register to be accessed. |
| 1762 | * @mask: Mask value to be used while writing value. |
| 1763 | * @value: Value to be written to register. |
| 1764 | * @out: Returned output data. |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1765 | * |
| 1766 | * This function returns requested data. |
| 1767 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1768 | * Return: Returns status, either success or error+reason. |
| 1769 | * |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1770 | */ |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 1771 | enum pm_ret_status pm_register_access(uint32_t register_access_id, |
| 1772 | uint32_t address, |
| 1773 | uint32_t mask, |
| 1774 | uint32_t value, |
| 1775 | uint32_t *out) |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1776 | { |
| 1777 | enum pm_ret_status ret; |
| 1778 | |
| 1779 | if (((ZYNQMP_CSU_BASEADDR & address) != ZYNQMP_CSU_BASEADDR) && |
| 1780 | ((CSUDMA_BASE & address) != CSUDMA_BASE) && |
| 1781 | ((RSA_CORE_BASE & address) != RSA_CORE_BASE) && |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1782 | ((PMU_GLOBAL_BASE & address) != PMU_GLOBAL_BASE)) { |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1783 | return PM_RET_ERROR_ACCESS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 1784 | } |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1785 | |
| 1786 | switch (register_access_id) { |
| 1787 | case CONFIG_REG_WRITE: |
| 1788 | ret = pm_mmio_write(address, mask, value); |
| 1789 | break; |
| 1790 | case CONFIG_REG_READ: |
| 1791 | ret = pm_mmio_read(address, out); |
| 1792 | break; |
| 1793 | default: |
| 1794 | ret = PM_RET_ERROR_ARGS; |
| 1795 | WARN("Unimplemented register_access call\n\r"); |
Venkatesh Yadav Abbarapu | 41886f7 | 2022-04-29 15:17:13 +0530 | [diff] [blame] | 1796 | break; |
Kalyani Akula | 6ebe483 | 2020-11-22 22:42:10 -0800 | [diff] [blame] | 1797 | } |
| 1798 | return ret; |
| 1799 | } |
VNSL Durga | deb1a36 | 2020-11-23 04:46:04 -0800 | [diff] [blame] | 1800 | |
| 1801 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1802 | * pm_efuse_access() - To program or read efuse bits. This function provides |
| 1803 | * access to the xilskey library to program/read |
| 1804 | * efuse bits. |
| 1805 | * @address_low: lower 32-bit Linear memory space address. |
| 1806 | * @address_high: higher 32-bit Linear memory space address. |
| 1807 | * @value: Returned output value. |
VNSL Durga | deb1a36 | 2020-11-23 04:46:04 -0800 | [diff] [blame] | 1808 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame] | 1809 | * Return: Returns status, either success or error+reason. |
VNSL Durga | deb1a36 | 2020-11-23 04:46:04 -0800 | [diff] [blame] | 1810 | * |
| 1811 | */ |
| 1812 | enum pm_ret_status pm_efuse_access(uint32_t address_high, |
| 1813 | uint32_t address_low, |
| 1814 | uint32_t *value) |
| 1815 | { |
| 1816 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1817 | |
| 1818 | /* Send request to the PMU */ |
| 1819 | PM_PACK_PAYLOAD3(payload, PM_EFUSE_ACCESS, address_high, address_low); |
| 1820 | |
| 1821 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
| 1822 | } |