[PATCH] bsp/imx: Fix system counter init for imx6

2021-01-18 Thread Christian Mauderer
For i.MX7 U-Boot initializes the system counter. On i.MX6 Barebox is
often used which doesn't initialize the counter. With this patch, we try
to auto-detect whether the counter is initialized or not and do the
initialization ourself if necessary.

Closes #3869
---
 bsps/arm/imx/start/bspstart.c | 61 ++-
 1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/bsps/arm/imx/start/bspstart.c b/bsps/arm/imx/start/bspstart.c
index 9f610d1ff5..238bc2bd28 100644
--- a/bsps/arm/imx/start/bspstart.c
+++ b/bsps/arm/imx/start/bspstart.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -59,6 +60,60 @@ uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t 
icells)
   return intr[1] + MAGIC_IRQ_OFFSET;
 }
 
+static bool imx_is_imx6(const void *fdt)
+{
+  /*
+   * At the moment: Check for some compatible strings that should be there
+   * somewhere in every fdt.
+   *
+   * FIXME: It would be nice if some CPU-ID could be used instead. But I didn't
+   * find one.
+   */
+  int node;
+
+  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ul");
+  if (node >= 0) {
+return true;
+  }
+
+  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ull");
+  if (node >= 0) {
+return true;
+  }
+
+  return false;
+}
+
+#define SYSCNT_CNTCR  (0x0)
+#define SYSCNT_CNTCR_ENABLE   (1 << 0)
+#define SYSCNT_CNTCR_HDBG (1 << 1)
+#define SYSCNT_CNTCR_FCREQ(n) (1 << (8 + (n)))
+#define SYSCNT_CNTFID(n)  (0x20 + 4 * (n))
+
+static uint32_t imx_syscnt_enable_and_return_frequency(const void *fdt)
+{
+  uint32_t freq;
+  volatile void *syscnt_base;
+
+  /* That's not in the usual FDTs. Sorry for falling back to a magic value. */
+  if (imx_is_imx6(fdt)) {
+syscnt_base = (void *)0x021dc000;
+  } else {
+syscnt_base = (void *)0x306c;
+  }
+
+  freq = *(uint32_t *)(syscnt_base + SYSCNT_CNTFID(0));
+
+  arm_cp15_set_counter_frequency(freq);
+
+  *(uint32_t *)(syscnt_base + SYSCNT_CNTCR) =
+SYSCNT_CNTCR_ENABLE |
+SYSCNT_CNTCR_HDBG |
+SYSCNT_CNTCR_FCREQ(0);
+
+  return freq;
+}
+
 void arm_generic_timer_get_config(
   uint32_t *frequency,
   uint32_t *irq
@@ -76,7 +131,11 @@ void arm_generic_timer_get_config(
   if (val != NULL && len >= 4) {
 *frequency = fdt32_to_cpu(val[0]);
   } else {
-bsp_fatal(IMX_FATAL_GENERIC_TIMER_FREQUENCY);
+/*
+ * Normally clock-frequency would be provided by the boot loader. If it
+ * didn't add one, we have to initialize the system counter ourself.
+ */
+*frequency = imx_syscnt_enable_and_return_frequency(fdt);
   }
 
   /* FIXME: Figure out how Linux gets a proper IRQ number */
-- 
2.26.2

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] bsp/imx: Fix system counter init for imx6

2021-01-18 Thread Christian MAUDERER

Hello,

I want to backport that patch to RTEMS 5 too because this problem 
occurred multiple times on the mailing list. If that is OK I'll create a 
separate ticket for RTEMS 5 that describes that problem. For RTEMS 6 it 
should finally be the last step to closing the "add i.MX6UL" ticket.


Best regards

Christian

Am 18.01.21 um 10:02 schrieb Christian Mauderer:

For i.MX7 U-Boot initializes the system counter. On i.MX6 Barebox is
often used which doesn't initialize the counter. With this patch, we try
to auto-detect whether the counter is initialized or not and do the
initialization ourself if necessary.

Closes #3869
---
  bsps/arm/imx/start/bspstart.c | 61 ++-
  1 file changed, 60 insertions(+), 1 deletion(-)

diff --git a/bsps/arm/imx/start/bspstart.c b/bsps/arm/imx/start/bspstart.c
index 9f610d1ff5..238bc2bd28 100644
--- a/bsps/arm/imx/start/bspstart.c
+++ b/bsps/arm/imx/start/bspstart.c
@@ -19,6 +19,7 @@
  #include 
  #include 
  #include 
+#include 
  
  #include 
  
@@ -59,6 +60,60 @@ uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)

return intr[1] + MAGIC_IRQ_OFFSET;
  }
  
+static bool imx_is_imx6(const void *fdt)

+{
+  /*
+   * At the moment: Check for some compatible strings that should be there
+   * somewhere in every fdt.
+   *
+   * FIXME: It would be nice if some CPU-ID could be used instead. But I didn't
+   * find one.
+   */
+  int node;
+
+  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ul");
+  if (node >= 0) {
+return true;
+  }
+
+  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ull");
+  if (node >= 0) {
+return true;
+  }
+
+  return false;
+}
+
+#define SYSCNT_CNTCR  (0x0)
+#define SYSCNT_CNTCR_ENABLE   (1 << 0)
+#define SYSCNT_CNTCR_HDBG (1 << 1)
+#define SYSCNT_CNTCR_FCREQ(n) (1 << (8 + (n)))
+#define SYSCNT_CNTFID(n)  (0x20 + 4 * (n))
+
+static uint32_t imx_syscnt_enable_and_return_frequency(const void *fdt)
+{
+  uint32_t freq;
+  volatile void *syscnt_base;
+
+  /* That's not in the usual FDTs. Sorry for falling back to a magic value. */
+  if (imx_is_imx6(fdt)) {
+syscnt_base = (void *)0x021dc000;
+  } else {
+syscnt_base = (void *)0x306c;
+  }
+
+  freq = *(uint32_t *)(syscnt_base + SYSCNT_CNTFID(0));
+
+  arm_cp15_set_counter_frequency(freq);
+
+  *(uint32_t *)(syscnt_base + SYSCNT_CNTCR) =
+SYSCNT_CNTCR_ENABLE |
+SYSCNT_CNTCR_HDBG |
+SYSCNT_CNTCR_FCREQ(0);
+
+  return freq;
+}
+
  void arm_generic_timer_get_config(
uint32_t *frequency,
uint32_t *irq
@@ -76,7 +131,11 @@ void arm_generic_timer_get_config(
if (val != NULL && len >= 4) {
  *frequency = fdt32_to_cpu(val[0]);
} else {
-bsp_fatal(IMX_FATAL_GENERIC_TIMER_FREQUENCY);
+/*
+ * Normally clock-frequency would be provided by the boot loader. If it
+ * didn't add one, we have to initialize the system counter ourself.
+ */
+*frequency = imx_syscnt_enable_and_return_frequency(fdt);
}
  
/* FIXME: Figure out how Linux gets a proper IRQ number */




--

embedded brains GmbH
Herr Christian MAUDERER
Dornierstr. 4
82178 Puchheim
Germany
email: christian.maude...@embedded-brains.de
phone: +49-89-18 94 741 - 18
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] bsp/imx: Fix system counter init for imx6

2021-01-18 Thread Chris Johns
On 18/1/21 8:05 pm, Christian MAUDERER wrote:
> I want to backport that patch to RTEMS 5 too because this problem occurred
> multiple times on the mailing list. If that is OK I'll create a separate 
> ticket
> for RTEMS 5 that describes that problem. For RTEMS 6 it should finally be the
> last step to closing the "add i.MX6UL" ticket.

This is OK for RTEMS 5. Please create the ticket and push the change when you
are ready.

Thanks
Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] Improve file header comment in generated files

2021-01-18 Thread Sebastian Huber
---
 c-user/config/bdbuf.rst | 10 +++---
 c-user/config/bsp-related.rst   | 10 +++---
 c-user/config/classic-api.rst   | 10 +++---
 c-user/config/classic-init-task.rst | 10 +++---
 c-user/config/device-driver.rst | 10 +++---
 c-user/config/event-record.rst  | 10 +++---
 c-user/config/filesystem.rst| 10 +++---
 c-user/config/general.rst   | 10 +++---
 c-user/config/idle-task.rst | 10 +++---
 c-user/config/mpci.rst  | 10 +++---
 c-user/config/posix-api.rst | 10 +++---
 c-user/config/posix-init-thread.rst | 10 +++---
 c-user/config/scheduler-general.rst | 10 +++---
 c-user/config/task-stack-alloc.rst  | 10 +++---
 c-user/event/directives.rst | 10 +++---
 c-user/event/introduction.rst   | 10 +++---
 c-user/io/directives.rst| 10 +++---
 c-user/io/introduction.rst  | 10 +++---
 c-user/object-services/directives.rst   | 10 +++---
 c-user/object-services/introduction.rst | 10 +++---
 c-user/partition/directives.rst | 10 +++---
 c-user/partition/introduction.rst   | 10 +++---
 c-user/timer/directives.rst | 10 +++---
 c-user/timer/introduction.rst   | 10 +++---
 eng/req/items.rst   | 10 +++---
 25 files changed, 175 insertions(+), 75 deletions(-)

diff --git a/c-user/config/bdbuf.rst b/c-user/config/bdbuf.rst
index 06399e0..5a3360f 100644
--- a/c-user/config/bdbuf.rst
+++ b/c-user/config/bdbuf.rst
@@ -8,11 +8,15 @@
 .. worded better please post a report or patch to an RTEMS mailing list
 .. or raise a bug report:
 ..
-.. https://docs.rtems.org/branches/master/user/support/bugs.html
+.. https://www.rtems.org/support/bugs.html
 ..
-.. For information on updating and regenerating please refer to:
+.. For information on updating and regenerating please refer to the How-To
+.. section in the Software Requirements Engineering chapter of the
+.. RTEMS Software Engineering manual.  The manual is provided as a part of
+.. a release.  For development sources please refer to the online
+.. documentation at:
 ..
-.. https://docs.rtems.org/branches/master/eng/req/howto.html
+.. https://docs.rtems.org
 
 .. Generated from spec:/acfg/if/group-bdbuf
 
diff --git a/c-user/config/bsp-related.rst b/c-user/config/bsp-related.rst
index 3d0a3ca..f9052ee 100644
--- a/c-user/config/bsp-related.rst
+++ b/c-user/config/bsp-related.rst
@@ -8,11 +8,15 @@
 .. worded better please post a report or patch to an RTEMS mailing list
 .. or raise a bug report:
 ..
-.. https://docs.rtems.org/branches/master/user/support/bugs.html
+.. https://www.rtems.org/support/bugs.html
 ..
-.. For information on updating and regenerating please refer to:
+.. For information on updating and regenerating please refer to the How-To
+.. section in the Software Requirements Engineering chapter of the
+.. RTEMS Software Engineering manual.  The manual is provided as a part of
+.. a release.  For development sources please refer to the online
+.. documentation at:
 ..
-.. https://docs.rtems.org/branches/master/eng/req/howto.html
+.. https://docs.rtems.org
 
 .. Generated from spec:/acfg/if/group-bsp
 
diff --git a/c-user/config/classic-api.rst b/c-user/config/classic-api.rst
index e44716a..5976927 100644
--- a/c-user/config/classic-api.rst
+++ b/c-user/config/classic-api.rst
@@ -8,11 +8,15 @@
 .. worded better please post a report or patch to an RTEMS mailing list
 .. or raise a bug report:
 ..
-.. https://docs.rtems.org/branches/master/user/support/bugs.html
+.. https://www.rtems.org/support/bugs.html
 ..
-.. For information on updating and regenerating please refer to:
+.. For information on updating and regenerating please refer to the How-To
+.. section in the Software Requirements Engineering chapter of the
+.. RTEMS Software Engineering manual.  The manual is provided as a part of
+.. a release.  For development sources please refer to the online
+.. documentation at:
 ..
-.. https://docs.rtems.org/branches/master/eng/req/howto.html
+.. https://docs.rtems.org
 
 .. Generated from spec:/acfg/if/group-classic
 
diff --git a/c-user/config/classic-init-task.rst 
b/c-user/config/classic-init-task.rst
index b331e40..81ecfda 100644
--- a/c-user/config/classic-init-task.rst
+++ b/c-user/config/classic-init-task.rst
@@ -8,11 +8,15 @@
 .. worded better please post a report or patch to an RTEMS mailing list
 .. or raise a bug report:
 ..
-.. https://docs.rtems.org/branches/master/user/support/bugs.html
+.. https://www.rtems.org/support/bugs.html
 ..
-.. For information on updating and regenerating please refer to:
+.. For information on updating and regenerating please refer to the How-To
+.. section in the Software Requirements Engineering chapter of the
+.. RTEMS Software Engineering manual.  The manual is provided as a part of
+.. a release.  For devel