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
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
15 Signed-off-by: Calvin Johnson <calvin.johnson@nxp.com>
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(-)
21 --- a/drivers/staging/fsl_ppfe/pfe_eth.c
22 +++ b/drivers/staging/fsl_ppfe/pfe_eth.c
25 #define LS1012A_REV_1_0 0x87040010
27 +bool pfe_use_old_dts_phy;
28 bool pfe_errata_a010897;
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)
36 + struct device_node *mdio_node;
38 struct phy_device *phydev;
40 netif_info(priv, drv, priv->ndev, "%s\n", __func__);
41 @@ -964,25 +966,30 @@ static int pfe_eth_mdio_init(struct pfe_
44 bus->name = "ls1012a MDIO Bus";
45 + snprintf(bus->id, MII_BUS_ID_SIZE, "ls1012a-%x", priv->id);
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);
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];
59 + priv->mdc_div = minfo->mdc_div;
63 - bus->irq[0] = minfo->irq[0];
65 - bus->parent = priv->pfe->dev;
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);
71 + mdio_node = of_get_child_by_name(priv->pfe->dev->of_node, "mdio");
73 + rc = of_mdiobus_register(bus, mdio_node);
74 + of_node_put(mdio_node);
76 + rc = mdiobus_register(bus);
80 netdev_err(priv->ndev, "mdiobus_register(%s) failed\n",
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()
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;
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);
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);
111 - if (of_phy_is_fixed_link(priv->phy_node)) {
112 - rc = of_phy_register_fixed_link(priv->phy_node);
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);
123 + netdev_err(ndev, "Unable to connect to phy\n");
128 phydev = phy_connect(ndev, phy_id,
129 &pfe_eth_adjust_link, interface);
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);
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);
145 /* Initialize mdio */
146 - if (minfo[id].enabled) {
147 - err = pfe_eth_mdio_init(priv, &minfo[id]);
149 - netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n",
153 + err = pfe_eth_mdio_init(priv, &minfo[id]);
155 + netdev_err(ndev, "%s: pfe_eth_mdio_init() failed\n", __func__);
160 @@ -2462,22 +2461,26 @@ static int pfe_eth_init_one(struct pfe *
161 HIF_RX_POLL_WEIGHT - 16);
163 err = register_netdev(ndev);
166 netdev_err(ndev, "register_netdev() failed\n");
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;
179 device_init_wakeup(&ndev->dev, WAKE_MAGIC);
181 - if (!(priv->einfo->phy_flags & GEMAC_NO_PHY)) {
182 - err = pfe_phy_init(ndev);
184 - netdev_err(ndev, "%s: pfe_phy_init() failed\n",
188 + err = pfe_phy_init(ndev);
190 + netdev_err(ndev, "%s: pfe_phy_init() failed\n",
196 @@ -2488,6 +2491,7 @@ phy_init:
198 netif_carrier_on(ndev);
201 /* Create all the sysfs files */
202 if (pfe_eth_sysfs_init(ndev))
204 @@ -2496,13 +2500,16 @@ phy_init:
205 __func__, priv->EMAC_baseaddr);
210 + pfe_phy_exit(priv->ndev);
215 unregister_netdev(ndev);
217 - pfe_eth_mdio_exit(priv->mii_bus);
219 + pfe_eth_mdio_exit(priv->mii_bus);
221 free_netdev(priv->ndev);
224 @@ -2553,9 +2560,16 @@ static void pfe_eth_exit_one(struct pfe_
226 pfe_eth_sysfs_exit(priv->ndev);
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;
237 + pfe_phy_exit(priv->ndev);
241 unregister_netdev(priv->ndev);
243 --- a/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
244 +++ b/drivers/staging/fsl_ppfe/pfe_ls1012a_platform.c
249 +extern bool pfe_use_old_dts_phy;
250 struct ls1012a_pfe_platform_data pfe_platform_data;
252 static int pfe_get_gemac_if_properties(struct device_node *parent, int port, int
253 @@ -59,8 +60,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;
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");
264 @@ -68,6 +71,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);