[RFC v1 2/4] regulator: core: Add sysfs class backward compatibility
From: Saravana Kannan
Date: Sat Feb 18 2023 - 03:33:10 EST
A regulator device's sysfs directory used to be created under
/sys/class/regulator when it is added to a class. Since the device is
now moved to be under a bus, add symlinks from /sys/class/regulator to
the real device sysfs directory.
Signed-off-by: Saravana Kannan <saravanak@xxxxxxxxxx>
---
drivers/regulator/core.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 1a212edcf216..b6700d50d230 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -43,6 +43,7 @@ static LIST_HEAD(regulator_coupler_list);
static bool has_full_constraints;
static struct dentry *debugfs_root;
+static struct class_compat *regulator_compat_class;
/*
* struct regulator_map
@@ -5636,6 +5637,11 @@ regulator_register(struct device *dev,
if (ret != 0)
goto unset_supplies;
+ if (class_compat_create_link(regulator_compat_class, &rdev->dev,
+ rdev->dev.parent))
+ dev_warn(&rdev->dev,
+ "Failed to create compatibility class link\n");
+
rdev_init_debugfs(rdev);
/* try to resolve regulators coupling since a new one was registered */
@@ -5702,6 +5708,8 @@ void regulator_unregister(struct regulator_dev *rdev)
unset_regulator_supplies(rdev);
list_del(&rdev->list);
regulator_ena_gpio_free(rdev);
+ class_compat_remove_link(regulator_compat_class, &rdev->dev,
+ rdev->dev.parent);
device_unregister(&rdev->dev);
mutex_unlock(®ulator_list_mutex);
@@ -6107,7 +6115,13 @@ static int __init regulator_init(void)
{
int ret;
+ regulator_compat_class = class_compat_register("regulator");
+ if (!regulator_compat_class)
+ return -ENOMEM;
+
ret = bus_register(®ulator_bus);
+ if (ret)
+ goto unreg_compat;
debugfs_root = debugfs_create_dir("regulator", NULL);
if (!debugfs_root)
@@ -6120,11 +6134,16 @@ static int __init regulator_init(void)
debugfs_create_file("regulator_summary", 0444, debugfs_root,
NULL, ®ulator_summary_fops);
#endif
+
regulator_dummy_init();
regulator_coupler_register(&generic_regulator_coupler);
return ret;
+
+unreg_compat:
+ class_compat_unregister(regulator_compat_class);
+ return ret;
}
/* init early to allow our consumers to complete system booting */
--
2.39.2.637.g21b0678d19-goog