1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
* Copyright (C) 2017 Pengutronix, Lucas Stach <l.stach@pengutronix.de>
*
* Based on code from Carlo Caione <carlo@carlocaione.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <common.h>
#include <init.h>
#include <io.h>
#include <restart.h>
#include <mach/wd.h>
static void __iomem *wd_base;
#define RESET_TIMEOUT 10
static void __noreturn bcm2835_restart_soc(struct restart_handler *rst)
{
uint32_t rstc;
rstc = readl(wd_base + PM_RSTC);
rstc &= ~PM_RSTC_WRCFG_SET;
rstc |= PM_RSTC_WRCFG_FULL_RESET;
writel(PM_PASSWORD | RESET_TIMEOUT, wd_base + PM_WDOG);
writel(PM_PASSWORD | rstc, wd_base + PM_RSTC);
hang();
}
static int bcm2835_wd_probe(struct device_d *dev)
{
struct resource *iores;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores)) {
dev_err(dev, "could not get memory region\n");
return PTR_ERR(iores);
}
wd_base = IOMEM(iores->start);
restart_handler_register_fn(bcm2835_restart_soc);
return 0;
}
static __maybe_unused struct of_device_id bcm2835_wd_dt_ids[] = {
{
.compatible = "brcm,bcm2835-pm-wdt",
}, {
/* sentinel */
},
};
static struct driver_d bcm2835_wd_driver = {
.name = "bcm2835_wd",
.of_compatible = DRV_OF_COMPAT(bcm2835_wd_dt_ids),
.probe = bcm2835_wd_probe,
};
static int __init bcm2835_wd_init(void)
{
return platform_driver_register(&bcm2835_wd_driver);
}
device_initcall(bcm2835_wd_init);
|