.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * PTP 1588 clock support |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2010 OMICRON electronics GmbH |
---|
5 | | - * |
---|
6 | | - * This program is free software; you can redistribute it and/or modify |
---|
7 | | - * it under the terms of the GNU General Public License as published by |
---|
8 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
9 | | - * (at your option) any later version. |
---|
10 | | - * |
---|
11 | | - * This program is distributed in the hope that it will be useful, |
---|
12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | | - * GNU General Public License for more details. |
---|
15 | | - * |
---|
16 | | - * You should have received a copy of the GNU General Public License |
---|
17 | | - * along with this program; if not, write to the Free Software |
---|
18 | | - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
19 | 6 | */ |
---|
20 | 7 | #include <linux/idr.h> |
---|
21 | 8 | #include <linux/device.h> |
---|
.. | .. |
---|
118 | 105 | struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); |
---|
119 | 106 | int err; |
---|
120 | 107 | |
---|
121 | | - err = ptp->info->gettime64(ptp->info, tp); |
---|
| 108 | + if (ptp->info->gettimex64) |
---|
| 109 | + err = ptp->info->gettimex64(ptp->info, tp, NULL); |
---|
| 110 | + else |
---|
| 111 | + err = ptp->info->gettime64(ptp->info, tp); |
---|
122 | 112 | return err; |
---|
123 | 113 | } |
---|
124 | 114 | |
---|
125 | | -static int ptp_clock_adjtime(struct posix_clock *pc, struct timex *tx) |
---|
| 115 | +static int ptp_clock_adjtime(struct posix_clock *pc, struct __kernel_timex *tx) |
---|
126 | 116 | { |
---|
127 | 117 | struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); |
---|
128 | 118 | struct ptp_clock_info *ops; |
---|
.. | .. |
---|
156 | 146 | else |
---|
157 | 147 | err = ops->adjfreq(ops, ppb); |
---|
158 | 148 | ptp->dialed_frequency = tx->freq; |
---|
| 149 | + } else if (tx->modes & ADJ_OFFSET) { |
---|
| 150 | + if (ops->adjphase) { |
---|
| 151 | + s32 offset = tx->offset; |
---|
| 152 | + |
---|
| 153 | + if (!(tx->modes & ADJ_NANO)) |
---|
| 154 | + offset *= NSEC_PER_USEC; |
---|
| 155 | + |
---|
| 156 | + err = ops->adjphase(ops, offset); |
---|
| 157 | + } |
---|
159 | 158 | } else if (tx->modes == 0) { |
---|
160 | 159 | tx->freq = ptp->dialed_frequency; |
---|
161 | 160 | err = 0; |
---|
.. | .. |
---|
233 | 232 | init_waitqueue_head(&ptp->tsev_wq); |
---|
234 | 233 | |
---|
235 | 234 | if (ptp->info->do_aux_work) { |
---|
236 | | - char *worker_name = kasprintf(GFP_KERNEL, "ptp%d", ptp->index); |
---|
237 | | - |
---|
238 | 235 | kthread_init_delayed_work(&ptp->aux_work, ptp_aux_kworker); |
---|
239 | | - ptp->kworker = kthread_create_worker(0, worker_name ? |
---|
240 | | - worker_name : info->name); |
---|
241 | | - kfree(worker_name); |
---|
| 236 | + ptp->kworker = kthread_create_worker(0, "ptp%d", ptp->index); |
---|
242 | 237 | if (IS_ERR(ptp->kworker)) { |
---|
243 | 238 | err = PTR_ERR(ptp->kworker); |
---|
244 | 239 | pr_err("failed to create ptp aux_worker %d\n", err); |
---|
.. | .. |
---|
258 | 253 | pps.mode = PTP_PPS_MODE; |
---|
259 | 254 | pps.owner = info->owner; |
---|
260 | 255 | ptp->pps_source = pps_register_source(&pps, PTP_PPS_DEFAULTS); |
---|
261 | | - if (!ptp->pps_source) { |
---|
262 | | - err = -EINVAL; |
---|
| 256 | + if (IS_ERR(ptp->pps_source)) { |
---|
| 257 | + err = PTR_ERR(ptp->pps_source); |
---|
263 | 258 | pr_err("failed to register pps source\n"); |
---|
264 | 259 | goto no_pps; |
---|
265 | 260 | } |
---|
.. | .. |
---|
362 | 357 | struct ptp_pin_desc *pin = NULL; |
---|
363 | 358 | int i; |
---|
364 | 359 | |
---|
365 | | - mutex_lock(&ptp->pincfg_mux); |
---|
366 | 360 | for (i = 0; i < ptp->info->n_pins; i++) { |
---|
367 | 361 | if (ptp->info->pin_config[i].func == func && |
---|
368 | 362 | ptp->info->pin_config[i].chan == chan) { |
---|
.. | .. |
---|
370 | 364 | break; |
---|
371 | 365 | } |
---|
372 | 366 | } |
---|
373 | | - mutex_unlock(&ptp->pincfg_mux); |
---|
374 | 367 | |
---|
375 | 368 | return pin ? i : -1; |
---|
376 | 369 | } |
---|
377 | 370 | EXPORT_SYMBOL(ptp_find_pin); |
---|
| 371 | + |
---|
| 372 | +int ptp_find_pin_unlocked(struct ptp_clock *ptp, |
---|
| 373 | + enum ptp_pin_function func, unsigned int chan) |
---|
| 374 | +{ |
---|
| 375 | + int result; |
---|
| 376 | + |
---|
| 377 | + mutex_lock(&ptp->pincfg_mux); |
---|
| 378 | + |
---|
| 379 | + result = ptp_find_pin(ptp, func, chan); |
---|
| 380 | + |
---|
| 381 | + mutex_unlock(&ptp->pincfg_mux); |
---|
| 382 | + |
---|
| 383 | + return result; |
---|
| 384 | +} |
---|
| 385 | +EXPORT_SYMBOL(ptp_find_pin_unlocked); |
---|
378 | 386 | |
---|
379 | 387 | int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay) |
---|
380 | 388 | { |
---|
.. | .. |
---|
382 | 390 | } |
---|
383 | 391 | EXPORT_SYMBOL(ptp_schedule_worker); |
---|
384 | 392 | |
---|
| 393 | +void ptp_cancel_worker_sync(struct ptp_clock *ptp) |
---|
| 394 | +{ |
---|
| 395 | + kthread_cancel_delayed_work_sync(&ptp->aux_work); |
---|
| 396 | +} |
---|
| 397 | +EXPORT_SYMBOL(ptp_cancel_worker_sync); |
---|
| 398 | + |
---|
385 | 399 | /* module operations */ |
---|
386 | 400 | |
---|
387 | 401 | static void __exit ptp_exit(void) |
---|