Commit graph

261 commits

Author SHA1 Message Date
Peter Bigot 0f7acb1dc3 drivers: adc_mcp320x: respect devicetree cs-gpios flags
Forward flags cell from cs-gpios devicetree property into device SPI
configuration.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-07-09 06:07:07 -05:00
Peter Bigot 62e045f979 drivers: adc_lmp90xxx: respect devicetree cs-gpios flags
Forward flags cell from cs-gpios devicetree property into device SPI
configuration.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-07-09 06:07:07 -05:00
Marcin Niestroj fdeed32844 adc: adc_shell: suppress -Wchar-subscripts with isdigit()
Suppress -Wchar-subscripts warnings when building with Newlib, by
casting isdigit() parameter to unsigned char.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
2020-07-09 11:28:54 +02:00
Anas Nashif ee985d81aa shell: enable modules by default if shell is enabled
If shell is enabled then enable all sub-shells if their dependencies are
satisfied. This was done for some modules and subsystems but was not
consistent.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-24 21:37:12 -04:00
Henrik Brix Andersen 0cf9be32c9 drivers: adc: lmp90xxx: set thread name
Set the thread name for the data acquisition thread in the TI LMP90xxx
ADC driver to aid in debugging and profiling.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-06-09 10:54:21 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Martí Bolívar 6e8775ff84 devicetree: remove DT_HAS_NODE_STATUS_OKAY
Several reviewers agreed that DT_HAS_NODE_STATUS_OKAY(...) was an
undesirable API for the following reasons:

- it's inconsistent with the rest of the DT_NODE_HAS_FOO names
- DT_NODE_HAS_FOO_BAR_BAZ(node) was agreed upon as a shorthand
  for macros which are equivalent to
  DT_NODE_HAS_FOO(node) && DT_NODE_HAS_BAR(node) &&
- DT_NODE_HAS_BAZ(node), and DT_HAS_NODE_STATUS_OKAY is an odd duck
- DT_NODE_HAS_STATUS(..., okay) was viewed as more readable anyway
- it is seen as a somewhat aesthetically challenged name

Replace all users with DT_NODE_HAS_STATUS(..., okay), which is
semantically equivalent.

This is mostly done with sed, but a few remaining cases were done by
hand, along with whitespace, docs, and comment changes. These special
cases include the Nordic SOC static assert files.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:24:42 +02:00
Peter Bigot 4f16b419e8 device: avoid casting away const from config_info pointer
The driver-specific config_info structure referenced from the device
structure is marked const.  Some drivers fail to preserve that
qualifier when casting the pointer to the driver-specific structure,
violating MISRA 11.8.

Changes produced by scripts/coccinelle/const_config_info.cocci.

Some changes proposed by the script are not included because they
reveal mutation of state through the const pointer, though the
code works as long as the driver-specific object is defined without
the const qualifier.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-13 18:21:52 +02:00
Martí Bolívar 7e0eed9235 devicetree: allow access to all nodes
Usually, we want to operate only on "available" device
nodes ("available" means "status is okay and a matching binding is
found"), but that's not true in all cases.

Sometimes we want to operate on special nodes without matching
bindings, such as those describing memory.

To handle the distinction, change various additional devicetree APIs
making it clear that they operate only on available device nodes,
adjusting gen_defines and devicetree.h implementation details
accordingly:

- emit macros for all existing nodes in gen_defines.py, regardless
  of status or matching binding
- rename DT_NUM_INST to DT_NUM_INST_STATUS_OKAY
- rename DT_NODE_HAS_COMPAT to DT_NODE_HAS_COMPAT_STATUS_OKAY
- rename DT_INST_FOREACH to DT_INST_FOREACH_STATUS_OKAY
- rename DT_ANY_INST_ON_BUS to DT_ANY_INST_ON_BUS_STATUS_OKAY
- rewrite DT_HAS_NODE_STATUS_OKAY in terms of a new DT_NODE_HAS_STATUS
- resurrect DT_HAS_NODE in the form of DT_NODE_EXISTS
- remove DT_COMPAT_ON_BUS as a public API
- use the new default_prop_types edtlib parameter

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-08 19:37:18 -05:00
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00
Gerard Marull-Paretas cfebfc188e drivers: adc: stm32: add support for H7 series
Add support for ADC on H7 series. Note that ADC1 and ADC2 share the same
register set, so it is added as "adc1_2".

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2020-05-07 23:01:59 -05:00
Kumar Gala 0a7d4e2135 devicetree: Change DT_FOREACH_IMPL_ to not insert semicolon
Remove semicolon between instance invocations of DT_FOREACH_IMPL_ and
thus DT_INST_FOREACH.  This provides more flexibility to the user.  This
requires we fixup in tree users to add semicolon where needed.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-07 20:03:56 -05:00
Kumar Gala 99d14e9075 adc: adc_shell: Fix compile error
Had an extra comma between macro and macro usage that casued the
following compile error:

	adc_shell.c:477:22: error: expected expression before ',' token

Easy fix to remove trailing comma in ADC_SHELL_COMMAND

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-06 23:56:33 -05:00
Martí Bolívar 87e1743ae0 devicetree: replace DT_HAS_DRV_INST with DT_INST_FOREACH
Make drivers multi-instance wherever possible using DT_INST_FOREACH.
This allows removing DT_HAS_DRV_INST in favor of making drivers just
do the right thing regardless of how many instances there are.

There are a few exceptions:

- SoC drivers which use CMake input files (like i2c_dw.c) or otherwise
  would require more time to convert than I have at the moment. For the
  sake of expediency, just inline the DT_HAS_DRV_INST expansion for
  now in these cases.

- SoC drivers which are explicitly single-instance (like the nRF SAADC
  driver). Again for the sake of expediency, drop a BUILD_ASSERT in
  those cases to make sure the assumption that all supported SoCs have
  at most one available instance is valid, failing fast otherwise.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-06 17:35:08 -05:00
Kumar Gala 024ea0e44e adc: Kconfig: Remove per instance ADC_{0..2} Kconfig symbols
No code utilizes CONFIG_ADC_{0..2} so we can now remove the Kconfig
sybmols for them.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-04 09:04:16 -05:00
Kumar Gala 897652a536 adc: adc_shell: Rework device name extraction from devicetree
Replace having dts_fixup.h files define DT_ADC_{0..2}_NAME with using
the new devicetree.h macros.  We test to see what driver compat is
enabled via DT_HAS_COMPAT and set DT_DRV_COMPAT to that compat.  Than we
can utilize the DT_INST_LABEL() macro to extract the name of the device.

We also replace the Kconfig ADC_{0..2} symbols with DT_HAS_DRV_INST.
This will allow us to remove those Kconfig symbols as this was the only
usage.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-02 10:27:07 -05:00
Kumar Gala 8639469339 drivers: adc: adc_mcp320x: Rename defines to remove DT_ prefix
We want to limit DT_ prefix to macros from devicetree.h and generation.
So rename DT_INST_MCP320X* to just INST_DT_MCP320X*.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-30 04:45:35 -05:00
Kumar Gala a918d301fe drivers: adc: adc_sam0: rework devicetree support
Rework the devicetree to utilize new DT_INST macros and extract per
instance data for clocks from devicetree.

We add a property ('calib-offset') for the SAM{D,E}5x family of SoCs
that is the bit position offset from ADC0 BIASCOMP in the NVM Software
Calibration Area Mapping.  For ADC0 this is typically 0 and for ADC1
this will be 14.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-29 08:02:36 -05:00
Kumar Gala 94fcf2efa1 drivers: adc: adc_sam_afec: rework device tree support
Reworked adc_sam_afec driver to utilize new DT_INST macros as part of
this rework we also now get pin ctrl/mux configuration information
from the device tree instead of via Kconfig and defines in soc_pinmap.h

We remove defines from dts_fixup.h and soc_pinmap.h and associated
Kconfig symbols that are no longer needed due to getting all that
information from devicetree.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-23 06:11:26 -05:00
Kumar Gala b07596bcea drivers: adc: mcux_adc12: create macro for device instantiation
Create a ACD12_MCUX_INIT macro that we can use with DT_INST_FOREACH for
device instantiation.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:23:47 -05:00
Kumar Gala bc4d12f8c8 drivers: adc: mcux_adc16: Convert to DT_INST
Convert driver to use new DT_INST macros throughout.  We can remove
various defines from dts_fixup.h now as well.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-20 15:23:47 -05:00
Aurelien Jarno 7e7e79481f drivers: adc: adc_stm32: enable internal voltage reference source
Like other STM32 series the STM32L4x SoCs have an internal voltage
reference source that need to be enabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2020-04-17 17:30:44 +02:00
Henrik Brix Andersen 1985ddf236 drivers: adc: lmp90xxx: convert to use k_msleep() instead of k_sleep()
Convert the LMP90xxx ADC driver from using k_sleep() to using
k_msleep() in order to resolve a compilation error caused by passing
an int to k_sleep().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-04-15 13:34:18 +02:00
Martí Bolívar bbde37113f adc: nordic: move to new DT API and kconfig style
Use the new devicetree API. Remove per-board enabling of ADC_0 by
setting ADC_0 to default y when the 'adc' node label points at an
enabled node of the expected compatible (depending on SoC).

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-13 18:34:39 -04:00
Paolo Teti 51125b2890 drivers: adc: adc_shell: Kconfig ADC_SHELL must depends on SHELL
To avoid linking errors ADC_SHELL must depends on SHELL.

Signed-off-by: Paolo Teti <paolo.teti@gmail.com>
2020-04-12 12:02:46 -04:00
Martí Bolívar bbd6473136 drivers: remove a couple of DT abstraction violations
DT_CALL_WITH_ARG() is an internal implementation detail that should
not be used outside of devicetree.h.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-04-08 09:00:38 -05:00
Peter Bigot ecf3bdb5b3 coccinelle: re-run timeout conversion semantic patch
Run the int_literal_to_timeout Coccinelle script to fix places where
it is clear that an integer duration is being passed where a timeout
value is required.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-04-02 19:47:51 +03:00
Andy Ross 32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Oleg Zhurakivskyy b1e1f64d14 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-31 07:18:06 +02:00
Kumar Gala 6c2451c5c0 adc: adc_lmp90xxx: Remove DT_INST_0_* comments
We have a number of cases that now look like:
   #if DT_HAS_COMPAT(ti_lmp90077)
   LMP90XXX_DEVICE(90077, 0, 16, 4);
   #endif /* DT_INST_0_TI_LMP90077 */

The DT_INST_0_TI_LMP90077 comment is stale, and doesn't add much since
the #if associated with the #endif is just 2 lines up.  Removing the old
comments seems the best cleanup.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-28 17:25:26 -05:00
Henrik Brix Andersen 23957a8938 drivers: adc: lmp90xxx: convert to new DT API
Use the new devicetree.h API instead of the legacy macros.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen 3de3ad0ffc drivers: adc: lmp90xxx: prevent SPI transactions from ISR context
Add checks to prevent SPI transactions from being run in ISR
context. This affects both the LMP90xxx ADC and GPIO drivers.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen ee97ab2bd8 drivers: adc: lmp90xxx: validate ADC sequence channels mask
Validate the channels mask passed from adc_read().

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen 15be7a5723 drivers: adc: lmp90xxx: move calibration setup to acquisition thread
Move calibration setup SPI transaction to acquisition thread to allow
adc_read_async() to be called from ISR context.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen 64bed8add6 drivers: adc: lmp90xxx: make adc_context_start_sampling() ISR safe
Introduce a dedicated function for performing an entire LMP90xxx ADC
channel read and sample all channels in one go in the ADC acquisition
thread.

This removes the SPI transactions from adc_context_start_sampling()
which can be called in k_timer ISR context for consecutive ADC reads.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen 9909a46f1f drivers: adc: lmp90xxx: use common crc8 implementation
Use the common Zephyr CRC8 SW implementation instead of a
driver-specific implementation.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen fce6a8b853 drivers: adc: lmp90xxx: do not exit acquisition thread on error
Keep the acquisition thread running even if an ADC reading failed.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-28 10:22:23 -05:00
Henrik Brix Andersen 53615ab11b drivers: adc: add Microchip MCP320x driver
Add driver for the Microchip MCP3204/MCP3208 12 bit ADCs with SPI
interface.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-03-27 16:17:06 +01:00
Kumar Gala 7a81cd9747 drivers: microchip: Convert microchip drivers to new DT_INST macros
Convert older DT_INST_ macro use in microchip drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 16:31:52 -05:00
Kumar Gala 989484b4bf drivers: stm32: Convert STM32 drivers to new DT_INST macros
Convert older DT_INST_ macro use in STM32 drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 12:22:12 -05:00
Kumar Gala 4b9fe8a24e drivers: mcux: Convert MCUX drivers to new DT_INST macros
Convert older DT_INST_ macro use in MCUX drivers to the new
include/devicetree.h DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-26 03:40:09 -05:00
Carles Cufi 4b37a8f3a4 Revert "global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()"
This reverts commit 8739517107.

Pull Request #23437 was merged by mistake with an invalid manifest.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-19 18:45:13 +01:00
Oleg Zhurakivskyy 8739517107 global: Replace BUILD_ASSERT_MSG() with BUILD_ASSERT()
Replace all occurences of BUILD_ASSERT_MSG() with BUILD_ASSERT()
as a result of merging BUILD_ASSERT() and BUILD_ASSERT_MSG().

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2020-03-19 15:47:53 +01:00
Takumi Ando 8d106d198e drivers: adc: Add STM32L1X ADC support
Add ADC driver support for STM32L1X SoC series.

Signed-off-by: Takumi Ando <takumi@t15.red>
2020-03-19 03:10:39 -05:00
Erwan Gouriou 0c9b537edf drivers: adc: adc_stm32: convert to DT_INST defines
Convert driver to use DT_INST_ defines.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-03-17 11:03:10 -06:00
Daniel Leung c3701f51d7 adc: mchp_xec: right justify ADC output data under 10-bit res
This enables the ADC output data to be shifted right when using
10-bit resolution. Or else, data would be left justified as if
it's doing 12-bit ADC with the right 2 bits filled with zeroes.

Fixes #23202

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-03-06 19:29:09 +02:00
Carles Cufi f55fcc9fd2 boards: frdm_kw41z: Override ADC vref choice properly
In order to overrdie a choice one needs to define it again. Override it
by redefining it in the .defconfig file.

See #22474.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-02-14 22:12:21 +02:00
Henrik Brix Andersen e5f3279abb adc: common: handle gain of 128 in adc_gain_invert()
Add missing entry for ADC_GAIN_128 in the adc_gain_invert() function.

This fixes 4420c5ed40.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2020-02-05 14:28:09 -06:00
Erwan Gouriou 609f78b75c drivers/adc: stm32: Don't enable ADC instance by default in driver
ADC_1 peripheral instance was enabled by default in driver.
This is not the usual way to enable peripheral instances, as it
makes board configuration unclear.
Move activation in boards that are declaring ADC support.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-02-05 13:56:26 -06:00
Peter Bigot 37239dbcbf gpio: rename typedef for devicetree flags
gpio_dt_flags_t is shorter and consistent with DT_ prefix.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-02-05 12:00:36 +01:00