Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Aug 2015 23:33:39 +0000 (UTC)
From:      Warner Losh <imp@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r287225 - in head: share/man/man4 share/man/man9 sys/conf sys/dev/ow sys/modules sys/modules/ow sys/modules/ow/ow sys/modules/ow/ow_temp sys/modules/ow/owc
Message-ID:  <201508272333.t7RNXdH5009539@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: imp
Date: Thu Aug 27 23:33:38 2015
New Revision: 287225
URL: https://svnweb.freebsd.org/changeset/base/287225

Log:
  New 1-Wire bus implementation. 1-Wire controller is abstracted, though
  only gpiobus configured via FDT is supported. Bus enumeration is
  supported. Devices are created for each device found. 1-Wire
  temperature controllers are supported, but other drivers could be
  written. Temperatures are polled and reported via a sysctl.  Errors
  are reported via sysctl counters. Mis-wired bus detection is included
  for more trouble shooting. See ow(4), owc(4) and ow_temp(4) for
  details of what's supported and known issues.
  
  This has been tested on Raspberry Pi-B, Pi2 and Beagle Bone Black
  with up to 7 devices.
  
  Differential Revision: https://reviews.freebsd.org/D2956
  Relnotes: yes
  MFC after: 2 weeks
  Reviewed by: loos@ (with many insightful comments)

Added:
  head/share/man/man4/ow.4   (contents, props changed)
  head/share/man/man4/ow_temp.4   (contents, props changed)
  head/share/man/man4/owc.4   (contents, props changed)
  head/share/man/man9/owll.9   (contents, props changed)
  head/share/man/man9/own.9   (contents, props changed)
  head/sys/dev/ow/
  head/sys/dev/ow/README.txt   (contents, props changed)
  head/sys/dev/ow/ow.c   (contents, props changed)
  head/sys/dev/ow/ow.h   (contents, props changed)
  head/sys/dev/ow/ow_temp.c   (contents, props changed)
  head/sys/dev/ow/owc_gpiobus.c   (contents, props changed)
  head/sys/dev/ow/owll.h   (contents, props changed)
  head/sys/dev/ow/owll_if.m   (contents, props changed)
  head/sys/dev/ow/own.h   (contents, props changed)
  head/sys/dev/ow/own_if.m   (contents, props changed)
  head/sys/modules/ow/
  head/sys/modules/ow/Makefile   (contents, props changed)
  head/sys/modules/ow/ow/
  head/sys/modules/ow/ow/Makefile   (contents, props changed)
  head/sys/modules/ow/ow_temp/
  head/sys/modules/ow/ow_temp/Makefile   (contents, props changed)
  head/sys/modules/ow/owc/
  head/sys/modules/ow/owc/Makefile   (contents, props changed)
Modified:
  head/share/man/man4/Makefile
  head/share/man/man9/Makefile
  head/sys/conf/files
  head/sys/modules/Makefile

Modified: head/share/man/man4/Makefile
==============================================================================
--- head/share/man/man4/Makefile	Thu Aug 27 22:42:02 2015	(r287224)
+++ head/share/man/man4/Makefile	Thu Aug 27 23:33:38 2015	(r287225)
@@ -379,6 +379,9 @@ MAN=	aac.4 \
 	oce.4 \
 	ohci.4 \
 	orm.4 \
+	ow.4 \
+	ow_temp.4 \
+	owc.4 \
 	${_padlock.4} \
 	pass.4 \
 	patm.4 \
@@ -667,6 +670,7 @@ MLINKS+=nge.4 if_nge.4
 MLINKS+=${_ntb.4} ${_if_ntb.4} \
 	${_ntb.4} ${_ntb_hw.4}
 MLINKS+=${_nxge.4} ${_if_nxge.4}
+MLINKS+=ow.4 onewire.4
 MLINKS+=patm.4 if_patm.4
 MLINKS+=pccbb.4 cbb.4
 MLINKS+=pcm.4 snd.4 \

Added: head/share/man/man4/ow.4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man4/ow.4	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,60 @@
+.\"
+.\" Copyright (c) 2015 M. Warner Losh
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 20, 2015
+.Dt OW 4
+.Os
+.Sh NAME
+.Nm ow
+.Nd Dallas Semiconductor 1-Wire bus
+.Sh SYNOPSIS
+.Cd device ow
+.Sh DESCRIPTION
+The
+.Nm
+module implements the Dallas Semiconductor 1-Wire bus.
+It attaches to the
+.Xr owc 4
+driver, which implements the low-level signaling of the
+1-Wire bus.
+.Sh SEE ALSO
+.Xr ow_temp 4 ,
+.Xr owc 4 ,
+.Xr owll 9 ,
+.Xr own 9
+.Sh LEGAL
+.Tn 1-Wire
+is a registered trademark of Maxim Integrated Products, Inc.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm
+device driver and this manual page were written by
+.An Warner Losh .

Added: head/share/man/man4/ow_temp.4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man4/ow_temp.4	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,155 @@
+.\"
+.\" Copyright (c) 2015 M. Warner Losh
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 20, 2015
+.Dt OW_TEMP 4
+.Os
+.Sh NAME
+.Nm ow_temp
+.Nd Dallas Semiconductor 1-Wire Temperature sensor
+.Sh SYNOPSIS
+.Cd device ow_temp
+.Sh DESCRIPTION
+The
+.Nm
+module supports many of the 1-Wire temperature sensors.
+.Pp
+The sensor is read periodically and the results returned via a
+.Xr sysctl 3
+as described below.
+.Sh HARDWARE
+These temperature sensors are supported by the
+.Nm
+driver:
+.Bl -tag -width MAX31820 -compact
+.It DS1820
+1-Wire Digital Thermometer
+.It DS18S20
+High-Precision 1-Wire Digital Thermometer
+.It DS18B20
+Programmable Resolution 1-Wire Digital Thermometer
+.It DS1822
+Econo 1-Wire Digital Thermometer
+.It DS1825
+Programmable Resolution 1-Wire Digital Thermometer with 4-bit ID
+.It MAX31820
+1-Wire, Parasite-Power, Ambient Temperature Sensor
+.El
+.Pp
+The driver supports Family codes 0x10, 0x22, 0x28, and 0x3b.
+.Sh SYSCTL
+The
+.Nm
+driver reports data via
+.Xr sysctl 8
+entries in the device's node in the
+.Xr sysctl 8
+tree:
+.Bl -tag -width xxxxxxxxxx
+.It temperature
+The last temperature read, in milli-Kelvin.
+.It badcrc
+The number of CRC errors in reading the temperature form the
+device.
+Some CRC errors are to be expected.
+High rates of CRC errors, however, generally indicate a noisy
+environment, cabling issues, or too many devices on the bus.
+.It badread
+The number of times a non-CRC error was encountered reading the temperature
+from the card.
+This type of error is very rare.
+.It reading_interval
+The time, in ticks, between successive reads of the sensor.
+.It parasite
+This item is non-zero when the device is connected using its parasitic
+power mode.
+It can also indicate a wiring error.
+.El
+.Pp
+Temperatures are reported in milli-Kelvin, even though the absolute
+accuracy is around 0.2 degrees for the good devices and around 1
+degree for cheaper devices.
+The devices report in steps of 0.0625 degrees.
+The driver preserves the precision of the device's measurements
+in its
+.Xr sysctl 8
+reports.
+These devices often have a much higher relative accuracy and
+repeatability than their absolute accuracy.
+This makes them well suited for control loops that strive for
+stability and become possible if the full precision is preserved.
+.Sh SEE ALSO
+.Xr ow 4 ,
+.Xr owc 4 ,
+.Xr sysctl 8 ,
+.Xr owll 9 ,
+.Xr own 9
+.Sh LEGAL
+.Tn 1-Wire
+is a registered trademark of Maxim Integrated Products, Inc.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm
+device driver and this manual page were written by
+.An Warner Losh .
+.Sh BUGS
+The parasitic mode of the devices does not work.
+It requires support from the
+.Xr owc 4
+driver that is unimplemented.
+.Pp
+The ID bits from the
+.Em DS1825
+are not recognized or reported.
+.Pp
+The type of the device is not reported via
+.Xr sysctl 8 .
+.Pp
+Alarm mode is not supported.
+It is not possible to set the low and high alarm temperatures.
+.Pp
+There is no way to write to the EEPROM.
+.Pp
+.Dq Convert Temperature
+requests are sent directly to the device.
+There is no way to use the broadcast ability of the 1-Wire bus to do
+all the conversions in parallel.
+.Pp
+It is not possible to set the precision on those devices that support
+it.
+.Pp
+The time to convert is fixed at 1 second, even though some devices are
+faster.
+.Pp
+There is no character device to supply a stream of readings to a
+program.
+Programs interested in the temperature must poll the sysctl to get the
+temperature.

Added: head/share/man/man4/owc.4
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man4/owc.4	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,95 @@
+.\"
+.\" Copyright (c) 2015 M. Warner Losh
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 20, 2015
+.Dt OWC 4
+.Os
+.Sh NAME
+.Nm owc
+.Nd Dallas Semiconductor 1-Wire Controller
+.Sh SYNOPSIS
+.Cd device owc
+.Sh DESCRIPTION
+The
+.Nm
+module implements Dallas Semiconductor 1-Wire signaling.
+It attaches the
+.Xr ow 4
+driver 1-Wire bus protocol.
+The
+.Nm
+device implements the Link Layer of the 1-Wire bus protocol stack.
+.Pp
+Bit banging a pin on a
+.Xr gpiobus 4
+is the only supported controller.
+Both standard and overdrive transfer timings are implemented.
+Strong pull-up functionality needed to support parasitic mode is not
+implemented.
+.Pp
+To enable 1-Wire for FDT systems requires modifying the DTS for your
+board to add something like:
+.Bd -literal
+/ {
+	...
+	onewire {
+		compatible = "w1-gpio";
+		gpios = <&gpio 4 1>;
+	};
+	...
+};
+.Ed
+.Pp
+The gpios property describes the GPIO pin the 1-Wire bus is connected
+to.
+For more details about the
+.Va gpios
+property, please consult
+.Pa /usr/src/sys/boot/fdt/dts/bindings-gpio.txt .
+.Sh SEE ALSO
+.Xr gpiobus 4 ,
+.Xr ow 4 ,
+.Xr ow_temp 4 ,
+.Xr owll 9 ,
+.Xr own 9
+.Sh LEGAL
+.Tn 1-Wire
+is a registered trademark of Maxim Integrated Products, Inc.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm
+device driver and this manual page were written by
+.An Warner Losh .
+.Sh CAVEATS
+The gpio driver implements timing by busy waiting, which can cause a
+high load on slower systems.
+.Sh BUGS
+Overdrive mode has not actually been tested.

Modified: head/share/man/man9/Makefile
==============================================================================
--- head/share/man/man9/Makefile	Thu Aug 27 22:42:02 2015	(r287224)
+++ head/share/man/man9/Makefile	Thu Aug 27 23:33:38 2015	(r287225)
@@ -190,6 +190,8 @@ MAN=	accept_filter.9 \
 	netisr.9 \
 	nv.9 \
 	osd.9 \
+	owll.9 \
+	own.9 \
 	panic.9 \
 	pbuf.9 \
 	PCBGROUP.9 \

Added: head/share/man/man9/owll.9
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man9/owll.9	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,93 @@
+.\"
+.\" Copyright (c) 2015 M. Warner Losh
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 20, 2015
+.Dt OWLL 9
+.Os
+.Sh NAME
+.Nm owll
+.Nm OWLL_WRITE_ONE,
+.Nm OWLL_WRITE_ZERO,
+.Nm OWLL_READ_DATA,
+.Nm OWLL_REASET_AND_PRESENCE
+.Nd Dallas Semiconductor 1-Wire Link Layer Interface
+.Sh SYNOPSIS
+.Ft int
+.Fn OWLL_WRITE_ONE "device_t lldev" "struct ow_timing *timing"
+.Ft int
+.Fn OWLL_WRITE_ZERO "device_t lldev" "struct ow_timing *timing"
+.Ft int
+.Fn OWLL_READ_DATA "device_t lldev" "struct ow_timing *timing" "int *bit"
+.Ft int
+.Fn OWLL_RESET_AND_PRESENCE "device_t lldev" "struct ow_timing *timing" "int *bit"
+.Sh DESCRIPTION
+The
+.Nm
+interface provides access to the link layer of the Dallas
+Semiconductor 1-Wire from upper layers of the protocol.
+.Pp
+.Fn OWLL_WRITE_ONE
+and
+.Fn OWLL_WRITE_ZERO
+writes a one bitor a zero bit respectively on the 1-Wire bus.
+.Pp
+.Fn OWLL_READ_DATA
+reads one bit from the 1-Wire bus.
+This is often referred to as a
+.Dq Read Time Slot
+in the 1-Wire device data sheets.
+.Pp
+The
+.Fn OWLL_RESET_AND_PRESENCE
+function starts a reset sequence and detects if any device(s) are
+present on the bus.
+This is the beginning of all 1-Wire transactions.
+.Sh NOTES
+This interface is intended to be used only by the
+.Xr ow 4
+device to talk to the low-level bus.
+By convention, the device that implements this interface is called
+.Xr owc 4 .
+Only devices that implement
+.Xr own 9
+should call these interfaces.
+.Sh SEE ALSO
+.Xr ow 4 ,
+.Xr owc 4 ,
+.Xr own 9
+.Sh LEGAL
+.Tn 1-Wire
+is a registered trademark of Maxim Integrated Products, Inc.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm
+device driver and this manual page were written by
+.An Warner Losh .

Added: head/share/man/man9/own.9
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man9/own.9	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,230 @@
+.\"
+.\" Copyright (c) 2015 M. Warner Losh
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"    notice, this list of conditions and the following disclaimer.
+.\" 2. The name of the author may not be used to endorse or promote products
+.\"    derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD$
+.\"
+.Dd July 20, 2015
+.Dt OWN 9
+.Os
+.Sh NAME
+.Nm own ,
+.Nm own_send_command ,
+.Nm own_commmand_wait ,
+.Nm own_self_command ,
+.Nm own_acquire_bus ,
+.Nm own crc ,
+.Nm own_release_bus ,
+.Nm OWN_ACQUIRE_BUS ,
+.Nm OWN_CRC ,
+.Nm OWN_RELEASE_BUS ,
+.Nm OWN_SEND_COMMAND
+.Nd Dallas Semiconductor 1-Wire Network and Transport Interface
+.Sh SYNOPSIS
+.In sys/bus.h
+.In dev/ow/own.h
+.Ft int
+.Fn own_send_command "device_t pdev" "struct ow_cmd *cmd"
+.Ft int
+.Fn own_command_wait "device_t pdev" "struct ow_cmd *cmd"
+.Ft int
+.Fn own_self_command "device_t pdev" "struct ow_cmd *cmd" "uint8_t xpt_cmd"
+.Ft int
+.Fn own_acquire_bus "device_t pdev" "int how"
+.Ft int
+.Fn own_release_bus "device_t pdev"
+.Ft int
+.Fn own_crc "device_t pdev" "uint8_t *buffer" "size_t len"
+.Ft int
+.Fn OWN_SEND_COMMAND "device_t ndev" "device_t pdev" "struct ow_cmd *cmd"
+.Ft int
+.Fn OWN_ACQUIRE_BUS "device_t ndev" "device_t pdev" "int how"
+.Ft void
+.Fn OWN_RELEASE_BUS "device_t ndev" "device_t pdev"
+.Ft uint8_t
+.Fn OWN_CRC "device_t ndev" "device_t pdev" "uint8_t *buffer" "size_t len"
+.Sh DESCRIPTION
+The
+.Nm
+interface defines three sets of functions for interacting with 1-Wire
+devices:
+sending commands,
+reserving the bus,
+and
+ensuring data integrity.
+Wrappers are provided for the raw
+.Nm OWN
+.Xr kobj 9
+interfaces and should be used for improved safety over the
+.Xr kobj 9
+ones.
+.Ss Bus Commands
+The 1-Wire bus defines different layers of access to the devices on
+the bus.
+The
+.Nm
+functions provide access to the network and transport layers.
+The network layer designates the next command as being either for all
+devices on the bus, or for a specific device.
+The network layer also specifies the speed used by the link layer.
+.Pp
+.Vt "struct ow_cmd"
+encapsulates network access, speed, and timing information.
+It specifies the commands to send and whether or not to read data.
+Its members are:
+.Bl -tag -width ".Va xxxx"
+.It Va flags
+Flags controlling the interpretation of the structure.
+These flags are defined in
+.In dev/ow/ow.h :
+.Bl -tag -width indent
+.It OW_FLAG_OVERDRIVE
+Send
+.Va xpt_cmd
+bytes and read
+.Va xpt_read
+bytes at overdrive speed.
+.It OW_FLAG_READ_BIT
+Interpret
+.Va xpt_read_len
+to be in bits to be read after
+.Va xpt_cmd
+rather than bytes.
+.El
+.It Va rom_cmd
+ROM command bytes to send.
+.It Va rom_len
+Number of ROM command bytes to send.
+.It Va rom_read_len
+Number of bytes to read after sending the ROM command.
+.It Va rom_read
+Buffer for bytes read after the ROM command.
+.It Va xpt_cmd
+Transport command to send.
+.It Va xpt_len
+Length of the transport command bytes to send.
+Specify 0 for no transport command.
+.It Va xpt_read_len
+Number of bytes to read after
+.Va xpt_cmd
+bytes are sent.
+If the
+.Dv OW_FLAG_READ_BIT
+bit is set in
+.Va flags ,
+then it is the number of bits to read.
+Bits read are packed into bytes.
+.It Va xpt_read
+Buffer for data read.
+.El
+.Pp
+.Fn own_command_wait
+acquires the 1-Wire bus, waiting if necessary,
+sends the command,
+and
+then releases the bus.
+.Fn own_send_command
+sends the command without bus reservation.
+.Fa pdev
+is the client device (the presentation layer device) sending the command.
+The
+.Fa cmd
+argument describes the transaction to send to the 1-Wire bus.
+.Pp
+.Fn own_self_command
+fills in
+.Fa cmd
+with a MATCH_ROM ROM command, the ROM address of
+.Fa pdev
+and the
+.Fa xpt_cmd
+as a convenient way to create directed commands.
+.Ss Bus Reservation
+The 1-Wire system includes an advisory lock for the bus that
+presentation layer devices can use to coordinate access.
+Locking is purely advisory at this time.
+.Pp
+.Fn own_acquire_bus
+reserves the bus.
+It waits indefinitely if the
+.Fa how
+argument is
+.Dv OWN_WAIT
+and returns the error
+.Dv EWOULDBLOCK
+if passed
+.Dv OWN_DONTWAIT
+when the bus is owned by another client.
+.Pp
+.Fn own_release_bus
+releases the bus.
+.Ss Data Integrity
+.Fn own_crc
+computes the 1-Wire standard CRC function over the data
+passed in
+.Fa buffer
+and
+.Fa len
+and returns the result.
+.Ss Notes
+The 1-Wire standard (Maxim AN937) defines layers that are akin to ISO
+networking layers.
+The lowest relevant layer, the link layer, defines the polling windows
+and the timing of the signaling of different modes.
+The network layer is built on top of the link layer
+and is used to address devices in a unicast or multicast manner.
+The transport layer defines commands and responses from the devices.
+The presentation layer is composed of the device specific commands and
+actions used to control the specific 1-Wire devices on bus.
+.Pp
+These interfaces are implemented by the
+.Xr ow 4
+device.
+Presentation layer devices (children of the newbus
+.Xr ow 4
+device) should only call the functions described here.
+The functionality provided by the
+.Xr owc 4
+device (specifically the
+.Xr owll 9
+interface) should only be called by the
+.Xr ow 4
+driver.
+.Sh SEE ALSO
+.Xr ow 4 ,
+.Xr owc 4 ,
+.Xr owll 9
+.Pa  http://pdfserv.maximintegrated.com/en/an/AN937.pdf
+.Sh LEGAL
+.Tn 1-Wire
+is a registered trademark of Maxim Integrated Products, Inc.
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Fx 11.0 .
+.Sh AUTHORS
+The
+.Nm
+device driver and this manual page were written by
+.An Warner Losh .

Modified: head/sys/conf/files
==============================================================================
--- head/sys/conf/files	Thu Aug 27 22:42:02 2015	(r287224)
+++ head/sys/conf/files	Thu Aug 27 23:33:38 2015	(r287225)
@@ -2088,6 +2088,13 @@ dev/ofw/ofw_iicbus.c		optional fdt iicbu
 dev/ofw/ofwbus.c		optional fdt
 dev/ofw/openfirm.c		optional fdt
 dev/ofw/openfirmio.c		optional fdt
+dev/ow/ow.c			optional ow				\
+	dependency	"owll_if.h"					\
+	dependency	"own_if.h"
+dev/ow/owll_if.m		optional ow
+dev/ow/own_if.m			optional ow
+dev/ow/ow_temp.c		optional ow_temp
+dev/ow/owc_gpiobus.c		optional owc gpio
 dev/patm/if_patm.c		optional patm pci
 dev/patm/if_patm_attach.c	optional patm pci
 dev/patm/if_patm_intr.c		optional patm pci

Added: head/sys/dev/ow/README.txt
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/ow/README.txt	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,19 @@
+Quick Design Document for 1-wire bus
+
+In new bus terms, 1-wire devices are attached to 1-wire buses (ow)
+which are attached to a one wire bridge (owc).
+
+The implementation follows the terminology used in the Maxim AN927
+Application note which defines the 1-wire bus as implemented for the
+iButton product. This is considered to be the canonical definition of
+the 1-wire bus. This means that the 1-wire bridge will implement the
+owll(9) interface. ow is one wire. ll is for Link Level to mirror the ISO
+stack terminology used by AN927. The 1-wire bus is implemented in the ow(4)
+device, which implements the own(9) interface (n for network, the layer
+described in the AN927). The presentation layer and above is the
+responsibility of the client device drivers to implement.
+
+Client drivers may only call the own(9) interface. The ow(4) driver
+calls the owll(9) interface and implements the own(9).
+
+$FreeBSD$

Added: head/sys/dev/ow/ow.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/ow/ow.c	Thu Aug 27 23:33:38 2015	(r287225)
@@ -0,0 +1,639 @@
+/*-
+ * Copyright (c) 2015 M. Warner Losh <imp@freebsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+#include <sys/bus.h>
+#include <sys/errno.h>
+#include <sys/libkern.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+
+#include <dev/ow/ow.h>
+#include <dev/ow/owll.h>
+#include <dev/ow/own.h>
+
+/*
+ * lldev - link level device
+ * ndev - network / transport device (this module)
+ * pdev - presentation device (children of this module)
+ */
+
+typedef int ow_enum_fn(device_t, device_t);
+typedef int ow_found_fn(device_t, romid_t);
+
+struct ow_softc 
+{
+	device_t	dev;		/* Newbus driver back pointer */
+	struct mtx	mtx;		/* bus mutex */
+	device_t	owner;		/* bus owner, if != NULL */
+};
+
+struct ow_devinfo
+{
+	romid_t	romid;
+};
+
+static int ow_acquire_bus(device_t ndev, device_t pdev, int how);
+static void ow_release_bus(device_t ndev, device_t pdev);
+
+#define	OW_LOCK(_sc) mtx_lock(&(_sc)->mtx)
+#define	OW_UNLOCK(_sc) mtx_unlock(&(_sc)->mtx)
+#define	OW_LOCK_DESTROY(_sc) mtx_destroy(&_sc->mtx)
+#define	OW_ASSERT_LOCKED(_sc) mtx_assert(&_sc->mtx, MA_OWNED)
+#define	OW_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->mtx, MA_NOTOWNED)
+
+static MALLOC_DEFINE(M_OW, "ow", "House keeping data for 1wire bus");
+
+static struct ow_timing timing_regular = {
+	.t_slot = 60,		/* 60 to 120 */
+	.t_low0 = 60,		/* really 60 to 120 */
+	.t_low1 = 1,		/* really 1 to 15 */
+	.t_release = 45,	/* <= 45us */
+	.t_rec = 1,		/* at least 1us */
+	.t_rdv = 15,		/* 15us */
+	.t_rstl = 480,		/* 480us or more */
+	.t_rsth = 480,		/* 480us or more */
+	.t_pdl = 60,		/* 60us to 240us */
+ 	.t_pdh = 60,		/* 15us to 60us */
+	.t_lowr = 1,		/* 1us */
+};
+
+/* NB: Untested */
+static struct ow_timing timing_overdrive = {
+	.t_slot = 11,		/* 6us to 16us */
+	.t_low0 = 6,		/* really 6 to 16 */
+	.t_low1 = 1,		/* really 1 to 2 */
+	.t_release = 4,		/* <= 4us */
+	.t_rec = 1,		/* at least 1us */
+	.t_rdv = 2,		/* 2us */
+	.t_rstl = 48,		/* 48us to 80us */
+	.t_rsth = 48,		/* 48us or more  */
+	.t_pdl = 8,		/* 8us to 24us */
+	.t_pdh = 2,		/* 2us to 6us */
+	.t_lowr = 1,		/* 1us */
+};
+
+static void
+ow_send_byte(device_t lldev, struct ow_timing *t, uint8_t byte)
+{
+	int i;
+	
+	for (i = 0; i < 8; i++)
+		if (byte & (1 << i))
+			OWLL_WRITE_ONE(lldev, t);
+		else
+			OWLL_WRITE_ZERO(lldev, t);
+}
+
+static void
+ow_read_byte(device_t lldev, struct ow_timing *t, uint8_t *bytep)
+{
+	int i;
+	uint8_t byte = 0;
+	int bit;
+	
+	for (i = 0; i < 8; i++) {
+		OWLL_READ_DATA(lldev, t, &bit);
+		byte |= bit << i;
+	}
+	*bytep = byte;
+}
+
+static int
+ow_send_command(device_t ndev, device_t pdev, struct ow_cmd *cmd)
+{
+	int present, i, bit, tries;
+	device_t lldev;
+	struct ow_timing *t;
+
+	lldev = device_get_parent(ndev);
+
+	/*
+	 * Retry the reset a couple of times before giving up.
+	 */
+	tries = 4;
+	do {
+		OWLL_RESET_AND_PRESENCE(lldev, &timing_regular, &present);
+		if (present == 1)
+			device_printf(ndev, "Reset said no device on bus?.\n");
+	} while (present == 1 && tries-- > 0);
+	if (present == 1) {
+		device_printf(ndev, "Reset said the device wasn't there.\n");
+		return ENOENT;		/* No devices acked the RESET */
+	}
+	if (present == -1) {
+		device_printf(ndev, "Reset discovered bus wired wrong.\n");
+		return ENOENT;
+	}
+
+	for (i = 0; i < cmd->rom_len; i++)
+		ow_send_byte(lldev, &timing_regular, cmd->rom_cmd[i]);
+	for (i = 0; i < cmd->rom_read_len; i++)
+		ow_read_byte(lldev, &timing_regular, cmd->rom_read + i);
+	if (cmd->xpt_len) {
+		/*
+		 * Per AN937, the reset pulse and ROM level are always
+		 * done with the regular timings. Certain ROM commands
+		 * put the device into overdrive mode for the remainder
+		 * of the data transfer, which is why we have to pass the
+		 * timings here. Commands that need to be handled like this
+		 * are expected to be flagged by the client.
+		 */
+		t = (cmd->flags & OW_FLAG_OVERDRIVE) ?
+		    &timing_overdrive : &timing_regular;
+		for (i = 0; i < cmd->xpt_len; i++)
+			ow_send_byte(lldev, t, cmd->xpt_cmd[i]);
+		if (cmd->flags & OW_FLAG_READ_BIT) {
+			memset(cmd->xpt_read, 0, (cmd->xpt_read_len + 7) / 8);
+			for (i = 0; i < cmd->xpt_read_len; i++) {
+				OWLL_READ_DATA(lldev, t, &bit);
+				cmd->xpt_read[i / 8] |= bit << (i % 8);
+			}
+		} else {
+			for (i = 0; i < cmd->xpt_read_len; i++)
+				ow_read_byte(lldev, t, cmd->xpt_read + i);
+		}
+	}
+	return 0;
+}
+
+static int
+ow_search_rom(device_t lldev, device_t dev)
+{
+	struct ow_cmd cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.rom_cmd[0] = SEARCH_ROM;
+	cmd.rom_len = 1;
+	return ow_send_command(lldev, dev, &cmd);
+}
+
+#if 0
+static int
+ow_alarm_search(device_t lldev, device_t dev)
+{
+	struct ow_cmd cmd;
+
+	memset(&cmd, 0, sizeof(cmd));
+	cmd.rom_cmd[0] = ALARM_SEARCH;
+	cmd.rom_len = 1;
+	return ow_send_command(lldev, dev, &cmd);
+}
+#endif
+
+static int
+ow_add_child(device_t dev, romid_t romid)
+{
+	struct ow_devinfo *di;
+	device_t child;
+
+	di = malloc(sizeof(*di), M_OW, M_WAITOK);
+	di->romid = romid;
+	child = device_add_child(dev, NULL, -1);
+	if (child == NULL) {
+		free(di, M_OW);
+		return ENOMEM;
+	}
+	device_set_ivars(child, di);
+	return (0);
+}
+
+static device_t
+ow_child_by_romid(device_t dev, romid_t romid)
+{
+	device_t *children, retval, child;
+	int nkid, i;
+	struct ow_devinfo *di;
+
+	if (device_get_children(dev, &children, &nkid) != 0)
+		return (NULL);
+	retval = NULL;
+	for (i = 0; i < nkid; i++) {
+		child = children[i];
+		di = device_get_ivars(child);
+		if (di->romid == romid) {
+			retval = child;
+			break;
+		}
+	}
+	free(children, M_TEMP);
+
+	return (retval);
+}
+
+/*
+ * CRC generator table -- taken from AN937 DOW CRC LOOKUP FUNCTION Table 2
+ */
+const uint8_t ow_crc_table[] = {
+	0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
+	157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
+	35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
+	190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
+	70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
+	219, 133,103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
+	101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
+	248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
+	140,210, 48, 110, 237, 179, 81, 15, 78, 16, 242,  172, 47, 113,147, 205,
+	17, 79, 173, 243, 112, 46, 204, 146, 211,141, 111, 49, 178, 236, 14, 80,
+	175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82,176, 238,
+	50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
+	202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
+	87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
+	233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
+	116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53
+};
+
+/*
+ * Converted from DO_CRC page 131 ANN937
+ */
+static uint8_t
+ow_crc(device_t ndev, device_t pdev, uint8_t *buffer, size_t len)
+{

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201508272333.t7RNXdH5009539>