Changeset 7b99d76 in rtems


Ignore:
Timestamp:
Jan 18, 2021, 9:02:40 AM (7 weeks ago)
Author:
Christian Mauderer <christian.mauderer@…>
Branches:
master
Children:
c45da42
Parents:
36b4e8c
git-author:
Christian Mauderer <christian.mauderer@…> (01/18/21 09:02:40)
git-committer:
Christian Mauderer <christian.mauderer@…> (01/21/21 09:17:31)
Message:

bsp/imx: Fix system counter init for imx6

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • bsps/arm/imx/start/bspstart.c

    r36b4e8c r7b99d76  
    2020#include <bsp/linker-symbols.h>
    2121#include <dev/clock/arm-generic-timer.h>
     22#include <libcpu/arm-cp15.h>
    2223
    2324#include <libfdt.h>
     
    6061}
    6162
     63static bool imx_is_imx6(const void *fdt)
     64{
     65  /*
     66   * At the moment: Check for some compatible strings that should be there
     67   * somewhere in every fdt.
     68   *
     69   * FIXME: It would be nice if some CPU-ID could be used instead. But I didn't
     70   * find one.
     71   */
     72  int node;
     73
     74  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ul");
     75  if (node >= 0) {
     76    return true;
     77  }
     78
     79  node = fdt_node_offset_by_compatible(fdt, -1, "fsl,imx6ull");
     80  if (node >= 0) {
     81    return true;
     82  }
     83
     84  return false;
     85}
     86
     87#define SYSCNT_CNTCR          (0x0)
     88#define SYSCNT_CNTCR_ENABLE   (1 << 0)
     89#define SYSCNT_CNTCR_HDBG     (1 << 1)
     90#define SYSCNT_CNTCR_FCREQ(n) (1 << (8 + (n)))
     91#define SYSCNT_CNTFID(n)      (0x20 + 4 * (n))
     92
     93static uint32_t imx_syscnt_enable_and_return_frequency(const void *fdt)
     94{
     95  uint32_t freq;
     96  volatile void *syscnt_base;
     97
     98  /* That's not in the usual FDTs. Sorry for falling back to a magic value. */
     99  if (imx_is_imx6(fdt)) {
     100    syscnt_base = (void *)0x021dc000;
     101  } else {
     102    syscnt_base = (void *)0x306c0000;
     103  }
     104
     105  freq = *(uint32_t *)(syscnt_base + SYSCNT_CNTFID(0));
     106
     107  arm_cp15_set_counter_frequency(freq);
     108
     109  *(uint32_t *)(syscnt_base + SYSCNT_CNTCR) =
     110    SYSCNT_CNTCR_ENABLE |
     111    SYSCNT_CNTCR_HDBG |
     112    SYSCNT_CNTCR_FCREQ(0);
     113
     114  return freq;
     115}
     116
    62117void arm_generic_timer_get_config(
    63118  uint32_t *frequency,
     
    77132    *frequency = fdt32_to_cpu(val[0]);
    78133  } else {
    79     bsp_fatal(IMX_FATAL_GENERIC_TIMER_FREQUENCY);
     134    /*
     135     * Normally clock-frequency would be provided by the boot loader. If it
     136     * didn't add one, we have to initialize the system counter ourself.
     137     */
     138    *frequency = imx_syscnt_enable_and_return_frequency(fdt);
    80139  }
    81140
Note: See TracChangeset for help on using the changeset viewer.