Now and again there has been talk on this list of adding PTP support
into Linux. One part of the picture is already in place, the
SO_TIMESTAMPING API for hardware time stamping. This patch set offers
the missing second part needed for complete IEEE 1588 support.
The only feature still to be implemented is the hook into the PPS
subsystem, to synchronize the Linux clock to the PTP clock.
Enjoy,
Richard
* Patch ChangeLog
** v3
*** general
- Added documentation on writing clock drivers.
- Added the ioctls for the ancillary clock features.
- Changed wrong subsys_initcall() to module_init() in clock drivers.
- Removed the (too coarse) character device mutex.
- Setting the clock now requires CAP_SYS_TIME.
*** gianfar
- Added alarm feature.
- Added device tree node binding description.
- Added fine grain locking of the clock registers.
- Added the external time stamp feature.
- Added white space for better style.
- Coverted base+offset to structure pointers for register access.
- When removing the driver, we now disable all PTP functions.
** v2
- Changed clock list from a static array into a dynamic list. Also,
use a bitmap to manage the clock's minor numbers.
- Replaced character device semaphore with a mutex.
- Drop .ko from module names in Kbuild help.
- Replace deprecated unifdef-y with header-y for user space header file.
- Added links to both of the ptpd patches on sourceforge.
- Gianfar driver now gets parameters from device tree.
- Added API documentation to Documentation/ptp/ptp.txt
Richard Cochran (3):
ptp: Added a brand new class driver for ptp clocks.
ptp: Added a clock that uses the Linux system time.
ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Documentation/powerpc/dts-bindings/fsl/tsec.txt | 56 +++
Documentation/ptp/ptp.txt | 95 ++++
Documentation/ptp/testptp.c | 245 +++++++++++
Documentation/ptp/testptp.mk ...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 exposed to user space as a character device with ioctls that allow tuning of the PTP clock. Signed-off-by: Richard Cochran <richard.cochran@omicron.at> --- Documentation/ptp/ptp.txt | 95 +++++++ Documentation/ptp/testptp.c | 245 ++++++++++++++++++ Documentation/ptp/testptp.mk | 33 +++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ptp/Kconfig | 26 ++ drivers/ptp/Makefile | 5 + drivers/ptp/ptp_clock.c | 512 ++++++++++++++++++++++++++++++++++++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 79 ++++++ include/linux/ptp_clock_kernel.h | 137 ++++++++++ 11 files changed, 1136 insertions(+), 0 deletions(-) create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h diff --git a/Documentation/ptp/ptp.txt b/Documentation/ptp/ptp.txt new file mode 100644 index 0000000..46858b3 --- /dev/null +++ b/Documentation/ptp/ptp.txt @@ -0,0 +1,95 @@ + +* PTP infrastructure for Linux + + This patch set introduces support for IEEE 1588 PTP clocks in + Linux. Together with the SO_TIMESTAMPING socket options, this + presents a standardized method for developing PTP user space + programs, synchronizing Linux with external clocks, and using the + ancillary features of PTP hardware clocks. + + A new class driver exports a kernel interface for specific clock + drivers and a user space interface. The infrastructure supports ...
Tested-by: Wolfgang Grandegger <wg@denx.de> on my Freescale MPC8313 setup with ptpd and ptpv2d. Wolfgang. --
This PTP clock simply uses the NTP time adjustment system calls. The driver can be used in systems that lack a special hardware PTP clock. Signed-off-by: Richard Cochran <richard.cochran@omicron.at> --- drivers/ptp/Kconfig | 12 ++++ drivers/ptp/Makefile | 1 + drivers/ptp/ptp_linux.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ kernel/time/ntp.c | 2 + 4 files changed, 151 insertions(+), 0 deletions(-) create mode 100644 drivers/ptp/ptp_linux.c diff --git a/drivers/ptp/Kconfig b/drivers/ptp/Kconfig index c80a25b..9390d44 100644 --- a/drivers/ptp/Kconfig +++ b/drivers/ptp/Kconfig @@ -23,4 +23,16 @@ config PTP_1588_CLOCK To compile this driver as a module, choose M here: the module will be called ptp_clock. +config PTP_1588_CLOCK_LINUX + tristate "Linux system timer as PTP clock" + depends on PTP_1588_CLOCK + help + This driver adds support for using the standard Linux time + source as a PTP clock. This clock is only useful if your PTP + programs are using software time stamps for the PTP Ethernet + packets. + + To compile this driver as a module, choose M here: the module + will be called ptp_linux. + endmenu diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile index b86695c..1651d52 100644 --- a/drivers/ptp/Makefile +++ b/drivers/ptp/Makefile @@ -3,3 +3,4 @@ # obj-$(CONFIG_PTP_1588_CLOCK) += ptp_clock.o +obj-$(CONFIG_PTP_1588_CLOCK_LINUX) += ptp_linux.o diff --git a/drivers/ptp/ptp_linux.c b/drivers/ptp/ptp_linux.c new file mode 100644 index 0000000..f0dbfc6 --- /dev/null +++ b/drivers/ptp/ptp_linux.c @@ -0,0 +1,136 @@ +/* + * PTP 1588 clock using the Linux system clock + * + * Copyright (C) 2010 OMICRON electronics GmbH + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + ...
The eTSEC includes a PTP clock with quite a few features. This patch adds support for the basic clock adjustment functions, plus two external time stamps and one alarm. Signed-off-by: Richard Cochran <richard.cochran@omicron.at> --- Documentation/powerpc/dts-bindings/fsl/tsec.txt | 56 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + drivers/net/Makefile | 1 + drivers/net/gianfar_ptp.c | 521 +++++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++++ drivers/ptp/Kconfig | 13 + 8 files changed, 746 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h diff --git a/Documentation/powerpc/dts-bindings/fsl/tsec.txt b/Documentation/powerpc/dts-bindings/fsl/tsec.txt index edb7ae1..b09ba66 100644 --- a/Documentation/powerpc/dts-bindings/fsl/tsec.txt +++ b/Documentation/powerpc/dts-bindings/fsl/tsec.txt @@ -74,3 +74,59 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - device_type Should be "ptp_clock" + - model Model of the device. Must be "eTSEC" + - reg Offset and length of the register set for the device + - interrupts There should be at least two and as many as four + PTP related interrupts + +Clock Properties: + + - tclk_period Timer reference clock period in nanoseconds. + - tmr_prsc Prescaler, divides the output clock. + - tmr_add Frequency compensation value. + - cksel 0= external clock, 1= eTSEC system clock, 3= RTC clock input. + Currently the driver only supports choice "1". + - tmr_fiper1 Fixed interval period pulse generator. + - tmr_fiper2 Fixed interval period pulse generator. + + ...
Model, while abused by the current gianfar binding code, is not supposed to be something that is ordinarily used to bind on. It is supposed to be a freeform field for indicating the specific model of hardware, mainly for human consumption or as a last resort for working around problems. Get rid of both device_type and model, and specify a compatible string instead (e.g. "fsl,etsec-ptp"). Or perhaps this should just be some additional properties on the existing gianfar nodes, rather than presenting it as a separate device? How do you associate a given ptp block with the corresponding gianfar node? If there are differences in ptp implementation between different versions of etsec, can the ptp Dashes are more typical in OF names than underscores, and it's generally better to be a little more verbose -- these aren't local loop iterators. Do these values describe the way the hardware is, or how it's been configured by firmware, or a set of values that are clearly optimal for this particular board? If it's just configuration for the Linux driver, that could reasonably differ based on what a given user or OS will want, You've got two IRQs, with the same handler, and the same dev_id? From the manual it looks like there's one PTP interrupt per eTSEC (which This driver controls every possible PTP implementation? -Scott --
Okay, will do. I really am at a loss at understanding all the rules in
the whole device tree world. I just tried to follow
There only one PTP clock. Its registers repeat in each port's memory
space, but you are only supposed to touch the first set of PTP
registers. If you consider how PTP works, there can never be per port
clocks, since this would make it impossible to make a boundary clock,
for example.
The whole idea of this PTP clock framework is to keep the clock
drivers separate from the MAC drivers, even when they use the same
hardware. The functionality is logically divided into two parts. The
MAC provides time stamps, and the clock provides a way to control its
offset and frequency.
Up until this point, people have simply hacked new private ioctls into
the driver for each MAC that supports PTP. That is not a good long
term solution for PTP support in Linux.
In general, I think it will not be hard to keep the MAC and the clock
drivers from stepping on each other's toes. The eTSEC hardware is
There are no differences (that I know of) in how the PTP clocks
work. I have in house the mpc8313, the mpc8572, and the p2020. The
mpc8572 appears to lack some of the TMR_CTRL bits, but this is
The names come from the register mnemonics from the documentation. I
prefer to use the same names as is found in the manuals. That way, a
Okay, but must I then change the following code in order to find them?
Does adding the prefix just mean that I also add it to my search
strings, or is it preprocessed (stripped) somehow?
static int get_of_u32(struct device_node *node, char *str, u32 *val)
{
int plen;
const u32 *prop = of_get_property(node, str, &plen);
if (!prop || plen != sizeof(*prop))
return -1;
*val = *prop;
return 0;
}
...
if (get_of_u32(node, "tclk_period",&etsects->tclk_period) ||
get_of_u32(node, "tmr_prsc",&etsects->tmr_prsc) ||
get_of_u32(node, "tmr_add",&etsects->tmr_add) ||
get_of_u32(node, "cksel",&etsects->cksel) ||
...There's some stuff in there that isn't how we'd do it now, but is slow OK. I'm not too familiar with PTP itself, was looking more at the If there's any possibility of needing to make a distinction (which probably can't be ruled out with future chips), the chip name could be made part of the compatible string, with a secondary compatible showing a canonical part name for that version of the PTP block. E.g. p2020 might have: compatble = "fsl,p2020-etsec-ptp", "fsl,mpc8313-etsec-ptp"; The driver would bind only on the mpc8313 version. There are several examples of this, such as the Freescale i2c driver and The device tree should still contain all of the interrupts, in case they're needed later -- and put a comment in the driver saying why the Put .compatible = "fsl,etsec-ptp" (or "fsl,mpc8313-etsec-ptp") where you have .type = "ptp_clock". -Scott --
I doubt they really have a third fiper. First of all, this signal is not routed anywhere on the boards. Also, according to the documentation, it has no bit in the TMR_CTRL or the TMR_TEMASK registers. Unless there is a bit in TMR_TEMASK, you cannot get an interrupt from it. If you cannot use the signal externally (in the "real" world) and you cannot get an interrupt, what good is it to have such a periodic signal? Polling the bit in the TMR_TEVENT to see when a pulse occurs seems pointless. Scott, you have connections, right? Can you clarify this for me? Thanks, Richard --
OK, but that's a separate issue from whether it exists on the chip and I'll ask around. -Scott --
Tested-by: Wolfgang Grandegger <wg@denx.de> on my Freescale MPC8313 setup with ptpd and ptpv2d. FYI: checkplatch.pl reports various errors for this patch series. Wolfgang. --
