]> git.ipfire.org Git - thirdparty/u-boot.git/blame - drivers/sysreset/sysreset_syscon.c
Merge branch 'master' of git://git.denx.de/u-boot-spi
[thirdparty/u-boot.git] / drivers / sysreset / sysreset_syscon.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
e3889691
ÁFR
2/*
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
4 *
5 * Derived from linux/drivers/power/reset/syscon-reboot.c:
6 * Copyright (C) 2013, Applied Micro Circuits Corporation
7 * Author: Feng Kan <fkan@apm.com>
e3889691
ÁFR
8 */
9
10#include <common.h>
11#include <dm.h>
12#include <errno.h>
13#include <regmap.h>
14#include <sysreset.h>
15#include <syscon.h>
16
e3889691
ÁFR
17struct syscon_reboot_priv {
18 struct regmap *regmap;
19 unsigned int offset;
20 unsigned int mask;
21};
22
23static int syscon_reboot_request(struct udevice *dev, enum sysreset_t type)
24{
25 struct syscon_reboot_priv *priv = dev_get_priv(dev);
26
27 regmap_write(priv->regmap, priv->offset, priv->mask);
28
29 return -EINPROGRESS;
30}
31
32static struct sysreset_ops syscon_reboot_ops = {
33 .request = syscon_reboot_request,
34};
35
36int syscon_reboot_probe(struct udevice *dev)
37{
e3889691 38 struct syscon_reboot_priv *priv = dev_get_priv(dev);
e3889691 39
662a74a2
PD
40 priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap");
41 if (IS_ERR(priv->regmap)) {
9b643e31 42 pr_err("unable to find regmap\n");
e3889691
ÁFR
43 return -ENODEV;
44 }
45
06069066
ÁFR
46 priv->offset = dev_read_u32_default(dev, "offset", 0);
47 priv->mask = dev_read_u32_default(dev, "mask", 0);
e3889691
ÁFR
48
49 return 0;
50}
51
52static const struct udevice_id syscon_reboot_ids[] = {
53 { .compatible = "syscon-reboot" },
54 { /* sentinel */ }
55};
56
57U_BOOT_DRIVER(syscon_reboot) = {
58 .name = "syscon_reboot",
59 .id = UCLASS_SYSRESET,
60 .of_match = syscon_reboot_ids,
61 .probe = syscon_reboot_probe,
62 .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv),
63 .ops = &syscon_reboot_ops,
64};