Skip to contentSkip to conversation

W1: u64 is not long long

PATCH New Greg KH 1 participant 6 messages Mar 24, 2006 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Greg KH

author
#1 lore raw

PATCH 3/8 W1: Add the DS2482 I2C-to-w1 bridge driver.

---

 Documentation/w1/masters/ds2482 |   31 ++
 drivers/w1/masters/Kconfig      |   10 +
 drivers/w1/masters/Makefile     |    2 
 drivers/w1/masters/ds2482.c     |  564 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 607 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/w1/masters/ds2482
 create mode 100644 drivers/w1/masters/ds2482.c

baf12ae29ab4cc6381e21b2e1a3af75a6a8f7566

Documentation/w1/masters/ds2482 new file +31 -0
new file mode 100644
index 0000000..c5d5478
@@ -0,0 +1,31 @@
+Kernel driver ds2482
+====================
+
+Supported chips:
+  * Maxim DS2482-100, Maxim DS2482-800
+    Prefix: 'ds2482'
+    Addresses scanned: None
+    Datasheets:
+        http://pdfserv.maxim-ic.com/en/ds/DS2482-100-DS2482S-100.pdf
+        http://pdfserv.maxim-ic.com/en/ds/DS2482-800-DS2482S-800.pdf
+
+Author: Ben Gardner <[email protected]>
+
+
+Description
+-----------
+
+The Maixm/Dallas Semiconductor DS2482 is a I2C device that provides
+one (DS2482-100) or eight (DS2482-800) 1-wire busses.
+
+
+General Remarks
+---------------
+
+Valid addresses are 0x18, 0x19, 0x1a, and 0x1b.
+However, the device cannot be detected without writing to the i2c bus, so no
+detection is done.
+You should force the device address.
+
+$ modprobe ds2482 force=0,0x18
+
drivers/w1/masters/Kconfig +10 -0
index 51bd64d..1ff11b5 100644
@@ -34,5 +34,15 @@ config W1_MASTER_DS9490_BRIDGE
 	  This support is also available as a module.  If so, the module
 	  will be called ds_w1_bridge.ko.
 
+config W1_MASTER_DS2482
+	tristate "Maxim DS2482 I2C to 1-Wire bridge"
+	depends on I2C && W1 && EXPERIMENTAL
+	help
+	  If you say yes here you get support for the Maxim DS2482
+	  I2C to 1-Wire bridge.
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called ds2482.
+
 endmenu
 
drivers/w1/masters/Makefile +2 -0
index d9b84e5..1f3c8b9 100644
@@ -9,3 +9,5 @@ ds9490r-objs    := dscore.o
 
 obj-$(CONFIG_W1_MASTER_DS9490_BRIDGE)	+= ds_w1_bridge.o
 
+obj-$(CONFIG_W1_MASTER_DS2482)		+= ds2482.o
+
drivers/w1/masters/ds2482.c new file +564 -0

564 lines not on this page · raw message

Signature · 1 line
1.2.4
author
#2 lore raw

PATCH 4/8 w1: misc cleanups

This patch contains the following cleanups:
- make needlessly global code static
- declarations for global code belong into header files
- w1.c: #if 0 the unused struct w1_slave_device

---

 drivers/w1/w1.c        |    6 ++++--
 drivers/w1/w1.h        |   10 ++++++++++
 drivers/w1/w1_family.c |    2 +-
 drivers/w1/w1_int.c    |   13 ++-----------
 drivers/w1/w1_io.c     |    2 +-
 5 files changed, 18 insertions(+), 15 deletions(-)

a9fb1c7b950bed4afe208c9d67e20f086bb6abbb

drivers/w1/w1.c +4 -2
index f0b47fe..5def7fb 100644
@@ -164,11 +164,12 @@ struct device w1_master_device = {
 	.release = &w1_master_release
 };
 
-struct device_driver w1_slave_driver = {
+static struct device_driver w1_slave_driver = {
 	.name = "w1_slave_driver",
 	.bus = &w1_bus_type,
 };
 
+#if 0
 struct device w1_slave_device = {
 	.parent = NULL,
 	.bus = &w1_bus_type,
@@ -176,6 +177,7 @@ struct device w1_slave_device = {
 	.driver = &w1_slave_driver,
 	.release = &w1_slave_release
 };
+#endif  /*  0  */
 
 static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -355,7 +357,7 @@ int w1_create_master_attributes(struct w
 	return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group);
 }
 
-void w1_destroy_master_attributes(struct w1_master *master)
+static void w1_destroy_master_attributes(struct w1_master *master)
 {
 	sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
 }
drivers/w1/w1.h +10 -0
index b62e771..5f09213 100644
@@ -203,6 +203,16 @@ static inline struct w1_master* dev_to_w
 	return container_of(dev, struct w1_master, dev);
 }
 
+extern int w1_max_slave_count;
+extern int w1_max_slave_ttl;
+extern spinlock_t w1_mlock;
+extern struct list_head w1_masters;
+extern struct device_driver w1_master_driver;
+extern struct device w1_master_device;
+
+int w1_process(void *data);
+void w1_reconnect_slaves(struct w1_family *f);
+
 #endif /* __KERNEL__ */
 
 #endif /* __W1_H */
drivers/w1/w1_family.c +1 -1
index 9e293e1..0e32c11 100644
@@ -25,10 +25,10 @@
 #include <linux/delay.h>
 
 #include "w1_family.h"
+#include "w1.h"
 
 DEFINE_SPINLOCK(w1_flock);
 static LIST_HEAD(w1_families);
-extern void w1_reconnect_slaves(struct w1_family *f);
 
 int w1_register_family(struct w1_family *newf)
 {
drivers/w1/w1_int.c +2 -11
index c3f67ea..4724693 100644
@@ -26,19 +26,10 @@
 #include "w1.h"
 #include "w1_log.h"
 #include "w1_netlink.h"
+#include "w1_int.h"
 
 static u32 w1_ids = 1;
 
-extern struct device_driver w1_master_driver;
-extern struct bus_type w1_bus_type;
-extern struct device w1_master_device;
-extern int w1_max_slave_count;
-extern int w1_max_slave_ttl;
-extern struct list_head w1_masters;
-extern spinlock_t w1_mlock;
-
-extern int w1_process(void *);
-
 static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
 				       struct device_driver *driver,
 				       struct device *device)
@@ -103,7 +94,7 @@ static struct w1_master * w1_alloc_dev(u
 	return dev;
 }
 
-void w1_free_dev(struct w1_master *dev)
+static void w1_free_dev(struct w1_master *dev)
 {
 	device_unregister(&dev->dev);
 }
drivers/w1/w1_io.c +1 -1
index e2a0433..f7f7e8b 100644
@@ -28,7 +28,7 @@
 #include "w1_log.h"
 #include "w1_io.h"
 
-int w1_delay_parm = 1;
+static int w1_delay_parm = 1;
 module_param_named(delay_coef, w1_delay_parm, int, 0);
 
 static u8 w1_crc8_table[] = {
Signature · 1 line
1.2.4
author
#3 lore raw

PATCH 5/8 fix W1_MASTER_DS9490_BRIDGE dependencies

W1_DS9490 was renamed to W1_MASTER_DS9490, but the entry in the dependencies of W1_MASTER_DS9490_BRIDGE was forgotten.

---

 drivers/w1/masters/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

ec068072f0e8499cfe7b71749b4a63c503e7d328

drivers/w1/masters/Kconfig +1 -1
index 1ff11b5..c6bad4d 100644
@@ -26,7 +26,7 @@ config W1_MASTER_DS9490
 
 config W1_MASTER_DS9490_BRIDGE
 	tristate "DS9490R USB <-> W1 transport layer for 1-wire"
-	depends on W1_DS9490
+	depends on W1_MASTER_DS9490
 	help
 	  Say Y here if you want to communicate with your 1-wire devices
 	  using DS9490R USB bridge.
Signature · 1 line
1.2.4
author
#4 lore raw

PATCH 6/8 W1: Remove incorrect MODULE_ALIAS

The w1 netlink socket is created by a hardware specific driver calling w1_add_master_device, so there is no point in including a module alias for netlink autoloading in the core.

---

 drivers/w1/w1_int.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

ecd5136c85cb4531a51f65241e7b3cd58420f3ed

drivers/w1/w1_int.c +0 -2
index 4724693..a2f9065 100644
@@ -208,5 +208,3 @@ void w1_remove_master_device(struct w1_b
 
 EXPORT_SYMBOL(w1_add_master_device);
 EXPORT_SYMBOL(w1_remove_master_device);
-
-MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_W1);
Signature · 1 line
1.2.4
author
#5 lore raw

PATCH 7/8 W1: u64 is not long long

You don't know what type a u64 is, hence you cannot print it without a cast.

---

 drivers/w1/w1.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

f73b5e7949945486a649e40821cd351e2f60bf02

drivers/w1/w1.c +5 -2
index 5def7fb..d640c1e 100644
@@ -388,11 +388,14 @@ static int w1_uevent(struct device *dev,
 	if (dev->driver != &w1_slave_driver || !sl)
 		return 0;
 
-	err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_FID=%02X", sl->reg_num.family);
+	err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size,
+			&cur_len, "W1_FID=%02X", sl->reg_num.family);
 	if (err)
 		return err;
 
-	err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size, &cur_len, "W1_SLAVE_ID=%024LX", (u64)sl->reg_num.id);
+	err = add_uevent_var(envp, num_envp, &cur_index, buffer, buffer_size,
+			&cur_len, "W1_SLAVE_ID=%024LX",
+			(unsigned long long)sl->reg_num.id);
 	if (err)
 		return err;
 
Signature · 1 line
1.2.4
author
#6 lore raw

PATCH 8/8 w1: use kthread api.

This patch removes old-style kernel thread initialization and changes w1 to use kthread api.
It is based on Christoph Hellwig <[email protected]> work.

---

 drivers/w1/w1.c     |   56 +++++++++++++++------------------------------------
 drivers/w1/w1.h     |    3 +--
 drivers/w1/w1_int.c |   34 ++++++++++---------------------
 3 files changed, 28 insertions(+), 65 deletions(-)

674a396c6d2ba0341ebdd7c1c9950f32f018e2dd

drivers/w1/w1.c +16 -40
index d640c1e..a698b51 100644
@@ -30,6 +30,7 @@
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/sched.h>
+#include <linux/kthread.h>
 
 #include <asm/atomic.h>
 
@@ -57,9 +58,7 @@ module_param_named(slave_ttl, w1_max_sla
 DEFINE_SPINLOCK(w1_mlock);
 LIST_HEAD(w1_masters);
 
-static pid_t control_thread;
-static int control_needs_exit;
-static DECLARE_COMPLETION(w1_control_complete);
+static struct task_struct *w1_control_thread;
 
 static int w1_master_match(struct device *dev, struct device_driver *drv)
 {
@@ -717,22 +716,16 @@ static int w1_control(void *data)
 {
 	struct w1_slave *sl, *sln;
 	struct w1_master *dev, *n;
-	int err, have_to_wait = 0;
+	int have_to_wait = 0;
 
-	daemonize("w1_control");
-	allow_signal(SIGTERM);
-
-	while (!control_needs_exit || have_to_wait) {
+	while (!kthread_should_stop() || have_to_wait) {
 		have_to_wait = 0;
 
 		try_to_freeze();
 		msleep_interruptible(w1_control_timeout * 1000);
 
-		if (signal_pending(current))
-			flush_signals(current);
-
 		list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) {
-			if (!control_needs_exit && !dev->flags)
+			if (!kthread_should_stop() && !dev->flags)
 				continue;
 			/*
 			 * Little race: we can create thread but not set the flag.
@@ -743,21 +736,12 @@ static int w1_control(void *data)
 				continue;
 			}
 
-			if (control_needs_exit) {
+			if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
 				set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
 
-				err = kill_proc(dev->kpid, SIGTERM, 1);
-				if (err)
-					dev_err(&dev->dev,
-						 "Failed to send signal to w1 kernel thread %d.\n",
-						 dev->kpid);
-			}
-
-			if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
-				wait_for_completion(&dev->dev_exited);
-				spin_lock_bh(&w1_mlock);
+				spin_lock(&w1_mlock);
 				list_del(&dev->w1_master_entry);
-				spin_unlock_bh(&w1_mlock);
+				spin_unlock(&w1_mlock);
 
 				down(&dev->mutex);
 				list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
@@ -789,7 +773,7 @@ static int w1_control(void *data)
 		}
 	}
 
-	complete_and_exit(&w1_control_complete, 0);
+	return 0;
 }
 
 int w1_process(void *data)
@@ -797,17 +781,11 @@ int w1_process(void *data)
 	struct w1_master *dev = (struct w1_master *) data;
 	struct w1_slave *sl, *sln;
 
-	daemonize("%s", dev->name);
-	allow_signal(SIGTERM);
-
-	while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
+	while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
 		try_to_freeze();
 		msleep_interruptible(w1_timeout * 1000);
 
-		if (signal_pending(current))
-			flush_signals(current);
-
-		if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
+		if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags))
 			break;
 
 		if (!dev->initialized)
@@ -840,7 +818,6 @@ int w1_process(void *data)
 	}
 
 	atomic_dec(&dev->refcnt);
-	complete_and_exit(&dev->dev_exited, 0);
 
 	return 0;
 }
@@ -873,11 +850,11 @@ static int w1_init(void)
 		goto err_out_master_unregister;
 	}
 
-	control_thread = kernel_thread(&w1_control, NULL, 0);
-	if (control_thread < 0) {
+	w1_control_thread = kthread_run(w1_control, NULL, "w1_control");
+	if (IS_ERR(w1_control_thread)) {
+		retval = PTR_ERR(w1_control_thread);
 		printk(KERN_ERR "Failed to create control thread. err=%d\n",
-			control_thread);
-		retval = control_thread;
+			retval);
 		goto err_out_slave_unregister;
 	}
 
@@ -903,8 +880,7 @@ static void w1_fini(void)
 	list_for_each_entry(dev, &w1_masters, w1_master_entry)
 		__w1_remove_master_device(dev);
 
-	control_needs_exit = 1;
-	wait_for_completion(&w1_control_complete);
+	kthread_stop(w1_control_thread);
 
 	driver_unregister(&w1_slave_driver);
 	driver_unregister(&w1_master_driver);
drivers/w1/w1.h +1 -2
index 5f09213..5698050 100644
@@ -172,12 +172,11 @@ struct w1_master
 
 	long			flags;
 
-	pid_t			kpid;
+	struct task_struct	*thread;
 	struct semaphore	mutex;
 
 	struct device_driver	*driver;
 	struct device		dev;
-	struct completion	dev_exited;
 
 	struct w1_bus_master	*bus_master;
 
drivers/w1/w1_int.c +11 -23
index a2f9065..68565aa 100644
@@ -22,6 +22,7 @@
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/delay.h>
+#include <linux/kthread.h>
 
 #include "w1.h"
 #include "w1_log.h"
@@ -56,7 +57,6 @@ static struct w1_master * w1_alloc_dev(u
 	dev->max_slave_count	= slave_count;
 	dev->slave_count	= 0;
 	dev->attempts		= 0;
-	dev->kpid		= -1;
 	dev->initialized	= 0;
 	dev->id			= id;
 	dev->slave_ttl		= slave_ttl;
@@ -67,8 +67,6 @@ static struct w1_master * w1_alloc_dev(u
 	INIT_LIST_HEAD(&dev->slist);
 	init_MUTEX(&dev->mutex);
 
-	init_completion(&dev->dev_exited);
-
 	memcpy(&dev->dev, device, sizeof(struct device));
 	snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id),
 		  "w1_bus_master%u", dev->id);
@@ -116,12 +114,12 @@ int w1_add_master_device(struct w1_bus_m
 	if (!dev)
 		return -ENOMEM;
 
-	dev->kpid = kernel_thread(&w1_process, dev, 0);
-	if (dev->kpid < 0) {
+	dev->thread = kthread_run(&w1_process, dev, "%s", dev->name);
+	if (IS_ERR(dev->thread)) {
+		retval = PTR_ERR(dev->thread);
 		dev_err(&dev->dev,
 			 "Failed to create new kernel thread. err=%d\n",
-			 dev->kpid);
-		retval = dev->kpid;
+			 retval);
 		goto err_out_free_dev;
 	}
 
@@ -138,20 +136,14 @@ int w1_add_master_device(struct w1_bus_m
 	spin_unlock(&w1_mlock);
 
 	msg.id.mst.id = dev->id;
-	msg.id.mst.pid = dev->kpid;
+	msg.id.mst.pid = dev->thread->pid;
 	msg.type = W1_MASTER_ADD;
 	w1_netlink_send(dev, &msg);
 
 	return 0;
 
 err_out_kill_thread:
-	set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
-	if (kill_proc(dev->kpid, SIGTERM, 1))
-		dev_err(&dev->dev,
-			 "Failed to send signal to w1 kernel thread %d.\n",
-			 dev->kpid);
-	wait_for_completion(&dev->dev_exited);
-
+	kthread_stop(dev->thread);
 err_out_free_dev:
 	w1_free_dev(dev);
 
@@ -160,18 +152,14 @@ err_out_free_dev:
 
 void __w1_remove_master_device(struct w1_master *dev)
 {
-	int err;
 	struct w1_netlink_msg msg;
+	pid_t pid = dev->thread->pid;
 
 	set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
-	err = kill_proc(dev->kpid, SIGTERM, 1);
-	if (err)
-		dev_err(&dev->dev,
-			 "%s: Failed to send signal to w1 kernel thread %d.\n",
-			 __func__, dev->kpid);
+	kthread_stop(dev->thread);
 
 	while (atomic_read(&dev->refcnt)) {
-		dev_dbg(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
+		dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
 				dev->name, atomic_read(&dev->refcnt));
 
 		if (msleep_interruptible(1000))
@@ -179,7 +167,7 @@ void __w1_remove_master_device(struct w1
 	}
 
 	msg.id.mst.id = dev->id;
-	msg.id.mst.pid = dev->kpid;
+	msg.id.mst.pid = pid;
 	msg.type = W1_MASTER_REMOVE;
 	w1_netlink_send(dev, &msg);
 
Signature · 1 line
1.2.4