blob: 9996716f13d6016ebaa490352f3e7fd56b22d1f3 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Patrice Chotardb8f96fc2017-02-21 13:37:06 +01002/*
Patrice Chotard9e216242017-10-23 09:53:57 +02003 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
Patrice Chotardb8f96fc2017-02-21 13:37:06 +01005 */
6
7#include <common.h>
8#include <dm.h>
9#include <regmap.h>
10#include <syscon.h>
11#include <sysreset.h>
12#include <asm/io.h>
13
14DECLARE_GLOBAL_DATA_PTR;
15
16struct sti_sysreset_priv {
17 phys_addr_t base;
18};
19
20static int sti_sysreset_request(struct udevice *dev, enum sysreset_t type)
21{
22 struct sti_sysreset_priv *priv = dev_get_priv(dev);
23
24 generic_clear_bit(0, (void __iomem *)priv->base);
25
26 return -EINPROGRESS;
27}
28
29static int sti_sysreset_probe(struct udevice *dev)
30{
31 struct sti_sysreset_priv *priv = dev_get_priv(dev);
32 struct udevice *syscon;
33 struct regmap *regmap;
34 struct fdtdec_phandle_args syscfg_phandle;
35 int ret;
36
37 /* get corresponding syscon phandle */
38 ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
39 "st,syscfg", NULL, 0, 0,
40 &syscfg_phandle);
41 if (ret < 0) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090042 pr_err("Can't get syscfg phandle: %d\n", ret);
Patrice Chotardb8f96fc2017-02-21 13:37:06 +010043 return ret;
44 }
45
46 ret = uclass_get_device_by_of_offset(UCLASS_SYSCON,
47 syscfg_phandle.node,
48 &syscon);
49 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090050 pr_err("%s: uclass_get_device_by_of_offset failed: %d\n",
Patrice Chotardb8f96fc2017-02-21 13:37:06 +010051 __func__, ret);
52 return ret;
53 }
54
55 regmap = syscon_get_regmap(syscon);
56 if (!regmap) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090057 pr_err("unable to get regmap for %s\n", syscon->name);
Patrice Chotardb8f96fc2017-02-21 13:37:06 +010058 return -ENODEV;
59 }
60
Masahiro Yamada54c5ecb2018-04-19 12:14:01 +090061 priv->base = regmap->ranges[0].start;
Patrice Chotardb8f96fc2017-02-21 13:37:06 +010062
63 return 0;
64}
65
66static struct sysreset_ops sti_sysreset = {
67 .request = sti_sysreset_request,
68};
69
70static const struct udevice_id sti_sysreset_ids[] = {
71 { .compatible = "st,stih407-restart" },
72 { }
73};
74
75U_BOOT_DRIVER(sysreset_sti) = {
76 .name = "sysreset_sti",
77 .id = UCLASS_SYSRESET,
78 .ops = &sti_sysreset,
79 .probe = sti_sysreset_probe,
80 .of_match = sti_sysreset_ids,
81 .priv_auto_alloc_size = sizeof(struct sti_sysreset_priv),
82};