2016-12-12 17:50:56 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Freescale Semiconductor, Inc.
|
2023-01-18 00:19:41 +01:00
|
|
|
* Copyright 2017, 2023-2024 NXP
|
2016-12-12 17:50:56 +01:00
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-12-12 17:50:56 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-24 20:11:52 +01:00
|
|
|
#define DT_DRV_COMPAT nxp_kinetis_gpio
|
|
|
|
|
2016-12-12 17:50:56 +01:00
|
|
|
#include <errno.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/drivers/gpio.h>
|
|
|
|
#include <zephyr/dt-bindings/gpio/nxp-kinetis-gpio.h>
|
2022-10-04 15:33:53 +02:00
|
|
|
#include <zephyr/irq.h>
|
2016-12-12 17:50:56 +01:00
|
|
|
#include <soc.h>
|
|
|
|
#include <fsl_common.h>
|
|
|
|
|
2022-10-21 20:18:01 +02:00
|
|
|
#include <zephyr/drivers/gpio/gpio_utils.h>
|
2016-12-12 17:50:56 +01:00
|
|
|
|
|
|
|
struct gpio_mcux_config {
|
2019-12-11 17:48:42 +01:00
|
|
|
/* gpio_driver_config needs to be first */
|
|
|
|
struct gpio_driver_config common;
|
2016-12-12 17:50:56 +01:00
|
|
|
GPIO_Type *gpio_base;
|
|
|
|
PORT_Type *port_base;
|
2017-04-01 19:52:47 +02:00
|
|
|
unsigned int flags;
|
2016-12-12 17:50:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gpio_mcux_data {
|
2019-09-18 15:23:18 +02:00
|
|
|
/* gpio_driver_data needs to be first */
|
|
|
|
struct gpio_driver_data common;
|
2016-12-12 17:50:56 +01:00
|
|
|
/* port ISR callback routine address */
|
|
|
|
sys_slist_t callbacks;
|
|
|
|
};
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_configure(const struct device *dev,
|
2020-01-30 19:12:39 +01:00
|
|
|
gpio_pin_t pin, gpio_flags_t flags)
|
2016-12-12 17:50:56 +01:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2016-12-12 17:50:56 +01:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
PORT_Type *port_base = config->port_base;
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t mask = 0U;
|
|
|
|
uint32_t pcr = 0U;
|
2016-12-12 17:50:56 +01:00
|
|
|
|
2019-01-30 23:52:34 +01: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 17:50:56 +01: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 16:31:07 +01: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 17:50:56 +01:00
|
|
|
}
|
2020-01-30 16:31:07 +01:00
|
|
|
gpio_base->PDDR |= BIT(pin);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
2016-12-12 17:50:56 +01:00
|
|
|
}
|
|
|
|
|
2021-04-02 19:15:30 +02:00
|
|
|
/* Set PCR mux to GPIO for the pin we are configuring */
|
|
|
|
mask |= PORT_PCR_MUX_MASK;
|
2023-03-29 21:35:50 +02:00
|
|
|
pcr |= PORT_PCR_MUX(PORT_MUX_GPIO);
|
|
|
|
|
|
|
|
#if defined(FSL_FEATURE_PORT_HAS_INPUT_BUFFER) && FSL_FEATURE_PORT_HAS_INPUT_BUFFER
|
|
|
|
/* Enable digital input buffer */
|
|
|
|
pcr |= PORT_PCR_IBE_MASK;
|
|
|
|
#endif
|
2021-04-02 19:15:30 +02:00
|
|
|
|
2016-12-12 17:50:56 +01: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 17:50:56 +01: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) {
|
2023-01-18 00:19:41 +01:00
|
|
|
/* Enable the pull and select the pulldown resistor, deselect
|
2016-12-12 17:50:56 +01:00
|
|
|
* the pullup resistor.
|
|
|
|
*/
|
|
|
|
pcr |= PORT_PCR_PE_MASK;
|
|
|
|
}
|
|
|
|
|
2021-10-27 14:44:36 +02:00
|
|
|
#if defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH
|
|
|
|
/* Determine the drive strength */
|
2021-10-27 14:52:31 +02:00
|
|
|
switch (flags & KINETIS_GPIO_DS_MASK) {
|
|
|
|
case KINETIS_GPIO_DS_DFLT:
|
2021-10-27 14:44:36 +02:00
|
|
|
/* Default is low drive strength */
|
|
|
|
mask |= PORT_PCR_DSE_MASK;
|
|
|
|
break;
|
2021-10-27 14:52:31 +02:00
|
|
|
case KINETIS_GPIO_DS_ALT:
|
2021-10-27 14:44:36 +02:00
|
|
|
/* Alternate is high drive strength */
|
|
|
|
pcr |= PORT_PCR_DSE_MASK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
#endif /* defined(FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH) && FSL_FEATURE_PORT_HAS_DRIVE_STRENGTH */
|
|
|
|
|
2020-01-30 16:31:07 +01: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 17:50:56 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_port_get_raw(const struct device *dev, uint32_t *value)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2019-08-09 01:28:40 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
*value = gpio_base->PDIR;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_port_set_masked_raw(const struct device *dev,
|
|
|
|
uint32_t mask,
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_t value)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2019-08-09 01:28:40 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PDOR = (gpio_base->PDOR & ~mask) | (mask & value);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_port_set_bits_raw(const struct device *dev,
|
|
|
|
uint32_t mask)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2019-08-09 01:28:40 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PSOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_port_clear_bits_raw(const struct device *dev,
|
|
|
|
uint32_t mask)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2019-08-09 01:28:40 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PCOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_port_toggle_bits(const struct device *dev, uint32_t mask)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2019-08-09 01:28:40 +02:00
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
gpio_base->PTOR = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-18 00:19:41 +01:00
|
|
|
#if !(defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
|
2020-04-30 20:33:38 +02:00
|
|
|
static uint32_t get_port_pcr_irqc_value_from_flags(const struct device *dev,
|
|
|
|
uint32_t pin,
|
|
|
|
enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
2019-10-16 03:20:41 +02:00
|
|
|
{
|
|
|
|
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;
|
2023-12-15 20:19:40 +01:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2019-10-16 03:20:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PORT_PCR_IRQC(port_interrupt);
|
|
|
|
}
|
2023-01-18 00:19:41 +01:00
|
|
|
#endif /* !defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT */
|
|
|
|
|
|
|
|
#if (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT) && \
|
|
|
|
FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT)
|
|
|
|
|
|
|
|
#define GPIO_MCUX_INTERRUPT_DISABLED 0
|
|
|
|
#define GPIO_MCUX_INTERRUPT_LOGIC_0 0x8
|
|
|
|
#define GPIO_MCUX_INTERRUPT_RISING_EDGE 0x9
|
|
|
|
#define GPIO_MCUX_INTERRUPT_FALLING_EDGE 0xA
|
|
|
|
#define GPIO_MCUX_INTERRUPT_BOTH_EDGE 0xB
|
|
|
|
#define GPIO_MCUX_INTERRUPT_LOGIC_1 0xC
|
|
|
|
|
|
|
|
static uint32_t get_gpio_icr_irqc_value_from_flags(const struct device *dev,
|
|
|
|
uint32_t pin,
|
|
|
|
enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
|
|
|
{
|
|
|
|
uint8_t gpio_interrupt = 0;
|
|
|
|
|
|
|
|
if (mode == GPIO_INT_MODE_DISABLED) {
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_DISABLED;
|
|
|
|
} else {
|
|
|
|
if (mode == GPIO_INT_MODE_LEVEL) {
|
|
|
|
if (trig == GPIO_INT_TRIG_LOW) {
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_LOGIC_0;
|
|
|
|
} else {
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_LOGIC_1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (trig) {
|
|
|
|
case GPIO_INT_TRIG_LOW:
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_FALLING_EDGE;
|
|
|
|
break;
|
|
|
|
case GPIO_INT_TRIG_HIGH:
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_RISING_EDGE;
|
|
|
|
break;
|
|
|
|
case GPIO_INT_TRIG_BOTH:
|
|
|
|
gpio_interrupt = GPIO_MCUX_INTERRUPT_BOTH_EDGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GPIO_ICR_IRQC(gpio_interrupt);
|
|
|
|
}
|
|
|
|
#endif /* (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT) */
|
2019-10-16 03:20:41 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_pin_interrupt_configure(const struct device *dev,
|
2020-01-30 19:12:39 +01:00
|
|
|
gpio_pin_t pin, enum gpio_int_mode mode,
|
|
|
|
enum gpio_int_trig trig)
|
2019-08-09 01:28:40 +02:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
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;
|
|
|
|
|
|
|
|
/* 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 15:23:18 +02:00
|
|
|
if ((mode != GPIO_INT_MODE_DISABLED) &&
|
2019-08-09 01:28:40 +02:00
|
|
|
((config->flags & GPIO_INT_ENABLE) == 0U)) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2023-01-18 00:19:41 +01:00
|
|
|
#if !(defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
|
2020-05-27 18:26:57 +02:00
|
|
|
uint32_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;
|
2023-01-18 00:19:41 +01:00
|
|
|
#elif (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT) && \
|
|
|
|
FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT)
|
|
|
|
uint32_t icr = get_gpio_icr_irqc_value_from_flags(dev, pin, mode, trig);
|
|
|
|
|
|
|
|
gpio_base->ICR[pin] = (gpio_base->ICR[pin] & ~GPIO_ICR_IRQC_MASK) | icr;
|
|
|
|
#endif /* !(defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) */
|
2019-08-09 01:28:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int gpio_mcux_manage_callback(const struct device *dev,
|
2016-12-12 17:50:56 +01:00
|
|
|
struct gpio_callback *callback, bool set)
|
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct gpio_mcux_data *data = dev->data;
|
2016-12-12 17:50:56 +01:00
|
|
|
|
2019-03-12 22:15:42 +01:00
|
|
|
return gpio_manage_callback(&data->callbacks, callback, set);
|
2016-12-12 17:50:56 +01:00
|
|
|
}
|
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 14:58:56 +02:00
|
|
|
static void gpio_mcux_port_isr(const struct device *dev)
|
2016-12-12 17:50:56 +01:00
|
|
|
{
|
2020-05-28 20:44:16 +02:00
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
2020-05-28 21:23:02 +02:00
|
|
|
struct gpio_mcux_data *data = dev->data;
|
2020-06-13 02:07:29 +02:00
|
|
|
uint32_t int_status;
|
2016-12-12 17:50:56 +01:00
|
|
|
|
2023-01-18 00:19:41 +01:00
|
|
|
#if !(defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) && FSL_FEATURE_PORT_HAS_NO_INTERRUPT)
|
2016-12-12 17:50:56 +01:00
|
|
|
int_status = config->port_base->ISFR;
|
|
|
|
|
|
|
|
/* Clear the port interrupts */
|
2020-06-13 02:07:29 +02:00
|
|
|
config->port_base->ISFR = int_status;
|
2023-01-18 00:19:41 +01:00
|
|
|
#elif (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT) && \
|
|
|
|
FSL_FEATURE_GPIO_HAS_INTERRUPT_CHANNEL_SELECT)
|
|
|
|
int_status = config->gpio_base->ISFR[0];
|
|
|
|
|
|
|
|
/* Clear the gpio interrupts */
|
|
|
|
config->gpio_base->ISFR[0] = int_status;
|
|
|
|
#endif /* !(defined(FSL_FEATURE_PORT_HAS_NO_INTERRUPT) */
|
2019-09-24 00:47:31 +02:00
|
|
|
|
2020-06-13 02:07:29 +02:00
|
|
|
gpio_fire_callbacks(&data->callbacks, dev, int_status);
|
2016-12-12 17:50:56 +01:00
|
|
|
}
|
|
|
|
|
2022-06-17 17:07:41 +02:00
|
|
|
#ifdef CONFIG_GPIO_GET_DIRECTION
|
|
|
|
static int gpio_mcux_port_get_direction(const struct device *dev, gpio_port_pins_t map,
|
|
|
|
gpio_port_pins_t *inputs, gpio_port_pins_t *outputs)
|
|
|
|
{
|
|
|
|
const struct gpio_mcux_config *config = dev->config;
|
|
|
|
GPIO_Type *gpio_base = config->gpio_base;
|
|
|
|
|
|
|
|
map &= config->common.port_pin_mask;
|
|
|
|
|
|
|
|
if (inputs != NULL) {
|
|
|
|
*inputs = map & (~gpio_base->PDDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outputs != NULL) {
|
|
|
|
*outputs = map & gpio_base->PDDR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_GPIO_GET_DIRECTION */
|
2016-12-12 17:50:56 +01:00
|
|
|
|
|
|
|
static const struct gpio_driver_api gpio_mcux_driver_api = {
|
2020-01-30 19:12:39 +01:00
|
|
|
.pin_configure = 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 17:50:56 +01:00
|
|
|
.manage_callback = gpio_mcux_manage_callback,
|
2022-06-17 17:07:41 +02:00
|
|
|
#ifdef CONFIG_GPIO_GET_DIRECTION
|
|
|
|
.port_get_direction = gpio_mcux_port_get_direction,
|
|
|
|
#endif /* CONFIG_GPIO_GET_DIRECTION */
|
2016-12-12 17:50:56 +01:00
|
|
|
};
|
|
|
|
|
2020-02-12 19:34:35 +01:00
|
|
|
#define GPIO_MCUX_IRQ_INIT(n) \
|
|
|
|
do { \
|
|
|
|
IRQ_CONNECT(DT_INST_IRQN(n), \
|
|
|
|
DT_INST_IRQ(n, priority), \
|
|
|
|
gpio_mcux_port_isr, \
|
2020-12-10 17:20:42 +01:00
|
|
|
DEVICE_DT_INST_GET(n), 0); \
|
2020-02-12 19:34:35 +01:00
|
|
|
\
|
|
|
|
irq_enable(DT_INST_IRQN(n)); \
|
2022-07-20 08:37:40 +02:00
|
|
|
} while (false)
|
2020-02-12 19:34:35 +01:00
|
|
|
|
|
|
|
#define GPIO_PORT_BASE_ADDR(n) DT_REG_ADDR(DT_INST_PHANDLE(n, nxp_kinetis_port))
|
|
|
|
|
|
|
|
#define GPIO_DEVICE_INIT_MCUX(n) \
|
2020-07-14 17:02:00 +02:00
|
|
|
static int gpio_mcux_port## n ## _init(const struct device *dev); \
|
2020-02-12 19:34:35 +01:00
|
|
|
\
|
|
|
|
static const struct gpio_mcux_config gpio_mcux_port## n ## _config = {\
|
|
|
|
.common = { \
|
|
|
|
.port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n),\
|
|
|
|
}, \
|
|
|
|
.gpio_base = (GPIO_Type *) DT_INST_REG_ADDR(n), \
|
|
|
|
.port_base = (PORT_Type *) GPIO_PORT_BASE_ADDR(n), \
|
|
|
|
.flags = UTIL_AND(DT_INST_IRQ_HAS_IDX(n, 0), GPIO_INT_ENABLE),\
|
|
|
|
}; \
|
|
|
|
\
|
|
|
|
static struct gpio_mcux_data gpio_mcux_port## n ##_data; \
|
|
|
|
\
|
2020-12-10 17:20:42 +01:00
|
|
|
DEVICE_DT_INST_DEFINE(n, \
|
2020-02-12 19:34:35 +01:00
|
|
|
gpio_mcux_port## n ##_init, \
|
2021-04-28 10:55:48 +02:00
|
|
|
NULL, \
|
2020-02-12 19:34:35 +01:00
|
|
|
&gpio_mcux_port## n ##_data, \
|
|
|
|
&gpio_mcux_port## n##_config, \
|
|
|
|
POST_KERNEL, \
|
2021-11-05 22:58:21 +01:00
|
|
|
CONFIG_GPIO_INIT_PRIORITY, \
|
2020-02-12 19:34:35 +01:00
|
|
|
&gpio_mcux_driver_api); \
|
|
|
|
\
|
2020-07-14 17:02:00 +02:00
|
|
|
static int gpio_mcux_port## n ##_init(const struct device *dev) \
|
2020-02-12 19:34:35 +01:00
|
|
|
{ \
|
|
|
|
IF_ENABLED(DT_INST_IRQ_HAS_IDX(n, 0), \
|
|
|
|
(GPIO_MCUX_IRQ_INIT(n);)) \
|
|
|
|
return 0; \
|
|
|
|
}
|
2016-12-12 17:50:56 +01:00
|
|
|
|
2020-05-06 20:23:07 +02:00
|
|
|
DT_INST_FOREACH_STATUS_OKAY(GPIO_DEVICE_INIT_MCUX)
|