Commit Graph

27 Commits

Author SHA1 Message Date
Maureen Helm a9b223b26b drivers: sensor: Refactor drivers to use SENSOR_DEVICE_DT_INST_DEFINE
Refactors all sensor drivers to use SENSOR_DEVICE_DT_INST_DEFINE, which
is a sensor-specific variant of DEVICE_DT_INST_DEFINE that provides a
common place to instantiate additional data structures for the future
sensor subsystem and/or sensor driver stats.

This approach was inspired by I2C_DEVICE_DT_INST_DEFINE to streamline
adding I2C stats support across all I2C drivers.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2022-10-27 09:27:14 +00:00
Kumar Gala df81fef944 drivers: sensor: Convert Kconfig bus 'depends on' to 'select'
This change in pattern is meant to address a misconfiguration issue
that can occur for sensors that support being on multiple busses
like I2C & SPI.

For example, you can have a configuration in which such a sensor is
on the I2C bus in the devicetree and the sensor is enabled.  However
the application configuration enables CONFIG_SPI=y and CONFIG_I2C=n
and this will cause the sensor driver to be built by default, however
since we don't have the I2C bus enabled the driver will not compile
correctly.

Previously we had been adding to board Kconfig.defconfig something
like:

	config I2C
		default y if SENSOR

This pattern doesn't scale well and may differ from what an application
specific need/use is.

So instead move to a pattern in which we leave the default enablement
up to the devicetree "status" property for the sensor.  We then have
the Kconfig move from 'depends on <BUS>' to 'select <BUS>' and in
the case of drivers that support multiple busses we have the Kconfig
be: 'select <BUS> if $(dt_compat_on_bus,$(<DT_COMPAT>),<BUS>) for
each bus type the sensor supports.

This removes the need to add Kconfig logic to each board and enables
the bus subsystem and bus controller driver if the sensor requires
it by default in the build system.

Fixes: #48518

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-08-08 06:58:18 +01:00
Kumar Gala f0441fba58 drivers: sensor: Update drivers to use devicetree Kconfig symbol
Update sensor drivers to use DT_HAS_<compat>_ENABLED Kconfig symbol
to expose the driver and enable it by default based on devicetree.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-22 02:20:18 -05:00
Anas Nashif 49b36ead95 drivers: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Armando Visconti dabaaa1e5d drivers/sensor: stmemsc: make use of spi_dt_spec and i2c_dt_spec
Make use of the new DT facilities that introduced two new
bus structures, spi_dt_spec and i2c_dt_spec, as well as the
macros, SPI_DT_SPEC_INST_GET and I2C_DT_SPEC_INST_GET, to
retrieve info from DT.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-10-22 09:06:07 -05:00
Martí Bolívar bd8afe9365 drivers: sensor: clean up zephyr_library calls
In drivers/sensor/CMakeLists.txt, we have various lines like this:

    add_subdirectory_ifdef(CONFIG_FOO foo)

Then drivers/sensor/foo/CMakeLists.txt says:

    zephyr_library()
    zephyr_library_sources_ifdef(CONFIG_FOO foo.c)

This is redundant; the foo/CMakeLists.txt won't be added to the build
system unless CONFIG_FOO=y in the first place, so there's no need for
extra boilerplate testing it again.

Remove all these unnecessary instances in each sensor driver's
CMakeLists.txt using this pattern:

    zephyr_library()
    zephyr_library_sources(foo.c)

In a couple of places, the '.c' extension is missing. Add them in for
consistency when that happens.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-06-30 09:36:33 -04:00
Kumar Gala 28e4af6176 drivers: sensor: iis2iclx: Fix compile warning
Fix compile warning with clang and extraneous parentheses

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-06-21 10:08:24 -05:00
Armando Visconti 468c553190 drivers/sensor: iis2iclx: (FIX) enable interrupt selectively
(same considerations as commit 2f01479b)
In a multi-instance driver it may happen that on some h/w
one device should use interrupts and a second device should use
polling mode. So, CONFIG_IIS2ICLX_TRIGGER is not enough to discriminmate
if interrupt inizialization routine should be called or not; the choice
is now based whether the "irq-gpios" property is present in the DT
for that particular instance or not.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-05-20 17:55:08 -04:00
Armando Visconti b430b8d6a6 drivers/sensor: iis2iclx: Fix shub for multi-instance case
In case of multi-instance the driver tries to discover whether
there are devices attached to SDx/SCx sensorhub bus. If not it
just turns the shub_inited variable (inside data structure) to false
and skips doing any further sensorhub related action for that
particular IIS2ICLX device instance, regardless the fact that the
macro CONFIG_IIS2ICLC_SENSORHUB is enabled.

Moreover, the info found during the enumeration process for a
particular instance (number and types of attached devices) must be
saved inside the per-instance data structure, so that more than one
IIS2ICLX device can be used as a sensorhub without interfering with
the others.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-05-18 11:18:08 -05:00
Armando Visconti 99308c514a drivers/sensor: iis2iclx: clean unused leftovers
Remove few unused declarations.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-05-07 20:53:47 -04:00
Gerard Marull-Paretas bf7a396538 drivers: sensor: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 15:30:03 -04:00
Gerard Marull-Paretas b735f5eb15 drivers: sensor: iis2iclx: use GPIO_DT_SPEC_INST_GET
Replace GPIO_DT_SPEC_GET for GPIO_DT_SPEC_INST_GET.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 18:17:23 +02:00
Armando Visconti 8717654c1d drivers/sensor: iis2iclx: move ctx structure inside config
Move ctx structure from struct data to struct config, so that
it can be filled at compile time and we could get rid of the bus
init routines.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-21 20:41:46 -04:00
Armando Visconti 6fa0d01c5f drivers/sensor: iis2iclx: Use DT helper for gpio_drdy
Use gpio_dt_spec structure and populate it using GPIO_DT_SPEC_GET
macro.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-21 20:41:46 -04:00
Armando Visconti 8b7a1a78c0 drivers/sensor: iis2iclx: Fix sensorhub building
The iis2iclx driver was not building correctly when
CONFIG_IIS2ICLX_SENSORHUB was enabled.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-01 15:34:36 -05:00
Armando Visconti aae2161542 drivers/sensor: iis2iclx: avoid using both ctx_i2c and ctx_spi
The STMEMSC HAL i/f requires every driver using it to define
for each instance a stmdev_ctx_t structure, which is used to
export the hardware specific APIs to handle i2c and spi busses
operations. Since this structure is bus agnostic, there is no
need to declare it twice for both i2c and spi. Instead, declare
only one structure, which will be populated either with i2c APIs
or with spi APIs according to where that particular instance is
declared inside the DT.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-01 15:34:36 -05:00
Armando Visconti 9e50268c96 drivers/sensor: iis2iclx: Make use of stmemsc common routines
Make use of the stmemsc i2c/spi read/write routine that
has been introduced to simplify the ST sensor drivers code.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-01 15:34:36 -05:00
Armando Visconti de707b6870 drivers/sensor: iis2iclx: fix multi-instance using new helpers
This commit simplifies the Device Tree configuration by using
the new helpers introduced in #30536.

In particular:
    - get bus devices with DEVICE_DT_GET
    - get SPI information with SPI_CONFIG_DT_INST

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-03-10 06:11:45 -05:00
James Harris b10428163a kernel: sem: add K_SEM_MAX_LIMIT
Currently there is no way to distinguish between a caller
explicitly asking for a semaphore with a limit that
happens to be `UINT_MAX` and a semaphore that just
has a limit "as large as possible".

Add `K_SEM_MAX_LIMIT`, currently defined to `UINT_MAX`, and akin
to `K_FOREVER` versus just passing some very large wait time.

In addition, the `k_sem_*` APIs were type-confused, where
the internal data structure was `uint32_t`, but the APIs took
and returned `unsigned int`. This changes the underlying data
structure to also use `unsigned int`, as changing the APIs
would be a (potentially) breaking change.

These changes are backwards-compatible, but it is strongly suggested
to take a quick scan for `k_sem_init` and `K_SEM_DEFINE` calls with
`UINT_MAX` (or `UINT32_MAX`) and replace them with `K_SEM_MAX_LIMIT`
where appropriate.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-05 08:13:53 -06:00
Armando Visconti 69269c52e8 drivers/sensor: iis2iclx: Move odr Kconfig property into dts
Move iis2iclx odr options from Kconfigs to Device Tree.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-02-15 07:58:36 -05:00
Armando Visconti 5ebada58a7 drivers/sensor: iis2iclx: Move range Kconfig property into dts
Converts iis2iclx range options (500mg, 1g, 2g, 3g) from Kconfigs
to Device Tree.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-02-15 07:58:36 -05:00
Armando Visconti 4141705ad3 drivers/sensor: Fix typos in iis2dlpc/iis2iclx/lsm6dso
The ',' character was used as line terminator instead of ';'
in SPI routines. The three affected drivers were not showing
any issue, but the typo is fixed for clarity.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-01-28 13:56:42 -05:00
Kumar Gala 5f605fd5ab drivers: sensor: Convert drivers to new DT device macros
Convert sensor drivers from:

    DEVICE_AND_API_INIT -> DEVICE_DT_INST_DEFINE
    DEVICE_GET -> DEVICE_DT_INST_GET
    DEVICE_DECLARE -> DEVICE_DT_INST_DECLARE

etc..

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-16 12:19:32 -05: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
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