2019-03-20 07:32:39 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2019, Linaro Limited
|
|
|
|
*/
|
|
|
|
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <malloc.h>
|
2019-03-20 07:32:39 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <dt-bindings/reset/ti-syscon.h>
|
|
|
|
#include <reset-uclass.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2019-03-20 07:32:39 +00:00
|
|
|
|
|
|
|
struct hisi_reset_priv {
|
|
|
|
void __iomem *base;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hisi_reset_deassert(struct reset_ctl *rst)
|
|
|
|
{
|
|
|
|
struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = readl(priv->base + rst->data);
|
|
|
|
if (rst->polarity & DEASSERT_SET)
|
|
|
|
val |= BIT(rst->id);
|
|
|
|
else
|
|
|
|
val &= ~BIT(rst->id);
|
|
|
|
writel(val, priv->base + rst->data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hisi_reset_assert(struct reset_ctl *rst)
|
|
|
|
{
|
|
|
|
struct hisi_reset_priv *priv = dev_get_priv(rst->dev);
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
val = readl(priv->base + rst->data);
|
|
|
|
if (rst->polarity & ASSERT_SET)
|
|
|
|
val |= BIT(rst->id);
|
|
|
|
else
|
|
|
|
val &= ~BIT(rst->id);
|
|
|
|
writel(val, priv->base + rst->data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hisi_reset_of_xlate(struct reset_ctl *rst,
|
|
|
|
struct ofnode_phandle_args *args)
|
|
|
|
{
|
2024-01-19 12:49:17 +00:00
|
|
|
unsigned long polarity;
|
|
|
|
|
|
|
|
switch (args->args_count) {
|
|
|
|
case 2:
|
|
|
|
polarity = ASSERT_SET;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
polarity = args->args[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-03-20 07:32:39 +00:00
|
|
|
debug("Invalid args_count: %d\n", args->args_count);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use .data field as register offset and .id field as bit shift */
|
|
|
|
rst->data = args->args[0];
|
|
|
|
rst->id = args->args[1];
|
2024-01-19 12:49:17 +00:00
|
|
|
rst->polarity = polarity;
|
2019-03-20 07:32:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct reset_ops hisi_reset_reset_ops = {
|
|
|
|
.of_xlate = hisi_reset_of_xlate,
|
|
|
|
.rst_assert = hisi_reset_assert,
|
|
|
|
.rst_deassert = hisi_reset_deassert,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id hisi_reset_ids[] = {
|
|
|
|
{ .compatible = "hisilicon,hi3798cv200-reset" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hisi_reset_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct hisi_reset_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->base = dev_remap_addr(dev);
|
|
|
|
if (!priv->base)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(hisi_reset) = {
|
|
|
|
.name = "hisilicon_reset",
|
|
|
|
.id = UCLASS_RESET,
|
|
|
|
.of_match = hisi_reset_ids,
|
|
|
|
.ops = &hisi_reset_reset_ops,
|
|
|
|
.probe = hisi_reset_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct hisi_reset_priv),
|
2019-03-20 07:32:39 +00:00
|
|
|
};
|