1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2020 Sean Anderson
9 #include <reset-uclass.h>
11 #include <linux/bitops.h>
12 #include <linux/err.h>
14 struct syscon_reset_priv {
15 struct regmap *regmap;
21 static int syscon_reset_request(struct reset_ctl *rst)
23 struct syscon_reset_priv *priv = dev_get_priv(rst->dev);
25 if (BIT(rst->id) & priv->mask)
31 static int syscon_reset_assert(struct reset_ctl *rst)
33 struct syscon_reset_priv *priv = dev_get_priv(rst->dev);
35 return regmap_update_bits(priv->regmap, priv->offset, BIT(rst->id),
36 priv->assert_high ? BIT(rst->id) : 0);
39 static int syscon_reset_deassert(struct reset_ctl *rst)
41 struct syscon_reset_priv *priv = dev_get_priv(rst->dev);
43 return regmap_update_bits(priv->regmap, priv->offset, BIT(rst->id),
44 priv->assert_high ? 0 : BIT(rst->id));
47 static const struct reset_ops syscon_reset_ops = {
48 .request = syscon_reset_request,
49 .rst_assert = syscon_reset_assert,
50 .rst_deassert = syscon_reset_deassert,
53 int syscon_reset_probe(struct udevice *dev)
55 struct syscon_reset_priv *priv = dev_get_priv(dev);
57 priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap");
58 if (IS_ERR(priv->regmap))
61 priv->offset = dev_read_u32_default(dev, "offset", 0);
62 priv->mask = dev_read_u32_default(dev, "mask", 0);
63 priv->assert_high = dev_read_u32_default(dev, "assert-high", true);
68 static const struct udevice_id syscon_reset_ids[] = {
69 { .compatible = "syscon-reset" },
73 U_BOOT_DRIVER(syscon_reset) = {
74 .name = "syscon_reset",
76 .of_match = syscon_reset_ids,
77 .probe = syscon_reset_probe,
78 .priv_auto = sizeof(struct syscon_reset_priv),
79 .ops = &syscon_reset_ops,