[PATCH] bsps/arm/imxrt: Add FDT and FDT helper for QTMR

Christian Mauderer christian.mauderer at embedded-brains.de
Thu Feb 11 15:47:21 UTC 2021


Makes it simpler to access the QTMR in an application via a FDT name or
link in an application specific FDT entry.
---
 bsps/arm/imxrt/include/fsl_qtmr.h             | 34 ++++++++++++++++
 bsps/arm/imxrt/include/imxrt/imxrt1050.dtsi   | 24 +++++++++++
 .../nxp/devices/MIMXRT1052/drivers/fsl_qtmr.c | 40 +++++++++++++++++++
 3 files changed, 98 insertions(+)

diff --git a/bsps/arm/imxrt/include/fsl_qtmr.h b/bsps/arm/imxrt/include/fsl_qtmr.h
index 589b9c3597..a675413f8d 100644
--- a/bsps/arm/imxrt/include/fsl_qtmr.h
+++ b/bsps/arm/imxrt/include/fsl_qtmr.h
@@ -8,6 +8,9 @@
 #define _FSL_QTMR_H_
 
 #include "fsl_common.h"
+#ifdef __rtems__
+#include <rtems.h>
+#endif /* __rtems__ */
 
 /*!
  * @addtogroup qtmr
@@ -177,6 +180,37 @@ extern "C" {
  * @name Initialization and deinitialization
  * @{
  */
+#ifdef __rtems__
+/*!
+ * @brief Return the timer base based on a FDT node.
+ *
+ * @param fdt      Pointer to the fdt
+ * @param node     The FDT node
+ *
+ * @return Pointer to the timer. NULL on error (for example if node isn't
+ *         compatible).
+ */
+TMR_Type *QTMR_get_regs_from_fdt(const void *fdt, int node);
+
+/*!
+ * @brief Return the timer IRQ vector based on a FDT node.
+ *
+ * @param fdt      Pointer to the fdt
+ * @param node     The FDT node
+ *
+ * @return IRQ vector number. BSP_INTERRUPT_VECTOR_INVALID on error.
+ */
+rtems_vector_number QTMR_get_IRQ_from_fdt(const void *fdt, int node);
+
+/*!
+ * @brief Return the clock source frequency of the quad timer.
+ *
+ * @param base     Quad Timer peripheral base address.
+ *
+ * @return IRQ vector number. BSP_INTERRUPT_VECTOR_INVALID on error.
+ */
+uint32_t QTMR_get_src_clk(TMR_Type *base);
+#endif /* __rtems__ */
 
 /*!
  * @brief Ungates the Quad Timer clock and configures the peripheral for basic operation.
diff --git a/bsps/arm/imxrt/include/imxrt/imxrt1050.dtsi b/bsps/arm/imxrt/include/imxrt/imxrt1050.dtsi
index 78c7b1c68e..610aa37e33 100644
--- a/bsps/arm/imxrt/include/imxrt/imxrt1050.dtsi
+++ b/bsps/arm/imxrt/include/imxrt/imxrt1050.dtsi
@@ -101,6 +101,30 @@
 			reg = <0x40100000 0x00100000>;
 			ranges;
 
+			qtimer4: timer at 401e8000 {
+				compatible = "nxp,imxrt-qtimer";
+				reg = <0x401e8000 0x4000>;
+				interrupts = <136>;
+			};
+
+			qtimer3: timer at 401e4000 {
+				compatible = "nxp,imxrt-qtimer";
+				reg = <0x401e4000 0x4000>;
+				interrupts = <135>;
+			};
+
+			qtimer2: timer at 401e0000 {
+				compatible = "nxp,imxrt-qtimer";
+				reg = <0x401e0000 0x4000>;
+				interrupts = <134>;
+			};
+
+			qtimer1: timer at 401dc000 {
+				compatible = "nxp,imxrt-qtimer";
+				reg = <0x401dc000 0x4000>;
+				interrupts = <133>;
+			};
+
 			gpio4: gpio at 401c4000 {
 				compatible = "fsl,imxrt-gpio",
 				    "fsl,imx6ul-gpio", "fsl,imx35-gpio";
diff --git a/bsps/arm/imxrt/nxp/devices/MIMXRT1052/drivers/fsl_qtmr.c b/bsps/arm/imxrt/nxp/devices/MIMXRT1052/drivers/fsl_qtmr.c
index 44b7867441..f96e5504be 100644
--- a/bsps/arm/imxrt/nxp/devices/MIMXRT1052/drivers/fsl_qtmr.c
+++ b/bsps/arm/imxrt/nxp/devices/MIMXRT1052/drivers/fsl_qtmr.c
@@ -6,6 +6,11 @@
  */
 
 #include "fsl_qtmr.h"
+#ifdef __rtems__
+#include <bsp.h>
+#include <bsp/irq.h>
+#include <libfdt.h>
+#endif /* __rtems__ */
 
 /* Component ID definition, used by tools. */
 #ifndef FSL_COMPONENT_ID
@@ -56,6 +61,41 @@ static uint32_t QTMR_GetInstance(TMR_Type *base)
     return instance;
 }
 
+#ifdef __rtems__
+TMR_Type *QTMR_get_regs_from_fdt(const void *fdt, int node)
+{
+    int rv;
+    TMR_Type *regs;
+
+    rv = fdt_node_check_compatible(fdt, node, "nxp,imxrt-qtimer");
+    if (rv != 0) {
+        return NULL;
+    }
+    regs = imx_get_reg_of_node(fdt, node);
+    return regs;
+}
+
+rtems_vector_number QTMR_get_IRQ_from_fdt(const void *fdt, int node)
+{
+    int rv;
+    rtems_vector_number irq;
+
+    rv = fdt_node_check_compatible(fdt, node, "nxp,imxrt-qtimer");
+    if (rv != 0) {
+        return BSP_INTERRUPT_VECTOR_INVALID;
+    }
+    irq = imx_get_irq_of_node(fdt, node, 0);
+    return irq;
+}
+
+uint32_t QTMR_get_src_clk(TMR_Type *base)
+{
+    (void) base;
+
+    return CLOCK_GetFreq(kCLOCK_IpgClk);
+}
+
+#endif /* __rtems__ */
 /*!
  * brief Ungates the Quad Timer clock and configures the peripheral for basic operation.
  *
-- 
2.26.2



More information about the devel mailing list