linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name
@ 2018-03-28  3:22 Anson Huang
  2018-03-28  3:22 ` [PATCH V2 2/4] clocksource/drivers/imx-tpm: " Anson Huang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Anson Huang @ 2018-03-28  3:22 UTC (permalink / raw)
  To: daniel.lezcano, tglx, robh+dt, mark.rutland
  Cc: Linux-imx, linux-kernel, devicetree

The clock name should be ipg instead of igp.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt b/Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt
index b4aa7dd..f82087b 100644
--- a/Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt
+++ b/Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt
@@ -15,7 +15,7 @@ Required properties:
 - interrupts :	Should be the clock event device interrupt.
 - clocks :	The clocks provided by the SoC to drive the timer, must contain
 		an entry for each entry in clock-names.
-- clock-names : Must include the following entries: "igp" and "per".
+- clock-names : Must include the following entries: "ipg" and "per".
 
 Example:
 tpm5: tpm@40260000 {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V2 2/4] clocksource/drivers/imx-tpm: fix typo of clock name
  2018-03-28  3:22 [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Anson Huang
@ 2018-03-28  3:22 ` Anson Huang
  2018-03-28  3:22 ` [PATCH V2 3/4] clocksource/drivers/imx-tpm: correct some registers operation flow Anson Huang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Anson Huang @ 2018-03-28  3:22 UTC (permalink / raw)
  To: daniel.lezcano, tglx, robh+dt, mark.rutland
  Cc: Linux-imx, linux-kernel, devicetree

The clock name should be ipg instead of igp.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
 drivers/clocksource/timer-imx-tpm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c
index 21bffdc..3f97d49 100644
--- a/drivers/clocksource/timer-imx-tpm.c
+++ b/drivers/clocksource/timer-imx-tpm.c
@@ -179,7 +179,7 @@ static int __init tpm_timer_init(struct device_node *np)
 	ipg = of_clk_get_by_name(np, "ipg");
 	per = of_clk_get_by_name(np, "per");
 	if (IS_ERR(ipg) || IS_ERR(per)) {
-		pr_err("tpm: failed to get igp or per clk\n");
+		pr_err("tpm: failed to get ipg or per clk\n");
 		ret = -ENODEV;
 		goto err_clk_get;
 	}
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V2 3/4] clocksource/drivers/imx-tpm: correct some registers operation flow
  2018-03-28  3:22 [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Anson Huang
  2018-03-28  3:22 ` [PATCH V2 2/4] clocksource/drivers/imx-tpm: " Anson Huang
@ 2018-03-28  3:22 ` Anson Huang
  2018-03-28  3:22 ` [PATCH V2 4/4] clocksource/drivers/imx-tpm: add different counter width support Anson Huang
  2018-03-28 13:21 ` [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Anson Huang @ 2018-03-28  3:22 UTC (permalink / raw)
  To: daniel.lezcano, tglx, robh+dt, mark.rutland
  Cc: Linux-imx, linux-kernel, devicetree

According to i.MX7ULP reference manual, TPM_SC_CPWMS can ONLY be
written when counter is disabled, TPM_SC_TOF is write-1-clear,
TPM_C0SC_CHF is also write-1-clear, correct these registers
initialization flow;

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
changes since V1:
	use separate patch to fix the clock name typo.
 drivers/clocksource/timer-imx-tpm.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c
index 3f97d49..7403e49 100644
--- a/drivers/clocksource/timer-imx-tpm.c
+++ b/drivers/clocksource/timer-imx-tpm.c
@@ -20,6 +20,7 @@
 #define TPM_SC				0x10
 #define TPM_SC_CMOD_INC_PER_CNT		(0x1 << 3)
 #define TPM_SC_CMOD_DIV_DEFAULT		0x3
+#define TPM_SC_TOF_MASK			(0x1 << 7)
 #define TPM_CNT				0x14
 #define TPM_MOD				0x18
 #define TPM_STATUS			0x1c
@@ -29,6 +30,7 @@
 #define TPM_C0SC_MODE_SHIFT		2
 #define TPM_C0SC_MODE_MASK		0x3c
 #define TPM_C0SC_MODE_SW_COMPARE	0x4
+#define TPM_C0SC_CHF_MASK		(0x1 << 7)
 #define TPM_C0V				0x24
 
 static void __iomem *timer_base;
@@ -205,9 +207,13 @@ static int __init tpm_timer_init(struct device_node *np)
 	 * 4) Channel0 disabled
 	 * 5) DMA transfers disabled
 	 */
+	/* make sure counter is disabled */
 	writel(0, timer_base + TPM_SC);
+	/* TOF is W1C */
+	writel(TPM_SC_TOF_MASK, timer_base + TPM_SC);
 	writel(0, timer_base + TPM_CNT);
-	writel(0, timer_base + TPM_C0SC);
+	/* CHF is W1C */
+	writel(TPM_C0SC_CHF_MASK, timer_base + TPM_C0SC);
 
 	/* increase per cnt, div 8 by default */
 	writel(TPM_SC_CMOD_INC_PER_CNT | TPM_SC_CMOD_DIV_DEFAULT,
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH V2 4/4] clocksource/drivers/imx-tpm: add different counter width support
  2018-03-28  3:22 [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Anson Huang
  2018-03-28  3:22 ` [PATCH V2 2/4] clocksource/drivers/imx-tpm: " Anson Huang
  2018-03-28  3:22 ` [PATCH V2 3/4] clocksource/drivers/imx-tpm: correct some registers operation flow Anson Huang
@ 2018-03-28  3:22 ` Anson Huang
  2018-03-28 13:21 ` [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Anson Huang @ 2018-03-28  3:22 UTC (permalink / raw)
  To: daniel.lezcano, tglx, robh+dt, mark.rutland
  Cc: Linux-imx, linux-kernel, devicetree

Different TPM modules have different width counters which
is 16-bit or 32-bit, the counter width can be read from
TPM_PARAM register bit[23:16], this patch adds dynamic
check for counter width to support both 16-bit and 32-bit
TPM modules.

Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
---
changes since V1:
	use largest prescaler for 16-bit counter;
	use lower rating for 16-bit counter than 32-bit;
	remove the computing in counter read function.
 drivers/clocksource/timer-imx-tpm.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/clocksource/timer-imx-tpm.c b/drivers/clocksource/timer-imx-tpm.c
index 7403e49..05d97a6 100644
--- a/drivers/clocksource/timer-imx-tpm.c
+++ b/drivers/clocksource/timer-imx-tpm.c
@@ -17,9 +17,13 @@
 #include <linux/of_irq.h>
 #include <linux/sched_clock.h>
 
+#define TPM_PARAM			0x4
+#define TPM_PARAM_WIDTH_SHIFT		16
+#define TPM_PARAM_WIDTH_MASK		(0xff << 16)
 #define TPM_SC				0x10
 #define TPM_SC_CMOD_INC_PER_CNT		(0x1 << 3)
 #define TPM_SC_CMOD_DIV_DEFAULT		0x3
+#define TPM_SC_CMOD_DIV_MAX		0x7
 #define TPM_SC_TOF_MASK			(0x1 << 7)
 #define TPM_CNT				0x14
 #define TPM_MOD				0x18
@@ -33,6 +37,8 @@
 #define TPM_C0SC_CHF_MASK		(0x1 << 7)
 #define TPM_C0V				0x24
 
+static int counter_width;
+static int rating;
 static void __iomem *timer_base;
 static struct clock_event_device clockevent_tpm;
 
@@ -85,10 +91,11 @@ static int __init tpm_clocksource_init(unsigned long rate)
 	tpm_delay_timer.freq = rate;
 	register_current_timer_delay(&tpm_delay_timer);
 
-	sched_clock_register(tpm_read_sched_clock, 32, rate);
+	sched_clock_register(tpm_read_sched_clock, counter_width, rate);
 
 	return clocksource_mmio_init(timer_base + TPM_CNT, "imx-tpm",
-				     rate, 200, 32, clocksource_mmio_readl_up);
+				     rate, rating, counter_width,
+				     clocksource_mmio_readl_up);
 }
 
 static int tpm_set_next_event(unsigned long delta,
@@ -141,7 +148,6 @@ static struct clock_event_device clockevent_tpm = {
 	.set_state_oneshot	= tpm_set_state_oneshot,
 	.set_next_event		= tpm_set_next_event,
 	.set_state_shutdown	= tpm_set_state_shutdown,
-	.rating			= 200,
 };
 
 static int __init tpm_clockevent_init(unsigned long rate, int irq)
@@ -151,10 +157,11 @@ static int __init tpm_clockevent_init(unsigned long rate, int irq)
 	ret = request_irq(irq, tpm_timer_interrupt, IRQF_TIMER | IRQF_IRQPOLL,
 			  "i.MX7ULP TPM Timer", &clockevent_tpm);
 
+	clockevent_tpm.rating = rating;
 	clockevent_tpm.cpumask = cpumask_of(0);
 	clockevent_tpm.irq = irq;
-	clockevents_config_and_register(&clockevent_tpm,
-					rate, 300, 0xfffffffe);
+	clockevents_config_and_register(&clockevent_tpm, rate, 300,
+					GENMASK(counter_width - 1, 1));
 
 	return ret;
 }
@@ -199,6 +206,11 @@ static int __init tpm_timer_init(struct device_node *np)
 		goto err_per_clk_enable;
 	}
 
+	counter_width = (readl(timer_base + TPM_PARAM) & TPM_PARAM_WIDTH_MASK)
+		>> TPM_PARAM_WIDTH_SHIFT;
+	/* use rating 200 for 32-bit counter and 150 for 16-bit counter */
+	rating = counter_width == 0x20 ? 200 : 150;
+
 	/*
 	 * Initialize tpm module to a known state
 	 * 1) Counter disabled
@@ -215,12 +227,17 @@ static int __init tpm_timer_init(struct device_node *np)
 	/* CHF is W1C */
 	writel(TPM_C0SC_CHF_MASK, timer_base + TPM_C0SC);
 
-	/* increase per cnt, div 8 by default */
-	writel(TPM_SC_CMOD_INC_PER_CNT | TPM_SC_CMOD_DIV_DEFAULT,
+	/*
+	 * increase per cnt,
+	 * div 8 for 32-bit counter and div 128 for 16-bit counter
+	 */
+	writel(TPM_SC_CMOD_INC_PER_CNT |
+		(counter_width == 0x20 ?
+		TPM_SC_CMOD_DIV_DEFAULT : TPM_SC_CMOD_DIV_MAX),
 		     timer_base + TPM_SC);
 
 	/* set MOD register to maximum for free running mode */
-	writel(0xffffffff, timer_base + TPM_MOD);
+	writel(GENMASK(counter_width - 1, 0), timer_base + TPM_MOD);
 
 	rate = clk_get_rate(per) >> 3;
 	ret = tpm_clocksource_init(rate);
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name
  2018-03-28  3:22 [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Anson Huang
                   ` (2 preceding siblings ...)
  2018-03-28  3:22 ` [PATCH V2 4/4] clocksource/drivers/imx-tpm: add different counter width support Anson Huang
@ 2018-03-28 13:21 ` Rob Herring
  3 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2018-03-28 13:21 UTC (permalink / raw)
  To: Anson Huang
  Cc: Daniel Lezcano, Thomas Gleixner, Mark Rutland, NXP Linux Team,
	linux-kernel, devicetree

On Tue, Mar 27, 2018 at 10:22 PM, Anson Huang <Anson.Huang@nxp.com> wrote:
> The clock name should be ipg instead of igp.
>
> Signed-off-by: Anson Huang <Anson.Huang@nxp.com>
> ---
>  Documentation/devicetree/bindings/timer/nxp,tpm-timer.txt | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-28 13:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-28  3:22 [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Anson Huang
2018-03-28  3:22 ` [PATCH V2 2/4] clocksource/drivers/imx-tpm: " Anson Huang
2018-03-28  3:22 ` [PATCH V2 3/4] clocksource/drivers/imx-tpm: correct some registers operation flow Anson Huang
2018-03-28  3:22 ` [PATCH V2 4/4] clocksource/drivers/imx-tpm: add different counter width support Anson Huang
2018-03-28 13:21 ` [PATCH V2 1/4] dt-bindings: timer: tpm: fix typo of clock name Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).