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