sunxi: driver refresh for 3.13
[openwrt.git] / target / linux / sunxi / patches-3.13 / 151-1-stmmac-fixup-1.patch
1 From 9cbadf094d9d479413dc8cfa77dff9e732184337 Mon Sep 17 00:00:00 2001
2 From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
3 Date: Thu, 16 Jan 2014 10:51:43 +0000
4 Subject: [PATCH] net: stmmac: support max-speed device tree property
5
6 This patch adds support to "max-speed" property which is a standard
7 Ethernet device tree property. max-speed specifies maximum speed
8 (specified in megabits per second) supported the device.
9
10 Depending on the clocking schemes some of the boards can only support
11 few link speeds, so having a way to limit the link speed in the mac
12 driver would allow such setups to work reliably.
13
14 Without this patch there is no way to tell the driver to limit the
15 link speed.
16
17 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
18 Acked-by: Giuseppe Cavallaro <peppe.cavallaro@st.com>
19 Signed-off-by: David S. Miller <davem@davemloft.net>
20 ---
21  drivers/net/ethernet/stmicro/stmmac/stmmac_main.c     | 4 +++-
22  drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 4 ++++
23  include/linux/stmmac.h                                | 1 +
24  3 files changed, 8 insertions(+), 1 deletion(-)
25
26 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
27 index ecdc8ab..15192c0 100644
28 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
29 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
30 @@ -776,6 +776,7 @@ static int stmmac_init_phy(struct net_device *dev)
31         char phy_id_fmt[MII_BUS_ID_SIZE + 3];
32         char bus_id[MII_BUS_ID_SIZE];
33         int interface = priv->plat->interface;
34 +       int max_speed = priv->plat->max_speed;
35         priv->oldlink = 0;
36         priv->speed = 0;
37         priv->oldduplex = -1;
38 @@ -800,7 +801,8 @@ static int stmmac_init_phy(struct net_device *dev)
39  
40         /* Stop Advertising 1000BASE Capability if interface is not GMII */
41         if ((interface == PHY_INTERFACE_MODE_MII) ||
42 -           (interface == PHY_INTERFACE_MODE_RMII))
43 +           (interface == PHY_INTERFACE_MODE_RMII) ||
44 +               (max_speed < 1000 &&  max_speed > 0))
45                 phydev->advertising &= ~(SUPPORTED_1000baseT_Half |
46                                          SUPPORTED_1000baseT_Full);
47  
48 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
49 index 38bd1f4..9377ee6 100644
50 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
51 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
52 @@ -42,6 +42,10 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
53         *mac = of_get_mac_address(np);
54         plat->interface = of_get_phy_mode(np);
55  
56 +       /* Get max speed of operation from device tree */
57 +       if (of_property_read_u32(np, "max-speed", &plat->max_speed))
58 +               plat->max_speed = -1;
59 +
60         plat->bus_id = of_alias_get_id(np, "ethernet");
61         if (plat->bus_id < 0)
62                 plat->bus_id = 0;
63 diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h
64 index bb5deb0..33ace71 100644
65 --- a/include/linux/stmmac.h
66 +++ b/include/linux/stmmac.h
67 @@ -110,6 +110,7 @@ struct plat_stmmacenet_data {
68         int force_sf_dma_mode;
69         int force_thresh_dma_mode;
70         int riwt_off;
71 +       int max_speed;
72         void (*fix_mac_speed)(void *priv, unsigned int speed);
73         void (*bus_setup)(void __iomem *ioaddr);
74         int (*init)(struct platform_device *pdev);
75 -- 
76 1.8.5.5
77