2019-10-07 13:08:44 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Vestas Wind Systems A/S
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief GPIO driver for the LMP90xxx AFE.
|
|
|
|
*/
|
|
|
|
|
2020-03-26 13:16:59 +01:00
|
|
|
#define DT_DRV_COMPAT ti_lmp90xxx_gpio
|
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/drivers/gpio.h>
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 09:58:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
2019-10-07 13:08:44 +02:00
|
|
|
|
|
|
|
#define LOG_LEVEL CONFIG_GPIO_LOG_LEVEL
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/logging/log.h>
|
2019-10-07 13:08:44 +02:00
|
|
|
LOG_MODULE_REGISTER(gpio_lmp90xxx);
|
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/drivers/adc/lmp90xxx.h>
|
2019-10-07 13:08:44 +02:00
|
|
|
|
2022-10-21 20:18:01 +02:00
|
|
|
#include <zephyr/drivers/gpio/gpio_utils.h>
|
2019-10-07 13:08:44 +02:00
|
|
|
|
|
|
|
struct gpio_lmp90xxx_config {
|
2020-01-26 23:13:00 +01:00
|
|
|
/* gpio_driver_config needs to be first */
|
|
|
|
struct gpio_driver_config common;
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct device *parent;
|
2019-10-07 13:08:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gpio_lmp90xxx_data {
|
2020-01-26 23:13:00 +01:00
|
|
|
/* gpio_driver_data needs to be first */
|
|
|
|
struct gpio_driver_data common;
|
2019-10-07 13:08:44 +02:00
|
|
|
};
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_config(const struct device *dev,
|
2020-01-30 19:12:39 +01:00
|
|
|
gpio_pin_t pin, gpio_flags_t flags)
|
2019-10-07 13:08:44 +02:00
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
int err = 0;
|
2019-10-07 13:08:44 +02:00
|
|
|
|
|
|
|
if (pin > LMP90XXX_GPIO_MAX) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-01-26 23:13:00 +01:00
|
|
|
if ((flags & GPIO_SINGLE_ENDED) != 0) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) != 0) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & GPIO_INT_ENABLE) {
|
2019-10-07 13:08:44 +02:00
|
|
|
/* LMP90xxx GPIOs do not support interrupts */
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-01-26 23:13:00 +01:00
|
|
|
switch (flags & GPIO_DIR_MASK) {
|
|
|
|
case GPIO_INPUT:
|
2021-05-27 11:47:41 +02:00
|
|
|
err = lmp90xxx_gpio_set_input(config->parent, pin);
|
2020-01-26 23:13:00 +01:00
|
|
|
break;
|
|
|
|
case GPIO_OUTPUT:
|
|
|
|
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
|
2021-05-27 11:47:41 +02:00
|
|
|
err = lmp90xxx_gpio_set_pin_value(config->parent, pin,
|
2020-01-26 23:13:00 +01:00
|
|
|
true);
|
|
|
|
} else if ((flags & GPIO_OUTPUT_INIT_LOW) != 0) {
|
2021-05-27 11:47:41 +02:00
|
|
|
err = lmp90xxx_gpio_set_pin_value(config->parent, pin,
|
2020-01-26 23:13:00 +01:00
|
|
|
false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
2021-05-27 11:47:41 +02:00
|
|
|
err = lmp90xxx_gpio_set_output(config->parent, pin);
|
2020-01-26 23:13:00 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
2019-10-07 13:08:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_port_get_raw(const struct device *dev,
|
2020-01-26 23:13:00 +01:00
|
|
|
gpio_port_value_t *value)
|
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
return lmp90xxx_gpio_port_get_raw(config->parent, value);
|
2020-01-26 23:13:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_port_set_masked_raw(const struct device *dev,
|
2020-01-26 23:13:00 +01:00
|
|
|
gpio_port_pins_t mask,
|
|
|
|
gpio_port_value_t value)
|
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
return lmp90xxx_gpio_port_set_masked_raw(config->parent, mask, value);
|
2020-01-26 23:13:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_port_set_bits_raw(const struct device *dev,
|
2020-01-26 23:13:00 +01:00
|
|
|
gpio_port_pins_t pins)
|
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
return lmp90xxx_gpio_port_set_bits_raw(config->parent, pins);
|
2020-01-26 23:13:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_port_clear_bits_raw(const struct device *dev,
|
2020-01-26 23:13:00 +01:00
|
|
|
gpio_port_pins_t pins)
|
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
return lmp90xxx_gpio_port_clear_bits_raw(config->parent, pins);
|
2020-01-26 23:13:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_port_toggle_bits(const struct device *dev,
|
2020-01-26 23:13:00 +01:00
|
|
|
gpio_port_pins_t pins)
|
|
|
|
{
|
2021-05-27 11:47:41 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2020-01-26 23:13:00 +01:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
return lmp90xxx_gpio_port_toggle_bits(config->parent, pins);
|
2020-01-26 23:13:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_pin_interrupt_configure(const struct device *dev,
|
2020-01-30 19:12:39 +01:00
|
|
|
gpio_pin_t pin,
|
2020-01-26 23:13:00 +01:00
|
|
|
enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
ARG_UNUSED(pin);
|
|
|
|
ARG_UNUSED(mode);
|
|
|
|
ARG_UNUSED(trig);
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_lmp90xxx_init(const struct device *dev)
|
2019-10-07 13:08:44 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_lmp90xxx_config *config = dev->config;
|
2019-10-07 13:08:44 +02:00
|
|
|
|
2021-05-27 11:47:41 +02:00
|
|
|
if (!device_is_ready(config->parent)) {
|
|
|
|
LOG_ERR("parent LMP90xxx device '%s' not ready",
|
|
|
|
config->parent->name);
|
2019-10-07 13:08:44 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct gpio_driver_api gpio_lmp90xxx_api = {
|
2020-01-30 19:12:39 +01:00
|
|
|
.pin_configure = gpio_lmp90xxx_config,
|
2020-01-26 23:13:00 +01:00
|
|
|
.port_set_masked_raw = gpio_lmp90xxx_port_set_masked_raw,
|
|
|
|
.port_set_bits_raw = gpio_lmp90xxx_port_set_bits_raw,
|
|
|
|
.port_clear_bits_raw = gpio_lmp90xxx_port_clear_bits_raw,
|
|
|
|
.port_toggle_bits = gpio_lmp90xxx_port_toggle_bits,
|
|
|
|
.pin_interrupt_configure = gpio_lmp90xxx_pin_interrupt_configure,
|
|
|
|
.port_get_raw = gpio_lmp90xxx_port_get_raw,
|
2019-10-07 13:08:44 +02:00
|
|
|
};
|
|
|
|
|
2021-12-05 07:04:59 +01:00
|
|
|
BUILD_ASSERT(CONFIG_GPIO_LMP90XXX_INIT_PRIORITY >
|
2021-10-19 21:45:49 +02:00
|
|
|
CONFIG_ADC_INIT_PRIORITY,
|
2020-03-12 16:16:00 +01:00
|
|
|
"LMP90xxx GPIO driver must be initialized after LMP90xxx ADC "
|
|
|
|
"driver");
|
2019-10-07 13:08:44 +02:00
|
|
|
|
|
|
|
#define GPIO_LMP90XXX_DEVICE(id) \
|
|
|
|
static const struct gpio_lmp90xxx_config gpio_lmp90xxx_##id##_cfg = {\
|
2020-01-26 23:13:00 +01:00
|
|
|
.common = { \
|
|
|
|
.port_pin_mask = \
|
2020-04-04 16:45:09 +02:00
|
|
|
GPIO_PORT_PIN_MASK_FROM_DT_INST(id) \
|
2020-01-26 23:13:00 +01:00
|
|
|
}, \
|
2021-05-27 11:47:41 +02:00
|
|
|
.parent = DEVICE_DT_GET(DT_INST_BUS(id)), \
|
2019-10-07 13:08:44 +02:00
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static struct gpio_lmp90xxx_data gpio_lmp90xxx_##id##_data; \
|
|
|
|
\
|
2020-12-10 17:20:42 +01:00
|
|
|
DEVICE_DT_INST_DEFINE(id, \
|
2019-10-07 13:08:44 +02:00
|
|
|
&gpio_lmp90xxx_init, \
|
2021-04-28 10:55:48 +02:00
|
|
|
NULL, \
|
2019-10-07 13:08:44 +02:00
|
|
|
&gpio_lmp90xxx_##id##_data, \
|
|
|
|
&gpio_lmp90xxx_##id##_cfg, POST_KERNEL, \
|
2021-12-05 07:04:59 +01:00
|
|
|
CONFIG_GPIO_LMP90XXX_INIT_PRIORITY, \
|
2020-05-07 21:09:05 +02:00
|
|
|
&gpio_lmp90xxx_api);
|
2019-10-07 13:08:44 +02:00
|
|
|
|
2020-05-06 20:23:07 +02:00
|
|
|
DT_INST_FOREACH_STATUS_OKAY(GPIO_LMP90XXX_DEVICE)
|