Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add a driver for the Taos TSL256x light sensors.
details: https://anonhg.NetBSD.org/src/rev/b0bf7b6832e7
branches: trunk
changeset: 319344:b0bf7b6832e7
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun May 27 05:31:20 2018 +0000
description:
Add a driver for the Taos TSL256x light sensors.
diffstat:
distrib/sets/lists/man/mi | 5 +-
share/man/man4/Makefile | 4 +-
share/man/man4/tsllux.4 | 132 +++++
sys/dev/i2c/files.i2c | 7 +-
sys/dev/i2c/tsl256x.c | 1062 +++++++++++++++++++++++++++++++++++++++++++++
sys/dev/i2c/tsl256xreg.h | 145 ++++++
6 files changed, 1351 insertions(+), 4 deletions(-)
diffs (truncated from 1420 to 300 lines):
diff -r 82c221105639 -r b0bf7b6832e7 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun May 27 01:39:00 2018 +0000
+++ b/distrib/sets/lists/man/mi Sun May 27 05:31:20 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1589 2018/05/23 01:05:47 christos Exp $
+# $NetBSD: mi,v 1.1590 2018/05/27 05:31:20 thorpej Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -1818,6 +1818,7 @@
./usr/share/man/cat4/tr.0 man-sys-catman .cat
./usr/share/man/cat4/tra.0 man-sys-catman .cat
./usr/share/man/cat4/trm.0 man-sys-catman .cat
+./usr/share/man/cat4/tsllux.0 man-sys-catman .cat
./usr/share/man/cat4/tty.0 man-sys-catman .cat
./usr/share/man/cat4/tun.0 man-sys-catman .cat
./usr/share/man/cat4/tuner.0 man-obsolete obsolete
@@ -4887,6 +4888,7 @@
./usr/share/man/html4/tr.html man-sys-htmlman html
./usr/share/man/html4/tra.html man-sys-htmlman html
./usr/share/man/html4/trm.html man-sys-htmlman html
+./usr/share/man/html4/tsllux.html man-sys-htmlman html
./usr/share/man/html4/tty.html man-sys-htmlman html
./usr/share/man/html4/tun.html man-sys-htmlman html
./usr/share/man/html4/tuner.html man-obsolete obsolete
@@ -7876,6 +7878,7 @@
./usr/share/man/man4/tr.4 man-sys-man .man
./usr/share/man/man4/tra.4 man-sys-man .man
./usr/share/man/man4/trm.4 man-sys-man .man
+./usr/share/man/man4/tsllux.4 man-sys-man .man
./usr/share/man/man4/tty.4 man-sys-man .man
./usr/share/man/man4/tun.4 man-sys-man .man
./usr/share/man/man4/tuner.4 man-obsolete obsolete
diff -r 82c221105639 -r b0bf7b6832e7 share/man/man4/Makefile
--- a/share/man/man4/Makefile Sun May 27 01:39:00 2018 +0000
+++ b/share/man/man4/Makefile Sun May 27 05:31:20 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.654 2018/05/20 14:08:33 thorpej Exp $
+# $NetBSD: Makefile,v 1.655 2018/05/27 05:31:20 thorpej Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -63,7 +63,7 @@
svwsata.4 swsensor.4 swwdog.4 sysmon.4 \
tap.4 tc.4 tcds.4 tcp.4 tcu.4 tdvfb.4 termios.4 tfb.4 thinkpad.4 \
ti.4 tl.4 tlp.4 tlphy.4 tpm.4 tprof.4 tr.4 tra.4 \
- trm.4 tty.4 tun.4 tqphy.4 twa.4 twe.4 txp.4 \
+ trm.4 tsllux.4 tty.4 tun.4 tqphy.4 twa.4 twe.4 txp.4 \
uark.4 ubsec.4 udp.4 uep.4 ug.4 uha.4 uk.4 ukphy.4 unix.4 userconf.4 \
vald.4 valz.4 veriexec.4 vga.4 vge.4 viaide.4 video.4 vioif.4 viomb.4 \
viornd.4 vioscsi.4 virt.4 \
diff -r 82c221105639 -r b0bf7b6832e7 share/man/man4/tsllux.4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/tsllux.4 Sun May 27 05:31:20 2018 +0000
@@ -0,0 +1,132 @@
+.\" $NetBSD: tsllux.4,v 1.1 2018/05/27 05:31:20 thorpej Exp $
+.\"
+.\" Copyright (c) 2018 Jason R Thorpe
+.\" 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 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.
+.\"
+.Dd May 21, 2018
+.Dt TSLLUX 4
+.Os
+.Sh NAME
+.Nm tsllux
+.Nd Taos TSL256x Light-to-Digital Coverter
+.Sh SYNOPSIS
+.Cd "tsllux* at iic? addr 0x29 flags 0x0"
+.Cd "tsllux* at iic? addr 0x39 flags 0x0"
+.Cd "tsllux* at iic? addr 0x49 flags 0x0"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for the
+.Tn Taos
+TSL2560 and TSL2561 light-to-digital converter
+.Pq ambient light sensor
+with the
+.Xr envsys 4
+API.
+.Pp
+The TSL2560 is designed to work with SMBus at 100 kHz.
+The TSL2561 is designed to work with I2C Fast-Mode at 400 kHz.
+The sensors come in a variety of packages, including 6-lead Chipscale
+.Pq CS ,
+6-lead TMB
+.Pq T ,
+dual flat no-lead
+.Pq FN ,
+and 6-lead ChipLED
+.Pq CL .
+The
+.Sq CS
+package requires a different set of coefficients for calculating
+the Lux value from the raw sensor data.
+This behavior is enabled by specifying the flag
+.Dv 0x1
+in the kernel configuration file or by using a
+.Xr sysctl 8
+variable; see below.
+.Pp
+The
+.Nm
+driver exports some
+.Xr sysctl 8
+variables to control the behavior of the sensor and driver:
+.Bl -tag -width "XX"
+.It hw.tsllux0.cs_package Pq boolean, read-write
+This variable indicates if the driver instance has been configured
+to use the coeffecients appropriate for the
+.Sq CS
+package variant.
+.It hw.tsllux0.auto_gain Pq boolean, read-write
+This variable indicates if the driver has been configured to use
+an auto-gain algorithm to improve sensitivity of the sensor while
+taking care to avoid sensor saturation.
+Auto-gain is disabled by default.
+.It hw.tsllux0.gain Pq integer, read-write
+This variable indicates the selected sensor gain.
+If auto-gain is enabled, this will reflect the current gain setting
+selected by the auto-gain algorithm.
+Otherwise, it reflects the previously-configured gain.
+Valid values are
+.Dv 1
+and
+.Dv 16 .
+The default gain is
+.Dv 1 .
+Writing to this variable implicitly disables auto-gain.
+.It hw.tsllux0.integration_time Pq integer, read-write
+This variable indicates the selected analog-to-digital converter
+integration time.
+Longer integration times correspond to more accurate readings, at the
+cost more costly read operation.
+Valid values are
+.Dv 13 Pq 13.7ms ,
+.Dv 101 Pq 101ms ,
+and
+.Dv 402 Pq 402ms .
+The default value is
+.Dv 101 .
+Note that that due to the granularity of sleep timing in the kernel,
+the
+.Nm
+driver will busy-wait for wait times less than 1 Hz, and add an additional
+sleep clock tick for wait times greater than 1 Hz.
+See
+.Xr hz 9 .
+.El
+.Sh SEE ALSO
+.Xr envsys 4 ,
+.Xr iic 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 9.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Jason R Thorpe Aq Mt thorpej%netbsd.org@localhost
+.Sh BUGS
+The driver does not currently support the sensor's interrupt features
+or the sensor's manual integration timing feature.
diff -r 82c221105639 -r b0bf7b6832e7 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c Sun May 27 01:39:00 2018 +0000
+++ b/sys/dev/i2c/files.i2c Sun May 27 05:31:20 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.i2c,v 1.91 2018/05/05 02:01:34 jmcneill Exp $
+# $NetBSD: files.i2c,v 1.92 2018/05/27 05:31:20 thorpej Exp $
obsolete defflag opt_i2cbus.h I2C_SCAN
define i2cbus { }
@@ -334,3 +334,8 @@
device imt: hid, hidmt, wsmousedev
attach imt at ihidbus
file dev/i2c/imt.c imt
+
+# Taos TSL256x ambient light sensor
+device tsllux: sysmon_envsys
+attach tsllux at iic
+file dev/i2c/tsl256x.c tsllux
diff -r 82c221105639 -r b0bf7b6832e7 sys/dev/i2c/tsl256x.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/tsl256x.c Sun May 27 05:31:20 2018 +0000
@@ -0,0 +1,1062 @@
+/* $NetBSD: tsl256x.c,v 1.1 2018/05/27 05:31:20 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2018 Jason R. Thorpe
+ * 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 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tsl256x.c,v 1.1 2018/05/27 05:31:20 thorpej Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/tsl256xreg.h>
+
+#include <dev/sysmon/sysmonvar.h>
+
+struct tsllux_softc {
+ device_t sc_dev;
+ i2c_tag_t sc_i2c;
+ i2c_addr_t sc_addr;
+ int sc_i2c_flags;
+
+ uint32_t sc_poweron;
+
+ /*
+ * Locking order is:
+ * tsllux mutex -> i2c bus
+ */
+ kmutex_t sc_lock;
+
+ uint8_t sc_itime;
+ uint8_t sc_gain;
+ bool sc_cs_package;
+ bool sc_auto_gain;
+
+ struct sysmon_envsys *sc_sme;
+ envsys_data_t sc_sensor;
+
+ struct sysctllog *sc_sysctllog;
+};
+
+#define TSLLUX_F_CS_PACKAGE 0x01
+
+static int tsllux_match(device_t, cfdata_t, void *);
+static void tsllux_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(tsllux, sizeof(struct tsllux_softc),
+ tsllux_match, tsllux_attach, NULL, NULL);
+
+static const char *tsllux_compats[] = {
+ "taos,tsl2560",
+ "taos,tsl2561",
+ "taos,tsl256x",
+ NULL
+};
+
+static int tsllux_read1(struct tsllux_softc *, uint8_t, uint8_t *);
+static int tsllux_read2(struct tsllux_softc *, uint8_t, uint16_t *);
+static int tsllux_write1(struct tsllux_softc *, uint8_t, uint8_t);
+#if 0
Home |
Main Index |
Thread Index |
Old Index