From a652d003a2fd685bddbdb25e25d4bb5c1f3ab0f0 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Thu, 23 Jan 2020 00:51:00 +0100 Subject: [PATCH 1/2] drivers: enc424j600: convert to new GPIO API Convert ENC424J600 controller driver to new GPIO API. Signed-off-by: Johann Fischer --- .../shields/link_board_eth/link_board_eth.overlay | 2 +- drivers/ethernet/eth_enc424j600.c | 13 ++++++------- drivers/ethernet/eth_enc424j600_priv.h | 1 + dts/bindings/ethernet/microchip,enc424j600.yaml | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/boards/shields/link_board_eth/link_board_eth.overlay b/boards/shields/link_board_eth/link_board_eth.overlay index f157f89dc9f68..90cb78db509e7 100644 --- a/boards/shields/link_board_eth/link_board_eth.overlay +++ b/boards/shields/link_board_eth/link_board_eth.overlay @@ -11,7 +11,7 @@ enc424j600@0 { compatible = "microchip,enc424j600"; spi-max-frequency = <14000000>; - int-gpios = <&arduino_header 15 0>; /* D9 */ + int-gpios = <&arduino_header 15 GPIO_ACTIVE_LOW>; /* D9 */ status = "okay"; label = "ETH_0"; reg = <0>; diff --git a/drivers/ethernet/eth_enc424j600.c b/drivers/ethernet/eth_enc424j600.c index 792d174076eaf..aafaba95f0b54 100644 --- a/drivers/ethernet/eth_enc424j600.c +++ b/drivers/ethernet/eth_enc424j600.c @@ -630,10 +630,8 @@ static int enc424j600_init(struct device *dev) } if (gpio_pin_configure(context->gpio, config->gpio_pin, - (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE - | GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) { - LOG_ERR("Unable to configure GPIO pin %u", - config->gpio_pin); + GPIO_INPUT | config->gpio_flags)) { + LOG_ERR("Unable to configure GPIO pin %u", config->gpio_pin); return -EINVAL; } @@ -644,9 +642,9 @@ static int enc424j600_init(struct device *dev) return -EINVAL; } - if (gpio_pin_enable_callback(context->gpio, config->gpio_pin)) { - return -EINVAL; - } + gpio_pin_interrupt_configure(context->gpio, + config->gpio_pin, + GPIO_INT_EDGE_TO_ACTIVE); /* Check SPI connection */ do { @@ -756,6 +754,7 @@ static struct enc424j600_runtime enc424j600_0_runtime = { static const struct enc424j600_config enc424j600_0_config = { .gpio_port = DT_INST_0_MICROCHIP_ENC424J600_INT_GPIOS_CONTROLLER, .gpio_pin = DT_INST_0_MICROCHIP_ENC424J600_INT_GPIOS_PIN, + .gpio_flags = DT_INST_0_MICROCHIP_ENC424J600_INT_GPIOS_FLAGS, .spi_port = DT_INST_0_MICROCHIP_ENC424J600_BUS_NAME, .spi_freq = DT_INST_0_MICROCHIP_ENC424J600_SPI_MAX_FREQUENCY, .spi_slave = DT_INST_0_MICROCHIP_ENC424J600_BASE_ADDRESS, diff --git a/drivers/ethernet/eth_enc424j600_priv.h b/drivers/ethernet/eth_enc424j600_priv.h index 2fdba54b95bed..304000341164e 100644 --- a/drivers/ethernet/eth_enc424j600_priv.h +++ b/drivers/ethernet/eth_enc424j600_priv.h @@ -275,6 +275,7 @@ struct enc424j600_config { const char *gpio_port; u8_t gpio_pin; + gpio_devicetree_flags_t gpio_flags; const char *spi_port; u8_t spi_cs_pin; const char *spi_cs_port; diff --git a/dts/bindings/ethernet/microchip,enc424j600.yaml b/dts/bindings/ethernet/microchip,enc424j600.yaml index e890f29245fc9..db1d5d7cdc5f6 100644 --- a/dts/bindings/ethernet/microchip,enc424j600.yaml +++ b/dts/bindings/ethernet/microchip,enc424j600.yaml @@ -12,3 +12,8 @@ properties: int-gpios: type: phandle-array required: true + description: Interrupt pin. + + The interrupt pin of ENC424J600 is active low. + If connected directly the MCU pin should be configured + as active low. From c532850c2c95a9870e5898b11e66f0c509d47cb3 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Thu, 23 Jan 2020 00:56:28 +0100 Subject: [PATCH 2/2] drivers: enc28j60: convert to new GPIO API Convert ENC28J60 controller driver to new GPIO API. Signed-off-by: Johann Fischer --- drivers/ethernet/eth_enc28j60.c | 13 ++++++------- drivers/ethernet/eth_enc28j60_priv.h | 1 + dts/bindings/ethernet/microchip,enc28j60.yaml | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/ethernet/eth_enc28j60.c b/drivers/ethernet/eth_enc28j60.c index abe4e44cd217d..adc7939b08380 100644 --- a/drivers/ethernet/eth_enc28j60.c +++ b/drivers/ethernet/eth_enc28j60.c @@ -694,10 +694,8 @@ static int eth_enc28j60_init(struct device *dev) } if (gpio_pin_configure(context->gpio, config->gpio_pin, - (GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE - | GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) { - LOG_ERR("Unable to configure GPIO pin %u", - config->gpio_pin); + GPIO_INPUT | config->gpio_flags)) { + LOG_ERR("Unable to configure GPIO pin %u", config->gpio_pin); return -EINVAL; } @@ -708,9 +706,9 @@ static int eth_enc28j60_init(struct device *dev) return -EINVAL; } - if (gpio_pin_enable_callback(context->gpio, config->gpio_pin)) { - return -EINVAL; - } + gpio_pin_interrupt_configure(context->gpio, + config->gpio_pin, + GPIO_INT_EDGE_TO_ACTIVE); if (eth_enc28j60_soft_reset(dev)) { LOG_ERR("Soft-reset failed"); @@ -763,6 +761,7 @@ static struct eth_enc28j60_runtime eth_enc28j60_0_runtime = { static const struct eth_enc28j60_config eth_enc28j60_0_config = { .gpio_port = DT_INST_0_MICROCHIP_ENC28J60_INT_GPIOS_CONTROLLER, .gpio_pin = DT_INST_0_MICROCHIP_ENC28J60_INT_GPIOS_PIN, + .gpio_flags = DT_INST_0_MICROCHIP_ENC28J60_INT_GPIOS_FLAGS, .spi_port = DT_INST_0_MICROCHIP_ENC28J60_BUS_NAME, .spi_freq = DT_INST_0_MICROCHIP_ENC28J60_SPI_MAX_FREQUENCY, .spi_slave = DT_INST_0_MICROCHIP_ENC28J60_BASE_ADDRESS, diff --git a/drivers/ethernet/eth_enc28j60_priv.h b/drivers/ethernet/eth_enc28j60_priv.h index dbbb356cec714..a0fff3b7003bc 100644 --- a/drivers/ethernet/eth_enc28j60_priv.h +++ b/drivers/ethernet/eth_enc28j60_priv.h @@ -216,6 +216,7 @@ struct eth_enc28j60_config { const char *gpio_port; u8_t gpio_pin; + gpio_devicetree_flags_t gpio_flags; const char *spi_port; u8_t spi_cs_pin; const char *spi_cs_port; diff --git a/dts/bindings/ethernet/microchip,enc28j60.yaml b/dts/bindings/ethernet/microchip,enc28j60.yaml index 8a285339767c4..9e500e4b7d5cd 100644 --- a/dts/bindings/ethernet/microchip,enc28j60.yaml +++ b/dts/bindings/ethernet/microchip,enc28j60.yaml @@ -11,3 +11,8 @@ properties: int-gpios: type: phandle-array required: true + description: Interrupt pin. + + The interrupt pin of ENC28J60 is active low. + If connected directly the MCU pin should be configured + as active low.