blob: bc0984e2d262038a9f6d0738311142e1b1c95374 [file] [log] [blame]
Vasileios Amoiridis639ff292024-11-05 14:27:44 +01001// 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
11static 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
22static 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
34U_BOOT_DRVINFO(bootcount_zynqmp) = {
35 .name = "bootcount_zynqmp",
36};
37
38static const struct bootcount_ops bootcount_zynqmp_ops = {
39 .get = bootcount_zynqmp_get,
40 .set = bootcount_zynqmp_set,
41};
42
43U_BOOT_DRIVER(bootcount_zynqmp) = {
44 .name = "bootcount_zynqmp",
45 .id = UCLASS_BOOTCOUNT,
46 .ops = &bootcount_zynqmp_ops,
47};