All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Christophe Dubois <jcd@tribudubois.net>
To: qemu-devel@nongnu.org, peter.maydell@linaro.org,
	crosthwaite.peter@gmail.com
Cc: Jean-Christophe Dubois <jcd@tribudubois.net>
Subject: [Qemu-devel] [PATCH v3 01/12] i.MX: Allow GPT timer to rollover.
Date: Tue,  1 Mar 2016 23:27:27 +0100	[thread overview]
Message-ID: <6e2b36117a249a78bf822dd59a390368f407136e.1456868959.git.jcd@tribudubois.net> (raw)
In-Reply-To: <cover.1456868959.git.jcd@tribudubois.net>

GPT timer need to rollover when it reaches 0xffffffff.

It also need to reset to 0 when in "restart mode" and crossing the
compare 1 register.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
---

Changes since V1:
 * None 

Changes since V2:
 * None 

 hw/timer/imx_gpt.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
index 5cdc3b3..916577b 100644
--- a/hw/timer/imx_gpt.c
+++ b/hw/timer/imx_gpt.c
@@ -134,7 +134,7 @@ static inline uint32_t imx_gpt_find_limit(uint32_t count, uint32_t reg,
 static void imx_gpt_compute_next_timeout(IMXGPTState *s, bool event)
 {
     uint32_t timeout = GPT_TIMER_MAX;
-    uint32_t count = 0;
+    uint32_t count;
     long long limit;
 
     if (!(s->cr & GPT_CR_EN)) {
@@ -142,20 +142,23 @@ static void imx_gpt_compute_next_timeout(IMXGPTState *s, bool event)
         return;
     }
 
-    if (event) {
-        /* This is a timer event  */
+    /* update the count */
+    count = imx_gpt_update_count(s);
 
-        if ((s->cr & GPT_CR_FRR)  && (s->next_timeout != GPT_TIMER_MAX)) {
-            /*
-             * if we are in free running mode and we have not reached
-             * the GPT_TIMER_MAX limit, then update the count
+    if (event) {
+        /*
+         * This is an event (the ptimer reached 0 and stopped), and the
+         * timer counter is now equal to s->next_timeout.
+         */
+        if (!(s->cr & GPT_CR_FRR) && (count == s->ocr1)) {
+            /* We are in restart mode and we crossed the compare channel 1
+             * value. We need to reset the counter to 0.
              */
-            count = imx_gpt_update_count(s);
+            count = s->cnt = s->next_timeout = 0;
+        } else if (count == GPT_TIMER_MAX) {
+            /* We reached GPT_TIMER_MAX so we need to rollover */
+            count = s->cnt = s->next_timeout = 0;
         }
-    } else {
-        /* not a timer event, then just update the count */
-
-        count = imx_gpt_update_count(s);
     }
 
     /* now, find the next timeout related to count */
-- 
2.5.0

  reply	other threads:[~2016-03-01 22:27 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01 22:27 [Qemu-devel] [PATCH v3 00/12] Add i.MX6 (Single/Dual/Quad) support Jean-Christophe Dubois
2016-03-01 22:27 ` Jean-Christophe Dubois [this message]
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 02/12] i.MX: Rename CCM NOCLK to CLK_NONE for naming consistency Jean-Christophe Dubois
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 03/12] i.MX: Remove CCM useless clock computation handling Jean-Christophe Dubois
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 04/12] i.MX: Add the CLK_IPG_HIGH clock Jean-Christophe Dubois
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 05/12] i.MX: Add i.MX6 CCM and ANALOG device Jean-Christophe Dubois
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 06/12] ARM: Factor out ARM on/off PSCI control functions Jean-Christophe Dubois
2016-03-10 10:14   ` Peter Maydell
2016-03-16 22:19     ` Jean-Christophe DUBOIS
2016-03-17  8:46       ` Peter Maydell
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 07/12] i.MX: Add i.MX6 System Reset Controller device Jean-Christophe Dubois
2016-03-10 10:20   ` Peter Maydell
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 08/12] i.MX: Add missing descriptions in devices Jean-Christophe Dubois
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 09/12] FIFO: Add a FIFO32 implementation Jean-Christophe Dubois
2016-03-10 10:25   ` Peter Maydell
2016-03-10 19:26     ` Jean-Christophe DUBOIS
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 10/12] i.MX: Add the Freescale SPI Controller Jean-Christophe Dubois
2016-03-10 10:31   ` Peter Maydell
2016-03-10 19:26     ` Jean-Christophe DUBOIS
2016-03-11  0:01       ` Peter Maydell
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 11/12] i.MX: Add i.MX6 SOC implementation Jean-Christophe Dubois
2016-03-10 10:33   ` Peter Maydell
2016-03-01 22:27 ` [Qemu-devel] [PATCH v3 12/12] i.MX: Add sabrelite i.MX6 emulation Jean-Christophe Dubois
2016-03-10 10:38   ` Peter Maydell
2016-03-10 19:24     ` Jean-Christophe DUBOIS
2016-03-10 23:57       ` Peter Maydell
2016-03-15 21:40         ` Jean-Christophe DUBOIS
2016-03-16  6:32           ` Peter Maydell
2016-03-16 11:28             ` Peter Maydell
2016-03-16 11:04 ` [Qemu-devel] [PATCH v3 00/12] Add i.MX6 (Single/Dual/Quad) support Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6e2b36117a249a78bf822dd59a390368f407136e.1456868959.git.jcd@tribudubois.net \
    --to=jcd@tribudubois.net \
    --cc=crosthwaite.peter@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.