blob: 22c602a4d2a73d50f60aae1e862e46fb19e44407 [file] [log] [blame]
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +02001/*
2 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
3 *
4 * Derived from linux/drivers/power/reset/syscon-reboot.c:
5 * Copyright (C) 2013, Applied Micro Circuits Corporation
6 * Author: Feng Kan <fkan@apm.com>
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 */
10
11#include <common.h>
12#include <dm.h>
13#include <errno.h>
14#include <regmap.h>
15#include <sysreset.h>
16#include <syscon.h>
17
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020018struct syscon_reboot_priv {
19 struct regmap *regmap;
20 unsigned int offset;
21 unsigned int mask;
22};
23
24static int syscon_reboot_request(struct udevice *dev, enum sysreset_t type)
25{
26 struct syscon_reboot_priv *priv = dev_get_priv(dev);
27
28 regmap_write(priv->regmap, priv->offset, priv->mask);
29
30 return -EINPROGRESS;
31}
32
33static struct sysreset_ops syscon_reboot_ops = {
34 .request = syscon_reboot_request,
35};
36
37int syscon_reboot_probe(struct udevice *dev)
38{
39 struct udevice *syscon;
40 struct syscon_reboot_priv *priv = dev_get_priv(dev);
41 int err;
42
43 err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
44 "regmap", &syscon);
45 if (err) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090046 pr_err("unable to find syscon device\n");
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020047 return err;
48 }
49
50 priv->regmap = syscon_get_regmap(syscon);
51 if (!priv->regmap) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090052 pr_err("unable to find regmap\n");
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020053 return -ENODEV;
54 }
55
Álvaro Fernández Rojas4bc3e252018-03-17 12:22:24 +010056 priv->offset = dev_read_u32_default(dev, "offset", 0);
57 priv->mask = dev_read_u32_default(dev, "mask", 0);
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020058
59 return 0;
60}
61
62static const struct udevice_id syscon_reboot_ids[] = {
63 { .compatible = "syscon-reboot" },
64 { /* sentinel */ }
65};
66
67U_BOOT_DRIVER(syscon_reboot) = {
68 .name = "syscon_reboot",
69 .id = UCLASS_SYSRESET,
70 .of_match = syscon_reboot_ids,
71 .probe = syscon_reboot_probe,
72 .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv),
73 .ops = &syscon_reboot_ops,
74};