Lines Matching defs:clock
112 static u64 __mlxsw_sp1_ptp_read_frc(struct mlxsw_sp1_ptp_clock *clock,
115 struct mlxsw_core *mlxsw_core = clock->common.core;
136 struct mlxsw_sp1_ptp_clock *clock =
139 return __mlxsw_sp1_ptp_read_frc(clock, NULL) & cc->mask;
143 mlxsw_sp_ptp_phc_adjfreq(struct mlxsw_sp_ptp_clock *clock, int freq_adj)
145 struct mlxsw_core *mlxsw_core = clock->core;
164 mlxsw_sp1_ptp_phc_settime(struct mlxsw_sp1_ptp_clock *clock, u64 nsec)
166 struct mlxsw_core *mlxsw_core = clock->common.core;
175 spin_lock_bh(&clock->lock);
176 cycles = mlxsw_sp1_ptp_ns2cycles(&clock->tc, next_sec_in_nsec);
177 spin_unlock_bh(&clock->lock);
192 struct mlxsw_sp1_ptp_clock *clock = mlxsw_sp1_ptp_clock(ptp);
197 spin_lock_bh(&clock->lock);
198 timecounter_read(&clock->tc);
199 clock->cycles.mult = adjust_by_scaled_ppm(clock->nominal_c_mult,
201 spin_unlock_bh(&clock->lock);
203 return mlxsw_sp_ptp_phc_adjfreq(&clock->common, ppb);
208 struct mlxsw_sp1_ptp_clock *clock = mlxsw_sp1_ptp_clock(ptp);
211 spin_lock_bh(&clock->lock);
212 timecounter_adjtime(&clock->tc, delta);
213 nsec = timecounter_read(&clock->tc);
214 spin_unlock_bh(&clock->lock);
216 return mlxsw_sp1_ptp_phc_settime(clock, nsec);
223 struct mlxsw_sp1_ptp_clock *clock = mlxsw_sp1_ptp_clock(ptp);
226 spin_lock_bh(&clock->lock);
227 cycles = __mlxsw_sp1_ptp_read_frc(clock, sts);
228 nsec = timecounter_cyc2time(&clock->tc, cycles);
229 spin_unlock_bh(&clock->lock);
239 struct mlxsw_sp1_ptp_clock *clock = mlxsw_sp1_ptp_clock(ptp);
242 spin_lock_bh(&clock->lock);
243 timecounter_init(&clock->tc, &clock->cycles, nsec);
244 nsec = timecounter_read(&clock->tc);
245 spin_unlock_bh(&clock->lock);
247 return mlxsw_sp1_ptp_phc_settime(clock, nsec);
263 struct mlxsw_sp1_ptp_clock *clock;
265 clock = container_of(dwork, struct mlxsw_sp1_ptp_clock, overflow_work);
267 spin_lock_bh(&clock->lock);
268 timecounter_read(&clock->tc);
269 spin_unlock_bh(&clock->lock);
270 mlxsw_core_schedule_dw(&clock->overflow_work, clock->overflow_period);
277 struct mlxsw_sp1_ptp_clock *clock;
280 clock = kzalloc(sizeof(*clock), GFP_KERNEL);
281 if (!clock)
284 spin_lock_init(&clock->lock);
285 clock->cycles.read = mlxsw_sp1_ptp_read_frc;
286 clock->cycles.shift = MLXSW_SP1_PTP_CLOCK_CYCLES_SHIFT;
287 clock->cycles.mult = clocksource_khz2mult(MLXSW_SP1_PTP_CLOCK_FREQ_KHZ,
288 clock->cycles.shift);
289 clock->nominal_c_mult = clock->cycles.mult;
290 clock->cycles.mask = CLOCKSOURCE_MASK(MLXSW_SP1_PTP_CLOCK_MASK);
291 clock->common.core = mlxsw_sp->core;
293 timecounter_init(&clock->tc, &clock->cycles, 0);
298 * (The clock source mask) and max amount of cycles that can be
299 * multiplied by clock multiplier where the result doesn't exceed
302 overflow_cycles = div64_u64(~0ULL >> 1, clock->cycles.mult);
303 overflow_cycles = min(overflow_cycles, div_u64(clock->cycles.mask, 3));
305 nsec = cyclecounter_cyc2ns(&clock->cycles, overflow_cycles, 0, &frac);
306 clock->overflow_period = nsecs_to_jiffies(nsec);
308 INIT_DELAYED_WORK(&clock->overflow_work, mlxsw_sp1_ptp_clock_overflow);
309 mlxsw_core_schedule_dw(&clock->overflow_work, 0);
311 clock->common.ptp_info = mlxsw_sp1_ptp_clock_info;
312 clock->common.ptp = ptp_clock_register(&clock->common.ptp_info, dev);
313 if (IS_ERR(clock->common.ptp)) {
314 err = PTR_ERR(clock->common.ptp);
319 return &clock->common;
322 cancel_delayed_work_sync(&clock->overflow_work);
323 kfree(clock);
329 struct mlxsw_sp1_ptp_clock *clock =
333 cancel_delayed_work_sync(&clock->overflow_work);
334 kfree(clock);
337 static u64 mlxsw_sp2_ptp_read_utc(struct mlxsw_sp_ptp_clock *clock,
340 struct mlxsw_core *mlxsw_core = clock->core;
360 mlxsw_sp2_ptp_phc_settime(struct mlxsw_sp_ptp_clock *clock, u64 nsec)
362 struct mlxsw_core *mlxsw_core = clock->core;
375 struct mlxsw_sp_ptp_clock *clock =
383 return mlxsw_sp_ptp_phc_adjfreq(clock, -ppb);
388 struct mlxsw_sp_ptp_clock *clock =
390 struct mlxsw_core *mlxsw_core = clock->core;
397 nsec = mlxsw_sp2_ptp_read_utc(clock, NULL);
400 return mlxsw_sp2_ptp_phc_settime(clock, nsec);
413 struct mlxsw_sp_ptp_clock *clock =
417 nsec = mlxsw_sp2_ptp_read_utc(clock, sts);
426 struct mlxsw_sp_ptp_clock *clock =
430 return mlxsw_sp2_ptp_phc_settime(clock, nsec);
446 struct mlxsw_sp_ptp_clock *clock;
449 clock = kzalloc(sizeof(*clock), GFP_KERNEL);
450 if (!clock)
453 clock->core = mlxsw_sp->core;
455 clock->ptp_info = mlxsw_sp2_ptp_clock_info;
457 err = mlxsw_sp2_ptp_phc_settime(clock, 0);
463 clock->ptp = ptp_clock_register(&clock->ptp_info, dev);
464 if (IS_ERR(clock->ptp)) {
465 err = PTR_ERR(clock->ptp);
470 return clock;
474 kfree(clock);
478 void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
480 ptp_clock_unregister(clock->ptp);
481 kfree(clock);
616 struct mlxsw_sp_ptp_clock *clock_common = mlxsw_sp->clock;
617 struct mlxsw_sp1_ptp_clock *clock =
623 spin_lock_bh(&clock->lock);
624 nsec = timecounter_cyc2time(&clock->tc, timestamp);
625 spin_unlock_bh(&clock->lock);
1282 info->phc_index = ptp_clock_index(mlxsw_sp->clock->ptp);
1418 * stamp using the global UTC clock. The seconds have only 8 bits in the
1671 info->phc_index = ptp_clock_index(mlxsw_sp->clock->ptp);