blob: 2db6766280f2934a060fa7934095af3c99a20a3c [file] [log] [blame]
developer074393a2019-09-25 17:45:29 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2019 MediaTek Inc. All Rights Reserved.
4 *
5 * Author: Weijie Gao <weijie.gao@mediatek.com>
6 */
7
developer074393a2019-09-25 17:45:29 +08008#include <dm.h>
9#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
developer074393a2019-09-25 17:45:29 +080012#include <reset-uclass.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060013#include <linux/bitops.h>
developer074393a2019-09-25 17:45:29 +080014#include <linux/io.h>
15
16struct mtmips_reset_priv {
17 void __iomem *base;
18};
19
developer074393a2019-09-25 17:45:29 +080020static int mtmips_reset_assert(struct reset_ctl *reset_ctl)
21{
22 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
23
24 setbits_32(priv->base, BIT(reset_ctl->id));
25
26 return 0;
27}
28
29static int mtmips_reset_deassert(struct reset_ctl *reset_ctl)
30{
31 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
32
33 clrbits_32(priv->base, BIT(reset_ctl->id));
34
35 return 0;
36}
37
38static const struct reset_ops mtmips_reset_ops = {
developer074393a2019-09-25 17:45:29 +080039 .rst_assert = mtmips_reset_assert,
40 .rst_deassert = mtmips_reset_deassert,
41};
42
43static int mtmips_reset_probe(struct udevice *dev)
44{
45 return 0;
46}
47
Simon Glassaad29ae2020-12-03 16:55:21 -070048static int mtmips_reset_of_to_plat(struct udevice *dev)
developer074393a2019-09-25 17:45:29 +080049{
50 struct mtmips_reset_priv *priv = dev_get_priv(dev);
51
52 priv->base = (void __iomem *)dev_remap_addr_index(dev, 0);
53 if (!priv->base)
54 return -EINVAL;
55
56 return 0;
57}
58
59static const struct udevice_id mtmips_reset_ids[] = {
60 { .compatible = "mediatek,mtmips-reset" },
61 { }
62};
63
64U_BOOT_DRIVER(mtmips_reset) = {
65 .name = "mtmips-reset",
66 .id = UCLASS_RESET,
67 .of_match = mtmips_reset_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -070068 .of_to_plat = mtmips_reset_of_to_plat,
developer074393a2019-09-25 17:45:29 +080069 .probe = mtmips_reset_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070070 .priv_auto = sizeof(struct mtmips_reset_priv),
developer074393a2019-09-25 17:45:29 +080071 .ops = &mtmips_reset_ops,
developer32602342020-11-12 16:37:14 +080072 .flags = DM_FLAG_PRE_RELOC,
developer074393a2019-09-25 17:45:29 +080073};