blob: fe5828edd94f58b501b773efa6b1771b63e98fbe [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{
935 return pm_api_clock_getstate(clock_id, state);
936}
937
938/**
939 * pm_clock_setdivider - Set the clock divider for given id
940 * @clock_id: Id of the clock
941 * @divider: divider value
942 *
943 * This function is used by master to set divider for any clock
944 * to achieve desired rate.
945 *
946 * Return: Returns status, either success or error+reason.
947 */
948enum pm_ret_status pm_clock_setdivider(unsigned int clock_id,
949 unsigned int divider)
950{
951 return pm_api_clock_setdivider(clock_id, divider);
952}
953
954/**
955 * pm_clock_getdivider - Get 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 get divider values
960 * for any clock.
961 *
962 * Return: Returns status, either success or error+reason.
963 */
964enum pm_ret_status pm_clock_getdivider(unsigned int clock_id,
965 unsigned int *divider)
966{
967 return pm_api_clock_getdivider(clock_id, divider);
968}
969
970/**
971 * pm_clock_setrate - Set the clock rate for given id
972 * @clock_id: Id of the clock
973 * @rate: rate value in hz
974 *
975 * This function is used by master to set rate for any clock.
976 *
977 * Return: Returns status, either success or error+reason.
978 */
979enum pm_ret_status pm_clock_setrate(unsigned int clock_id,
980 uint64_t rate)
981{
982 return pm_api_clock_setrate(clock_id, rate);
983}
984
985/**
986 * pm_clock_getrate - Get the clock rate for given id
987 * @clock_id: Id of the clock
988 * @rate: rate value in hz
989 *
990 * This function is used by master to get rate
991 * for any clock.
992 *
993 * Return: Returns status, either success or error+reason.
994 */
995enum pm_ret_status pm_clock_getrate(unsigned int clock_id,
996 uint64_t *rate)
997{
998 return pm_api_clock_getrate(clock_id, rate);
999}
1000
1001/**
1002 * pm_clock_setparent - Set the clock parent for given id
1003 * @clock_id: Id of the clock
1004 * @parent_id: parent id
1005 *
1006 * This function is used by master to set parent for any clock.
1007 *
1008 * Return: Returns status, either success or error+reason.
1009 */
1010enum pm_ret_status pm_clock_setparent(unsigned int clock_id,
1011 unsigned int parent_id)
1012{
1013 return pm_api_clock_setparent(clock_id, parent_id);
1014}
1015
1016/**
1017 * pm_clock_getparent - Get the clock parent for given id
1018 * @clock_id: Id of the clock
1019 * @parent_id: parent id
1020 *
1021 * This function is used by master to get parent index
1022 * for any clock.
1023 *
1024 * Return: Returns status, either success or error+reason.
1025 */
1026enum pm_ret_status pm_clock_getparent(unsigned int clock_id,
1027 unsigned int *parent_id)
1028{
1029 return pm_api_clock_getparent(clock_id, parent_id);
1030}
1031
1032/**
Rajan Vajad5dd8362018-01-30 04:16:31 -08001033 * pm_pinctrl_get_num_pins - PM call to request number of pins
1034 * @npins: Number of pins
1035 *
1036 * This function is used by master to get number of pins
1037 *
1038 * Return: Returns status, either success or error+reason.
1039 */
1040static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins)
1041{
1042 return pm_api_pinctrl_get_num_pins(npins);
1043}
1044
1045/**
1046 * pm_pinctrl_get_num_functions - PM call to request number of functions
1047 * @nfuncs: Number of functions
1048 *
1049 * This function is used by master to get number of functions
1050 *
1051 * Return: Returns status, either success or error+reason.
1052 */
1053static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs)
1054{
1055 return pm_api_pinctrl_get_num_functions(nfuncs);
1056}
1057
1058/**
1059 * pm_pinctrl_get_num_function_groups - PM call to request number of
1060 * function groups
1061 * @fid: Id of function
1062 * @ngroups: Number of function groups
1063 *
1064 * This function is used by master to get number of function groups specified
1065 * by given function Id
1066 *
1067 * Return: Returns status, either success or error+reason.
1068 */
1069static enum pm_ret_status pm_pinctrl_get_num_function_groups(unsigned int fid,
1070 uint32_t *ngroups)
1071{
1072 return pm_api_pinctrl_get_num_func_groups(fid, ngroups);
1073}
1074
1075/**
1076 * pm_pinctrl_get_function_name - PM call to request function name
1077 * @fid: Id of function
1078 * @name: Name of function
1079 *
1080 * This function is used by master to get name of function 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_function_name(unsigned int fid,
1086 char *name)
1087{
1088 return pm_api_pinctrl_get_function_name(fid, name);
1089}
1090
1091/**
1092 * pm_pinctrl_get_function_groups - PM call to request function groups
1093 * @fid: Id of function
1094 * @index: Index of next function groups
1095 * @groups: Function groups
1096 *
1097 * This function is used by master to get function groups specified
1098 * by given function Id. This API will return 6 function groups with
1099 * a single response. To get other function groups, master should call
1100 * same API in loop with new function groups index till error is returned.
1101 *
1102 * E.g First call should have index 0 which will return function groups
1103 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1104 * function groups 6, 7, 8, 9, 10 and 11 and so on.
1105 *
1106 * Return: Returns status, either success or error+reason.
1107 */
1108static enum pm_ret_status pm_pinctrl_get_function_groups(unsigned int fid,
1109 unsigned int index,
1110 uint16_t *groups)
1111{
1112 return pm_api_pinctrl_get_function_groups(fid, index, groups);
1113}
1114
1115/**
1116 * pm_pinctrl_get_pin_groups - PM call to request pin groups
1117 * @pin_id: Id of pin
1118 * @index: Index of next pin groups
1119 * @groups: pin groups
1120 *
1121 * This function is used by master to get pin groups specified
1122 * by given pin Id. This API will return 6 pin groups with
1123 * a single response. To get other pin groups, master should call
1124 * same API in loop with new pin groups index till error is returned.
1125 *
1126 * E.g First call should have index 0 which will return pin groups
1127 * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
1128 * pin groups 6, 7, 8, 9, 10 and 11 and so on.
1129 *
1130 * Return: Returns status, either success or error+reason.
1131 */
1132static enum pm_ret_status pm_pinctrl_get_pin_groups(unsigned int pin_id,
1133 unsigned int index,
1134 uint16_t *groups)
1135{
1136 return pm_api_pinctrl_get_pin_groups(pin_id, index, groups);
1137}
1138
1139/**
Rajan Vaja35116132018-01-17 02:39:25 -08001140 * pm_query_data() - PM API for querying firmware data
1141 * @arg1 Argument 1 to requested IOCTL call
1142 * @arg2 Argument 2 to requested IOCTL call
1143 * @arg3 Argument 3 to requested IOCTL call
1144 * @arg4 Argument 4 to requested IOCTL call
1145 * @data Returned output data
1146 *
1147 * This function returns requested data.
1148 *
1149 * @return Returns status, either success or error+reason
1150 */
1151enum pm_ret_status pm_query_data(enum pm_query_id qid,
1152 unsigned int arg1,
1153 unsigned int arg2,
1154 unsigned int arg3,
1155 unsigned int *data)
1156{
1157 enum pm_ret_status ret;
1158
1159 switch (qid) {
1160 case PM_QID_CLOCK_GET_NAME:
1161 ret = pm_clock_get_name(arg1, (char *)data);
1162 break;
1163 case PM_QID_CLOCK_GET_TOPOLOGY:
1164 ret = pm_clock_get_topology(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001165 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001166 break;
1167 case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
1168 ret = pm_clock_get_fixedfactor_params(arg1, &data[1], &data[2]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001169 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001170 break;
1171 case PM_QID_CLOCK_GET_PARENTS:
1172 ret = pm_clock_get_parents(arg1, arg2, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001173 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001174 break;
1175 case PM_QID_CLOCK_GET_ATTRIBUTES:
1176 ret = pm_clock_get_attributes(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001177 data[0] = (unsigned int)ret;
Rajan Vaja35116132018-01-17 02:39:25 -08001178 break;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001179 case PM_QID_PINCTRL_GET_NUM_PINS:
1180 ret = pm_pinctrl_get_num_pins(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001181 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001182 break;
1183 case PM_QID_PINCTRL_GET_NUM_FUNCTIONS:
1184 ret = pm_pinctrl_get_num_functions(&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001185 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001186 break;
1187 case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS:
1188 ret = pm_pinctrl_get_num_function_groups(arg1, &data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001189 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001190 break;
1191 case PM_QID_PINCTRL_GET_FUNCTION_NAME:
1192 ret = pm_pinctrl_get_function_name(arg1, (char *)data);
1193 break;
1194 case PM_QID_PINCTRL_GET_FUNCTION_GROUPS:
1195 ret = pm_pinctrl_get_function_groups(arg1, arg2,
1196 (uint16_t *)&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_PIN_GROUPS:
1200 ret = pm_pinctrl_get_pin_groups(arg1, arg2,
1201 (uint16_t *)&data[1]);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001202 data[0] = (unsigned int)ret;
Rajan Vajad5dd8362018-01-30 04:16:31 -08001203 break;
Rajan Vajada959402018-07-20 03:16:27 -07001204 case PM_QID_CLOCK_GET_NUM_CLOCKS:
1205 ret = pm_clock_get_num_clocks(&data[1]);
1206 data[0] = (unsigned int)ret;
1207 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001208 default:
1209 ret = PM_RET_ERROR_ARGS;
1210 WARN("Unimplemented query service call: 0x%x\n", qid);
Jolly Shah69fb5bf2018-02-07 16:25:41 -08001211 break;
Rajan Vaja35116132018-01-17 02:39:25 -08001212 }
1213
1214 return ret;
1215}
Siva Durga Prasad Paladuguf3994cc2018-05-01 11:12:55 +05301216
1217enum pm_ret_status pm_sha_hash(uint32_t address_high,
1218 uint32_t address_low,
1219 uint32_t size,
1220 uint32_t flags)
1221{
1222 uint32_t payload[PAYLOAD_ARG_CNT];
1223
1224 /* Send request to the PMU */
1225 PM_PACK_PAYLOAD5(payload, PM_SECURE_SHA, address_high, address_low,
1226 size, flags);
1227 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1228}
1229
1230enum pm_ret_status pm_rsa_core(uint32_t address_high,
1231 uint32_t address_low,
1232 uint32_t size,
1233 uint32_t flags)
1234{
1235 uint32_t payload[PAYLOAD_ARG_CNT];
1236
1237 /* Send request to the PMU */
1238 PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA, address_high, address_low,
1239 size, flags);
1240 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1241}
Siva Durga Prasad Paladugua4ed4b22018-04-30 20:06:58 +05301242
1243enum pm_ret_status pm_secure_image(uint32_t address_low,
1244 uint32_t address_high,
1245 uint32_t key_lo,
1246 uint32_t key_hi,
1247 uint32_t *value)
1248{
1249 uint32_t payload[PAYLOAD_ARG_CNT];
1250
1251 /* Send request to the PMU */
1252 PM_PACK_PAYLOAD5(payload, PM_SECURE_IMAGE, address_high, address_low,
1253 key_hi, key_lo);
1254 return pm_ipi_send_sync(primary_proc, payload, value, 2);
1255}
Siva Durga Prasad Paladugu7c6516a2018-09-04 17:41:34 +05301256
1257/**
1258 * pm_fpga_read - Perform the fpga configuration readback
1259 *
1260 * @reg_numframes: Configuration register offset (or) Number of frames to read
1261 * @address_low: lower 32-bit Linear memory space address
1262 * @address_high: higher 32-bit Linear memory space address
1263 * @readback_type: Type of fpga readback operation
1264 * 0 -- Configuration Register readback
1265 * 1 -- Configuration Data readback
1266 * @value: Value to read
1267 *
1268 * This function provides access to the xilfpga library to read
1269 * the PL configuration.
1270 *
1271 * Return: Returns status, either success or error+reason.
1272 */
1273enum pm_ret_status pm_fpga_read(uint32_t reg_numframes,
1274 uint32_t address_low,
1275 uint32_t address_high,
1276 uint32_t readback_type,
1277 uint32_t *value)
1278{
1279 uint32_t payload[PAYLOAD_ARG_CNT];
1280
1281 /* Send request to the PMU */
1282 PM_PACK_PAYLOAD5(payload, PM_FPGA_READ, reg_numframes, address_low,
1283 address_high, readback_type);
1284 return pm_ipi_send_sync(primary_proc, payload, value, 1);
1285}
Jolly Shaha7cc5ee2019-01-02 12:27:00 -08001286
1287/*
1288 * pm_pll_set_parameter() - Set the PLL parameter value
1289 * @nid Node id of the target PLL
1290 * @param_id ID of the PLL parameter
1291 * @value Parameter value to be set
1292 *
1293 * Setting the parameter will have physical effect once the PLL mode is set to
1294 * integer or fractional.
1295 *
1296 * @return Error if an argument is not valid or status as returned by the
1297 * PM controller (PMU)
1298 */
1299enum pm_ret_status pm_pll_set_parameter(enum pm_node_id nid,
1300 enum pm_pll_param param_id,
1301 unsigned int value)
1302{
1303 uint32_t payload[PAYLOAD_ARG_CNT];
1304
1305 /* Check if given node ID is a PLL node */
1306 if (nid < NODE_APLL || nid > NODE_IOPLL)
1307 return PM_RET_ERROR_ARGS;
1308
1309 /* Check if parameter ID is valid and return an error if it's not */
1310 if (param_id >= PM_PLL_PARAM_MAX)
1311 return PM_RET_ERROR_ARGS;
1312
1313 /* Send request to the PMU */
1314 PM_PACK_PAYLOAD4(payload, PM_PLL_SET_PARAMETER, nid, param_id, value);
1315 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1316}
Jolly Shahcb2f45d2019-01-04 11:28:38 -08001317
1318/**
1319 * pm_pll_get_parameter() - Get the PLL parameter value
1320 * @nid Node id of the target PLL
1321 * @param_id ID of the PLL parameter
1322 * @value Location to store the parameter value
1323 *
1324 * @return Error if an argument is not valid or status as returned by the
1325 * PM controller (PMU)
1326 */
1327enum pm_ret_status pm_pll_get_parameter(enum pm_node_id nid,
1328 enum pm_pll_param param_id,
1329 unsigned int *value)
1330{
1331 uint32_t payload[PAYLOAD_ARG_CNT];
1332
1333 /* Check if given node ID is a PLL node */
1334 if (nid < NODE_APLL || nid > NODE_IOPLL)
1335 return PM_RET_ERROR_ARGS;
1336
1337 /* Check if parameter ID is valid and return an error if it's not */
1338 if (param_id >= PM_PLL_PARAM_MAX)
1339 return PM_RET_ERROR_ARGS;
1340
1341 /* Send request to the PMU */
1342 PM_PACK_PAYLOAD3(payload, PM_PLL_GET_PARAMETER, nid, param_id);
1343 return pm_ipi_send_sync(primary_proc, payload, value, 1);
1344}
Jolly Shah1f0d5852019-01-04 11:32:31 -08001345
1346/**
1347 * pm_pll_set_mode() - Set the PLL mode
1348 * @nid Node id of the target PLL
1349 * @mode PLL mode to be set
1350 *
1351 * If reset mode is set the PM controller will first bypass the PLL and then
1352 * assert the reset. If integer or fractional mode is set the PM controller will
1353 * ensure that the complete PLL programming sequence is satisfied. After this
1354 * function returns success the PLL is locked and its bypass is deasserted.
1355 *
1356 * @return Error if an argument is not valid or status as returned by the
1357 * PM controller (PMU)
1358 */
1359enum pm_ret_status pm_pll_set_mode(enum pm_node_id nid, enum pm_pll_mode mode)
1360{
1361 uint32_t payload[PAYLOAD_ARG_CNT];
1362
1363 /* Check if given node ID is a PLL node */
1364 if (nid < NODE_APLL || nid > NODE_IOPLL)
1365 return PM_RET_ERROR_ARGS;
1366
1367 /* Check if PLL mode is valid */
1368 if (mode >= PM_PLL_MODE_MAX)
1369 return PM_RET_ERROR_ARGS;
1370
1371 /* Send request to the PMU */
1372 PM_PACK_PAYLOAD3(payload, PM_PLL_SET_MODE, nid, mode);
1373 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1374}
Jolly Shah141421e2019-01-04 11:35:48 -08001375
1376/**
1377 * pm_pll_get_mode() - Get the PLL mode
1378 * @nid Node id of the target PLL
1379 * @mode Location to store the mode of the PLL
1380 *
1381 * @return Error if an argument is not valid or status as returned by the
1382 * PM controller (PMU)
1383 */
1384enum pm_ret_status pm_pll_get_mode(enum pm_node_id nid, enum pm_pll_mode *mode)
1385{
1386 uint32_t payload[PAYLOAD_ARG_CNT];
1387
1388 /* Check if given node ID is a PLL node */
1389 if (nid < NODE_APLL || nid > NODE_IOPLL)
1390 return PM_RET_ERROR_ARGS;
1391
1392 /* Send request to the PMU */
1393 PM_PACK_PAYLOAD2(payload, PM_PLL_GET_MODE, nid);
1394 return pm_ipi_send_sync(primary_proc, payload, mode, 1);
1395}