.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (c) 2014 MediaTek Inc. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License version 2 as |
---|
6 | | - * published by the Free Software Foundation. |
---|
7 | | - * |
---|
8 | | - * This program is distributed in the hope that it will be useful, |
---|
9 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
10 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
11 | | - * GNU General Public License for more details. |
---|
12 | 4 | */ |
---|
13 | 5 | |
---|
14 | 6 | #include <linux/mfd/syscon.h> |
---|
.. | .. |
---|
26 | 18 | int regofs; |
---|
27 | 19 | struct reset_controller_dev rcdev; |
---|
28 | 20 | }; |
---|
| 21 | + |
---|
| 22 | +static int mtk_reset_assert_set_clr(struct reset_controller_dev *rcdev, |
---|
| 23 | + unsigned long id) |
---|
| 24 | +{ |
---|
| 25 | + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev); |
---|
| 26 | + unsigned int reg = data->regofs + ((id / 32) << 4); |
---|
| 27 | + |
---|
| 28 | + return regmap_write(data->regmap, reg, BIT(id % 32)); |
---|
| 29 | +} |
---|
| 30 | + |
---|
| 31 | +static int mtk_reset_deassert_set_clr(struct reset_controller_dev *rcdev, |
---|
| 32 | + unsigned long id) |
---|
| 33 | +{ |
---|
| 34 | + struct mtk_reset *data = container_of(rcdev, struct mtk_reset, rcdev); |
---|
| 35 | + unsigned int reg = data->regofs + ((id / 32) << 4) + 0x4; |
---|
| 36 | + |
---|
| 37 | + return regmap_write(data->regmap, reg, BIT(id % 32)); |
---|
| 38 | +} |
---|
29 | 39 | |
---|
30 | 40 | static int mtk_reset_assert(struct reset_controller_dev *rcdev, |
---|
31 | 41 | unsigned long id) |
---|
.. | .. |
---|
57 | 67 | return mtk_reset_deassert(rcdev, id); |
---|
58 | 68 | } |
---|
59 | 69 | |
---|
| 70 | +static int mtk_reset_set_clr(struct reset_controller_dev *rcdev, |
---|
| 71 | + unsigned long id) |
---|
| 72 | +{ |
---|
| 73 | + int ret; |
---|
| 74 | + |
---|
| 75 | + ret = mtk_reset_assert_set_clr(rcdev, id); |
---|
| 76 | + if (ret) |
---|
| 77 | + return ret; |
---|
| 78 | + return mtk_reset_deassert_set_clr(rcdev, id); |
---|
| 79 | +} |
---|
| 80 | + |
---|
60 | 81 | static const struct reset_control_ops mtk_reset_ops = { |
---|
61 | 82 | .assert = mtk_reset_assert, |
---|
62 | 83 | .deassert = mtk_reset_deassert, |
---|
63 | 84 | .reset = mtk_reset, |
---|
64 | 85 | }; |
---|
65 | 86 | |
---|
66 | | -void mtk_register_reset_controller(struct device_node *np, |
---|
67 | | - unsigned int num_regs, int regofs) |
---|
| 87 | +static const struct reset_control_ops mtk_reset_ops_set_clr = { |
---|
| 88 | + .assert = mtk_reset_assert_set_clr, |
---|
| 89 | + .deassert = mtk_reset_deassert_set_clr, |
---|
| 90 | + .reset = mtk_reset_set_clr, |
---|
| 91 | +}; |
---|
| 92 | + |
---|
| 93 | +static void mtk_register_reset_controller_common(struct device_node *np, |
---|
| 94 | + unsigned int num_regs, int regofs, |
---|
| 95 | + const struct reset_control_ops *reset_ops) |
---|
68 | 96 | { |
---|
69 | 97 | struct mtk_reset *data; |
---|
70 | 98 | int ret; |
---|
.. | .. |
---|
85 | 113 | data->regofs = regofs; |
---|
86 | 114 | data->rcdev.owner = THIS_MODULE; |
---|
87 | 115 | data->rcdev.nr_resets = num_regs * 32; |
---|
88 | | - data->rcdev.ops = &mtk_reset_ops; |
---|
| 116 | + data->rcdev.ops = reset_ops; |
---|
89 | 117 | data->rcdev.of_node = np; |
---|
90 | 118 | |
---|
91 | 119 | ret = reset_controller_register(&data->rcdev); |
---|
.. | .. |
---|
95 | 123 | return; |
---|
96 | 124 | } |
---|
97 | 125 | } |
---|
| 126 | + |
---|
| 127 | +void mtk_register_reset_controller(struct device_node *np, |
---|
| 128 | + unsigned int num_regs, int regofs) |
---|
| 129 | +{ |
---|
| 130 | + mtk_register_reset_controller_common(np, num_regs, regofs, |
---|
| 131 | + &mtk_reset_ops); |
---|
| 132 | +} |
---|
| 133 | + |
---|
| 134 | +void mtk_register_reset_controller_set_clr(struct device_node *np, |
---|
| 135 | + unsigned int num_regs, int regofs) |
---|
| 136 | +{ |
---|
| 137 | + mtk_register_reset_controller_common(np, num_regs, regofs, |
---|
| 138 | + &mtk_reset_ops_set_clr); |
---|
| 139 | +} |
---|