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