2016-12-12 10:50:56 -06:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Freescale Semiconductor, Inc.
|
2017-01-20 08:16:32 -06:00
|
|
|
* Copyright (c) 2017, NXP
|
2016-12-12 10:50:56 -06:00
|
|
|
*
|
2017-01-18 17:01:01 -08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-12-12 10:50:56 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <device.h>
|
2019-06-25 15:53:52 -04:00
|
|
|
#include <drivers/gpio.h>
|
2016-12-12 10:50:56 -06:00
|
|
|
#include <soc.h>
|
|
|
|
#include <fsl_common.h>
|
|
|
|
#include <fsl_port.h>
|
|
|
|
|
|
|
|
#include "gpio_utils.h"
|
|
|
|
|
|
|
|
struct gpio_mcux_config {
|
2019-12-11 10:48:42 -06:00
|
|
|
/* gpio_driver_config needs to be first */
|
|
|
|
struct gpio_driver_config common;
|
2016-12-12 10:50:56 -06:00
|
|
|
GPIO_Type *gpio_base;
|
|
|
|
PORT_Type *port_base;
|
2017-04-01 14:52:47 -03:00
|
|
|
unsigned int flags;
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gpio_mcux_data {
|
2019-09-18 08:23:18 -05:00
|
|
|
/* gpio_driver_data needs to be first */
|
|
|
|
struct gpio_driver_data common;
|
2016-12-12 10:50:56 -06:00
|
|
|
/* port ISR callback routine address */
|
|
|
|
sys_slist_t callbacks;
|
|
|
|
/* pin callback routine enable flags, by pin number */
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t pin_callback_enables;
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static int gpio_mcux_configure(struct device *dev,
|
2020-01-30 09:31:07 -06:00
|
|
|
u32_t pin, int flags)
|
2016-12-12 10:50:56 -06:00
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
PORT_Type *port_base = config->port_base;
|
2018-11-29 11:12:22 -08:00
|
|
|
u32_t mask = 0U;
|
|
|
|
u32_t pcr = 0U;
|
2016-12-12 10:50:56 -06:00
|
|
|
|
2019-01-30 16:52:34 -06:00
|
|
|
/* Check for an invalid pin number */
|
|
|
|
if (pin >= ARRAY_SIZE(port_base->PCR)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:28:40 +02:00
|
|
|
if (((flags & GPIO_INPUT) != 0) && ((flags & GPIO_OUTPUT) != 0)) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((flags & GPIO_SINGLE_ENDED) != 0) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2016-12-12 10:50:56 -06:00
|
|
|
/* The flags contain options that require touching registers in the
|
|
|
|
* GPIO module and the corresponding PORT module.
|
|
|
|
*
|
|
|
|
* Start with the GPIO module and set up the pin direction register.
|
|
|
|
* 0 - pin is input, 1 - pin is output
|
|
|
|
*/
|
|
|
|
|
2020-01-30 09:31:07 -06:00
|
|
|
switch (flags & GPIO_DIR_MASK) {
|
|
|
|
case GPIO_INPUT:
|
|
|
|
gpio_base->PDDR &= ~BIT(pin);
|
|
|
|
break;
|
|
|
|
case GPIO_OUTPUT:
|
|
|
|
if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) {
|
|
|
|
gpio_base->PSOR = BIT(pin);
|
|
|
|
} else if ((flags & GPIO_OUTPUT_INIT_LOW) != 0) {
|
|
|
|
gpio_base->PCOR = BIT(pin);
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
2020-01-30 09:31:07 -06:00
|
|
|
gpio_base->PDDR |= BIT(pin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now do the PORT module. Figure out the pullup/pulldown
|
|
|
|
* configuration, but don't write it to the PCR register yet.
|
|
|
|
*/
|
|
|
|
mask |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
|
|
|
|
|
2019-08-09 01:28:40 +02:00
|
|
|
if ((flags & GPIO_PULL_UP) != 0) {
|
2016-12-12 10:50:56 -06:00
|
|
|
/* Enable the pull and select the pullup resistor. */
|
|
|
|
pcr |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
|
|
|
|
|
2019-08-09 01:28:40 +02:00
|
|
|
} else if ((flags & GPIO_PULL_DOWN) != 0) {
|
2016-12-12 10:50:56 -06:00
|
|
|
/* Enable the pull and select the pulldown resistor (deselect
|
|
|
|
* the pullup resistor.
|
|
|
|
*/
|
|
|
|
pcr |= PORT_PCR_PE_MASK;
|
|
|
|
}
|
|
|
|
|
2020-01-30 09:31:07 -06:00
|
|
|
/* Accessing by pin, we only need to write one PCR register. */
|
|
|
|
port_base->PCR[pin] = (port_base->PCR[pin] & ~mask) | pcr;
|
2016-12-12 10:50:56 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:28:40 +02:00
|
|
|
static int gpio_mcux_port_get_raw(struct device *dev, u32_t *value)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
*value = gpio_base->PDIR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_port_set_masked_raw(struct device *dev, u32_t mask,
|
|
|
|
u32_t value)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PDOR = (gpio_base->PDOR & ~mask) | (mask & value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_port_set_bits_raw(struct device *dev, u32_t mask)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PSOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_port_clear_bits_raw(struct device *dev, u32_t mask)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PCOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_port_toggle_bits(struct device *dev, u32_t mask)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PTOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-16 03:20:41 +02:00
|
|
|
static u32_t get_port_pcr_irqc_value_from_flags(struct device *dev,
|
|
|
|
u32_t pin, enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
|
|
|
{
|
|
|
|
port_interrupt_t port_interrupt = 0;
|
|
|
|
|
|
|
|
if (mode == GPIO_INT_MODE_DISABLED) {
|
|
|
|
port_interrupt = kPORT_InterruptOrDMADisabled;
|
|
|
|
} else {
|
|
|
|
if (mode == GPIO_INT_MODE_LEVEL) {
|
|
|
|
if (trig == GPIO_INT_TRIG_LOW) {
|
|
|
|
port_interrupt = kPORT_InterruptLogicZero;
|
|
|
|
} else {
|
|
|
|
port_interrupt = kPORT_InterruptLogicOne;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (trig) {
|
|
|
|
case GPIO_INT_TRIG_LOW:
|
|
|
|
port_interrupt = kPORT_InterruptFallingEdge;
|
|
|
|
break;
|
|
|
|
case GPIO_INT_TRIG_HIGH:
|
|
|
|
port_interrupt = kPORT_InterruptRisingEdge;
|
|
|
|
break;
|
|
|
|
case GPIO_INT_TRIG_BOTH:
|
|
|
|
port_interrupt = kPORT_InterruptEitherEdge;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PORT_PCR_IRQC(port_interrupt);
|
|
|
|
}
|
|
|
|
|
2019-08-09 01:28:40 +02:00
|
|
|
static int gpio_mcux_pin_interrupt_configure(struct device *dev,
|
2019-09-18 08:23:18 -05:00
|
|
|
unsigned int pin, enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
2019-10-16 03:20:41 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
2019-08-09 01:28:40 +02:00
|
|
|
PORT_Type *port_base = config->port_base;
|
|
|
|
struct gpio_mcux_data *data = dev->driver_data;
|
|
|
|
|
|
|
|
/* Check for an invalid pin number */
|
|
|
|
if (pin >= ARRAY_SIZE(port_base->PCR)) {
|
|
|
|
return -EINVAL;
|
2019-10-16 03:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for an invalid pin configuration */
|
|
|
|
if ((mode != GPIO_INT_MODE_DISABLED) &&
|
|
|
|
((gpio_base->PDDR & BIT(pin)) != 0)) {
|
|
|
|
return -EINVAL;
|
2019-08-09 01:28:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if GPIO port supports interrupts */
|
2019-09-18 08:23:18 -05:00
|
|
|
if ((mode != GPIO_INT_MODE_DISABLED) &&
|
2019-08-09 01:28:40 +02:00
|
|
|
((config->flags & GPIO_INT_ENABLE) == 0U)) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2019-09-18 08:23:18 -05:00
|
|
|
u32_t pcr = get_port_pcr_irqc_value_from_flags(dev, pin, mode, trig);
|
2019-08-09 01:28:40 +02:00
|
|
|
|
|
|
|
port_base->PCR[pin] = (port_base->PCR[pin] & ~PORT_PCR_IRQC_MASK) | pcr;
|
|
|
|
|
2019-09-18 08:23:18 -05:00
|
|
|
WRITE_BIT(data->pin_callback_enables, pin, mode != GPIO_INT_DISABLE);
|
2019-08-09 01:28:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-12 10:50:56 -06:00
|
|
|
static int gpio_mcux_manage_callback(struct device *dev,
|
|
|
|
struct gpio_callback *callback, bool set)
|
|
|
|
{
|
|
|
|
struct gpio_mcux_data *data = dev->driver_data;
|
|
|
|
|
2019-03-12 15:15:42 -06:00
|
|
|
return gpio_manage_callback(&data->callbacks, callback, set);
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_enable_callback(struct device *dev,
|
2020-01-30 20:00:01 -06:00
|
|
|
u32_t pin)
|
2016-12-12 10:50:56 -06:00
|
|
|
{
|
|
|
|
struct gpio_mcux_data *data = dev->driver_data;
|
|
|
|
|
2020-01-30 20:00:01 -06:00
|
|
|
data->pin_callback_enables |= BIT(pin);
|
2016-12-12 10:50:56 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gpio_mcux_disable_callback(struct device *dev,
|
2020-01-30 20:00:01 -06:00
|
|
|
u32_t pin)
|
2016-12-12 10:50:56 -06:00
|
|
|
{
|
|
|
|
struct gpio_mcux_data *data = dev->driver_data;
|
|
|
|
|
2020-01-30 20:00:01 -06:00
|
|
|
data->pin_callback_enables &= ~BIT(pin);
|
2016-12-12 10:50:56 -06:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gpio_mcux_port_isr(void *arg)
|
|
|
|
{
|
|
|
|
struct device *dev = (struct device *)arg;
|
|
|
|
const struct gpio_mcux_config *config = dev->config->config_info;
|
|
|
|
struct gpio_mcux_data *data = dev->driver_data;
|
2017-04-21 10:03:20 -05:00
|
|
|
u32_t enabled_int, int_status;
|
2016-12-12 10:50:56 -06:00
|
|
|
|
|
|
|
int_status = config->port_base->ISFR;
|
|
|
|
enabled_int = int_status & data->pin_callback_enables;
|
|
|
|
|
|
|
|
/* Clear the port interrupts */
|
2019-09-23 17:47:31 -05:00
|
|
|
config->port_base->ISFR = enabled_int;
|
|
|
|
|
|
|
|
gpio_fire_callbacks(&data->callbacks, dev, enabled_int);
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct gpio_driver_api gpio_mcux_driver_api = {
|
|
|
|
.config = gpio_mcux_configure,
|
2019-08-09 01:28:40 +02:00
|
|
|
.port_get_raw = gpio_mcux_port_get_raw,
|
|
|
|
.port_set_masked_raw = gpio_mcux_port_set_masked_raw,
|
|
|
|
.port_set_bits_raw = gpio_mcux_port_set_bits_raw,
|
|
|
|
.port_clear_bits_raw = gpio_mcux_port_clear_bits_raw,
|
|
|
|
.port_toggle_bits = gpio_mcux_port_toggle_bits,
|
|
|
|
.pin_interrupt_configure = gpio_mcux_pin_interrupt_configure,
|
2016-12-12 10:50:56 -06:00
|
|
|
.manage_callback = gpio_mcux_manage_callback,
|
|
|
|
.enable_callback = gpio_mcux_enable_callback,
|
|
|
|
.disable_callback = gpio_mcux_disable_callback,
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_MCUX_PORTA
|
|
|
|
static int gpio_mcux_porta_init(struct device *dev);
|
|
|
|
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_porta_config = {
|
2019-12-11 10:48:42 -06:00
|
|
|
.common = {
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_0_NXP_KINETIS_GPIO_NGPIOS),
|
|
|
|
},
|
2019-02-08 10:30:42 -06:00
|
|
|
.gpio_base = (GPIO_Type *) DT_NXP_KINETIS_GPIO_GPIO_A_BASE_ADDRESS,
|
2016-12-12 10:50:56 -06:00
|
|
|
.port_base = PORTA,
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_A_IRQ_0
|
2019-08-09 01:28:40 +02:00
|
|
|
.flags = GPIO_INT_ENABLE,
|
2017-04-01 14:52:47 -03:00
|
|
|
#else
|
|
|
|
.flags = 0,
|
|
|
|
#endif
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gpio_mcux_data gpio_mcux_porta_data;
|
|
|
|
|
2019-02-08 10:30:42 -06:00
|
|
|
DEVICE_AND_API_INIT(gpio_mcux_porta, DT_NXP_KINETIS_GPIO_GPIO_A_LABEL,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_porta_init,
|
|
|
|
&gpio_mcux_porta_data, &gpio_mcux_porta_config,
|
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
|
|
|
&gpio_mcux_driver_api);
|
|
|
|
|
|
|
|
static int gpio_mcux_porta_init(struct device *dev)
|
|
|
|
{
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_A_IRQ_0
|
|
|
|
IRQ_CONNECT(DT_NXP_KINETIS_GPIO_GPIO_A_IRQ_0, DT_NXP_KINETIS_GPIO_GPIO_A_IRQ_0_PRIORITY,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_port_isr, DEVICE_GET(gpio_mcux_porta), 0);
|
|
|
|
|
2019-06-19 12:55:29 -05:00
|
|
|
irq_enable(DT_NXP_KINETIS_GPIO_GPIO_A_IRQ_0);
|
2017-04-01 14:52:47 -03:00
|
|
|
#endif
|
2019-02-22 15:01:42 -06:00
|
|
|
return 0;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_MCUX_PORTA */
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_MCUX_PORTB
|
|
|
|
static int gpio_mcux_portb_init(struct device *dev);
|
|
|
|
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_portb_config = {
|
2019-12-11 10:48:42 -06:00
|
|
|
.common = {
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_1_NXP_KINETIS_GPIO_NGPIOS),
|
|
|
|
},
|
2019-02-08 10:30:42 -06:00
|
|
|
.gpio_base = (GPIO_Type *) DT_NXP_KINETIS_GPIO_GPIO_B_BASE_ADDRESS,
|
2016-12-12 10:50:56 -06:00
|
|
|
.port_base = PORTB,
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_B_IRQ_0
|
2019-08-09 01:28:40 +02:00
|
|
|
.flags = GPIO_INT_ENABLE,
|
2017-04-01 14:52:47 -03:00
|
|
|
#else
|
|
|
|
.flags = 0,
|
|
|
|
#endif
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gpio_mcux_data gpio_mcux_portb_data;
|
|
|
|
|
2019-02-08 10:30:42 -06:00
|
|
|
DEVICE_AND_API_INIT(gpio_mcux_portb, DT_NXP_KINETIS_GPIO_GPIO_B_LABEL,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_portb_init,
|
|
|
|
&gpio_mcux_portb_data, &gpio_mcux_portb_config,
|
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
|
|
|
&gpio_mcux_driver_api);
|
|
|
|
|
|
|
|
static int gpio_mcux_portb_init(struct device *dev)
|
|
|
|
{
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_B_IRQ_0
|
|
|
|
IRQ_CONNECT(DT_NXP_KINETIS_GPIO_GPIO_B_IRQ_0, DT_NXP_KINETIS_GPIO_GPIO_B_IRQ_0_PRIORITY,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_port_isr, DEVICE_GET(gpio_mcux_portb), 0);
|
|
|
|
|
2019-06-19 12:55:29 -05:00
|
|
|
irq_enable(DT_NXP_KINETIS_GPIO_GPIO_B_IRQ_0);
|
2017-04-01 14:52:47 -03:00
|
|
|
#endif
|
2019-02-22 15:01:42 -06:00
|
|
|
return 0;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_MCUX_PORTB */
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_MCUX_PORTC
|
|
|
|
static int gpio_mcux_portc_init(struct device *dev);
|
|
|
|
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_portc_config = {
|
2019-12-11 10:48:42 -06:00
|
|
|
.common = {
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_2_NXP_KINETIS_GPIO_NGPIOS),
|
|
|
|
},
|
2019-02-08 10:30:42 -06:00
|
|
|
.gpio_base = (GPIO_Type *) DT_NXP_KINETIS_GPIO_GPIO_C_BASE_ADDRESS,
|
2016-12-12 10:50:56 -06:00
|
|
|
.port_base = PORTC,
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_C_IRQ_0
|
2019-08-09 01:28:40 +02:00
|
|
|
.flags = GPIO_INT_ENABLE,
|
2017-04-01 14:52:47 -03:00
|
|
|
#else
|
|
|
|
.flags = 0,
|
|
|
|
#endif
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gpio_mcux_data gpio_mcux_portc_data;
|
|
|
|
|
2019-02-08 10:30:42 -06:00
|
|
|
DEVICE_AND_API_INIT(gpio_mcux_portc, DT_NXP_KINETIS_GPIO_GPIO_C_LABEL,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_portc_init,
|
|
|
|
&gpio_mcux_portc_data, &gpio_mcux_portc_config,
|
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
|
|
|
&gpio_mcux_driver_api);
|
|
|
|
|
|
|
|
static int gpio_mcux_portc_init(struct device *dev)
|
|
|
|
{
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_C_IRQ_0
|
|
|
|
IRQ_CONNECT(DT_NXP_KINETIS_GPIO_GPIO_C_IRQ_0, DT_NXP_KINETIS_GPIO_GPIO_C_IRQ_0_PRIORITY,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_port_isr, DEVICE_GET(gpio_mcux_portc), 0);
|
|
|
|
|
2019-06-19 12:55:29 -05:00
|
|
|
irq_enable(DT_NXP_KINETIS_GPIO_GPIO_C_IRQ_0);
|
2017-04-01 14:52:47 -03:00
|
|
|
#endif
|
2019-02-22 15:01:42 -06:00
|
|
|
return 0;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_MCUX_PORTC */
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_MCUX_PORTD
|
|
|
|
static int gpio_mcux_portd_init(struct device *dev);
|
|
|
|
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_portd_config = {
|
2019-12-11 10:48:42 -06:00
|
|
|
.common = {
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_3_NXP_KINETIS_GPIO_NGPIOS),
|
|
|
|
},
|
2019-02-08 10:30:42 -06:00
|
|
|
.gpio_base = (GPIO_Type *) DT_NXP_KINETIS_GPIO_GPIO_D_BASE_ADDRESS,
|
2016-12-12 10:50:56 -06:00
|
|
|
.port_base = PORTD,
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_D_IRQ_0
|
2019-08-09 01:28:40 +02:00
|
|
|
.flags = GPIO_INT_ENABLE,
|
2017-04-01 14:52:47 -03:00
|
|
|
#else
|
|
|
|
.flags = 0,
|
|
|
|
#endif
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gpio_mcux_data gpio_mcux_portd_data;
|
|
|
|
|
2019-02-08 10:30:42 -06:00
|
|
|
DEVICE_AND_API_INIT(gpio_mcux_portd, DT_NXP_KINETIS_GPIO_GPIO_D_LABEL,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_portd_init,
|
|
|
|
&gpio_mcux_portd_data, &gpio_mcux_portd_config,
|
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
|
|
|
&gpio_mcux_driver_api);
|
|
|
|
|
|
|
|
static int gpio_mcux_portd_init(struct device *dev)
|
|
|
|
{
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_D_IRQ_0
|
|
|
|
IRQ_CONNECT(DT_NXP_KINETIS_GPIO_GPIO_D_IRQ_0, DT_NXP_KINETIS_GPIO_GPIO_D_IRQ_0_PRIORITY,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_port_isr, DEVICE_GET(gpio_mcux_portd), 0);
|
|
|
|
|
2019-06-19 12:55:29 -05:00
|
|
|
irq_enable(DT_NXP_KINETIS_GPIO_GPIO_D_IRQ_0);
|
2017-04-01 14:52:47 -03:00
|
|
|
#endif
|
2019-02-22 15:01:42 -06:00
|
|
|
return 0;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_MCUX_PORTD */
|
|
|
|
|
|
|
|
#ifdef CONFIG_GPIO_MCUX_PORTE
|
|
|
|
static int gpio_mcux_porte_init(struct device *dev);
|
|
|
|
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_porte_config = {
|
2019-12-11 10:48:42 -06:00
|
|
|
.common = {
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_NGPIOS(DT_INST_4_NXP_KINETIS_GPIO_NGPIOS),
|
|
|
|
},
|
2019-02-08 10:30:42 -06:00
|
|
|
.gpio_base = (GPIO_Type *) DT_NXP_KINETIS_GPIO_GPIO_E_BASE_ADDRESS,
|
2016-12-12 10:50:56 -06:00
|
|
|
.port_base = PORTE,
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_E_IRQ_0
|
2019-08-09 01:28:40 +02:00
|
|
|
.flags = GPIO_INT_ENABLE,
|
2017-04-01 14:52:47 -03:00
|
|
|
#else
|
|
|
|
.flags = 0,
|
|
|
|
#endif
|
2016-12-12 10:50:56 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct gpio_mcux_data gpio_mcux_porte_data;
|
|
|
|
|
2019-02-08 10:30:42 -06:00
|
|
|
DEVICE_AND_API_INIT(gpio_mcux_porte, DT_NXP_KINETIS_GPIO_GPIO_E_LABEL,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_porte_init,
|
|
|
|
&gpio_mcux_porte_data, &gpio_mcux_porte_config,
|
|
|
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
|
|
|
|
&gpio_mcux_driver_api);
|
|
|
|
|
|
|
|
static int gpio_mcux_porte_init(struct device *dev)
|
|
|
|
{
|
2019-06-19 12:55:29 -05:00
|
|
|
#ifdef DT_NXP_KINETIS_GPIO_GPIO_E_IRQ_0
|
|
|
|
IRQ_CONNECT(DT_NXP_KINETIS_GPIO_GPIO_E_IRQ_0, DT_NXP_KINETIS_GPIO_GPIO_E_IRQ_0_PRIORITY,
|
2016-12-12 10:50:56 -06:00
|
|
|
gpio_mcux_port_isr, DEVICE_GET(gpio_mcux_porte), 0);
|
|
|
|
|
2019-06-19 12:55:29 -05:00
|
|
|
irq_enable(DT_NXP_KINETIS_GPIO_GPIO_E_IRQ_0);
|
2017-04-01 14:52:47 -03:00
|
|
|
#endif
|
2019-02-22 15:01:42 -06:00
|
|
|
return 0;
|
2016-12-12 10:50:56 -06:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_MCUX_PORTE */
|