blob: 1028160247ac4171ca6f881702d48a1985798fa8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +02002/*
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>
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +02008 */
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
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020017struct 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
Patrick Delaunay9dd211e2019-04-18 17:16:21 +020027 if (type == SYSRESET_POWER)
28 return -EPROTONOSUPPORT;
29
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020030 regmap_write(priv->regmap, priv->offset, priv->mask);
31
32 return -EINPROGRESS;
33}
34
35static struct sysreset_ops syscon_reboot_ops = {
36 .request = syscon_reboot_request,
37};
38
39int syscon_reboot_probe(struct udevice *dev)
40{
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020041 struct syscon_reboot_priv *priv = dev_get_priv(dev);
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020042
Patrick Delaunaya48fc802019-03-07 09:57:14 +010043 priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap");
44 if (IS_ERR(priv->regmap)) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090045 pr_err("unable to find regmap\n");
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020046 return -ENODEV;
47 }
48
Álvaro Fernández Rojas4bc3e252018-03-17 12:22:24 +010049 priv->offset = dev_read_u32_default(dev, "offset", 0);
50 priv->mask = dev_read_u32_default(dev, "mask", 0);
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020051
52 return 0;
53}
54
55static const struct udevice_id syscon_reboot_ids[] = {
56 { .compatible = "syscon-reboot" },
57 { /* sentinel */ }
58};
59
60U_BOOT_DRIVER(syscon_reboot) = {
61 .name = "syscon_reboot",
62 .id = UCLASS_SYSRESET,
63 .of_match = syscon_reboot_ids,
64 .probe = syscon_reboot_probe,
65 .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv),
66 .ops = &syscon_reboot_ops,
67};