From b9677d254935da30f567366d140cf8dc5c089a3b Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 25 Jul 2023 20:04:52 +0000 Subject: [PATCH] ethernet: esp32: make phy a phandle of the ethernet device Change the eth-phy definition so that the phy is pointed by a phandle rather than a child node, make the phy device a child of mdio. This makes more sense from a devicetree hirearchy where the phandles have to be initialized before the device itself, allows keeping the priorities in check with CHECK_INIT_PRIORITIES. (cherry picked from commit d7504ab4744c5552c8f6adf04ee9d81d00c6a628) Original-Signed-off-by: Fabio Baltieri GitOrigin-RevId: d7504ab4744c5552c8f6adf04ee9d81d00c6a628 Change-Id: I0277bcc74c124319d644873d555818ffe27d0810 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/4743846 Commit-Queue: Keith Short Reviewed-by: Keith Short Tested-by: ChromeOS Prod (Robot) Tested-by: Keith Short --- .../xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts | 10 ++++++---- drivers/ethernet/eth_esp32.c | 9 ++++++--- dts/bindings/ethernet/espressif,esp32-eth.yaml | 2 ++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/boards/xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts b/boards/xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts index d772cd817d3..b0c3bf9e2b2 100644 --- a/boards/xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts +++ b/boards/xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts @@ -115,7 +115,10 @@ }; }; -ð { +&mdio { + pinctrl-0 = <&mdio_default>; + pinctrl-names = "default"; + phy: phy { compatible = "ethernet-phy"; status = "disabled"; @@ -124,7 +127,6 @@ }; }; -&mdio { - pinctrl-0 = <&mdio_default>; - pinctrl-names = "default"; +ð { + phy-handle = <&phy>; }; diff --git a/drivers/ethernet/eth_esp32.c b/drivers/ethernet/eth_esp32.c index ca02d013ee7..0b1744efe6c 100644 --- a/drivers/ethernet/eth_esp32.c +++ b/drivers/ethernet/eth_esp32.c @@ -47,6 +47,9 @@ struct eth_esp32_dev_data { struct k_thread rx_thread; }; +static const struct device *eth_esp32_phy_dev = DEVICE_DT_GET( + DT_INST_PHANDLE(0, phy_handle)); + static enum ethernet_hw_caps eth_esp32_caps(const struct device *dev) { ARG_UNUSED(dev); @@ -278,7 +281,6 @@ static void eth_esp32_iface_init(struct net_if *iface) { const struct device *dev = net_if_get_device(iface); struct eth_esp32_dev_data *dev_data = dev->data; - const struct device *phy_dev = DEVICE_DT_GET(DT_INST_CHILD(0, phy)); dev_data->iface = iface; @@ -288,8 +290,9 @@ static void eth_esp32_iface_init(struct net_if *iface) ethernet_init(iface); - if (device_is_ready(phy_dev)) { - phy_link_callback_set(phy_dev, phy_link_state_changed, (void *)dev); + if (device_is_ready(eth_esp32_phy_dev)) { + phy_link_callback_set(eth_esp32_phy_dev, phy_link_state_changed, + (void *)dev); } else { LOG_ERR("PHY device not ready"); } diff --git a/dts/bindings/ethernet/espressif,esp32-eth.yaml b/dts/bindings/ethernet/espressif,esp32-eth.yaml index b3021da7ca3..3ffd12cdc50 100644 --- a/dts/bindings/ethernet/espressif,esp32-eth.yaml +++ b/dts/bindings/ethernet/espressif,esp32-eth.yaml @@ -19,3 +19,5 @@ properties: Phy connection type define the physical interface connection between PHY and MAC. The default value uses Reduced Media-Independent Interface (RMII) mode. + phy-handle: + required: true