reset-meson.c (2c138ee3354f8088769d05701a2e16d1cb4cc22d) reset-meson.c (c38ae95cd31c636ae21fff3e6a9250df680f0cdd)
1// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2/*
3 * Amlogic Meson Reset Controller driver
4 *
1// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2/*
3 * Amlogic Meson Reset Controller driver
4 *
5 * Copyright (c) 2016 BayLibre, SAS.
6 * Author: Neil Armstrong <narmstrong@baylibre.com>
5 * Copyright (c) 2016-2024 BayLibre, SAS.
6 * Authors: Neil Armstrong <narmstrong@baylibre.com>
7 * Jerome Brunet <jbrunet@baylibre.com>
7 */
8 */
9
8#include <linux/err.h>
10#include <linux/err.h>
9#include <linux/init.h>
10#include <linux/io.h>
11#include <linux/of.h>
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/regmap.h>
15#include <linux/reset-controller.h>
11#include <linux/io.h>
12#include <linux/of.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/regmap.h>
16#include <linux/reset-controller.h>
16#include <linux/slab.h>
17#include <linux/types.h>
18
17
19struct meson_reset_param {
20 unsigned int reset_num;
21 unsigned int reset_offset;
22 unsigned int level_offset;
23 bool level_low_reset;
24};
18#include "reset-meson.h"
25
19
26struct meson_reset {
27 const struct meson_reset_param *param;
28 struct reset_controller_dev rcdev;
29 struct regmap *map;
30};
31
32static void meson_reset_offset_and_bit(struct meson_reset *data,
33 unsigned long id,
34 unsigned int *offset,
35 unsigned int *bit)
36{
37 unsigned int stride = regmap_get_reg_stride(data->map);
38
39 *offset = (id / (stride * BITS_PER_BYTE)) * stride;
40 *bit = id % (stride * BITS_PER_BYTE);
41}
42
43static int meson_reset_reset(struct reset_controller_dev *rcdev,
44 unsigned long id)
45{
46 struct meson_reset *data =
47 container_of(rcdev, struct meson_reset, rcdev);
48 unsigned int offset, bit;
49
50 meson_reset_offset_and_bit(data, id, &offset, &bit);
51 offset += data->param->reset_offset;
52
53 return regmap_write(data->map, offset, BIT(bit));
54}
55
56static int meson_reset_level(struct reset_controller_dev *rcdev,
57 unsigned long id, bool assert)
58{
59 struct meson_reset *data =
60 container_of(rcdev, struct meson_reset, rcdev);
61 unsigned int offset, bit;
62
63 meson_reset_offset_and_bit(data, id, &offset, &bit);
64 offset += data->param->level_offset;
65 assert ^= data->param->level_low_reset;
66
67 return regmap_update_bits(data->map, offset,
68 BIT(bit), assert ? BIT(bit) : 0);
69}
70
71static int meson_reset_status(struct reset_controller_dev *rcdev,
72 unsigned long id)
73{
74 struct meson_reset *data =
75 container_of(rcdev, struct meson_reset, rcdev);
76 unsigned int val, offset, bit;
77
78 meson_reset_offset_and_bit(data, id, &offset, &bit);
79 offset += data->param->level_offset;
80
81 regmap_read(data->map, offset, &val);
82 val = !!(BIT(bit) & val);
83
84 return val ^ data->param->level_low_reset;
85}
86
87static int meson_reset_assert(struct reset_controller_dev *rcdev,
88 unsigned long id)
89{
90 return meson_reset_level(rcdev, id, true);
91}
92
93static int meson_reset_deassert(struct reset_controller_dev *rcdev,
94 unsigned long id)
95{
96 return meson_reset_level(rcdev, id, false);
97}
98
99static const struct reset_control_ops meson_reset_ops = {
100 .reset = meson_reset_reset,
101 .assert = meson_reset_assert,
102 .deassert = meson_reset_deassert,
103 .status = meson_reset_status,
104};
105
106static const struct meson_reset_param meson8b_param = {
107 .reset_num = 256,
108 .reset_offset = 0x0,
109 .level_offset = 0x7c,
110 .level_low_reset = true,
111};
112
113static const struct meson_reset_param meson_a1_param = {

--- 32 unchanged lines hidden (view full) ---

146static const struct regmap_config regmap_config = {
147 .reg_bits = 32,
148 .val_bits = 32,
149 .reg_stride = 4,
150};
151
152static int meson_reset_probe(struct platform_device *pdev)
153{
20static const struct meson_reset_param meson8b_param = {
21 .reset_num = 256,
22 .reset_offset = 0x0,
23 .level_offset = 0x7c,
24 .level_low_reset = true,
25};
26
27static const struct meson_reset_param meson_a1_param = {

--- 32 unchanged lines hidden (view full) ---

60static const struct regmap_config regmap_config = {
61 .reg_bits = 32,
62 .val_bits = 32,
63 .reg_stride = 4,
64};
65
66static int meson_reset_probe(struct platform_device *pdev)
67{
68 const struct meson_reset_param *param;
154 struct device *dev = &pdev->dev;
69 struct device *dev = &pdev->dev;
155 struct meson_reset *data;
70 struct regmap *map;
156 void __iomem *base;
157
71 void __iomem *base;
72
158 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
159 if (!data)
160 return -ENOMEM;
161
162 base = devm_platform_ioremap_resource(pdev, 0);
163 if (IS_ERR(base))
164 return PTR_ERR(base);
165
73 base = devm_platform_ioremap_resource(pdev, 0);
74 if (IS_ERR(base))
75 return PTR_ERR(base);
76
166 data->param = device_get_match_data(dev);
167 if (!data->param)
77 param = device_get_match_data(dev);
78 if (!param)
168 return -ENODEV;
169
79 return -ENODEV;
80
170 data->map = devm_regmap_init_mmio(dev, base, &regmap_config);
171 if (IS_ERR(data->map))
172 return dev_err_probe(dev, PTR_ERR(data->map),
81 map = devm_regmap_init_mmio(dev, base, &regmap_config);
82 if (IS_ERR(map))
83 return dev_err_probe(dev, PTR_ERR(map),
173 "can't init regmap mmio region\n");
174
84 "can't init regmap mmio region\n");
85
175 data->rcdev.owner = THIS_MODULE;
176 data->rcdev.nr_resets = data->param->reset_num;
177 data->rcdev.ops = &meson_reset_ops;
178 data->rcdev.of_node = dev->of_node;
179
180 return devm_reset_controller_register(dev, &data->rcdev);
86 return meson_reset_controller_register(dev, map, param);
181}
182
183static struct platform_driver meson_reset_driver = {
184 .probe = meson_reset_probe,
185 .driver = {
186 .name = "meson_reset",
187 .of_match_table = meson_reset_dt_ids,
188 },
189};
190module_platform_driver(meson_reset_driver);
191
192MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver");
193MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
87}
88
89static struct platform_driver meson_reset_driver = {
90 .probe = meson_reset_probe,
91 .driver = {
92 .name = "meson_reset",
93 .of_match_table = meson_reset_dt_ids,
94 },
95};
96module_platform_driver(meson_reset_driver);
97
98MODULE_DESCRIPTION("Amlogic Meson Reset Controller driver");
99MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
100MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
194MODULE_LICENSE("Dual BSD/GPL");
101MODULE_LICENSE("Dual BSD/GPL");
102MODULE_IMPORT_NS(MESON_RESET);