@@ -32,10 +32,10 @@ struct mv88e6xxx_cc_coeffs {
3232 * simplifies to
3333 * clkadj = scaled_ppm * 2^7 / 5^5
3434 */
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 ,
3939 .cc_mult_num = 1 << 7 ,
4040 .cc_mult_dem = 3125ULL ,
4141};
@@ -47,10 +47,10 @@ static const struct mv88e6xxx_cc_coeffs mv88e6250_cc_coeffs = {
4747 * simplifies to
4848 * clkadj = scaled_ppm * 2^9 / 5^6
4949 */
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 ,
5454 .cc_mult_num = 1 << 9 ,
5555 .cc_mult_dem = 15625ULL
5656};
@@ -96,6 +96,31 @@ static int mv88e6352_set_gpio_func(struct mv88e6xxx_chip *chip, int pin,
9696 return chip -> info -> ops -> gpio_ops -> set_pctl (chip , pin , func );
9797}
9898
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+
99124static u64 mv88e6352_ptp_clock_read (const struct cyclecounter * cc )
100125{
101126 struct mv88e6xxx_chip * chip = cc_to_chip (cc );
@@ -217,7 +242,6 @@ static void mv88e6352_tai_event_work(struct work_struct *ugly)
217242static int mv88e6xxx_ptp_adjfine (struct ptp_clock_info * ptp , long scaled_ppm )
218243{
219244 struct mv88e6xxx_chip * chip = ptp_to_chip (ptp );
220- const struct mv88e6xxx_ptp_ops * ptp_ops = chip -> info -> ops -> ptp_ops ;
221245 int neg_adj = 0 ;
222246 u32 diff , mult ;
223247 u64 adj ;
@@ -227,10 +251,10 @@ static int mv88e6xxx_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
227251 scaled_ppm = - scaled_ppm ;
228252 }
229253
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 ;
232256 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 );
234258
235259 mv88e6xxx_reg_lock (chip );
236260
@@ -377,7 +401,6 @@ const struct mv88e6xxx_ptp_ops mv88e6165_ptp_ops = {
377401 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
378402 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
379403 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
380- .cc_coeffs = & mv88e6xxx_cc_coeffs
381404};
382405
383406const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
@@ -401,7 +424,6 @@ const struct mv88e6xxx_ptp_ops mv88e6250_ptp_ops = {
401424 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
402425 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
403426 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
404- .cc_coeffs = & mv88e6250_cc_coeffs ,
405427};
406428
407429const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
@@ -425,7 +447,6 @@ const struct mv88e6xxx_ptp_ops mv88e6352_ptp_ops = {
425447 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
426448 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
427449 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
428- .cc_coeffs = & mv88e6xxx_cc_coeffs ,
429450};
430451
431452const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
@@ -450,7 +471,6 @@ const struct mv88e6xxx_ptp_ops mv88e6390_ptp_ops = {
450471 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT ) |
451472 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC ) |
452473 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ ),
453- .cc_coeffs = & mv88e6xxx_cc_coeffs ,
454474};
455475
456476static u64 mv88e6xxx_ptp_clock_read (const struct cyclecounter * cc )
@@ -485,11 +505,15 @@ int mv88e6xxx_ptp_setup(struct mv88e6xxx_chip *chip)
485505 int i ;
486506
487507 /* 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+
488512 memset (& chip -> tstamp_cc , 0 , sizeof (chip -> tstamp_cc ));
489513 chip -> tstamp_cc .read = mv88e6xxx_ptp_clock_read ;
490514 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 ;
493517
494518 timecounter_init (& chip -> tstamp_tc , & chip -> tstamp_cc ,
495519 ktime_to_ns (ktime_get_real ()));
0 commit comments