Skip to content

Commit a7657f1

Browse files
cavagiudavem330
authored andcommitted
stmmac: fix MDIO settings
Initially the phy_bus_name was added to manipulate the driver name but it was recently just used to manage the fixed-link and then to take some decision at run-time. So the patch uses the is_pseudo_fixed_link and removes the phy_bus_name variable not necessary anymore. The driver can manage the mdio registration by using phy-handle, dwmac-mdio and own parameter e.g. snps,phy-addr. This patch takes care about all these possible configurations and fixes the mdio registration in case of there is a real transceiver or a switch (that needs to be managed by using fixed-link). Signed-off-by: Giuseppe Cavallaro <peppe.cavallaro@st.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Tested-by: Frank Schäfer <fschaefer.oss@googlemail.com> Cc: Gabriel Fernandez <gabriel.fernandez@linaro.org> Cc: Dinh Nguyen <dinh.linux@gmail.com> Cc: David S. Miller <davem@davemloft.net> Cc: Phil Reid <preid@electromag.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d7e944c commit a7657f1

File tree

4 files changed

+73
-48
lines changed

4 files changed

+73
-48
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
278278
*/
279279
bool stmmac_eee_init(struct stmmac_priv *priv)
280280
{
281-
char *phy_bus_name = priv->plat->phy_bus_name;
282281
unsigned long flags;
283282
bool ret = false;
284283

@@ -290,7 +289,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
290289
goto out;
291290

292291
/* Never init EEE in case of a switch is attached */
293-
if (phy_bus_name && (!strcmp(phy_bus_name, "fixed")))
292+
if (priv->phydev->is_pseudo_fixed_link)
294293
goto out;
295294

296295
/* MAC core supports the EEE feature. */
@@ -827,12 +826,8 @@ static int stmmac_init_phy(struct net_device *dev)
827826
phydev = of_phy_connect(dev, priv->plat->phy_node,
828827
&stmmac_adjust_link, 0, interface);
829828
} else {
830-
if (priv->plat->phy_bus_name)
831-
snprintf(bus_id, MII_BUS_ID_SIZE, "%s-%x",
832-
priv->plat->phy_bus_name, priv->plat->bus_id);
833-
else
834-
snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
835-
priv->plat->bus_id);
829+
snprintf(bus_id, MII_BUS_ID_SIZE, "stmmac-%x",
830+
priv->plat->bus_id);
836831

837832
snprintf(phy_id_fmt, MII_BUS_ID_SIZE + 3, PHY_ID_FMT, bus_id,
838833
priv->plat->phy_addr);
@@ -871,9 +866,8 @@ static int stmmac_init_phy(struct net_device *dev)
871866
}
872867

873868
/* If attached to a switch, there is no reason to poll phy handler */
874-
if (priv->plat->phy_bus_name)
875-
if (!strcmp(priv->plat->phy_bus_name, "fixed"))
876-
phydev->irq = PHY_IGNORE_INTERRUPT;
869+
if (phydev->is_pseudo_fixed_link)
870+
phydev->irq = PHY_IGNORE_INTERRUPT;
877871

878872
pr_debug("stmmac_init_phy: %s: attached to PHY (UID 0x%x)"
879873
" Link = %d\n", dev->name, phydev->phy_id, phydev->link);

drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,29 +198,12 @@ int stmmac_mdio_register(struct net_device *ndev)
198198
struct mii_bus *new_bus;
199199
struct stmmac_priv *priv = netdev_priv(ndev);
200200
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
201+
struct device_node *mdio_node = priv->plat->mdio_node;
201202
int addr, found;
202-
struct device_node *mdio_node = NULL;
203-
struct device_node *child_node = NULL;
204203

205204
if (!mdio_bus_data)
206205
return 0;
207206

208-
if (IS_ENABLED(CONFIG_OF)) {
209-
for_each_child_of_node(priv->device->of_node, child_node) {
210-
if (of_device_is_compatible(child_node,
211-
"snps,dwmac-mdio")) {
212-
mdio_node = child_node;
213-
break;
214-
}
215-
}
216-
217-
if (mdio_node) {
218-
netdev_dbg(ndev, "FOUND MDIO subnode\n");
219-
} else {
220-
netdev_warn(ndev, "No MDIO subnode found\n");
221-
}
222-
}
223-
224207
new_bus = mdiobus_alloc();
225208
if (new_bus == NULL)
226209
return -ENOMEM;

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,69 @@ static struct stmmac_axi *stmmac_axi_setup(struct platform_device *pdev)
131131
return axi;
132132
}
133133

134+
/**
135+
* stmmac_dt_phy - parse device-tree driver parameters to allocate PHY resources
136+
* @plat: driver data platform structure
137+
* @np: device tree node
138+
* @dev: device pointer
139+
* Description:
140+
* The mdio bus will be allocated in case of a phy transceiver is on board;
141+
* it will be NULL if the fixed-link is configured.
142+
* If there is the "snps,dwmac-mdio" sub-node the mdio will be allocated
143+
* in any case (for DSA, mdio must be registered even if fixed-link).
144+
* The table below sums the supported configurations:
145+
* -------------------------------
146+
* snps,phy-addr | Y
147+
* -------------------------------
148+
* phy-handle | Y
149+
* -------------------------------
150+
* fixed-link | N
151+
* -------------------------------
152+
* snps,dwmac-mdio |
153+
* even if | Y
154+
* fixed-link |
155+
* -------------------------------
156+
*
157+
* It returns 0 in case of success otherwise -ENODEV.
158+
*/
159+
static int stmmac_dt_phy(struct plat_stmmacenet_data *plat,
160+
struct device_node *np, struct device *dev)
161+
{
162+
bool mdio = true;
163+
164+
/* If phy-handle property is passed from DT, use it as the PHY */
165+
plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
166+
if (plat->phy_node)
167+
dev_dbg(dev, "Found phy-handle subnode\n");
168+
169+
/* If phy-handle is not specified, check if we have a fixed-phy */
170+
if (!plat->phy_node && of_phy_is_fixed_link(np)) {
171+
if ((of_phy_register_fixed_link(np) < 0))
172+
return -ENODEV;
173+
174+
dev_dbg(dev, "Found fixed-link subnode\n");
175+
plat->phy_node = of_node_get(np);
176+
mdio = false;
177+
}
178+
179+
/* If snps,dwmac-mdio is passed from DT, always register the MDIO */
180+
for_each_child_of_node(np, plat->mdio_node) {
181+
if (of_device_is_compatible(plat->mdio_node, "snps,dwmac-mdio"))
182+
break;
183+
}
184+
185+
if (plat->mdio_node) {
186+
dev_dbg(dev, "Found MDIO subnode\n");
187+
mdio = true;
188+
}
189+
190+
if (mdio)
191+
plat->mdio_bus_data =
192+
devm_kzalloc(dev, sizeof(struct stmmac_mdio_bus_data),
193+
GFP_KERNEL);
194+
return 0;
195+
}
196+
134197
/**
135198
* stmmac_probe_config_dt - parse device-tree driver parameters
136199
* @pdev: platform_device structure
@@ -165,30 +228,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
165228
/* Default to phy auto-detection */
166229
plat->phy_addr = -1;
167230

168-
/* If we find a phy-handle property, use it as the PHY */
169-
plat->phy_node = of_parse_phandle(np, "phy-handle", 0);
170-
171-
/* If phy-handle is not specified, check if we have a fixed-phy */
172-
if (!plat->phy_node && of_phy_is_fixed_link(np)) {
173-
if ((of_phy_register_fixed_link(np) < 0))
174-
return ERR_PTR(-ENODEV);
175-
176-
plat->phy_node = of_node_get(np);
177-
}
178-
179231
/* "snps,phy-addr" is not a standard property. Mark it as deprecated
180232
* and warn of its use. Remove this when phy node support is added.
181233
*/
182234
if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
183235
dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
184236

185-
if ((plat->phy_node && !of_phy_is_fixed_link(np)) || plat->phy_bus_name)
186-
plat->mdio_bus_data = NULL;
187-
else
188-
plat->mdio_bus_data =
189-
devm_kzalloc(&pdev->dev,
190-
sizeof(struct stmmac_mdio_bus_data),
191-
GFP_KERNEL);
237+
/* To Configure PHY by using all device-tree supported properties */
238+
if (stmmac_dt_phy(plat, np, &pdev->dev))
239+
return ERR_PTR(-ENODEV);
192240

193241
of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
194242

include/linux/stmmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ struct stmmac_axi {
108108
};
109109

110110
struct plat_stmmacenet_data {
111-
char *phy_bus_name;
112111
int bus_id;
113112
int phy_addr;
114113
int interface;
115114
struct stmmac_mdio_bus_data *mdio_bus_data;
116115
struct device_node *phy_node;
116+
struct device_node *mdio_node;
117117
struct stmmac_dma_cfg *dma_cfg;
118118
int clk_csr;
119119
int has_gmac;

0 commit comments

Comments
 (0)