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