Skip to content

Commit 0744bce

Browse files
Jay at Control Module IndustriesRobertCNelson
authored andcommitted
cpsw: search for phy
I have encountered the same issue(s) on A6A boards. I couldn't find a patch, so I wrote this patch to update the device tree in the davinci_mdio driver in the 3.15.1 tree, it seems to correct it. I would welcome any input on a different approach. https://groups.google.com/d/msg/beagleboard/9mctrG26Mc8/SRlnumt0LoMJ v4.1-rcX: added hack around CONFIG_OF_OVERLAY v4.2-rc3+: added if (of_machine_is_compatible("ti,am335x-bone")) so we do not break dual ethernet am335x devices Signed-off-by: Robert Nelson <[email protected]>
1 parent 97a952e commit 0744bce

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

drivers/net/ethernet/ti/davinci_mdio.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ struct davinci_mdio_data {
9292
u32 clk_div;
9393
};
9494

95+
#if IS_ENABLED(CONFIG_OF)
96+
static void davinci_mdio_update_dt_from_phymask(u32 phy_mask);
97+
#endif
98+
9599
static void davinci_mdio_init_clk(struct davinci_mdio_data *data)
96100
{
97101
u32 mdio_in, div, mdio_out_khz, access_time;
@@ -159,6 +163,12 @@ static int davinci_mdio_reset(struct mii_bus *bus)
159163
/* restrict mdio bus to live phys only */
160164
dev_info(data->dev, "detected phy mask %x\n", ~phy_mask);
161165
phy_mask = ~phy_mask;
166+
167+
#if IS_ENABLED(CONFIG_OF)
168+
if (of_machine_is_compatible("ti,am335x-bone"))
169+
davinci_mdio_update_dt_from_phymask(phy_mask);
170+
#endif
171+
162172
} else {
163173
/* desperately scan all phys */
164174
dev_warn(data->dev, "no live phy, scanning all\n");
@@ -474,6 +484,93 @@ static int davinci_mdio_runtime_resume(struct device *dev)
474484
davinci_mdio_enable(data);
475485
return 0;
476486
}
487+
static void davinci_mdio_update_dt_from_phymask(u32 phy_mask)
488+
{
489+
int i, len, skip;
490+
u32 addr;
491+
__be32 *old_phy_p, *phy_id_p;
492+
struct property *phy_id_property = NULL;
493+
struct device_node *node_p, *slave_p;
494+
495+
addr = 0;
496+
497+
for (i = 0; i < PHY_MAX_ADDR; i++) {
498+
if ((phy_mask & (1 << i)) == 0) {
499+
addr = (u32) i;
500+
break;
501+
}
502+
}
503+
504+
for_each_compatible_node(node_p, NULL, "ti,cpsw") {
505+
for_each_node_by_name(slave_p, "slave") {
506+
507+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
508+
skip = 1;
509+
// Hack, the overlay fixup "slave" doesn't have phy-mode...
510+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy-mode", &len);
511+
512+
if (len != (sizeof(__be32 *) * 1))
513+
{
514+
skip = 0;
515+
}
516+
517+
if (skip) {
518+
#endif
519+
520+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy_id", &len);
521+
522+
if (len != (sizeof(__be32 *) * 2))
523+
goto err_out;
524+
525+
if (old_phy_p) {
526+
527+
phy_id_property = kzalloc(sizeof(*phy_id_property), GFP_KERNEL);
528+
529+
if (! phy_id_property)
530+
goto err_out;
531+
532+
phy_id_property->length = len;
533+
phy_id_property->name = kstrdup("phy_id", GFP_KERNEL);
534+
phy_id_property->value = kzalloc(len, GFP_KERNEL);
535+
536+
if (! phy_id_property->name)
537+
goto err_out;
538+
539+
if (! phy_id_property->value)
540+
goto err_out;
541+
542+
memcpy(phy_id_property->value, old_phy_p, len);
543+
544+
phy_id_p = (__be32 *) phy_id_property->value + 1;
545+
546+
*phy_id_p = cpu_to_be32(addr);
547+
548+
of_update_property(slave_p, phy_id_property);
549+
pr_info("davinci_mdio: dt: updated phy_id[%d] from phy_mask[%x]\n", addr, phy_mask);
550+
551+
++addr;
552+
}
553+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
554+
}
555+
#endif
556+
}
557+
}
558+
559+
return;
560+
561+
err_out:
562+
563+
if (phy_id_property) {
564+
if (phy_id_property->name)
565+
kfree(phy_id_property->name);
566+
567+
if (phy_id_property->value)
568+
kfree(phy_id_property->value);
569+
570+
if (phy_id_property)
571+
kfree(phy_id_property);
572+
}
573+
}
477574
#endif
478575

479576
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)