Commit Graph

829 Commits

Author SHA1 Message Date
Gaspard Rigolot 2e024f5ed9 drivers: sensor: dps310 fix pressure and temperature registers
The two registers were inverted.

Signed-off-by: Gaspard Rigolot <gaspard.rigolot@stimio.fr>
2020-12-10 08:59:32 -06:00
Anas Nashif dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Kumar Gala 06a5946266 drivers: Convert to use new DEVICE_DT_INST_* macros
Move users that are DEVICE_DT_DECLARE(DT_DRV_INST(n, ...)) to
DEVICE_DT_INST_DECLARE(n, ...) and similar for DEVICE_DT_DEFINE.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-09 14:06:48 -06:00
Tomasz Bursztyka 8d694d11b6 drivers/sensor: Fix device attribute names for lis2mdl and fxos8700
Found it via running coccinelle script found in:
af6140cc0d
and 98d9b01322

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-12-03 09:42:26 -05:00
Tomasz Bursztyka e2847552fc drivers/sensor: Fix constant qualifier for lis2mdl PM function
Found it via running coccinelle script in:
e18fcbba5a

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-12-03 09:42:26 -05:00
Yuval Peress beaf0230ba drivers: sensors: bmi160: Fix issue with sample read
When testing the bmi160 I've come across an issue where the readings
didn't make sense to me. The issue comes from reading the
BMI160_SAMPLE_BURST_READ_ADDR which is 0x0C assuming both accelerometer
and gyroscope. At this point we would normally read 12 bytes
(2 bytes per sample * 3 axes * 2 sensors). This reading takes place in
bmi160_sample_fetch and begins writing to data->sample.raw

Without this change, the first byte written is actually to the dummy
byte which effectively gets tossed. The issue is that this is the
GYR_X<7:0>(LSB) according to the BMI160 data sheet. When we later call
either bmi160_gyr_channel_get or bmi160_acc_channel_get we're looking
at sample.gyr and sample.acc (which is effectively shiften by 1 byte).

This change gets rid of the dummy byte which re-alignes gyr with the
start of the raw buffer.

Signed-off-by: Yuval Peress <peress@chromium.org>
2020-12-01 17:58:06 -05:00
Peter Bigot f3db8f5acc drivers: sensor: ccs811: convert to dt device defines
Use the devicetree node as the source of object name and other
information used when defining the device structure.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-01 15:19:22 -05:00
Maureen Helm 18d7058ac8 drivers: sensor: Rework fxos8700 driver to use DT_INST_FOREACH
Reworks the fxos8700 sensor driver to use DT_INST_FOREACH_STATUS_OKAY.
This allows it to support multiple instances, however only a single
instance was tested with the frdm_k64f board.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Maureen Helm e015561c44 drivers: sensor: Fix fxos8700 device driver_api/data attributes
Fixes the fxos8700 sensor driver to reflect recent changes in the
generic device driver structure, renaming driver_data and config_info to
data and config respectively. These instances in the fxos8700 sensor
driver were missed because we haven't enabled the magnetic vector
magnitude function in CI.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Maureen Helm 84cc60e53c drivers: sensor: Convert fxos8700 vector mag Kconfigs to dts properties
Converts fxos8700 magnetic vector magnitude options from Kconfigs to
optional device tree properties.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Maureen Helm cb98e9aa11 drivers: sensor: Convert fxos8700 power mode Kconfigs to dts property
Converts fxos8700 power mode options (normal, low noise low power, high
resolution, low power) from Kconfigs to an optional device tree
property.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Maureen Helm 6199de14c4 drivers: sensor: Convert fxos8700 range Kconfigs to dts property
Converts fxos8700 range options (2g, 4g, 8g mode) from Kconfigs to an
optional device tree property.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Maureen Helm d4b9d197f3 drivers: sensor: Convert fxos8700 pulse Kconfigs to dts properties
Converts fxos8700 pulse detection options from Kconfigs to optional
device tree properties.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-11-17 16:51:50 -05:00
Peter Bigot ab9f7497ba shell: shell: select FP formatting support
This module needs to format floating point values in shell print
statements, which requires FP format support.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-17 14:44:59 -06:00
Armando Visconti 46b12406de drivers/sensor: lis2dh: Fix multi-instance leftovers
Introduced two per instance booleans, which get set using DT info:

  1. is_lsm303agr_dev: if the device is a LSM303AGR_ACCEL, then
     the scale values have to be changed.

  2. Handle disconnect-sdo-sa0-pull-up if present in ntsnace DT.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-11-17 14:44:18 -06:00
Armando Visconti d962e3590f drivers/sensor: lis2dh: Fix interrupt handling for multi instance
Handle interrupts correctly for multi instance, checking per
device DT bindings instead of global Kconfig definitions.

The old interrupt behaviour has been maintained, fixing DRDY to
be on INT1 and Any Motion event on INT2.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-11-17 14:44:18 -06:00
Armando Visconti c380142920 drivers/sensor: iis2iclx: add multi-instance
Make this driver multi-instance and use the new API.

Notes for sensorhub mode:
In case of multiples devices it is possible that some of them
has i2c slaves attached to it (sensorhub mode) but not the
others. Since the driver is configured in the same way for
all the instances (CONFIG_SENSORHUB=y), the routine that initialize
the sensorhub part does not fail anymore in case no slaves
are found for a particular instance. Instead, those non-sensorhub
driver instances will set the shub_inited flag to false and
will totally ignore the feature.

Notes for triggers:
In case of multiples devices the device pin the interrupt wire is
attached to can be different (INT1 or INT2 pin). So, this
information has been moved in DTS and then stored in the
specific instance config structure.
Currently the driver is able to handle a sngle interrupt line
at a time attached to either INT1 or INT2.
MOreover, the interrupt initialization for a driver instance proceed
only if the drdy has been configured in its DT, else it returns ok.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-11-11 13:17:18 +01:00
Yurii Gubin f700d74884 drivers: sensor: lsm6dsl: fixed irq_pin for interrupt handling
Obtaining irq_pin from dev leads to disabling interrupts
on unpredictable pin, as dev points to GPIO, not LSM6DSL.

Fixes #29721

Signed-off-by: Yurii Gubin <y.gubin@gmail.com>
2020-11-06 12:48:33 -06:00
Kumar Gala b4a3880a75 drivers: remove unnecessary use of DEVICE_AND_API_INIT
For drivers that support CONFIG_DEVICE_POWER_MANAGEMENT there are some
cases that look like:

  #ifdef CONFIG_DEVICE_POWER_MANAGEMENT
    DEVICE_DEFINE()
  #else
    DEVICE_AND_API_INIT()
  #endif

There is no need to special case this as the pm_control_fn argument to
DEVICE_DEFINE will just be ignored in the
!CONFIG_DEVICE_POWER_MANAGEMENT case.  So we can cleanup the code a
little and remove the #else cases for the drivers that do this.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-11-06 09:42:47 -06:00
Armando Visconti 667db2db88 drivers/sensor: lsm6dsl: Fix build when irq_gpios is not in DT
In case of h/w setup with multiples device instances it is possible
that some of them wants to use triggers but not the others (no
interrupt line.

Since Kconfig configuration is the same way for all the instances
(CONFIG_LSM6DSL_TRIGGER=y), the driver behaves differently according
to how the device instance has been configured in the DT.
If irq-gpios is present, then the driver initialize the interrupt
part, else it skip irq init and returns ok, but data->gpio != NULL
xis checked in trigger_set() API.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-11-02 10:00:07 -06:00
Stephane D'Alu 61b0009bdf sensor_shell: added missing sensor channel.
Synchronized with list of channel defined in sensor.h

Signed-off-by: Stephane D'Alu <sdalu@sdalu.com>
2020-11-02 09:52:54 -06:00
Simon Glass 0b1a7d109d drivers: sensor: bmi160: Add support for I2C
At present this driver only supports SPI. Add support for I2C as well,
following the model of BME280.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 0de655e371 drivers: sensor: bmi160: Prepare to support I2C
At present this driver only supports SPI. Refactor it so that SPI is
just one of the options. This does not change any functionality.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 1f1f695ae2 drivers: sensor: bmi160: Rename 'spi' to 'bus'
This member holds the SPI bus pointer. Change its name to make that
more obvious and so that it can be used for an I2C bus also.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 28f8ddae0b drivers: sensor: bmi160: Use only one read/write function
At present there are three separate read functions and two write
functions. This makes it harder to provide an interface that can work
with either SPI or I2C.

Use bmi160_read() for all reads and create a new bmi160_write()
function for all writes.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 226cacbc3d drivers: sensor: bmi160: Move SPI config to config
At present this driver only supports a single instance. It sets up some
of its config in the init routine. It is better to put config in
constant data so that multiple instances can be supported and RAM space
is minimised.

Update the driver accordingly.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass 57fdcd4018 drivers: sensor: bmi160: Use 'data' for the data pointer
Currently a 'bmi160' pointer is used to point to the driver data. This
confusing, as the driver uses both data and config. Rename the variable
to 'data' like the bme280 driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass a32f87b1e0 drivers: sensor: bmi160: Define accessors for the bmi160
Add inline functions to obtain the data and configuration.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Simon Glass c3823b9144 drivers: sensor: bmi160: Shorten the structs a bit
This driver uses verbose names for the config and data structures, which
makes it harder to see which one we are talking about. Shorten it, like
the bme280 driver.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-27 16:41:30 +01:00
Philémon Jaermann cbed8815a2 drivers: sensor: Use macro parameter to dereference device
The TACH_XEC_DATA macro was not using its parameter
to retrieve the data structure.
It was working by chance so far.

Signed-off-by: Philémon Jaermann <p.jaermann@gmail.com>
2020-10-21 08:29:36 -04:00
Armando Visconti 1921a2d84e drivers/sensor: add support to IIS2ICLX accelerometer
The IIS2ICLX is a high-accuracy. ultra-low noise, low-power
two-axis linear accelerometer which can be interfaced through
either I2C or SPI bus.
Its high accuracy, stability over temperature and repeatability
make IIS2ICLX particularly suitable for inclination measurement
for industrial applications (inclinometers).

https://www.st.com/resource/en/datasheet/iis2iclx.pdf

This driver is based on stmemsc i/f v1.03.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-10-15 09:57:47 -05:00
Armando Visconti de5135b05e modules/hal_st: Align sensor drivers to stmemsc HAL i/f v1.03
Align all sensor drivers that are using stmemsc (STdC) HAL i/f
to new APIs of stmemsc v1.03.

Requires https://github.com/zephyrproject-rtos/hal_st/pull/5
(merged as b52fdbf4b62439be9fab9bb4bae9690a42d2fb14)

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-10-13 09:46:08 -05:00
Armando Visconti 4250028483 drivers/sensor: iis2mdc: Fix the temperature in celsius
Fix the formula to translate raw temperature read from
register to Celsius.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-10-13 09:46:08 -05:00
Armando Visconti 99b97f5ff4 drivers/sensor: ism330dhcx: Fix init routines order
The interrupt enabling routine was called before the
chip enabling routine resulting in a runtime failure
when triggers are set.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-10-13 09:46:08 -05:00
Simon Glass 442f38d610 emul: Add an emulator for the Bosch BMI160 accelerometer
This emulator supports enable functionality to start up the device and
read a few samples. It connects itself to any BMI160 device it finds in
the device tree. The SPI emulation controller driver is used to direct
SPI messages from the BMI160 driver to the BMI160 emulator.

Add a few more definitions to the header file, as needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Simon Glass 5a9f389159 drivers: sensor: bmi160: Use more constants for reg access
At present register access is a mix of constants and open-coded values
in the driver. Add a few more constants to clean this up.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Simon Glass 2c73f3ed4c drivers: sensor: bmi160: Add a constant for number of axes
Define a constant instead of using an open-coded value.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Simon Glass e944855bbc drivers: sensor: bmi160: Move the ready bit into the header
This should be accessible to all files that need register access. Move
it into the header.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-10-05 15:33:00 -04:00
Emil Hammarstrom 7743b1e553 drivers: sensor: lis2mdl: Add device power management
The power draw of this magnetometer is significant,
device power management is needed for our use-cases.

Signed-off-by: Emil Hammarstrom <emil.hammarstrom@assaabloy.com>
Change-Id: I71158e629e93b491c6d673aa81001b7a7099f654
2020-10-02 11:32:59 +02:00
Armando Visconti fe6a73669d drivers: sensor: hts221: Add checks for drdy_gpios macros
To avoid build errors enable the trigger only if DRDY gpio is
defined in DTS. Fix #28443

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-09-24 09:51:08 -05:00
Armando Visconti 4df0d019fd drivers/sensor/lsm6dsl: Fix read/write bus API in shub code
The ce0cc3a7 commit (lsm6dsl: make the driver multi-instance) changes
all bus API signature, which now requires a "const struct device *dev"
and not a "struct lsm6dsl_data *data". By mistake the shub part was
left unchanged. Fix: #28565

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-09-23 13:17:06 -05:00
Armando Visconti ce0cc3a7cc drivers: sensor: lsm6dsl: make the driver multi-instance
Make this driver multi-instance and use the new API.
Fixes #28390

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-09-18 22:08:44 -04:00
Erwan Gouriou 8b47e563e2 dts/Kconfig: Remove HAS_DTS_I2C
HAS_DTS_I2C is now selected by I2C and
always used as I2C && HAS_DTS_I2C.

It could then be purely removed.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-09-18 13:34:44 -05:00
Armando Visconti 4ea9a8bd95 drivers: sensor: lis2dh: make the driver multi-instance
Make this driver multi-instance and use the new API.
Fixes #27753.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2020-09-14 13:28:45 -05:00
Richard Osterloh 0a0026afe2 drivers: sensor: Add VCNL4040 driver
Add support for Vishay VCNL4040 proximity and light sensor

Signed-off-by: Richard Osterloh <richard.osterloh@gmail.com>
2020-09-04 13:03:12 -05:00
Tomasz Bursztyka d00d86972a drivers: sensor: Fix device instance const qualifier loss
It is necessary to wrap the device pointer into data.
Which was done already on most of them when global trigger is enabled.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Flavio Ceolin 0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Jamie McCrae 4cf1832fa8 drivers: sensors: sm351lt: Add new driver
Adds sm351lt magnetoresitive sensor driver.

Signed-off-by: Jamie McCrae <jamie.mccrae@lairdconnect.com>
2020-08-24 16:48:47 -05:00
Matija Tudan efae88ce3a sensor: fxos8700: implement magnetic vector magnitude function
The magnetometer vector-magnitude function will generate an interrupt
when magnitude is greater than specified threshold value. The user
may program the threshold value to establish the conditions needed
to detect a magnetic vector-magnitude change event. Depending on the
values chosen for the reference values, this function may be
configured to detect a magnetic field magnitude that is above
a preset threshold (with reference values = 0), or a change in magnitude
between two magnetic vectors greater than the preset threshold
(with reference values non-zero).

Default configuration of M_VECM_CFG register (address 0x69) is 0x4e.

Signed-off-by: Matija Tudan <mtudan@mobilisis.hr>
2020-08-21 12:30:50 -05:00