Skip to contentSkip to conversation

net: phy: mscc-miim: add MDIO bus frequency support

PATCH Applied Michael Walle 3 participants 7 messages Apr 5, 2022 – Apr 6, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover net: phy: mscc-miim: add MDIO bus frequency support

Introduce MDIO bus frequency support. This way the board can have a faster (or maybe slower) bus frequency than the hardware default.

changes since v2:
- resend, no RFC anymore, because net-next is open again

changes since v1:
- fail probe if clock-frequency is set, but not clock is given
- rename clk_freq to bus_freq
- add maxItems to interrupts property
- put compatible and reg first in the example

Michael Walle (3):
dt-bindings: net: convert mscc-miim to YAML format
dt-bindings: net: mscc-miim: add clock and clock-frequency
net: phy: mscc-miim: add support to set MDIO bus frequency

 .../devicetree/bindings/net/mscc,miim.yaml    | 61 +++++++++++++++++++
 .../devicetree/bindings/net/mscc-miim.txt     | 26 --------
 drivers/net/mdio/mdio-mscc-miim.c             | 58 +++++++++++++++++-
 3 files changed, 117 insertions(+), 28 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/mscc,miim.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/mscc-miim.txt
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 1/3 dt-bindings: net: convert mscc-miim to YAML format

Convert the mscc-miim device tree binding to the new YAML format.

The original binding don't mention if the interrupt property is optional or not. But on the SparX-5 SoC, for example, the interrupt property isn't used, thus in the new binding that property is optional. FWIW the driver doesn't use interrupts at all.

---
 .../devicetree/bindings/net/mscc,miim.yaml    | 56 +++++++++++++++++++
 .../devicetree/bindings/net/mscc-miim.txt     | 26 ---------
 2 files changed, 56 insertions(+), 26 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/mscc,miim.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/mscc-miim.txt
Documentation/devicetree/bindings/net/mscc,miim.yaml new file +56 -0
new file mode 100644
index 000000000000..cdc39aa20683
@@ -0,0 +1,56 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/mscc,miim.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microsemi MII Management Controller (MIIM)
+
+maintainers:
+  - Alexandre Belloni <[email protected]>
+
+allOf:
+  - $ref: "mdio.yaml#"
+
+properties:
+  compatible:
+    enum:
+      - mscc,ocelot-miim
+      - microchip,lan966x-miim
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  reg:
+    items:
+      - description: base address
+      - description: associated reset register for internal PHYs
+    minItems: 1
+
+  interrupts:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio@107009c {
+      compatible = "mscc,ocelot-miim";
+      reg = <0x107009c 0x36>, <0x10700f0 0x8>;
+      interrupts = <14>;
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      phy0: ethernet-phy@0 {
+        reg = <0>;
+      };
+    };
Documentation/devicetree/bindings/net/mscc-miim.txt deleted +0 -26
deleted file mode 100644
index 70e0cb1ee485..000000000000
@@ -1,26 +0,0 @@
-Microsemi MII Management Controller (MIIM) / MDIO
-=================================================
-
-Properties:
-- compatible: must be "mscc,ocelot-miim" or "microchip,lan966x-miim"
-- reg: The base address of the MDIO bus controller register bank. Optionally, a
-  second register bank can be defined if there is an associated reset register
-  for internal PHYs
-- #address-cells: Must be <1>.
-- #size-cells: Must be <0>.  MDIO addresses have no size component.
-- interrupts: interrupt specifier (refer to the interrupt binding)
-
-Typically an MDIO bus might have several children.
-
-Example:
-	mdio@107009c {
-		#address-cells = <1>;
-		#size-cells = <0>;
-		compatible = "mscc,ocelot-miim";
-		reg = <0x107009c 0x36>, <0x10700f0 0x8>;
-		interrupts = <14>;
-
-		phy0: ethernet-phy@0 {
-			reg = <0>;
-		};
-	};
Signature · 1 line
2.30.2
maintainer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH net-next v3 1/3] dt-bindings: net: convert mscc-miim to YAML format

Quoted 9 lines · Michael Walle

Convert the mscc-miim device tree binding to the new YAML format.

The original binding don't mention if the interrupt property is optional or not. But on the SparX-5 SoC, for example, the interrupt property isn't used, thus in the new binding that property is optional. FWIW the driver doesn't use interrupts at all.

Andrew

#3 lore raw

PATCH v3 2/3 dt-bindings: net: mscc-miim: add clock and clock-frequency

In reply to Michael Walle

Add the (optional) clock input of the MDIO controller and indicate that the common clock-frequency property is supported. The driver can use it to set the desired MDIO bus frequency.

---
 Documentation/devicetree/bindings/net/mscc,miim.yaml | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/net/mscc,miim.yaml +5 -0
index cdc39aa20683..2c451cfa4e0b 100644
@@ -33,6 +33,11 @@ properties:
   interrupts:
     maxItems: 1
 
+  clocks:
+    maxItems: 1
+
+  clock-frequency: true
+
 required:
   - compatible
   - reg
Signature · 1 line
2.30.2
maintainer Reviewed-by on v3 2/3
#4 lore raw

Re: [PATCH net-next v3 2/3] dt-bindings: net: mscc-miim: add clock and clock-frequency

Quoted 6 lines · Michael Walle

Add the (optional) clock input of the MDIO controller and indicate that the common clock-frequency property is supported. The driver can use it to set the desired MDIO bus frequency.

Andrew

#5 lore raw

PATCH v3 3/3 net: phy: mscc-miim: add support to set MDIO bus frequency

In reply to Michael Walle

Until now, the MDIO bus will have the hardware default bus frequency. Read the desired frequency of the bus from the device tree and configure it.

---
 drivers/net/mdio/mdio-mscc-miim.c | 58 +++++++++++++++++++++++++++++--
 1 file changed, 56 insertions(+), 2 deletions(-)
drivers/net/mdio/mdio-mscc-miim.c +56 -2
index c9efcfa2a1ce..7fd979f68dc0 100644
@@ -7,6 +7,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <linux/kernel.h>
@@ -30,6 +31,8 @@
 #define		MSCC_MIIM_CMD_VLD		BIT(31)
 #define MSCC_MIIM_REG_DATA		0xC
 #define		MSCC_MIIM_DATA_ERROR		(BIT(16) | BIT(17))
+#define MSCC_MIIM_REG_CFG		0x10
+#define		MSCC_MIIM_CFG_PRESCALE_MASK	GENMASK(7, 0)
 
 #define MSCC_PHY_REG_PHY_CFG	0x0
 #define		PHY_CFG_PHY_ENA		(BIT(0) | BIT(1) | BIT(2) | BIT(3))
@@ -50,6 +53,8 @@ struct mscc_miim_dev {
 	int mii_status_offset;
 	struct regmap *phy_regs;
 	const struct mscc_miim_info *info;
+	struct clk *clk;
+	u32 bus_freq;
 };
 
 /* When high resolution timers aren't built-in: we can't use usleep_range() as
@@ -242,9 +247,32 @@ int mscc_miim_setup(struct device *dev, struct mii_bus **pbus, const char *name,
 }
 EXPORT_SYMBOL(mscc_miim_setup);
 
+static int mscc_miim_clk_set(struct mii_bus *bus)
+{
+	struct mscc_miim_dev *miim = bus->priv;
+	unsigned long rate;
+	u32 div;
+
+	/* Keep the current settings */
+	if (!miim->bus_freq)
+		return 0;
+
+	rate = clk_get_rate(miim->clk);
+
+	div = DIV_ROUND_UP(rate, 2 * miim->bus_freq) - 1;
+	if (div == 0 || div & ~MSCC_MIIM_CFG_PRESCALE_MASK) {
+		dev_err(&bus->dev, "Incorrect MDIO clock frequency\n");
+		return -EINVAL;
+	}
+
+	return regmap_update_bits(miim->regs, MSCC_MIIM_REG_CFG,
+				  MSCC_MIIM_CFG_PRESCALE_MASK, div);
+}
+
 static int mscc_miim_probe(struct platform_device *pdev)
 {
 	struct regmap *mii_regmap, *phy_regmap = NULL;
+	struct device_node *np = pdev->dev.of_node;
 	void __iomem *regs, *phy_regs;
 	struct mscc_miim_dev *miim;
 	struct resource *res;
@@ -295,21 +323,47 @@ static int mscc_miim_probe(struct platform_device *pdev)
 	if (!miim->info)
 		return -EINVAL;
 
-	ret = of_mdiobus_register(bus, pdev->dev.of_node);
+	miim->clk = devm_clk_get_optional(&pdev->dev, NULL);
+	if (IS_ERR(miim->clk))
+		return PTR_ERR(miim->clk);
+
+	of_property_read_u32(np, "clock-frequency", &miim->bus_freq);
+
+	if (miim->bus_freq && !miim->clk) {
+		dev_err(&pdev->dev,
+			"cannot use clock-frequency without a clock\n");
+		return -EINVAL;
+	}
+
+	ret = clk_prepare_enable(miim->clk);
+	if (ret)
+		return ret;
+
+	ret = mscc_miim_clk_set(bus);
+	if (ret)
+		goto out_disable_clk;
+
+	ret = of_mdiobus_register(bus, np);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret);
-		return ret;
+		goto out_disable_clk;
 	}
 
 	platform_set_drvdata(pdev, bus);
 
 	return 0;
+
+out_disable_clk:
+	clk_disable_unprepare(miim->clk);
+	return ret;
 }
 
 static int mscc_miim_remove(struct platform_device *pdev)
 {
 	struct mii_bus *bus = platform_get_drvdata(pdev);
+	struct mscc_miim_dev *miim = bus->priv;
 
+	clk_disable_unprepare(miim->clk);
 	mdiobus_unregister(bus);
 
 	return 0;
Signature · 1 line
2.30.2
#6 lore raw
In reply to Michael Walle
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:

Quoted 6 lines · On Tue, 5 Apr 2022 14:09:48 +0200 you wrote:

Introduce MDIO bus frequency support. This way the board can have a faster (or maybe slower) bus frequency than the hardware default.

changes since v2:
- resend, no RFC anymore, because net-next is open again

Quoted 7 lines

changes since v1:
- fail probe if clock-frequency is set, but not clock is given
- rename clk_freq to bus_freq
- add maxItems to interrupts property
- put compatible and reg first in the example

[...]

Here is the summary with links:
- [net-next,v3,1/3] dt-bindings: net: convert mscc-miim to YAML format

    https://git.kernel.org/netdev/net-next/c/ed941f65da81
  - [net-next,v3,2/3] dt-bindings: net: mscc-miim: add clock and clock-frequency
    https://git.kernel.org/netdev/net-next/c/b0385d4c1fff
  - [net-next,v3,3/3] net: phy: mscc-miim: add support to set MDIO bus frequency
    https://git.kernel.org/netdev/net-next/c/bb2a1934ca01

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html