FreeBSD kernel IICBUS device code
ads111x.c File Reference
#include <sys/cdefs.h>
#include "opt_platform.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/module.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <dev/iicbus/iiconf.h>
#include <dev/iicbus/iicbus.h>
#include "iicbus_if.h"
Include dependency graph for ads111x.c:

Go to the source code of this file.

Data Structures

struct  ads111x_channel
 
struct  ads111x_chipinfo
 
struct  ads111x_softc
 

Macros

#define ADS111x_CONV   0 /* Reg 0: Latest sample (ro) */
 
#define ADS111x_CONF   1 /* Reg 1: Config (rw) */
 
#define ADS111x_CONF_OS_SHIFT   15 /* Operational state */
 
#define ADS111x_CONF_MUX_SHIFT   12 /* Input mux setting */
 
#define ADS111x_CONF_GAIN_SHIFT   9 /* Programmable gain amp */
 
#define ADS111x_CONF_MODE_SHIFT   8 /* Operational mode */
 
#define ADS111x_CONF_RATE_SHIFT   5 /* Sample rate */
 
#define ADS111x_CONF_COMP_DISABLE   3 /* Comparator disable */
 
#define ADS111x_LOTHRESH   2 /* Compare lo threshold (rw) */
 
#define ADS111x_HITHRESH   3 /* Compare hi threshold (rw) */
 
#define ADS111x_CONF_MEASURE   (1u << ADS111x_CONF_OS_SHIFT)
 
#define ADS111x_CONF_IDLE   (1u << ADS111x_CONF_OS_SHIFT)
 
#define ADS111x_CONF_DEFAULT    ((1 << ADS111x_CONF_MODE_SHIFT) | ADS111x_CONF_COMP_DISABLE)
 
#define ADS111x_CONF_USERMASK   0x001f
 
#define DEFAULT_GAINIDX   2
 
#define DEFAULT_RATEIDX   4
 
#define ADS101x_RANGEDIV   ((1 << 15) - 15)
 
#define ADS111x_RANGEDIV   ((1 << 15) - 1)
 
#define ADS111x_MAX_CHANNELS   8
 

Functions

 __FBSDID ("$FreeBSD$")
 
static int ads111x_write_2 (struct ads111x_softc *sc, int reg, int val)
 
static int ads111x_read_2 (struct ads111x_softc *sc, int reg, int *val)
 
static int ads111x_sample_voltage (struct ads111x_softc *sc, int channum, int *voltage)
 
static int ads111x_sysctl_gainidx (SYSCTL_HANDLER_ARGS)
 
static int ads111x_sysctl_rateidx (SYSCTL_HANDLER_ARGS)
 
static int ads111x_sysctl_voltage (SYSCTL_HANDLER_ARGS)
 
static int ads111x_sysctl_config (SYSCTL_HANDLER_ARGS)
 
static int ads111x_sysctl_lothresh (SYSCTL_HANDLER_ARGS)
 
static int ads111x_sysctl_hithresh (SYSCTL_HANDLER_ARGS)
 
static void ads111x_setup_channel (struct ads111x_softc *sc, int chan, int gainidx, int rateidx)
 
static void ads111x_add_channels (struct ads111x_softc *sc)
 
static const struct ads111x_chipinfoads111x_find_chipinfo (device_t dev)
 
static int ads111x_probe (device_t dev)
 
static int ads111x_attach (device_t dev)
 
static int ads111x_detach (device_t dev)
 
 DRIVER_MODULE (ads111x, iicbus, ads111x_driver, ads111x_devclass, NULL, NULL)
 
 MODULE_VERSION (ads111x, 1)
 
 MODULE_DEPEND (ads111x, iicbus, 1, 1, 1)
 

Variables

static const u_int fixedranges [8]
 
static const u_int gainranges [8]
 
static const u_int rates101x [8] = {128, 250, 490, 920, 1600, 2400, 3300, 3300}
 
static const u_int rates111x [8] = { 8, 16, 32, 64, 128, 250, 475, 860}
 
static struct ads111x_chipinfo ads111x_chip_infos []
 
static device_method_t ads111x_methods []
 
static driver_t ads111x_driver
 
static devclass_t ads111x_devclass
 

Macro Definition Documentation

◆ ADS101x_RANGEDIV

#define ADS101x_RANGEDIV   ((1 << 15) - 15)

Definition at line 113 of file ads111x.c.

◆ ADS111x_CONF

#define ADS111x_CONF   1 /* Reg 1: Config (rw) */

Definition at line 61 of file ads111x.c.

◆ ADS111x_CONF_COMP_DISABLE

#define ADS111x_CONF_COMP_DISABLE   3 /* Comparator disable */

Definition at line 67 of file ads111x.c.

◆ ADS111x_CONF_DEFAULT

#define ADS111x_CONF_DEFAULT    ((1 << ADS111x_CONF_MODE_SHIFT) | ADS111x_CONF_COMP_DISABLE)

Definition at line 87 of file ads111x.c.

◆ ADS111x_CONF_GAIN_SHIFT

#define ADS111x_CONF_GAIN_SHIFT   9 /* Programmable gain amp */

Definition at line 64 of file ads111x.c.

◆ ADS111x_CONF_IDLE

#define ADS111x_CONF_IDLE   (1u << ADS111x_CONF_OS_SHIFT)

Definition at line 78 of file ads111x.c.

◆ ADS111x_CONF_MEASURE

#define ADS111x_CONF_MEASURE   (1u << ADS111x_CONF_OS_SHIFT)

Definition at line 77 of file ads111x.c.

◆ ADS111x_CONF_MODE_SHIFT

#define ADS111x_CONF_MODE_SHIFT   8 /* Operational mode */

Definition at line 65 of file ads111x.c.

◆ ADS111x_CONF_MUX_SHIFT

#define ADS111x_CONF_MUX_SHIFT   12 /* Input mux setting */

Definition at line 63 of file ads111x.c.

◆ ADS111x_CONF_OS_SHIFT

#define ADS111x_CONF_OS_SHIFT   15 /* Operational state */

Definition at line 62 of file ads111x.c.

◆ ADS111x_CONF_RATE_SHIFT

#define ADS111x_CONF_RATE_SHIFT   5 /* Sample rate */

Definition at line 66 of file ads111x.c.

◆ ADS111x_CONF_USERMASK

#define ADS111x_CONF_USERMASK   0x001f

Definition at line 89 of file ads111x.c.

◆ ADS111x_CONV

#define ADS111x_CONV   0 /* Reg 0: Latest sample (ro) */

Definition at line 59 of file ads111x.c.

◆ ADS111x_HITHRESH

#define ADS111x_HITHRESH   3 /* Compare hi threshold (rw) */

Definition at line 71 of file ads111x.c.

◆ ADS111x_LOTHRESH

#define ADS111x_LOTHRESH   2 /* Compare lo threshold (rw) */

Definition at line 69 of file ads111x.c.

◆ ADS111x_MAX_CHANNELS

#define ADS111x_MAX_CHANNELS   8

Definition at line 126 of file ads111x.c.

◆ ADS111x_RANGEDIV

#define ADS111x_RANGEDIV   ((1 << 15) - 1)

Definition at line 114 of file ads111x.c.

◆ DEFAULT_GAINIDX

#define DEFAULT_GAINIDX   2

Definition at line 97 of file ads111x.c.

◆ DEFAULT_RATEIDX

#define DEFAULT_RATEIDX   4

Definition at line 98 of file ads111x.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ ads111x_add_channels()

static void ads111x_add_channels ( struct ads111x_softc sc)
static

Definition at line 427 of file ads111x.c.

References ADS111x_MAX_CHANNELS, ads111x_setup_channel(), ads111x_softc::chipinfo, DEFAULT_GAINIDX, DEFAULT_RATEIDX, ads111x_softc::dev, and ads111x_chipinfo::numchan.

Referenced by ads111x_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_attach()

◆ ads111x_detach()

static int ads111x_detach ( device_t  dev)
static

Definition at line 586 of file ads111x.c.

References dev, and ads111x_softc::lock.

◆ ads111x_find_chipinfo()

static const struct ads111x_chipinfo * ads111x_find_chipinfo ( device_t  dev)
static

Definition at line 491 of file ads111x.c.

References ads111x_chip_infos, compat_data, dev, and ads111x_chipinfo::name.

Referenced by ads111x_attach(), and ads111x_probe().

Here is the caller graph for this function:

◆ ads111x_probe()

static int ads111x_probe ( device_t  dev)
static

Definition at line 521 of file ads111x.c.

References ads111x_find_chipinfo(), dev, and ads111x_chipinfo::name.

Here is the call graph for this function:

◆ ads111x_read_2()

static int ads111x_read_2 ( struct ads111x_softc sc,
int  reg,
int *  val 
)
static

Definition at line 190 of file ads111x.c.

References data, ads111x_softc::dev, iic2errno(), IIC_WAIT, iicdev_readfrom(), and val.

Referenced by ads111x_sample_voltage(), ads111x_sysctl_hithresh(), and ads111x_sysctl_lothresh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_sample_voltage()

static int ads111x_sample_voltage ( struct ads111x_softc sc,
int  channum,
int *  voltage 
)
static

◆ ads111x_setup_channel()

static void ads111x_setup_channel ( struct ads111x_softc sc,
int  chan,
int  gainidx,
int  rateidx 
)
static

Definition at line 386 of file ads111x.c.

References ads111x_sysctl_gainidx(), ads111x_sysctl_rateidx(), ads111x_sysctl_voltage(), ads111x_softc::channels, ads111x_channel::configured, ads111x_softc::dev, ads111x_channel::gainidx, and ads111x_channel::rateidx.

Referenced by ads111x_add_channels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_sysctl_config()

static int ads111x_sysctl_config ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 330 of file ads111x.c.

References ADS111x_CONF, ADS111x_CONF_USERMASK, ads111x_write_2(), ads111x_softc::cfgword, and ads111x_softc::lock.

Referenced by ads111x_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_sysctl_gainidx()

static int ads111x_sysctl_gainidx ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 263 of file ads111x.c.

References ads111x_softc::channels, ads111x_channel::gainidx, and ads111x_softc::lock.

Referenced by ads111x_setup_channel().

Here is the caller graph for this function:

◆ ads111x_sysctl_hithresh()

static int ads111x_sysctl_hithresh ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 367 of file ads111x.c.

References ADS111x_CONF, ADS111x_HITHRESH, ads111x_read_2(), ads111x_write_2(), and ads111x_softc::lock.

Referenced by ads111x_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_sysctl_lothresh()

static int ads111x_sysctl_lothresh ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 348 of file ads111x.c.

References ADS111x_CONF, ADS111x_LOTHRESH, ads111x_read_2(), ads111x_write_2(), and ads111x_softc::lock.

Referenced by ads111x_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_sysctl_rateidx()

static int ads111x_sysctl_rateidx ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 285 of file ads111x.c.

References ads111x_softc::channels, ads111x_softc::lock, and ads111x_channel::rateidx.

Referenced by ads111x_setup_channel().

Here is the caller graph for this function:

◆ ads111x_sysctl_voltage()

static int ads111x_sysctl_voltage ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 307 of file ads111x.c.

References ads111x_sample_voltage(), ads111x_softc::dev, and ads111x_softc::lock.

Referenced by ads111x_setup_channel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ads111x_write_2()

static int ads111x_write_2 ( struct ads111x_softc sc,
int  reg,
int  val 
)
static

Definition at line 170 of file ads111x.c.

References iic_msg::buf, data, ads111x_softc::dev, iic_msg::flags, IIC_M_WR, IIC_WAIT, iicbus_transfer_excl(), iic_msg::len, msgs, iic_msg::slave, and val.

Referenced by ads111x_attach(), ads111x_sample_voltage(), ads111x_sysctl_config(), ads111x_sysctl_hithresh(), and ads111x_sysctl_lothresh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DRIVER_MODULE()

DRIVER_MODULE ( ads111x  ,
iicbus  ,
ads111x_driver  ,
ads111x_devclass  ,
NULL  ,
NULL   
)

◆ MODULE_DEPEND()

MODULE_DEPEND ( ads111x  ,
iicbus  ,
,
,
 
)

◆ MODULE_VERSION()

MODULE_VERSION ( ads111x  ,
 
)

Variable Documentation

◆ ads111x_chip_infos

struct ads111x_chipinfo ads111x_chip_infos[]
static
Initial value:
= {
{ "ADS1013", fixedranges, rates101x, 1, ADS101x_RANGEDIV },
{ "ADS1014", gainranges, rates101x, 1, ADS101x_RANGEDIV },
{ "ADS1015", gainranges, rates101x, 8, ADS101x_RANGEDIV },
{ "ADS1113", fixedranges, rates111x, 1, ADS111x_RANGEDIV },
{ "ADS1114", gainranges, rates111x, 1, ADS111x_RANGEDIV },
{ "ADS1115", gainranges, rates111x, 8, ADS111x_RANGEDIV },
}
static const u_int fixedranges[8]
Definition: ads111x.c:105
static const u_int rates111x[8]
Definition: ads111x.c:118
#define ADS101x_RANGEDIV
Definition: ads111x.c:113
static const u_int rates101x[8]
Definition: ads111x.c:117
static const u_int gainranges[8]
Definition: ads111x.c:108
#define ADS111x_RANGEDIV
Definition: ads111x.c:114

Definition at line 136 of file ads111x.c.

Referenced by ads111x_find_chipinfo().

◆ ads111x_devclass

devclass_t ads111x_devclass
static

Definition at line 609 of file ads111x.c.

◆ ads111x_driver

driver_t ads111x_driver
static
Initial value:
= {
"ads111x",
sizeof(struct ads111x_softc),
}
static device_method_t ads111x_methods[]
Definition: ads111x.c:596

Definition at line 604 of file ads111x.c.

◆ ads111x_methods

device_method_t ads111x_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, ads111x_probe),
DEVMETHOD(device_attach, ads111x_attach),
DEVMETHOD(device_detach, ads111x_detach),
DEVMETHOD_END,
}
static int ads111x_attach(device_t dev)
Definition: ads111x.c:539
static int ads111x_detach(device_t dev)
Definition: ads111x.c:586
static int ads111x_probe(device_t dev)
Definition: ads111x.c:521

Definition at line 596 of file ads111x.c.

◆ fixedranges

const u_int fixedranges[8]
static
Initial value:
= {
2048000, 2048000, 2048000, 2048000, 2048000, 2048000, 2048000, 2048000,
}

Definition at line 105 of file ads111x.c.

◆ gainranges

const u_int gainranges[8]
static
Initial value:
= {
6144000, 4096000, 2048000, 1024000, 512000, 256000, 256000, 256000,
}

Definition at line 108 of file ads111x.c.

◆ rates101x

const u_int rates101x[8] = {128, 250, 490, 920, 1600, 2400, 3300, 3300}
static

Definition at line 117 of file ads111x.c.

◆ rates111x

const u_int rates111x[8] = { 8, 16, 32, 64, 128, 250, 475, 860}
static

Definition at line 118 of file ads111x.c.