PTP hardware clock infrastructure for Linux¶
This patch set introduces support for IEEE 1588 PTP clocks inLinux. Together with the SO_TIMESTAMPING socket options, thispresents a standardized method for developing PTP user spaceprograms, synchronizing Linux with external clocks, and using theancillary features of PTP hardware clocks.
A new class driver exports a kernel interface for specific clockdrivers and a user space interface. The infrastructure supports acomplete set of PTP hardware clock functionality.
- Basic clock operations- Set time- Get time- Shift the clock by a given offset atomically- Adjust clock frequency
- Ancillary clock features- Time stamp external events- Period output signals configurable from user space- Low Pass Filter (LPF) access from user space- Synchronization of the Linux system time via the PPS subsystem
PTP hardware clock kernel API¶
A PTP clock driver registers itself with the class driver. Theclass driver handles all of the dealings with user space. Theauthor of a clock driver need only implement the details ofprogramming the clock hardware. The clock driver notifies the classdriver of asynchronous events (alarms and external time stamps) viaa simple message passing interface.
The class driver supports multiple PTP clock drivers. In normal usecases, only one PTP clock is needed. However, for testing anddevelopment, it can be useful to have more than one clock in asingle system, in order to allow performance comparisons.
PTP hardware clock user space API¶
The class driver also creates a character device for eachregistered clock. User space can use an open file descriptor fromthe character device as a POSIX clock id and may callclock_gettime, clock_settime, and clock_adjtime. These callsimplement the basic clock operations.
User space programs may control the clock using standardizedioctls. A program may query, enable, configure, and disable theancillary clock features. User space can receive time stampedevents via blocking read() and poll().
Writing clock drivers¶
Clock drivers include include/linux/ptp_clock_kernel.h and registerthemselves by presenting a ‘struct ptp_clock_info’ to theregistration method. Clock drivers must implement all of thefunctions in the interface. If a clock does not offer a particularancillary feature, then the driver should just return -EOPNOTSUPPfrom those functions.
Drivers must ensure that all of the methods in interface arereentrant. Since most hardware implementations treat the time valueas a 64 bit integer accessed as two 32 bit registers, driversshould use spin_lock_irqsave/spin_unlock_irqrestore to protectagainst concurrent access. This locking cannot be accomplished inclass driver, since the lock may also be needed by the clockdriver’s interrupt service routine.
Supported hardware¶
- Freescale eTSEC gianfar
- 2 Time stamp external triggers, programmable polarity (opt. interrupt)
- 2 Alarm registers (optional interrupt)
- 3 Periodic signals (optional interrupt)
- National DP83640
- 6 GPIOs programmable as inputs or outputs
- 6 GPIOs with dedicated functions (LED/JTAG/clock) can also beused as general inputs or outputs
- GPIO inputs can time stamp external triggers
- GPIO outputs can produce periodic signals
- 1 interrupt pin
- Intel IXP465
- Auxiliary Slave/Master Mode Snapshot (optional interrupt)
- Target Time (optional interrupt)
- Renesas (IDT) ClockMatrix™
- Up to 4 independent PHC channels
- Integrated low pass filter (LPF), access via .adjPhase (compliant to ITU-T G.8273.2)
- Programmable output periodic signals
- Programmable inputs can time stamp external triggers
- Driver and/or hardware configuration through firmware (idtcm.bin)
- LPF settings (bandwidth, phase limiting, automatic holdover, physical layer assist (per ITU-T G.8273.2))
- Programmable output PTP clocks, any frequency up to 1GHz (to other PHY/MAC time stampers, refclk to ASSPs/SoCs/FPGAs)
- Lock to GNSS input, automatic switching between GNSS and user-space PHC control (optional)