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 56.Xr Sysctl 8 57provides access to the voltage measurements made by the device. 58Each time the 59.Va dev.ads111x.<unit>.<channel>.voltage 60variable is accessed for a given channel, the driver switches the 61chip's internal mux to choose the right input pins for that channel, 62directs it to make a single measurement, and returns the measured value 63in microvolts. 64The amount of time required to make the measurement is a function 65of the sampling rate configured for the device. 66While device is directed to make a single measurement, it still averages 67the input values for the same amount of time as it would to emit one 68sample if it were in continuous mode. 69For example, if the sample rate were configured as 125 samples per 70second, a single measurement would require 8 milliseconds. 71.Pp 72For devices that support multiple input pins, the device datasheet 73describes mux settings to control how those pins are interpeted when 74making either single-ended or differential measurements. 75There are eight possible ways to combine the inputs from the four pins. 76The 77.Nm 78driver models that by creating a separate output channel for each of 79the eight combinations. 80To make a measurement on a given pin or pair of pins, you simply access 81the voltage variable for the channel number that corresponds the mux 82setting number (0 through 7) shown in the datasheet. 83When the driver is configured with hints or FDT data, it creates 84sysctl variables for just the channels specified in the config data. 85When there is no channel config data, it creates all eight possible 86channels so that you can access whichever one(s) you need. 87.Pp 88For devices that include an 89.Va alert 90output pin, the 91.Nm 92driver does not directly support the pin in terms of sensing or 93acting on changes in the pin state. 94However, you may connect the pin to a gpio input or fan controller 95or other external device, and use the driver's sysctl variables to 96configure behavior and threshold values for the pin. 97The driver avoids perturbing your settings as it does other 98manipulations to the config register. 99.Sh SYSCTL VARIABLES 100Sysctl variables are used to access the voltage measurements, and to 101change the configuration of the channels. 102All writeable variables may also be set as 103.Xr loader 8 104tunables. 105Channel numbers in these sysctl variables range from 0 through 7. 106.Bl -tag -width indent 107.It Va dev.ads111x.<unit>.config 108Provides access to the configuration register bits that control the 109alert pin configuration. 110Other bits which are controlled by the driver are masked out, and 111cannot be viewed or changed using this variable. 112.It Va dev.ads111x.<unit>.lo_thresh 113Sets the low threshold for activating the alert pin. 114.It Va dev.ads111x.<unit>.hi_thresh 115Sets the high threshold for activating the alert pin. 116.It Va dev.ads111x.<unit>.<channel>.rate_index 117Sets the sample rate for the channel. 118The device datasheet documents eight available sample rates, chosen 119by setting a value of 0 through 7 into the corresponding control 120register bits. 121This variable sets the value used for those bits when making a 122measurement on the given channel. 123.Pp 124Because measurements are always made in single-shot mode, think of 125this variable as controlling the averaging time for a single sample; 126the time to make a measurement is 1 / samplerate. 127.It Va dev.ads111x.<unit>.<channel>.gain_index 128Sets the programmable gain amplifier for the channel on devices 129which have an internal amplifier. 130The device datasheet documents eight available gain values, chosen 131by setting a value of 0 through 7 into the corresponding control 132register bits. 133This variable sets the value used for those bits when making a 134measurement on the given channel. 135.It Va dev.ads111x.<unit>.<channel>.voltage 136Reading this variable causes the device to make a measurement on 137the corresponding input pin(s) and return the voltage in microvolts. 138.Pp 139Note that this variable does not appear when you list multiple 140sysctl variables -- you must access it specifically by name, because 141accessing it triggers device I/O. 142.El 143.Sh HARDWARE 144The 145.Nm 146driver provides support for the following devices: 147.Pp 148.Bl -column -compact -offset indent "XXXXXXXX" "XXXXXXXX" 149.It ADS1013 Ta ADS1113 150.It ADS1014 Ta ADS1114 151.It ADS1015 Ta ADS1115 152.El 153.Sh FDT CONFIGURATION 154On an 155.Xr fdt 4 156based system, the 157.Nm 158device is defined as a slave device subnode 159of the i2c bus controller node. 160All properties documented in the 161.Va ads1015.txt 162bindings document can be used with the 163.Nm 164device. 165.Pp 166The following properties are required in the 167.Nm 168device subnode: 169.Bl -tag -width indent 170.It Va compatible 171One of the following: 172.Bl -column -compact -offset indent ".Dq ti,ads1013" ".Dq ti,ads1113" 173.It Dq ti,ads1013 Ta Dq ti,ads1113 174.It Dq ti,ads1014 Ta Dq ti,ads1114 175.It Dq ti,ads1015 Ta Dq ti,ads1115 176.El 177.It Va reg 178I2c slave address of device. 179.El 180.Pp 181Specific channels can be configured by adding child nodes to the 182.Nm 183node, as described in the standard ads1015.txt bindings document. 184If no channels are configured, sysctl variables will be created 185for all possible channels supported by the device type, otherwise 186only the specified channels are created. 187.Ss Example including channel configuration 188.Bd -unfilled -offset indent 189adc@48 { 190 compatible = "ti,ads1115"; 191 reg = <0x48>; 192 status = "okay"; 193 #address-cells = <1>; 194 #size-cells = <0>; 195 196 channel@6 { 197 reg = <6>; 198 ti,gain = <3>; 199 ti,datarate = <4>; 200 }; 201 channel@7 { 202 reg = <7>; 203 ti,gain = <1>; 204 ti,datarate = <7>; 205 }; 206}; 207.Ed 208.Sh HINTS CONFIGURATION 209On a 210.Xr device.hints 5 211based system, such as 212.Li MIPS , 213these values are configurable for 214.Nm : 215.Bl -tag -width indent 216.It Va hint.ads111x.<unit>.at 217The iicbus instance the 218.Nm 219instance is attached to. 220.It Va hint.ads111x.<unit>.<channel>.gain_index 221The amplifier gain, as described above for the sysctl variable 222.Va dev.ads111x.<unit>.<channel>.gain_index . 223.It Va hint.ads111x.<unit>.<channel>.rate_index 224The sample rate, as described above for the sysctl variable 225.Va dev.ads111x.<unit>.<channel>.rate_index . 226.El 227.Pp 228If no channels are configured, sysctl variables will be created 229for all possible channels supported by the device type, otherwise 230only the specified channels are created. 231.Sh SEE ALSO 232.Xr fdt 4 , 233.Xr sysctl 8 234.Sh HISTORY 235The 236.Nm 237driver first appeared in 238.Fx 13.0 . 239