1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020 Sifive, Inc.
4 * Author: Sagar Kadam <sagar.kadam@sifive.com>
9 #include <reset-uclass.h>
11 #include <dm/device_compat.h>
13 #include <linux/bitops.h>
15 #define PRCI_RESETREG_OFFSET 0x28
17 struct sifive_reset_priv {
19 /* number of reset signals */
23 static int sifive_rst_trigger(struct reset_ctl *rst, bool level)
25 struct sifive_reset_priv *priv = dev_get_priv(rst->dev);
27 int regval = readl(priv->base + PRCI_RESETREG_OFFSET);
29 /* Derive bitposition from rst id */
37 writel(regval, priv->base + PRCI_RESETREG_OFFSET);
42 static int sifive_reset_assert(struct reset_ctl *rst)
44 return sifive_rst_trigger(rst, false);
47 static int sifive_reset_deassert(struct reset_ctl *rst)
49 return sifive_rst_trigger(rst, true);
52 static int sifive_reset_request(struct reset_ctl *rst)
54 struct sifive_reset_priv *priv = dev_get_priv(rst->dev);
56 debug("%s(rst=%p) (dev=%p, id=%lu) (nr_reset=%d)\n", __func__,
57 rst, rst->dev, rst->id, priv->nr_reset);
59 if (rst->id > priv->nr_reset)
65 static int sifive_reset_free(struct reset_ctl *rst)
67 struct sifive_reset_priv *priv = dev_get_priv(rst->dev);
69 debug("%s(rst=%p) (dev=%p, id=%lu) (nr_reset=%d)\n", __func__,
70 rst, rst->dev, rst->id, priv->nr_reset);
75 static int sifive_reset_probe(struct udevice *dev)
77 struct sifive_reset_priv *priv = dev_get_priv(dev);
79 priv->base = dev_remap_addr(dev);
86 int sifive_reset_bind(struct udevice *dev, ulong count)
88 struct udevice *rst_dev;
89 struct sifive_reset_priv *priv;
92 ret = device_bind_driver_to_node(dev, "sifive-reset", "reset",
93 dev_ofnode(dev), &rst_dev);
95 dev_err(dev, "failed to bind sifive_reset driver (ret=%d)\n", ret);
98 priv = malloc(sizeof(struct sifive_reset_priv));
99 priv->nr_reset = count;
100 rst_dev->priv = priv;
105 const struct reset_ops sifive_reset_ops = {
106 .request = sifive_reset_request,
107 .rfree = sifive_reset_free,
108 .rst_assert = sifive_reset_assert,
109 .rst_deassert = sifive_reset_deassert,
112 U_BOOT_DRIVER(sifive_reset) = {
113 .name = "sifive-reset",
115 .ops = &sifive_reset_ops,
116 .probe = sifive_reset_probe,
117 .priv_auto_alloc_size = sizeof(struct sifive_reset_priv),