add chaos_calmer branch
[15.05/openwrt.git] / target / linux / ipq806x / patches-4.0 / 701-stmmac-add-phy-handle-support-to-the-platform-layer.patch
1 From 4f09499bc1d9bb095caccbcd73ff951ee631e521 Mon Sep 17 00:00:00 2001
2 From: Mathieu Olivari <mathieu@codeaurora.org>
3 Date: Fri, 8 May 2015 15:42:40 -0700
4 Subject: [PATCH 1/8] stmmac: add phy-handle support to the platform layer
5
6 On stmmac driver, PHY specification in device-tree was done using the
7 non-standard property "snps,phy-addr". Specifying a PHY on a different
8 MDIO bus that the one within the stmmac controller doesn't seem to be
9 possible when device-tree is used.
10
11 This change adds support for the phy-handle property, as specified in
12 Documentation/devicetree/bindings/net/ethernet.txt.
13
14 Signed-off-by: Mathieu Olivari <mathieu@codeaurora.org>
15 ---
16  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c  | 28 ++++++++++++++--------
17  .../net/ethernet/stmicro/stmmac/stmmac_platform.c  |  6 ++++-
18  include/linux/stmmac.h                             |  1 +
19  3 files changed, 24 insertions(+), 11 deletions(-)
20
21 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
22 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
23 @@ -52,6 +52,7 @@
24  #include "stmmac_ptp.h"
25  #include "stmmac.h"
26  #include <linux/reset.h>
27 +#include <linux/of_mdio.h>
28  
29  #define STMMAC_ALIGN(x)        L1_CACHE_ALIGN(x)
30  
31 @@ -816,18 +817,25 @@ static int stmmac_init_phy(struct net_de
32         priv->speed = 0;
33         priv->oldduplex = -1;
34  
35 -       if (priv->plat->phy_bus_name)
36 -               snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
37 -                        priv->plat->phy_bus_name, priv->plat->bus_id);
38 -       else
39 -               snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
40 -                        priv->plat->bus_id);
41 -
42 -       snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
43 -                priv->plat->phy_addr);
44 -       pr_debug("stmmac_init_phy:  trying to attach to %s\n", phy_id_fmt);
45 +       if (priv->plat->phy_node) {
46 +               phydev = of_phy_connect(dev, priv->plat->phy_node,
47 +                                       &stmmac_adjust_link, 0, interface);
48 +       } else {
49 +               if (priv->plat->phy_bus_name)
50 +                       snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
51 +                                priv->plat->phy_bus_name, priv->plat->bus_id);
52 +               else
53 +                       snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
54 +                                priv->plat->bus_id);
55 +
56 +               snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
57 +                        priv->plat->phy_addr);
58 +               pr_debug("stmmac_init_phy:  trying to attach to %s\n",
59 +                        phy_id_fmt);
60  
61 -       phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link, interface);
62 +               phydev = phy_connect(dev, phy_id_fmt, &stmmac_adjust_link,
63 +                                    interface);
64 +       }
65  
66         if (IS_ERR(phydev)) {
67                 pr_err("%s: Could not attach to PHY\n", dev->name);
68 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
69 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
70 @@ -27,6 +27,7 @@
71  #include <linux/of.h>
72  #include <linux/of_net.h>
73  #include <linux/of_device.h>
74 +#include <linux/of_mdio.h>
75  
76  #include "stmmac.h"
77  #include "stmmac_platform.h"
78 @@ -167,13 +168,16 @@ static int stmmac_probe_config_dt(struct
79         /* Default to phy auto-detection */
80         plat->phy_addr = -1;
81  
82 +       /* If we find a phy-handle property, use it as the PHY */
83 +       plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
84 +
85         /* "snps,phy-addr" is not a standard property. Mark it as deprecated
86          * and warn of its use. Remove this when phy node support is added.
87          */
88         if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
89                 dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
90  
91 -       if (plat->phy_bus_name)
92 +       if (plat->phy_node || plat->phy_bus_name)
93                 plat->mdio_bus_data = NULL;
94         else
95                 plat->mdio_bus_data =
96 --- a/include/linux/stmmac.h
97 +++ b/include/linux/stmmac.h
98 @@ -99,6 +99,7 @@ struct plat_stmmacenet_data {
99         int phy_addr;
100         int interface;
101         struct stmmac_mdio_bus_data *mdio_bus_data;
102 +       struct device_node *phy_node;
103         struct stmmac_dma_cfg *dma_cfg;
104         int clk_csr;
105         int has_gmac;