blob: 3abce7f678679ac838476f77773eabefea9e9802 [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
18DECLARE_GLOBAL_DATA_PTR;
19
20struct syscon_reboot_priv {
21 struct regmap *regmap;
22 unsigned int offset;
23 unsigned int mask;
24};
25
26static int syscon_reboot_request(struct udevice *dev, enum sysreset_t type)
27{
28 struct syscon_reboot_priv *priv = dev_get_priv(dev);
29
30 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{
41 struct udevice *syscon;
42 struct syscon_reboot_priv *priv = dev_get_priv(dev);
43 int err;
44
45 err = uclass_get_device_by_phandle(UCLASS_SYSCON, dev,
46 "regmap", &syscon);
47 if (err) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090048 pr_err("unable to find syscon device\n");
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020049 return err;
50 }
51
52 priv->regmap = syscon_get_regmap(syscon);
53 if (!priv->regmap) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090054 pr_err("unable to find regmap\n");
Álvaro Fernández Rojasaa19aaf2017-04-25 00:39:14 +020055 return -ENODEV;
56 }
57
58 priv->offset = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
59 "offset", 0);
60 priv->mask = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
61 "mask", 0);
62
63 return 0;
64}
65
66static const struct udevice_id syscon_reboot_ids[] = {
67 { .compatible = "syscon-reboot" },
68 { /* sentinel */ }
69};
70
71U_BOOT_DRIVER(syscon_reboot) = {
72 .name = "syscon_reboot",
73 .id = UCLASS_SYSRESET,
74 .of_match = syscon_reboot_ids,
75 .probe = syscon_reboot_probe,
76 .priv_auto_alloc_size = sizeof(struct syscon_reboot_priv),
77 .ops = &syscon_reboot_ops,
78};