blob: 49471dcac761b40e59c8572f655b65628b7ac04a [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/**
Siva Durga Prasad Paladugu8bd905b2018-09-04 18:05:50 +0530605 * pm_aes_engine() - Aes data blob encryption/decryption
606 * This function provides access to the xilsecure library to
607 * encrypt/decrypt data blobs.
608 *
609 * address_low: lower 32-bit address of the AesParams structure
610 *
611 * address_high: higher 32-bit address of the AesParams structure
612 *
613 * value: Returned output value
614 *
615 * @return Returns status, either success or error+reason
616 */
617enum pm_ret_status pm_aes_engine(uint32_t address_high,
618 uint32_t address_low,
619 uint32_t *value)
620{
621 uint32_t payload[PAYLOAD_ARG_CNT];
622
623 /* Send request to the PMU */
624 PM_PACK_PAYLOAD3(payload, PM_SECURE_AES, address_high, address_low);
625 return pm_ipi_send_sync(primary_proc, payload, value, 1);
626}
627
628/**
Rajan Vaja83687612018-01-17 02:39:20 -0800629 * pm_pinctrl_request() - Request Pin from firmware
630 * @pin Pin number to request
631 *
632 * This function requests pin from firmware.
633 *
634 * @return Returns status, either success or error+reason.
635 */
636enum pm_ret_status pm_pinctrl_request(unsigned int pin)
637{
638 return PM_RET_SUCCESS;
639}
640
641/**
642 * pm_pinctrl_release() - Release Pin from firmware
643 * @pin Pin number to release
644 *
645 * This function releases pin from firmware.
646 *
647 * @return Returns status, either success or error+reason.
648 */
649enum pm_ret_status pm_pinctrl_release(unsigned int pin)
650{
651 return PM_RET_SUCCESS;
652}
653
654/**
655 * pm_pinctrl_get_function() - Read function id set for the given pin
656 * @pin Pin number
657 * @nid Node ID of function currently set for given pin
658 *
659 * This function provides the function currently set for the given pin.
660 *
661 * @return Returns status, either success or error+reason
662 */
663enum pm_ret_status pm_pinctrl_get_function(unsigned int pin,
664 enum pm_node_id *nid)
665{
Rajan Vaja0ac2be12018-01-17 02:39:21 -0800666 return pm_api_pinctrl_get_function(pin, nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800667}
668
669/**
670 * pm_pinctrl_set_function() - Set function id set for the given pin
671 * @pin Pin number
672 * @nid Node ID of function to set for given pin
673 *
674 * This function provides the function currently set for the given pin.
675 *
676 * @return Returns status, either success or error+reason
677 */
678enum pm_ret_status pm_pinctrl_set_function(unsigned int pin,
679 enum pm_node_id nid)
680{
Jolly Shah69fb5bf2018-02-07 16:25:41 -0800681 return pm_api_pinctrl_set_function(pin, (unsigned int)nid);
Rajan Vaja83687612018-01-17 02:39:20 -0800682}
683
684/**
685 * pm_pinctrl_get_config() - Read value of requested config param for given pin
686 * @pin Pin number
687 * @param Parameter values to be read
688 * @value Buffer for configuration Parameter value
689 *
690 * This function provides the configuration parameter value for the given pin.
691 *
692 * @return Returns status, either success or error+reason
693 */
694enum pm_ret_status pm_pinctrl_get_config(unsigned int pin,
695 unsigned int param,
696 unsigned int *value)
697{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800698 return pm_api_pinctrl_get_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800699}
700
701/**
702 * pm_pinctrl_set_config() - Read value of requested config param for given pin
703 * @pin Pin number
704 * @param Parameter to set
705 * @value Parameter value to set
706 *
707 * This function provides the configuration parameter value for the given pin.
708 *
709 * @return Returns status, either success or error+reason
710 */
711enum pm_ret_status pm_pinctrl_set_config(unsigned int pin,
712 unsigned int param,
713 unsigned int value)
714{
Rajan Vaja5e139e72018-01-17 02:39:22 -0800715 return pm_api_pinctrl_set_config(pin, param, value);
Rajan Vaja83687612018-01-17 02:39:20 -0800716}
Rajan Vaja5529a012018-01-17 02:39:23 -0800717
718/**
719 * pm_ioctl() - PM IOCTL API for device control and configs
720 * @node_id Node ID of the device
721 * @ioctl_id ID of the requested IOCTL
722 * @arg1 Argument 1 to requested IOCTL call
723 * @arg2 Argument 2 to requested IOCTL call
724 * @out Returned output value
725 *
726 * This function calls IOCTL to firmware for device control and configuration.
727 *
728 * @return Returns status, either success or error+reason
729 */
730enum pm_ret_status pm_ioctl(enum pm_node_id nid,
731 unsigned int ioctl_id,
732 unsigned int arg1,
733 unsigned int arg2,
734 unsigned int *value)
735{
736 return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value);
737}
Rajan Vaja35116132018-01-17 02:39:25 -0800738
739/**
Rajan Vajada959402018-07-20 03:16:27 -0700740 * pm_clock_get_num_clocks - PM call to request number of clocks
741 * @nclockss: Number of clocks
742 *
743 * This function is used by master to get number of clocks.
744 *
745 * Return: Returns status, either success or error+reason.
746 */
747static enum pm_ret_status pm_clock_get_num_clocks(uint32_t *nclocks)
748{
749 return pm_api_clock_get_num_clocks(nclocks);
750}
751
752/**
Rajan Vaja35116132018-01-17 02:39:25 -0800753 * pm_clock_get_name() - PM call to request a clock's name
754 * @clock_id Clock ID
755 * @name Name of clock (max 16 bytes)
756 *
757 * This function is used by master to get nmae of clock specified
758 * by given clock ID.
759 *
760 * @return Returns status, either success or error+reason
761 */
762static enum pm_ret_status pm_clock_get_name(unsigned int clock_id, char *name)
763{
764 return pm_api_clock_get_name(clock_id, name);
765}
766
767/**
768 * pm_clock_get_topology() - PM call to request a clock's topology
769 * @clock_id Clock ID
770 * @index Topology index for next toplogy node
771 * @topology Buffer to store nodes in topology and flags
772 *
773 * This function is used by master to get topology information for the
774 * clock specified by given clock ID. Each response would return 3
775 * topology nodes. To get next nodes, caller needs to call this API with
776 * index of next node. Index starts from 0.
777 *
778 * @return Returns status, either success or error+reason
779 */
780static enum pm_ret_status pm_clock_get_topology(unsigned int clock_id,
781 unsigned int index,
782 uint32_t *topology)
783{
784 return pm_api_clock_get_topology(clock_id, index, topology);
785}
786
787/**
788 * pm_clock_get_fixedfactor_params() - PM call to request a clock's fixed factor
789 * parameters for fixed clock
790 * @clock_id Clock ID
791 * @mul Multiplication value
792 * @div Divisor value
793 *
794 * This function is used by master to get fixed factor parameers for the
795 * fixed clock. This API is application only for the fixed clock.
796 *
797 * @return Returns status, either success or error+reason
798 */
799static enum pm_ret_status pm_clock_get_fixedfactor_params(unsigned int clock_id,
800 uint32_t *mul,
801 uint32_t *div)
802{
803 return pm_api_clock_get_fixedfactor_params(clock_id, mul, div);
804}
805
806/**
807 * pm_clock_get_parents() - PM call to request a clock's first 3 parents
808 * @clock_id Clock ID
809 * @index Index of next parent
810 * @parents Parents of the given clock
811 *
812 * This function is used by master to get clock's parents information.
813 * This API will return 3 parents with a single response. To get other
814 * parents, master should call same API in loop with new parent index
815 * till error is returned.
816 *
817 * E.g First call should have index 0 which will return parents 0, 1 and
818 * 2. Next call, index should be 3 which will return parent 3,4 and 5 and
819 * so on.
820 *
821 * @return Returns status, either success or error+reason
822 */
823static enum pm_ret_status pm_clock_get_parents(unsigned int clock_id,
824 unsigned int index,
825 uint32_t *parents)
826{
827 return pm_api_clock_get_parents(clock_id, index, parents);
828}
829
830/**
831 * pm_clock_get_attributes() - PM call to request a clock's attributes
832 * @clock_id Clock ID
833 * @attr Clock attributes
834 *
835 * This function is used by master to get clock's attributes
836 * (e.g. valid, clock type, etc).
837 *
838 * @return Returns status, either success or error+reason
839 */
840static enum pm_ret_status pm_clock_get_attributes(unsigned int clock_id,
841 uint32_t *attr)
842{
843 return pm_api_clock_get_attributes(clock_id, attr);
844}
845
846/**
Jolly Shaha5209802019-01-04 11:45:59 -0800847 * pm_clock_gate() - Configure clock gate
848 * @clock_id Id of the clock to be configured
849 * @enable Flag 0=disable (gate the clock), !0=enable (activate the clock)
850 *
851 * @return Error if an argument is not valid or status as returned by the
852 * PM controller (PMU)
853 */
854static enum pm_ret_status pm_clock_gate(unsigned int clock_id,
855 unsigned char enable)
856{
857 uint32_t payload[PAYLOAD_ARG_CNT];
858 enum pm_ret_status status;
859 enum pm_api_id api_id;
860
861 /* Check if clock ID is valid and return an error if it is not */
862 status = pm_clock_id_is_valid(clock_id);
863 if (status != PM_RET_SUCCESS)
864 return status;
865
866 if (enable)
867 api_id = PM_CLOCK_ENABLE;
868 else
869 api_id = PM_CLOCK_DISABLE;
870
871 /* Send request to the PMU */
872 PM_PACK_PAYLOAD2(payload, api_id, clock_id);
873 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
874}
875
876/**
Rajan Vaja35116132018-01-17 02:39:25 -0800877 * pm_clock_enable() - Enable the clock for given id
878 * @clock_id: Id of the clock to be enabled
879 *
880 * This function is used by master to enable the clock
881 * including peripherals and PLL clocks.
882 *
Jolly Shaha5209802019-01-04 11:45:59 -0800883 * @return: Error if an argument is not valid or status as returned by the
884 * pm_clock_gate
Rajan Vaja35116132018-01-17 02:39:25 -0800885 */
Rajan Vaja35116132018-01-17 02:39:25 -0800886enum pm_ret_status pm_clock_enable(unsigned int clock_id)
887{
Jolly Shaha5209802019-01-04 11:45:59 -0800888 struct pm_pll *pll;
889
890 /* First try to handle it as a PLL */
891 pll = pm_clock_get_pll(clock_id);
892 if (pll)
893 return pm_clock_pll_enable(pll);
894
895 /* It's an on-chip clock, PMU should configure clock's gate */
896 return pm_clock_gate(clock_id, 1);
Rajan Vaja35116132018-01-17 02:39:25 -0800897}
898
899/**
900 * pm_clock_disable - Disable the clock for given id
901 * @clock_id: Id of the clock to be disable
902 *
903 * This function is used by master to disable the clock
904 * including peripherals and PLL clocks.
905 *
Jolly Shaha9057a02019-01-02 12:54:40 -0800906 * @return: Error if an argument is not valid or status as returned by the
907 * pm_clock_gate
Rajan Vaja35116132018-01-17 02:39:25 -0800908 */
Rajan Vaja35116132018-01-17 02:39:25 -0800909enum pm_ret_status pm_clock_disable(unsigned int clock_id)
910{
Jolly Shaha9057a02019-01-02 12:54:40 -0800911 struct pm_pll *pll;
912
913 /* First try to handle it as a PLL */
914 pll = pm_clock_get_pll(clock_id);
915 if (pll)
916 return pm_clock_pll_disable(pll);
917
918 /* It's an on-chip clock, PMU should configure clock's gate */
919 return pm_clock_gate(clock_id, 0);
Rajan Vaja35116132018-01-17 02:39:25 -0800920}
921
922/**
923 * pm_clock_getstate - Get the clock state for given id
924 * @clock_id: Id of the clock to be queried
925 * @state: 1/0 (Enabled/Disabled)
926 *
927 * This function is used by master to get the state of clock
928 * including peripherals and PLL clocks.
929 *
930 * Return: Returns status, either success or error+reason.
931 */
932enum pm_ret_status pm_clock_getstate(unsigned int clock_id,
933 unsigned int *state)
934{
Jolly Shah99e8ac92019-01-02 12:55:41 -0800935 struct pm_pll *pll;
936 uint32_t payload[PAYLOAD_ARG_CNT];
937 enum pm_ret_status status;
938
939 /* First try to handle it as a PLL */
940 pll = pm_clock_get_pll(clock_id);
941 if (pll)
942 return pm_clock_pll_get_state(pll, state);
943
944 /* Check if clock ID is a valid on-chip clock */
945 status = pm_clock_id_is_valid(clock_id);
946 if (status != PM_RET_SUCCESS)
947 return status;
948
949 /* Send request to the PMU */
950 PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETSTATE, clock_id);
951 return pm_ipi_send_sync(primary_proc, payload, state, 1);
Rajan Vaja35116132018-01-17 02:39:25 -0800952}
953
954/**
955 * pm_clock_setdivider - Set the clock divider for given id
956 * @clock_id: Id of the clock
957 * @divider: divider value
958 *
959 * This function is used by master to set divider for any clock
960 * to achieve desired rate.
961 *
962 * Return: Returns status, either success or error+reason.
963 */
964enum pm_ret_status pm_clock_setdivider(unsigned int clock_id,
965 unsigned int divider)
966{
967 return pm_api_clock_setdivider(clock_id, divider);
968}
969
970/**
971 * pm_clock_getdivider - Get the clock divider for given id
972 * @clock_id: Id of the clock
973 * @divider: divider value
974 *
975 * This function is used by master to get divider values
976 * for any clock.
977 *
978 * Return: Returns status, either success or error+reason.
979 */
980enum pm_ret_status pm_clock_getdivider(unsigned int clock_id,
981 unsigned int *divider)
982{
983 return pm_api_clock_getdivider(clock_id, divider);
984}
985
986/**
987 * pm_clock_setrate - Set the clock rate for given id
988 * @clock_id: Id of the clock
989 * @rate: rate value in hz
990 *
991 * This function is used by master to set rate for any clock.
992 *
993 * Return: Returns status, either success or error+reason.
994 */
995enum pm_ret_status pm_clock_setrate(unsigned int clock_id,
996 uint64_t rate)
997{
998 return pm_api_clock_setrate(clock_id, rate);
999}
1000
1001/**
1002 * pm_clock_getrate - Get the clock rate for given id
1003 * @clock_id: Id of the clock
1004 * @rate: rate value in hz
1005 *
1006 * This function is used by master to get rate
1007 * for any clock.
1008 *
1009 * Return: Returns status, either success or error+reason.
1010 */
1011enum pm_ret_status pm_clock_getrate(unsigned int clock_id,
1012 uint64_t *rate)
1013{
1014 return pm_api_clock_getrate(clock_id, rate);
1015}
1016
1017/**
1018 * pm_clock_setparent - Set the clock parent for given id
1019 * @clock_id: Id of the clock
1020 * @parent_id: parent id
1021 *
1022 * This function is used by master to set parent for any clock.
1023 *
1024 * Return: Returns status, either success or error+reason.
1025 */
1026enum pm_ret_status pm_clock_setparent(unsigned int clock_id,
1027 unsigned int parent_id)
1028{
1029 return pm_api_clock_setparent(clock_id, parent_id);
1030}
1031
1032/**
1033 * pm_clock_getparent - Get the clock parent for given id
1034 * @clock_id: Id of the clock
1035 * @parent_id: parent id
1036 *
1037 * This function is used by master to get parent index
1038 * for any clock.
1039 *
1040 * Return: Returns status, either success or error+reason.
1041 */
1042enum pm_ret_status pm_clock_getparent(unsigned int clock_id,
1043 unsigned int *parent_id)
1044{
1045 return pm_api_clock_getparent(clock_id, parent_id);
1046}
1047
1048/**
Rajan Vajad5dd8362018-01-30 04:16:31 -08001049 * pm_pinctrl_get_num_pins - PM call to request number of pins
1050 * @npins: Number of pins
1051 *
1052 * This function is used by master to get number of pins
1053 *
1054 * Return: Returns status, either success or error+reason.
1055 */
1056static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins)
1057{
1058 return pm_api_pinctrl_get_num_pins(npins);
1059}
1060
1061/**
1062 * pm_pinctrl_get_num_functions - PM call to request number of functions
1063 * @nfuncs: Number of functions
1064 *
1065 * This function is used by master to get number of functions
1066 *
1067 * Return: Returns status, either success or error+reason.
1068 */
1069static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs)
1070{
1071 return pm_api_pinctrl_get_num_functions(nfuncs);
1072}
1073
1074/**
1075 * pm_pinctrl_get_num_function_groups - PM call to request number of
1076 * function groups
1077 * @fid: Id of function
1078 * @ngroups: Number of function groups
1079 *
1080 * This function is used by master to get number of function groups specified
1081 * by given function Id
1082 *
1083 * Return: Returns status, either success or error+reason.
1084 */
1085static enum pm_ret_status pm_pinctrl_get_num_function_groups(unsigned int fid,
1086 uint32_t *ngroups)
1087{
1088 return pm_api_pinctrl_get_num_func_groups(fid, ngroups);
1089}
1090
1091/**
1092 * pm_pinctrl_get_function_name - PM call to request function name
1093 * @fid: Id of function
1094 * @name: Name of function
1095 *
1096 * This function is used by master to get name of function specified
1097 * by given function Id
1098 *
1099 * Return: Returns status, either success or error+reason.
1100 */
1101static enum pm_ret_status pm_pinctrl_get_function_name(unsigned int fid,
1102 char *name)
1103{
1104 return pm_api_pinctrl_get_function_name(fid, name);
1105}
1106
1107/**
1108 * pm_pinctrl_get_function_groups - PM call to request function groups
1109 * @fid: Id of function
1110 * @index: Index of next function groups
1111 * @groups: Function groups
1112 *
1113 * This function is used by master to get function groups specified
1114 * by given function Id. This API will return 6 function groups with
1115 * a single response. To get other function groups, master should call
1116 * same API in loop with new function groups index till error is returned.
1117 *
1118 * E.g First call should have index 0 which will return function groups
1119 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1120 * function groups 6, 7, 8, 9, 10 and 11 and so on.
1121 *
1122 * Return: Returns status, either success or error+reason.
1123 */
1124static enum pm_ret_status pm_pinctrl_get_function_groups(unsigned int fid,
1125 unsigned int index,
1126 uint16_t *groups)
1127{
1128 return pm_api_pinctrl_get_function_groups(fid, index, groups);
1129}
1130
1131/**
1132 * pm_pinctrl_get_pin_groups - PM call to request pin groups
1133 * @pin_id: Id of pin
1134 * @index: Index of next pin groups
1135 * @groups: pin groups
1136 *
1137 * This function is used by master to get pin groups specified
1138 * by given pin Id. This API will return 6 pin groups with
1139 * a single response. To get other pin groups, master should call
1140 * same API in loop with new pin groups index till error is returned.
1141 *
1142 * E.g First call should have index 0 which will return pin groups
1143 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1144 * pin groups 6, 7, 8, 9, 10 and 11 and so on.
1145 *
1146 * Return: Returns status, either success or error+reason.
1147 */
1148static enum pm_ret_status pm_pinctrl_get_pin_groups(unsigned int pin_id,
1149 unsigned int index,
1150 uint16_t *groups)
1151{
1152 return pm_api_pinctrl_get_pin_groups(pin_id, index, groups);
1153}
1154
1155/**
Rajan Vaja35116132018-01-17 02:39:25 -08001156 * pm_query_data() - PM API for querying firmware data
1157 * @arg1 Argument 1 to requested IOCTL call
1158 * @arg2 Argument 2 to requested IOCTL call
1159 * @arg3 Argument 3 to requested IOCTL call
1160 * @arg4 Argument 4 to requested IOCTL call
1161 * @data Returned output data
1162 *
1163 * This function returns requested data.
1164 *
1165 * @return Returns status, either success or error+reason
1166 */
1167enum pm_ret_status pm_query_data(enum pm_query_id qid,
1168 unsigned int arg1,
1169 unsigned int arg2,
1170 unsigned int arg3,
1171 unsigned int *data)
1172{
1173 enum pm_ret_status ret;
1174
1175 switch (qid) {
1176 case PM_QID_CLOCK_GET_NAME:
1177 ret = pm_clock_get_name(arg1, (char *)data);
1178 break;
1179 case PM_QID_CLOCK_GET_TOPOLOGY:
1180 ret = pm_clock_get_topology(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001181 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001182 break;
1183 case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
1184 ret = pm_clock_get_fixedfactor_params(arg1, &data[1], &data[2]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001185 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001186 break;
1187 case PM_QID_CLOCK_GET_PARENTS:
1188 ret = pm_clock_get_parents(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001189 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001190 break;
1191 case PM_QID_CLOCK_GET_ATTRIBUTES:
1192 ret = pm_clock_get_attributes(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001193 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001194 break;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001195 case PM_QID_PINCTRL_GET_NUM_PINS:
1196 ret = pm_pinctrl_get_num_pins(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001197 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001198 break;
1199 case PM_QID_PINCTRL_GET_NUM_FUNCTIONS:
1200 ret = pm_pinctrl_get_num_functions(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001201 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001202 break;
1203 case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS:
1204 ret = pm_pinctrl_get_num_function_groups(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001205 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001206 break;
1207 case PM_QID_PINCTRL_GET_FUNCTION_NAME:
1208 ret = pm_pinctrl_get_function_name(arg1, (char *)data);
1209 break;
1210 case PM_QID_PINCTRL_GET_FUNCTION_GROUPS:
1211 ret = pm_pinctrl_get_function_groups(arg1, arg2,
1212 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001213 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001214 break;
1215 case PM_QID_PINCTRL_GET_PIN_GROUPS:
1216 ret = pm_pinctrl_get_pin_groups(arg1, arg2,
1217 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001218 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001219 break;
Rajan Vajada959402018-07-20 03:16:27 -07001220 case PM_QID_CLOCK_GET_NUM_CLOCKS:
1221 ret = pm_clock_get_num_clocks(&data[1]);
1222 data[0] = (unsigned int)ret;
1223 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001224 default:
1225 ret = PM_RET_ERROR_ARGS;
1226 WARN("Unimplemented query service call: 0x%x\n", qid);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001227 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001228 }
1229
1230 return ret;
1231}
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +05301232
1233enum pm_ret_status pm_sha_hash(uint32_t address_high,
1234 uint32_t address_low,
1235 uint32_t size,
1236 uint32_t flags)
1237{
1238 uint32_t payload[PAYLOAD_ARG_CNT];
1239
1240 /* Send request to the PMU */
1241 PM_PACK_PAYLOAD5(payload, PM_SECURE_SHA, address_high, address_low,
1242 size, flags);
1243 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1244}
1245
1246enum pm_ret_status pm_rsa_core(uint32_t address_high,
1247 uint32_t address_low,
1248 uint32_t size,
1249 uint32_t flags)
1250{
1251 uint32_t payload[PAYLOAD_ARG_CNT];
1252
1253 /* Send request to the PMU */
1254 PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA, address_high, address_low,
1255 size, flags);
1256 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1257}
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +05301258
1259enum pm_ret_status pm_secure_image(uint32_t address_low,
1260 uint32_t address_high,
1261 uint32_t key_lo,
1262 uint32_t key_hi,
1263 uint32_t *value)
1264{
1265 uint32_t payload[PAYLOAD_ARG_CNT];
1266
1267 /* Send request to the PMU */
1268 PM_PACK_PAYLOAD5(payload, PM_SECURE_IMAGE, address_high, address_low,
1269 key_hi, key_lo);
1270 return pm_ipi_send_sync(primary_proc, payload, value, 2);
1271}
Siva Durga Prasad Paladugu7c6516a2018-09-04 17:41:34 +05301272
1273/**
1274 * pm_fpga_read - Perform the fpga configuration readback
1275 *
1276 * @reg_numframes: Configuration register offset (or) Number of frames to read
1277 * @address_low: lower 32-bit Linear memory space address
1278 * @address_high: higher 32-bit Linear memory space address
1279 * @readback_type: Type of fpga readback operation
1280 * 0 -- Configuration Register readback
1281 * 1 -- Configuration Data readback
1282 * @value: Value to read
1283 *
1284 * This function provides access to the xilfpga library to read
1285 * the PL configuration.
1286 *
1287 * Return: Returns status, either success or error+reason.
1288 */
1289enum pm_ret_status pm_fpga_read(uint32_t reg_numframes,
1290 uint32_t address_low,
1291 uint32_t address_high,
1292 uint32_t readback_type,
1293 uint32_t *value)
1294{
1295 uint32_t payload[PAYLOAD_ARG_CNT];
1296
1297 /* Send request to the PMU */
1298 PM_PACK_PAYLOAD5(payload, PM_FPGA_READ, reg_numframes, address_low,
1299 address_high, readback_type);
1300 return pm_ipi_send_sync(primary_proc, payload, value, 1);
1301}
Jolly Shaha7cc5ee2019-01-02 12:27:00 -08001302
1303/*
1304 * pm_pll_set_parameter() - Set the PLL parameter value
1305 * @nid Node id of the target PLL
1306 * @param_id ID of the PLL parameter
1307 * @value Parameter value to be set
1308 *
1309 * Setting the parameter will have physical effect once the PLL mode is set to
1310 * integer or fractional.
1311 *
1312 * @return Error if an argument is not valid or status as returned by the
1313 * PM controller (PMU)
1314 */
1315enum pm_ret_status pm_pll_set_parameter(enum pm_node_id nid,
1316 enum pm_pll_param param_id,
1317 unsigned int value)
1318{
1319 uint32_t payload[PAYLOAD_ARG_CNT];
1320
1321 /* Check if given node ID is a PLL node */
1322 if (nid < NODE_APLL || nid > NODE_IOPLL)
1323 return PM_RET_ERROR_ARGS;
1324
1325 /* Check if parameter ID is valid and return an error if it's not */
1326 if (param_id >= PM_PLL_PARAM_MAX)
1327 return PM_RET_ERROR_ARGS;
1328
1329 /* Send request to the PMU */
1330 PM_PACK_PAYLOAD4(payload, PM_PLL_SET_PARAMETER, nid, param_id, value);
1331 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1332}
Jolly Shahcb2f45d2019-01-04 11:28:38 -08001333
1334/**
1335 * pm_pll_get_parameter() - Get the PLL parameter value
1336 * @nid Node id of the target PLL
1337 * @param_id ID of the PLL parameter
1338 * @value Location to store the parameter value
1339 *
1340 * @return Error if an argument is not valid or status as returned by the
1341 * PM controller (PMU)
1342 */
1343enum pm_ret_status pm_pll_get_parameter(enum pm_node_id nid,
1344 enum pm_pll_param param_id,
1345 unsigned int *value)
1346{
1347 uint32_t payload[PAYLOAD_ARG_CNT];
1348
1349 /* Check if given node ID is a PLL node */
1350 if (nid < NODE_APLL || nid > NODE_IOPLL)
1351 return PM_RET_ERROR_ARGS;
1352
1353 /* Check if parameter ID is valid and return an error if it's not */
1354 if (param_id >= PM_PLL_PARAM_MAX)
1355 return PM_RET_ERROR_ARGS;
1356
1357 /* Send request to the PMU */
1358 PM_PACK_PAYLOAD3(payload, PM_PLL_GET_PARAMETER, nid, param_id);
1359 return pm_ipi_send_sync(primary_proc, payload, value, 1);
1360}
Jolly Shah1f0d5852019-01-04 11:32:31 -08001361
1362/**
1363 * pm_pll_set_mode() - Set the PLL mode
1364 * @nid Node id of the target PLL
1365 * @mode PLL mode to be set
1366 *
1367 * If reset mode is set the PM controller will first bypass the PLL and then
1368 * assert the reset. If integer or fractional mode is set the PM controller will
1369 * ensure that the complete PLL programming sequence is satisfied. After this
1370 * function returns success the PLL is locked and its bypass is deasserted.
1371 *
1372 * @return Error if an argument is not valid or status as returned by the
1373 * PM controller (PMU)
1374 */
1375enum pm_ret_status pm_pll_set_mode(enum pm_node_id nid, enum pm_pll_mode mode)
1376{
1377 uint32_t payload[PAYLOAD_ARG_CNT];
1378
1379 /* Check if given node ID is a PLL node */
1380 if (nid < NODE_APLL || nid > NODE_IOPLL)
1381 return PM_RET_ERROR_ARGS;
1382
1383 /* Check if PLL mode is valid */
1384 if (mode >= PM_PLL_MODE_MAX)
1385 return PM_RET_ERROR_ARGS;
1386
1387 /* Send request to the PMU */
1388 PM_PACK_PAYLOAD3(payload, PM_PLL_SET_MODE, nid, mode);
1389 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1390}
Jolly Shah141421e2019-01-04 11:35:48 -08001391
1392/**
1393 * pm_pll_get_mode() - Get the PLL mode
1394 * @nid Node id of the target PLL
1395 * @mode Location to store the mode of the PLL
1396 *
1397 * @return Error if an argument is not valid or status as returned by the
1398 * PM controller (PMU)
1399 */
1400enum pm_ret_status pm_pll_get_mode(enum pm_node_id nid, enum pm_pll_mode *mode)
1401{
1402 uint32_t payload[PAYLOAD_ARG_CNT];
1403
1404 /* Check if given node ID is a PLL node */
1405 if (nid < NODE_APLL || nid > NODE_IOPLL)
1406 return PM_RET_ERROR_ARGS;
1407
1408 /* Send request to the PMU */
1409 PM_PACK_PAYLOAD2(payload, PM_PLL_GET_MODE, nid);
1410 return pm_ipi_send_sync(primary_proc, payload, mode, 1);
1411}