From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Florian Fainelli <f.fainelli@gmail.com>,
"David S . Miller" <davem@davemloft.net>,
Sasha Levin <sashal@kernel.org>,
netdev@vger.kernel.org, devicetree@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 083/191] net: phy: mdio-bcm-unimac: Allow configuring MDIO clock divider
Date: Sat, 9 Nov 2019 21:38:25 -0500 [thread overview]
Message-ID: <20191110024013.29782-83-sashal@kernel.org> (raw)
In-Reply-To: <20191110024013.29782-1-sashal@kernel.org>
From: Florian Fainelli <f.fainelli@gmail.com>
[ Upstream commit b78ac6ecd1b6b46f8767cbafa95a7b0b51b87ad8 ]
Allow the configuration of the MDIO clock divider when the Device Tree
contains 'clock-frequency' property (similar to I2C and SPI buses).
Because the hardware may have lost its state during suspend/resume,
re-apply the MDIO clock divider upon resumption.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
.../bindings/net/brcm,unimac-mdio.txt | 3 +
drivers/net/phy/mdio-bcm-unimac.c | 83 ++++++++++++++++++-
2 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.txt b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.txt
index 4648948f7c3b8..e15589f477876 100644
--- a/Documentation/devicetree/bindings/net/brcm,unimac-mdio.txt
+++ b/Documentation/devicetree/bindings/net/brcm,unimac-mdio.txt
@@ -19,6 +19,9 @@ Optional properties:
- interrupt-names: must be "mdio_done_error" when there is a share interrupt fed
to this hardware block, or must be "mdio_done" for the first interrupt and
"mdio_error" for the second when there are separate interrupts
+- clocks: A reference to the clock supplying the MDIO bus controller
+- clock-frequency: the MDIO bus clock that must be output by the MDIO bus
+ hardware, if absent, the default hardware values are used
Child nodes of this MDIO bus controller node are standard Ethernet PHY device
nodes as described in Documentation/devicetree/bindings/net/phy.txt
diff --git a/drivers/net/phy/mdio-bcm-unimac.c b/drivers/net/phy/mdio-bcm-unimac.c
index 8d370667fa1b3..80b9583eaa952 100644
--- a/drivers/net/phy/mdio-bcm-unimac.c
+++ b/drivers/net/phy/mdio-bcm-unimac.c
@@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/io.h>
#include <linux/delay.h>
+#include <linux/clk.h>
#include <linux/of.h>
#include <linux/of_platform.h>
@@ -45,6 +46,8 @@ struct unimac_mdio_priv {
void __iomem *base;
int (*wait_func) (void *wait_func_data);
void *wait_func_data;
+ struct clk *clk;
+ u32 clk_freq;
};
static inline u32 unimac_mdio_readl(struct unimac_mdio_priv *priv, u32 offset)
@@ -189,6 +192,35 @@ static int unimac_mdio_reset(struct mii_bus *bus)
return 0;
}
+static void unimac_mdio_clk_set(struct unimac_mdio_priv *priv)
+{
+ unsigned long rate;
+ u32 reg, div;
+
+ /* Keep the hardware default values */
+ if (!priv->clk_freq)
+ return;
+
+ if (!priv->clk)
+ rate = 250000000;
+ else
+ rate = clk_get_rate(priv->clk);
+
+ div = (rate / (2 * priv->clk_freq)) - 1;
+ if (div & ~MDIO_CLK_DIV_MASK) {
+ pr_warn("Incorrect MDIO clock frequency, ignoring\n");
+ return;
+ }
+
+ /* The MDIO clock is the reference clock (typicaly 250Mhz) divided by
+ * 2 x (MDIO_CLK_DIV + 1)
+ */
+ reg = unimac_mdio_readl(priv, MDIO_CFG);
+ reg &= ~(MDIO_CLK_DIV_MASK << MDIO_CLK_DIV_SHIFT);
+ reg |= div << MDIO_CLK_DIV_SHIFT;
+ unimac_mdio_writel(priv, reg, MDIO_CFG);
+}
+
static int unimac_mdio_probe(struct platform_device *pdev)
{
struct unimac_mdio_pdata *pdata = pdev->dev.platform_data;
@@ -217,9 +249,26 @@ static int unimac_mdio_probe(struct platform_device *pdev)
return -ENOMEM;
}
+ priv->clk = devm_clk_get(&pdev->dev, NULL);
+ if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
+ return PTR_ERR(priv->clk);
+ else
+ priv->clk = NULL;
+
+ ret = clk_prepare_enable(priv->clk);
+ if (ret)
+ return ret;
+
+ if (of_property_read_u32(np, "clock-frequency", &priv->clk_freq))
+ priv->clk_freq = 0;
+
+ unimac_mdio_clk_set(priv);
+
priv->mii_bus = mdiobus_alloc();
- if (!priv->mii_bus)
- return -ENOMEM;
+ if (!priv->mii_bus) {
+ ret = -ENOMEM;
+ goto out_clk_disable;
+ }
bus = priv->mii_bus;
bus->priv = priv;
@@ -253,6 +302,8 @@ static int unimac_mdio_probe(struct platform_device *pdev)
out_mdio_free:
mdiobus_free(bus);
+out_clk_disable:
+ clk_disable_unprepare(priv->clk);
return ret;
}
@@ -262,10 +313,37 @@ static int unimac_mdio_remove(struct platform_device *pdev)
mdiobus_unregister(priv->mii_bus);
mdiobus_free(priv->mii_bus);
+ clk_disable_unprepare(priv->clk);
+
+ return 0;
+}
+
+static int unimac_mdio_suspend(struct device *d)
+{
+ struct unimac_mdio_priv *priv = dev_get_drvdata(d);
+
+ clk_disable_unprepare(priv->clk);
+
+ return 0;
+}
+
+static int unimac_mdio_resume(struct device *d)
+{
+ struct unimac_mdio_priv *priv = dev_get_drvdata(d);
+ int ret;
+
+ ret = clk_prepare_enable(priv->clk);
+ if (ret)
+ return ret;
+
+ unimac_mdio_clk_set(priv);
return 0;
}
+static SIMPLE_DEV_PM_OPS(unimac_mdio_pm_ops,
+ unimac_mdio_suspend, unimac_mdio_resume);
+
static const struct of_device_id unimac_mdio_ids[] = {
{ .compatible = "brcm,genet-mdio-v5", },
{ .compatible = "brcm,genet-mdio-v4", },
@@ -281,6 +359,7 @@ static struct platform_driver unimac_mdio_driver = {
.driver = {
.name = UNIMAC_MDIO_DRV_NAME,
.of_match_table = unimac_mdio_ids,
+ .pm = &unimac_mdio_pm_ops,
},
.probe = unimac_mdio_probe,
.remove = unimac_mdio_remove,
--
2.20.1
next prev parent reply other threads:[~2019-11-10 3:13 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20191110024013.29782-1-sashal@kernel.org>
2019-11-10 2:37 ` [PATCH AUTOSEL 4.19 009/191] ARM: dts: xilinx: Fix I2C and SPI bus warnings Sasha Levin
2019-11-10 2:37 ` [PATCH AUTOSEL 4.19 014/191] arm64: dts: ti: k3-am65: Change #address-cells and #size-cells of interconnect to 2 Sasha Levin
2019-11-10 2:37 ` [PATCH AUTOSEL 4.19 033/191] ARM: dts: atmel: Fix I2C and SPI bus warnings Sasha Levin
2019-11-10 2:37 ` [PATCH AUTOSEL 4.19 035/191] of/unittest: Fix I2C bus unit-address error Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 062/191] ARM: dts: am335x-evm: fix number of cpsw Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 063/191] ARM: dts: ti: Fix SPI and I2C bus warnings Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 066/191] ARM: dts: ux500: Correct SCU unit address Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 067/191] ARM: dts: ux500: Fix LCDA clock line muxing Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 068/191] ARM: dts: ste: Fix SPI controller node names Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 073/191] ARM: dts: marvell: Fix SPI and I2C bus warnings Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 075/191] ARM: dts: stm32: enable display on stm32mp157c-ev1 board Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 076/191] ARM: dts: clearfog: fix sdhci supply property name Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 077/191] ARM: dts: stm32: Fix SPI controller node names Sasha Levin
2019-11-10 2:38 ` Sasha Levin [this message]
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 090/191] arm64: dts: rockchip: Fix microSD in rk3399 sapphire board Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 096/191] ARM: dts: rockchip: explicitly set vcc_sd0 pin to gpio on rk3188-radxarock Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 100/191] ARM: dts: exynos: Correct audio subsystem parent clock on Peach Chromebooks Sasha Levin
2019-11-10 2:38 ` [PATCH AUTOSEL 4.19 107/191] ARM: dts: imx6ull: update vdd_soc voltage for 900MHz operating point Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 130/191] ARM: dts: meson8b: odroidc1: enable the SAR ADC Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 131/191] arm64: dts: fsl: Fix I2C and SPI bus warnings Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 132/191] ARM: dts: imx51-zii-rdu1: Fix the rtc compatible string Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 136/191] arm64: tegra: I2C on Tegra194 is not compatible with Tegra114 Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 137/191] ARM: dts: tegra30: fix xcvr-setup-use-fuses Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 138/191] ARM: dts: tegra20: restore address order Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 139/191] ARM: tegra: apalis_t30: fix mmc1 cmd pull-up Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 140/191] ARM: tegra: apalis_t30: fix mcp2515 can controller interrupt polarity Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 141/191] ARM: tegra: colibri_t30: " Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 142/191] ARM: dts: paz00: fix wakeup gpio keycode Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 151/191] ARM: dts: realview: Fix SPI controller node names Sasha Levin
2019-11-10 2:39 ` [PATCH AUTOSEL 4.19 177/191] arm64: dts: amd: Fix SPI bus warnings Sasha Levin
2019-11-10 2:40 ` [PATCH AUTOSEL 4.19 178/191] arm64: dts: lg: Fix SPI controller node names Sasha Levin
2019-11-10 2:40 ` [PATCH AUTOSEL 4.19 179/191] ARM: dts: lpc32xx: " Sasha Levin
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=20191110024013.29782-83-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stable@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).