From 460eb219ba139a5eff179b8896999b7fde42931c Mon Sep 17 00:00:00 2001 From: Patrick Van Oosterwijck Date: Thu, 25 Sep 2025 15:45:07 -0600 Subject: [PATCH] [ethernet] Add LAN8670 PHY support (#10874) Co-authored-by: J. Nick Koston --- esphome/components/ethernet/__init__.py | 23 ++++++++++++++++++- .../ethernet/ethernet_component.cpp | 16 +++++++++++++ .../components/ethernet/ethernet_component.h | 1 + esphome/idf_component.yml | 4 ++++ tests/components/ethernet/common-lan8670.yaml | 14 +++++++++++ .../ethernet/test-lan8670.esp32-ard.yaml | 1 + .../ethernet/test-lan8670.esp32-idf.yaml | 1 + 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/components/ethernet/common-lan8670.yaml create mode 100644 tests/components/ethernet/test-lan8670.esp32-ard.yaml create mode 100644 tests/components/ethernet/test-lan8670.esp32-idf.yaml diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index ef8e82a843..75b09dc8e4 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -2,9 +2,15 @@ import logging from esphome import pins import esphome.codegen as cg -from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant +from esphome.components.esp32 import ( + add_idf_component, + add_idf_sdkconfig_option, + get_esp32_variant, +) from esphome.components.esp32.const import ( + VARIANT_ESP32, VARIANT_ESP32C3, + VARIANT_ESP32P4, VARIANT_ESP32S2, VARIANT_ESP32S3, ) @@ -75,12 +81,14 @@ ETHERNET_TYPES = { "W5500": EthernetType.ETHERNET_TYPE_W5500, "OPENETH": EthernetType.ETHERNET_TYPE_OPENETH, "DM9051": EthernetType.ETHERNET_TYPE_DM9051, + "LAN8670": EthernetType.ETHERNET_TYPE_LAN8670, } # PHY types that need compile-time defines for conditional compilation _PHY_TYPE_TO_DEFINE = { "KSZ8081": "USE_ETHERNET_KSZ8081", "KSZ8081RNA": "USE_ETHERNET_KSZ8081", + "LAN8670": "USE_ETHERNET_LAN8670", # Add other PHY types here only if they need conditional compilation } @@ -136,6 +144,14 @@ def _validate(config): else: use_address = CORE.name + config[CONF_DOMAIN] config[CONF_USE_ADDRESS] = use_address + + # Validate LAN8670 is only used with ESP32 classic or ESP32-P4 + if config[CONF_TYPE] == "LAN8670": + variant = get_esp32_variant() + if variant not in (VARIANT_ESP32, VARIANT_ESP32P4): + raise cv.Invalid( + f"LAN8670 PHY is only supported on ESP32 classic and ESP32-P4, not {variant}" + ) if config[CONF_TYPE] in SPI_ETHERNET_TYPES: if _is_framework_spi_polling_mode_supported(): if CONF_POLLING_INTERVAL in config and CONF_INTERRUPT_PIN in config: @@ -248,6 +264,7 @@ CONFIG_SCHEMA = cv.All( "W5500": SPI_SCHEMA, "OPENETH": BASE_SCHEMA, "DM9051": SPI_SCHEMA, + "LAN8670": RMII_SCHEMA, }, upper=True, ), @@ -356,5 +373,9 @@ async def to_code(config): # Also disable WiFi/BT coexistence since WiFi is disabled add_idf_sdkconfig_option("CONFIG_SW_COEXIST_ENABLE", False) + if config[CONF_TYPE] == "LAN8670": + # Add LAN867x 10BASE-T1S PHY support component + add_idf_component(name="espressif/lan867x", ref="2.0.0") + if CORE.using_arduino: cg.add_library("WiFi", None) diff --git a/esphome/components/ethernet/ethernet_component.cpp b/esphome/components/ethernet/ethernet_component.cpp index ff14d19427..cb43b2c83c 100644 --- a/esphome/components/ethernet/ethernet_component.cpp +++ b/esphome/components/ethernet/ethernet_component.cpp @@ -9,6 +9,10 @@ #include #include "esp_event.h" +#ifdef USE_ETHERNET_LAN8670 +#include "esp_eth_phy_lan867x.h" +#endif + #ifdef USE_ETHERNET_SPI #include #include @@ -200,6 +204,12 @@ void EthernetComponent::setup() { this->phy_ = esp_eth_phy_new_ksz80xx(&phy_config); break; } +#ifdef USE_ETHERNET_LAN8670 + case ETHERNET_TYPE_LAN8670: { + this->phy_ = esp_eth_phy_new_lan867x(&phy_config); + break; + } +#endif #endif #ifdef USE_ETHERNET_SPI #if CONFIG_ETH_SPI_ETHERNET_W5500 @@ -353,6 +363,12 @@ void EthernetComponent::dump_config() { eth_type = "DM9051"; break; +#ifdef USE_ETHERNET_LAN8670 + case ETHERNET_TYPE_LAN8670: + eth_type = "LAN8670"; + break; +#endif + default: eth_type = "Unknown"; break; diff --git a/esphome/components/ethernet/ethernet_component.h b/esphome/components/ethernet/ethernet_component.h index bbb9d7fb60..fae5bb1257 100644 --- a/esphome/components/ethernet/ethernet_component.h +++ b/esphome/components/ethernet/ethernet_component.h @@ -28,6 +28,7 @@ enum EthernetType : uint8_t { ETHERNET_TYPE_W5500, ETHERNET_TYPE_OPENETH, ETHERNET_TYPE_DM9051, + ETHERNET_TYPE_LAN8670, }; struct ManualIP { diff --git a/esphome/idf_component.yml b/esphome/idf_component.yml index 687efd2b49..1a6dc8b97d 100644 --- a/esphome/idf_component.yml +++ b/esphome/idf_component.yml @@ -19,3 +19,7 @@ dependencies: - if: "target in [esp32h2, esp32p4]" zorxx/multipart-parser: version: 1.0.1 + espressif/lan867x: + version: "2.0.0" + rules: + - if: "target in [esp32, esp32p4]" diff --git a/tests/components/ethernet/common-lan8670.yaml b/tests/components/ethernet/common-lan8670.yaml new file mode 100644 index 0000000000..ec2f24273d --- /dev/null +++ b/tests/components/ethernet/common-lan8670.yaml @@ -0,0 +1,14 @@ +ethernet: + type: LAN8670 + mdc_pin: 23 + mdio_pin: 25 + clk: + pin: 0 + mode: CLK_EXT_IN + phy_addr: 0 + power_pin: 26 + manual_ip: + static_ip: 192.168.178.56 + gateway: 192.168.178.1 + subnet: 255.255.255.0 + domain: .local diff --git a/tests/components/ethernet/test-lan8670.esp32-ard.yaml b/tests/components/ethernet/test-lan8670.esp32-ard.yaml new file mode 100644 index 0000000000..914a06ae88 --- /dev/null +++ b/tests/components/ethernet/test-lan8670.esp32-ard.yaml @@ -0,0 +1 @@ +<<: !include common-lan8670.yaml diff --git a/tests/components/ethernet/test-lan8670.esp32-idf.yaml b/tests/components/ethernet/test-lan8670.esp32-idf.yaml new file mode 100644 index 0000000000..914a06ae88 --- /dev/null +++ b/tests/components/ethernet/test-lan8670.esp32-idf.yaml @@ -0,0 +1 @@ +<<: !include common-lan8670.yaml