Skip to contentSkip to conversation

arm64: dts: fsl: add clocks property for fman ptp timer node

PATCH Superseded Yangbo Lu 3 participants 9 messages Jul 30, 2018 – Aug 1, 2018

Subsystems (8)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yangbo Lu

author maintainer
#0 lore raw

PATCH 1/3 arm64: dts: fsl: add clocks property for fman ptp timer node

This patch is to add clocks property for fman ptp timer node.

---
 arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi +1 -0
index a56a408..4664c33 100644
@@ -80,4 +80,5 @@ ptp_timer0: ptp-timer at 1afe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x0 0x1afe000 0x0 0x1000>;
 	interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>;
+	clocks = <&clockgen 3 0>;
 };
Signature · 1 line
1.7.1
author maintainer
#1 lore raw

PATCH 2/3 powerpc/mpc85xx: add clocks property for fman ptp timer node

This patch is to add clocks property for fman ptp timer node.

---
 arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi   |    1 +
 arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi   |    1 +
 arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi  |    1 +
 arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi  |    1 +
 arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi |    1 +
 5 files changed, 5 insertions(+), 0 deletions(-)
arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi +1 -0
index 6b124f7..9b6cf91 100644
@@ -100,4 +100,5 @@ ptp_timer0: ptp-timer at 4fe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x4fe000 0x1000>;
 	interrupts = <96 2 0 0>;
+	clocks = <&clockgen 3 0>;
 };
arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi +1 -0
index b80aaf5..e95c11f 100644
@@ -100,4 +100,5 @@ ptp_timer1: ptp-timer at 5fe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x5fe000 0x1000>;
 	interrupts = <97 2 0 0>;
+	clocks = <&clockgen 3 1>;
 };
arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi +1 -0
index d3720fd..d62b36c 100644
@@ -105,4 +105,5 @@ ptp_timer0: ptp-timer at 4fe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x4fe000 0x1000>;
 	interrupts = <96 2 0 0>;
+	clocks = <&clockgen 3 0>;
 };
arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi +1 -0
index ae34c20..3102324 100644
@@ -105,4 +105,5 @@ ptp_timer1: ptp-timer at 5fe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x5fe000 0x1000>;
 	interrupts = <97 2 0 0>;
+	clocks = <&clockgen 3 1>;
 };
arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi +1 -0
index 02f2755..c90702b 100644
@@ -93,4 +93,5 @@ ptp_timer0: ptp-timer at 4fe000 {
 	compatible = "fsl,fman-ptp-timer";
 	reg = <0x4fe000 0x1000>;
 	interrupts = <96 2 0 0>;
+	clocks = <&clockgen 3 0>;
 };
Signature · 1 line
1.7.1
author maintainer
#2 lore raw

PATCH 3/3 ptp_qoriq: convert to use module parameters for initialization

In reply to Yangbo Lu

The ptp_qoriq driver initialized the 1588 timer with the configurations provided by the properties of device tree node. For example,

  fsl,tclk-period = <5>;
  fsl,tmr-prsc    = <2>;
  fsl,tmr-add     = <0xaaaaaaab>;
  fsl,tmr-fiper1  = <999999995>;
  fsl,tmr-fiper2  = <99990>;
  fsl,max-adj     = <499999999>;

These things actually were runtime configurations which were not proper to be put into dts. This patch is to convert to use module parameters for 1588 timer initialization, and to support initial register values calculation.
If the parameters are not provided, the driver will calculate register values with a set of default parameters. With this patch, those dts properties are no longer needed for new platform to support 1588 timer, and many QorIQ DPAA platforms (some P series and T series platforms of PowerPC, and some LS series platforms of ARM64) could use this driver for their fman ptp timer with default module parameters. However, this patch didn't remove the dts method. Because there were still many old platforms using the dts method. We need to clean up their dts files, verify module parameters on them, and convert them to the new method gradually in case of breaking any function.

---
 drivers/ptp/ptp_qoriq.c       |  117 +++++++++++++++++++++++++++++++++++++++-
 include/linux/fsl/ptp_qoriq.h |    1 +
 2 files changed, 115 insertions(+), 3 deletions(-)
drivers/ptp/ptp_qoriq.c +114 -3
index a14c317..22baf83 100644
@@ -29,9 +29,30 @@
 #include <linux/of_platform.h>
 #include <linux/timex.h>
 #include <linux/slab.h>
+#include <linux/clk.h>
 
 #include <linux/fsl/ptp_qoriq.h>
 
+static unsigned int cksel = DEFAULT_CKSEL;
+module_param(cksel, uint, 0644);
+MODULE_PARM_DESC(cksel, "Select reference clock");
+
+static unsigned int clk_src;
+module_param(clk_src, uint, 0644);
+MODULE_PARM_DESC(clk_src, "Reference clock frequency (if clocks property not provided in dts)");
+
+static unsigned int tmr_prsc = 2;
+module_param(tmr_prsc, uint, 0644);
+MODULE_PARM_DESC(tmr_prsc, "Output clock division/prescale factor");
+
+static unsigned int tmr_fiper1 = 1000000000;
+module_param(tmr_fiper1, uint, 0644);
+MODULE_PARM_DESC(tmr_fiper1, "Desired fixed interval pulse period (ns)");
+
+static unsigned int tmr_fiper2 = 100000;
+module_param(tmr_fiper2, uint, 0644);
+MODULE_PARM_DESC(tmr_fiper2, "Desired fixed interval pulse period (ns)");
+
 /*
  * Register access functions
  */
@@ -317,6 +338,91 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp,
 	.enable		= ptp_qoriq_enable,
 };
 
+/**
+ * qoriq_ptp_nominal_freq - calculate nominal frequency by reference clock
+ *			    frequency
+ *
+ * @clk_src: reference clock frequency
+ *
+ * The nominal frequency is the desired clock frequency.
+ * It should be less than the reference clock frequency.
+ * It should be a factor of 1000MHz.
+ *
+ * Return the nominal frequency
+ */
+static u32 qoriq_ptp_nominal_freq(u32 clk_src)
+{
+	u32 remainder = 0;
+
+	clk_src /= 1000000;
+	remainder = clk_src % 100;
+	if (remainder) {
+		clk_src -= remainder;
+		clk_src += 100;
+	}
+
+	do {
+		clk_src -= 100;
+
+	} while (1000 % clk_src);
+
+	return clk_src * 1000000;
+}
+
+static int qoriq_ptp_config(struct qoriq_ptp *qoriq_ptp,
+			    struct device_node *node)
+{
+	struct clk *clk;
+	u64 freq_comp;
+	u64 max_adj;
+	u32 nominal_freq;
+
+	qoriq_ptp->cksel = cksel;
+
+	if (clk_src) {
+		qoriq_ptp->clk_src = clk_src;
+	} else {
+		clk = of_clk_get(node, 0);
+		if (!IS_ERR(clk)) {
+			qoriq_ptp->clk_src = clk_get_rate(clk);
+			clk_put(clk);
+		}
+	}
+
+	if (qoriq_ptp->clk_src <= 100000000UL) {
+		pr_err("error reference clock value, or lower than 100MHz\n");
+		return -EINVAL;
+	}
+
+	nominal_freq = qoriq_ptp_nominal_freq(qoriq_ptp->clk_src);
+	if (!nominal_freq)
+		return -EINVAL;
+
+	qoriq_ptp->tclk_period = 1000000000UL / nominal_freq;
+	qoriq_ptp->tmr_prsc = tmr_prsc;
+
+	/* Calculate initial frequency compensation value for TMR_ADD register.
+	 * freq_comp = ceil(2^32 / freq_ratio)
+	 * freq_ratio = reference_clock_freq / nominal_freq
+	 */
+	freq_comp = ((u64)1 << 32) * nominal_freq;
+	if (do_div(freq_comp, qoriq_ptp->clk_src))
+		freq_comp++;
+
+	qoriq_ptp->tmr_add = freq_comp;
+	qoriq_ptp->tmr_fiper1 = tmr_fiper1 - qoriq_ptp->tclk_period;
+	qoriq_ptp->tmr_fiper2 = tmr_fiper2 - qoriq_ptp->tclk_period;
+
+	/* max_adj = 1000000000 * (freq_ratio - 1.0) - 1
+	 * freq_ratio = reference_clock_freq / nominal_freq
+	 */
+	max_adj = 1000000000ULL * (qoriq_ptp->clk_src - nominal_freq);
+	max_adj = max_adj / nominal_freq - 1;
+	qoriq_ptp->caps.max_adj = max_adj;
+
+	return 0;
+}
+
 static int qoriq_ptp_probe(struct platform_device *dev)
 {
 	struct device_node *node = dev->dev.of_node;
@@ -332,7 +438,7 @@ static int qoriq_ptp_probe(struct platform_device *dev)
 	if (!qoriq_ptp)
 		goto no_memory;
 
-	err = -ENODEV;
+	err = -EINVAL;
 
 	qoriq_ptp->caps = ptp_qoriq_caps;
 
@@ -351,10 +457,14 @@ static int qoriq_ptp_probe(struct platform_device *dev)
 				 "fsl,tmr-fiper2", &qoriq_ptp->tmr_fiper2) ||
 	    of_property_read_u32(node,
 				 "fsl,max-adj", &qoriq_ptp->caps.max_adj)) {
-		pr_err("device tree node missing required elements\n");
-		goto no_node;
+		pr_warn("device tree node missing required elements, try module param\n");
+
+		if (qoriq_ptp_config(qoriq_ptp, node))
+			goto no_param;
 	}
 
+	err = -ENODEV;
+
 	qoriq_ptp->irq = platform_get_irq(dev, 0);
 
 	if (qoriq_ptp->irq < 0) {
@@ -436,6 +546,7 @@ static int qoriq_ptp_probe(struct platform_device *dev)
 	release_resource(qoriq_ptp->rsrc);
 no_resource:
 	free_irq(qoriq_ptp->irq, qoriq_ptp);
+no_param:
 no_node:
 	kfree(qoriq_ptp);
 no_memory:
include/linux/fsl/ptp_qoriq.h +1 -0
index dc3dac4..586d430 100644
@@ -147,6 +147,7 @@ struct qoriq_ptp {
 	u32 cksel;
 	u32 tmr_fiper1;
 	u32 tmr_fiper2;
+	u32 clk_src;
 };
 
 static inline u32 qoriq_read(unsigned __iomem *addr)
Signature · 1 line
1.7.1
maintainer
#3 lore raw

Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

Quoted 11 lines · Yangbo Lu

The ptp_qoriq driver initialized the 1588 timer with the configurations provided by the properties of device tree node. For example,

  fsl,tclk-period = <5>;
  fsl,tmr-prsc    = <2>;
  fsl,tmr-add     = <0xaaaaaaab>;
  fsl,tmr-fiper1  = <999999995>;
  fsl,tmr-fiper2  = <99990>;
  fsl,max-adj     = <499999999>;
Quoted 2 lines

These things actually were runtime configurations which were not proper to be put into dts.

That is debatable. While I agree that the dts isn't ideal for these, still it is the lesser of two or more evils.

Quoted 3 lines

This patch is to convert
to use module parameters for 1588 timer initialization, and to support initial register values calculation.

It is hard for me to understand how using module parameters improves the situation.

Quoted 4 lines

If the parameters are not provided, the driver will calculate register values with a set of default parameters. With this patch, those dts properties are no longer needed for new platform to support 1588 timer, and many QorIQ DPAA platforms

Quoted 8 lines

(some P series and T series platforms of PowerPC, and some LS series platforms of ARM64) could use this driver for their fman ptp timer with default module parameters. However, this patch didn't remove the dts method. Because there were still many old platforms using the dts method. We need to clean up their dts files, verify module parameters on them, and convert them to the new method gradually in case of breaking any function.

In addition, like it or not, because the dts is an ABI, you must continue support of the dts values as a legacy option.

Thanks,
Richard

maintainer
#7 lore raw

Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

In reply to Yangbo Lu

From: Yangbo Lu <[email protected]>
Date: Mon, 30 Jul 2018 18:01:54 +0800

Quoted 9 lines
drivers/ptp/ptp_qoriq.c +9 -0
+static unsigned int cksel = DEFAULT_CKSEL;
+module_param(cksel, uint, 0644);
+MODULE_PARM_DESC(cksel, "Select reference clock");
+
+static unsigned int clk_src;
+module_param(clk_src, uint, 0644);
+MODULE_PARM_DESC(clk_src, "Reference clock frequency (if clocks property not provided in dts)");
+
+static unsigned int tmr_prsc = 2;

drivers/ptp/ptp_qoriq.c line 54

Quoted 10 lines
drivers/ptp/ptp_qoriq.c +10 -0
+module_param(tmr_prsc, uint, 0644);
+MODULE_PARM_DESC(tmr_prsc, "Output clock division/prescale factor");
+
+static unsigned int tmr_fiper1 = 1000000000;
+module_param(tmr_fiper1, uint, 0644);
+MODULE_PARM_DESC(tmr_fiper1, "Desired fixed interval pulse period (ns)");
+
+static unsigned int tmr_fiper2 = 100000;
+module_param(tmr_fiper2, uint, 0644);
+MODULE_PARM_DESC(tmr_fiper2, "Desired fixed interval pulse period (ns)");

Sorry, there is no way I am every applying something like this. Module parameters are to be avoided at all costs.

And you don't need it here, you have DTS, please use it.

You are required to support the existing DTS cases, in order to avoid breaking things, anyways.

author maintainer
#4 lore raw

RE: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

In reply to Richard Cochran

Hi Richard,

Quoted 24 lines

-----Original Message-----
From: Richard Cochran [mailto:richardcochran at gmail.com]
Sent: Monday, July 30, 2018 10:31 PM
To: Y.b. Lu <[email protected]>
Cc: netdev at vger.kernel.org; Madalin-cristian Bucur <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>; David S . Miller <[email protected]>; devicetree at vger.kernel.org; linuxppc-dev at lists.ozlabs.org; linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org
Subject: Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

Quoted 11 lines · Yangbo Lu

The ptp_qoriq driver initialized the 1588 timer with the configurations provided by the properties of device tree node. For example,

  fsl,tclk-period = <5>;
  fsl,tmr-prsc    = <2>;
  fsl,tmr-add     = <0xaaaaaaab>;
  fsl,tmr-fiper1  = <999999995>;
  fsl,tmr-fiper2  = <99990>;
  fsl,max-adj     = <499999999>;
Quoted 5 lines
Quoted 2 lines

These things actually were runtime configurations which were not proper to be put into dts.

That is debatable. While I agree that the dts isn't ideal for these, still it is the lesser of two or more evils.

[Y.b. Lu] Ok. You're right indeed :)

Quoted 7 lines
Quoted 4 lines

This patch is to convert
to use module parameters for 1588 timer initialization, and to support initial register values calculation.

It is hard for me to understand how using module parameters improves the situation.

[Y.b. Lu] Actually I'm not sure whether module_param will be accepted to replace dts. I thought the most possibility would be rejection before sending them out.
Just want suggestion and confirmation whether there is better idea than dts from your comments.

Since we should keep the dts, I will drop the module_param.
Could I add a function to calculate a set of default register values to initialize ptp timer when dts method failed to get required properties in driver?
I think this will be useful. The ptp timer on new platforms (you may see two dts patches in this patchset. Many platforms will be affected.) will work without these dts properties. If user want specific setting, they can set dts properties.

Quoted 12 lines
Quoted 11 lines

If the parameters are not provided, the driver will calculate register values with a set of default parameters. With this patch, those dts properties are no longer needed for new platform to support 1588 timer, and many QorIQ DPAA platforms (some P series and T series platforms of PowerPC, and some LS series platforms of ARM64) could use this driver for their fman ptp timer with default module parameters. However, this patch didn't remove the dts method. Because there were still many old platforms using the dts method. We need to clean up their dts files, verify module parameters on them, and convert them to the new method gradually in case of breaking any function.

Quoted 2 lines

In addition, like it or not, because the dts is an ABI, you must continue support of the dts values as a legacy option.

[Y.b. Lu] I get your point now. The dts should be kept :)

Quoted 3 lines

Thanks,
Richard

author maintainer
#8 lore raw

RE: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

In reply to David Miller

Hi David,

Quoted 38 lines

-----Original Message-----
From: David Miller [mailto:davem at davemloft.net]
Sent: Tuesday, July 31, 2018 12:26 AM
To: Y.b. Lu <[email protected]>
Cc: netdev at vger.kernel.org; Madalin-cristian Bucur <[email protected]>; richardcochran at gmail.com; robh+dt at kernel.org; shawnguo at kernel.org; devicetree at vger.kernel.org; linuxppc-dev at lists.ozlabs.org; linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org
Subject: Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

From: Yangbo Lu <[email protected]>
Date: Mon, 30 Jul 2018 18:01:54 +0800

Quoted 9 lines
(quoted diff) +9 -0
+static unsigned int cksel = DEFAULT_CKSEL; module_param(cksel, uint,
+0644); MODULE_PARM_DESC(cksel, "Select reference clock");
+
+static unsigned int clk_src;
+module_param(clk_src, uint, 0644);
+MODULE_PARM_DESC(clk_src, "Reference clock frequency (if clocks
+property not provided in dts)");
+
+static unsigned int tmr_prsc = 2;

Review

Quoted 10 lines
(quoted diff) +10 -0
+module_param(tmr_prsc, uint, 0644);
+MODULE_PARM_DESC(tmr_prsc, "Output clock division/prescale factor");
+
+static unsigned int tmr_fiper1 = 1000000000; module_param(tmr_fiper1,
+uint, 0644); MODULE_PARM_DESC(tmr_fiper1, "Desired fixed interval
+pulse period (ns)");
+
+static unsigned int tmr_fiper2 = 100000; module_param(tmr_fiper2,
+uint, 0644); MODULE_PARM_DESC(tmr_fiper2, "Desired fixed interval
+pulse period (ns)");

Sorry, there is no way I am every applying something like this. Module parameters are to be avoided at all costs.

Quoted 4 lines

And you don't need it here, you have DTS, please use it.

You are required to support the existing DTS cases, in order to avoid breaking things, anyways.

[Y.b. Lu] I get your point. Will drop module_param method. Thanks a lot for your suggestion.

maintainer
#5 lore raw

Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

In reply to Y.b. Lu
Quoted 3 lines · Y.b. Lu

Could I add a function to calculate a set of default register values to initialize ptp timer when dts method failed to get required properties in driver?

Yes, it would be ideal if the driver can pick correct values automatically.

However, the frequency on the FIPER outputs can't be configured automatically, and we don't have an API for the user to choose this.

Quoted 4 lines

I think this will be useful. The ptp timer on new platforms (you may see two dts patches in this patchset. Many platforms will be affected.) will work without these dts properties. If user want specific setting, they can set dts properties.

Sure.

Thanks,
Richard

author maintainer
#6 lore raw

RE: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

Hi Richard,

Quoted 14 lines

-----Original Message-----
From: Richard Cochran [mailto:richardcochran at gmail.com]
Sent: Wednesday, August 1, 2018 2:15 PM
To: Y.b. Lu <[email protected]>
Cc: netdev at vger.kernel.org; Madalin-cristian Bucur <[email protected]>; Rob Herring <[email protected]>; Shawn Guo <[email protected]>; David S . Miller <[email protected]>; devicetree at vger.kernel.org; linuxppc-dev at lists.ozlabs.org; linux-arm-kernel at lists.infradead.org; linux-kernel at vger.kernel.org
Subject: Re: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization

On Wed, Aug 01, 2018 at 04:36:40AM +0000, Y.b. Lu wrote:

Quoted 8 lines
Quoted 3 lines

Could I add a function to calculate a set of default register values to initialize ptp timer when dts method failed to get required properties in driver?

Yes, it would be ideal if the driver can pick correct values automatically.

However, the frequency on the FIPER outputs can't be configured automatically, and we don't have an API for the user to choose this.

[Y.b. Lu] Thanks a lot. Just let me send out the v2 patch for your reviewing.

Quoted 10 lines
Quoted 5 lines

I think this will be useful. The ptp timer on new platforms (you may see two dts patches in this patchset. Many platforms will be affected.) will work without these dts properties. If user want specific setting, they can set dts properties.

Sure.

Thanks,
Richard