Skip to contentSkip to conversation

PHY: micrel.c: add support for KSZ9031

PATCH Superseded David Andrey 4 participants 7 messages Feb 6, 2013 – Jul 8, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PHY: micrel.c: add support for KSZ9031

Add support for Micrel PHY KSZ9031 in phylib, including small rework for KSZ9021 to avoid code duplication

Cc Troy Kisky <[email protected]>
Cc Joe Herschberger <[email protected]>
Cc Andy Fleming <[email protected]>

---

Changes for v2:
- Same startup function for KSZ9021 and 9031

---
 drivers/net/phy/micrel.c |   79 ++++++++++++++++++++++++++++++----------------
 1 files changed, 52 insertions(+), 27 deletions(-)
drivers/net/phy/micrel.c +52 -27
index 30f3264..2a8b6cb 100644
@@ -18,6 +18,7 @@
  *
  * Copyright 2010-2011 Freescale Semiconductor, Inc.
  * author Andy Fleming
+ * (C) 2012 NetModule AG, David Andrey, added KSZ9031
  *
  */
 #include <config.h>
@@ -52,16 +53,46 @@ static struct phy_driver KS8721_driver = {
 };
 #endif
 
+
+/**
+ * KSZ9021 - KSZ9031 common
+ */
+
+#define MII_KSZ90xx_PHY_CTL		0x1f
+#define MIIM_KSZ90xx_PHYCTL_1000	(1 << 6)
+#define MIIM_KSZ90xx_PHYCTL_100		(1 << 5)
+#define MIIM_KSZ90xx_PHYCTL_10		(1 << 4)
+#define MIIM_KSZ90xx_PHYCTL_DUPLEX	(1 << 3)
+
+static int ksz90xx_startup(struct phy_device *phydev)
+{
+	unsigned phy_ctl;
+	genphy_update_link(phydev);
+	phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL);
+
+	if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX)
+		phydev->duplex = DUPLEX_FULL;
+	else
+		phydev->duplex = DUPLEX_HALF;
+
+	if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000)
+		phydev->speed = SPEED_1000;
+	else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100)
+		phydev->speed = SPEED_100;
+	else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10)
+		phydev->speed = SPEED_10;
+	return 0;
+}
 #ifdef CONFIG_PHY_MICREL_KSZ9021
-/* ksz9021 PHY Registers */
+
+/*
+ * KSZ9021
+ */
+
+/* PHY Registers */
 #define MII_KSZ9021_EXTENDED_CTRL	0x0b
 #define MII_KSZ9021_EXTENDED_DATAW	0x0c
 #define MII_KSZ9021_EXTENDED_DATAR	0x0d
-#define MII_KSZ9021_PHY_CTL		0x1f
-#define MIIM_KSZ9021_PHYCTL_1000	(1 << 6)
-#define MIIM_KSZ9021_PHYCTL_100		(1 << 5)
-#define MIIM_KSZ9021_PHYCTL_10		(1 << 4)
-#define MIIM_KSZ9021_PHYCTL_DUPLEX	(1 << 3)
 
 #define CTRL1000_PREFER_MASTER		(1 << 10)
 #define CTRL1000_CONFIG_MASTER		(1 << 11)
@@ -106,37 +137,30 @@ static int ksz9021_config(struct phy_device *phydev)
 	return 0;
 }
 
-static int ksz9021_startup(struct phy_device *phydev)
-{
-	unsigned phy_ctl;
-	genphy_update_link(phydev);
-	phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_PHY_CTL);
-
-	if (phy_ctl & MIIM_KSZ9021_PHYCTL_DUPLEX)
-		phydev->duplex = DUPLEX_FULL;
-	else
-		phydev->duplex = DUPLEX_HALF;
-
-	if (phy_ctl & MIIM_KSZ9021_PHYCTL_1000)
-		phydev->speed = SPEED_1000;
-	else if (phy_ctl & MIIM_KSZ9021_PHYCTL_100)
-		phydev->speed = SPEED_100;
-	else if (phy_ctl & MIIM_KSZ9021_PHYCTL_10)
-		phydev->speed = SPEED_10;
-	return 0;
-}
-
 static struct phy_driver ksz9021_driver = {
 	.name = "Micrel ksz9021",
 	.uid  = 0x221610,
 	.mask = 0xfffff0,
 	.features = PHY_GBIT_FEATURES,
 	.config = &ksz9021_config,
-	.startup = &ksz9021_startup,
+	.startup = &ksz90xx_startup,
 	.shutdown = &genphy_shutdown,
 };
 #endif
 
+/*
+ * KSZ9031
+ */
+static struct phy_driver ksz9031_driver = {
+	.name = "Micrel ksz9031",
+	.uid  = 0x221620,
+	.mask = 0xfffffe,
+	.features = PHY_GBIT_FEATURES,
+	.config   = &genphy_config,
+	.startup  = &ksz90xx_startup,
+	.shutdown = &genphy_shutdown,
+};
+
 int phy_micrel_init(void)
 {
 	phy_register(&KSZ804_driver);
@@ -145,5 +169,6 @@ int phy_micrel_init(void)
 #else
 	phy_register(&KS8721_driver);
 #endif
+	phy_register(&ksz9031_driver);
 	return 0;
 }
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v2 1/1 PHY: micrel.c: add support for KSZ9031

Hi David,

Quoted 100 lines · David Andrey

Add support for Micrel PHY KSZ9031 in phylib, including small rework for KSZ9021 to avoid code duplication

Cc Troy Kisky <[email protected]>
Cc Joe Herschberger <[email protected]>
Cc Andy Fleming <[email protected]>

---

Changes for v2:
- Same startup function for KSZ9021 and 9031

---
 drivers/net/phy/micrel.c |   79 ++++++++++++++++++++++++++++++----------------
 1 files changed, 52 insertions(+), 27 deletions(-)
drivers/net/phy/micrel.c +37 -20
index 30f3264..2a8b6cb 100644
@@ -18,6 +18,7 @@
  *
  * Copyright 2010-2011 Freescale Semiconductor, Inc.
  * author Andy Fleming
+ * (C) 2012 NetModule AG, David Andrey, added KSZ9031
  *
  */
 #include <config.h>
@@ -52,16 +53,46 @@ static struct phy_driver KS8721_driver = {
 };
 #endif
 
+
+/**
+ * KSZ9021 - KSZ9031 common
+ */
+
+#define MII_KSZ90xx_PHY_CTL		0x1f
+#define MIIM_KSZ90xx_PHYCTL_1000	(1 << 6)
+#define MIIM_KSZ90xx_PHYCTL_100		(1 << 5)
+#define MIIM_KSZ90xx_PHYCTL_10		(1 << 4)
+#define MIIM_KSZ90xx_PHYCTL_DUPLEX	(1 << 3)
+
+static int ksz90xx_startup(struct phy_device *phydev)
+{
+	unsigned phy_ctl;
+	genphy_update_link(phydev);
+	phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL);
+
+	if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX)
+		phydev->duplex = DUPLEX_FULL;
+	else
+		phydev->duplex = DUPLEX_HALF;
+
+	if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000)
+		phydev->speed = SPEED_1000;
+	else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100)
+		phydev->speed = SPEED_100;
+	else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10)
+		phydev->speed = SPEED_10;
+	return 0;
+}
 #ifdef CONFIG_PHY_MICREL_KSZ9021
-/* ksz9021 PHY Registers */
+
+/*
+ * KSZ9021
+ */
+
+/* PHY Registers */
 #define MII_KSZ9021_EXTENDED_CTRL	0x0b
 #define MII_KSZ9021_EXTENDED_DATAW	0x0c
 #define MII_KSZ9021_EXTENDED_DATAR	0x0d
-#define MII_KSZ9021_PHY_CTL		0x1f
-#define MIIM_KSZ9021_PHYCTL_1000	(1 << 6)
-#define MIIM_KSZ9021_PHYCTL_100		(1 << 5)
-#define MIIM_KSZ9021_PHYCTL_10		(1 << 4)
-#define MIIM_KSZ9021_PHYCTL_DUPLEX	(1 << 3)
 
 #define CTRL1000_PREFER_MASTER		(1 << 10)
 #define CTRL1000_CONFIG_MASTER		(1 << 11)
@@ -106,37 +137,30 @@ static int ksz9021_config(struct phy_device *phydev)
 	return 0;
 }
 
-static int ksz9021_startup(struct phy_device *phydev)
-{
-	unsigned phy_ctl;
-	genphy_update_link(phydev);
-	phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_PHY_CTL);
-
-	if (phy_ctl & MIIM_KSZ9021_PHYCTL_DUPLEX)
-		phydev->duplex = DUPLEX_FULL;
-	else
-		phydev->duplex = DUPLEX_HALF;
-
-	if (phy_ctl & MIIM_KSZ9021_PHYCTL_1000)
-		phydev->speed = SPEED_1000;
-	else if (phy_ctl & MIIM_KSZ9021_PHYCTL_100)

drivers/net/phy/micrel.c static int ksz9021_config(struct phy_device *phydev) · line 143

Quoted 10 lines
drivers/net/phy/micrel.c +0 -6
-		phydev->speed = SPEED_100;
-	else if (phy_ctl & MIIM_KSZ9021_PHYCTL_10)
-		phydev->speed = SPEED_10;
-	return 0;
-}
-
 static struct phy_driver ksz9021_driver = {
 	.name = "Micrel ksz9021",
 	.uid  = 0x221610,
 	.mask = 0xfffff0,

Why don't you just change the mask to support both PHY's with one struct here? Something like this:

static struct phy_driver ksz9021_driver = {
- .name = "Micrel ksz9021",
+ .name = "Micrel ksz90x1",
.uid = 0x221610,
- .mask = 0xfffff0,
+ .mask = 0xffffc0,

This would be much "simpler". Does it work for you?

Best regards,
Stefan

--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: office at denx.de

#2 lore raw

PATCH v2 1/1 PHY: micrel.c: add support for KSZ9031

Hi Stefan,

Quoted 1 line

Why don't you just change the mask to support both PHY's with one

struct here? Something like this:

Quoted 9 lines

static struct phy_driver ksz9021_driver = {

(quoted diff) +2 -2
-	.name = "Micrel ksz9021",
+	.name = "Micrel ksz90x1",
 	.uid  = 0x221610,
-	.mask = 0xfffff0,
+	.mask = 0xffffc0,

This would be much "simpler". Does it work for you?

Well, because the ksz9031 works well with the generic phy config function. See ksz9021_config vs genphy_config

Regards
David

#3 lore raw

PATCH v2 1/1 PHY: micrel.c: add support for KSZ9031

Hi David,

Quoted 10 lines · David Andrey
Quoted 1 line

Why don't you just change the mask to support both PHY's with one

struct here? Something like this:

Quoted 8 lines

static struct phy_driver ksz9021_driver = {

(quoted diff) +2 -2
-	.name = "Micrel ksz9021",
+	.name = "Micrel ksz90x1",
 	.uid  = 0x221610,
-	.mask = 0xfffff0,
+	.mask = 0xffffc0,
Quoted 4 lines
Quoted 1 line

This would be much "simpler". Does it work for you?

Well, because the ksz9031 works well with the generic phy config function. See ksz9021_config vs genphy_config

Okay, I see. Thanks.

Thanks,
Stefan

#5 lore raw

PATCH v2 1/1 PHY: micrel.c: add support for KSZ9031

Quoted 7 lines · Fabio Estevam

Hi Joe,

Quoted 4 lines · David Andrey

Add support for Micrel PHY KSZ9031 in phylib, including small rework for KSZ9021 to avoid code duplication

Quoted 6 lines
Quoted 4 lines
Cc Troy Kisky <[email protected]>
Cc Joe Herschberger <[email protected]>
Cc Andy Fleming <[email protected]>

Can we get this one applied for the upcoming 2013.04?

I have this in a branch, but I'm fixing problems with a few patches. I'll send a PR soon that should include this.

Cheers,
-Joe