Skip to contentSkip to conversation

1-wire: in-kernel notification on device events

PATCH In review Sergey Yanovich 2 participants 2 messages Mar 22, 2013 – Mar 29, 2013 W1 dallas's 1-wire bus

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 1-wire: in-kernel notification on device events

Before this patch 1-wire subsystem didn't provide access to its add/remove events to other parts of the kernel. Now it is possible to register a standard notifier_block observer, which will be informed of subsequent device insertions and removals.

The framework is copied from USB subsystem.

---
 drivers/w1/Kconfig      |    7 ++
 drivers/w1/Makefile     |    3 +-
 drivers/w1/notify.c     |   76 ++++++++++++++++++++
 drivers/w1/w1.c         |    2 +
 drivers/w1/w1.h         |  160 ++++--------------------------------------
 drivers/w1/w1_int.c     |    2 +
 drivers/w1/w1_netlink.h |   11 +--
 include/linux/w1.h      |  176 +++++++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 279 insertions(+), 158 deletions(-)
 create mode 100644 drivers/w1/notify.c
 create mode 100644 include/linux/w1.h
drivers/w1/Kconfig +7 -0
index 6743bde..d33d074 100644
@@ -25,6 +25,13 @@ config W1_CON
 	  2. Userspace commands. Includes read/write and search/alarm search commands.
 	  3. Replies to userspace commands.
 
+config W1_NOTIFY
+	bool "Dallas's 1-wire device notifications"
+	default n
+	---help---
+	  This allows other parts of kernel to be notified of 1-wire hotplug
+	  events.
+
 source drivers/w1/masters/Kconfig
 source drivers/w1/slaves/Kconfig
 
drivers/w1/Makefile +2 -1
index 6bb0b54..233ec84 100644
@@ -3,7 +3,8 @@
 #
 
 obj-$(CONFIG_W1)	+= wire.o
-wire-objs		:= w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o
+wire-objs		:= w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o \
+			notify.o
 
 obj-y			+= masters/ slaves/
 
drivers/w1/notify.c new file +76 -0

76 lines not on this page · raw message

drivers/w1/w1.c +2 -0
index 7994d933..f546005 100644
@@ -709,6 +709,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
 	memcpy(msg.id.id, rn, sizeof(msg.id));
 	msg.type = W1_SLAVE_ADD;
 	w1_netlink_send(dev, &msg);
+	w1_notify_add_slave(sl);
 
 	return 0;
 }
@@ -728,6 +729,7 @@ void w1_slave_detach(struct w1_slave *sl)
 	memcpy(msg.id.id, &sl->reg_num, sizeof(msg.id));
 	msg.type = W1_SLAVE_REMOVE;
 	w1_netlink_send(sl->master, &msg);
+	w1_notify_remove_slave(sl);
 
 	device_remove_file(&sl->dev, &w1_slave_attr_id);
 	device_remove_file(&sl->dev, &w1_slave_attr_name);
drivers/w1/w1.h +13 -147

186 lines not on this page · raw message

drivers/w1/w1_int.c +2 -0
index 5a98649..279dacb 100644
@@ -179,6 +179,7 @@ int w1_add_master_device(struct w1_bus_master *master)
 	msg.id.mst.id = dev->id;
 	msg.type = W1_MASTER_ADD;
 	w1_netlink_send(dev, &msg);
+	w1_notify_add_master(dev);
 
 	return 0;
 
@@ -224,6 +225,7 @@ void __w1_remove_master_device(struct w1_master *dev)
 	msg.id.mst.id = dev->id;
 	msg.type = W1_MASTER_REMOVE;
 	w1_netlink_send(dev, &msg);
+	w1_notify_remove_master(dev);
 
 	w1_free_dev(dev);
 }
drivers/w1/w1_netlink.h +1 -10
index b0922dc..ef4b0fb 100644
@@ -25,18 +25,9 @@
 #include <asm/types.h>
 #include <linux/connector.h>
 
+#include <linux/w1.h>
 #include "w1.h"
 
-enum w1_netlink_message_types {
-	W1_SLAVE_ADD = 0,
-	W1_SLAVE_REMOVE,
-	W1_MASTER_ADD,
-	W1_MASTER_REMOVE,
-	W1_MASTER_CMD,
-	W1_SLAVE_CMD,
-	W1_LIST_MASTERS,
-};
-
 struct w1_netlink_msg
 {
 	__u8				type;
include/linux/w1.h new file +176 -0

176 lines not on this page · raw message

Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sergey Yanovich

Before this patch 1-wire subsystem didn't provide access to its add/remove events to other parts of the kernel. Now it is possible to register a standard notifier_block observer, which will be informed of subsequent device insertions and removals.

The framework is copied from USB subsystem.

Thanks Sergey, patch looks good to me

Greg, please pull it into your tree.
Thank you

Signature · 1 line
	Evgeniy Polyakov