1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2018 MediaTek Inc.
5 * Author: Ryder Lee <ryder.lee@mediatek.com>
6 * Weijie Gao <weijie.gao@mediatek.com>
13 #include <reset-uclass.h>
16 struct mediatek_reset_priv {
17 struct regmap *regmap;
22 static int mediatek_reset_request(struct reset_ctl *reset_ctl)
27 static int mediatek_reset_free(struct reset_ctl *reset_ctl)
32 static int mediatek_reset_assert(struct reset_ctl *reset_ctl)
34 struct mediatek_reset_priv *priv = dev_get_priv(reset_ctl->dev);
35 int id = reset_ctl->id;
37 if (id >= priv->nr_resets)
40 return regmap_update_bits(priv->regmap,
41 priv->regofs + ((id / 32) << 2), BIT(id % 32), BIT(id % 32));
44 static int mediatek_reset_deassert(struct reset_ctl *reset_ctl)
46 struct mediatek_reset_priv *priv = dev_get_priv(reset_ctl->dev);
47 int id = reset_ctl->id;
49 if (id >= priv->nr_resets)
52 return regmap_update_bits(priv->regmap,
53 priv->regofs + ((id / 32) << 2), BIT(id % 32), 0);
56 struct reset_ops mediatek_reset_ops = {
57 .request = mediatek_reset_request,
58 .rfree = mediatek_reset_free,
59 .rst_assert = mediatek_reset_assert,
60 .rst_deassert = mediatek_reset_deassert,
63 static int mediatek_reset_probe(struct udevice *dev)
65 struct mediatek_reset_priv *priv = dev_get_priv(dev);
67 if (!priv->regofs && !priv->nr_resets)
70 priv->regmap = syscon_node_to_regmap(dev_ofnode(dev));
71 if (IS_ERR(priv->regmap))
72 return PTR_ERR(priv->regmap);
77 int mediatek_reset_bind(struct udevice *pdev, u32 regofs, u32 num_regs)
79 struct udevice *rst_dev;
80 struct mediatek_reset_priv *priv;
83 ret = device_bind_driver_to_node(pdev, "mediatek_reset", "reset",
84 dev_ofnode(pdev), &rst_dev);
88 priv = malloc(sizeof(struct mediatek_reset_priv));
89 priv->regofs = regofs;
90 priv->nr_resets = num_regs * 32;
96 U_BOOT_DRIVER(mediatek_reset) = {
97 .name = "mediatek_reset",
99 .probe = mediatek_reset_probe,
100 .ops = &mediatek_reset_ops,
101 .priv_auto_alloc_size = sizeof(struct mediatek_reset_priv),