1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2018 Theobroma Systems Design und Consulting GmbH
12 int dm_bootcount_get(struct udevice *dev, u32 *bootcount)
14 struct bootcount_ops *ops = bootcount_get_ops(dev);
19 return ops->get(dev, bootcount);
22 int dm_bootcount_set(struct udevice *dev, const u32 bootcount)
24 struct bootcount_ops *ops = bootcount_get_ops(dev);
29 return ops->set(dev, bootcount);
32 /* Now implement the generic default functions */
33 void bootcount_store(ulong val)
35 struct udevice *dev = NULL;
37 const char *propname = "u-boot,bootcount-device";
41 * If there's a preferred bootcount device selected by the user (by
42 * setting '/chosen/u-boot,bootcount-device' in the DTS), try to use
45 node = ofnode_get_chosen_node(propname);
46 if (ofnode_valid(node))
47 ret = uclass_get_device_by_ofnode(UCLASS_BOOTCOUNT, node, &dev);
49 /* If there was no user-selected device, use the first available one */
51 ret = uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev);
54 ret = dm_bootcount_set(dev, val);
57 pr_debug("%s: failed to store 0x%lx\n", __func__, val);
60 ulong bootcount_load(void)
62 struct udevice *dev = NULL;
64 const char *propname = "u-boot,bootcount-device";
69 * If there's a preferred bootcount device selected by the user (by
70 * setting '/chosen/u-boot,bootcount-device' in the DTS), try to use
73 node = ofnode_get_chosen_node(propname);
74 if (ofnode_valid(node))
75 ret = uclass_get_device_by_ofnode(UCLASS_BOOTCOUNT, node, &dev);
77 /* If there was no user-selected device, use the first available one */
79 ret = uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev);
82 ret = dm_bootcount_get(dev, &val);
85 pr_debug("%s: failed to load bootcount\n", __func__);
87 /* Return the 0, if the call to dm_bootcount_get failed */
91 UCLASS_DRIVER(bootcount) = {
93 .id = UCLASS_BOOTCOUNT,