Lines Matching full:ptp

3  * PTP 1588 clock support
98 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_settime() local
100 return ptp->info->settime64(ptp->info, tp); in ptp_clock_settime()
105 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_gettime() local
108 if (ptp->info->gettimex64) in ptp_clock_gettime()
109 err = ptp->info->gettimex64(ptp->info, tp, NULL); in ptp_clock_gettime()
111 err = ptp->info->gettime64(ptp->info, tp); in ptp_clock_gettime()
117 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); in ptp_clock_adjtime() local
121 ops = ptp->info; in ptp_clock_adjtime()
148 ptp->dialed_frequency = tx->freq; in ptp_clock_adjtime()
159 tx->freq = ptp->dialed_frequency; in ptp_clock_adjtime()
180 struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev); in ptp_clock_release() local
182 ptp_cleanup_pin_groups(ptp); in ptp_clock_release()
183 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_release()
184 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_release()
185 ida_simple_remove(&ptp_clocks_map, ptp->index); in ptp_clock_release()
186 kfree(ptp); in ptp_clock_release()
191 struct ptp_clock *ptp = container_of(work, struct ptp_clock, in ptp_aux_kworker() local
193 struct ptp_clock_info *info = ptp->info; in ptp_aux_kworker()
199 kthread_queue_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_aux_kworker()
207 struct ptp_clock *ptp; in ptp_clock_register() local
215 ptp = kzalloc(sizeof(struct ptp_clock), GFP_KERNEL); in ptp_clock_register()
216 if (ptp == NULL) in ptp_clock_register()
225 ptp->clock.ops = ptp_clock_ops; in ptp_clock_register()
226 ptp->info = info; in ptp_clock_register()
227 ptp->devid = MKDEV(major, index); in ptp_clock_register()
228 ptp->index = index; in ptp_clock_register()
229 spin_lock_init(&ptp->tsevq.lock); in ptp_clock_register()
230 mutex_init(&ptp->tsevq_mux); in ptp_clock_register()
231 mutex_init(&ptp->pincfg_mux); in ptp_clock_register()
232 init_waitqueue_head(&ptp->tsev_wq); in ptp_clock_register()
234 if (ptp->info->do_aux_work) { in ptp_clock_register()
235 kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); in ptp_clock_register()
236 ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index); in ptp_clock_register()
237 if (IS_ERR(ptp->kworker)) { in ptp_clock_register()
238 err = PTR_ERR(ptp->kworker); in ptp_clock_register()
239 pr_err("failed to create ptp aux_worker %d\n", err); in ptp_clock_register()
244 err = ptp_populate_pin_groups(ptp); in ptp_clock_register()
252 snprintf(pps.name, PPS_MAX_NAME_LEN, "ptp%d", index); in ptp_clock_register()
255 ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS); in ptp_clock_register()
256 if (IS_ERR(ptp->pps_source)) { in ptp_clock_register()
257 err = PTR_ERR(ptp->pps_source); in ptp_clock_register()
264 device_initialize(&ptp->dev); in ptp_clock_register()
265 ptp->dev.devt = ptp->devid; in ptp_clock_register()
266 ptp->dev.class = ptp_class; in ptp_clock_register()
267 ptp->dev.parent = parent; in ptp_clock_register()
268 ptp->dev.groups = ptp->pin_attr_groups; in ptp_clock_register()
269 ptp->dev.release = ptp_clock_release; in ptp_clock_register()
270 dev_set_drvdata(&ptp->dev, ptp); in ptp_clock_register()
271 dev_set_name(&ptp->dev, "ptp%d", ptp->index); in ptp_clock_register()
274 err = posix_clock_register(&ptp->clock, &ptp->dev); in ptp_clock_register()
280 return ptp; in ptp_clock_register()
283 if (ptp->pps_source) in ptp_clock_register()
284 pps_unregister_source(ptp->pps_source); in ptp_clock_register()
286 ptp_cleanup_pin_groups(ptp); in ptp_clock_register()
288 if (ptp->kworker) in ptp_clock_register()
289 kthread_destroy_worker(ptp->kworker); in ptp_clock_register()
291 mutex_destroy(&ptp->tsevq_mux); in ptp_clock_register()
292 mutex_destroy(&ptp->pincfg_mux); in ptp_clock_register()
295 kfree(ptp); in ptp_clock_register()
301 int ptp_clock_unregister(struct ptp_clock *ptp) in ptp_clock_unregister() argument
303 ptp->defunct = 1; in ptp_clock_unregister()
304 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_unregister()
306 if (ptp->kworker) { in ptp_clock_unregister()
307 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_clock_unregister()
308 kthread_destroy_worker(ptp->kworker); in ptp_clock_unregister()
312 if (ptp->pps_source) in ptp_clock_unregister()
313 pps_unregister_source(ptp->pps_source); in ptp_clock_unregister()
315 posix_clock_unregister(&ptp->clock); in ptp_clock_unregister()
321 void ptp_clock_event(struct ptp_clock *ptp, struct ptp_clock_event *event) in ptp_clock_event() argument
331 enqueue_external_timestamp(&ptp->tsevq, event); in ptp_clock_event()
332 wake_up_interruptible(&ptp->tsev_wq); in ptp_clock_event()
337 pps_event(ptp->pps_source, &evt, PTP_PPS_EVENT, NULL); in ptp_clock_event()
341 pps_event(ptp->pps_source, &event->pps_times, in ptp_clock_event()
348 int ptp_clock_index(struct ptp_clock *ptp) in ptp_clock_index() argument
350 return ptp->index; in ptp_clock_index()
354 int ptp_find_pin(struct ptp_clock *ptp, in ptp_find_pin() argument
360 for (i = 0; i < ptp->info->n_pins; i++) { in ptp_find_pin()
361 if (ptp->info->pin_config[i].func == func && in ptp_find_pin()
362 ptp->info->pin_config[i].chan == chan) { in ptp_find_pin()
363 pin = &ptp->info->pin_config[i]; in ptp_find_pin()
372 int ptp_find_pin_unlocked(struct ptp_clock *ptp, in ptp_find_pin_unlocked() argument
377 mutex_lock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
379 result = ptp_find_pin(ptp, func, chan); in ptp_find_pin_unlocked()
381 mutex_unlock(&ptp->pincfg_mux); in ptp_find_pin_unlocked()
387 int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay) in ptp_schedule_worker() argument
389 return kthread_mod_delayed_work(ptp->kworker, &ptp->aux_work, delay); in ptp_schedule_worker()
393 void ptp_cancel_worker_sync(struct ptp_clock *ptp) in ptp_cancel_worker_sync() argument
395 kthread_cancel_delayed_work_sync(&ptp->aux_work); in ptp_cancel_worker_sync()
412 ptp_class = class_create(THIS_MODULE, "ptp"); in ptp_init()
414 pr_err("ptp: failed to allocate class\n"); in ptp_init()
418 err = alloc_chrdev_region(&ptp_devt, 0, MINORMASK + 1, "ptp"); in ptp_init()
420 pr_err("ptp: failed to allocate device region\n"); in ptp_init()
425 pr_info("PTP clock support registered\n"); in ptp_init()
437 MODULE_DESCRIPTION("PTP clocks support");