1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware layer
5 * Copyright (C) 2014-2022 Xilinx, Inc.
6 * Copyright (C) 2022 - 2024, Advanced Micro Devices, Inc.
8 * Michal Simek <michal.simek@amd.com>
9 * Davorin Mista <davorin.mista@aggios.com>
10 * Jolly Shah <jollys@xilinx.com>
11 * Rajan Vaja <rajanv@xilinx.com>
14 #include <linux/arm-smccc.h>
15 #include <linux/compiler.h>
16 #include <linux/device.h>
17 #include <linux/init.h>
18 #include <linux/mfd/core.h>
19 #include <linux/module.h>
21 #include <linux/of_platform.h>
22 #include <linux/platform_device.h>
23 #include <linux/slab.h>
24 #include <linux/uaccess.h>
25 #include <linux/hashtable.h>
27 #include <linux/firmware/xlnx-zynqmp.h>
28 #include <linux/firmware/xlnx-event-manager.h>
29 #include "zynqmp-debug.h"
31 /* Max HashMap Order for PM API feature check (1<<7 = 128) */
32 #define PM_API_FEATURE_CHECK_MAX_ORDER 7
34 /* CRL registers and bitfields */
35 #define CRL_APB_BASE 0xFF5E0000U
36 /* BOOT_PIN_CTRL- Used to control the mode pins after boot */
37 #define CRL_APB_BOOT_PIN_CTRL (CRL_APB_BASE + (0x250U))
38 /* BOOT_PIN_CTRL_MASK- out_val[11:8], out_en[3:0] */
39 #define CRL_APB_BOOTPIN_CTRL_MASK 0xF0FU
41 /* IOCTL/QUERY feature payload size */
42 #define FEATURE_PAYLOAD_SIZE 2
44 static bool feature_check_enabled
;
45 static DEFINE_HASHTABLE(pm_api_features_map
, PM_API_FEATURE_CHECK_MAX_ORDER
);
46 static u32 ioctl_features
[FEATURE_PAYLOAD_SIZE
];
47 static u32 query_features
[FEATURE_PAYLOAD_SIZE
];
49 static u32 sip_svc_version
;
50 static struct platform_device
*em_dev
;
53 * struct zynqmp_devinfo - Structure for Zynqmp device instance
54 * @dev: Device Pointer
55 * @feature_conf_id: Feature conf id
57 struct zynqmp_devinfo
{
63 * struct pm_api_feature_data - PM API Feature data
64 * @pm_api_id: PM API Id, used as key to index into hashmap
65 * @feature_status: status of PM API feature: valid, invalid
66 * @hentry: hlist_node that hooks this entry into hashtable
68 struct pm_api_feature_data
{
71 struct hlist_node hentry
;
74 static const struct mfd_cell firmware_devs
[] = {
76 .name
= "zynqmp_power_controller",
81 * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
82 * @ret_status: PMUFW return code
84 * Return: corresponding Linux error code
86 static int zynqmp_pm_ret_code(u32 ret_status
)
90 case XST_PM_DOUBLE_REQ
:
92 case XST_PM_NO_FEATURE
:
94 case XST_PM_INVALID_VERSION
:
96 case XST_PM_NO_ACCESS
:
98 case XST_PM_ABORT_SUSPEND
:
100 case XST_PM_MULT_USER
:
102 case XST_PM_INTERNAL
:
103 case XST_PM_CONFLICT
:
104 case XST_PM_INVALID_NODE
:
105 case XST_PM_INVALID_CRC
:
111 static noinline
int do_fw_call_fail(u32
*ret_payload
, u32 num_args
, ...)
117 * PM function call wrapper
118 * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
120 static int (*do_fw_call
)(u32
*ret_payload
, u32
, ...) = do_fw_call_fail
;
123 * do_fw_call_smc() - Call system-level platform management layer (SMC)
124 * @num_args: Number of variable arguments should be <= 8
125 * @ret_payload: Returned value array
127 * Invoke platform management function via SMC call (no hypervisor present).
129 * Return: Returns status, either success or error+reason
131 static noinline
int do_fw_call_smc(u32
*ret_payload
, u32 num_args
, ...)
133 struct arm_smccc_res res
;
141 va_start(arg_list
, num_args
);
143 for (i
= 0; i
< num_args
; i
++)
144 args
[i
] = va_arg(arg_list
, u64
);
148 arm_smccc_smc(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6], args
[7], &res
);
151 ret_payload
[0] = lower_32_bits(res
.a0
);
152 ret_payload
[1] = upper_32_bits(res
.a0
);
153 ret_payload
[2] = lower_32_bits(res
.a1
);
154 ret_payload
[3] = upper_32_bits(res
.a1
);
155 ret_payload
[4] = lower_32_bits(res
.a2
);
156 ret_payload
[5] = upper_32_bits(res
.a2
);
157 ret_payload
[6] = lower_32_bits(res
.a3
);
160 return zynqmp_pm_ret_code((enum pm_ret_status
)res
.a0
);
164 * do_fw_call_hvc() - Call system-level platform management layer (HVC)
165 * @num_args: Number of variable arguments should be <= 8
166 * @ret_payload: Returned value array
168 * Invoke platform management function via HVC
169 * HVC-based for communication through hypervisor
170 * (no direct communication with ATF).
172 * Return: Returns status, either success or error+reason
174 static noinline
int do_fw_call_hvc(u32
*ret_payload
, u32 num_args
, ...)
176 struct arm_smccc_res res
;
184 va_start(arg_list
, num_args
);
186 for (i
= 0; i
< num_args
; i
++)
187 args
[i
] = va_arg(arg_list
, u64
);
191 arm_smccc_hvc(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6], args
[7], &res
);
194 ret_payload
[0] = lower_32_bits(res
.a0
);
195 ret_payload
[1] = upper_32_bits(res
.a0
);
196 ret_payload
[2] = lower_32_bits(res
.a1
);
197 ret_payload
[3] = upper_32_bits(res
.a1
);
198 ret_payload
[4] = lower_32_bits(res
.a2
);
199 ret_payload
[5] = upper_32_bits(res
.a2
);
200 ret_payload
[6] = lower_32_bits(res
.a3
);
203 return zynqmp_pm_ret_code((enum pm_ret_status
)res
.a0
);
206 static int __do_feature_check_call(const u32 api_id
, u32
*ret_payload
)
211 u32 feature_check_api_id
;
213 module_id
= FIELD_GET(MODULE_ID_MASK
, api_id
);
216 * Feature check of APIs belonging to PM, XSEM, and TF-A are handled by calling
217 * PM_FEATURE_CHECK API. For other modules, call PM_API_FEATURES API.
219 if (module_id
== PM_MODULE_ID
|| module_id
== XSEM_MODULE_ID
|| module_id
== TF_A_MODULE_ID
)
220 feature_check_api_id
= PM_FEATURE_CHECK
;
222 feature_check_api_id
= PM_API_FEATURES
;
225 * Feature check of TF-A APIs is done in the TF-A layer and it expects for
226 * MODULE_ID_MASK bits of SMC's arg[0] to be the same as PM_MODULE_ID.
228 if (module_id
== TF_A_MODULE_ID
) {
229 module_id
= PM_MODULE_ID
;
232 smc_arg
[1] = (api_id
& API_ID_MASK
);
235 smc_arg
[0] = PM_SIP_SVC
| FIELD_PREP(MODULE_ID_MASK
, module_id
) | feature_check_api_id
;
237 ret
= do_fw_call(ret_payload
, 2, smc_arg
[0], smc_arg
[1]);
241 ret
= ret_payload
[1];
246 static int do_feature_check_call(const u32 api_id
)
249 u32 ret_payload
[PAYLOAD_ARG_CNT
];
250 struct pm_api_feature_data
*feature_data
;
252 /* Check for existing entry in hash table for given api */
253 hash_for_each_possible(pm_api_features_map
, feature_data
, hentry
,
255 if (feature_data
->pm_api_id
== api_id
)
256 return feature_data
->feature_status
;
259 /* Add new entry if not present */
260 feature_data
= kmalloc(sizeof(*feature_data
), GFP_ATOMIC
);
264 feature_data
->pm_api_id
= api_id
;
265 ret
= __do_feature_check_call(api_id
, ret_payload
);
267 feature_data
->feature_status
= ret
;
268 hash_add(pm_api_features_map
, &feature_data
->hentry
, api_id
);
270 if (api_id
== PM_IOCTL
)
271 /* Store supported IOCTL IDs mask */
272 memcpy(ioctl_features
, &ret_payload
[2], FEATURE_PAYLOAD_SIZE
* 4);
273 else if (api_id
== PM_QUERY_DATA
)
274 /* Store supported QUERY IDs mask */
275 memcpy(query_features
, &ret_payload
[2], FEATURE_PAYLOAD_SIZE
* 4);
281 * zynqmp_pm_feature() - Check whether given feature is supported or not and
282 * store supported IOCTL/QUERY ID mask
283 * @api_id: API ID to check
285 * Return: Returns status, either success or error+reason
287 int zynqmp_pm_feature(const u32 api_id
)
291 if (!feature_check_enabled
)
294 ret
= do_feature_check_call(api_id
);
298 EXPORT_SYMBOL_GPL(zynqmp_pm_feature
);
301 * zynqmp_pm_is_function_supported() - Check whether given IOCTL/QUERY function
302 * is supported or not
303 * @api_id: PM_IOCTL or PM_QUERY_DATA
304 * @id: IOCTL or QUERY function IDs
306 * Return: Returns status, either success or error+reason
308 int zynqmp_pm_is_function_supported(const u32 api_id
, const u32 id
)
313 /* Input arguments validation */
314 if (id
>= 64 || (api_id
!= PM_IOCTL
&& api_id
!= PM_QUERY_DATA
))
317 /* Check feature check API version */
318 ret
= do_feature_check_call(PM_FEATURE_CHECK
);
322 /* Check if feature check version 2 is supported or not */
323 if ((ret
& FIRMWARE_VERSION_MASK
) == PM_API_VERSION_2
) {
325 * Call feature check for IOCTL/QUERY API to get IOCTL ID or
326 * QUERY ID feature status.
328 ret
= do_feature_check_call(api_id
);
332 bit_mask
= (api_id
== PM_IOCTL
) ? ioctl_features
: query_features
;
334 if ((bit_mask
[(id
/ 32)] & BIT((id
% 32))) == 0U)
342 EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported
);
345 * zynqmp_pm_invoke_fw_fn() - Invoke the system-level platform management layer
346 * caller function depending on the configuration
347 * @pm_api_id: Requested PM-API call
348 * @ret_payload: Returned value array
349 * @num_args: Number of arguments to requested PM-API call
351 * Invoke platform management function for SMC or HVC call, depending on
353 * Following SMC Calling Convention (SMCCC) for SMC64:
354 * Pm Function Identifier,
355 * PM_SIP_SVC + PASS_THROUGH_FW_CMD_ID =
356 * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
357 * ((SMC_64) << FUNCID_CC_SHIFT)
358 * ((SIP_START) << FUNCID_OEN_SHIFT)
359 * (PASS_THROUGH_FW_CMD_ID))
361 * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
362 * PASS_THROUGH_FW_CMD_ID - Fixed SiP SVC call ID for FW specific calls.
364 * Return: Returns status, either success or error+reason
366 int zynqmp_pm_invoke_fw_fn(u32 pm_api_id
, u32
*ret_payload
, u32 num_args
, ...)
369 * Added SIP service call Function Identifier
370 * Make sure to stay in x0 register
372 u64 smc_arg
[SMC_ARG_CNT_64
];
375 u32 args
[SMC_ARG_CNT_32
] = {0};
378 if (num_args
> SMC_ARG_CNT_32
)
381 va_start(arg_list
, num_args
);
383 /* Check if feature is supported or not */
384 ret
= zynqmp_pm_feature(pm_api_id
);
388 for (i
= 0; i
< num_args
; i
++)
389 args
[i
] = va_arg(arg_list
, u32
);
393 module_id
= FIELD_GET(PLM_MODULE_ID_MASK
, pm_api_id
);
396 module_id
= XPM_MODULE_ID
;
398 smc_arg
[0] = PM_SIP_SVC
| PASS_THROUGH_FW_CMD_ID
;
399 smc_arg
[1] = ((u64
)args
[0] << 32U) | FIELD_PREP(PLM_MODULE_ID_MASK
, module_id
) |
400 (pm_api_id
& API_ID_MASK
);
401 for (i
= 1; i
< (SMC_ARG_CNT_64
- 1); i
++)
402 smc_arg
[i
+ 1] = ((u64
)args
[(i
* 2)] << 32U) | args
[(i
* 2) - 1];
404 return do_fw_call(ret_payload
, 8, smc_arg
[0], smc_arg
[1], smc_arg
[2], smc_arg
[3],
405 smc_arg
[4], smc_arg
[5], smc_arg
[6], smc_arg
[7]);
409 * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
410 * caller function depending on the configuration
411 * @pm_api_id: Requested PM-API call
412 * @ret_payload: Returned value array
413 * @num_args: Number of arguments to requested PM-API call
415 * Invoke platform management function for SMC or HVC call, depending on
417 * Following SMC Calling Convention (SMCCC) for SMC64:
418 * Pm Function Identifier,
419 * PM_SIP_SVC + PM_API_ID =
420 * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
421 * ((SMC_64) << FUNCID_CC_SHIFT)
422 * ((SIP_START) << FUNCID_OEN_SHIFT)
423 * ((PM_API_ID) & FUNCID_NUM_MASK))
425 * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
426 * PM_API_ID - Platform Management API ID.
428 * Return: Returns status, either success or error+reason
430 int zynqmp_pm_invoke_fn(u32 pm_api_id
, u32
*ret_payload
, u32 num_args
, ...)
433 * Added SIP service call Function Identifier
434 * Make sure to stay in x0 register
444 va_start(arg_list
, num_args
);
446 /* Check if feature is supported or not */
447 ret
= zynqmp_pm_feature(pm_api_id
);
451 for (i
= 0; i
< num_args
; i
++)
452 args
[i
] = va_arg(arg_list
, u32
);
456 smc_arg
[0] = PM_SIP_SVC
| pm_api_id
;
457 for (i
= 0; i
< 7; i
++)
458 smc_arg
[i
+ 1] = ((u64
)args
[(i
* 2) + 1] << 32) | args
[i
* 2];
460 return do_fw_call(ret_payload
, 8, smc_arg
[0], smc_arg
[1], smc_arg
[2], smc_arg
[3],
461 smc_arg
[4], smc_arg
[5], smc_arg
[6], smc_arg
[7]);
464 static u32 pm_api_version
;
465 static u32 pm_tz_version
;
466 static u32 pm_family_code
;
467 static u32 pm_sub_family_code
;
469 int zynqmp_pm_register_sgi(u32 sgi_num
, u32 reset
)
473 ret
= zynqmp_pm_invoke_fn(TF_A_PM_REGISTER_SGI
, NULL
, 2, sgi_num
, reset
);
474 if (ret
!= -EOPNOTSUPP
&& !ret
)
477 /* try old implementation as fallback strategy if above fails */
478 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, IOCTL_REGISTER_SGI
, sgi_num
, reset
);
482 * zynqmp_pm_get_api_version() - Get version number of PMU PM firmware
483 * @version: Returned version value
485 * Return: Returns status, either success or error+reason
487 int zynqmp_pm_get_api_version(u32
*version
)
489 u32 ret_payload
[PAYLOAD_ARG_CNT
];
495 /* Check is PM API version already verified */
496 if (pm_api_version
> 0) {
497 *version
= pm_api_version
;
500 ret
= zynqmp_pm_invoke_fn(PM_GET_API_VERSION
, ret_payload
, 0);
501 *version
= ret_payload
[1];
505 EXPORT_SYMBOL_GPL(zynqmp_pm_get_api_version
);
508 * zynqmp_pm_get_chipid - Get silicon ID registers
509 * @idcode: IDCODE register
510 * @version: version register
512 * Return: Returns the status of the operation and the idcode and version
513 * registers in @idcode and @version.
515 int zynqmp_pm_get_chipid(u32
*idcode
, u32
*version
)
517 u32 ret_payload
[PAYLOAD_ARG_CNT
];
520 if (!idcode
|| !version
)
523 ret
= zynqmp_pm_invoke_fn(PM_GET_CHIPID
, ret_payload
, 0);
524 *idcode
= ret_payload
[1];
525 *version
= ret_payload
[2];
529 EXPORT_SYMBOL_GPL(zynqmp_pm_get_chipid
);
532 * zynqmp_pm_get_family_info() - Get family info of platform
533 * @family: Returned family code value
534 * @subfamily: Returned sub-family code value
536 * Return: Returns status, either success or error+reason
538 int zynqmp_pm_get_family_info(u32
*family
, u32
*subfamily
)
540 u32 ret_payload
[PAYLOAD_ARG_CNT
];
544 /* Check is family or sub-family code already received */
545 if (pm_family_code
&& pm_sub_family_code
) {
546 *family
= pm_family_code
;
547 *subfamily
= pm_sub_family_code
;
551 ret
= zynqmp_pm_invoke_fn(PM_GET_CHIPID
, ret_payload
, 0);
555 idcode
= ret_payload
[1];
556 pm_family_code
= FIELD_GET(FAMILY_CODE_MASK
, idcode
);
557 pm_sub_family_code
= FIELD_GET(SUB_FAMILY_CODE_MASK
, idcode
);
558 *family
= pm_family_code
;
559 *subfamily
= pm_sub_family_code
;
563 EXPORT_SYMBOL_GPL(zynqmp_pm_get_family_info
);
566 * zynqmp_pm_get_sip_svc_version() - Get SiP service call version
567 * @version: Returned version value
569 * Return: Returns status, either success or error+reason
571 static int zynqmp_pm_get_sip_svc_version(u32
*version
)
573 struct arm_smccc_res res
;
574 u64 args
[SMC_ARG_CNT_64
] = {0};
579 /* Check if SiP SVC version already verified */
580 if (sip_svc_version
> 0) {
581 *version
= sip_svc_version
;
585 args
[0] = GET_SIP_SVC_VERSION
;
587 arm_smccc_smc(args
[0], args
[1], args
[2], args
[3], args
[4], args
[5], args
[6], args
[7], &res
);
589 *version
= ((lower_32_bits(res
.a0
) << 16U) | lower_32_bits(res
.a1
));
591 return zynqmp_pm_ret_code(XST_PM_SUCCESS
);
595 * zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
596 * @version: Returned version value
598 * Return: Returns status, either success or error+reason
600 static int zynqmp_pm_get_trustzone_version(u32
*version
)
602 u32 ret_payload
[PAYLOAD_ARG_CNT
];
608 /* Check is PM trustzone version already verified */
609 if (pm_tz_version
> 0) {
610 *version
= pm_tz_version
;
613 ret
= zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION
, ret_payload
, 0);
614 *version
= ret_payload
[1];
620 * get_set_conduit_method() - Choose SMC or HVC based communication
621 * @np: Pointer to the device_node structure
623 * Use SMC or HVC-based functions to communicate with EL2/EL3.
625 * Return: Returns 0 on success or error code
627 static int get_set_conduit_method(struct device_node
*np
)
631 if (of_property_read_string(np
, "method", &method
)) {
632 pr_warn("%s missing \"method\" property\n", __func__
);
636 if (!strcmp("hvc", method
)) {
637 do_fw_call
= do_fw_call_hvc
;
638 } else if (!strcmp("smc", method
)) {
639 do_fw_call
= do_fw_call_smc
;
641 pr_warn("%s Invalid \"method\" property: %s\n",
650 * zynqmp_pm_query_data() - Get query data from firmware
651 * @qdata: Variable to the zynqmp_pm_query_data structure
652 * @out: Returned output value
654 * Return: Returns status, either success or error+reason
656 int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata
, u32
*out
)
659 u32 ret_payload
[PAYLOAD_ARG_CNT
] = {0};
661 if (sip_svc_version
>= SIP_SVC_PASSTHROUGH_VERSION
) {
662 ret
= zynqmp_pm_invoke_fw_fn(PM_QUERY_DATA
, ret_payload
, 4,
663 qdata
.qid
, qdata
.arg1
,
664 qdata
.arg2
, qdata
.arg3
);
665 /* To support backward compatibility */
666 if (!ret
&& !ret_payload
[0]) {
668 * TF-A passes return status on 0th index but
669 * api to get clock name reads data from 0th
670 * index so pass data at 0th index instead of
673 if (qdata
.qid
== PM_QID_CLOCK_GET_NAME
||
674 qdata
.qid
== PM_QID_PINCTRL_GET_FUNCTION_NAME
)
677 for (; i
< PAYLOAD_ARG_CNT
; i
++, out
++)
678 *out
= ret_payload
[i
];
684 ret
= zynqmp_pm_invoke_fn(PM_QUERY_DATA
, out
, 4, qdata
.qid
,
685 qdata
.arg1
, qdata
.arg2
, qdata
.arg3
);
688 * For clock name query, all bytes in SMC response are clock name
689 * characters and return code is always success. For invalid clocks,
690 * clock name bytes would be zeros.
692 return qdata
.qid
== PM_QID_CLOCK_GET_NAME
? 0 : ret
;
694 EXPORT_SYMBOL_GPL(zynqmp_pm_query_data
);
697 * zynqmp_pm_clock_enable() - Enable the clock for given id
698 * @clock_id: ID of the clock to be enabled
700 * This function is used by master to enable the clock
701 * including peripherals and PLL clocks.
703 * Return: Returns status, either success or error+reason
705 int zynqmp_pm_clock_enable(u32 clock_id
)
707 return zynqmp_pm_invoke_fn(PM_CLOCK_ENABLE
, NULL
, 1, clock_id
);
709 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_enable
);
712 * zynqmp_pm_clock_disable() - Disable the clock for given id
713 * @clock_id: ID of the clock to be disable
715 * This function is used by master to disable the clock
716 * including peripherals and PLL clocks.
718 * Return: Returns status, either success or error+reason
720 int zynqmp_pm_clock_disable(u32 clock_id
)
722 return zynqmp_pm_invoke_fn(PM_CLOCK_DISABLE
, NULL
, 1, clock_id
);
724 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_disable
);
727 * zynqmp_pm_clock_getstate() - Get the clock state for given id
728 * @clock_id: ID of the clock to be queried
729 * @state: 1/0 (Enabled/Disabled)
731 * This function is used by master to get the state of clock
732 * including peripherals and PLL clocks.
734 * Return: Returns status, either success or error+reason
736 int zynqmp_pm_clock_getstate(u32 clock_id
, u32
*state
)
738 u32 ret_payload
[PAYLOAD_ARG_CNT
];
741 ret
= zynqmp_pm_invoke_fn(PM_CLOCK_GETSTATE
, ret_payload
, 1, clock_id
);
742 *state
= ret_payload
[1];
746 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getstate
);
749 * zynqmp_pm_clock_setdivider() - Set the clock divider for given id
750 * @clock_id: ID of the clock
751 * @divider: divider value
753 * This function is used by master to set divider for any clock
754 * to achieve desired rate.
756 * Return: Returns status, either success or error+reason
758 int zynqmp_pm_clock_setdivider(u32 clock_id
, u32 divider
)
760 return zynqmp_pm_invoke_fn(PM_CLOCK_SETDIVIDER
, NULL
, 2, clock_id
, divider
);
762 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setdivider
);
765 * zynqmp_pm_clock_getdivider() - Get the clock divider for given id
766 * @clock_id: ID of the clock
767 * @divider: divider value
769 * This function is used by master to get divider values
772 * Return: Returns status, either success or error+reason
774 int zynqmp_pm_clock_getdivider(u32 clock_id
, u32
*divider
)
776 u32 ret_payload
[PAYLOAD_ARG_CNT
];
779 ret
= zynqmp_pm_invoke_fn(PM_CLOCK_GETDIVIDER
, ret_payload
, 1, clock_id
);
780 *divider
= ret_payload
[1];
784 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getdivider
);
787 * zynqmp_pm_clock_setparent() - Set the clock parent for given id
788 * @clock_id: ID of the clock
789 * @parent_id: parent id
791 * This function is used by master to set parent for any clock.
793 * Return: Returns status, either success or error+reason
795 int zynqmp_pm_clock_setparent(u32 clock_id
, u32 parent_id
)
797 return zynqmp_pm_invoke_fn(PM_CLOCK_SETPARENT
, NULL
, 2, clock_id
, parent_id
);
799 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setparent
);
802 * zynqmp_pm_clock_getparent() - Get the clock parent for given id
803 * @clock_id: ID of the clock
804 * @parent_id: parent id
806 * This function is used by master to get parent index
809 * Return: Returns status, either success or error+reason
811 int zynqmp_pm_clock_getparent(u32 clock_id
, u32
*parent_id
)
813 u32 ret_payload
[PAYLOAD_ARG_CNT
];
816 ret
= zynqmp_pm_invoke_fn(PM_CLOCK_GETPARENT
, ret_payload
, 1, clock_id
);
817 *parent_id
= ret_payload
[1];
821 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getparent
);
824 * zynqmp_pm_set_pll_frac_mode() - PM API for set PLL mode
826 * @clk_id: PLL clock ID
827 * @mode: PLL mode (PLL_MODE_FRAC/PLL_MODE_INT)
829 * This function sets PLL mode
831 * Return: Returns status, either success or error+reason
833 int zynqmp_pm_set_pll_frac_mode(u32 clk_id
, u32 mode
)
835 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_SET_PLL_FRAC_MODE
, clk_id
, mode
);
837 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_mode
);
840 * zynqmp_pm_get_pll_frac_mode() - PM API for get PLL mode
842 * @clk_id: PLL clock ID
845 * This function return current PLL mode
847 * Return: Returns status, either success or error+reason
849 int zynqmp_pm_get_pll_frac_mode(u32 clk_id
, u32
*mode
)
851 return zynqmp_pm_invoke_fn(PM_IOCTL
, mode
, 3, 0, IOCTL_GET_PLL_FRAC_MODE
, clk_id
);
853 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_mode
);
856 * zynqmp_pm_set_pll_frac_data() - PM API for setting pll fraction data
858 * @clk_id: PLL clock ID
859 * @data: fraction data
861 * This function sets fraction data.
862 * It is valid for fraction mode only.
864 * Return: Returns status, either success or error+reason
866 int zynqmp_pm_set_pll_frac_data(u32 clk_id
, u32 data
)
868 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_SET_PLL_FRAC_DATA
, clk_id
, data
);
870 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_data
);
873 * zynqmp_pm_get_pll_frac_data() - PM API for getting pll fraction data
875 * @clk_id: PLL clock ID
876 * @data: fraction data
878 * This function returns fraction data value.
880 * Return: Returns status, either success or error+reason
882 int zynqmp_pm_get_pll_frac_data(u32 clk_id
, u32
*data
)
884 return zynqmp_pm_invoke_fn(PM_IOCTL
, data
, 3, 0, IOCTL_GET_PLL_FRAC_DATA
, clk_id
);
886 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_data
);
889 * zynqmp_pm_set_sd_tapdelay() - Set tap delay for the SD device
891 * @node_id: Node ID of the device
892 * @type: Type of tap delay to set (input/output)
893 * @value: Value to set fot the tap delay
895 * This function sets input/output tap delay for the SD device.
897 * Return: Returns status, either success or error+reason
899 int zynqmp_pm_set_sd_tapdelay(u32 node_id
, u32 type
, u32 value
)
901 u32 reg
= (type
== PM_TAPDELAY_INPUT
) ? SD_ITAPDLY
: SD_OTAPDLYSEL
;
902 u32 mask
= (node_id
== NODE_SD_0
) ? GENMASK(15, 0) : GENMASK(31, 16);
905 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, node_id
, IOCTL_SET_SD_TAPDELAY
, type
,
910 * Work around completely misdesigned firmware API on Xilinx ZynqMP.
911 * The IOCTL_SET_SD_TAPDELAY firmware call allows the caller to only
912 * ever set IOU_SLCR SD_ITAPDLY Register SD0_ITAPDLYENA/SD1_ITAPDLYENA
913 * bits, but there is no matching call to clear those bits. If those
914 * bits are not cleared, SDMMC tuning may fail.
916 * Luckily, there are PM_MMIO_READ/PM_MMIO_WRITE calls which seem to
917 * allow complete unrestricted access to all address space, including
918 * IOU_SLCR SD_ITAPDLY Register and all the other registers, access
919 * to which was supposed to be protected by the current firmware API.
921 * Use PM_MMIO_READ/PM_MMIO_WRITE to re-implement the missing counter
922 * part of IOCTL_SET_SD_TAPDELAY which clears SDx_ITAPDLYENA bits.
924 return zynqmp_pm_invoke_fn(PM_MMIO_WRITE
, NULL
, 2, reg
, mask
);
926 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_tapdelay
);
929 * zynqmp_pm_sd_dll_reset() - Reset DLL logic
931 * @node_id: Node ID of the device
934 * This function resets DLL logic for the SD device.
936 * Return: Returns status, either success or error+reason
938 int zynqmp_pm_sd_dll_reset(u32 node_id
, u32 type
)
940 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, node_id
, IOCTL_SD_DLL_RESET
, type
);
942 EXPORT_SYMBOL_GPL(zynqmp_pm_sd_dll_reset
);
945 * zynqmp_pm_ospi_mux_select() - OSPI Mux selection
947 * @dev_id: Device Id of the OSPI device.
948 * @select: OSPI Mux select value.
950 * This function select the OSPI Mux.
952 * Return: Returns status, either success or error+reason
954 int zynqmp_pm_ospi_mux_select(u32 dev_id
, u32 select
)
956 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, dev_id
, IOCTL_OSPI_MUX_SELECT
, select
);
958 EXPORT_SYMBOL_GPL(zynqmp_pm_ospi_mux_select
);
961 * zynqmp_pm_write_ggs() - PM API for writing global general storage (ggs)
962 * @index: GGS register index
963 * @value: Register value to be written
965 * This function writes value to GGS register.
967 * Return: Returns status, either success or error+reason
969 int zynqmp_pm_write_ggs(u32 index
, u32 value
)
971 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_WRITE_GGS
, index
, value
);
973 EXPORT_SYMBOL_GPL(zynqmp_pm_write_ggs
);
976 * zynqmp_pm_read_ggs() - PM API for reading global general storage (ggs)
977 * @index: GGS register index
978 * @value: Register value to be written
980 * This function returns GGS register value.
982 * Return: Returns status, either success or error+reason
984 int zynqmp_pm_read_ggs(u32 index
, u32
*value
)
986 return zynqmp_pm_invoke_fn(PM_IOCTL
, value
, 3, 0, IOCTL_READ_GGS
, index
);
988 EXPORT_SYMBOL_GPL(zynqmp_pm_read_ggs
);
991 * zynqmp_pm_write_pggs() - PM API for writing persistent global general
993 * @index: PGGS register index
994 * @value: Register value to be written
996 * This function writes value to PGGS register.
998 * Return: Returns status, either success or error+reason
1000 int zynqmp_pm_write_pggs(u32 index
, u32 value
)
1002 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_WRITE_PGGS
, index
, value
);
1004 EXPORT_SYMBOL_GPL(zynqmp_pm_write_pggs
);
1007 * zynqmp_pm_read_pggs() - PM API for reading persistent global general
1009 * @index: PGGS register index
1010 * @value: Register value to be written
1012 * This function returns PGGS register value.
1014 * Return: Returns status, either success or error+reason
1016 int zynqmp_pm_read_pggs(u32 index
, u32
*value
)
1018 return zynqmp_pm_invoke_fn(PM_IOCTL
, value
, 3, 0, IOCTL_READ_PGGS
, index
);
1020 EXPORT_SYMBOL_GPL(zynqmp_pm_read_pggs
);
1022 int zynqmp_pm_set_tapdelay_bypass(u32 index
, u32 value
)
1024 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_SET_TAPDELAY_BYPASS
, index
, value
);
1026 EXPORT_SYMBOL_GPL(zynqmp_pm_set_tapdelay_bypass
);
1029 * zynqmp_pm_set_boot_health_status() - PM API for setting healthy boot status
1030 * @value: Status value to be written
1032 * This function sets healthy bit value to indicate boot health status
1035 * Return: Returns status, either success or error+reason
1037 int zynqmp_pm_set_boot_health_status(u32 value
)
1039 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, 0, IOCTL_SET_BOOT_HEALTH_STATUS
, value
);
1043 * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
1044 * @reset: Reset to be configured
1045 * @assert_flag: Flag stating should reset be asserted (1) or
1048 * Return: Returns status, either success or error+reason
1050 int zynqmp_pm_reset_assert(const u32 reset
,
1051 const enum zynqmp_pm_reset_action assert_flag
)
1053 return zynqmp_pm_invoke_fn(PM_RESET_ASSERT
, NULL
, 2, reset
, assert_flag
);
1055 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_assert
);
1058 * zynqmp_pm_reset_get_status - Get status of the reset
1059 * @reset: Reset whose status should be returned
1060 * @status: Returned status
1062 * Return: Returns status, either success or error+reason
1064 int zynqmp_pm_reset_get_status(const u32 reset
, u32
*status
)
1066 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1072 ret
= zynqmp_pm_invoke_fn(PM_RESET_GET_STATUS
, ret_payload
, 1, reset
);
1073 *status
= ret_payload
[1];
1077 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_get_status
);
1080 * zynqmp_pm_fpga_load - Perform the fpga load
1081 * @address: Address to write to
1082 * @size: pl bitstream size
1083 * @flags: Bitstream type
1084 * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
1085 * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
1087 * This function provides access to pmufw. To transfer
1088 * the required bitstream into PL.
1090 * Return: Returns status, either success or error+reason
1092 int zynqmp_pm_fpga_load(const u64 address
, const u32 size
, const u32 flags
)
1094 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1097 ret
= zynqmp_pm_invoke_fn(PM_FPGA_LOAD
, ret_payload
, 4, lower_32_bits(address
),
1098 upper_32_bits(address
), size
, flags
);
1100 return -ret_payload
[0];
1104 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load
);
1107 * zynqmp_pm_fpga_get_status - Read value from PCAP status register
1108 * @value: Value to read
1110 * This function provides access to the pmufw to get the PCAP
1113 * Return: Returns status, either success or error+reason
1115 int zynqmp_pm_fpga_get_status(u32
*value
)
1117 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1123 ret
= zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS
, ret_payload
, 0);
1124 *value
= ret_payload
[1];
1128 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status
);
1131 * zynqmp_pm_fpga_get_config_status - Get the FPGA configuration status.
1132 * @value: Buffer to store FPGA configuration status.
1134 * This function provides access to the pmufw to get the FPGA configuration
1137 * Return: 0 on success, a negative value on error
1139 int zynqmp_pm_fpga_get_config_status(u32
*value
)
1141 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1142 u32 buf
, lower_addr
, upper_addr
;
1148 lower_addr
= lower_32_bits((u64
)&buf
);
1149 upper_addr
= upper_32_bits((u64
)&buf
);
1151 ret
= zynqmp_pm_invoke_fn(PM_FPGA_READ
, ret_payload
, 4,
1152 XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET
, lower_addr
, upper_addr
,
1153 XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG
);
1155 *value
= ret_payload
[1];
1159 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_config_status
);
1162 * zynqmp_pm_pinctrl_request - Request Pin from firmware
1163 * @pin: Pin number to request
1165 * This function requests pin from firmware.
1167 * Return: Returns status, either success or error+reason.
1169 int zynqmp_pm_pinctrl_request(const u32 pin
)
1171 return zynqmp_pm_invoke_fn(PM_PINCTRL_REQUEST
, NULL
, 1, pin
);
1173 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_request
);
1176 * zynqmp_pm_pinctrl_release - Inform firmware that Pin control is released
1177 * @pin: Pin number to release
1179 * This function release pin from firmware.
1181 * Return: Returns status, either success or error+reason.
1183 int zynqmp_pm_pinctrl_release(const u32 pin
)
1185 return zynqmp_pm_invoke_fn(PM_PINCTRL_RELEASE
, NULL
, 1, pin
);
1187 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_release
);
1190 * zynqmp_pm_pinctrl_set_function - Set requested function for the pin
1192 * @id: Function ID to set
1194 * This function sets requested function for the given pin.
1196 * Return: Returns status, either success or error+reason.
1198 int zynqmp_pm_pinctrl_set_function(const u32 pin
, const u32 id
)
1200 return zynqmp_pm_invoke_fn(PM_PINCTRL_SET_FUNCTION
, NULL
, 2, pin
, id
);
1202 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_function
);
1205 * zynqmp_pm_pinctrl_get_config - Get configuration parameter for the pin
1207 * @param: Parameter to get
1208 * @value: Buffer to store parameter value
1210 * This function gets requested configuration parameter for the given pin.
1212 * Return: Returns status, either success or error+reason.
1214 int zynqmp_pm_pinctrl_get_config(const u32 pin
, const u32 param
,
1217 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1223 ret
= zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_GET
, ret_payload
, 2, pin
, param
);
1224 *value
= ret_payload
[1];
1228 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_config
);
1231 * zynqmp_pm_pinctrl_set_config - Set configuration parameter for the pin
1233 * @param: Parameter to set
1234 * @value: Parameter value to set
1236 * This function sets requested configuration parameter for the given pin.
1238 * Return: Returns status, either success or error+reason.
1240 int zynqmp_pm_pinctrl_set_config(const u32 pin
, const u32 param
,
1245 if (pm_family_code
== ZYNQMP_FAMILY_CODE
&&
1246 param
== PM_PINCTRL_CONFIG_TRI_STATE
) {
1247 ret
= zynqmp_pm_feature(PM_PINCTRL_CONFIG_PARAM_SET
);
1248 if (ret
< PM_PINCTRL_PARAM_SET_VERSION
) {
1249 pr_warn("The requested pinctrl feature is not supported in the current firmware.\n"
1250 "Expected firmware version is 2023.1 and above for this feature to work.\r\n");
1255 return zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_SET
, NULL
, 3, pin
, param
, value
);
1257 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_config
);
1260 * zynqmp_pm_bootmode_read() - PM Config API for read bootpin status
1261 * @ps_mode: Returned output value of ps_mode
1263 * This API function is to be used for notify the power management controller
1264 * to read bootpin status.
1266 * Return: status, either success or error+reason
1268 unsigned int zynqmp_pm_bootmode_read(u32
*ps_mode
)
1271 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1273 ret
= zynqmp_pm_invoke_fn(PM_MMIO_READ
, ret_payload
, 1, CRL_APB_BOOT_PIN_CTRL
);
1275 *ps_mode
= ret_payload
[1];
1279 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_read
);
1282 * zynqmp_pm_bootmode_write() - PM Config API for Configure bootpin
1283 * @ps_mode: Value to be written to the bootpin ctrl register
1285 * This API function is to be used for notify the power management controller
1286 * to configure bootpin.
1288 * Return: Returns status, either success or error+reason
1290 int zynqmp_pm_bootmode_write(u32 ps_mode
)
1292 return zynqmp_pm_invoke_fn(PM_MMIO_WRITE
, NULL
, 3, CRL_APB_BOOT_PIN_CTRL
,
1293 CRL_APB_BOOTPIN_CTRL_MASK
, ps_mode
);
1295 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_write
);
1298 * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
1299 * master has initialized its own power management
1301 * Return: Returns status, either success or error+reason
1303 * This API function is to be used for notify the power management controller
1304 * about the completed power management initialization.
1306 int zynqmp_pm_init_finalize(void)
1308 return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE
, NULL
, 0);
1310 EXPORT_SYMBOL_GPL(zynqmp_pm_init_finalize
);
1313 * zynqmp_pm_set_suspend_mode() - Set system suspend mode
1314 * @mode: Mode to set for system suspend
1316 * This API function is used to set mode of system suspend.
1318 * Return: Returns status, either success or error+reason
1320 int zynqmp_pm_set_suspend_mode(u32 mode
)
1322 return zynqmp_pm_invoke_fn(PM_SET_SUSPEND_MODE
, NULL
, 1, mode
);
1324 EXPORT_SYMBOL_GPL(zynqmp_pm_set_suspend_mode
);
1327 * zynqmp_pm_request_node() - Request a node with specific capabilities
1328 * @node: Node ID of the slave
1329 * @capabilities: Requested capabilities of the slave
1330 * @qos: Quality of service (not supported)
1331 * @ack: Flag to specify whether acknowledge is requested
1333 * This function is used by master to request particular node from firmware.
1334 * Every master must request node before using it.
1336 * Return: Returns status, either success or error+reason
1338 int zynqmp_pm_request_node(const u32 node
, const u32 capabilities
,
1339 const u32 qos
, const enum zynqmp_pm_request_ack ack
)
1341 return zynqmp_pm_invoke_fn(PM_REQUEST_NODE
, NULL
, 4, node
, capabilities
, qos
, ack
);
1343 EXPORT_SYMBOL_GPL(zynqmp_pm_request_node
);
1346 * zynqmp_pm_release_node() - Release a node
1347 * @node: Node ID of the slave
1349 * This function is used by master to inform firmware that master
1350 * has released node. Once released, master must not use that node
1351 * without re-request.
1353 * Return: Returns status, either success or error+reason
1355 int zynqmp_pm_release_node(const u32 node
)
1357 return zynqmp_pm_invoke_fn(PM_RELEASE_NODE
, NULL
, 1, node
);
1359 EXPORT_SYMBOL_GPL(zynqmp_pm_release_node
);
1362 * zynqmp_pm_get_rpu_mode() - Get RPU mode
1363 * @node_id: Node ID of the device
1364 * @rpu_mode: return by reference value
1365 * either split or lockstep
1367 * Return: return 0 on success or error+reason.
1368 * if success, then rpu_mode will be set
1369 * to current rpu mode.
1371 int zynqmp_pm_get_rpu_mode(u32 node_id
, enum rpu_oper_mode
*rpu_mode
)
1373 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1376 ret
= zynqmp_pm_invoke_fn(PM_IOCTL
, ret_payload
, 2, node_id
, IOCTL_GET_RPU_OPER_MODE
);
1378 /* only set rpu_mode if no error */
1379 if (ret
== XST_PM_SUCCESS
)
1380 *rpu_mode
= ret_payload
[0];
1384 EXPORT_SYMBOL_GPL(zynqmp_pm_get_rpu_mode
);
1387 * zynqmp_pm_set_rpu_mode() - Set RPU mode
1388 * @node_id: Node ID of the device
1389 * @rpu_mode: Argument 1 to requested IOCTL call. either split or lockstep
1391 * This function is used to set RPU mode to split or
1394 * Return: Returns status, either success or error+reason
1396 int zynqmp_pm_set_rpu_mode(u32 node_id
, enum rpu_oper_mode rpu_mode
)
1398 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, node_id
, IOCTL_SET_RPU_OPER_MODE
,
1401 EXPORT_SYMBOL_GPL(zynqmp_pm_set_rpu_mode
);
1404 * zynqmp_pm_set_tcm_config - configure TCM
1405 * @node_id: Firmware specific TCM subsystem ID
1406 * @tcm_mode: Argument 1 to requested IOCTL call
1407 * either PM_RPU_TCM_COMB or PM_RPU_TCM_SPLIT
1409 * This function is used to set RPU mode to split or combined
1411 * Return: status: 0 for success, else failure
1413 int zynqmp_pm_set_tcm_config(u32 node_id
, enum rpu_tcm_comb tcm_mode
)
1415 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 3, node_id
, IOCTL_TCM_COMB_CONFIG
,
1418 EXPORT_SYMBOL_GPL(zynqmp_pm_set_tcm_config
);
1421 * zynqmp_pm_force_pwrdwn - PM call to request for another PU or subsystem to
1422 * be powered down forcefully
1423 * @node: Node ID of the targeted PU or subsystem
1424 * @ack: Flag to specify whether acknowledge is requested
1426 * Return: status, either success or error+reason
1428 int zynqmp_pm_force_pwrdwn(const u32 node
,
1429 const enum zynqmp_pm_request_ack ack
)
1431 return zynqmp_pm_invoke_fn(PM_FORCE_POWERDOWN
, NULL
, 2, node
, ack
);
1433 EXPORT_SYMBOL_GPL(zynqmp_pm_force_pwrdwn
);
1436 * zynqmp_pm_request_wake - PM call to wake up selected master or subsystem
1437 * @node: Node ID of the master or subsystem
1438 * @set_addr: Specifies whether the address argument is relevant
1439 * @address: Address from which to resume when woken up
1440 * @ack: Flag to specify whether acknowledge requested
1442 * Return: status, either success or error+reason
1444 int zynqmp_pm_request_wake(const u32 node
,
1445 const bool set_addr
,
1447 const enum zynqmp_pm_request_ack ack
)
1449 /* set_addr flag is encoded into 1st bit of address */
1450 return zynqmp_pm_invoke_fn(PM_REQUEST_WAKEUP
, NULL
, 4, node
, address
| set_addr
,
1451 address
>> 32, ack
);
1453 EXPORT_SYMBOL_GPL(zynqmp_pm_request_wake
);
1456 * zynqmp_pm_set_requirement() - PM call to set requirement for PM slaves
1457 * @node: Node ID of the slave
1458 * @capabilities: Requested capabilities of the slave
1459 * @qos: Quality of service (not supported)
1460 * @ack: Flag to specify whether acknowledge is requested
1462 * This API function is to be used for slaves a PU already has requested
1463 * to change its capabilities.
1465 * Return: Returns status, either success or error+reason
1467 int zynqmp_pm_set_requirement(const u32 node
, const u32 capabilities
,
1469 const enum zynqmp_pm_request_ack ack
)
1471 return zynqmp_pm_invoke_fn(PM_SET_REQUIREMENT
, NULL
, 4, node
, capabilities
, qos
, ack
);
1473 EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement
);
1476 * zynqmp_pm_load_pdi - Load and process PDI
1477 * @src: Source device where PDI is located
1478 * @address: PDI src address
1480 * This function provides support to load PDI from linux
1482 * Return: Returns status, either success or error+reason
1484 int zynqmp_pm_load_pdi(const u32 src
, const u64 address
)
1486 return zynqmp_pm_invoke_fn(PM_LOAD_PDI
, NULL
, 3, src
, lower_32_bits(address
),
1487 upper_32_bits(address
));
1489 EXPORT_SYMBOL_GPL(zynqmp_pm_load_pdi
);
1492 * zynqmp_pm_aes_engine - Access AES hardware to encrypt/decrypt the data using
1494 * @address: Address of the AesParams structure.
1495 * @out: Returned output value
1497 * Return: Returns status, either success or error code.
1499 int zynqmp_pm_aes_engine(const u64 address
, u32
*out
)
1501 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1507 ret
= zynqmp_pm_invoke_fn(PM_SECURE_AES
, ret_payload
, 2, upper_32_bits(address
),
1508 lower_32_bits(address
));
1509 *out
= ret_payload
[1];
1513 EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine
);
1516 * zynqmp_pm_efuse_access - Provides access to efuse memory.
1517 * @address: Address of the efuse params structure
1518 * @out: Returned output value
1520 * Return: Returns status, either success or error code.
1522 int zynqmp_pm_efuse_access(const u64 address
, u32
*out
)
1524 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1530 ret
= zynqmp_pm_invoke_fn(PM_EFUSE_ACCESS
, ret_payload
, 2,
1531 upper_32_bits(address
),
1532 lower_32_bits(address
));
1533 *out
= ret_payload
[1];
1537 EXPORT_SYMBOL_GPL(zynqmp_pm_efuse_access
);
1540 * zynqmp_pm_sha_hash - Access the SHA engine to calculate the hash
1541 * @address: Address of the data/ Address of output buffer where
1542 * hash should be stored.
1543 * @size: Size of the data.
1545 * BIT(0) - for initializing csudma driver and SHA3(Here address
1546 * and size inputs can be NULL).
1547 * BIT(1) - to call Sha3_Update API which can be called multiple
1548 * times when data is not contiguous.
1549 * BIT(2) - to get final hash of the whole updated data.
1550 * Hash will be overwritten at provided address with
1553 * Return: Returns status, either success or error code.
1555 int zynqmp_pm_sha_hash(const u64 address
, const u32 size
, const u32 flags
)
1557 u32 lower_addr
= lower_32_bits(address
);
1558 u32 upper_addr
= upper_32_bits(address
);
1560 return zynqmp_pm_invoke_fn(PM_SECURE_SHA
, NULL
, 4, upper_addr
, lower_addr
, size
, flags
);
1562 EXPORT_SYMBOL_GPL(zynqmp_pm_sha_hash
);
1565 * zynqmp_pm_register_notifier() - PM API for register a subsystem
1566 * to be notified about specific
1568 * @node: Node ID to which the event is related.
1569 * @event: Event Mask of Error events for which wants to get notified.
1570 * @wake: Wake subsystem upon capturing the event if value 1
1571 * @enable: Enable the registration for value 1, disable for value 0
1573 * This function is used to register/un-register for particular node-event
1574 * combination in firmware.
1576 * Return: Returns status, either success or error+reason
1579 int zynqmp_pm_register_notifier(const u32 node
, const u32 event
,
1580 const u32 wake
, const u32 enable
)
1582 return zynqmp_pm_invoke_fn(PM_REGISTER_NOTIFIER
, NULL
, 4, node
, event
, wake
, enable
);
1584 EXPORT_SYMBOL_GPL(zynqmp_pm_register_notifier
);
1587 * zynqmp_pm_system_shutdown - PM call to request a system shutdown or restart
1588 * @type: Shutdown or restart? 0 for shutdown, 1 for restart
1589 * @subtype: Specifies which system should be restarted or shut down
1591 * Return: Returns status, either success or error+reason
1593 int zynqmp_pm_system_shutdown(const u32 type
, const u32 subtype
)
1595 return zynqmp_pm_invoke_fn(PM_SYSTEM_SHUTDOWN
, NULL
, 2, type
, subtype
);
1599 * zynqmp_pm_set_feature_config - PM call to request IOCTL for feature config
1600 * @id: The config ID of the feature to be configured
1601 * @value: The config value of the feature to be configured
1603 * Return: Returns 0 on success or error value on failure.
1605 int zynqmp_pm_set_feature_config(enum pm_feature_config_id id
, u32 value
)
1607 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, 0, IOCTL_SET_FEATURE_CONFIG
, id
, value
);
1611 * zynqmp_pm_get_feature_config - PM call to get value of configured feature
1612 * @id: The config id of the feature to be queried
1613 * @payload: Returned value array
1615 * Return: Returns 0 on success or error value on failure.
1617 int zynqmp_pm_get_feature_config(enum pm_feature_config_id id
,
1620 return zynqmp_pm_invoke_fn(PM_IOCTL
, payload
, 3, 0, IOCTL_GET_FEATURE_CONFIG
, id
);
1624 * zynqmp_pm_set_sd_config - PM call to set value of SD config registers
1626 * @config: The config type of SD registers
1627 * @value: Value to be set
1629 * Return: Returns 0 on success or error value on failure.
1631 int zynqmp_pm_set_sd_config(u32 node
, enum pm_sd_config_type config
, u32 value
)
1633 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, node
, IOCTL_SET_SD_CONFIG
, config
, value
);
1635 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_config
);
1638 * zynqmp_pm_set_gem_config - PM call to set value of GEM config registers
1639 * @node: GEM node ID
1640 * @config: The config type of GEM registers
1641 * @value: Value to be set
1643 * Return: Returns 0 on success or error value on failure.
1645 int zynqmp_pm_set_gem_config(u32 node
, enum pm_gem_config_type config
,
1648 return zynqmp_pm_invoke_fn(PM_IOCTL
, NULL
, 4, node
, IOCTL_SET_GEM_CONFIG
, config
, value
);
1650 EXPORT_SYMBOL_GPL(zynqmp_pm_set_gem_config
);
1653 * struct zynqmp_pm_shutdown_scope - Struct for shutdown scope
1654 * @subtype: Shutdown subtype
1655 * @name: Matching string for scope argument
1657 * This struct encapsulates mapping between shutdown scope ID and string.
1659 struct zynqmp_pm_shutdown_scope
{
1660 const enum zynqmp_pm_shutdown_subtype subtype
;
1664 static struct zynqmp_pm_shutdown_scope shutdown_scopes
[] = {
1665 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM
] = {
1666 .subtype
= ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM
,
1667 .name
= "subsystem",
1669 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY
] = {
1670 .subtype
= ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY
,
1673 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM
] = {
1674 .subtype
= ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM
,
1679 static struct zynqmp_pm_shutdown_scope
*selected_scope
=
1680 &shutdown_scopes
[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM
];
1683 * zynqmp_pm_is_shutdown_scope_valid - Check if shutdown scope string is valid
1684 * @scope_string: Shutdown scope string
1686 * Return: Return pointer to matching shutdown scope struct from
1687 * array of available options in system if string is valid,
1688 * otherwise returns NULL.
1690 static struct zynqmp_pm_shutdown_scope
*
1691 zynqmp_pm_is_shutdown_scope_valid(const char *scope_string
)
1695 for (count
= 0; count
< ARRAY_SIZE(shutdown_scopes
); count
++)
1696 if (sysfs_streq(scope_string
, shutdown_scopes
[count
].name
))
1697 return &shutdown_scopes
[count
];
1702 static ssize_t
shutdown_scope_show(struct device
*device
,
1703 struct device_attribute
*attr
,
1708 for (i
= 0; i
< ARRAY_SIZE(shutdown_scopes
); i
++) {
1709 if (&shutdown_scopes
[i
] == selected_scope
) {
1711 strcat(buf
, shutdown_scopes
[i
].name
);
1714 strcat(buf
, shutdown_scopes
[i
].name
);
1723 static ssize_t
shutdown_scope_store(struct device
*device
,
1724 struct device_attribute
*attr
,
1725 const char *buf
, size_t count
)
1728 struct zynqmp_pm_shutdown_scope
*scope
;
1730 scope
= zynqmp_pm_is_shutdown_scope_valid(buf
);
1734 ret
= zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY
,
1737 pr_err("unable to set shutdown scope %s\n", buf
);
1741 selected_scope
= scope
;
1746 static DEVICE_ATTR_RW(shutdown_scope
);
1748 static ssize_t
health_status_store(struct device
*device
,
1749 struct device_attribute
*attr
,
1750 const char *buf
, size_t count
)
1755 ret
= kstrtouint(buf
, 10, &value
);
1759 ret
= zynqmp_pm_set_boot_health_status(value
);
1761 dev_err(device
, "unable to set healthy bit value to %u\n",
1769 static DEVICE_ATTR_WO(health_status
);
1771 static ssize_t
ggs_show(struct device
*device
,
1772 struct device_attribute
*attr
,
1777 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1779 ret
= zynqmp_pm_read_ggs(reg
, ret_payload
);
1783 return sprintf(buf
, "0x%x\n", ret_payload
[1]);
1786 static ssize_t
ggs_store(struct device
*device
,
1787 struct device_attribute
*attr
,
1788 const char *buf
, size_t count
,
1794 if (reg
>= GSS_NUM_REGS
)
1797 ret
= kstrtol(buf
, 16, &value
);
1803 ret
= zynqmp_pm_write_ggs(reg
, value
);
1810 /* GGS register show functions */
1811 #define GGS0_SHOW(N) \
1812 ssize_t ggs##N##_show(struct device *device, \
1813 struct device_attribute *attr, \
1816 return ggs_show(device, attr, buf, N); \
1819 static GGS0_SHOW(0);
1820 static GGS0_SHOW(1);
1821 static GGS0_SHOW(2);
1822 static GGS0_SHOW(3);
1824 /* GGS register store function */
1825 #define GGS0_STORE(N) \
1826 ssize_t ggs##N##_store(struct device *device, \
1827 struct device_attribute *attr, \
1831 return ggs_store(device, attr, buf, count, N); \
1834 static GGS0_STORE(0);
1835 static GGS0_STORE(1);
1836 static GGS0_STORE(2);
1837 static GGS0_STORE(3);
1839 static ssize_t
pggs_show(struct device
*device
,
1840 struct device_attribute
*attr
,
1845 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1847 ret
= zynqmp_pm_read_pggs(reg
, ret_payload
);
1851 return sprintf(buf
, "0x%x\n", ret_payload
[1]);
1854 static ssize_t
pggs_store(struct device
*device
,
1855 struct device_attribute
*attr
,
1856 const char *buf
, size_t count
,
1862 if (reg
>= GSS_NUM_REGS
)
1865 ret
= kstrtol(buf
, 16, &value
);
1871 ret
= zynqmp_pm_write_pggs(reg
, value
);
1879 #define PGGS0_SHOW(N) \
1880 ssize_t pggs##N##_show(struct device *device, \
1881 struct device_attribute *attr, \
1884 return pggs_show(device, attr, buf, N); \
1887 #define PGGS0_STORE(N) \
1888 ssize_t pggs##N##_store(struct device *device, \
1889 struct device_attribute *attr, \
1893 return pggs_store(device, attr, buf, count, N); \
1896 /* PGGS register show functions */
1897 static PGGS0_SHOW(0);
1898 static PGGS0_SHOW(1);
1899 static PGGS0_SHOW(2);
1900 static PGGS0_SHOW(3);
1902 /* PGGS register store functions */
1903 static PGGS0_STORE(0);
1904 static PGGS0_STORE(1);
1905 static PGGS0_STORE(2);
1906 static PGGS0_STORE(3);
1908 /* GGS register attributes */
1909 static DEVICE_ATTR_RW(ggs0
);
1910 static DEVICE_ATTR_RW(ggs1
);
1911 static DEVICE_ATTR_RW(ggs2
);
1912 static DEVICE_ATTR_RW(ggs3
);
1914 /* PGGS register attributes */
1915 static DEVICE_ATTR_RW(pggs0
);
1916 static DEVICE_ATTR_RW(pggs1
);
1917 static DEVICE_ATTR_RW(pggs2
);
1918 static DEVICE_ATTR_RW(pggs3
);
1920 static ssize_t
feature_config_id_show(struct device
*device
,
1921 struct device_attribute
*attr
,
1924 struct zynqmp_devinfo
*devinfo
= dev_get_drvdata(device
);
1926 return sysfs_emit(buf
, "%d\n", devinfo
->feature_conf_id
);
1929 static ssize_t
feature_config_id_store(struct device
*device
,
1930 struct device_attribute
*attr
,
1931 const char *buf
, size_t count
)
1935 struct zynqmp_devinfo
*devinfo
= dev_get_drvdata(device
);
1940 ret
= kstrtou32(buf
, 10, &config_id
);
1944 devinfo
->feature_conf_id
= config_id
;
1949 static DEVICE_ATTR_RW(feature_config_id
);
1951 static ssize_t
feature_config_value_show(struct device
*device
,
1952 struct device_attribute
*attr
,
1956 u32 ret_payload
[PAYLOAD_ARG_CNT
];
1957 struct zynqmp_devinfo
*devinfo
= dev_get_drvdata(device
);
1959 ret
= zynqmp_pm_get_feature_config(devinfo
->feature_conf_id
,
1964 return sysfs_emit(buf
, "%d\n", ret_payload
[1]);
1967 static ssize_t
feature_config_value_store(struct device
*device
,
1968 struct device_attribute
*attr
,
1969 const char *buf
, size_t count
)
1973 struct zynqmp_devinfo
*devinfo
= dev_get_drvdata(device
);
1978 ret
= kstrtou32(buf
, 10, &value
);
1982 ret
= zynqmp_pm_set_feature_config(devinfo
->feature_conf_id
,
1990 static DEVICE_ATTR_RW(feature_config_value
);
1992 static struct attribute
*zynqmp_firmware_attrs
[] = {
1993 &dev_attr_ggs0
.attr
,
1994 &dev_attr_ggs1
.attr
,
1995 &dev_attr_ggs2
.attr
,
1996 &dev_attr_ggs3
.attr
,
1997 &dev_attr_pggs0
.attr
,
1998 &dev_attr_pggs1
.attr
,
1999 &dev_attr_pggs2
.attr
,
2000 &dev_attr_pggs3
.attr
,
2001 &dev_attr_shutdown_scope
.attr
,
2002 &dev_attr_health_status
.attr
,
2003 &dev_attr_feature_config_id
.attr
,
2004 &dev_attr_feature_config_value
.attr
,
2008 ATTRIBUTE_GROUPS(zynqmp_firmware
);
2010 static int zynqmp_firmware_probe(struct platform_device
*pdev
)
2012 struct device
*dev
= &pdev
->dev
;
2013 struct zynqmp_devinfo
*devinfo
;
2016 ret
= get_set_conduit_method(dev
->of_node
);
2020 /* Get SiP SVC version number */
2021 ret
= zynqmp_pm_get_sip_svc_version(&sip_svc_version
);
2025 ret
= do_feature_check_call(PM_FEATURE_CHECK
);
2026 if (ret
>= 0 && ((ret
& FIRMWARE_VERSION_MASK
) >= PM_API_VERSION_1
))
2027 feature_check_enabled
= true;
2029 devinfo
= devm_kzalloc(dev
, sizeof(*devinfo
), GFP_KERNEL
);
2035 platform_set_drvdata(pdev
, devinfo
);
2037 /* Check PM API version number */
2038 ret
= zynqmp_pm_get_api_version(&pm_api_version
);
2042 if (pm_api_version
< ZYNQMP_PM_VERSION
) {
2043 panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
2045 ZYNQMP_PM_VERSION_MAJOR
, ZYNQMP_PM_VERSION_MINOR
,
2046 pm_api_version
>> 16, pm_api_version
& 0xFFFF);
2049 pr_info("%s Platform Management API v%d.%d\n", __func__
,
2050 pm_api_version
>> 16, pm_api_version
& 0xFFFF);
2052 /* Get the Family code and sub family code of platform */
2053 ret
= zynqmp_pm_get_family_info(&pm_family_code
, &pm_sub_family_code
);
2057 /* Check trustzone version number */
2058 ret
= zynqmp_pm_get_trustzone_version(&pm_tz_version
);
2060 panic("Legacy trustzone found without version support\n");
2062 if (pm_tz_version
< ZYNQMP_TZ_VERSION
)
2063 panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
2065 ZYNQMP_TZ_VERSION_MAJOR
, ZYNQMP_TZ_VERSION_MINOR
,
2066 pm_tz_version
>> 16, pm_tz_version
& 0xFFFF);
2068 pr_info("%s Trustzone version v%d.%d\n", __func__
,
2069 pm_tz_version
>> 16, pm_tz_version
& 0xFFFF);
2071 ret
= mfd_add_devices(&pdev
->dev
, PLATFORM_DEVID_NONE
, firmware_devs
,
2072 ARRAY_SIZE(firmware_devs
), NULL
, 0, NULL
);
2074 dev_err(&pdev
->dev
, "failed to add MFD devices %d\n", ret
);
2078 zynqmp_pm_api_debugfs_init();
2080 if (pm_family_code
== VERSAL_FAMILY_CODE
) {
2081 em_dev
= platform_device_register_data(&pdev
->dev
, "xlnx_event_manager",
2084 dev_err_probe(&pdev
->dev
, PTR_ERR(em_dev
), "EM register fail with error\n");
2087 return of_platform_populate(dev
->of_node
, NULL
, NULL
, dev
);
2090 static void zynqmp_firmware_remove(struct platform_device
*pdev
)
2092 struct pm_api_feature_data
*feature_data
;
2093 struct hlist_node
*tmp
;
2096 mfd_remove_devices(&pdev
->dev
);
2097 zynqmp_pm_api_debugfs_exit();
2099 hash_for_each_safe(pm_api_features_map
, i
, tmp
, feature_data
, hentry
) {
2100 hash_del(&feature_data
->hentry
);
2101 kfree(feature_data
);
2104 platform_device_unregister(em_dev
);
2107 static const struct of_device_id zynqmp_firmware_of_match
[] = {
2108 {.compatible
= "xlnx,zynqmp-firmware"},
2109 {.compatible
= "xlnx,versal-firmware"},
2112 MODULE_DEVICE_TABLE(of
, zynqmp_firmware_of_match
);
2114 static struct platform_driver zynqmp_firmware_driver
= {
2116 .name
= "zynqmp_firmware",
2117 .of_match_table
= zynqmp_firmware_of_match
,
2118 .dev_groups
= zynqmp_firmware_groups
,
2120 .probe
= zynqmp_firmware_probe
,
2121 .remove
= zynqmp_firmware_remove
,
2123 module_platform_driver(zynqmp_firmware_driver
);