Subject: onewire bus patch for review
To: None <tech-kern@NetBSD.org>
From: Jeff Rizzo <riz@NetBSD.org>
List: tech-kern
Date: 04/04/2006 17:59:42
A while back, I posted to current-users to see if anyone was
interested in some code I was working on to attach Dallas Semiconductor
One-wire devices via the gpio(4) framework, and I got some favorable
responses.

Well, about a week after that, Alexander Yurchenko added code to OpenBSD
to do just that - and it was much cleaner than what I had up to that
point.  So, I decided to port it rather than reinvent the wheel.

I did, however have to fix the onewire search algorithm - it's a bit
convoluted, and his did not originally find all the devices on my bus.

These patches include support for some temperature sensors, including
the popular ds18b20 - I have not yet ported the "owid" driver, as I
don't have any devices to test with at the moment.

I'd appreciate any feedback on the patches, which can be found here:

http://www.tastylime.net/netbsd/onewire.diff

To use, lines similar to this should be added to your kernel
config:

gpioow* at gpio? offset 6 mask 0x1
onewire* at gpioow?
owtemp* at onewire?
options ONEWIRE_DEBUG
options ONEWIREVERBOSE

(The offset will need to be changed to the actual GPIO pin number on the
gpio bus you use)

I've tested this with several DS18B20 and DS1822 temperature sensors,
connected to a Soekris 4521 :

1974672+38996+222304 [160752+151828]=0x26f6d4
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 3.99.17 (ONEWIRE) #156: Tue Apr  4 16:51:45 PDT 2006
        riz@boogers.sf.ca.us:/work/netbsd/onewire-dev/buildobj/work/netbsd/onewire-dev/src/sys/arch/i386/compile/ONEWIRE
total memory = 65088 KB
avail memory = 61276 KB
BIOS32 rev. 0 found at 0xf7840
mainbus0 (root)
cpu0 at mainbus0: (uniprocessor)
cpu0: AMD Am5x86 W/B 133/160 (486-class), id 0x4f4
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
elansc0 at pci0 dev 0 function 0: AMD Elan SC520 System Controller
elansc0: product 0 stepping 1.1, CPU clock 133MHz
gpio0 at elansc0: 32 pins
gpioow0 at gpio0 pins 6: DATA[6]
onewire0 at gpioow0
vendor 0x168c product 0x0013 (ethernet network, revision 0x01) at pci0 dev 16 function 0 not configured
cbb0 at pci0 dev 17 function 0: vendor 0x104c product 0xac51 (rev. 0x00)
cbb1 at pci0 dev 17 function 1: vendor 0x104c product 0xac51 (rev. 0x00)
sip0 at pci0 dev 18 function 0: NatSemi DP83815 10/100 Ethernet, rev 00
sip0: interrupting at irq 5
sip0: Ethernet address 00:00:24:c1:b8:48
nsphyter0 at sip0 phy 0: DP83815 10/100 media interface, rev. 1
nsphyter0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
sip1 at pci0 dev 19 function 0: NatSemi DP83815 10/100 Ethernet, rev 00
sip1: interrupting at irq 9
sip1: Ethernet address 00:00:24:c1:b8:49
nsphyter1 at sip1 phy 0: DP83815 10/100 media interface, rev. 1
nsphyter1: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
cbb0: interrupting at irq 11
cardslot0 at cbb0 slot 0 flags 0
cardbus0 at cardslot0: bus 1
pcmcia0 at cardslot0
cbb1: interrupting at irq 11
cardslot1 at cbb1 slot 1 flags 0
cardbus1 at cardslot1: bus 2
pcmcia1 at cardslot1
isa0 at mainbus0
com0 at isa0 port 0x3f8-0x3ff irq 4: ns16550a, working fifo
com0: console
com1 at isa0 port 0x2f8-0x2ff irq 3: ns16550a, working fifo
wdc1 at isa0 port 0x170-0x177 irq 15
atabus0 at wdc1 channel 0
npx0 at isa0 port 0xf0-0xff
IPsec: Initialized Security Association Processing.
owtemp0 at onewire0 family 0x28 sn 0000001b57f4
owtemp1 at onewire0 family 0x28 sn 0000001b635f
owtemp2 at onewire0 family 0x28 sn 0000001b5b7f
owtemp3 at onewire0 family 0x22 sn 0000000a8e36
wd0 at atabus0 drive 0: <SanDisk SDCFB-128>
wd0: drive supports 1-sector PIO transfers, LBA addressing
wd0: 122 MB, 978 cyl, 8 head, 32 sec, 512 bytes/sect x 250368 sectors
boot device: sip0
root on sip0
nfs_boot: trying DHCP/BOOTP
sip0: link state changed to DOWN
sip0: link state changed to UP
nfs_boot: DHCP next-server: 192.168.3.1
nfs_boot: my_domain=york.redcrowgroup.com
nfs_boot: my_addr=192.168.3.87
nfs_boot: my_mask=255.255.255.0
nfs_boot: gateway=192.168.3.1
root on 192.168.3.1:/usr/netboot/soekris-current-20051006
root file system type: nfs
WARNING: NVRAM century is 19 but RTC year is 2006
warning: no /dev/console
init: Creating mfs /dev (414 blocks, 1024 inodes)
/etc/rc.conf is not configured.  Multiuser boot aborted.
Enter pathname of shell or RETURN for /bin/sh: 
Terminal type? [unknown] vt100
Terminal type is vt100.                                                 
We recommend creating a non-root account and using su(1) for root access.
# envstat
            owtemp0            owtemp1            owtemp2            owtemp3
               degC               degC               degC               degC
              26.12              25.06              25.94              26.31
# 


Comments and suggestions appreciated.  
+j