blob: a3beaad95f6055ddd19593e25228ee07a6dc321c [file] [log] [blame]
Soren Brinkmann76fcae32016-03-06 20:16:27 -08001/*
Rajan Vaja83687612018-01-17 02:39:20 -08002 * Copyright (c) 2013-2018, ARM Limited and Contributors. All rights reserved.
Soren Brinkmann76fcae32016-03-06 20:16:27 -08003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Soren Brinkmann76fcae32016-03-06 20:16:27 -08005 */
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 Vaja35116132018-01-17 02:39:25 -080014#include "pm_api_clock.h"
Rajan Vaja5529a012018-01-17 02:39:23 -080015#include "pm_api_ioctl.h"
Rajan Vaja0ac2be12018-01-17 02:39:21 -080016#include "pm_api_pinctrl.h"
Isla Mitchelle3631462017-07-14 10:46:32 +010017#include "pm_api_sys.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080018#include "pm_client.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080019#include "pm_common.h"
Isla Mitchelle3631462017-07-14 10:46:32 +010020#include "pm_ipi.h"
Soren Brinkmann76fcae32016-03-06 20:16:27 -080021
Siva Durga Prasad Paladugu1f80d3f2018-04-30 15:56:10 +053022/* default shutdown/reboot scope is system(2) */
23static 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 */
30unsigned int pm_get_shutdown_scope(void)
31{
32 return pm_shutdown_scope;
33}
34
Soren Brinkmann76fcae32016-03-06 20:16:27 -080035/**
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 Drazic0bd9d0c2016-07-20 17:17:39 +020071 * @state Requested state
Soren Brinkmann76fcae32016-03-06 20:16:27 -080072 * @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 */
79enum 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 Drazic4c0765a2016-07-26 12:11:33 +020092 pm_client_suspend(proc, state);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080093 /* Send request to the PMU */
94 PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency,
95 state, address, (address >> 32));
Soren Brinkmannd6c9e032016-09-22 11:35:47 -070096 return pm_ipi_send_sync(proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -080097}
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 */
109enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700118 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800119 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 */
139enum 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 Brinkmann76fcae32016-03-06 20:16:27 -0800146
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800147
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 Brinkmannd6c9e032016-09-22 11:35:47 -0700157 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800158 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 */
170enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700179 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800180 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 */
194enum 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 */
218enum 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 Paladugu1f80d3f2018-04-30 15:56:10 +0530231 * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope
232 * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800233 *
234 * @return Returns status, either success or error+reason
235 */
Soren Brinkmann58fbb9b2016-09-02 09:50:54 -0700236enum pm_ret_status pm_system_shutdown(unsigned int type, unsigned int subtype)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800237{
238 uint32_t payload[PAYLOAD_ARG_CNT];
239
Siva Durga Prasad Paladugu1f80d3f2018-04-30 15:56:10 +0530240 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 Brinkmann58fbb9b2016-09-02 09:50:54 -0700246 PM_PACK_PAYLOAD3(payload, PM_SYSTEM_SHUTDOWN, type, subtype);
Tejas Patelaf4b10e2018-02-09 02:42:59 -0800247 return pm_ipi_send_non_blocking(primary_proc, payload);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800248}
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 */
261enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700271 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800272 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 */
287enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700298 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800299 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 */
309enum 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 */
324enum 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 */
341enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700347 return pm_ipi_send_sync(primary_proc, payload, version, 1);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800348}
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 */
356enum pm_ret_status pm_set_configuration(unsigned int phys_addr)
357{
358 return PM_RET_ERROR_NOTSUPPORTED;
359}
360
361/**
Filip Drazicf2ddd912017-03-15 11:50:47 +0100362 * 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 */
368enum 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 Hadziahmetagic1caf88e2017-01-27 18:42:44 +0100378 * 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 Brinkmann76fcae32016-03-06 20:16:27 -0800384 *
385 * @return Returns status, either success or error+reason
386 */
Anes Hadziahmetagic1caf88e2017-01-27 18:42:44 +0100387enum pm_ret_status pm_get_node_status(enum pm_node_id nid,
388 uint32_t *ret_buff)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800389{
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800390 uint32_t payload[PAYLOAD_ARG_CNT];
391
392 PM_PACK_PAYLOAD2(payload, PM_GET_NODE_STATUS, nid);
Anes Hadziahmetagic1caf88e2017-01-27 18:42:44 +0100393 return pm_ipi_send_sync(primary_proc, payload, ret_buff, 3);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800394}
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 */
405enum 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 Hadziahmetagicc95ae092016-05-12 16:17:34 +0200410 uint32_t payload[PAYLOAD_ARG_CNT];
411
412 PM_PACK_PAYLOAD5(payload, PM_REGISTER_NOTIFIER,
413 nid, event, wake, enable);
414
Soren Brinkmanna1b0a902016-09-30 11:30:21 -0700415 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800416}
417
418/**
Anes Hadziahmetagic92aee012016-05-12 16:17:30 +0200419 * 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 Brinkmann76fcae32016-03-06 20:16:27 -0800426 *
427 * @return Returns status, either success or error+reason
428 */
429enum pm_ret_status pm_get_op_characteristic(enum pm_node_id nid,
Anes Hadziahmetagic92aee012016-05-12 16:17:30 +0200430 enum pm_opchar_type type,
431 uint32_t *result)
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800432{
Anes Hadziahmetagic92aee012016-05-12 16:17:30 +0200433 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700437 return pm_ipi_send_sync(primary_proc, payload, result, 1);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800438}
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 */
449enum 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 */
466enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700473 return pm_ipi_send_sync(primary_proc, payload, reset_status, 1);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800474}
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 */
487enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700495 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800496}
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 */
508enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700514 return pm_ipi_send_sync(primary_proc, payload, value, 1);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800515}
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530516
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 */
531enum 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 Paladugubf83b9c2018-02-07 13:13:01 +0530541 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530542}
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 */
552enum 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 Brinkmannd6c9e032016-09-22 11:35:47 -0700558 return pm_ipi_send_sync(primary_proc, payload, value, 1);
Nava kishore Manne68d460c2016-08-20 23:18:09 +0530559}
Soren Brinkmanncb366812016-09-22 12:21:11 -0700560
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 */
568enum 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 Brinkmann84f0af42016-09-30 14:24:25 -0700576
577/**
Siva Durga Prasad Paladugude93d982018-04-30 15:49:27 +0530578 * 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 */
591enum 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 Vaja83687612018-01-17 02:39:20 -0800605 * 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 */
612enum 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 */
625enum 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 */
639enum pm_ret_status pm_pinctrl_get_function(unsigned int pin,
640 enum pm_node_id *nid)
641{
Rajan Vaja0ac2be12018-01-17 02:39:21 -0800642 return pm_api_pinctrl_get_function(pin, nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800643}
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 */
654enum pm_ret_status pm_pinctrl_set_function(unsigned int pin,
655 enum pm_node_id nid)
656{
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800657 return pm_api_pinctrl_set_function(pin, (unsigned int)nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800658}
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 */
670enum pm_ret_status pm_pinctrl_get_config(unsigned int pin,
671 unsigned int param,
672 unsigned int *value)
673{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800674 return pm_api_pinctrl_get_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800675}
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 */
687enum pm_ret_status pm_pinctrl_set_config(unsigned int pin,
688 unsigned int param,
689 unsigned int value)
690{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800691 return pm_api_pinctrl_set_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800692}
Rajan Vaja5529a012018-01-17 02:39:23 -0800693
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 */
706enum 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 Vaja35116132018-01-17 02:39:25 -0800714
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 */
725static 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 */
743static 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 */
762static 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 */
786static 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 */
803static 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
819enum 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
834enum 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 */
849enum 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 */
865enum 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 */
881enum 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 */
896enum 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 */
912enum 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 */
927enum 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 */
943enum 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 Vajad5dd8362018-01-30 04:16:31 -0800950 * 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 */
957static 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 */
970static 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 */
986static 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 */
1002static 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 */
1025static 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 */
1049static 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 Vaja35116132018-01-17 02:39:25 -08001057 * 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 */
1068enum 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 Shah69fb5bf2018-02-07 16:25:41 -08001082 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001083 break;
1084 case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
1085 ret = pm_clock_get_fixedfactor_params(arg1, &data[1], &data[2]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001086 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001087 break;
1088 case PM_QID_CLOCK_GET_PARENTS:
1089 ret = pm_clock_get_parents(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001090 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001091 break;
1092 case PM_QID_CLOCK_GET_ATTRIBUTES:
1093 ret = pm_clock_get_attributes(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001094 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001095 break;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001096 case PM_QID_PINCTRL_GET_NUM_PINS:
1097 ret = pm_pinctrl_get_num_pins(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001098 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001099 break;
1100 case PM_QID_PINCTRL_GET_NUM_FUNCTIONS:
1101 ret = pm_pinctrl_get_num_functions(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001102 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001103 break;
1104 case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS:
1105 ret = pm_pinctrl_get_num_function_groups(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001106 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001107 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 Shah69fb5bf2018-02-07 16:25:41 -08001114 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001115 break;
1116 case PM_QID_PINCTRL_GET_PIN_GROUPS:
1117 ret = pm_pinctrl_get_pin_groups(arg1, arg2,
1118 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001119 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001120 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001121 default:
1122 ret = PM_RET_ERROR_ARGS;
1123 WARN("Unimplemented query service call: 0x%x\n", qid);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001124 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001125 }
1126
1127 return ret;
1128}
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +05301129
1130enum 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
1143enum 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}