Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/i2c Rename tsl256x.c -> tsllux.c. No other changes ...
details: https://anonhg.NetBSD.org/src/rev/983c48c03d93
branches: trunk
changeset: 979660:983c48c03d93
user: thorpej <thorpej%NetBSD.org@localhost>
date: Mon Jan 04 22:09:35 2021 +0000
description:
Rename tsl256x.c -> tsllux.c. No other changes are made by this commit.
diffstat:
sys/dev/i2c/files.i2c | 4 +-
sys/dev/i2c/tsl256x.c | 1049 -------------------------------------------------
sys/dev/i2c/tsllux.c | 1049 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 1051 insertions(+), 1051 deletions(-)
diffs (truncated from 2124 to 300 lines):
diff -r 37c1c8932c88 -r 983c48c03d93 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c Mon Jan 04 21:59:48 2021 +0000
+++ b/sys/dev/i2c/files.i2c Mon Jan 04 22:09:35 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.i2c,v 1.114 2020/12/29 01:47:51 thorpej Exp $
+# $NetBSD: files.i2c,v 1.115 2021/01/04 22:09:35 thorpej Exp $
obsolete defflag opt_i2cbus.h I2C_SCAN
define i2cbus { }
@@ -342,7 +342,7 @@
# Taos TSL256x ambient light sensor
device tsllux: sysmon_envsys
attach tsllux at iic
-file dev/i2c/tsl256x.c tsllux
+file dev/i2c/tsllux.c tsllux
# Philips/NXP TEA5767
device tea5767radio : radiodev
diff -r 37c1c8932c88 -r 983c48c03d93 sys/dev/i2c/tsl256x.c
--- a/sys/dev/i2c/tsl256x.c Mon Jan 04 21:59:48 2021 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1049 +0,0 @@
-/* $NetBSD: tsl256x.c,v 1.9 2021/01/04 21:59:48 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.9 2021/01/04 21:59:48 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;
-
- 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 struct device_compatible_entry tsllux_compat_data[] = {
- { "amstaos,tsl2560", 0 },
- { "amstaos,tsl2561", 0 },
- { NULL, 0 }
-};
-
-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
-static int tsllux_write2(struct tsllux_softc *, uint8_t, uint16_t);
-#endif
-
-static void tsllux_sysctl_attach(struct tsllux_softc *);
-
-static int tsllux_poweron(struct tsllux_softc *);
-static int tsllux_poweroff(struct tsllux_softc *);
-
-static int tsllux_set_integration_time(struct tsllux_softc *, uint8_t);
-static int tsllux_set_gain(struct tsllux_softc *, uint8_t);
-static int tsllux_set_autogain(struct tsllux_softc *, bool);
-
-static int tsllux_get_lux(struct tsllux_softc *, uint32_t *,
- uint16_t *, uint16_t *);
-
-static void tsllux_sensors_refresh(struct sysmon_envsys *, envsys_data_t *);
-
-static int
-tsllux_match(device_t parent, cfdata_t match, void *aux)
-{
- struct i2c_attach_args *ia = aux;
- uint8_t id_reg;
- int error, match_result;
-
- if (iic_use_direct_match(ia, match, tsllux_compat_data, &match_result))
- return (match_result);
-
- switch (ia->ia_addr) {
- case TSL256x_SLAVEADDR_GND:
- case TSL256x_SLAVEADDR_FLOAT:
- case TSL256x_SLAVEADDR_VDD:
- break;
-
- default:
- return (0);
- }
-
- if (iic_acquire_bus(ia->ia_tag, 0) != 0)
- return (0);
- error = iic_smbus_read_byte(ia->ia_tag, ia->ia_addr,
- TSL256x_REG_ID | COMMAND6x_CMD, &id_reg, 0);
- iic_release_bus(ia->ia_tag, 0);
-
- if (error)
- return (0);
-
- /* XXX This loses if we have a 2560 rev. 0. */
- if (id_reg == 0)
- return (I2C_MATCH_ADDRESS_ONLY);
-
- return (I2C_MATCH_ADDRESS_AND_PROBE);
-}
-
-static void
-tsllux_attach(device_t parent, device_t self, void *aux)
-{
- struct tsllux_softc *sc = device_private(self);
- struct i2c_attach_args *ia = aux;
- bool have_i2c;
-
- /* XXX IPL_NONE changes when we support threshold interrupts. */
- mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
-
- sc->sc_dev = self;
- sc->sc_i2c = ia->ia_tag;
- sc->sc_addr = ia->ia_addr;
-
- if (self->dv_cfdata != NULL &&
- self->dv_cfdata->cf_flags & TSLLUX_F_CS_PACKAGE)
- sc->sc_cs_package = true;
-
- if (iic_acquire_bus(ia->ia_tag, 0) != 0) {
- return;
- }
-
- have_i2c = true;
-
- /* Power on the device and clear any pending interrupts. */
- if (tsllux_write1(sc, TSL256x_REG_CONTROL | COMMAND6x_CLEAR,
- CONTROL6x_POWER_ON)) {
- aprint_error_dev(self, ": unable to power on device\n");
- goto out;
- }
- sc->sc_poweron = 1;
-
- /* Make sure interrupts are disabled. */
- if (tsllux_write1(sc, TSL256x_REG_INTERRUPT | COMMAND6x_CLEAR, 0)) {
- aprint_error_dev(self, ": unable to disable interrupts\n");
- goto out;
- }
-
- aprint_naive("\n");
- aprint_normal(": TSL256x Light-to-Digital converter%s\n",
- sc->sc_cs_package ? " (CS package)" : "");
-
- /* Inititalize timing to reasonable defaults. */
- sc->sc_auto_gain = true;
- sc->sc_gain = TIMING6x_GAIN_16X;
- if (tsllux_set_integration_time(sc, TIMING6x_INTEG_101ms)) {
- aprint_error_dev(self, ": unable to set integration time\n");
- goto out;
- }
-
- tsllux_poweroff(sc);
-
- iic_release_bus(ia->ia_tag, 0);
- have_i2c = false;
-
- tsllux_sysctl_attach(sc);
-
- sc->sc_sme = sysmon_envsys_create();
- sc->sc_sme->sme_name = device_xname(self);
- sc->sc_sme->sme_cookie = sc;
- sc->sc_sme->sme_refresh = tsllux_sensors_refresh;
-
- sc->sc_sensor.units = ENVSYS_LUX;
- sc->sc_sensor.state = ENVSYS_SINVALID;
- snprintf(sc->sc_sensor.desc, sizeof(sc->sc_sensor.desc),
- "ambient light");
- sysmon_envsys_sensor_attach(sc->sc_sme, &sc->sc_sensor);
-
- sysmon_envsys_register(sc->sc_sme);
-
- out:
- if (have_i2c) {
- if (sc->sc_poweron)
- tsllux_poweroff(sc);
- iic_release_bus(ia->ia_tag, 0);
- }
-}
-
-static int
-tsllux_sysctl_cs_package(SYSCTLFN_ARGS)
-{
- struct tsllux_softc *sc;
- struct sysctlnode node;
- int error;
- u_int val;
-
- node = *rnode;
- sc = node.sysctl_data;
-
- mutex_enter(&sc->sc_lock);
- val = sc->sc_cs_package ? 1 : 0;
- node.sysctl_data = &val;
- error = sysctl_lookup(SYSCTLFN_CALL(&node));
- if (error || newp == NULL) {
- mutex_exit(&sc->sc_lock);
- return (error);
- }
-
- /* CS package indicator is used only in software; no need for I2C. */
-
- sc->sc_cs_package = val ? true : false;
- mutex_exit(&sc->sc_lock);
-
- return (error);
-}
-
-static int
-tsllux_sysctl_autogain(SYSCTLFN_ARGS)
-{
- struct tsllux_softc *sc;
- struct sysctlnode node;
- int error;
- u_int val;
-
- node = *rnode;
- sc = node.sysctl_data;
-
- mutex_enter(&sc->sc_lock);
- val = sc->sc_auto_gain ? 1 : 0;
- node.sysctl_data = &val;
- error = sysctl_lookup(SYSCTLFN_CALL(&node));
- if (error || newp == NULL) {
- mutex_exit(&sc->sc_lock);
- return (error);
- }
-
- /* Auto-gain is a software feature; no need for I2C. */
-
- error = tsllux_set_autogain(sc, val ? true : false);
- mutex_exit(&sc->sc_lock);
-
- return (error);
-}
-
-static int
-tsllux_sysctl_gain(SYSCTLFN_ARGS)
Home |
Main Index |
Thread Index |
Old Index