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