blob: bc20e3335c5caa395e6c7257598dee058561f720 [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
8#include <common.h>
9#include <dm.h>
10#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <malloc.h>
developer074393a2019-09-25 17:45:29 +080013#include <reset-uclass.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
developer074393a2019-09-25 17:45:29 +080015#include <linux/io.h>
16
17struct mtmips_reset_priv {
18 void __iomem *base;
19};
20
21static int mtmips_reset_request(struct reset_ctl *reset_ctl)
22{
23 return 0;
24}
25
26static int mtmips_reset_free(struct reset_ctl *reset_ctl)
27{
28 return 0;
29}
30
31static 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
40static 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
49static const struct reset_ops mtmips_reset_ops = {
50 .request = mtmips_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -070051 .rfree = mtmips_reset_free,
developer074393a2019-09-25 17:45:29 +080052 .rst_assert = mtmips_reset_assert,
53 .rst_deassert = mtmips_reset_deassert,
54};
55
56static int mtmips_reset_probe(struct udevice *dev)
57{
58 return 0;
59}
60
61static int mtmips_reset_ofdata_to_platdata(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
72static const struct udevice_id mtmips_reset_ids[] = {
73 { .compatible = "mediatek,mtmips-reset" },
74 { }
75};
76
77U_BOOT_DRIVER(mtmips_reset) = {
78 .name = "mtmips-reset",
79 .id = UCLASS_RESET,
80 .of_match = mtmips_reset_ids,
81 .ofdata_to_platdata = mtmips_reset_ofdata_to_platdata,
82 .probe = mtmips_reset_probe,
83 .priv_auto_alloc_size = sizeof(struct mtmips_reset_priv),
84 .ops = &mtmips_reset_ops,
85};