blob: 4e71d5255845c1b50d5c2dbb2cca5dc679df13fa [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
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 Glass94474b22020-02-03 07:35:52 -070051 .rfree = mtmips_reset_free,
Weijie Gaof7ae6b62019-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
Simon Glassd1998a92020-12-03 16:55:21 -070061static int mtmips_reset_of_to_plat(struct udevice *dev)
Weijie Gaof7ae6b62019-09-25 17:45:29 +080062{
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,
Simon Glassd1998a92020-12-03 16:55:21 -070081 .of_to_plat = mtmips_reset_of_to_plat,
Weijie Gaof7ae6b62019-09-25 17:45:29 +080082 .probe = mtmips_reset_probe,
Simon Glass41575d82020-12-03 16:55:17 -070083 .priv_auto = sizeof(struct mtmips_reset_priv),
Weijie Gaof7ae6b62019-09-25 17:45:29 +080084 .ops = &mtmips_reset_ops,
Weijie Gao8d6465b2020-11-12 16:37:14 +080085 .flags = DM_FLAG_PRE_RELOC,
Weijie Gaof7ae6b62019-09-25 17:45:29 +080086};