1 // 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
8 #include <common.h>
9 #include <dm.h>
10 #include <errno.h>
11 #include <log.h>
12 #include <malloc.h>
13 #include <reset-uclass.h>
14 #include <linux/bitops.h>
15 #include <linux/io.h>
16
17 struct mtmips_reset_priv {
18 void __iomem *base;
19 };
20
mtmips_reset_request(struct reset_ctl * reset_ctl)21 static int mtmips_reset_request(struct reset_ctl *reset_ctl)
22 {
23 return 0;
24 }
25
mtmips_reset_free(struct reset_ctl * reset_ctl)26 static int mtmips_reset_free(struct reset_ctl *reset_ctl)
27 {
28 return 0;
29 }
30
mtmips_reset_assert(struct reset_ctl * reset_ctl)31 static int mtmips_reset_assert(struct reset_ctl *reset_ctl)
32 {
33 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
34
35 setbits_32(priv->base, BIT(reset_ctl->id));
36
37 return 0;
38 }
39
mtmips_reset_deassert(struct reset_ctl * reset_ctl)40 static int mtmips_reset_deassert(struct reset_ctl *reset_ctl)
41 {
42 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
43
44 clrbits_32(priv->base, BIT(reset_ctl->id));
45
46 return 0;
47 }
48
49 static const struct reset_ops mtmips_reset_ops = {
50 .request = mtmips_reset_request,
51 .rfree = mtmips_reset_free,
52 .rst_assert = mtmips_reset_assert,
53 .rst_deassert = mtmips_reset_deassert,
54 };
55
mtmips_reset_probe(struct udevice * dev)56 static int mtmips_reset_probe(struct udevice *dev)
57 {
58 return 0;
59 }
60
mtmips_reset_of_to_plat(struct udevice * dev)61 static int mtmips_reset_of_to_plat(struct udevice *dev)
62 {
63 struct mtmips_reset_priv *priv = dev_get_priv(dev);
64
65 priv->base = (void __iomem *)dev_remap_addr_index(dev, 0);
66 if (!priv->base)
67 return -EINVAL;
68
69 return 0;
70 }
71
72 static const struct udevice_id mtmips_reset_ids[] = {
73 { .compatible = "mediatek,mtmips-reset" },
74 { }
75 };
76
77 U_BOOT_DRIVER(mtmips_reset) = {
78 .name = "mtmips-reset",
79 .id = UCLASS_RESET,
80 .of_match = mtmips_reset_ids,
81 .of_to_plat = mtmips_reset_of_to_plat,
82 .probe = mtmips_reset_probe,
83 .priv_auto = sizeof(struct mtmips_reset_priv),
84 .ops = &mtmips_reset_ops,
85 .flags = DM_FLAG_PRE_RELOC,
86 };
87