From 718a538f945a84244a460df434c3f6f04701957b Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sun, 17 Apr 2005 22:58:14 +0400 Subject: [PATCH] w1_therm: support for ds18b20, ds1822 thermal sensors. Support for ds18b20, ds1822 thermal sensors. Based on code from Tiziano M_ller . Patch is against 2.6.12-rc2 and should be applied without problems on top of any later kernels since w1_therm driver was not changed. Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_family.h | 4 ++- drivers/w1/w1_therm.c | 92 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 85 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 07fa49412a9..2995c6cb869 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -27,8 +27,10 @@ #include #define W1_FAMILY_DEFAULT 0 -#define W1_FAMILY_THERM 0x10 #define W1_FAMILY_SMEM 0x01 +#define W1_THERM_DS18S20 0x10 +#define W1_THERM_DS1822 0x22 +#define W1_THERM_DS18B20 0x28 #define MAXNAMELEN 32 diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c index 70310f7a722..84e8043a449 100644 --- a/drivers/w1/w1_therm.c +++ b/drivers/w1/w1_therm.c @@ -53,6 +53,50 @@ static struct w1_family_ops w1_therm_fops = { .rvalname = "temp1_input", }; +static struct w1_family w1_therm_family_DS18S20 = { + .fid = W1_THERM_DS18S20, + .fops = &w1_therm_fops, +}; + +static struct w1_family w1_therm_family_DS18B20 = { + .fid = W1_THERM_DS18B20, + .fops = &w1_therm_fops, +}; +static struct w1_family w1_therm_family_DS1822 = { + .fid = W1_THERM_DS1822, + .fops = &w1_therm_fops, +}; + +struct w1_therm_family_converter +{ + u8 fid; + u8 broken; + u16 reserved; + struct w1_family *f; + int (*convert)(u8 rom[9]); +}; + +static inline int w1_DS18B20_convert_temp(u8 rom[9]); +static inline int w1_DS18S20_convert_temp(u8 rom[9]); + +static struct w1_therm_family_converter w1_therm_families[] = { + { + .fid = W1_THERM_DS18S20, + .f = &w1_therm_family_DS18S20, + .convert = w1_DS18S20_convert_temp + }, + { + .fid = W1_THERM_DS1822, + .f = &w1_therm_family_DS1822, + .convert = w1_DS18B20_convert_temp + }, + { + .fid = W1_THERM_DS18B20, + .f = &w1_therm_family_DS18B20, + .convert = w1_DS18B20_convert_temp + }, +}; + static ssize_t w1_therm_read_name(struct device *dev, struct device_attribute *attr, char *buf) { struct w1_slave *sl = container_of(dev, struct w1_slave, dev); @@ -60,9 +104,19 @@ static ssize_t w1_therm_read_name(struct device *dev, struct device_attribute *a return sprintf(buf, "%s\n", sl->name); } -static inline int w1_convert_temp(u8 rom[9]) +static inline int w1_DS18B20_convert_temp(u8 rom[9]) +{ + int t = (rom[1] << 8) | rom[0]; + t /= 16; + return t; +} + +static inline int w1_DS18S20_convert_temp(u8 rom[9]) { int t, h; + + if (!rom[7]) + return 0; if (rom[1] == 0) t = ((s32)rom[0] >> 1)*1000; @@ -77,11 +131,22 @@ static inline int w1_convert_temp(u8 rom[9]) return t; } +static inline int w1_convert_temp(u8 rom[9], u8 fid) +{ + int i; + + for (i=0; irom)); + return sprintf(buf, "%d\n", w1_convert_temp(sl->rom, sl->family->fid)); } static int w1_therm_check_rom(u8 rom[9]) @@ -176,7 +241,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si for (i = 0; i < 9; ++i) count += sprintf(buf + count, "%02x ", sl->rom[i]); - count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom)); + count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom, sl->family->fid)); out: up(&dev->mutex); out_dec: @@ -186,19 +251,26 @@ out_dec: return count; } -static struct w1_family w1_therm_family = { - .fid = W1_FAMILY_THERM, - .fops = &w1_therm_fops, -}; - static int __init w1_therm_init(void) { - return w1_register_family(&w1_therm_family); + int err, i; + + for (i=0; i Date: Mon, 2 May 2005 14:26:42 +0400 Subject: [PATCH] w1_smem: support for new simple rom family [0x81 id]. Support for new simple rom family [0x81 id]. It is the same as existing 0x01 family, which is used in ds9490* w1 adapters. Patch is on top of new-thermal-sensor-families patch. Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_family.h | 3 ++- drivers/w1/w1_smem.c | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 2995c6cb869..d01f0424cee 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -27,7 +27,8 @@ #include #define W1_FAMILY_DEFAULT 0 -#define W1_FAMILY_SMEM 0x01 +#define W1_FAMILY_SMEM_01 0x01 +#define W1_FAMILY_SMEM_81 0x81 #define W1_THERM_DS18S20 0x10 #define W1_THERM_DS1822 0x22 #define W1_THERM_DS18B20 0x28 diff --git a/drivers/w1/w1_smem.c b/drivers/w1/w1_smem.c index 674eb75a9ba..4a335f1a2ae 100644 --- a/drivers/w1/w1_smem.c +++ b/drivers/w1/w1_smem.c @@ -99,19 +99,37 @@ out_dec: return count; } -static struct w1_family w1_smem_family = { - .fid = W1_FAMILY_SMEM, +static struct w1_family w1_smem_family_01 = { + .fid = W1_FAMILY_SMEM_01, + .fops = &w1_smem_fops, +}; + +static struct w1_family w1_smem_family_81 = { + .fid = W1_FAMILY_SMEM_81, .fops = &w1_smem_fops, }; static int __init w1_smem_init(void) { - return w1_register_family(&w1_smem_family); + int err; + + err = w1_register_family(&w1_smem_family_01); + if (err) + return err; + + err = w1_register_family(&w1_smem_family_81); + if (err) { + w1_unregister_family(&w1_smem_family_01); + return err; + } + + return 0; } static void __exit w1_smem_fini(void) { - w1_unregister_family(&w1_smem_family); + w1_unregister_family(&w1_smem_family_01); + w1_unregister_family(&w1_smem_family_81); } module_init(w1_smem_init); -- cgit v1.2.3-18-g5258 From 7785925dd8e0d2f389d4a9168f1683c6b249a552 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Fri, 20 May 2005 22:33:25 +0400 Subject: [PATCH] w1: cleanups. - white space changes. - list_for_each_entry/list_for_each_entry_safe and reverse changes. - small coding style changes. - removed redundant NULL checks. - use attribute group and macros instead of direct device attributes. Patch is havily based on work from Adrian Bunk and Dmitry Torokhov, thanks guys. Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/Kconfig | 16 +-- drivers/w1/matrox_w1.c | 10 +- drivers/w1/w1.c | 273 +++++++++++++++++------------------------------- drivers/w1/w1.h | 43 ++++---- drivers/w1/w1_family.c | 4 +- drivers/w1/w1_family.h | 10 +- drivers/w1/w1_int.c | 29 +++-- drivers/w1/w1_int.h | 6 +- drivers/w1/w1_io.c | 4 +- drivers/w1/w1_io.h | 4 +- drivers/w1/w1_log.h | 4 +- drivers/w1/w1_netlink.h | 4 +- drivers/w1/w1_smem.c | 8 +- drivers/w1/w1_therm.c | 12 +-- 14 files changed, 171 insertions(+), 256 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig index 2ab65c902fe..4f120796273 100644 --- a/drivers/w1/Kconfig +++ b/drivers/w1/Kconfig @@ -3,9 +3,9 @@ menu "Dallas's 1-wire bus" config W1 tristate "Dallas's 1-wire support" ---help--- - Dallas's 1-wire bus is usefull to connect slow 1-pin devices + Dallas's 1-wire bus is usefull to connect slow 1-pin devices such as iButtons and thermal sensors. - + If you want W1 support, you should say Y here. This W1 support can also be built as a module. If so, the module @@ -17,8 +17,8 @@ config W1_MATROX help Say Y here if you want to communicate with your 1-wire devices using Matrox's G400 GPIO pins. - - This support is also available as a module. If so, the module + + This support is also available as a module. If so, the module will be called matrox_w1.ko. config W1_DS9490 @@ -27,17 +27,17 @@ config W1_DS9490 help Say Y here if you want to have a driver for DS9490R UWB <-> W1 bridge. - This support is also available as a module. If so, the module + This support is also available as a module. If so, the module will be called ds9490r.ko. -config W1_DS9490_BRIDGE +config W1_DS9490R_BRIDGE tristate "DS9490R USB <-> W1 transport layer for 1-wire" depends on W1_DS9490 help Say Y here if you want to communicate with your 1-wire devices using DS9490R USB bridge. - This support is also available as a module. If so, the module + This support is also available as a module. If so, the module will be called ds_w1_bridge.ko. config W1_THERM @@ -51,7 +51,7 @@ config W1_SMEM tristate "Simple 64bit memory family implementation" depends on W1 help - Say Y here if you want to connect 1-wire + Say Y here if you want to connect 1-wire simple 64bit memory rom(ds2401/ds2411/ds1990*) to you wire. endmenu diff --git a/drivers/w1/matrox_w1.c b/drivers/w1/matrox_w1.c index e565416458e..0b03f8f93f6 100644 --- a/drivers/w1/matrox_w1.c +++ b/drivers/w1/matrox_w1.c @@ -1,8 +1,8 @@ /* - * matrox_w1.c + * matrox_w1.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,7 +59,7 @@ static struct pci_driver matrox_w1_pci_driver = { .remove = __devexit_p(matrox_w1_remove), }; -/* +/* * Matrox G400 DDC registers. */ @@ -177,8 +177,8 @@ static int __devinit matrox_w1_probe(struct pci_dev *pdev, const struct pci_devi dev->bus_master = (struct w1_bus_master *)(dev + 1); - /* - * True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c + /* + * True for G400, for some other we need resource 0, see drivers/video/matrox/matroxfb_base.c */ dev->phys_addr = pci_resource_start(pdev, 1); diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 24a192e3b8b..5b49c9a937f 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -1,8 +1,8 @@ /* - * w1.c + * w1.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -99,6 +99,23 @@ static ssize_t w1_default_read_bin(struct kobject *kobj, char *buf, loff_t off, return sprintf(buf, "No family registered.\n"); } +static struct device_attribute w1_slave_attribute = + __ATTR(name, S_IRUGO, w1_default_read_name, NULL); + +static struct device_attribute w1_slave_attribute_val = + __ATTR(value, S_IRUGO, w1_default_read_name, NULL); + +static struct bin_attribute w1_slave_bin_attribute = { + .attr = { + .name = "w1_slave", + .mode = S_IRUGO, + .owner = THIS_MODULE, + }, + .size = W1_SLAVE_DATA_SIZE, + .read = &w1_default_read_bin, +}; + + static struct bus_type w1_bus_type = { .name = "w1", .match = w1_master_match, @@ -119,34 +136,16 @@ struct device w1_device = { .release = &w1_master_release }; -static struct device_attribute w1_slave_attribute = { - .attr = { - .name = "name", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_default_read_name, -}; - -static struct device_attribute w1_slave_attribute_val = { - .attr = { - .name = "value", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_default_read_name, -}; - static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) { struct w1_master *md = container_of (dev, struct w1_master, dev); ssize_t count; - + if (down_interruptible (&md->mutex)) return -EBUSY; count = sprintf(buf, "%s\n", md->name); - + up(&md->mutex); return count; @@ -156,12 +155,12 @@ static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct devic { struct w1_master *md = container_of(dev, struct w1_master, dev); ssize_t count; - + if (down_interruptible(&md->mutex)) return -EBUSY; count = sprintf(buf, "0x%p\n", md->bus_master); - + up(&md->mutex); return count; } @@ -177,12 +176,12 @@ static ssize_t w1_master_attribute_show_max_slave_count(struct device *dev, stru { struct w1_master *md = container_of(dev, struct w1_master, dev); ssize_t count; - + if (down_interruptible(&md->mutex)) return -EBUSY; count = sprintf(buf, "%d\n", md->max_slave_count); - + up(&md->mutex); return count; } @@ -191,12 +190,12 @@ static ssize_t w1_master_attribute_show_attempts(struct device *dev, struct devi { struct w1_master *md = container_of(dev, struct w1_master, dev); ssize_t count; - + if (down_interruptible(&md->mutex)) return -EBUSY; count = sprintf(buf, "%lu\n", md->attempts); - + up(&md->mutex); return count; } @@ -205,12 +204,12 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d { struct w1_master *md = container_of(dev, struct w1_master, dev); ssize_t count; - + if (down_interruptible(&md->mutex)) return -EBUSY; count = sprintf(buf, "%d\n", md->slave_count); - + up(&md->mutex); return count; } @@ -233,7 +232,7 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device list_for_each_safe(ent, n, &md->slist) { sl = list_entry(ent, struct w1_slave, w1_slave_entry); - c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); + c -= snprintf(buf + PAGE_SIZE - c, c, "%s\n", sl->name); } } @@ -242,73 +241,44 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device return PAGE_SIZE - c; } -static struct device_attribute w1_master_attribute_slaves = { - .attr = { - .name = "w1_master_slaves", - .mode = S_IRUGO, - .owner = THIS_MODULE, - }, - .show = &w1_master_attribute_show_slaves, -}; -static struct device_attribute w1_master_attribute_slave_count = { - .attr = { - .name = "w1_master_slave_count", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_slave_count, -}; -static struct device_attribute w1_master_attribute_attempts = { - .attr = { - .name = "w1_master_attempts", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_attempts, -}; -static struct device_attribute w1_master_attribute_max_slave_count = { - .attr = { - .name = "w1_master_max_slave_count", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_max_slave_count, -}; -static struct device_attribute w1_master_attribute_timeout = { - .attr = { - .name = "w1_master_timeout", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_timeout, -}; -static struct device_attribute w1_master_attribute_pointer = { - .attr = { - .name = "w1_master_pointer", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_pointer, -}; -static struct device_attribute w1_master_attribute_name = { - .attr = { - .name = "w1_master_name", - .mode = S_IRUGO, - .owner = THIS_MODULE - }, - .show = &w1_master_attribute_show_name, +#define W1_MASTER_ATTR_RO(_name, _mode) \ + struct device_attribute w1_master_attribute_##_name = \ + __ATTR(w1_master_##_name, _mode, \ + w1_master_attribute_show_##_name, NULL) + +static W1_MASTER_ATTR_RO(name, S_IRUGO); +static W1_MASTER_ATTR_RO(slaves, S_IRUGO); +static W1_MASTER_ATTR_RO(slave_count, S_IRUGO); +static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO); +static W1_MASTER_ATTR_RO(attempts, S_IRUGO); +static W1_MASTER_ATTR_RO(timeout, S_IRUGO); +static W1_MASTER_ATTR_RO(pointer, S_IRUGO); + +static struct attribute *w1_master_default_attrs[] = { + &w1_master_attribute_name.attr, + &w1_master_attribute_slaves.attr, + &w1_master_attribute_slave_count.attr, + &w1_master_attribute_max_slave_count.attr, + &w1_master_attribute_attempts.attr, + &w1_master_attribute_timeout.attr, + &w1_master_attribute_pointer.attr, + NULL }; -static struct bin_attribute w1_slave_bin_attribute = { - .attr = { - .name = "w1_slave", - .mode = S_IRUGO, - .owner = THIS_MODULE, - }, - .size = W1_SLAVE_DATA_SIZE, - .read = &w1_default_read_bin, +static struct attribute_group w1_master_defattr_group = { + .attrs = w1_master_default_attrs, }; +int w1_create_master_attributes(struct w1_master *master) +{ + return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group); +} + +void w1_destroy_master_attributes(struct w1_master *master) +{ + sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); +} + static int __w1_attach_slave_device(struct w1_slave *sl) { int err; @@ -341,7 +311,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl) memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); memcpy(&sl->attr_val, &w1_slave_attribute_val, sizeof(sl->attr_val)); - + sl->attr_bin.read = sl->family->fops->rbin; sl->attr_name.show = sl->family->fops->rname; sl->attr_val.show = sl->family->fops->rval; @@ -445,7 +415,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) static void w1_slave_detach(struct w1_slave *sl) { struct w1_netlink_msg msg; - + dev_info(&sl->dev, "%s: detaching %s.\n", __func__, sl->name); while (atomic_read(&sl->refcnt)) { @@ -471,8 +441,8 @@ static struct w1_master *w1_search_master(unsigned long data) { struct w1_master *dev; int found = 0; - - spin_lock_irq(&w1_mlock); + + spin_lock_bh(&w1_mlock); list_for_each_entry(dev, &w1_masters, w1_master_entry) { if (dev->bus_master->data == data) { found = 1; @@ -480,12 +450,12 @@ static struct w1_master *w1_search_master(unsigned long data) break; } } - spin_unlock_irq(&w1_mlock); + spin_unlock_bh(&w1_mlock); return (found)?dev:NULL; } -void w1_slave_found(unsigned long data, u64 rn) +static void w1_slave_found(unsigned long data, u64 rn) { int slave_count; struct w1_slave *sl; @@ -500,7 +470,7 @@ void w1_slave_found(unsigned long data, u64 rn) data); return; } - + tmp = (struct w1_reg_num *) &rn; slave_count = 0; @@ -513,8 +483,7 @@ void w1_slave_found(unsigned long data, u64 rn) sl->reg_num.crc == tmp->crc) { set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); break; - } - else if (sl->reg_num.family == tmp->family) { + } else if (sl->reg_num.family == tmp->family) { family_found = 1; break; } @@ -528,7 +497,7 @@ void w1_slave_found(unsigned long data, u64 rn) rn && ((le64_to_cpu(rn) >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn, 7)) { w1_attach_slave_device(dev, tmp); } - + atomic_dec(&dev->refcnt); } @@ -545,8 +514,8 @@ void w1_search(struct w1_master *dev) desc_bit = 64; - while (!(id_bit && comp_bit) && !last_device - && count++ < dev->max_slave_count) { + while (!(id_bit && comp_bit) && !last_device && + count++ < dev->max_slave_count) { last = rn; rn = 0; @@ -591,8 +560,7 @@ void w1_search(struct w1_master *dev) last_family_desc = last_zero; } - } - else + } else search_bit = id_bit; tmp = search_bit; @@ -615,42 +583,15 @@ void w1_search(struct w1_master *dev) last_device = 1; desc_bit = last_zero; - + w1_slave_found(dev->bus_master->data, rn); } } -int w1_create_master_attributes(struct w1_master *dev) -{ - if ( device_create_file(&dev->dev, &w1_master_attribute_slaves) < 0 || - device_create_file(&dev->dev, &w1_master_attribute_slave_count) < 0 || - device_create_file(&dev->dev, &w1_master_attribute_attempts) < 0 || - device_create_file(&dev->dev, &w1_master_attribute_max_slave_count) < 0 || - device_create_file(&dev->dev, &w1_master_attribute_timeout) < 0|| - device_create_file(&dev->dev, &w1_master_attribute_pointer) < 0|| - device_create_file(&dev->dev, &w1_master_attribute_name) < 0) - return -EINVAL; - - return 0; -} - -void w1_destroy_master_attributes(struct w1_master *dev) -{ - device_remove_file(&dev->dev, &w1_master_attribute_slaves); - device_remove_file(&dev->dev, &w1_master_attribute_slave_count); - device_remove_file(&dev->dev, &w1_master_attribute_attempts); - device_remove_file(&dev->dev, &w1_master_attribute_max_slave_count); - device_remove_file(&dev->dev, &w1_master_attribute_timeout); - device_remove_file(&dev->dev, &w1_master_attribute_pointer); - device_remove_file(&dev->dev, &w1_master_attribute_name); -} - - -int w1_control(void *data) +static int w1_control(void *data) { - struct w1_slave *sl; - struct w1_master *dev; - struct list_head *ent, *ment, *n, *mn; + struct w1_slave *sl, *sln; + struct w1_master *dev, *n; int err, have_to_wait = 0; daemonize("w1_control"); @@ -665,9 +606,7 @@ int w1_control(void *data) if (signal_pending(current)) flush_signals(current); - list_for_each_safe(ment, mn, &w1_masters) { - dev = list_entry(ment, struct w1_master, w1_master_entry); - + list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) { if (!control_needs_exit && !dev->need_exit) continue; /* @@ -679,9 +618,9 @@ int w1_control(void *data) continue; } - spin_lock(&w1_mlock); + spin_lock_bh(&w1_mlock); list_del(&dev->w1_master_entry); - spin_unlock(&w1_mlock); + spin_unlock_bh(&w1_mlock); if (control_needs_exit) { dev->need_exit = 1; @@ -695,19 +634,11 @@ int w1_control(void *data) wait_for_completion(&dev->dev_exited); - list_for_each_safe(ent, n, &dev->slist) { - sl = list_entry(ent, struct w1_slave, w1_slave_entry); - - if (!sl) - dev_warn(&dev->dev, - "%s: slave entry is NULL.\n", - __func__); - else { - list_del(&sl->w1_slave_entry); + list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { + list_del(&sl->w1_slave_entry); - w1_slave_detach(sl); - kfree(sl); - } + w1_slave_detach(sl); + kfree(sl); } w1_destroy_master_attributes(dev); atomic_dec(&dev->refcnt); @@ -720,8 +651,7 @@ int w1_control(void *data) int w1_process(void *data) { struct w1_master *dev = (struct w1_master *) data; - struct list_head *ent, *n; - struct w1_slave *sl; + struct w1_slave *sl, *sln; daemonize("%s", dev->name); allow_signal(SIGTERM); @@ -742,27 +672,20 @@ int w1_process(void *data) if (down_interruptible(&dev->mutex)) continue; - list_for_each_safe(ent, n, &dev->slist) { - sl = list_entry(ent, struct w1_slave, w1_slave_entry); - - if (sl) + list_for_each_entry(sl, &dev->slist, w1_slave_entry) clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); - } - - w1_search_devices(dev, w1_slave_found); - list_for_each_safe(ent, n, &dev->slist) { - sl = list_entry(ent, struct w1_slave, w1_slave_entry); + w1_search_devices(dev, w1_slave_found); - if (sl && !test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { + list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { + if (!test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags) && !--sl->ttl) { list_del (&sl->w1_slave_entry); w1_slave_detach (sl); kfree (sl); dev->slave_count--; - } - else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) + } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) sl->ttl = dev->slave_ttl; } up(&dev->mutex); @@ -774,7 +697,7 @@ int w1_process(void *data) return 0; } -int w1_init(void) +static int w1_init(void) { int retval; @@ -814,18 +737,14 @@ err_out_exit_init: return retval; } -void w1_fini(void) +static void w1_fini(void) { struct w1_master *dev; - struct list_head *ent, *n; - list_for_each_safe(ent, n, &w1_masters) { - dev = list_entry(ent, struct w1_master, w1_master_entry); + 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); driver_unregister(&w1_driver); diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index abbddaf3f8e..90a2e737d2c 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -1,8 +1,8 @@ /* - * w1.h + * w1.h * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,9 +25,9 @@ struct w1_reg_num { #if defined(__LITTLE_ENDIAN_BITFIELD) - __u64 family:8, - id:48, - crc:8; + __u64 family:8, + id:48, + crc:8; #elif defined(__BIG_ENDIAN_BITFIELD) __u64 crc:8, id:48, @@ -74,11 +74,11 @@ struct w1_slave int ttl; struct w1_master *master; - struct w1_family *family; - struct device dev; - struct completion dev_released; + struct w1_family *family; + struct device dev; + struct completion dev_released; - struct bin_attribute attr_bin; + struct bin_attribute attr_bin; struct device_attribute attr_name, attr_val; }; @@ -90,16 +90,16 @@ struct w1_bus_master u8 (*read_bit)(unsigned long); void (*write_bit)(unsigned long, u8); - + u8 (*read_byte)(unsigned long); - void (*write_byte)(unsigned long, u8); - + void (*write_byte)(unsigned long, u8); + u8 (*read_block)(unsigned long, u8 *, int); void (*write_block)(unsigned long, u8 *, int); - - u8 (*touch_bit)(unsigned long, u8); - - u8 (*reset_bus)(unsigned long); + + u8 (*touch_bit)(unsigned long, u8); + + u8 (*reset_bus)(unsigned long); void (*search)(unsigned long, w1_slave_found_callback); }; @@ -123,21 +123,20 @@ struct w1_master int need_exit; pid_t kpid; - struct semaphore mutex; + struct semaphore mutex; struct device_driver *driver; - struct device dev; - struct completion dev_released; - struct completion dev_exited; + struct device dev; + struct completion dev_released; + struct completion dev_exited; struct w1_bus_master *bus_master; u32 seq, groups; - struct sock *nls; + struct sock *nls; }; int w1_create_master_attributes(struct w1_master *); -void w1_destroy_master_attributes(struct w1_master *); void w1_search(struct w1_master *dev); #endif /* __KERNEL__ */ diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c index d1d56eca106..3941fb05b8e 100644 --- a/drivers/w1/w1_family.c +++ b/drivers/w1/w1_family.c @@ -1,8 +1,8 @@ /* - * w1_family.c + * w1_family.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index d01f0424cee..218f1272062 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -1,8 +1,8 @@ /* - * w1_family.h + * w1_family.h * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,7 +39,7 @@ struct w1_family_ops { ssize_t (* rname)(struct device *, struct device_attribute *, char *); ssize_t (* rbin)(struct kobject *, char *, loff_t, size_t); - + ssize_t (* rval)(struct device *, struct device_attribute *, char *); unsigned char rvalname[MAXNAMELEN]; }; @@ -48,9 +48,9 @@ struct w1_family { struct list_head family_entry; u8 fid; - + struct w1_family_ops *fops; - + atomic_t refcnt; u8 need_exit; }; diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index 5f0bafbbd57..ce24e3b3fc2 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -1,8 +1,8 @@ /* - * w1_int.c + * w1_int.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,9 @@ extern spinlock_t w1_mlock; extern int w1_process(void *); -struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, - struct device_driver *driver, struct device *device) +static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, + struct device_driver *driver, + struct device *device) { struct w1_master *dev; int err; @@ -60,13 +61,13 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, dev->bus_master = (struct w1_bus_master *)(dev + 1); - dev->owner = THIS_MODULE; - dev->max_slave_count = slave_count; - dev->slave_count = 0; - dev->attempts = 0; - dev->kpid = -1; - dev->initialized = 0; - dev->id = id; + dev->owner = THIS_MODULE; + 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; atomic_set(&dev->refcnt, 2); @@ -105,7 +106,7 @@ struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, return dev; } -void w1_free_dev(struct w1_master *dev) +static void w1_free_dev(struct w1_master *dev) { device_unregister(&dev->dev); if (dev->nls && dev->nls->sk_socket) @@ -197,10 +198,8 @@ void __w1_remove_master_device(struct w1_master *dev) void w1_remove_master_device(struct w1_bus_master *bm) { struct w1_master *dev = NULL; - struct list_head *ent, *n; - list_for_each_safe(ent, n, &w1_masters) { - dev = list_entry(ent, struct w1_master, w1_master_entry); + list_for_each_entry(dev, &w1_masters, w1_master_entry) { if (!dev->initialized) continue; diff --git a/drivers/w1/w1_int.h b/drivers/w1/w1_int.h index fdb531e87fa..4274082d226 100644 --- a/drivers/w1/w1_int.h +++ b/drivers/w1/w1_int.h @@ -1,8 +1,8 @@ /* - * w1_int.h + * w1_int.h * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,8 +27,6 @@ #include "w1.h" -struct w1_master * w1_alloc_dev(u32, int, int, struct device_driver *, struct device *); -void w1_free_dev(struct w1_master *dev); int w1_add_master_device(struct w1_bus_master *); void w1_remove_master_device(struct w1_bus_master *); void __w1_remove_master_device(struct w1_master *); diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 02796b5a39f..298ee8b7254 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c @@ -1,8 +1,8 @@ /* - * w1_io.c + * w1_io.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/w1/w1_io.h b/drivers/w1/w1_io.h index 6c573005a71..327c22ba50d 100644 --- a/drivers/w1/w1_io.h +++ b/drivers/w1/w1_io.h @@ -1,8 +1,8 @@ /* - * w1_io.h + * w1_io.h * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/w1/w1_log.h b/drivers/w1/w1_log.h index a6bf6f44dce..fe6bdf43380 100644 --- a/drivers/w1/w1_log.h +++ b/drivers/w1/w1_log.h @@ -1,8 +1,8 @@ /* - * w1_log.h + * w1_log.h * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h index ea1b530abad..8615756946d 100644 --- a/drivers/w1/w1_netlink.h +++ b/drivers/w1/w1_netlink.h @@ -33,13 +33,13 @@ enum w1_netlink_message_types { W1_MASTER_REMOVE, }; -struct w1_netlink_msg +struct w1_netlink_msg { __u8 type; __u8 reserved[3]; union { - struct w1_reg_num id; + struct w1_reg_num id; __u64 w1_id; struct { diff --git a/drivers/w1/w1_smem.c b/drivers/w1/w1_smem.c index 4a335f1a2ae..285eb8f8457 100644 --- a/drivers/w1/w1_smem.c +++ b/drivers/w1/w1_smem.c @@ -1,8 +1,8 @@ /* - * w1_smem.c + * w1_smem.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the smems of the GNU General Public License as published by @@ -70,7 +70,7 @@ static ssize_t w1_smem_read_val(struct device *dev, struct device_attribute *att static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) { struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), - struct w1_slave, dev); + struct w1_slave, dev); int i; atomic_inc(&sl->refcnt); @@ -90,7 +90,7 @@ static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, siz for (i = 0; i < 8; ++i) count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]); count += sprintf(buf + count, "\n"); - + out: up(&sl->master->mutex); out_dec: diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c index 84e8043a449..e52abca0507 100644 --- a/drivers/w1/w1_therm.c +++ b/drivers/w1/w1_therm.c @@ -1,8 +1,8 @@ /* - * w1_therm.c + * w1_therm.c * * Copyright (c) 2004 Evgeniy Polyakov - * + * * * This program is free software; you can redistribute it and/or modify * it under the therms of the GNU General Public License as published by @@ -38,7 +38,7 @@ MODULE_AUTHOR("Evgeniy Polyakov "); MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature family."); static u8 bad_roms[][9] = { - {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87}, + {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87}, {} }; @@ -163,7 +163,7 @@ static int w1_therm_check_rom(u8 rom[9]) static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) { struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), - struct w1_slave, dev); + struct w1_slave, dev); struct w1_master *dev = sl->master; u8 rom[9], crc, verdict; int i, max_trying = 10; @@ -198,7 +198,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si unsigned int tm = 750; memcpy(&match[1], (u64 *) & sl->reg_num, 8); - + w1_write_block(dev, match, 9); w1_write_8(dev, W1_CONVERT_TEMP); @@ -211,7 +211,7 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj, char *buf, loff_t off, si if (!w1_reset_bus (dev)) { w1_write_block(dev, match, 9); - + w1_write_8(dev, W1_READ_SCRATCHPAD); if ((count = w1_read_block(dev, rom, 9)) != 9) { dev_warn(&dev->dev, "w1_read_block() returned %d instead of 9.\n", count); -- cgit v1.2.3-18-g5258 From ca775c629a366ded01aae69da8410f70aaf85de1 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Fri, 20 May 2005 22:49:08 +0400 Subject: [PATCH] w1: new family structure. Removed some fields which are not required. First step for writing operations. Now only read and read name remain. Patch depends on w1 cleanups patch. Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 18 ------------------ drivers/w1/w1.h | 2 +- drivers/w1/w1_family.c | 2 +- drivers/w1/w1_family.h | 3 --- drivers/w1/w1_therm.c | 10 ---------- 5 files changed, 2 insertions(+), 33 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 5b49c9a937f..c85d75ed835 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -102,9 +102,6 @@ static ssize_t w1_default_read_bin(struct kobject *kobj, char *buf, loff_t off, static struct device_attribute w1_slave_attribute = __ATTR(name, S_IRUGO, w1_default_read_name, NULL); -static struct device_attribute w1_slave_attribute_val = - __ATTR(value, S_IRUGO, w1_default_read_name, NULL); - static struct bin_attribute w1_slave_bin_attribute = { .attr = { .name = "w1_slave", @@ -310,12 +307,9 @@ static int __w1_attach_slave_device(struct w1_slave *sl) memcpy(&sl->attr_bin, &w1_slave_bin_attribute, sizeof(sl->attr_bin)); memcpy(&sl->attr_name, &w1_slave_attribute, sizeof(sl->attr_name)); - memcpy(&sl->attr_val, &w1_slave_attribute_val, sizeof(sl->attr_val)); sl->attr_bin.read = sl->family->fops->rbin; sl->attr_name.show = sl->family->fops->rname; - sl->attr_val.show = sl->family->fops->rval; - sl->attr_val.attr.name = sl->family->fops->rvalname; err = device_create_file(&sl->dev, &sl->attr_name); if (err < 0) { @@ -326,23 +320,12 @@ static int __w1_attach_slave_device(struct w1_slave *sl) return err; } - err = device_create_file(&sl->dev, &sl->attr_val); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - sl->dev.bus_id, err); - device_remove_file(&sl->dev, &sl->attr_name); - device_unregister(&sl->dev); - return err; - } - err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); if (err < 0) { dev_err(&sl->dev, "sysfs file creation for [%s] failed. err=%d\n", sl->dev.bus_id, err); device_remove_file(&sl->dev, &sl->attr_name); - device_remove_file(&sl->dev, &sl->attr_val); device_unregister(&sl->dev); return err; } @@ -428,7 +411,6 @@ static void w1_slave_detach(struct w1_slave *sl) sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin); device_remove_file(&sl->dev, &sl->attr_name); - device_remove_file(&sl->dev, &sl->attr_val); device_unregister(&sl->dev); w1_family_put(sl->family); diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 90a2e737d2c..44dfb92e55c 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -79,7 +79,7 @@ struct w1_slave struct completion dev_released; struct bin_attribute attr_bin; - struct device_attribute attr_name, attr_val; + struct device_attribute attr_name; }; typedef void (* w1_slave_found_callback)(unsigned long, u64); diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c index 3941fb05b8e..b8502d910c5 100644 --- a/drivers/w1/w1_family.c +++ b/drivers/w1/w1_family.c @@ -30,7 +30,7 @@ static LIST_HEAD(w1_families); static int w1_check_family(struct w1_family *f) { - if (!f->fops->rname || !f->fops->rbin || !f->fops->rval || !f->fops->rvalname) + if (!f->fops->rname || !f->fops->rbin) return -EINVAL; return 0; diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h index 218f1272062..b26da01bbc3 100644 --- a/drivers/w1/w1_family.h +++ b/drivers/w1/w1_family.h @@ -39,9 +39,6 @@ struct w1_family_ops { ssize_t (* rname)(struct device *, struct device_attribute *, char *); ssize_t (* rbin)(struct kobject *, char *, loff_t, size_t); - - ssize_t (* rval)(struct device *, struct device_attribute *, char *); - unsigned char rvalname[MAXNAMELEN]; }; struct w1_family diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c index e52abca0507..b9896c10af6 100644 --- a/drivers/w1/w1_therm.c +++ b/drivers/w1/w1_therm.c @@ -43,14 +43,11 @@ static u8 bad_roms[][9] = { }; static ssize_t w1_therm_read_name(struct device *, struct device_attribute *attr, char *); -static ssize_t w1_therm_read_temp(struct device *, struct device_attribute *attr, char *); static ssize_t w1_therm_read_bin(struct kobject *, char *, loff_t, size_t); static struct w1_family_ops w1_therm_fops = { .rname = &w1_therm_read_name, .rbin = &w1_therm_read_bin, - .rval = &w1_therm_read_temp, - .rvalname = "temp1_input", }; static struct w1_family w1_therm_family_DS18S20 = { @@ -142,13 +139,6 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid) return 0; } -static ssize_t w1_therm_read_temp(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w1_slave *sl = container_of(dev, struct w1_slave, dev); - - return sprintf(buf, "%d\n", w1_convert_temp(sl->rom, sl->family->fid)); -} - static int w1_therm_check_rom(u8 rom[9]) { int i; -- cgit v1.2.3-18-g5258 From c7b2b2a723174d22a743180d5367f0028226031b Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Tue, 21 Jun 2005 21:01:59 -0700 Subject: [PATCH] w1: fix build issues Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_smem.c | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1_smem.c b/drivers/w1/w1_smem.c index 285eb8f8457..70d2d469963 100644 --- a/drivers/w1/w1_smem.c +++ b/drivers/w1/w1_smem.c @@ -37,14 +37,11 @@ MODULE_AUTHOR("Evgeniy Polyakov "); MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, 64bit memory family."); static ssize_t w1_smem_read_name(struct device *, struct device_attribute *attr, char *); -static ssize_t w1_smem_read_val(struct device *, struct device_attribute *attr, char *); static ssize_t w1_smem_read_bin(struct kobject *, char *, loff_t, size_t); static struct w1_family_ops w1_smem_fops = { .rname = &w1_smem_read_name, .rbin = &w1_smem_read_bin, - .rval = &w1_smem_read_val, - .rvalname = "id", }; static ssize_t w1_smem_read_name(struct device *dev, struct device_attribute *attr, char *buf) @@ -54,19 +51,6 @@ static ssize_t w1_smem_read_name(struct device *dev, struct device_attribute *at return sprintf(buf, "%s\n", sl->name); } -static ssize_t w1_smem_read_val(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct w1_slave *sl = container_of(dev, struct w1_slave, dev); - int i; - ssize_t count = 0; - - for (i = 0; i < 8; ++i) - count += sprintf(buf + count, "%02x ", ((u8 *)&sl->reg_num)[i]); - count += sprintf(buf + count, "\n"); - - return count; -} - static ssize_t w1_smem_read_bin(struct kobject *kobj, char *buf, loff_t off, size_t count) { struct w1_slave *sl = container_of(container_of(kobj, struct device, kobj), -- cgit v1.2.3-18-g5258 From 4e470aa9642d49230bcdfbb393cf5a81da333aba Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Fri, 20 May 2005 22:50:33 +0400 Subject: [PATCH] w1_therm: removed duplicated family id. We can access family id through w1_family structure. Signed-off-by: Evgeniy Polyakov --- drivers/w1/w1_therm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1_therm.c b/drivers/w1/w1_therm.c index b9896c10af6..165526c9360 100644 --- a/drivers/w1/w1_therm.c +++ b/drivers/w1/w1_therm.c @@ -66,7 +66,6 @@ static struct w1_family w1_therm_family_DS1822 = { struct w1_therm_family_converter { - u8 fid; u8 broken; u16 reserved; struct w1_family *f; @@ -78,17 +77,14 @@ static inline int w1_DS18S20_convert_temp(u8 rom[9]); static struct w1_therm_family_converter w1_therm_families[] = { { - .fid = W1_THERM_DS18S20, .f = &w1_therm_family_DS18S20, .convert = w1_DS18S20_convert_temp }, { - .fid = W1_THERM_DS1822, .f = &w1_therm_family_DS1822, .convert = w1_DS18B20_convert_temp }, { - .fid = W1_THERM_DS18B20, .f = &w1_therm_family_DS18B20, .convert = w1_DS18B20_convert_temp }, @@ -133,7 +129,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid) int i; for (i=0; ifid == fid) return w1_therm_families[i].convert(rom); return 0; -- cgit v1.2.3-18-g5258 From be57ce267fd558c52d2389530c15618681b7cfa7 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sat, 4 Jun 2005 01:21:46 +0400 Subject: [PATCH] w1: Cleans up usage of touch_bit/w1_read_bit/w1_write_bit. Cleans up usage of touch_bit/w1_read_bit/w1_write_bit. Signed-off-by: Ben Gardner Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1_int.c | 8 ++++++ drivers/w1/w1_io.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++------- drivers/w1/w1_io.h | 4 +-- 3 files changed, 70 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index ce24e3b3fc2..280f140ae69 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -121,6 +121,14 @@ int w1_add_master_device(struct w1_bus_master *master) int retval = 0; struct w1_netlink_msg msg; + /* validate minimum functionality */ + if (!(master->touch_bit && master->reset_bus) && + !(master->write_bit && master->read_bit)) + { + printk(KERN_ERR "w1_add_master_device: invalid function set\n"); + return(-EINVAL); + } + dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_driver, &w1_device); if (!dev) return -ENOMEM; diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 298ee8b7254..2173336b60a 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c @@ -55,15 +55,29 @@ void w1_delay(unsigned long tm) udelay(tm * w1_delay_parm); } +static void w1_write_bit(struct w1_master *dev, int bit); +static u8 w1_read_bit(struct w1_master *dev); + +/** + * Generates a write-0 or write-1 cycle and samples the level. + */ u8 w1_touch_bit(struct w1_master *dev, int bit) { if (dev->bus_master->touch_bit) return dev->bus_master->touch_bit(dev->bus_master->data, bit); - else + else if (bit) return w1_read_bit(dev); + else { + w1_write_bit(dev, 0); + return(0); + } } -void w1_write_bit(struct w1_master *dev, int bit) +/** + * Generates a write-0 or write-1 cycle. + * Only call if dev->bus_master->touch_bit is NULL + */ +static void w1_write_bit(struct w1_master *dev, int bit) { if (bit) { dev->bus_master->write_bit(dev->bus_master->data, 0); @@ -78,6 +92,12 @@ void w1_write_bit(struct w1_master *dev, int bit) } } +/** + * Writes 8 bits. + * + * @param dev the master device + * @param byte the byte to write + */ void w1_write_8(struct w1_master *dev, u8 byte) { int i; @@ -86,10 +106,15 @@ void w1_write_8(struct w1_master *dev, u8 byte) dev->bus_master->write_byte(dev->bus_master->data, byte); else for (i = 0; i < 8; ++i) - w1_write_bit(dev, (byte >> i) & 0x1); + w1_touch_bit(dev, (byte >> i) & 0x1); } -u8 w1_read_bit(struct w1_master *dev) + +/** + * Generates a write-1 cycle and samples the level. + * Only call if dev->bus_master->touch_bit is NULL + */ +static u8 w1_read_bit(struct w1_master *dev) { int result; @@ -104,6 +129,12 @@ u8 w1_read_bit(struct w1_master *dev) return result & 0x1; } +/** + * Reads 8 bits. + * + * @param dev the master device + * @return the byte read + */ u8 w1_read_8(struct w1_master * dev) { int i; @@ -113,12 +144,20 @@ u8 w1_read_8(struct w1_master * dev) res = dev->bus_master->read_byte(dev->bus_master->data); else for (i = 0; i < 8; ++i) - res |= (w1_read_bit(dev) << i); + res |= (w1_touch_bit(dev,1) << i); return res; } -void w1_write_block(struct w1_master *dev, u8 *buf, int len) +/** + * Writes a series of bytes. + * + * @param dev the master device + * @param buf pointer to the data to write + * @param len the number of bytes to write + * @return the byte read + */ +void w1_write_block(struct w1_master *dev, const u8 *buf, int len) { int i; @@ -129,6 +168,14 @@ void w1_write_block(struct w1_master *dev, u8 *buf, int len) w1_write_8(dev, buf[i]); } +/** + * Reads a series of bytes. + * + * @param dev the master device + * @param buf pointer to the buffer to fill + * @param len the number of bytes to read + * @return the number of bytes read + */ u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) { int i; @@ -145,9 +192,15 @@ u8 w1_read_block(struct w1_master *dev, u8 *buf, int len) return ret; } +/** + * Issues a reset bus sequence. + * + * @param dev The bus master pointer + * @return 0=Device present, 1=No device present or error + */ int w1_reset_bus(struct w1_master *dev) { - int result = 0; + int result; if (dev->bus_master->reset_bus) result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1; @@ -183,9 +236,8 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb) w1_search(dev); } -EXPORT_SYMBOL(w1_write_bit); +EXPORT_SYMBOL(w1_touch_bit); EXPORT_SYMBOL(w1_write_8); -EXPORT_SYMBOL(w1_read_bit); EXPORT_SYMBOL(w1_read_8); EXPORT_SYMBOL(w1_reset_bus); EXPORT_SYMBOL(w1_calc_crc8); diff --git a/drivers/w1/w1_io.h b/drivers/w1/w1_io.h index 327c22ba50d..d6daa3189c6 100644 --- a/drivers/w1/w1_io.h +++ b/drivers/w1/w1_io.h @@ -26,13 +26,11 @@ void w1_delay(unsigned long); u8 w1_touch_bit(struct w1_master *, int); -void w1_write_bit(struct w1_master *, int); void w1_write_8(struct w1_master *, u8); -u8 w1_read_bit(struct w1_master *); u8 w1_read_8(struct w1_master *); int w1_reset_bus(struct w1_master *); u8 w1_calc_crc8(u8 *, int); -void w1_write_block(struct w1_master *, u8 *, int); +void w1_write_block(struct w1_master *, const u8 *, int); u8 w1_read_block(struct w1_master *, u8 *, int); void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb); -- cgit v1.2.3-18-g5258 From 6b729861831177b270a2932a13e79cb41d673146 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sat, 4 Jun 2005 01:30:43 +0400 Subject: [PATCH] w1: Added the triplet w1 master method and changes w1_search() to use it. Adds the triplet w1 master method and changes w1_search() to use it. Signed-off-by: Ben Gardner Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 138 +++++++++++++++++++++++++---------------------------- drivers/w1/w1.h | 87 +++++++++++++++++++++++++-------- drivers/w1/w1_io.c | 43 ++++++++++++++++- drivers/w1/w1_io.h | 1 + 4 files changed, 175 insertions(+), 94 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index c85d75ed835..4fa959f0855 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -135,7 +135,7 @@ struct device w1_device = { static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_attribute *attr, char *buf) { - struct w1_master *md = container_of (dev, struct w1_master, dev); + struct w1_master *md = container_of(dev, struct w1_master, dev); ssize_t count; if (down_interruptible (&md->mutex)) @@ -212,7 +212,6 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d } static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf) - { struct w1_master *md = container_of(dev, struct w1_master, dev); int c = PAGE_SIZE; @@ -286,13 +285,13 @@ static int __w1_attach_slave_device(struct w1_slave *sl) sl->dev.release = &w1_slave_release; snprintf(&sl->dev.bus_id[0], sizeof(sl->dev.bus_id), - "%02x-%012llx", - (unsigned int) sl->reg_num.family, - (unsigned long long) sl->reg_num.id); - snprintf (&sl->name[0], sizeof(sl->name), - "%02x-%012llx", - (unsigned int) sl->reg_num.family, - (unsigned long long) sl->reg_num.id); + "%02x-%012llx", + (unsigned int) sl->reg_num.family, + (unsigned long long) sl->reg_num.id); + snprintf(&sl->name[0], sizeof(sl->name), + "%02x-%012llx", + (unsigned int) sl->reg_num.family, + (unsigned long long) sl->reg_num.id); dev_dbg(&sl->dev, "%s: registering %s.\n", __func__, &sl->dev.bus_id[0]); @@ -300,8 +299,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl) err = device_register(&sl->dev); if (err < 0) { dev_err(&sl->dev, - "Device registration [%s] failed. err=%d\n", - sl->dev.bus_id, err); + "Device registration [%s] failed. err=%d\n", + sl->dev.bus_id, err); return err; } @@ -314,8 +313,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl) err = device_create_file(&sl->dev, &sl->attr_name); if (err < 0) { dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - sl->dev.bus_id, err); + "sysfs file creation for [%s] failed. err=%d\n", + sl->dev.bus_id, err); device_unregister(&sl->dev); return err; } @@ -323,8 +322,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl) err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); if (err < 0) { dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - sl->dev.bus_id, err); + "sysfs file creation for [%s] failed. err=%d\n", + sl->dev.bus_id, err); device_remove_file(&sl->dev, &sl->attr_name); device_unregister(&sl->dev); return err; @@ -483,26 +482,39 @@ static void w1_slave_found(unsigned long data, u64 rn) atomic_dec(&dev->refcnt); } -void w1_search(struct w1_master *dev) +/** + * Performs a ROM Search & registers any devices found. + * The 1-wire search is a simple binary tree search. + * For each bit of the address, we read two bits and write one bit. + * The bit written will put to sleep all devies that don't match that bit. + * When the two reads differ, the direction choice is obvious. + * When both bits are 0, we must choose a path to take. + * When we can scan all 64 bits without having to choose a path, we are done. + * + * See "Application note 187 1-wire search algorithm" at www.maxim-ic.com + * + * @dev The master device to search + * @cb Function to call when a device is found + */ +void w1_search(struct w1_master *dev, w1_slave_found_callback cb) { - u64 last, rn, tmp; - int i, count = 0; - int last_family_desc, last_zero, last_device; - int search_bit, id_bit, comp_bit, desc_bit; + u64 last_rn, rn, tmp64; + int i, slave_count = 0; + int last_zero, last_device; + int search_bit, desc_bit; + u8 triplet_ret = 0; - search_bit = id_bit = comp_bit = 0; - rn = tmp = last = 0; - last_device = last_zero = last_family_desc = 0; + search_bit = 0; + rn = last_rn = 0; + last_device = 0; + last_zero = -1; desc_bit = 64; - while (!(id_bit && comp_bit) && !last_device && - count++ < dev->max_slave_count) { - last = rn; + while ( !last_device && (slave_count++ < dev->max_slave_count) ) { + last_rn = rn; rn = 0; - last_family_desc = 0; - /* * Reset bus and all 1-wire device state machines * so they can respond to our requests. @@ -514,59 +526,39 @@ void w1_search(struct w1_master *dev) break; } -#if 1 + /* Start the search */ w1_write_8(dev, W1_SEARCH); for (i = 0; i < 64; ++i) { - /* - * Read 2 bits from bus. - * All who don't sleep must send ID bit and COMPLEMENT ID bit. - * They actually are ANDed between all senders. - */ - id_bit = w1_touch_bit(dev, 1); - comp_bit = w1_touch_bit(dev, 1); - - if (id_bit && comp_bit) - break; - - if (id_bit == 0 && comp_bit == 0) { - if (i == desc_bit) - search_bit = 1; - else if (i > desc_bit) - search_bit = 0; - else - search_bit = ((last >> i) & 0x1); - - if (search_bit == 0) { - last_zero = i; - if (last_zero < 9) - last_family_desc = last_zero; - } + /* Determine the direction/search bit */ + if (i == desc_bit) + search_bit = 1; /* took the 0 path last time, so take the 1 path */ + else if (i > desc_bit) + search_bit = 0; /* take the 0 path on the next branch */ + else + search_bit = ((last_rn >> i) & 0x1); - } else - search_bit = id_bit; + /** Read two bits and write one bit */ + triplet_ret = w1_triplet(dev, search_bit); - tmp = search_bit; - rn |= (tmp << i); + /* quit if no device responded */ + if ( (triplet_ret & 0x03) == 0x03 ) + break; - /* - * Write 1 bit to bus - * and make all who don't have "search_bit" in "i"'th position - * in it's registration number sleep. - */ - if (dev->bus_master->touch_bit) - w1_touch_bit(dev, search_bit); - else - w1_write_bit(dev, search_bit); + /* If both directions were valid, and we took the 0 path... */ + if (triplet_ret == 0) + last_zero = i; + /* extract the direction taken & update the device number */ + tmp64 = (triplet_ret >> 2); + rn |= (tmp64 << i); } -#endif - - if (desc_bit == last_zero) - last_device = 1; - desc_bit = last_zero; - - w1_slave_found(dev->bus_master->data, rn); + if ( (triplet_ret & 0x03) != 0x03 ) { + if ( (desc_bit == last_zero) || (last_zero < 0)) + last_device = 1; + desc_bit = last_zero; + cb(dev->bus_master->data, rn); + } } } diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 44dfb92e55c..3cfdd08d32f 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -25,9 +25,9 @@ struct w1_reg_num { #if defined(__LITTLE_ENDIAN_BITFIELD) - __u64 family:8, - id:48, - crc:8; + __u64 family:8, + id:48, + crc:8; #elif defined(__BIG_ENDIAN_BITFIELD) __u64 crc:8, id:48, @@ -84,24 +84,71 @@ struct w1_slave typedef void (* w1_slave_found_callback)(unsigned long, u64); + +/** + * Note: read_bit and write_bit are very low level functions and should only + * be used with hardware that doesn't really support 1-wire operations, + * like a parallel/serial port. + * Either define read_bit and write_bit OR define, at minimum, touch_bit and + * reset_bus. + */ struct w1_bus_master { - unsigned long data; - - u8 (*read_bit)(unsigned long); - void (*write_bit)(unsigned long, u8); - - u8 (*read_byte)(unsigned long); - void (*write_byte)(unsigned long, u8); - - u8 (*read_block)(unsigned long, u8 *, int); - void (*write_block)(unsigned long, u8 *, int); - - u8 (*touch_bit)(unsigned long, u8); - - u8 (*reset_bus)(unsigned long); - - void (*search)(unsigned long, w1_slave_found_callback); + /** the first parameter in all the functions below */ + unsigned long data; + + /** + * Sample the line level + * @return the level read (0 or 1) + */ + u8 (*read_bit)(unsigned long); + + /** Sets the line level */ + void (*write_bit)(unsigned long, u8); + + /** + * touch_bit is the lowest-level function for devices that really + * support the 1-wire protocol. + * touch_bit(0) = write-0 cycle + * touch_bit(1) = write-1 / read cycle + * @return the bit read (0 or 1) + */ + u8 (*touch_bit)(unsigned long, u8); + + /** + * Reads a bytes. Same as 8 touch_bit(1) calls. + * @return the byte read + */ + u8 (*read_byte)(unsigned long); + + /** + * Writes a byte. Same as 8 touch_bit(x) calls. + */ + void (*write_byte)(unsigned long, u8); + + /** + * Same as a series of read_byte() calls + * @return the number of bytes read + */ + u8 (*read_block)(unsigned long, u8 *, int); + + /** Same as a series of write_byte() calls */ + void (*write_block)(unsigned long, const u8 *, int); + + /** + * Combines two reads and a smart write for ROM searches + * @return bit0=Id bit1=comp_id bit2=dir_taken + */ + u8 (*triplet)(unsigned long, u8); + + /** + * long write-0 with a read for the presence pulse detection + * @return -1=Error, 0=Device present, 1=No device present + */ + u8 (*reset_bus)(unsigned long); + + /** Really nice hardware can handles the ROM searches */ + void (*search)(unsigned long, w1_slave_found_callback); }; struct w1_master @@ -137,7 +184,7 @@ struct w1_master }; int w1_create_master_attributes(struct w1_master *); -void w1_search(struct w1_master *dev); +void w1_search(struct w1_master *dev, w1_slave_found_callback cb); #endif /* __KERNEL__ */ diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c index 2173336b60a..00f03222017 100644 --- a/drivers/w1/w1_io.c +++ b/drivers/w1/w1_io.c @@ -129,6 +129,47 @@ static u8 w1_read_bit(struct w1_master *dev) return result & 0x1; } +/** + * Does a triplet - used for searching ROM addresses. + * Return bits: + * bit 0 = id_bit + * bit 1 = comp_bit + * bit 2 = dir_taken + * If both bits 0 & 1 are set, the search should be restarted. + * + * @param dev the master device + * @param bdir the bit to write if both id_bit and comp_bit are 0 + * @return bit fields - see above + */ +u8 w1_triplet(struct w1_master *dev, int bdir) +{ + if ( dev->bus_master->triplet ) + return(dev->bus_master->triplet(dev->bus_master->data, bdir)); + else { + u8 id_bit = w1_touch_bit(dev, 1); + u8 comp_bit = w1_touch_bit(dev, 1); + u8 retval; + + if ( id_bit && comp_bit ) + return(0x03); /* error */ + + if ( !id_bit && !comp_bit ) { + /* Both bits are valid, take the direction given */ + retval = bdir ? 0x04 : 0; + } else { + /* Only one bit is valid, take that direction */ + bdir = id_bit; + retval = id_bit ? 0x05 : 0x02; + } + + if ( dev->bus_master->touch_bit ) + w1_touch_bit(dev, bdir); + else + w1_write_bit(dev, bdir); + return(retval); + } +} + /** * Reads 8 bits. * @@ -233,7 +274,7 @@ void w1_search_devices(struct w1_master *dev, w1_slave_found_callback cb) if (dev->bus_master->search) dev->bus_master->search(dev->bus_master->data, cb); else - w1_search(dev); + w1_search(dev, cb); } EXPORT_SYMBOL(w1_touch_bit); diff --git a/drivers/w1/w1_io.h b/drivers/w1/w1_io.h index d6daa3189c6..af5829778aa 100644 --- a/drivers/w1/w1_io.h +++ b/drivers/w1/w1_io.h @@ -26,6 +26,7 @@ void w1_delay(unsigned long); u8 w1_touch_bit(struct w1_master *, int); +u8 w1_triplet(struct w1_master *dev, int bdir); void w1_write_8(struct w1_master *, u8); u8 w1_read_8(struct w1_master *); int w1_reset_bus(struct w1_master *); -- cgit v1.2.3-18-g5258 From 2a9d0c178158da4a9bcf22311a414c26a8102d13 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sat, 4 Jun 2005 01:31:02 +0400 Subject: [PATCH] w1: Adds a sysfs entry (w1_master_search) that allows you to disable/enable periodic searches. Adds a sysfs entry (w1_master_search) that allows you to disable/enable periodic searches. Signed-off-by: Ben Gardner Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- drivers/w1/w1.h | 1 + drivers/w1/w1_int.c | 1 + 3 files changed, 51 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 4fa959f0855..48da17596d4 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -148,6 +148,39 @@ static ssize_t w1_master_attribute_show_name(struct device *dev, struct device_a return count; } +static ssize_t w1_master_attribute_store_search(struct device * dev, + struct device_attribute *attr, + const char * buf, size_t count) +{ + struct w1_master *md = container_of(dev, struct w1_master, dev); + + if (down_interruptible (&md->mutex)) + return -EBUSY; + + md->search_count = simple_strtol(buf, NULL, 0); + + up(&md->mutex); + + return count; +} + +static ssize_t w1_master_attribute_show_search(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct w1_master *md = container_of(dev, struct w1_master, dev); + ssize_t count; + + if (down_interruptible (&md->mutex)) + return -EBUSY; + + count = sprintf(buf, "%d\n", md->search_count); + + up(&md->mutex); + + return count; +} + static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf) { struct w1_master *md = container_of(dev, struct w1_master, dev); @@ -242,6 +275,12 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device __ATTR(w1_master_##_name, _mode, \ w1_master_attribute_show_##_name, NULL) +#define W1_MASTER_ATTR_RW(_name, _mode) \ + struct device_attribute w1_master_attribute_##_name = \ + __ATTR(w1_master_##_name, _mode, \ + w1_master_attribute_show_##_name, \ + w1_master_attribute_store_##_name) + static W1_MASTER_ATTR_RO(name, S_IRUGO); static W1_MASTER_ATTR_RO(slaves, S_IRUGO); static W1_MASTER_ATTR_RO(slave_count, S_IRUGO); @@ -249,6 +288,7 @@ static W1_MASTER_ATTR_RO(max_slave_count, S_IRUGO); static W1_MASTER_ATTR_RO(attempts, S_IRUGO); static W1_MASTER_ATTR_RO(timeout, S_IRUGO); static W1_MASTER_ATTR_RO(pointer, S_IRUGO); +static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO); static struct attribute *w1_master_default_attrs[] = { &w1_master_attribute_name.attr, @@ -258,6 +298,7 @@ static struct attribute *w1_master_default_attrs[] = { &w1_master_attribute_attempts.attr, &w1_master_attribute_timeout.attr, &w1_master_attribute_pointer.attr, + &w1_master_attribute_search.attr, NULL }; @@ -643,11 +684,14 @@ int w1_process(void *data) if (!dev->initialized) continue; + if (dev->search_count == 0) + continue; + if (down_interruptible(&dev->mutex)) continue; list_for_each_entry(sl, &dev->slist, w1_slave_entry) - clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); + clear_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags); w1_search_devices(dev, w1_slave_found); @@ -662,6 +706,10 @@ int w1_process(void *data) } else if (test_bit(W1_SLAVE_ACTIVE, (unsigned long *)&sl->flags)) sl->ttl = dev->slave_ttl; } + + if (dev->search_count > 0) + dev->search_count--; + up(&dev->mutex); } diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 3cfdd08d32f..6b5f7be50b8 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -162,6 +162,7 @@ struct w1_master int slave_ttl; int initialized; u32 id; + int search_count; atomic_t refcnt; diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index 280f140ae69..cf18f1324f0 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -69,6 +69,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, dev->initialized = 0; dev->id = id; dev->slave_ttl = slave_ttl; + dev->search_count = -1; /* continual scan */ atomic_set(&dev->refcnt, 2); -- cgit v1.2.3-18-g5258 From 99c5bfe993af1af37ddd615e72207dc7220dc526 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sat, 4 Jun 2005 01:31:26 +0400 Subject: [PATCH] w1: Adds a default family so that new slave families will show up in sysfs. Adds a default family so that new slave families will show up in sysfs. Signed-off-by: Ben Gardner Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/w1.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 48da17596d4..0e6ccd46af0 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -59,6 +59,19 @@ static pid_t control_thread; static int control_needs_exit; static DECLARE_COMPLETION(w1_control_complete); +/* stuff for the default family */ +static ssize_t w1_famdefault_read_name(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct w1_slave *sl = container_of(dev, struct w1_slave, dev); + return(sprintf(buf, "%s\n", sl->name)); +} +static struct w1_family_ops w1_default_fops = { + .rname = &w1_famdefault_read_name, +}; +static struct w1_family w1_default_family = { + .fops = &w1_default_fops, +}; + static int w1_master_match(struct device *dev, struct device_driver *drv) { return 1; @@ -360,14 +373,16 @@ static int __w1_attach_slave_device(struct w1_slave *sl) return err; } - err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); - if (err < 0) { - dev_err(&sl->dev, - "sysfs file creation for [%s] failed. err=%d\n", - sl->dev.bus_id, err); - device_remove_file(&sl->dev, &sl->attr_name); - device_unregister(&sl->dev); - return err; + if ( sl->attr_bin.read ) { + err = sysfs_create_bin_file(&sl->dev.kobj, &sl->attr_bin); + if (err < 0) { + dev_err(&sl->dev, + "sysfs file creation for [%s] failed. err=%d\n", + sl->dev.bus_id, err); + device_remove_file(&sl->dev, &sl->attr_name); + device_unregister(&sl->dev); + return err; + } } list_add_tail(&sl->w1_slave_entry, &sl->master->slist); @@ -403,12 +418,10 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) spin_lock(&w1_flock); f = w1_family_registered(rn->family); if (!f) { - spin_unlock(&w1_flock); + f= &w1_default_family; dev_info(&dev->dev, "Family %x for %02x.%012llx.%02x is not registered.\n", rn->family, rn->family, (unsigned long long)rn->id, rn->crc); - kfree(sl); - return -ENODEV; } __w1_family_get(f); spin_unlock(&w1_flock); @@ -449,7 +462,9 @@ static void w1_slave_detach(struct w1_slave *sl) flush_signals(current); } - sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin); + if ( sl->attr_bin.read ) { + sysfs_remove_bin_file (&sl->dev.kobj, &sl->attr_bin); + } device_remove_file(&sl->dev, &sl->attr_name); device_unregister(&sl->dev); w1_family_put(sl->family); -- cgit v1.2.3-18-g5258 From 6adf87bd7b7832105b9c6bc08adf6a4d229f1e79 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Sat, 4 Jun 2005 01:29:25 +0400 Subject: [PATCH] w1: reconnect feature. I've created reconnect feature - if on start there are no registered families all new devices will have defailt family, later when driver for appropriate family is loaded, slaves, which were faound earlier, will still have defult family instead of right one. Reconnect feature will force control thread to run through all master devices and all slaves found and search for slaves with default family id and try to reconnect them. It does not store newly registered family and does not check only those slaves which have reg_num.family the same as being registered one - all slaves with default family are reconnected. Signed-off-by: Evgeniy Polyakov Signed-off-by: Greg Kroah-Hartman --- drivers/w1/ds_w1_bridge.c | 4 +-- drivers/w1/w1.c | 68 ++++++++++++++++++++++++++++++++++++----------- drivers/w1/w1.h | 6 ++++- drivers/w1/w1_family.c | 3 ++- drivers/w1/w1_int.c | 11 ++++---- 5 files changed, 67 insertions(+), 25 deletions(-) (limited to 'drivers') diff --git a/drivers/w1/ds_w1_bridge.c b/drivers/w1/ds_w1_bridge.c index 0baaeb5fd63..7bddd8ac7d7 100644 --- a/drivers/w1/ds_w1_bridge.c +++ b/drivers/w1/ds_w1_bridge.c @@ -83,11 +83,11 @@ static u8 ds9490r_read_byte(unsigned long data) return byte; } -static void ds9490r_write_block(unsigned long data, u8 *buf, int len) +static void ds9490r_write_block(unsigned long data, const u8 *buf, int len) { struct ds_device *dev = (struct ds_device *)data; - ds_write_block(dev, buf, len); + ds_write_block(dev, (u8 *)buf, len); } static u8 ds9490r_read_block(unsigned long data, u8 *buf, int len) diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c index 0e6ccd46af0..b460927ec32 100644 --- a/drivers/w1/w1.c +++ b/drivers/w1/w1.c @@ -469,6 +469,8 @@ static void w1_slave_detach(struct w1_slave *sl) device_unregister(&sl->dev); w1_family_put(sl->family); + sl->master->slave_count--; + memcpy(&msg.id.id, &sl->reg_num, sizeof(msg.id.id)); msg.type = W1_SLAVE_REMOVE; w1_netlink_send(sl->master, &msg); @@ -492,6 +494,20 @@ static struct w1_master *w1_search_master(unsigned long data) return (found)?dev:NULL; } +void w1_reconnect_slaves(struct w1_family *f) +{ + struct w1_master *dev; + + spin_lock_bh(&w1_mlock); + list_for_each_entry(dev, &w1_masters, w1_master_entry) { + dev_info(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", + dev->name, f->fid); + set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); + } + spin_unlock_bh(&w1_mlock); +} + + static void w1_slave_found(unsigned long data, u64 rn) { int slave_count; @@ -637,7 +653,7 @@ static int w1_control(void *data) flush_signals(current); list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) { - if (!control_needs_exit && !dev->need_exit) + if (!control_needs_exit && !dev->flags) continue; /* * Little race: we can create thread but not set the flag. @@ -648,12 +664,8 @@ static int w1_control(void *data) continue; } - spin_lock_bh(&w1_mlock); - list_del(&dev->w1_master_entry); - spin_unlock_bh(&w1_mlock); - if (control_needs_exit) { - dev->need_exit = 1; + set_bit(W1_MASTER_NEED_EXIT, &dev->flags); err = kill_proc(dev->kpid, SIGTERM, 1); if (err) @@ -662,16 +674,42 @@ static int w1_control(void *data) dev->kpid); } - wait_for_completion(&dev->dev_exited); + if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { + wait_for_completion(&dev->dev_exited); + spin_lock_bh(&w1_mlock); + list_del(&dev->w1_master_entry); + spin_unlock_bh(&w1_mlock); + + list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { + list_del(&sl->w1_slave_entry); + + w1_slave_detach(sl); + kfree(sl); + } + w1_destroy_master_attributes(dev); + atomic_dec(&dev->refcnt); + continue; + } + + if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) { + dev_info(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name); + down(&dev->mutex); + list_for_each_entry(sl, &dev->slist, w1_slave_entry) { + if (sl->family->fid == W1_FAMILY_DEFAULT) { + struct w1_reg_num rn; + list_del(&sl->w1_slave_entry); + w1_slave_detach(sl); + + memcpy(&rn, &sl->reg_num, sizeof(rn)); - list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) { - list_del(&sl->w1_slave_entry); + kfree(sl); - w1_slave_detach(sl); - kfree(sl); + w1_attach_slave_device(dev, &rn); + } + } + clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); + up(&dev->mutex); } - w1_destroy_master_attributes(dev); - atomic_dec(&dev->refcnt); } } @@ -686,14 +724,14 @@ int w1_process(void *data) daemonize("%s", dev->name); allow_signal(SIGTERM); - while (!dev->need_exit) { + while (!test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) { try_to_freeze(PF_FREEZE); msleep_interruptible(w1_timeout * 1000); if (signal_pending(current)) flush_signals(current); - if (dev->need_exit) + if (test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) break; if (!dev->initialized) diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h index 6b5f7be50b8..4f0a986e33e 100644 --- a/drivers/w1/w1.h +++ b/drivers/w1/w1.h @@ -151,6 +151,9 @@ struct w1_bus_master void (*search)(unsigned long, w1_slave_found_callback); }; +#define W1_MASTER_NEED_EXIT 0 +#define W1_MASTER_NEED_RECONNECT 1 + struct w1_master { struct list_head w1_master_entry; @@ -169,7 +172,8 @@ struct w1_master void *priv; int priv_size; - int need_exit; + long flags; + pid_t kpid; struct semaphore mutex; diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c index b8502d910c5..73e73f6be48 100644 --- a/drivers/w1/w1_family.c +++ b/drivers/w1/w1_family.c @@ -60,9 +60,10 @@ int w1_register_family(struct w1_family *newf) newf->need_exit = 0; list_add_tail(&newf->family_entry, &w1_families); } - spin_unlock(&w1_flock); + w1_reconnect_slaves(newf); + return ret; } diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c index cf18f1324f0..35e85d96170 100644 --- a/drivers/w1/w1_int.c +++ b/drivers/w1/w1_int.c @@ -124,10 +124,9 @@ int w1_add_master_device(struct w1_bus_master *master) /* validate minimum functionality */ if (!(master->touch_bit && master->reset_bus) && - !(master->write_bit && master->read_bit)) - { - printk(KERN_ERR "w1_add_master_device: invalid function set\n"); - return(-EINVAL); + !(master->write_bit && master->read_bit)) { + printk(KERN_ERR "w1_add_master_device: invalid function set\n"); + return(-EINVAL); } dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_driver, &w1_device); @@ -163,7 +162,7 @@ int w1_add_master_device(struct w1_bus_master *master) return 0; err_out_kill_thread: - dev->need_exit = 1; + 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", @@ -181,7 +180,7 @@ void __w1_remove_master_device(struct w1_master *dev) int err; struct w1_netlink_msg msg; - dev->need_exit = 1; + set_bit(W1_MASTER_NEED_EXIT, &dev->flags); err = kill_proc(dev->kpid, SIGTERM, 1); if (err) dev_err(&dev->dev, -- cgit v1.2.3-18-g5258 From e5c515b4532f4aac2b1136612d8c3ecd1891f431 Mon Sep 17 00:00:00 2001 From: Evgeniy Polyakov Date: Fri, 10 Jun 2005 14:53:22 +0400 Subject: [PATCH] w1: fix compiler warnings Signed-off-by: Evgeniy Polyakov --- drivers/w1/w1_family.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c index 73e73f6be48..02eee57d3c0 100644 --- a/drivers/w1/w1_family.c +++ b/drivers/w1/w1_family.c @@ -27,6 +27,7 @@ DEFINE_SPINLOCK(w1_flock); static LIST_HEAD(w1_families); +extern void w1_reconnect_slaves(struct w1_family *f); static int w1_check_family(struct w1_family *f) { -- cgit v1.2.3-18-g5258