xref: /linux/drivers/firmware/xilinx/zynqmp.c (revision a6d5f9dca42eab3526e2f73aa5b7df2a5fec2c9d)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Xilinx Zynq MPSoC Firmware layer
4  *
5  *  Copyright (C) 2014-2018 Xilinx, Inc.
6  *
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>
11  */
12 
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>
19 #include <linux/of.h>
20 #include <linux/of_platform.h>
21 #include <linux/slab.h>
22 #include <linux/uaccess.h>
23 
24 #include <linux/firmware/xlnx-zynqmp.h>
25 #include "zynqmp-debug.h"
26 
27 static const struct zynqmp_eemi_ops *eemi_ops_tbl;
28 
29 static const struct mfd_cell firmware_devs[] = {
30 	{
31 		.name = "zynqmp_power_controller",
32 	},
33 };
34 
35 /**
36  * zynqmp_pm_ret_code() - Convert PMU-FW error codes to Linux error codes
37  * @ret_status:		PMUFW return code
38  *
39  * Return: corresponding Linux error code
40  */
41 static int zynqmp_pm_ret_code(u32 ret_status)
42 {
43 	switch (ret_status) {
44 	case XST_PM_SUCCESS:
45 	case XST_PM_DOUBLE_REQ:
46 		return 0;
47 	case XST_PM_NO_ACCESS:
48 		return -EACCES;
49 	case XST_PM_ABORT_SUSPEND:
50 		return -ECANCELED;
51 	case XST_PM_MULT_USER:
52 		return -EUSERS;
53 	case XST_PM_INTERNAL:
54 	case XST_PM_CONFLICT:
55 	case XST_PM_INVALID_NODE:
56 	default:
57 		return -EINVAL;
58 	}
59 }
60 
61 static noinline int do_fw_call_fail(u64 arg0, u64 arg1, u64 arg2,
62 				    u32 *ret_payload)
63 {
64 	return -ENODEV;
65 }
66 
67 /*
68  * PM function call wrapper
69  * Invoke do_fw_call_smc or do_fw_call_hvc, depending on the configuration
70  */
71 static int (*do_fw_call)(u64, u64, u64, u32 *ret_payload) = do_fw_call_fail;
72 
73 /**
74  * do_fw_call_smc() - Call system-level platform management layer (SMC)
75  * @arg0:		Argument 0 to SMC call
76  * @arg1:		Argument 1 to SMC call
77  * @arg2:		Argument 2 to SMC call
78  * @ret_payload:	Returned value array
79  *
80  * Invoke platform management function via SMC call (no hypervisor present).
81  *
82  * Return: Returns status, either success or error+reason
83  */
84 static noinline int do_fw_call_smc(u64 arg0, u64 arg1, u64 arg2,
85 				   u32 *ret_payload)
86 {
87 	struct arm_smccc_res res;
88 
89 	arm_smccc_smc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
90 
91 	if (ret_payload) {
92 		ret_payload[0] = lower_32_bits(res.a0);
93 		ret_payload[1] = upper_32_bits(res.a0);
94 		ret_payload[2] = lower_32_bits(res.a1);
95 		ret_payload[3] = upper_32_bits(res.a1);
96 	}
97 
98 	return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
99 }
100 
101 /**
102  * do_fw_call_hvc() - Call system-level platform management layer (HVC)
103  * @arg0:		Argument 0 to HVC call
104  * @arg1:		Argument 1 to HVC call
105  * @arg2:		Argument 2 to HVC call
106  * @ret_payload:	Returned value array
107  *
108  * Invoke platform management function via HVC
109  * HVC-based for communication through hypervisor
110  * (no direct communication with ATF).
111  *
112  * Return: Returns status, either success or error+reason
113  */
114 static noinline int do_fw_call_hvc(u64 arg0, u64 arg1, u64 arg2,
115 				   u32 *ret_payload)
116 {
117 	struct arm_smccc_res res;
118 
119 	arm_smccc_hvc(arg0, arg1, arg2, 0, 0, 0, 0, 0, &res);
120 
121 	if (ret_payload) {
122 		ret_payload[0] = lower_32_bits(res.a0);
123 		ret_payload[1] = upper_32_bits(res.a0);
124 		ret_payload[2] = lower_32_bits(res.a1);
125 		ret_payload[3] = upper_32_bits(res.a1);
126 	}
127 
128 	return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
129 }
130 
131 /**
132  * zynqmp_pm_invoke_fn() - Invoke the system-level platform management layer
133  *			   caller function depending on the configuration
134  * @pm_api_id:		Requested PM-API call
135  * @arg0:		Argument 0 to requested PM-API call
136  * @arg1:		Argument 1 to requested PM-API call
137  * @arg2:		Argument 2 to requested PM-API call
138  * @arg3:		Argument 3 to requested PM-API call
139  * @ret_payload:	Returned value array
140  *
141  * Invoke platform management function for SMC or HVC call, depending on
142  * configuration.
143  * Following SMC Calling Convention (SMCCC) for SMC64:
144  * Pm Function Identifier,
145  * PM_SIP_SVC + PM_API_ID =
146  *	((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT)
147  *	((SMC_64) << FUNCID_CC_SHIFT)
148  *	((SIP_START) << FUNCID_OEN_SHIFT)
149  *	((PM_API_ID) & FUNCID_NUM_MASK))
150  *
151  * PM_SIP_SVC	- Registered ZynqMP SIP Service Call.
152  * PM_API_ID	- Platform Management API ID.
153  *
154  * Return: Returns status, either success or error+reason
155  */
156 int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 arg0, u32 arg1,
157 			u32 arg2, u32 arg3, u32 *ret_payload)
158 {
159 	/*
160 	 * Added SIP service call Function Identifier
161 	 * Make sure to stay in x0 register
162 	 */
163 	u64 smc_arg[4];
164 
165 	smc_arg[0] = PM_SIP_SVC | pm_api_id;
166 	smc_arg[1] = ((u64)arg1 << 32) | arg0;
167 	smc_arg[2] = ((u64)arg3 << 32) | arg2;
168 
169 	return do_fw_call(smc_arg[0], smc_arg[1], smc_arg[2], ret_payload);
170 }
171 
172 static u32 pm_api_version;
173 static u32 pm_tz_version;
174 
175 /**
176  * zynqmp_pm_get_api_version() - Get version number of PMU PM firmware
177  * @version:	Returned version value
178  *
179  * Return: Returns status, either success or error+reason
180  */
181 static int zynqmp_pm_get_api_version(u32 *version)
182 {
183 	u32 ret_payload[PAYLOAD_ARG_CNT];
184 	int ret;
185 
186 	if (!version)
187 		return -EINVAL;
188 
189 	/* Check is PM API version already verified */
190 	if (pm_api_version > 0) {
191 		*version = pm_api_version;
192 		return 0;
193 	}
194 	ret = zynqmp_pm_invoke_fn(PM_GET_API_VERSION, 0, 0, 0, 0, ret_payload);
195 	*version = ret_payload[1];
196 
197 	return ret;
198 }
199 
200 /**
201  * zynqmp_pm_get_chipid - Get silicon ID registers
202  * @idcode:     IDCODE register
203  * @version:    version register
204  *
205  * Return:      Returns the status of the operation and the idcode and version
206  *              registers in @idcode and @version.
207  */
208 static int zynqmp_pm_get_chipid(u32 *idcode, u32 *version)
209 {
210 	u32 ret_payload[PAYLOAD_ARG_CNT];
211 	int ret;
212 
213 	if (!idcode || !version)
214 		return -EINVAL;
215 
216 	ret = zynqmp_pm_invoke_fn(PM_GET_CHIPID, 0, 0, 0, 0, ret_payload);
217 	*idcode = ret_payload[1];
218 	*version = ret_payload[2];
219 
220 	return ret;
221 }
222 
223 /**
224  * zynqmp_pm_get_trustzone_version() - Get secure trustzone firmware version
225  * @version:	Returned version value
226  *
227  * Return: Returns status, either success or error+reason
228  */
229 static int zynqmp_pm_get_trustzone_version(u32 *version)
230 {
231 	u32 ret_payload[PAYLOAD_ARG_CNT];
232 	int ret;
233 
234 	if (!version)
235 		return -EINVAL;
236 
237 	/* Check is PM trustzone version already verified */
238 	if (pm_tz_version > 0) {
239 		*version = pm_tz_version;
240 		return 0;
241 	}
242 	ret = zynqmp_pm_invoke_fn(PM_GET_TRUSTZONE_VERSION, 0, 0,
243 				  0, 0, ret_payload);
244 	*version = ret_payload[1];
245 
246 	return ret;
247 }
248 
249 /**
250  * get_set_conduit_method() - Choose SMC or HVC based communication
251  * @np:		Pointer to the device_node structure
252  *
253  * Use SMC or HVC-based functions to communicate with EL2/EL3.
254  *
255  * Return: Returns 0 on success or error code
256  */
257 static int get_set_conduit_method(struct device_node *np)
258 {
259 	const char *method;
260 
261 	if (of_property_read_string(np, "method", &method)) {
262 		pr_warn("%s missing \"method\" property\n", __func__);
263 		return -ENXIO;
264 	}
265 
266 	if (!strcmp("hvc", method)) {
267 		do_fw_call = do_fw_call_hvc;
268 	} else if (!strcmp("smc", method)) {
269 		do_fw_call = do_fw_call_smc;
270 	} else {
271 		pr_warn("%s Invalid \"method\" property: %s\n",
272 			__func__, method);
273 		return -EINVAL;
274 	}
275 
276 	return 0;
277 }
278 
279 /**
280  * zynqmp_pm_query_data() - Get query data from firmware
281  * @qdata:	Variable to the zynqmp_pm_query_data structure
282  * @out:	Returned output value
283  *
284  * Return: Returns status, either success or error+reason
285  */
286 static int zynqmp_pm_query_data(struct zynqmp_pm_query_data qdata, u32 *out)
287 {
288 	int ret;
289 
290 	ret = zynqmp_pm_invoke_fn(PM_QUERY_DATA, qdata.qid, qdata.arg1,
291 				  qdata.arg2, qdata.arg3, out);
292 
293 	/*
294 	 * For clock name query, all bytes in SMC response are clock name
295 	 * characters and return code is always success. For invalid clocks,
296 	 * clock name bytes would be zeros.
297 	 */
298 	return qdata.qid == PM_QID_CLOCK_GET_NAME ? 0 : ret;
299 }
300 
301 /**
302  * zynqmp_pm_clock_enable() - Enable the clock for given id
303  * @clock_id:	ID of the clock to be enabled
304  *
305  * This function is used by master to enable the clock
306  * including peripherals and PLL clocks.
307  *
308  * Return: Returns status, either success or error+reason
309  */
310 static int zynqmp_pm_clock_enable(u32 clock_id)
311 {
312 	return zynqmp_pm_invoke_fn(PM_CLOCK_ENABLE, clock_id, 0, 0, 0, NULL);
313 }
314 
315 /**
316  * zynqmp_pm_clock_disable() - Disable the clock for given id
317  * @clock_id:	ID of the clock to be disable
318  *
319  * This function is used by master to disable the clock
320  * including peripherals and PLL clocks.
321  *
322  * Return: Returns status, either success or error+reason
323  */
324 static int zynqmp_pm_clock_disable(u32 clock_id)
325 {
326 	return zynqmp_pm_invoke_fn(PM_CLOCK_DISABLE, clock_id, 0, 0, 0, NULL);
327 }
328 
329 /**
330  * zynqmp_pm_clock_getstate() - Get the clock state for given id
331  * @clock_id:	ID of the clock to be queried
332  * @state:	1/0 (Enabled/Disabled)
333  *
334  * This function is used by master to get the state of clock
335  * including peripherals and PLL clocks.
336  *
337  * Return: Returns status, either success or error+reason
338  */
339 static int zynqmp_pm_clock_getstate(u32 clock_id, u32 *state)
340 {
341 	u32 ret_payload[PAYLOAD_ARG_CNT];
342 	int ret;
343 
344 	ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETSTATE, clock_id, 0,
345 				  0, 0, ret_payload);
346 	*state = ret_payload[1];
347 
348 	return ret;
349 }
350 
351 /**
352  * zynqmp_pm_clock_setdivider() - Set the clock divider for given id
353  * @clock_id:	ID of the clock
354  * @divider:	divider value
355  *
356  * This function is used by master to set divider for any clock
357  * to achieve desired rate.
358  *
359  * Return: Returns status, either success or error+reason
360  */
361 static int zynqmp_pm_clock_setdivider(u32 clock_id, u32 divider)
362 {
363 	return zynqmp_pm_invoke_fn(PM_CLOCK_SETDIVIDER, clock_id, divider,
364 				   0, 0, NULL);
365 }
366 
367 /**
368  * zynqmp_pm_clock_getdivider() - Get the clock divider for given id
369  * @clock_id:	ID of the clock
370  * @divider:	divider value
371  *
372  * This function is used by master to get divider values
373  * for any clock.
374  *
375  * Return: Returns status, either success or error+reason
376  */
377 static int zynqmp_pm_clock_getdivider(u32 clock_id, u32 *divider)
378 {
379 	u32 ret_payload[PAYLOAD_ARG_CNT];
380 	int ret;
381 
382 	ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETDIVIDER, clock_id, 0,
383 				  0, 0, ret_payload);
384 	*divider = ret_payload[1];
385 
386 	return ret;
387 }
388 
389 /**
390  * zynqmp_pm_clock_setrate() - Set the clock rate for given id
391  * @clock_id:	ID of the clock
392  * @rate:	rate value in hz
393  *
394  * This function is used by master to set rate for any clock.
395  *
396  * Return: Returns status, either success or error+reason
397  */
398 static int zynqmp_pm_clock_setrate(u32 clock_id, u64 rate)
399 {
400 	return zynqmp_pm_invoke_fn(PM_CLOCK_SETRATE, clock_id,
401 				   lower_32_bits(rate),
402 				   upper_32_bits(rate),
403 				   0, NULL);
404 }
405 
406 /**
407  * zynqmp_pm_clock_getrate() - Get the clock rate for given id
408  * @clock_id:	ID of the clock
409  * @rate:	rate value in hz
410  *
411  * This function is used by master to get rate
412  * for any clock.
413  *
414  * Return: Returns status, either success or error+reason
415  */
416 static int zynqmp_pm_clock_getrate(u32 clock_id, u64 *rate)
417 {
418 	u32 ret_payload[PAYLOAD_ARG_CNT];
419 	int ret;
420 
421 	ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETRATE, clock_id, 0,
422 				  0, 0, ret_payload);
423 	*rate = ((u64)ret_payload[2] << 32) | ret_payload[1];
424 
425 	return ret;
426 }
427 
428 /**
429  * zynqmp_pm_clock_setparent() - Set the clock parent for given id
430  * @clock_id:	ID of the clock
431  * @parent_id:	parent id
432  *
433  * This function is used by master to set parent for any clock.
434  *
435  * Return: Returns status, either success or error+reason
436  */
437 static int zynqmp_pm_clock_setparent(u32 clock_id, u32 parent_id)
438 {
439 	return zynqmp_pm_invoke_fn(PM_CLOCK_SETPARENT, clock_id,
440 				   parent_id, 0, 0, NULL);
441 }
442 
443 /**
444  * zynqmp_pm_clock_getparent() - Get the clock parent for given id
445  * @clock_id:	ID of the clock
446  * @parent_id:	parent id
447  *
448  * This function is used by master to get parent index
449  * for any clock.
450  *
451  * Return: Returns status, either success or error+reason
452  */
453 static int zynqmp_pm_clock_getparent(u32 clock_id, u32 *parent_id)
454 {
455 	u32 ret_payload[PAYLOAD_ARG_CNT];
456 	int ret;
457 
458 	ret = zynqmp_pm_invoke_fn(PM_CLOCK_GETPARENT, clock_id, 0,
459 				  0, 0, ret_payload);
460 	*parent_id = ret_payload[1];
461 
462 	return ret;
463 }
464 
465 /**
466  * zynqmp_is_valid_ioctl() - Check whether IOCTL ID is valid or not
467  * @ioctl_id:	IOCTL ID
468  *
469  * Return: 1 if IOCTL is valid else 0
470  */
471 static inline int zynqmp_is_valid_ioctl(u32 ioctl_id)
472 {
473 	switch (ioctl_id) {
474 	case IOCTL_SET_PLL_FRAC_MODE:
475 	case IOCTL_GET_PLL_FRAC_MODE:
476 	case IOCTL_SET_PLL_FRAC_DATA:
477 	case IOCTL_GET_PLL_FRAC_DATA:
478 		return 1;
479 	default:
480 		return 0;
481 	}
482 }
483 
484 /**
485  * zynqmp_pm_ioctl() - PM IOCTL API for device control and configs
486  * @node_id:	Node ID of the device
487  * @ioctl_id:	ID of the requested IOCTL
488  * @arg1:	Argument 1 to requested IOCTL call
489  * @arg2:	Argument 2 to requested IOCTL call
490  * @out:	Returned output value
491  *
492  * This function calls IOCTL to firmware for device control and configuration.
493  *
494  * Return: Returns status, either success or error+reason
495  */
496 static int zynqmp_pm_ioctl(u32 node_id, u32 ioctl_id, u32 arg1, u32 arg2,
497 			   u32 *out)
498 {
499 	if (!zynqmp_is_valid_ioctl(ioctl_id))
500 		return -EINVAL;
501 
502 	return zynqmp_pm_invoke_fn(PM_IOCTL, node_id, ioctl_id,
503 				   arg1, arg2, out);
504 }
505 
506 /**
507  * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
508  * @reset:		Reset to be configured
509  * @assert_flag:	Flag stating should reset be asserted (1) or
510  *			released (0)
511  *
512  * Return: Returns status, either success or error+reason
513  */
514 static int zynqmp_pm_reset_assert(const enum zynqmp_pm_reset reset,
515 				  const enum zynqmp_pm_reset_action assert_flag)
516 {
517 	return zynqmp_pm_invoke_fn(PM_RESET_ASSERT, reset, assert_flag,
518 				   0, 0, NULL);
519 }
520 
521 /**
522  * zynqmp_pm_reset_get_status - Get status of the reset
523  * @reset:      Reset whose status should be returned
524  * @status:     Returned status
525  *
526  * Return: Returns status, either success or error+reason
527  */
528 static int zynqmp_pm_reset_get_status(const enum zynqmp_pm_reset reset,
529 				      u32 *status)
530 {
531 	u32 ret_payload[PAYLOAD_ARG_CNT];
532 	int ret;
533 
534 	if (!status)
535 		return -EINVAL;
536 
537 	ret = zynqmp_pm_invoke_fn(PM_RESET_GET_STATUS, reset, 0,
538 				  0, 0, ret_payload);
539 	*status = ret_payload[1];
540 
541 	return ret;
542 }
543 
544 /**
545  * zynqmp_pm_fpga_load - Perform the fpga load
546  * @address:	Address to write to
547  * @size:	pl bitstream size
548  * @flags:	Bitstream type
549  *	-XILINX_ZYNQMP_PM_FPGA_FULL:  FPGA full reconfiguration
550  *	-XILINX_ZYNQMP_PM_FPGA_PARTIAL: FPGA partial reconfiguration
551  *
552  * This function provides access to pmufw. To transfer
553  * the required bitstream into PL.
554  *
555  * Return: Returns status, either success or error+reason
556  */
557 static int zynqmp_pm_fpga_load(const u64 address, const u32 size,
558 			       const u32 flags)
559 {
560 	return zynqmp_pm_invoke_fn(PM_FPGA_LOAD, lower_32_bits(address),
561 				   upper_32_bits(address), size, flags, NULL);
562 }
563 
564 /**
565  * zynqmp_pm_fpga_get_status - Read value from PCAP status register
566  * @value: Value to read
567  *
568  * This function provides access to the pmufw to get the PCAP
569  * status
570  *
571  * Return: Returns status, either success or error+reason
572  */
573 static int zynqmp_pm_fpga_get_status(u32 *value)
574 {
575 	u32 ret_payload[PAYLOAD_ARG_CNT];
576 	int ret;
577 
578 	if (!value)
579 		return -EINVAL;
580 
581 	ret = zynqmp_pm_invoke_fn(PM_FPGA_GET_STATUS, 0, 0, 0, 0, ret_payload);
582 	*value = ret_payload[1];
583 
584 	return ret;
585 }
586 
587 /**
588  * zynqmp_pm_init_finalize() - PM call to inform firmware that the caller
589  *			       master has initialized its own power management
590  *
591  * This API function is to be used for notify the power management controller
592  * about the completed power management initialization.
593  *
594  * Return: Returns status, either success or error+reason
595  */
596 static int zynqmp_pm_init_finalize(void)
597 {
598 	return zynqmp_pm_invoke_fn(PM_PM_INIT_FINALIZE, 0, 0, 0, 0, NULL);
599 }
600 
601 /**
602  * zynqmp_pm_set_suspend_mode()	- Set system suspend mode
603  * @mode:	Mode to set for system suspend
604  *
605  * This API function is used to set mode of system suspend.
606  *
607  * Return: Returns status, either success or error+reason
608  */
609 static int zynqmp_pm_set_suspend_mode(u32 mode)
610 {
611 	return zynqmp_pm_invoke_fn(PM_SET_SUSPEND_MODE, mode, 0, 0, 0, NULL);
612 }
613 
614 /**
615  * zynqmp_pm_request_node() - Request a node with specific capabilities
616  * @node:		Node ID of the slave
617  * @capabilities:	Requested capabilities of the slave
618  * @qos:		Quality of service (not supported)
619  * @ack:		Flag to specify whether acknowledge is requested
620  *
621  * This function is used by master to request particular node from firmware.
622  * Every master must request node before using it.
623  *
624  * Return: Returns status, either success or error+reason
625  */
626 static int zynqmp_pm_request_node(const u32 node, const u32 capabilities,
627 				  const u32 qos,
628 				  const enum zynqmp_pm_request_ack ack)
629 {
630 	return zynqmp_pm_invoke_fn(PM_REQUEST_NODE, node, capabilities,
631 				   qos, ack, NULL);
632 }
633 
634 /**
635  * zynqmp_pm_release_node() - Release a node
636  * @node:	Node ID of the slave
637  *
638  * This function is used by master to inform firmware that master
639  * has released node. Once released, master must not use that node
640  * without re-request.
641  *
642  * Return: Returns status, either success or error+reason
643  */
644 static int zynqmp_pm_release_node(const u32 node)
645 {
646 	return zynqmp_pm_invoke_fn(PM_RELEASE_NODE, node, 0, 0, 0, NULL);
647 }
648 
649 /**
650  * zynqmp_pm_set_requirement() - PM call to set requirement for PM slaves
651  * @node:		Node ID of the slave
652  * @capabilities:	Requested capabilities of the slave
653  * @qos:		Quality of service (not supported)
654  * @ack:		Flag to specify whether acknowledge is requested
655  *
656  * This API function is to be used for slaves a PU already has requested
657  * to change its capabilities.
658  *
659  * Return: Returns status, either success or error+reason
660  */
661 static int zynqmp_pm_set_requirement(const u32 node, const u32 capabilities,
662 				     const u32 qos,
663 				     const enum zynqmp_pm_request_ack ack)
664 {
665 	return zynqmp_pm_invoke_fn(PM_SET_REQUIREMENT, node, capabilities,
666 				   qos, ack, NULL);
667 }
668 
669 static const struct zynqmp_eemi_ops eemi_ops = {
670 	.get_api_version = zynqmp_pm_get_api_version,
671 	.get_chipid = zynqmp_pm_get_chipid,
672 	.query_data = zynqmp_pm_query_data,
673 	.clock_enable = zynqmp_pm_clock_enable,
674 	.clock_disable = zynqmp_pm_clock_disable,
675 	.clock_getstate = zynqmp_pm_clock_getstate,
676 	.clock_setdivider = zynqmp_pm_clock_setdivider,
677 	.clock_getdivider = zynqmp_pm_clock_getdivider,
678 	.clock_setrate = zynqmp_pm_clock_setrate,
679 	.clock_getrate = zynqmp_pm_clock_getrate,
680 	.clock_setparent = zynqmp_pm_clock_setparent,
681 	.clock_getparent = zynqmp_pm_clock_getparent,
682 	.ioctl = zynqmp_pm_ioctl,
683 	.reset_assert = zynqmp_pm_reset_assert,
684 	.reset_get_status = zynqmp_pm_reset_get_status,
685 	.init_finalize = zynqmp_pm_init_finalize,
686 	.set_suspend_mode = zynqmp_pm_set_suspend_mode,
687 	.request_node = zynqmp_pm_request_node,
688 	.release_node = zynqmp_pm_release_node,
689 	.set_requirement = zynqmp_pm_set_requirement,
690 	.fpga_load = zynqmp_pm_fpga_load,
691 	.fpga_get_status = zynqmp_pm_fpga_get_status,
692 };
693 
694 /**
695  * zynqmp_pm_get_eemi_ops - Get eemi ops functions
696  *
697  * Return: Pointer of eemi_ops structure
698  */
699 const struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
700 {
701 	if (eemi_ops_tbl)
702 		return eemi_ops_tbl;
703 	else
704 		return ERR_PTR(-EPROBE_DEFER);
705 
706 }
707 EXPORT_SYMBOL_GPL(zynqmp_pm_get_eemi_ops);
708 
709 static int zynqmp_firmware_probe(struct platform_device *pdev)
710 {
711 	struct device *dev = &pdev->dev;
712 	struct device_node *np;
713 	int ret;
714 
715 	np = of_find_compatible_node(NULL, NULL, "xlnx,zynqmp");
716 	if (!np) {
717 		np = of_find_compatible_node(NULL, NULL, "xlnx,versal");
718 		if (!np)
719 			return 0;
720 	}
721 	of_node_put(np);
722 
723 	ret = get_set_conduit_method(dev->of_node);
724 	if (ret)
725 		return ret;
726 
727 	/* Check PM API version number */
728 	zynqmp_pm_get_api_version(&pm_api_version);
729 	if (pm_api_version < ZYNQMP_PM_VERSION) {
730 		panic("%s Platform Management API version error. Expected: v%d.%d - Found: v%d.%d\n",
731 		      __func__,
732 		      ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR,
733 		      pm_api_version >> 16, pm_api_version & 0xFFFF);
734 	}
735 
736 	pr_info("%s Platform Management API v%d.%d\n", __func__,
737 		pm_api_version >> 16, pm_api_version & 0xFFFF);
738 
739 	/* Check trustzone version number */
740 	ret = zynqmp_pm_get_trustzone_version(&pm_tz_version);
741 	if (ret)
742 		panic("Legacy trustzone found without version support\n");
743 
744 	if (pm_tz_version < ZYNQMP_TZ_VERSION)
745 		panic("%s Trustzone version error. Expected: v%d.%d - Found: v%d.%d\n",
746 		      __func__,
747 		      ZYNQMP_TZ_VERSION_MAJOR, ZYNQMP_TZ_VERSION_MINOR,
748 		      pm_tz_version >> 16, pm_tz_version & 0xFFFF);
749 
750 	pr_info("%s Trustzone version v%d.%d\n", __func__,
751 		pm_tz_version >> 16, pm_tz_version & 0xFFFF);
752 
753 	/* Assign eemi_ops_table */
754 	eemi_ops_tbl = &eemi_ops;
755 
756 	zynqmp_pm_api_debugfs_init();
757 
758 	ret = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, firmware_devs,
759 			      ARRAY_SIZE(firmware_devs), NULL, 0, NULL);
760 	if (ret) {
761 		dev_err(&pdev->dev, "failed to add MFD devices %d\n", ret);
762 		return ret;
763 	}
764 
765 	return of_platform_populate(dev->of_node, NULL, NULL, dev);
766 }
767 
768 static int zynqmp_firmware_remove(struct platform_device *pdev)
769 {
770 	mfd_remove_devices(&pdev->dev);
771 	zynqmp_pm_api_debugfs_exit();
772 
773 	return 0;
774 }
775 
776 static const struct of_device_id zynqmp_firmware_of_match[] = {
777 	{.compatible = "xlnx,zynqmp-firmware"},
778 	{.compatible = "xlnx,versal-firmware"},
779 	{},
780 };
781 MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
782 
783 static struct platform_driver zynqmp_firmware_driver = {
784 	.driver = {
785 		.name = "zynqmp_firmware",
786 		.of_match_table = zynqmp_firmware_of_match,
787 	},
788 	.probe = zynqmp_firmware_probe,
789 	.remove = zynqmp_firmware_remove,
790 };
791 module_platform_driver(zynqmp_firmware_driver);
792