Skip to content

Commit 1fadee0

Browse files
saschahauerdavem330
authored andcommitted
net/phy: micrel: Add clock support for KSZ8021/KSZ8031
The KSZ8021 and KSZ8031 support RMII reference input clocks of 25MHz and 50MHz. Both PHYs differ in the default frequency they expect after reset. If this differs from the actual input clock, then register 0x1f bit 7 must be changed. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5af7fb6 commit 1fadee0

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎Documentation/devicetree/bindings/net/micrel.txt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ Optional properties:
1616
KSZ8051: register 0x1f, bits 5..4
1717

1818
See the respective PHY datasheet for the mode values.
19+
20+
- clocks, clock-names: contains clocks according to the common clock bindings.
21+
22+
supported clocks:
23+
- KSZ8021, KSZ8031: "rmii-ref": The RMII refence input clock. Used
24+
to determine the XI input clock.

‎drivers/net/phy/micrel.c‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/phy.h>
2727
#include <linux/micrel_phy.h>
2828
#include <linux/of.h>
29+
#include <linux/clk.h>
2930

3031
/* Operation Mode Strap Override */
3132
#define MII_KSZPHY_OMSO 0x16
@@ -72,9 +73,12 @@ static int ksz_config_flags(struct phy_device *phydev)
7273
{
7374
int regval;
7475

75-
if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK) {
76+
if (phydev->dev_flags & (MICREL_PHY_50MHZ_CLK | MICREL_PHY_25MHZ_CLK)) {
7677
regval = phy_read(phydev, MII_KSZPHY_CTRL);
77-
regval |= KSZ8051_RMII_50MHZ_CLK;
78+
if (phydev->dev_flags & MICREL_PHY_50MHZ_CLK)
79+
regval |= KSZ8051_RMII_50MHZ_CLK;
80+
else
81+
regval &= ~KSZ8051_RMII_50MHZ_CLK;
7882
return phy_write(phydev, MII_KSZPHY_CTRL, regval);
7983
}
8084
return 0;
@@ -440,6 +444,27 @@ ksz9021_wr_mmd_phyreg(struct phy_device *phydev, int ptrad, int devnum,
440444
{
441445
}
442446

447+
static int ksz8021_probe(struct phy_device *phydev)
448+
{
449+
struct clk *clk;
450+
451+
clk = devm_clk_get(&phydev->dev, "rmii-ref");
452+
if (!IS_ERR(clk)) {
453+
unsigned long rate = clk_get_rate(clk);
454+
455+
if (rate > 24500000 && rate < 25500000) {
456+
phydev->dev_flags |= MICREL_PHY_25MHZ_CLK;
457+
} else if (rate > 49500000 && rate < 50500000) {
458+
phydev->dev_flags |= MICREL_PHY_50MHZ_CLK;
459+
} else {
460+
dev_err(&phydev->dev, "Clock rate out of range: %ld\n", rate);
461+
return -EINVAL;
462+
}
463+
}
464+
465+
return 0;
466+
}
467+
443468
static struct phy_driver ksphy_driver[] = {
444469
{
445470
.phy_id = PHY_ID_KS8737,
@@ -462,6 +487,7 @@ static struct phy_driver ksphy_driver[] = {
462487
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
463488
SUPPORTED_Asym_Pause),
464489
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
490+
.probe = ksz8021_probe,
465491
.config_init = ksz8021_config_init,
466492
.config_aneg = genphy_config_aneg,
467493
.read_status = genphy_read_status,
@@ -477,6 +503,7 @@ static struct phy_driver ksphy_driver[] = {
477503
.features = (PHY_BASIC_FEATURES | SUPPORTED_Pause |
478504
SUPPORTED_Asym_Pause),
479505
.flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
506+
.probe = ksz8021_probe,
480507
.config_init = ksz8021_config_init,
481508
.config_aneg = genphy_config_aneg,
482509
.read_status = genphy_read_status,

‎include/linux/micrel_phy.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
/* struct phy_device dev_flags definitions */
3939
#define MICREL_PHY_50MHZ_CLK 0x00000001
40+
#define MICREL_PHY_25MHZ_CLK 0x00000002
4041

4142
#define MICREL_KSZ9021_EXTREG_CTRL 0xB
4243
#define MICREL_KSZ9021_EXTREG_DATA_WRITE 0xC

0 commit comments

Comments
 (0)