Skip to content

Commit 3e65ede

Browse files
shenghaoyangPaolo Abeni
authored andcommitted
net: dsa: mv88e6xxx: support 4000ps cycle counter period
The MV88E6393X family of devices can run its cycle counter off an internal 250MHz clock instead of an external 125MHz one. Add support for this cycle counter period by adding another set of coefficients and lowering the periodic cycle counter read interval to compensate for faster overflows at the increased frequency. Otherwise, the PHC runs at 2x real time in userspace and cannot be synchronized. Fixes: de776d0 ("net: dsa: mv88e6xxx: add support for mv88e6393x family") Signed-off-by: Shenghao Yang <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 7e3c180 commit 3e65ede

File tree

1 file changed

+20
-3
lines changed
  • drivers/net/dsa/mv88e6xxx

1 file changed

+20
-3
lines changed

drivers/net/dsa/mv88e6xxx/ptp.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_10ns_coeffs = {
4040
.cc_mult_dem = 3125ULL,
4141
};
4242

43-
/* Other families:
43+
/* Other families except MV88E6393X in internal clock mode:
4444
* Raw timestamps are in units of 8-ns clock periods.
4545
*
4646
* clkadj = scaled_ppm * 8*2^28 / (10^6 * 2^16)
@@ -55,6 +55,21 @@ static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_8ns_coeffs = {
5555
.cc_mult_dem = 15625ULL
5656
};
5757

58+
/* Family MV88E6393X using internal clock:
59+
* Raw timestamps are in units of 4-ns clock periods.
60+
*
61+
* clkadj = scaled_ppm * 4*2^28 / (10^6 * 2^16)
62+
* simplifies to
63+
* clkadj = scaled_ppm * 2^8 / 5^6
64+
*/
65+
#define MV88E6XXX_CC_4NS_SHIFT 28
66+
static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_4ns_coeffs = {
67+
.cc_shift = MV88E6XXX_CC_4NS_SHIFT,
68+
.cc_mult = 4 << MV88E6XXX_CC_4NS_SHIFT,
69+
.cc_mult_num = 1 << 8,
70+
.cc_mult_dem = 15625ULL
71+
};
72+
5873
#define TAI_EVENT_WORK_INTERVAL msecs_to_jiffies(100)
5974

6075
#define cc_to_chip(cc) container_of(cc, struct mv88e6xxx_chip, tstamp_cc)
@@ -110,6 +125,8 @@ mv88e6xxx_cc_coeff_get(struct mv88e6xxx_chip *chip)
110125
}
111126

112127
switch (period_ps) {
128+
case 4000:
129+
return &mv88e6xxx_cc_4ns_coeffs;
113130
case 8000:
114131
return &mv88e6xxx_cc_8ns_coeffs;
115132
case 10000:
@@ -483,10 +500,10 @@ static u64 mv88e6xxx_ptp_clock_read(const struct cyclecounter *cc)
483500
return 0;
484501
}
485502

486-
/* With a 125MHz input clock, the 32-bit timestamp counter overflows in ~34.3
503+
/* With a 250MHz input clock, the 32-bit timestamp counter overflows in ~17.2
487504
* seconds; this task forces periodic reads so that we don't miss any.
488505
*/
489-
#define MV88E6XXX_TAI_OVERFLOW_PERIOD (HZ * 16)
506+
#define MV88E6XXX_TAI_OVERFLOW_PERIOD (HZ * 8)
490507
static void mv88e6xxx_ptp_overflow_check(struct work_struct *work)
491508
{
492509
struct delayed_work *dw = to_delayed_work(work);

0 commit comments

Comments
 (0)