qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors
@ 2022-12-20 17:27 Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX7D: Connect GPT timers to IRQ Jean-Christophe Dubois
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jean-Christophe Dubois @ 2022-12-20 17:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jean-Christophe Dubois, qemu-arm

This patch series allow GPT timers to be used on Qemu emulated i.MX7.

In particular it allows GPT timer to raise interrupts in i.MX7 processor
and supports some of the fixed frequency clocks.

Note: CCM generated clock sources will be added with a later patch.

This also brings some fixes to the i.MX6UL GPT timer as its clock sources
differ slightly from the i.MX7 version.

Tested by running µCOS application on i.MX7D emulated processor. µCOS
is using the GPT timer as its tick source.

Jean-Christophe Dubois (3):
  i.MX7D: Connect GPT timers to IRQ
  i.MX7D: Compute clock frequency for the fixed frequency clocks.
  i.MX6UL: Add a specific GPT timer instance for the i.MX6UL

 hw/arm/fsl-imx6ul.c        |  2 +-
 hw/arm/fsl-imx7.c          | 10 ++++++++
 hw/misc/imx6ul_ccm.c       |  6 -----
 hw/misc/imx7_ccm.c         | 49 +++++++++++++++++++++++++++++++-------
 hw/timer/imx_gpt.c         | 25 +++++++++++++++++++
 include/hw/arm/fsl-imx7.h  |  5 ++++
 include/hw/timer/imx_gpt.h |  1 +
 7 files changed, 82 insertions(+), 16 deletions(-)

-- 
2.34.1



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

* [PATCH] i.MX7D: Connect GPT timers to IRQ
  2022-12-20 17:27 [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Jean-Christophe Dubois
@ 2022-12-20 17:27 ` Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX7D: Compute clock frequency for the fixed frequency clocks Jean-Christophe Dubois
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe Dubois @ 2022-12-20 17:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jean-Christophe Dubois, qemu-arm

So far the GPT timers were unable to raise IRQs to the processor.

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
---
 hw/arm/fsl-imx7.c         | 10 ++++++++++
 include/hw/arm/fsl-imx7.h |  5 +++++
 2 files changed, 15 insertions(+)

diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c
index cc6fdb9373..146bb559bb 100644
--- a/hw/arm/fsl-imx7.c
+++ b/hw/arm/fsl-imx7.c
@@ -219,9 +219,19 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp)
             FSL_IMX7_GPT4_ADDR,
         };
 
+        static const int FSL_IMX7_GPTn_IRQ[FSL_IMX7_NUM_GPTS] = {
+            FSL_IMX7_GPT1_IRQ,
+            FSL_IMX7_GPT2_IRQ,
+            FSL_IMX7_GPT3_IRQ,
+            FSL_IMX7_GPT4_IRQ,
+        };
+
         s->gpt[i].ccm = IMX_CCM(&s->ccm);
         sysbus_realize(SYS_BUS_DEVICE(&s->gpt[i]), &error_abort);
         sysbus_mmio_map(SYS_BUS_DEVICE(&s->gpt[i]), 0, FSL_IMX7_GPTn_ADDR[i]);
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->gpt[i]), 0,
+                           qdev_get_gpio_in(DEVICE(&s->a7mpcore),
+                                            FSL_IMX7_GPTn_IRQ[i]));
     }
 
     for (i = 0; i < FSL_IMX7_NUM_GPIOS; i++) {
diff --git a/include/hw/arm/fsl-imx7.h b/include/hw/arm/fsl-imx7.h
index 1c5fa6fd67..50f19d8db0 100644
--- a/include/hw/arm/fsl-imx7.h
+++ b/include/hw/arm/fsl-imx7.h
@@ -235,6 +235,11 @@ enum FslIMX7IRQs {
     FSL_IMX7_USB2_IRQ     = 42,
     FSL_IMX7_USB3_IRQ     = 40,
 
+    FSL_IMX7_GPT1_IRQ     = 55,
+    FSL_IMX7_GPT2_IRQ     = 54,
+    FSL_IMX7_GPT3_IRQ     = 53,
+    FSL_IMX7_GPT4_IRQ     = 52,
+
     FSL_IMX7_WDOG1_IRQ    = 78,
     FSL_IMX7_WDOG2_IRQ    = 79,
     FSL_IMX7_WDOG3_IRQ    = 10,
-- 
2.34.1



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

* [PATCH] i.MX7D: Compute clock frequency for the fixed frequency clocks.
  2022-12-20 17:27 [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX7D: Connect GPT timers to IRQ Jean-Christophe Dubois
@ 2022-12-20 17:27 ` Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX6UL: Add a specific GPT timer instance for the i.MX6UL Jean-Christophe Dubois
  2023-01-05 15:11 ` [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe Dubois @ 2022-12-20 17:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jean-Christophe Dubois, qemu-arm

CCM derived clocks will have to be added later.

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
---
 hw/misc/imx7_ccm.c | 49 +++++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 9 deletions(-)

diff --git a/hw/misc/imx7_ccm.c b/hw/misc/imx7_ccm.c
index 075159e497..f135ec7b7e 100644
--- a/hw/misc/imx7_ccm.c
+++ b/hw/misc/imx7_ccm.c
@@ -16,6 +16,10 @@
 #include "hw/misc/imx7_ccm.h"
 #include "migration/vmstate.h"
 
+#include "trace.h"
+
+#define CKIH_FREQ 24000000 /* 24MHz crystal input */
+
 static void imx7_analog_reset(DeviceState *dev)
 {
     IMX7AnalogState *s = IMX7_ANALOG(dev);
@@ -219,16 +223,43 @@ static const VMStateDescription vmstate_imx7_ccm = {
 static uint32_t imx7_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
 {
     /*
-     * This function is "consumed" by GPT emulation code, however on
-     * i.MX7 each GPT block can have their own clock root. This means
-     * that this functions needs somehow to know requester's identity
-     * and the way to pass it: be it via additional IMXClk constants
-     * or by adding another argument to this method needs to be
-     * figured out
+     * This function is "consumed" by GPT emulation code. Some clocks
+     * have fixed frequencies and we can provide requested frequency
+     * easily. However for CCM provided clocks (like IPG) each GPT
+     * timer can have its own clock root.
+     * This means we need additionnal information when calling this
+     * function to know the requester's identity.
      */
-    qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Not implemented\n",
-                  TYPE_IMX7_CCM, __func__);
-    return 0;
+    uint32_t freq = 0;
+
+    switch (clock) {
+    case CLK_NONE:
+        break;
+    case CLK_32k:
+        freq = CKIL_FREQ;
+        break;
+    case CLK_HIGH:
+        freq = CKIH_FREQ;
+        break;
+    case CLK_IPG:
+    case CLK_IPG_HIGH:
+        /*
+         * For now we don't have a way to figure out the device this
+         * function is called for. Until then the IPG derived clocks
+         * are left unimplemented.
+         */
+        qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Clock %d Not implemented\n",
+                      TYPE_IMX7_CCM, __func__, clock);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
+                      TYPE_IMX7_CCM, __func__, clock);
+        break;
+    }
+
+    trace_ccm_clock_freq(clock, freq);
+
+    return freq;
 }
 
 static void imx7_ccm_class_init(ObjectClass *klass, void *data)
-- 
2.34.1



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

* [PATCH] i.MX6UL: Add a specific GPT timer instance for the i.MX6UL
  2022-12-20 17:27 [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX7D: Connect GPT timers to IRQ Jean-Christophe Dubois
  2022-12-20 17:27 ` [PATCH] i.MX7D: Compute clock frequency for the fixed frequency clocks Jean-Christophe Dubois
@ 2022-12-20 17:27 ` Jean-Christophe Dubois
  2023-01-05 15:11 ` [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Jean-Christophe Dubois @ 2022-12-20 17:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Jean-Christophe Dubois, qemu-arm

The i.MX6UL doesn't support CLK_HIGH ou CLK_HIGH_DIV clock source.

Signed-off-by: Jean-Christophe Dubois <jcd@tribudubois.net>
---
 hw/arm/fsl-imx6ul.c        |  2 +-
 hw/misc/imx6ul_ccm.c       |  6 ------
 hw/timer/imx_gpt.c         | 25 +++++++++++++++++++++++++
 include/hw/timer/imx_gpt.h |  1 +
 4 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c
index f189712329..d88d6cc1c5 100644
--- a/hw/arm/fsl-imx6ul.c
+++ b/hw/arm/fsl-imx6ul.c
@@ -81,7 +81,7 @@ static void fsl_imx6ul_init(Object *obj)
      */
     for (i = 0; i < FSL_IMX6UL_NUM_GPTS; i++) {
         snprintf(name, NAME_SIZE, "gpt%d", i);
-        object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX7_GPT);
+        object_initialize_child(obj, name, &s->gpt[i], TYPE_IMX6UL_GPT);
     }
 
     /*
diff --git a/hw/misc/imx6ul_ccm.c b/hw/misc/imx6ul_ccm.c
index a65d031455..e01bb68ac7 100644
--- a/hw/misc/imx6ul_ccm.c
+++ b/hw/misc/imx6ul_ccm.c
@@ -522,12 +522,6 @@ static uint32_t imx6ul_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock)
     case CLK_32k:
         freq = CKIL_FREQ;
         break;
-    case CLK_HIGH:
-        freq = CKIH_FREQ;
-        break;
-    case CLK_HIGH_DIV:
-        freq = CKIH_FREQ / 8;
-        break;
     default:
         qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: unsupported clock %d\n",
                       TYPE_IMX6UL_CCM, __func__, clock);
diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c
index 80b8302639..7222b1b387 100644
--- a/hw/timer/imx_gpt.c
+++ b/hw/timer/imx_gpt.c
@@ -115,6 +115,17 @@ static const IMXClk imx6_gpt_clocks[] = {
     CLK_HIGH,      /* 111 reference clock */
 };
 
+static const IMXClk imx6ul_gpt_clocks[] = {
+    CLK_NONE,      /* 000 No clock source */
+    CLK_IPG,       /* 001 ipg_clk, 532MHz*/
+    CLK_IPG_HIGH,  /* 010 ipg_clk_highfreq */
+    CLK_EXT,       /* 011 External clock */
+    CLK_32k,       /* 100 ipg_clk_32k */
+    CLK_NONE,      /* 101 not defined */
+    CLK_NONE,      /* 110 not defined */
+    CLK_NONE,      /* 111 not defined */
+};
+
 static const IMXClk imx7_gpt_clocks[] = {
     CLK_NONE,      /* 000 No clock source */
     CLK_IPG,       /* 001 ipg_clk, 532MHz*/
@@ -539,6 +550,13 @@ static void imx6_gpt_init(Object *obj)
     s->clocks = imx6_gpt_clocks;
 }
 
+static void imx6ul_gpt_init(Object *obj)
+{
+    IMXGPTState *s = IMX_GPT(obj);
+
+    s->clocks = imx6ul_gpt_clocks;
+}
+
 static void imx7_gpt_init(Object *obj)
 {
     IMXGPTState *s = IMX_GPT(obj);
@@ -566,6 +584,12 @@ static const TypeInfo imx6_gpt_info = {
     .instance_init = imx6_gpt_init,
 };
 
+static const TypeInfo imx6ul_gpt_info = {
+    .name = TYPE_IMX6UL_GPT,
+    .parent = TYPE_IMX25_GPT,
+    .instance_init = imx6ul_gpt_init,
+};
+
 static const TypeInfo imx7_gpt_info = {
     .name = TYPE_IMX7_GPT,
     .parent = TYPE_IMX25_GPT,
@@ -577,6 +601,7 @@ static void imx_gpt_register_types(void)
     type_register_static(&imx25_gpt_info);
     type_register_static(&imx31_gpt_info);
     type_register_static(&imx6_gpt_info);
+    type_register_static(&imx6ul_gpt_info);
     type_register_static(&imx7_gpt_info);
 }
 
diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h
index ff5c8a351a..5a1230da35 100644
--- a/include/hw/timer/imx_gpt.h
+++ b/include/hw/timer/imx_gpt.h
@@ -78,6 +78,7 @@
 #define TYPE_IMX25_GPT "imx25.gpt"
 #define TYPE_IMX31_GPT "imx31.gpt"
 #define TYPE_IMX6_GPT "imx6.gpt"
+#define TYPE_IMX6UL_GPT "imx6ul.gpt"
 #define TYPE_IMX7_GPT "imx7.gpt"
 
 #define TYPE_IMX_GPT TYPE_IMX25_GPT
-- 
2.34.1



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

* Re: [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors
  2022-12-20 17:27 [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Jean-Christophe Dubois
                   ` (2 preceding siblings ...)
  2022-12-20 17:27 ` [PATCH] i.MX6UL: Add a specific GPT timer instance for the i.MX6UL Jean-Christophe Dubois
@ 2023-01-05 15:11 ` Peter Maydell
  3 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2023-01-05 15:11 UTC (permalink / raw)
  To: Jean-Christophe Dubois; +Cc: qemu-devel, qemu-arm

On Tue, 20 Dec 2022 at 18:18, Jean-Christophe Dubois
<jcd@tribudubois.net> wrote:
>
> This patch series allow GPT timers to be used on Qemu emulated i.MX7.
>
> In particular it allows GPT timer to raise interrupts in i.MX7 processor
> and supports some of the fixed frequency clocks.
>
> Note: CCM generated clock sources will be added with a later patch.
>
> This also brings some fixes to the i.MX6UL GPT timer as its clock sources
> differ slightly from the i.MX7 version.
>
> Tested by running µCOS application on i.MX7D emulated processor. µCOS
> is using the GPT timer as its tick source.
>
> Jean-Christophe Dubois (3):
>   i.MX7D: Connect GPT timers to IRQ
>   i.MX7D: Compute clock frequency for the fixed frequency clocks.
>   i.MX6UL: Add a specific GPT timer instance for the i.MX6UL
>
>  hw/arm/fsl-imx6ul.c        |  2 +-
>  hw/arm/fsl-imx7.c          | 10 ++++++++
>  hw/misc/imx6ul_ccm.c       |  6 -----
>  hw/misc/imx7_ccm.c         | 49 +++++++++++++++++++++++++++++++-------
>  hw/timer/imx_gpt.c         | 25 +++++++++++++++++++
>  include/hw/arm/fsl-imx7.h  |  5 ++++
>  include/hw/timer/imx_gpt.h |  1 +
>  7 files changed, 82 insertions(+), 16 deletions(-)

Thanks, I've applied this series to target-arm.next.

Something slightly odd seems to have happened to the threading
of this series -- on the archive you can see that the patchmails
are correctly followups to the cover letter:
https://lore.kernel.org/qemu-devel/cover.1671548388.git.jcd@tribudubois.net/
but patchew and patches don't identify the whole thing as a single
series and they show up as separate patches:
https://patchew.org/search?q=project%3AQEMU+from%3Ajean-christophe

This might be because the subject [PATCH] tags don't have the usual
"0/3" for the cover letter and "1/3" "2/3" "3/3" for each patch.
git format-patch ought to be able to do this automatically.

thanks
-- PMM


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

end of thread, other threads:[~2023-01-05 15:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20 17:27 [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Jean-Christophe Dubois
2022-12-20 17:27 ` [PATCH] i.MX7D: Connect GPT timers to IRQ Jean-Christophe Dubois
2022-12-20 17:27 ` [PATCH] i.MX7D: Compute clock frequency for the fixed frequency clocks Jean-Christophe Dubois
2022-12-20 17:27 ` [PATCH] i.MX6UL: Add a specific GPT timer instance for the i.MX6UL Jean-Christophe Dubois
2023-01-05 15:11 ` [PATCH] Fix i.MX GPT timers for i.MX6UL and i.MX7 processors Peter Maydell

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).