Lines Matching full:ptp
3 * PTP 1588 clock support
29 .name = "ptp",
96 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_settime() local
98 if (ptp_clock_freerun(ptp)) { in ptp_clock_settime()
99 pr_err("ptp: physical clock is free running\n"); in ptp_clock_settime()
103 return ptp->info->settime64(ptp->info, tp); in ptp_clock_settime()
108 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_gettime() local
111 if (ptp->info->gettimex64) in ptp_clock_gettime()
112 err = ptp->info->gettimex64(ptp->info, tp, NULL); in ptp_clock_gettime()
114 err = ptp->info->gettime64(ptp->info, tp); in ptp_clock_gettime()
120 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_adjtime() local
124 if (ptp_clock_freerun(ptp)) { in ptp_clock_adjtime()
125 pr_err("ptp: physical clock is free running\n"); in ptp_clock_adjtime()
129 ops = ptp->info; in ptp_clock_adjtime()
153 ptp->dialed_frequency = tx->freq; in ptp_clock_adjtime()
168 tx->freq = ptp->dialed_frequency; in ptp_clock_adjtime()
190 struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); in ptp_clock_release() local
194 ptp_cleanup_pin_groups(ptp); in ptp_clock_release()
195 kfree(ptp->vclock_index); in ptp_clock_release()
196 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_release()
197 mutex_destroy(&ptp->n_vclocks_mux); in ptp_clock_release()
199 spin_lock_irqsave(&ptp->tsevqs_lock, flags); in ptp_clock_release()
200 tsevq = list_first_entry(&ptp->tsevqs, struct timestamp_event_queue, in ptp_clock_release()
203 spin_unlock_irqrestore(&ptp->tsevqs_lock, flags); in ptp_clock_release()
206 debugfs_remove(ptp->debugfs_root); in ptp_clock_release()
207 xa_erase(&ptp_clocks_map, ptp->index); in ptp_clock_release()
208 kfree(ptp); in ptp_clock_release()
221 struct ptp_clock *ptp = container_of(work, struct ptp_clock, in ptp_aux_kworker() local
223 struct ptp_clock_info *info = ptp->info; in ptp_aux_kworker()
229 kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_aux_kworker()
237 struct ptp_clock *ptp; in ptp_clock_register() local
247 ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL); in ptp_clock_register()
248 if (!ptp) { in ptp_clock_register()
253 err = xa_alloc(&ptp_clocks_map, &index, ptp, xa_limit_31b, in ptp_clock_register()
258 ptp->clock.ops = ptp_clock_ops; in ptp_clock_register()
259 ptp->info = info; in ptp_clock_register()
260 ptp->devid = MKDEV(major, index); in ptp_clock_register()
261 ptp->index = index; in ptp_clock_register()
262 INIT_LIST_HEAD(&ptp->tsevqs); in ptp_clock_register()
268 list_add_tail(&queue->qlist, &ptp->tsevqs); in ptp_clock_register()
269 spin_lock_init(&ptp->tsevqs_lock); in ptp_clock_register()
277 mutex_init(&ptp->pincfg_mux); in ptp_clock_register()
278 mutex_init(&ptp->n_vclocks_mux); in ptp_clock_register()
279 init_waitqueue_head(&ptp->tsev_wq); in ptp_clock_register()
281 if (ptp->info->getcycles64 || ptp->info->getcyclesx64) { in ptp_clock_register()
282 ptp->has_cycles = true; in ptp_clock_register()
283 if (!ptp->info->getcycles64 && ptp->info->getcyclesx64) in ptp_clock_register()
284 ptp->info->getcycles64 = ptp_getcycles64; in ptp_clock_register()
287 ptp->info->getcycles64 = ptp_getcycles64; in ptp_clock_register()
289 if (ptp->info->gettimex64) in ptp_clock_register()
290 ptp->info->getcyclesx64 = ptp->info->gettimex64; in ptp_clock_register()
292 if (ptp->info->getcrosststamp) in ptp_clock_register()
293 ptp->info->getcrosscycles = ptp->info->getcrosststamp; in ptp_clock_register()
296 if (ptp->info->do_aux_work) { in ptp_clock_register()
297 kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); in ptp_clock_register()
298 ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index); in ptp_clock_register()
299 if (IS_ERR(ptp->kworker)) { in ptp_clock_register()
300 err = PTR_ERR(ptp->kworker); in ptp_clock_register()
301 pr_err("failed to create ptp aux_worker %d\n", err); in ptp_clock_register()
306 /* PTP virtual clock is being registered under physical clock */ in ptp_clock_register()
308 strcmp(parent->class->name, "ptp") == 0) in ptp_clock_register()
309 ptp->is_virtual_clock = true; in ptp_clock_register()
311 if (!ptp->is_virtual_clock) { in ptp_clock_register()
312 ptp->max_vclocks = PTP_DEFAULT_MAX_VCLOCKS; in ptp_clock_register()
314 size = sizeof(int) * ptp->max_vclocks; in ptp_clock_register()
315 ptp->vclock_index = kzalloc(size, GFP_KERNEL); in ptp_clock_register()
316 if (!ptp->vclock_index) { in ptp_clock_register()
322 err = ptp_populate_pin_groups(ptp); in ptp_clock_register()
330 snprintf(pps.name, PPS_MAX_NAME_LEN, "ptp%d", index); in ptp_clock_register()
333 ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS); in ptp_clock_register()
334 if (IS_ERR(ptp->pps_source)) { in ptp_clock_register()
335 err = PTR_ERR(ptp->pps_source); in ptp_clock_register()
339 ptp->pps_source->lookup_cookie = ptp; in ptp_clock_register()
343 device_initialize(&ptp->dev); in ptp_clock_register()
344 ptp->dev.devt = ptp->devid; in ptp_clock_register()
345 ptp->dev.class = &ptp_class; in ptp_clock_register()
346 ptp->dev.parent = parent; in ptp_clock_register()
347 ptp->dev.groups = ptp->pin_attr_groups; in ptp_clock_register()
348 ptp->dev.release = ptp_clock_release; in ptp_clock_register()
349 dev_set_drvdata(&ptp->dev, ptp); in ptp_clock_register()
350 dev_set_name(&ptp->dev, "ptp%d", ptp->index); in ptp_clock_register()
353 err = posix_clock_register(&ptp->clock, &ptp->dev); in ptp_clock_register()
355 if (ptp->pps_source) in ptp_clock_register()
356 pps_unregister_source(ptp->pps_source); in ptp_clock_register()
358 if (ptp->kworker) in ptp_clock_register()
359 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
361 put_device(&ptp->dev); in ptp_clock_register()
368 snprintf(debugfsname, sizeof(debugfsname), "ptp%d", ptp->index); in ptp_clock_register()
369 ptp->debugfs_root = debugfs_create_dir(debugfsname, NULL); in ptp_clock_register()
371 return ptp; in ptp_clock_register()
374 ptp_cleanup_pin_groups(ptp); in ptp_clock_register()
376 kfree(ptp->vclock_index); in ptp_clock_register()
378 if (ptp->kworker) in ptp_clock_register()
379 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
381 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_register()
382 mutex_destroy(&ptp->n_vclocks_mux); in ptp_clock_register()
390 kfree(ptp); in ptp_clock_register()
398 struct ptp_clock *ptp = dev_get_drvdata(dev); in unregister_vclock() local
400 ptp_vclock_unregister(info_to_vclock(ptp->info)); in unregister_vclock()
404 int ptp_clock_unregister(struct ptp_clock *ptp) in ptp_clock_unregister() argument
406 if (ptp_vclock_in_use(ptp)) { in ptp_clock_unregister()
407 device_for_each_child(&ptp->dev, NULL, unregister_vclock); in ptp_clock_unregister()
410 ptp->defunct = 1; in ptp_clock_unregister()
411 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_unregister()
413 if (ptp->kworker) { in ptp_clock_unregister()
414 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_clock_unregister()
415 kthread_destroy_worker(ptp->kworker); in ptp_clock_unregister()
419 if (ptp->pps_source) in ptp_clock_unregister()
420 pps_unregister_source(ptp->pps_source); in ptp_clock_unregister()
422 posix_clock_unregister(&ptp->clock); in ptp_clock_unregister()
428 void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) in ptp_clock_event() argument
442 spin_lock_irqsave(&ptp->tsevqs_lock, flags); in ptp_clock_event()
443 list_for_each_entry(tsevq, &ptp->tsevqs, qlist) { in ptp_clock_event()
447 spin_unlock_irqrestore(&ptp->tsevqs_lock, flags); in ptp_clock_event()
448 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_event()
453 pps_event(ptp->pps_source, &evt, PTP_PPS_EVENT, NULL); in ptp_clock_event()
457 pps_event(ptp->pps_source, &event->pps_times, in ptp_clock_event()
464 int ptp_clock_index(struct ptp_clock *ptp) in ptp_clock_index() argument
466 return ptp->index; in ptp_clock_index()
470 int ptp_find_pin(struct ptp_clock *ptp, in ptp_find_pin() argument
476 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_find_pin()
477 if (ptp->info->pin_config[i].func == func && in ptp_find_pin()
478 ptp->info->pin_config[i].chan == chan) { in ptp_find_pin()
479 pin = &ptp->info->pin_config[i]; in ptp_find_pin()
488 int ptp_find_pin_unlocked(struct ptp_clock *ptp, in ptp_find_pin_unlocked() argument
493 mutex_lock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
495 result = ptp_find_pin(ptp, func, chan); in ptp_find_pin_unlocked()
497 mutex_unlock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
503 int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay) in ptp_schedule_worker() argument
505 return kthread_mod_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_schedule_worker()
509 void ptp_cancel_worker_sync(struct ptp_clock *ptp) in ptp_cancel_worker_sync() argument
511 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_cancel_worker_sync()
530 pr_err("ptp: failed to allocate class\n"); in ptp_init()
534 err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp"); in ptp_init()
536 pr_err("ptp: failed to allocate device region\n"); in ptp_init()
540 pr_info("PTP clock support registered\n"); in ptp_init()
552 MODULE_DESCRIPTION("PTP clocks support");