drivers: ieee802154_mcr20a: convert to new GPIO API

Convert MCR20A 802154 controller driver to new GPIO API.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
This commit is contained in:
Johann Fischer 2020-01-24 23:06:23 +01:00 committed by Carles Cufí
commit 3eecab88e6
3 changed files with 32 additions and 29 deletions

View file

@ -12,8 +12,9 @@
reg = <0x0>; reg = <0x0>;
label = "mcr20a"; label = "mcr20a";
spi-max-frequency = <4000000>; spi-max-frequency = <4000000>;
irqb-gpios = <&arduino_header 8 0>; /* D2 */ irqb-gpios = <&arduino_header 8
reset-gpios = <&arduino_header 11 0>; /* D5 */ (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; /* D2 */
reset-gpios = <&arduino_header 11 GPIO_ACTIVE_LOW>; /* D5 */
status = "okay"; status = "okay";
}; };
}; };

View file

@ -792,24 +792,16 @@ static inline void irqb_int_handler(struct device *port,
k_sem_give(&mcr20a->isr_sem); k_sem_give(&mcr20a->isr_sem);
} }
static inline void set_reset(struct device *dev, u32_t value)
{
struct mcr20a_context *mcr20a = dev->driver_data;
gpio_pin_write(mcr20a->reset_gpio,
DT_INST_0_NXP_MCR20A_RESET_GPIOS_PIN, value);
}
static void enable_irqb_interrupt(struct mcr20a_context *mcr20a, static void enable_irqb_interrupt(struct mcr20a_context *mcr20a,
bool enable) bool enable)
{ {
if (enable) { gpio_flags_t flags = enable
gpio_pin_enable_callback(mcr20a->irq_gpio, ? GPIO_INT_EDGE_TO_ACTIVE
DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN); : GPIO_INT_DISABLE;
} else {
gpio_pin_disable_callback(mcr20a->irq_gpio, gpio_pin_interrupt_configure(mcr20a->irq_gpio,
DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN); DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN,
} flags);
} }
static inline void setup_gpio_callbacks(struct mcr20a_context *mcr20a) static inline void setup_gpio_callbacks(struct mcr20a_context *mcr20a)
@ -1269,22 +1261,24 @@ static int power_on_and_setup(struct device *dev)
{ {
struct mcr20a_context *mcr20a = dev->driver_data; struct mcr20a_context *mcr20a = dev->driver_data;
u8_t timeout = 6U; u8_t timeout = 6U;
u32_t status; int pin;
u8_t tmp = 0U; u8_t tmp = 0U;
if (!PART_OF_KW2XD_SIP) { if (!PART_OF_KW2XD_SIP) {
set_reset(dev, 0); gpio_pin_set(mcr20a->reset_gpio,
DT_INST_0_NXP_MCR20A_RESET_GPIOS_PIN, 1);
z_usleep(150); z_usleep(150);
set_reset(dev, 1); gpio_pin_set(mcr20a->reset_gpio,
DT_INST_0_NXP_MCR20A_RESET_GPIOS_PIN, 0);
do { do {
z_usleep(50); z_usleep(50);
timeout--; timeout--;
gpio_pin_read(mcr20a->irq_gpio, pin = gpio_pin_get(mcr20a->irq_gpio,
DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN, &status); DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN);
} while (status && timeout); } while (pin > 0 && timeout);
if (status) { if (pin) {
LOG_ERR("Timeout, failed to get WAKE IRQ"); LOG_ERR("Timeout, failed to get WAKE IRQ");
return -EIO; return -EIO;
} }
@ -1344,9 +1338,7 @@ static inline int configure_gpios(struct device *dev)
gpio_pin_configure(mcr20a->irq_gpio, gpio_pin_configure(mcr20a->irq_gpio,
DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN, DT_INST_0_NXP_MCR20A_IRQB_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INPUT | DT_INST_0_NXP_MCR20A_IRQB_GPIOS_FLAGS);
GPIO_PUD_PULL_UP |
GPIO_INT_ACTIVE_LOW);
if (!PART_OF_KW2XD_SIP) { if (!PART_OF_KW2XD_SIP) {
/* setup gpio for the modems reset */ /* setup gpio for the modems reset */
@ -1361,8 +1353,8 @@ static inline int configure_gpios(struct device *dev)
gpio_pin_configure(mcr20a->reset_gpio, gpio_pin_configure(mcr20a->reset_gpio,
DT_INST_0_NXP_MCR20A_RESET_GPIOS_PIN, DT_INST_0_NXP_MCR20A_RESET_GPIOS_PIN,
GPIO_DIR_OUT); GPIO_OUTPUT_ACTIVE |
set_reset(dev, 0); DT_INST_0_NXP_MCR20A_RESET_GPIOS_FLAGS);
} }
return 0; return 0;

View file

@ -11,7 +11,17 @@ properties:
irqb-gpios: irqb-gpios:
type: phandle-array type: phandle-array
required: true required: true
description: Interrupt pin.
The interrupt pin of MCR20A is open-drain, active low.
If connected directly the MCU pin should be configured
as pull-up, active low.
reset-gpios: reset-gpios:
type: phandle-array type: phandle-array
required: true required: true
description: RESET pin.
The RESET pin of MCR20A is active low.
If connected directly the MCU pin should be configured
as active low.