Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 1 | // 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 Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 13 | #include <reset-uclass.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 15 | #include <linux/io.h> |
| 16 | |
| 17 | struct mtmips_reset_priv { |
| 18 | void __iomem *base; |
| 19 | }; |
| 20 | |
| 21 | static int mtmips_reset_request(struct reset_ctl *reset_ctl) |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | static int mtmips_reset_free(struct reset_ctl *reset_ctl) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | static 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 | |
| 40 | static 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 | |
| 49 | static const struct reset_ops mtmips_reset_ops = { |
| 50 | .request = mtmips_reset_request, |
Simon Glass | 94474b2 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 51 | .rfree = mtmips_reset_free, |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 52 | .rst_assert = mtmips_reset_assert, |
| 53 | .rst_deassert = mtmips_reset_deassert, |
| 54 | }; |
| 55 | |
| 56 | static int mtmips_reset_probe(struct udevice *dev) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 61 | static int mtmips_reset_of_to_plat(struct udevice *dev) |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 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 | |
| 72 | static const struct udevice_id mtmips_reset_ids[] = { |
| 73 | { .compatible = "mediatek,mtmips-reset" }, |
| 74 | { } |
| 75 | }; |
| 76 | |
| 77 | U_BOOT_DRIVER(mtmips_reset) = { |
| 78 | .name = "mtmips-reset", |
| 79 | .id = UCLASS_RESET, |
| 80 | .of_match = mtmips_reset_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 81 | .of_to_plat = mtmips_reset_of_to_plat, |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 82 | .probe = mtmips_reset_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 83 | .priv_auto = sizeof(struct mtmips_reset_priv), |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 84 | .ops = &mtmips_reset_ops, |
Weijie Gao | 8d6465b | 2020-11-12 16:37:14 +0800 | [diff] [blame] | 85 | .flags = DM_FLAG_PRE_RELOC, |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 86 | }; |