2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-21 12:37:06 +00:00
|
|
|
/*
|
2017-10-23 07:53:57 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
|
|
|
* Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
|
2017-02-21 12:37:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <regmap.h>
|
|
|
|
#include <syscon.h>
|
|
|
|
#include <sysreset.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2017-02-21 12:37:06 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
struct sti_sysreset_priv {
|
|
|
|
phys_addr_t base;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sti_sysreset_request(struct udevice *dev, enum sysreset_t type)
|
|
|
|
{
|
|
|
|
struct sti_sysreset_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
generic_clear_bit(0, (void __iomem *)priv->base);
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sti_sysreset_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct sti_sysreset_priv *priv = dev_get_priv(dev);
|
|
|
|
struct udevice *syscon;
|
|
|
|
struct regmap *regmap;
|
|
|
|
struct fdtdec_phandle_args syscfg_phandle;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* get corresponding syscon phandle */
|
|
|
|
ret = fdtdec_parse_phandle_with_args(gd->fdt_blob, dev_of_offset(dev),
|
|
|
|
"st,syscfg", NULL, 0, 0,
|
|
|
|
&syscfg_phandle);
|
|
|
|
if (ret < 0) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("Can't get syscfg phandle: %d\n", ret);
|
2017-02-21 12:37:06 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_of_offset(UCLASS_SYSCON,
|
|
|
|
syscfg_phandle.node,
|
|
|
|
&syscon);
|
|
|
|
if (ret) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("%s: uclass_get_device_by_of_offset failed: %d\n",
|
2017-02-21 12:37:06 +00:00
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
regmap = syscon_get_regmap(syscon);
|
|
|
|
if (!regmap) {
|
2017-09-16 05:10:41 +00:00
|
|
|
pr_err("unable to get regmap for %s\n", syscon->name);
|
2017-02-21 12:37:06 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-04-19 03:14:01 +00:00
|
|
|
priv->base = regmap->ranges[0].start;
|
2017-02-21 12:37:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sysreset_ops sti_sysreset = {
|
|
|
|
.request = sti_sysreset_request,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id sti_sysreset_ids[] = {
|
|
|
|
{ .compatible = "st,stih407-restart" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sysreset_sti) = {
|
|
|
|
.name = "sysreset_sti",
|
|
|
|
.id = UCLASS_SYSRESET,
|
|
|
|
.ops = &sti_sysreset,
|
|
|
|
.probe = sti_sysreset_probe,
|
|
|
|
.of_match = sti_sysreset_ids,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct sti_sysreset_priv),
|
|
|
|
};
|