1.\" 2.\" Copyright (c) 2019 Ian Lepore <ian@freebsd.org> 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24.\" 25.Dd September 2, 2019 26.Dt ADS111x 4 27.Os 28.Sh NAME 29.Nm ads111x 30.Nd driver for ADS101x and ADS111x i2c analog to digital converters 31.Sh SYNOPSIS 32To compile this driver into the kernel, 33place the following line in your 34kernel configuration file: 35.Bd -ragged -offset indent 36.Cd "device ads111x" 37.Ed 38.Pp 39Alternatively, to load the driver as a 40module at boot time, place the following line in 41.Xr loader.conf 5 : 42.Bd -literal -offset indent 43ads111x_load="YES" 44.Ed 45.Sh DESCRIPTION 46The 47.Nm 48driver provides support for the ADS101x/ADS111x family of analog 49to digital converter (ADC) devices. 50The supported devices are all similar to each other, varying in 51features such as resolution and number of input channels. 52The devices offer a number of configuration options which can be 53set via hints, FDT data, and 54.Xr sysctl 8 . 55.Pp 56The 57.Xr sysctl 8 58utility provides access to the voltage measurements made by the device. 59Each time the 60.Va dev.ads111x.<unit>.<channel>.voltage 61variable is accessed for a given channel, the driver switches the 62chip's internal mux to choose the right input pins for that channel, 63directs it to make a single measurement, and returns the measured value 64in microvolts. 65The amount of time required to make the measurement is a function 66of the sampling rate configured for the device. 67While device is directed to make a single measurement, it still averages 68the input values for the same amount of time as it would to emit one 69sample if it were in continuous mode. 70For example, if the sample rate were configured as 125 samples per 71second, a single measurement would require 8 milliseconds. 72.Pp 73For devices that support multiple input pins, the device datasheet 74describes mux settings to control how those pins are interpeted when 75making either single-ended or differential measurements. 76There are eight possible ways to combine the inputs from the four pins. 77The 78.Nm 79driver models that by creating a separate output channel for each of 80the eight combinations. 81To make a measurement on a given pin or pair of pins, you simply access 82the voltage variable for the channel number that corresponds the mux 83setting number (0 through 7) shown in the datasheet. 84When the driver is configured with hints or FDT data, it creates 85sysctl variables for just the channels specified in the config data. 86When there is no channel config data, it creates all eight possible 87channels so that you can access whichever one(s) you need. 88.Pp 89For devices that include an 90.Va alert 91output pin, the 92.Nm 93driver does not directly support the pin in terms of sensing or 94acting on changes in the pin state. 95However, you may connect the pin to a gpio input or fan controller 96or other external device, and use the driver's sysctl variables to 97configure behavior and threshold values for the pin. 98The driver avoids perturbing your settings as it does other 99manipulations to the config register. 100.Sh SYSCTL VARIABLES 101Sysctl variables are used to access the voltage measurements, and to 102change the configuration of the channels. 103All writeable variables may also be set as 104.Xr loader 8 105tunables. 106Channel numbers in these sysctl variables range from 0 through 7. 107.Bl -tag -width indent 108.It Va dev.ads111x.<unit>.config 109Provides access to the configuration register bits that control the 110alert pin configuration. 111Other bits which are controlled by the driver are masked out, and 112cannot be viewed or changed using this variable. 113.It Va dev.ads111x.<unit>.lo_thresh 114Sets the low threshold for activating the alert pin. 115.It Va dev.ads111x.<unit>.hi_thresh 116Sets the high threshold for activating the alert pin. 117.It Va dev.ads111x.<unit>.<channel>.rate_index 118Sets the sample rate for the channel. 119The device datasheet documents eight available sample rates, chosen 120by setting a value of 0 through 7 into the corresponding control 121register bits. 122This variable sets the value used for those bits when making a 123measurement on the given channel. 124.Pp 125Because measurements are always made in single-shot mode, think of 126this variable as controlling the averaging time for a single sample; 127the time to make a measurement is 1 / samplerate. 128.It Va dev.ads111x.<unit>.<channel>.gain_index 129Sets the programmable gain amplifier for the channel on devices 130which have an internal amplifier. 131The device datasheet documents eight available gain values, chosen 132by setting a value of 0 through 7 into the corresponding control 133register bits. 134This variable sets the value used for those bits when making a 135measurement on the given channel. 136.It Va dev.ads111x.<unit>.<channel>.voltage 137Reading this variable causes the device to make a measurement on 138the corresponding input pin(s) and return the voltage in microvolts. 139.Pp 140Note that this variable does not appear when you list multiple 141sysctl variables -- you must access it specifically by name, because 142accessing it triggers device I/O. 143.El 144.Sh HARDWARE 145The 146.Nm 147driver provides support for the following devices: 148.Pp 149.Bl -column -compact -offset indent "XXXXXXXX" "XXXXXXXX" 150.It ADS1013 Ta ADS1113 151.It ADS1014 Ta ADS1114 152.It ADS1015 Ta ADS1115 153.El 154.Sh FDT CONFIGURATION 155On an 156.Xr fdt 4 157based system, the 158.Nm 159device is defined as a slave device subnode 160of the i2c bus controller node. 161All properties documented in the 162.Va ads1015.txt 163bindings document can be used with the 164.Nm 165device. 166.Pp 167The following properties are required in the 168.Nm 169device subnode: 170.Bl -tag -width indent 171.It Va compatible 172One of the following: 173.Bl -column -compact -offset indent ".Dq ti,ads1013" ".Dq ti,ads1113" 174.It Dq ti,ads1013 Ta Dq ti,ads1113 175.It Dq ti,ads1014 Ta Dq ti,ads1114 176.It Dq ti,ads1015 Ta Dq ti,ads1115 177.El 178.It Va reg 179I2c slave address of device. 180.El 181.Pp 182Specific channels can be configured by adding child nodes to the 183.Nm 184node, as described in the standard ads1015.txt bindings document. 185If no channels are configured, sysctl variables will be created 186for all possible channels supported by the device type, otherwise 187only the specified channels are created. 188.Ss Example including channel configuration 189.Bd -unfilled -offset indent 190adc@48 { 191 compatible = "ti,ads1115"; 192 reg = <0x48>; 193 status = "okay"; 194 #address-cells = <1>; 195 #size-cells = <0>; 196 197 channel@6 { 198 reg = <6>; 199 ti,gain = <3>; 200 ti,datarate = <4>; 201 }; 202 channel@7 { 203 reg = <7>; 204 ti,gain = <1>; 205 ti,datarate = <7>; 206 }; 207}; 208.Ed 209.Sh HINTS CONFIGURATION 210On a 211.Xr device.hints 5 212based system, such as 213.Li MIPS , 214these values are configurable for 215.Nm : 216.Bl -tag -width indent 217.It Va hint.ads111x.<unit>.at 218The iicbus instance the 219.Nm 220instance is attached to. 221.It Va hint.ads111x.<unit>.<channel>.gain_index 222The amplifier gain, as described above for the sysctl variable 223.Va dev.ads111x.<unit>.<channel>.gain_index . 224.It Va hint.ads111x.<unit>.<channel>.rate_index 225The sample rate, as described above for the sysctl variable 226.Va dev.ads111x.<unit>.<channel>.rate_index . 227.El 228.Pp 229If no channels are configured, sysctl variables will be created 230for all possible channels supported by the device type, otherwise 231only the specified channels are created. 232.Sh SEE ALSO 233.Xr fdt 4 , 234.Xr sysctl 8 235.Sh HISTORY 236The 237.Nm 238driver first appeared in 239.Fx 13.0 . 240