kernel: bump 5.4 to 5.4.40
[openwrt/staging/wigyori.git] / target / linux / layerscape / patches-5.4 / 701-net-0314-staging-fsl_ppfe-eth-support-single-interface-initia.patch
1 From dff5fdd84a9ace2d9b8b56659c0855542829148a Mon Sep 17 00:00:00 2001
2 From: Calvin Johnson <calvin.johnson@nxp.com>
3 Date: Fri, 23 Nov 2018 23:58:28 +0530
4 Subject: [PATCH] staging: fsl_ppfe/eth: support single interface
5 initialization
6
7 - arrange members of struct mii_bus in sequence matching phy.h
8 - if mdio node is defined, use of_mdiobus_register to register
9 child nodes (phy devices) available on the mdio bus.
10 - remove of_phy_register_fixed_link from pfe_phy_init as it is being
11 handled in pfe_get_gemac_if_properties
12 - remove mdio enabled check
13 - skip phy init, if no PHY or fixed-link
14
15 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
16 ---
17 drivers/staging/fsl_ppfe/pfe_eth.c | 110 +++++++++++++-----------
18 drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c | 4 +
19 2 files changed, 66 insertions(+), 48 deletions(-)
20
21 --- a/drivers/staging/fsl_ppfe/pfe_eth.c
22 +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
23 @@ -47,6 +47,7 @@
24
25 #define LS1012A_REV_1_0 0x87040010
26
27 +bool pfe_use_old_dts_phy;
28 bool pfe_errata_a010897;
29
30 static void *cbus_emac_base[3];
31 @@ -950,7 +951,8 @@ static int pfe_eth_mdio_init(struct pfe_
32 struct ls1012a_mdio_platform_data *minfo)
33 {
34 struct mii_bus *bus;
35 - int rc, ii;
36 + struct device_node *mdio_node;
37 + int rc = 0, ii;
38 struct phy_device *phydev;
39
40 netif_info(priv, drv, priv->ndev, "%s\n", __func__);
41 @@ -964,25 +966,30 @@ static int pfe_eth_mdio_init(struct pfe_
42 }
43
44 bus->name = "ls1012a MDIO Bus";
45 + snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
46 +
47 + bus->priv = priv;
48 bus->read = &pfe_eth_mdio_read;
49 bus->write = &pfe_eth_mdio_write;
50 bus->reset = &pfe_eth_mdio_reset;
51 - snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
52 - bus->priv = priv;
53 -
54 + bus->parent = priv->pfe->dev;
55 bus->phy_mask = minfo->phy_mask;
56 - priv->mdc_div = minfo->mdc_div;
57 + bus->irq[0] = minfo->irq[0];
58
59 + priv->mdc_div = minfo->mdc_div;
60 if (!priv->mdc_div)
61 priv->mdc_div = 64;
62 -
63 - bus->irq[0] = minfo->irq[0];
64 -
65 - bus->parent = priv->pfe->dev;
66 -
67 netif_info(priv, drv, priv->ndev, "%s: mdc_div: %d, phy_mask: %x\n",
68 __func__, priv->mdc_div, bus->phy_mask);
69 - rc = mdiobus_register(bus);
70 +
71 + mdio_node = of_get_child_by_name(priv->pfe->dev->of_node, "mdio");
72 + if (mdio_node) {
73 + rc = of_mdiobus_register(bus, mdio_node);
74 + of_node_put(mdio_node);
75 + } else {
76 + rc = mdiobus_register(bus);
77 + }
78 +
79 if (rc) {
80 netdev_err(priv->ndev, "mdiobus_register(%s) failed\n",
81 bus->name);
82 @@ -995,7 +1002,6 @@ static int pfe_eth_mdio_init(struct pfe_
83 * 3rd argument as true and then register the phy device
84 * via phy_device_register()
85 */
86 -
87 if (priv->einfo->mii_config == PHY_INTERFACE_MODE_2500SGMII) {
88 for (ii = 0; ii < NUM_GEMAC_SUPPORT; ii++) {
89 phydev = get_phy_device(priv->mii_bus,
90 @@ -1268,8 +1274,6 @@ static int pfe_phy_init(struct net_devic
91 char phy_id[MII_BUS_ID_SIZE + 3];
92 char bus_id[MII_BUS_ID_SIZE];
93 phy_interface_t interface;
94 - struct device_node *phy_node;
95 - int rc;
96
97 priv->oldlink = 0;
98 priv->oldspeed = 0;
99 @@ -1278,7 +1282,6 @@ static int pfe_phy_init(struct net_devic
100 snprintf(bus_id, MII_BUS_ID_SIZE, "ls1012a-%d", 0);
101 snprintf(phy_id, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
102 priv->einfo->phy_id);
103 -
104 netif_info(priv, drv, ndev, "%s: %s\n", __func__, phy_id);
105 interface = priv->einfo->mii_config;
106 if ((interface == PHY_INTERFACE_MODE_SGMII) ||
107 @@ -1301,23 +1304,22 @@ static int pfe_phy_init(struct net_devic
108 priv->oldduplex = -1;
109 pr_info("%s interface %x\n", __func__, interface);
110
111 - if (of_phy_is_fixed_link(priv->phy_node)) {
112 - rc = of_phy_register_fixed_link(priv->phy_node);
113 - if (rc)
114 - return rc;
115 - phy_node = of_node_get(priv->phy_node);
116 - phydev = of_phy_connect(ndev, phy_node, pfe_eth_adjust_link, 0,
117 + if (priv->phy_node) {
118 + phydev = of_phy_connect(ndev, priv->phy_node,
119 + pfe_eth_adjust_link, 0,
120 priv->einfo->mii_config);
121 - of_node_put(phy_node);
122 + if (!(phydev)) {
123 + netdev_err(ndev, "Unable to connect to phy\n");
124 + return -ENODEV;
125 + }
126
127 } else {
128 phydev = phy_connect(ndev, phy_id,
129 &pfe_eth_adjust_link, interface);
130 - }
131 -
132 - if (IS_ERR(phydev)) {
133 - netdev_err(ndev, "phy_connect() failed\n");
134 - return PTR_ERR(phydev);
135 + if (IS_ERR(phydev)) {
136 + netdev_err(ndev, "Unable to connect to phy\n");
137 + return PTR_ERR(phydev);
138 + }
139 }
140
141 priv->phydev = phydev;
142 @@ -2411,13 +2413,10 @@ static int pfe_eth_init_one(struct pfe *
143 memcpy(ndev->dev_addr, einfo[id].mac_addr, ETH_ALEN);
144
145 /* Initialize mdio */
146 - if (minfo[id].enabled) {
147 - err = pfe_eth_mdio_init(priv, &minfo[id]);
148 - if (err) {
149 - netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n",
150 - __func__);
151 - goto err2;
152 - }
153 + err = pfe_eth_mdio_init(priv, &minfo[id]);
154 + if (err) {
155 + netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n", __func__);
156 + goto err1;
157 }
158
159 if (us)
160 @@ -2462,22 +2461,26 @@ static int pfe_eth_init_one(struct pfe *
161 HIF_RX_POLL_WEIGHT - 16);
162
163 err = register_netdev(ndev);
164 -
165 if (err) {
166 netdev_err(ndev, "register_netdev() failed\n");
167 - goto err3;
168 + goto err2;
169 + }
170 +
171 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
172 + ((pfe_use_old_dts_phy) &&
173 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
174 + pr_info("%s: No PHY or fixed-link\n", __func__);
175 + goto skip_phy_init;
176 }
177
178 phy_init:
179 device_init_wakeup(&ndev->dev, WAKE_MAGIC);
180
181 - if (!(priv->einfo->phy_flags & GEMAC_NO_PHY)) {
182 - err = pfe_phy_init(ndev);
183 - if (err) {
184 - netdev_err(ndev, "%s: pfe_phy_init() failed\n",
185 - __func__);
186 - goto err4;
187 - }
188 + err = pfe_phy_init(ndev);
189 + if (err) {
190 + netdev_err(ndev, "%s: pfe_phy_init() failed\n",
191 + __func__);
192 + goto err3;
193 }
194
195 if (us) {
196 @@ -2488,6 +2491,7 @@ phy_init:
197
198 netif_carrier_on(ndev);
199
200 +skip_phy_init:
201 /* Create all the sysfs files */
202 if (pfe_eth_sysfs_init(ndev))
203 goto err4;
204 @@ -2496,13 +2500,16 @@ phy_init:
205 __func__, priv->EMAC_baseaddr);
206
207 return 0;
208 +
209 err4:
210 + pfe_phy_exit(priv->ndev);
211 +err3:
212 if (us)
213 - goto err3;
214 + goto err2;
215 unregister_netdev(ndev);
216 -err3:
217 - pfe_eth_mdio_exit(priv->mii_bus);
218 err2:
219 + pfe_eth_mdio_exit(priv->mii_bus);
220 +err1:
221 free_netdev(priv->ndev);
222 err0:
223 return err;
224 @@ -2553,9 +2560,16 @@ static void pfe_eth_exit_one(struct pfe_
225 if (!us)
226 pfe_eth_sysfs_exit(priv->ndev);
227
228 - if (!(priv->einfo->phy_flags & GEMAC_NO_PHY))
229 - pfe_phy_exit(priv->ndev);
230 + if ((!(pfe_use_old_dts_phy) && !(priv->phy_node)) ||
231 + ((pfe_use_old_dts_phy) &&
232 + (priv->einfo->phy_flags & GEMAC_NO_PHY))) {
233 + pr_info("%s: No PHY or fixed-link\n", __func__);
234 + goto skip_phy_exit;
235 + }
236 +
237 + pfe_phy_exit(priv->ndev);
238
239 +skip_phy_exit:
240 if (!us)
241 unregister_netdev(priv->ndev);
242
243 --- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
244 +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
245 @@ -18,6 +18,7 @@
246
247 #include "pfe_mod.h"
248
249 +extern bool pfe_use_old_dts_phy;
250 struct ls1012a_pfe_platform_data pfe_platform_data;
251
252 static int pfe_get_gemac_if_properties(struct device_node *parent, int port, int
253 @@ -64,8 +65,10 @@ static int pfe_get_gemac_if_properties(s
254 phy_node = of_parse_phandle(gem, "phy-handle", 0);
255 pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
256 if (phy_node) {
257 + pfe_use_old_dts_phy = false;
258 goto process_phynode;
259 } else if (of_phy_is_fixed_link(gem)) {
260 + pfe_use_old_dts_phy = false;
261 if (of_phy_register_fixed_link(gem) < 0) {
262 pr_err("broken fixed-link specification\n");
263 goto err;
264 @@ -73,6 +76,7 @@ static int pfe_get_gemac_if_properties(s
265 phy_node = of_node_get(gem);
266 pdata->ls1012a_eth_pdata[port].phy_node = phy_node;
267 } else if (of_get_property(gem, "fsl,pfe-phy-if-flags", &size)) {
268 + pfe_use_old_dts_phy = true;
269 /* Use old dts properties for phy handling */
270 addr = of_get_property(gem, "fsl,pfe-phy-if-flags", &size);
271 pdata->ls1012a_eth_pdata[port].phy_flags = be32_to_cpup(addr);