Skip to content

Commit ef13683

Browse files
sipragadavem330
authored andcommitted
net: dsa: rtl8365mb: set RGMII RX delay in steps of 0.3 ns
A contact at Realtek has clarified what exactly the units of RGMII RX delay are. The answer is that the unit of RX delay is "about 0.3 ns". Take this into account when parsing rx-internal-delay-ps by approximating the closest step value. Delays of more than 2.1 ns are rejected. This obviously contradicts the previous assumption in the driver that a step value of 4 was "about 2 ns", but Realtek also points out that it is easy to find more than one RX delay step value which makes RGMII work. Fixes: 4af2950 ("net: dsa: realtek-smi: add rtl8365mb subdriver for RTL8365MB-VC") Cc: Arınç ÜNAL <[email protected]> Signed-off-by: Alvin Šipraga <[email protected]> Acked-by: Arınç ÜNAL <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1ecab93 commit ef13683

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/net/dsa/rtl8365mb.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,8 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_smi *smi, int port,
760760
* 0 = no delay, 1 = 2 ns delay
761761
* RX delay:
762762
* 0 = no delay, 7 = maximum delay
763-
* No units are specified, but there are a total of 8 steps.
763+
* Each step is approximately 0.3 ns, so the maximum delay is about
764+
* 2.1 ns.
764765
*
765766
* The vendor driver also states that this must be configured *before*
766767
* forcing the external interface into a particular mode, which is done
@@ -771,10 +772,6 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_smi *smi, int port,
771772
* specified. We ignore the detail of the RGMII interface mode
772773
* (RGMII_{RXID, TXID, etc.}), as this is considered to be a PHY-only
773774
* property.
774-
*
775-
* For the RX delay, we assume that a register value of 4 corresponds to
776-
* 2 ns. But this is just an educated guess, so ignore all other values
777-
* to avoid too much confusion.
778775
*/
779776
if (!of_property_read_u32(dn, "tx-internal-delay-ps", &val)) {
780777
val = val / 1000; /* convert to ns */
@@ -787,13 +784,13 @@ static int rtl8365mb_ext_config_rgmii(struct realtek_smi *smi, int port,
787784
}
788785

789786
if (!of_property_read_u32(dn, "rx-internal-delay-ps", &val)) {
790-
val = val / 1000; /* convert to ns */
787+
val = DIV_ROUND_CLOSEST(val, 300); /* convert to 0.3 ns step */
791788

792-
if (val == 0 || val == 2)
793-
rx_delay = val * 2;
789+
if (val <= 7)
790+
rx_delay = val;
794791
else
795792
dev_warn(smi->dev,
796-
"EXT port RX delay must be 0 to 2 ns\n");
793+
"EXT port RX delay must be 0 to 2.1 ns\n");
797794
}
798795

799796
ret = regmap_update_bits(

0 commit comments

Comments
 (0)