Vasileios Amoiridis | 639ff29 | 2024-11-05 14:27:44 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // SPDX-FileCopyrightText: 2024 CERN (home.cern) |
| 3 | |
| 4 | #include <bootcount.h> |
| 5 | #include <dm.h> |
| 6 | #include <stdio.h> |
| 7 | #include <zynqmp_firmware.h> |
| 8 | #include <asm/arch/hardware.h> |
| 9 | #include <dm/platdata.h> |
| 10 | |
| 11 | static int bootcount_zynqmp_set(struct udevice *dev, const u32 val) |
| 12 | { |
| 13 | int ret; |
| 14 | |
| 15 | ret = zynqmp_mmio_write((ulong)&pmu_base->pers_gen_storage2, 0xFF, val); |
| 16 | if (ret) |
| 17 | pr_info("%s write fail\n", __func__); |
| 18 | |
| 19 | return ret; |
| 20 | } |
| 21 | |
| 22 | static int bootcount_zynqmp_get(struct udevice *dev, u32 *val) |
| 23 | { |
| 24 | int ret; |
| 25 | |
| 26 | *val = 0; |
| 27 | ret = zynqmp_mmio_read((ulong)&pmu_base->pers_gen_storage2, val); |
| 28 | if (ret) |
| 29 | pr_info("%s read fail\n", __func__); |
| 30 | |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | U_BOOT_DRVINFO(bootcount_zynqmp) = { |
| 35 | .name = "bootcount_zynqmp", |
| 36 | }; |
| 37 | |
| 38 | static const struct bootcount_ops bootcount_zynqmp_ops = { |
| 39 | .get = bootcount_zynqmp_get, |
| 40 | .set = bootcount_zynqmp_set, |
| 41 | }; |
| 42 | |
| 43 | U_BOOT_DRIVER(bootcount_zynqmp) = { |
| 44 | .name = "bootcount_zynqmp", |
| 45 | .id = UCLASS_BOOTCOUNT, |
| 46 | .ops = &bootcount_zynqmp_ops, |
| 47 | }; |