source: rtems/c/src/lib/libbsp/arm/altera-cyclone-v/startup/bspstart.c @ c0a3c899

5
Last change on this file since c0a3c899 was c0a3c899, checked in by Sebastian Huber <sebastian.huber@…>, on 10/13/17 at 09:20:39

bsp/altera-cyclone-v: Update clock frequencies

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * Copyright (c) 2013, 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/bootcard.h>
16#include <bsp/arm-a9mpcore-clock.h>
17#include <bsp/fdt.h>
18#include <bsp/irq-generic.h>
19#include <bsp/linker-symbols.h>
20
21#include <alt_clock_manager.h>
22
23#include <libfdt.h>
24
25static void set_clock(
26  const void *fdt,
27  int parent,
28  ALT_CLK_t clk,
29  const char *name
30)
31{
32  int node;
33  int len;
34  const uint32_t *val;
35
36  node = fdt_subnode_offset(fdt, parent, name);
37  val = fdt_getprop(fdt, node, "clock-frequency", &len);
38
39  if (val != NULL && len >= 4) {
40    alt_clk_ext_clk_freq_set(clk, fdt32_to_cpu(val[0]));
41  }
42}
43
44static void set_clock_by_output_name(
45  const void *fdt,
46  ALT_CLK_t clk,
47  const char *clock_output_name
48)
49{
50  int node;
51  int len;
52  const uint32_t *val;
53
54  node = fdt_node_offset_by_prop_value(
55    fdt,
56    -1,
57    "clock-output-names",
58    clock_output_name,
59    strlen(clock_output_name) + 1
60  );
61  val = fdt_getprop(fdt, node, "clock-frequency", &len);
62
63  if (val != NULL && len >= 4) {
64    alt_clk_ext_clk_freq_set(clk, fdt32_to_cpu(val[0]));
65  }
66}
67
68static void update_clocks(void)
69{
70  const void *fdt;
71  int parent;
72
73  fdt = bsp_fdt_get();
74
75  /* Try to set by node name */
76  parent = fdt_node_offset_by_compatible(fdt, -1, "altr,clk-mgr");
77  parent = fdt_subnode_offset(fdt, parent, "clocks");
78  set_clock(fdt, parent, ALT_CLK_OSC1, "osc1");
79  set_clock(fdt, parent, ALT_CLK_IN_PIN_OSC2, "osc2");
80  set_clock(fdt, parent, ALT_CLK_F2H_PERIPH_REF, "f2s_periph_ref_clk");
81  set_clock(fdt, parent, ALT_CLK_F2H_SDRAM_REF, "f2s_sdram_ref_clk");
82
83  /* Try to set by "clock-output-names" property value */
84  set_clock_by_output_name(fdt, ALT_CLK_OSC1, "hps_0_eosc1-clk");
85  set_clock_by_output_name(fdt, ALT_CLK_IN_PIN_OSC2, "hps_0_eosc2-clk");
86  set_clock_by_output_name(fdt, ALT_CLK_F2H_PERIPH_REF, "hps_0_f2s_periph_ref_clk-clk");
87  set_clock_by_output_name(fdt, ALT_CLK_F2H_SDRAM_REF, "hps_0_f2s_sdram_ref_clk-clk");
88}
89
90void bsp_start(void)
91{
92  update_clocks();
93  a9mpcore_clock_initialize_early();
94  bsp_interrupt_initialize();
95  rtems_cache_coherent_add_area(
96    bsp_section_nocacheheap_begin,
97    (uintptr_t) bsp_section_nocacheheap_size
98  );
99}
Note: See TracBrowser for help on using the repository browser.