1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware layer
5 * Copyright (C) 2014-2022 Xilinx, Inc.
13 #include <linux/arm-smccc.h>
14 #include <linux/compiler.h>
15 #include <linux/device.h>
16 #include <linux/init.h>
17 #include <linux/mfd/core.h>
18 #include <linux/module.h>
20 #include <linux/of_platform.h>
21 #include <linux/platform_device.h>
22 #include <linux/slab.h>
23 #include <linux/uaccess.h>
24 #include <linux/hashtable.h>
26 #include <linux/firmware/xlnx-zynqmp.h>
27 #include <linux/firmware/xlnx-event-manager.h>
28 #include "zynqmp-debug.h"
30 /* Max HashMap Order for PM API feature check (1<<7 = 128) */
31 #define PM_API_FEATURE_CHECK_MAX_ORDER 7
33 /* CRL registers and bitfields */
34 #define CRL_APB_BASE 0xFF5E0000U
35 /* BOOT_PIN_CTRL- Used to control the mode pins after boot */
36 #define CRL_APB_BOOT_PIN_CTRL (CRL_APB_BASE + (0x250U))
37 /* BOOT_PIN_CTRL_MASK- out_val[11:8], out_en[3:0] */
38 #define CRL_APB_BOOTPIN_CTRL_MASK 0xF0FU
40 /* IOCTL/QUERY feature payload size */
41 #define FEATURE_PAYLOAD_SIZE 2
43 /* Firmware feature check version mask */
44 #define FIRMWARE_VERSION_MASK GENMASK(15, 0)
46 static bool feature_check_enabled;
47 static DEFINE_HASHTABLE(pm_api_features_map, PM_API_FEATURE_CHECK_MAX_ORDER);
48 static u32 ioctl_features[FEATURE_PAYLOAD_SIZE];
49 static u32 query_features[FEATURE_PAYLOAD_SIZE];
51 static struct platform_device *em_dev;
54 * struct zynqmp_devinfo - Structure for Zynqmp device instance
55 * @dev: Device Pointer
56 * @feature_conf_id: Feature conf id
58 struct zynqmp_devinfo {
64 * struct pm_api_feature_data - PM API Feature data
65 * @pm_api_id: PM API Id, used as key to index into hashmap
66 * @feature_status: status of PM API feature: valid, invalid
67 * @hentry: hlist_node that hooks this entry into hashtable
69 struct pm_api_feature_data {
72 struct hlist_node hentry;
75 static const struct mfd_cell firmware_devs[] = {
77 .name = "zynqmp_power_controller",
82 * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
83 * @ret_status: PMUFW return code
85 * Return: corresponding Linux error code
87 static int zynqmp_pm_ret_code(u32 ret_status)
91 case XST_PM_DOUBLE_REQ:
93 case XST_PM_NO_FEATURE:
95 case XST_PM_NO_ACCESS:
97 case XST_PM_ABORT_SUSPEND:
99 case XST_PM_MULT_USER:
101 case XST_PM_INTERNAL:
102 case XST_PM_CONFLICT:
103 case XST_PM_INVALID_NODE:
109 static noinline int do_fw_call_fail(u64 arg0, u64 arg1, u64 arg2,
116 * PM function call wrapper
117 * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
119 static int (*do_fw_call)(u64, u64, u64, u32 *ret_payload) = do_fw_call_fail;
122 * do_fw_call_smc() - Call system-level platform management layer (SMC)
123 * @arg0: Argument 0 to SMC call
124 * @arg1: Argument 1 to SMC call
125 * @arg2: Argument 2 to SMC call
126 * @ret_payload: Returned value array
128 * Invoke platform management function via SMC call (no hypervisor present).
130 * Return: Returns status, either success or error+reason
132 static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2,
135 struct arm_smccc_res res;
137 arm_smccc_smc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
140 ret_payload[0] = lower_32_bits(res.a0);
141 ret_payload[1] = upper_32_bits(res.a0);
142 ret_payload[2] = lower_32_bits(res.a1);
143 ret_payload[3] = upper_32_bits(res.a1);
146 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
150 * do_fw_call_hvc() - Call system-level platform management layer (HVC)
151 * @arg0: Argument 0 to HVC call
152 * @arg1: Argument 1 to HVC call
153 * @arg2: Argument 2 to HVC call
154 * @ret_payload: Returned value array
156 * Invoke platform management function via HVC
157 * HVC-based for communication through hypervisor
158 * (no direct communication with ATF).
160 * Return: Returns status, either success or error+reason
162 static noinline int do_fw_call_hvc(u64 arg0, u64 arg1, u64 arg2,
165 struct arm_smccc_res res;
167 arm_smccc_hvc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
170 ret_payload[0] = lower_32_bits(res.a0);
171 ret_payload[1] = upper_32_bits(res.a0);
172 ret_payload[2] = lower_32_bits(res.a1);
173 ret_payload[3] = upper_32_bits(res.a1);
176 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
179 static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
184 smc_arg[0] = PM_SIP_SVC | PM_FEATURE_CHECK;
187 ret = do_fw_call(smc_arg[0], smc_arg[1], 0, ret_payload);
191 ret = ret_payload[1];
196 static int do_feature_check_call(const u32 api_id)
199 u32 ret_payload[PAYLOAD_ARG_CNT];
200 struct pm_api_feature_data *feature_data;
202 /* Check for existing entry in hash table for given api */
203 hash_for_each_possible(pm_api_features_map, feature_data, hentry,
205 if (feature_data->pm_api_id == api_id)
206 return feature_data->feature_status;
209 /* Add new entry if not present */
210 feature_data = kmalloc(sizeof(*feature_data), GFP_ATOMIC);
214 feature_data->pm_api_id = api_id;
215 ret = __do_feature_check_call(api_id, ret_payload);
217 feature_data->feature_status = ret;
218 hash_add(pm_api_features_map, &feature_data->hentry, api_id);
220 if (api_id == PM_IOCTL)
221 /* Store supported IOCTL IDs mask */
222 memcpy(ioctl_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
223 else if (api_id == PM_QUERY_DATA)
224 /* Store supported QUERY IDs mask */
225 memcpy(query_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
231 * zynqmp_pm_feature() - Check whether given feature is supported or not and
232 * store supported IOCTL/QUERY ID mask
233 * @api_id: API ID to check
235 * Return: Returns status, either success or error+reason
237 int zynqmp_pm_feature(const u32 api_id)
241 if (!feature_check_enabled)
244 ret = do_feature_check_call(api_id);
248 EXPORT_SYMBOL_GPL(zynqmp_pm_feature);
251 * zynqmp_pm_is_function_supported() - Check whether given IOCTL/QUERY function
252 * is supported or not
253 * @api_id: PM_IOCTL or PM_QUERY_DATA
254 * @id: IOCTL or QUERY function IDs
256 * Return: Returns status, either success or error+reason
258 int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
263 /* Input arguments validation */
264 if (id >= 64 || (api_id != PM_IOCTL && api_id != PM_QUERY_DATA))
267 /* Check feature check API version */
268 ret = do_feature_check_call(PM_FEATURE_CHECK);
272 /* Check if feature check version 2 is supported or not */
273 if ((ret & FIRMWARE_VERSION_MASK) == PM_API_VERSION_2) {
275 * Call feature check for IOCTL/QUERY API to get IOCTL ID or
276 * QUERY ID feature status.
278 ret = do_feature_check_call(api_id);
282 bit_mask = (api_id == PM_IOCTL) ? ioctl_features : query_features;
284 if ((bit_mask[(id / 32)] & BIT((id % 32))) == 0U)
292 EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
295 * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
296 * caller function depending on the configuration
297 * @pm_api_id: Requested PM-API call
298 * @arg0: Argument 0 to requested PM-API call
299 * @arg1: Argument 1 to requested PM-API call
300 * @arg2: Argument 2 to requested PM-API call
301 * @arg3: Argument 3 to requested PM-API call
302 * @ret_payload: Returned value array
304 * Invoke platform management function for SMC or HVC call, depending on
306 * Following SMC Calling Convention (SMCCC) for SMC64:
307 * Pm Function Identifier,
308 * PM_SIP_SVC + PM_API_ID =
309 * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
310 * ((SMC_64) << FUNCID_CC_SHIFT)
311 * ((SIP_START) << FUNCID_OEN_SHIFT)
312 * ((PM_API_ID) & FUNCID_NUM_MASK))
314 * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
315 * PM_API_ID - Platform Management API ID.
317 * Return: Returns status, either success or error+reason
319 int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
320 u32 arg2, u32 arg3, u32 *ret_payload)
323 * Added SIP service call Function Identifier
324 * Make sure to stay in x0 register
329 /* Check if feature is supported or not */
330 ret = zynqmp_pm_feature(pm_api_id);
334 smc_arg[0] = PM_SIP_SVC | pm_api_id;
335 smc_arg[1] = ((u64)arg1 << 32) | arg0;
336 smc_arg[2] = ((u64)arg3 << 32) | arg2;
338 return do_fw_call(smc_arg[0], smc_arg[1], smc_arg[2], ret_payload);
341 static u32 pm_api_version;
342 static u32 pm_tz_version;
343 static u32 pm_family_code;
344 static u32 pm_sub_family_code;
346 int zynqmp_pm_register_sgi(u32 sgi_num, u32 reset)
350 ret = zynqmp_pm_invoke_fn(TF_A_PM_REGISTER_SGI, sgi_num, reset, 0, 0,
355 /* try old implementation as fallback strategy if above fails */
356 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_REGISTER_SGI, sgi_num,
361 * zynqmp_pm_get_api_version() - Get version number of PMU PM firmware
362 * @version: Returned version value
364 * Return: Returns status, either success or error+reason
366 int zynqmp_pm_get_api_version(u32 *version)
368 u32 ret_payload[PAYLOAD_ARG_CNT];
374 /* Check is PM API version already verified */
375 if (pm_api_version > 0) {
376 *version = pm_api_version;
379 ret = zynqmp_pm_invoke_fn(PM_GET_API_VERSION, 0, 0, 0, 0, ret_payload);
380 *version = ret_payload[1];
384 EXPORT_SYMBOL_GPL(zynqmp_pm_get_api_version);
387 * zynqmp_pm_get_chipid - Get silicon ID registers
388 * @idcode: IDCODE register
389 * @version: version register
391 * Return: Returns the status of the operation and the idcode and version
392 * registers in @idcode and @version.
394 int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
396 u32 ret_payload[PAYLOAD_ARG_CNT];
399 if (!idcode || !version)
402 ret = zynqmp_pm_invoke_fn(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
403 *idcode = ret_payload[1];
404 *version = ret_payload[2];
408 EXPORT_SYMBOL_GPL(zynqmp_pm_get_chipid);
411 * zynqmp_pm_get_family_info() - Get family info of platform
412 * @family: Returned family code value
413 * @subfamily: Returned sub-family code value
415 * Return: Returns status, either success or error+reason
417 static int zynqmp_pm_get_family_info(u32 *family, u32 *subfamily)
419 u32 ret_payload[PAYLOAD_ARG_CNT];
423 /* Check is family or sub-family code already received */
424 if (pm_family_code && pm_sub_family_code) {
425 *family = pm_family_code;
426 *subfamily = pm_sub_family_code;
430 ret = zynqmp_pm_invoke_fn(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
434 idcode = ret_payload[1];
435 pm_family_code = FIELD_GET(FAMILY_CODE_MASK, idcode);
436 pm_sub_family_code = FIELD_GET(SUB_FAMILY_CODE_MASK, idcode);
437 *family = pm_family_code;
438 *subfamily = pm_sub_family_code;
444 * zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
445 * @version: Returned version value
447 * Return: Returns status, either success or error+reason
449 static int zynqmp_pm_get_trustzone_version(u32 *version)
451 u32 ret_payload[PAYLOAD_ARG_CNT];
457 /* Check is PM trustzone version already verified */
458 if (pm_tz_version > 0) {
459 *version = pm_tz_version;
462 ret = zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION, 0, 0,
464 *version = ret_payload[1];
470 * get_set_conduit_method() - Choose SMC or HVC based communication
471 * @np: Pointer to the device_node structure
473 * Use SMC or HVC-based functions to communicate with EL2/EL3.
475 * Return: Returns 0 on success or error code
477 static int get_set_conduit_method(struct device_node *np)
481 if (of_property_read_string(np, "method", &method)) {
482 pr_warn("%s missing \"method\" property\n", __func__);
486 if (!strcmp("hvc", method)) {
487 do_fw_call = do_fw_call_hvc;
488 } else if (!strcmp("smc", method)) {
489 do_fw_call = do_fw_call_smc;
491 pr_warn("%s Invalid \"method\" property: %s\n",
500 * zynqmp_pm_query_data() - Get query data from firmware
501 * @qdata: Variable to the zynqmp_pm_query_data structure
502 * @out: Returned output value
504 * Return: Returns status, either success or error+reason
506 int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out)
510 ret = zynqmp_pm_invoke_fn(PM_QUERY_DATA, qdata.qid, qdata.arg1,
511 qdata.arg2, qdata.arg3, out);
514 * For clock name query, all bytes in SMC response are clock name
515 * characters and return code is always success. For invalid clocks,
516 * clock name bytes would be zeros.
518 return qdata.qid == PM_QID_CLOCK_GET_NAME ? 0 : ret;
520 EXPORT_SYMBOL_GPL(zynqmp_pm_query_data);
523 * zynqmp_pm_clock_enable() - Enable the clock for given id
524 * @clock_id: ID of the clock to be enabled
526 * This function is used by master to enable the clock
527 * including peripherals and PLL clocks.
529 * Return: Returns status, either success or error+reason
531 int zynqmp_pm_clock_enable(u32 clock_id)
533 return zynqmp_pm_invoke_fn(PM_CLOCK_ENABLE, clock_id, 0, 0, 0, NULL);
535 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_enable);
538 * zynqmp_pm_clock_disable() - Disable the clock for given id
539 * @clock_id: ID of the clock to be disable
541 * This function is used by master to disable the clock
542 * including peripherals and PLL clocks.
544 * Return: Returns status, either success or error+reason
546 int zynqmp_pm_clock_disable(u32 clock_id)
548 return zynqmp_pm_invoke_fn(PM_CLOCK_DISABLE, clock_id, 0, 0, 0, NULL);
550 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_disable);
553 * zynqmp_pm_clock_getstate() - Get the clock state for given id
554 * @clock_id: ID of the clock to be queried
555 * @state: 1/0 (Enabled/Disabled)
557 * This function is used by master to get the state of clock
558 * including peripherals and PLL clocks.
560 * Return: Returns status, either success or error+reason
562 int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state)
564 u32 ret_payload[PAYLOAD_ARG_CNT];
567 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETSTATE, clock_id, 0,
569 *state = ret_payload[1];
573 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getstate);
576 * zynqmp_pm_clock_setdivider() - Set the clock divider for given id
577 * @clock_id: ID of the clock
578 * @divider: divider value
580 * This function is used by master to set divider for any clock
581 * to achieve desired rate.
583 * Return: Returns status, either success or error+reason
585 int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider)
587 return zynqmp_pm_invoke_fn(PM_CLOCK_SETDIVIDER, clock_id, divider,
590 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setdivider);
593 * zynqmp_pm_clock_getdivider() - Get the clock divider for given id
594 * @clock_id: ID of the clock
595 * @divider: divider value
597 * This function is used by master to get divider values
600 * Return: Returns status, either success or error+reason
602 int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider)
604 u32 ret_payload[PAYLOAD_ARG_CNT];
607 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETDIVIDER, clock_id, 0,
609 *divider = ret_payload[1];
613 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getdivider);
616 * zynqmp_pm_clock_setrate() - Set the clock rate for given id
617 * @clock_id: ID of the clock
618 * @rate: rate value in hz
620 * This function is used by master to set rate for any clock.
622 * Return: Returns status, either success or error+reason
624 int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate)
626 return zynqmp_pm_invoke_fn(PM_CLOCK_SETRATE, clock_id,
631 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setrate);
634 * zynqmp_pm_clock_getrate() - Get the clock rate for given id
635 * @clock_id: ID of the clock
636 * @rate: rate value in hz
638 * This function is used by master to get rate
641 * Return: Returns status, either success or error+reason
643 int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate)
645 u32 ret_payload[PAYLOAD_ARG_CNT];
648 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETRATE, clock_id, 0,
650 *rate = ((u64)ret_payload[2] << 32) | ret_payload[1];
654 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getrate);
657 * zynqmp_pm_clock_setparent() - Set the clock parent for given id
658 * @clock_id: ID of the clock
659 * @parent_id: parent id
661 * This function is used by master to set parent for any clock.
663 * Return: Returns status, either success or error+reason
665 int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id)
667 return zynqmp_pm_invoke_fn(PM_CLOCK_SETPARENT, clock_id,
668 parent_id, 0, 0, NULL);
670 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setparent);
673 * zynqmp_pm_clock_getparent() - Get the clock parent for given id
674 * @clock_id: ID of the clock
675 * @parent_id: parent id
677 * This function is used by master to get parent index
680 * Return: Returns status, either success or error+reason
682 int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
684 u32 ret_payload[PAYLOAD_ARG_CNT];
687 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETPARENT, clock_id, 0,
689 *parent_id = ret_payload[1];
693 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getparent);
696 * zynqmp_pm_set_pll_frac_mode() - PM API for set PLL mode
698 * @clk_id: PLL clock ID
699 * @mode: PLL mode (PLL_MODE_FRAC/PLL_MODE_INT)
701 * This function sets PLL mode
703 * Return: Returns status, either success or error+reason
705 int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
707 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_MODE,
710 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_mode);
713 * zynqmp_pm_get_pll_frac_mode() - PM API for get PLL mode
715 * @clk_id: PLL clock ID
718 * This function return current PLL mode
720 * Return: Returns status, either success or error+reason
722 int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
724 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_MODE,
727 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_mode);
730 * zynqmp_pm_set_pll_frac_data() - PM API for setting pll fraction data
732 * @clk_id: PLL clock ID
733 * @data: fraction data
735 * This function sets fraction data.
736 * It is valid for fraction mode only.
738 * Return: Returns status, either success or error+reason
740 int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
742 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_DATA,
745 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_data);
748 * zynqmp_pm_get_pll_frac_data() - PM API for getting pll fraction data
750 * @clk_id: PLL clock ID
751 * @data: fraction data
753 * This function returns fraction data value.
755 * Return: Returns status, either success or error+reason
757 int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
759 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_DATA,
762 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_data);
765 * zynqmp_pm_set_sd_tapdelay() - Set tap delay for the SD device
767 * @node_id: Node ID of the device
768 * @type: Type of tap delay to set (input/output)
769 * @value: Value to set fot the tap delay
771 * This function sets input/output tap delay for the SD device.
773 * Return: Returns status, either success or error+reason
775 int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
777 u32 reg = (type == PM_TAPDELAY_INPUT) ? SD_ITAPDLY : SD_OTAPDLYSEL;
778 u32 mask = (node_id == NODE_SD_0) ? GENMASK(15, 0) : GENMASK(31, 16);
781 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id,
782 IOCTL_SET_SD_TAPDELAY,
787 * Work around completely misdesigned firmware API on Xilinx ZynqMP.
788 * The IOCTL_SET_SD_TAPDELAY firmware call allows the caller to only
789 * ever set IOU_SLCR SD_ITAPDLY Register SD0_ITAPDLYENA/SD1_ITAPDLYENA
790 * bits, but there is no matching call to clear those bits. If those
791 * bits are not cleared, SDMMC tuning may fail.
793 * Luckily, there are PM_MMIO_READ/PM_MMIO_WRITE calls which seem to
794 * allow complete unrestricted access to all address space, including
795 * IOU_SLCR SD_ITAPDLY Register and all the other registers, access
796 * to which was supposed to be protected by the current firmware API.
798 * Use PM_MMIO_READ/PM_MMIO_WRITE to re-implement the missing counter
799 * part of IOCTL_SET_SD_TAPDELAY which clears SDx_ITAPDLYENA bits.
801 return zynqmp_pm_invoke_fn(PM_MMIO_WRITE, reg, mask, 0, 0, NULL);
803 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_tapdelay);
806 * zynqmp_pm_sd_dll_reset() - Reset DLL logic
808 * @node_id: Node ID of the device
811 * This function resets DLL logic for the SD device.
813 * Return: Returns status, either success or error+reason
815 int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
817 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SD_DLL_RESET,
820 EXPORT_SYMBOL_GPL(zynqmp_pm_sd_dll_reset);
823 * zynqmp_pm_ospi_mux_select() - OSPI Mux selection
825 * @dev_id: Device Id of the OSPI device.
826 * @select: OSPI Mux select value.
828 * This function select the OSPI Mux.
830 * Return: Returns status, either success or error+reason
832 int zynqmp_pm_ospi_mux_select(u32 dev_id, u32 select)
834 return zynqmp_pm_invoke_fn(PM_IOCTL, dev_id, IOCTL_OSPI_MUX_SELECT,
837 EXPORT_SYMBOL_GPL(zynqmp_pm_ospi_mux_select);
840 * zynqmp_pm_write_ggs() - PM API for writing global general storage (ggs)
841 * @index: GGS register index
842 * @value: Register value to be written
844 * This function writes value to GGS register.
846 * Return: Returns status, either success or error+reason
848 int zynqmp_pm_write_ggs(u32 index, u32 value)
850 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_GGS,
853 EXPORT_SYMBOL_GPL(zynqmp_pm_write_ggs);
856 * zynqmp_pm_read_ggs() - PM API for reading global general storage (ggs)
857 * @index: GGS register index
858 * @value: Register value to be written
860 * This function returns GGS register value.
862 * Return: Returns status, either success or error+reason
864 int zynqmp_pm_read_ggs(u32 index, u32 *value)
866 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_GGS,
869 EXPORT_SYMBOL_GPL(zynqmp_pm_read_ggs);
872 * zynqmp_pm_write_pggs() - PM API for writing persistent global general
874 * @index: PGGS register index
875 * @value: Register value to be written
877 * This function writes value to PGGS register.
879 * Return: Returns status, either success or error+reason
881 int zynqmp_pm_write_pggs(u32 index, u32 value)
883 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_PGGS, index, value,
886 EXPORT_SYMBOL_GPL(zynqmp_pm_write_pggs);
889 * zynqmp_pm_read_pggs() - PM API for reading persistent global general
891 * @index: PGGS register index
892 * @value: Register value to be written
894 * This function returns PGGS register value.
896 * Return: Returns status, either success or error+reason
898 int zynqmp_pm_read_pggs(u32 index, u32 *value)
900 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_PGGS, index, 0,
903 EXPORT_SYMBOL_GPL(zynqmp_pm_read_pggs);
905 int zynqmp_pm_set_tapdelay_bypass(u32 index, u32 value)
907 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_TAPDELAY_BYPASS,
910 EXPORT_SYMBOL_GPL(zynqmp_pm_set_tapdelay_bypass);
913 * zynqmp_pm_set_boot_health_status() - PM API for setting healthy boot status
914 * @value: Status value to be written
916 * This function sets healthy bit value to indicate boot health status
919 * Return: Returns status, either success or error+reason
921 int zynqmp_pm_set_boot_health_status(u32 value)
923 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_BOOT_HEALTH_STATUS,
928 * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
929 * @reset: Reset to be configured
930 * @assert_flag: Flag stating should reset be asserted (1) or
933 * Return: Returns status, either success or error+reason
935 int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
936 const enum zynqmp_pm_reset_action assert_flag)
938 return zynqmp_pm_invoke_fn(PM_RESET_ASSERT, reset, assert_flag,
941 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_assert);
944 * zynqmp_pm_reset_get_status - Get status of the reset
945 * @reset: Reset whose status should be returned
946 * @status: Returned status
948 * Return: Returns status, either success or error+reason
950 int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset, u32 *status)
952 u32 ret_payload[PAYLOAD_ARG_CNT];
958 ret = zynqmp_pm_invoke_fn(PM_RESET_GET_STATUS, reset, 0,
960 *status = ret_payload[1];
964 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_get_status);
967 * zynqmp_pm_fpga_load - Perform the fpga load
968 * @address: Address to write to
969 * @size: pl bitstream size
970 * @flags: Bitstream type
971 * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
972 * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
974 * This function provides access to pmufw. To transfer
975 * the required bitstream into PL.
977 * Return: Returns status, either success or error+reason
979 int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags)
981 u32 ret_payload[PAYLOAD_ARG_CNT];
984 ret = zynqmp_pm_invoke_fn(PM_FPGA_LOAD, lower_32_bits(address),
985 upper_32_bits(address), size, flags,
988 return -ret_payload[0];
992 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load);
995 * zynqmp_pm_fpga_get_status - Read value from PCAP status register
996 * @value: Value to read
998 * This function provides access to the pmufw to get the PCAP
1001 * Return: Returns status, either success or error+reason
1003 int zynqmp_pm_fpga_get_status(u32 *value)
1005 u32 ret_payload[PAYLOAD_ARG_CNT];
1011 ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, 0, 0, 0, 0, ret_payload);
1012 *value = ret_payload[1];
1016 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
1019 * zynqmp_pm_fpga_get_config_status - Get the FPGA configuration status.
1020 * @value: Buffer to store FPGA configuration status.
1022 * This function provides access to the pmufw to get the FPGA configuration
1025 * Return: 0 on success, a negative value on error
1027 int zynqmp_pm_fpga_get_config_status(u32 *value)
1029 u32 ret_payload[PAYLOAD_ARG_CNT];
1030 u32 buf, lower_addr, upper_addr;
1036 lower_addr = lower_32_bits((u64)&buf);
1037 upper_addr = upper_32_bits((u64)&buf);
1039 ret = zynqmp_pm_invoke_fn(PM_FPGA_READ,
1040 XILINX_ZYNQMP_PM_FPGA_CONFIG_STAT_OFFSET,
1041 lower_addr, upper_addr,
1042 XILINX_ZYNQMP_PM_FPGA_READ_CONFIG_REG,
1045 *value = ret_payload[1];
1049 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_config_status);
1052 * zynqmp_pm_pinctrl_request - Request Pin from firmware
1053 * @pin: Pin number to request
1055 * This function requests pin from firmware.
1057 * Return: Returns status, either success or error+reason.
1059 int zynqmp_pm_pinctrl_request(const u32 pin)
1061 return zynqmp_pm_invoke_fn(PM_PINCTRL_REQUEST, pin, 0, 0, 0, NULL);
1063 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_request);
1066 * zynqmp_pm_pinctrl_release - Inform firmware that Pin control is released
1067 * @pin: Pin number to release
1069 * This function release pin from firmware.
1071 * Return: Returns status, either success or error+reason.
1073 int zynqmp_pm_pinctrl_release(const u32 pin)
1075 return zynqmp_pm_invoke_fn(PM_PINCTRL_RELEASE, pin, 0, 0, 0, NULL);
1077 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_release);
1080 * zynqmp_pm_pinctrl_get_function - Read function id set for the given pin
1082 * @id: Buffer to store function ID
1084 * This function provides the function currently set for the given pin.
1086 * Return: Returns status, either success or error+reason
1088 int zynqmp_pm_pinctrl_get_function(const u32 pin, u32 *id)
1090 u32 ret_payload[PAYLOAD_ARG_CNT];
1096 ret = zynqmp_pm_invoke_fn(PM_PINCTRL_GET_FUNCTION, pin, 0,
1098 *id = ret_payload[1];
1102 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_function);
1105 * zynqmp_pm_pinctrl_set_function - Set requested function for the pin
1107 * @id: Function ID to set
1109 * This function sets requested function for the given pin.
1111 * Return: Returns status, either success or error+reason.
1113 int zynqmp_pm_pinctrl_set_function(const u32 pin, const u32 id)
1115 return zynqmp_pm_invoke_fn(PM_PINCTRL_SET_FUNCTION, pin, id,
1118 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_function);
1121 * zynqmp_pm_pinctrl_get_config - Get configuration parameter for the pin
1123 * @param: Parameter to get
1124 * @value: Buffer to store parameter value
1126 * This function gets requested configuration parameter for the given pin.
1128 * Return: Returns status, either success or error+reason.
1130 int zynqmp_pm_pinctrl_get_config(const u32 pin, const u32 param,
1133 u32 ret_payload[PAYLOAD_ARG_CNT];
1139 ret = zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_GET, pin, param,
1141 *value = ret_payload[1];
1145 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_config);
1148 * zynqmp_pm_pinctrl_set_config - Set configuration parameter for the pin
1150 * @param: Parameter to set
1151 * @value: Parameter value to set
1153 * This function sets requested configuration parameter for the given pin.
1155 * Return: Returns status, either success or error+reason.
1157 int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param,
1162 if (pm_family_code == ZYNQMP_FAMILY_CODE &&
1163 param == PM_PINCTRL_CONFIG_TRI_STATE) {
1164 ret = zynqmp_pm_feature(PM_PINCTRL_CONFIG_PARAM_SET);
1165 if (ret < PM_PINCTRL_PARAM_SET_VERSION)
1169 return zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_SET, pin,
1170 param, value, 0, NULL);
1172 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_config);
1175 * zynqmp_pm_bootmode_read() - PM Config API for read bootpin status
1176 * @ps_mode: Returned output value of ps_mode
1178 * This API function is to be used for notify the power management controller
1179 * to read bootpin status.
1181 * Return: status, either success or error+reason
1183 unsigned int zynqmp_pm_bootmode_read(u32 *ps_mode)
1186 u32 ret_payload[PAYLOAD_ARG_CNT];
1188 ret = zynqmp_pm_invoke_fn(PM_MMIO_READ, CRL_APB_BOOT_PIN_CTRL, 0,
1191 *ps_mode = ret_payload[1];
1195 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_read);
1198 * zynqmp_pm_bootmode_write() - PM Config API for Configure bootpin
1199 * @ps_mode: Value to be written to the bootpin ctrl register
1201 * This API function is to be used for notify the power management controller
1202 * to configure bootpin.
1204 * Return: Returns status, either success or error+reason
1206 int zynqmp_pm_bootmode_write(u32 ps_mode)
1208 return zynqmp_pm_invoke_fn(PM_MMIO_WRITE, CRL_APB_BOOT_PIN_CTRL,
1209 CRL_APB_BOOTPIN_CTRL_MASK, ps_mode, 0, NULL);
1211 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_write);
1214 * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
1215 * master has initialized its own power management
1217 * Return: Returns status, either success or error+reason
1219 * This API function is to be used for notify the power management controller
1220 * about the completed power management initialization.
1222 int zynqmp_pm_init_finalize(void)
1224 return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, 0, 0, 0, 0, NULL);
1226 EXPORT_SYMBOL_GPL(zynqmp_pm_init_finalize);
1229 * zynqmp_pm_set_suspend_mode() - Set system suspend mode
1230 * @mode: Mode to set for system suspend
1232 * This API function is used to set mode of system suspend.
1234 * Return: Returns status, either success or error+reason
1236 int zynqmp_pm_set_suspend_mode(u32 mode)
1238 return zynqmp_pm_invoke_fn(PM_SET_SUSPEND_MODE, mode, 0, 0, 0, NULL);
1240 EXPORT_SYMBOL_GPL(zynqmp_pm_set_suspend_mode);
1243 * zynqmp_pm_request_node() - Request a node with specific capabilities
1244 * @node: Node ID of the slave
1245 * @capabilities: Requested capabilities of the slave
1246 * @qos: Quality of service (not supported)
1247 * @ack: Flag to specify whether acknowledge is requested
1249 * This function is used by master to request particular node from firmware.
1250 * Every master must request node before using it.
1252 * Return: Returns status, either success or error+reason
1254 int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
1255 const u32 qos, const enum zynqmp_pm_request_ack ack)
1257 return zynqmp_pm_invoke_fn(PM_REQUEST_NODE, node, capabilities,
1260 EXPORT_SYMBOL_GPL(zynqmp_pm_request_node);
1263 * zynqmp_pm_release_node() - Release a node
1264 * @node: Node ID of the slave
1266 * This function is used by master to inform firmware that master
1267 * has released node. Once released, master must not use that node
1268 * without re-request.
1270 * Return: Returns status, either success or error+reason
1272 int zynqmp_pm_release_node(const u32 node)
1274 return zynqmp_pm_invoke_fn(PM_RELEASE_NODE, node, 0, 0, 0, NULL);
1276 EXPORT_SYMBOL_GPL(zynqmp_pm_release_node);
1279 * zynqmp_pm_get_rpu_mode() - Get RPU mode
1280 * @node_id: Node ID of the device
1281 * @rpu_mode: return by reference value
1282 * either split or lockstep
1284 * Return: return 0 on success or error+reason.
1285 * if success, then rpu_mode will be set
1286 * to current rpu mode.
1288 int zynqmp_pm_get_rpu_mode(u32 node_id, enum rpu_oper_mode *rpu_mode)
1290 u32 ret_payload[PAYLOAD_ARG_CNT];
1293 ret = zynqmp_pm_invoke_fn(PM_IOCTL, node_id,
1294 IOCTL_GET_RPU_OPER_MODE, 0, 0, ret_payload);
1296 /* only set rpu_mode if no error */
1297 if (ret == XST_PM_SUCCESS)
1298 *rpu_mode = ret_payload[0];
1302 EXPORT_SYMBOL_GPL(zynqmp_pm_get_rpu_mode);
1305 * zynqmp_pm_set_rpu_mode() - Set RPU mode
1306 * @node_id: Node ID of the device
1307 * @rpu_mode: Argument 1 to requested IOCTL call. either split or lockstep
1309 * This function is used to set RPU mode to split or
1312 * Return: Returns status, either success or error+reason
1314 int zynqmp_pm_set_rpu_mode(u32 node_id, enum rpu_oper_mode rpu_mode)
1316 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id,
1317 IOCTL_SET_RPU_OPER_MODE, (u32)rpu_mode,
1320 EXPORT_SYMBOL_GPL(zynqmp_pm_set_rpu_mode);
1323 * zynqmp_pm_set_tcm_config - configure TCM
1324 * @node_id: Firmware specific TCM subsystem ID
1325 * @tcm_mode: Argument 1 to requested IOCTL call
1326 * either PM_RPU_TCM_COMB or PM_RPU_TCM_SPLIT
1328 * This function is used to set RPU mode to split or combined
1330 * Return: status: 0 for success, else failure
1332 int zynqmp_pm_set_tcm_config(u32 node_id, enum rpu_tcm_comb tcm_mode)
1334 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id,
1335 IOCTL_TCM_COMB_CONFIG, (u32)tcm_mode, 0,
1338 EXPORT_SYMBOL_GPL(zynqmp_pm_set_tcm_config);
1341 * zynqmp_pm_force_pwrdwn - PM call to request for another PU or subsystem to
1342 * be powered down forcefully
1343 * @node: Node ID of the targeted PU or subsystem
1344 * @ack: Flag to specify whether acknowledge is requested
1346 * Return: status, either success or error+reason
1348 int zynqmp_pm_force_pwrdwn(const u32 node,
1349 const enum zynqmp_pm_request_ack ack)
1351 return zynqmp_pm_invoke_fn(PM_FORCE_POWERDOWN, node, ack, 0, 0, NULL);
1353 EXPORT_SYMBOL_GPL(zynqmp_pm_force_pwrdwn);
1356 * zynqmp_pm_request_wake - PM call to wake up selected master or subsystem
1357 * @node: Node ID of the master or subsystem
1358 * @set_addr: Specifies whether the address argument is relevant
1359 * @address: Address from which to resume when woken up
1360 * @ack: Flag to specify whether acknowledge requested
1362 * Return: status, either success or error+reason
1364 int zynqmp_pm_request_wake(const u32 node,
1365 const bool set_addr,
1367 const enum zynqmp_pm_request_ack ack)
1369 /* set_addr flag is encoded into 1st bit of address */
1370 return zynqmp_pm_invoke_fn(PM_REQUEST_WAKEUP, node, address | set_addr,
1371 address >> 32, ack, NULL);
1373 EXPORT_SYMBOL_GPL(zynqmp_pm_request_wake);
1376 * zynqmp_pm_set_requirement() - PM call to set requirement for PM slaves
1377 * @node: Node ID of the slave
1378 * @capabilities: Requested capabilities of the slave
1379 * @qos: Quality of service (not supported)
1380 * @ack: Flag to specify whether acknowledge is requested
1382 * This API function is to be used for slaves a PU already has requested
1383 * to change its capabilities.
1385 * Return: Returns status, either success or error+reason
1387 int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
1389 const enum zynqmp_pm_request_ack ack)
1391 return zynqmp_pm_invoke_fn(PM_SET_REQUIREMENT, node, capabilities,
1394 EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement);
1397 * zynqmp_pm_load_pdi - Load and process PDI
1398 * @src: Source device where PDI is located
1399 * @address: PDI src address
1401 * This function provides support to load PDI from linux
1403 * Return: Returns status, either success or error+reason
1405 int zynqmp_pm_load_pdi(const u32 src, const u64 address)
1407 return zynqmp_pm_invoke_fn(PM_LOAD_PDI, src,
1408 lower_32_bits(address),
1409 upper_32_bits(address), 0, NULL);
1411 EXPORT_SYMBOL_GPL(zynqmp_pm_load_pdi);
1414 * zynqmp_pm_aes_engine - Access AES hardware to encrypt/decrypt the data using
1416 * @address: Address of the AesParams structure.
1417 * @out: Returned output value
1419 * Return: Returns status, either success or error code.
1421 int zynqmp_pm_aes_engine(const u64 address, u32 *out)
1423 u32 ret_payload[PAYLOAD_ARG_CNT];
1429 ret = zynqmp_pm_invoke_fn(PM_SECURE_AES, upper_32_bits(address),
1430 lower_32_bits(address),
1432 *out = ret_payload[1];
1436 EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine);
1439 * zynqmp_pm_sha_hash - Access the SHA engine to calculate the hash
1440 * @address: Address of the data/ Address of output buffer where
1441 * hash should be stored.
1442 * @size: Size of the data.
1444 * BIT(0) - for initializing csudma driver and SHA3(Here address
1445 * and size inputs can be NULL).
1446 * BIT(1) - to call Sha3_Update API which can be called multiple
1447 * times when data is not contiguous.
1448 * BIT(2) - to get final hash of the whole updated data.
1449 * Hash will be overwritten at provided address with
1452 * Return: Returns status, either success or error code.
1454 int zynqmp_pm_sha_hash(const u64 address, const u32 size, const u32 flags)
1456 u32 lower_addr = lower_32_bits(address);
1457 u32 upper_addr = upper_32_bits(address);
1459 return zynqmp_pm_invoke_fn(PM_SECURE_SHA, upper_addr, lower_addr,
1462 EXPORT_SYMBOL_GPL(zynqmp_pm_sha_hash);
1465 * zynqmp_pm_register_notifier() - PM API for register a subsystem
1466 * to be notified about specific
1468 * @node: Node ID to which the event is related.
1469 * @event: Event Mask of Error events for which wants to get notified.
1470 * @wake: Wake subsystem upon capturing the event if value 1
1471 * @enable: Enable the registration for value 1, disable for value 0
1473 * This function is used to register/un-register for particular node-event
1474 * combination in firmware.
1476 * Return: Returns status, either success or error+reason
1479 int zynqmp_pm_register_notifier(const u32 node, const u32 event,
1480 const u32 wake, const u32 enable)
1482 return zynqmp_pm_invoke_fn(PM_REGISTER_NOTIFIER, node, event,
1483 wake, enable, NULL);
1485 EXPORT_SYMBOL_GPL(zynqmp_pm_register_notifier);
1488 * zynqmp_pm_system_shutdown - PM call to request a system shutdown or restart
1489 * @type: Shutdown or restart? 0 for shutdown, 1 for restart
1490 * @subtype: Specifies which system should be restarted or shut down
1492 * Return: Returns status, either success or error+reason
1494 int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype)
1496 return zynqmp_pm_invoke_fn(PM_SYSTEM_SHUTDOWN, type, subtype,
1501 * zynqmp_pm_set_feature_config - PM call to request IOCTL for feature config
1502 * @id: The config ID of the feature to be configured
1503 * @value: The config value of the feature to be configured
1505 * Return: Returns 0 on success or error value on failure.
1507 int zynqmp_pm_set_feature_config(enum pm_feature_config_id id, u32 value)
1509 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_FEATURE_CONFIG,
1514 * zynqmp_pm_get_feature_config - PM call to get value of configured feature
1515 * @id: The config id of the feature to be queried
1516 * @payload: Returned value array
1518 * Return: Returns 0 on success or error value on failure.
1520 int zynqmp_pm_get_feature_config(enum pm_feature_config_id id,
1523 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_FEATURE_CONFIG,
1528 * zynqmp_pm_set_sd_config - PM call to set value of SD config registers
1530 * @config: The config type of SD registers
1531 * @value: Value to be set
1533 * Return: Returns 0 on success or error value on failure.
1535 int zynqmp_pm_set_sd_config(u32 node, enum pm_sd_config_type config, u32 value)
1537 return zynqmp_pm_invoke_fn(PM_IOCTL, node, IOCTL_SET_SD_CONFIG,
1538 config, value, NULL);
1540 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_config);
1543 * zynqmp_pm_set_gem_config - PM call to set value of GEM config registers
1544 * @node: GEM node ID
1545 * @config: The config type of GEM registers
1546 * @value: Value to be set
1548 * Return: Returns 0 on success or error value on failure.
1550 int zynqmp_pm_set_gem_config(u32 node, enum pm_gem_config_type config,
1553 return zynqmp_pm_invoke_fn(PM_IOCTL, node, IOCTL_SET_GEM_CONFIG,
1554 config, value, NULL);
1556 EXPORT_SYMBOL_GPL(zynqmp_pm_set_gem_config);
1559 * struct zynqmp_pm_shutdown_scope - Struct for shutdown scope
1560 * @subtype: Shutdown subtype
1561 * @name: Matching string for scope argument
1563 * This struct encapsulates mapping between shutdown scope ID and string.
1565 struct zynqmp_pm_shutdown_scope {
1566 const enum zynqmp_pm_shutdown_subtype subtype;
1570 static struct zynqmp_pm_shutdown_scope shutdown_scopes[] = {
1571 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM] = {
1572 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
1573 .name = "subsystem",
1575 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY] = {
1576 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
1579 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM] = {
1580 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
1585 static struct zynqmp_pm_shutdown_scope *selected_scope =
1586 &shutdown_scopes[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM];
1589 * zynqmp_pm_is_shutdown_scope_valid - Check if shutdown scope string is valid
1590 * @scope_string: Shutdown scope string
1592 * Return: Return pointer to matching shutdown scope struct from
1593 * array of available options in system if string is valid,
1594 * otherwise returns NULL.
1596 static struct zynqmp_pm_shutdown_scope*
1597 zynqmp_pm_is_shutdown_scope_valid(const char *scope_string)
1601 for (count = 0; count < ARRAY_SIZE(shutdown_scopes); count++)
1602 if (sysfs_streq(scope_string, shutdown_scopes[count].name))
1603 return &shutdown_scopes[count];
1608 static ssize_t shutdown_scope_show(struct device *device,
1609 struct device_attribute *attr,
1614 for (i = 0; i < ARRAY_SIZE(shutdown_scopes); i++) {
1615 if (&shutdown_scopes[i] == selected_scope) {
1617 strcat(buf, shutdown_scopes[i].name);
1620 strcat(buf, shutdown_scopes[i].name);
1629 static ssize_t shutdown_scope_store(struct device *device,
1630 struct device_attribute *attr,
1631 const char *buf, size_t count)
1634 struct zynqmp_pm_shutdown_scope *scope;
1636 scope = zynqmp_pm_is_shutdown_scope_valid(buf);
1640 ret = zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
1643 pr_err("unable to set shutdown scope %s\n", buf);
1647 selected_scope = scope;
1652 static DEVICE_ATTR_RW(shutdown_scope);
1654 static ssize_t health_status_store(struct device *device,
1655 struct device_attribute *attr,
1656 const char *buf, size_t count)
1661 ret = kstrtouint(buf, 10, &value);
1665 ret = zynqmp_pm_set_boot_health_status(value);
1667 dev_err(device, "unable to set healthy bit value to %u\n",
1675 static DEVICE_ATTR_WO(health_status);
1677 static ssize_t ggs_show(struct device *device,
1678 struct device_attribute *attr,
1683 u32 ret_payload[PAYLOAD_ARG_CNT];
1685 ret = zynqmp_pm_read_ggs(reg, ret_payload);
1689 return sprintf(buf, "0x%x\n", ret_payload[1]);
1692 static ssize_t ggs_store(struct device *device,
1693 struct device_attribute *attr,
1694 const char *buf, size_t count,
1700 if (reg >= GSS_NUM_REGS)
1703 ret = kstrtol(buf, 16, &value);
1709 ret = zynqmp_pm_write_ggs(reg, value);
1716 /* GGS register show functions */
1717 #define GGS0_SHOW(N) \
1718 ssize_t ggs##N##_show(struct device *device, \
1719 struct device_attribute *attr, \
1722 return ggs_show(device, attr, buf, N); \
1725 static GGS0_SHOW(0);
1726 static GGS0_SHOW(1);
1727 static GGS0_SHOW(2);
1728 static GGS0_SHOW(3);
1730 /* GGS register store function */
1731 #define GGS0_STORE(N) \
1732 ssize_t ggs##N##_store(struct device *device, \
1733 struct device_attribute *attr, \
1737 return ggs_store(device, attr, buf, count, N); \
1740 static GGS0_STORE(0);
1741 static GGS0_STORE(1);
1742 static GGS0_STORE(2);
1743 static GGS0_STORE(3);
1745 static ssize_t pggs_show(struct device *device,
1746 struct device_attribute *attr,
1751 u32 ret_payload[PAYLOAD_ARG_CNT];
1753 ret = zynqmp_pm_read_pggs(reg, ret_payload);
1757 return sprintf(buf, "0x%x\n", ret_payload[1]);
1760 static ssize_t pggs_store(struct device *device,
1761 struct device_attribute *attr,
1762 const char *buf, size_t count,
1768 if (reg >= GSS_NUM_REGS)
1771 ret = kstrtol(buf, 16, &value);
1777 ret = zynqmp_pm_write_pggs(reg, value);
1785 #define PGGS0_SHOW(N) \
1786 ssize_t pggs##N##_show(struct device *device, \
1787 struct device_attribute *attr, \
1790 return pggs_show(device, attr, buf, N); \
1793 #define PGGS0_STORE(N) \
1794 ssize_t pggs##N##_store(struct device *device, \
1795 struct device_attribute *attr, \
1799 return pggs_store(device, attr, buf, count, N); \
1802 /* PGGS register show functions */
1803 static PGGS0_SHOW(0);
1804 static PGGS0_SHOW(1);
1805 static PGGS0_SHOW(2);
1806 static PGGS0_SHOW(3);
1808 /* PGGS register store functions */
1809 static PGGS0_STORE(0);
1810 static PGGS0_STORE(1);
1811 static PGGS0_STORE(2);
1812 static PGGS0_STORE(3);
1814 /* GGS register attributes */
1815 static DEVICE_ATTR_RW(ggs0);
1816 static DEVICE_ATTR_RW(ggs1);
1817 static DEVICE_ATTR_RW(ggs2);
1818 static DEVICE_ATTR_RW(ggs3);
1820 /* PGGS register attributes */
1821 static DEVICE_ATTR_RW(pggs0);
1822 static DEVICE_ATTR_RW(pggs1);
1823 static DEVICE_ATTR_RW(pggs2);
1824 static DEVICE_ATTR_RW(pggs3);
1826 static ssize_t feature_config_id_show(struct device *device,
1827 struct device_attribute *attr,
1830 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1832 return sysfs_emit(buf, "%d\n", devinfo->feature_conf_id);
1835 static ssize_t feature_config_id_store(struct device *device,
1836 struct device_attribute *attr,
1837 const char *buf, size_t count)
1841 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1846 ret = kstrtou32(buf, 10, &config_id);
1850 devinfo->feature_conf_id = config_id;
1855 static DEVICE_ATTR_RW(feature_config_id);
1857 static ssize_t feature_config_value_show(struct device *device,
1858 struct device_attribute *attr,
1862 u32 ret_payload[PAYLOAD_ARG_CNT];
1863 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1865 ret = zynqmp_pm_get_feature_config(devinfo->feature_conf_id,
1870 return sysfs_emit(buf, "%d\n", ret_payload[1]);
1873 static ssize_t feature_config_value_store(struct device *device,
1874 struct device_attribute *attr,
1875 const char *buf, size_t count)
1879 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1884 ret = kstrtou32(buf, 10, &value);
1888 ret = zynqmp_pm_set_feature_config(devinfo->feature_conf_id,
1896 static DEVICE_ATTR_RW(feature_config_value);
1898 static struct attribute *zynqmp_firmware_attrs[] = {
1899 &dev_attr_ggs0.attr,
1900 &dev_attr_ggs1.attr,
1901 &dev_attr_ggs2.attr,
1902 &dev_attr_ggs3.attr,
1903 &dev_attr_pggs0.attr,
1904 &dev_attr_pggs1.attr,
1905 &dev_attr_pggs2.attr,
1906 &dev_attr_pggs3.attr,
1907 &dev_attr_shutdown_scope.attr,
1908 &dev_attr_health_status.attr,
1909 &dev_attr_feature_config_id.attr,
1910 &dev_attr_feature_config_value.attr,
1914 ATTRIBUTE_GROUPS(zynqmp_firmware);
1916 static int zynqmp_firmware_probe(struct platform_device *pdev)
1918 struct device *dev = &pdev->dev;
1919 struct device_node *np;
1920 struct zynqmp_devinfo *devinfo;
1923 ret = get_set_conduit_method(dev->of_node);
1927 np = of_find_compatible_node(NULL, NULL, "xlnx,zynqmp");
1929 np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
1933 feature_check_enabled = true;
1936 if (!feature_check_enabled) {
1937 ret = do_feature_check_call(PM_FEATURE_CHECK);
1939 feature_check_enabled = true;
1944 devinfo = devm_kzalloc(dev, sizeof(*devinfo), GFP_KERNEL);
1950 platform_set_drvdata(pdev, devinfo);
1952 /* Check PM API version number */
1953 ret = zynqmp_pm_get_api_version(&pm_api_version);
1957 if (pm_api_version < ZYNQMP_PM_VERSION) {
1958 panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
1960 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
1961 pm_api_version >> 16, pm_api_version & 0xFFFF);
1964 pr_info("%s Platform Management API v%d.%d\n", __func__,
1965 pm_api_version >> 16, pm_api_version & 0xFFFF);
1967 /* Get the Family code and sub family code of platform */
1968 ret = zynqmp_pm_get_family_info(&pm_family_code, &pm_sub_family_code);
1972 /* Check trustzone version number */
1973 ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
1975 panic("Legacy trustzone found without version support\n");
1977 if (pm_tz_version < ZYNQMP_TZ_VERSION)
1978 panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
1980 ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
1981 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1983 pr_info("%s Trustzone version v%d.%d\n", __func__,
1984 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1986 ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
1987 ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
1989 dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
1993 zynqmp_pm_api_debugfs_init();
1995 np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
1997 em_dev = platform_device_register_data(&pdev->dev, "xlnx_event_manager",
2000 dev_err_probe(&pdev->dev, PTR_ERR(em_dev), "EM register fail with error\n");
2004 return of_platform_populate(dev->of_node, NULL, NULL, dev);
2007 static int zynqmp_firmware_remove(struct platform_device *pdev)
2009 struct pm_api_feature_data *feature_data;
2010 struct hlist_node *tmp;
2013 mfd_remove_devices(&pdev->dev);
2014 zynqmp_pm_api_debugfs_exit();
2016 hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
2017 hash_del(&feature_data->hentry);
2018 kfree(feature_data);
2021 platform_device_unregister(em_dev);
2026 static const struct of_device_id zynqmp_firmware_of_match[] = {
2027 {.compatible = "xlnx,zynqmp-firmware"},
2028 {.compatible = "xlnx,versal-firmware"},
2031 MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
2033 static struct platform_driver zynqmp_firmware_driver = {
2035 .name = "zynqmp_firmware",
2036 .of_match_table = zynqmp_firmware_of_match,
2037 .dev_groups = zynqmp_firmware_groups,
2039 .probe = zynqmp_firmware_probe,
2040 .remove = zynqmp_firmware_remove,
2042 module_platform_driver(zynqmp_firmware_driver);