diff mbox series

[U-Boot] net/phy/cortina.c: Update get_phy_id implementation

Message ID 1517292518-11054-1-git-send-email-priyanka.jain@nxp.com
State Accepted
Commit af5484acb0e8e4b6d0d977f84d8dde7b537c441d
Delegated to: Joe Hershberger
Headers show
Series [U-Boot] net/phy/cortina.c: Update get_phy_id implementation | expand

Commit Message

Priyanka Jain Jan. 30, 2018, 6:08 a.m. UTC
Update get_phy_id() implementation in cortina.c to check
for Cortina_phy by comparing device phy_id with cortina phy_id
instead of relying on presence of CORTINA macros.

This will allow get_phy_id to work with non-cortina phy devices
which might have same phy address as Cortina device but on
different  bus.

Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>
---
 drivers/net/phy/cortina.c | 46 +++++++++++++++++-----------------------------
 1 file changed, 17 insertions(+), 29 deletions(-)

Comments

Joe Hershberger March 19, 2018, 9:07 p.m. UTC | #1
On Tue, Jan 30, 2018 at 12:08 AM, Priyanka Jain <priyanka.jain@nxp.com> wrote:
> Update get_phy_id() implementation in cortina.c to check
> for Cortina_phy by comparing device phy_id with cortina phy_id
> instead of relying on presence of CORTINA macros.
>
> This will allow get_phy_id to work with non-cortina phy devices
> which might have same phy address as Cortina device but on
> different  bus.
>
> Signed-off-by: Priyanka Jain <priyanka.jain@nxp.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Joe Hershberger March 26, 2018, 7:26 p.m. UTC | #2
Hi Priyanka,

https://patchwork.ozlabs.org/patch/867403/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

diff --git a/drivers/net/phy/cortina.c b/drivers/net/phy/cortina.c
index 637d89a..3ac833d 100644
--- a/drivers/net/phy/cortina.c
+++ b/drivers/net/phy/cortina.c
@@ -295,45 +295,33 @@  int phy_cortina_init(void)
 int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id)
 {
 	int phy_reg;
-	bool is_cortina_phy = false;
-
-	switch (addr) {
-#ifdef CORTINA_PHY_ADDR1
-	case CORTINA_PHY_ADDR1:
-#endif
-#ifdef CORTINA_PHY_ADDR2
-	case CORTINA_PHY_ADDR2:
-#endif
-#ifdef CORTINA_PHY_ADDR3
-	case CORTINA_PHY_ADDR3:
-#endif
-#ifdef CORTINA_PHY_ADDR4
-	case CORTINA_PHY_ADDR4:
-#endif
-		is_cortina_phy = true;
-		break;
-	default:
-		break;
-	}
 
 	/* Cortina PHY has non-standard offset of PHY ID registers */
-	if (is_cortina_phy)
-		phy_reg = bus->read(bus, addr, 0, VILLA_GLOBAL_CHIP_ID_LSB);
-	else
-		phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
+	phy_reg = bus->read(bus, addr, 0, VILLA_GLOBAL_CHIP_ID_LSB);
+	if (phy_reg < 0)
+		return -EIO;
+	*phy_id = (phy_reg & 0xffff) << 16;
 
+	phy_reg = bus->read(bus, addr, 0, VILLA_GLOBAL_CHIP_ID_MSB);
 	if (phy_reg < 0)
 		return -EIO;
+	*phy_id |= (phy_reg & 0xffff);
 
-	*phy_id = (phy_reg & 0xffff) << 16;
-	if (is_cortina_phy)
-		phy_reg = bus->read(bus, addr, 0, VILLA_GLOBAL_CHIP_ID_MSB);
-	else
-		phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
+	if (*phy_id == PHY_UID_CS4340)
+		return 0;
 
+	/*
+	 * If Cortina PHY not detected,
+	 * try generic way to find PHY ID registers
+	 */
+	phy_reg = bus->read(bus, addr, devad, MII_PHYSID1);
 	if (phy_reg < 0)
 		return -EIO;
+	*phy_id = (phy_reg & 0xffff) << 16;
 
+	phy_reg = bus->read(bus, addr, devad, MII_PHYSID2);
+	if (phy_reg < 0)
+		return -EIO;
 	*phy_id |= (phy_reg & 0xffff);
 
 	return 0;