blob: 7bb8469823c88c898889403366330942839bfae6 [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 Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <malloc.h>
Weijie Gaof7ae6b62019-09-25 17:45:29 +080013#include <reset-uclass.h>
Simon Glasscd93d622020-05-10 11:40:13 -060014#include <linux/bitops.h>
Weijie Gaof7ae6b62019-09-25 17:45:29 +080015#include <linux/io.h>
16
17struct mtmips_reset_priv {
18 void __iomem *base;
19};
20
Weijie Gaof7ae6b62019-09-25 17:45:29 +080021static int mtmips_reset_assert(struct reset_ctl *reset_ctl)
22{
23 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
24
25 setbits_32(priv->base, BIT(reset_ctl->id));
26
27 return 0;
28}
29
30static int mtmips_reset_deassert(struct reset_ctl *reset_ctl)
31{
32 struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev);
33
34 clrbits_32(priv->base, BIT(reset_ctl->id));
35
36 return 0;
37}
38
39static const struct reset_ops mtmips_reset_ops = {
Weijie Gaof7ae6b62019-09-25 17:45:29 +080040 .rst_assert = mtmips_reset_assert,
41 .rst_deassert = mtmips_reset_deassert,
42};
43
44static int mtmips_reset_probe(struct udevice *dev)
45{
46 return 0;
47}
48
Simon Glassd1998a92020-12-03 16:55:21 -070049static int mtmips_reset_of_to_plat(struct udevice *dev)
Weijie Gaof7ae6b62019-09-25 17:45:29 +080050{
51 struct mtmips_reset_priv *priv = dev_get_priv(dev);
52
53 priv->base = (void __iomem *)dev_remap_addr_index(dev, 0);
54 if (!priv->base)
55 return -EINVAL;
56
57 return 0;
58}
59
60static const struct udevice_id mtmips_reset_ids[] = {
61 { .compatible = "mediatek,mtmips-reset" },
62 { }
63};
64
65U_BOOT_DRIVER(mtmips_reset) = {
66 .name = "mtmips-reset",
67 .id = UCLASS_RESET,
68 .of_match = mtmips_reset_ids,
Simon Glassd1998a92020-12-03 16:55:21 -070069 .of_to_plat = mtmips_reset_of_to_plat,
Weijie Gaof7ae6b62019-09-25 17:45:29 +080070 .probe = mtmips_reset_probe,
Simon Glass41575d82020-12-03 16:55:17 -070071 .priv_auto = sizeof(struct mtmips_reset_priv),
Weijie Gaof7ae6b62019-09-25 17:45:29 +080072 .ops = &mtmips_reset_ops,
Weijie Gao8d6465b2020-11-12 16:37:14 +080073 .flags = DM_FLAG_PRE_RELOC,
Weijie Gaof7ae6b62019-09-25 17:45:29 +080074};