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

Go to the source code of this file.

Data Structures

struct  htu21_softc
 

Macros

#define HTU21_ADDR   0x40
 
#define HTU21_GET_TEMP   0xe3
 
#define HTU21_GET_HUM   0xe5
 
#define HTU21_GET_TEMP_NH   0xf3
 
#define HTU21_GET_HUM_NH   0xf5
 
#define HTU21_WRITE_CFG   0xe6
 
#define HTU21_READ_CFG   0xe7
 
#define HTU21_RESET   0xfe
 
#define HTU2x_SERIAL0_0   0xfa
 
#define HTU2x_SERIAL0_1   0x0f
 
#define HTU2x_SERIAL1_0   0xfc
 
#define HTU2x_SERIAL1_1   0xc9
 

Functions

 __FBSDID ("$FreeBSD$")
 
static uint8_t calc_crc (uint16_t data)
 
static int check_crc_16 (const uint8_t *data, uint8_t expected)
 
static int check_crc_8 (const uint8_t data, uint8_t expected)
 
static int htu21_get_measurement (device_t dev, uint8_t cmd, uint8_t *data, int count)
 
static int htu21_get_measurement_nohold (device_t dev, uint8_t cmd, uint8_t *data, int count)
 
static int htu21_temp_sysctl (SYSCTL_HANDLER_ARGS)
 
static int htu21_rh_sysctl (SYSCTL_HANDLER_ARGS)
 
static int htu21_get_cfg (device_t dev, uint8_t *cfg)
 
static int htu21_set_cfg (device_t dev, uint8_t cfg)
 
static int htu21_heater_sysctl (SYSCTL_HANDLER_ARGS)
 
static int htu21_power_sysctl (SYSCTL_HANDLER_ARGS)
 
static int htu21_get_serial (device_t dev)
 
static void htu21_start (void *arg)
 
static int htu21_probe (device_t dev)
 
static int htu21_attach (device_t dev)
 
static int htu21_detach (device_t dev)
 
 DRIVER_MODULE (htu21, iicbus, htu21_driver, htu21_devclass, 0, 0)
 
 MODULE_DEPEND (htu21, iicbus, IICBUS_MINVER, IICBUS_PREFVER, IICBUS_MAXVER)
 
 MODULE_VERSION (htu21, 1)
 
 IICBUS_FDT_PNP_INFO (compat_data)
 

Variables

static device_method_t htu21_methods []
 
static driver_t htu21_driver
 
static devclass_t htu21_devclass
 

Macro Definition Documentation

◆ HTU21_ADDR

#define HTU21_ADDR   0x40

Definition at line 61 of file htu21.c.

◆ HTU21_GET_HUM

#define HTU21_GET_HUM   0xe5

Definition at line 64 of file htu21.c.

◆ HTU21_GET_HUM_NH

#define HTU21_GET_HUM_NH   0xf5

Definition at line 66 of file htu21.c.

◆ HTU21_GET_TEMP

#define HTU21_GET_TEMP   0xe3

Definition at line 63 of file htu21.c.

◆ HTU21_GET_TEMP_NH

#define HTU21_GET_TEMP_NH   0xf3

Definition at line 65 of file htu21.c.

◆ HTU21_READ_CFG

#define HTU21_READ_CFG   0xe7

Definition at line 68 of file htu21.c.

◆ HTU21_RESET

#define HTU21_RESET   0xfe

Definition at line 69 of file htu21.c.

◆ HTU21_WRITE_CFG

#define HTU21_WRITE_CFG   0xe6

Definition at line 67 of file htu21.c.

◆ HTU2x_SERIAL0_0

#define HTU2x_SERIAL0_0   0xfa

Definition at line 71 of file htu21.c.

◆ HTU2x_SERIAL0_1

#define HTU2x_SERIAL0_1   0x0f

Definition at line 72 of file htu21.c.

◆ HTU2x_SERIAL1_0

#define HTU2x_SERIAL1_0   0xfc

Definition at line 73 of file htu21.c.

◆ HTU2x_SERIAL1_1

#define HTU2x_SERIAL1_1   0xc9

Definition at line 74 of file htu21.c.

Function Documentation

◆ __FBSDID()

__FBSDID ( "$FreeBSD$"  )

◆ calc_crc()

static uint8_t calc_crc ( uint16_t  data)
static

Definition at line 92 of file htu21.c.

References data.

Referenced by check_crc_16(), and check_crc_8().

Here is the caller graph for this function:

◆ check_crc_16()

static int check_crc_16 ( const uint8_t *  data,
uint8_t  expected 
)
static

Definition at line 108 of file htu21.c.

References calc_crc(), and data.

Referenced by htu21_get_serial(), htu21_rh_sysctl(), and htu21_temp_sysctl().

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

◆ check_crc_8()

static int check_crc_8 ( const uint8_t  data,
uint8_t  expected 
)
static

Definition at line 117 of file htu21.c.

References calc_crc(), and data.

Referenced by htu21_get_serial().

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

◆ DRIVER_MODULE()

DRIVER_MODULE ( htu21  ,
iicbus  ,
htu21_driver  ,
htu21_devclass  ,
,
 
)

◆ htu21_attach()

static int htu21_attach ( device_t  dev)
static

Definition at line 487 of file htu21.c.

References dev, htu21_start(), htu21_softc::sc_addr, and htu21_softc::sc_dev.

Here is the call graph for this function:

◆ htu21_detach()

static int htu21_detach ( device_t  dev)
static

Definition at line 504 of file htu21.c.

◆ htu21_get_cfg()

static int htu21_get_cfg ( device_t  dev,
uint8_t *  cfg 
)
static

Definition at line 255 of file htu21.c.

References iic_msg::buf, dev, iic_msg::flags, HTU21_READ_CFG, IIC_INTRWAIT, IIC_M_NOSTOP, IIC_M_RD, IIC_M_WR, iicbus_transfer_excl(), iic_msg::len, msgs, htu21_softc::sc_addr, and iic_msg::slave.

Referenced by htu21_heater_sysctl(), and htu21_power_sysctl().

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

◆ htu21_get_measurement()

static int htu21_get_measurement ( device_t  dev,
uint8_t  cmd,
uint8_t *  data,
int  count 
)
static

Definition at line 126 of file htu21.c.

References iic_msg::buf, data, dev, iic_msg::flags, IIC_INTRWAIT, IIC_M_NOSTOP, IIC_M_RD, IIC_M_WR, iicbus_transfer_excl(), iic_msg::len, msgs, htu21_softc::sc_addr, and iic_msg::slave.

Referenced by htu21_rh_sysctl(), and htu21_temp_sysctl().

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

◆ htu21_get_measurement_nohold()

static int htu21_get_measurement_nohold ( device_t  dev,
uint8_t  cmd,
uint8_t *  data,
int  count 
)
static

Definition at line 149 of file htu21.c.

References iic_msg::buf, data, dev, iic_msg::flags, IIC_ENOACK, IIC_INTRWAIT, IIC_M_RD, IIC_M_WR, iicbus_transfer_excl(), iic_msg::len, msgs, htu21_softc::sc_addr, and iic_msg::slave.

Referenced by htu21_rh_sysctl(), and htu21_temp_sysctl().

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

◆ htu21_get_serial()

static int htu21_get_serial ( device_t  dev)
static

Definition at line 348 of file htu21.c.

References iic_msg::buf, check_crc_16(), check_crc_8(), data, dev, iic_msg::flags, HTU2x_SERIAL0_0, HTU2x_SERIAL0_1, HTU2x_SERIAL1_0, HTU2x_SERIAL1_1, IIC_INTRWAIT, IIC_M_NOSTOP, IIC_M_RD, IIC_M_WR, iicbus_transfer_excl(), iic_msg::len, msgs, htu21_softc::sc_addr, htu21_softc::sc_serial, and iic_msg::slave.

Referenced by htu21_start().

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

◆ htu21_heater_sysctl()

static int htu21_heater_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 301 of file htu21.c.

References dev, htu21_get_cfg(), and htu21_set_cfg().

Referenced by htu21_start().

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

◆ htu21_power_sysctl()

static int htu21_power_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 326 of file htu21.c.

References dev, and htu21_get_cfg().

Referenced by htu21_start().

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

◆ htu21_probe()

static int htu21_probe ( device_t  dev)
static

Definition at line 462 of file htu21.c.

References addr, compat_data, dev, and HTU21_ADDR.

◆ htu21_rh_sysctl()

static int htu21_rh_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 220 of file htu21.c.

References check_crc_16(), dev, HTU21_GET_HUM, HTU21_GET_HUM_NH, htu21_get_measurement(), htu21_get_measurement_nohold(), htu21_softc::sc_errcount, and htu21_softc::sc_hold.

Referenced by htu21_start().

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

◆ htu21_set_cfg()

static int htu21_set_cfg ( device_t  dev,
uint8_t  cfg 
)
static

Definition at line 280 of file htu21.c.

References iic_msg::buf, buf, dev, iic_msg::flags, HTU21_WRITE_CFG, IIC_INTRWAIT, IIC_M_WR, iicbus_transfer_excl(), iic_msg::len, htu21_softc::sc_addr, and iic_msg::slave.

Referenced by htu21_heater_sysctl().

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

◆ htu21_start()

static void htu21_start ( void *  arg)
static

Definition at line 412 of file htu21.c.

References dev, htu21_get_serial(), htu21_heater_sysctl(), htu21_power_sysctl(), htu21_rh_sysctl(), htu21_temp_sysctl(), htu21_softc::sc_dev, htu21_softc::sc_errcount, htu21_softc::sc_hold, and htu21_softc::sc_serial.

Referenced by htu21_attach().

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

◆ htu21_temp_sysctl()

static int htu21_temp_sysctl ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 185 of file htu21.c.

References check_crc_16(), dev, htu21_get_measurement(), htu21_get_measurement_nohold(), HTU21_GET_TEMP, HTU21_GET_TEMP_NH, htu21_softc::sc_errcount, and htu21_softc::sc_hold.

Referenced by htu21_start().

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

◆ IICBUS_FDT_PNP_INFO()

IICBUS_FDT_PNP_INFO ( compat_data  )

◆ MODULE_DEPEND()

MODULE_DEPEND ( htu21  ,
iicbus  ,
IICBUS_MINVER  ,
IICBUS_PREFVER  ,
IICBUS_MAXVER   
)

◆ MODULE_VERSION()

MODULE_VERSION ( htu21  ,
 
)

Variable Documentation

◆ htu21_devclass

devclass_t htu21_devclass
static

Definition at line 524 of file htu21.c.

◆ htu21_driver

driver_t htu21_driver
static
Initial value:
= {
"htu21",
sizeof(struct htu21_softc)
}
static device_method_t htu21_methods[]
Definition: htu21.c:509

Definition at line 518 of file htu21.c.

◆ htu21_methods

device_method_t htu21_methods[]
static
Initial value:
= {
DEVMETHOD(device_probe, htu21_probe),
DEVMETHOD(device_attach, htu21_attach),
DEVMETHOD(device_detach, htu21_detach),
DEVMETHOD_END
}
static int htu21_probe(device_t dev)
Definition: htu21.c:462
static int htu21_attach(device_t dev)
Definition: htu21.c:487
static int htu21_detach(device_t dev)
Definition: htu21.c:504

Definition at line 509 of file htu21.c.