Commit graph

808 commits

Author SHA1 Message Date
Aymeric Aillet
513389b659 drivers: adc: lmp90xxx: do not use generated macros
Do not used generated macro from devicetree subsys directly
in driver.
Remove definition of it's own "FOREACH_STATUS_OKAY".
Redefine "DT_DRV_COMPAT" for each supported compatible string.

Signed-off-by: Aymeric Aillet <aymeric.aillet@iot.bzh>
2022-02-21 22:09:27 -05:00
Tim Lin
4381841bd8 ITE: drivers/adc: fix the sampling flow of ADC
The ADC sampling of it8xxx2 needs to read each channel in sequence,
so it needs to wait for an interrupt to read data in the loop
through k_sem_take().

In test_adc.c, k_timer_start() is used in the interval test, so we
need to use polling wait instead of k_sem_take() to wait, otherwise
it will cause kernel panic.

k_is_in_isr() can determine whether to use polling or k_sem_take()
at present.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2022-02-21 21:01:43 -05:00
Attie Grande
24478c8a4d drivers: adc: adc_sam0: Change local variables to lower case
Local variables should not be in capitals.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2022-02-04 10:49:09 +01:00
Attie Grande
e4d4eaca03 soc: atmel_sam0: Implement fixup.h for ADC driver
The ADC driver now supports three different implementations. To maintain
readability, this patch implements an adc_fixup.h that permits more
generic access to relevant registers.

This patch also introduces support for a new third shape ADC - as found
in the SAML21 for example.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2022-02-04 10:49:09 +01:00
Attie Grande
d45a9a11b7 drivers: adc: adc_sam0: Fix interpretation of channels
Previously this was expected to be equal to 1 at all times. This doesn't
play well with the sample or other users (e.g: adc_shell). Instead, we
should count the number of active channels in the bitfield, and ensure
that only one is identified.

Signed-off-by: Attie Grande <attie.grande@argentum-systems.co.uk>
2022-02-04 10:49:09 +01:00
Wealian Liao
6d6c5e1155 drivers: npcx: Drop DRV_CONFIG/DRV_DATA usage
Stop using DRV_CONFIG/DRV_DATA macros and use dev->data and dev->config
instead.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2022-01-28 10:06:05 +01:00
Wealian Liao
3565f71a72 drivers: npcx: Correct the macro parentheses
This corrects the following:
1. The priority of type cast is lower than member access. So don't need
the redundant parentheses.
2. The macro should be added to the parentheses.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2022-01-28 10:06:05 +01:00
Gerard Marull-Paretas
435213a753 drivers: remove redundant data/config casts
Some drivers explicitely casted data/config from void * to the
corresponding type. However, this is unnecessary and, in many drivers it
has been misused to drop const qualifier (refer to previous commits).

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Gerard Marull-Paretas
93b3cba2f1 drivers: adc: ite_it8xxx2: constify device config access
`const` was missing from one device config access.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Gerard Marull-Paretas
6745333511 drivers: adc: drop DEV_DATA/DEV_CFG usage
Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data
and dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Alexander Mihajlovic
cfce5afcd9 drivers: adc: stm32: Clear ADRDY before waiting
Clear ADRDY before enabling ADC to ensure the subsequent
wait for ADRDY does not stop prematurely in case ADRDY
was already set.

The "ADC on-off control" sections of the following reference manuals
were consulted. That gives at least one instance per series affected
by this change, even if not every affected MCU is covered.

- RM0438 (STM32L552xx and STM32L562xx)
- RM0351 (STM32L47xxx, STM32L48xxx, STM32L49xxx and STM32L4Axxx)
- RM0434 (STM32WB55xx and STM32WB35xx)
- RM0454 (STM32G0x0)
- RM0440 (STM32G4 Series)
- RM0399 (STM32H745/755 and STM32H747/757)
- RM0433 (STM32H742, STM32H743/753 and STM32H750)
- RM0453 (STM32WL5x)

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-01-17 11:48:30 -05:00
Alexander Mihajlovic
e521c7d49e drivers: adc: stm32: Add function to enable ADC consistently
Use a wrapper for LL_ADC_Enable that also waits for ADRDY if required
by the SoC to make sure it's properly enabled everywhere this is done.

Signed-off-by: Alexander Mihajlovic <a@abxy.se>
2022-01-17 11:48:30 -05:00
Jordan Yates
8173277cc1 drivers: adc: test driver
Add a dummy driver for the `vnd,adc` compatible to allow compilation of
drivers utilising an ADC when running "build_all" tests.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-01-17 08:13:41 -05:00
Marius Scholtz
14e15df00f drivers: arm: stm32: adc: Added Shared IRQ
Certain stm32 soc's have a single shared irq for all adc channels
on those soc's only a single channel is supported.

Added a Kconfig that enables a shared irq for stm32f2x, stm32f4x,
stm32f7x soc's. The shared IRQ uses a flag to limit the number of
interrupts defined to only 1. A shared irq handler is added which
determines which ADC instance the interrupt is for, it then calls
into the existing interrupt.

Signed-off-by: Marius Scholtz <mariuss@ricelectronics.com>
2022-01-11 11:50:43 +01:00
Wealian Liao
7add8f7fa0 drivers: adc: npcx: Fix register offset
NPCX7/9 has a different ADC register structure. NPCX7 has 3 threshold
detectors from offset 0x14 & has 10 input channels. NPCX9 has 6
threshold detectors from offset 0x60 & has 12 input channels.

This commit fixes the NPCX ADC register structure.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2022-01-07 11:21:29 -05:00
Francois Ramu
e9b9e4c6ad drivers: adc: driver setting the oversampling for stm32wl
RM 0453: the sw is allowed to write the Oversampling
ratio or shift of the ADC Config.Reg.2 only when ADSTART = 0
(no conversion is on-going). So disabling it will be stopped.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-01-04 09:12:08 -05:00
Francois Ramu
c918c4f1d9 drivers: adc: driver setting the resolution for stm32wl
RM 0453: the sw is allowed to write the Data Resolution bits
of the ADC Config.Reg.1 only when ADEN = 0 (ADC disable).

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-01-04 09:12:08 -05:00
Gerard Marull-Paretas
5dc6ed3ce3 pinctrl: require ; after PINCTRL_DT_(INST_)DEFINE macros
The PINCTRL_DT_(INST_)DEFINE macros already defined the trailing ;,
making its usage inconsistent with other macros such as
DEVICE_DT_DEFINE.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-01 07:39:08 -05:00
Aditya Bhutada
e4481f82cb drivers: adc: adc_mchp_xec: update configuration register clk times
MCHP ADC configuration register need to be updated with appropriate
clock time values for high & low time clock.

Signed-off-by: Aditya Bhutada <aditya.bhutada@intel.com>
2021-12-22 13:47:18 -05:00
Pete Dietl
bc1b262885 drivers: adc: stm32: Disable ADC before calibration
The STM32 docs state that the ADC may not be calibrated unless
the ADC is disabled (ADEN=0). This commit implements this constraint

Fixes #40936

Signed-off-by: Pete Dietl <petedietl@gmail.com>
2021-12-15 14:39:31 -06:00
Erwan Gouriou
93956b2073 drivers/adc: stm32: use new pinctrl API
Use the new pinctrl API to configure pins.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-11-26 11:36:42 +01:00
Francois Ramu
2185863d3b drivers: adc: add the stm32U5 devices to the adc driver
The STM32U5x device has ADC instance of different versions
similar to the stm32H7 about the oversampling.
ADC1 of 14bit resolution has a ratio from 1..1024 on OSR[9:0]
ADC4 of 12bit resolution has a ratio on OVSR[2:0]

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-11-09 15:59:23 -06:00
Francois Ramu
e26fcc47b9 drivers: adc: stm32 oversampling includes the ADC of the stm32U5 soc
This commit extends the configuration of the oversampling
ratio and shift for the stm32U5xx soc, depending on the
ADC instance: ratio is a value from 1..1024 or a LL_ADC_OVS_RATIO_x
to be used with the stm32Cube LL function.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-11-09 15:59:23 -06:00
Bartosz Bilas
7e43332436 drivers: adc: mcp320x: convert to spi_dt_spec
Convert mcp320x driver to use `spi_dt_spec` helpers.

Signed-off-by: Bartosz Bilas <bartosz.bilas@hotmail.com>
2021-11-04 07:18:09 -04:00
Francois Ramu
3ee3a46b6a drivers: adc: stm32h7 adc driver has a range for oversampling ratio
On the stm32H7 family, there are ADC which have Oversampling ratio
of 10 bits OSVR[9:0] in the CFGR2 register. It means that oversampling
512x or 1024x are possible.
Other values are not allowed as the oversampling field of the struct
adc_sequence (adc.h) is 2^oversampling.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-10-25 19:15:03 -04:00
Francois Ramu
0af4a393ee drivers: adc: stm32h7 adc driver has a different oversampling ratio
The adc_stm32_oversampling function is used to configure
the ratio and shift for each sequence->oversampling
depending on the soc serie and ADC instance in the serie
In the stm32H7 serie, only ADC3 of ADC_VER_V5_V90 version
have a LL_ADC_OVS_RATIO_x contant (other a 9bit value).

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-10-25 19:15:03 -04:00
Francois Ramu
41bfec7c52 drivers: adc: stm32h7 adc driver using LL function
Change the access to the PCSEL register by using the LL function
because on the STM32H7xx soc, some devices have no PCEL register
especially on ADC3 of the stm32H723.
The LL function manages this difference.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-10-25 19:15:03 -04:00
Andrei Auchynnikau
3b3a30612f drivers: add adc driver for the NXP RT series
adc driver is based on the NXP MCUX hal library

Signed-off-by: Andrei Auchynnikau <ovchinnikov@strim-tech.com>
2021-10-22 15:43:36 -05:00
Maureen Helm
b0cdef3c25 drivers: adc: Refactor drivers to use shared init priority
Refactors all of the ADC drivers to use a shared driver class
initialization priority configuration, CONFIG_ADC_INIT_PRIORITY, to
allow configuring ADC drivers separately from other devices. This is
similar to other driver classes like I2C and SPI.

The default is set to CONFIG_KERNEL_INIT_PRIORITY_DEVICE to preserve the
existing default initialization priority for most drivers. The
exceptions are lmp90xxx, mcp320x, and mcux_adc16 drivers which have
dependencies on GPIO, SPI, and/or DMA drivers and must therefore
initialize later than the default device priority.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2021-10-20 07:33:44 -04:00
Francois Ramu
acad37196d drivers: adc: stm32 adc disable causing endless loop
Setting Oversampling also applies on stm32L5 but disabling
the ADC will cause endless loop except for the stm32L0 serie.
Errata applies only on stm32G0 soc series when
writing ADC_CFGR1 register.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-09-28 06:12:47 -04:00
Francois Ramu
97c031822b drivers: adc: stm32 disable the ADC before setting the Oversampling
On those STM32 series, setting of this feature is conditioned to
the ADC state: it is allowed to set/reset the oversampler (OVSE bit)
and set the Oversampling ratio (OVSR bits) in the ADC_CFGR2 register
only when ADC is disabled or enabled without conversion on going.
Then is the ADC re-enabled.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-09-18 09:02:31 -04:00
Francois Ramu
572ab24241 drivers: adc: stm32 disable the ADC before setting the Resolution
On those STM32 series, setting of this feature is conditioned to
the ADC state: it is allowed to write the Data resolution (RES bits)
in the ADC_CFGR1 register only when ADC is disabled (ADEN=0).

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-09-18 09:02:31 -04:00
Gerson Fernando Budke
bca28015e3 drivers: adc: adc_sam0: Fix result ready interrupt
Atmel sam0 adc peripheral have multiple interrupt vectors for same5x
devices.  This configure interrupt vector by name to ensure that proper
interrupt handle will be executed.

Fixes #37779

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2021-09-02 06:45:35 -04:00
Martí Bolívar
2b9d477576 adc: npcx: use new DT pinctrl accessors
Update to use the new APIs.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2021-08-25 18:09:00 -04:00
David Leach
d3cd0d2f9a drivers: adc: add LPADC driver support to mimxrt685 platform
Add LPADC support to the mimxrt685 platform.

Signed-off-by: David Leach <david.leach@nxp.com>
2021-08-25 18:02:00 -04:00
Scott Worley
19dd46ef68 Microchip: MEC172x: ADC driver
Add ADC driver version 2 for MEC172x using new in-tree headers
and device tree properties. Update the ADC shell for the new driver.

Signed-off-by: Scott Worley <scott.worley@microchip.com>
2021-08-11 19:44:31 -04:00
Francois Ramu
bfeb9b4684 drivers: adc: stm32h7 has a different oversampling config API
The LL_ADC_ConfigOverSamplingRatioShift function for
the stm32H7xx soc serie differs from other for the 'ratio':
"This parameter can be in the range from 1 to 1024"
Note that in the stm32h7xx_ll_adc.c the LL_ADC_OVS_RATIO_xxx value is
defined for ADC of type ADC_VER_V5_V90.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-08-03 10:34:49 -05:00
Jordan Yates
c5868310ca adc: lmp90xxx: convert to spi_dt_spec
Convert SPI usage to `struct spi_dt_spec`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2021-08-03 13:58:39 +02:00
Tim Lin
733cd7ccd8 ITE: drivers/adc: it8xxx2: access pinctrl_0 property from soc_dt.h
This PR will cleanup related pinctrl_0 property which has been
moved to soc_dt.h

TEST=alternate function is as intended.
console command: md .b 0xf01650 8
00F01650: 00 00 00 00 80 00 00 80
TEST=read adc
console command: adc
ADC_VBUS_C0 = 11330 mV
ADC_BOARD_ID_0 = 2997 mV
ADC_BOARD_ID_1 = 1318 mV
ADC_AMON_BMON = 68166 mV
ADC_VBUS_C1 = 12270 mV
ADC_PMON = 32 mV
ADC_PSYS = 32 mV

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
2021-07-30 19:54:56 -04:00
Aurelien Jarno
58b8c4006e drivers: adc: STM32: add support for oversampling
The STM32 G0, G4, H7, L0, L4, WB and WL series have hardware support for
oversampling. This patch adds support for it, using the oversampling
value provided in the adc sequence. The result is shifted right
accordingly to not change the resolution of the measured value, like it
is done on other ADC drivers.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-07-29 11:48:41 -04:00
Crist Xu
04ab2400e6 driver: adc: an adc driver for rt1170
reuse the lpc's lpadc driver for rt1170, modify the dts and add
some macro to shield some code of LPC series. Also add the
board support inside the tests/drivers/adc/adc_api/src/test_adc.c,
and a dts node:zephyr,user inside
samples/drivers/adc/boards/mimxrt1170_evk_cm7.overlay

Signed-off-by: Crist Xu <crist.xu@nxp.com>
2021-07-20 13:15:58 -05:00
Sidhdharth Yadav
bdf425cd5c drivers: adc: Adding CONFIG_SOC_SERIES_STM32L5X in stm32l5 series
Allowing ADC to build in stm32l5 series.

Signed-off-by: Sidhdharth Yadav <sidhdharth.yadav@hcl.com>
2021-07-06 18:03:22 -04:00
Aurelien Jarno
2a96cc0347 drivers: adc: STM32: fix support for internal voltage reference source
Commit c045cbd336 added support for internal voltage reference source,
but in practice only the temp sensor is supported. Fix that.

Also change the code to keep the existing paths so that VREFINT and
TEMPSENSOR can be used at the same time.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2021-07-06 18:01:57 -04:00
Dario Binacchi
c3a067e841 drivers: adc: stm32: fix f3x series
The patch fixes driver compile errors and ADC management for the f3x
series. It was developed and tested for the stm32f373 variant.

Tested-by: Dario Binacchi <dariobin@libero.it>
Signed-off-by: Dario Binacchi <dariobin@libero.it>
2021-07-06 15:08:04 -05:00
Henrik Brix Andersen
fadc5d15a3 drivers: adc: mcux_adc16: reduce log verbosity
Reduce the initialization done log message from informational to debug.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2021-07-01 17:04:04 -05:00
Fabio Baltieri
3af832868c drivers: npcx: convert NPCX drivers clock client to DEVICE_DT_GET
Convert the various device_get_binding() calls used to get the device
clock node to use DEVICE_DT_GET. The latter is processed at link time,
so it should be a bit more efficient.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2021-06-27 23:02:39 -04:00
Crist Xu
530db5154e lpadc: a bug fix for the drivers/adc_mcux_lpadc.c
it need to be a && between two condition, to satisfy
the comment: only 12 / 13 bit resolution is supported,
if FSL_FEATURE_LPADC_HAS_CMDL_MODE is not defined. not
using ||.

Signed-off-by: Crist Xu <crist.xu@nxp.com>
2021-06-21 14:19:29 -05:00
Lasse Sangild
ec174d41b6 drivers: adc: stm32: Perform calibration if set in sequence
The calibration bit previously did nothing.

Move calibration to allow call in start_read.

Signed-off-by: Lasse Sangild <lsangild@gmail.com>
2021-06-16 10:39:18 +02:00
Lasse Sangild
e4463a7d9e drivers: adc: stm32: Add STM32h7xx linearity calibration
The STM32H7 series has a special ADC, which is calibrated
on the factory. The calibration values are stored in flash
and must be retrieved upon powering up the device.

Failure to calibrate the device leads to missing codes in
the ADC readings.

Fixes #35529

Signed-off-by: Lasse Sangild <lsangild@gmail.com>
2021-06-16 10:39:18 +02:00
Piotr Mienkowski
aaf64e0bdf soc: atmel_sam: Add _INST to ATMEL_SAM_DT_PIN* macros
The macros are used to get the pin(s) of a given driver instance. Add
_INST prefix to match convention used by the devicetree.h. The original
macros can now be used to obtain pin(s) of an arbitrary device instance
identified by the nodelabel.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-06-14 09:50:41 -05:00