2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-04-17 19:00:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google, Inc
|
2020-10-15 02:25:13 +00:00
|
|
|
* Copyright 2020 ASPEED Technology Inc.
|
2017-04-17 19:00:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-04-17 19:00:24 +00:00
|
|
|
#include <misc.h>
|
|
|
|
#include <reset.h>
|
|
|
|
#include <reset-uclass.h>
|
2020-10-15 02:25:13 +00:00
|
|
|
#include <linux/err.h>
|
2017-04-17 19:00:24 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/scu_ast2500.h>
|
|
|
|
|
|
|
|
struct ast2500_reset_priv {
|
|
|
|
struct ast2500_scu *scu;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ast2500_reset_assert(struct reset_ctl *reset_ctl)
|
|
|
|
{
|
|
|
|
struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
|
2020-10-15 02:25:13 +00:00
|
|
|
struct ast2500_scu *scu = priv->scu;
|
|
|
|
|
|
|
|
debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
|
2017-04-17 19:00:24 +00:00
|
|
|
|
2020-10-15 02:25:13 +00:00
|
|
|
if (reset_ctl->id < 32)
|
|
|
|
setbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
|
|
|
|
else
|
|
|
|
setbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
|
|
|
|
|
|
|
|
return 0;
|
2017-04-17 19:00:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 02:25:13 +00:00
|
|
|
static int ast2500_reset_deassert(struct reset_ctl *reset_ctl)
|
2017-04-17 19:00:24 +00:00
|
|
|
{
|
2020-10-15 02:25:13 +00:00
|
|
|
struct ast2500_reset_priv *priv = dev_get_priv(reset_ctl->dev);
|
|
|
|
struct ast2500_scu *scu = priv->scu;
|
|
|
|
|
|
|
|
debug("%s: reset_ctl->id: %lu\n", __func__, reset_ctl->id);
|
|
|
|
|
|
|
|
if (reset_ctl->id < 32)
|
|
|
|
clrbits_le32(&scu->sysreset_ctrl1, BIT(reset_ctl->id));
|
|
|
|
else
|
|
|
|
clrbits_le32(&scu->sysreset_ctrl2, BIT(reset_ctl->id - 32));
|
2017-04-17 19:00:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast2500_reset_probe(struct udevice *dev)
|
|
|
|
{
|
2020-10-15 02:25:13 +00:00
|
|
|
int rc;
|
2017-04-17 19:00:24 +00:00
|
|
|
struct ast2500_reset_priv *priv = dev_get_priv(dev);
|
2020-10-15 02:25:13 +00:00
|
|
|
struct udevice *scu_dev;
|
|
|
|
|
|
|
|
/* get SCU base from clock device */
|
|
|
|
rc = uclass_get_device_by_driver(UCLASS_CLK,
|
2020-12-29 03:34:56 +00:00
|
|
|
DM_DRIVER_GET(aspeed_ast2500_scu), &scu_dev);
|
2020-10-15 02:25:13 +00:00
|
|
|
if (rc) {
|
|
|
|
debug("%s: clock device not found, rc=%d\n", __func__, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
2017-04-17 19:00:24 +00:00
|
|
|
|
2020-10-15 02:25:13 +00:00
|
|
|
priv->scu = devfdt_get_addr_ptr(scu_dev);
|
|
|
|
if (IS_ERR_OR_NULL(priv->scu)) {
|
|
|
|
debug("%s: invalid SCU base pointer\n", __func__);
|
|
|
|
return PTR_ERR(priv->scu);
|
|
|
|
}
|
2017-04-17 19:00:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id ast2500_reset_ids[] = {
|
|
|
|
{ .compatible = "aspeed,ast2500-reset" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct reset_ops ast2500_reset_ops = {
|
2020-10-15 02:25:13 +00:00
|
|
|
.rst_assert = ast2500_reset_assert,
|
|
|
|
.rst_deassert = ast2500_reset_deassert,
|
2017-04-17 19:00:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ast2500_reset) = {
|
2020-10-15 02:25:13 +00:00
|
|
|
.name = "ast2500_reset",
|
|
|
|
.id = UCLASS_RESET,
|
2017-04-17 19:00:24 +00:00
|
|
|
.of_match = ast2500_reset_ids,
|
|
|
|
.probe = ast2500_reset_probe,
|
|
|
|
.ops = &ast2500_reset_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct ast2500_reset_priv),
|
2017-04-17 19:00:24 +00:00
|
|
|
};
|