Skip to contentSkip to conversation

regulator: event: Add regulator netlink event support

PATCH Superseded Naresh Solanki 2 participants 4 messages Nov 28, 2023 – Dec 6, 2023 Voltage and current regulator framework

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 regulator: event: Add regulator netlink event support

This commit introduces netlink event support to the regulator subsystem.

Changes:
- Introduce event.c and regnl.h for netlink event handling.
- Implement reg_generate_netlink_event to broadcast regulator events.
- Update Makefile to include the new event.c file.

---
Chagnes in V3:
- Add Kconfig option REGULATOR_NETLINK_EVENTS for regulator netlink support
- Add mechanism to avoid regulator name duplication
- Add UAPI header for regulator with define's for regulator events & netlink.

---
 drivers/regulator/Kconfig          | 10 ++++
 drivers/regulator/Makefile         |  1 +
 drivers/regulator/core.c           | 19 ++++++-
 drivers/regulator/event.c          | 86 ++++++++++++++++++++++++++++++
 drivers/regulator/regnl.h          |  8 +++
 include/linux/regulator/consumer.h | 47 +---------------
 include/uapi/regulator/regulator.h | 85 +++++++++++++++++++++++++++++
 7 files changed, 209 insertions(+), 47 deletions(-)
 create mode 100644 drivers/regulator/event.c
 create mode 100644 drivers/regulator/regnl.h
 create mode 100644 include/uapi/regulator/regulator.h
drivers/regulator/Kconfig +10 -0
index f3ec24691378..00d3898ee599 100644
@@ -56,6 +56,16 @@ config REGULATOR_USERSPACE_CONSUMER
 
 	  If unsure, say no.
 
+config REGULATOR_NETLINK_EVENTS
+	tristate "Enable support for receiving regulator events via netlink"
+	depends on NET
+	help
+	  Enabling this option allows the kernel to broadcast regulator events using
+	  the netlink mechanism. User-space applications can subscribe to these events
+	  for real-time updates on various regulator events.
+
+	  If unsure, say no.
+
 config REGULATOR_88PG86X
 	tristate "Marvell 88PG86X voltage regulators"
 	depends on I2C
drivers/regulator/Makefile +1 -0
index b2b059b5ee56..46fb569e6be8 100644
@@ -5,6 +5,7 @@
 
 
 obj-$(CONFIG_REGULATOR) += core.o dummy.o fixed-helper.o helpers.o devres.o irq_helpers.o
+obj-$(CONFIG_REGULATOR_NETLINK_EVENTS) += event.o
 obj-$(CONFIG_OF) += of_regulator.o
 obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
drivers/regulator/core.c +18 -1
index 4aa9ec8c22f3..a968dabb48f5 100644
@@ -33,6 +33,7 @@
 
 #include "dummy.h"
 #include "internal.h"
+#include "regnl.h"
 
 static DEFINE_WW_CLASS(regulator_ww_class);
 static DEFINE_MUTEX(regulator_nesting_mutex);
@@ -4854,7 +4855,23 @@ static int _notifier_call_chain(struct regulator_dev *rdev,
 				  unsigned long event, void *data)
 {
 	/* call rdev chain first */
-	return blocking_notifier_call_chain(&rdev->notifier, event, data);
+	int ret =  blocking_notifier_call_chain(&rdev->notifier, event, data);
+
+	if (IS_REACHABLE(CONFIG_REGULATOR_NETLINK_EVENTS)) {
+		struct device *parent = rdev->dev.parent;
+		const char *rname = rdev_get_name(rdev);
+		char name[32];
+
+		/* Avoid duplicate debugfs directory names */
+		if (parent && rname == rdev->desc->name) {
+			snprintf(name, sizeof(name), "%s-%s", dev_name(parent),
+				 rname);
+			rname = name;
+		}
+		reg_generate_netlink_event(rname, event);
+	}
+
+	return ret;
 }
 
 int _regulator_bulk_get(struct device *dev, int num_consumers,
drivers/regulator/event.c new file +86 -0

86 lines not on this page · raw message

drivers/regulator/regnl.h new file +8 -0
new file mode 100644
index 000000000000..0b27972bd523
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __REGULATOR_EVENT_H
+#define __REGULATOR_EVENT_H
+
+int reg_generate_netlink_event(const char *reg_name, u64 event);
+
+#endif
include/linux/regulator/consumer.h +1 -46

59 lines not on this page · raw message

include/uapi/regulator/regulator.h new file +85 -0

85 lines not on this page · raw message

base-commit: 753e4d5c433da57da75dd4c3e1aececc8e874a62

Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 6 lines · Naresh Solanki

This commit introduces netlink event support to the regulator subsystem.

Changes:
- Introduce event.c and regnl.h for netlink event handling.
- Implement reg_generate_netlink_event to broadcast regulator events.
- Update Makefile to include the new event.c file.

This looks good however it breaks an allmodconfig build:

ERROR: modpost: missing MODULE_LICENSE() in drivers/regulator/event.o

drivers/regulator/Kconfig config REGULATOR_USERSPACE_CONSUMER · line 61

Quoted 3 lines
drivers/regulator/Kconfig +3 -0
+config REGULATOR_NETLINK_EVENTS
+	tristate "Enable support for receiving regulator events via netlink"
+	depends on NET

I think this needs to be a bool (NET is a bool so there's no dependency issues there hopefully).

Thanks for pushing this forwards.

#2 lore raw

Hi

Quoted 11 lines · Mark Brown
Quoted 6 lines · Naresh Solanki

This commit introduces netlink event support to the regulator subsystem.

Changes:
- Introduce event.c and regnl.h for netlink event handling.
- Implement reg_generate_netlink_event to broadcast regulator events.
- Update Makefile to include the new event.c file.

This looks good however it breaks an allmodconfig build:

Quoted 8 lines

ERROR: modpost: missing MODULE_LICENSE() in drivers/regulator/event.o

drivers/regulator/Kconfig config REGULATOR_USERSPACE_CONSUMER · line 61

Quoted 3 lines
drivers/regulator/Kconfig +3 -0
+config REGULATOR_NETLINK_EVENTS
+     tristate "Enable support for receiving regulator events via netlink"
+     depends on NET

I think this needs to be a bool (NET is a bool so there's no dependency issues there hopefully).

Thanks for pointing this out. I missed testing build with allmodconfig. As suggested, after updating Kconfig from tristate to bool this issue got resolved.

Will push v4 with the fix.

Regards,
Naresh

Quoted 2 lines

Thanks for pushing this forwards.

maintainer
#3 lore raw
In reply to Naresh Solanki
Quoted 8 lines · Naresh Solanki

This commit introduces netlink event support to the regulator subsystem.

Changes:
- Introduce event.c and regnl.h for netlink event handling.
- Implement reg_generate_netlink_event to broadcast regulator events.
- Update Makefile to include the new event.c file.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next

Thanks!

[1/1] regulator: event: Add regulator netlink event support

      commit: 16e5ac127d8d18adf85fe5ba847d77b58d1ed418

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark