Skip to content

Commit 1c940f7

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 b40fb04 commit 1c940f7

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

drivers/ethernet/eth_lan9250.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,17 +679,48 @@ 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+
return ret;
690693
}
691694

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

694725
/* Reset and wait for ready on the LAN9250 SPI device */
695726
ret = lan9250_sw_reset(dev);
@@ -727,6 +758,7 @@ static int lan9250_init(const struct device *dev)
727758
static const struct lan9250_config lan9250_##inst##_config = { \
728759
.spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8)), \
729760
.interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
761+
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
730762
.timeout = CONFIG_ETH_LAN9250_BUF_ALLOC_TIMEOUT, \
731763
.random_mac = DT_INST_PROP(inst, zephyr_random_mac_address), \
732764
}; \

0 commit comments

Comments
 (0)