Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 1 | /* |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * ZynqMP system level PM-API functions and communication with PMU via |
| 9 | * IPI interrupts |
| 10 | */ |
| 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <platform.h> |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 14 | #include "pm_api_clock.h" |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 15 | #include "pm_api_ioctl.h" |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 16 | #include "pm_api_pinctrl.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 17 | #include "pm_api_sys.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 18 | #include "pm_client.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 19 | #include "pm_common.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 20 | #include "pm_ipi.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 21 | |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 22 | /* default shutdown/reboot scope is system(2) */ |
| 23 | static unsigned int pm_shutdown_scope = PMF_SHUTDOWN_SUBTYPE_SYSTEM; |
| 24 | |
| 25 | /** |
| 26 | * pm_get_shutdown_scope() - Get the currently set shutdown scope |
| 27 | * |
| 28 | * @return Shutdown scope value |
| 29 | */ |
| 30 | unsigned int pm_get_shutdown_scope(void) |
| 31 | { |
| 32 | return pm_shutdown_scope; |
| 33 | } |
| 34 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 35 | /** |
| 36 | * Assigning of argument values into array elements. |
| 37 | */ |
| 38 | #define PM_PACK_PAYLOAD1(pl, arg0) { \ |
| 39 | pl[0] = (uint32_t)(arg0); \ |
| 40 | } |
| 41 | |
| 42 | #define PM_PACK_PAYLOAD2(pl, arg0, arg1) { \ |
| 43 | pl[1] = (uint32_t)(arg1); \ |
| 44 | PM_PACK_PAYLOAD1(pl, arg0); \ |
| 45 | } |
| 46 | |
| 47 | #define PM_PACK_PAYLOAD3(pl, arg0, arg1, arg2) { \ |
| 48 | pl[2] = (uint32_t)(arg2); \ |
| 49 | PM_PACK_PAYLOAD2(pl, arg0, arg1); \ |
| 50 | } |
| 51 | |
| 52 | #define PM_PACK_PAYLOAD4(pl, arg0, arg1, arg2, arg3) { \ |
| 53 | pl[3] = (uint32_t)(arg3); \ |
| 54 | PM_PACK_PAYLOAD3(pl, arg0, arg1, arg2); \ |
| 55 | } |
| 56 | |
| 57 | #define PM_PACK_PAYLOAD5(pl, arg0, arg1, arg2, arg3, arg4) { \ |
| 58 | pl[4] = (uint32_t)(arg4); \ |
| 59 | PM_PACK_PAYLOAD4(pl, arg0, arg1, arg2, arg3); \ |
| 60 | } |
| 61 | |
| 62 | #define PM_PACK_PAYLOAD6(pl, arg0, arg1, arg2, arg3, arg4, arg5) { \ |
| 63 | pl[5] = (uint32_t)(arg5); \ |
| 64 | PM_PACK_PAYLOAD5(pl, arg0, arg1, arg2, arg3, arg4); \ |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * pm_self_suspend() - PM call for processor to suspend itself |
| 69 | * @nid Node id of the processor or subsystem |
| 70 | * @latency Requested maximum wakeup latency (not supported) |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 71 | * @state Requested state |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 72 | * @address Resume address |
| 73 | * |
| 74 | * This is a blocking call, it will return only once PMU has responded. |
| 75 | * On a wakeup, resume address will be automatically set by PMU. |
| 76 | * |
| 77 | * @return Returns status, either success or error+reason |
| 78 | */ |
| 79 | enum pm_ret_status pm_self_suspend(enum pm_node_id nid, |
| 80 | unsigned int latency, |
| 81 | unsigned int state, |
| 82 | uintptr_t address) |
| 83 | { |
| 84 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 85 | unsigned int cpuid = plat_my_core_pos(); |
| 86 | const struct pm_proc *proc = pm_get_proc(cpuid); |
| 87 | |
| 88 | /* |
| 89 | * Do client specific suspend operations |
| 90 | * (e.g. set powerdown request bit) |
| 91 | */ |
Filip Drazic | 4c0765a | 2016-07-26 12:11:33 +0200 | [diff] [blame] | 92 | pm_client_suspend(proc, state); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 93 | /* Send request to the PMU */ |
| 94 | PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency, |
| 95 | state, address, (address >> 32)); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 96 | return pm_ipi_send_sync(proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /** |
| 100 | * pm_req_suspend() - PM call to request for another PU or subsystem to |
| 101 | * be suspended gracefully. |
| 102 | * @target Node id of the targeted PU or subsystem |
| 103 | * @ack Flag to specify whether acknowledge is requested |
| 104 | * @latency Requested wakeup latency (not supported) |
| 105 | * @state Requested state (not supported) |
| 106 | * |
| 107 | * @return Returns status, either success or error+reason |
| 108 | */ |
| 109 | enum pm_ret_status pm_req_suspend(enum pm_node_id target, |
| 110 | enum pm_request_ack ack, |
| 111 | unsigned int latency, unsigned int state) |
| 112 | { |
| 113 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 114 | |
| 115 | /* Send request to the PMU */ |
| 116 | PM_PACK_PAYLOAD5(payload, PM_REQ_SUSPEND, target, ack, latency, state); |
| 117 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 118 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 119 | else |
| 120 | return pm_ipi_send(primary_proc, payload); |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * pm_req_wakeup() - PM call for processor to wake up selected processor |
| 125 | * or subsystem |
| 126 | * @target Node id of the processor or subsystem to wake up |
| 127 | * @ack Flag to specify whether acknowledge requested |
| 128 | * @set_address Resume address presence indicator |
| 129 | * 1 resume address specified, 0 otherwise |
| 130 | * @address Resume address |
| 131 | * |
| 132 | * This API function is either used to power up another APU core for SMP |
| 133 | * (by PSCI) or to power up an entirely different PU or subsystem, such |
| 134 | * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be |
| 135 | * automatically set by PMU. |
| 136 | * |
| 137 | * @return Returns status, either success or error+reason |
| 138 | */ |
| 139 | enum pm_ret_status pm_req_wakeup(enum pm_node_id target, |
| 140 | unsigned int set_address, |
| 141 | uintptr_t address, |
| 142 | enum pm_request_ack ack) |
| 143 | { |
| 144 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 145 | uint64_t encoded_address; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 146 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 147 | |
| 148 | /* encode set Address into 1st bit of address */ |
| 149 | encoded_address = address; |
| 150 | encoded_address |= !!set_address; |
| 151 | |
| 152 | /* Send request to the PMU to perform the wake of the PU */ |
| 153 | PM_PACK_PAYLOAD5(payload, PM_REQ_WAKEUP, target, encoded_address, |
| 154 | encoded_address >> 32, ack); |
| 155 | |
| 156 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 157 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 158 | else |
| 159 | return pm_ipi_send(primary_proc, payload); |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * pm_force_powerdown() - PM call to request for another PU or subsystem to |
| 164 | * be powered down forcefully |
| 165 | * @target Node id of the targeted PU or subsystem |
| 166 | * @ack Flag to specify whether acknowledge is requested |
| 167 | * |
| 168 | * @return Returns status, either success or error+reason |
| 169 | */ |
| 170 | enum pm_ret_status pm_force_powerdown(enum pm_node_id target, |
| 171 | enum pm_request_ack ack) |
| 172 | { |
| 173 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 174 | |
| 175 | /* Send request to the PMU */ |
| 176 | PM_PACK_PAYLOAD3(payload, PM_FORCE_POWERDOWN, target, ack); |
| 177 | |
| 178 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 179 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 180 | else |
| 181 | return pm_ipi_send(primary_proc, payload); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * pm_abort_suspend() - PM call to announce that a prior suspend request |
| 186 | * is to be aborted. |
| 187 | * @reason Reason for the abort |
| 188 | * |
| 189 | * Calling PU expects the PMU to abort the initiated suspend procedure. |
| 190 | * This is a non-blocking call without any acknowledge. |
| 191 | * |
| 192 | * @return Returns status, either success or error+reason |
| 193 | */ |
| 194 | enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason) |
| 195 | { |
| 196 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 197 | |
| 198 | /* |
| 199 | * Do client specific abort suspend operations |
| 200 | * (e.g. enable interrupts and clear powerdown request bit) |
| 201 | */ |
| 202 | pm_client_abort_suspend(); |
| 203 | /* Send request to the PMU */ |
| 204 | /* TODO: allow passing the node ID of the affected CPU */ |
| 205 | PM_PACK_PAYLOAD3(payload, PM_ABORT_SUSPEND, reason, |
| 206 | primary_proc->node_id); |
| 207 | return pm_ipi_send(primary_proc, payload); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended |
| 212 | * @target Node id of the targeted PU or subsystem |
| 213 | * @wkup_node Node id of the wakeup peripheral |
| 214 | * @enable Enable or disable the specified peripheral as wake source |
| 215 | * |
| 216 | * @return Returns status, either success or error+reason |
| 217 | */ |
| 218 | enum pm_ret_status pm_set_wakeup_source(enum pm_node_id target, |
| 219 | enum pm_node_id wkup_node, |
| 220 | unsigned int enable) |
| 221 | { |
| 222 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 223 | |
| 224 | PM_PACK_PAYLOAD4(payload, PM_SET_WAKEUP_SOURCE, target, wkup_node, |
| 225 | enable); |
| 226 | return pm_ipi_send(primary_proc, payload); |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * pm_system_shutdown() - PM call to request a system shutdown or restart |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 231 | * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope |
| 232 | * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 233 | * |
| 234 | * @return Returns status, either success or error+reason |
| 235 | */ |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 236 | enum pm_ret_status pm_system_shutdown(unsigned int type, unsigned int subtype) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 237 | { |
| 238 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 239 | |
Siva Durga Prasad Paladugu | 1f80d3f | 2018-04-30 15:56:10 +0530 | [diff] [blame] | 240 | if (type == PMF_SHUTDOWN_TYPE_SETSCOPE_ONLY) { |
| 241 | /* Setting scope for subsequent PSCI reboot or shutdown */ |
| 242 | pm_shutdown_scope = subtype; |
| 243 | return PM_RET_SUCCESS; |
| 244 | } |
| 245 | |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 246 | PM_PACK_PAYLOAD3(payload, PM_SYSTEM_SHUTDOWN, type, subtype); |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 247 | return pm_ipi_send_non_blocking(primary_proc, payload); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* APIs for managing PM slaves: */ |
| 251 | |
| 252 | /** |
| 253 | * pm_req_node() - PM call to request a node with specific capabilities |
| 254 | * @nid Node id of the slave |
| 255 | * @capabilities Requested capabilities of the slave |
| 256 | * @qos Quality of service (not supported) |
| 257 | * @ack Flag to specify whether acknowledge is requested |
| 258 | * |
| 259 | * @return Returns status, either success or error+reason |
| 260 | */ |
| 261 | enum pm_ret_status pm_req_node(enum pm_node_id nid, |
| 262 | unsigned int capabilities, |
| 263 | unsigned int qos, |
| 264 | enum pm_request_ack ack) |
| 265 | { |
| 266 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 267 | |
| 268 | PM_PACK_PAYLOAD5(payload, PM_REQ_NODE, nid, capabilities, qos, ack); |
| 269 | |
| 270 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 271 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 272 | else |
| 273 | return pm_ipi_send(primary_proc, payload); |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * pm_set_requirement() - PM call to set requirement for PM slaves |
| 278 | * @nid Node id of the slave |
| 279 | * @capabilities Requested capabilities of the slave |
| 280 | * @qos Quality of service (not supported) |
| 281 | * @ack Flag to specify whether acknowledge is requested |
| 282 | * |
| 283 | * This API function is to be used for slaves a PU already has requested |
| 284 | * |
| 285 | * @return Returns status, either success or error+reason |
| 286 | */ |
| 287 | enum pm_ret_status pm_set_requirement(enum pm_node_id nid, |
| 288 | unsigned int capabilities, |
| 289 | unsigned int qos, |
| 290 | enum pm_request_ack ack) |
| 291 | { |
| 292 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 293 | |
| 294 | PM_PACK_PAYLOAD5(payload, PM_SET_REQUIREMENT, nid, capabilities, qos, |
| 295 | ack); |
| 296 | |
| 297 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 298 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 299 | else |
| 300 | return pm_ipi_send(primary_proc, payload); |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * pm_release_node() - PM call to release a node |
| 305 | * @nid Node id of the slave |
| 306 | * |
| 307 | * @return Returns status, either success or error+reason |
| 308 | */ |
| 309 | enum pm_ret_status pm_release_node(enum pm_node_id nid) |
| 310 | { |
| 311 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 312 | |
| 313 | PM_PACK_PAYLOAD2(payload, PM_RELEASE_NODE, nid); |
| 314 | return pm_ipi_send(primary_proc, payload); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * pm_set_max_latency() - PM call to set wakeup latency requirements |
| 319 | * @nid Node id of the slave |
| 320 | * @latency Requested maximum wakeup latency |
| 321 | * |
| 322 | * @return Returns status, either success or error+reason |
| 323 | */ |
| 324 | enum pm_ret_status pm_set_max_latency(enum pm_node_id nid, |
| 325 | unsigned int latency) |
| 326 | { |
| 327 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 328 | |
| 329 | PM_PACK_PAYLOAD3(payload, PM_SET_MAX_LATENCY, nid, latency); |
| 330 | return pm_ipi_send(primary_proc, payload); |
| 331 | } |
| 332 | |
| 333 | /* Miscellaneous API functions */ |
| 334 | |
| 335 | /** |
| 336 | * pm_get_api_version() - Get version number of PMU PM firmware |
| 337 | * @version Returns 32-bit version number of PMU Power Management Firmware |
| 338 | * |
| 339 | * @return Returns status, either success or error+reason |
| 340 | */ |
| 341 | enum pm_ret_status pm_get_api_version(unsigned int *version) |
| 342 | { |
| 343 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 344 | |
| 345 | /* Send request to the PMU */ |
| 346 | PM_PACK_PAYLOAD1(payload, PM_GET_API_VERSION); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 347 | return pm_ipi_send_sync(primary_proc, payload, version, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /** |
| 351 | * pm_set_configuration() - PM call to set system configuration |
| 352 | * @phys_addr Physical 32-bit address of data structure in memory |
| 353 | * |
| 354 | * @return Returns status, either success or error+reason |
| 355 | */ |
| 356 | enum pm_ret_status pm_set_configuration(unsigned int phys_addr) |
| 357 | { |
| 358 | return PM_RET_ERROR_NOTSUPPORTED; |
| 359 | } |
| 360 | |
| 361 | /** |
Filip Drazic | f2ddd91 | 2017-03-15 11:50:47 +0100 | [diff] [blame] | 362 | * pm_init_finalize() - Call to notify PMU firmware that master has power |
| 363 | * management enabled and that it has finished its |
| 364 | * initialization |
| 365 | * |
| 366 | * @return Status returned by the PMU firmware |
| 367 | */ |
| 368 | enum pm_ret_status pm_init_finalize(void) |
| 369 | { |
| 370 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 371 | |
| 372 | /* Send request to the PMU */ |
| 373 | PM_PACK_PAYLOAD1(payload, PM_INIT_FINALIZE); |
| 374 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 375 | } |
| 376 | |
| 377 | /** |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 378 | * pm_get_node_status() - PM call to request a node's current status |
| 379 | * @nid Node id |
| 380 | * @ret_buff Buffer for the return values: |
| 381 | * [0] - Current power state of the node |
| 382 | * [1] - Current requirements for the node (slave nodes only) |
| 383 | * [2] - Current usage status for the node (slave nodes only) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 384 | * |
| 385 | * @return Returns status, either success or error+reason |
| 386 | */ |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 387 | enum pm_ret_status pm_get_node_status(enum pm_node_id nid, |
| 388 | uint32_t *ret_buff) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 389 | { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 390 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 391 | |
| 392 | PM_PACK_PAYLOAD2(payload, PM_GET_NODE_STATUS, nid); |
Anes Hadziahmetagic | 1caf88e | 2017-01-27 18:42:44 +0100 | [diff] [blame] | 393 | return pm_ipi_send_sync(primary_proc, payload, ret_buff, 3); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /** |
| 397 | * pm_register_notifier() - Register the PU to be notified of PM events |
| 398 | * @nid Node id of the slave |
| 399 | * @event The event to be notified about |
| 400 | * @wake Wake up on event |
| 401 | * @enable Enable or disable the notifier |
| 402 | * |
| 403 | * @return Returns status, either success or error+reason |
| 404 | */ |
| 405 | enum pm_ret_status pm_register_notifier(enum pm_node_id nid, |
| 406 | unsigned int event, |
| 407 | unsigned int wake, |
| 408 | unsigned int enable) |
| 409 | { |
Anes Hadziahmetagic | c95ae09 | 2016-05-12 16:17:34 +0200 | [diff] [blame] | 410 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 411 | |
| 412 | PM_PACK_PAYLOAD5(payload, PM_REGISTER_NOTIFIER, |
| 413 | nid, event, wake, enable); |
| 414 | |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 415 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /** |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 419 | * pm_get_op_characteristic() - PM call to request operating characteristics |
| 420 | * of a node |
| 421 | * @nid Node id of the slave |
| 422 | * @type Type of the operating characteristic |
| 423 | * (power, temperature and latency) |
| 424 | * @result Returns the operating characteristic for the requested node, |
| 425 | * specified by the type |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 426 | * |
| 427 | * @return Returns status, either success or error+reason |
| 428 | */ |
| 429 | enum pm_ret_status pm_get_op_characteristic(enum pm_node_id nid, |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 430 | enum pm_opchar_type type, |
| 431 | uint32_t *result) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 432 | { |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 433 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 434 | |
| 435 | /* Send request to the PMU */ |
| 436 | PM_PACK_PAYLOAD3(payload, PM_GET_OP_CHARACTERISTIC, nid, type); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 437 | return pm_ipi_send_sync(primary_proc, payload, result, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* Direct-Control API functions */ |
| 441 | |
| 442 | /** |
| 443 | * pm_reset_assert() - Assert reset |
| 444 | * @reset Reset ID |
| 445 | * @assert Assert (1) or de-assert (0) |
| 446 | * |
| 447 | * @return Returns status, either success or error+reason |
| 448 | */ |
| 449 | enum pm_ret_status pm_reset_assert(unsigned int reset, |
| 450 | unsigned int assert) |
| 451 | { |
| 452 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 453 | |
| 454 | /* Send request to the PMU */ |
| 455 | PM_PACK_PAYLOAD3(payload, PM_RESET_ASSERT, reset, assert); |
| 456 | return pm_ipi_send(primary_proc, payload); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * pm_reset_get_status() - Get current status of a reset line |
| 461 | * @reset Reset ID |
| 462 | * @reset_status Returns current status of selected reset line |
| 463 | * |
| 464 | * @return Returns status, either success or error+reason |
| 465 | */ |
| 466 | enum pm_ret_status pm_reset_get_status(unsigned int reset, |
| 467 | unsigned int *reset_status) |
| 468 | { |
| 469 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 470 | |
| 471 | /* Send request to the PMU */ |
| 472 | PM_PACK_PAYLOAD2(payload, PM_RESET_GET_STATUS, reset); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 473 | return pm_ipi_send_sync(primary_proc, payload, reset_status, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /** |
| 477 | * pm_mmio_write() - Perform write to protected mmio |
| 478 | * @address Address to write to |
| 479 | * @mask Mask to apply |
| 480 | * @value Value to write |
| 481 | * |
| 482 | * This function provides access to PM-related control registers |
| 483 | * that may not be directly accessible by a particular PU. |
| 484 | * |
| 485 | * @return Returns status, either success or error+reason |
| 486 | */ |
| 487 | enum pm_ret_status pm_mmio_write(uintptr_t address, |
| 488 | unsigned int mask, |
| 489 | unsigned int value) |
| 490 | { |
| 491 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 492 | |
| 493 | /* Send request to the PMU */ |
| 494 | PM_PACK_PAYLOAD4(payload, PM_MMIO_WRITE, address, mask, value); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 495 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /** |
| 499 | * pm_mmio_read() - Read value from protected mmio |
| 500 | * @address Address to write to |
| 501 | * @value Value to write |
| 502 | * |
| 503 | * This function provides access to PM-related control registers |
| 504 | * that may not be directly accessible by a particular PU. |
| 505 | * |
| 506 | * @return Returns status, either success or error+reason |
| 507 | */ |
| 508 | enum pm_ret_status pm_mmio_read(uintptr_t address, unsigned int *value) |
| 509 | { |
| 510 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 511 | |
| 512 | /* Send request to the PMU */ |
| 513 | PM_PACK_PAYLOAD2(payload, PM_MMIO_READ, address); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 514 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 515 | } |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 516 | |
| 517 | /** |
| 518 | * pm_fpga_load() - Load the bitstream into the PL. |
| 519 | * |
| 520 | * This function provides access to the xilfpga library to load |
| 521 | * the Bit-stream into PL. |
| 522 | * |
| 523 | * address_low: lower 32-bit Linear memory space address |
| 524 | * |
| 525 | * address_high: higher 32-bit Linear memory space address |
| 526 | * |
| 527 | * size: Number of 32bit words |
| 528 | * |
| 529 | * @return Returns status, either success or error+reason |
| 530 | */ |
| 531 | enum pm_ret_status pm_fpga_load(uint32_t address_low, |
| 532 | uint32_t address_high, |
| 533 | uint32_t size, |
| 534 | uint32_t flags) |
| 535 | { |
| 536 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 537 | |
| 538 | /* Send request to the PMU */ |
| 539 | PM_PACK_PAYLOAD5(payload, PM_FPGA_LOAD, address_high, address_low, |
| 540 | size, flags); |
Siva Durga Prasad Paladugu | bf83b9c | 2018-02-07 13:13:01 +0530 | [diff] [blame] | 541 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
| 545 | * pm_fpga_get_status() - Read value from fpga status register |
| 546 | * @value Value to read |
| 547 | * |
| 548 | * This function provides access to the xilfpga library to get |
| 549 | * the fpga status |
| 550 | * @return Returns status, either success or error+reason |
| 551 | */ |
| 552 | enum pm_ret_status pm_fpga_get_status(unsigned int *value) |
| 553 | { |
| 554 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 555 | |
| 556 | /* Send request to the PMU */ |
| 557 | PM_PACK_PAYLOAD1(payload, PM_FPGA_GET_STATUS); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 558 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 559 | } |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 560 | |
| 561 | /** |
| 562 | * pm_get_chipid() - Read silicon ID registers |
| 563 | * @value Buffer for return values. Must be large enough |
| 564 | * to hold 8 bytes. |
| 565 | * |
| 566 | * @return Returns silicon ID registers |
| 567 | */ |
| 568 | enum pm_ret_status pm_get_chipid(uint32_t *value) |
| 569 | { |
| 570 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 571 | |
| 572 | /* Send request to the PMU */ |
| 573 | PM_PACK_PAYLOAD1(payload, PM_GET_CHIPID); |
| 574 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 575 | } |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 576 | |
| 577 | /** |
Siva Durga Prasad Paladugu | de93d98 | 2018-04-30 15:49:27 +0530 | [diff] [blame] | 578 | * pm_secure_rsaaes() - Load the secure images. |
| 579 | * |
| 580 | * This function provides access to the xilsecure library to load |
| 581 | * the authenticated, encrypted, and authenicated/encrypted images. |
| 582 | * |
| 583 | * address_low: lower 32-bit Linear memory space address |
| 584 | * |
| 585 | * address_high: higher 32-bit Linear memory space address |
| 586 | * |
| 587 | * size: Number of 32bit words |
| 588 | * |
| 589 | * @return Returns status, either success or error+reason |
| 590 | */ |
| 591 | enum pm_ret_status pm_secure_rsaaes(uint32_t address_low, |
| 592 | uint32_t address_high, |
| 593 | uint32_t size, |
| 594 | uint32_t flags) |
| 595 | { |
| 596 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 597 | |
| 598 | /* Send request to the PMU */ |
| 599 | PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA_AES, address_high, address_low, |
| 600 | size, flags); |
| 601 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 602 | } |
| 603 | |
| 604 | /** |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 605 | * pm_pinctrl_request() - Request Pin from firmware |
| 606 | * @pin Pin number to request |
| 607 | * |
| 608 | * This function requests pin from firmware. |
| 609 | * |
| 610 | * @return Returns status, either success or error+reason. |
| 611 | */ |
| 612 | enum pm_ret_status pm_pinctrl_request(unsigned int pin) |
| 613 | { |
| 614 | return PM_RET_SUCCESS; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * pm_pinctrl_release() - Release Pin from firmware |
| 619 | * @pin Pin number to release |
| 620 | * |
| 621 | * This function releases pin from firmware. |
| 622 | * |
| 623 | * @return Returns status, either success or error+reason. |
| 624 | */ |
| 625 | enum pm_ret_status pm_pinctrl_release(unsigned int pin) |
| 626 | { |
| 627 | return PM_RET_SUCCESS; |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * pm_pinctrl_get_function() - Read function id set for the given pin |
| 632 | * @pin Pin number |
| 633 | * @nid Node ID of function currently set for given pin |
| 634 | * |
| 635 | * This function provides the function currently set for the given pin. |
| 636 | * |
| 637 | * @return Returns status, either success or error+reason |
| 638 | */ |
| 639 | enum pm_ret_status pm_pinctrl_get_function(unsigned int pin, |
| 640 | enum pm_node_id *nid) |
| 641 | { |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 642 | return pm_api_pinctrl_get_function(pin, nid); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | /** |
| 646 | * pm_pinctrl_set_function() - Set function id set for the given pin |
| 647 | * @pin Pin number |
| 648 | * @nid Node ID of function to set for given pin |
| 649 | * |
| 650 | * This function provides the function currently set for the given pin. |
| 651 | * |
| 652 | * @return Returns status, either success or error+reason |
| 653 | */ |
| 654 | enum pm_ret_status pm_pinctrl_set_function(unsigned int pin, |
| 655 | enum pm_node_id nid) |
| 656 | { |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 657 | return pm_api_pinctrl_set_function(pin, (unsigned int)nid); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | /** |
| 661 | * pm_pinctrl_get_config() - Read value of requested config param for given pin |
| 662 | * @pin Pin number |
| 663 | * @param Parameter values to be read |
| 664 | * @value Buffer for configuration Parameter value |
| 665 | * |
| 666 | * This function provides the configuration parameter value for the given pin. |
| 667 | * |
| 668 | * @return Returns status, either success or error+reason |
| 669 | */ |
| 670 | enum pm_ret_status pm_pinctrl_get_config(unsigned int pin, |
| 671 | unsigned int param, |
| 672 | unsigned int *value) |
| 673 | { |
Rajan Vaja | 5e139e7 | 2018-01-17 02:39:22 -0800 | [diff] [blame] | 674 | return pm_api_pinctrl_get_config(pin, param, value); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | /** |
| 678 | * pm_pinctrl_set_config() - Read value of requested config param for given pin |
| 679 | * @pin Pin number |
| 680 | * @param Parameter to set |
| 681 | * @value Parameter value to set |
| 682 | * |
| 683 | * This function provides the configuration parameter value for the given pin. |
| 684 | * |
| 685 | * @return Returns status, either success or error+reason |
| 686 | */ |
| 687 | enum pm_ret_status pm_pinctrl_set_config(unsigned int pin, |
| 688 | unsigned int param, |
| 689 | unsigned int value) |
| 690 | { |
Rajan Vaja | 5e139e7 | 2018-01-17 02:39:22 -0800 | [diff] [blame] | 691 | return pm_api_pinctrl_set_config(pin, param, value); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 692 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * pm_ioctl() - PM IOCTL API for device control and configs |
| 696 | * @node_id Node ID of the device |
| 697 | * @ioctl_id ID of the requested IOCTL |
| 698 | * @arg1 Argument 1 to requested IOCTL call |
| 699 | * @arg2 Argument 2 to requested IOCTL call |
| 700 | * @out Returned output value |
| 701 | * |
| 702 | * This function calls IOCTL to firmware for device control and configuration. |
| 703 | * |
| 704 | * @return Returns status, either success or error+reason |
| 705 | */ |
| 706 | enum pm_ret_status pm_ioctl(enum pm_node_id nid, |
| 707 | unsigned int ioctl_id, |
| 708 | unsigned int arg1, |
| 709 | unsigned int arg2, |
| 710 | unsigned int *value) |
| 711 | { |
| 712 | return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value); |
| 713 | } |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 714 | |
| 715 | /** |
| 716 | * pm_clock_get_name() - PM call to request a clock's name |
| 717 | * @clock_id Clock ID |
| 718 | * @name Name of clock (max 16 bytes) |
| 719 | * |
| 720 | * This function is used by master to get nmae of clock specified |
| 721 | * by given clock ID. |
| 722 | * |
| 723 | * @return Returns status, either success or error+reason |
| 724 | */ |
| 725 | static enum pm_ret_status pm_clock_get_name(unsigned int clock_id, char *name) |
| 726 | { |
| 727 | return pm_api_clock_get_name(clock_id, name); |
| 728 | } |
| 729 | |
| 730 | /** |
| 731 | * pm_clock_get_topology() - PM call to request a clock's topology |
| 732 | * @clock_id Clock ID |
| 733 | * @index Topology index for next toplogy node |
| 734 | * @topology Buffer to store nodes in topology and flags |
| 735 | * |
| 736 | * This function is used by master to get topology information for the |
| 737 | * clock specified by given clock ID. Each response would return 3 |
| 738 | * topology nodes. To get next nodes, caller needs to call this API with |
| 739 | * index of next node. Index starts from 0. |
| 740 | * |
| 741 | * @return Returns status, either success or error+reason |
| 742 | */ |
| 743 | static enum pm_ret_status pm_clock_get_topology(unsigned int clock_id, |
| 744 | unsigned int index, |
| 745 | uint32_t *topology) |
| 746 | { |
| 747 | return pm_api_clock_get_topology(clock_id, index, topology); |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * pm_clock_get_fixedfactor_params() - PM call to request a clock's fixed factor |
| 752 | * parameters for fixed clock |
| 753 | * @clock_id Clock ID |
| 754 | * @mul Multiplication value |
| 755 | * @div Divisor value |
| 756 | * |
| 757 | * This function is used by master to get fixed factor parameers for the |
| 758 | * fixed clock. This API is application only for the fixed clock. |
| 759 | * |
| 760 | * @return Returns status, either success or error+reason |
| 761 | */ |
| 762 | static enum pm_ret_status pm_clock_get_fixedfactor_params(unsigned int clock_id, |
| 763 | uint32_t *mul, |
| 764 | uint32_t *div) |
| 765 | { |
| 766 | return pm_api_clock_get_fixedfactor_params(clock_id, mul, div); |
| 767 | } |
| 768 | |
| 769 | /** |
| 770 | * pm_clock_get_parents() - PM call to request a clock's first 3 parents |
| 771 | * @clock_id Clock ID |
| 772 | * @index Index of next parent |
| 773 | * @parents Parents of the given clock |
| 774 | * |
| 775 | * This function is used by master to get clock's parents information. |
| 776 | * This API will return 3 parents with a single response. To get other |
| 777 | * parents, master should call same API in loop with new parent index |
| 778 | * till error is returned. |
| 779 | * |
| 780 | * E.g First call should have index 0 which will return parents 0, 1 and |
| 781 | * 2. Next call, index should be 3 which will return parent 3,4 and 5 and |
| 782 | * so on. |
| 783 | * |
| 784 | * @return Returns status, either success or error+reason |
| 785 | */ |
| 786 | static enum pm_ret_status pm_clock_get_parents(unsigned int clock_id, |
| 787 | unsigned int index, |
| 788 | uint32_t *parents) |
| 789 | { |
| 790 | return pm_api_clock_get_parents(clock_id, index, parents); |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * pm_clock_get_attributes() - PM call to request a clock's attributes |
| 795 | * @clock_id Clock ID |
| 796 | * @attr Clock attributes |
| 797 | * |
| 798 | * This function is used by master to get clock's attributes |
| 799 | * (e.g. valid, clock type, etc). |
| 800 | * |
| 801 | * @return Returns status, either success or error+reason |
| 802 | */ |
| 803 | static enum pm_ret_status pm_clock_get_attributes(unsigned int clock_id, |
| 804 | uint32_t *attr) |
| 805 | { |
| 806 | return pm_api_clock_get_attributes(clock_id, attr); |
| 807 | } |
| 808 | |
| 809 | /** |
| 810 | * pm_clock_enable() - Enable the clock for given id |
| 811 | * @clock_id: Id of the clock to be enabled |
| 812 | * |
| 813 | * This function is used by master to enable the clock |
| 814 | * including peripherals and PLL clocks. |
| 815 | * |
| 816 | * Return: Returns status, either success or error+reason. |
| 817 | */ |
| 818 | |
| 819 | enum pm_ret_status pm_clock_enable(unsigned int clock_id) |
| 820 | { |
| 821 | return pm_api_clock_enable(clock_id); |
| 822 | } |
| 823 | |
| 824 | /** |
| 825 | * pm_clock_disable - Disable the clock for given id |
| 826 | * @clock_id: Id of the clock to be disable |
| 827 | * |
| 828 | * This function is used by master to disable the clock |
| 829 | * including peripherals and PLL clocks. |
| 830 | * |
| 831 | * Return: Returns status, either success or error+reason. |
| 832 | */ |
| 833 | |
| 834 | enum pm_ret_status pm_clock_disable(unsigned int clock_id) |
| 835 | { |
| 836 | return pm_api_clock_disable(clock_id); |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * pm_clock_getstate - Get the clock state for given id |
| 841 | * @clock_id: Id of the clock to be queried |
| 842 | * @state: 1/0 (Enabled/Disabled) |
| 843 | * |
| 844 | * This function is used by master to get the state of clock |
| 845 | * including peripherals and PLL clocks. |
| 846 | * |
| 847 | * Return: Returns status, either success or error+reason. |
| 848 | */ |
| 849 | enum pm_ret_status pm_clock_getstate(unsigned int clock_id, |
| 850 | unsigned int *state) |
| 851 | { |
| 852 | return pm_api_clock_getstate(clock_id, state); |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * pm_clock_setdivider - Set the clock divider for given id |
| 857 | * @clock_id: Id of the clock |
| 858 | * @divider: divider value |
| 859 | * |
| 860 | * This function is used by master to set divider for any clock |
| 861 | * to achieve desired rate. |
| 862 | * |
| 863 | * Return: Returns status, either success or error+reason. |
| 864 | */ |
| 865 | enum pm_ret_status pm_clock_setdivider(unsigned int clock_id, |
| 866 | unsigned int divider) |
| 867 | { |
| 868 | return pm_api_clock_setdivider(clock_id, divider); |
| 869 | } |
| 870 | |
| 871 | /** |
| 872 | * pm_clock_getdivider - Get the clock divider for given id |
| 873 | * @clock_id: Id of the clock |
| 874 | * @divider: divider value |
| 875 | * |
| 876 | * This function is used by master to get divider values |
| 877 | * for any clock. |
| 878 | * |
| 879 | * Return: Returns status, either success or error+reason. |
| 880 | */ |
| 881 | enum pm_ret_status pm_clock_getdivider(unsigned int clock_id, |
| 882 | unsigned int *divider) |
| 883 | { |
| 884 | return pm_api_clock_getdivider(clock_id, divider); |
| 885 | } |
| 886 | |
| 887 | /** |
| 888 | * pm_clock_setrate - Set the clock rate for given id |
| 889 | * @clock_id: Id of the clock |
| 890 | * @rate: rate value in hz |
| 891 | * |
| 892 | * This function is used by master to set rate for any clock. |
| 893 | * |
| 894 | * Return: Returns status, either success or error+reason. |
| 895 | */ |
| 896 | enum pm_ret_status pm_clock_setrate(unsigned int clock_id, |
| 897 | uint64_t rate) |
| 898 | { |
| 899 | return pm_api_clock_setrate(clock_id, rate); |
| 900 | } |
| 901 | |
| 902 | /** |
| 903 | * pm_clock_getrate - Get the clock rate for given id |
| 904 | * @clock_id: Id of the clock |
| 905 | * @rate: rate value in hz |
| 906 | * |
| 907 | * This function is used by master to get rate |
| 908 | * for any clock. |
| 909 | * |
| 910 | * Return: Returns status, either success or error+reason. |
| 911 | */ |
| 912 | enum pm_ret_status pm_clock_getrate(unsigned int clock_id, |
| 913 | uint64_t *rate) |
| 914 | { |
| 915 | return pm_api_clock_getrate(clock_id, rate); |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * pm_clock_setparent - Set the clock parent for given id |
| 920 | * @clock_id: Id of the clock |
| 921 | * @parent_id: parent id |
| 922 | * |
| 923 | * This function is used by master to set parent for any clock. |
| 924 | * |
| 925 | * Return: Returns status, either success or error+reason. |
| 926 | */ |
| 927 | enum pm_ret_status pm_clock_setparent(unsigned int clock_id, |
| 928 | unsigned int parent_id) |
| 929 | { |
| 930 | return pm_api_clock_setparent(clock_id, parent_id); |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * pm_clock_getparent - Get the clock parent for given id |
| 935 | * @clock_id: Id of the clock |
| 936 | * @parent_id: parent id |
| 937 | * |
| 938 | * This function is used by master to get parent index |
| 939 | * for any clock. |
| 940 | * |
| 941 | * Return: Returns status, either success or error+reason. |
| 942 | */ |
| 943 | enum pm_ret_status pm_clock_getparent(unsigned int clock_id, |
| 944 | unsigned int *parent_id) |
| 945 | { |
| 946 | return pm_api_clock_getparent(clock_id, parent_id); |
| 947 | } |
| 948 | |
| 949 | /** |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 950 | * pm_pinctrl_get_num_pins - PM call to request number of pins |
| 951 | * @npins: Number of pins |
| 952 | * |
| 953 | * This function is used by master to get number of pins |
| 954 | * |
| 955 | * Return: Returns status, either success or error+reason. |
| 956 | */ |
| 957 | static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins) |
| 958 | { |
| 959 | return pm_api_pinctrl_get_num_pins(npins); |
| 960 | } |
| 961 | |
| 962 | /** |
| 963 | * pm_pinctrl_get_num_functions - PM call to request number of functions |
| 964 | * @nfuncs: Number of functions |
| 965 | * |
| 966 | * This function is used by master to get number of functions |
| 967 | * |
| 968 | * Return: Returns status, either success or error+reason. |
| 969 | */ |
| 970 | static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs) |
| 971 | { |
| 972 | return pm_api_pinctrl_get_num_functions(nfuncs); |
| 973 | } |
| 974 | |
| 975 | /** |
| 976 | * pm_pinctrl_get_num_function_groups - PM call to request number of |
| 977 | * function groups |
| 978 | * @fid: Id of function |
| 979 | * @ngroups: Number of function groups |
| 980 | * |
| 981 | * This function is used by master to get number of function groups specified |
| 982 | * by given function Id |
| 983 | * |
| 984 | * Return: Returns status, either success or error+reason. |
| 985 | */ |
| 986 | static enum pm_ret_status pm_pinctrl_get_num_function_groups(unsigned int fid, |
| 987 | uint32_t *ngroups) |
| 988 | { |
| 989 | return pm_api_pinctrl_get_num_func_groups(fid, ngroups); |
| 990 | } |
| 991 | |
| 992 | /** |
| 993 | * pm_pinctrl_get_function_name - PM call to request function name |
| 994 | * @fid: Id of function |
| 995 | * @name: Name of function |
| 996 | * |
| 997 | * This function is used by master to get name of function specified |
| 998 | * by given function Id |
| 999 | * |
| 1000 | * Return: Returns status, either success or error+reason. |
| 1001 | */ |
| 1002 | static enum pm_ret_status pm_pinctrl_get_function_name(unsigned int fid, |
| 1003 | char *name) |
| 1004 | { |
| 1005 | return pm_api_pinctrl_get_function_name(fid, name); |
| 1006 | } |
| 1007 | |
| 1008 | /** |
| 1009 | * pm_pinctrl_get_function_groups - PM call to request function groups |
| 1010 | * @fid: Id of function |
| 1011 | * @index: Index of next function groups |
| 1012 | * @groups: Function groups |
| 1013 | * |
| 1014 | * This function is used by master to get function groups specified |
| 1015 | * by given function Id. This API will return 6 function groups with |
| 1016 | * a single response. To get other function groups, master should call |
| 1017 | * same API in loop with new function groups index till error is returned. |
| 1018 | * |
| 1019 | * E.g First call should have index 0 which will return function groups |
| 1020 | * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return |
| 1021 | * function groups 6, 7, 8, 9, 10 and 11 and so on. |
| 1022 | * |
| 1023 | * Return: Returns status, either success or error+reason. |
| 1024 | */ |
| 1025 | static enum pm_ret_status pm_pinctrl_get_function_groups(unsigned int fid, |
| 1026 | unsigned int index, |
| 1027 | uint16_t *groups) |
| 1028 | { |
| 1029 | return pm_api_pinctrl_get_function_groups(fid, index, groups); |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * pm_pinctrl_get_pin_groups - PM call to request pin groups |
| 1034 | * @pin_id: Id of pin |
| 1035 | * @index: Index of next pin groups |
| 1036 | * @groups: pin groups |
| 1037 | * |
| 1038 | * This function is used by master to get pin groups specified |
| 1039 | * by given pin Id. This API will return 6 pin groups with |
| 1040 | * a single response. To get other pin groups, master should call |
| 1041 | * same API in loop with new pin groups index till error is returned. |
| 1042 | * |
| 1043 | * E.g First call should have index 0 which will return pin groups |
| 1044 | * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return |
| 1045 | * pin groups 6, 7, 8, 9, 10 and 11 and so on. |
| 1046 | * |
| 1047 | * Return: Returns status, either success or error+reason. |
| 1048 | */ |
| 1049 | static enum pm_ret_status pm_pinctrl_get_pin_groups(unsigned int pin_id, |
| 1050 | unsigned int index, |
| 1051 | uint16_t *groups) |
| 1052 | { |
| 1053 | return pm_api_pinctrl_get_pin_groups(pin_id, index, groups); |
| 1054 | } |
| 1055 | |
| 1056 | /** |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1057 | * pm_query_data() - PM API for querying firmware data |
| 1058 | * @arg1 Argument 1 to requested IOCTL call |
| 1059 | * @arg2 Argument 2 to requested IOCTL call |
| 1060 | * @arg3 Argument 3 to requested IOCTL call |
| 1061 | * @arg4 Argument 4 to requested IOCTL call |
| 1062 | * @data Returned output data |
| 1063 | * |
| 1064 | * This function returns requested data. |
| 1065 | * |
| 1066 | * @return Returns status, either success or error+reason |
| 1067 | */ |
| 1068 | enum pm_ret_status pm_query_data(enum pm_query_id qid, |
| 1069 | unsigned int arg1, |
| 1070 | unsigned int arg2, |
| 1071 | unsigned int arg3, |
| 1072 | unsigned int *data) |
| 1073 | { |
| 1074 | enum pm_ret_status ret; |
| 1075 | |
| 1076 | switch (qid) { |
| 1077 | case PM_QID_CLOCK_GET_NAME: |
| 1078 | ret = pm_clock_get_name(arg1, (char *)data); |
| 1079 | break; |
| 1080 | case PM_QID_CLOCK_GET_TOPOLOGY: |
| 1081 | ret = pm_clock_get_topology(arg1, arg2, &data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1082 | data[0] = (unsigned int)ret; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1083 | break; |
| 1084 | case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS: |
| 1085 | ret = pm_clock_get_fixedfactor_params(arg1, &data[1], &data[2]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1086 | data[0] = (unsigned int)ret; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1087 | break; |
| 1088 | case PM_QID_CLOCK_GET_PARENTS: |
| 1089 | ret = pm_clock_get_parents(arg1, arg2, &data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1090 | data[0] = (unsigned int)ret; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1091 | break; |
| 1092 | case PM_QID_CLOCK_GET_ATTRIBUTES: |
| 1093 | ret = pm_clock_get_attributes(arg1, &data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1094 | data[0] = (unsigned int)ret; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1095 | break; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1096 | case PM_QID_PINCTRL_GET_NUM_PINS: |
| 1097 | ret = pm_pinctrl_get_num_pins(&data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1098 | data[0] = (unsigned int)ret; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1099 | break; |
| 1100 | case PM_QID_PINCTRL_GET_NUM_FUNCTIONS: |
| 1101 | ret = pm_pinctrl_get_num_functions(&data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1102 | data[0] = (unsigned int)ret; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1103 | break; |
| 1104 | case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS: |
| 1105 | ret = pm_pinctrl_get_num_function_groups(arg1, &data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1106 | data[0] = (unsigned int)ret; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1107 | break; |
| 1108 | case PM_QID_PINCTRL_GET_FUNCTION_NAME: |
| 1109 | ret = pm_pinctrl_get_function_name(arg1, (char *)data); |
| 1110 | break; |
| 1111 | case PM_QID_PINCTRL_GET_FUNCTION_GROUPS: |
| 1112 | ret = pm_pinctrl_get_function_groups(arg1, arg2, |
| 1113 | (uint16_t *)&data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1114 | data[0] = (unsigned int)ret; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1115 | break; |
| 1116 | case PM_QID_PINCTRL_GET_PIN_GROUPS: |
| 1117 | ret = pm_pinctrl_get_pin_groups(arg1, arg2, |
| 1118 | (uint16_t *)&data[1]); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1119 | data[0] = (unsigned int)ret; |
Rajan Vaja | d5dd836 | 2018-01-30 04:16:31 -0800 | [diff] [blame] | 1120 | break; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1121 | default: |
| 1122 | ret = PM_RET_ERROR_ARGS; |
| 1123 | WARN("Unimplemented query service call: 0x%x\n", qid); |
Jolly Shah | 69fb5bf | 2018-02-07 16:25:41 -0800 | [diff] [blame] | 1124 | break; |
Rajan Vaja | 3511613 | 2018-01-17 02:39:25 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | return ret; |
| 1128 | } |
Siva Durga Prasad Paladugu | f3994cc | 2018-05-01 11:12:55 +0530 | [diff] [blame] | 1129 | |
| 1130 | enum pm_ret_status pm_sha_hash(uint32_t address_high, |
| 1131 | uint32_t address_low, |
| 1132 | uint32_t size, |
| 1133 | uint32_t flags) |
| 1134 | { |
| 1135 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1136 | |
| 1137 | /* Send request to the PMU */ |
| 1138 | PM_PACK_PAYLOAD5(payload, PM_SECURE_SHA, address_high, address_low, |
| 1139 | size, flags); |
| 1140 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1141 | } |
| 1142 | |
| 1143 | enum pm_ret_status pm_rsa_core(uint32_t address_high, |
| 1144 | uint32_t address_low, |
| 1145 | uint32_t size, |
| 1146 | uint32_t flags) |
| 1147 | { |
| 1148 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1149 | |
| 1150 | /* Send request to the PMU */ |
| 1151 | PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA, address_high, address_low, |
| 1152 | size, flags); |
| 1153 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 1154 | } |
Siva Durga Prasad Paladugu | a4ed4b2 | 2018-04-30 20:06:58 +0530 | [diff] [blame] | 1155 | |
| 1156 | enum pm_ret_status pm_secure_image(uint32_t address_low, |
| 1157 | uint32_t address_high, |
| 1158 | uint32_t key_lo, |
| 1159 | uint32_t key_hi, |
| 1160 | uint32_t *value) |
| 1161 | { |
| 1162 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 1163 | |
| 1164 | /* Send request to the PMU */ |
| 1165 | PM_PACK_PAYLOAD5(payload, PM_SECURE_IMAGE, address_high, address_low, |
| 1166 | key_hi, key_lo); |
| 1167 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 1168 | } |