@@ -678,17 +678,49 @@ static int lan9250_init(const struct device *dev)
678678 return - EINVAL ;
679679 }
680680
681- if (gpio_pin_configure_dt (& config -> interrupt , GPIO_INPUT )) {
681+ ret = gpio_pin_configure_dt (& config -> interrupt , GPIO_INPUT );
682+ if (ret < 0 ) {
682683 LOG_ERR ("Unable to configure GPIO pin %u" , config -> interrupt .pin );
683- return - EINVAL ;
684+ return ret ;
684685 }
685686
686- gpio_init_callback (& (context -> gpio_cb ), lan9250_gpio_callback , BIT (config -> interrupt .pin ));
687- if (gpio_add_callback (config -> interrupt .port , & (context -> gpio_cb ))) {
688- return - EINVAL ;
687+ gpio_init_callback (& (context -> gpio_cb ), lan9250_gpio_callback ,
688+ BIT (config -> interrupt .pin ));
689+ ret = gpio_add_callback (config -> interrupt .port , & context -> gpio_cb );
690+ if (ret < 0 ) {
691+ LOG_ERR ("Unable to add GPIO callback %u" , config -> interrupt .pin );
692+ return ret ;
689693 }
690694
691- 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+ }
692724
693725 /* Reset and wait for ready on the LAN9250 SPI device */
694726 ret = lan9250_sw_reset (dev );
@@ -720,6 +752,7 @@ static int lan9250_init(const struct device *dev)
720752 static const struct lan9250_config lan9250_##inst##_config = { \
721753 .spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8)), \
722754 .interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
755+ .reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, {0}), \
723756 .timeout = CONFIG_ETH_LAN9250_BUF_ALLOC_TIMEOUT, \
724757 .mac_cfg = NET_ETH_MAC_DT_INST_CONFIG_INIT(inst), \
725758 }; \
0 commit comments