Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src add HYT-221/271/939 humidity/temperature I2C sensor
details: https://anonhg.NetBSD.org/src/rev/452e01c75a4e
branches: trunk
changeset: 329293:452e01c75a4e
user: kardel <kardel%NetBSD.org@localhost>
date: Sun May 18 11:46:23 2014 +0000
description:
add HYT-221/271/939 humidity/temperature I2C sensor
extend envsys(4) framework by %rH (relative humidity)
diffstat:
doc/CHANGES | 6 +-
share/man/man4/Makefile | 4 +-
share/man/man4/hythygtemp.4 | 63 ++++++
sys/dev/i2c/files.i2c | 7 +-
sys/dev/i2c/hytp14.c | 312 +++++++++++++++++++++++++++++++
sys/dev/i2c/hytp14reg.h | 90 ++++++++
sys/dev/i2c/hytp14var.h | 75 +++++++
sys/dev/sysmon/sysmon_envsys_tables.c | 5 +-
sys/modules/Makefile | 3 +-
sys/modules/hythygtemp/Makefile | 11 +
sys/modules/hythygtemp/hythygtemp.ioconf | 9 +
sys/sys/envsys.h | 7 +-
usr.sbin/envstat/envstat.8 | 9 +-
usr.sbin/envstat/envstat.c | 6 +-
14 files changed, 592 insertions(+), 15 deletions(-)
diffs (truncated from 779 to 300 lines):
diff -r 1c3416b234f0 -r 452e01c75a4e doc/CHANGES
--- a/doc/CHANGES Sun May 18 11:04:51 2014 +0000
+++ b/doc/CHANGES Sun May 18 11:46:23 2014 +0000
@@ -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 @@
[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]
\ No newline at end of file
diff -r 1c3416b234f0 -r 452e01c75a4e share/man/man4/Makefile
--- a/share/man/man4/Makefile Sun May 18 11:04:51 2014 +0000
+++ b/share/man/man4/Makefile Sun May 18 11:46:23 2014 +0000
@@ -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 @@
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 \
diff -r 1c3416b234f0 -r 452e01c75a4e share/man/man4/hythygtemp.4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/hythygtemp.4 Sun May 18 11:46:23 2014 +0000
@@ -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@localhost .
diff -r 1c3416b234f0 -r 452e01c75a4e sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c Sun May 18 11:04:51 2014 +0000
+++ b/sys/dev/i2c/files.i2c Sun May 18 11:46:23 2014 +0000
@@ -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 @@
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
diff -r 1c3416b234f0 -r 452e01c75a4e sys/dev/i2c/hytp14.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/hytp14.c Sun May 18 11:46:23 2014 +0000
@@ -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;
Home |
Main Index |
Thread Index |
Old Index