blob: a57854374ea13c37908f09616174e945cbf50799 [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"
Tejas Patel9d09ff92019-01-08 01:46:35 -080018
19/*********************************************************************
20 * Target module IDs macros
21 ********************************************************************/
22#define LIBPM_MODULE_ID 0x2
23#define LOADER_MODULE_ID 0x7
24
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -080025/* default shutdown/reboot scope is system(2) */
26static unsigned int pm_shutdown_scope = XPM_SHUTDOWN_SUBTYPE_RST_SYSTEM;
27
28/**
29 * pm_get_shutdown_scope() - Get the currently set shutdown scope
30 *
31 * @return Shutdown scope value
32 */
33unsigned int pm_get_shutdown_scope(void)
34{
35 return pm_shutdown_scope;
36}
37
Tejas Patel9d09ff92019-01-08 01:46:35 -080038/**
39 * Assigning of argument values into array elements.
40 */
Tejas Patel18072da2021-02-25 20:16:56 -080041#define PM_PACK_PAYLOAD1(pl, mid, flag, arg0) { \
42 pl[0] = (uint32_t)((uint32_t)((arg0) & 0xFF) | (mid << 8) | ((flag) << 24)); \
Tejas Patel9d09ff92019-01-08 01:46:35 -080043}
44
Tejas Patel18072da2021-02-25 20:16:56 -080045#define PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1) { \
46 pl[1] = (uint32_t)(arg1); \
47 PM_PACK_PAYLOAD1(pl, mid, flag, arg0); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080048}
49
Tejas Patel18072da2021-02-25 20:16:56 -080050#define PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2) { \
51 pl[2] = (uint32_t)(arg2); \
52 PM_PACK_PAYLOAD2(pl, mid, flag, arg0, arg1); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080053}
54
Tejas Patel18072da2021-02-25 20:16:56 -080055#define PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3) { \
56 pl[3] = (uint32_t)(arg3); \
57 PM_PACK_PAYLOAD3(pl, mid, flag, arg0, arg1, arg2); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080058}
59
Tejas Patel18072da2021-02-25 20:16:56 -080060#define PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4) { \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080061 pl[4] = (uint32_t)(arg4); \
Tejas Patel18072da2021-02-25 20:16:56 -080062 PM_PACK_PAYLOAD4(pl, mid, flag, arg0, arg1, arg2, arg3); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080063}
64
Tejas Patel18072da2021-02-25 20:16:56 -080065#define PM_PACK_PAYLOAD6(pl, mid, flag, arg0, arg1, arg2, arg3, arg4, arg5) { \
66 pl[5] = (uint32_t)(arg5); \
67 PM_PACK_PAYLOAD5(pl, mid, flag, arg0, arg1, arg2, arg3, arg4); \
Tejas Patelfe0e10a2019-12-08 23:29:44 -080068}
69
Tejas Patel9d09ff92019-01-08 01:46:35 -080070/* PM API functions */
71
72/**
73 * pm_get_api_version() - Get version number of PMC PM firmware
74 * @version Returns 32-bit version number of PMC Power Management Firmware
Tejas Patel18072da2021-02-25 20:16:56 -080075 * @flag 0 - Call from secure source
76 * 1 - Call from non-secure source
Tejas Patel9d09ff92019-01-08 01:46:35 -080077 *
78 * @return Returns status, either success or error+reason
79 */
Tejas Patel18072da2021-02-25 20:16:56 -080080enum pm_ret_status pm_get_api_version(unsigned int *version, uint32_t flag)
Tejas Patel9d09ff92019-01-08 01:46:35 -080081{
82 uint32_t payload[PAYLOAD_ARG_CNT];
83
84 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -080085 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_API_VERSION);
Tejas Patel9d09ff92019-01-08 01:46:35 -080086 return pm_ipi_send_sync(primary_proc, payload, version, 1);
87}
Tejas Patelfe0e10a2019-12-08 23:29:44 -080088
89/**
Ravi Patel476b5b12019-08-12 03:10:10 -070090 * pm_init_finalize() - Call to notify PMC PM firmware that master has power
91 * management enabled and that it has finished its
92 * initialization
Tejas Patel18072da2021-02-25 20:16:56 -080093 * @flag 0 - Call from secure source
94 * 1 - Call from non-secure source
Ravi Patel476b5b12019-08-12 03:10:10 -070095 *
96 * @return Status returned by the PMU firmware
97 */
Tejas Patel18072da2021-02-25 20:16:56 -080098enum pm_ret_status pm_init_finalize(uint32_t flag)
Ravi Patel476b5b12019-08-12 03:10:10 -070099{
100 uint32_t payload[PAYLOAD_ARG_CNT];
101
102 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800103 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_INIT_FINALIZE);
Ravi Patel476b5b12019-08-12 03:10:10 -0700104 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
105}
106
107/**
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800108 * pm_self_suspend() - PM call for processor to suspend itself
109 * @nid Node id of the processor or subsystem
110 * @latency Requested maximum wakeup latency (not supported)
111 * @state Requested state
112 * @address Resume address
Tejas Patel18072da2021-02-25 20:16:56 -0800113 * @flag 0 - Call from secure source
114 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800115 *
116 * This is a blocking call, it will return only once PMU has responded.
117 * On a wakeup, resume address will be automatically set by PMU.
118 *
119 * @return Returns status, either success or error+reason
120 */
121enum pm_ret_status pm_self_suspend(uint32_t nid,
122 unsigned int latency,
123 unsigned int state,
Tejas Patel18072da2021-02-25 20:16:56 -0800124 uintptr_t address, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800125{
126 uint32_t payload[PAYLOAD_ARG_CNT];
127 unsigned int cpuid = plat_my_core_pos();
128 const struct pm_proc *proc = pm_get_proc(cpuid);
129
130 if (!proc) {
131 WARN("Failed to get proc %d\n", cpuid);
132 return PM_RET_ERROR_INTERNAL;
133 }
134
135 /*
136 * Do client specific suspend operations
137 * (e.g. set powerdown request bit)
138 */
139 pm_client_suspend(proc, state);
140
141 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -0800142 PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, flag, PM_SELF_SUSPEND,
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800143 proc->node_id, latency, state, address,
144 (address >> 32));
145 return pm_ipi_send_sync(proc, payload, NULL, 0);
146}
147
148/**
149 * pm_abort_suspend() - PM call to announce that a prior suspend request
150 * is to be aborted.
151 * @reason Reason for the abort
Tejas Patel18072da2021-02-25 20:16:56 -0800152 * @flag 0 - Call from secure source
153 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800154 *
155 * Calling PU expects the PMU to abort the initiated suspend procedure.
156 * This is a non-blocking call without any acknowledge.
157 *
158 * @return Returns status, either success or error+reason
159 */
Tejas Patel18072da2021-02-25 20:16:56 -0800160enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason, uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800161{
162 uint32_t payload[PAYLOAD_ARG_CNT];
163
164 /*
165 * Do client specific abort suspend operations
166 * (e.g. enable interrupts and clear powerdown request bit)
167 */
168 pm_client_abort_suspend();
169
170 /* Send request to the PLM */
Tejas Patel18072da2021-02-25 20:16:56 -0800171 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_ABORT_SUSPEND,
172 reason, primary_proc->node_id);
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800173 return pm_ipi_send(primary_proc, payload);
174}
175
176/**
177 * pm_req_suspend() - PM call to request for another PU or subsystem to
178 * be suspended gracefully.
179 * @target Node id of the targeted PU or subsystem
180 * @ack Flag to specify whether acknowledge is requested
181 * @latency Requested wakeup latency (not supported)
182 * @state Requested state (not supported)
Tejas Patel18072da2021-02-25 20:16:56 -0800183 * @flag 0 - Call from secure source
184 * 1 - Call from non-secure source
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800185 *
186 * @return Returns status, either success or error+reason
187 */
188enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack,
Tejas Patel18072da2021-02-25 20:16:56 -0800189 unsigned int latency, unsigned int state,
190 uint32_t flag)
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800191{
192 uint32_t payload[PAYLOAD_ARG_CNT];
193
194 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -0800195 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_REQ_SUSPEND, target,
Tejas Patelfe0e10a2019-12-08 23:29:44 -0800196 latency, state);
197 if (ack == IPI_BLOCKING)
198 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
199 else
200 return pm_ipi_send(primary_proc, payload);
201}
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800202
203/**
Tejas Patel49cd8712019-01-23 14:18:51 +0530204 * pm_req_wakeup() - PM call for processor to wake up selected processor
205 * or subsystem
206 * @target Device ID of the processor or subsystem to wake up
207 * @set_address Resume address presence indicator
208 * 1 - resume address specified, 0 - otherwise
209 * @address Resume address
210 * @ack Flag to specify whether acknowledge requested
Tejas Patel18072da2021-02-25 20:16:56 -0800211 * @flag 0 - Call from secure source
212 * 1 - Call from non-secure source
Tejas Patel49cd8712019-01-23 14:18:51 +0530213 *
214 * This API function is either used to power up another APU core for SMP
215 * (by PSCI) or to power up an entirely different PU or subsystem, such
216 * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be
217 * automatically set by PMC.
218 *
219 * @return Returns status, either success or error+reason
220 */
221enum pm_ret_status pm_req_wakeup(uint32_t target, uint32_t set_address,
Tejas Patel18072da2021-02-25 20:16:56 -0800222 uintptr_t address, uint8_t ack, uint32_t flag)
Tejas Patel49cd8712019-01-23 14:18:51 +0530223{
224 uint32_t payload[PAYLOAD_ARG_CNT];
225
226 /* Send request to the PMC to perform the wake of the PU */
Tejas Patel18072da2021-02-25 20:16:56 -0800227 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQ_WAKEUP, target,
Tejas Patel49cd8712019-01-23 14:18:51 +0530228 set_address, address, ack);
229
230 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
231}
232
233/**
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800234 * pm_request_device() - Request a device
235 * @device_id Device ID
236 * @capabilities Requested capabilities for the device
237 * @qos Required Quality of Service
238 * @ack Flag to specify whether acknowledge requested
Tejas Patel18072da2021-02-25 20:16:56 -0800239 * @flag 0 - Call from secure source
240 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800241 *
242 * @return Returns status, either success or error+reason
243 */
244enum pm_ret_status pm_request_device(uint32_t device_id, uint32_t capabilities,
Tejas Patel18072da2021-02-25 20:16:56 -0800245 uint32_t qos, uint32_t ack, uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800246{
247 uint32_t payload[PAYLOAD_ARG_CNT];
248
249 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800250 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REQUEST_DEVICE,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800251 device_id, capabilities, qos, ack);
252
253 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
254}
255
256/**
257 * pm_release_device() - Release a device
258 * @device_id Device ID
Tejas Patel18072da2021-02-25 20:16:56 -0800259 * @flag 0 - Call from secure source
260 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800261 *
262 * @return Returns status, either success or error+reason
263 */
Tejas Patel18072da2021-02-25 20:16:56 -0800264enum pm_ret_status pm_release_device(uint32_t device_id, uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800265{
266 uint32_t payload[PAYLOAD_ARG_CNT];
267
268 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800269 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RELEASE_DEVICE,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800270 device_id);
271
272 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
273}
274
275/**
276 * pm_set_requirement() - Set requirement for the device
277 * @device_id Device ID
278 * @capabilities Requested capabilities for the device
279 * @latency Requested maximum latency
280 * @qos Required Quality of Service
Tejas Patel18072da2021-02-25 20:16:56 -0800281 * @flag 0 - Call from secure source
282 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800283 *
284 * @return Returns status, either success or error+reason
285 */
286enum pm_ret_status pm_set_requirement(uint32_t device_id, uint32_t capabilities,
Tejas Patel18072da2021-02-25 20:16:56 -0800287 uint32_t latency, uint32_t qos,
288 uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800289{
290 uint32_t payload[PAYLOAD_ARG_CNT];
291
292 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800293 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_SET_REQUIREMENT,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800294 device_id, capabilities, latency, qos);
295
296 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
297}
298
299/**
300 * pm_get_device_status() - Get device's status
301 * @device_id Device ID
302 * @response Buffer to store device status response
Tejas Patel18072da2021-02-25 20:16:56 -0800303 * @flag 0 - Call from secure source
304 * 1 - Call from non-secure source
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800305 *
306 * @return Returns status, either success or error+reason
307 */
Tejas Patel18072da2021-02-25 20:16:56 -0800308enum pm_ret_status pm_get_device_status(uint32_t device_id, uint32_t *response,
309 uint32_t flag)
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800310{
311 uint32_t payload[PAYLOAD_ARG_CNT];
312
313 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800314 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_GET_DEVICE_STATUS,
Tejas Patel41f3e0b2019-01-08 01:46:37 -0800315 device_id);
316
317 return pm_ipi_send_sync(primary_proc, payload, response, 3);
318}
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800319
320/**
321 * pm_reset_assert() - Assert/De-assert reset
322 * @reset Reset ID
323 * @assert Assert (1) or de-assert (0)
Tejas Patel18072da2021-02-25 20:16:56 -0800324 * @flag 0 - Call from secure source
325 * 1 - Call from non-secure source
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800326 *
327 * @return Returns status, either success or error+reason
328 */
Tejas Patel18072da2021-02-25 20:16:56 -0800329enum pm_ret_status pm_reset_assert(uint32_t reset, bool assert, uint32_t flag)
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800330{
331 uint32_t payload[PAYLOAD_ARG_CNT];
332
333 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800334 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT, reset,
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800335 assert);
336
337 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
338}
339
340/**
341 * pm_reset_get_status() - Get current status of a reset line
342 * @reset Reset ID
343 * @status Returns current status of selected reset ID
Tejas Patel18072da2021-02-25 20:16:56 -0800344 * @flag 0 - Call from secure source
345 * 1 - Call from non-secure source
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800346 *
347 * @return Returns status, either success or error+reason
348 */
Tejas Patel18072da2021-02-25 20:16:56 -0800349enum pm_ret_status pm_reset_get_status(uint32_t reset, uint32_t *status,
350 uint32_t flag)
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800351{
352 uint32_t payload[PAYLOAD_ARG_CNT];
353
354 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800355 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_RESET_ASSERT,
356 reset);
Tejas Patel87c4f3a2019-01-08 01:46:38 -0800357
358 return pm_ipi_send_sync(primary_proc, payload, status, 1);
359}
Tejas Patel20e92022019-01-08 01:46:39 -0800360
361/**
Rajan Vaja649e9242019-03-04 11:09:40 +0530362 * pm_get_callbackdata() - Read from IPI response buffer
363 * @data - array of PAYLOAD_ARG_CNT elements
Tejas Patel18072da2021-02-25 20:16:56 -0800364 * @flag - 0 - Call from secure source
365 * 1 - Call from non-secure source
Rajan Vaja649e9242019-03-04 11:09:40 +0530366 *
367 * Read value from ipi buffer response buffer.
368 */
Tejas Patel18072da2021-02-25 20:16:56 -0800369void pm_get_callbackdata(uint32_t *data, size_t count, uint32_t flag)
Rajan Vaja649e9242019-03-04 11:09:40 +0530370{
371 /* Return if interrupt is not from PMU */
372 if (!pm_ipi_irq_status(primary_proc))
373 return;
374
375 pm_ipi_buff_read_callb(data, count);
376 pm_ipi_irq_clear(primary_proc);
377}
378
379/**
Tejas Patel20e92022019-01-08 01:46:39 -0800380 * pm_pinctrl_request() - Request a pin
381 * @pin Pin ID
Tejas Patel18072da2021-02-25 20:16:56 -0800382 * @flag 0 - Call from secure source
383 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800384 *
385 * @return Returns status, either success or error+reason
386 */
Tejas Patel18072da2021-02-25 20:16:56 -0800387enum pm_ret_status pm_pinctrl_request(uint32_t pin, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800388{
389 uint32_t payload[PAYLOAD_ARG_CNT];
390
391 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800392 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_REQUEST,
393 pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800394
395 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
396}
397
398/**
399 * pm_pinctrl_release() - Release a pin
400 * @pin Pin ID
Tejas Patel18072da2021-02-25 20:16:56 -0800401 * @flag 0 - Call from secure source
402 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800403 *
404 * @return Returns status, either success or error+reason
405 */
Tejas Patel18072da2021-02-25 20:16:56 -0800406enum pm_ret_status pm_pinctrl_release(uint32_t pin, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800407{
408 uint32_t payload[PAYLOAD_ARG_CNT];
409
410 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800411 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PINCTRL_RELEASE,
412 pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800413
414 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
415}
416
417/**
418 * pm_pinctrl_set_function() - Set pin function
419 * @pin Pin ID
420 * @function Function ID
Tejas Patel18072da2021-02-25 20:16:56 -0800421 * @flag 0 - Call from secure source
422 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800423 *
424 * @return Returns status, either success or error+reason
425 */
Tejas Patel18072da2021-02-25 20:16:56 -0800426enum pm_ret_status pm_pinctrl_set_function(uint32_t pin, uint32_t function,
427 uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800428{
429 uint32_t payload[PAYLOAD_ARG_CNT];
430
431 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800432 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
433 PM_PINCTRL_SET_FUNCTION, pin, function)
Tejas Patel20e92022019-01-08 01:46:39 -0800434
435 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
436}
437
438/**
439 * pm_pinctrl_get_function() - Get function set on the pin
440 * @pin Pin ID
441 * @function Function set on the pin
Tejas Patel18072da2021-02-25 20:16:56 -0800442 * @flag 0 - Call from secure source
443 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800444 *
445 * @return Returns status, either success or error+reason
446 */
Tejas Patel18072da2021-02-25 20:16:56 -0800447enum pm_ret_status pm_pinctrl_get_function(uint32_t pin, uint32_t *function,
448 uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800449{
450 uint32_t payload[PAYLOAD_ARG_CNT];
451
452 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800453 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag,
454 PM_PINCTRL_SET_FUNCTION, pin);
Tejas Patel20e92022019-01-08 01:46:39 -0800455
456 return pm_ipi_send_sync(primary_proc, payload, function, 1);
457}
458
459/**
460 * pm_pinctrl_set_pin_param() - Set configuration parameter for the pin
461 * @pin Pin ID
462 * @param Parameter ID
463 * @value Parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800464 * @flag 0 - Call from secure source
465 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800466 *
467 * @return Returns status, either success or error+reason
468 */
469enum pm_ret_status pm_pinctrl_set_pin_param(uint32_t pin, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800470 uint32_t value, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800471{
472 uint32_t payload[PAYLOAD_ARG_CNT];
473
474 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800475 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag,
476 PM_PINCTRL_CONFIG_PARAM_SET, pin, param, value);
Tejas Patel20e92022019-01-08 01:46:39 -0800477
478 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
479}
480
481/**
482 * pm_pinctrl_get_pin_param() - Get configuration parameter value for the pin
483 * @pin Pin ID
484 * @param Parameter ID
485 * @value Buffer to store parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800486 * @flag 0 - Call from secure source
487 * 1 - Call from non-secure source
Tejas Patel20e92022019-01-08 01:46:39 -0800488 *
489 * @return Returns status, either success or error+reason
490 */
491enum pm_ret_status pm_pinctrl_get_pin_param(uint32_t pin, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800492 uint32_t *value, uint32_t flag)
Tejas Patel20e92022019-01-08 01:46:39 -0800493{
494 uint32_t payload[PAYLOAD_ARG_CNT];
495
496 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800497 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
498 PM_PINCTRL_CONFIG_PARAM_GET, pin, param);
Tejas Patel20e92022019-01-08 01:46:39 -0800499
500 return pm_ipi_send_sync(primary_proc, payload, value, 1);
501}
Tejas Patel1f56fb12019-01-08 01:46:40 -0800502
503/**
504 * pm_clock_enable() - Enable the clock
505 * @clk_id Clock ID
Tejas Patel18072da2021-02-25 20:16:56 -0800506 * @flag 0 - Call from secure source
507 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800508 *
509 * @return Returns status, either success or error+reason
510 */
Tejas Patel18072da2021-02-25 20:16:56 -0800511enum pm_ret_status pm_clock_enable(uint32_t clk_id, uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800512{
513 uint32_t payload[PAYLOAD_ARG_CNT];
514
515 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800516 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_ENABLE,
517 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800518
519 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
520}
521
522/**
523 * pm_clock_disable() - Disable the clock
524 * @clk_id Clock ID
Tejas Patel18072da2021-02-25 20:16:56 -0800525 * @flag 0 - Call from secure source
526 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800527 *
528 * @return Returns status, either success or error+reason
529 */
Tejas Patel18072da2021-02-25 20:16:56 -0800530enum pm_ret_status pm_clock_disable(uint32_t clk_id, uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800531{
532 uint32_t payload[PAYLOAD_ARG_CNT];
533
534 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800535 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_DISABLE,
536 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800537
538 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
539}
540
541/**
542 * pm_clock_get_state() - Get clock status
543 * @clk_id Clock ID
544 * @state: Buffer to store clock status (1: Enabled, 0:Disabled)
Tejas Patel18072da2021-02-25 20:16:56 -0800545 * @flag 0 - Call from secure source
546 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800547 *
548 * @return Returns status, either success or error+reason
549 */
Tejas Patel18072da2021-02-25 20:16:56 -0800550enum pm_ret_status pm_clock_get_state(uint32_t clk_id, uint32_t *state,
551 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800552{
553 uint32_t payload[PAYLOAD_ARG_CNT];
554
555 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800556 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETSTATE,
557 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800558
559 return pm_ipi_send_sync(primary_proc, payload, state, 1);
560}
561
562/**
563 * pm_clock_set_divider() - Set divider for the clock
564 * @clk_id Clock ID
565 * @divider Divider value
Tejas Patel18072da2021-02-25 20:16:56 -0800566 * @flag 0 - Call from secure source
567 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800568 *
569 * @return Returns status, either success or error+reason
570 */
Tejas Patel18072da2021-02-25 20:16:56 -0800571enum pm_ret_status pm_clock_set_divider(uint32_t clk_id, uint32_t divider,
572 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800573{
574 uint32_t payload[PAYLOAD_ARG_CNT];
575
576 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800577 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETDIVIDER,
578 clk_id, divider);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800579
580 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
581}
582
583/**
584 * pm_clock_get_divider() - Get divider value for the clock
585 * @clk_id Clock ID
586 * @divider: Buffer to store clock divider value
Tejas Patel18072da2021-02-25 20:16:56 -0800587 * @flag 0 - Call from secure source
588 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800589 *
590 * @return Returns status, either success or error+reason
591 */
Tejas Patel18072da2021-02-25 20:16:56 -0800592enum pm_ret_status pm_clock_get_divider(uint32_t clk_id, uint32_t *divider,
593 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800594{
595 uint32_t payload[PAYLOAD_ARG_CNT];
596
597 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800598 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETDIVIDER,
599 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800600
601 return pm_ipi_send_sync(primary_proc, payload, divider, 1);
602}
603
604/**
605 * pm_clock_set_parent() - Set parent for the clock
606 * @clk_id Clock ID
607 * @parent Parent ID
Tejas Patel18072da2021-02-25 20:16:56 -0800608 * @flag 0 - Call from secure source
609 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800610 *
611 * @return Returns status, either success or error+reason
612 */
Tejas Patel18072da2021-02-25 20:16:56 -0800613enum pm_ret_status pm_clock_set_parent(uint32_t clk_id, uint32_t parent,
614 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800615{
616 uint32_t payload[PAYLOAD_ARG_CNT];
617
618 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800619 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_SETPARENT,
620 clk_id, parent);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800621
622 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
623}
624
625/**
626 * pm_clock_get_parent() - Get parent value for the clock
627 * @clk_id Clock ID
628 * @parent: Buffer to store clock parent value
Tejas Patel18072da2021-02-25 20:16:56 -0800629 * @flag 0 - Call from secure source
630 * 1 - Call from non-secure source
Tejas Patel1f56fb12019-01-08 01:46:40 -0800631 *
632 * @return Returns status, either success or error+reason
633 */
Tejas Patel18072da2021-02-25 20:16:56 -0800634enum pm_ret_status pm_clock_get_parent(uint32_t clk_id, uint32_t *parent,
635 uint32_t flag)
Tejas Patel1f56fb12019-01-08 01:46:40 -0800636{
637 uint32_t payload[PAYLOAD_ARG_CNT];
638
639 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800640 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETPARENT,
641 clk_id);
Tejas Patel1f56fb12019-01-08 01:46:40 -0800642
643 return pm_ipi_send_sync(primary_proc, payload, parent, 1);
644}
Tejas Patel84275bf2020-09-01 04:43:53 -0700645/**
646 * pm_clock_get_rate() - Get the rate value for the clock
647 * @clk_id Clock ID
648 * @rate: Buffer to store clock rate value
Tejas Patel18072da2021-02-25 20:16:56 -0800649 * @flag 0 - Call from secure source
650 * 1 - Call from non-secure source
Tejas Patel84275bf2020-09-01 04:43:53 -0700651 *
652 * @return Returns status, either success or error+reason
653 */
Tejas Patel18072da2021-02-25 20:16:56 -0800654enum pm_ret_status pm_clock_get_rate(uint32_t clk_id, uint32_t *clk_rate,
655 uint32_t flag)
Tejas Patel84275bf2020-09-01 04:43:53 -0700656{
657 uint32_t payload[PAYLOAD_ARG_CNT];
658
659 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800660 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_CLOCK_GETRATE,
661 clk_id);
Tejas Patel84275bf2020-09-01 04:43:53 -0700662
663 return pm_ipi_send_sync(primary_proc, payload, clk_rate, 2);
664}
Tejas Patel023116d2019-01-08 01:46:41 -0800665
666/**
667 * pm_pll_set_param() - Set PLL parameter
668 * @clk_id PLL clock ID
669 * @param PLL parameter ID
670 * @value Value to set for PLL parameter
Tejas Patel18072da2021-02-25 20:16:56 -0800671 * @flag 0 - Call from secure source
672 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800673 *
674 * @return Returns status, either success or error+reason
675 */
676enum pm_ret_status pm_pll_set_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800677 uint32_t value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800678{
679 uint32_t payload[PAYLOAD_ARG_CNT];
680
681 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800682 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_PARAMETER,
683 clk_id, param, value);
Tejas Patel023116d2019-01-08 01:46:41 -0800684
685 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
686}
687
688/**
689 * pm_pll_get_param() - Get PLL parameter value
690 * @clk_id PLL clock ID
691 * @param PLL parameter ID
692 * @value: Buffer to store PLL parameter value
Tejas Patel18072da2021-02-25 20:16:56 -0800693 * @flag 0 - Call from secure source
694 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800695 *
696 * @return Returns status, either success or error+reason
697 */
698enum pm_ret_status pm_pll_get_param(uint32_t clk_id, uint32_t param,
Tejas Patel18072da2021-02-25 20:16:56 -0800699 uint32_t *value, uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800700{
701 uint32_t payload[PAYLOAD_ARG_CNT];
702
703 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800704 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_PARAMETER,
705 clk_id, param);
Tejas Patel023116d2019-01-08 01:46:41 -0800706
707 return pm_ipi_send_sync(primary_proc, payload, value, 1);
708}
709
710/**
711 * pm_pll_set_mode() - Set PLL mode
712 * @clk_id PLL clock ID
713 * @mode PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800714 * @flag 0 - Call from secure source
715 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800716 *
717 * @return Returns status, either success or error+reason
718 */
Tejas Patel18072da2021-02-25 20:16:56 -0800719enum pm_ret_status pm_pll_set_mode(uint32_t clk_id, uint32_t mode,
720 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800721{
722 uint32_t payload[PAYLOAD_ARG_CNT];
723
724 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800725 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_PLL_SET_MODE,
726 clk_id, mode);
Tejas Patel023116d2019-01-08 01:46:41 -0800727
728 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
729}
730
731/**
732 * pm_pll_get_mode() - Get PLL mode
733 * @clk_id PLL clock ID
734 * @mode: Buffer to store PLL mode
Tejas Patel18072da2021-02-25 20:16:56 -0800735 * @flag 0 - Call from secure source
736 * 1 - Call from non-secure source
Tejas Patel023116d2019-01-08 01:46:41 -0800737 *
738 * @return Returns status, either success or error+reason
739 */
Tejas Patel18072da2021-02-25 20:16:56 -0800740enum pm_ret_status pm_pll_get_mode(uint32_t clk_id, uint32_t *mode,
741 uint32_t flag)
Tejas Patel023116d2019-01-08 01:46:41 -0800742{
743 uint32_t payload[PAYLOAD_ARG_CNT];
744
745 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800746 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag, PM_PLL_GET_MODE,
747 clk_id);
Tejas Patel023116d2019-01-08 01:46:41 -0800748
749 return pm_ipi_send_sync(primary_proc, payload, mode, 1);
750}
Tejas Patel6b282252019-01-10 03:03:47 -0800751
752/**
753 * pm_force_powerdown() - PM call to request for another PU or subsystem to
754 * be powered down forcefully
755 * @target Device ID of the PU node to be forced powered down.
756 * @ack Flag to specify whether acknowledge is requested
Tejas Patel18072da2021-02-25 20:16:56 -0800757 * @flag 0 - Call from secure source
758 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800759 *
760 * @return Returns status, either success or error+reason
761 */
Tejas Patel18072da2021-02-25 20:16:56 -0800762enum pm_ret_status pm_force_powerdown(uint32_t target, uint8_t ack,
763 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800764{
765 uint32_t payload[PAYLOAD_ARG_CNT];
766
767 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800768 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_FORCE_POWERDOWN,
769 target, ack);
Tejas Patel6b282252019-01-10 03:03:47 -0800770
771 if (ack == IPI_BLOCKING)
772 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
773 else
774 return pm_ipi_send(primary_proc, payload);
775}
776
777/**
778 * pm_system_shutdown() - PM call to request a system shutdown or restart
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800779 * @type Shutdown or restart? 0=shutdown, 1=restart, 2=setscope
Tejas Patel6b282252019-01-10 03:03:47 -0800780 * @subtype Scope: 0=APU-subsystem, 1=PS, 2=system
Tejas Patel18072da2021-02-25 20:16:56 -0800781 * @flag 0 - Call from secure source
782 * 1 - Call from non-secure source
Tejas Patel6b282252019-01-10 03:03:47 -0800783 *
784 * @return Returns status, either success or error+reason
785 */
Tejas Patel18072da2021-02-25 20:16:56 -0800786enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype,
787 uint32_t flag)
Tejas Patel6b282252019-01-10 03:03:47 -0800788{
789 uint32_t payload[PAYLOAD_ARG_CNT];
790
Saeed Nowshadic5a1bda2019-12-08 23:35:35 -0800791 if (type == XPM_SHUTDOWN_TYPE_SETSCOPE_ONLY) {
792 /* Setting scope for subsequent PSCI reboot or shutdown */
793 pm_shutdown_scope = subtype;
794 return PM_RET_SUCCESS;
795 }
796
Tejas Patel6b282252019-01-10 03:03:47 -0800797 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800798 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SYSTEM_SHUTDOWN,
799 type, subtype);
Tejas Patel6b282252019-01-10 03:03:47 -0800800
801 return pm_ipi_send_non_blocking(primary_proc, payload);
802}
Tejas Patel9141f442019-01-10 03:03:48 -0800803
804/**
Tejas Patela3e34ad2019-02-01 17:25:19 +0530805* pm_query_data() - PM API for querying firmware data
806* @qid The type of data to query
807* @arg1 Argument 1 to requested query data call
808* @arg2 Argument 2 to requested query data call
809* @arg3 Argument 3 to requested query data call
810* @data Returned output data
Tejas Patel18072da2021-02-25 20:16:56 -0800811* @flag 0 - Call from secure source
812* 1 - Call from non-secure source
Tejas Patela3e34ad2019-02-01 17:25:19 +0530813*
814* This function returns requested data.
815*/
816enum pm_ret_status pm_query_data(uint32_t qid, uint32_t arg1, uint32_t arg2,
Tejas Patel18072da2021-02-25 20:16:56 -0800817 uint32_t arg3, uint32_t *data, uint32_t flag)
Tejas Patela3e34ad2019-02-01 17:25:19 +0530818{
Rajan Vaja030620d2020-11-23 04:13:54 -0800819 uint32_t ret;
820 uint32_t version;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530821 uint32_t payload[PAYLOAD_ARG_CNT];
Rajan Vaja030620d2020-11-23 04:13:54 -0800822 uint32_t fw_api_version;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530823
824 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800825 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_QUERY_DATA, qid,
826 arg1, arg2, arg3);
Rajan Vaja030620d2020-11-23 04:13:54 -0800827
Tejas Patel18072da2021-02-25 20:16:56 -0800828 ret = pm_feature_check(PM_QUERY_DATA, &version, flag);
Manish Pandey3bc1bea2020-12-10 10:48:22 +0000829 if (PM_RET_SUCCESS == ret) {
Rajan Vaja030620d2020-11-23 04:13:54 -0800830 fw_api_version = version & 0xFFFF ;
831 if ((2U == fw_api_version) &&
832 ((XPM_QID_CLOCK_GET_NAME == qid) ||
833 (XPM_QID_PINCTRL_GET_FUNCTION_NAME == qid))) {
834 ret = pm_ipi_send_sync(primary_proc, payload, data, 8);
835 ret = data[0];
836 data[0] = data[1];
837 data[1] = data[2];
838 data[2] = data[3];
839 } else {
840 ret = pm_ipi_send_sync(primary_proc, payload, data, 4);
841 }
842 }
843 return ret;
Tejas Patela3e34ad2019-02-01 17:25:19 +0530844}
845/**
Tejas Patel9141f442019-01-10 03:03:48 -0800846 * pm_api_ioctl() - PM IOCTL API for device control and configs
847 * @device_id Device ID
848 * @ioctl_id ID of the requested IOCTL
849 * @arg1 Argument 1 to requested IOCTL call
850 * @arg2 Argument 2 to requested IOCTL call
851 * @value Returned output value
Tejas Patel18072da2021-02-25 20:16:56 -0800852 * @flag 0 - Call from secure source
853 * 1 - Call from non-secure source
Tejas Patel9141f442019-01-10 03:03:48 -0800854 *
855 * This function calls IOCTL to firmware for device control and configuration.
856 *
857 * @return Returns status, either success or error+reason
858 */
859enum pm_ret_status pm_api_ioctl(uint32_t device_id, uint32_t ioctl_id,
Tejas Patel18072da2021-02-25 20:16:56 -0800860 uint32_t arg1, uint32_t arg2, uint32_t *value,
861 uint32_t flag)
Tejas Patel9141f442019-01-10 03:03:48 -0800862{
863 uint32_t payload[PAYLOAD_ARG_CNT];
864
865 switch (ioctl_id) {
866 case IOCTL_SET_PLL_FRAC_MODE:
Tejas Patel18072da2021-02-25 20:16:56 -0800867 return pm_pll_set_mode(arg1, arg2, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800868 case IOCTL_GET_PLL_FRAC_MODE:
Tejas Patel18072da2021-02-25 20:16:56 -0800869 return pm_pll_get_mode(arg1, value, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800870 case IOCTL_SET_PLL_FRAC_DATA:
Tejas Patel18072da2021-02-25 20:16:56 -0800871 return pm_pll_set_param(arg1, PM_PLL_PARAM_DATA, arg2, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800872 case IOCTL_GET_PLL_FRAC_DATA:
Tejas Patel18072da2021-02-25 20:16:56 -0800873 return pm_pll_get_param(arg1, PM_PLL_PARAM_DATA, value, flag);
Tejas Patel9141f442019-01-10 03:03:48 -0800874 default:
875 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800876 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_IOCTL,
877 device_id, ioctl_id, arg1, arg2);
Tejas Patel9141f442019-01-10 03:03:48 -0800878 return pm_ipi_send_sync(primary_proc, payload, value, 1);
879 }
880}
Tejas Pateldb812052019-01-23 14:18:53 +0530881
882/**
883 * pm_set_wakeup_source() - PM call to specify the wakeup source while suspended
884 * @target Device id of the targeted PU or subsystem
885 * @wkup_node Device id of the wakeup peripheral
886 * @enable Enable or disable the specified peripheral as wake source
Tejas Patel18072da2021-02-25 20:16:56 -0800887 * @flag 0 - Call from secure source
888 * 1 - Call from non-secure source
Tejas Pateldb812052019-01-23 14:18:53 +0530889 *
890 * @return Returns status, either success or error+reason
891 */
892enum pm_ret_status pm_set_wakeup_source(uint32_t target, uint32_t wkup_device,
Tejas Patel18072da2021-02-25 20:16:56 -0800893 uint8_t enable, uint32_t flag)
Tejas Pateldb812052019-01-23 14:18:53 +0530894{
895 uint32_t payload[PAYLOAD_ARG_CNT];
896
Tejas Patel18072da2021-02-25 20:16:56 -0800897 PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, flag, PM_SET_WAKEUP_SOURCE,
898 target, wkup_device, enable);
Tejas Pateldb812052019-01-23 14:18:53 +0530899 return pm_ipi_send(primary_proc, payload);
900}
Ravi Patel22b0b492019-03-06 12:34:46 +0530901
902/**
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700903 * pm_get_chipid() - Read silicon ID registers
904 * @value Buffer for return values. Must be large enough
905 * to hold 8 bytes.
Tejas Patel18072da2021-02-25 20:16:56 -0800906 * @flag 0 - Call from secure source
907 * 1 - Call from non-secure source
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700908 *
909 * @return Returns silicon ID registers
910 */
Tejas Patel18072da2021-02-25 20:16:56 -0800911enum pm_ret_status pm_get_chipid(uint32_t *value, uint32_t flag)
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700912{
913 uint32_t payload[PAYLOAD_ARG_CNT];
914
915 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -0800916 PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, flag, PM_GET_CHIPID);
Ravi Patelbd4aa5a2019-08-12 03:17:54 -0700917
918 return pm_ipi_send_sync(primary_proc, payload, value, 2);
919}
920
921/**
Ravi Patel22b0b492019-03-06 12:34:46 +0530922 * pm_feature_check() - Returns the supported API version if supported
923 * @api_id API ID to check
924 * @value Returned supported API version
Tejas Patel18072da2021-02-25 20:16:56 -0800925 * @flag 0 - Call from secure source
926 * 1 - Call from non-secure source
Ravi Patel22b0b492019-03-06 12:34:46 +0530927 *
928 * @return Returns status, either success or error+reason
929 */
Tejas Patel18072da2021-02-25 20:16:56 -0800930enum pm_ret_status pm_feature_check(uint32_t api_id, unsigned int *version,
931 uint32_t flag)
Ravi Patel22b0b492019-03-06 12:34:46 +0530932{
933 uint32_t payload[PAYLOAD_ARG_CNT], fw_api_version;
934 uint32_t status;
935
936 switch (api_id) {
937 case PM_GET_CALLBACK_DATA:
938 case PM_GET_TRUSTZONE_VERSION:
Rajan Vajaad1ffff2021-01-20 00:53:45 -0800939 case PM_LOAD_PDI:
Ravi Patel22b0b492019-03-06 12:34:46 +0530940 *version = (PM_API_BASE_VERSION << 16);
941 return PM_RET_SUCCESS;
942 case PM_GET_API_VERSION:
943 case PM_GET_DEVICE_STATUS:
Saeed Nowshadi2294b422019-06-03 10:22:35 -0700944 case PM_GET_OP_CHARACTERISTIC:
Ravi Patel22b0b492019-03-06 12:34:46 +0530945 case PM_REQ_SUSPEND:
946 case PM_SELF_SUSPEND:
947 case PM_FORCE_POWERDOWN:
948 case PM_ABORT_SUSPEND:
949 case PM_REQ_WAKEUP:
950 case PM_SET_WAKEUP_SOURCE:
951 case PM_SYSTEM_SHUTDOWN:
952 case PM_REQUEST_DEVICE:
953 case PM_RELEASE_DEVICE:
954 case PM_SET_REQUIREMENT:
955 case PM_RESET_ASSERT:
956 case PM_RESET_GET_STATUS:
Venkatesh Yadav Abbarapu95ecd452019-12-10 22:16:36 -0500957 case PM_GET_CHIPID:
Ravi Patel22b0b492019-03-06 12:34:46 +0530958 case PM_PINCTRL_REQUEST:
959 case PM_PINCTRL_RELEASE:
960 case PM_PINCTRL_GET_FUNCTION:
961 case PM_PINCTRL_SET_FUNCTION:
962 case PM_PINCTRL_CONFIG_PARAM_GET:
963 case PM_PINCTRL_CONFIG_PARAM_SET:
964 case PM_IOCTL:
Ravi Patel22b0b492019-03-06 12:34:46 +0530965 case PM_CLOCK_ENABLE:
966 case PM_CLOCK_DISABLE:
967 case PM_CLOCK_GETSTATE:
968 case PM_CLOCK_SETDIVIDER:
969 case PM_CLOCK_GETDIVIDER:
970 case PM_CLOCK_SETPARENT:
971 case PM_CLOCK_GETPARENT:
Tejas Patel84275bf2020-09-01 04:43:53 -0700972 case PM_CLOCK_GETRATE:
Ravi Patel22b0b492019-03-06 12:34:46 +0530973 case PM_PLL_SET_PARAMETER:
974 case PM_PLL_GET_PARAMETER:
975 case PM_PLL_SET_MODE:
976 case PM_PLL_GET_MODE:
977 case PM_FEATURE_CHECK:
Ravi Patel476b5b12019-08-12 03:10:10 -0700978 case PM_INIT_FINALIZE:
Tejas Patel5c154e12020-11-25 01:53:12 -0800979 case PM_SET_MAX_LATENCY:
Tejas Patel42015552020-11-25 01:56:57 -0800980 case PM_REGISTER_NOTIFIER:
Ravi Patel22b0b492019-03-06 12:34:46 +0530981 *version = (PM_API_BASE_VERSION << 16);
982 break;
Rajan Vajaad1ffff2021-01-20 00:53:45 -0800983 case PM_QUERY_DATA:
984 *version = (PM_API_QUERY_DATA_VERSION << 16);
985 break;
Ravi Patel22b0b492019-03-06 12:34:46 +0530986 default:
987 *version = 0U;
988 return PM_RET_ERROR_NOFEATURE;
989 }
990
Tejas Patel18072da2021-02-25 20:16:56 -0800991 PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, flag,
992 PM_FEATURE_CHECK, api_id);
Ravi Patel22b0b492019-03-06 12:34:46 +0530993
994 status = pm_ipi_send_sync(primary_proc, payload, &fw_api_version, 1);
995 if (status != PM_RET_SUCCESS)
996 return status;
997
998 *version |= fw_api_version;
999
1000 return PM_RET_SUCCESS;
1001}
Jolly Shahed05a712019-03-22 05:33:39 +05301002
1003/**
1004 * pm_load_pdi() - Load the PDI
1005 *
1006 * This function provides support to load PDI from linux
1007 *
1008 * src: Source device of pdi(DDR, OCM, SD etc)
1009 * address_low: lower 32-bit Linear memory space address
1010 * address_high: higher 32-bit Linear memory space address
Tejas Patel18072da2021-02-25 20:16:56 -08001011 * @flag 0 - Call from secure source
1012 * 1 - Call from non-secure source
Jolly Shahed05a712019-03-22 05:33:39 +05301013 *
1014 * @return Returns status, either success or error+reason
1015 */
Tejas Patel18072da2021-02-25 20:16:56 -08001016enum pm_ret_status pm_load_pdi(uint32_t src, uint32_t address_low,
1017 uint32_t address_high, uint32_t flag)
Jolly Shahed05a712019-03-22 05:33:39 +05301018{
1019 uint32_t payload[PAYLOAD_ARG_CNT];
1020
1021 /* Send request to the PMU */
Tejas Patel18072da2021-02-25 20:16:56 -08001022 PM_PACK_PAYLOAD4(payload, LOADER_MODULE_ID, flag, PM_LOAD_PDI, src,
Jolly Shahed05a712019-03-22 05:33:39 +05301023 address_high, address_low);
1024 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1025}
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001026
1027/**
1028 * pm_get_op_characteristic() - PM call to request operating characteristics
1029 * of a device
1030 * @device_id Device id
1031 * @type Type of the operating characteristic
1032 * (power, temperature and latency)
1033 * @result Returns the operating characteristic for the requested device,
1034 * specified by the type
Tejas Patel18072da2021-02-25 20:16:56 -08001035 * @flag 0 - Call from secure source
1036 * 1 - Call from non-secure source
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001037 *
1038 * @return Returns status, either success or error+reason
1039 */
1040enum pm_ret_status pm_get_op_characteristic(uint32_t device_id,
1041 enum pm_opchar_type type,
Tejas Patel18072da2021-02-25 20:16:56 -08001042 uint32_t *result, uint32_t flag)
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001043{
1044 uint32_t payload[PAYLOAD_ARG_CNT];
1045
1046 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001047 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag,
1048 PM_GET_OP_CHARACTERISTIC, device_id, type);
Saeed Nowshadi2294b422019-06-03 10:22:35 -07001049 return pm_ipi_send_sync(primary_proc, payload, result, 1);
1050}
Tejas Patel5c154e12020-11-25 01:53:12 -08001051
1052/**
1053 * pm_set_max_latency() - PM call to change in the maximum wake-up latency
1054 * requirements for a specific device currently
1055 * used by that CPU.
1056 * @device_id Device ID
1057 * @latency Latency value
Tejas Patel18072da2021-02-25 20:16:56 -08001058 * @flag 0 - Call from secure source
1059 * 1 - Call from non-secure source
Tejas Patel5c154e12020-11-25 01:53:12 -08001060 *
1061 * @return Returns status, either success or error+reason
1062 */
Tejas Patel18072da2021-02-25 20:16:56 -08001063enum pm_ret_status pm_set_max_latency(uint32_t device_id, uint32_t latency,
1064 uint32_t flag)
Tejas Patel5c154e12020-11-25 01:53:12 -08001065{
1066 uint32_t payload[PAYLOAD_ARG_CNT];
1067
1068 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001069 PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, flag, PM_SET_MAX_LATENCY,
Tejas Patel5c154e12020-11-25 01:53:12 -08001070 device_id, latency);
1071
1072 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1073}
Tejas Patel42015552020-11-25 01:56:57 -08001074
1075/**
1076 * pm_register_notifier() - PM call to register a subsystem to be notified
1077 * about the device event
1078 * @device_id Device ID for the Node to which the event is related
1079 * @event Event in question
1080 * @wake Wake subsystem upon capturing the event if value 1
1081 * @enable Enable the registration for value 1, disable for value 0
Tejas Patel18072da2021-02-25 20:16:56 -08001082 * @flag 0 - Call from secure source
1083 * 1 - Call from non-secure source
Tejas Patel42015552020-11-25 01:56:57 -08001084 *
1085 * @return Returns status, either success or error+reason
1086 */
1087enum pm_ret_status pm_register_notifier(uint32_t device_id, uint32_t event,
Tejas Patel18072da2021-02-25 20:16:56 -08001088 uint32_t wake, uint32_t enable,
1089 uint32_t flag)
Tejas Patel42015552020-11-25 01:56:57 -08001090{
1091 uint32_t payload[PAYLOAD_ARG_CNT];
1092
1093 /* Send request to the PMC */
Tejas Patel18072da2021-02-25 20:16:56 -08001094 PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, flag, PM_REGISTER_NOTIFIER,
Tejas Patel42015552020-11-25 01:56:57 -08001095 device_id, event, wake, enable);
1096
1097 return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
1098}