Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Xilinx Zynq MPSoC Firmware driver |
| 4 | * |
| 5 | * Copyright (C) 2018-2019 Xilinx, Inc. |
| 6 | */ |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 7 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 8 | #include <common.h> |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 11 | #if defined(CONFIG_ZYNQMP_IPI) |
| 12 | #include <mailbox.h> |
Ibai Erkiaga | c8a3efa | 2019-09-27 11:37:01 +0100 | [diff] [blame] | 13 | #include <zynqmp_firmware.h> |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 14 | #include <asm/arch/sys_proto.h> |
| 15 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 16 | #define PMUFW_PAYLOAD_ARG_CNT 8 |
| 17 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 18 | struct zynqmp_power { |
| 19 | struct mbox_chan tx_chan; |
| 20 | struct mbox_chan rx_chan; |
| 21 | } zynqmp_power; |
| 22 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 23 | static int ipi_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen) |
| 24 | { |
| 25 | struct zynqmp_ipi_msg msg; |
| 26 | int ret; |
| 27 | |
| 28 | if (req_len > PMUFW_PAYLOAD_ARG_CNT || |
| 29 | res_maxlen > PMUFW_PAYLOAD_ARG_CNT) |
| 30 | return -EINVAL; |
| 31 | |
| 32 | if (!(zynqmp_power.tx_chan.dev) || !(&zynqmp_power.rx_chan.dev)) |
| 33 | return -EINVAL; |
| 34 | |
| 35 | msg.buf = (u32 *)req; |
| 36 | msg.len = req_len; |
| 37 | ret = mbox_send(&zynqmp_power.tx_chan, &msg); |
| 38 | if (ret) { |
| 39 | debug("%s: Sending message failed\n", __func__); |
| 40 | return ret; |
| 41 | } |
| 42 | |
| 43 | msg.buf = res; |
| 44 | msg.len = res_maxlen; |
| 45 | ret = mbox_recv(&zynqmp_power.rx_chan, &msg, 100); |
| 46 | if (ret) |
| 47 | debug("%s: Receiving message failed\n", __func__); |
| 48 | |
| 49 | return ret; |
| 50 | } |
| 51 | |
Michal Simek | d9d98eb7 | 2019-09-27 14:08:41 +0200 | [diff] [blame^] | 52 | static int send_req(const u32 *req, size_t req_len, u32 *res, size_t res_maxlen) |
| 53 | { |
| 54 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 55 | return ipi_req(req, req_len, res, res_maxlen); |
| 56 | |
| 57 | return invoke_smc(req[0] + PM_SIP_SVC, 0, 0, 0, 0, res); |
| 58 | } |
| 59 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 60 | unsigned int zynqmp_firmware_version(void) |
| 61 | { |
| 62 | int ret; |
| 63 | u32 ret_payload[PAYLOAD_ARG_CNT]; |
| 64 | static u32 pm_api_version = ZYNQMP_PM_VERSION_INVALID; |
| 65 | |
| 66 | /* |
| 67 | * Get PMU version only once and later |
| 68 | * just return stored values instead of |
| 69 | * asking PMUFW again. |
| 70 | **/ |
| 71 | if (pm_api_version == ZYNQMP_PM_VERSION_INVALID) { |
Michal Simek | d9d98eb7 | 2019-09-27 14:08:41 +0200 | [diff] [blame^] | 72 | const u32 request[] = { PM_GET_API_VERSION }; |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 73 | |
Michal Simek | d9d98eb7 | 2019-09-27 14:08:41 +0200 | [diff] [blame^] | 74 | ret = send_req(request, ARRAY_SIZE(request), ret_payload, 2); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 75 | if (ret) |
| 76 | panic("PMUFW is not found - Please load it!\n"); |
| 77 | |
| 78 | pm_api_version = ret_payload[1]; |
| 79 | if (pm_api_version < ZYNQMP_PM_VERSION) |
| 80 | panic("PMUFW version error. Expected: v%d.%d\n", |
| 81 | ZYNQMP_PM_VERSION_MAJOR, ZYNQMP_PM_VERSION_MINOR); |
| 82 | } |
| 83 | |
| 84 | return pm_api_version; |
| 85 | }; |
| 86 | |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 87 | static int zynqmp_power_probe(struct udevice *dev) |
| 88 | { |
| 89 | int ret = 0; |
| 90 | |
| 91 | debug("%s, (dev=%p)\n", __func__, dev); |
| 92 | |
| 93 | ret = mbox_get_by_name(dev, "tx", &zynqmp_power.tx_chan); |
| 94 | if (ret) { |
| 95 | debug("%s, cannot tx mailbox\n", __func__); |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | ret = mbox_get_by_name(dev, "rx", &zynqmp_power.rx_chan); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 100 | if (ret) { |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 101 | debug("%s, cannot rx mailbox\n", __func__); |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 102 | return ret; |
| 103 | } |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 104 | |
Ibai Erkiaga | 99b2c28 | 2019-09-27 11:37:00 +0100 | [diff] [blame] | 105 | ret = zynqmp_firmware_version(); |
| 106 | printf("PMUFW:\tv%d.%d\n", |
| 107 | ret >> ZYNQMP_PM_VERSION_MAJOR_SHIFT, |
| 108 | ret & ZYNQMP_PM_VERSION_MINOR_MASK); |
| 109 | |
| 110 | return 0; |
Ibai Erkiaga | d47ed6f | 2019-09-27 12:51:41 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | static const struct udevice_id zynqmp_power_ids[] = { |
| 114 | { .compatible = "xlnx,zynqmp-power" }, |
| 115 | { } |
| 116 | }; |
| 117 | |
| 118 | U_BOOT_DRIVER(zynqmp_power) = { |
| 119 | .name = "zynqmp_power", |
| 120 | .id = UCLASS_FIRMWARE, |
| 121 | .of_match = zynqmp_power_ids, |
| 122 | .probe = zynqmp_power_probe, |
| 123 | }; |
| 124 | #endif |
| 125 | |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 126 | static const struct udevice_id zynqmp_firmware_ids[] = { |
| 127 | { .compatible = "xlnx,zynqmp-firmware" }, |
Siva Durga Prasad Paladugu | f7a7120 | 2019-06-23 12:24:57 +0530 | [diff] [blame] | 128 | { .compatible = "xlnx,versal-firmware"}, |
Rajan Vaja | 833be32 | 2019-02-15 04:45:32 -0800 | [diff] [blame] | 129 | { } |
| 130 | }; |
| 131 | |
| 132 | U_BOOT_DRIVER(zynqmp_firmware) = { |
| 133 | .id = UCLASS_FIRMWARE, |
| 134 | .name = "zynqmp-firmware", |
| 135 | .probe = dm_scan_fdt_dev, |
| 136 | .of_match = zynqmp_firmware_ids, |
| 137 | }; |