[PATCH 6/8] reset: amlogic: add toggle reset support

From: Jerome Brunet
Date: Wed Jul 10 2024 - 12:26:55 EST


Add the emulation for the reset callback using level reset if reset is not
directly supported. This is done to keep the functionality of reset
driver of audio clock controller. This is expected to work by the related
reset consumers.

Signed-off-by: Jerome Brunet <jbrunet@xxxxxxxxxxxx>
---
drivers/reset/reset-meson.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c
index 65ba9190cb53..e34a10b15593 100644
--- a/drivers/reset/reset-meson.c
+++ b/drivers/reset/reset-meson.c
@@ -17,6 +17,7 @@
#include <linux/types.h>

struct meson_reset_param {
+ const struct reset_control_ops *reset_ops;
unsigned int reset_num;
int reset_offset;
int level_offset;
@@ -98,6 +99,18 @@ static int meson_reset_deassert(struct reset_controller_dev *rcdev,
return meson_reset_level(rcdev, id, false);
}

+static int meson_reset_level_toggle(struct reset_controller_dev *rcdev,
+ unsigned long id)
+{
+ int ret;
+
+ ret = meson_reset_assert(rcdev, id);
+ if (ret)
+ return ret;
+
+ return meson_reset_deassert(rcdev, id);
+}
+
static const struct reset_control_ops meson_reset_ops = {
.reset = meson_reset_reset,
.assert = meson_reset_assert,
@@ -105,6 +118,13 @@ static const struct reset_control_ops meson_reset_ops = {
.status = meson_reset_status,
};

+static const struct reset_control_ops meson_reset_toggle_ops = {
+ .reset = meson_reset_level_toggle,
+ .assert = meson_reset_assert,
+ .deassert = meson_reset_deassert,
+ .status = meson_reset_status,
+};
+
static int meson_reset_probe(struct device *dev, struct regmap *map,
const struct meson_reset_param *param)
{
@@ -118,13 +138,14 @@ static int meson_reset_probe(struct device *dev, struct regmap *map,
data->map = map;
data->rcdev.owner = dev->driver->owner;
data->rcdev.nr_resets = param->reset_num;
- data->rcdev.ops = &meson_reset_ops;
+ data->rcdev.ops = param->reset_ops;
data->rcdev.of_node = dev->of_node;

return devm_reset_controller_register(dev, &data->rcdev);
}

static const struct meson_reset_param meson8b_param = {
+ .reset_ops = &meson_reset_ops,
.reset_num = 256,
.reset_offset = 0x0,
.level_offset = 0x7c,
@@ -132,6 +153,7 @@ static const struct meson_reset_param meson8b_param = {
};

static const struct meson_reset_param meson_a1_param = {
+ .reset_ops = &meson_reset_ops,
.reset_num = 96,
.reset_offset = 0x0,
.level_offset = 0x40,
@@ -139,6 +161,7 @@ static const struct meson_reset_param meson_a1_param = {
};

static const struct meson_reset_param meson_s4_param = {
+ .reset_ops = &meson_reset_ops,
.reset_num = 192,
.reset_offset = 0x0,
.level_offset = 0x40,
--
2.43.0