mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v1 6/7] net/phy: marvell: improve config_aneg for 88E1121R and 88E1318S
Date: Wed, 11 Jan 2017 16:59:19 +0100	[thread overview]
Message-ID: <20170111155920.13179-7-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20170111155920.13179-1-u.kleine-koenig@pengutronix.de>

This is taken from the Linux driver

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/net/phy/marvell.c | 78 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 76 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index d504cf85a1da..6bb50a3a1f4c 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -133,6 +133,80 @@ static int marvell_read_status(struct phy_device *phydev)
 	return 0;
 }
 
+static inline bool phy_interface_is_rgmii(struct phy_device *phydev)
+{
+	return phydev->interface >= PHY_INTERFACE_MODE_RGMII &&
+		phydev->interface <= PHY_INTERFACE_MODE_RGMII_TXID;
+};
+
+static int m88e1121_config_aneg(struct phy_device *phydev)
+{
+	int err, oldpage, mscr;
+
+	oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
+
+	err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
+			MII_88E1121_PHY_MSCR_PAGE);
+	if (err < 0)
+		return err;
+
+	if (phy_interface_is_rgmii(phydev)) {
+
+		mscr = phy_read(phydev, MII_88E1121_PHY_MSCR_REG) &
+			MII_88E1121_PHY_MSCR_DELAY_MASK;
+
+		if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
+			mscr |= (MII_88E1121_PHY_MSCR_RX_DELAY |
+				 MII_88E1121_PHY_MSCR_TX_DELAY);
+		else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
+			mscr |= MII_88E1121_PHY_MSCR_RX_DELAY;
+		else if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
+			mscr |= MII_88E1121_PHY_MSCR_TX_DELAY;
+
+		err = phy_write(phydev, MII_88E1121_PHY_MSCR_REG, mscr);
+		if (err < 0)
+			return err;
+	}
+
+	phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
+
+	err = phy_write(phydev, MII_BMCR, BMCR_RESET);
+	if (err < 0)
+		return err;
+
+	err = phy_write(phydev, MII_M1011_PHY_SCR,
+			MII_M1011_PHY_SCR_AUTO_CROSS);
+	if (err < 0)
+		return err;
+
+	return genphy_config_aneg(phydev);
+}
+
+static int m88e1318_config_aneg(struct phy_device *phydev)
+{
+	int err, oldpage, mscr;
+
+	oldpage = phy_read(phydev, MII_MARVELL_PHY_PAGE);
+
+	err = phy_write(phydev, MII_MARVELL_PHY_PAGE,
+			MII_88E1121_PHY_MSCR_PAGE);
+	if (err < 0)
+		return err;
+
+	mscr = phy_read(phydev, MII_88E1318S_PHY_MSCR1_REG);
+	mscr |= MII_88E1318S_PHY_MSCR1_PAD_ODD;
+
+	err = phy_write(phydev, MII_88E1318S_PHY_MSCR1_REG, mscr);
+	if (err < 0)
+		return err;
+
+	err = phy_write(phydev, MII_MARVELL_PHY_PAGE, oldpage);
+	if (err < 0)
+		return err;
+
+	return m88e1121_config_aneg(phydev);
+}
+
 static int m88e1540_config_init(struct phy_device *phydev)
 {
 	u16 reg;
@@ -244,7 +318,7 @@ static struct phy_driver marvell_drivers[] = {
 		.drv.name = "Marvell 88E1121R",
 		.features = PHY_GBIT_FEATURES,
 		.config_init = &m88e1121_config_init,
-		.config_aneg = &genphy_config_aneg,
+		.config_aneg = &m88e1121_config_aneg,
 		.read_status = &marvell_read_status,
 	},
 	{
@@ -253,7 +327,7 @@ static struct phy_driver marvell_drivers[] = {
 		.drv.name = "Marvell 88E1318S",
 		.features = PHY_GBIT_FEATURES,
 		.config_init = &m88e1318s_config_init,
-		.config_aneg = &genphy_config_aneg,
+		.config_aneg = &m88e1318_config_aneg,
 		.read_status = &marvell_read_status,
 	},
 	{
-- 
2.11.0


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

  parent reply	other threads:[~2017-01-11 15:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 15:59 [PATCH v1 0/7] net/phy: marvell: add support for 88e1510 Uwe Kleine-König
2017-01-11 15:59 ` [PATCH v1 1/7] net/phy: marvell: rename 88E1545 to 88E1540 Uwe Kleine-König
2017-01-11 15:59 ` [PATCH v1 2/7] net/phy: marvell: 88E1540 LED registers already exist on 88E1121 Uwe Kleine-König
2017-01-11 15:59 ` [PATCH v1 3/7] net/phy: marvell: rename phy_driver array to match Linux driver Uwe Kleine-König
2017-01-11 15:59 ` [PATCH v1 4/7] net/phy: marvell: change spacing to be more similar to the " Uwe Kleine-König
2017-01-11 15:59 ` [PATCH v1 5/7] net/phy: marvell: align definition of MII_88E1121_PHY_MSCR to " Uwe Kleine-König
2017-01-11 15:59 ` Uwe Kleine-König [this message]
2017-01-11 15:59 ` [PATCH v1 7/7] net/phy: marvell: add support for 88e1510 to marvell phy driver Uwe Kleine-König
2017-01-13  6:54 ` [PATCH v1 0/7] net/phy: marvell: add support for 88e1510 Sascha Hauer

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=20170111155920.13179-7-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --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