Skip to content

Commit

Permalink
Merge branch 'lpc_eth-parse-phy-nodes-from-device-tree'
Browse files Browse the repository at this point in the history
Alexandre Belloni says:

====================
net: lpc_eth: parse phy nodes from device tree

Allow describing connected phys using device tree. This solves issues finding
the phy on the mdio bus and allows decribing the interrupt line the phy is
possibly connected to.

Changes in v3:
 - rebased on net-next
 - collected Reviewed-by

Changes in v2:
 - move the phy decription in the mdio subnode.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Oct 18, 2019
2 parents 3858a64 + 3503bf0 commit ebcd670
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Documentation/devicetree/bindings/net/lpc-eth.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Optional properties:
absent, "rmii" is assumed.
- use-iram: Use LPC32xx internal SRAM (IRAM) for DMA buffering

Optional subnodes:
- mdio : specifies the mdio bus, used as a container for phy nodes according to
phy.txt in the same directory


Example:

mac: ethernet@31060000 {
Expand Down
28 changes: 20 additions & 8 deletions drivers/net/ethernet/nxp/lpc_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/etherdevice.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_mdio.h>
#include <linux/of_net.h>
#include <linux/phy.h>
#include <linux/platform_device.h>
Expand Down Expand Up @@ -391,6 +392,7 @@ struct rx_status_t {
struct netdata_local {
struct platform_device *pdev;
struct net_device *ndev;
struct device_node *phy_node;
spinlock_t lock;
void __iomem *net_base;
u32 msg_enable;
Expand Down Expand Up @@ -749,22 +751,26 @@ static void lpc_handle_link_change(struct net_device *ndev)
static int lpc_mii_probe(struct net_device *ndev)
{
struct netdata_local *pldat = netdev_priv(ndev);
struct phy_device *phydev = phy_find_first(pldat->mii_bus);

if (!phydev) {
netdev_err(ndev, "no PHY found\n");
return -ENODEV;
}
struct phy_device *phydev;

/* Attach to the PHY */
if (lpc_phy_interface_mode(&pldat->pdev->dev) == PHY_INTERFACE_MODE_MII)
netdev_info(ndev, "using MII interface\n");
else
netdev_info(ndev, "using RMII interface\n");

if (pldat->phy_node)
phydev = of_phy_find_device(pldat->phy_node);
else
phydev = phy_find_first(pldat->mii_bus);
if (!phydev) {
netdev_err(ndev, "no PHY found\n");
return -ENODEV;
}

phydev = phy_connect(ndev, phydev_name(phydev),
&lpc_handle_link_change,
lpc_phy_interface_mode(&pldat->pdev->dev));

if (IS_ERR(phydev)) {
netdev_err(ndev, "Could not attach to PHY\n");
return PTR_ERR(phydev);
Expand All @@ -783,6 +789,7 @@ static int lpc_mii_probe(struct net_device *ndev)

static int lpc_mii_init(struct netdata_local *pldat)
{
struct device_node *node;
int err = -ENXIO;

pldat->mii_bus = mdiobus_alloc();
Expand Down Expand Up @@ -812,7 +819,10 @@ static int lpc_mii_init(struct netdata_local *pldat)

platform_set_drvdata(pldat->pdev, pldat->mii_bus);

if (mdiobus_register(pldat->mii_bus))
node = of_get_child_by_name(pldat->pdev->dev.of_node, "mdio");
err = of_mdiobus_register(pldat->mii_bus, node);
of_node_put(node);
if (err)
goto err_out_unregister_bus;

if (lpc_mii_probe(pldat->ndev) != 0)
Expand Down Expand Up @@ -1345,6 +1355,8 @@ static int lpc_eth_drv_probe(struct platform_device *pdev)
netdev_dbg(ndev, "DMA buffer V address :0x%p\n",
pldat->dma_buff_base_v);

pldat->phy_node = of_parse_phandle(np, "phy-handle", 0);

/* Get MAC address from current HW setting (POR state is all zeros) */
__lpc_get_mac(pldat, ndev->dev_addr);

Expand Down

0 comments on commit ebcd670

Please sign in to comment.