[RFC/PATCH 21/22] W1: implement standard hotplug handler
From: Dmitry Torokhov
Date: Thu Apr 21 2005 - 03:43:19 EST
Ahem.. Kmail just refuses send this on inline... Sorry.
--
Dmitry
W1: implement W1 bus hotplug handler. Slave devices will define
FID (family ID) end SN (serial number) environment variables.
Signed-off-by: Dmitry Torokhov <dtor@xxxxxxx>
---
w1.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 44 insertions(+), 7 deletions(-)
Index: dtor/drivers/w1/w1.c
===================================================================
--- dtor.orig/drivers/w1/w1.c
+++ dtor/drivers/w1/w1.c
@@ -50,6 +50,10 @@ module_param_named(scan_interval, w1_sca
module_param_named(max_slave_count, w1_max_slave_count, int, 0);
module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
+struct device_driver w1_master_driver = {
+ .name = "master",
+};
+
static int w1_bus_match(struct device *dev, struct device_driver *drv)
{
/*
@@ -67,14 +71,46 @@ static int w1_bus_match(struct device *d
return 0;
}
-static struct bus_type w1_bus_type = {
- .name = "w1",
- .match = w1_bus_match,
-};
+#ifdef CONFIG_HOTPLUG
+static int w1_hotplug(struct device *dev, char **envp, int num_envp,
+ char *buffer, int buffer_size)
+{
+ struct w1_slave *slave;
+ int i = 0;
+ int len = 0;
-struct device_driver w1_master_driver = {
- .name = "master",
- .bus = &w1_bus_type,
+ if (!dev)
+ return -ENODEV;
+
+ if (dev->driver == &w1_master_driver)
+ return 0;
+
+ slave = to_w1_slave(dev);
+
+ if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &len,
+ "FID=%02X", slave->reg_num.family))
+ return -ENOMEM;
+
+ if (add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &len,
+ "SN=%024llX", slave->reg_num.id))
+ return -ENOMEM;
+
+ envp[i] = NULL;
+
+ return 0;
+}
+#else
+static int w1_hotplug(struct device *dev, char **envp, int num_envp,
+ char *buffer, int buffer_size)
+{
+ return -ENODEV;
+}
+#endif /* CONFIG_HOTPLUG */
+
+static struct bus_type w1_bus_type = {
+ .name = "w1",
+ .match = w1_bus_match,
+ .hotplug = w1_hotplug,
};
static ssize_t w1_slave_attribute_show_family(struct device *dev, char *buf)
@@ -541,6 +577,7 @@ static int w1_init(void)
return error;
}
+ w1_master_driver.bus = &w1_bus_type;
error = driver_register(&w1_master_driver);
if (error) {
printk(KERN_ERR