Skip to content

Commit 162e638

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 4d3a20c commit 162e638

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
@@ -108,6 +108,10 @@ struct davinci_mdio_data {
108108
u32 clk_div;
109109
};
110110

111+
#if IS_ENABLED(CONFIG_OF)
112+
static void davinci_mdio_update_dt_from_phymask(u32 phy_mask);
113+
#endif
114+
111115
static void davinci_mdio_init_clk(struct davinci_mdio_data *data)
112116
{
113117
u32 mdio_in, div, mdio_out_khz, access_time;
@@ -175,6 +179,12 @@ static int davinci_mdio_reset(struct mii_bus *bus)
175179
/* restrict mdio bus to live phys only */
176180
dev_info(data->dev, "detected phy mask %x\n", ~phy_mask);
177181
phy_mask = ~phy_mask;
182+
183+
#if IS_ENABLED(CONFIG_OF)
184+
if (of_machine_is_compatible("ti,am335x-bone"))
185+
davinci_mdio_update_dt_from_phymask(phy_mask);
186+
#endif
187+
178188
} else {
179189
/* desperately scan all phys */
180190
dev_warn(data->dev, "no live phy, scanning all\n");
@@ -488,6 +498,93 @@ static int davinci_mdio_runtime_resume(struct device *dev)
488498
davinci_mdio_enable(data);
489499
return 0;
490500
}
501+
static void davinci_mdio_update_dt_from_phymask(u32 phy_mask)
502+
{
503+
int i, len, skip;
504+
u32 addr;
505+
__be32 *old_phy_p, *phy_id_p;
506+
struct property *phy_id_property = NULL;
507+
struct device_node *node_p, *slave_p;
508+
509+
addr = 0;
510+
511+
for (i = 0; i < PHY_MAX_ADDR; i++) {
512+
if ((phy_mask & (1 << i)) == 0) {
513+
addr = (u32) i;
514+
break;
515+
}
516+
}
517+
518+
for_each_compatible_node(node_p, NULL, "ti,cpsw") {
519+
for_each_node_by_name(slave_p, "slave") {
520+
521+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
522+
skip = 1;
523+
// Hack, the overlay fixup "slave" doesn't have phy-mode...
524+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy-mode", &len);
525+
526+
if (len != (sizeof(__be32 *) * 1))
527+
{
528+
skip = 0;
529+
}
530+
531+
if (skip) {
532+
#endif
533+
534+
old_phy_p = (__be32 *) of_get_property(slave_p, "phy_id", &len);
535+
536+
if (len != (sizeof(__be32 *) * 2))
537+
goto err_out;
538+
539+
if (old_phy_p) {
540+
541+
phy_id_property = kzalloc(sizeof(*phy_id_property), GFP_KERNEL);
542+
543+
if (! phy_id_property)
544+
goto err_out;
545+
546+
phy_id_property->length = len;
547+
phy_id_property->name = kstrdup("phy_id", GFP_KERNEL);
548+
phy_id_property->value = kzalloc(len, GFP_KERNEL);
549+
550+
if (! phy_id_property->name)
551+
goto err_out;
552+
553+
if (! phy_id_property->value)
554+
goto err_out;
555+
556+
memcpy(phy_id_property->value, old_phy_p, len);
557+
558+
phy_id_p = (__be32 *) phy_id_property->value + 1;
559+
560+
*phy_id_p = cpu_to_be32(addr);
561+
562+
of_update_property(slave_p, phy_id_property);
563+
pr_info("davinci_mdio: dt: updated phy_id[%d] from phy_mask[%x]\n", addr, phy_mask);
564+
565+
++addr;
566+
}
567+
#if IS_ENABLED(CONFIG_OF_OVERLAY)
568+
}
569+
#endif
570+
}
571+
}
572+
573+
return;
574+
575+
err_out:
576+
577+
if (phy_id_property) {
578+
if (phy_id_property->name)
579+
kfree(phy_id_property->name);
580+
581+
if (phy_id_property->value)
582+
kfree(phy_id_property->value);
583+
584+
if (phy_id_property)
585+
kfree(phy_id_property);
586+
}
587+
}
491588
#endif
492589

493590
#ifdef CONFIG_PM_SLEEP

0 commit comments

Comments
 (0)