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 | |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 12 | #include <reset-uclass.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 14 | #include <linux/io.h> |
| 15 | |
| 16 | struct mtmips_reset_priv { |
| 17 | void __iomem *base; |
| 18 | }; |
| 19 | |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 20 | static int mtmips_reset_assert(struct reset_ctl *reset_ctl) |
| 21 | { |
| 22 | struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 23 | |
| 24 | setbits_32(priv->base, BIT(reset_ctl->id)); |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static int mtmips_reset_deassert(struct reset_ctl *reset_ctl) |
| 30 | { |
| 31 | struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 32 | |
| 33 | clrbits_32(priv->base, BIT(reset_ctl->id)); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static const struct reset_ops mtmips_reset_ops = { |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 39 | .rst_assert = mtmips_reset_assert, |
| 40 | .rst_deassert = mtmips_reset_deassert, |
| 41 | }; |
| 42 | |
| 43 | static int mtmips_reset_probe(struct udevice *dev) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 48 | static int mtmips_reset_of_to_plat(struct udevice *dev) |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 49 | { |
| 50 | struct mtmips_reset_priv *priv = dev_get_priv(dev); |
| 51 | |
| 52 | priv->base = (void __iomem *)dev_remap_addr_index(dev, 0); |
| 53 | if (!priv->base) |
| 54 | return -EINVAL; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static const struct udevice_id mtmips_reset_ids[] = { |
| 60 | { .compatible = "mediatek,mtmips-reset" }, |
| 61 | { } |
| 62 | }; |
| 63 | |
| 64 | U_BOOT_DRIVER(mtmips_reset) = { |
| 65 | .name = "mtmips-reset", |
| 66 | .id = UCLASS_RESET, |
| 67 | .of_match = mtmips_reset_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 68 | .of_to_plat = mtmips_reset_of_to_plat, |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 69 | .probe = mtmips_reset_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 70 | .priv_auto = sizeof(struct mtmips_reset_priv), |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 71 | .ops = &mtmips_reset_ops, |
developer | 3260234 | 2020-11-12 16:37:14 +0800 | [diff] [blame] | 72 | .flags = DM_FLAG_PRE_RELOC, |
developer | 074393a | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 73 | }; |