Changeset c0a3c899 in rtems


Ignore:
Timestamp:
Oct 13, 2017, 9:20:39 AM (21 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
12641f7b
Parents:
217913b
git-author:
Sebastian Huber <sebastian.huber@…> (10/13/17 09:20:39)
git-committer:
Sebastian Huber <sebastian.huber@…> (12/14/17 06:01:13)
Message:

bsp/altera-cyclone-v: Update clock frequencies

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/arm/altera-cyclone-v/startup/bspstart.c

    r217913b rc0a3c899  
    11/*
    2  * Copyright (c) 2013-2015 embedded brains GmbH.  All rights reserved.
     2 * Copyright (c) 2013, 2017 embedded brains GmbH.  All rights reserved.
    33 *
    44 *  embedded brains GmbH
     
    1515#include <bsp/bootcard.h>
    1616#include <bsp/arm-a9mpcore-clock.h>
     17#include <bsp/fdt.h>
    1718#include <bsp/irq-generic.h>
    1819#include <bsp/linker-symbols.h>
    1920
    20 void bsp_start( void )
     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)
    2131{
     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();
    2293  a9mpcore_clock_initialize_early();
    2394  bsp_interrupt_initialize();
Note: See TracChangeset for help on using the changeset viewer.