@@ -32,10 +32,10 @@ struct mv88e6xxx_cc_coeffs {
32
32
* simplifies to
33
33
* clkadj = scaled_ppm * 2^7 / 5^5
34
34
*/
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 ,
35
+ #define MV88E6XXX_CC_10NS_SHIFT 28
36
+ static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_10ns_coeffs = {
37
+ .cc_shift = MV88E6XXX_CC_10NS_SHIFT ,
38
+ .cc_mult = 10 << MV88E6XXX_CC_10NS_SHIFT ,
39
39
.cc_mult_num = 1 << 7 ,
40
40
.cc_mult_dem = 3125ULL ,
41
41
};
@@ -47,10 +47,10 @@ static const struct mv88e6xxx_cc_coeffs mv88e6250_cc_coeffs = {
47
47
* simplifies to
48
48
* clkadj = scaled_ppm * 2^9 / 5^6
49
49
*/
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 ,
50
+ #define MV88E6XXX_CC_8NS_SHIFT 28
51
+ static const struct mv88e6xxx_cc_coeffs mv88e6xxx_cc_8ns_coeffs = {
52
+ .cc_shift = MV88E6XXX_CC_8NS_SHIFT ,
53
+ .cc_mult = 8 << MV88E6XXX_CC_8NS_SHIFT ,
54
54
.cc_mult_num = 1 << 9 ,
55
55
.cc_mult_dem = 15625ULL
56
56
};
@@ -96,6 +96,31 @@ static int mv88e6352_set_gpio_func(struct mv88e6xxx_chip *chip, int pin,
96
96
return chip -> info -> ops -> gpio_ops -> set_pctl (chip , pin , func );
97
97
}
98
98
99
+ static const struct mv88e6xxx_cc_coeffs *
100
+ mv88e6xxx_cc_coeff_get (struct mv88e6xxx_chip * chip )
101
+ {
102
+ u16 period_ps ;
103
+ int err ;
104
+
105
+ err = mv88e6xxx_tai_read (chip , MV88E6XXX_TAI_CLOCK_PERIOD , & period_ps , 1 );
106
+ if (err ) {
107
+ dev_err (chip -> dev , "failed to read cycle counter period: %d\n" ,
108
+ err );
109
+ return ERR_PTR (err );
110
+ }
111
+
112
+ switch (period_ps ) {
113
+ case 8000 :
114
+ return & mv88e6xxx_cc_8ns_coeffs ;
115
+ case 10000 :
116
+ return & mv88e6xxx_cc_10ns_coeffs ;
117
+ default :
118
+ dev_err (chip -> dev , "unexpected cycle counter period of %u ps\n" ,
119
+ period_ps );
120
+ return ERR_PTR (- ENODEV );
121
+ }
122
+ }
123
+
99
124
static u64 mv88e6352_ptp_clock_read (const struct cyclecounter * cc )
100
125
{
101
126
struct mv88e6xxx_chip * chip = cc_to_chip (cc );
@@ -217,7 +242,6 @@ static void mv88e6352_tai_event_work(struct work_struct *ugly)
217
242
static int mv88e6xxx_ptp_adjfine (struct ptp_clock_info * ptp , long scaled_ppm )
218
243
{
219
244
struct mv88e6xxx_chip * chip = ptp_to_chip (ptp );
220
- const struct mv88e6xxx_ptp_ops * ptp_ops = chip -> info -> ops -> ptp_ops ;
221
245
int neg_adj = 0 ;
222
246
u32 diff , mult ;
223
247
u64 adj ;
@@ -227,10 +251,10 @@ static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
227
251
scaled_ppm = - scaled_ppm ;
228
252
}
229
253
230
- mult = ptp_ops -> cc_coeffs -> cc_mult ;
231
- adj = ptp_ops -> cc_coeffs -> cc_mult_num ;
254
+ mult = chip -> cc_coeffs -> cc_mult ;
255
+ adj = chip -> cc_coeffs -> cc_mult_num ;
232
256
adj *= scaled_ppm ;
233
- diff = div_u64 (adj , ptp_ops -> cc_coeffs -> cc_mult_dem );
257
+ diff = div_u64 (adj , chip -> cc_coeffs -> cc_mult_dem );
234
258
235
259
mv88e6xxx_reg_lock (chip );
236
260
@@ -377,7 +401,6 @@ const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {
377
401
(1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
378
402
(1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
379
403
(1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
380
- .cc_coeffs = & mv88e6xxx_cc_coeffs
381
404
};
382
405
383
406
const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
@@ -401,7 +424,6 @@ const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
401
424
(1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
402
425
(1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
403
426
(1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
404
- .cc_coeffs = & mv88e6250_cc_coeffs ,
405
427
};
406
428
407
429
const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
@@ -425,7 +447,6 @@ const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
425
447
(1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
426
448
(1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
427
449
(1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
428
- .cc_coeffs = & mv88e6xxx_cc_coeffs ,
429
450
};
430
451
431
452
const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
@@ -450,7 +471,6 @@ const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
450
471
(1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
451
472
(1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
452
473
(1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
453
- .cc_coeffs = & mv88e6xxx_cc_coeffs ,
454
474
};
455
475
456
476
static u64 mv88e6xxx_ptp_clock_read (const struct cyclecounter * cc )
@@ -485,11 +505,15 @@ int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
485
505
int i ;
486
506
487
507
/* Set up the cycle counter */
508
+ chip -> cc_coeffs = mv88e6xxx_cc_coeff_get (chip );
509
+ if (IS_ERR (chip -> cc_coeffs ))
510
+ return PTR_ERR (chip -> cc_coeffs );
511
+
488
512
memset (& chip -> tstamp_cc , 0 , sizeof (chip -> tstamp_cc ));
489
513
chip -> tstamp_cc .read = mv88e6xxx_ptp_clock_read ;
490
514
chip -> tstamp_cc .mask = CYCLECOUNTER_MASK (32 );
491
- chip -> tstamp_cc .mult = ptp_ops -> cc_coeffs -> cc_mult ;
492
- chip -> tstamp_cc .shift = ptp_ops -> cc_coeffs -> cc_shift ;
515
+ chip -> tstamp_cc .mult = chip -> cc_coeffs -> cc_mult ;
516
+ chip -> tstamp_cc .shift = chip -> cc_coeffs -> cc_shift ;
493
517
494
518
timecounter_init (& chip -> tstamp_tc , & chip -> tstamp_cc ,
495
519
ktime_to_ns (ktime_get_real ()));
0 commit comments