@@ -74,7 +74,7 @@ static void eth_enc28j60_set_bank(const struct device *dev, uint16_t reg_addr)
7474
7575 spi_write_dt (& config -> spi , & tx );
7676 } else {
77- LOG_DBG ("Failure while setting bank to 0x%04x" , reg_addr );
77+ LOG_DBG ("%s: Failure while setting bank to 0x%04x" , dev -> name , reg_addr );
7878 }
7979}
8080
@@ -133,7 +133,7 @@ static void eth_enc28j60_read_reg(const struct device *dev, uint16_t reg_addr,
133133 if (!spi_transceive_dt (& config -> spi , & tx , & rx )) {
134134 * value = buf [rx_size - 1 ];
135135 } else {
136- LOG_DBG ("Failure while reading register 0x%04x" , reg_addr );
136+ LOG_DBG ("%s: Failure while reading register 0x%04x" , dev -> name , reg_addr );
137137 * value = 0U ;
138138 }
139139}
@@ -209,7 +209,7 @@ static void eth_enc28j60_write_mem(const struct device *dev,
209209 tx_buf [1 ].len = MAX_BUFFER_LENGTH ;
210210
211211 if (spi_write_dt (& config -> spi , & tx )) {
212- LOG_ERR ("Failed to write memory" );
212+ LOG_ERR ("%s: Failed to write memory" , dev -> name );
213213 return ;
214214 }
215215 }
@@ -219,7 +219,7 @@ static void eth_enc28j60_write_mem(const struct device *dev,
219219 tx_buf [1 ].len = num_remaining ;
220220
221221 if (spi_write_dt (& config -> spi , & tx )) {
222- LOG_ERR ("Failed to write memory" );
222+ LOG_ERR ("%s: Failed to write memory" , dev -> name );
223223 }
224224 }
225225}
@@ -261,7 +261,7 @@ static void eth_enc28j60_read_mem(const struct device *dev,
261261 rx_buf [1 ].len = MAX_BUFFER_LENGTH ;
262262
263263 if (spi_transceive_dt (& config -> spi , & tx , & rx )) {
264- LOG_ERR ("Failed to read memory" );
264+ LOG_ERR ("%s: Failed to read memory" , dev -> name );
265265 return ;
266266 }
267267 }
@@ -271,7 +271,7 @@ static void eth_enc28j60_read_mem(const struct device *dev,
271271 rx_buf [1 ].len = num_remaining ;
272272
273273 if (spi_transceive_dt (& config -> spi , & tx , & rx )) {
274- LOG_ERR ("Failed to read memory" );
274+ LOG_ERR ("%s: Failed to read memory" , dev -> name );
275275 }
276276 }
277277}
@@ -476,7 +476,7 @@ static int eth_enc28j60_tx(const struct device *dev, struct net_pkt *pkt)
476476 struct net_buf * frag ;
477477 uint8_t tx_end ;
478478
479- LOG_DBG ("pkt %p (len %u)" , pkt , len );
479+ LOG_DBG ("%s: pkt %p (len %u)" , dev -> name , pkt , len );
480480
481481 k_sem_take (& context -> tx_rx_sem , K_FOREVER );
482482
@@ -530,11 +530,11 @@ static int eth_enc28j60_tx(const struct device *dev, struct net_pkt *pkt)
530530 k_sem_give (& context -> tx_rx_sem );
531531
532532 if (tx_end & ENC28J60_BIT_ESTAT_TXABRT ) {
533- LOG_ERR ("TX failed!" );
533+ LOG_ERR ("%s: TX failed!" , dev -> name );
534534 return - EIO ;
535535 }
536536
537- LOG_DBG ("Tx successful" );
537+ LOG_DBG ("%s: Tx successful" , dev -> name );
538538
539539 return 0 ;
540540}
@@ -553,7 +553,7 @@ static void enc28j60_read_packet(const struct device *dev, uint16_t *vlan_tag,
553553 pkt = net_pkt_rx_alloc_with_buffer (get_iface (context , * vlan_tag ), frm_len ,
554554 AF_UNSPEC , 0 , K_MSEC (config -> timeout ));
555555 if (!pkt ) {
556- LOG_ERR ("Could not allocate rx buffer" );
556+ LOG_ERR ("%s: Could not allocate rx buffer" , dev -> name );
557557 eth_stats_update_errors_rx (get_iface (context , * vlan_tag ));
558558 return ;
559559 }
@@ -620,7 +620,7 @@ static void enc28j60_read_packet(const struct device *dev, uint16_t *vlan_tag,
620620#endif /* CONFIG_NET_VLAN */
621621
622622 /* Feed buffer frame to IP stack */
623- LOG_DBG ("Received packet of length %u" , lengthfr );
623+ LOG_DBG ("%s: Received packet of length %u" , dev -> name , lengthfr );
624624 if (net_recv_data (net_pkt_iface (pkt ), pkt ) < 0 ) {
625625 net_pkt_unref (pkt );
626626 }
@@ -722,10 +722,10 @@ static void eth_enc28j60_rx_thread(const struct device *dev)
722722 eth_enc28j60_read_phy (dev , ENC28J60_PHY_PHIR , & phir );
723723 eth_enc28j60_read_phy (dev , ENC28J60_PHY_PHSTAT2 , & phstat2 );
724724 if (phstat2 & ENC28J60_BIT_PHSTAT2_LSTAT ) {
725- LOG_INF ("Link up" );
725+ LOG_INF ("%s: Link up" , dev -> name );
726726 net_eth_carrier_on (context -> iface );
727727 } else {
728- LOG_INF ("Link down" );
728+ LOG_INF ("%s: Link down" , dev -> name );
729729
730730 if (context -> iface_initialized ) {
731731 net_eth_carrier_off (context -> iface );
@@ -783,19 +783,18 @@ static int eth_enc28j60_init(const struct device *dev)
783783
784784 /* SPI config */
785785 if (!spi_is_ready_dt (& config -> spi )) {
786- LOG_ERR ("SPI master port %s not ready" , config -> spi .bus -> name );
786+ LOG_ERR ("%s: SPI master port %s not ready" , dev -> name , config -> spi .bus -> name );
787787 return - EINVAL ;
788788 }
789789
790790 /* Initialize GPIO */
791791 if (!device_is_ready (config -> interrupt .port )) {
792- LOG_ERR ("GPIO port %s not ready" , config -> interrupt .port -> name );
792+ LOG_ERR ("%s: GPIO port %s not ready" , dev -> name , config -> interrupt .port -> name );
793793 return - EINVAL ;
794794 }
795795
796796 if (gpio_pin_configure_dt (& config -> interrupt , GPIO_INPUT )) {
797- LOG_ERR ("Unable to configure GPIO pin %u" ,
798- config -> interrupt .pin );
797+ LOG_ERR ("%s: Unable to configure GPIO pin %u" , dev -> name , config -> interrupt .pin );
799798 return - EINVAL ;
800799 }
801800
@@ -810,7 +809,7 @@ static int eth_enc28j60_init(const struct device *dev)
810809 GPIO_INT_EDGE_TO_ACTIVE );
811810
812811 if (eth_enc28j60_soft_reset (dev )) {
813- LOG_ERR ("Soft-reset failed" );
812+ LOG_ERR ("%s: Soft-reset failed" , dev -> name );
814813 return - EIO ;
815814 }
816815
@@ -845,31 +844,28 @@ static int eth_enc28j60_init(const struct device *dev)
845844 K_PRIO_COOP (CONFIG_ETH_ENC28J60_RX_THREAD_PRIO ),
846845 0 , K_NO_WAIT );
847846
848- LOG_INF ("ENC28J60 Initialized" );
847+ LOG_INF ("%s: Initialized" , dev -> name );
849848
850849 return 0 ;
851850}
852851
853- #ifdef CONFIG_ETH_ENC28J60_0
854-
855- static struct eth_enc28j60_runtime eth_enc28j60_0_runtime = {
856- .mac_address = DT_INST_PROP (0 , local_mac_address ),
857- .tx_rx_sem = Z_SEM_INITIALIZER (eth_enc28j60_0_runtime .tx_rx_sem ,
858- 1 , UINT_MAX ),
859- .int_sem = Z_SEM_INITIALIZER (eth_enc28j60_0_runtime .int_sem ,
860- 0 , UINT_MAX ),
861- };
862-
863- static const struct eth_enc28j60_config eth_enc28j60_0_config = {
864- .spi = SPI_DT_SPEC_INST_GET (0 , SPI_WORD_SET (8 ), 0 ),
865- .interrupt = GPIO_DT_SPEC_INST_GET (0 , int_gpios ),
866- .full_duplex = DT_INST_PROP (0 , full_duplex ),
867- .timeout = CONFIG_ETH_ENC28J60_TIMEOUT ,
868- };
869-
870- ETH_NET_DEVICE_DT_INST_DEFINE (0 ,
871- eth_enc28j60_init , NULL ,
872- & eth_enc28j60_0_runtime , & eth_enc28j60_0_config ,
873- CONFIG_ETH_INIT_PRIORITY , & api_funcs , NET_ETH_MTU );
874-
875- #endif /* CONFIG_ETH_ENC28J60_0 */
852+ #define ENC28J60_DEFINE (inst ) \
853+ static struct eth_enc28j60_runtime eth_enc28j60_runtime_##inst = { \
854+ .mac_address = DT_INST_PROP(inst, local_mac_address), \
855+ .tx_rx_sem = \
856+ Z_SEM_INITIALIZER((eth_enc28j60_runtime_##inst).tx_rx_sem, 1, UINT_MAX), \
857+ .int_sem = Z_SEM_INITIALIZER((eth_enc28j60_runtime_##inst).int_sem, 0, UINT_MAX), \
858+ }; \
859+ \
860+ static const struct eth_enc28j60_config eth_enc28j60_config_##inst = { \
861+ .spi = SPI_DT_SPEC_INST_GET(inst, SPI_WORD_SET(8), 0), \
862+ .interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
863+ .full_duplex = DT_INST_PROP(0, full_duplex), \
864+ .timeout = CONFIG_ETH_ENC28J60_TIMEOUT, \
865+ }; \
866+ \
867+ ETH_NET_DEVICE_DT_INST_DEFINE(inst, eth_enc28j60_init, NULL, ð_enc28j60_runtime_##inst, \
868+ ð_enc28j60_config_##inst, CONFIG_ETH_INIT_PRIORITY, \
869+ &api_funcs, NET_ETH_MTU);
870+
871+ DT_INST_FOREACH_STATUS_OKAY (ENC28J60_DEFINE );
0 commit comments