From: Andre Przywara <andre.przywara@arm.com>
To: Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Jernej Skrabec <jernej.skrabec@gmail.com>
Subject: [PATCH] net: phy: mdio: add clock support for PHYs
Date: Mon, 4 Jul 2022 01:45:33 +0100 [thread overview]
Message-ID: <20220704004533.17762-1-andre.przywara@arm.com> (raw)
So far the generic Ethernet PHY subsystem supports PHYs having a reset
line, which needs to be de-asserted before the PHY can be used. This
corresponds to an "RST" pin on most external PHY chips.
But most PHY chips also need an external clock signal, which may feed
some internal PLL, and/or is used to drive the internal logic. In many
systems this clock signal is provided by a fixed crystal oscillator, so
is of no particular interest to software.
However some systems use a more complex clock source, or try to save a
few pennies by avoiding the crystal. The X-Powers AC200 mixed signal PHY
chip, for instance, uses a software-controlled clock gate, and the
Lindenis V5 development board drives its RTL8211 PHY via a clock pin
on the SoC.
On those systems the clock source needs to be actively enabled by
software, before the PHY can be used. To support those machines, add a
struct clk, populate it from firmware tables, and enable or disable it
when needed, similar to toggling the reset line.
In contrast to exclusive reset lines, calls to clock_disable() need to
be balanced with calls to clock_enable() before, also the gate is
supposed to be initially disabled. This means we cannot treat it exactly
the same as the reset line, but have to skip the initial handling, and
just enable or disable the gate in the probe and remove handlers.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
drivers/net/phy/mdio_bus.c | 18 ++++++++++++++++++
drivers/net/phy/mdio_device.c | 12 ++++++++++++
include/linux/mdio.h | 1 +
3 files changed, 31 insertions(+)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 8a2dbe849866..5cf84f92dab4 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -8,6 +8,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/errno.h>
@@ -67,6 +68,19 @@ static int mdiobus_register_reset(struct mdio_device *mdiodev)
return 0;
}
+static int mdiobus_register_clock(struct mdio_device *mdiodev)
+{
+ struct clk *clk;
+
+ clk = devm_clk_get_optional(&mdiodev->dev, NULL);
+ if (IS_ERR(clk))
+ return PTR_ERR(clk);
+
+ mdiodev->clk = clk;
+
+ return 0;
+}
+
int mdiobus_register_device(struct mdio_device *mdiodev)
{
int err;
@@ -83,6 +97,10 @@ int mdiobus_register_device(struct mdio_device *mdiodev)
if (err)
return err;
+ err = mdiobus_register_clock(mdiodev);
+ if (err)
+ return err;
+
/* Assert the reset signal */
mdio_device_reset(mdiodev, 1);
}
diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c
index 250742ffdfd9..e8424a46a81e 100644
--- a/drivers/net/phy/mdio_device.c
+++ b/drivers/net/phy/mdio_device.c
@@ -6,6 +6,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/gpio.h>
@@ -136,6 +137,14 @@ void mdio_device_reset(struct mdio_device *mdiodev, int value)
}
EXPORT_SYMBOL(mdio_device_reset);
+static void mdio_device_toggle_clock(struct mdio_device *mdiodev, int value)
+{
+ if (value)
+ clk_prepare_enable(mdiodev->clk);
+ else
+ clk_disable_unprepare(mdiodev->clk);
+}
+
/**
* mdio_probe - probe an MDIO device
* @dev: device to probe
@@ -152,11 +161,13 @@ static int mdio_probe(struct device *dev)
/* Deassert the reset signal */
mdio_device_reset(mdiodev, 0);
+ mdio_device_toggle_clock(mdiodev, 1);
if (mdiodrv->probe) {
err = mdiodrv->probe(mdiodev);
if (err) {
/* Assert the reset signal */
+ mdio_device_toggle_clock(mdiodev, 0);
mdio_device_reset(mdiodev, 1);
}
}
@@ -174,6 +185,7 @@ static int mdio_remove(struct device *dev)
mdiodrv->remove(mdiodev);
/* Assert the reset signal */
+ mdio_device_toggle_clock(mdiodev, 0);
mdio_device_reset(mdiodev, 1);
return 0;
diff --git a/include/linux/mdio.h b/include/linux/mdio.h
index 00177567cfef..95c13bdb312b 100644
--- a/include/linux/mdio.h
+++ b/include/linux/mdio.h
@@ -50,6 +50,7 @@ struct mdio_device {
struct reset_control *reset_ctrl;
unsigned int reset_assert_delay;
unsigned int reset_deassert_delay;
+ struct clk *clk;
};
static inline struct mdio_device *to_mdio_device(const struct device *dev)
--
2.35.3
next reply other threads:[~2022-07-04 0:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-04 0:45 Andre Przywara [this message]
2022-07-04 8:05 ` Andrew Lunn
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=20220704004533.17762-1-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=jernej.skrabec@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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
all inboxes | Powered by JetHome®