drivers: adc: add LMP90xxx ADC driver with GPIO
Add driver for the Texas Instruments LMP90xxx series of multi-channel, low-power 16-/24-bit sensor analog frontends (AFEs). The functionality is split into two drivers; an ADC driver and a GPIO driver. Tested with LMP90080 and LMP90100. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
9d71384e50
commit
bc2113bd46
|
@ -135,6 +135,7 @@
|
|||
/drivers/flash/*stm32* @superna9999
|
||||
/drivers/gpio/ @mnkp @pabigot
|
||||
/drivers/gpio/*ht16k33* @henrikbrixandersen
|
||||
/drivers/gpio/*lmp90xxx* @henrikbrixandersen
|
||||
/drivers/gpio/*stm32* @rsalveti @idlethread
|
||||
/drivers/hwinfo/ @alexanderwachter
|
||||
/drivers/i2c/*litex* @mateusz-holenko @kgugala @pgielda
|
||||
|
|
|
@ -11,4 +11,5 @@ zephyr_library_sources_ifdef(CONFIG_ADC_NRFX_SAADC adc_nrfx_saadc.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_ADC_SAM0 adc_sam0.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ADC_STM32 adc_stm32.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ADC_XEC adc_mchp_xec.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_ADC_LMP90XXX adc_lmp90xxx.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE adc_handlers.c)
|
||||
|
|
|
@ -57,4 +57,6 @@ source "drivers/adc/Kconfig.stm32"
|
|||
|
||||
source "drivers/adc/Kconfig.xec"
|
||||
|
||||
source "drivers/adc/Kconfig.lmp90xxx"
|
||||
|
||||
endif # ADC
|
||||
|
|
54
drivers/adc/Kconfig.lmp90xxx
Normal file
54
drivers/adc/Kconfig.lmp90xxx
Normal file
|
@ -0,0 +1,54 @@
|
|||
# LMP90xxx ADC configuration options
|
||||
|
||||
# Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
config ADC_LMP90XXX
|
||||
bool "LMP90xxx driver"
|
||||
depends on SPI
|
||||
select ADC_CONFIGURABLE_INPUTS
|
||||
help
|
||||
Enable LMP90xxx ADC driver.
|
||||
|
||||
The LMP90xxx is a multi-channel, low power sensor analog
|
||||
frontend (AFE).
|
||||
|
||||
if ADC_LMP90XXX
|
||||
|
||||
config ADC_LMP90XXX_INIT_PRIORITY
|
||||
int "Init priority"
|
||||
default 80
|
||||
help
|
||||
LMP90xxx ADC device driver initialization priority.
|
||||
|
||||
config ADC_LMP90XXX_ACQUISITION_THREAD_STACK_SIZE
|
||||
int "Stack size for the ADC data acquisition thread"
|
||||
default 400
|
||||
help
|
||||
Size of the stack used for the internal data acquisition
|
||||
thread.
|
||||
|
||||
config ADC_LMP90XXX_ACQUISITION_THREAD_PRIO
|
||||
int "Priority for the ADC data acquisition thread"
|
||||
default 0
|
||||
help
|
||||
Priority level for the internal ADC data acquisition thread.
|
||||
|
||||
config ADC_LMP90XXX_CRC
|
||||
bool "Use Cyclic Redundancy Check (CRC)"
|
||||
default y
|
||||
help
|
||||
Use Cyclic Redundancy Check (CRC) to verify the integrity of
|
||||
the data read from the LMP90xxx.
|
||||
|
||||
config ADC_LMP90XXX_GPIO
|
||||
bool "Enable GPIO support"
|
||||
depends on GPIO
|
||||
select GPIO_LMP90XXX
|
||||
help
|
||||
Enable GPIO child device support in the LMP90xxx ADC driver.
|
||||
|
||||
The GPIO functionality is handled by the LMP90xxx GPIO
|
||||
driver.
|
||||
|
||||
endif # ADC_LMP90XXX
|
1137
drivers/adc/adc_lmp90xxx.c
Normal file
1137
drivers/adc/adc_lmp90xxx.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -26,6 +26,7 @@ zephyr_library_sources_ifdef(CONFIG_GPIO_INTEL_APL gpio_intel_apl.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_GPIO_STELLARIS gpio_stellaris.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_RV32M1 gpio_rv32m1.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_HT16K33 gpio_ht16k33.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_LMP90XXX gpio_lmp90xxx.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_GPIO_SHELL gpio_shell.c)
|
||||
|
||||
|
|
|
@ -67,4 +67,6 @@ source "drivers/gpio/Kconfig.rv32m1"
|
|||
|
||||
source "drivers/gpio/Kconfig.ht16k33"
|
||||
|
||||
source "drivers/gpio/Kconfig.lmp90xxx"
|
||||
|
||||
endif # GPIO
|
||||
|
|
27
drivers/gpio/Kconfig.lmp90xxx
Normal file
27
drivers/gpio/Kconfig.lmp90xxx
Normal file
|
@ -0,0 +1,27 @@
|
|||
# LMP90xxx GPIO configuration options
|
||||
|
||||
# Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
menuconfig GPIO_LMP90XXX
|
||||
bool "LMP90xxx GPIO driver"
|
||||
depends on ADC_LMP90XXX_GPIO
|
||||
help
|
||||
Enable GPIO driver for LMP90xxx.
|
||||
|
||||
The LMP90xxx is a multi-channel, low power sensor analog
|
||||
frontend (AFE).
|
||||
|
||||
The GPIO port of the LMP90xxx (D6 to D0) is exposed as a
|
||||
GPIO controller driver with read/write support.
|
||||
|
||||
if GPIO_LMP90XXX
|
||||
|
||||
config GPIO_LMP90XXX_INIT_PRIORITY
|
||||
int "Driver init priority"
|
||||
default 99
|
||||
help
|
||||
Device driver initialization priority. This driver must be
|
||||
initialized after the LMP90xxx ADC driver.
|
||||
|
||||
endif # GPIO_LMP90XXX
|
143
drivers/gpio/gpio_lmp90xxx.c
Normal file
143
drivers/gpio/gpio_lmp90xxx.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief GPIO driver for the LMP90xxx AFE.
|
||||
*/
|
||||
|
||||
#include <drivers/gpio.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_GPIO_LOG_LEVEL
|
||||
#include <logging/log.h>
|
||||
LOG_MODULE_REGISTER(gpio_lmp90xxx);
|
||||
|
||||
#include <adc/lmp90xxx.h>
|
||||
|
||||
#include "gpio_utils.h"
|
||||
|
||||
struct gpio_lmp90xxx_config {
|
||||
char *parent_dev_name;
|
||||
};
|
||||
|
||||
struct gpio_lmp90xxx_data {
|
||||
struct device *parent;
|
||||
};
|
||||
|
||||
static int gpio_lmp90xxx_config(struct device *dev, int access_op,
|
||||
u32_t pin, int flags)
|
||||
{
|
||||
struct gpio_lmp90xxx_data *data = dev->driver_data;
|
||||
int err;
|
||||
|
||||
if (access_op != GPIO_ACCESS_BY_PIN) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (pin > LMP90XXX_GPIO_MAX) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (flags & GPIO_INT) {
|
||||
/* LMP90xxx GPIOs do not support interrupts */
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (flags & GPIO_DIR_OUT) {
|
||||
err = lmp90xxx_gpio_set_output(data->parent, pin);
|
||||
} else {
|
||||
err = lmp90xxx_gpio_set_input(data->parent, pin);
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int gpio_lmp90xxx_write(struct device *dev, int access_op,
|
||||
u32_t pin, u32_t value)
|
||||
{
|
||||
struct gpio_lmp90xxx_data *data = dev->driver_data;
|
||||
|
||||
if (access_op != GPIO_ACCESS_BY_PIN) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (pin > LMP90XXX_GPIO_MAX) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return lmp90xxx_gpio_set_pin_value(data->parent, pin,
|
||||
value ? true : false);
|
||||
}
|
||||
|
||||
static int gpio_lmp90xxx_read(struct device *dev, int access_op,
|
||||
u32_t pin, u32_t *value)
|
||||
{
|
||||
struct gpio_lmp90xxx_data *data = dev->driver_data;
|
||||
bool set;
|
||||
int err;
|
||||
|
||||
if (access_op != GPIO_ACCESS_BY_PIN) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (pin > LMP90XXX_GPIO_MAX) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = lmp90xxx_gpio_get_pin_value(data->parent, pin, &set);
|
||||
if (!err) {
|
||||
*value = set ? 1 : 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int gpio_lmp90xxx_init(struct device *dev)
|
||||
{
|
||||
const struct gpio_lmp90xxx_config *config = dev->config->config_info;
|
||||
struct gpio_lmp90xxx_data *data = dev->driver_data;
|
||||
|
||||
data->parent = device_get_binding(config->parent_dev_name);
|
||||
if (!data->parent) {
|
||||
LOG_ERR("parent LMP90xxx device '%s' not found",
|
||||
config->parent_dev_name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct gpio_driver_api gpio_lmp90xxx_api = {
|
||||
.config = gpio_lmp90xxx_config,
|
||||
.write = gpio_lmp90xxx_write,
|
||||
.read = gpio_lmp90xxx_read,
|
||||
};
|
||||
|
||||
BUILD_ASSERT_MSG(CONFIG_GPIO_LMP90XXX_INIT_PRIORITY >
|
||||
CONFIG_ADC_LMP90XXX_INIT_PRIORITY,
|
||||
"LMP90xxx GPIO driver must be initialized after LMP90xxx ADC "
|
||||
"driver");
|
||||
|
||||
#define GPIO_LMP90XXX_DEVICE(id) \
|
||||
static const struct gpio_lmp90xxx_config gpio_lmp90xxx_##id##_cfg = {\
|
||||
.parent_dev_name = \
|
||||
DT_INST_##id##_TI_LMP90XXX_GPIO_BUS_NAME, \
|
||||
}; \
|
||||
\
|
||||
static struct gpio_lmp90xxx_data gpio_lmp90xxx_##id##_data; \
|
||||
\
|
||||
DEVICE_AND_API_INIT(gpio_lmp90xxx_##id, \
|
||||
DT_INST_##id##_TI_LMP90XXX_GPIO_LABEL, \
|
||||
&gpio_lmp90xxx_init, \
|
||||
&gpio_lmp90xxx_##id##_data, \
|
||||
&gpio_lmp90xxx_##id##_cfg, POST_KERNEL, \
|
||||
CONFIG_GPIO_LMP90XXX_INIT_PRIORITY, \
|
||||
&gpio_lmp90xxx_api)
|
||||
|
||||
#ifdef DT_INST_0_TI_LMP90XXX_GPIO
|
||||
GPIO_LMP90XXX_DEVICE(0);
|
||||
#endif
|
18
dts/bindings/gpio/ti,lmp90xxx-gpio.yaml
Normal file
18
dts/bindings/gpio/ti,lmp90xxx-gpio.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
description: TI LMP90xxx GPIO controller binding
|
||||
|
||||
compatible: "ti,lmp90xxx-gpio"
|
||||
|
||||
include: [gpio-controller.yaml, base.yaml]
|
||||
|
||||
on-bus: lmp90xxx
|
||||
|
||||
properties:
|
||||
label:
|
||||
required: true
|
||||
|
||||
"#gpio-cells":
|
||||
const: 2
|
||||
|
||||
gpio-cells:
|
||||
- pin
|
||||
- flags
|
5
dts/bindings/iio/adc/ti,lmp90077.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90077.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90077 AFE binding
|
||||
|
||||
compatible: "ti,lmp90077"
|
||||
|
||||
include: ti,lmp90xxx-base.yaml
|
5
dts/bindings/iio/adc/ti,lmp90078.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90078.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90078 AFE binding
|
||||
|
||||
compatible: "ti,lmp90078"
|
||||
|
||||
include: ti,lmp90xxx-current.yaml
|
5
dts/bindings/iio/adc/ti,lmp90079.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90079.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90079 AFE binding
|
||||
|
||||
compatible: "ti,lmp90079"
|
||||
|
||||
include: ti,lmp90xxx-base.yaml
|
5
dts/bindings/iio/adc/ti,lmp90080.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90080.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90080 AFE binding
|
||||
|
||||
compatible: "ti,lmp90080"
|
||||
|
||||
include: ti,lmp90xxx-current.yaml
|
5
dts/bindings/iio/adc/ti,lmp90097.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90097.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90097 AFE binding
|
||||
|
||||
compatible: "ti,lmp90097"
|
||||
|
||||
include: ti,lmp90xxx-base.yaml
|
5
dts/bindings/iio/adc/ti,lmp90098.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90098.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90098 AFE binding
|
||||
|
||||
compatible: "ti,lmp90098"
|
||||
|
||||
include: ti,lmp90xxx-current.yaml
|
5
dts/bindings/iio/adc/ti,lmp90099.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90099.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90099 AFE binding
|
||||
|
||||
compatible: "ti,lmp90099"
|
||||
|
||||
include: ti,lmp90xxx-base.yaml
|
5
dts/bindings/iio/adc/ti,lmp90100.yaml
Normal file
5
dts/bindings/iio/adc/ti,lmp90100.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
description: Texas Instruments LMP90100 AFE binding
|
||||
|
||||
compatible: "ti,lmp90100"
|
||||
|
||||
include: ti,lmp90xxx-current.yaml
|
18
dts/bindings/iio/adc/ti,lmp90xxx-base.yaml
Normal file
18
dts/bindings/iio/adc/ti,lmp90xxx-base.yaml
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Common fields for Texas Instruments LMP90xxx AFEs
|
||||
|
||||
include: [adc-controller.yaml, spi-device.yaml]
|
||||
|
||||
bus: lmp90xxx
|
||||
|
||||
properties:
|
||||
drdyb-gpios:
|
||||
type: phandle-array
|
||||
required: false
|
||||
description: Data Ready Bar
|
||||
|
||||
"#io-channel-cells":
|
||||
const: 2
|
||||
|
||||
io-channel-cells:
|
||||
- positive
|
||||
- negative
|
9
dts/bindings/iio/adc/ti,lmp90xxx-current.yaml
Normal file
9
dts/bindings/iio/adc/ti,lmp90xxx-current.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
# Common fields for Texas Instruments LMP90xxx AFEs with current sources
|
||||
|
||||
include: ti,lmp90xxx-base.yaml
|
||||
|
||||
properties:
|
||||
rtd-current:
|
||||
type: int
|
||||
required: false
|
||||
description: RTD current in microampere
|
24
include/drivers/adc/lmp90xxx.h
Normal file
24
include/drivers/adc/lmp90xxx.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_ADC_LMP90XXX_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_ADC_LMP90XXX_H_
|
||||
|
||||
#include <device.h>
|
||||
#include <zephyr/types.h>
|
||||
|
||||
/* LMP90xxx supports GPIO D0..D6 */
|
||||
#define LMP90XXX_GPIO_MAX 6
|
||||
|
||||
int lmp90xxx_gpio_set_output(struct device *dev, u8_t pin);
|
||||
|
||||
int lmp90xxx_gpio_set_input(struct device *dev, u8_t pin);
|
||||
|
||||
int lmp90xxx_gpio_set_pin_value(struct device *dev, u8_t pin, bool value);
|
||||
|
||||
int lmp90xxx_gpio_get_pin_value(struct device *dev, u8_t pin, bool *value);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_ADC_LMP90XXX_H_ */
|
Loading…
Reference in a new issue