add HYT-221/271/939 humidity/temperature I2C sensor
extend envsys(4) framework by %rH (relative humidity)
This commit is contained in:
parent
13bd467664
commit
54c2251d60
@ -1,4 +1,4 @@
|
||||
# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1925 $>
|
||||
# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1926 $>
|
||||
#
|
||||
#
|
||||
# [Note: This file does not mention every change made to the NetBSD source tree.
|
||||
@ -417,3 +417,7 @@ Changes from NetBSD 6.0 to NetBSD 7.0:
|
||||
[pettai 20140424]
|
||||
libc: Update to tzcode2014c. [christos 20140513]
|
||||
zoneinfo: Import tzdata2014c. [apb 20140515]
|
||||
hythygtemp(4): Add HYT-221/271/939 humidity/temperature iic sensor
|
||||
driver. [kardel 20140518]
|
||||
envsys(4): Add %rH (relative Humidity) to sensor framework.
|
||||
[kardel 20140518]
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.613 2014/04/23 06:53:14 kardel Exp $
|
||||
# $NetBSD: Makefile,v 1.614 2014/05/18 11:46:23 kardel Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/18/93
|
||||
|
||||
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
|
||||
@ -28,7 +28,7 @@ MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
|
||||
gcscaudio.4 gem.4 genfb.4 gentbi.4 geodeide.4 \
|
||||
glxtphy.4 gpib.4 gpio.4 gpiolock.4 gpiopwm.4 gpiosim.4 gre.4 \
|
||||
gphyter.4 gsip.4 \
|
||||
hdaudio.4 hifn.4 hme.4 hpacel.4 hpqlb.4 hptide.4 \
|
||||
hdaudio.4 hifn.4 hme.4 hpacel.4 hpqlb.4 hptide.4 hythygtemp.4 \
|
||||
ibmcd.4 ibmhawk.4 ichsmb.4 icmp.4 icp.4 icsphy.4 iee.4 ieee80211.4 \
|
||||
ifmedia.4 igmafb.4 igphy.4 igsfb.4 iha.4 ihphy.4 iic.4 inet.4 ikphy.4 \
|
||||
inphy.4 intersil7170.4 \
|
||||
|
63
share/man/man4/hythygtemp.4
Normal file
63
share/man/man4/hythygtemp.4
Normal file
@ -0,0 +1,63 @@
|
||||
.\" $NetBSD: hythygtemp.4,v 1.1 2014/05/18 11:46:23 kardel Exp $
|
||||
.\"
|
||||
.\"Copyright (c) 2014 Frank Kardel
|
||||
.\"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. 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 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 FOUNDATION 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.
|
||||
.\"
|
||||
.Dd May 18, 2014
|
||||
.Dt HYTHYGTEMP 4
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm hythygtemp
|
||||
.Nd Driver for IST-AG HYT-221/271/939 sensor chip via I2C bus
|
||||
.Sh SYNOPSIS
|
||||
.Cd "hythygtemp* at iic? addr 0x28"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
driver provides measurements from the HYT-221/271/939 humidity/temperature
|
||||
sensors via the
|
||||
.Xr envsys 4
|
||||
framework.
|
||||
The
|
||||
.Nm
|
||||
.Ar addr
|
||||
argument selects the address at the
|
||||
.Xr iic 4
|
||||
bus. The sensor chips can be reconfigured to respond to other addresses than the
|
||||
default value of 0x28.
|
||||
.Sh SEE ALSO
|
||||
.Xr envstat 8 ,
|
||||
.Xr envsys 4 ,
|
||||
.Xr iic 4
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
driver first appeared in
|
||||
.Nx 7.0 .
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
The
|
||||
.Nm
|
||||
driver was written by
|
||||
.An Frank Kardel Aq Mt kardel@NetBSD.org .
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.i2c,v 1.53 2013/10/15 19:13:32 jdc Exp $
|
||||
# $NetBSD: files.i2c,v 1.54 2014/05/18 11:46:23 kardel Exp $
|
||||
|
||||
obsolete defflag opt_i2cbus.h I2C_SCAN
|
||||
define i2cbus { }
|
||||
@ -103,6 +103,11 @@ device lmtemp: sysmon_envsys
|
||||
attach lmtemp at iic
|
||||
file dev/i2c/lm75.c lmtemp
|
||||
|
||||
# IST-AG Humidity and Teperature sensor (P14)
|
||||
device hythygtemp: sysmon_envsys
|
||||
attach hythygtemp at iic
|
||||
file dev/i2c/hytp14.c hythygtemp
|
||||
|
||||
# National Semiconductor LM78 temp sensor/fan controller
|
||||
attach lm at iic with lm_iic
|
||||
file dev/i2c/lm_i2c.c lm_iic
|
||||
|
312
sys/dev/i2c/hytp14.c
Normal file
312
sys/dev/i2c/hytp14.c
Normal file
@ -0,0 +1,312 @@
|
||||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Frank Kardel.
|
||||
*
|
||||
* 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. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* IST-AG P14 calibrated Hygro-/Temperature sensor module
|
||||
* Devices: HYT-271, HYT-221 and HYT-939
|
||||
*
|
||||
* see:
|
||||
* http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/
|
||||
* $FILE/AHHYTM_E2.1.pdf
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: hytp14.c,v 1.1 2014/05/18 11:46:23 kardel Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/module.h>
|
||||
|
||||
#include <dev/sysmon/sysmonvar.h>
|
||||
|
||||
#include <dev/i2c/i2cvar.h>
|
||||
#include <dev/i2c/hytp14reg.h>
|
||||
#include <dev/i2c/hytp14var.h>
|
||||
|
||||
static int hytp14_match(device_t, cfdata_t, void *);
|
||||
static void hytp14_attach(device_t, device_t, void *);
|
||||
static int hytp14_detach(device_t, int);
|
||||
static int hytp14_refresh_sensor(struct hytp14_sc *sc);
|
||||
static void hytp14_refresh(struct sysmon_envsys *, envsys_data_t *);
|
||||
static void hytp14_refresh_humidity(struct hytp14_sc *, envsys_data_t *);
|
||||
static void hytp14_refresh_temp(struct hytp14_sc *, envsys_data_t *);
|
||||
|
||||
/* #define HYT_DEBUG 3 */
|
||||
#ifdef HYT_DEBUG
|
||||
volatile int hythygtemp_debug = HYT_DEBUG;
|
||||
|
||||
#define DPRINTF(_L_, _X_) do { \
|
||||
if ((_L_) <= hythygtemp_debug) { \
|
||||
printf _X_; \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define DPRINTF(_L_, _X_)
|
||||
#endif
|
||||
|
||||
CFATTACH_DECL_NEW(hythygtemp, sizeof(struct hytp14_sc),
|
||||
hytp14_match, hytp14_attach, hytp14_detach, NULL);
|
||||
|
||||
static struct hytp14_sensor hytp14_sensors[] = {
|
||||
{
|
||||
.desc = "humidity",
|
||||
.type = ENVSYS_SRELHUMIDITY,
|
||||
.refresh = hytp14_refresh_humidity
|
||||
},
|
||||
{
|
||||
.desc = "temperature",
|
||||
.type = ENVSYS_STEMP,
|
||||
.refresh = hytp14_refresh_temp
|
||||
}
|
||||
};
|
||||
|
||||
static int
|
||||
hytp14_match(device_t parent, cfdata_t match, void *aux)
|
||||
{
|
||||
struct i2c_attach_args *ia = aux;
|
||||
|
||||
if (ia->ia_name) {
|
||||
/* direct config - check name */
|
||||
if (strcmp(ia->ia_name, "hythygtemp") == 0)
|
||||
return 1;
|
||||
} else {
|
||||
/* indirect config - check typical address */
|
||||
if (ia->ia_addr == HYTP14_DEFAULT_ADDR)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
hytp14_attach(device_t parent, device_t self, void *aux)
|
||||
{
|
||||
struct hytp14_sc *sc = device_private(self);
|
||||
struct i2c_attach_args *ia = aux;
|
||||
int i;
|
||||
|
||||
sc->sc_dev = self;
|
||||
sc->sc_tag = ia->ia_tag;
|
||||
sc->sc_addr = ia->ia_addr;
|
||||
sc->sc_refresh = 0;
|
||||
sc->sc_valid = ENVSYS_SINVALID;
|
||||
sc->sc_numsensors = __arraycount(hytp14_sensors);
|
||||
|
||||
if ((sc->sc_sme = sysmon_envsys_create()) == NULL) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to create sysmon structure\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < sc->sc_numsensors; i++) {
|
||||
strlcpy(sc->sc_sensors[i].desc,
|
||||
hytp14_sensors[i].desc,
|
||||
sizeof sc->sc_sensors[i].desc);
|
||||
|
||||
sc->sc_sensors[i].units = hytp14_sensors[i].type;
|
||||
sc->sc_sensors[i].state = ENVSYS_SINVALID;
|
||||
|
||||
DPRINTF(2, ("hytp14_attach: registering sensor %d (%s)\n", i,
|
||||
sc->sc_sensors[i].desc));
|
||||
|
||||
if (sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensors[i])) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to attach sensor\n");
|
||||
sysmon_envsys_destroy(sc->sc_sme);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sc->sc_sme->sme_name = device_xname(sc->sc_dev);
|
||||
sc->sc_sme->sme_cookie = sc;
|
||||
sc->sc_sme->sme_refresh = hytp14_refresh;
|
||||
|
||||
DPRINTF(2, ("hytp14_attach: registering with envsys\n"));
|
||||
|
||||
if (sysmon_envsys_register(sc->sc_sme)) {
|
||||
aprint_error_dev(sc->sc_dev,
|
||||
"unable to register with sysmon\n");
|
||||
sysmon_envsys_destroy(sc->sc_sme);
|
||||
return;
|
||||
}
|
||||
|
||||
aprint_normal(": HYT-221/271/939 humidity and temperature sensor\n");
|
||||
}
|
||||
|
||||
static int hytp14_detach(device_t self, int flags)
|
||||
{
|
||||
struct hytp14_sc *sc = device_private(self);
|
||||
|
||||
if (sc->sc_sme != NULL) {
|
||||
sysmon_envsys_unregister(sc->sc_sme);
|
||||
sc->sc_sme = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
hytp14_refresh_sensor(struct hytp14_sc *sc)
|
||||
{
|
||||
int error = 0;
|
||||
uint8_t buf[I2C_EXEC_MAX_BUFLEN];
|
||||
|
||||
/* no more than once per second */
|
||||
if (hardclock_ticks - sc->sc_refresh < hz)
|
||||
return sc->sc_valid;
|
||||
|
||||
DPRINTF(2, ("hytp14_refresh_sensor(%s)\n", device_xname(sc->sc_dev)));
|
||||
|
||||
if ((error = iic_acquire_bus(sc->sc_tag, 0)) == 0) {
|
||||
DPRINTF(3, ("hytp14_refresh_sensor(%s): bus locked\n", device_xname(sc->sc_dev)));
|
||||
|
||||
/* send MR command */
|
||||
/* avoid quick read/write by providing a result buffer */
|
||||
if ((error = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP,
|
||||
sc->sc_addr, NULL, 0, buf, sizeof buf, 0)) == 0) {
|
||||
DPRINTF(3, ("hytp14_refresh_sensor(%s): MR sent\n",
|
||||
device_xname(sc->sc_dev)));
|
||||
|
||||
/* send DF command - read data from sensor */
|
||||
if ((error = iic_exec(sc->sc_tag, I2C_OP_READ_WITH_STOP,
|
||||
sc->sc_addr, NULL, 0, sc->sc_data,
|
||||
sizeof sc->sc_data, 0)) != 0) {
|
||||
DPRINTF(2, ("%s: %s: failed read from 0x%02x - error %d\n",
|
||||
device_xname(sc->sc_dev),
|
||||
__func__, sc->sc_addr, error));
|
||||
} else {
|
||||
DPRINTF(2, ("hytp14_refresh_sensor(%s): DF success : 0x%02x%02x%02x%02x\n",
|
||||
device_xname(sc->sc_dev),
|
||||
sc->sc_data[0],
|
||||
sc->sc_data[1],
|
||||
sc->sc_data[2],
|
||||
sc->sc_data[3]));
|
||||
}
|
||||
} else {
|
||||
DPRINTF(2, ("%s: %s: failed read from 0x%02x - error %d\n",
|
||||
device_xname(sc->sc_dev), __func__,
|
||||
sc->sc_addr, error));
|
||||
}
|
||||
|
||||
iic_release_bus(sc->sc_tag, 0);
|
||||
DPRINTF(3, ("hytp14_refresh_sensor(%s): bus released\n", device_xname(sc->sc_dev)));
|
||||
} else {
|
||||
DPRINTF(2, ("%s: %s: failed read from 0x%02x - error %d\n",
|
||||
device_xname(sc->sc_dev), __func__, sc->sc_addr, error));
|
||||
}
|
||||
|
||||
sc->sc_refresh = hardclock_ticks;
|
||||
|
||||
if (error == 0) {
|
||||
sc->sc_valid = ENVSYS_SVALID;
|
||||
} else {
|
||||
sc->sc_valid = ENVSYS_SINVALID;
|
||||
}
|
||||
|
||||
return sc->sc_valid;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
hytp14_refresh_humidity(struct hytp14_sc *sc, envsys_data_t *edata)
|
||||
{
|
||||
uint16_t hyg;
|
||||
int status;
|
||||
|
||||
status = hytp14_refresh_sensor(sc);
|
||||
|
||||
if (status == ENVSYS_SVALID) {
|
||||
hyg = (sc->sc_data[0] << 8) | sc->sc_data[1];
|
||||
|
||||
edata->value_cur = (1000000000 / HYTP14_HYG_SCALE) * (int32_t)HYTP14_HYG_RAWVAL(hyg);
|
||||
edata->value_cur /= 10;
|
||||
}
|
||||
|
||||
edata->state = status;
|
||||
}
|
||||
|
||||
static void
|
||||
hytp14_refresh_temp(struct hytp14_sc *sc, envsys_data_t *edata)
|
||||
{
|
||||
uint16_t temp;
|
||||
int status;
|
||||
|
||||
status = hytp14_refresh_sensor(sc);
|
||||
|
||||
if (status == ENVSYS_SVALID) {
|
||||
temp = HYTP14_TEMP_RAWVAL((sc->sc_data[2] << 8) | sc->sc_data[3]);
|
||||
|
||||
edata->value_cur = (HYTP14_TEMP_FACTOR * 1000000) / HYTP14_TEMP_SCALE;
|
||||
edata->value_cur *= (int32_t)temp;
|
||||
edata->value_cur += HYTP14_TEMP_OFFSET * 1000000 + 273150000;
|
||||
}
|
||||
|
||||
edata->state = status;
|
||||
}
|
||||
|
||||
static void
|
||||
hytp14_refresh(struct sysmon_envsys *sme, envsys_data_t *edata)
|
||||
{
|
||||
struct hytp14_sc *sc = sme->sme_cookie;
|
||||
|
||||
hytp14_sensors[edata->sensor].refresh(sc, edata);
|
||||
}
|
||||
|
||||
|
||||
MODULE(MODULE_CLASS_DRIVER, hythygtemp, "iic");
|
||||
|
||||
#ifdef _MODULE
|
||||
#include "ioconf.c"
|
||||
#endif
|
||||
|
||||
static int
|
||||
hythygtemp_modcmd(modcmd_t cmd, void *opaque)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
switch (cmd) {
|
||||
case MODULE_CMD_INIT:
|
||||
#ifdef _MODULE
|
||||
error = config_init_component(cfdriver_ioconf_hythygtemp,
|
||||
cfattach_ioconf_hythygtemp, cfdata_ioconf_hythygtemp);
|
||||
#endif
|
||||
return error;
|
||||
|
||||
case MODULE_CMD_FINI:
|
||||
#ifdef _MODULE
|
||||
error = config_fini_component(cfdriver_ioconf_hythygtemp,
|
||||
cfattach_ioconf_hythygtemp, cfdata_ioconf_hythygtemp);
|
||||
#endif
|
||||
return error;
|
||||
|
||||
default:
|
||||
return ENOTTY;
|
||||
}
|
||||
}
|
90
sys/dev/i2c/hytp14reg.h
Normal file
90
sys/dev/i2c/hytp14reg.h
Normal file
@ -0,0 +1,90 @@
|
||||
/* $NetBSD: hytp14reg.h,v 1.1 2014/05/18 11:46:23 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Frank Kardel.
|
||||
*
|
||||
* 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. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* IST-AG P14 calibrated Hygro-/Temperature sensor module
|
||||
* Devices: HYT-271, HYT-221 and HYT-939
|
||||
*
|
||||
* see:
|
||||
* http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/
|
||||
* $FILE/AHHYTM_E2.1.pdf
|
||||
*/
|
||||
#ifndef _DEV_I2C_HYTP14REG_H_
|
||||
#define _DEV_I2C_HYTP14REG_H_
|
||||
|
||||
#define HYTP14_DEFAULT_ADDR 0x28
|
||||
|
||||
#define HYTP14_CMD_SEND 0x50 /* send command */
|
||||
#define HYTP14_CMD_RESP 0x51 /* receive response */
|
||||
|
||||
#define HYTP14_CMD_START_NOM 0x80 /* end command mode (or power-off) */
|
||||
#define HYTP14_CMD_START_CM 0xA0 /* start command mode (within 10ms after power-up) */
|
||||
#define HYTP14_CMD_GET_REV 0xB0 /* get revison */
|
||||
|
||||
#define HYTP14_NUM_WORDS 32
|
||||
#define HYTP14_READ_OFFSET 0x00 /* command offset to read EEPROM words */
|
||||
#define HYTP14_WRITE_OFFSET 0x40 /* command offset to write EEPROM words */
|
||||
|
||||
#define HYTP14_READ_EEPROM(_X_) (HYTP14_READ_OFFSET + (_X_) & (HYTP14_NUM_WORDS - 1))
|
||||
#define HYTP14_WRITE_EEPROM(_X_) (HYTP14_WRITE_OFFSET + (_X_) & (HYTP14_NUM_WORDS - 1))
|
||||
|
||||
#define HYTP14_EEADDR_I2CADDR 0x1C /* I2C address EEPROD word address */
|
||||
|
||||
#define HYTP14_RESP_CMDMODE 0x80 /* command mode response */
|
||||
#define HYTP14_RESP_STALE 0y40 /* stale measurement data */
|
||||
|
||||
#define HYTP14_DIAG_ERR_CFG 0x20 /* configuration error */
|
||||
#define HYTP14_DIAG_ERR_RAMPRTY 0x10 /* RAM parity error */
|
||||
#define HYTP14_DIAG_ERR_UNCEEP 0x08 /* uncorrectable EEPROM error */
|
||||
#define HYTP14_DIAG_ERR_COREEP 0x04 /* correctable EEPROM error */
|
||||
|
||||
#define HYTP14_RESP_MASK 0x03
|
||||
#define HYTP14_RESP_BUSY 0x00 /* device is busy */
|
||||
#define HYTP14_RESP_ACK 0x01 /* positive acknowlege */
|
||||
#define HYTP14_RESP_NACK 0x02 /* negative acknowlege */
|
||||
|
||||
#define HYTP14_ST_CMDMODE 0x8000 /* command mode */
|
||||
#define HYTP14_ST_STALE 0x4000 /* stale measurement data */
|
||||
#define HYTP14_HYG_RAWVAL(_X_) ((_X_) & 0x3FFF)
|
||||
#define HYTP14_HYG_SCALE (1<<14)
|
||||
#define HYTP14_TEMP_RAWVAL(_X_) (((_X_) >> 2) & 0x3FFF)
|
||||
#define HYTP14_TEMP_SCALE (1<<14)
|
||||
#define HYTP14_TEMP_FACTOR 165
|
||||
#define HYTP14_TEMP_OFFSET (-40)
|
||||
|
||||
#endif
|
||||
/*
|
||||
* $Log: hytp14reg.h,v $
|
||||
* Revision 1.1 2014/05/18 11:46:23 kardel
|
||||
* add HYT-221/271/939 humidity/temperature I2C sensor
|
||||
* extend envsys(4) framework by %rH (relative humidity)
|
||||
*
|
||||
*/
|
75
sys/dev/i2c/hytp14var.h
Normal file
75
sys/dev/i2c/hytp14var.h
Normal file
@ -0,0 +1,75 @@
|
||||
/* $NetBSD: hytp14var.h,v 1.1 2014/05/18 11:46:23 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Frank Kardel.
|
||||
*
|
||||
* 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. 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* IST-AG P14 calibrated Hygro-/Temperature sensor module
|
||||
* Devices: HYT-271, HYT-221 and HYT-939
|
||||
*
|
||||
* see:
|
||||
* http://www.ist-ag.com/eh/ist-ag/resource.nsf/imgref/Download_AHHYTM_E2.1.pdf/
|
||||
* $FILE/AHHYTM_E2.1.pdf
|
||||
*/
|
||||
#ifndef _DEV_I2C_HYTP14VAR_H_
|
||||
#define _DEV_I2C_HYTP14VAR_H_
|
||||
|
||||
#define HYTP14_DEFAULT_ADDR 0x28
|
||||
|
||||
#define HYTP14_NUM_SENSORS 2
|
||||
|
||||
struct hytp14_sc {
|
||||
device_t sc_dev;
|
||||
i2c_tag_t sc_tag;
|
||||
i2c_addr_t sc_addr;
|
||||
|
||||
int sc_refresh; /* last refresh from hardclock_ticks */
|
||||
int sc_valid; /* ENVSYS validity state for this sensor */
|
||||
uint8_t sc_data[4]; /* last data read */
|
||||
|
||||
int sc_numsensors;
|
||||
|
||||
struct sysmon_envsys *sc_sme;
|
||||
envsys_data_t sc_sensors[HYTP14_NUM_SENSORS];
|
||||
};
|
||||
|
||||
struct hytp14_sensor {
|
||||
const char *desc;
|
||||
enum envsys_units type;
|
||||
void (*refresh)(struct hytp14_sc *, envsys_data_t *);
|
||||
};
|
||||
|
||||
#endif
|
||||
/*
|
||||
* $Log: hytp14var.h,v $
|
||||
* Revision 1.1 2014/05/18 11:46:23 kardel
|
||||
* add HYT-221/271/939 humidity/temperature I2C sensor
|
||||
* extend envsys(4) framework by %rH (relative humidity)
|
||||
*
|
||||
*/
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $ */
|
||||
/* $NetBSD: sysmon_envsys_tables.c,v 1.12 2014/05/18 11:46:23 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007 Juan Romero Pardines.
|
||||
@ -26,7 +26,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.11 2012/08/27 21:42:04 pgoyette Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sysmon_envsys_tables.c,v 1.12 2014/05/18 11:46:23 kardel Exp $");
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
@ -51,6 +51,7 @@ static const struct sme_descr_entry sme_units_description[] = {
|
||||
{ ENVSYS_DRIVE, PENVSYS_TYPE_DRIVE, "Drive" },
|
||||
{ ENVSYS_BATTERY_CAPACITY, PENVSYS_TYPE_BATTERY,"Battery capacity" },
|
||||
{ ENVSYS_BATTERY_CHARGE, -1, "Battery charge" },
|
||||
{ ENVSYS_SRELHUMIDITY, -1, "relative Humidity" },
|
||||
{ -1, -1, "unknown" }
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.135 2014/01/03 16:16:10 pgoyette Exp $
|
||||
# $NetBSD: Makefile,v 1.136 2014/05/18 11:46:23 kardel Exp $
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
@ -39,6 +39,7 @@ SUBDIR+= gpioiic
|
||||
SUBDIR+= gpioow
|
||||
SUBDIR+= gpiosim
|
||||
SUBDIR+= hfs
|
||||
SUBDIR+= hythygtemp
|
||||
SUBDIR+= if_axe
|
||||
SUBDIR+= if_axen
|
||||
SUBDIR+= if_npflog
|
||||
|
11
sys/modules/hythygtemp/Makefile
Normal file
11
sys/modules/hythygtemp/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
# $NetBSD: Makefile,v 1.1 2014/05/18 11:46:24 kardel Exp $
|
||||
|
||||
.include "../Makefile.inc"
|
||||
|
||||
.PATH: ${S}/dev/i2c
|
||||
|
||||
KMOD= hythygtemp
|
||||
IOCONF= hythygtemp.ioconf
|
||||
SRCS= hytp14.c
|
||||
|
||||
.include <bsd.kmodule.mk>
|
9
sys/modules/hythygtemp/hythygtemp.ioconf
Normal file
9
sys/modules/hythygtemp/hythygtemp.ioconf
Normal file
@ -0,0 +1,9 @@
|
||||
# $NetBSD: hythygtemp.ioconf,v 1.1 2014/05/18 11:46:24 kardel Exp $
|
||||
|
||||
ioconf hythygtemp
|
||||
|
||||
include "conf/files"
|
||||
|
||||
pseudo-root iic*
|
||||
|
||||
hythygtemp* at iic? addr 0x28
|
@ -1,7 +1,7 @@
|
||||
/* $NetBSD: envsys.h,v 1.33 2012/12/05 04:21:30 riastradh Exp $ */
|
||||
/* $NetBSD: envsys.h,v 1.34 2014/05/18 11:46:24 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2007 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999, 2007, 2014 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
@ -63,6 +63,7 @@ enum envsys_units {
|
||||
ENVSYS_DRIVE, /* Drive */
|
||||
ENVSYS_BATTERY_CAPACITY, /* Battery capacity */
|
||||
ENVSYS_BATTERY_CHARGE, /* Battery charging/discharging */
|
||||
ENVSYS_SRELHUMIDITY, /* relative humidity */
|
||||
ENVSYS_NSENSORS
|
||||
};
|
||||
|
||||
@ -161,7 +162,7 @@ typedef struct envsys_tre_data envsys_tre_data_t;
|
||||
#ifdef ENVSYSUNITNAMES
|
||||
static const char * const envsysunitnames[] = {
|
||||
"degC", "RPM", "VAC", "V", "Ohms", "W",
|
||||
"A", "Wh", "Ah", "bool", "integer", "drive", "Unk"
|
||||
"A", "Wh", "Ah", "bool", "integer", "drive", "%rH", "Unk"
|
||||
};
|
||||
static const char * const envsysdrivestatus[] = {
|
||||
"unknown", "empty", "ready", "powering up", "online", "idle", "active",
|
||||
|
@ -1,6 +1,6 @@
|
||||
.\" $NetBSD: envstat.8,v 1.61 2012/02/09 18:10:26 riz Exp $
|
||||
.\" $NetBSD: envstat.8,v 1.62 2014/05/18 11:46:24 kardel Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2000, 2007, 2008, 2009 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 2000, 2007, 2008, 2009, 2014 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
@ -27,7 +27,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd June 7, 2011
|
||||
.Dd May 18, 2014
|
||||
.Dt ENVSTAT 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -166,6 +166,8 @@ Volts AC
|
||||
Watts
|
||||
.It Wh
|
||||
Watt-hours
|
||||
.It %rH
|
||||
relative Humidity
|
||||
.El
|
||||
.Sh EXAMPLES
|
||||
To display the
|
||||
@ -217,6 +219,7 @@ invalid states every second:
|
||||
.Xr envctrl 4 ,
|
||||
.Xr envsys 4 ,
|
||||
.Xr finsio 4 ,
|
||||
.Xr hythygtemp 4 ,
|
||||
.Xr ipmi 4 ,
|
||||
.Xr itesio 4 ,
|
||||
.Xr lm 4 ,
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: envstat.c,v 1.94 2012/12/14 05:29:28 pgoyette Exp $ */
|
||||
/* $NetBSD: envstat.c,v 1.95 2014/05/18 11:46:24 kardel Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2007, 2008 Juan Romero Pardines.
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: envstat.c,v 1.94 2012/12/14 05:29:28 pgoyette Exp $");
|
||||
__RCSID("$NetBSD: envstat.c,v 1.95 2014/05/18 11:46:24 kardel Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <stdio.h>
|
||||
@ -975,6 +975,8 @@ do { \
|
||||
stype = "Wh";
|
||||
else if (strcmp(sensor->type, "Ampere hour") == 0)
|
||||
stype = "Ah";
|
||||
else if (strcmp(sensor->type, "relative Humidity") == 0)
|
||||
stype = "%rH";
|
||||
else
|
||||
stype = "?";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user