1413788ceSPatrice Chotard /*
2413788ceSPatrice Chotard * (C) Copyright 2017 Patrice Chotard <patrice.chotard@st.com>
3413788ceSPatrice Chotard *
4413788ceSPatrice Chotard * SPDX-License-Identifier: GPL-2.0+
5413788ceSPatrice Chotard */
6413788ceSPatrice Chotard
7413788ceSPatrice Chotard #include <common.h>
8413788ceSPatrice Chotard #include <dm.h>
9413788ceSPatrice Chotard #include <regmap.h>
10413788ceSPatrice Chotard #include <syscon.h>
11413788ceSPatrice Chotard #include <sysreset.h>
12413788ceSPatrice Chotard #include <asm/io.h>
13413788ceSPatrice Chotard
14413788ceSPatrice Chotard DECLARE_GLOBAL_DATA_PTR;
15413788ceSPatrice Chotard
16413788ceSPatrice Chotard struct sti_sysreset_priv {
17413788ceSPatrice Chotard phys_addr_t base;
18413788ceSPatrice Chotard };
19413788ceSPatrice Chotard
sti_sysreset_request(struct udevice * dev,enum sysreset_t type)20413788ceSPatrice Chotard static int sti_sysreset_request(struct udevice *dev, enum sysreset_t type)
21413788ceSPatrice Chotard {
22413788ceSPatrice Chotard struct sti_sysreset_priv *priv = dev_get_priv(dev);
23413788ceSPatrice Chotard
24413788ceSPatrice Chotard generic_clear_bit(0, (void __iomem *)priv->base);
25413788ceSPatrice Chotard
26413788ceSPatrice Chotard return -EINPROGRESS;
27413788ceSPatrice Chotard }
28413788ceSPatrice Chotard
sti_sysreset_probe(struct udevice * dev)29413788ceSPatrice Chotard static int sti_sysreset_probe(struct udevice *dev)
30413788ceSPatrice Chotard {
31413788ceSPatrice Chotard struct sti_sysreset_priv *priv = dev_get_priv(dev);
32413788ceSPatrice Chotard struct udevice *syscon;
33413788ceSPatrice Chotard struct regmap *regmap;
34413788ceSPatrice Chotard struct fdtdec_phandle_args syscfg_phandle;
35413788ceSPatrice Chotard int ret;
36413788ceSPatrice Chotard
37413788ceSPatrice Chotard /* get corresponding syscon phandle */
38413788ceSPatrice Chotard ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
39413788ceSPatrice Chotard "st,syscfg", NULL, 0, 0,
40413788ceSPatrice Chotard &syscfg_phandle);
41413788ceSPatrice Chotard if (ret < 0) {
42*90aa625cSMasahiro Yamada pr_err("Can't get syscfg phandle: %d\n", ret);
43413788ceSPatrice Chotard return ret;
44413788ceSPatrice Chotard }
45413788ceSPatrice Chotard
46413788ceSPatrice Chotard ret = uclass_get_device_by_of_offset(UCLASS_SYSCON,
47413788ceSPatrice Chotard syscfg_phandle.node,
48413788ceSPatrice Chotard &syscon);
49413788ceSPatrice Chotard if (ret) {
50*90aa625cSMasahiro Yamada pr_err("%s: uclass_get_device_by_of_offset failed: %d\n",
51413788ceSPatrice Chotard __func__, ret);
52413788ceSPatrice Chotard return ret;
53413788ceSPatrice Chotard }
54413788ceSPatrice Chotard
55413788ceSPatrice Chotard regmap = syscon_get_regmap(syscon);
56413788ceSPatrice Chotard if (!regmap) {
57*90aa625cSMasahiro Yamada pr_err("unable to get regmap for %s\n", syscon->name);
58413788ceSPatrice Chotard return -ENODEV;
59413788ceSPatrice Chotard }
60413788ceSPatrice Chotard
61413788ceSPatrice Chotard priv->base = regmap->base;
62413788ceSPatrice Chotard
63413788ceSPatrice Chotard return 0;
64413788ceSPatrice Chotard }
65413788ceSPatrice Chotard
66413788ceSPatrice Chotard static struct sysreset_ops sti_sysreset = {
67413788ceSPatrice Chotard .request = sti_sysreset_request,
68413788ceSPatrice Chotard };
69413788ceSPatrice Chotard
70413788ceSPatrice Chotard static const struct udevice_id sti_sysreset_ids[] = {
71413788ceSPatrice Chotard { .compatible = "st,stih407-restart" },
72413788ceSPatrice Chotard { }
73413788ceSPatrice Chotard };
74413788ceSPatrice Chotard
75413788ceSPatrice Chotard U_BOOT_DRIVER(sysreset_sti) = {
76413788ceSPatrice Chotard .name = "sysreset_sti",
77413788ceSPatrice Chotard .id = UCLASS_SYSRESET,
78413788ceSPatrice Chotard .ops = &sti_sysreset,
79413788ceSPatrice Chotard .probe = sti_sysreset_probe,
80413788ceSPatrice Chotard .of_match = sti_sysreset_ids,
81413788ceSPatrice Chotard .priv_auto_alloc_size = sizeof(struct sti_sysreset_priv),
82413788ceSPatrice Chotard };
83