Skip to content

Commit

Permalink
Merge branch 'generic-implementation-of-phy-interface-and-fixed_phy-s…
Browse files Browse the repository at this point in the history
…upport-for-the-lan743x-device'

Pavithra Sathyanarayanan says:

====================
generic implementation of phy interface and fixed_phy support for the LAN743x device

This patch series includes the following changes:

- Remove the unwanted interface settings in the LAN743x driver as
  it is preset in EEPROM configurations.

- Handle generic implementation for the phy interfaces for different
  devices LAN7430/31 and pci11x1x.

- Add new feature for fixed_phy support at 1Gbps full duplex for the
  LAN7431 device if a phy not found over MDIO. Includes support for
  communication between a MAC in a LAN7431 device and custom phys
  without an MDIO interface.
====================

Link: https://lore.kernel.org/r/20230117141614.4411-1-Pavithra.Sathyanarayanan@microchip.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Paolo Abeni committed Jan 19, 2023
2 parents 3c107f3 + 624864f commit c84f433
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
59 changes: 41 additions & 18 deletions drivers/net/ethernet/microchip/lan743x_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,14 +1418,6 @@ static void lan743x_phy_link_status_change(struct net_device *netdev)

data = lan743x_csr_read(adapter, MAC_CR);

/* set interface mode */
if (phy_interface_is_rgmii(phydev))
/* RGMII */
data &= ~MAC_CR_MII_EN_;
else
/* GMII */
data |= MAC_CR_MII_EN_;

/* set duplex mode */
if (phydev->duplex)
data |= MAC_CR_DPX_;
Expand Down Expand Up @@ -1477,10 +1469,33 @@ static void lan743x_phy_close(struct lan743x_adapter *adapter)
netdev->phydev = NULL;
}

static void lan743x_phy_interface_select(struct lan743x_adapter *adapter)
{
u32 id_rev;
u32 data;

data = lan743x_csr_read(adapter, MAC_CR);
id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_;

if (adapter->is_pci11x1x && adapter->is_sgmii_en)
adapter->phy_interface = PHY_INTERFACE_MODE_SGMII;
else if (id_rev == ID_REV_ID_LAN7430_)
adapter->phy_interface = PHY_INTERFACE_MODE_GMII;
else if ((id_rev == ID_REV_ID_LAN7431_) && (data & MAC_CR_MII_EN_))
adapter->phy_interface = PHY_INTERFACE_MODE_MII;
else
adapter->phy_interface = PHY_INTERFACE_MODE_RGMII;
}

static int lan743x_phy_open(struct lan743x_adapter *adapter)
{
struct net_device *netdev = adapter->netdev;
struct lan743x_phy *phy = &adapter->phy;
struct fixed_phy_status fphy_status = {
.link = 1,
.speed = SPEED_1000,
.duplex = DUPLEX_FULL,
};
struct phy_device *phydev;
int ret = -EIO;

Expand All @@ -1491,17 +1506,25 @@ static int lan743x_phy_open(struct lan743x_adapter *adapter)
if (!phydev) {
/* try internal phy */
phydev = phy_find_first(adapter->mdiobus);
if (!phydev)
goto return_error;
if (!phydev) {
if ((adapter->csr.id_rev & ID_REV_ID_MASK_) ==
ID_REV_ID_LAN7431_) {
phydev = fixed_phy_register(PHY_POLL,
&fphy_status, NULL);
if (IS_ERR(phydev)) {
netdev_err(netdev, "No PHY/fixed_PHY found\n");
return -EIO;
}
} else {
goto return_error;
}
}

if (adapter->is_pci11x1x)
ret = phy_connect_direct(netdev, phydev,
lan743x_phy_link_status_change,
PHY_INTERFACE_MODE_RGMII);
else
ret = phy_connect_direct(netdev, phydev,
lan743x_phy_link_status_change,
PHY_INTERFACE_MODE_GMII);
lan743x_phy_interface_select(adapter);

ret = phy_connect_direct(netdev, phydev,
lan743x_phy_link_status_change,
adapter->phy_interface);
if (ret)
goto return_error;
}
Expand Down
1 change: 1 addition & 0 deletions drivers/net/ethernet/microchip/lan743x_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ struct lan743x_adapter {
#define LAN743X_ADAPTER_FLAG_OTP BIT(0)
u32 flags;
u32 hw_cfg;
phy_interface_t phy_interface;
};

#define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
Expand Down

0 comments on commit c84f433

Please sign in to comment.