public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Quentin Schulz <quentin.schulz@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/3] net: phy: mscc: factorize part of config function for VSC8584
Date: Fri, 14 Sep 2018 14:48:32 +0200	[thread overview]
Message-ID: <20180914124833.24906-3-quentin.schulz@bootlin.com> (raw)
In-Reply-To: <20180914124833.24906-1-quentin.schulz@bootlin.com>

Part of the config is common between the VSC8584 and the VSC8574, so to
prepare for the upcoming support of VSC8574, use the phy_device.priv
pointer that will keep the function that holds code that is PHY-specific
and that should be called during config function.

Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
---
 drivers/net/phy/mscc.c | 56 +++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 17 deletions(-)

diff --git a/drivers/net/phy/mscc.c b/drivers/net/phy/mscc.c
index 0e54fe0eff..b9dfcadd85 100644
--- a/drivers/net/phy/mscc.c
+++ b/drivers/net/phy/mscc.c
@@ -249,6 +249,10 @@ vsc_phy_clk_slew {
 	VSC_PHY_CLK_SLEW_RATE_7,
 };
 
+struct vsc85xx_priv {
+	int (*config_pre)(struct phy_device *phydev);
+};
+
 static void vsc8584_csr_write(struct mii_dev *bus, int phy0, u16 addr, u32 val)
 {
 	bus->write(bus, phy0, MDIO_DEVAD_NONE, MSCC_PHY_REG_TR_DATA_18,
@@ -444,11 +448,28 @@ static int vsc8584_patch_fw(struct mii_dev *bus, int phy, const u8 *fw_patch,
 	return 0;
 }
 
-static int vsc8584_config_pre_init(struct mii_dev *bus, int phy0)
+static int vsc8584_config_pre_init(struct phy_device *phydev)
 {
-	u16 reg, crc;
+	struct mii_dev *bus = phydev->bus;
+	u16 reg, crc, phy0, addr;
 	int ret;
 
+	if ((phydev->phy_id & MSCC_DEV_REV_MASK) != VSC8584_REVB) {
+		pr_warn("VSC8584 revA not officially supported, skipping firmware patching. Use at your own risk.\n");
+		return 0;
+	}
+
+	phy_write(phydev, MDIO_DEVAD_NONE, MSCC_EXT_PAGE_ACCESS,
+		  MSCC_PHY_PAGE_EXT1);
+	addr = phy_read(phydev, MDIO_DEVAD_NONE, MSCC_PHY_EXT_PHY_CNTL_4);
+	addr >>= PHY_CNTL_4_ADDR_POS;
+
+	reg = phy_read(phydev, MDIO_DEVAD_NONE, MSCC_PHY_ACTIPHY_CNTL);
+	if (reg & PHY_ADDR_REVERSED)
+		phy0 = phydev->addr + addr;
+	else
+		phy0 = phydev->addr - addr;
+
 	bus->write(bus, phy0, MDIO_DEVAD_NONE, MSCC_EXT_PAGE_ACCESS,
 		   MSCC_PHY_PAGE_STD);
 
@@ -898,32 +919,22 @@ static int vsc8541_config(struct phy_device *phydev)
 	return genphy_config_aneg(phydev);
 }
 
-static int vsc8584_config(struct phy_device *phydev)
+static int vsc8584_config_init(struct phy_device *phydev)
 {
+	struct vsc85xx_priv *priv = phydev->priv;
 	int ret;
 	u16 addr;
 	u16 reg_val;
 	u16 val;
-	u16 base_addr;
 
 	phy_write(phydev, MDIO_DEVAD_NONE, MSCC_EXT_PAGE_ACCESS,
 		  MSCC_PHY_PAGE_EXT1);
 	addr = phy_read(phydev, MDIO_DEVAD_NONE, MSCC_PHY_EXT_PHY_CNTL_4);
 	addr >>= PHY_CNTL_4_ADDR_POS;
 
-	val = phy_read(phydev, MDIO_DEVAD_NONE, MSCC_PHY_ACTIPHY_CNTL);
-	if (val & PHY_ADDR_REVERSED)
-		base_addr = phydev->addr + addr;
-	else
-		base_addr = phydev->addr - addr;
-
-	if ((phydev->phy_id & MSCC_DEV_REV_MASK) != VSC8584_REVB) {
-		pr_warn("VSC8584 revA not officially supported, skipping firmware patching. Use at your own risk.\n");
-	} else {
-		ret = vsc8584_config_pre_init(phydev->bus, base_addr);
-		if (ret)
-			return ret;
-	}
+	ret = priv->config_pre(phydev);
+	if (ret)
+		return ret;
 
 	phy_write(phydev, MDIO_DEVAD_NONE, MSCC_EXT_PAGE_ACCESS,
 		  MSCC_PHY_PAGE_GPIO);
@@ -988,6 +999,17 @@ static int vsc8584_config(struct phy_device *phydev)
 	return genphy_config(phydev);
 }
 
+static struct vsc85xx_priv vsc8584_priv = {
+	.config_pre = vsc8584_config_pre_init,
+};
+
+static int vsc8584_config(struct phy_device *phydev)
+{
+	phydev->priv = &vsc8584_priv;
+
+	return vsc8584_config_init(phydev);
+}
+
 static struct phy_driver VSC8530_driver = {
 	.name = "Microsemi VSC8530",
 	.uid = PHY_ID_VSC8530,
-- 
2.17.1

  parent reply	other threads:[~2018-09-14 12:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-14 12:48 [U-Boot] [PATCH 0/3] add support for VSC8584 and VSC8574 Microsemi PHYs Quentin Schulz
2018-09-14 12:48 ` [U-Boot] [PATCH 1/3] net: phy: mscc: add support for VSC8584 PHY Quentin Schulz
2018-10-22 21:52   ` Joe Hershberger
2018-10-31  8:20     ` Quentin Schulz
2018-09-14 12:48 ` Quentin Schulz [this message]
2018-10-22 22:11   ` [U-Boot] [PATCH 2/3] net: phy: mscc: factorize part of config function for VSC8584 Joe Hershberger
2018-09-14 12:48 ` [U-Boot] [PATCH 3/3] net: phy: mscc: add support for VSC8574 PHY Quentin Schulz
2018-10-22 22:25   ` Joe Hershberger
2018-10-30 15:54     ` Quentin Schulz

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=20180914124833.24906-3-quentin.schulz@bootlin.com \
    --to=quentin.schulz@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /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