Coverage Report

Created: 2026-11-13 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/arch/sandbox/board/watchdog.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-only
2
3
#include <common.h>
4
#include <errno.h>
5
#include <driver.h>
6
#include <mach/linux.h>
7
#include <of.h>
8
#include <watchdog.h>
9
#include <linux/nvmem-consumer.h>
10
#include <asm/reset_source.h>
11
12
struct sandbox_watchdog {
13
  struct watchdog wdd;
14
  bool cant_disable :1;
15
  struct nvmem_cell *reset_source_cell;
16
};
17
18
static inline struct sandbox_watchdog *to_sandbox_watchdog(struct watchdog *wdd)
19
0
{
20
0
  return container_of(wdd, struct sandbox_watchdog, wdd);
21
0
}
22
23
static int sandbox_watchdog_set_timeout(struct watchdog *wdd, unsigned int timeout)
24
0
{
25
0
  struct sandbox_watchdog *wd = to_sandbox_watchdog(wdd);
26
27
0
  if (!timeout && wd->cant_disable)
28
0
    return -ENOSYS;
29
30
0
  if (timeout > wdd->timeout_max)
31
0
    return -EINVAL;
32
33
0
  sandbox_save_reset_source(wd->reset_source_cell, RESET_WDG);
34
35
0
  linux_watchdog_set_timeout(timeout);
36
0
  return 0;
37
0
}
38
39
static int sandbox_watchdog_probe(struct device *dev)
40
30
{
41
30
  struct device_node *np = dev->of_node;
42
30
  struct sandbox_watchdog *wd;
43
30
  struct watchdog *wdd;
44
45
30
  wd = xzalloc(sizeof(*wd));
46
47
30
  wdd = &wd->wdd;
48
30
  wdd->hwdev = dev;
49
30
  wdd->set_timeout = sandbox_watchdog_set_timeout;
50
30
  wdd->timeout_max = 1000;
51
52
30
  wd->reset_source_cell = of_nvmem_cell_get(np, "reset-source");
53
30
  if (IS_ERR(wd->reset_source_cell)) {
54
0
    if (PTR_ERR(wd->reset_source_cell) != -EPROBE_DEFER)
55
0
      dev_warn(dev, "No reset source info available: %pe\n",
56
0
         wd->reset_source_cell);
57
0
    wd->reset_source_cell = NULL;
58
0
  }
59
60
30
  wd->cant_disable = of_property_read_bool(np, "barebox,cant-disable");
61
62
30
  return watchdog_register(wdd);
63
30
}
64
65
66
static __maybe_unused struct of_device_id sandbox_watchdog_dt_ids[] = {
67
  { .compatible = "barebox,sandbox-watchdog" },
68
  { /* sentinel */ }
69
};
70
MODULE_DEVICE_TABLE(of, sandbox_watchdog_dt_ids);
71
72
static struct driver sandbox_watchdog_drv = {
73
  .name  = "sandbox-watchdog",
74
  .of_compatible = sandbox_watchdog_dt_ids,
75
  .probe = sandbox_watchdog_probe,
76
};
77
device_platform_driver(sandbox_watchdog_drv);