Skip to content

Commit d94ba80

Browse files
richardcochranjohnstultz-work
authored andcommitted
ptp: Added a brand new class driver for ptp clocks.
This patch adds an infrastructure for hardware clocks that implement IEEE 1588, the Precision Time Protocol (PTP). A class driver offers a registration method to particular hardware clock drivers. Each clock is presented as a standard POSIX clock. The ancillary clock features are exposed in two different ways, via the sysfs and by a character device. Signed-off-by: Richard Cochran <[email protected]> Acked-by: Arnd Bergmann <[email protected]> Acked-by: David S. Miller <[email protected]> Signed-off-by: John Stultz <[email protected]>
1 parent caebc16 commit d94ba80

File tree

16 files changed

+1695
-0
lines changed

16 files changed

+1695
-0
lines changed

Documentation/ABI/testing/sysfs-ptp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
What: /sys/class/ptp/
2+
Date: September 2010
3+
Contact: Richard Cochran <[email protected]>
4+
Description:
5+
This directory contains files and directories
6+
providing a standardized interface to the ancillary
7+
features of PTP hardware clocks.
8+
9+
What: /sys/class/ptp/ptpN/
10+
Date: September 2010
11+
Contact: Richard Cochran <[email protected]>
12+
Description:
13+
This directory contains the attributes of the Nth PTP
14+
hardware clock registered into the PTP class driver
15+
subsystem.
16+
17+
What: /sys/class/ptp/ptpN/clock_name
18+
Date: September 2010
19+
Contact: Richard Cochran <[email protected]>
20+
Description:
21+
This file contains the name of the PTP hardware clock
22+
as a human readable string.
23+
24+
What: /sys/class/ptp/ptpN/max_adjustment
25+
Date: September 2010
26+
Contact: Richard Cochran <[email protected]>
27+
Description:
28+
This file contains the PTP hardware clock's maximum
29+
frequency adjustment value (a positive integer) in
30+
parts per billion.
31+
32+
What: /sys/class/ptp/ptpN/n_alarms
33+
Date: September 2010
34+
Contact: Richard Cochran <[email protected]>
35+
Description:
36+
This file contains the number of periodic or one shot
37+
alarms offer by the PTP hardware clock.
38+
39+
What: /sys/class/ptp/ptpN/n_external_timestamps
40+
Date: September 2010
41+
Contact: Richard Cochran <[email protected]>
42+
Description:
43+
This file contains the number of external timestamp
44+
channels offered by the PTP hardware clock.
45+
46+
What: /sys/class/ptp/ptpN/n_periodic_outputs
47+
Date: September 2010
48+
Contact: Richard Cochran <[email protected]>
49+
Description:
50+
This file contains the number of programmable periodic
51+
output channels offered by the PTP hardware clock.
52+
53+
What: /sys/class/ptp/ptpN/pps_avaiable
54+
Date: September 2010
55+
Contact: Richard Cochran <[email protected]>
56+
Description:
57+
This file indicates whether the PTP hardware clock
58+
supports a Pulse Per Second to the host CPU. Reading
59+
"1" means that the PPS is supported, while "0" means
60+
not supported.
61+
62+
What: /sys/class/ptp/ptpN/extts_enable
63+
Date: September 2010
64+
Contact: Richard Cochran <[email protected]>
65+
Description:
66+
This write-only file enables or disables external
67+
timestamps. To enable external timestamps, write the
68+
channel index followed by a "1" into the file.
69+
To disable external timestamps, write the channel
70+
index followed by a "0" into the file.
71+
72+
What: /sys/class/ptp/ptpN/fifo
73+
Date: September 2010
74+
Contact: Richard Cochran <[email protected]>
75+
Description:
76+
This file provides timestamps on external events, in
77+
the form of three integers: channel index, seconds,
78+
and nanoseconds.
79+
80+
What: /sys/class/ptp/ptpN/period
81+
Date: September 2010
82+
Contact: Richard Cochran <[email protected]>
83+
Description:
84+
This write-only file enables or disables periodic
85+
outputs. To enable a periodic output, write five
86+
integers into the file: channel index, start time
87+
seconds, start time nanoseconds, period seconds, and
88+
period nanoseconds. To disable a periodic output, set
89+
all the seconds and nanoseconds values to zero.
90+
91+
What: /sys/class/ptp/ptpN/pps_enable
92+
Date: September 2010
93+
Contact: Richard Cochran <[email protected]>
94+
Description:
95+
This write-only file enables or disables delivery of
96+
PPS events to the Linux PPS subsystem. To enable PPS
97+
events, write a "1" into the file. To disable events,
98+
write a "0" into the file.

Documentation/ptp/ptp.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
* PTP hardware clock infrastructure for Linux
3+
4+
This patch set introduces support for IEEE 1588 PTP clocks in
5+
Linux. Together with the SO_TIMESTAMPING socket options, this
6+
presents a standardized method for developing PTP user space
7+
programs, synchronizing Linux with external clocks, and using the
8+
ancillary features of PTP hardware clocks.
9+
10+
A new class driver exports a kernel interface for specific clock
11+
drivers and a user space interface. The infrastructure supports a
12+
complete set of PTP hardware clock functionality.
13+
14+
+ Basic clock operations
15+
- Set time
16+
- Get time
17+
- Shift the clock by a given offset atomically
18+
- Adjust clock frequency
19+
20+
+ Ancillary clock features
21+
- One short or periodic alarms, with signal delivery to user program
22+
- Time stamp external events
23+
- Period output signals configurable from user space
24+
- Synchronization of the Linux system time via the PPS subsystem
25+
26+
** PTP hardware clock kernel API
27+
28+
A PTP clock driver registers itself with the class driver. The
29+
class driver handles all of the dealings with user space. The
30+
author of a clock driver need only implement the details of
31+
programming the clock hardware. The clock driver notifies the class
32+
driver of asynchronous events (alarms and external time stamps) via
33+
a simple message passing interface.
34+
35+
The class driver supports multiple PTP clock drivers. In normal use
36+
cases, only one PTP clock is needed. However, for testing and
37+
development, it can be useful to have more than one clock in a
38+
single system, in order to allow performance comparisons.
39+
40+
** PTP hardware clock user space API
41+
42+
The class driver also creates a character device for each
43+
registered clock. User space can use an open file descriptor from
44+
the character device as a POSIX clock id and may call
45+
clock_gettime, clock_settime, and clock_adjtime. These calls
46+
implement the basic clock operations.
47+
48+
User space programs may control the clock using standardized
49+
ioctls. A program may query, enable, configure, and disable the
50+
ancillary clock features. User space can receive time stamped
51+
events via blocking read() and poll(). One shot and periodic
52+
signals may be configured via the POSIX timer_settime() system
53+
call.
54+
55+
** Writing clock drivers
56+
57+
Clock drivers include include/linux/ptp_clock_kernel.h and register
58+
themselves by presenting a 'struct ptp_clock_info' to the
59+
registration method. Clock drivers must implement all of the
60+
functions in the interface. If a clock does not offer a particular
61+
ancillary feature, then the driver should just return -EOPNOTSUPP
62+
from those functions.
63+
64+
Drivers must ensure that all of the methods in interface are
65+
reentrant. Since most hardware implementations treat the time value
66+
as a 64 bit integer accessed as two 32 bit registers, drivers
67+
should use spin_lock_irqsave/spin_unlock_irqrestore to protect
68+
against concurrent access. This locking cannot be accomplished in
69+
class driver, since the lock may also be needed by the clock
70+
driver's interrupt service routine.
71+
72+
** Supported hardware
73+
74+
+ Freescale eTSEC gianfar
75+
- 2 Time stamp external triggers, programmable polarity (opt. interrupt)
76+
- 2 Alarm registers (optional interrupt)
77+
- 3 Periodic signals (optional interrupt)
78+
79+
+ National DP83640
80+
- 6 GPIOs programmable as inputs or outputs
81+
- 6 GPIOs with dedicated functions (LED/JTAG/clock) can also be
82+
used as general inputs or outputs
83+
- GPIO inputs can time stamp external triggers
84+
- GPIO outputs can produce periodic signals
85+
- 1 interrupt pin
86+
87+
+ Intel IXP465
88+
- Auxiliary Slave/Master Mode Snapshot (optional interrupt)
89+
- Target Time (optional interrupt)

0 commit comments

Comments
 (0)