developer | 074393a | 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 | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 13 | #include <reset-uclass.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
developer | 074393a | 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 | |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 21 | static 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 | |
| 30 | static 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 | |
| 39 | static const struct reset_ops mtmips_reset_ops = { |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 40 | .rst_assert = mtmips_reset_assert, |
| 41 | .rst_deassert = mtmips_reset_deassert, |
| 42 | }; |
| 43 | |
| 44 | static int mtmips_reset_probe(struct udevice *dev) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 49 | static int mtmips_reset_of_to_plat(struct udevice *dev) |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 50 | { |
| 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 | |
| 60 | static const struct udevice_id mtmips_reset_ids[] = { |
| 61 | { .compatible = "mediatek,mtmips-reset" }, |
| 62 | { } |
| 63 | }; |
| 64 | |
| 65 | U_BOOT_DRIVER(mtmips_reset) = { |
| 66 | .name = "mtmips-reset", |
| 67 | .id = UCLASS_RESET, |
| 68 | .of_match = mtmips_reset_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 69 | .of_to_plat = mtmips_reset_of_to_plat, |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 70 | .probe = mtmips_reset_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 71 | .priv_auto = sizeof(struct mtmips_reset_priv), |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 72 | .ops = &mtmips_reset_ops, |
developer | 3260234 | 2020-11-12 16:37:14 +0800 | [diff] [blame] | 73 | .flags = DM_FLAG_PRE_RELOC, |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 74 | }; |