hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/reset/reset-meson.c
....@@ -1,75 +1,31 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
12 /*
23 * Amlogic Meson Reset Controller driver
34 *
4
- * This file is provided under a dual BSD/GPLv2 license. When using or
5
- * redistributing this file, you may do so under either license.
6
- *
7
- * GPL LICENSE SUMMARY
8
- *
95 * Copyright (c) 2016 BayLibre, SAS.
106 * Author: Neil Armstrong <narmstrong@baylibre.com>
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of version 2 of the GNU General Public License as
14
- * published by the Free Software Foundation.
15
- *
16
- * This program is distributed in the hope that it will be useful, but
17
- * WITHOUT ANY WARRANTY; without even the implied warranty of
18
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
- * General Public License for more details.
20
- *
21
- * You should have received a copy of the GNU General Public License
22
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
23
- * The full GNU General Public License is included in this distribution
24
- * in the file called COPYING.
25
- *
26
- * BSD LICENSE
27
- *
28
- * Copyright (c) 2016 BayLibre, SAS.
29
- * Author: Neil Armstrong <narmstrong@baylibre.com>
30
- *
31
- * Redistribution and use in source and binary forms, with or without
32
- * modification, are permitted provided that the following conditions
33
- * are met:
34
- *
35
- * * Redistributions of source code must retain the above copyright
36
- * notice, this list of conditions and the following disclaimer.
37
- * * Redistributions in binary form must reproduce the above copyright
38
- * notice, this list of conditions and the following disclaimer in
39
- * the documentation and/or other materials provided with the
40
- * distribution.
41
- * * Neither the name of Intel Corporation nor the names of its
42
- * contributors may be used to endorse or promote products derived
43
- * from this software without specific prior written permission.
44
- *
45
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
567 */
578 #include <linux/err.h>
589 #include <linux/init.h>
5910 #include <linux/io.h>
6011 #include <linux/of.h>
12
+#include <linux/module.h>
6113 #include <linux/platform_device.h>
6214 #include <linux/reset-controller.h>
6315 #include <linux/slab.h>
6416 #include <linux/types.h>
6517 #include <linux/of_device.h>
6618
67
-#define REG_COUNT 8
6819 #define BITS_PER_REG 32
69
-#define LEVEL_OFFSET 0x7c
20
+
21
+struct meson_reset_param {
22
+ int reg_count;
23
+ int level_offset;
24
+};
7025
7126 struct meson_reset {
7227 void __iomem *reg_base;
28
+ const struct meson_reset_param *param;
7329 struct reset_controller_dev rcdev;
7430 spinlock_t lock;
7531 };
....@@ -95,9 +51,11 @@
9551 container_of(rcdev, struct meson_reset, rcdev);
9652 unsigned int bank = id / BITS_PER_REG;
9753 unsigned int offset = id % BITS_PER_REG;
98
- void __iomem *reg_addr = data->reg_base + LEVEL_OFFSET + (bank << 2);
54
+ void __iomem *reg_addr;
9955 unsigned long flags;
10056 u32 reg;
57
+
58
+ reg_addr = data->reg_base + data->param->level_offset + (bank << 2);
10159
10260 spin_lock_irqsave(&data->lock, flags);
10361
....@@ -130,12 +88,24 @@
13088 .deassert = meson_reset_deassert,
13189 };
13290
91
+static const struct meson_reset_param meson8b_param = {
92
+ .reg_count = 8,
93
+ .level_offset = 0x7c,
94
+};
95
+
96
+static const struct meson_reset_param meson_a1_param = {
97
+ .reg_count = 3,
98
+ .level_offset = 0x40,
99
+};
100
+
133101 static const struct of_device_id meson_reset_dt_ids[] = {
134
- { .compatible = "amlogic,meson8b-reset" },
135
- { .compatible = "amlogic,meson-gxbb-reset" },
136
- { .compatible = "amlogic,meson-axg-reset" },
102
+ { .compatible = "amlogic,meson8b-reset", .data = &meson8b_param},
103
+ { .compatible = "amlogic,meson-gxbb-reset", .data = &meson8b_param},
104
+ { .compatible = "amlogic,meson-axg-reset", .data = &meson8b_param},
105
+ { .compatible = "amlogic,meson-a1-reset", .data = &meson_a1_param},
137106 { /* sentinel */ },
138107 };
108
+MODULE_DEVICE_TABLE(of, meson_reset_dt_ids);
139109
140110 static int meson_reset_probe(struct platform_device *pdev)
141111 {
....@@ -151,12 +121,16 @@
151121 if (IS_ERR(data->reg_base))
152122 return PTR_ERR(data->reg_base);
153123
124
+ data->param = of_device_get_match_data(&pdev->dev);
125
+ if (!data->param)
126
+ return -ENODEV;
127
+
154128 platform_set_drvdata(pdev, data);
155129
156130 spin_lock_init(&data->lock);
157131
158132 data->rcdev.owner = THIS_MODULE;
159
- data->rcdev.nr_resets = REG_COUNT * BITS_PER_REG;
133
+ data->rcdev.nr_resets = data->param->reg_count * BITS_PER_REG;
160134 data->rcdev.ops = &meson_reset_ops;
161135 data->rcdev.of_node = pdev->dev.of_node;
162136
....@@ -170,4 +144,8 @@
170144 .of_match_table = meson_reset_dt_ids,
171145 },
172146 };
173
-builtin_platform_driver(meson_reset_driver);
147
+module_platform_driver(meson_reset_driver);
148
+
149
+MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver");
150
+MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
151
+MODULE_LICENSE("Dual BSD/GPL");