ptp: IEEE 1588 hardware clock support
Subsystems (12)
Richard Cochran
maintainerv11 cover ptp: IEEE 1588 hardware clock support
This just might be the last round of review of the PTP hardware clock patch series. These patches apply on top of the timers/core branch in the tip tree. Patches 1 and 4 have changed since the last version.
* Why all the CCs?
- One driver is for PowerPC, and adds device tree stuff.
- One driver is for the ARM Xscale IXP465.
* Patch ChangeLog
** v11
- added more padding to the structures in the user space ABI
- tweaked Kconfig to make dependencies more clear
- fixed locking on time stamp event queue
- added John Stultz's acks on patches 2 and 3.
- now the phyter driver handles multiple PHYs
Richard Cochran (4):
ptp: Added a brand new class driver for ptp clocks.
ptp: Added a clock that uses the eTSEC found on the MPC85xx.
ptp: Added a clock driver for the IXP46x.
ptp: Added a clock driver for the National Semiconductor PHYTER.
Documentation/ABI/testing/sysfs-ptp | 98 ++ .../devicetree/bindings/net/fsl-tsec-phy.txt | 57 ++ Documentation/ptp/ptp.txt | 89 ++ Documentation/ptp/testptp.c | 352 +++++++ Documentation/ptp/testptp.mk | 33 + arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.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/arm/ixp4xx_eth.c | 192 ++++- drivers/net/gianfar_ptp.c | 448 +++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++ drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 1012 ++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 267 +++++ drivers/ptp/Kconfig | 75 ++ drivers/ptp/Makefile | 7 + drivers/ptp/ptp_chardev.c | 156 +++ drivers/ptp/ptp_clock.c | 320 ++++++ drivers/ptp/ptp_ixp46x.c | 332 +++++++ drivers/ptp/ptp_private.h | 86 ++ drivers/ptp/ptp_sysfs.c | 230 +++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 84 ++ include/linux/ptp_clock_kernel.h | 139 +++ 29 files changed, 4227 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp create mode 100644 Documentation/ptp/ptp.txt create mode 100644 Documentation/ptp/testptp.c create mode 100644 Documentation/ptp/testptp.mk create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h create mode 100644 drivers/ptp/Kconfig create mode 100644 drivers/ptp/Makefile create mode 100644 drivers/ptp/ptp_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_ixp46x.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h
Richard Cochran
maintainerPATCH v11 1/4 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.
--- Documentation/ABI/testing/sysfs-ptp | 98 ++++++++++ Documentation/ptp/ptp.txt | 89 +++++++++ Documentation/ptp/testptp.c | 352 +++++++++++++++++++++++++++++++++++ Documentation/ptp/testptp.mk | 33 ++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ptp/Kconfig | 30 +++ drivers/ptp/Makefile | 6 + drivers/ptp/ptp_chardev.c | 156 ++++++++++++++++ drivers/ptp/ptp_clock.c | 320 +++++++++++++++++++++++++++++++ drivers/ptp/ptp_private.h | 86 +++++++++ drivers/ptp/ptp_sysfs.c | 230 +++++++++++++++++++++++ include/linux/Kbuild | 1 + include/linux/ptp_clock.h | 84 +++++++++ include/linux/ptp_clock_kernel.h | 139 ++++++++++++++ 15 files changed, 1627 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-ptp 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_chardev.c create mode 100644 drivers/ptp/ptp_clock.c create mode 100644 drivers/ptp/ptp_private.h create mode 100644 drivers/ptp/ptp_sysfs.c create mode 100644 include/linux/ptp_clock.h create mode 100644 include/linux/ptp_clock_kernel.h
Documentation/ABI/testing/sysfs-ptp new file +98 -0
@@ -0,0 +1,98 @@ +What: /sys/class/ptp/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains files and directories + providing a standardized interface to the ancillary + features of PTP hardware clocks. + +What: /sys/class/ptp/ptpN/ +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This directory contains the attributes of the Nth PTP + hardware clock registered into the PTP class driver + subsystem. + +What: /sys/class/ptp/ptpN/clock_name +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the name of the PTP hardware clock + as a human readable string. + +What: /sys/class/ptp/ptpN/max_adjustment +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the PTP hardware clock's maximum + frequency adjustment value (a positive integer) in + parts per billion. + +What: /sys/class/ptp/ptpN/n_alarms +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of periodic or one shot + alarms offer by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_external_timestamps +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of external timestamp + channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/n_periodic_outputs +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file contains the number of programmable periodic + output channels offered by the PTP hardware clock. + +What: /sys/class/ptp/ptpN/pps_avaiable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file indicates whether the PTP hardware clock + supports a Pulse Per Second to the host CPU. Reading + "1" means that the PPS is supported, while "0" means + not supported. + +What: /sys/class/ptp/ptpN/extts_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables external + timestamps. To enable external timestamps, write the + channel index followed by a "1" into the file. + To disable external timestamps, write the channel + index followed by a "0" into the file. + +What: /sys/class/ptp/ptpN/fifo +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This file provides timestamps on external events, in + the form of three integers: channel index, seconds, + and nanoseconds. + +What: /sys/class/ptp/ptpN/period +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables periodic + outputs. To enable a periodic output, write five + integers into the file: channel index, start time + seconds, start time nanoseconds, period seconds, and + period nanoseconds. To disable a periodic output, set + all the seconds and nanoseconds values to zero. + +What: /sys/class/ptp/ptpN/pps_enable +Date: September 2010 +Contact: Richard Cochran <[email protected]> +Description: + This write-only file enables or disables delivery of + PPS events to the Linux PPS subsystem. To enable PPS + events, write a "1" into the file. To disable events, + write a "0" into the file.
Documentation/ptp/ptp.txt new file +89 -0
89 lines not on this page · raw message
Documentation/ptp/testptp.c new file +352 -0
352 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
@@ -54,6 +54,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
@@ -76,6 +76,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 +30 -0
@@ -0,0 +1,30 @@ +# +# PTP clock support configuration +# + +menu "PTP clock support" + +comment "Enable Device Drivers -> PPS to see the PTP clock options." + depends on PPS=n + +config PTP_1588_CLOCK + tristate "PTP clock support" + depends on EXPERIMENTAL + depends on PPS + 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. + +endmenu
drivers/ptp/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# +# Makefile for PTP 1588 clock support. +# + +ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o +obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o
drivers/ptp/ptp_chardev.c new file +156 -0
156 lines not on this page · raw message
drivers/ptp/ptp_clock.c new file +320 -0
320 lines not on this page · raw message
drivers/ptp/ptp_private.h new file +86 -0
86 lines not on this page · raw message
drivers/ptp/ptp_sysfs.c new file +230 -0
230 lines not on this page · raw message
include/linux/Kbuild +1 -0
@@ -300,6 +300,7 @@ header-y += ppp-comp.h header-y += ppp_defs.h header-y += pps.h header-y += prctl.h +header-y += ptp_clock.h header-y += ptrace.h header-y += qnx4_fs.h header-y += qnxtypes.h
include/linux/ptp_clock.h new file +84 -0
84 lines not on this page · raw message
include/linux/ptp_clock_kernel.h new file +139 -0
139 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v11 2/4 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, one alarm, and the PPS callback.
--- .../devicetree/bindings/net/fsl-tsec-phy.txt | 57 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.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 | 448 ++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++++ drivers/ptp/Kconfig | 13 + 9 files changed, 688 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.h
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +57 -0
@@ -74,3 +74,60 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp" + - reg Offset and length of the register set for the device + - interrupts There should be at least two interrupts. Some devices + have 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. + - max-adj Maximum frequency adjustment in parts per billion. + + 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 + max_adj = 1000000000 * (FreqDivRatio - 1.0) - 1 + + 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 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <659999998>; + };
arch/powerpc/boot/dts/mpc8313erdb.dts +14 -0
@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <659999998>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
arch/powerpc/boot/dts/mpc8572ds.dts +14 -0
@@ -324,6 +324,20 @@ }; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2 71 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xAAAAAAAB>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x3B9AC9FB>; + max-adj = <499999999>; + }; + 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 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <249999999>; + }; + 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 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;
drivers/net/Makefile +1 -0
@@ -31,6 +31,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 +448 -0
448 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
@@ -27,4 +27,17 @@ config PTP_1588_CLOCK To compile this driver as a module, choose M here: the module will be called ptp. +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.7.0.4
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 25 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, one alarm, and the PPS callback.
--- .../devicetree/bindings/net/fsl-tsec-phy.txt | 57 +++ arch/powerpc/boot/dts/mpc8313erdb.dts | 14 + arch/powerpc/boot/dts/mpc8572ds.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 | 448 ++++++++++++++++++++ drivers/net/gianfar_ptp_reg.h | 113 +++++ drivers/ptp/Kconfig | 13 + 9 files changed, 688 insertions(+), 0 deletions(-) create mode 100644 drivers/net/gianfar_ptp.c create mode 100644 drivers/net/gianfar_ptp_reg.hDocumentation/devicetree/bindings/net/fsl-tsec-phy.txt +0
-0
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 82
Quoted 9 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +6
-0@@ -74,3 +74,60 @@ Example: interrupt-parent = <&mpic>; phy-handle = <&phy0> }; + +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp"
Should specify an *exact* part; ie: "fsl,mpc8313-etsec-ptp" instead of trying to define a generic catchall. The reason is that the same marketing name can end up getting applied to a wide range of parts.
Instead, choose one specific device to stand in as the 'common' implementation and get all parts with the same core to claim compatibility with it. ie: a p2020 might have:
compatible = "fsl,mpc2020-etsec-ptp", "fsl,mpc8313-etsec-ptp";
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 93
Quoted 11 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +11
-0+ - reg Offset and length of the register set for the device + - interrupts There should be at least two interrupts. Some devices + have 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".
I'd be hesitant about defining something that isn't actually implemented yet. You may find the binding to be insufficient at a later date.
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 96
Quoted 3 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +3
-0+ - tmr-fiper1 Fixed interval period pulse generator. + - tmr-fiper2 Fixed interval period pulse generator. + - max-adj Maximum frequency adjustment in parts per billion.
These are all custom properties (not part of any shared binding) so they should probably be prefixed with 'fsl,'.
Quoted 11 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +11
-0+ + 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
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 117
Quoted 10 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +10
-0+ PulseWidth = 1 / OutputClock microseconds + FiperFreq1 = desired frequency in Hz + FiperDiv1 = 1000000 * OutputClock / FiperFreq1 + tmr_fiper1 = tmr_prsc * tclk_period * FiperDiv1 - tclk_period + max_adj = 1000000000 * (FreqDivRatio - 1.0) - 1 + + 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.
Good documentation, thanks. Question though, how many of these values will the end user (or board builder) be likely to want to change. It is risky encoding the calculation results into the device tree when they aren't the actually parameters that will be manipulated, or at least very user-unfriendly.
Quoted 492 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +16
-0+ +Example: + + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <659999998>; + };arch/powerpc/boot/dts/mpc8313erdb.dts +14
-0@@ -208,6 +208,20 @@ sleep = <&pmc 0x00300000>; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <659999998>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;arch/powerpc/boot/dts/mpc8572ds.dts +14
-0@@ -324,6 +324,20 @@ }; }; + ptp_clock@24E00 { + compatible = "fsl,etsec-ptp"; + reg = <0x24E00 0xB0>; + interrupts = <68 2 69 2 70 2 71 2>; + interrupt-parent = < &mpic >; + tclk-period = <5>; + tmr-prsc = <200>; + tmr-add = <0xAAAAAAAB>; + cksel = <1>; + tmr-fiper1 = <0x3B9AC9FB>; + tmr-fiper2 = <0x3B9AC9FB>; + max-adj = <499999999>; + }; + 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 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <249999999>; + }; + 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 { + compatible = "fsl,etsec-ptp"; + 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>; + max-adj = <249999999>; + }; + enet0: ethernet@24000 { #address-cells = <1>; #size-cells = <1>;drivers/net/Makefile +1
-0@@ -31,6 +31,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.odrivers/net/gianfar_ptp.c new file +358
-0@@ -0,0 +1,448 @@ +/* +* PTP 1588 clock using the eTSEC +* +* 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. +*/ +#include <linux/device.h> +#include <linux/hrtimer.h> +#include <linux/init.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/timex.h> +#include <linux/io.h> + +#include <linux/ptp_clock_kernel.h> + +#include "gianfar_ptp_reg.h" +#include "gianfar.h" + +#define DRIVER "gianfar_ptp" +#define N_ALARM 1/* first alarm is used internally to reset fipers */ +#define N_EXT_TS 2 +#define REG_SIZE sizeof(struct gianfar_ptp_registers) + +struct etsects { +struct gianfar_ptp_registers *regs; +struct ptp_clock *clock; +struct ptp_clock_info caps; +int irq; +u64 alarm_interval;/* for periodic alarm */ +u64 alarm_value; +u32 tclk_period;/* nanoseconds */ +u32 tmr_prsc; +u32 tmr_add; +u32 cksel; +u32 tmr_fiper1; +u32 tmr_fiper2; +}; + +/* Private globals */ +static struct etsects the_clock; +DEFINE_SPINLOCK (register_lock); + +/* +* Register access functions +*/ + +static u64 tmr_cnt_read (struct etsects *etsects) +{ +u64 ns; +u32 lo, hi; + + lo =gfar_read (&etsects->regs->tmr_cnt_l); + hi =gfar_read (&etsects->regs->tmr_cnt_h); + ns = ((u64 ) hi) <<32 ; + ns |= lo; +return ns; +} + +static void tmr_cnt_write (struct etsects *etsects,u64 ns) +{ +u32 hi = ns >>32 ; +u32 lo = ns &0xffffffff ; + +gfar_write (&etsects->regs->tmr_cnt_l, lo); +gfar_write (&etsects->regs->tmr_cnt_h, hi); +} + +static void set_alarm (struct etsects *etsects) +{ +u64 ns; +u32 lo, hi; + + ns =tmr_cnt_read (etsects) +1500000000ULL ; + ns =div_u64 (ns,1000000000UL ) *1000000000ULL ; + ns -= etsects->tclk_period; + hi = ns >>32 ; + lo = ns &0xffffffff ; +gfar_write (&etsects->regs->tmr_alarm1_l, lo); +gfar_write (&etsects->regs->tmr_alarm1_h, hi); +} + +static void set_fipers (struct etsects *etsects) +{ +u32 tmr_ctrl =gfar_read (&etsects->regs->tmr_ctrl); + +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl & (~TE )); +gfar_write (&etsects->regs->tmr_prsc, etsects->tmr_prsc); +gfar_write (&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); +gfar_write (&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); +set_alarm (etsects); +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl|TE ); +} + +/* +* Interrupt service routine +*/ + +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 (etsects->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 (etsects->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 (etsects->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 ; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock (®ister_lock); + etsects->alarm_value =0 ; + etsects->alarm_interval =0 ; + } + } + +if (val &PP1 ) { + ack |=PP1 ; + event.type =PTP_CLOCK_PPS ; +ptp_clock_event (etsects->clock, &event); + } + +if (ack) { +gfar_write (&etsects->regs->tmr_tevent, ack); +return IRQ_HANDLED ; + }else +return IRQ_NONE ; +} + +/* +* PTP clock operations +*/ + +static int ptp_gianfar_adjfreq (struct ptp_clock_info *ptp,s32 ppb) +{ +u64 adj; +u32 diff, tmr_add; +int neg_adj =0 ; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +if (ppb <0 ) { + neg_adj =1 ; + ppb = -ppb; + } + tmr_add = etsects->tmr_add; + adj = tmr_add; + adj *= ppb; + diff =div_u64 (adj,1000000000ULL ); + + tmr_add = neg_adj ? tmr_add - diff : tmr_add + diff; + +gfar_write (&etsects->regs->tmr_add, tmr_add); + +return 0 ; +} + +static int ptp_gianfar_adjtime (struct ptp_clock_info *ptp,s64 delta) +{ +s64 now; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +spin_lock_irqsave (®ister_lock, flags); + + now =tmr_cnt_read (etsects); + now += delta; +tmr_cnt_write (etsects, now); + +spin_unlock_irqrestore (®ister_lock, flags); + +set_fipers (etsects); + +return 0 ; +} + +static int ptp_gianfar_gettime (struct ptp_clock_info *ptp,struct timespec *ts) +{ +u64 ns; +u32 remainder; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + +spin_lock_irqsave (®ister_lock, flags); + + ns =tmr_cnt_read (etsects); + +spin_unlock_irqrestore (®ister_lock, flags); + + ts->tv_sec =div_u64_rem (ns,1000000000 , &remainder); + ts->tv_nsec = remainder; +return 0 ; +} + +static int ptp_gianfar_settime (struct ptp_clock_info *ptp, +const struct timespec *ts) +{ +u64 ns; +unsigned long flags; + struct etsects *etsects = container_of(ptp, struct etsects, caps); + + ns = ts->tv_sec *1000000000ULL ; + ns += ts->tv_nsec; + +spin_lock_irqsave (®ister_lock, flags); + +tmr_cnt_write (etsects, ns); +set_fipers (etsects); + +spin_unlock_irqrestore (®ister_lock, flags); + +return 0 ; +} + +static int ptp_gianfar_enable (struct ptp_clock_info *ptp, +struct ptp_clock_request *rq,int on) +{ + struct etsects *etsects = container_of(ptp, struct etsects, caps); +unsigned long flags; +u32 bit, mask; + +switch (rq->type) { +case PTP_CLK_REQ_EXTTS : +switch (rq->extts.index) { +case 0 : + bit =ETS1EN ; +break ; +case 1 : + bit =ETS2EN ; +break ; +default : +return -EINVAL ; + } +spin_lock_irqsave (®ister_lock, flags); + mask =gfar_read (&etsects->regs->tmr_temask); +if (on) + mask |= bit; +else + mask &= ~bit; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock_irqrestore (®ister_lock, flags); +return 0 ; + +case PTP_CLK_REQ_PPS : +spin_lock_irqsave (®ister_lock, flags); + mask =gfar_read (&etsects->regs->tmr_temask); +if (on) + mask |=PP1EN ; +else + mask &= ~PP1EN ; +gfar_write (&etsects->regs->tmr_temask, mask); +spin_unlock_irqrestore (®ister_lock, flags); +return 0 ; + +default : +break ; + } + +return -EOPNOTSUPP ; +} + +static struct ptp_clock_info ptp_gianfar_caps = { + .owner =THIS_MODULE , + .name ="gianfar clock" , + .max_adj =512000 , + .n_alarm =N_ALARM , + .n_ext_ts =N_EXT_TS , + .n_per_out =0 , + .pps =1 , + .adjfreq = ptp_gianfar_adjfreq, + .adjtime = ptp_gianfar_adjtime, + .gettime = ptp_gianfar_gettime, + .settime = ptp_gianfar_settime, + .enable = ptp_gianfar_enable, +}; + +/* OF device tree */ + +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 ; +} + +static int gianfar_ptp_probe (struct platform_device *dev, +const struct of_device_id *match) +{ +struct device_node *node = dev->dev.of_node; +struct etsects *etsects = &the_clock; +struct timespec now; +u32 tmr_ctrl; + + etsects->caps = ptp_gianfar_caps; + + if (get_of_u32(node, "tclk-period", &etsects->tclk_period) || + get_of_u32(node, "tmr-prsc", &etsects->tmr_prsc) ||
drivers/net/gianfar_ptp.c line 368
Quoted 10 lines
drivers/net/gianfar_ptp.c new file +10
-0+ 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) || + get_of_u32(node, "max-adj", &etsects->caps.max_adj)) { +pr_err ("device tree node missing required elements\n" ); +return -ENODEV ; + } + + etsects->irq =irq_of_parse_and_map (node,0 );
Use platform_get_irq().
drivers/net/gianfar_ptp.c line 378
Quoted 10 lines
drivers/net/gianfar_ptp.c new file +10
-0+ +if (etsects->irq ==NO_IRQ ) { +pr_err ("irq not in device tree\n" ); +return -ENODEV ; + } +if (request_irq (etsects->irq, isr,0 ,DRIVER , etsects)) { +pr_err ("request_irq failed\n" ); +return -ENODEV ; + } + etsects->regs =of_iomap (node,0 );
Use platform_get_resource(), and don't forget to request the resources.
Quoted 32 lines
drivers/net/gianfar_ptp.c new file +32
-0+if (!etsects->regs) { +pr_err ("of_iomap ptp registers failed\n" ); +return -EINVAL ; + } +getnstimeofday (&now); +ptp_gianfar_settime (&etsects->caps, &now); + + tmr_ctrl = + (etsects->tclk_period &TCLK_PERIOD_MASK ) <<TCLK_PERIOD_SHIFT | + (etsects->cksel &CKSEL_MASK ) <<CKSEL_SHIFT ; + +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl); +gfar_write (&etsects->regs->tmr_add, etsects->tmr_add); +gfar_write (&etsects->regs->tmr_prsc, etsects->tmr_prsc); +gfar_write (&etsects->regs->tmr_fiper1, etsects->tmr_fiper1); +gfar_write (&etsects->regs->tmr_fiper2, etsects->tmr_fiper2); +set_alarm (etsects); +gfar_write (&etsects->regs->tmr_ctrl, tmr_ctrl|FS |RTPE |TE ); + + etsects->clock =ptp_clock_register (&etsects->caps); + +return IS_ERR (etsects->clock) ?PTR_ERR (etsects->clock) :0 ; +} + +static int gianfar_ptp_remove (struct platform_device *dev) +{ +gfar_write (&the_clock.regs->tmr_temask,0 ); +gfar_write (&the_clock.regs->tmr_ctrl,0 ); + +ptp_clock_unregister (the_clock.clock); +free_irq (the_clock.irq, &the_clock); +iounmap (the_clock.regs);
drivers/net/gianfar_ptp.c line 420
Quoted 10 lines
drivers/net/gianfar_ptp.c new file +10
-0+ +return 0 ; +} + +static struct of_device_id match_table[] = { + { .compatible ="fsl,etsec-ptp" }, + {}, +}; + +static struct of_platform_driver gianfar_ptp_driver = {
Use a platform_driver instead. of_platform_driver is deprecated and being removed.
drivers/net/gianfar_ptp_reg.h
Quoted 33 lines
drivers/net/gianfar_ptp.c new file +28
-0+ .driver = { + .name = "gianfar_ptp", + .of_match_table = match_table, + .owner = THIS_MODULE, + }, + .probe = gianfar_ptp_probe, + .remove = gianfar_ptp_remove, +}; + +/* module operations */ + +static int __init ptp_gianfar_init (void ) +{ +return of_register_platform_driver (&gianfar_ptp_driver); +} + +module_init (ptp_gianfar_init); + +static void __exit ptp_gianfar_exit(void) +{ +of_unregister_platform_driver (&gianfar_ptp_driver); +} + +module_exit (ptp_gianfar_exit); + +MODULE_AUTHOR ("Richard Cochran <richard.cochran-3mrvs1K0uXizZXS1Dc/[email protected]>" ); +MODULE_DESCRIPTION ("PTP clock using the eTSEC" ); +MODULE_LICENSE ("GPL" );drivers/net/gianfar_ptp_reg.h new file +0
-0
This data is only used by gianfar_ptp.c, so there is no need for a separate include file. Move the contents of gianfar_ptp_reg.h into gianfar_ptp.c
g.
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 12 lines · On Wed, 23 Feb 2011 09:50:58 -0700 Grant Likely…
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 82
Quoted 6 lines · Richard Cochran
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +6
-0+ +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp"Should specify an *exact* part; ie: "fsl,mpc8313-etsec-ptp" instead of trying to define a generic catchall. The reason is that the same marketing name can end up getting applied to a wide range of parts.
Quoted 5 lines
Instead, choose one specific device to stand in as the 'common' implementation and get all parts with the same core to claim compatibility with it. ie: a p2020 might have:
compatible = "fsl,mpc2020-etsec-ptp", "fsl,mpc8313-etsec-ptp";
eTSEC is versioned, that's more reliable than the chip name since chips have revisions (rev 2.1 of mpc8313 has eTSEC 1.6, not sure about previous revs of mpc8313). Logic blocks can be and have been uprevved between one revision of a chip to the next. I think "fsl,mpc8313rev2.1-etsec-ptp" would be taking things a bit too far (and there could be board-level bugs too...).
If you really need to know the exact SoC you're on, look in SVR (which will provide revision info as well). Isn't the device tree for things that can't be probed?
The eTSEC revision is probeable as well, but due the way PTP is described as a separate node, the driver doesn't have straightforward access to those registers.
Insisting on an explicit chip also encourages people to claim compatibility with that chip without ensuring that it really is fully compatible.
-Scott
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 28 lines · Scott Wood
Quoted 12 lines · On Wed, 23 Feb 2011 09:50:58 -0700 Grant Likely…
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 82
Quoted 6 lines · Richard Cochran
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +6
-0+ +* Gianfar PTP clock nodes + +General Properties: + + - compatible Should be "fsl,etsec-ptp"Should specify an *exact* part; ie: "fsl,mpc8313-etsec-ptp" instead of trying to define a generic catchall. The reason is that the same marketing name can end up getting applied to a wide range of parts.
Quoted 5 lines
Instead, choose one specific device to stand in as the 'common' implementation and get all parts with the same core to claim compatibility with it. ie: a p2020 might have:
compatible = "fsl,mpc2020-etsec-ptp", "fsl,mpc8313-etsec-ptp";eTSEC is versioned, that's more reliable than the chip name since chips have revisions (rev 2.1 of mpc8313 has eTSEC 1.6, not sure about previous revs of mpc8313). Logic blocks can be and have been uprevved between one revision of a chip to the next. I think "fsl,mpc8313rev2.1-etsec-ptp" would be taking things a bit too far (and there could be board-level bugs too...).
Quoted 3 lines
If you really need to know the exact SoC you're on, look in SVR (which will provide revision info as well). Isn't the device tree for things that can't be probed?
This is far more about the binding than it is about the chip revision. When documenting a binding it makes far more sense to anchor it to a specific implementation than to try and come up with a 'generic' catchall. A new binding means new compatible value and dropping any claims of being compatible with the old.
It is not about the logic block version, particularly when it is detectable by the driver as you say.
Quoted 4 lines
The eTSEC revision is probeable as well, but due the way PTP is described as a separate node, the driver doesn't have straightforward access to those registers.
Ignorant question: Should the ptp be described as a separate node?
Quoted 3 lines
Insisting on an explicit chip also encourages people to claim compatibility with that chip without ensuring that it really is fully compatible.
In practise, I've not seen this to be an issue.
g.
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 8 lines · On Wed, 23 Feb 2011 10:54:59 -0700 Grant Likely…
Quoted 7 lines · Scott Wood
eTSEC is versioned, that's more reliable than the chip name since chips have revisions (rev 2.1 of mpc8313 has eTSEC 1.6, not sure about previous revs of mpc8313). Logic blocks can be and have been uprevved between one revision of a chip to the next. I think "fsl,mpc8313rev2.1-etsec-ptp" would be taking things a bit too far (and there could be board-level bugs too...).
Quoted 8 lines
Quoted 3 lines
If you really need to know the exact SoC you're on, look in SVR (which will provide revision info as well). Isn't the device tree for things that can't be probed?
This is far more about the binding than it is about the chip revision. When documenting a binding it makes far more sense to anchor it to a specific implementation than to try and come up with a 'generic' catchall.
Whatever string is used should be written into a binding document.
fsl,etsec-v1.6-ptp seems like it would be just as good for that purpose.
Even just fsl,etsec-ptp will identify the binding, though it's lacking in identifying the hardware (in the absence of access to the eTSEC ID registers).
If somehow Freescale makes something completely different in the future called "etsec-ptp", then we'll just have to pick a different name for *that* compatible (after we smack whoever was responsible for reusing the name). The point of the vendor namespacing is to constrain this problem to a manageable scope.
Quoted 5 lines
Quoted 3 lines
The eTSEC revision is probeable as well, but due the way PTP is described as a separate node, the driver doesn't have straightforward access to those registers.
Ignorant question: Should the ptp be described as a separate node?
Probably not.
Quoted 4 lines
Quoted 2 lines
Insisting on an explicit chip also encourages people to claim compatibility with that chip without ensuring that it really is fully compatible.
In practise, I've not seen this to be an issue.
I see it often enough in our BSPs (though the BSP device trees tend to be problematic in a variety of ways), especially on things like guts and pmc.
It's a question of how strong a statement people are asked to make -- in a place where fixing errors is somewhat painful, and we don't really need that strong statement of compatibility to be made, as long as there's another way to fully identify the hardware (e.g. SVR, top-level board compatible) if some strange workaround needs to be made[1].
To turn things around, in practice, I've not seen compatibles that don't encode a specific chip name to be a problem, as long as it's well documented what it means.
-Scott
[1] IIRC, this was the original reason for citing a specific chip, but it doesn't hold up if that chip gets cited by other chips as compatible. If compatibliity includes having all the same bugs, then very little will be able to claim compatibility, and we'll be back to long lists of device IDs in the driver. Not to mention errata that are discovered after a device tree claiming compatibility is released...
Richard Cochran
maintainerRe: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 7 lines · Scott Wood
Whatever string is used should be written into a binding document.
fsl,etsec-v1.6-ptp seems like it would be just as good for that purpose.
Even just fsl,etsec-ptp will identify the binding, though it's lacking in identifying the hardware (in the absence of access to the eTSEC ID registers).
I read the conversation, and I don't mind admitting that I do not understand what you both are arguing/discussing about.
How should I set the strings? Like this?
arch/powerpc/boot/dts/mpc8313erdb.dts:
ptp_clock@24E00 {
compatible = "fsl,mpc8313-etsec-ptp";
}
arch/powerpc/boot/dts/mpc8572ds.dts:
ptp_clock@24E00 {
compatible = "fsl,mpc8572-etsec-ptp";
}
arch/powerpc/boot/dts/p2020ds.dts:
ptp_clock@24E00 {
compatible = "fsl,p2020ds-etsec-ptp";
}
arch/powerpc/boot/dts/p2020rdb.dts:
ptp_clock@24E00 {
compatible = "fsl,p2020rdb-etsec-ptp";
} drivers/net/gianfar_ptp.c:
static struct of_device_id match_table[] = {
{ .compatible = "fsl,mpc8313-etsec-ptp" },
{ .compatible = "fsl,mpc8572-etsec-ptp" },
{ .compatible = "fsl,p2020ds-etsec-ptp" },
{ .compatible = "fsl,p2020rdb-etsec-ptp" },
{},
};Please let me know if this is what you meant.
Thanks,
Richard
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 33 lines · On Thu, 24 Feb 2011 17:50:04 +0100 Richard Cochran <[email protected]>…
Quoted 7 lines · Scott Wood
Whatever string is used should be written into a binding document.
fsl,etsec-v1.6-ptp seems like it would be just as good for that purpose.
Even just fsl,etsec-ptp will identify the binding, though it's lacking in identifying the hardware (in the absence of access to the eTSEC ID registers).
I read the conversation, and I don't mind admitting that I do not understand what you both are arguing/discussing about.
How should I set the strings? Like this?
arch/powerpc/boot/dts/mpc8313erdb.dts:ptp_clock@24E00 { compatible = "fsl,mpc8313-etsec-ptp"; } arch/powerpc/boot/dts/mpc8572ds.dts: ptp_clock@24E00 { compatible = "fsl,mpc8572-etsec-ptp"; } arch/powerpc/boot/dts/p2020ds.dts: ptp_clock@24E00 { compatible = "fsl,p2020ds-etsec-ptp"; } arch/powerpc/boot/dts/p2020rdb.dts: ptp_clock@24E00 { compatible = "fsl,p2020rdb-etsec-ptp"; }
drivers/net/gianfar_ptp.c:
Quoted 7 lines
static struct of_device_id match_table[] = {
{ .compatible = "fsl,mpc8313-etsec-ptp" },
{ .compatible = "fsl,mpc8572-etsec-ptp" },
{ .compatible = "fsl,p2020ds-etsec-ptp" },
{ .compatible = "fsl,p2020rdb-etsec-ptp" },
{},
};Those last two are boards, not chips. I don't think even Grant is asking to take things that far.
My vote, if it goes in a separate node at all, is "fsl,etsec-ptp", and let the driver use SVR. Even encoding an etsec version in the compatible string would be difficult, unless fixed up by u-boot, as it appears to differ based on chip revision (and the chip manuals seem to often not match the hardware regarding the advertised eTSEC revision) and we don't normally have separate dts files for different revisions of the same chip. Plus, our docs (at least the public ones) don't seem to be very helpful in determining what version of eTSEC implies what.
If you want to use chip-based compatibles instead, then use the actual name of the chip. You'll need to verify 100% compatibility if you want to claim compatibility with another chip; it's probably easier/safer to just list every single Freescale chip that has this type of PTP in a huge compatible table, like PCI drivers do.
-Scott
Richard Cochran
maintainerRe: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 1 line · Scott Wood
My vote, if it goes in a separate node at all, is "fsl,etsec-ptp",
So, that is what the patch does.
Quoted 1 line
and let the driver use SVR.
What is SVR?
Thanks,
Richard
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 9 lines · Richard Cochran
Quoted 1 line · Scott Wood
My vote, if it goes in a separate node at all, is "fsl,etsec-ptp",
So, that is what the patch does.
Quoted 1 line
and let the driver use SVR.
What is SVR?
An on chip register that provides the exact version of the SoC. (As opposed to PVR which is the version of the cpu core).
g.
Richard Cochran
maintainerRe: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Grant LikelyQuoted 7 lines · Grant Likely
Quoted 3 lines · Scott Wood
The eTSEC revision is probeable as well, but due the way PTP is described as a separate node, the driver doesn't have straightforward access to those registers.
Ignorant question: Should the ptp be described as a separate node?
Well, the PTP Hardware Clock function is logically separate from the MAC function. PHCs can be implemented in the MAC, in the PHY, or in between in an FPGA on MII bus.
If the PHC is in the MAC, then it might be wise to implement one driver that offers both the MAC and the PHC.
In the case of gianfar, it is not really necessary to combine the PHC into the gianfar driver, since the registers are pretty well separated. Also, given the size and complexity (and churn over time) of the gianfar driver, I decided to keep the PHC separate.
Right now, the driver correctly handles all the clock revisions in the boards that I have (mpc8313, mpc8572, p2020ds, p2020rdb).
If checking the revision becomes important, then we can always export a function from gianfar to provide this.
Thanks,
Richard
Re: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
Quoted 11 lines · On Thu, 24 Feb 2011 17:39:44 +0100 Richard Cochran <[email protected]>…
Quoted 7 lines · Grant Likely
Quoted 3 lines · Scott Wood
The eTSEC revision is probeable as well, but due the way PTP is described as a separate node, the driver doesn't have straightforward access to those registers.
Ignorant question: Should the ptp be described as a separate node?
Well, the PTP Hardware Clock function is logically separate from the MAC function.
The eTSEC node doesn't describe the MAC function, it describes the whole device (or at least it should... we make an exception for MDIO, which should probably have been a subnode instead).
Quoted 9 lines
PHCs can be implemented in the MAC, in the PHY, or in between in an FPGA on MII bus.
If the PHC is in the MAC, then it might be wise to implement one driver that offers both the MAC and the PHC.
In the case of gianfar, it is not really necessary to combine the PHC into the gianfar driver, since the registers are pretty well separated.
How the drivers are structured in Linux is a separate concern from how the devices are described in the device tree. The tree is supposed to be an OS-independent representation of hardware.
If Linux has multiple drivers that correspond to portions of one node, a toplevel driver can register platform devices for the components, adding in any additional information like versioning that it gets from the toplevel registers.
-Scott
Richard Cochran
maintainerRe: [PATCH V11 2/4] ptp: Added a clock that uses the eTSEC found on the MPC85xx.
In reply to Grant LikelyQuoted 12 lines · Grant Likely
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 93
Quoted 7 lines · Richard Cochran
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +7
-0+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".I'd be hesitant about defining something that isn't actually implemented yet. You may find the binding to be insufficient at a later date.
Okay, I'll remove it.
We never got the external VCO working anyhow.
Quoted 6 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 96
Quoted 3 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +3
-0+ - tmr-fiper1 Fixed interval period pulse generator. + - tmr-fiper2 Fixed interval period pulse generator. + - max-adj Maximum frequency adjustment in parts per billion.These are all custom properties (not part of any shared binding) so they should probably be prefixed with 'fsl,'.
Okay, fine.
Quoted 10 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt Example: · line 117
Quoted 4 lines
Documentation/devicetree/bindings/net/fsl-tsec-phy.txt +4
-0+ 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.Good documentation, thanks. Question though, how many of these values will the end user (or board builder) be likely to want to change. It is risky encoding the calculation results into the device tree when they aren't the actually parameters that will be manipulated, or at least very user-unfriendly.
The whole thing is pretty opaque, and my explanation is (IMHO) way better that Freescale's documentation of how the fipers work.
The board designer / system designer will want to set these carefully, but never change them. Basically, for a given input clock, there is only one optimal setting.
I think the device tree is the right place for that kind of setting.
The fiper1 signal should always be a 1 PPS. We could make fiper2 run time programmable via PHC ioctls, but I think this can wait.
Quoted 3 lines
drivers/net/gianfar_ptp.c line 368
Quoted 1 line
drivers/net/gianfar_ptp.c new file +1
-0+ etsects->irq =irq_of_parse_and_map (node,0 );Use
platform_get_irq().
Okay.
Quoted 4 lines
drivers/net/gianfar_ptp.c line 378
Quoted 1 line
drivers/net/gianfar_ptp.c new file +1
-0+ etsects->regs =of_iomap (node,0 );Use
platform_get_resource(), and don't forget to request the resources.
Okay, but didn't you tell me before to do this way?
http://marc.info/?l=linux-netdev&m=127662247203659&w=4
Quoted 4 lines
Quoted 1 line
+static struct
of_platform_drivergianfar_ptp_driver= {Use a
platform_driverinstead.of_platform_driveris deprecated and being removed.
Ja, should have noticed that myself, sorry.
Quoted 5 lines
Quoted 1 line
+++
b/drivers/net/gianfar_ptp_reg.hThis data is only used by
gianfar_ptp.c, so there is no need for a separate include file. Move the contents ofgianfar_ptp_reg.hintogianfar_ptp.c
You are right, of course, since private #defines and declarations should simply stay in their .c files. Some people think that all #defines and declarations must go into a header file.
I am not one of those people, but in this case, I generated the file from a little tool I wrote and so kept it separate.
Still, it is no trouble to combine the header into the driver .c file.
Thanks for your review,
Richard
Richard Cochran
maintainerPATCH v11 3/4 ptp: Added a clock driver for the IXP46x.
In reply to Richard CochranThis patch adds a driver for the hardware time stamping unit found on the IXP465. The basic clock operations and an external trigger are implemented.
--- arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h | 78 ++++++ drivers/net/arm/ixp4xx_eth.c | 192 ++++++++++++++- drivers/ptp/Kconfig | 13 + drivers/ptp/Makefile | 1 + drivers/ptp/ptp_ixp46x.c | 332 +++++++++++++++++++++++++ 5 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h create mode 100644 drivers/ptp/ptp_ixp46x.c
arch/arm/mach-ixp4xx/include/mach/ixp46x_ts.h new file +78 -0
@@ -0,0 +1,78 @@ +/* +* PTP 1588 clock using the IXP46X +* +* 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. +*/ + +#ifndef _IXP46X_TS_H_ +#define _IXP46X_TS_H_ + +#define DEFAULT_ADDEND 0xF0000029 +#define TICKS_NS_SHIFT 4 + +struct ixp46x_channel_ctl { +u32 ch_control;/* 0x40 Time Synchronization Channel Control */ +u32 ch_event;/* 0x44 Time Synchronization Channel Event */ +u32 tx_snap_lo;/* 0x48 Transmit Snapshot Low Register */ +u32 tx_snap_hi;/* 0x4C Transmit Snapshot High Register */ +u32 rx_snap_lo;/* 0x50 Receive Snapshot Low Register */ +u32 rx_snap_hi;/* 0x54 Receive Snapshot High Register */ +u32 src_uuid_lo;/* 0x58 Source UUID0 Low Register */ +u32 src_uuid_hi;/* 0x5C Sequence Identifier/Source UUID0 High */ +}; + +struct ixp46x_ts_regs { +u32 control;/* 0x00 Time Sync Control Register */ +u32 event;/* 0x04 Time Sync Event Register */ +u32 addend;/* 0x08 Time Sync Addend Register */ +u32 accum;/* 0x0C Time Sync Accumulator Register */ +u32 test;/* 0x10 Time Sync Test Register */ +u32 unused;/* 0x14 */ +u32 rsystime_lo;/* 0x18 RawSystemTime_Low Register */ +u32 rsystime_hi;/* 0x1C RawSystemTime_High Register */ +u32 systime_lo;/* 0x20 SystemTime_Low Register */ +u32 systime_hi;/* 0x24 SystemTime_High Register */ +u32 trgt_lo;/* 0x28 TargetTime_Low Register */ +u32 trgt_hi;/* 0x2C TargetTime_High Register */ +u32 asms_lo;/* 0x30 Auxiliary Slave Mode Snapshot Low */ +u32 asms_hi;/* 0x34 Auxiliary Slave Mode Snapshot High */ +u32 amms_lo;/* 0x38 Auxiliary Master Mode Snapshot Low */ +u32 amms_hi;/* 0x3C Auxiliary Master Mode Snapshot High */ + +struct ixp46x_channel_ctl channel[3 ]; +}; + +/* 0x00 Time Sync Control Register Bits */ +#define TSCR_AMM (1<<3) +#define TSCR_ASM (1<<2) +#define TSCR_TTM (1<<1) +#define TSCR_RST (1<<0) + +/* 0x04 Time Sync Event Register Bits */ +#define TSER_SNM (1<<3) +#define TSER_SNS (1<<2) +#define TTIPEND (1<<1) + +/* 0x40 Time Synchronization Channel Control Register Bits */ +#define MASTER_MODE (1<<0) +#define TIMESTAMP_ALL (1<<1) + +/* 0x44 Time Synchronization Channel Event Register Bits */ +#define TX_SNAPSHOT_LOCKED (1<<0) +#define RX_SNAPSHOT_LOCKED (1<<1) + +#endif
drivers/net/arm/ixp4xx_eth.c +189 -3
254 lines not on this page · raw message
drivers/ptp/Kconfig +13 -0
@@ -40,4 +40,17 @@ config PTP_1588_CLOCK_GIANFAR To compile this driver as a module, choose M here: the module will be called gianfar_ptp. +config PTP_1588_CLOCK_IXP46X + tristate "Intel IXP46x as PTP clock" + depends on PTP_1588_CLOCK + depends on IXP4XX_ETH + help + This driver adds support for using the IXP46X 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 ptp_ixp46x. + endmenu
drivers/ptp/Makefile +1 -0
@@ -4,3 +4,4 @@ ptp-y := ptp_clock.o ptp_chardev.o ptp_sysfs.o obj-$(CONFIG_PTP_1588_CLOCK) += ptp.o +obj-$(CONFIG_PTP_1588_CLOCK_IXP46X) += ptp_ixp46x.o
drivers/ptp/ptp_ixp46x.c new file +332 -0
332 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v11 4/4 ptp: Added a clock driver for the National Semiconductor PHYTER.
In reply to Richard CochranThis patch adds support for the PTP clock found on the DP83640. The basic clock operations and one external time stamp have been implemented.
--- drivers/net/phy/Makefile | 1 + drivers/net/phy/dp83640.c | 1012 +++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/dp83640_reg.h | 267 +++++++++++ drivers/ptp/Kconfig | 19 + 4 files changed, 1299 insertions(+), 0 deletions(-) create mode 100644 drivers/net/phy/dp83640.c create mode 100644 drivers/net/phy/dp83640_reg.h
drivers/net/phy/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_FIXED_PHY) += fixed.o obj-$(CONFIG_MDIO_BITBANG) += mdio-bitbang.o obj-$(CONFIG_MDIO_GPIO) += mdio-gpio.o obj-$(CONFIG_NATIONAL_PHY) += national.o +obj-$(CONFIG_DP83640_PHY) += dp83640.o obj-$(CONFIG_STE10XP) += ste10Xp.o obj-$(CONFIG_MICREL_PHY) += micrel.o obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
drivers/net/phy/dp83640.c new file +1012 -0
1,012 lines not on this page · raw message
drivers/net/phy/dp83640_reg.h new file +267 -0
267 lines not on this page · raw message
drivers/ptp/Kconfig +19 -0
@@ -53,4 +53,23 @@ config PTP_1588_CLOCK_IXP46X To compile this driver as a module, choose M here: the module will be called ptp_ixp46x. +comment "Enable PHYLIB and NETWORK_PHY_TIMESTAMPING to see the additional clocks." + depends on PTP_1588_CLOCK && (PHYLIB=n || NETWORK_PHY_TIMESTAMPING=n) + +config DP83640_PHY + tristate "Driver for the National Semiconductor DP83640 PHYTER" + depends on PTP_1588_CLOCK + depends on NETWORK_PHY_TIMESTAMPING + depends on PHYLIB + ---help--- + Supports the DP83640 PHYTER with IEEE 1588 features. + + This driver adds support for using the DP83640 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. + + In order for this to work, your MAC driver must also + implement the skb_tx_timetamp() function. + endmenu
Signature · 1 line
1.7.0.4
Richard Cochran
maintainer* Previous Discussions
This patch set previously appeared on the netdev list. Since V5 of the character device patch set, the discussion has moved to the lkml.
- IEEE 1588 hardware clock support [V5]
http://lkml.org/lkml/2010/8/16/90
- POSIX clock tuning syscall with static clock ids
http://lkml.org/lkml/2010/8/23/49
- POSIX clock tuning syscall with dynamic clock ids
http://lkml.org/lkml/2010/9/3/119
- IEEE 1588 hardware clock support [V6]
http://lkml.org/lkml/2010/9/23/310
- Dynamic clock devices [RFC]
http://lkml.org/lkml/2010/11/4/290
- IEEE 1588 hardware clock support [V7]
http://lkml.org/lkml/2010/12/16/195
- IEEE 1588 hardware clock support [V8]
http://lkml.org/lkml/2010/12/31/128
- IEEE 1588 hardware clock support [V9]
http://lkml.org/lkml/2011/1/13/65
- IEEE 1588 hardware clock support [V10]
http://lkml.org/lkml/2011/1/27/71
- Thomas Gleixner: Rework of the PTP support series core code
http://lkml.org/lkml/2011/2/1/137