mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: Heinrich.Toews@wago.com
Subject: [PATCH] ARM: omap: Wago PFC200: Initialize switch registers
Date: Mon, 28 Jan 2019 15:17:49 +0100	[thread overview]
Message-ID: <20190128141749.19262-1-s.hauer@pengutronix.de> (raw)

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

                 reply	other threads:[~2019-01-28 14:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190128141749.19262-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=Heinrich.Toews@wago.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox