Skip to content

Commit

Permalink
dm: mdio: add dm_eth_phy_connect_index()
Browse files Browse the repository at this point in the history
Add the dm_eth_phy_connect_index() API which will let us connect to
a specific PHY referenced through the phy-handle property.

With this API, we can support multiple PHYs per an Ethernet device.
The DTS node can be populated with something like below:

	phy-handle = <&inphi1_phy0 &inphi1_phy1>;

If needed, the driver can call the dm_eth_phy_connect_index() multiple
times so that it can probe and configure both PHYs described in the DTS.

Signed-off-by: Ioana Ciornei <[email protected]>
  • Loading branch information
IoanaCiornei authored and p-priyanka-jain committed Jun 30, 2021
1 parent ad0ae45 commit b87e550
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 13 additions & 0 deletions include/miiphy.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
*/
struct phy_device *dm_eth_phy_connect(struct udevice *ethdev);

/**
* dm_eth_phy_connect_index - Connect an Eth device to the #phy_index PHY based on device tree
* This means that the phy-handle reference can now hold multiple PHYs.
*
* Picks up the DT phy-handle and phy-mode from ethernet device node and
* connects the ethernet device to the linked PHY.
*
* @ethdev: ethernet device
*
* @return pointer to phy_device, or 0 on error
*/
struct phy_device *dm_eth_phy_connect_index(struct udevice *ethdev, int phy_index);

#endif

#ifdef CONFIG_DM_MDIO_MUX
Expand Down
17 changes: 12 additions & 5 deletions net/mdio-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
}

static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
phy_interface_t interface)
phy_interface_t interface,
int phy_index)
{
u32 phy_addr;
struct udevice *mdiodev;
Expand All @@ -150,7 +151,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,

for (i = 0; i < PHY_HANDLE_STR_CNT; i++)
if (!dev_read_phandle_with_args(ethdev, phy_handle_str[i], NULL,
0, 0, &phandle))
0, phy_index, &phandle))
break;

if (!ofnode_valid(phandle.node)) {
Expand Down Expand Up @@ -184,8 +185,8 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
return phy;
}

/* Connect to a PHY linked in eth DT node */
struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
/* Connect to the #phy_index PHY linked in eth DT node */
struct phy_device *dm_eth_phy_connect_index(struct udevice *ethdev, int phy_index)
{
const char *if_str;
phy_interface_t interface;
Expand All @@ -210,7 +211,7 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
if (interface == PHY_INTERFACE_MODE_NONE)
dev_dbg(ethdev, "can't find interface mode, default to NONE\n");

phy = dm_eth_connect_phy_handle(ethdev, interface);
phy = dm_eth_connect_phy_handle(ethdev, interface, phy_index);

if (!phy)
return NULL;
Expand All @@ -220,6 +221,12 @@ struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
return phy;
}

/* Connect to a PHY linked in eth DT node */
struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
{
return dm_eth_phy_connect_index(ethdev, 0);
}

UCLASS_DRIVER(mdio) = {
.id = UCLASS_MDIO,
.name = "mdio",
Expand Down

0 comments on commit b87e550

Please sign in to comment.