Skip to content

Commit 775669b

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 63726cd commit 775669b

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");
@@ -472,6 +482,93 @@ static int davinci_mdio_runtime_resume(struct device *dev)
472482
davinci_mdio_enable(data);
473483
return 0;
474484
}
485+
static void davinci_mdio_update_dt_from_phymask(u32 phy_mask)
486+
{
487+
int i, len, skip;
488+
u32 addr;
489+
__be32 *old_phy_p, *phy_id_p;
490+
struct property *phy_id_property = NULL;
491+
struct device_node *node_p, *slave_p;
492+
493+
addr = 0;
494+
495+
for (i = 0; i < PHY_MAX_ADDR; i++) {
496+
if ((phy_mask & (1 << i)) == 0) {
497+
addr = (u32) i;
498+
break;
499+
}
500+
}
501+
502+
for_each_compatible_node(node_p, NULL, "ti,cpsw") {
503+
for_each_node_by_name(slave_p, "slave") {
504+
505+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
506+
skip = 1;
507+
// Hack, the overlay fixup "slave" doesn't have phy-mode...
508+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy-mode", &len);
509+
510+
if (len != (sizeof(__be32 *) * 1))
511+
{
512+
skip = 0;
513+
}
514+
515+
if (skip) {
516+
#endif
517+
518+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy_id", &len);
519+
520+
if (len != (sizeof(__be32 *) * 2))
521+
goto err_out;
522+
523+
if (old_phy_p) {
524+
525+
phy_id_property = kzalloc(sizeof(*phy_id_property), GFP_KERNEL);
526+
527+
if (! phy_id_property)
528+
goto err_out;
529+
530+
phy_id_property->length = len;
531+
phy_id_property->name = kstrdup("phy_id", GFP_KERNEL);
532+
phy_id_property->value = kzalloc(len, GFP_KERNEL);
533+
534+
if (! phy_id_property->name)
535+
goto err_out;
536+
537+
if (! phy_id_property->value)
538+
goto err_out;
539+
540+
memcpy(phy_id_property->value, old_phy_p, len);
541+
542+
phy_id_p = (__be32 *) phy_id_property->value + 1;
543+
544+
*phy_id_p = cpu_to_be32(addr);
545+
546+
of_update_property(slave_p, phy_id_property);
547+
pr_info("davinci_mdio: dt: updated phy_id[%d] from phy_mask[%x]\n", addr, phy_mask);
548+
549+
++addr;
550+
}
551+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
552+
}
553+
#endif
554+
}
555+
}
556+
557+
return;
558+
559+
err_out:
560+
561+
if (phy_id_property) {
562+
if (phy_id_property->name)
563+
kfree(phy_id_property->name);
564+
565+
if (phy_id_property->value)
566+
kfree(phy_id_property->value);
567+
568+
if (phy_id_property)
569+
kfree(phy_id_property);
570+
}
571+
}
475572
#endif
476573

477574
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)