1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
11 int dm_bootcount_get(struct udevice *dev, u32 *bootcount)
13 struct bootcount_ops *ops = bootcount_get_ops(dev);
18 return ops->get(dev, bootcount);
21 int dm_bootcount_set(struct udevice *dev, const u32 bootcount)
23 struct bootcount_ops *ops = bootcount_get_ops(dev);
28 return ops->set(dev, bootcount);
31 /* Now implement the generic default functions */
32 void bootcount_store(ulong val)
34 struct udevice *dev = NULL;
36 const char *propname = "u-boot,bootcount-device";
40 * If there's a preferred bootcount device selected by the user (by
41 * setting '/chosen/u-boot,bootcount-device' in the DTS), try to use
44 node = ofnode_get_chosen_node(propname);
45 if (ofnode_valid(node))
46 ret = uclass_get_device_by_ofnode(UCLASS_BOOTCOUNT, node, &dev);
48 /* If there was no user-selected device, use the first available one */
50 ret = uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev);
53 ret = dm_bootcount_set(dev, val);
56 pr_debug("%s: failed to store 0x%lx\n", __func__, val);
59 ulong bootcount_load(void)
61 struct udevice *dev = NULL;
63 const char *propname = "u-boot,bootcount-device";
68 * If there's a preferred bootcount device selected by the user (by
69 * setting '/chosen/u-boot,bootcount-device' in the DTS), try to use
72 node = ofnode_get_chosen_node(propname);
73 if (ofnode_valid(node))
74 ret = uclass_get_device_by_ofnode(UCLASS_BOOTCOUNT, node, &dev);
76 /* If there was no user-selected device, use the first available one */
78 ret = uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev);
81 ret = dm_bootcount_get(dev, &val);
84 pr_debug("%s: failed to load bootcount\n", __func__);
86 /* Return the 0, if the call to dm_bootcount_get failed */
90 UCLASS_DRIVER(bootcount) = {
92 .id = UCLASS_BOOTCOUNT,