Skip to content

Commit 6637c5b

Browse files
Jamie McCraejukkar
authored andcommitted
drivers: ethernet: enc424j600: Add config get support for driver
This allows the current speed of the connection (100Mbps/10Mbps) and if it is operating in half or full duplex to be queried Signed-off-by: Jamie McCrae <[email protected]>
1 parent 5719e54 commit 6637c5b

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

drivers/ethernet/eth_enc424j600.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*
33
* Copyright (c) 2016 Intel Corporation
44
* Copyright (c) 2019 PHYTEC Messtechnik GmbH
5+
* Copyright (c) 2021 Laird Connectivity
56
*
67
* SPDX-License-Identifier: Apache-2.0
78
*/
@@ -496,6 +497,54 @@ static void enc424j600_rx_thread(struct enc424j600_runtime *context)
496497
}
497498
}
498499

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+
499548
static enum ethernet_hw_caps enc424j600_get_capabilities(const struct device *dev)
500549
{
501550
ARG_UNUSED(dev);
@@ -590,7 +639,7 @@ static int enc424j600_stop_device(const struct device *dev)
590639

591640
static const struct ethernet_api api_funcs = {
592641
.iface_api.init = enc424j600_iface_init,
593-
642+
.get_config = enc424j600_get_config,
594643
.get_capabilities = enc424j600_get_capabilities,
595644
.send = enc424j600_tx,
596645
.start = enc424j600_start_device,

0 commit comments

Comments
 (0)