Lines Matching +full:tx +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0-or-later
13 #include <linux/posix-clock.h>
38 return PTP_MAX_TIMESTAMPS - queue_cnt(q) - 1; in queue_free()
49 seconds = div_u64_rem(src->timestamp, 1000000000, &remainder); in enqueue_external_timestamp()
51 spin_lock_irqsave(&queue->lock, flags); in enqueue_external_timestamp()
53 dst = &queue->buf[queue->tail]; in enqueue_external_timestamp()
54 dst->index = src->index; in enqueue_external_timestamp()
55 dst->t.sec = seconds; in enqueue_external_timestamp()
56 dst->t.nsec = remainder; in enqueue_external_timestamp()
60 WRITE_ONCE(queue->head, (queue->head + 1) % PTP_MAX_TIMESTAMPS); in enqueue_external_timestamp()
62 WRITE_ONCE(queue->tail, (queue->tail + 1) % PTP_MAX_TIMESTAMPS); in enqueue_external_timestamp()
64 spin_unlock_irqrestore(&queue->lock, flags); in enqueue_external_timestamp()
70 * The 'freq' field in the 'struct timex' is in parts per in scaled_ppm_to_ppb()
92 tp->tv_sec = 0; in ptp_clock_getres()
93 tp->tv_nsec = 1; in ptp_clock_getres()
101 return ptp->info->settime64(ptp->info, tp); in ptp_clock_settime()
109 if (ptp->info->gettimex64) in ptp_clock_gettime()
110 err = ptp->info->gettimex64(ptp->info, tp, NULL); in ptp_clock_gettime()
112 err = ptp->info->gettime64(ptp->info, tp); in ptp_clock_gettime()
116 static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) in ptp_clock_adjtime() argument
120 int err = -EOPNOTSUPP; in ptp_clock_adjtime()
122 ops = ptp->info; in ptp_clock_adjtime()
124 if (tx->modes & ADJ_SETOFFSET) { in ptp_clock_adjtime()
129 ts.tv_sec = tx->time.tv_sec; in ptp_clock_adjtime()
130 ts.tv_nsec = tx->time.tv_usec; in ptp_clock_adjtime()
132 if (!(tx->modes & ADJ_NANO)) in ptp_clock_adjtime()
136 return -EINVAL; in ptp_clock_adjtime()
140 err = ops->adjtime(ops, delta); in ptp_clock_adjtime()
141 } else if (tx->modes & ADJ_FREQUENCY) { in ptp_clock_adjtime()
142 long ppb = scaled_ppm_to_ppb(tx->freq); in ptp_clock_adjtime()
143 if (ppb > ops->max_adj || ppb < -ops->max_adj) in ptp_clock_adjtime()
144 return -ERANGE; in ptp_clock_adjtime()
145 if (ops->adjfine) in ptp_clock_adjtime()
146 err = ops->adjfine(ops, tx->freq); in ptp_clock_adjtime()
148 err = ops->adjfreq(ops, ppb); in ptp_clock_adjtime()
149 ptp->dialed_frequency = tx->freq; in ptp_clock_adjtime()
150 } else if (tx->modes & ADJ_OFFSET) { in ptp_clock_adjtime()
151 if (ops->adjphase) { in ptp_clock_adjtime()
152 s32 offset = tx->offset; in ptp_clock_adjtime()
154 if (!(tx->modes & ADJ_NANO)) in ptp_clock_adjtime()
157 err = ops->adjphase(ops, offset); in ptp_clock_adjtime()
159 } else if (tx->modes == 0) { in ptp_clock_adjtime()
160 tx->freq = ptp->dialed_frequency; in ptp_clock_adjtime()
184 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_release()
185 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_release()
186 ida_simple_remove(&ptp_clocks_map, ptp->index); in ptp_clock_release()
194 struct ptp_clock_info *info = ptp->info; in ptp_aux_kworker()
197 delay = info->do_aux_work(info); in ptp_aux_kworker()
200 kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_aux_kworker()
211 if (info->n_alarm > PTP_MAX_ALARMS) in ptp_clock_register()
212 return ERR_PTR(-EINVAL); in ptp_clock_register()
215 err = -ENOMEM; in ptp_clock_register()
226 ptp->clock.ops = ptp_clock_ops; in ptp_clock_register()
227 ptp->info = info; in ptp_clock_register()
228 ptp->devid = MKDEV(major, index); in ptp_clock_register()
229 ptp->index = index; in ptp_clock_register()
230 spin_lock_init(&ptp->tsevq.lock); in ptp_clock_register()
231 mutex_init(&ptp->tsevq_mux); in ptp_clock_register()
232 mutex_init(&ptp->pincfg_mux); in ptp_clock_register()
233 init_waitqueue_head(&ptp->tsev_wq); in ptp_clock_register()
235 if (ptp->info->do_aux_work) { in ptp_clock_register()
236 kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); in ptp_clock_register()
237 ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index); in ptp_clock_register()
238 if (IS_ERR(ptp->kworker)) { in ptp_clock_register()
239 err = PTR_ERR(ptp->kworker); in ptp_clock_register()
250 if (info->pps) { in ptp_clock_register()
255 pps.owner = info->owner; in ptp_clock_register()
256 ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS); in ptp_clock_register()
257 if (IS_ERR(ptp->pps_source)) { in ptp_clock_register()
258 err = PTR_ERR(ptp->pps_source); in ptp_clock_register()
265 device_initialize(&ptp->dev); in ptp_clock_register()
266 ptp->dev.devt = ptp->devid; in ptp_clock_register()
267 ptp->dev.class = ptp_class; in ptp_clock_register()
268 ptp->dev.parent = parent; in ptp_clock_register()
269 ptp->dev.groups = ptp->pin_attr_groups; in ptp_clock_register()
270 ptp->dev.release = ptp_clock_release; in ptp_clock_register()
271 dev_set_drvdata(&ptp->dev, ptp); in ptp_clock_register()
272 dev_set_name(&ptp->dev, "ptp%d", ptp->index); in ptp_clock_register()
275 err = posix_clock_register(&ptp->clock, &ptp->dev); in ptp_clock_register()
284 if (ptp->pps_source) in ptp_clock_register()
285 pps_unregister_source(ptp->pps_source); in ptp_clock_register()
289 if (ptp->kworker) in ptp_clock_register()
290 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
292 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_register()
293 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_register()
304 ptp->defunct = 1; in ptp_clock_unregister()
305 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_unregister()
307 if (ptp->kworker) { in ptp_clock_unregister()
308 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_clock_unregister()
309 kthread_destroy_worker(ptp->kworker); in ptp_clock_unregister()
313 if (ptp->pps_source) in ptp_clock_unregister()
314 pps_unregister_source(ptp->pps_source); in ptp_clock_unregister()
316 posix_clock_unregister(&ptp->clock); in ptp_clock_unregister()
326 switch (event->type) { in ptp_clock_event()
332 enqueue_external_timestamp(&ptp->tsevq, event); in ptp_clock_event()
333 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_event()
338 pps_event(ptp->pps_source, &evt, PTP_PPS_EVENT, NULL); in ptp_clock_event()
342 pps_event(ptp->pps_source, &event->pps_times, in ptp_clock_event()
351 return ptp->index; in ptp_clock_index()
361 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_find_pin()
362 if (ptp->info->pin_config[i].func == func && in ptp_find_pin()
363 ptp->info->pin_config[i].chan == chan) { in ptp_find_pin()
364 pin = &ptp->info->pin_config[i]; in ptp_find_pin()
369 return pin ? i : -1; in ptp_find_pin()
378 mutex_lock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
382 mutex_unlock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
390 return kthread_mod_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_schedule_worker()
396 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_cancel_worker_sync()
425 ptp_class->dev_groups = ptp_groups; in ptp_init()