Skip to content

Commit 93dac9c

Browse files
committed
drivers: ethernet: lan9250: add in the reset gpio configurate
The reset gpio field was in the config structure but was not coded into the initialization path. So, add the appropriate code to handle the gpio setup when it is defined in the device tree. Signed-off-by: Charles Hardin <ckhardin@gmail.com>
1 parent a78fbb3 commit 93dac9c

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

drivers/ethernet/eth_lan9250.c

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,17 +679,49 @@ static int lan9250_init(const struct device *dev)
679679
return -EINVAL;
680680
}
681681

682-
if (gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT)) {
682+
ret = gpio_pin_configure_dt(&config->interrupt, GPIO_INPUT);
683+
if (ret < 0) {
683684
LOG_ERR("Unable to configure GPIO pin %u", config->interrupt.pin);
684-
return -EINVAL;
685+
return ret;
685686
}
686687

687-
gpio_init_callback(&(context->gpio_cb), lan9250_gpio_callback, BIT(config->interrupt.pin));
688-
if (gpio_add_callback(config->interrupt.port, &(context->gpio_cb))) {
689-
return -EINVAL;
688+
gpio_init_callback(&(context->gpio_cb), lan9250_gpio_callback,
689+
BIT(config->interrupt.pin));
690+
ret = gpio_add_callback(config->interrupt.port, &context->gpio_cb);
691+
if (ret < 0) {
692+
LOG_ERR("Unable to add GPIO callback %u", config->interrupt.pin);
693+
return ret;
690694
}
691695

692-
gpio_pin_interrupt_configure_dt(&config->interrupt, GPIO_INT_EDGE_TO_ACTIVE);
696+
ret = gpio_pin_interrupt_configure_dt(&config->interrupt,
697+
GPIO_INT_EDGE_TO_ACTIVE);
698+
if (ret < 0) {
699+
LOG_ERR("Unable to enable GPIO INT %u", config->interrupt.pin);
700+
return ret;
701+
}
702+
703+
if (config->reset.port != NULL) {
704+
if (!gpio_is_ready_dt(&config->reset)) {
705+
LOG_ERR("GPIO port %s not ready", config->reset.port->name);
706+
return -EINVAL;
707+
}
708+
709+
ret = gpio_pin_configure_dt(&config->reset, GPIO_OUTPUT);
710+
if (ret < 0) {
711+
LOG_ERR("Unable to configure GPIO pin %u", config->reset.pin);
712+
return ret;
713+
}
714+
715+
/* See Section 19.6.3 from the LAN9250 Data Sheet
716+
*
717+
* trstia is 200 microseconds min (use 250 us)
718+
* tcfg is 15 milliseconds min (use 20 ms for after reset)
719+
*/
720+
gpio_pin_set_dt(&config->reset, 1);
721+
k_usleep(250);
722+
gpio_pin_set_dt(&config->reset, 0);
723+
k_msleep(20);
724+
}
693725

694726
/* Reset and wait for ready on the LAN9250 SPI device */
695727
ret = lan9250_sw_reset(dev);
@@ -727,6 +759,7 @@ static int lan9250_init(const struct device *dev)
727759
static const struct lan9250_config lan9250_##inst##_config = { \
728760
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8)), \
729761
.interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
762+
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
730763
.timeout = CONFIG_ETH_LAN9250_BUF_ALLOC_TIMEOUT, \
731764
.random_mac = DT_INST_PROP(inst, zephyr_random_mac_address), \
732765
}; \

0 commit comments

Comments
 (0)