blob: 4b709abff67cdb6adfc36ad45f01fb9511b03cc7 [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);
Soren Brinkmann76fcae32016-03-06 20:16:27 -0800247 return pm_ipi_send(primary_proc, payload);
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 */
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);
541 return pm_ipi_send(primary_proc, payload);
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 */
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/**
Soren Brinkmann84f0af42016-09-30 14:24:25 -0700605 * pm_get_callbackdata() - Read from IPI response buffer
606 * @data - array of PAYLOAD_ARG_CNT elements
607 *
608 * Read value from ipi buffer response buffer.
609 */
610void pm_get_callbackdata(uint32_t *data, size_t count)
611{
Soren Brinkmann84f0af42016-09-30 14:24:25 -0700612 pm_ipi_buff_read_callb(data, count);
Wendy Liang328105c2017-10-03 23:21:11 -0700613 pm_ipi_irq_clear(primary_proc);
Soren Brinkmann84f0af42016-09-30 14:24:25 -0700614}
Rajan Vaja83687612018-01-17 02:39:20 -0800615
616/**
617 * pm_pinctrl_request() - Request Pin from firmware
618 * @pin Pin number to request
619 *
620 * This function requests pin from firmware.
621 *
622 * @return Returns status, either success or error+reason.
623 */
624enum pm_ret_status pm_pinctrl_request(unsigned int pin)
625{
626 return PM_RET_SUCCESS;
627}
628
629/**
630 * pm_pinctrl_release() - Release Pin from firmware
631 * @pin Pin number to release
632 *
633 * This function releases pin from firmware.
634 *
635 * @return Returns status, either success or error+reason.
636 */
637enum pm_ret_status pm_pinctrl_release(unsigned int pin)
638{
639 return PM_RET_SUCCESS;
640}
641
642/**
643 * pm_pinctrl_get_function() - Read function id set for the given pin
644 * @pin Pin number
645 * @nid Node ID of function currently set for given pin
646 *
647 * This function provides the function currently set for the given pin.
648 *
649 * @return Returns status, either success or error+reason
650 */
651enum pm_ret_status pm_pinctrl_get_function(unsigned int pin,
652 enum pm_node_id *nid)
653{
Rajan Vaja0ac2be12018-01-17 02:39:21 -0800654 return pm_api_pinctrl_get_function(pin, nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800655}
656
657/**
658 * pm_pinctrl_set_function() - Set function id set for the given pin
659 * @pin Pin number
660 * @nid Node ID of function to set for given pin
661 *
662 * This function provides the function currently set for the given pin.
663 *
664 * @return Returns status, either success or error+reason
665 */
666enum pm_ret_status pm_pinctrl_set_function(unsigned int pin,
667 enum pm_node_id nid)
668{
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800669 return pm_api_pinctrl_set_function(pin, (unsigned int)nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800670}
671
672/**
673 * pm_pinctrl_get_config() - Read value of requested config param for given pin
674 * @pin Pin number
675 * @param Parameter values to be read
676 * @value Buffer for configuration Parameter value
677 *
678 * This function provides the configuration parameter value for the given pin.
679 *
680 * @return Returns status, either success or error+reason
681 */
682enum pm_ret_status pm_pinctrl_get_config(unsigned int pin,
683 unsigned int param,
684 unsigned int *value)
685{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800686 return pm_api_pinctrl_get_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800687}
688
689/**
690 * pm_pinctrl_set_config() - Read value of requested config param for given pin
691 * @pin Pin number
692 * @param Parameter to set
693 * @value Parameter value to set
694 *
695 * This function provides the configuration parameter value for the given pin.
696 *
697 * @return Returns status, either success or error+reason
698 */
699enum pm_ret_status pm_pinctrl_set_config(unsigned int pin,
700 unsigned int param,
701 unsigned int value)
702{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800703 return pm_api_pinctrl_set_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800704}
Rajan Vaja5529a012018-01-17 02:39:23 -0800705
706/**
707 * pm_ioctl() - PM IOCTL API for device control and configs
708 * @node_id Node ID of the device
709 * @ioctl_id ID of the requested IOCTL
710 * @arg1 Argument 1 to requested IOCTL call
711 * @arg2 Argument 2 to requested IOCTL call
712 * @out Returned output value
713 *
714 * This function calls IOCTL to firmware for device control and configuration.
715 *
716 * @return Returns status, either success or error+reason
717 */
718enum pm_ret_status pm_ioctl(enum pm_node_id nid,
719 unsigned int ioctl_id,
720 unsigned int arg1,
721 unsigned int arg2,
722 unsigned int *value)
723{
724 return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value);
725}
Rajan Vaja35116132018-01-17 02:39:25 -0800726
727/**
728 * pm_clock_get_name() - PM call to request a clock's name
729 * @clock_id Clock ID
730 * @name Name of clock (max 16 bytes)
731 *
732 * This function is used by master to get nmae of clock specified
733 * by given clock ID.
734 *
735 * @return Returns status, either success or error+reason
736 */
737static enum pm_ret_status pm_clock_get_name(unsigned int clock_id, char *name)
738{
739 return pm_api_clock_get_name(clock_id, name);
740}
741
742/**
743 * pm_clock_get_topology() - PM call to request a clock's topology
744 * @clock_id Clock ID
745 * @index Topology index for next toplogy node
746 * @topology Buffer to store nodes in topology and flags
747 *
748 * This function is used by master to get topology information for the
749 * clock specified by given clock ID. Each response would return 3
750 * topology nodes. To get next nodes, caller needs to call this API with
751 * index of next node. Index starts from 0.
752 *
753 * @return Returns status, either success or error+reason
754 */
755static enum pm_ret_status pm_clock_get_topology(unsigned int clock_id,
756 unsigned int index,
757 uint32_t *topology)
758{
759 return pm_api_clock_get_topology(clock_id, index, topology);
760}
761
762/**
763 * pm_clock_get_fixedfactor_params() - PM call to request a clock's fixed factor
764 * parameters for fixed clock
765 * @clock_id Clock ID
766 * @mul Multiplication value
767 * @div Divisor value
768 *
769 * This function is used by master to get fixed factor parameers for the
770 * fixed clock. This API is application only for the fixed clock.
771 *
772 * @return Returns status, either success or error+reason
773 */
774static enum pm_ret_status pm_clock_get_fixedfactor_params(unsigned int clock_id,
775 uint32_t *mul,
776 uint32_t *div)
777{
778 return pm_api_clock_get_fixedfactor_params(clock_id, mul, div);
779}
780
781/**
782 * pm_clock_get_parents() - PM call to request a clock's first 3 parents
783 * @clock_id Clock ID
784 * @index Index of next parent
785 * @parents Parents of the given clock
786 *
787 * This function is used by master to get clock's parents information.
788 * This API will return 3 parents with a single response. To get other
789 * parents, master should call same API in loop with new parent index
790 * till error is returned.
791 *
792 * E.g First call should have index 0 which will return parents 0, 1 and
793 * 2. Next call, index should be 3 which will return parent 3,4 and 5 and
794 * so on.
795 *
796 * @return Returns status, either success or error+reason
797 */
798static enum pm_ret_status pm_clock_get_parents(unsigned int clock_id,
799 unsigned int index,
800 uint32_t *parents)
801{
802 return pm_api_clock_get_parents(clock_id, index, parents);
803}
804
805/**
806 * pm_clock_get_attributes() - PM call to request a clock's attributes
807 * @clock_id Clock ID
808 * @attr Clock attributes
809 *
810 * This function is used by master to get clock's attributes
811 * (e.g. valid, clock type, etc).
812 *
813 * @return Returns status, either success or error+reason
814 */
815static enum pm_ret_status pm_clock_get_attributes(unsigned int clock_id,
816 uint32_t *attr)
817{
818 return pm_api_clock_get_attributes(clock_id, attr);
819}
820
821/**
822 * pm_clock_enable() - Enable the clock for given id
823 * @clock_id: Id of the clock to be enabled
824 *
825 * This function is used by master to enable the clock
826 * including peripherals and PLL clocks.
827 *
828 * Return: Returns status, either success or error+reason.
829 */
830
831enum pm_ret_status pm_clock_enable(unsigned int clock_id)
832{
833 return pm_api_clock_enable(clock_id);
834}
835
836/**
837 * pm_clock_disable - Disable the clock for given id
838 * @clock_id: Id of the clock to be disable
839 *
840 * This function is used by master to disable the clock
841 * including peripherals and PLL clocks.
842 *
843 * Return: Returns status, either success or error+reason.
844 */
845
846enum pm_ret_status pm_clock_disable(unsigned int clock_id)
847{
848 return pm_api_clock_disable(clock_id);
849}
850
851/**
852 * pm_clock_getstate - Get the clock state for given id
853 * @clock_id: Id of the clock to be queried
854 * @state: 1/0 (Enabled/Disabled)
855 *
856 * This function is used by master to get the state of clock
857 * including peripherals and PLL clocks.
858 *
859 * Return: Returns status, either success or error+reason.
860 */
861enum pm_ret_status pm_clock_getstate(unsigned int clock_id,
862 unsigned int *state)
863{
864 return pm_api_clock_getstate(clock_id, state);
865}
866
867/**
868 * pm_clock_setdivider - Set the clock divider for given id
869 * @clock_id: Id of the clock
870 * @divider: divider value
871 *
872 * This function is used by master to set divider for any clock
873 * to achieve desired rate.
874 *
875 * Return: Returns status, either success or error+reason.
876 */
877enum pm_ret_status pm_clock_setdivider(unsigned int clock_id,
878 unsigned int divider)
879{
880 return pm_api_clock_setdivider(clock_id, divider);
881}
882
883/**
884 * pm_clock_getdivider - Get the clock divider for given id
885 * @clock_id: Id of the clock
886 * @divider: divider value
887 *
888 * This function is used by master to get divider values
889 * for any clock.
890 *
891 * Return: Returns status, either success or error+reason.
892 */
893enum pm_ret_status pm_clock_getdivider(unsigned int clock_id,
894 unsigned int *divider)
895{
896 return pm_api_clock_getdivider(clock_id, divider);
897}
898
899/**
900 * pm_clock_setrate - Set the clock rate for given id
901 * @clock_id: Id of the clock
902 * @rate: rate value in hz
903 *
904 * This function is used by master to set rate for any clock.
905 *
906 * Return: Returns status, either success or error+reason.
907 */
908enum pm_ret_status pm_clock_setrate(unsigned int clock_id,
909 uint64_t rate)
910{
911 return pm_api_clock_setrate(clock_id, rate);
912}
913
914/**
915 * pm_clock_getrate - Get the clock rate for given id
916 * @clock_id: Id of the clock
917 * @rate: rate value in hz
918 *
919 * This function is used by master to get rate
920 * for any clock.
921 *
922 * Return: Returns status, either success or error+reason.
923 */
924enum pm_ret_status pm_clock_getrate(unsigned int clock_id,
925 uint64_t *rate)
926{
927 return pm_api_clock_getrate(clock_id, rate);
928}
929
930/**
931 * pm_clock_setparent - Set the clock parent for given id
932 * @clock_id: Id of the clock
933 * @parent_id: parent id
934 *
935 * This function is used by master to set parent for any clock.
936 *
937 * Return: Returns status, either success or error+reason.
938 */
939enum pm_ret_status pm_clock_setparent(unsigned int clock_id,
940 unsigned int parent_id)
941{
942 return pm_api_clock_setparent(clock_id, parent_id);
943}
944
945/**
946 * pm_clock_getparent - Get the clock parent for given id
947 * @clock_id: Id of the clock
948 * @parent_id: parent id
949 *
950 * This function is used by master to get parent index
951 * for any clock.
952 *
953 * Return: Returns status, either success or error+reason.
954 */
955enum pm_ret_status pm_clock_getparent(unsigned int clock_id,
956 unsigned int *parent_id)
957{
958 return pm_api_clock_getparent(clock_id, parent_id);
959}
960
961/**
Rajan Vajad5dd8362018-01-30 04:16:31 -0800962 * pm_pinctrl_get_num_pins - PM call to request number of pins
963 * @npins: Number of pins
964 *
965 * This function is used by master to get number of pins
966 *
967 * Return: Returns status, either success or error+reason.
968 */
969static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins)
970{
971 return pm_api_pinctrl_get_num_pins(npins);
972}
973
974/**
975 * pm_pinctrl_get_num_functions - PM call to request number of functions
976 * @nfuncs: Number of functions
977 *
978 * This function is used by master to get number of functions
979 *
980 * Return: Returns status, either success or error+reason.
981 */
982static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs)
983{
984 return pm_api_pinctrl_get_num_functions(nfuncs);
985}
986
987/**
988 * pm_pinctrl_get_num_function_groups - PM call to request number of
989 * function groups
990 * @fid: Id of function
991 * @ngroups: Number of function groups
992 *
993 * This function is used by master to get number of function groups specified
994 * by given function Id
995 *
996 * Return: Returns status, either success or error+reason.
997 */
998static enum pm_ret_status pm_pinctrl_get_num_function_groups(unsigned int fid,
999 uint32_t *ngroups)
1000{
1001 return pm_api_pinctrl_get_num_func_groups(fid, ngroups);
1002}
1003
1004/**
1005 * pm_pinctrl_get_function_name - PM call to request function name
1006 * @fid: Id of function
1007 * @name: Name of function
1008 *
1009 * This function is used by master to get name of function specified
1010 * by given function Id
1011 *
1012 * Return: Returns status, either success or error+reason.
1013 */
1014static enum pm_ret_status pm_pinctrl_get_function_name(unsigned int fid,
1015 char *name)
1016{
1017 return pm_api_pinctrl_get_function_name(fid, name);
1018}
1019
1020/**
1021 * pm_pinctrl_get_function_groups - PM call to request function groups
1022 * @fid: Id of function
1023 * @index: Index of next function groups
1024 * @groups: Function groups
1025 *
1026 * This function is used by master to get function groups specified
1027 * by given function Id. This API will return 6 function groups with
1028 * a single response. To get other function groups, master should call
1029 * same API in loop with new function groups index till error is returned.
1030 *
1031 * E.g First call should have index 0 which will return function groups
1032 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1033 * function groups 6, 7, 8, 9, 10 and 11 and so on.
1034 *
1035 * Return: Returns status, either success or error+reason.
1036 */
1037static enum pm_ret_status pm_pinctrl_get_function_groups(unsigned int fid,
1038 unsigned int index,
1039 uint16_t *groups)
1040{
1041 return pm_api_pinctrl_get_function_groups(fid, index, groups);
1042}
1043
1044/**
1045 * pm_pinctrl_get_pin_groups - PM call to request pin groups
1046 * @pin_id: Id of pin
1047 * @index: Index of next pin groups
1048 * @groups: pin groups
1049 *
1050 * This function is used by master to get pin groups specified
1051 * by given pin Id. This API will return 6 pin groups with
1052 * a single response. To get other pin groups, master should call
1053 * same API in loop with new pin groups index till error is returned.
1054 *
1055 * E.g First call should have index 0 which will return pin groups
1056 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1057 * pin groups 6, 7, 8, 9, 10 and 11 and so on.
1058 *
1059 * Return: Returns status, either success or error+reason.
1060 */
1061static enum pm_ret_status pm_pinctrl_get_pin_groups(unsigned int pin_id,
1062 unsigned int index,
1063 uint16_t *groups)
1064{
1065 return pm_api_pinctrl_get_pin_groups(pin_id, index, groups);
1066}
1067
1068/**
Rajan Vaja35116132018-01-17 02:39:25 -08001069 * pm_query_data() - PM API for querying firmware data
1070 * @arg1 Argument 1 to requested IOCTL call
1071 * @arg2 Argument 2 to requested IOCTL call
1072 * @arg3 Argument 3 to requested IOCTL call
1073 * @arg4 Argument 4 to requested IOCTL call
1074 * @data Returned output data
1075 *
1076 * This function returns requested data.
1077 *
1078 * @return Returns status, either success or error+reason
1079 */
1080enum pm_ret_status pm_query_data(enum pm_query_id qid,
1081 unsigned int arg1,
1082 unsigned int arg2,
1083 unsigned int arg3,
1084 unsigned int *data)
1085{
1086 enum pm_ret_status ret;
1087
1088 switch (qid) {
1089 case PM_QID_CLOCK_GET_NAME:
1090 ret = pm_clock_get_name(arg1, (char *)data);
1091 break;
1092 case PM_QID_CLOCK_GET_TOPOLOGY:
1093 ret = pm_clock_get_topology(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001094 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001095 break;
1096 case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
1097 ret = pm_clock_get_fixedfactor_params(arg1, &data[1], &data[2]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001098 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001099 break;
1100 case PM_QID_CLOCK_GET_PARENTS:
1101 ret = pm_clock_get_parents(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001102 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001103 break;
1104 case PM_QID_CLOCK_GET_ATTRIBUTES:
1105 ret = pm_clock_get_attributes(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001106 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001107 break;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001108 case PM_QID_PINCTRL_GET_NUM_PINS:
1109 ret = pm_pinctrl_get_num_pins(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001110 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001111 break;
1112 case PM_QID_PINCTRL_GET_NUM_FUNCTIONS:
1113 ret = pm_pinctrl_get_num_functions(&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_NUM_FUNCTION_GROUPS:
1117 ret = pm_pinctrl_get_num_function_groups(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001118 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001119 break;
1120 case PM_QID_PINCTRL_GET_FUNCTION_NAME:
1121 ret = pm_pinctrl_get_function_name(arg1, (char *)data);
1122 break;
1123 case PM_QID_PINCTRL_GET_FUNCTION_GROUPS:
1124 ret = pm_pinctrl_get_function_groups(arg1, arg2,
1125 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001126 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001127 break;
1128 case PM_QID_PINCTRL_GET_PIN_GROUPS:
1129 ret = pm_pinctrl_get_pin_groups(arg1, arg2,
1130 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001131 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001132 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001133 default:
1134 ret = PM_RET_ERROR_ARGS;
1135 WARN("Unimplemented query service call: 0x%x\n", qid);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001136 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001137 }
1138
1139 return ret;
1140}