mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] ARM: omap: Wago PFC200: Initialize switch registers
@ 2019-01-28 14:17 Sascha Hauer
  0 siblings, 0 replies; only message in thread
From: Sascha Hauer @ 2019-01-28 14:17 UTC (permalink / raw)
  To: Barebox List; +Cc: Heinrich.Toews

The PFC200 has a KSZ886x switch connected. Some of its registers need to
be initialized for proper ehternet support. Add the initialization code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Heinrich.Toews@wago.com
---
 arch/arm/boards/wago-pfc-am35xx/board.c | 45 +++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/arch/arm/boards/wago-pfc-am35xx/board.c b/arch/arm/boards/wago-pfc-am35xx/board.c
index 2bad40912d..c0a039ba50 100644
--- a/arch/arm/boards/wago-pfc-am35xx/board.c
+++ b/arch/arm/boards/wago-pfc-am35xx/board.c
@@ -3,6 +3,7 @@
  * Copyright (C) 2014 WAGO Kontakttechnik GmbH & Co. KG <http://global.wago.com>
  * Author: Heinrich Toews <heinrich.toews@wago.com>
  */
+#define pr_fmt(fmt)	"pfc200: " fmt
 
 #include <common.h>
 #include <init.h>
@@ -10,6 +11,8 @@
 #include <gpio.h>
 #include <linux/sizes.h>
 #include <linux/err.h>
+#include <linux/phy.h>
+#include <linux/micrel_phy.h>
 #include <asm/memory.h>
 #include <mach/generic.h>
 
@@ -23,6 +26,48 @@ static int pfc200_mem_init(void)
 }
 mem_initcall(pfc200_mem_init);
 
+#define BMCR_HP_MDIX 0x20
+
+static int pfc200_phy_fixup(struct mii_bus *mii, int phyadr)
+{
+	struct phy_device *phydev;
+	int ret;
+
+	phydev = mdiobus_scan(mii, phyadr);
+
+	if (IS_ERR(phydev)) {
+		pr_err("Cannot find phydev %d on mii bus\n", phyadr);
+		return PTR_ERR(phydev);
+	}
+
+	ret = phy_write(phydev, MII_BMCR, BMCR_ANENABLE | BMCR_HP_MDIX);
+	if (ret)
+		pr_err("Failed to write to phy: %s\n", strerror(-ret));
+
+	return ret;
+}
+
+static int pfc200_late_init(void)
+{
+	struct mii_bus *mii;
+
+	if (!of_machine_is_compatible("ti,pfc200"))
+		return 0;
+
+	mii = mdiobus_get_bus(0);
+	if (!mii) {
+		pr_err("Cannot find mii bus 0\n");
+		return -ENODEV;
+	}
+
+	pfc200_phy_fixup(mii, 1);
+	pfc200_phy_fixup(mii, 2);
+
+	return 0;
+}
+late_initcall(pfc200_late_init);
+
+
 #define GPIO_KSZ886x_RESET	136
 
 static int pfc200_devices_init(void)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-01-28 14:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-28 14:17 [PATCH] ARM: omap: Wago PFC200: Initialize switch registers Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox