Dallas 1-wire protocol implementation.
On Sun, 20 Jun 2004 16:51:31 +0400
Evgeniy Polyakov <[email protected]> wrote:
Ping.
iButton support will coming soon.
Quoted 24 lines
Hello.
I have some notes about such devices and design of the Linux kernel w1 implementation.1. After rereading specs for various *<->w1 master
devices I found that all they do support bit interface since it is required by w1 search algorithm. Maybe some devices exist that drive some register when they found new slave device on the bus and provide it's address in other register, and also such devices require flags that indicates that search must be proceeded or stopped.
I don't now about such devices, but if they exist one can easily update w1 master operations structure to support search callback for it, and main master's ->process() routing to call it instead of default bit-bangingw1_search()call. I will do it if you provide datasheet.2. By design I leave main master's ->process() call as easy as possible and move all data processing out to slave device drivers(family drivers). Master just searches for devices on the bus, requests it's drivers and provide them all needed functionality. Now I extended a bit w1 master operations to support read_/write_byte() and
reset_bus()calls, so if provided they will be called before bit operations.
Quoted 8 lines
So in case of DS2490 you just need to write driver implementing
read_bitandwrite_bitoperations using some USB commands, then register it as master. Any slave devices that will be found in bus connected to DS2490 will use automatically any operations that you will provide, but they actually needs only bit operations. Others are just extensions.Thank you for review and comments.
Evgeniy Polyakov ( s0mbre )
Only failure makes us experts. -- Theo de Raadt
-------------- next part --------------
MAINTAINERS renamed from MAINTAINERS.orig +6 -0
@@ -2336,6 +2336,12 @@ M: [email protected] S: Maintained +W1 DALLAS'S 1-WIRE BUS +P: Evgeniy Polyakov +M: [email protected] +L: [email protected] +S: Maintained + WAN ROUTER & SANGOMA WANPIPE DRIVERS & API (X.25, FRAME RELAY, PPP, CISCO HDLC) P: Nenad Corbic M: [email protected]
-------------- next part --------------
drivers/Kconfig renamed from drivers/Kconfig~ +2 -0
@@ -42,6 +42,8 @@ source "drivers/i2c/Kconfig" +source "drivers/w1/Kconfig" + source "drivers/misc/Kconfig" source "drivers/media/Kconfig"
-------------- next part --------------
drivers/Makefile renamed from drivers/Makefile~ +1 -0
@@ -42,6 +42,7 @@ obj-$(CONFIG_SERIO) += input/serio/ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_I2C) += i2c/ +obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_PHONE) += telephony/ obj-$(CONFIG_MD) += md/ obj-$(CONFIG_BT) += bluetooth/
-------------- next part --------------
drivers/w1/Kconfig renamed from tmp/w1/Kconfig +31 -0
@@ -0,0 +1,31 @@ +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 + 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 + will be called wire.ko. + +config W1_MATROX + tristate "Matrox G400 transport layer for 1-wire" + depends on W1 + 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 + will be called matrox_w1.ko. + +config W1_THERM + tristate "Thermal family implementation" + depends on W1 + help + Say Y here if you want to connect 1-wire thermal sensors to you + wire. + +endmenu
drivers/w1/Makefile renamed from tmp/w1/Makefile +9 -0
@@ -0,0 +1,9 @@ +# +# Makefile for the Dallas's 1-wire bus. +# + +obj-$(CONFIG_W1) += wire.o +wire-objs := w1.o w1_int.o w1_family.o w1_netlink.o w1_io.o + +obj-$(CONFIG_W1_MATROX) += matrox_w1.o +obj-$(CONFIG_W1_THERM) += w1_therm.o
drivers/w1/matrox_w1.c renamed from tmp/w1/matrox_w1.c +259 -0
259 lines not on this page · raw message
drivers/w1/w1.c renamed from tmp/w1/w1.c +623 -0
623 lines not on this page · raw message
drivers/w1/w1.h renamed from tmp/w1/w1.h +112 -0
112 lines not on this page · raw message
drivers/w1/w1_family.c renamed from tmp/w1/w1_family.c +133 -0
133 lines not on this page · raw message
drivers/w1/w1_family.h renamed from tmp/w1/w1_family.h +65 -0
65 lines not on this page · raw message
drivers/w1/w1_int.c renamed from tmp/w1/w1_int.c +208 -0
208 lines not on this page · raw message
drivers/w1/w1_int.h renamed from tmp/w1/w1_int.h +36 -0
@@ -0,0 +1,36 @@ +/* +* w1_int.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* 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 +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __W1_INT_H +#define __W1_INT_H + +#include <linux/kernel.h> +#include <linux/device.h> + +#include "w1.h" + +struct w1_master *w1_alloc_dev (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 *); + +#endif /* __W1_INT_H */
drivers/w1/w1_io.c renamed from tmp/w1/w1_io.c +138 -0
138 lines not on this page · raw message
drivers/w1/w1_io.h renamed from tmp/w1/w1_io.h +35 -0
@@ -0,0 +1,35 @@ +/* +* w1_io.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* 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 +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __W1_IO_H +#define __W1_IO_H + +#include "w1.h" + +void w1_delay (unsigned long ); +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 ); + +#endif /* __W1_IO_H */
drivers/w1/w1_log.h renamed from tmp/w1/w1_log.h +38 -0
@@ -0,0 +1,38 @@ +/* +* w1_log.h +* +* Copyright (c) 2004 Evgeniy Polyakov <[email protected]> +* +* +* 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 +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef __W1_LOG_H +#define __W1_LOG_H + +#define DEBUG + +#ifdef W1_DEBUG +# define assert (expr) do {} while (0) +#else +# define assert (expr) \ + if(unlikely(!(expr))) { \ + printk(KERN_ERR "Assertion failed! %s,%s,%s,line=%d\n", \ + #expr,__FILE__,__FUNCTION__,__LINE__); \ + } +#endif + +#endif /* __W1_LOG_H */ +
drivers/w1/w1_netlink.c renamed from tmp/w1/w1_netlink.c +55 -0
55 lines not on this page · raw message
drivers/w1/w1_netlink.h renamed from tmp/w1/w1_netlink.h +44 -0
44 lines not on this page · raw message
drivers/w1/w1_therm.c renamed from tmp/w1/w1_therm.c +177 -0
177 lines not on this page · raw message
Hi all,
How many times will Evgeniy have to resend his work?
If it's OK and of general interest, let's integrate it into the main kernel tree now.
If for some reason w1 is not to be integrated into the kernel, better let Evgeniy know why instead of waiting for another dozen resends.
Thanks.
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Quoted 5 lines · Evgeniy Polyakov
On Sun, 20 Jun 2004 16:51:31 +0400
Evgeniy Polyakov <[email protected]> wrote:Ping.
iButton support will coming soon.
Ok, sorry for the long delay.
I finally commited this patch, along with a bunch of minor cleanups:
- small formatting ones (took the extra " " out before the "(" in a function call)
- made some global symbols have a "w1" in them (like "flock")
And then I disabled this whole function:
Quoted 24 lines
drivers/w1/w1.c renamed from tmp/w1/w1.c +24
-0+ssize_t w1_master_attribute_show (struct device *dev,char *buf) +{ + struct w1_master *md = container_of (dev, struct w1_master, dev); +int c =PAGE_SIZE ; + +if (down_interruptible (&md->mutex)) +return -EBUSY ; + + c -=snprintf (buf +PAGE_SIZE - c, c,"%s\n" , md->name); + c -=snprintf (buf +PAGE_SIZE - c, c, +"bus_master=0x%p, timeout=%d, max_slave_count=%d, attempts=%lu\n" , + md->bus_master, w1_timeout, md->max_slave_count, + md->attempts); + c -=snprintf (buf +PAGE_SIZE - c, c,"%d slaves: " , + md->slave_count); +if (md->slave_count =0 ) + c -=snprintf (buf +PAGE_SIZE - c, c,"no.\n" ); +else { +struct list_head *ent, *n; +struct w1_slave *sl; + + list_for_each_safe (ent, n, &md->slist) { + sl = list_entry (ent, struct w1_slave, w1_slave_entry); +
drivers/w1/w1.c line 173
Quoted 10 lines
drivers/w1/w1.c renamed from tmp/w1/w1.c +10
-0+ c -=snprintf (buf +PAGE_SIZE - c, c,"%s[%p] " , + sl->name, sl); + } + c -=snprintf (buf +PAGE_SIZE - c, c,"\n" ); + } + +up (&md->mutex); + +return PAGE_SIZE - c; +}
As sysfs files should be 1 value per file. If you want to output a whole bunch of info, you need to make a whole bunch of files.
I've added the patch to my bk trees, and it should show up in the next -mm release. If you need a copy of the patch I've applied, so that you can send me updates and you don't want to mess with bitkeeper, please let me know and I'll send it to you.
Oh heck, I've put it here for everyone to see, to make it easier:
www.kernel.org/pub/linux/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
thanks, and again, sorry for the delay.
greg k-h
Quoted 2 lines
Oh heck, I've put it here for everyone to see, to make it easier:
www.kernel.org/pub/linux/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
I think it really is:
http://www.kernel.org/pub/linux/kernel/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
Signature · 2 lines
Jean Delvare http://khali.linux-fr.org/
Quoted 8 lines · On Fri, 9 Jul 2004 16:42:22 -0700 Greg KH <[email protected]> wrote:
Quoted 5 lines · Evgeniy Polyakov
On Sun, 20 Jun 2004 16:51:31 +0400
Evgeniy Polyakov <[email protected]> wrote:Ping.
iButton support will coming soon.Ok, sorry for the long delay.
Result definetely worth waiting.
Quoted 4 lines
I finally commited this patch, along with a bunch of minor cleanups:
- small formatting ones (took the extra " " out before the "(" in a function call)
- made some global symbols have a "w1" in them (like "flock")
I've checked your changes and totally agree.
Quoted 31 lines
And then I disabled this whole function:
Quoted 29 lines
drivers/w1/w1.c renamed from tmp/w1/w1.c +3
-0+ssize_t w1_master_attribute_show (struct device *dev,char *buf) +{ + struct w1_master *md = container_of (dev, struct w1_master,dev);+ int c =
PAGE_SIZE;drivers/w1/w1.c renamed from tmp/w1/w1.c +7
-0+ +if (down_interruptible (&md->mutex)) +return -EBUSY ; + + c -=snprintf (buf +PAGE_SIZE - c, c,"%s\n" , md->name); + c -= snprintf (buf + PAGE_SIZE - c, c, + "bus_master=0x%p, timeout=%d, max_slave_count=%d,attempts=%lu\n",+
md->bus_master,w1_timeout,md->max_slave_count,drivers/w1/w1.c renamed from tmp/w1/w1.c +17
-0+ md->attempts); + c -=snprintf (buf +PAGE_SIZE - c, c,"%d slaves: " , + md->slave_count); +if (md->slave_count =0 ) + c -=snprintf (buf +PAGE_SIZE - c, c,"no.\n" ); +else { +struct list_head *ent, *n; +struct w1_slave *sl; + + 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[%p] " , + sl->name, sl); + } + c -=snprintf (buf +PAGE_SIZE - c, c,"\n" ); + }
Quoted 8 lines
drivers/w1/w1.c line 173
Quoted 5 lines
drivers/w1/w1.c renamed from tmp/w1/w1.c +5
-0+ +up (&md->mutex); + +return PAGE_SIZE - c; +}As sysfs files should be 1 value per file. If you want to output a whole bunch of info, you need to make a whole bunch of files.
Ok, I will split it up.
Quoted 7 lines
I've added the patch to my bk trees, and it should show up in the next -mm release. If you need a copy of the patch I've applied, so that you can send me updates and you don't want to mess with bitkeeper, please let me know and I'll send it to you.
Oh heck, I've put it here for everyone to see, to make it easier:
www.kernel.org/pub/linux/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
Actually I found it there:www.kernel.org/pub/linux/kernel/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
Quoted 1 line
thanks, and again, sorry for the delay.
As I said, result worth waiting ;)
Thank you.
Quoted 1 line
greg k-h
Evgeniy Polyakov ( s0mbre )
Only failure makes us experts. -- Theo de Raadt
Quoted 5 lines · Evgeniy Polyakov
Quoted 2 lines
Oh heck, I've put it here for everyone to see, to make it easier:
www.kernel.org/pub/linux/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patchActually I found it there:
www.kernel.org/pub/linux/kernel/people/gregkh/i2c/2.6/2.6.7/w1-2.6.7.patch
Oops, you are correct, that's what I get for trying to remember the url from memory.
thanks,
greg k-h