hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/ptp/ptp_clock.c
....@@ -1,21 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * PTP 1588 clock support
34 *
45 * 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.
196 */
207 #include <linux/idr.h>
218 #include <linux/device.h>
....@@ -118,11 +105,14 @@
118105 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
119106 int err;
120107
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);
122112 return err;
123113 }
124114
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)
126116 {
127117 struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock);
128118 struct ptp_clock_info *ops;
....@@ -156,6 +146,15 @@
156146 else
157147 err = ops->adjfreq(ops, ppb);
158148 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
+ }
159158 } else if (tx->modes == 0) {
160159 tx->freq = ptp->dialed_frequency;
161160 err = 0;
....@@ -233,12 +232,8 @@
233232 init_waitqueue_head(&ptp->tsev_wq);
234233
235234 if (ptp->info->do_aux_work) {
236
- char *worker_name = kasprintf(GFP_KERNEL, "ptp%d", ptp->index);
237
-
238235 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);
242237 if (IS_ERR(ptp->kworker)) {
243238 err = PTR_ERR(ptp->kworker);
244239 pr_err("failed to create ptp aux_worker %d\n", err);
....@@ -258,8 +253,8 @@
258253 pps.mode = PTP_PPS_MODE;
259254 pps.owner = info->owner;
260255 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);
263258 pr_err("failed to register pps source\n");
264259 goto no_pps;
265260 }
....@@ -362,7 +357,6 @@
362357 struct ptp_pin_desc *pin = NULL;
363358 int i;
364359
365
- mutex_lock(&ptp->pincfg_mux);
366360 for (i = 0; i < ptp->info->n_pins; i++) {
367361 if (ptp->info->pin_config[i].func == func &&
368362 ptp->info->pin_config[i].chan == chan) {
....@@ -370,11 +364,25 @@
370364 break;
371365 }
372366 }
373
- mutex_unlock(&ptp->pincfg_mux);
374367
375368 return pin ? i : -1;
376369 }
377370 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);
378386
379387 int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay)
380388 {
....@@ -382,6 +390,12 @@
382390 }
383391 EXPORT_SYMBOL(ptp_schedule_worker);
384392
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
+
385399 /* module operations */
386400
387401 static void __exit ptp_exit(void)