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 | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 12 | #include <reset-uclass.h> |
| 13 | #include <linux/io.h> |
| 14 | |
| 15 | struct mtmips_reset_priv { |
| 16 | void __iomem *base; |
| 17 | }; |
| 18 | |
| 19 | static int mtmips_reset_request(struct reset_ctl *reset_ctl) |
| 20 | { |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static int mtmips_reset_free(struct reset_ctl *reset_ctl) |
| 25 | { |
| 26 | return 0; |
| 27 | } |
| 28 | |
| 29 | static int mtmips_reset_assert(struct reset_ctl *reset_ctl) |
| 30 | { |
| 31 | struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 32 | |
| 33 | setbits_32(priv->base, BIT(reset_ctl->id)); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int mtmips_reset_deassert(struct reset_ctl *reset_ctl) |
| 39 | { |
| 40 | struct mtmips_reset_priv *priv = dev_get_priv(reset_ctl->dev); |
| 41 | |
| 42 | clrbits_32(priv->base, BIT(reset_ctl->id)); |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static const struct reset_ops mtmips_reset_ops = { |
| 48 | .request = mtmips_reset_request, |
Simon Glass | 94474b2 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 49 | .rfree = mtmips_reset_free, |
Weijie Gao | f7ae6b6 | 2019-09-25 17:45:29 +0800 | [diff] [blame] | 50 | .rst_assert = mtmips_reset_assert, |
| 51 | .rst_deassert = mtmips_reset_deassert, |
| 52 | }; |
| 53 | |
| 54 | static int mtmips_reset_probe(struct udevice *dev) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int mtmips_reset_ofdata_to_platdata(struct udevice *dev) |
| 60 | { |
| 61 | struct mtmips_reset_priv *priv = dev_get_priv(dev); |
| 62 | |
| 63 | priv->base = (void __iomem *)dev_remap_addr_index(dev, 0); |
| 64 | if (!priv->base) |
| 65 | return -EINVAL; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static const struct udevice_id mtmips_reset_ids[] = { |
| 71 | { .compatible = "mediatek,mtmips-reset" }, |
| 72 | { } |
| 73 | }; |
| 74 | |
| 75 | U_BOOT_DRIVER(mtmips_reset) = { |
| 76 | .name = "mtmips-reset", |
| 77 | .id = UCLASS_RESET, |
| 78 | .of_match = mtmips_reset_ids, |
| 79 | .ofdata_to_platdata = mtmips_reset_ofdata_to_platdata, |
| 80 | .probe = mtmips_reset_probe, |
| 81 | .priv_auto_alloc_size = sizeof(struct mtmips_reset_priv), |
| 82 | .ops = &mtmips_reset_ops, |
| 83 | }; |