History

Merge branch 'mscc-miim'

Michael Walle says: ==================== 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 ====================

David S. Miller committed 4 years ago

Commit 44ec5f72 parents 1ee375d bb2a1933 files · +117 −28Browse files

Unified · Split

3 files
  1. Documentation/devicetree/bindings/net/mscc,miim.yaml +61 −0
  2. Documentation/devicetree/bindings/net/mscc-miim.txt +0 −26
  3. drivers/net/mdio/mdio-mscc-miim.c +56 −2
Documentation/devicetree/bindings/net/mscc,miim.yaml+61−0
@@ -0,0 +1,61 @@
1+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
2+%YAML 1.2
3+---
4+$id: http://devicetree.org/schemas/net/mscc,miim.yaml#
5+$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+title: Microsemi MII Management Controller (MIIM)
8+
9+maintainers:
10+ - Alexandre Belloni <alexandre.belloni@bootlin.com>
11+
12+allOf:
13+ - $ref: "mdio.yaml#"
14+
15+properties:
16+ compatible:
17+ enum:
18+ - mscc,ocelot-miim
19+ - microchip,lan966x-miim
20+
21+ "#address-cells":
22+ const: 1
23+
24+ "#size-cells":
25+ const: 0
26+
27+ reg:
28+ items:
29+ - description: base address
30+ - description: associated reset register for internal PHYs
31+ minItems: 1
32+
33+ interrupts:
34+ maxItems: 1
35+
36+ clocks:
37+ maxItems: 1
38+
39+ clock-frequency: true
40+
41+required:
42+ - compatible
43+ - reg
44+ - "#address-cells"
45+ - "#size-cells"
46+
47+unevaluatedProperties: false
48+
49+examples:
50+ - |
51+ mdio@107009c {
52+ compatible = "mscc,ocelot-miim";
53+ reg = <0x107009c 0x36>, <0x10700f0 0x8>;
54+ interrupts = <14>;
55+ #address-cells = <1>;
56+ #size-cells = <0>;
57+
58+ phy0: ethernet-phy@0 {
59+ reg = <0>;
60+ };
61+ };
Documentation/devicetree/bindings/net/mscc-miim.txt+0−26
@@ -1,26 +0,0 @@
1−Microsemi MII Management Controller (MIIM) / MDIO
2−=================================================
3−
4−Properties:
5−- compatible: must be "mscc,ocelot-miim" or "microchip,lan966x-miim"
6−- reg: The base address of the MDIO bus controller register bank. Optionally, a
7− second register bank can be defined if there is an associated reset register
8− for internal PHYs
9−- #address-cells: Must be <1>.
10−- #size-cells: Must be <0>. MDIO addresses have no size component.
11−- interrupts: interrupt specifier (refer to the interrupt binding)
12−
13−Typically an MDIO bus might have several children.
14−
15−Example:
16− mdio@107009c {
17− #address-cells = <1>;
18− #size-cells = <0>;
19− compatible = "mscc,ocelot-miim";
20− reg = <0x107009c 0x36>, <0x10700f0 0x8>;
21− interrupts = <14>;
22−
23− phy0: ethernet-phy@0 {
24− reg = <0>;
25− };
26− };
drivers/net/mdio/mdio-mscc-miim.c+56−2
@@ -7,6 +7,7 @@ · 6 unmodified lines
77 */
88
99 #include <linux/bitops.h>
10+#include <linux/clk.h>
1011 #include <linux/io.h>
1112 #include <linux/iopoll.h>
1213 #include <linux/kernel.h>
@@ -30,6 +31,8 @@ · 17 unmodified lines
3031 #define MSCC_MIIM_CMD_VLD BIT(31)
3132 #define MSCC_MIIM_REG_DATA 0xC
3233 #define MSCC_MIIM_DATA_ERROR (BIT(16) | BIT(17))
34+#define MSCC_MIIM_REG_CFG 0x10
35+#define MSCC_MIIM_CFG_PRESCALE_MASK GENMASK(7, 0)
3336
3437 #define MSCC_PHY_REG_PHY_CFG 0x0
3538 #define PHY_CFG_PHY_ENA (BIT(0) | BIT(1) | BIT(2) | BIT(3))
@@ -50,6 +53,8 @@ struct mscc_miim_dev { · 14 unmodified lines
5053 int mii_status_offset;
5154 struct regmap *phy_regs;
5255 const struct mscc_miim_info *info;
56+ struct clk *clk;
57+ u32 bus_freq;
5358 };
5459
5560 /* When high resolution timers aren't built-in: we can't use usleep_range() as
@@ -235,9 +240,32 @@ int mscc_miim_setup(struct device *dev, struct mii_bus **pbus, const char *name, · 179 unmodified lines
235240 }
236241 EXPORT_SYMBOL(mscc_miim_setup);
237242
243+static int mscc_miim_clk_set(struct mii_bus *bus)
244+{
245+ struct mscc_miim_dev *miim = bus->priv;
246+ unsigned long rate;
247+ u32 div;
248+
249+ /* Keep the current settings */
250+ if (!miim->bus_freq)
251+ return 0;
252+
253+ rate = clk_get_rate(miim->clk);
254+
255+ div = DIV_ROUND_UP(rate, 2 * miim->bus_freq) - 1;
256+ if (div == 0 || div & ~MSCC_MIIM_CFG_PRESCALE_MASK) {
257+ dev_err(&bus->dev, "Incorrect MDIO clock frequency\n");
258+ return -EINVAL;
259+ }
260+
261+ return regmap_update_bits(miim->regs, MSCC_MIIM_REG_CFG,
262+ MSCC_MIIM_CFG_PRESCALE_MASK, div);
263+}
264+
238265 static int mscc_miim_probe(struct platform_device *pdev)
239266 {
240267 struct regmap *mii_regmap, *phy_regmap = NULL;
268+ struct device_node *np = pdev->dev.of_node;
241269 void __iomem *regs, *phy_regs;
242270 struct mscc_miim_dev *miim;
243271 struct resource *res;
@@ -288,21 +316,47 @@ static int mscc_miim_probe(struct platform_device *pdev) · 44 unmodified lines
288316 if (!miim->info)
289317 return -EINVAL;
290318
291− ret = of_mdiobus_register(bus, pdev->dev.of_node);
319+ miim->clk = devm_clk_get_optional(&pdev->dev, NULL);
320+ if (IS_ERR(miim->clk))
321+ return PTR_ERR(miim->clk);
322+
323+ of_property_read_u32(np, "clock-frequency", &miim->bus_freq);
324+
325+ if (miim->bus_freq && !miim->clk) {
326+ dev_err(&pdev->dev,
327+ "cannot use clock-frequency without a clock\n");
328+ return -EINVAL;
329+ }
330+
331+ ret = clk_prepare_enable(miim->clk);
332+ if (ret)
333+ return ret;
334+
335+ ret = mscc_miim_clk_set(bus);
336+ if (ret)
337+ goto out_disable_clk;
338+
339+ ret = of_mdiobus_register(bus, np);
292340 if (ret < 0) {
293341 dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret);
294− return ret;
342+ goto out_disable_clk;
295343 }
296344
297345 platform_set_drvdata(pdev, bus);
298346
299347 return 0;
348+
349+out_disable_clk:
350+ clk_disable_unprepare(miim->clk);
351+ return ret;
300352 }
301353
302354 static int mscc_miim_remove(struct platform_device *pdev)
303355 {
304356 struct mii_bus *bus = platform_get_drvdata(pdev);
357+ struct mscc_miim_dev *miim = bus->priv;
305358
359+ clk_disable_unprepare(miim->clk);
306360 mdiobus_unregister(bus);
307361
308362 return 0;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t