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 <fabiobaltieri@google.com>
This commit is contained in:
Fabio Baltieri 2023-07-25 20:04:52 +00:00 committed by Chris Friedt
commit d7504ab474
3 changed files with 14 additions and 7 deletions

View file

@ -115,7 +115,10 @@
};
};
&eth {
&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";
&eth {
phy-handle = <&phy>;
};

View file

@ -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");
}

View file

@ -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