1818
1919#define MV88E6XXX_MAX_ADJ_PPB 1000000
2020
21+ struct mv88e6xxx_cc_coeffs {
22+ u32 cc_shift ;
23+ u32 cc_mult ;
24+ u32 cc_mult_num ;
25+ u32 cc_mult_dem ;
26+ };
27+
2128/* Family MV88E6250:
2229 * Raw timestamps are in units of 10-ns clock periods.
2330 *
2431 * clkadj = scaled_ppm * 10*2^28 / (10^6 * 2^16)
2532 * simplifies to
2633 * clkadj = scaled_ppm * 2^7 / 5^5
2734 */
28- #define MV88E6250_CC_SHIFT 28
29- #define MV88E6250_CC_MULT (10 << MV88E6250_CC_SHIFT)
30- #define MV88E6250_CC_MULT_NUM (1 << 7)
31- #define MV88E6250_CC_MULT_DEM 3125ULL
35+ #define MV88E6250_CC_SHIFT 28
36+ static const struct mv88e6xxx_cc_coeffs mv88e6250_cc_coeffs = {
37+ .cc_shift = MV88E6250_CC_SHIFT ,
38+ .cc_mult = 10 << MV88E6250_CC_SHIFT ,
39+ .cc_mult_num = 1 << 7 ,
40+ .cc_mult_dem = 3125ULL ,
41+ };
3242
3343/* Other families:
3444 * Raw timestamps are in units of 8-ns clock periods.
3747 * simplifies to
3848 * clkadj = scaled_ppm * 2^9 / 5^6
3949 */
40- #define MV88E6XXX_CC_SHIFT 28
41- #define MV88E6XXX_CC_MULT (8 << MV88E6XXX_CC_SHIFT)
42- #define MV88E6XXX_CC_MULT_NUM (1 << 9)
43- #define MV88E6XXX_CC_MULT_DEM 15625ULL
50+ #define MV88E6XXX_CC_SHIFT 28
51+ static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_coeffs = {
52+ .cc_shift = MV88E6XXX_CC_SHIFT ,
53+ .cc_mult = 8 << MV88E6XXX_CC_SHIFT ,
54+ .cc_mult_num = 1 << 9 ,
55+ .cc_mult_dem = 15625ULL
56+ };
4457
4558#define TAI_EVENT_WORK_INTERVAL msecs_to_jiffies(100)
4659
@@ -214,10 +227,10 @@ static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
214227 scaled_ppm = - scaled_ppm ;
215228 }
216229
217- mult = ptp_ops -> cc_mult ;
218- adj = ptp_ops -> cc_mult_num ;
230+ mult = ptp_ops -> cc_coeffs -> cc_mult ;
231+ adj = ptp_ops -> cc_coeffs -> cc_mult_num ;
219232 adj *= scaled_ppm ;
220- diff = div_u64 (adj , ptp_ops -> cc_mult_dem );
233+ diff = div_u64 (adj , ptp_ops -> cc_coeffs -> cc_mult_dem );
221234
222235 mv88e6xxx_reg_lock (chip );
223236
@@ -364,10 +377,7 @@ const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {
364377 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
365378 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
366379 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
367- .cc_shift = MV88E6XXX_CC_SHIFT ,
368- .cc_mult = MV88E6XXX_CC_MULT ,
369- .cc_mult_num = MV88E6XXX_CC_MULT_NUM ,
370- .cc_mult_dem = MV88E6XXX_CC_MULT_DEM ,
380+ .cc_coeffs = & mv88e6xxx_cc_coeffs
371381};
372382
373383const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
@@ -391,10 +401,7 @@ const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
391401 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
392402 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
393403 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
394- .cc_shift = MV88E6250_CC_SHIFT ,
395- .cc_mult = MV88E6250_CC_MULT ,
396- .cc_mult_num = MV88E6250_CC_MULT_NUM ,
397- .cc_mult_dem = MV88E6250_CC_MULT_DEM ,
404+ .cc_coeffs = & mv88e6250_cc_coeffs ,
398405};
399406
400407const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
@@ -418,10 +425,7 @@ const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
418425 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
419426 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
420427 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
421- .cc_shift = MV88E6XXX_CC_SHIFT ,
422- .cc_mult = MV88E6XXX_CC_MULT ,
423- .cc_mult_num = MV88E6XXX_CC_MULT_NUM ,
424- .cc_mult_dem = MV88E6XXX_CC_MULT_DEM ,
428+ .cc_coeffs = & mv88e6xxx_cc_coeffs ,
425429};
426430
427431const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
@@ -446,10 +450,7 @@ const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
446450 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
447451 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
448452 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
449- .cc_shift = MV88E6XXX_CC_SHIFT ,
450- .cc_mult = MV88E6XXX_CC_MULT ,
451- .cc_mult_num = MV88E6XXX_CC_MULT_NUM ,
452- .cc_mult_dem = MV88E6XXX_CC_MULT_DEM ,
453+ .cc_coeffs = & mv88e6xxx_cc_coeffs ,
453454};
454455
455456static u64 mv88e6xxx_ptp_clock_read (const struct cyclecounter * cc )
@@ -487,8 +488,8 @@ int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
487488 memset (& chip -> tstamp_cc , 0 , sizeof (chip -> tstamp_cc ));
488489 chip -> tstamp_cc .read = mv88e6xxx_ptp_clock_read ;
489490 chip -> tstamp_cc .mask = CYCLECOUNTER_MASK (32 );
490- chip -> tstamp_cc .mult = ptp_ops -> cc_mult ;
491- chip -> tstamp_cc .shift = ptp_ops -> cc_shift ;
491+ chip -> tstamp_cc .mult = ptp_ops -> cc_coeffs -> cc_mult ;
492+ chip -> tstamp_cc .shift = ptp_ops -> cc_coeffs -> cc_shift ;
492493
493494 timecounter_init (& chip -> tstamp_tc , & chip -> tstamp_cc ,
494495 ktime_to_ns (ktime_get_real ()));
0 commit comments