blob: 4fe35534fcf7864927fbc375b71b9b04df7774c8 [file] [log] [blame]
Tejas Patel9d09ff92019-01-08 01:46:35 -08001/*
Venkatesh Yadav Abbarapu95ecd452019-12-10 22:16:36 -05002 * Copyright (c) 2019-2020, Xilinx, Inc. All rights reserved.
Tejas Patel9d09ff92019-01-08 01:46:35 -08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
8 * Versal system level PM-API functions and communication with PMC via
9 * IPI interrupts
10 */
11
12#include <pm_common.h>
13#include <pm_ipi.h>
Tejas Patelfe0e10a2019-12-08 23:29:44 -080014#include <plat/common/platform.h>
Tejas Patel9d09ff92019-01-08 01:46:35 -080015#include "pm_api_sys.h"
16#include "pm_client.h"
Rajan Vaja030620d2020-11-23 04:13:54 -080017#include "pm_defs.h"
Shubhrajyoti Dattaabf61222021-03-17 23:01:17 +053018#include "pm_svc_main.h"
Tejas Patel9d09ff92019-01-08 01:46:35 -080019
20/*********************************************************************
21 * Target module IDs macros
22 ********************************************************************/
23#define LIBPM_MODULE_ID 0x2
24#define LOADER_MODULE_ID 0x7
25
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -080026/* default shutdown/reboot scope is system(2) */
27static unsigned int pm_shutdown_scope = XPM_SHUTDOWN_SUBTYPE_RST_SYSTEM;
28
29/**
30 * pm_get_shutdown_scope() - Get the currently set shutdown scope
31 *
32 * @return Shutdown scope value
33 */
34unsigned int pm_get_shutdown_scope(void)
35{
36 return pm_shutdown_scope;
37}
38
Tejas Patel9d09ff92019-01-08 01:46:35 -080039/**
40 * Assigning of argument values into array elements.
41 */
Tejas Patel18072da2021-02-25 20:16:56 -080042#define PM_PACK_PAYLOAD1(pl, mid, flag, arg0) { \
43 pl[0] = (uint32_t)((uint32_t)((arg0) & 0xFF) | (mid << 8) | ((flag) << 24)); \
Tejas Patel9d09ff92019-01-08 01:46:35 -080044}
45
Tejas Patel18072da2021-02-25 20:16:56 -080046#define PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1) { \
47 pl[1] = (uint32_t)(arg1); \
48 PM_PACK_PAYLOAD1(pl, mid, flag, arg0); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080049}
50
Tejas Patel18072da2021-02-25 20:16:56 -080051#define PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2) { \
52 pl[2] = (uint32_t)(arg2); \
53 PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080054}
55
Tejas Patel18072da2021-02-25 20:16:56 -080056#define PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3) { \
57 pl[3] = (uint32_t)(arg3); \
58 PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080059}
60
Tejas Patel18072da2021-02-25 20:16:56 -080061#define PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4) { \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080062 pl[4] = (uint32_t)(arg4); \
Tejas Patel18072da2021-02-25 20:16:56 -080063 PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080064}
65
Tejas Patel18072da2021-02-25 20:16:56 -080066#define PM_PACK_PAYLOAD6(pl, mid, flag, arg0, arg1, arg2, arg3, arg4, arg5) { \
67 pl[5] = (uint32_t)(arg5); \
68 PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080069}
70
Tejas Patel9d09ff92019-01-08 01:46:35 -080071/* PM API functions */
72
73/**
74 * pm_get_api_version() - Get version number of PMC PM firmware
75 * @version Returns 32-bit version number of PMC Power Management Firmware
Tejas Patel18072da2021-02-25 20:16:56 -080076 * @flag 0 - Call from secure source
77 * 1 - Call from non-secure source
Tejas Patel9d09ff92019-01-08 01:46:35 -080078 *
79 * @return Returns status, either success or error+reason
80 */
Tejas Patel18072da2021-02-25 20:16:56 -080081enum pm_ret_status pm_get_api_version(unsigned int *version, uint32_t flag)
Tejas Patel9d09ff92019-01-08 01:46:35 -080082{
83 uint32_t payload[PAYLOAD_ARG_CNT];
84
85 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -080086 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_API_VERSION);
Tejas Patel9d09ff92019-01-08 01:46:35 -080087 return pm_ipi_send_sync(primary_proc, payload, version, 1);
88}
Tejas Patelfe0e10a2019-12-08 23:29:44 -080089
90/**
Ravi Patel476b5b12019-08-12 03:10:10 -070091 * pm_init_finalize() - Call to notify PMC PM firmware that master has power
92 * management enabled and that it has finished its
93 * initialization
Tejas Patel18072da2021-02-25 20:16:56 -080094 * @flag 0 - Call from secure source
95 * 1 - Call from non-secure source
Ravi Patel476b5b12019-08-12 03:10:10 -070096 *
97 * @return Status returned by the PMU firmware
98 */
Tejas Patel18072da2021-02-25 20:16:56 -080099enum pm_ret_status pm_init_finalize(uint32_t flag)
Ravi Patel476b5b12019-08-12 03:10:10 -0700100{
101 uint32_t payload[PAYLOAD_ARG_CNT];
102
103 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800104 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_INIT_FINALIZE);
Ravi Patel476b5b12019-08-12 03:10:10 -0700105 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
106}
107
108/**
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800109 * pm_self_suspend() - PM call for processor to suspend itself
110 * @nid Node id of the processor or subsystem
111 * @latency Requested maximum wakeup latency (not supported)
112 * @state Requested state
113 * @address Resume address
Tejas Patel18072da2021-02-25 20:16:56 -0800114 * @flag 0 - Call from secure source
115 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800116 *
117 * This is a blocking call, it will return only once PMU has responded.
118 * On a wakeup, resume address will be automatically set by PMU.
119 *
120 * @return Returns status, either success or error+reason
121 */
122enum pm_ret_status pm_self_suspend(uint32_t nid,
123 unsigned int latency,
124 unsigned int state,
Tejas Patel18072da2021-02-25 20:16:56 -0800125 uintptr_t address, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800126{
127 uint32_t payload[PAYLOAD_ARG_CNT];
128 unsigned int cpuid = plat_my_core_pos();
129 const struct pm_proc *proc = pm_get_proc(cpuid);
130
131 if (!proc) {
132 WARN("Failed to get proc %d\n", cpuid);
133 return PM_RET_ERROR_INTERNAL;
134 }
135
136 /*
137 * Do client specific suspend operations
138 * (e.g. set powerdown request bit)
139 */
140 pm_client_suspend(proc, state);
141
142 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -0800143 PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, flag, PM_SELF_SUSPEND,
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800144 proc->node_id, latency, state, address,
145 (address >> 32));
146 return pm_ipi_send_sync(proc, payload, NULL, 0);
147}
148
149/**
150 * pm_abort_suspend() - PM call to announce that a prior suspend request
151 * is to be aborted.
152 * @reason Reason for the abort
Tejas Patel18072da2021-02-25 20:16:56 -0800153 * @flag 0 - Call from secure source
154 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800155 *
156 * Calling PU expects the PMU to abort the initiated suspend procedure.
157 * This is a non-blocking call without any acknowledge.
158 *
159 * @return Returns status, either success or error+reason
160 */
Tejas Patel18072da2021-02-25 20:16:56 -0800161enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800162{
163 uint32_t payload[PAYLOAD_ARG_CNT];
164
165 /*
166 * Do client specific abort suspend operations
167 * (e.g. enable interrupts and clear powerdown request bit)
168 */
169 pm_client_abort_suspend();
170
171 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -0800172 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_ABORT_SUSPEND,
173 reason, primary_proc->node_id);
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800174 return pm_ipi_send(primary_proc, payload);
175}
176
177/**
178 * pm_req_suspend() - PM call to request for another PU or subsystem to
179 * be suspended gracefully.
180 * @target Node id of the targeted PU or subsystem
181 * @ack Flag to specify whether acknowledge is requested
182 * @latency Requested wakeup latency (not supported)
183 * @state Requested state (not supported)
Tejas Patel18072da2021-02-25 20:16:56 -0800184 * @flag 0 - Call from secure source
185 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800186 *
187 * @return Returns status, either success or error+reason
188 */
189enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack,
Tejas Patel18072da2021-02-25 20:16:56 -0800190 unsigned int latency, unsigned int state,
191 uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800192{
193 uint32_t payload[PAYLOAD_ARG_CNT];
194
195 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800196 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_REQ_SUSPEND, target,
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800197 latency, state);
198 if (ack == IPI_BLOCKING)
199 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
200 else
201 return pm_ipi_send(primary_proc, payload);
202}
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800203
204/**
Tejas Patel49cd8712019-01-23 14:18:51 +0530205 * pm_req_wakeup() - PM call for processor to wake up selected processor
206 * or subsystem
207 * @target Device ID of the processor or subsystem to wake up
208 * @set_address Resume address presence indicator
209 * 1 - resume address specified, 0 - otherwise
210 * @address Resume address
211 * @ack Flag to specify whether acknowledge requested
Tejas Patel18072da2021-02-25 20:16:56 -0800212 * @flag 0 - Call from secure source
213 * 1 - Call from non-secure source
Tejas Patel49cd8712019-01-23 14:18:51 +0530214 *
215 * This API function is either used to power up another APU core for SMP
216 * (by PSCI) or to power up an entirely different PU or subsystem, such
217 * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be
218 * automatically set by PMC.
219 *
220 * @return Returns status, either success or error+reason
221 */
222enum pm_ret_status pm_req_wakeup(uint32_t target, uint32_t set_address,
Tejas Patel18072da2021-02-25 20:16:56 -0800223 uintptr_t address, uint8_t ack, uint32_t flag)
Tejas Patel49cd8712019-01-23 14:18:51 +0530224{
225 uint32_t payload[PAYLOAD_ARG_CNT];
226
227 /* Send request to the PMC to perform the wake of the PU */
Tejas Patel18072da2021-02-25 20:16:56 -0800228 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQ_WAKEUP, target,
Tejas Patel49cd8712019-01-23 14:18:51 +0530229 set_address, address, ack);
230
231 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
232}
233
234/**
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800235 * pm_request_device() - Request a device
236 * @device_id Device ID
237 * @capabilities Requested capabilities for the device
238 * @qos Required Quality of Service
239 * @ack Flag to specify whether acknowledge requested
Tejas Patel18072da2021-02-25 20:16:56 -0800240 * @flag 0 - Call from secure source
241 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800242 *
243 * @return Returns status, either success or error+reason
244 */
245enum pm_ret_status pm_request_device(uint32_t device_id, uint32_t capabilities,
Tejas Patel18072da2021-02-25 20:16:56 -0800246 uint32_t qos, uint32_t ack, uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800247{
248 uint32_t payload[PAYLOAD_ARG_CNT];
249
250 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800251 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQUEST_DEVICE,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800252 device_id, capabilities, qos, ack);
253
254 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
255}
256
257/**
258 * pm_release_device() - Release a device
259 * @device_id Device ID
Tejas Patel18072da2021-02-25 20:16:56 -0800260 * @flag 0 - Call from secure source
261 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800262 *
263 * @return Returns status, either success or error+reason
264 */
Tejas Patel18072da2021-02-25 20:16:56 -0800265enum pm_ret_status pm_release_device(uint32_t device_id, uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800266{
267 uint32_t payload[PAYLOAD_ARG_CNT];
268
269 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800270 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RELEASE_DEVICE,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800271 device_id);
272
273 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
274}
275
276/**
277 * pm_set_requirement() - Set requirement for the device
278 * @device_id Device ID
279 * @capabilities Requested capabilities for the device
280 * @latency Requested maximum latency
281 * @qos Required Quality of Service
Tejas Patel18072da2021-02-25 20:16:56 -0800282 * @flag 0 - Call from secure source
283 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800284 *
285 * @return Returns status, either success or error+reason
286 */
287enum pm_ret_status pm_set_requirement(uint32_t device_id, uint32_t capabilities,
Tejas Patel18072da2021-02-25 20:16:56 -0800288 uint32_t latency, uint32_t qos,
289 uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800290{
291 uint32_t payload[PAYLOAD_ARG_CNT];
292
293 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800294 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_SET_REQUIREMENT,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800295 device_id, capabilities, latency, qos);
296
297 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
298}
299
300/**
301 * pm_get_device_status() - Get device's status
302 * @device_id Device ID
303 * @response Buffer to store device status response
Tejas Patel18072da2021-02-25 20:16:56 -0800304 * @flag 0 - Call from secure source
305 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800306 *
307 * @return Returns status, either success or error+reason
308 */
Tejas Patel18072da2021-02-25 20:16:56 -0800309enum pm_ret_status pm_get_device_status(uint32_t device_id, uint32_t *response,
310 uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800311{
312 uint32_t payload[PAYLOAD_ARG_CNT];
313
314 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800315 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_GET_DEVICE_STATUS,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800316 device_id);
317
318 return pm_ipi_send_sync(primary_proc, payload, response, 3);
319}
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800320
321/**
322 * pm_reset_assert() - Assert/De-assert reset
323 * @reset Reset ID
324 * @assert Assert (1) or de-assert (0)
Tejas Patel18072da2021-02-25 20:16:56 -0800325 * @flag 0 - Call from secure source
326 * 1 - Call from non-secure source
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800327 *
328 * @return Returns status, either success or error+reason
329 */
Tejas Patel18072da2021-02-25 20:16:56 -0800330enum pm_ret_status pm_reset_assert(uint32_t reset, bool assert, uint32_t flag)
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800331{
332 uint32_t payload[PAYLOAD_ARG_CNT];
333
334 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800335 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT, reset,
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800336 assert);
337
338 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
339}
340
341/**
342 * pm_reset_get_status() - Get current status of a reset line
343 * @reset Reset ID
344 * @status Returns current status of selected reset ID
Tejas Patel18072da2021-02-25 20:16:56 -0800345 * @flag 0 - Call from secure source
346 * 1 - Call from non-secure source
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800347 *
348 * @return Returns status, either success or error+reason
349 */
Tejas Patel18072da2021-02-25 20:16:56 -0800350enum pm_ret_status pm_reset_get_status(uint32_t reset, uint32_t *status,
351 uint32_t flag)
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800352{
353 uint32_t payload[PAYLOAD_ARG_CNT];
354
355 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800356 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT,
357 reset);
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800358
359 return pm_ipi_send_sync(primary_proc, payload, status, 1);
360}
Tejas Patel20e92022019-01-08 01:46:39 -0800361
362/**
Rajan Vaja649e9242019-03-04 11:09:40 +0530363 * pm_get_callbackdata() - Read from IPI response buffer
364 * @data - array of PAYLOAD_ARG_CNT elements
Tejas Patel18072da2021-02-25 20:16:56 -0800365 * @flag - 0 - Call from secure source
366 * 1 - Call from non-secure source
Rajan Vaja649e9242019-03-04 11:09:40 +0530367 *
368 * Read value from ipi buffer response buffer.
369 */
Tejas Patel18072da2021-02-25 20:16:56 -0800370void pm_get_callbackdata(uint32_t *data, size_t count, uint32_t flag)
Rajan Vaja649e9242019-03-04 11:09:40 +0530371{
372 /* Return if interrupt is not from PMU */
373 if (!pm_ipi_irq_status(primary_proc))
374 return;
375
376 pm_ipi_buff_read_callb(data, count);
377 pm_ipi_irq_clear(primary_proc);
378}
379
380/**
Tejas Patel20e92022019-01-08 01:46:39 -0800381 * pm_pinctrl_request() - Request a pin
382 * @pin Pin ID
Tejas Patel18072da2021-02-25 20:16:56 -0800383 * @flag 0 - Call from secure source
384 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800385 *
386 * @return Returns status, either success or error+reason
387 */
Tejas Patel18072da2021-02-25 20:16:56 -0800388enum pm_ret_status pm_pinctrl_request(uint32_t pin, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800389{
390 uint32_t payload[PAYLOAD_ARG_CNT];
391
392 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800393 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_REQUEST,
394 pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800395
396 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
397}
398
399/**
400 * pm_pinctrl_release() - Release a pin
401 * @pin Pin ID
Tejas Patel18072da2021-02-25 20:16:56 -0800402 * @flag 0 - Call from secure source
403 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800404 *
405 * @return Returns status, either success or error+reason
406 */
Tejas Patel18072da2021-02-25 20:16:56 -0800407enum pm_ret_status pm_pinctrl_release(uint32_t pin, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800408{
409 uint32_t payload[PAYLOAD_ARG_CNT];
410
411 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800412 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_RELEASE,
413 pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800414
415 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
416}
417
418/**
419 * pm_pinctrl_set_function() - Set pin function
420 * @pin Pin ID
421 * @function Function ID
Tejas Patel18072da2021-02-25 20:16:56 -0800422 * @flag 0 - Call from secure source
423 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800424 *
425 * @return Returns status, either success or error+reason
426 */
Tejas Patel18072da2021-02-25 20:16:56 -0800427enum pm_ret_status pm_pinctrl_set_function(uint32_t pin, uint32_t function,
428 uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800429{
430 uint32_t payload[PAYLOAD_ARG_CNT];
431
432 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800433 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
434 PM_PINCTRL_SET_FUNCTION, pin, function)
Tejas Patel20e92022019-01-08 01:46:39 -0800435
436 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
437}
438
439/**
440 * pm_pinctrl_get_function() - Get function set on the pin
441 * @pin Pin ID
442 * @function Function set on the pin
Tejas Patel18072da2021-02-25 20:16:56 -0800443 * @flag 0 - Call from secure source
444 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800445 *
446 * @return Returns status, either success or error+reason
447 */
Tejas Patel18072da2021-02-25 20:16:56 -0800448enum pm_ret_status pm_pinctrl_get_function(uint32_t pin, uint32_t *function,
449 uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800450{
451 uint32_t payload[PAYLOAD_ARG_CNT];
452
453 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800454 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag,
455 PM_PINCTRL_SET_FUNCTION, pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800456
457 return pm_ipi_send_sync(primary_proc, payload, function, 1);
458}
459
460/**
461 * pm_pinctrl_set_pin_param() - Set configuration parameter for the pin
462 * @pin Pin ID
463 * @param Parameter ID
464 * @value Parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800465 * @flag 0 - Call from secure source
466 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800467 *
468 * @return Returns status, either success or error+reason
469 */
470enum pm_ret_status pm_pinctrl_set_pin_param(uint32_t pin, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800471 uint32_t value, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800472{
473 uint32_t payload[PAYLOAD_ARG_CNT];
474
475 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800476 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag,
477 PM_PINCTRL_CONFIG_PARAM_SET, pin, param, value);
Tejas Patel20e92022019-01-08 01:46:39 -0800478
479 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
480}
481
482/**
483 * pm_pinctrl_get_pin_param() - Get configuration parameter value for the pin
484 * @pin Pin ID
485 * @param Parameter ID
486 * @value Buffer to store parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800487 * @flag 0 - Call from secure source
488 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800489 *
490 * @return Returns status, either success or error+reason
491 */
492enum pm_ret_status pm_pinctrl_get_pin_param(uint32_t pin, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800493 uint32_t *value, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800494{
495 uint32_t payload[PAYLOAD_ARG_CNT];
496
497 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800498 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
499 PM_PINCTRL_CONFIG_PARAM_GET, pin, param);
Tejas Patel20e92022019-01-08 01:46:39 -0800500
501 return pm_ipi_send_sync(primary_proc, payload, value, 1);
502}
Tejas Patel1f56fb12019-01-08 01:46:40 -0800503
504/**
505 * pm_clock_enable() - Enable the clock
506 * @clk_id Clock ID
Tejas Patel18072da2021-02-25 20:16:56 -0800507 * @flag 0 - Call from secure source
508 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800509 *
510 * @return Returns status, either success or error+reason
511 */
Tejas Patel18072da2021-02-25 20:16:56 -0800512enum pm_ret_status pm_clock_enable(uint32_t clk_id, uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800513{
514 uint32_t payload[PAYLOAD_ARG_CNT];
515
516 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800517 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_ENABLE,
518 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800519
520 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
521}
522
523/**
524 * pm_clock_disable() - Disable the clock
525 * @clk_id Clock ID
Tejas Patel18072da2021-02-25 20:16:56 -0800526 * @flag 0 - Call from secure source
527 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800528 *
529 * @return Returns status, either success or error+reason
530 */
Tejas Patel18072da2021-02-25 20:16:56 -0800531enum pm_ret_status pm_clock_disable(uint32_t clk_id, uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800532{
533 uint32_t payload[PAYLOAD_ARG_CNT];
534
535 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800536 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_DISABLE,
537 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800538
539 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
540}
541
542/**
543 * pm_clock_get_state() - Get clock status
544 * @clk_id Clock ID
545 * @state: Buffer to store clock status (1: Enabled, 0:Disabled)
Tejas Patel18072da2021-02-25 20:16:56 -0800546 * @flag 0 - Call from secure source
547 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800548 *
549 * @return Returns status, either success or error+reason
550 */
Tejas Patel18072da2021-02-25 20:16:56 -0800551enum pm_ret_status pm_clock_get_state(uint32_t clk_id, uint32_t *state,
552 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800553{
554 uint32_t payload[PAYLOAD_ARG_CNT];
555
556 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800557 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETSTATE,
558 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800559
560 return pm_ipi_send_sync(primary_proc, payload, state, 1);
561}
562
563/**
564 * pm_clock_set_divider() - Set divider for the clock
565 * @clk_id Clock ID
566 * @divider Divider value
Tejas Patel18072da2021-02-25 20:16:56 -0800567 * @flag 0 - Call from secure source
568 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800569 *
570 * @return Returns status, either success or error+reason
571 */
Tejas Patel18072da2021-02-25 20:16:56 -0800572enum pm_ret_status pm_clock_set_divider(uint32_t clk_id, uint32_t divider,
573 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800574{
575 uint32_t payload[PAYLOAD_ARG_CNT];
576
577 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800578 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETDIVIDER,
579 clk_id, divider);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800580
581 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
582}
583
584/**
585 * pm_clock_get_divider() - Get divider value for the clock
586 * @clk_id Clock ID
587 * @divider: Buffer to store clock divider value
Tejas Patel18072da2021-02-25 20:16:56 -0800588 * @flag 0 - Call from secure source
589 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800590 *
591 * @return Returns status, either success or error+reason
592 */
Tejas Patel18072da2021-02-25 20:16:56 -0800593enum pm_ret_status pm_clock_get_divider(uint32_t clk_id, uint32_t *divider,
594 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800595{
596 uint32_t payload[PAYLOAD_ARG_CNT];
597
598 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800599 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETDIVIDER,
600 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800601
602 return pm_ipi_send_sync(primary_proc, payload, divider, 1);
603}
604
605/**
606 * pm_clock_set_parent() - Set parent for the clock
607 * @clk_id Clock ID
608 * @parent Parent ID
Tejas Patel18072da2021-02-25 20:16:56 -0800609 * @flag 0 - Call from secure source
610 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800611 *
612 * @return Returns status, either success or error+reason
613 */
Tejas Patel18072da2021-02-25 20:16:56 -0800614enum pm_ret_status pm_clock_set_parent(uint32_t clk_id, uint32_t parent,
615 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800616{
617 uint32_t payload[PAYLOAD_ARG_CNT];
618
619 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800620 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETPARENT,
621 clk_id, parent);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800622
623 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
624}
625
626/**
627 * pm_clock_get_parent() - Get parent value for the clock
628 * @clk_id Clock ID
629 * @parent: Buffer to store clock parent value
Tejas Patel18072da2021-02-25 20:16:56 -0800630 * @flag 0 - Call from secure source
631 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800632 *
633 * @return Returns status, either success or error+reason
634 */
Tejas Patel18072da2021-02-25 20:16:56 -0800635enum pm_ret_status pm_clock_get_parent(uint32_t clk_id, uint32_t *parent,
636 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800637{
638 uint32_t payload[PAYLOAD_ARG_CNT];
639
640 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800641 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETPARENT,
642 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800643
644 return pm_ipi_send_sync(primary_proc, payload, parent, 1);
645}
Tejas Patel84275bf2020-09-01 04:43:53 -0700646/**
647 * pm_clock_get_rate() - Get the rate value for the clock
648 * @clk_id Clock ID
649 * @rate: Buffer to store clock rate value
Tejas Patel18072da2021-02-25 20:16:56 -0800650 * @flag 0 - Call from secure source
651 * 1 - Call from non-secure source
Tejas Patel84275bf2020-09-01 04:43:53 -0700652 *
653 * @return Returns status, either success or error+reason
654 */
Tejas Patel18072da2021-02-25 20:16:56 -0800655enum pm_ret_status pm_clock_get_rate(uint32_t clk_id, uint32_t *clk_rate,
656 uint32_t flag)
Tejas Patel84275bf2020-09-01 04:43:53 -0700657{
658 uint32_t payload[PAYLOAD_ARG_CNT];
659
660 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800661 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETRATE,
662 clk_id);
Tejas Patel84275bf2020-09-01 04:43:53 -0700663
664 return pm_ipi_send_sync(primary_proc, payload, clk_rate, 2);
665}
Tejas Patel023116d2019-01-08 01:46:41 -0800666
667/**
668 * pm_pll_set_param() - Set PLL parameter
669 * @clk_id PLL clock ID
670 * @param PLL parameter ID
671 * @value Value to set for PLL parameter
Tejas Patel18072da2021-02-25 20:16:56 -0800672 * @flag 0 - Call from secure source
673 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800674 *
675 * @return Returns status, either success or error+reason
676 */
677enum pm_ret_status pm_pll_set_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800678 uint32_t value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800679{
680 uint32_t payload[PAYLOAD_ARG_CNT];
681
682 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800683 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_PARAMETER,
684 clk_id, param, value);
Tejas Patel023116d2019-01-08 01:46:41 -0800685
686 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
687}
688
689/**
690 * pm_pll_get_param() - Get PLL parameter value
691 * @clk_id PLL clock ID
692 * @param PLL parameter ID
693 * @value: Buffer to store PLL parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800694 * @flag 0 - Call from secure source
695 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800696 *
697 * @return Returns status, either success or error+reason
698 */
699enum pm_ret_status pm_pll_get_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800700 uint32_t *value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800701{
702 uint32_t payload[PAYLOAD_ARG_CNT];
703
704 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800705 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_PARAMETER,
706 clk_id, param);
Tejas Patel023116d2019-01-08 01:46:41 -0800707
708 return pm_ipi_send_sync(primary_proc, payload, value, 1);
709}
710
711/**
712 * pm_pll_set_mode() - Set PLL mode
713 * @clk_id PLL clock ID
714 * @mode PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800715 * @flag 0 - Call from secure source
716 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800717 *
718 * @return Returns status, either success or error+reason
719 */
Tejas Patel18072da2021-02-25 20:16:56 -0800720enum pm_ret_status pm_pll_set_mode(uint32_t clk_id, uint32_t mode,
721 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800722{
723 uint32_t payload[PAYLOAD_ARG_CNT];
724
725 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800726 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_MODE,
727 clk_id, mode);
Tejas Patel023116d2019-01-08 01:46:41 -0800728
729 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
730}
731
732/**
733 * pm_pll_get_mode() - Get PLL mode
734 * @clk_id PLL clock ID
735 * @mode: Buffer to store PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800736 * @flag 0 - Call from secure source
737 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800738 *
739 * @return Returns status, either success or error+reason
740 */
Tejas Patel18072da2021-02-25 20:16:56 -0800741enum pm_ret_status pm_pll_get_mode(uint32_t clk_id, uint32_t *mode,
742 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800743{
744 uint32_t payload[PAYLOAD_ARG_CNT];
745
746 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800747 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_MODE,
748 clk_id);
Tejas Patel023116d2019-01-08 01:46:41 -0800749
750 return pm_ipi_send_sync(primary_proc, payload, mode, 1);
751}
Tejas Patel6b282252019-01-10 03:03:47 -0800752
753/**
754 * pm_force_powerdown() - PM call to request for another PU or subsystem to
755 * be powered down forcefully
756 * @target Device ID of the PU node to be forced powered down.
757 * @ack Flag to specify whether acknowledge is requested
Tejas Patel18072da2021-02-25 20:16:56 -0800758 * @flag 0 - Call from secure source
759 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800760 *
761 * @return Returns status, either success or error+reason
762 */
Tejas Patel18072da2021-02-25 20:16:56 -0800763enum pm_ret_status pm_force_powerdown(uint32_t target, uint8_t ack,
764 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800765{
766 uint32_t payload[PAYLOAD_ARG_CNT];
767
768 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800769 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_FORCE_POWERDOWN,
770 target, ack);
Tejas Patel6b282252019-01-10 03:03:47 -0800771
772 if (ack == IPI_BLOCKING)
773 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
774 else
775 return pm_ipi_send(primary_proc, payload);
776}
777
778/**
779 * pm_system_shutdown() - PM call to request a system shutdown or restart
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800780 * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope
Tejas Patel6b282252019-01-10 03:03:47 -0800781 * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system
Tejas Patel18072da2021-02-25 20:16:56 -0800782 * @flag 0 - Call from secure source
783 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800784 *
785 * @return Returns status, either success or error+reason
786 */
Tejas Patel18072da2021-02-25 20:16:56 -0800787enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype,
788 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800789{
790 uint32_t payload[PAYLOAD_ARG_CNT];
791
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800792 if (type == XPM_SHUTDOWN_TYPE_SETSCOPE_ONLY) {
793 /* Setting scope for subsequent PSCI reboot or shutdown */
794 pm_shutdown_scope = subtype;
795 return PM_RET_SUCCESS;
796 }
797
Tejas Patel6b282252019-01-10 03:03:47 -0800798 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800799 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SYSTEM_SHUTDOWN,
800 type, subtype);
Tejas Patel6b282252019-01-10 03:03:47 -0800801
802 return pm_ipi_send_non_blocking(primary_proc, payload);
803}
Tejas Patel9141f442019-01-10 03:03:48 -0800804
805/**
Tejas Patela3e34ad2019-02-01 17:25:19 +0530806* pm_query_data() - PM API for querying firmware data
807* @qid The type of data to query
808* @arg1 Argument 1 to requested query data call
809* @arg2 Argument 2 to requested query data call
810* @arg3 Argument 3 to requested query data call
811* @data Returned output data
Tejas Patel18072da2021-02-25 20:16:56 -0800812* @flag 0 - Call from secure source
813* 1 - Call from non-secure source
Tejas Patela3e34ad2019-02-01 17:25:19 +0530814*
815* This function returns requested data.
816*/
817enum pm_ret_status pm_query_data(uint32_t qid, uint32_t arg1, uint32_t arg2,
Tejas Patel18072da2021-02-25 20:16:56 -0800818 uint32_t arg3, uint32_t *data, uint32_t flag)
Tejas Patela3e34ad2019-02-01 17:25:19 +0530819{
Rajan Vaja030620d2020-11-23 04:13:54 -0800820 uint32_t ret;
821 uint32_t version;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530822 uint32_t payload[PAYLOAD_ARG_CNT];
Rajan Vaja030620d2020-11-23 04:13:54 -0800823 uint32_t fw_api_version;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530824
825 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800826 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_QUERY_DATA, qid,
827 arg1, arg2, arg3);
Rajan Vaja030620d2020-11-23 04:13:54 -0800828
Tejas Patel18072da2021-02-25 20:16:56 -0800829 ret = pm_feature_check(PM_QUERY_DATA, &version, flag);
Manish Pandey3bc1bea2020-12-10 10:48:22 +0000830 if (PM_RET_SUCCESS == ret) {
Rajan Vaja030620d2020-11-23 04:13:54 -0800831 fw_api_version = version & 0xFFFF ;
832 if ((2U == fw_api_version) &&
833 ((XPM_QID_CLOCK_GET_NAME == qid) ||
834 (XPM_QID_PINCTRL_GET_FUNCTION_NAME == qid))) {
835 ret = pm_ipi_send_sync(primary_proc, payload, data, 8);
836 ret = data[0];
837 data[0] = data[1];
838 data[1] = data[2];
839 data[2] = data[3];
840 } else {
841 ret = pm_ipi_send_sync(primary_proc, payload, data, 4);
842 }
843 }
844 return ret;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530845}
846/**
Tejas Patel9141f442019-01-10 03:03:48 -0800847 * pm_api_ioctl() - PM IOCTL API for device control and configs
848 * @device_id Device ID
849 * @ioctl_id ID of the requested IOCTL
850 * @arg1 Argument 1 to requested IOCTL call
851 * @arg2 Argument 2 to requested IOCTL call
852 * @value Returned output value
Tejas Patel18072da2021-02-25 20:16:56 -0800853 * @flag 0 - Call from secure source
854 * 1 - Call from non-secure source
Tejas Patel9141f442019-01-10 03:03:48 -0800855 *
856 * This function calls IOCTL to firmware for device control and configuration.
857 *
858 * @return Returns status, either success or error+reason
859 */
860enum pm_ret_status pm_api_ioctl(uint32_t device_id, uint32_t ioctl_id,
Tejas Patel18072da2021-02-25 20:16:56 -0800861 uint32_t arg1, uint32_t arg2, uint32_t *value,
862 uint32_t flag)
Tejas Patel9141f442019-01-10 03:03:48 -0800863{
864 uint32_t payload[PAYLOAD_ARG_CNT];
865
866 switch (ioctl_id) {
867 case IOCTL_SET_PLL_FRAC_MODE:
Tejas Patel18072da2021-02-25 20:16:56 -0800868 return pm_pll_set_mode(arg1, arg2, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800869 case IOCTL_GET_PLL_FRAC_MODE:
Tejas Patel18072da2021-02-25 20:16:56 -0800870 return pm_pll_get_mode(arg1, value, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800871 case IOCTL_SET_PLL_FRAC_DATA:
Tejas Patel18072da2021-02-25 20:16:56 -0800872 return pm_pll_set_param(arg1, PM_PLL_PARAM_DATA, arg2, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800873 case IOCTL_GET_PLL_FRAC_DATA:
Tejas Patel18072da2021-02-25 20:16:56 -0800874 return pm_pll_get_param(arg1, PM_PLL_PARAM_DATA, value, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800875 default:
876 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800877 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_IOCTL,
878 device_id, ioctl_id, arg1, arg2);
Tejas Patel9141f442019-01-10 03:03:48 -0800879 return pm_ipi_send_sync(primary_proc, payload, value, 1);
880 }
881}
Tejas Pateldb812052019-01-23 14:18:53 +0530882
883/**
884 * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended
885 * @target Device id of the targeted PU or subsystem
886 * @wkup_node Device id of the wakeup peripheral
887 * @enable Enable or disable the specified peripheral as wake source
Tejas Patel18072da2021-02-25 20:16:56 -0800888 * @flag 0 - Call from secure source
889 * 1 - Call from non-secure source
Tejas Pateldb812052019-01-23 14:18:53 +0530890 *
891 * @return Returns status, either success or error+reason
892 */
893enum pm_ret_status pm_set_wakeup_source(uint32_t target, uint32_t wkup_device,
Tejas Patel18072da2021-02-25 20:16:56 -0800894 uint8_t enable, uint32_t flag)
Tejas Pateldb812052019-01-23 14:18:53 +0530895{
896 uint32_t payload[PAYLOAD_ARG_CNT];
897
Tejas Patel18072da2021-02-25 20:16:56 -0800898 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_SET_WAKEUP_SOURCE,
899 target, wkup_device, enable);
Tejas Pateldb812052019-01-23 14:18:53 +0530900 return pm_ipi_send(primary_proc, payload);
901}
Ravi Patel22b0b492019-03-06 12:34:46 +0530902
903/**
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700904 * pm_get_chipid() - Read silicon ID registers
905 * @value Buffer for return values. Must be large enough
906 * to hold 8 bytes.
Tejas Patel18072da2021-02-25 20:16:56 -0800907 * @flag 0 - Call from secure source
908 * 1 - Call from non-secure source
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700909 *
910 * @return Returns silicon ID registers
911 */
Tejas Patel18072da2021-02-25 20:16:56 -0800912enum pm_ret_status pm_get_chipid(uint32_t *value, uint32_t flag)
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700913{
914 uint32_t payload[PAYLOAD_ARG_CNT];
915
916 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800917 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_CHIPID);
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700918
919 return pm_ipi_send_sync(primary_proc, payload, value, 2);
920}
921
922/**
Ravi Patel22b0b492019-03-06 12:34:46 +0530923 * pm_feature_check() - Returns the supported API version if supported
924 * @api_id API ID to check
925 * @value Returned supported API version
Tejas Patel18072da2021-02-25 20:16:56 -0800926 * @flag 0 - Call from secure source
927 * 1 - Call from non-secure source
Ravi Patel22b0b492019-03-06 12:34:46 +0530928 *
929 * @return Returns status, either success or error+reason
930 */
Tejas Patel18072da2021-02-25 20:16:56 -0800931enum pm_ret_status pm_feature_check(uint32_t api_id, unsigned int *version,
932 uint32_t flag)
Ravi Patel22b0b492019-03-06 12:34:46 +0530933{
934 uint32_t payload[PAYLOAD_ARG_CNT], fw_api_version;
935 uint32_t status;
936
937 switch (api_id) {
938 case PM_GET_CALLBACK_DATA:
939 case PM_GET_TRUSTZONE_VERSION:
Rajan Vajaad1ffff2021-01-20 00:53:45 -0800940 case PM_LOAD_PDI:
Ravi Patel22b0b492019-03-06 12:34:46 +0530941 *version = (PM_API_BASE_VERSION << 16);
942 return PM_RET_SUCCESS;
943 case PM_GET_API_VERSION:
944 case PM_GET_DEVICE_STATUS:
Saeed Nowshadi2294b422019-06-03 10:22:35 -0700945 case PM_GET_OP_CHARACTERISTIC:
Ravi Patel22b0b492019-03-06 12:34:46 +0530946 case PM_REQ_SUSPEND:
947 case PM_SELF_SUSPEND:
948 case PM_FORCE_POWERDOWN:
949 case PM_ABORT_SUSPEND:
950 case PM_REQ_WAKEUP:
951 case PM_SET_WAKEUP_SOURCE:
952 case PM_SYSTEM_SHUTDOWN:
953 case PM_REQUEST_DEVICE:
954 case PM_RELEASE_DEVICE:
955 case PM_SET_REQUIREMENT:
956 case PM_RESET_ASSERT:
957 case PM_RESET_GET_STATUS:
Venkatesh Yadav Abbarapu95ecd452019-12-10 22:16:36 -0500958 case PM_GET_CHIPID:
Ravi Patel22b0b492019-03-06 12:34:46 +0530959 case PM_PINCTRL_REQUEST:
960 case PM_PINCTRL_RELEASE:
961 case PM_PINCTRL_GET_FUNCTION:
962 case PM_PINCTRL_SET_FUNCTION:
963 case PM_PINCTRL_CONFIG_PARAM_GET:
964 case PM_PINCTRL_CONFIG_PARAM_SET:
965 case PM_IOCTL:
Ravi Patel22b0b492019-03-06 12:34:46 +0530966 case PM_CLOCK_ENABLE:
967 case PM_CLOCK_DISABLE:
968 case PM_CLOCK_GETSTATE:
969 case PM_CLOCK_SETDIVIDER:
970 case PM_CLOCK_GETDIVIDER:
971 case PM_CLOCK_SETPARENT:
972 case PM_CLOCK_GETPARENT:
Tejas Patel84275bf2020-09-01 04:43:53 -0700973 case PM_CLOCK_GETRATE:
Ravi Patel22b0b492019-03-06 12:34:46 +0530974 case PM_PLL_SET_PARAMETER:
975 case PM_PLL_GET_PARAMETER:
976 case PM_PLL_SET_MODE:
977 case PM_PLL_GET_MODE:
978 case PM_FEATURE_CHECK:
Ravi Patel476b5b12019-08-12 03:10:10 -0700979 case PM_INIT_FINALIZE:
Tejas Patel5c154e12020-11-25 01:53:12 -0800980 case PM_SET_MAX_LATENCY:
Tejas Patel42015552020-11-25 01:56:57 -0800981 case PM_REGISTER_NOTIFIER:
Ravi Patel22b0b492019-03-06 12:34:46 +0530982 *version = (PM_API_BASE_VERSION << 16);
983 break;
Rajan Vajaad1ffff2021-01-20 00:53:45 -0800984 case PM_QUERY_DATA:
985 *version = (PM_API_QUERY_DATA_VERSION << 16);
986 break;
Ravi Patel22b0b492019-03-06 12:34:46 +0530987 default:
988 *version = 0U;
989 return PM_RET_ERROR_NOFEATURE;
990 }
991
Tejas Patel18072da2021-02-25 20:16:56 -0800992 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag,
993 PM_FEATURE_CHECK, api_id);
Ravi Patel22b0b492019-03-06 12:34:46 +0530994
995 status = pm_ipi_send_sync(primary_proc, payload, &fw_api_version, 1);
996 if (status != PM_RET_SUCCESS)
997 return status;
998
999 *version |= fw_api_version;
1000
1001 return PM_RET_SUCCESS;
1002}
Jolly Shahed05a712019-03-22 05:33:39 +05301003
1004/**
1005 * pm_load_pdi() - Load the PDI
1006 *
1007 * This function provides support to load PDI from linux
1008 *
1009 * src: Source device of pdi(DDR, OCM, SD etc)
1010 * address_low: lower 32-bit Linear memory space address
1011 * address_high: higher 32-bit Linear memory space address
Tejas Patel18072da2021-02-25 20:16:56 -08001012 * @flag 0 - Call from secure source
1013 * 1 - Call from non-secure source
Jolly Shahed05a712019-03-22 05:33:39 +05301014 *
1015 * @return Returns status, either success or error+reason
1016 */
Tejas Patel18072da2021-02-25 20:16:56 -08001017enum pm_ret_status pm_load_pdi(uint32_t src, uint32_t address_low,
1018 uint32_t address_high, uint32_t flag)
Jolly Shahed05a712019-03-22 05:33:39 +05301019{
1020 uint32_t payload[PAYLOAD_ARG_CNT];
1021
1022 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -08001023 PM_PACK_PAYLOAD4(payload, LOADER_MODULE_ID, flag, PM_LOAD_PDI, src,
Jolly Shahed05a712019-03-22 05:33:39 +05301024 address_high, address_low);
1025 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1026}
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001027
1028/**
1029 * pm_get_op_characteristic() - PM call to request operating characteristics
1030 * of a device
1031 * @device_id Device id
1032 * @type Type of the operating characteristic
1033 * (power, temperature and latency)
1034 * @result Returns the operating characteristic for the requested device,
1035 * specified by the type
Tejas Patel18072da2021-02-25 20:16:56 -08001036 * @flag 0 - Call from secure source
1037 * 1 - Call from non-secure source
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001038 *
1039 * @return Returns status, either success or error+reason
1040 */
1041enum pm_ret_status pm_get_op_characteristic(uint32_t device_id,
1042 enum pm_opchar_type type,
Tejas Patel18072da2021-02-25 20:16:56 -08001043 uint32_t *result, uint32_t flag)
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001044{
1045 uint32_t payload[PAYLOAD_ARG_CNT];
1046
1047 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001048 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
1049 PM_GET_OP_CHARACTERISTIC, device_id, type);
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001050 return pm_ipi_send_sync(primary_proc, payload, result, 1);
1051}
Tejas Patel5c154e12020-11-25 01:53:12 -08001052
1053/**
1054 * pm_set_max_latency() - PM call to change in the maximum wake-up latency
1055 * requirements for a specific device currently
1056 * used by that CPU.
1057 * @device_id Device ID
1058 * @latency Latency value
Tejas Patel18072da2021-02-25 20:16:56 -08001059 * @flag 0 - Call from secure source
1060 * 1 - Call from non-secure source
Tejas Patel5c154e12020-11-25 01:53:12 -08001061 *
1062 * @return Returns status, either success or error+reason
1063 */
Tejas Patel18072da2021-02-25 20:16:56 -08001064enum pm_ret_status pm_set_max_latency(uint32_t device_id, uint32_t latency,
1065 uint32_t flag)
Tejas Patel5c154e12020-11-25 01:53:12 -08001066{
1067 uint32_t payload[PAYLOAD_ARG_CNT];
1068
1069 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001070 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SET_MAX_LATENCY,
Tejas Patel5c154e12020-11-25 01:53:12 -08001071 device_id, latency);
1072
1073 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1074}
Tejas Patel42015552020-11-25 01:56:57 -08001075
1076/**
1077 * pm_register_notifier() - PM call to register a subsystem to be notified
1078 * about the device event
1079 * @device_id Device ID for the Node to which the event is related
1080 * @event Event in question
1081 * @wake Wake subsystem upon capturing the event if value 1
1082 * @enable Enable the registration for value 1, disable for value 0
Tejas Patel18072da2021-02-25 20:16:56 -08001083 * @flag 0 - Call from secure source
1084 * 1 - Call from non-secure source
Tejas Patel42015552020-11-25 01:56:57 -08001085 *
1086 * @return Returns status, either success or error+reason
1087 */
1088enum pm_ret_status pm_register_notifier(uint32_t device_id, uint32_t event,
Tejas Patel18072da2021-02-25 20:16:56 -08001089 uint32_t wake, uint32_t enable,
1090 uint32_t flag)
Tejas Patel42015552020-11-25 01:56:57 -08001091{
1092 uint32_t payload[PAYLOAD_ARG_CNT];
1093
1094 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001095 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REGISTER_NOTIFIER,
Tejas Patel42015552020-11-25 01:56:57 -08001096 device_id, event, wake, enable);
1097
1098 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1099}