1 // SPDX-License-Identifier: GPL-2.0
3 * Xilinx Zynq MPSoC Firmware layer
5 * Copyright (C) 2014-2020 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/slab.h>
22 #include <linux/uaccess.h>
24 #include <linux/firmware/xlnx-zynqmp.h>
25 #include "zynqmp-debug.h"
27 static bool feature_check_enabled;
28 static u32 zynqmp_pm_features[PM_API_MAX];
30 static const struct mfd_cell firmware_devs[] = {
32 .name = "zynqmp_power_controller",
37 * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
38 * @ret_status: PMUFW return code
40 * Return: corresponding Linux error code
42 static int zynqmp_pm_ret_code(u32 ret_status)
46 case XST_PM_DOUBLE_REQ:
48 case XST_PM_NO_FEATURE:
50 case XST_PM_NO_ACCESS:
52 case XST_PM_ABORT_SUSPEND:
54 case XST_PM_MULT_USER:
58 case XST_PM_INVALID_NODE:
64 static noinline int do_fw_call_fail(u64 arg0, u64 arg1, u64 arg2,
71 * PM function call wrapper
72 * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
74 static int (*do_fw_call)(u64, u64, u64, u32 *ret_payload) = do_fw_call_fail;
77 * do_fw_call_smc() - Call system-level platform management layer (SMC)
78 * @arg0: Argument 0 to SMC call
79 * @arg1: Argument 1 to SMC call
80 * @arg2: Argument 2 to SMC call
81 * @ret_payload: Returned value array
83 * Invoke platform management function via SMC call (no hypervisor present).
85 * Return: Returns status, either success or error+reason
87 static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2,
90 struct arm_smccc_res res;
92 arm_smccc_smc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
95 ret_payload[0] = lower_32_bits(res.a0);
96 ret_payload[1] = upper_32_bits(res.a0);
97 ret_payload[2] = lower_32_bits(res.a1);
98 ret_payload[3] = upper_32_bits(res.a1);
101 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
105 * do_fw_call_hvc() - Call system-level platform management layer (HVC)
106 * @arg0: Argument 0 to HVC call
107 * @arg1: Argument 1 to HVC call
108 * @arg2: Argument 2 to HVC call
109 * @ret_payload: Returned value array
111 * Invoke platform management function via HVC
112 * HVC-based for communication through hypervisor
113 * (no direct communication with ATF).
115 * Return: Returns status, either success or error+reason
117 static noinline int do_fw_call_hvc(u64 arg0, u64 arg1, u64 arg2,
120 struct arm_smccc_res res;
122 arm_smccc_hvc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
125 ret_payload[0] = lower_32_bits(res.a0);
126 ret_payload[1] = upper_32_bits(res.a0);
127 ret_payload[2] = lower_32_bits(res.a1);
128 ret_payload[3] = upper_32_bits(res.a1);
131 return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
135 * zynqmp_pm_feature() - Check weather given feature is supported or not
136 * @api_id: API ID to check
138 * Return: Returns status, either success or error+reason
140 static int zynqmp_pm_feature(u32 api_id)
143 u32 ret_payload[PAYLOAD_ARG_CNT];
146 if (!feature_check_enabled)
149 /* Return value if feature is already checked */
150 if (zynqmp_pm_features[api_id] != PM_FEATURE_UNCHECKED)
151 return zynqmp_pm_features[api_id];
153 smc_arg[0] = PM_SIP_SVC | PM_FEATURE_CHECK;
156 ret = do_fw_call(smc_arg[0], smc_arg[1], 0, ret_payload);
158 zynqmp_pm_features[api_id] = PM_FEATURE_INVALID;
159 return PM_FEATURE_INVALID;
162 zynqmp_pm_features[api_id] = ret_payload[1];
164 return zynqmp_pm_features[api_id];
168 * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
169 * caller function depending on the configuration
170 * @pm_api_id: Requested PM-API call
171 * @arg0: Argument 0 to requested PM-API call
172 * @arg1: Argument 1 to requested PM-API call
173 * @arg2: Argument 2 to requested PM-API call
174 * @arg3: Argument 3 to requested PM-API call
175 * @ret_payload: Returned value array
177 * Invoke platform management function for SMC or HVC call, depending on
179 * Following SMC Calling Convention (SMCCC) for SMC64:
180 * Pm Function Identifier,
181 * PM_SIP_SVC + PM_API_ID =
182 * ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
183 * ((SMC_64) << FUNCID_CC_SHIFT)
184 * ((SIP_START) << FUNCID_OEN_SHIFT)
185 * ((PM_API_ID) & FUNCID_NUM_MASK))
187 * PM_SIP_SVC - Registered ZynqMP SIP Service Call.
188 * PM_API_ID - Platform Management API ID.
190 * Return: Returns status, either success or error+reason
192 int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
193 u32 arg2, u32 arg3, u32 *ret_payload)
196 * Added SIP service call Function Identifier
197 * Make sure to stay in x0 register
201 if (zynqmp_pm_feature(pm_api_id) == PM_FEATURE_INVALID)
204 smc_arg[0] = PM_SIP_SVC | pm_api_id;
205 smc_arg[1] = ((u64)arg1 << 32) | arg0;
206 smc_arg[2] = ((u64)arg3 << 32) | arg2;
208 return do_fw_call(smc_arg[0], smc_arg[1], smc_arg[2], ret_payload);
211 static u32 pm_api_version;
212 static u32 pm_tz_version;
215 * zynqmp_pm_get_api_version() - Get version number of PMU PM firmware
216 * @version: Returned version value
218 * Return: Returns status, either success or error+reason
220 int zynqmp_pm_get_api_version(u32 *version)
222 u32 ret_payload[PAYLOAD_ARG_CNT];
228 /* Check is PM API version already verified */
229 if (pm_api_version > 0) {
230 *version = pm_api_version;
233 ret = zynqmp_pm_invoke_fn(PM_GET_API_VERSION, 0, 0, 0, 0, ret_payload);
234 *version = ret_payload[1];
238 EXPORT_SYMBOL_GPL(zynqmp_pm_get_api_version);
241 * zynqmp_pm_get_chipid - Get silicon ID registers
242 * @idcode: IDCODE register
243 * @version: version register
245 * Return: Returns the status of the operation and the idcode and version
246 * registers in @idcode and @version.
248 int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
250 u32 ret_payload[PAYLOAD_ARG_CNT];
253 if (!idcode || !version)
256 ret = zynqmp_pm_invoke_fn(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
257 *idcode = ret_payload[1];
258 *version = ret_payload[2];
262 EXPORT_SYMBOL_GPL(zynqmp_pm_get_chipid);
265 * zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
266 * @version: Returned version value
268 * Return: Returns status, either success or error+reason
270 static int zynqmp_pm_get_trustzone_version(u32 *version)
272 u32 ret_payload[PAYLOAD_ARG_CNT];
278 /* Check is PM trustzone version already verified */
279 if (pm_tz_version > 0) {
280 *version = pm_tz_version;
283 ret = zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION, 0, 0,
285 *version = ret_payload[1];
291 * get_set_conduit_method() - Choose SMC or HVC based communication
292 * @np: Pointer to the device_node structure
294 * Use SMC or HVC-based functions to communicate with EL2/EL3.
296 * Return: Returns 0 on success or error code
298 static int get_set_conduit_method(struct device_node *np)
302 if (of_property_read_string(np, "method", &method)) {
303 pr_warn("%s missing \"method\" property\n", __func__);
307 if (!strcmp("hvc", method)) {
308 do_fw_call = do_fw_call_hvc;
309 } else if (!strcmp("smc", method)) {
310 do_fw_call = do_fw_call_smc;
312 pr_warn("%s Invalid \"method\" property: %s\n",
321 * zynqmp_pm_query_data() - Get query data from firmware
322 * @qdata: Variable to the zynqmp_pm_query_data structure
323 * @out: Returned output value
325 * Return: Returns status, either success or error+reason
327 int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out)
331 ret = zynqmp_pm_invoke_fn(PM_QUERY_DATA, qdata.qid, qdata.arg1,
332 qdata.arg2, qdata.arg3, out);
335 * For clock name query, all bytes in SMC response are clock name
336 * characters and return code is always success. For invalid clocks,
337 * clock name bytes would be zeros.
339 return qdata.qid == PM_QID_CLOCK_GET_NAME ? 0 : ret;
341 EXPORT_SYMBOL_GPL(zynqmp_pm_query_data);
344 * zynqmp_pm_clock_enable() - Enable the clock for given id
345 * @clock_id: ID of the clock to be enabled
347 * This function is used by master to enable the clock
348 * including peripherals and PLL clocks.
350 * Return: Returns status, either success or error+reason
352 int zynqmp_pm_clock_enable(u32 clock_id)
354 return zynqmp_pm_invoke_fn(PM_CLOCK_ENABLE, clock_id, 0, 0, 0, NULL);
356 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_enable);
359 * zynqmp_pm_clock_disable() - Disable the clock for given id
360 * @clock_id: ID of the clock to be disable
362 * This function is used by master to disable the clock
363 * including peripherals and PLL clocks.
365 * Return: Returns status, either success or error+reason
367 int zynqmp_pm_clock_disable(u32 clock_id)
369 return zynqmp_pm_invoke_fn(PM_CLOCK_DISABLE, clock_id, 0, 0, 0, NULL);
371 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_disable);
374 * zynqmp_pm_clock_getstate() - Get the clock state for given id
375 * @clock_id: ID of the clock to be queried
376 * @state: 1/0 (Enabled/Disabled)
378 * This function is used by master to get the state of clock
379 * including peripherals and PLL clocks.
381 * Return: Returns status, either success or error+reason
383 int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state)
385 u32 ret_payload[PAYLOAD_ARG_CNT];
388 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETSTATE, clock_id, 0,
390 *state = ret_payload[1];
394 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getstate);
397 * zynqmp_pm_clock_setdivider() - Set the clock divider for given id
398 * @clock_id: ID of the clock
399 * @divider: divider value
401 * This function is used by master to set divider for any clock
402 * to achieve desired rate.
404 * Return: Returns status, either success or error+reason
406 int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider)
408 return zynqmp_pm_invoke_fn(PM_CLOCK_SETDIVIDER, clock_id, divider,
411 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setdivider);
414 * zynqmp_pm_clock_getdivider() - Get the clock divider for given id
415 * @clock_id: ID of the clock
416 * @divider: divider value
418 * This function is used by master to get divider values
421 * Return: Returns status, either success or error+reason
423 int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider)
425 u32 ret_payload[PAYLOAD_ARG_CNT];
428 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETDIVIDER, clock_id, 0,
430 *divider = ret_payload[1];
434 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getdivider);
437 * zynqmp_pm_clock_setrate() - Set the clock rate for given id
438 * @clock_id: ID of the clock
439 * @rate: rate value in hz
441 * This function is used by master to set rate for any clock.
443 * Return: Returns status, either success or error+reason
445 int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate)
447 return zynqmp_pm_invoke_fn(PM_CLOCK_SETRATE, clock_id,
452 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setrate);
455 * zynqmp_pm_clock_getrate() - Get the clock rate for given id
456 * @clock_id: ID of the clock
457 * @rate: rate value in hz
459 * This function is used by master to get rate
462 * Return: Returns status, either success or error+reason
464 int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate)
466 u32 ret_payload[PAYLOAD_ARG_CNT];
469 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETRATE, clock_id, 0,
471 *rate = ((u64)ret_payload[2] << 32) | ret_payload[1];
475 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getrate);
478 * zynqmp_pm_clock_setparent() - Set the clock parent for given id
479 * @clock_id: ID of the clock
480 * @parent_id: parent id
482 * This function is used by master to set parent for any clock.
484 * Return: Returns status, either success or error+reason
486 int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id)
488 return zynqmp_pm_invoke_fn(PM_CLOCK_SETPARENT, clock_id,
489 parent_id, 0, 0, NULL);
491 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_setparent);
494 * zynqmp_pm_clock_getparent() - Get the clock parent for given id
495 * @clock_id: ID of the clock
496 * @parent_id: parent id
498 * This function is used by master to get parent index
501 * Return: Returns status, either success or error+reason
503 int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
505 u32 ret_payload[PAYLOAD_ARG_CNT];
508 ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETPARENT, clock_id, 0,
510 *parent_id = ret_payload[1];
514 EXPORT_SYMBOL_GPL(zynqmp_pm_clock_getparent);
517 * zynqmp_pm_set_pll_frac_mode() - PM API for set PLL mode
519 * @clk_id: PLL clock ID
520 * @mode: PLL mode (PLL_MODE_FRAC/PLL_MODE_INT)
522 * This function sets PLL mode
524 * Return: Returns status, either success or error+reason
526 int zynqmp_pm_set_pll_frac_mode(u32 clk_id, u32 mode)
528 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_MODE,
531 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_mode);
534 * zynqmp_pm_get_pll_frac_mode() - PM API for get PLL mode
536 * @clk_id: PLL clock ID
539 * This function return current PLL mode
541 * Return: Returns status, either success or error+reason
543 int zynqmp_pm_get_pll_frac_mode(u32 clk_id, u32 *mode)
545 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_MODE,
548 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_mode);
551 * zynqmp_pm_set_pll_frac_data() - PM API for setting pll fraction data
553 * @clk_id: PLL clock ID
554 * @data: fraction data
556 * This function sets fraction data.
557 * It is valid for fraction mode only.
559 * Return: Returns status, either success or error+reason
561 int zynqmp_pm_set_pll_frac_data(u32 clk_id, u32 data)
563 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_PLL_FRAC_DATA,
566 EXPORT_SYMBOL_GPL(zynqmp_pm_set_pll_frac_data);
569 * zynqmp_pm_get_pll_frac_data() - PM API for getting pll fraction data
571 * @clk_id: PLL clock ID
572 * @data: fraction data
574 * This function returns fraction data value.
576 * Return: Returns status, either success or error+reason
578 int zynqmp_pm_get_pll_frac_data(u32 clk_id, u32 *data)
580 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_GET_PLL_FRAC_DATA,
583 EXPORT_SYMBOL_GPL(zynqmp_pm_get_pll_frac_data);
586 * zynqmp_pm_set_sd_tapdelay() - Set tap delay for the SD device
588 * @node_id Node ID of the device
589 * @type Type of tap delay to set (input/output)
590 * @value Value to set fot the tap delay
592 * This function sets input/output tap delay for the SD device.
594 * @return Returns status, either success or error+reason
596 int zynqmp_pm_set_sd_tapdelay(u32 node_id, u32 type, u32 value)
598 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SET_SD_TAPDELAY,
601 EXPORT_SYMBOL_GPL(zynqmp_pm_set_sd_tapdelay);
604 * zynqmp_pm_sd_dll_reset() - Reset DLL logic
606 * @node_id Node ID of the device
609 * This function resets DLL logic for the SD device.
611 * @return Returns status, either success or error+reason
613 int zynqmp_pm_sd_dll_reset(u32 node_id, u32 type)
615 return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, IOCTL_SET_SD_TAPDELAY,
618 EXPORT_SYMBOL_GPL(zynqmp_pm_sd_dll_reset);
621 * zynqmp_pm_write_ggs() - PM API for writing global general storage (ggs)
622 * @index GGS register index
623 * @value Register value to be written
625 * This function writes value to GGS register.
627 * @return Returns status, either success or error+reason
629 int zynqmp_pm_write_ggs(u32 index, u32 value)
631 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_GGS,
634 EXPORT_SYMBOL_GPL(zynqmp_pm_write_ggs);
637 * zynqmp_pm_write_ggs() - PM API for reading global general storage (ggs)
638 * @index GGS register index
639 * @value Register value to be written
641 * This function returns GGS register value.
643 * @return Returns status, either success or error+reason
645 int zynqmp_pm_read_ggs(u32 index, u32 *value)
647 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_GGS,
650 EXPORT_SYMBOL_GPL(zynqmp_pm_read_ggs);
653 * zynqmp_pm_write_pggs() - PM API for writing persistent global general
655 * @index PGGS register index
656 * @value Register value to be written
658 * This function writes value to PGGS register.
660 * @return Returns status, either success or error+reason
662 int zynqmp_pm_write_pggs(u32 index, u32 value)
664 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_WRITE_PGGS, index, value,
667 EXPORT_SYMBOL_GPL(zynqmp_pm_write_pggs);
670 * zynqmp_pm_write_pggs() - PM API for reading persistent global general
672 * @index PGGS register index
673 * @value Register value to be written
675 * This function returns PGGS register value.
677 * @return Returns status, either success or error+reason
679 int zynqmp_pm_read_pggs(u32 index, u32 *value)
681 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_READ_PGGS, index, 0,
684 EXPORT_SYMBOL_GPL(zynqmp_pm_read_pggs);
687 * zynqmp_pm_set_boot_health_status() - PM API for setting healthy boot status
688 * @value Status value to be written
690 * This function sets healthy bit value to indicate boot health status
693 * @return Returns status, either success or error+reason
695 int zynqmp_pm_set_boot_health_status(u32 value)
697 return zynqmp_pm_invoke_fn(PM_IOCTL, 0, IOCTL_SET_BOOT_HEALTH_STATUS,
702 * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
703 * @reset: Reset to be configured
704 * @assert_flag: Flag stating should reset be asserted (1) or
707 * Return: Returns status, either success or error+reason
709 int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
710 const enum zynqmp_pm_reset_action assert_flag)
712 return zynqmp_pm_invoke_fn(PM_RESET_ASSERT, reset, assert_flag,
715 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_assert);
718 * zynqmp_pm_reset_get_status - Get status of the reset
719 * @reset: Reset whose status should be returned
720 * @status: Returned status
722 * Return: Returns status, either success or error+reason
724 int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset, u32 *status)
726 u32 ret_payload[PAYLOAD_ARG_CNT];
732 ret = zynqmp_pm_invoke_fn(PM_RESET_GET_STATUS, reset, 0,
734 *status = ret_payload[1];
738 EXPORT_SYMBOL_GPL(zynqmp_pm_reset_get_status);
741 * zynqmp_pm_fpga_load - Perform the fpga load
742 * @address: Address to write to
743 * @size: pl bitstream size
744 * @flags: Bitstream type
745 * -XILINX_ZYNQMP_PM_FPGA_FULL: FPGA full reconfiguration
746 * -XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
748 * This function provides access to pmufw. To transfer
749 * the required bitstream into PL.
751 * Return: Returns status, either success or error+reason
753 int zynqmp_pm_fpga_load(const u64 address, const u32 size, const u32 flags)
755 return zynqmp_pm_invoke_fn(PM_FPGA_LOAD, lower_32_bits(address),
756 upper_32_bits(address), size, flags, NULL);
758 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_load);
761 * zynqmp_pm_fpga_get_status - Read value from PCAP status register
762 * @value: Value to read
764 * This function provides access to the pmufw to get the PCAP
767 * Return: Returns status, either success or error+reason
769 int zynqmp_pm_fpga_get_status(u32 *value)
771 u32 ret_payload[PAYLOAD_ARG_CNT];
777 ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, 0, 0, 0, 0, ret_payload);
778 *value = ret_payload[1];
782 EXPORT_SYMBOL_GPL(zynqmp_pm_fpga_get_status);
785 * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
786 * master has initialized its own power management
788 * This API function is to be used for notify the power management controller
789 * about the completed power management initialization.
791 * Return: Returns status, either success or error+reason
793 int zynqmp_pm_init_finalize(void)
795 return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, 0, 0, 0, 0, NULL);
797 EXPORT_SYMBOL_GPL(zynqmp_pm_init_finalize);
800 * zynqmp_pm_set_suspend_mode() - Set system suspend mode
801 * @mode: Mode to set for system suspend
803 * This API function is used to set mode of system suspend.
805 * Return: Returns status, either success or error+reason
807 int zynqmp_pm_set_suspend_mode(u32 mode)
809 return zynqmp_pm_invoke_fn(PM_SET_SUSPEND_MODE, mode, 0, 0, 0, NULL);
811 EXPORT_SYMBOL_GPL(zynqmp_pm_set_suspend_mode);
814 * zynqmp_pm_request_node() - Request a node with specific capabilities
815 * @node: Node ID of the slave
816 * @capabilities: Requested capabilities of the slave
817 * @qos: Quality of service (not supported)
818 * @ack: Flag to specify whether acknowledge is requested
820 * This function is used by master to request particular node from firmware.
821 * Every master must request node before using it.
823 * Return: Returns status, either success or error+reason
825 int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
826 const u32 qos, const enum zynqmp_pm_request_ack ack)
828 return zynqmp_pm_invoke_fn(PM_REQUEST_NODE, node, capabilities,
831 EXPORT_SYMBOL_GPL(zynqmp_pm_request_node);
834 * zynqmp_pm_release_node() - Release a node
835 * @node: Node ID of the slave
837 * This function is used by master to inform firmware that master
838 * has released node. Once released, master must not use that node
839 * without re-request.
841 * Return: Returns status, either success or error+reason
843 int zynqmp_pm_release_node(const u32 node)
845 return zynqmp_pm_invoke_fn(PM_RELEASE_NODE, node, 0, 0, 0, NULL);
847 EXPORT_SYMBOL_GPL(zynqmp_pm_release_node);
850 * zynqmp_pm_set_requirement() - PM call to set requirement for PM slaves
851 * @node: Node ID of the slave
852 * @capabilities: Requested capabilities of the slave
853 * @qos: Quality of service (not supported)
854 * @ack: Flag to specify whether acknowledge is requested
856 * This API function is to be used for slaves a PU already has requested
857 * to change its capabilities.
859 * Return: Returns status, either success or error+reason
861 int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
863 const enum zynqmp_pm_request_ack ack)
865 return zynqmp_pm_invoke_fn(PM_SET_REQUIREMENT, node, capabilities,
868 EXPORT_SYMBOL_GPL(zynqmp_pm_set_requirement);
871 * zynqmp_pm_aes - Access AES hardware to encrypt/decrypt the data using
873 * @address: Address of the AesParams structure.
874 * @out: Returned output value
876 * Return: Returns status, either success or error code.
878 int zynqmp_pm_aes_engine(const u64 address, u32 *out)
880 u32 ret_payload[PAYLOAD_ARG_CNT];
886 ret = zynqmp_pm_invoke_fn(PM_SECURE_AES, upper_32_bits(address),
887 lower_32_bits(address),
889 *out = ret_payload[1];
893 EXPORT_SYMBOL_GPL(zynqmp_pm_aes_engine);
896 * zynqmp_pm_system_shutdown - PM call to request a system shutdown or restart
897 * @type: Shutdown or restart? 0 for shutdown, 1 for restart
898 * @subtype: Specifies which system should be restarted or shut down
900 * Return: Returns status, either success or error+reason
902 int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype)
904 return zynqmp_pm_invoke_fn(PM_SYSTEM_SHUTDOWN, type, subtype,
909 * struct zynqmp_pm_shutdown_scope - Struct for shutdown scope
910 * @subtype: Shutdown subtype
911 * @name: Matching string for scope argument
913 * This struct encapsulates mapping between shutdown scope ID and string.
915 struct zynqmp_pm_shutdown_scope {
916 const enum zynqmp_pm_shutdown_subtype subtype;
920 static struct zynqmp_pm_shutdown_scope shutdown_scopes[] = {
921 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM] = {
922 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SUBSYSTEM,
925 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY] = {
926 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_PS_ONLY,
929 [ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM] = {
930 .subtype = ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
935 static struct zynqmp_pm_shutdown_scope *selected_scope =
936 &shutdown_scopes[ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM];
939 * zynqmp_pm_is_shutdown_scope_valid - Check if shutdown scope string is valid
940 * @scope_string: Shutdown scope string
942 * Return: Return pointer to matching shutdown scope struct from
943 * array of available options in system if string is valid,
944 * otherwise returns NULL.
946 static struct zynqmp_pm_shutdown_scope*
947 zynqmp_pm_is_shutdown_scope_valid(const char *scope_string)
951 for (count = 0; count < ARRAY_SIZE(shutdown_scopes); count++)
952 if (sysfs_streq(scope_string, shutdown_scopes[count].name))
953 return &shutdown_scopes[count];
958 static ssize_t shutdown_scope_show(struct device *device,
959 struct device_attribute *attr,
964 for (i = 0; i < ARRAY_SIZE(shutdown_scopes); i++) {
965 if (&shutdown_scopes[i] == selected_scope) {
967 strcat(buf, shutdown_scopes[i].name);
970 strcat(buf, shutdown_scopes[i].name);
979 static ssize_t shutdown_scope_store(struct device *device,
980 struct device_attribute *attr,
981 const char *buf, size_t count)
984 struct zynqmp_pm_shutdown_scope *scope;
986 scope = zynqmp_pm_is_shutdown_scope_valid(buf);
990 ret = zynqmp_pm_system_shutdown(ZYNQMP_PM_SHUTDOWN_TYPE_SETSCOPE_ONLY,
993 pr_err("unable to set shutdown scope %s\n", buf);
997 selected_scope = scope;
1002 static DEVICE_ATTR_RW(shutdown_scope);
1004 static ssize_t health_status_store(struct device *device,
1005 struct device_attribute *attr,
1006 const char *buf, size_t count)
1011 ret = kstrtouint(buf, 10, &value);
1015 ret = zynqmp_pm_set_boot_health_status(value);
1017 dev_err(device, "unable to set healthy bit value to %u\n",
1025 static DEVICE_ATTR_WO(health_status);
1027 static ssize_t ggs_show(struct device *device,
1028 struct device_attribute *attr,
1033 u32 ret_payload[PAYLOAD_ARG_CNT];
1035 ret = zynqmp_pm_read_ggs(reg, ret_payload);
1039 return sprintf(buf, "0x%x\n", ret_payload[1]);
1042 static ssize_t ggs_store(struct device *device,
1043 struct device_attribute *attr,
1044 const char *buf, size_t count,
1050 if (reg >= GSS_NUM_REGS)
1053 ret = kstrtol(buf, 16, &value);
1059 ret = zynqmp_pm_write_ggs(reg, value);
1066 /* GGS register show functions */
1067 #define GGS0_SHOW(N) \
1068 ssize_t ggs##N##_show(struct device *device, \
1069 struct device_attribute *attr, \
1072 return ggs_show(device, attr, buf, N); \
1075 static GGS0_SHOW(0);
1076 static GGS0_SHOW(1);
1077 static GGS0_SHOW(2);
1078 static GGS0_SHOW(3);
1080 /* GGS register store function */
1081 #define GGS0_STORE(N) \
1082 ssize_t ggs##N##_store(struct device *device, \
1083 struct device_attribute *attr, \
1087 return ggs_store(device, attr, buf, count, N); \
1090 static GGS0_STORE(0);
1091 static GGS0_STORE(1);
1092 static GGS0_STORE(2);
1093 static GGS0_STORE(3);
1095 static ssize_t pggs_show(struct device *device,
1096 struct device_attribute *attr,
1101 u32 ret_payload[PAYLOAD_ARG_CNT];
1103 ret = zynqmp_pm_read_pggs(reg, ret_payload);
1107 return sprintf(buf, "0x%x\n", ret_payload[1]);
1110 static ssize_t pggs_store(struct device *device,
1111 struct device_attribute *attr,
1112 const char *buf, size_t count,
1118 if (reg >= GSS_NUM_REGS)
1121 ret = kstrtol(buf, 16, &value);
1127 ret = zynqmp_pm_write_pggs(reg, value);
1135 #define PGGS0_SHOW(N) \
1136 ssize_t pggs##N##_show(struct device *device, \
1137 struct device_attribute *attr, \
1140 return pggs_show(device, attr, buf, N); \
1143 #define PGGS0_STORE(N) \
1144 ssize_t pggs##N##_store(struct device *device, \
1145 struct device_attribute *attr, \
1149 return pggs_store(device, attr, buf, count, N); \
1152 /* PGGS register show functions */
1153 static PGGS0_SHOW(0);
1154 static PGGS0_SHOW(1);
1155 static PGGS0_SHOW(2);
1156 static PGGS0_SHOW(3);
1158 /* PGGS register store functions */
1159 static PGGS0_STORE(0);
1160 static PGGS0_STORE(1);
1161 static PGGS0_STORE(2);
1162 static PGGS0_STORE(3);
1164 /* GGS register attributes */
1165 static DEVICE_ATTR_RW(ggs0);
1166 static DEVICE_ATTR_RW(ggs1);
1167 static DEVICE_ATTR_RW(ggs2);
1168 static DEVICE_ATTR_RW(ggs3);
1170 /* PGGS register attributes */
1171 static DEVICE_ATTR_RW(pggs0);
1172 static DEVICE_ATTR_RW(pggs1);
1173 static DEVICE_ATTR_RW(pggs2);
1174 static DEVICE_ATTR_RW(pggs3);
1176 static struct attribute *zynqmp_firmware_attrs[] = {
1177 &dev_attr_ggs0.attr,
1178 &dev_attr_ggs1.attr,
1179 &dev_attr_ggs2.attr,
1180 &dev_attr_ggs3.attr,
1181 &dev_attr_pggs0.attr,
1182 &dev_attr_pggs1.attr,
1183 &dev_attr_pggs2.attr,
1184 &dev_attr_pggs3.attr,
1185 &dev_attr_shutdown_scope.attr,
1186 &dev_attr_health_status.attr,
1190 ATTRIBUTE_GROUPS(zynqmp_firmware);
1192 static int zynqmp_firmware_probe(struct platform_device *pdev)
1194 struct device *dev = &pdev->dev;
1195 struct device_node *np;
1198 np = of_find_compatible_node(NULL, NULL, "xlnx,zynqmp");
1200 np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
1204 feature_check_enabled = true;
1208 ret = get_set_conduit_method(dev->of_node);
1212 /* Check PM API version number */
1213 zynqmp_pm_get_api_version(&pm_api_version);
1214 if (pm_api_version < ZYNQMP_PM_VERSION) {
1215 panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
1217 ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
1218 pm_api_version >> 16, pm_api_version & 0xFFFF);
1221 pr_info("%s Platform Management API v%d.%d\n", __func__,
1222 pm_api_version >> 16, pm_api_version & 0xFFFF);
1224 /* Check trustzone version number */
1225 ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
1227 panic("Legacy trustzone found without version support\n");
1229 if (pm_tz_version < ZYNQMP_TZ_VERSION)
1230 panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
1232 ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
1233 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1235 pr_info("%s Trustzone version v%d.%d\n", __func__,
1236 pm_tz_version >> 16, pm_tz_version & 0xFFFF);
1238 ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
1239 ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
1241 dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
1245 zynqmp_pm_api_debugfs_init();
1247 return of_platform_populate(dev->of_node, NULL, NULL, dev);
1250 static int zynqmp_firmware_remove(struct platform_device *pdev)
1252 mfd_remove_devices(&pdev->dev);
1253 zynqmp_pm_api_debugfs_exit();
1258 static const struct of_device_id zynqmp_firmware_of_match[] = {
1259 {.compatible = "xlnx,zynqmp-firmware"},
1260 {.compatible = "xlnx,versal-firmware"},
1263 MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
1265 static struct platform_driver zynqmp_firmware_driver = {
1267 .name = "zynqmp_firmware",
1268 .of_match_table = zynqmp_firmware_of_match,
1269 .dev_groups = zynqmp_firmware_groups,
1271 .probe = zynqmp_firmware_probe,
1272 .remove = zynqmp_firmware_remove,
1274 module_platform_driver(zynqmp_firmware_driver);