Skip to content

Commit d7504ab

Browse files
fabiobaltiericfriedt
authored andcommitted
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. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 957ea75 commit d7504ab

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

boards/xtensa/esp32_ethernet_kit/esp32_ethernet_kit.dts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@
115115
};
116116
};
117117

118-
&eth {
118+
&mdio {
119+
pinctrl-0 = <&mdio_default>;
120+
pinctrl-names = "default";
121+
119122
phy: phy {
120123
compatible = "ethernet-phy";
121124
status = "disabled";
@@ -124,7 +127,6 @@
124127
};
125128
};
126129

127-
&mdio {
128-
pinctrl-0 = <&mdio_default>;
129-
pinctrl-names = "default";
130+
&eth {
131+
phy-handle = <&phy>;
130132
};

drivers/ethernet/eth_esp32.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ struct eth_esp32_dev_data {
4747
struct k_thread rx_thread;
4848
};
4949

50+
static const struct device *eth_esp32_phy_dev = DEVICE_DT_GET(
51+
DT_INST_PHANDLE(0, phy_handle));
52+
5053
static enum ethernet_hw_caps eth_esp32_caps(const struct device *dev)
5154
{
5255
ARG_UNUSED(dev);
@@ -278,7 +281,6 @@ static void eth_esp32_iface_init(struct net_if *iface)
278281
{
279282
const struct device *dev = net_if_get_device(iface);
280283
struct eth_esp32_dev_data *dev_data = dev->data;
281-
const struct device *phy_dev = DEVICE_DT_GET(DT_INST_CHILD(0, phy));
282284

283285
dev_data->iface = iface;
284286

@@ -288,8 +290,9 @@ static void eth_esp32_iface_init(struct net_if *iface)
288290

289291
ethernet_init(iface);
290292

291-
if (device_is_ready(phy_dev)) {
292-
phy_link_callback_set(phy_dev, phy_link_state_changed, (void *)dev);
293+
if (device_is_ready(eth_esp32_phy_dev)) {
294+
phy_link_callback_set(eth_esp32_phy_dev, phy_link_state_changed,
295+
(void *)dev);
293296
} else {
294297
LOG_ERR("PHY device not ready");
295298
}

dts/bindings/ethernet/espressif,esp32-eth.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ properties:
1919
Phy connection type define the physical interface connection between
2020
PHY and MAC. The default value uses Reduced Media-Independent
2121
Interface (RMII) mode.
22+
phy-handle:
23+
required: true

0 commit comments

Comments
 (0)