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 | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 14 | #include "pm_api_ioctl.h" |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 15 | #include "pm_api_pinctrl.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 16 | #include "pm_api_sys.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 17 | #include "pm_client.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 18 | #include "pm_common.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 19 | #include "pm_ipi.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Assigning of argument values into array elements. |
| 23 | */ |
| 24 | #define PM_PACK_PAYLOAD1(pl, arg0) { \ |
| 25 | pl[0] = (uint32_t)(arg0); \ |
| 26 | } |
| 27 | |
| 28 | #define PM_PACK_PAYLOAD2(pl, arg0, arg1) { \ |
| 29 | pl[1] = (uint32_t)(arg1); \ |
| 30 | PM_PACK_PAYLOAD1(pl, arg0); \ |
| 31 | } |
| 32 | |
| 33 | #define PM_PACK_PAYLOAD3(pl, arg0, arg1, arg2) { \ |
| 34 | pl[2] = (uint32_t)(arg2); \ |
| 35 | PM_PACK_PAYLOAD2(pl, arg0, arg1); \ |
| 36 | } |
| 37 | |
| 38 | #define PM_PACK_PAYLOAD4(pl, arg0, arg1, arg2, arg3) { \ |
| 39 | pl[3] = (uint32_t)(arg3); \ |
| 40 | PM_PACK_PAYLOAD3(pl, arg0, arg1, arg2); \ |
| 41 | } |
| 42 | |
| 43 | #define PM_PACK_PAYLOAD5(pl, arg0, arg1, arg2, arg3, arg4) { \ |
| 44 | pl[4] = (uint32_t)(arg4); \ |
| 45 | PM_PACK_PAYLOAD4(pl, arg0, arg1, arg2, arg3); \ |
| 46 | } |
| 47 | |
| 48 | #define PM_PACK_PAYLOAD6(pl, arg0, arg1, arg2, arg3, arg4, arg5) { \ |
| 49 | pl[5] = (uint32_t)(arg5); \ |
| 50 | PM_PACK_PAYLOAD5(pl, arg0, arg1, arg2, arg3, arg4); \ |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * pm_self_suspend() - PM call for processor to suspend itself |
| 55 | * @nid Node id of the processor or subsystem |
| 56 | * @latency Requested maximum wakeup latency (not supported) |
Filip Drazic | 0bd9d0c | 2016-07-20 17:17:39 +0200 | [diff] [blame] | 57 | * @state Requested state |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 58 | * @address Resume address |
| 59 | * |
| 60 | * This is a blocking call, it will return only once PMU has responded. |
| 61 | * On a wakeup, resume address will be automatically set by PMU. |
| 62 | * |
| 63 | * @return Returns status, either success or error+reason |
| 64 | */ |
| 65 | enum pm_ret_status pm_self_suspend(enum pm_node_id nid, |
| 66 | unsigned int latency, |
| 67 | unsigned int state, |
| 68 | uintptr_t address) |
| 69 | { |
| 70 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 71 | unsigned int cpuid = plat_my_core_pos(); |
| 72 | const struct pm_proc *proc = pm_get_proc(cpuid); |
| 73 | |
| 74 | /* |
| 75 | * Do client specific suspend operations |
| 76 | * (e.g. set powerdown request bit) |
| 77 | */ |
Filip Drazic | 4c0765a | 2016-07-26 12:11:33 +0200 | [diff] [blame] | 78 | pm_client_suspend(proc, state); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 79 | /* Send request to the PMU */ |
| 80 | PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency, |
| 81 | state, address, (address >> 32)); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 82 | return pm_ipi_send_sync(proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * pm_req_suspend() - PM call to request for another PU or subsystem to |
| 87 | * be suspended gracefully. |
| 88 | * @target Node id of the targeted PU or subsystem |
| 89 | * @ack Flag to specify whether acknowledge is requested |
| 90 | * @latency Requested wakeup latency (not supported) |
| 91 | * @state Requested state (not supported) |
| 92 | * |
| 93 | * @return Returns status, either success or error+reason |
| 94 | */ |
| 95 | enum pm_ret_status pm_req_suspend(enum pm_node_id target, |
| 96 | enum pm_request_ack ack, |
| 97 | unsigned int latency, unsigned int state) |
| 98 | { |
| 99 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 100 | |
| 101 | /* Send request to the PMU */ |
| 102 | PM_PACK_PAYLOAD5(payload, PM_REQ_SUSPEND, target, ack, latency, state); |
| 103 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 104 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 105 | else |
| 106 | return pm_ipi_send(primary_proc, payload); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * pm_req_wakeup() - PM call for processor to wake up selected processor |
| 111 | * or subsystem |
| 112 | * @target Node id of the processor or subsystem to wake up |
| 113 | * @ack Flag to specify whether acknowledge requested |
| 114 | * @set_address Resume address presence indicator |
| 115 | * 1 resume address specified, 0 otherwise |
| 116 | * @address Resume address |
| 117 | * |
| 118 | * This API function is either used to power up another APU core for SMP |
| 119 | * (by PSCI) or to power up an entirely different PU or subsystem, such |
| 120 | * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be |
| 121 | * automatically set by PMU. |
| 122 | * |
| 123 | * @return Returns status, either success or error+reason |
| 124 | */ |
| 125 | enum pm_ret_status pm_req_wakeup(enum pm_node_id target, |
| 126 | unsigned int set_address, |
| 127 | uintptr_t address, |
| 128 | enum pm_request_ack ack) |
| 129 | { |
| 130 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 131 | uint64_t encoded_address; |
| 132 | const struct pm_proc *proc = pm_get_proc_by_node(target); |
| 133 | |
| 134 | /* invoke APU-specific code for waking up another APU core */ |
| 135 | pm_client_wakeup(proc); |
| 136 | |
| 137 | /* encode set Address into 1st bit of address */ |
| 138 | encoded_address = address; |
| 139 | encoded_address |= !!set_address; |
| 140 | |
| 141 | /* Send request to the PMU to perform the wake of the PU */ |
| 142 | PM_PACK_PAYLOAD5(payload, PM_REQ_WAKEUP, target, encoded_address, |
| 143 | encoded_address >> 32, ack); |
| 144 | |
| 145 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 146 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 147 | else |
| 148 | return pm_ipi_send(primary_proc, payload); |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * pm_force_powerdown() - PM call to request for another PU or subsystem to |
| 153 | * be powered down forcefully |
| 154 | * @target Node id of the targeted PU or subsystem |
| 155 | * @ack Flag to specify whether acknowledge is requested |
| 156 | * |
| 157 | * @return Returns status, either success or error+reason |
| 158 | */ |
| 159 | enum pm_ret_status pm_force_powerdown(enum pm_node_id target, |
| 160 | enum pm_request_ack ack) |
| 161 | { |
| 162 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 163 | |
| 164 | /* Send request to the PMU */ |
| 165 | PM_PACK_PAYLOAD3(payload, PM_FORCE_POWERDOWN, target, ack); |
| 166 | |
| 167 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 168 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 169 | else |
| 170 | return pm_ipi_send(primary_proc, payload); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * pm_abort_suspend() - PM call to announce that a prior suspend request |
| 175 | * is to be aborted. |
| 176 | * @reason Reason for the abort |
| 177 | * |
| 178 | * Calling PU expects the PMU to abort the initiated suspend procedure. |
| 179 | * This is a non-blocking call without any acknowledge. |
| 180 | * |
| 181 | * @return Returns status, either success or error+reason |
| 182 | */ |
| 183 | enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason) |
| 184 | { |
| 185 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 186 | |
| 187 | /* |
| 188 | * Do client specific abort suspend operations |
| 189 | * (e.g. enable interrupts and clear powerdown request bit) |
| 190 | */ |
| 191 | pm_client_abort_suspend(); |
| 192 | /* Send request to the PMU */ |
| 193 | /* TODO: allow passing the node ID of the affected CPU */ |
| 194 | PM_PACK_PAYLOAD3(payload, PM_ABORT_SUSPEND, reason, |
| 195 | primary_proc->node_id); |
| 196 | return pm_ipi_send(primary_proc, payload); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended |
| 201 | * @target Node id of the targeted PU or subsystem |
| 202 | * @wkup_node Node id of the wakeup peripheral |
| 203 | * @enable Enable or disable the specified peripheral as wake source |
| 204 | * |
| 205 | * @return Returns status, either success or error+reason |
| 206 | */ |
| 207 | enum pm_ret_status pm_set_wakeup_source(enum pm_node_id target, |
| 208 | enum pm_node_id wkup_node, |
| 209 | unsigned int enable) |
| 210 | { |
| 211 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 212 | |
| 213 | PM_PACK_PAYLOAD4(payload, PM_SET_WAKEUP_SOURCE, target, wkup_node, |
| 214 | enable); |
| 215 | return pm_ipi_send(primary_proc, payload); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * pm_system_shutdown() - PM call to request a system shutdown or restart |
| 220 | * @restart Shutdown or restart? 0 for shutdown, 1 for restart |
| 221 | * |
| 222 | * @return Returns status, either success or error+reason |
| 223 | */ |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 224 | 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] | 225 | { |
| 226 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 227 | |
Soren Brinkmann | 58fbb9b | 2016-09-02 09:50:54 -0700 | [diff] [blame] | 228 | PM_PACK_PAYLOAD3(payload, PM_SYSTEM_SHUTDOWN, type, subtype); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 229 | return pm_ipi_send(primary_proc, payload); |
| 230 | } |
| 231 | |
| 232 | /* APIs for managing PM slaves: */ |
| 233 | |
| 234 | /** |
| 235 | * pm_req_node() - PM call to request a node with specific capabilities |
| 236 | * @nid Node id of the slave |
| 237 | * @capabilities Requested capabilities of the slave |
| 238 | * @qos Quality of service (not supported) |
| 239 | * @ack Flag to specify whether acknowledge is requested |
| 240 | * |
| 241 | * @return Returns status, either success or error+reason |
| 242 | */ |
| 243 | enum pm_ret_status pm_req_node(enum pm_node_id nid, |
| 244 | unsigned int capabilities, |
| 245 | unsigned int qos, |
| 246 | enum pm_request_ack ack) |
| 247 | { |
| 248 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 249 | |
| 250 | PM_PACK_PAYLOAD5(payload, PM_REQ_NODE, nid, capabilities, qos, ack); |
| 251 | |
| 252 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 253 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 254 | else |
| 255 | return pm_ipi_send(primary_proc, payload); |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * pm_set_requirement() - PM call to set requirement for PM slaves |
| 260 | * @nid Node id of the slave |
| 261 | * @capabilities Requested capabilities of the slave |
| 262 | * @qos Quality of service (not supported) |
| 263 | * @ack Flag to specify whether acknowledge is requested |
| 264 | * |
| 265 | * This API function is to be used for slaves a PU already has requested |
| 266 | * |
| 267 | * @return Returns status, either success or error+reason |
| 268 | */ |
| 269 | enum pm_ret_status pm_set_requirement(enum pm_node_id nid, |
| 270 | unsigned int capabilities, |
| 271 | unsigned int qos, |
| 272 | enum pm_request_ack ack) |
| 273 | { |
| 274 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 275 | |
| 276 | PM_PACK_PAYLOAD5(payload, PM_SET_REQUIREMENT, nid, capabilities, qos, |
| 277 | ack); |
| 278 | |
| 279 | if (ack == REQ_ACK_BLOCKING) |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 280 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 281 | else |
| 282 | return pm_ipi_send(primary_proc, payload); |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * pm_release_node() - PM call to release a node |
| 287 | * @nid Node id of the slave |
| 288 | * |
| 289 | * @return Returns status, either success or error+reason |
| 290 | */ |
| 291 | enum pm_ret_status pm_release_node(enum pm_node_id nid) |
| 292 | { |
| 293 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 294 | |
| 295 | PM_PACK_PAYLOAD2(payload, PM_RELEASE_NODE, nid); |
| 296 | return pm_ipi_send(primary_proc, payload); |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * pm_set_max_latency() - PM call to set wakeup latency requirements |
| 301 | * @nid Node id of the slave |
| 302 | * @latency Requested maximum wakeup latency |
| 303 | * |
| 304 | * @return Returns status, either success or error+reason |
| 305 | */ |
| 306 | enum pm_ret_status pm_set_max_latency(enum pm_node_id nid, |
| 307 | unsigned int latency) |
| 308 | { |
| 309 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 310 | |
| 311 | PM_PACK_PAYLOAD3(payload, PM_SET_MAX_LATENCY, nid, latency); |
| 312 | return pm_ipi_send(primary_proc, payload); |
| 313 | } |
| 314 | |
| 315 | /* Miscellaneous API functions */ |
| 316 | |
| 317 | /** |
| 318 | * pm_get_api_version() - Get version number of PMU PM firmware |
| 319 | * @version Returns 32-bit version number of PMU Power Management Firmware |
| 320 | * |
| 321 | * @return Returns status, either success or error+reason |
| 322 | */ |
| 323 | enum pm_ret_status pm_get_api_version(unsigned int *version) |
| 324 | { |
| 325 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 326 | |
| 327 | /* Send request to the PMU */ |
| 328 | PM_PACK_PAYLOAD1(payload, PM_GET_API_VERSION); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 329 | return pm_ipi_send_sync(primary_proc, payload, version, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | /** |
| 333 | * pm_set_configuration() - PM call to set system configuration |
| 334 | * @phys_addr Physical 32-bit address of data structure in memory |
| 335 | * |
| 336 | * @return Returns status, either success or error+reason |
| 337 | */ |
| 338 | enum pm_ret_status pm_set_configuration(unsigned int phys_addr) |
| 339 | { |
| 340 | return PM_RET_ERROR_NOTSUPPORTED; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * pm_get_node_status() - PM call to request a node's current power state |
| 345 | * @nid Node id of the slave |
| 346 | * |
| 347 | * @return Returns status, either success or error+reason |
| 348 | */ |
| 349 | enum pm_ret_status pm_get_node_status(enum pm_node_id nid) |
| 350 | { |
| 351 | /* TODO: Add power state argument!! */ |
| 352 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 353 | |
| 354 | PM_PACK_PAYLOAD2(payload, PM_GET_NODE_STATUS, nid); |
| 355 | return pm_ipi_send(primary_proc, payload); |
| 356 | } |
| 357 | |
| 358 | /** |
| 359 | * pm_register_notifier() - Register the PU to be notified of PM events |
| 360 | * @nid Node id of the slave |
| 361 | * @event The event to be notified about |
| 362 | * @wake Wake up on event |
| 363 | * @enable Enable or disable the notifier |
| 364 | * |
| 365 | * @return Returns status, either success or error+reason |
| 366 | */ |
| 367 | enum pm_ret_status pm_register_notifier(enum pm_node_id nid, |
| 368 | unsigned int event, |
| 369 | unsigned int wake, |
| 370 | unsigned int enable) |
| 371 | { |
Anes Hadziahmetagic | c95ae09 | 2016-05-12 16:17:34 +0200 | [diff] [blame] | 372 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 373 | |
| 374 | PM_PACK_PAYLOAD5(payload, PM_REGISTER_NOTIFIER, |
| 375 | nid, event, wake, enable); |
| 376 | |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 377 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /** |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 381 | * pm_get_op_characteristic() - PM call to request operating characteristics |
| 382 | * of a node |
| 383 | * @nid Node id of the slave |
| 384 | * @type Type of the operating characteristic |
| 385 | * (power, temperature and latency) |
| 386 | * @result Returns the operating characteristic for the requested node, |
| 387 | * specified by the type |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 388 | * |
| 389 | * @return Returns status, either success or error+reason |
| 390 | */ |
| 391 | 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] | 392 | enum pm_opchar_type type, |
| 393 | uint32_t *result) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 394 | { |
Anes Hadziahmetagic | 92aee01 | 2016-05-12 16:17:30 +0200 | [diff] [blame] | 395 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 396 | |
| 397 | /* Send request to the PMU */ |
| 398 | PM_PACK_PAYLOAD3(payload, PM_GET_OP_CHARACTERISTIC, nid, type); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 399 | return pm_ipi_send_sync(primary_proc, payload, result, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | /* Direct-Control API functions */ |
| 403 | |
| 404 | /** |
| 405 | * pm_reset_assert() - Assert reset |
| 406 | * @reset Reset ID |
| 407 | * @assert Assert (1) or de-assert (0) |
| 408 | * |
| 409 | * @return Returns status, either success or error+reason |
| 410 | */ |
| 411 | enum pm_ret_status pm_reset_assert(unsigned int reset, |
| 412 | unsigned int assert) |
| 413 | { |
| 414 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 415 | |
| 416 | /* Send request to the PMU */ |
| 417 | PM_PACK_PAYLOAD3(payload, PM_RESET_ASSERT, reset, assert); |
| 418 | return pm_ipi_send(primary_proc, payload); |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * pm_reset_get_status() - Get current status of a reset line |
| 423 | * @reset Reset ID |
| 424 | * @reset_status Returns current status of selected reset line |
| 425 | * |
| 426 | * @return Returns status, either success or error+reason |
| 427 | */ |
| 428 | enum pm_ret_status pm_reset_get_status(unsigned int reset, |
| 429 | unsigned int *reset_status) |
| 430 | { |
| 431 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 432 | |
| 433 | /* Send request to the PMU */ |
| 434 | PM_PACK_PAYLOAD2(payload, PM_RESET_GET_STATUS, reset); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 435 | return pm_ipi_send_sync(primary_proc, payload, reset_status, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /** |
| 439 | * pm_mmio_write() - Perform write to protected mmio |
| 440 | * @address Address to write to |
| 441 | * @mask Mask to apply |
| 442 | * @value Value to write |
| 443 | * |
| 444 | * This function provides access to PM-related control registers |
| 445 | * that may not be directly accessible by a particular PU. |
| 446 | * |
| 447 | * @return Returns status, either success or error+reason |
| 448 | */ |
| 449 | enum pm_ret_status pm_mmio_write(uintptr_t address, |
| 450 | unsigned int mask, |
| 451 | unsigned int value) |
| 452 | { |
| 453 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 454 | |
| 455 | /* Send request to the PMU */ |
| 456 | PM_PACK_PAYLOAD4(payload, PM_MMIO_WRITE, address, mask, value); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 457 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
| 461 | * pm_mmio_read() - Read value from protected mmio |
| 462 | * @address Address to write to |
| 463 | * @value Value to write |
| 464 | * |
| 465 | * This function provides access to PM-related control registers |
| 466 | * that may not be directly accessible by a particular PU. |
| 467 | * |
| 468 | * @return Returns status, either success or error+reason |
| 469 | */ |
| 470 | enum pm_ret_status pm_mmio_read(uintptr_t address, unsigned int *value) |
| 471 | { |
| 472 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 473 | |
| 474 | /* Send request to the PMU */ |
| 475 | PM_PACK_PAYLOAD2(payload, PM_MMIO_READ, address); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 476 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 477 | } |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 478 | |
| 479 | /** |
| 480 | * pm_fpga_load() - Load the bitstream into the PL. |
| 481 | * |
| 482 | * This function provides access to the xilfpga library to load |
| 483 | * the Bit-stream into PL. |
| 484 | * |
| 485 | * address_low: lower 32-bit Linear memory space address |
| 486 | * |
| 487 | * address_high: higher 32-bit Linear memory space address |
| 488 | * |
| 489 | * size: Number of 32bit words |
| 490 | * |
| 491 | * @return Returns status, either success or error+reason |
| 492 | */ |
| 493 | enum pm_ret_status pm_fpga_load(uint32_t address_low, |
| 494 | uint32_t address_high, |
| 495 | uint32_t size, |
| 496 | uint32_t flags) |
| 497 | { |
| 498 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 499 | |
| 500 | /* Send request to the PMU */ |
| 501 | PM_PACK_PAYLOAD5(payload, PM_FPGA_LOAD, address_high, address_low, |
| 502 | size, flags); |
| 503 | return pm_ipi_send(primary_proc, payload); |
| 504 | } |
| 505 | |
| 506 | /** |
| 507 | * pm_fpga_get_status() - Read value from fpga status register |
| 508 | * @value Value to read |
| 509 | * |
| 510 | * This function provides access to the xilfpga library to get |
| 511 | * the fpga status |
| 512 | * @return Returns status, either success or error+reason |
| 513 | */ |
| 514 | enum pm_ret_status pm_fpga_get_status(unsigned int *value) |
| 515 | { |
| 516 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 517 | |
| 518 | /* Send request to the PMU */ |
| 519 | PM_PACK_PAYLOAD1(payload, PM_FPGA_GET_STATUS); |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 520 | return pm_ipi_send_sync(primary_proc, payload, value, 1); |
Nava kishore Manne | 68d460c | 2016-08-20 23:18:09 +0530 | [diff] [blame] | 521 | } |
Soren Brinkmann | cb36681 | 2016-09-22 12:21:11 -0700 | [diff] [blame] | 522 | |
| 523 | /** |
| 524 | * pm_get_chipid() - Read silicon ID registers |
| 525 | * @value Buffer for return values. Must be large enough |
| 526 | * to hold 8 bytes. |
| 527 | * |
| 528 | * @return Returns silicon ID registers |
| 529 | */ |
| 530 | enum pm_ret_status pm_get_chipid(uint32_t *value) |
| 531 | { |
| 532 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 533 | |
| 534 | /* Send request to the PMU */ |
| 535 | PM_PACK_PAYLOAD1(payload, PM_GET_CHIPID); |
| 536 | return pm_ipi_send_sync(primary_proc, payload, value, 2); |
| 537 | } |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 538 | |
| 539 | /** |
| 540 | * pm_get_callbackdata() - Read from IPI response buffer |
| 541 | * @data - array of PAYLOAD_ARG_CNT elements |
| 542 | * |
| 543 | * Read value from ipi buffer response buffer. |
| 544 | */ |
| 545 | void pm_get_callbackdata(uint32_t *data, size_t count) |
| 546 | { |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 547 | pm_ipi_buff_read_callb(data, count); |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 548 | pm_ipi_irq_clear(primary_proc); |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 549 | } |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 550 | |
| 551 | /** |
| 552 | * pm_pinctrl_request() - Request Pin from firmware |
| 553 | * @pin Pin number to request |
| 554 | * |
| 555 | * This function requests pin from firmware. |
| 556 | * |
| 557 | * @return Returns status, either success or error+reason. |
| 558 | */ |
| 559 | enum pm_ret_status pm_pinctrl_request(unsigned int pin) |
| 560 | { |
| 561 | return PM_RET_SUCCESS; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * pm_pinctrl_release() - Release Pin from firmware |
| 566 | * @pin Pin number to release |
| 567 | * |
| 568 | * This function releases pin from firmware. |
| 569 | * |
| 570 | * @return Returns status, either success or error+reason. |
| 571 | */ |
| 572 | enum pm_ret_status pm_pinctrl_release(unsigned int pin) |
| 573 | { |
| 574 | return PM_RET_SUCCESS; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * pm_pinctrl_get_function() - Read function id set for the given pin |
| 579 | * @pin Pin number |
| 580 | * @nid Node ID of function currently set for given pin |
| 581 | * |
| 582 | * This function provides the function currently set for the given pin. |
| 583 | * |
| 584 | * @return Returns status, either success or error+reason |
| 585 | */ |
| 586 | enum pm_ret_status pm_pinctrl_get_function(unsigned int pin, |
| 587 | enum pm_node_id *nid) |
| 588 | { |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 589 | return pm_api_pinctrl_get_function(pin, nid); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
| 593 | * pm_pinctrl_set_function() - Set function id set for the given pin |
| 594 | * @pin Pin number |
| 595 | * @nid Node ID of function to set for given pin |
| 596 | * |
| 597 | * This function provides the function currently set for the given pin. |
| 598 | * |
| 599 | * @return Returns status, either success or error+reason |
| 600 | */ |
| 601 | enum pm_ret_status pm_pinctrl_set_function(unsigned int pin, |
| 602 | enum pm_node_id nid) |
| 603 | { |
Rajan Vaja | 0ac2be1 | 2018-01-17 02:39:21 -0800 | [diff] [blame] | 604 | return pm_api_pinctrl_set_function(pin, nid); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /** |
| 608 | * pm_pinctrl_get_config() - Read value of requested config param for given pin |
| 609 | * @pin Pin number |
| 610 | * @param Parameter values to be read |
| 611 | * @value Buffer for configuration Parameter value |
| 612 | * |
| 613 | * This function provides the configuration parameter value for the given pin. |
| 614 | * |
| 615 | * @return Returns status, either success or error+reason |
| 616 | */ |
| 617 | enum pm_ret_status pm_pinctrl_get_config(unsigned int pin, |
| 618 | unsigned int param, |
| 619 | unsigned int *value) |
| 620 | { |
Rajan Vaja | 5e139e7 | 2018-01-17 02:39:22 -0800 | [diff] [blame] | 621 | return pm_api_pinctrl_get_config(pin, param, value); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /** |
| 625 | * pm_pinctrl_set_config() - Read value of requested config param for given pin |
| 626 | * @pin Pin number |
| 627 | * @param Parameter to set |
| 628 | * @value Parameter value to set |
| 629 | * |
| 630 | * This function provides the configuration parameter value for the given pin. |
| 631 | * |
| 632 | * @return Returns status, either success or error+reason |
| 633 | */ |
| 634 | enum pm_ret_status pm_pinctrl_set_config(unsigned int pin, |
| 635 | unsigned int param, |
| 636 | unsigned int value) |
| 637 | { |
Rajan Vaja | 5e139e7 | 2018-01-17 02:39:22 -0800 | [diff] [blame] | 638 | return pm_api_pinctrl_set_config(pin, param, value); |
Rajan Vaja | 8368761 | 2018-01-17 02:39:20 -0800 | [diff] [blame] | 639 | } |
Rajan Vaja | 5529a01 | 2018-01-17 02:39:23 -0800 | [diff] [blame] | 640 | |
| 641 | /** |
| 642 | * pm_ioctl() - PM IOCTL API for device control and configs |
| 643 | * @node_id Node ID of the device |
| 644 | * @ioctl_id ID of the requested IOCTL |
| 645 | * @arg1 Argument 1 to requested IOCTL call |
| 646 | * @arg2 Argument 2 to requested IOCTL call |
| 647 | * @out Returned output value |
| 648 | * |
| 649 | * This function calls IOCTL to firmware for device control and configuration. |
| 650 | * |
| 651 | * @return Returns status, either success or error+reason |
| 652 | */ |
| 653 | enum pm_ret_status pm_ioctl(enum pm_node_id nid, |
| 654 | unsigned int ioctl_id, |
| 655 | unsigned int arg1, |
| 656 | unsigned int arg2, |
| 657 | unsigned int *value) |
| 658 | { |
| 659 | return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value); |
| 660 | } |