Skip to content

Commit 3b91b03

Browse files
CHKDSK88davem330
authored andcommitted
net: dsa: vsc73xx: make RGMII delays configurable
This patch switches hardcoded RGMII transmit/receive delay to a configurable value. Delay values are taken from the properties of the CPU port: 'tx-internal-delay-ps' and 'rx-internal-delay-ps'. The default value is configured to 2.0 ns to maintain backward compatibility with existing code. Signed-off-by: Pawel Dembicki <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3fafd92 commit 3b91b03

File tree

1 file changed

+66
-4
lines changed

1 file changed

+66
-4
lines changed

drivers/net/dsa/vitesse-vsc73xx-core.c

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,67 @@ vsc73xx_update_vlan_table(struct vsc73xx *vsc, int port, u16 vid, bool set)
684684
return vsc73xx_write_vlan_table_entry(vsc, vid, portmap);
685685
}
686686

687+
static int vsc73xx_configure_rgmii_port_delay(struct dsa_switch *ds)
688+
{
689+
/* Keep 2.0 ns delay for backward complatibility */
690+
u32 tx_delay = VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS;
691+
u32 rx_delay = VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS;
692+
struct dsa_port *dp = dsa_to_port(ds, CPU_PORT);
693+
struct device_node *port_dn = dp->dn;
694+
struct vsc73xx *vsc = ds->priv;
695+
u32 delay;
696+
697+
if (!of_property_read_u32(port_dn, "tx-internal-delay-ps", &delay)) {
698+
switch (delay) {
699+
case 0:
700+
tx_delay = VSC73XX_GMIIDELAY_GMII0_GTXDELAY_NONE;
701+
break;
702+
case 1400:
703+
tx_delay = VSC73XX_GMIIDELAY_GMII0_GTXDELAY_1_4_NS;
704+
break;
705+
case 1700:
706+
tx_delay = VSC73XX_GMIIDELAY_GMII0_GTXDELAY_1_7_NS;
707+
break;
708+
case 2000:
709+
break;
710+
default:
711+
dev_err(vsc->dev,
712+
"Unsupported RGMII Transmit Clock Delay\n");
713+
return -EINVAL;
714+
}
715+
} else {
716+
dev_dbg(vsc->dev,
717+
"RGMII Transmit Clock Delay isn't configured, set to 2.0 ns\n");
718+
}
719+
720+
if (!of_property_read_u32(port_dn, "rx-internal-delay-ps", &delay)) {
721+
switch (delay) {
722+
case 0:
723+
rx_delay = VSC73XX_GMIIDELAY_GMII0_RXDELAY_NONE;
724+
break;
725+
case 1400:
726+
rx_delay = VSC73XX_GMIIDELAY_GMII0_RXDELAY_1_4_NS;
727+
break;
728+
case 1700:
729+
rx_delay = VSC73XX_GMIIDELAY_GMII0_RXDELAY_1_7_NS;
730+
break;
731+
case 2000:
732+
break;
733+
default:
734+
dev_err(vsc->dev,
735+
"Unsupported RGMII Receive Clock Delay value\n");
736+
return -EINVAL;
737+
}
738+
} else {
739+
dev_dbg(vsc->dev,
740+
"RGMII Receive Clock Delay isn't configured, set to 2.0 ns\n");
741+
}
742+
743+
/* MII delay, set both GTX and RX delay */
744+
return vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY,
745+
tx_delay | rx_delay);
746+
}
747+
687748
static int vsc73xx_setup(struct dsa_switch *ds)
688749
{
689750
struct vsc73xx *vsc = ds->priv;
@@ -746,10 +807,11 @@ static int vsc73xx_setup(struct dsa_switch *ds)
746807
VSC73XX_MAC_CFG, VSC73XX_MAC_CFG_RESET);
747808
}
748809

749-
/* MII delay, set both GTX and RX delay to 2 ns */
750-
vsc73xx_write(vsc, VSC73XX_BLOCK_SYSTEM, 0, VSC73XX_GMIIDELAY,
751-
VSC73XX_GMIIDELAY_GMII0_GTXDELAY_2_0_NS |
752-
VSC73XX_GMIIDELAY_GMII0_RXDELAY_2_0_NS);
810+
/* Configure RGMII delay */
811+
ret = vsc73xx_configure_rgmii_port_delay(ds);
812+
if (ret)
813+
return ret;
814+
753815
/* Ingess VLAN reception mask (table 145) */
754816
vsc73xx_write(vsc, VSC73XX_BLOCK_ANALYZER, 0, VSC73XX_VLANMASK,
755817
0xff);

0 commit comments

Comments
 (0)