hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/include/linux/ptp_clock_kernel.h
....@@ -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
218 #ifndef _PTP_CLOCK_KERNEL_H_
....@@ -39,8 +26,17 @@
3926 };
4027
4128 struct system_device_crosststamp;
29
+
4230 /**
43
- * struct ptp_clock_info - decribes a PTP hardware clock
31
+ * struct ptp_system_timestamp - system time corresponding to a PHC timestamp
32
+ */
33
+struct ptp_system_timestamp {
34
+ struct timespec64 pre_ts;
35
+ struct timespec64 post_ts;
36
+};
37
+
38
+/**
39
+ * struct ptp_clock_info - describes a PTP hardware clock
4440 *
4541 * @owner: The clock driver should set to THIS_MODULE.
4642 * @name: A short "friendly name" to identify the clock and to
....@@ -69,11 +65,24 @@
6965 * parameter delta: Desired frequency offset from nominal frequency
7066 * in parts per billion
7167 *
68
+ * @adjphase: Adjusts the phase offset of the hardware clock.
69
+ * parameter delta: Desired change in nanoseconds.
70
+ *
7271 * @adjtime: Shifts the time of the hardware clock.
7372 * parameter delta: Desired change in nanoseconds.
7473 *
7574 * @gettime64: Reads the current time from the hardware clock.
75
+ * This method is deprecated. New drivers should implement
76
+ * the @gettimex64 method instead.
7677 * parameter ts: Holds the result.
78
+ *
79
+ * @gettimex64: Reads the current time from the hardware clock and optionally
80
+ * also the system clock.
81
+ * parameter ts: Holds the PHC timestamp.
82
+ * parameter sts: If not NULL, it holds a pair of timestamps from
83
+ * the system clock. The first reading is made right before
84
+ * reading the lowest bits of the PHC timestamp and the second
85
+ * reading immediately follows that.
7786 *
7887 * @getcrosststamp: Reads the current time from the hardware clock and
7988 * system clock simultaneously.
....@@ -99,10 +108,10 @@
99108 * parameter func: the desired function to use.
100109 * parameter chan: the function channel index to use.
101110 *
102
- * @do_work: Request driver to perform auxiliary (periodic) operations
103
- * Driver should return delay of the next auxiliary work scheduling
104
- * time (>=0) or negative value in case further scheduling
105
- * is not required.
111
+ * @do_aux_work: Request driver to perform auxiliary (periodic) operations
112
+ * Driver should return delay of the next auxiliary work
113
+ * scheduling time (>=0) or negative value in case further
114
+ * scheduling is not required.
106115 *
107116 * Drivers should embed their ptp_clock_info within a private
108117 * structure, obtaining a reference to it using container_of().
....@@ -122,8 +131,11 @@
122131 struct ptp_pin_desc *pin_config;
123132 int (*adjfine)(struct ptp_clock_info *ptp, long scaled_ppm);
124133 int (*adjfreq)(struct ptp_clock_info *ptp, s32 delta);
134
+ int (*adjphase)(struct ptp_clock_info *ptp, s32 phase);
125135 int (*adjtime)(struct ptp_clock_info *ptp, s64 delta);
126136 int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts);
137
+ int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts,
138
+ struct ptp_system_timestamp *sts);
127139 int (*getcrosststamp)(struct ptp_clock_info *ptp,
128140 struct system_device_crosststamp *cts);
129141 int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts);
....@@ -215,6 +227,12 @@
215227 /**
216228 * ptp_find_pin() - obtain the pin index of a given auxiliary function
217229 *
230
+ * The caller must hold ptp_clock::pincfg_mux. Drivers do not have
231
+ * access to that mutex as ptp_clock is an opaque type. However, the
232
+ * core code acquires the mutex before invoking the driver's
233
+ * ptp_clock_info::enable() callback, and so drivers may call this
234
+ * function from that context.
235
+ *
218236 * @ptp: The clock obtained from ptp_clock_register().
219237 * @func: One of the ptp_pin_function enumerated values.
220238 * @chan: The particular functional channel to find.
....@@ -226,6 +244,19 @@
226244 enum ptp_pin_function func, unsigned int chan);
227245
228246 /**
247
+ * ptp_find_pin_unlocked() - wrapper for ptp_find_pin()
248
+ *
249
+ * This function acquires the ptp_clock::pincfg_mux mutex before
250
+ * invoking ptp_find_pin(). Instead of using this function, drivers
251
+ * should most likely call ptp_find_pin() directly from their
252
+ * ptp_clock_info::enable() method.
253
+ *
254
+ */
255
+
256
+int ptp_find_pin_unlocked(struct ptp_clock *ptp,
257
+ enum ptp_pin_function func, unsigned int chan);
258
+
259
+/**
229260 * ptp_schedule_worker() - schedule ptp auxiliary work
230261 *
231262 * @ptp: The clock obtained from ptp_clock_register().
....@@ -234,6 +265,13 @@
234265 */
235266
236267 int ptp_schedule_worker(struct ptp_clock *ptp, unsigned long delay);
268
+
269
+/**
270
+ * ptp_cancel_worker_sync() - cancel ptp auxiliary clock
271
+ *
272
+ * @ptp: The clock obtained from ptp_clock_register().
273
+ */
274
+void ptp_cancel_worker_sync(struct ptp_clock *ptp);
237275
238276 #else
239277 static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
....@@ -252,7 +290,21 @@
252290 static inline int ptp_schedule_worker(struct ptp_clock *ptp,
253291 unsigned long delay)
254292 { return -EOPNOTSUPP; }
293
+static inline void ptp_cancel_worker_sync(struct ptp_clock *ptp)
294
+{ }
255295
256296 #endif
257297
298
+static inline void ptp_read_system_prets(struct ptp_system_timestamp *sts)
299
+{
300
+ if (sts)
301
+ ktime_get_real_ts64(&sts->pre_ts);
302
+}
303
+
304
+static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts)
305
+{
306
+ if (sts)
307
+ ktime_get_real_ts64(&sts->post_ts);
308
+}
309
+
258310 #endif