[RFC PATCH 2/4] reset: Allow removing a lookup

From: Tony Lindgren
Date: Thu Apr 11 2024 - 01:24:15 EST


If a parent device provides resets for the child devices using a lookup
table, let's also allow removal of the lookup table when removing the
child devices.

Signed-off-by: Tony Lindgren <tony@xxxxxxxxxxx>
---
drivers/reset/core.c | 27 +++++++++++++++++++++++++++
include/linux/reset-controller.h | 7 +++++++
2 files changed, 34 insertions(+)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -217,6 +217,33 @@ void reset_controller_add_lookup(struct reset_control_lookup *lookup,
}
EXPORT_SYMBOL_GPL(reset_controller_add_lookup);

+/**
+ * reset_controller_remove_lookup - unregister a set of lookup entries
+ * @lookup: array of reset lookup entries
+ * @num_entries: number of entries in the lookup array
+ */
+void reset_controller_remove_lookup(struct reset_control_lookup *lookup,
+ unsigned int num_entries)
+{
+ struct reset_control_lookup *entry;
+ unsigned int i;
+
+ mutex_lock(&reset_lookup_mutex);
+ for (i = 0; i < num_entries; i++) {
+ entry = &lookup[i];
+
+ if (!entry->dev_id || !entry->provider) {
+ pr_warn("%s(): reset lookup entry badly specified, skipping\n",
+ __func__);
+ continue;
+ }
+
+ list_del(&entry->list);
+ }
+ mutex_unlock(&reset_lookup_mutex);
+}
+EXPORT_SYMBOL_GPL(reset_controller_remove_lookup);
+
static inline struct reset_control_array *
rstc_to_array(struct reset_control *rstc) {
return container_of(rstc, struct reset_control_array, base);
diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h
--- a/include/linux/reset-controller.h
+++ b/include/linux/reset-controller.h
@@ -93,6 +93,8 @@ int devm_reset_controller_register(struct device *dev,

void reset_controller_add_lookup(struct reset_control_lookup *lookup,
unsigned int num_entries);
+void reset_controller_remove_lookup(struct reset_control_lookup *lookup,
+ unsigned int num_entries);
#else
static inline int reset_controller_register(struct reset_controller_dev *rcdev)
{
@@ -113,6 +115,11 @@ static inline void reset_controller_add_lookup(struct reset_control_lookup *look
unsigned int num_entries)
{
}
+
+static inline void reset_controller_remove_lookup(struct reset_control_lookup *lookup,
+ unsigned int num_entries)
+{
+}
#endif

#endif
--
2.44.0