Lines Matching full:ptp
3 * PTP 1588 clock support
79 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_settime() local
81 if (ptp_clock_freerun(ptp)) { in ptp_clock_settime()
82 pr_err("ptp: physical clock is free running\n"); in ptp_clock_settime()
86 return ptp->info->settime64(ptp->info, tp); in ptp_clock_settime()
91 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_gettime() local
94 if (ptp->info->gettimex64) in ptp_clock_gettime()
95 err = ptp->info->gettimex64(ptp->info, tp, NULL); in ptp_clock_gettime()
97 err = ptp->info->gettime64(ptp->info, tp); in ptp_clock_gettime()
103 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_adjtime() local
107 if (ptp_clock_freerun(ptp)) { in ptp_clock_adjtime()
108 pr_err("ptp: physical clock is free running\n"); in ptp_clock_adjtime()
112 ops = ptp->info; in ptp_clock_adjtime()
137 ptp->dialed_frequency = tx->freq; in ptp_clock_adjtime()
152 tx->freq = ptp->dialed_frequency; in ptp_clock_adjtime()
173 struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); in ptp_clock_release() local
175 ptp_cleanup_pin_groups(ptp); in ptp_clock_release()
176 kfree(ptp->vclock_index); in ptp_clock_release()
177 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_release()
178 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_release()
179 mutex_destroy(&ptp->n_vclocks_mux); in ptp_clock_release()
180 ida_free(&ptp_clocks_map, ptp->index); in ptp_clock_release()
181 kfree(ptp); in ptp_clock_release()
194 struct ptp_clock *ptp = container_of(work, struct ptp_clock, in ptp_aux_kworker() local
196 struct ptp_clock_info *info = ptp->info; in ptp_aux_kworker()
202 kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_aux_kworker()
210 struct ptp_clock *ptp; in ptp_clock_register() local
219 ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL); in ptp_clock_register()
220 if (ptp == NULL) in ptp_clock_register()
229 ptp->clock.ops = ptp_clock_ops; in ptp_clock_register()
230 ptp->info = info; in ptp_clock_register()
231 ptp->devid = MKDEV(major, index); in ptp_clock_register()
232 ptp->index = index; in ptp_clock_register()
233 spin_lock_init(&ptp->tsevq.lock); in ptp_clock_register()
234 mutex_init(&ptp->tsevq_mux); in ptp_clock_register()
235 mutex_init(&ptp->pincfg_mux); in ptp_clock_register()
236 mutex_init(&ptp->n_vclocks_mux); in ptp_clock_register()
237 init_waitqueue_head(&ptp->tsev_wq); in ptp_clock_register()
239 if (ptp->info->getcycles64 || ptp->info->getcyclesx64) { in ptp_clock_register()
240 ptp->has_cycles = true; in ptp_clock_register()
241 if (!ptp->info->getcycles64 && ptp->info->getcyclesx64) in ptp_clock_register()
242 ptp->info->getcycles64 = ptp_getcycles64; in ptp_clock_register()
245 ptp->info->getcycles64 = ptp_getcycles64; in ptp_clock_register()
247 if (ptp->info->gettimex64) in ptp_clock_register()
248 ptp->info->getcyclesx64 = ptp->info->gettimex64; in ptp_clock_register()
250 if (ptp->info->getcrosststamp) in ptp_clock_register()
251 ptp->info->getcrosscycles = ptp->info->getcrosststamp; in ptp_clock_register()
254 if (ptp->info->do_aux_work) { in ptp_clock_register()
255 kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); in ptp_clock_register()
256 ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index); in ptp_clock_register()
257 if (IS_ERR(ptp->kworker)) { in ptp_clock_register()
258 err = PTR_ERR(ptp->kworker); in ptp_clock_register()
259 pr_err("failed to create ptp aux_worker %d\n", err); in ptp_clock_register()
264 /* PTP virtual clock is being registered under physical clock */ in ptp_clock_register()
266 strcmp(parent->class->name, "ptp") == 0) in ptp_clock_register()
267 ptp->is_virtual_clock = true; in ptp_clock_register()
269 if (!ptp->is_virtual_clock) { in ptp_clock_register()
270 ptp->max_vclocks = PTP_DEFAULT_MAX_VCLOCKS; in ptp_clock_register()
272 size = sizeof(int) * ptp->max_vclocks; in ptp_clock_register()
273 ptp->vclock_index = kzalloc(size, GFP_KERNEL); in ptp_clock_register()
274 if (!ptp->vclock_index) { in ptp_clock_register()
280 err = ptp_populate_pin_groups(ptp); in ptp_clock_register()
288 snprintf(pps.name, PPS_MAX_NAME_LEN, "ptp%d", index); in ptp_clock_register()
291 ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS); in ptp_clock_register()
292 if (IS_ERR(ptp->pps_source)) { in ptp_clock_register()
293 err = PTR_ERR(ptp->pps_source); in ptp_clock_register()
297 ptp->pps_source->lookup_cookie = ptp; in ptp_clock_register()
301 device_initialize(&ptp->dev); in ptp_clock_register()
302 ptp->dev.devt = ptp->devid; in ptp_clock_register()
303 ptp->dev.class = ptp_class; in ptp_clock_register()
304 ptp->dev.parent = parent; in ptp_clock_register()
305 ptp->dev.groups = ptp->pin_attr_groups; in ptp_clock_register()
306 ptp->dev.release = ptp_clock_release; in ptp_clock_register()
307 dev_set_drvdata(&ptp->dev, ptp); in ptp_clock_register()
308 dev_set_name(&ptp->dev, "ptp%d", ptp->index); in ptp_clock_register()
311 err = posix_clock_register(&ptp->clock, &ptp->dev); in ptp_clock_register()
313 if (ptp->pps_source) in ptp_clock_register()
314 pps_unregister_source(ptp->pps_source); in ptp_clock_register()
316 if (ptp->kworker) in ptp_clock_register()
317 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
319 put_device(&ptp->dev); in ptp_clock_register()
325 return ptp; in ptp_clock_register()
328 ptp_cleanup_pin_groups(ptp); in ptp_clock_register()
330 kfree(ptp->vclock_index); in ptp_clock_register()
332 if (ptp->kworker) in ptp_clock_register()
333 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
335 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_register()
336 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_register()
337 mutex_destroy(&ptp->n_vclocks_mux); in ptp_clock_register()
340 kfree(ptp); in ptp_clock_register()
348 struct ptp_clock *ptp = dev_get_drvdata(dev); in unregister_vclock() local
350 ptp_vclock_unregister(info_to_vclock(ptp->info)); in unregister_vclock()
354 int ptp_clock_unregister(struct ptp_clock *ptp) in ptp_clock_unregister() argument
356 if (ptp_vclock_in_use(ptp)) { in ptp_clock_unregister()
357 device_for_each_child(&ptp->dev, NULL, unregister_vclock); in ptp_clock_unregister()
360 ptp->defunct = 1; in ptp_clock_unregister()
361 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_unregister()
363 if (ptp->kworker) { in ptp_clock_unregister()
364 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_clock_unregister()
365 kthread_destroy_worker(ptp->kworker); in ptp_clock_unregister()
369 if (ptp->pps_source) in ptp_clock_unregister()
370 pps_unregister_source(ptp->pps_source); in ptp_clock_unregister()
372 posix_clock_unregister(&ptp->clock); in ptp_clock_unregister()
378 void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) in ptp_clock_event() argument
388 enqueue_external_timestamp(&ptp->tsevq, event); in ptp_clock_event()
389 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_event()
394 pps_event(ptp->pps_source, &evt, PTP_PPS_EVENT, NULL); in ptp_clock_event()
398 pps_event(ptp->pps_source, &event->pps_times, in ptp_clock_event()
405 int ptp_clock_index(struct ptp_clock *ptp) in ptp_clock_index() argument
407 return ptp->index; in ptp_clock_index()
411 int ptp_find_pin(struct ptp_clock *ptp, in ptp_find_pin() argument
417 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_find_pin()
418 if (ptp->info->pin_config[i].func == func && in ptp_find_pin()
419 ptp->info->pin_config[i].chan == chan) { in ptp_find_pin()
420 pin = &ptp->info->pin_config[i]; in ptp_find_pin()
429 int ptp_find_pin_unlocked(struct ptp_clock *ptp, in ptp_find_pin_unlocked() argument
434 mutex_lock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
436 result = ptp_find_pin(ptp, func, chan); in ptp_find_pin_unlocked()
438 mutex_unlock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
444 int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay) in ptp_schedule_worker() argument
446 return kthread_mod_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_schedule_worker()
450 void ptp_cancel_worker_sync(struct ptp_clock *ptp) in ptp_cancel_worker_sync() argument
452 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_cancel_worker_sync()
469 ptp_class = class_create("ptp"); in ptp_init()
471 pr_err("ptp: failed to allocate class\n"); in ptp_init()
475 err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp"); in ptp_init()
477 pr_err("ptp: failed to allocate device region\n"); in ptp_init()
482 pr_info("PTP clock support registered\n"); in ptp_init()
494 MODULE_DESCRIPTION("PTP clocks support");