ptp: IEEE 1588 clock support
Subsystems (7)
Richard Cochran
maintainerv3 cover ptp: IEEE 1588 clock support
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 | 33 ++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/p2020ds.dts | 14 + arch/powerpc/boot/dts/p2020rdb.dts | 14 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/net/Makefile | 1 + drivers/net/gianfar_ptp.c | 521 +++++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++++ drivers/ptp/Kconfig | 51 +++ drivers/ptp/Makefile | 6 + drivers/ptp/ptp_clock.c | 512 ++++++++++++++++++++++ drivers/ptp/ptp_linux.c | 136 ++++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 79 ++++ include/linux/ptp_clock_kernel.h | 137 ++++++ kernel/time/ntp.c | 2 + 20 files changed, 2033 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/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_linux.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h
Richard Cochran
maintainerPATCH v3 1/3 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 exposed to user space as a character device with ioctls that allow tuning of the PTP clock.
--- 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
Documentation/ptp/ptp.txt new file +95 -0
@@ -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 a + complete set of PTP functionality. + + + Basic clock operations + - Set time + - Get time + - Shift the clock by a given offset atomically + - Adjust clock frequency + + + Ancillary clock features + - One short or periodic alarms, with signal delivery to user program + - Time stamp external events + - Period output signals configurable from user space + - Synchronization of the Linux system time via the PPS subsystem + +** PTP kernel API + + A PTP clock driver registers itself with the class driver. The + class driver handles all of the dealings with user space. The + author of a clock driver need only implement the details of + programming the clock hardware. The clock driver notifies the class + driver of asynchronous events (alarms and external time stamps) via + a simple message passing interface. + + The class driver supports multiple PTP clock drivers. In normal use + cases, only one PTP clock is needed. However, for testing and + development, it can be useful to have more than one clock in a + single system, in order to allow performance comparisons. + +** PTP user space API + + The class driver creates a character device for each registered PTP + clock. User space programs may control the clock using standardized + ioctls. A program may query, enable, configure, and disable the + ancillary clock features. User space can receive time stamped + events via blocking read() and poll(). One shot and periodic + signals may be configured via an ioctl API with semantics similar + to the POSIX timer_settime() system call. + + As an real life example, the following two patches for ptpd version + 1.0.0 demonstrate how the API works. + + https://sourceforge.net/tracker/?func=detail&aid=2992845&group_id=139814&atid=744634 + + https://sourceforge.net/tracker/?func=detail&aid=2992847&group_id=139814&atid=744634 + +** Writing clock drivers + + Clock drivers include include/linux/ptp_clock_kernel.h and register + themselves by presenting a 'struct ptp_clock_info' to the + registration method. Clock drivers must implement all of the + functions in the interface. If a clock does not offer a particular + ancillary feature, then the driver should just return -EOPNOTSUPP + from those functions. + + Drivers must ensure that all of the methods in interface are + reentrant. Since most hardware implementations treat the time value + as a 64 bit integer accessed as two 32 bit registers, drivers + should use spin_lock_irqsave/spin_unlock_irqrestore to protect + against concurrent access. This locking cannot be accomplished in + class driver, since the lock may also be needed by the clock + driver's interrupt service routine. + +** Supported hardware + + + Standard Linux system timer + - No special PTP features + - For use with software time stamping + + + 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 be + used 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)
Documentation/ptp/testptp.c new file +245 -0
245 lines not on this page · raw message
Documentation/ptp/testptp.mk new file +33 -0
@@ -0,0 +1,33 @@ +# PTP 1588 clock support - User space test program +# +# 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. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +CC = $(CROSS_COMPILE)gcc +INC = -I$(KBUILD_OUTPUT)/usr/include +CFLAGS = -Wall $(INC) +LDLIBS = -lrt +PROGS = testptp + +all: $(PROGS) + +testptp: testptp.o + +clean: + rm -f testptp.o + +distclean: clean + rm -f $(PROGS)
drivers/Kconfig +2 -0
@@ -52,6 +52,8 @@ source "drivers/spi/Kconfig" source "drivers/pps/Kconfig" +source "drivers/ptp/Kconfig" + source "drivers/gpio/Kconfig" source "drivers/w1/Kconfig"
drivers/Makefile +1 -0
@@ -75,6 +75,7 @@ obj-$(CONFIG_I2O) += message/ obj-$(CONFIG_RTC_LIB) += rtc/ obj-y += i2c/ media/ obj-$(CONFIG_PPS) += pps/ +obj-$(CONFIG_PTP_1588_CLOCK) += ptp/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_POWER_SUPPLY) += power/ obj-$(CONFIG_HWMON) += hwmon/
drivers/ptp/Kconfig new file +26 -0
@@ -0,0 +1,26 @@ +# +# PTP clock support configuration +# + +menu "PTP clock support" + +config PTP_1588_CLOCK + tristate "PTP clock support" + depends on EXPERIMENTAL + help + The IEEE 1588 standard defines a method to precisely + synchronize distributed clocks over Ethernet networks. The + standard defines a Precision Time Protocol (PTP), which can + be used to achieve synchronization within a few dozen + microseconds. In addition, with the help of special hardware + time stamping units, it can be possible to achieve + synchronization to within a few hundred nanoseconds. + + This driver adds support for PTP clocks as character + devices. If you want to use a PTP clock, then you should + also enable at least one clock driver as well. + + To compile this driver as a module, choose M here: the module + will be called ptp_clock. + +endmenu
drivers/ptp/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# +# Makefile for PTP 1588 clock support. +# + +obj-$(CONFIG_PTP_1588_CLOCK) += ptp_clock.o
drivers/ptp/ptp_clock.c new file +512 -0
512 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -140,6 +140,7 @@ header-y += pkt_sched.h header-y += posix_types.h header-y += ppdev.h header-y += prctl.h +header-y += ptp_clock.h header-y += qnxtypes.h header-y += qnx4_fs.h header-y += radeonfb.h
include/linux/ptp_clock.h new file +79 -0
79 lines not on this page · raw message
include/linux/ptp_clock_kernel.h new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
1.6.3.3
Re: [PATCH v3 1/3] ptp: Added a brand new class driver for ptp clocks.
Quoted 7 lines · Richard Cochran
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 <[email protected]>
on my Freescale MPC8313 setup with ptpd and ptpv2d.
Wolfgang.
Richard Cochran
maintainerPATCH v3 2/3 ptp: Added a clock that uses the Linux system time.
In reply to Richard CochranThis PTP clock simply uses the NTP time adjustment system calls. The driver can be used in systems that lack a special hardware PTP clock.
--- 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
drivers/ptp/Kconfig +12 -0
@@ -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
drivers/ptp/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_PTP_1588_CLOCK) += ptp_clock.o +obj-$(CONFIG_PTP_1588_CLOCK_LINUX) += ptp_linux.o
drivers/ptp/ptp_linux.c new file +136 -0
136 lines not on this page · raw message
kernel/time/ntp.c +2 -0
@@ -14,6 +14,7 @@#include <linux/timex.h> #include <linux/time.h> #include <linux/mm.h> +#include <linux/module.h> /* * NTP timekeeping variables:
@@ -535,6 +536,7 @@ int do_adjtimex(struct timex *txc)return result; } +EXPORT_SYMBOL (do_adjtimex);static int __init ntp_tick_adj_setup (char *str) {
Signature · 1 line
1.6.3.3
Richard Cochran
maintainerPATCH v3 3/3 ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Richard CochranThe 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.
--- 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
Documentation/powerpc/dts-bindings/fsl/tsec.txt +56 -0
@@ -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. + + These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right. + Here is how to figure good values: + + TimerOsc = system clock MHz + tclk_period = desired clock period nanoseconds + NominalFreq = 1000 / tclk_period MHz + FreqDivRatio = TimerOsc / NominalFreq (must be greater that 1.0) + tmr_add = ceil(2^32 / FreqDivRatio) + OutputClock = NominalFreq / tmr_prsc MHz + PulseWidth = 1 / OutputClock microseconds + FiperFreq1 = desired frequency in Hz + FiperDiv1 = 1000000 * OutputClock / FiperFreq1 + tmr_fiper1 = tmr_prsc * tclk_period * FiperDiv1 - tclk_period + + The calculation for tmr_fiper2 is the same as for tmr_fiper1. The + driver expects that tmr_fiper1 will be correctly set to produce a 1 + Pulse Per Second (PPS) signal, since this will be offered to the PPS + subsystem to synchronize the Linux clock. + +Example: + + ptp_clock@24E00 { + device_type = "ptp_clock"; + model = "eTSEC"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk_period = <10>; + tmr_prsc = <100>; + tmr_add = <0x999999A4>; + cksel = <0x1>; + tmr_fiper1 = <0x3B9AC9F6>; + tmr_fiper2 = <0x00018696>; + };
arch/powerpc/boot/dts/mpc8313erdb.dts +14 -0
@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + device_type = "ptp_clock"; + model = "eTSEC"; + reg = <0x24E00 0xB0>; + interrupts = <12 0x8 13 0x8>; + interrupt-parent = < &ipic >; + tclk_period = <10>; + tmr_prsc = <100>; + tmr_add = <0x999999A4>; + cksel = <0x1>; + tmr_fiper1 = <0x3B9AC9F6>; + tmr_fiper2 = <0x00018696>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020ds.dts +14 -0
@@ -336,6 +336,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + device_type = "ptp_clock"; + model = "eTSEC"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk_period = <5>; + tmr_prsc = <200>; + tmr_add = <0xCCCCCCCD>; + cksel = <1>; + tmr_fiper1 = <0x3B9AC9FB>; + tmr_fiper2 = <0x0001869B>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/p2020rdb.dts +14 -0
@@ -396,6 +396,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + device_type = "ptp_clock"; + model = "eTSEC"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk_period = <5>; + tmr_prsc = <200>; + tmr_add = <0xCCCCCCCD>; + cksel = <1>; + tmr_fiper1 = <0x3B9AC9FB>; + tmr_fiper2 = <0x0001869B>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
drivers/net/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_ATL2) += atlx/ obj-$(CONFIG_ATL1E) += atl1e/ obj-$(CONFIG_ATL1C) += atl1c/ obj-$(CONFIG_GIANFAR) += gianfar_driver.o +obj-$(CONFIG_PTP_1588_CLOCK_GIANFAR) += gianfar_ptp.o obj-$(CONFIG_TEHUTI) += tehuti.o obj-$(CONFIG_ENIC) += enic/ obj-$(CONFIG_JME) += jme.o
drivers/net/gianfar_ptp.c new file +521 -0
521 lines not on this page · raw message
drivers/net/gianfar_ptp_reg.h new file +113 -0
113 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -35,4 +35,17 @@ config PTP_1588_CLOCK_LINUX To compile this driver as a module, choose M here: the module will be called ptp_linux. +config PTP_1588_CLOCK_GIANFAR + tristate "Freescale eTSEC as PTP clock" + depends on PTP_1588_CLOCK + depends on GIANFAR + help + This driver adds support for using the eTSEC as a PTP + clock. This clock is only useful if your PTP programs are + getting hardware time stamps on the PTP Ethernet packets + using the SO_TIMESTAMPING API. + + To compile this driver as a module, choose M here: the module + will be called gianfar_ptp. + endmenu
Signature · 1 line
1.6.3.3
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 5 lines · Richard Cochran
Documentation/powerpc/dts-bindings/fsl/tsec.txt +0
-0
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 82
Quoted 9 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +6
-0@@ -74,3 +74,59 @@ Example: interrupt-parent =<&mpic>; phy-handle =<&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - device_type Should be "ptp_clock"
Device_type is deprecated in most contexts for flat device trees.
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 83
Quoted 1 line
Documentation/powerpc/dts-bindings/fsl/tsec.txt +1
-0+ - model Model of the device. Must be "eTSEC"
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 driver see the etsec version register?
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 96
Quoted 13 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +13
-0+ - 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.
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.
They should probably have an "fsl,ptp-" prefix as well.
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 99
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +2
-0+ These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right.
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, the device tree probably isn't the right place for it.
Quoted 12 lines
arch/powerpc/boot/dts/p2020ds.dts +4
-0@@ -336,6 +336,20 @@ phy_type = "ulpi"; }; + ptp_clock@24E00 { + device_type = "ptp_clock"; + model = "eTSEC"; + reg = <0x24E00 0xB0>;
arch/powerpc/boot/dts/p2020ds.dts line 352
Quoted 10 lines
arch/powerpc/boot/dts/p2020ds.dts +10
-0+ interrupts = <68 2 69 2 70 2>; + interrupt-parent = < &mpic >; + tclk_period = <5>; + tmr_prsc = <200>; + tmr_add = <0xCCCCCCCD>; + cksel = <1>; + tmr_fiper1 = <0x3B9AC9FB>; + tmr_fiper2 = <0x0001869B>; + }; +
This one has 3 interrupts? The driver supports only two.
arch/powerpc/boot/dts/p2020ds.dts line 354
Quoted 2 lines
arch/powerpc/boot/dts/p2020ds.dts +2
-0+/* Private globals */ +static struct ptp_clock *gianfar_clock;
Do you not support more than one of these?
arch/powerpc/boot/dts/p2020ds.dts line 355
Quoted 1 line
arch/powerpc/boot/dts/p2020ds.dts +1
-0+static struct etsects the_clock;
"The" clock? As oppsed to the "other" clock one line above? :-)
Quoted 53 lines
arch/powerpc/boot/dts/p2020ds.dts +53
-0+static irqreturn_t isr(int irq, void *priv) +{ + struct etsects *etsects = priv; + struct ptp_clock_event event; + u64 ns; + u32 ack=0, lo, hi, mask, val; + + val = gfar_read(&etsects->regs->tmr_tevent); + + if (val& ETS1) { + ack |= ETS1; + hi = gfar_read(&etsects->regs->tmr_etts1_h); + lo = gfar_read(&etsects->regs->tmr_etts1_l); + event.type = PTP_CLOCK_EXTTS; + event.index = 0; + event.timestamp = ((u64) hi)<< 32; + event.timestamp |= lo; + ptp_clock_event(gianfar_clock,&event); + } + + if (val& ETS2) { + ack |= ETS2; + hi = gfar_read(&etsects->regs->tmr_etts2_h); + lo = gfar_read(&etsects->regs->tmr_etts2_l); + event.type = PTP_CLOCK_EXTTS; + event.index = 1; + event.timestamp = ((u64) hi)<< 32; + event.timestamp |= lo; + ptp_clock_event(gianfar_clock,&event); + } + + if (val& ALM2) { + ack |= ALM2; + if (etsects->alarm_value) { + event.type = PTP_CLOCK_ALARM; + event.index = 0; + event.timestamp = etsects->alarm_value; + ptp_clock_event(gianfar_clock,&event); + } + if (etsects->alarm_interval) { + ns = etsects->alarm_value + etsects->alarm_interval; + hi = ns>> 32; + lo = ns& 0xffffffff; + spin_lock(®ister_lock); + gfar_write(&etsects->regs->tmr_alarm2_l, lo); + gfar_write(&etsects->regs->tmr_alarm2_h, hi); + spin_unlock(®ister_lock); + etsects->alarm_value = ns; + } else { + gfar_write(&etsects->regs->tmr_tevent, ALM2); + spin_lock(®ister_lock); + mask = gfar_read(&etsects->regs->tmr_temask); + mask&= ~ALM2EN;
arch/powerpc/boot/dts/p2020ds.dts
Quoted 10 lines
arch/powerpc/boot/dts/p2020ds.dts +10
-0+ gfar_write(&etsects->regs->tmr_temask, mask); + spin_unlock(®ister_lock); + etsects->alarm_value = 0; + etsects->alarm_interval = 0; + } + } + + gfar_write(&etsects->regs->tmr_tevent, ack); + + return IRQ_HANDLED;
Should only return IRQ_HANDLED if you found an event.
arch/powerpc/boot/dts/p2020ds.dts
Quoted 7 lines
arch/powerpc/boot/dts/p2020ds.dts +7
-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) || + get_of_u32(node, "tmr_fiper1",&etsects->tmr_fiper1) || + get_of_u32(node, "tmr_fiper2",&etsects->tmr_fiper2)) + return -ENODEV;
Might want to print an error so the user knows what's missing.
arch/powerpc/boot/dts/p2020ds.dts
Quoted 13 lines
arch/powerpc/boot/dts/p2020ds.dts +13
-0+ for (i = 0; i< N_IRQS; i++) { + + etsects->irq[i] = irq_of_parse_and_map(node, i); + + if (etsects->irq[i] == NO_IRQ) { + pr_err("irq[%d] not in device tree", i); + return -ENODEV; + } + + if (request_irq(etsects->irq[i], isr, 0, DRIVER, etsects)) { + pr_err("request_irq failed irq %d", etsects->irq[i]); + return -ENODEV; + }
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 would explain 3 interrupts on p2020).
arch/powerpc/boot/dts/p2020ds.dts
Quoted 4 lines
arch/powerpc/boot/dts/p2020ds.dts +4
-0+static struct of_device_id match_table[] = { + { .type = "ptp_clock" }, + {}, +};
This driver controls every possible PTP implementation?
-Scott
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 5 lines · Scott Wood
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 1 line · Richard Cochran
Documentation/powerpc/dts-bindings/fsl/tsec.txt +0
-0Get rid of both
device_typeand model, and specify a compatible string instead (e.g. "fsl,etsec-ptp").
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 Documentation/powerpc and what is already present in the kernel.
Quoted 4 lines
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?
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 certainly able to be used in this way.
Quoted 3 lines
If there are differences in ptp implementation between different versions of etsec, can the ptp driver see the etsec version register?
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 probably a documentation bug. I will check it.
Quoted 11 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 96
Quoted 7 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +7
-0+ - 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.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.
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 person working with docu in hand will have an easier job.
Quoted 1 line
They should probably have an "fsl,ptp-" prefix as well.
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) ||
get_of_u32(node, "tmr_fiper1",&etsects->tmr_fiper1) ||
get_of_u32(node, "tmr_fiper2",&etsects->tmr_fiper2))
return -ENODEV;Quoted 8 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 99
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +2
-0+ These properties set the operational parameters for the PTP + clock. You must choose these carefully for the clock to work right.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, the device tree probably isn't the right place for it.
The values are related to the board. One important parameter is the input clock, and the rest reflect some engineering decisions/tradeoffs related to the signals to and from the PTP clock. There is not just one "optimal" choice, so I wanted to let the designer set the values. In any case, the parameters are definitely related to the board (not to the cpu or to linux), so I think the device tree is the right place for them.
Quoted 1 line
This one has 3 interrupts? The driver supports only two.
The documentation does not specify the IRQ line that each event belongs to. After some trial and error, it appears that all of the ancillary clock interrupts arrive on the first interrupt. The other lines (one per port) must be for the Tx/Rx packet time stamp indication, but we don't need these for the clock or for the MAC.
I'll just reduce the driver to one interrupt.
Quoted 8 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +2
-0+/* Private globals */ +static struct ptp_clock *gianfar_clock;Do you not support more than one of these?
Quoted 1 line
+static struct etsects
the_clock;"The" clock? As oppsed to the "other" clock one line above? :-)
The 'gianfar_clock' variable holds the returned instance from the class driver, while 'the_clock' is the driver's private data (and there can only be one driver).
I'll combine these into one struct to make it more clear and less funny sounding.
Quoted 3 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 1 line
Documentation/powerpc/dts-bindings/fsl/tsec.txt +1
-0+ return IRQ_HANDLED;Should only return
IRQ_HANDLEDif you found an event.
Okay.
Quoted 9 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 7 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +7
-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) || + get_of_u32(node, "tmr_fiper1",&etsects->tmr_fiper1) || + get_of_u32(node, "tmr_fiper2",&etsects->tmr_fiper2)) + return -ENODEV;Might want to print an error so the user knows what's missing.
Okay.
Quoted 3 lines
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 would explain 3 interrupts on p2020).
Will reduce to just one IRQ.
Quoted 6 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 4 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +4
-0+static struct of_device_id match_table[] = { + { .type = "ptp_clock" }, + {}, +};This driver controls every possible PTP implementation?
No, I only want to match with the eTSEC clock device. Given the compatible string above ("fsl,etsec-ptp"), what is the correct way to do this? (pointer to an existing driver to emulate would be enough)
Thanks for your help,
Richard
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 10 lines · Richard Cochran
Quoted 5 lines · Scott Wood
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 1 line · Richard Cochran
Documentation/powerpc/dts-bindings/fsl/tsec.txt +0
-0Get rid of both
device_typeand model, and specify a compatible string instead (e.g. "fsl,etsec-ptp").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
Documentation/powerpcand what is already present in the kernel.
There's some stuff in there that isn't how we'd do it now, but is slow to change for compatibility reasons.
Quoted 8 lines
Quoted 4 lines
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?
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.
OK. I'm not too familiar with PTP itself, was looking more at the device tree and similar structural bits.
Quoted 4 lines
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_CTRLbits, but this is probably a documentation bug. I will check it.
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 binding (ignore the legacy "fsl-i2c").
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 96
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +2
-0+ - tmr_fiper1 Fixed interval period pulse generator. + - tmr_fiper2 Fixed interval period pulse generator.
MPC8572 and P2020 have fiper3 as well.
Quoted 5 lines
Quoted 1 line
They should probably have an "fsl,ptp-" prefix as well.
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?
It is not stripped; you have to change the code as well.
Quoted 5 lines
Quoted 3 lines
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 would explain 3 interrupts on p2020).Will reduce to just one IRQ.
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 first interrupt seems sufficient.
Quoted 10 lines
Quoted 6 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt
Quoted 4 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +4
-0+static struct of_device_id match_table[] = { + { .type = "ptp_clock" }, + {}, +};This driver controls every possible PTP implementation?
No, I only want to match with the eTSEC clock device. Given the compatible string above ("fsl,etsec-ptp"), what is the correct way to do this? (pointer to an existing driver to emulate would be enough)
Put .compatible = "fsl,etsec-ptp" (or "fsl,mpc8313-etsec-ptp") where you have .type = "ptp_clock".
-Scott
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 5 lines · Scott Wood
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt Example: · line 96
Quoted 2 lines
Documentation/powerpc/dts-bindings/fsl/tsec.txt +2
-0+ - tmr_fiper1 Fixed interval period pulse generator. + - tmr_fiper2 Fixed interval period pulse generator.MPC8572 and P2020 have fiper3 as well.
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
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 10 lines · Richard Cochran
Quoted 5 lines · Scott Wood
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ - tmr_fiper1 Fixed interval period pulse generator. + - tmr_fiper2 Fixed interval period pulse generator.MPC8572 and P2020 have fiper3 as well.
I doubt they really have a third fiper.
First of all, this signal is not routed anywhere on the boards.
OK, but that's a separate issue from whether it exists on the chip and could be used on a different board.
Quoted 2 lines
Also, according to the documentation, it has no bit in the
TMR_CTRLor theTMR_TEMASKregisters.
It does seem inconsistent -- but could just be bad docs.
Quoted 9 lines
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_TEVENTto see when a pulse occurs seems pointless.Scott, you have connections, right? Can you clarify this for me?
I'll ask around.
-Scott
Re: [PATCH v3 3/3] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Richard CochranQuoted 5 lines · Richard Cochran
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 <[email protected]>
on my Freescale MPC8313 setup with ptpd and ptpv2d.
FYI: checkplatch.pl reports various errors for this patch series.
Wolfgang.