sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 153-2-stmmac-add-support-for-optional-reset-control.patch
1 From c5e4ddbdfa1134a36589c1466ed4abb85fe6f976 Mon Sep 17 00:00:00 2001
2 From: Chen-Yu Tsai <wens@csie.org>
3 Date: Fri, 17 Jan 2014 21:24:41 +0800
4 Subject: [PATCH] net: stmmac: Add support for optional reset control
5
6 The DWMAC has a reset assert line, which is used on some SoCs. Add an
7 optional reset control to stmmac driver core.
8
9 To support reset control deferred probing, this patch changes the driver
10 probe function to return the actual error, instead of just -EINVAL.
11
12 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
14 ---
15  Documentation/devicetree/bindings/net/stmmac.txt      |  3 +++
16  drivers/net/ethernet/stmicro/stmmac/Kconfig           |  1 +
17  drivers/net/ethernet/stmicro/stmmac/stmmac.h          |  2 ++
18  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c     | 19 ++++++++++++++++++-
19  drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c      |  4 ++--
20  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c |  4 ++--
21  6 files changed, 28 insertions(+), 5 deletions(-)
22
23 diff --git a/Documentation/devicetree/bindings/net/stmmac.txt b/Documentation/devicetree/bindings/net/stmmac.txt
24 index eba0e5e..d132513 100644
25 --- a/Documentation/devicetree/bindings/net/stmmac.txt
26 +++ b/Documentation/devicetree/bindings/net/stmmac.txt
27 @@ -30,6 +30,9 @@ Required properties:
28  
29  Optional properties:
30  - mac-address: 6 bytes, mac address
31 +- resets: Should contain a phandle to the STMMAC reset signal, if any
32 +- reset-names: Should contain the reset signal name "stmmaceth", if a
33 +       reset phandle is given
34  
35  Examples:
36  
37 diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
38 index 6e52c0f..b59d1ef 100644
39 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
40 +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
41 @@ -5,6 +5,7 @@ config STMMAC_ETH
42         select PHYLIB
43         select CRC32
44         select PTP_1588_CLOCK
45 +       select RESET_CONTROLLER
46         ---help---
47           This is the driver for the Ethernet IPs are built around a
48           Synopsys IP Core and only tested on the STMicroelectronics
49 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
50 index 73709e9..c1c141f 100644
51 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
52 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
53 @@ -32,6 +32,7 @@
54  #include <linux/pci.h>
55  #include "common.h"
56  #include <linux/ptp_clock_kernel.h>
57 +#include <linux/reset.h>
58  
59  struct stmmac_priv {
60         /* Frequently used values are kept adjacent for cache effect */
61 @@ -91,6 +92,7 @@ struct stmmac_priv {
62         int wolopts;
63         int wol_irq;
64         struct clk *stmmac_clk;
65 +       struct reset_control *stmmac_rst;
66         int clk_csr;
67         struct timer_list eee_ctrl_timer;
68         int lpi_irq;
69 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
70 index 0d2c4cb..0c5c120 100644
71 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
72 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
73 @@ -51,6 +51,7 @@
74  #include <linux/net_tstamp.h>
75  #include "stmmac_ptp.h"
76  #include "stmmac.h"
77 +#include <linux/reset.h>
78  
79  #define STMMAC_ALIGN(x)        L1_CACHE_ALIGN(x)
80  #define JUMBO_LEN      9000
81 @@ -2728,10 +2729,24 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
82         if (IS_ERR(priv->stmmac_clk)) {
83                 dev_warn(priv->device, "%s: warning: cannot get CSR clock\n",
84                          __func__);
85 +               ret = PTR_ERR(priv->stmmac_clk);
86                 goto error_clk_get;
87         }
88         clk_prepare_enable(priv->stmmac_clk);
89  
90 +       priv->stmmac_rst = devm_reset_control_get(priv->device,
91 +                                                 STMMAC_RESOURCE_NAME);
92 +       if (IS_ERR(priv->stmmac_rst)) {
93 +               if (PTR_ERR(priv->stmmac_rst) == -EPROBE_DEFER) {
94 +                       ret = -EPROBE_DEFER;
95 +                       goto error_hw_init;
96 +               }
97 +               dev_info(priv->device, "no reset control found\n");
98 +               priv->stmmac_rst = NULL;
99 +       }
100 +       if (priv->stmmac_rst)
101 +               reset_control_deassert(priv->stmmac_rst);
102 +
103         /* Init MAC and get the capabilities */
104         ret = stmmac_hw_init(priv);
105         if (ret)
106 @@ -2808,7 +2823,7 @@ struct stmmac_priv *stmmac_dvr_probe(struct device *device,
107  error_clk_get:
108         free_netdev(ndev);
109  
110 -       return NULL;
111 +       return ERR_PTR(ret);
112  }
113  
114  /**
115 @@ -2832,6 +2847,8 @@ int stmmac_dvr_remove(struct net_device *ndev)
116                 stmmac_mdio_unregister(ndev);
117         netif_carrier_off(ndev);
118         unregister_netdev(ndev);
119 +       if (priv->stmmac_rst)
120 +               reset_control_assert(priv->stmmac_rst);
121         clk_disable_unprepare(priv->stmmac_clk);
122         free_netdev(ndev);
123  
124 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
125 index 37ba2e0..2916089 100644
126 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
127 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
128 @@ -100,9 +100,9 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
129         stmmac_default_data();
130  
131         priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
132 -       if (!priv) {
133 +       if (IS_ERR(priv)) {
134                 pr_err("%s: main driver probe failed", __func__);
135 -               ret = -ENODEV;
136 +               ret = PTR_ERR(priv);
137                 goto err_out;
138         }
139         priv->dev->irq = pdev->irq;
140 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
141 index 6d0bf22..cc6b89a7 100644
142 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
143 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
144 @@ -152,9 +152,9 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
145         }
146  
147         priv = stmmac_dvr_probe(&(pdev->dev), plat_dat, addr);
148 -       if (!priv) {
149 +       if (IS_ERR(priv)) {
150                 pr_err("%s: main driver probe failed", __func__);
151 -               return -ENODEV;
152 +               return PTR_ERR(priv);
153         }
154  
155         /* Get MAC address if available (DT) */
156 -- 
157 1.8.5.5
158