[U-Boot] [PATCH 3/4] net: phy: add support for Micrel's KSZ9021

Troy Kisky troy.kisky at boundarydevices.com
Thu Jan 26 23:21:44 CET 2012


Add the gigabit phy KSZ9021.

Signed-off-by: Troy Kisky <troy.kisky at boundarydevices.com>
---
 drivers/net/phy/Makefile         |    1 +
 drivers/net/phy/micrel_ksz9021.c |  124 ++++++++++++++++++++++++++++++++++++++
 drivers/net/phy/phy.c            |    3 +
 3 files changed, 128 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/phy/micrel_ksz9021.c

diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
index feced39..86ec3c5 100644
--- a/drivers/net/phy/Makefile
+++ b/drivers/net/phy/Makefile
@@ -36,6 +36,7 @@ COBJS-$(CONFIG_PHY_DAVICOM) += davicom.o
 COBJS-$(CONFIG_PHY_LXT) += lxt.o
 COBJS-$(CONFIG_PHY_MARVELL) += marvell.o
 COBJS-$(CONFIG_PHY_MICREL) += micrel.o
+COBJS-$(CONFIG_PHY_MICREL_KSZ9021) += micrel_ksz9021.o
 COBJS-$(CONFIG_PHY_NATSEMI) += natsemi.o
 COBJS-$(CONFIG_PHY_REALTEK) += realtek.o
 COBJS-$(CONFIG_PHY_SMSC) += smsc.o
diff --git a/drivers/net/phy/micrel_ksz9021.c b/drivers/net/phy/micrel_ksz9021.c
new file mode 100644
index 0000000..f17b798
--- /dev/null
+++ b/drivers/net/phy/micrel_ksz9021.c
@@ -0,0 +1,124 @@
+/*
+ * Micrel KSZ9021 PHY driver
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ * Copyright 2012 Boundary Devices
+ *
+ */
+#include <config.h>
+#include <common.h>
+#include <phy.h>
+
+/* ksz9021 PHY Registers */
+#define MII_KSZ9021_EXTENDED_CTRL	0x0b
+#define MII_KSZ9021_EXTENDED_DATAW	0x0c
+#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)
+#define CTRL1000_MANUAL_CONFIG		(1 << 12)
+
+/* This is used to set board specific things like clock skew */
+unsigned short ksz9021_por_cmds[] = {
+#ifdef CONFIG_PHY_MICREL_KSZ9021_INIT_CMDS
+	CONFIG_PHY_MICREL_KSZ9021_INIT_CMDS
+#endif
+	0, 0
+};
+
+int ksz9021_send_phy_cmds(struct phy_device *phydev, unsigned short* p)
+{
+	for (;;) {
+		unsigned reg = *p++;
+		unsigned val = *p++;
+		if (reg == 0 && val == 0)
+			break;
+		if (reg < 32) {
+			phy_write(phydev, MDIO_DEVAD_NONE, reg, val);
+		} else {
+			phy_write(phydev, MDIO_DEVAD_NONE,
+					MII_KSZ9021_EXTENDED_CTRL, reg);
+			phy_write(phydev, MDIO_DEVAD_NONE,
+					MII_KSZ9021_EXTENDED_DATAW, val);
+		}
+	}
+	return 0;
+}
+
+/* Micrel ksz9021 */
+static int ksz9021_config(struct phy_device *phydev)
+{
+	unsigned ctrl1000 = 0;
+	const unsigned master = CTRL1000_PREFER_MASTER |
+			CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
+	unsigned features = phydev->drv->features;
+
+	ksz9021_send_phy_cmds(phydev, ksz9021_por_cmds);
+	if (getenv("disable_giga"))
+		features &= ~(SUPPORTED_1000baseT_Half |
+				SUPPORTED_1000baseT_Full);
+	/* force master mode for 1000BaseT due to chip errata */
+	if (features & SUPPORTED_1000baseT_Half)
+		ctrl1000 |= ADVERTISE_1000HALF | master;
+	if (features & SUPPORTED_1000baseT_Full)
+		ctrl1000 |= ADVERTISE_1000FULL | master;
+	phydev->advertising = phydev->supported = features;
+	phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
+	genphy_config_aneg(phydev);
+	genphy_restart_aneg(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,
+	.shutdown = &genphy_shutdown,
+};
+
+int phy_ksz9021_init(void)
+{
+	phy_register(&ksz9021_driver);
+	return 0;
+}
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index eb55180..7e1e4b6 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -438,6 +438,9 @@ int phy_init(void)
 #ifdef CONFIG_PHY_MICREL
 	phy_micrel_init();
 #endif
+#ifdef CONFIG_PHY_MICREL_KSZ9021
+	phy_ksz9021_init();
+#endif
 #ifdef CONFIG_PHY_NATSEMI
 	phy_natsemi_init();
 #endif
-- 
1.7.5.4



More information about the U-Boot mailing list