|
2 | 2 | * |
3 | 3 | * Copyright (c) 2016 Intel Corporation |
4 | 4 | * Copyright (c) 2019 PHYTEC Messtechnik GmbH |
| 5 | + * Copyright (c) 2021 Laird Connectivity |
5 | 6 | * |
6 | 7 | * SPDX-License-Identifier: Apache-2.0 |
7 | 8 | */ |
@@ -496,6 +497,54 @@ static void enc424j600_rx_thread(struct enc424j600_runtime *context) |
496 | 497 | } |
497 | 498 | } |
498 | 499 |
|
| 500 | +static int enc424j600_get_config(const struct device *dev, |
| 501 | + enum ethernet_config_type type, |
| 502 | + struct ethernet_config *config) |
| 503 | +{ |
| 504 | + uint16_t tmp; |
| 505 | + int rc = 0; |
| 506 | + struct enc424j600_runtime *context = dev->data; |
| 507 | + |
| 508 | + if (type != ETHERNET_CONFIG_TYPE_LINK && |
| 509 | + type != ETHERNET_CONFIG_TYPE_DUPLEX) { |
| 510 | + /* Unsupported configuration query */ |
| 511 | + return -ENOTSUP; |
| 512 | + } |
| 513 | + |
| 514 | + k_sem_take(&context->tx_rx_sem, K_FOREVER); |
| 515 | + |
| 516 | + if (type == ETHERNET_CONFIG_TYPE_LINK) { |
| 517 | + /* Query active link speed */ |
| 518 | + enc424j600_read_phy(dev, ENC424J600_PSFR_PHSTAT3, &tmp); |
| 519 | + |
| 520 | + if (tmp & ENC424J600_PHSTAT3_SPDDPX_100) { |
| 521 | + /* 100Mbps link speed */ |
| 522 | + config->l.link_100bt = true; |
| 523 | + } else if (tmp & ENC424J600_PHSTAT3_SPDDPX_10) { |
| 524 | + /* 10Mbps link speed */ |
| 525 | + config->l.link_10bt = true; |
| 526 | + } else { |
| 527 | + /* Unknown link speed */ |
| 528 | + rc = -EINVAL; |
| 529 | + } |
| 530 | + } else if (type == ETHERNET_CONFIG_TYPE_DUPLEX) { |
| 531 | + /* Query if half or full duplex */ |
| 532 | + enc424j600_read_phy(dev, ENC424J600_PSFR_PHSTAT3, &tmp); |
| 533 | + |
| 534 | + /* Assume operating in half duplex mode */ |
| 535 | + config->full_duplex = false; |
| 536 | + |
| 537 | + if (tmp & ENC424J600_PHSTAT3_SPDDPX_FD) { |
| 538 | + /* Operating in full duplex mode */ |
| 539 | + config->full_duplex = true; |
| 540 | + } |
| 541 | + } |
| 542 | + |
| 543 | + k_sem_give(&context->tx_rx_sem); |
| 544 | + |
| 545 | + return rc; |
| 546 | +} |
| 547 | + |
499 | 548 | static enum ethernet_hw_caps enc424j600_get_capabilities(const struct device *dev) |
500 | 549 | { |
501 | 550 | ARG_UNUSED(dev); |
@@ -590,7 +639,7 @@ static int enc424j600_stop_device(const struct device *dev) |
590 | 639 |
|
591 | 640 | static const struct ethernet_api api_funcs = { |
592 | 641 | .iface_api.init = enc424j600_iface_init, |
593 | | - |
| 642 | + .get_config = enc424j600_get_config, |
594 | 643 | .get_capabilities = enc424j600_get_capabilities, |
595 | 644 | .send = enc424j600_tx, |
596 | 645 | .start = enc424j600_start_device, |
|
0 commit comments