* [PATCH 1/3] net: davinci_mdio: drop phy_mask detection
2024-11-13 8:29 [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
@ 2024-11-13 8:29 ` Sascha Hauer
2024-11-13 8:29 ` [PATCH 2/3] net: davinci_mdio: initialize priv->dev Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-11-13 8:29 UTC (permalink / raw)
To: open list:BAREBOX
The davinci_mdio driver tries to autodetect connected phys using the
controllers internal state engine that seems to periodically scan for
phys. It then sets phy_mask according to the phys found. This doesn't
work on a beagleplay board because the timeout is too short.
This phy detection mechanism is an optimization only, which in the best
case saves some time needed to scan the bus for phys later on. Normally
the phys are described in the device tree, in this case the bus isn't
scanned for devices anyway, so instead of adjusting the timeout we can
drop the whole thing altogether.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/davinci_mdio.c | 29 -----------------------------
1 file changed, 29 deletions(-)
diff --git a/drivers/net/davinci_mdio.c b/drivers/net/davinci_mdio.c
index c5cd28fba4..fad14e92ea 100644
--- a/drivers/net/davinci_mdio.c
+++ b/drivers/net/davinci_mdio.c
@@ -110,8 +110,6 @@ static int cpsw_mdio_probe(struct device *dev)
{
struct resource *iores;
struct cpsw_mdio_priv *priv;
- uint64_t start;
- uint32_t phy_mask;
int ret;
priv = xzalloc(sizeof(*priv));
@@ -137,33 +135,6 @@ static int cpsw_mdio_probe(struct device *dev)
*/
writel(0xff | CONTROL_ENABLE, &priv->mdio_regs->control);
- /*
- * wait for scan logic to settle:
- * the scan time consists of (a) a large fixed component, and (b) a
- * small component that varies with the mii bus frequency. These
- * were estimated using measurements at 1.1 and 2.2 MHz on tnetv107x
- * silicon. Since the effect of (b) was found to be largely
- * negligible, we keep things simple here.
- */
- udelay(2000);
-
- start = get_time_ns();
- while (1) {
- phy_mask = readl(&priv->mdio_regs->alive);
- if (phy_mask) {
- dev_info(dev, "detected phy mask 0x%x\n", phy_mask);
- phy_mask = ~phy_mask;
- break;
- }
- if (is_timeout(start, 256 * MSECOND)) {
- dev_err(dev, "no live phy, scanning all\n");
- phy_mask = 0;
- break;
- }
- }
-
- priv->miibus.phy_mask = phy_mask;
-
ret = mdiobus_register(&priv->miibus);
if (ret)
return ret;
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] net: davinci_mdio: initialize priv->dev
2024-11-13 8:29 [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
2024-11-13 8:29 ` [PATCH 1/3] net: davinci_mdio: drop phy_mask detection Sascha Hauer
@ 2024-11-13 8:29 ` Sascha Hauer
2024-11-13 8:29 ` [PATCH 3/3] net: davinci_mdio: initialize divider from clk Sascha Hauer
2024-11-25 10:26 ` [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-11-13 8:29 UTC (permalink / raw)
To: open list:BAREBOX
struct cpsw_mdio_priv has a struct device *dev member which is used, but
never initialized. Add the missing initialization.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/davinci_mdio.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/davinci_mdio.c b/drivers/net/davinci_mdio.c
index fad14e92ea..ef08911f3f 100644
--- a/drivers/net/davinci_mdio.c
+++ b/drivers/net/davinci_mdio.c
@@ -113,6 +113,7 @@ static int cpsw_mdio_probe(struct device *dev)
int ret;
priv = xzalloc(sizeof(*priv));
+ priv->dev = dev;
/* If we can't request I/O memory region, we'll assume parent did
* it for us
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] net: davinci_mdio: initialize divider from clk
2024-11-13 8:29 [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
2024-11-13 8:29 ` [PATCH 1/3] net: davinci_mdio: drop phy_mask detection Sascha Hauer
2024-11-13 8:29 ` [PATCH 2/3] net: davinci_mdio: initialize priv->dev Sascha Hauer
@ 2024-11-13 8:29 ` Sascha Hauer
2024-11-25 10:26 ` [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-11-13 8:29 UTC (permalink / raw)
To: open list:BAREBOX
Instead of using a fixed divider value calculate a divider from the
input clock.
We currently do not have clk support for am33xx, so we can't handle
no clk as an error. In this case assume a clock frequency of 256MHz.
With a default desired MDIO clock of 1MHz (used in many TI dtsi files)
we get a divider value of 0xff which we previously used as hardcoded
value.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/net/davinci_mdio.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/net/davinci_mdio.c b/drivers/net/davinci_mdio.c
index ef08911f3f..a0cff97aa5 100644
--- a/drivers/net/davinci_mdio.c
+++ b/drivers/net/davinci_mdio.c
@@ -7,6 +7,7 @@
#include <clock.h>
#include <xfuncs.h>
#include <io.h>
+#include <linux/clk.h>
#define PHY_REG_MASK 0x1f
#define PHY_ID_MASK 0x1f
@@ -43,6 +44,7 @@ struct cpsw_mdio_priv {
struct device *dev;
struct mii_bus miibus;
struct cpsw_mdio_regs *mdio_regs;
+ struct clk *clk;
};
/* wait until hardware is ready for another user access */
@@ -106,6 +108,28 @@ static int cpsw_mdio_write(struct mii_bus *bus, int phy_id, int phy_reg, u16 val
return 0;
}
+#define CONTROL_MAX_DIV 0xffff
+
+static void cpsw_mdio_init_clk(struct cpsw_mdio_priv *priv)
+{
+ u32 mdio_in, clk_div;
+ u32 bus_freq = 2560000;
+
+ of_property_read_u32(priv->dev->of_node, "bus_freq", &bus_freq);
+
+ priv->clk = clk_get_enabled(priv->dev, "fck");
+ if (IS_ERR(priv->clk))
+ mdio_in = 250000000;
+ else
+ mdio_in = clk_get_rate(priv->clk);
+
+ clk_div = (mdio_in / bus_freq) - 1;
+ if (clk_div > CONTROL_MAX_DIV)
+ clk_div = CONTROL_MAX_DIV;
+
+ writel(clk_div | CONTROL_ENABLE, &priv->mdio_regs->control);
+}
+
static int cpsw_mdio_probe(struct device *dev)
{
struct resource *iores;
@@ -129,12 +153,7 @@ static int cpsw_mdio_probe(struct device *dev)
priv->miibus.priv = priv;
priv->miibus.parent = dev;
- /*
- * set enable and clock divider
- *
- * FIXME: Use a clock to calculate the divider
- */
- writel(0xff | CONTROL_ENABLE, &priv->mdio_regs->control);
+ cpsw_mdio_init_clk(priv);
ret = mdiobus_register(&priv->miibus);
if (ret)
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] davinci_mdio: clk fixes
2024-11-13 8:29 [PATCH 0/3] davinci_mdio: clk fixes Sascha Hauer
` (2 preceding siblings ...)
2024-11-13 8:29 ` [PATCH 3/3] net: davinci_mdio: initialize divider from clk Sascha Hauer
@ 2024-11-25 10:26 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-11-25 10:26 UTC (permalink / raw)
To: open list:BAREBOX, Sascha Hauer
On Wed, 13 Nov 2024 09:29:26 +0100, Sascha Hauer wrote:
> This series fixes some deficiencies in the davinci_mdio driver
>
>
Applied, thanks!
[1/3] net: davinci_mdio: drop phy_mask detection
https://git.pengutronix.de/cgit/barebox/commit/?id=643dcaaa036d (link may not be stable)
[2/3] net: davinci_mdio: initialize priv->dev
https://git.pengutronix.de/cgit/barebox/commit/?id=1de09fa72aa1 (link may not be stable)
[3/3] net: davinci_mdio: initialize divider from clk
https://git.pengutronix.de/cgit/barebox/commit/?id=eba8de9eadb1 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 5+ messages in thread