1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware layer
5 * Copyright (C) 2014-2021 Xilinx, Inc.
7 * Michal Simek <michal.simek@xilinx.com>
8 * Davorin Mista <davorin.mista@aggios.com>
9 * Jolly Shah <jollys@xilinx.com>
10 * Rajan Vaja <rajanv@xilinx.com>
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/slab.h>
22 #include <linux/uaccess.h>
23 #include <linux/hashtable.h>
25 #include <linux/firmware/xlnx-zynqmp.h>
26 #include <linux/firmware/xlnx-event-manager.h>
27 #include "zynqmp-debug.h"
29 /* Max HashMap Order for PM API feature check (1<<7 = 128) */
30 #define PM_API_FEATURE_CHECK_MAX_ORDER 7
32 /* CRL registers and bitfields */
33 #define CRL_APB_BASE 0xFF5E0000U
34 /* BOOT_PIN_CTRL- Used to control the mode pins after boot */
35 #define CRL_APB_BOOT_PIN_CTRL (CRL_APB_BASE + (0x250U))
36 /* BOOT_PIN_CTRL_MASK- out_val[11:8], out_en[3:0] */
37 #define CRL_APB_BOOTPIN_CTRL_MASK 0xF0FU
39 /* IOCTL/QUERY feature payload size */
40 #define FEATURE_PAYLOAD_SIZE 2
42 /* Firmware feature check version mask */
43 #define FIRMWARE_VERSION_MASK GENMASK(15, 0)
45 static bool feature_check_enabled;
46 static DEFINE_HASHTABLE(pm_api_features_map, PM_API_FEATURE_CHECK_MAX_ORDER);
47 static u32 ioctl_features[FEATURE_PAYLOAD_SIZE];
48 static u32 query_features[FEATURE_PAYLOAD_SIZE];
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_NO_ACCESS:
96 case XST_PM_ABORT_SUSPEND:
98 case XST_PM_MULT_USER:
100 case XST_PM_INTERNAL:
101 case XST_PM_CONFLICT:
102 case XST_PM_INVALID_NODE:
108 static noinline int do_fw_call_fail(u64 arg0, u64 arg1, u64 arg2,
115 * PM function call wrapper
116 * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
118 static int (*do_fw_call)(u64, u64, u64, u32 *ret_payload) = do_fw_call_fail;
121 * do_fw_call_smc() - Call system-level platform management layer (SMC)
122 * @arg0: Argument 0 to SMC call
123 * @arg1: Argument 1 to SMC call
124 * @arg2: Argument 2 to SMC call
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(u64 arg0, u64 arg1, u64 arg2,
134 struct arm_smccc_res res;
136 arm_smccc_smc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
139 ret_payload[0] = lower_32_bits(res.a0);
140 ret_payload[1] = upper_32_bits(res.a0);
141 ret_payload[2] = lower_32_bits(res.a1);
142 ret_payload[3] = upper_32_bits(res.a1);
145 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
149 * do_fw_call_hvc() - Call system-level platform management layer (HVC)
150 * @arg0: Argument 0 to HVC call
151 * @arg1: Argument 1 to HVC call
152 * @arg2: Argument 2 to HVC call
153 * @ret_payload: Returned value array
155 * Invoke platform management function via HVC
156 * HVC-based for communication through hypervisor
157 * (no direct communication with ATF).
159 * Return: Returns status, either success or error+reason
161 static noinline int do_fw_call_hvc(u64 arg0, u64 arg1, u64 arg2,
164 struct arm_smccc_res res;
166 arm_smccc_hvc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
169 ret_payload[0] = lower_32_bits(res.a0);
170 ret_payload[1] = upper_32_bits(res.a0);
171 ret_payload[2] = lower_32_bits(res.a1);
172 ret_payload[3] = upper_32_bits(res.a1);
175 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
178 static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
183 smc_arg[0] = PM_SIP_SVC | PM_FEATURE_CHECK;
186 ret = do_fw_call(smc_arg[0], smc_arg[1], 0, ret_payload);
190 ret = ret_payload[1];
195 static int do_feature_check_call(const u32 api_id)
198 u32 ret_payload[PAYLOAD_ARG_CNT];
199 struct pm_api_feature_data *feature_data;
201 /* Check for existing entry in hash table for given api */
202 hash_for_each_possible(pm_api_features_map, feature_data, hentry,
204 if (feature_data->pm_api_id == api_id)
205 return feature_data->feature_status;
208 /* Add new entry if not present */
209 feature_data = kmalloc(sizeof(*feature_data), GFP_KERNEL);
213 feature_data->pm_api_id = api_id;
214 ret = __do_feature_check_call(api_id, ret_payload);
216 feature_data->feature_status = ret;
217 hash_add(pm_api_features_map, &feature_data->hentry, api_id);
219 if (api_id == PM_IOCTL)
220 /* Store supported IOCTL IDs mask */
221 memcpy(ioctl_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
222 else if (api_id == PM_QUERY_DATA)
223 /* Store supported QUERY IDs mask */
224 memcpy(query_features, &ret_payload[2], FEATURE_PAYLOAD_SIZE * 4);
228 EXPORT_SYMBOL_GPL(zynqmp_pm_feature);
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);
250 * zynqmp_pm_is_function_supported() - Check whether given IOCTL/QUERY function
251 * is supported or not
252 * @api_id: PM_IOCTL or PM_QUERY_DATA
253 * @id: IOCTL or QUERY function IDs
255 * Return: Returns status, either success or error+reason
257 int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
262 /* Input arguments validation */
263 if (id >= 64 || (api_id != PM_IOCTL && api_id != PM_QUERY_DATA))
266 /* Check feature check API version */
267 ret = do_feature_check_call(PM_FEATURE_CHECK);
271 /* Check if feature check version 2 is supported or not */
272 if ((ret & FIRMWARE_VERSION_MASK) == PM_API_VERSION_2) {
274 * Call feature check for IOCTL/QUERY API to get IOCTL ID or
275 * QUERY ID feature status.
277 ret = do_feature_check_call(api_id);
281 bit_mask = (api_id == PM_IOCTL) ? ioctl_features : query_features;
283 if ((bit_mask[(id / 32)] & BIT((id % 32))) == 0U)
291 EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
294 * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
295 * caller function depending on the configuration
296 * @pm_api_id: Requested PM-API call
297 * @arg0: Argument 0 to requested PM-API call
298 * @arg1: Argument 1 to requested PM-API call
299 * @arg2: Argument 2 to requested PM-API call
300 * @arg3: Argument 3 to requested PM-API call
301 * @ret_payload: Returned value array
303 * Invoke platform management function for SMC or HVC call, depending on
305 * Following SMC Calling Convention (SMCCC) for SMC64:
306 * Pm Function Identifier,
307 * PM_SIP_SVC + PM_API_ID =
308 * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
309 * ((SMC_64) << FUNCID_CC_SHIFT)
310 * ((SIP_START) << FUNCID_OEN_SHIFT)
311 * ((PM_API_ID) & FUNCID_NUM_MASK))
313 * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
314 * PM_API_ID - Platform Management API ID.
316 * Return: Returns status, either success or error+reason
318 int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
319 u32 arg2, u32 arg3, u32 *ret_payload)
322 * Added SIP service call Function Identifier
323 * Make sure to stay in x0 register
328 /* Check if feature is supported or not */
329 ret = zynqmp_pm_feature(pm_api_id);
333 smc_arg[0] = PM_SIP_SVC | pm_api_id;
334 smc_arg[1] = ((u64)arg1 << 32) | arg0;
335 smc_arg[2] = ((u64)arg3 << 32) | arg2;
337 return do_fw_call(smc_arg[0], smc_arg[1], smc_arg[2], ret_payload);
340 static u32 pm_api_version;
341 static u32 pm_tz_version;
344 * zynqmp_pm_get_api_version() - Get version number of PMU PM firmware
345 * @version: Returned version value
347 * Return: Returns status, either success or error+reason
349 int zynqmp_pm_get_api_version(u32 *version)
351 u32 ret_payload[PAYLOAD_ARG_CNT];
357 /* Check is PM API version already verified */
358 if (pm_api_version > 0) {
359 *version = pm_api_version;
362 ret = zynqmp_pm_invoke_fn(PM_GET_API_VERSION, 0, 0, 0, 0, ret_payload);
363 *version = ret_payload[1];
367 EXPORT_SYMBOL_GPL(zynqmp_pm_get_api_version);
370 * zynqmp_pm_get_chipid - Get silicon ID registers
371 * @idcode: IDCODE register
372 * @version: version register
374 * Return: Returns the status of the operation and the idcode and version
375 * registers in @idcode and @version.
377 int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
379 u32 ret_payload[PAYLOAD_ARG_CNT];
382 if (!idcode || !version)
385 ret = zynqmp_pm_invoke_fn(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
386 *idcode = ret_payload[1];
387 *version = ret_payload[2];
391 EXPORT_SYMBOL_GPL(zynqmp_pm_get_chipid);
394 * zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
395 * @version: Returned version value
397 * Return: Returns status, either success or error+reason
399 static int zynqmp_pm_get_trustzone_version(u32 *version)
401 u32 ret_payload[PAYLOAD_ARG_CNT];
407 /* Check is PM trustzone version already verified */
408 if (pm_tz_version > 0) {
409 *version = pm_tz_version;
412 ret = zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION, 0, 0,
414 *version = ret_payload[1];
420 * get_set_conduit_method() - Choose SMC or HVC based communication
421 * @np: Pointer to the device_node structure
423 * Use SMC or HVC-based functions to communicate with EL2/EL3.
425 * Return: Returns 0 on success or error code
427 static int get_set_conduit_method(struct device_node *np)
431 if (of_property_read_string(np, "method", &method)) {
432 pr_warn("%s missing \"method\" property\n", __func__);
436 if (!strcmp("hvc", method)) {
437 do_fw_call = do_fw_call_hvc;
438 } else if (!strcmp("smc", method)) {
439 do_fw_call = do_fw_call_smc;
441 pr_warn("%s Invalid \"method\" property: %s\n",
450 * zynqmp_pm_query_data() - Get query data from firmware
451 * @qdata: Variable to the zynqmp_pm_query_data structure
452 * @out: Returned output value
454 * Return: Returns status, either success or error+reason
456 int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out)
460 ret = zynqmp_pm_invoke_fn(PM_QUERY_DATA, qdata.qid, qdata.arg1,
461 qdata.arg2, qdata.arg3, out);
464 * For clock name query, all bytes in SMC response are clock name
465 * characters and return code is always success. For invalid clocks,
466 * clock name bytes would be zeros.
468 return qdata.qid == PM_QID_CLOCK_GET_NAME ? 0 : ret;
470 EXPORT_SYMBOL_GPL(zynqmp_pm_query_data);
473 * zynqmp_pm_clock_enable() - Enable the clock for given id
474 * @clock_id: ID of the clock to be enabled
476 * This function is used by master to enable the clock
477 * including peripherals and PLL clocks.
479 * Return: Returns status, either success or error+reason
481 int zynqmp_pm_clock_enable(u32 clock_id)
483 return zynqmp_pm_invoke_fn(PM_CLOCK_ENABLE, clock_id, 0, 0, 0, NULL);
485 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_enable);
488 * zynqmp_pm_clock_disable() - Disable the clock for given id
489 * @clock_id: ID of the clock to be disable
491 * This function is used by master to disable the clock
492 * including peripherals and PLL clocks.
494 * Return: Returns status, either success or error+reason
496 int zynqmp_pm_clock_disable(u32 clock_id)
498 return zynqmp_pm_invoke_fn(PM_CLOCK_DISABLE, clock_id, 0, 0, 0, NULL);
500 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_disable);
503 * zynqmp_pm_clock_getstate() - Get the clock state for given id
504 * @clock_id: ID of the clock to be queried
505 * @state: 1/0 (Enabled/Disabled)
507 * This function is used by master to get the state of clock
508 * including peripherals and PLL clocks.
510 * Return: Returns status, either success or error+reason
512 int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state)
514 u32 ret_payload[PAYLOAD_ARG_CNT];
517 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETSTATE, clock_id, 0,
519 *state = ret_payload[1];
523 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getstate);
526 * zynqmp_pm_clock_setdivider() - Set the clock divider for given id
527 * @clock_id: ID of the clock
528 * @divider: divider value
530 * This function is used by master to set divider for any clock
531 * to achieve desired rate.
533 * Return: Returns status, either success or error+reason
535 int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider)
537 return zynqmp_pm_invoke_fn(PM_CLOCK_SETDIVIDER, clock_id, divider,
540 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setdivider);
543 * zynqmp_pm_clock_getdivider() - Get the clock divider for given id
544 * @clock_id: ID of the clock
545 * @divider: divider value
547 * This function is used by master to get divider values
550 * Return: Returns status, either success or error+reason
552 int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider)
554 u32 ret_payload[PAYLOAD_ARG_CNT];
557 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETDIVIDER, clock_id, 0,
559 *divider = ret_payload[1];
563 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getdivider);
566 * zynqmp_pm_clock_setrate() - Set the clock rate for given id
567 * @clock_id: ID of the clock
568 * @rate: rate value in hz
570 * This function is used by master to set rate for any clock.
572 * Return: Returns status, either success or error+reason
574 int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate)
576 return zynqmp_pm_invoke_fn(PM_CLOCK_SETRATE, clock_id,
581 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setrate);
584 * zynqmp_pm_clock_getrate() - Get the clock rate for given id
585 * @clock_id: ID of the clock
586 * @rate: rate value in hz
588 * This function is used by master to get rate
591 * Return: Returns status, either success or error+reason
593 int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate)
595 u32 ret_payload[PAYLOAD_ARG_CNT];
598 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETRATE, clock_id, 0,
600 *rate = ((u64)ret_payload[2] << 32) | ret_payload[1];
604 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getrate);
607 * zynqmp_pm_clock_setparent() - Set the clock parent for given id
608 * @clock_id: ID of the clock
609 * @parent_id: parent id
611 * This function is used by master to set parent for any clock.
613 * Return: Returns status, either success or error+reason
615 int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id)
617 return zynqmp_pm_invoke_fn(PM_CLOCK_SETPARENT, clock_id,
618 parent_id, 0, 0, NULL);
620 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setparent);
623 * zynqmp_pm_clock_getparent() - Get the clock parent for given id
624 * @clock_id: ID of the clock
625 * @parent_id: parent id
627 * This function is used by master to get parent index
630 * Return: Returns status, either success or error+reason
632 int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
634 u32 ret_payload[PAYLOAD_ARG_CNT];
637 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETPARENT, clock_id, 0,
639 *parent_id = ret_payload[1];
643 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getparent);
646 * zynqmp_pm_set_pll_frac_mode() - PM API for set PLL mode
648 * @clk_id: PLL clock ID
649 * @mode: PLL mode (PLL_MODE_FRAC/PLL_MODE_INT)
651 * This function sets PLL mode
653 * Return: Returns status, either success or error+reason
655 int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
657 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_MODE,
660 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_mode);
663 * zynqmp_pm_get_pll_frac_mode() - PM API for get PLL mode
665 * @clk_id: PLL clock ID
668 * This function return current PLL mode
670 * Return: Returns status, either success or error+reason
672 int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
674 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_MODE,
677 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_mode);
680 * zynqmp_pm_set_pll_frac_data() - PM API for setting pll fraction data
682 * @clk_id: PLL clock ID
683 * @data: fraction data
685 * This function sets fraction data.
686 * It is valid for fraction mode only.
688 * Return: Returns status, either success or error+reason
690 int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
692 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_DATA,
695 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_data);
698 * zynqmp_pm_get_pll_frac_data() - PM API for getting pll fraction data
700 * @clk_id: PLL clock ID
701 * @data: fraction data
703 * This function returns fraction data value.
705 * Return: Returns status, either success or error+reason
707 int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
709 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_DATA,
712 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_data);
715 * zynqmp_pm_set_sd_tapdelay() - Set tap delay for the SD device
717 * @node_id: Node ID of the device
718 * @type: Type of tap delay to set (input/output)
719 * @value: Value to set fot the tap delay
721 * This function sets input/output tap delay for the SD device.
723 * Return: Returns status, either success or error+reason
725 int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
727 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SET_SD_TAPDELAY,
730 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_tapdelay);
733 * zynqmp_pm_sd_dll_reset() - Reset DLL logic
735 * @node_id: Node ID of the device
738 * This function resets DLL logic for the SD device.
740 * Return: Returns status, either success or error+reason
742 int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
744 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SD_DLL_RESET,
747 EXPORT_SYMBOL_GPL(zynqmp_pm_sd_dll_reset);
750 * zynqmp_pm_ospi_mux_select() - OSPI Mux selection
752 * @dev_id: Device Id of the OSPI device.
753 * @select: OSPI Mux select value.
755 * This function select the OSPI Mux.
757 * Return: Returns status, either success or error+reason
759 int zynqmp_pm_ospi_mux_select(u32 dev_id, u32 select)
761 return zynqmp_pm_invoke_fn(PM_IOCTL, dev_id, IOCTL_OSPI_MUX_SELECT,
764 EXPORT_SYMBOL_GPL(zynqmp_pm_ospi_mux_select);
767 * zynqmp_pm_write_ggs() - PM API for writing global general storage (ggs)
768 * @index: GGS register index
769 * @value: Register value to be written
771 * This function writes value to GGS register.
773 * Return: Returns status, either success or error+reason
775 int zynqmp_pm_write_ggs(u32 index, u32 value)
777 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_GGS,
780 EXPORT_SYMBOL_GPL(zynqmp_pm_write_ggs);
783 * zynqmp_pm_read_ggs() - PM API for reading global general storage (ggs)
784 * @index: GGS register index
785 * @value: Register value to be written
787 * This function returns GGS register value.
789 * Return: Returns status, either success or error+reason
791 int zynqmp_pm_read_ggs(u32 index, u32 *value)
793 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_GGS,
796 EXPORT_SYMBOL_GPL(zynqmp_pm_read_ggs);
799 * zynqmp_pm_write_pggs() - PM API for writing persistent global general
801 * @index: PGGS register index
802 * @value: Register value to be written
804 * This function writes value to PGGS register.
806 * Return: Returns status, either success or error+reason
808 int zynqmp_pm_write_pggs(u32 index, u32 value)
810 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_PGGS, index, value,
813 EXPORT_SYMBOL_GPL(zynqmp_pm_write_pggs);
816 * zynqmp_pm_read_pggs() - PM API for reading persistent global general
818 * @index: PGGS register index
819 * @value: Register value to be written
821 * This function returns PGGS register value.
823 * Return: Returns status, either success or error+reason
825 int zynqmp_pm_read_pggs(u32 index, u32 *value)
827 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_PGGS, index, 0,
830 EXPORT_SYMBOL_GPL(zynqmp_pm_read_pggs);
833 * zynqmp_pm_set_boot_health_status() - PM API for setting healthy boot status
834 * @value: Status value to be written
836 * This function sets healthy bit value to indicate boot health status
839 * Return: Returns status, either success or error+reason
841 int zynqmp_pm_set_boot_health_status(u32 value)
843 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_BOOT_HEALTH_STATUS,
848 * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
849 * @reset: Reset to be configured
850 * @assert_flag: Flag stating should reset be asserted (1) or
853 * Return: Returns status, either success or error+reason
855 int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
856 const enum zynqmp_pm_reset_action assert_flag)
858 return zynqmp_pm_invoke_fn(PM_RESET_ASSERT, reset, assert_flag,
861 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_assert);
864 * zynqmp_pm_reset_get_status - Get status of the reset
865 * @reset: Reset whose status should be returned
866 * @status: Returned status
868 * Return: Returns status, either success or error+reason
870 int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset, u32 *status)
872 u32 ret_payload[PAYLOAD_ARG_CNT];
878 ret = zynqmp_pm_invoke_fn(PM_RESET_GET_STATUS, reset, 0,
880 *status = ret_payload[1];
884 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_get_status);
887 * zynqmp_pm_fpga_load - Perform the fpga load
888 * @address: Address to write to
889 * @size: pl bitstream size
890 * @flags: Bitstream type
891 * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
892 * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
894 * This function provides access to pmufw. To transfer
895 * the required bitstream into PL.
897 * Return: Returns status, either success or error+reason
899 int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags)
901 return zynqmp_pm_invoke_fn(PM_FPGA_LOAD, lower_32_bits(address),
902 upper_32_bits(address), size, flags, NULL);
904 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load);
907 * zynqmp_pm_fpga_get_status - Read value from PCAP status register
908 * @value: Value to read
910 * This function provides access to the pmufw to get the PCAP
913 * Return: Returns status, either success or error+reason
915 int zynqmp_pm_fpga_get_status(u32 *value)
917 u32 ret_payload[PAYLOAD_ARG_CNT];
923 ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, 0, 0, 0, 0, ret_payload);
924 *value = ret_payload[1];
928 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
931 * zynqmp_pm_pinctrl_request - Request Pin from firmware
932 * @pin: Pin number to request
934 * This function requests pin from firmware.
936 * Return: Returns status, either success or error+reason.
938 int zynqmp_pm_pinctrl_request(const u32 pin)
940 return zynqmp_pm_invoke_fn(PM_PINCTRL_REQUEST, pin, 0, 0, 0, NULL);
942 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_request);
945 * zynqmp_pm_pinctrl_release - Inform firmware that Pin control is released
946 * @pin: Pin number to release
948 * This function release pin from firmware.
950 * Return: Returns status, either success or error+reason.
952 int zynqmp_pm_pinctrl_release(const u32 pin)
954 return zynqmp_pm_invoke_fn(PM_PINCTRL_RELEASE, pin, 0, 0, 0, NULL);
956 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_release);
959 * zynqmp_pm_pinctrl_get_function - Read function id set for the given pin
961 * @id: Buffer to store function ID
963 * This function provides the function currently set for the given pin.
965 * Return: Returns status, either success or error+reason
967 int zynqmp_pm_pinctrl_get_function(const u32 pin, u32 *id)
969 u32 ret_payload[PAYLOAD_ARG_CNT];
975 ret = zynqmp_pm_invoke_fn(PM_PINCTRL_GET_FUNCTION, pin, 0,
977 *id = ret_payload[1];
981 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_function);
984 * zynqmp_pm_pinctrl_set_function - Set requested function for the pin
986 * @id: Function ID to set
988 * This function sets requested function for the given pin.
990 * Return: Returns status, either success or error+reason.
992 int zynqmp_pm_pinctrl_set_function(const u32 pin, const u32 id)
994 return zynqmp_pm_invoke_fn(PM_PINCTRL_SET_FUNCTION, pin, id,
997 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_function);
1000 * zynqmp_pm_pinctrl_get_config - Get configuration parameter for the pin
1002 * @param: Parameter to get
1003 * @value: Buffer to store parameter value
1005 * This function gets requested configuration parameter for the given pin.
1007 * Return: Returns status, either success or error+reason.
1009 int zynqmp_pm_pinctrl_get_config(const u32 pin, const u32 param,
1012 u32 ret_payload[PAYLOAD_ARG_CNT];
1018 ret = zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_GET, pin, param,
1020 *value = ret_payload[1];
1024 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_get_config);
1027 * zynqmp_pm_pinctrl_set_config - Set configuration parameter for the pin
1029 * @param: Parameter to set
1030 * @value: Parameter value to set
1032 * This function sets requested configuration parameter for the given pin.
1034 * Return: Returns status, either success or error+reason.
1036 int zynqmp_pm_pinctrl_set_config(const u32 pin, const u32 param,
1039 return zynqmp_pm_invoke_fn(PM_PINCTRL_CONFIG_PARAM_SET, pin,
1040 param, value, 0, NULL);
1042 EXPORT_SYMBOL_GPL(zynqmp_pm_pinctrl_set_config);
1045 * zynqmp_pm_bootmode_read() - PM Config API for read bootpin status
1046 * @ps_mode: Returned output value of ps_mode
1048 * This API function is to be used for notify the power management controller
1049 * to read bootpin status.
1051 * Return: status, either success or error+reason
1053 unsigned int zynqmp_pm_bootmode_read(u32 *ps_mode)
1056 u32 ret_payload[PAYLOAD_ARG_CNT];
1058 ret = zynqmp_pm_invoke_fn(PM_MMIO_READ, CRL_APB_BOOT_PIN_CTRL, 0,
1061 *ps_mode = ret_payload[1];
1065 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_read);
1068 * zynqmp_pm_bootmode_write() - PM Config API for Configure bootpin
1069 * @ps_mode: Value to be written to the bootpin ctrl register
1071 * This API function is to be used for notify the power management controller
1072 * to configure bootpin.
1074 * Return: Returns status, either success or error+reason
1076 int zynqmp_pm_bootmode_write(u32 ps_mode)
1078 return zynqmp_pm_invoke_fn(PM_MMIO_WRITE, CRL_APB_BOOT_PIN_CTRL,
1079 CRL_APB_BOOTPIN_CTRL_MASK, ps_mode, 0, NULL);
1081 EXPORT_SYMBOL_GPL(zynqmp_pm_bootmode_write);
1084 * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
1085 * master has initialized its own power management
1087 * Return: Returns status, either success or error+reason
1089 * This API function is to be used for notify the power management controller
1090 * about the completed power management initialization.
1092 int zynqmp_pm_init_finalize(void)
1094 return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, 0, 0, 0, 0, NULL);
1096 EXPORT_SYMBOL_GPL(zynqmp_pm_init_finalize);
1099 * zynqmp_pm_set_suspend_mode() - Set system suspend mode
1100 * @mode: Mode to set for system suspend
1102 * This API function is used to set mode of system suspend.
1104 * Return: Returns status, either success or error+reason
1106 int zynqmp_pm_set_suspend_mode(u32 mode)
1108 return zynqmp_pm_invoke_fn(PM_SET_SUSPEND_MODE, mode, 0, 0, 0, NULL);
1110 EXPORT_SYMBOL_GPL(zynqmp_pm_set_suspend_mode);
1113 * zynqmp_pm_request_node() - Request a node with specific capabilities
1114 * @node: Node ID of the slave
1115 * @capabilities: Requested capabilities of the slave
1116 * @qos: Quality of service (not supported)
1117 * @ack: Flag to specify whether acknowledge is requested
1119 * This function is used by master to request particular node from firmware.
1120 * Every master must request node before using it.
1122 * Return: Returns status, either success or error+reason
1124 int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
1125 const u32 qos, const enum zynqmp_pm_request_ack ack)
1127 return zynqmp_pm_invoke_fn(PM_REQUEST_NODE, node, capabilities,
1130 EXPORT_SYMBOL_GPL(zynqmp_pm_request_node);
1133 * zynqmp_pm_release_node() - Release a node
1134 * @node: Node ID of the slave
1136 * This function is used by master to inform firmware that master
1137 * has released node. Once released, master must not use that node
1138 * without re-request.
1140 * Return: Returns status, either success or error+reason
1142 int zynqmp_pm_release_node(const u32 node)
1144 return zynqmp_pm_invoke_fn(PM_RELEASE_NODE, node, 0, 0, 0, NULL);
1146 EXPORT_SYMBOL_GPL(zynqmp_pm_release_node);
1149 * zynqmp_pm_set_requirement() - PM call to set requirement for PM slaves
1150 * @node: Node ID of the slave
1151 * @capabilities: Requested capabilities of the slave
1152 * @qos: Quality of service (not supported)
1153 * @ack: Flag to specify whether acknowledge is requested
1155 * This API function is to be used for slaves a PU already has requested
1156 * to change its capabilities.
1158 * Return: Returns status, either success or error+reason
1160 int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
1162 const enum zynqmp_pm_request_ack ack)
1164 return zynqmp_pm_invoke_fn(PM_SET_REQUIREMENT, node, capabilities,
1167 EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement);
1170 * zynqmp_pm_load_pdi - Load and process PDI
1171 * @src: Source device where PDI is located
1172 * @address: PDI src address
1174 * This function provides support to load PDI from linux
1176 * Return: Returns status, either success or error+reason
1178 int zynqmp_pm_load_pdi(const u32 src, const u64 address)
1180 return zynqmp_pm_invoke_fn(PM_LOAD_PDI, src,
1181 lower_32_bits(address),
1182 upper_32_bits(address), 0, NULL);
1184 EXPORT_SYMBOL_GPL(zynqmp_pm_load_pdi);
1187 * zynqmp_pm_aes_engine - Access AES hardware to encrypt/decrypt the data using
1189 * @address: Address of the AesParams structure.
1190 * @out: Returned output value
1192 * Return: Returns status, either success or error code.
1194 int zynqmp_pm_aes_engine(const u64 address, u32 *out)
1196 u32 ret_payload[PAYLOAD_ARG_CNT];
1202 ret = zynqmp_pm_invoke_fn(PM_SECURE_AES, upper_32_bits(address),
1203 lower_32_bits(address),
1205 *out = ret_payload[1];
1209 EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine);
1212 * zynqmp_pm_sha_hash - Access the SHA engine to calculate the hash
1213 * @address: Address of the data/ Address of output buffer where
1214 * hash should be stored.
1215 * @size: Size of the data.
1217 * BIT(0) - for initializing csudma driver and SHA3(Here address
1218 * and size inputs can be NULL).
1219 * BIT(1) - to call Sha3_Update API which can be called multiple
1220 * times when data is not contiguous.
1221 * BIT(2) - to get final hash of the whole updated data.
1222 * Hash will be overwritten at provided address with
1225 * Return: Returns status, either success or error code.
1227 int zynqmp_pm_sha_hash(const u64 address, const u32 size, const u32 flags)
1229 u32 lower_addr = lower_32_bits(address);
1230 u32 upper_addr = upper_32_bits(address);
1232 return zynqmp_pm_invoke_fn(PM_SECURE_SHA, upper_addr, lower_addr,
1235 EXPORT_SYMBOL_GPL(zynqmp_pm_sha_hash);
1238 * zynqmp_pm_register_notifier() - PM API for register a subsystem
1239 * to be notified about specific
1241 * @node: Node ID to which the event is related.
1242 * @event: Event Mask of Error events for which wants to get notified.
1243 * @wake: Wake subsystem upon capturing the event if value 1
1244 * @enable: Enable the registration for value 1, disable for value 0
1246 * This function is used to register/un-register for particular node-event
1247 * combination in firmware.
1249 * Return: Returns status, either success or error+reason
1252 int zynqmp_pm_register_notifier(const u32 node, const u32 event,
1253 const u32 wake, const u32 enable)
1255 return zynqmp_pm_invoke_fn(PM_REGISTER_NOTIFIER, node, event,
1256 wake, enable, NULL);
1258 EXPORT_SYMBOL_GPL(zynqmp_pm_register_notifier);
1261 * zynqmp_pm_system_shutdown - PM call to request a system shutdown or restart
1262 * @type: Shutdown or restart? 0 for shutdown, 1 for restart
1263 * @subtype: Specifies which system should be restarted or shut down
1265 * Return: Returns status, either success or error+reason
1267 int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype)
1269 return zynqmp_pm_invoke_fn(PM_SYSTEM_SHUTDOWN, type, subtype,
1274 * zynqmp_pm_set_feature_config - PM call to request IOCTL for feature config
1275 * @id: The config ID of the feature to be configured
1276 * @value: The config value of the feature to be configured
1278 * Return: Returns 0 on success or error value on failure.
1280 int zynqmp_pm_set_feature_config(enum pm_feature_config_id id, u32 value)
1282 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_FEATURE_CONFIG,
1287 * zynqmp_pm_get_feature_config - PM call to get value of configured feature
1288 * @id: The config id of the feature to be queried
1289 * @payload: Returned value array
1291 * Return: Returns 0 on success or error value on failure.
1293 int zynqmp_pm_get_feature_config(enum pm_feature_config_id id,
1296 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_FEATURE_CONFIG,
1301 * struct zynqmp_pm_shutdown_scope - Struct for shutdown scope
1302 * @subtype: Shutdown subtype
1303 * @name: Matching string for scope argument
1305 * This struct encapsulates mapping between shutdown scope ID and string.
1307 struct zynqmp_pm_shutdown_scope {
1308 const enum zynqmp_pm_shutdown_subtype subtype;
1312 static struct zynqmp_pm_shutdown_scope shutdown_scopes[] = {
1313 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM] = {
1314 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
1315 .name = "subsystem",
1317 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY] = {
1318 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
1321 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM] = {
1322 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
1327 static struct zynqmp_pm_shutdown_scope *selected_scope =
1328 &shutdown_scopes[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM];
1331 * zynqmp_pm_is_shutdown_scope_valid - Check if shutdown scope string is valid
1332 * @scope_string: Shutdown scope string
1334 * Return: Return pointer to matching shutdown scope struct from
1335 * array of available options in system if string is valid,
1336 * otherwise returns NULL.
1338 static struct zynqmp_pm_shutdown_scope*
1339 zynqmp_pm_is_shutdown_scope_valid(const char *scope_string)
1343 for (count = 0; count < ARRAY_SIZE(shutdown_scopes); count++)
1344 if (sysfs_streq(scope_string, shutdown_scopes[count].name))
1345 return &shutdown_scopes[count];
1350 static ssize_t shutdown_scope_show(struct device *device,
1351 struct device_attribute *attr,
1356 for (i = 0; i < ARRAY_SIZE(shutdown_scopes); i++) {
1357 if (&shutdown_scopes[i] == selected_scope) {
1359 strcat(buf, shutdown_scopes[i].name);
1362 strcat(buf, shutdown_scopes[i].name);
1371 static ssize_t shutdown_scope_store(struct device *device,
1372 struct device_attribute *attr,
1373 const char *buf, size_t count)
1376 struct zynqmp_pm_shutdown_scope *scope;
1378 scope = zynqmp_pm_is_shutdown_scope_valid(buf);
1382 ret = zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
1385 pr_err("unable to set shutdown scope %s\n", buf);
1389 selected_scope = scope;
1394 static DEVICE_ATTR_RW(shutdown_scope);
1396 static ssize_t health_status_store(struct device *device,
1397 struct device_attribute *attr,
1398 const char *buf, size_t count)
1403 ret = kstrtouint(buf, 10, &value);
1407 ret = zynqmp_pm_set_boot_health_status(value);
1409 dev_err(device, "unable to set healthy bit value to %u\n",
1417 static DEVICE_ATTR_WO(health_status);
1419 static ssize_t ggs_show(struct device *device,
1420 struct device_attribute *attr,
1425 u32 ret_payload[PAYLOAD_ARG_CNT];
1427 ret = zynqmp_pm_read_ggs(reg, ret_payload);
1431 return sprintf(buf, "0x%x\n", ret_payload[1]);
1434 static ssize_t ggs_store(struct device *device,
1435 struct device_attribute *attr,
1436 const char *buf, size_t count,
1442 if (reg >= GSS_NUM_REGS)
1445 ret = kstrtol(buf, 16, &value);
1451 ret = zynqmp_pm_write_ggs(reg, value);
1458 /* GGS register show functions */
1459 #define GGS0_SHOW(N) \
1460 ssize_t ggs##N##_show(struct device *device, \
1461 struct device_attribute *attr, \
1464 return ggs_show(device, attr, buf, N); \
1467 static GGS0_SHOW(0);
1468 static GGS0_SHOW(1);
1469 static GGS0_SHOW(2);
1470 static GGS0_SHOW(3);
1472 /* GGS register store function */
1473 #define GGS0_STORE(N) \
1474 ssize_t ggs##N##_store(struct device *device, \
1475 struct device_attribute *attr, \
1479 return ggs_store(device, attr, buf, count, N); \
1482 static GGS0_STORE(0);
1483 static GGS0_STORE(1);
1484 static GGS0_STORE(2);
1485 static GGS0_STORE(3);
1487 static ssize_t pggs_show(struct device *device,
1488 struct device_attribute *attr,
1493 u32 ret_payload[PAYLOAD_ARG_CNT];
1495 ret = zynqmp_pm_read_pggs(reg, ret_payload);
1499 return sprintf(buf, "0x%x\n", ret_payload[1]);
1502 static ssize_t pggs_store(struct device *device,
1503 struct device_attribute *attr,
1504 const char *buf, size_t count,
1510 if (reg >= GSS_NUM_REGS)
1513 ret = kstrtol(buf, 16, &value);
1519 ret = zynqmp_pm_write_pggs(reg, value);
1527 #define PGGS0_SHOW(N) \
1528 ssize_t pggs##N##_show(struct device *device, \
1529 struct device_attribute *attr, \
1532 return pggs_show(device, attr, buf, N); \
1535 #define PGGS0_STORE(N) \
1536 ssize_t pggs##N##_store(struct device *device, \
1537 struct device_attribute *attr, \
1541 return pggs_store(device, attr, buf, count, N); \
1544 /* PGGS register show functions */
1545 static PGGS0_SHOW(0);
1546 static PGGS0_SHOW(1);
1547 static PGGS0_SHOW(2);
1548 static PGGS0_SHOW(3);
1550 /* PGGS register store functions */
1551 static PGGS0_STORE(0);
1552 static PGGS0_STORE(1);
1553 static PGGS0_STORE(2);
1554 static PGGS0_STORE(3);
1556 /* GGS register attributes */
1557 static DEVICE_ATTR_RW(ggs0);
1558 static DEVICE_ATTR_RW(ggs1);
1559 static DEVICE_ATTR_RW(ggs2);
1560 static DEVICE_ATTR_RW(ggs3);
1562 /* PGGS register attributes */
1563 static DEVICE_ATTR_RW(pggs0);
1564 static DEVICE_ATTR_RW(pggs1);
1565 static DEVICE_ATTR_RW(pggs2);
1566 static DEVICE_ATTR_RW(pggs3);
1568 static ssize_t feature_config_id_show(struct device *device,
1569 struct device_attribute *attr,
1572 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1574 return sysfs_emit(buf, "%d\n", devinfo->feature_conf_id);
1577 static ssize_t feature_config_id_store(struct device *device,
1578 struct device_attribute *attr,
1579 const char *buf, size_t count)
1583 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1588 ret = kstrtou32(buf, 10, &config_id);
1592 devinfo->feature_conf_id = config_id;
1597 static DEVICE_ATTR_RW(feature_config_id);
1599 static ssize_t feature_config_value_show(struct device *device,
1600 struct device_attribute *attr,
1604 u32 ret_payload[PAYLOAD_ARG_CNT];
1605 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1607 ret = zynqmp_pm_get_feature_config(devinfo->feature_conf_id,
1612 return sysfs_emit(buf, "%d\n", ret_payload[1]);
1615 static ssize_t feature_config_value_store(struct device *device,
1616 struct device_attribute *attr,
1617 const char *buf, size_t count)
1621 struct zynqmp_devinfo *devinfo = dev_get_drvdata(device);
1626 ret = kstrtou32(buf, 10, &value);
1630 ret = zynqmp_pm_set_feature_config(devinfo->feature_conf_id,
1638 static DEVICE_ATTR_RW(feature_config_value);
1640 static struct attribute *zynqmp_firmware_attrs[] = {
1641 &dev_attr_ggs0.attr,
1642 &dev_attr_ggs1.attr,
1643 &dev_attr_ggs2.attr,
1644 &dev_attr_ggs3.attr,
1645 &dev_attr_pggs0.attr,
1646 &dev_attr_pggs1.attr,
1647 &dev_attr_pggs2.attr,
1648 &dev_attr_pggs3.attr,
1649 &dev_attr_shutdown_scope.attr,
1650 &dev_attr_health_status.attr,
1651 &dev_attr_feature_config_id.attr,
1652 &dev_attr_feature_config_value.attr,
1656 ATTRIBUTE_GROUPS(zynqmp_firmware);
1658 static int zynqmp_firmware_probe(struct platform_device *pdev)
1660 struct device *dev = &pdev->dev;
1661 struct device_node *np;
1662 struct zynqmp_devinfo *devinfo;
1665 ret = get_set_conduit_method(dev->of_node);
1669 np = of_find_compatible_node(NULL, NULL, "xlnx,zynqmp");
1671 np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
1675 feature_check_enabled = true;
1678 if (!feature_check_enabled) {
1679 ret = do_feature_check_call(PM_FEATURE_CHECK);
1681 feature_check_enabled = true;
1686 devinfo = devm_kzalloc(dev, sizeof(*devinfo), GFP_KERNEL);
1692 platform_set_drvdata(pdev, devinfo);
1694 /* Check PM API version number */
1695 ret = zynqmp_pm_get_api_version(&pm_api_version);
1699 if (pm_api_version < ZYNQMP_PM_VERSION) {
1700 panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
1702 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
1703 pm_api_version >> 16, pm_api_version & 0xFFFF);
1706 pr_info("%s Platform Management API v%d.%d\n", __func__,
1707 pm_api_version >> 16, pm_api_version & 0xFFFF);
1709 /* Check trustzone version number */
1710 ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
1712 panic("Legacy trustzone found without version support\n");
1714 if (pm_tz_version < ZYNQMP_TZ_VERSION)
1715 panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
1717 ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
1718 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1720 pr_info("%s Trustzone version v%d.%d\n", __func__,
1721 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1723 ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
1724 ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
1726 dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
1730 zynqmp_pm_api_debugfs_init();
1732 np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
1734 em_dev = platform_device_register_data(&pdev->dev, "xlnx_event_manager",
1737 dev_err_probe(&pdev->dev, PTR_ERR(em_dev), "EM register fail with error\n");
1741 return of_platform_populate(dev->of_node, NULL, NULL, dev);
1744 static int zynqmp_firmware_remove(struct platform_device *pdev)
1746 struct pm_api_feature_data *feature_data;
1747 struct hlist_node *tmp;
1750 mfd_remove_devices(&pdev->dev);
1751 zynqmp_pm_api_debugfs_exit();
1753 hash_for_each_safe(pm_api_features_map, i, tmp, feature_data, hentry) {
1754 hash_del(&feature_data->hentry);
1755 kfree(feature_data);
1758 platform_device_unregister(em_dev);
1763 static const struct of_device_id zynqmp_firmware_of_match[] = {
1764 {.compatible = "xlnx,zynqmp-firmware"},
1765 {.compatible = "xlnx,versal-firmware"},
1768 MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
1770 static struct platform_driver zynqmp_firmware_driver = {
1772 .name = "zynqmp_firmware",
1773 .of_match_table = zynqmp_firmware_of_match,
1774 .dev_groups = zynqmp_firmware_groups,
1776 .probe = zynqmp_firmware_probe,
1777 .remove = zynqmp_firmware_remove,
1779 module_platform_driver(zynqmp_firmware_driver);