source: rtems/c/src/lib/libbsp/arm/imx/startup/bspstart.c @ ce28d601

5
Last change on this file since ce28d601 was ce28d601, checked in by Sebastian Huber <sebastian.huber@…>, on 09/28/17 at 08:03:44

bsp/imx: Add imx_get_reg_of_node()

Update #3090.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#include <bsp.h>
16#include <bsp/bootcard.h>
17#include <bsp/fatal.h>
18#include <bsp/fdt.h>
19#include <bsp/irq-generic.h>
20#include <bsp/linker-symbols.h>
21
22#include <libfdt.h>
23
24#define MAGIC_IRQ_OFFSET 32
25
26void *imx_get_reg_of_node(const void *fdt, int node)
27{
28  int len;
29  const uint32_t *val;
30
31  val = fdt_getprop(fdt, node, "reg", &len);
32  if (val == NULL || len < 4) {
33    return NULL;
34  }
35
36  return (void *) fdt32_to_cpu(val[0]);
37}
38
39rtems_vector_number imx_get_irq_of_node(
40  const void *fdt,
41  int node,
42  size_t index
43)
44{
45  int len;
46  const uint32_t *val;
47
48  val = fdt_getprop(fdt, node, "interrupts", &len);
49  if (val == NULL || len < (int) ((index + 1) * 12)) {
50    return UINT32_MAX;
51  }
52
53  return fdt32_to_cpu(val[index * 3 + 1]) + MAGIC_IRQ_OFFSET;
54}
55
56uint32_t bsp_fdt_map_intr(const uint32_t *intr, size_t icells)
57{
58  return intr[1] + MAGIC_IRQ_OFFSET;
59}
60
61void arm_generic_timer_get_config(
62  uint32_t *frequency,
63  uint32_t *irq
64)
65{
66  const void *fdt;
67  int node;
68  int len;
69  const uint32_t *val;
70
71  fdt = bsp_fdt_get();
72  node = fdt_path_offset(fdt, "/timer");
73
74  val = fdt_getprop(fdt, node, "clock-frequency", &len);
75  if (val != NULL && len >= 4) {
76    *frequency = fdt32_to_cpu(val[0]);
77  } else {
78    bsp_fatal(IMX_FATAL_GENERIC_TIMER_FREQUENCY);
79  }
80
81  /* FIXME: Figure out how Linux gets a proper IRQ number */
82  *irq = imx_get_irq_of_node(fdt, node, 0) - 16;
83}
84
85void bsp_start(void)
86{
87  bsp_interrupt_initialize();
88  rtems_cache_coherent_add_area(
89    bsp_section_nocacheheap_begin,
90    (uintptr_t) bsp_section_nocacheheap_size
91  );
92}
Note: See TracBrowser for help on using the repository browser.