7
7
#include <zephyr/logging/log.h>
8
8
LOG_MODULE_REGISTER (eth_adin2111 , CONFIG_ETHERNET_LOG_LEVEL );
9
9
10
- #define DT_DRV_COMPAT adi_adin2111
11
-
12
10
#include <zephyr/net/net_pkt.h>
13
11
#include <zephyr/net/ethernet.h>
14
12
#include <zephyr/net/phy.h>
@@ -269,6 +267,9 @@ static inline void adin2111_port_on_phyint(const struct device *dev)
269
267
static void adin2111_offload_thread (const struct device * dev )
270
268
{
271
269
struct adin2111_data * ctx = dev -> data ;
270
+ const struct adin2111_port_config * pcfg = dev -> config ;
271
+ const struct adin2111_config * adin_cfg = pcfg -> adin -> config ;
272
+ bool is_adin2111 = (adin_cfg -> id == ADIN2111_MAC );
272
273
uint32_t status0 ;
273
274
uint32_t status1 ;
274
275
int ret ;
@@ -312,7 +313,7 @@ static void adin2111_offload_thread(const struct device *dev)
312
313
}
313
314
314
315
/* handle port 2 phy interrupts */
315
- if (status1 & ADIN2111_STATUS1_PHYINT ) {
316
+ if (( status1 & ADIN2111_STATUS1_PHYINT ) && is_adin2111 ) {
316
317
adin2111_port_on_phyint (ctx -> port [1 ]);
317
318
}
318
319
@@ -332,7 +333,7 @@ static void adin2111_offload_thread(const struct device *dev)
332
333
}
333
334
334
335
/* handle port 2 rx */
335
- if (status1 & ADIN2111_STATUS1_P2_RX_RDY ) {
336
+ if (( status1 & ADIN2111_STATUS1_P2_RX_RDY ) && is_adin2111 ) {
336
337
do {
337
338
ret = adin2111_read_fifo (dev , 1U );
338
339
if (ret < 0 ) {
@@ -570,9 +571,11 @@ static int adin2111_write_filter_address(const struct device *dev,
570
571
571
572
static int adin2111_filter_multicast (const struct device * dev )
572
573
{
574
+ const struct adin2111_config * cfg = dev -> config ;
575
+ bool is_adin2111 = (cfg -> id == ADIN2111_MAC );
573
576
uint8_t mm [6 ] = {BIT (0 ), 0U , 0U , 0U , 0U , 0U };
574
577
uint32_t rules = ADIN2111_ADDR_APPLY2PORT1 |
575
- ADIN2111_ADDR_APPLY2PORT2 |
578
+ ( is_adin2111 ? ADIN2111_ADDR_APPLY2PORT2 : 0 ) |
576
579
ADIN2111_ADDR_TO_HOST |
577
580
ADIN2111_ADDR_TO_OTHER_PORT ;
578
581
@@ -582,9 +585,11 @@ static int adin2111_filter_multicast(const struct device *dev)
582
585
583
586
static int adin2111_filter_broadcast (const struct device * dev )
584
587
{
588
+ const struct adin2111_config * cfg = dev -> config ;
589
+ bool is_adin2111 = (cfg -> id == ADIN2111_MAC );
585
590
uint8_t mac [] = {0xFFU , 0xFFU , 0xFFU , 0xFFU , 0xFFU , 0xFFU };
586
591
uint32_t rules = ADIN2111_ADDR_APPLY2PORT1 |
587
- ADIN2111_ADDR_APPLY2PORT2 |
592
+ ( is_adin2111 ? ADIN2111_ADDR_APPLY2PORT2 : 0 ) |
588
593
ADIN2111_ADDR_TO_HOST |
589
594
ADIN2111_ADDR_TO_OTHER_PORT ;
590
595
@@ -727,7 +732,7 @@ static int adin2111_check_spi(const struct device *dev)
727
732
for (count = 0U ; count < ADIN2111_DEV_AWAIT_RETRY_COUNT ; ++ count ) {
728
733
ret = eth_adin2111_reg_read (dev , ADIN2111_PHYID , & val );
729
734
if (ret >= 0 ) {
730
- if (val == ADIN2111_PHYID_RST_VAL ) {
735
+ if (val == ADIN2111_PHYID_RST_VAL || val == ADIN1110_PHYID_RST_VAL ) {
731
736
break ;
732
737
}
733
738
ret = - ETIMEDOUT ;
@@ -768,6 +773,7 @@ static int adin2111_await_device(const struct device *dev)
768
773
static int adin2111_init (const struct device * dev )
769
774
{
770
775
const struct adin2111_config * cfg = dev -> config ;
776
+ bool is_adin2111 = (cfg -> id == ADIN2111_MAC );
771
777
struct adin2111_data * ctx = dev -> data ;
772
778
int ret ;
773
779
uint32_t val ;
@@ -880,8 +886,8 @@ static int adin2111_init(const struct device *dev)
880
886
/* The setting will take effect after the ports */
881
887
/* are out of software powerdown. */
882
888
val |= (ADIN2111_CONFIG2_PORT_CUT_THRU_EN |
883
- ADIN2111_CONFIG2_P1_FWD_UNK2P2 |
884
- ADIN2111_CONFIG2_P2_FWD_UNK2P1 );
889
+ ( is_adin2111 ? ADIN2111_CONFIG2_P1_FWD_UNK2P2 : 0 ) |
890
+ ( is_adin2111 ? ADIN2111_CONFIG2_P2_FWD_UNK2P1 : 0 ) );
885
891
886
892
ret = eth_adin2111_reg_write (dev , ADIN2111_CONFIG2 , val );
887
893
if (ret < 0 ) {
@@ -894,8 +900,8 @@ static int adin2111_init(const struct device *dev)
894
900
ctx -> imask1 = ~(ADIN2111_IMASK1_TX_RDY_MASK |
895
901
ADIN2111_IMASK1_P1_RX_RDY_MASK |
896
902
ADIN2111_IMASK1_SPI_ERR_MASK |
897
- ADIN2111_IMASK1_P2_RX_RDY_MASK |
898
- ADIN2111_IMASK1_P2_PHYINT_MASK );
903
+ ( is_adin2111 ? ADIN2111_IMASK1_P2_RX_RDY_MASK : 0 ) |
904
+ ( is_adin2111 ? ADIN2111_IMASK1_P2_PHYINT_MASK : 0 ) );
899
905
900
906
/* enable interrupts */
901
907
ret = eth_adin2111_reg_write (dev , ADIN2111_IMASK0 , ctx -> imask0 );
@@ -956,15 +962,16 @@ static const struct ethernet_api adin2111_port_api = {
956
962
957
963
#define ADIN2111_SPI_OPERATION ((uint16_t)(SPI_OP_MODE_MASTER | SPI_TRANSFER_MSB | SPI_WORD_SET(8)))
958
964
959
- #define ADIN2111_MAC_INITIALIZE (inst ) \
965
+ #define ADIN2111_MAC_INITIALIZE (inst , dev_id , ifaces ) \
960
966
static uint8_t __aligned(4) adin2111_buffer_##inst[CONFIG_ETH_ADIN2111_BUFFER_SIZE]; \
961
967
static const struct adin2111_config adin2111_config_##inst = { \
968
+ .id = dev_id, \
962
969
.spi = SPI_DT_SPEC_INST_GET(inst, ADIN2111_SPI_OPERATION, 1), \
963
970
.interrupt = GPIO_DT_SPEC_INST_GET(inst, int_gpios), \
964
971
.reset = GPIO_DT_SPEC_INST_GET_OR(inst, reset_gpios, { 0 }), \
965
972
}; \
966
973
static struct adin2111_data adin2111_data_##inst = { \
967
- .ifaces_left_to_init = 2U , \
974
+ .ifaces_left_to_init = ifaces , \
968
975
.port = {}, \
969
976
.offload_sem = Z_SEM_INITIALIZER(adin2111_data_##inst.offload_sem, 0, 1), \
970
977
.lock = Z_MUTEX_INITIALIZER(adin2111_data_##inst.lock), \
@@ -974,9 +981,21 @@ static const struct ethernet_api adin2111_port_api = {
974
981
DEVICE_DT_DEFINE (DT_DRV_INST (inst ), adin2111_init , NULL , \
975
982
& adin2111_data_ ##inst , & adin2111_config_ ##inst , \
976
983
POST_KERNEL , CONFIG_ETH_ADIN2111_INIT_PRIORITY , \
977
- NULL ); \
984
+ NULL );
985
+
986
+ #define ADIN2111_MAC_INIT (inst ) ADIN2111_MAC_INITIALIZE(inst, ADIN2111_MAC, 2) \
978
987
/* ports */ \
979
988
ADIN2111_PORT_DEVICE_INIT_INSTANCE (inst , 0 , 1 ) \
980
989
ADIN2111_PORT_DEVICE_INIT_INSTANCE (inst , 1 , 2 )
981
990
982
- DT_INST_FOREACH_STATUS_OKAY (ADIN2111_MAC_INITIALIZE )
991
+ #undef DT_DRV_COMPAT
992
+ #define DT_DRV_COMPAT adi_adin2111
993
+ DT_INST_FOREACH_STATUS_OKAY (ADIN2111_MAC_INIT )
994
+
995
+ #define ADIN1110_MAC_INIT (inst ) ADIN2111_MAC_INITIALIZE (inst , ADIN1110_MAC , 1 ) \
996
+ /* ports */ \
997
+ ADIN2111_PORT_DEVICE_INIT_INSTANCE (inst , 0 , 1 )
998
+
999
+ #undef DT_DRV_COMPAT
1000
+ #define DT_DRV_COMPAT adi_adin1110
1001
+ DT_INST_FOREACH_STATUS_OKAY (ADIN1110_MAC_INIT )
0 commit comments