source: rtems/c/src/lib/libbsp/powerpc/mpc55xxevb/startup/start-early.c @ eb1951a

4.115
Last change on this file since eb1951a was 6273201, checked in by Sebastian Huber <sebastian.huber@…>, on 05/31/12 at 14:37:02

bsps/powerpc: Add load section for .nocache

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup mpc55xx
5 *
6 * @brief Early initialization code.
7 */
8
9/*
10 * Copyright (c) 2008-2012 embedded brains GmbH.  All rights reserved.
11 *
12 *  embedded brains GmbH
13 *  Obere Lagerstr. 30
14 *  82178 Puchheim
15 *  Germany
16 *  <rtems@embedded-brains.de>
17 *
18 * The license and distribution terms for this file may be
19 * found in the file LICENSE in this distribution or at
20 * http://www.rtems.com/license/LICENSE.
21 */
22
23#include <bsp.h>
24#include <bsp/start.h>
25#include <bsp/mpc55xx-config.h>
26#include <bsp/linker-symbols.h>
27
28/* This function is defined in start.S */
29BSP_START_TEXT_SECTION void mpc55xx_start_load_section(
30  void *dst,
31  const void *src,
32  size_t n
33);
34
35static BSP_START_TEXT_SECTION void mpc55xx_start_mmu(void)
36{
37  #ifdef MPC55XX_BOOTFLAGS
38    /* If the low bit of bootflag 0 is clear don't change the MMU.  */
39    bool do_mmu_config = (mpc55xx_bootflag_0 [0] & 1) != 0;
40  #else
41    bool do_mmu_config = true;
42  #endif
43
44  if (do_mmu_config) {
45    mpc55xx_start_mmu_apply_config(
46      &mpc55xx_start_config_mmu [0],
47      mpc55xx_start_config_mmu_count [0]
48    );
49  }
50}
51
52static BSP_START_TEXT_SECTION void mpc55xx_start_internal_ram(void)
53{
54  /* Initialize internal SRAM to zero (ECC) */
55  bsp_start_zero(
56    (char *) bsp_ram_start + MPC55XX_EARLY_STACK_SIZE,
57    (size_t) bsp_ram_size - MPC55XX_EARLY_STACK_SIZE
58  );
59  #ifdef MPC55XX_HAS_SECOND_INTERNAL_RAM_AREA
60    bsp_start_zero(&bsp_ram_1_start [0], (size_t) bsp_ram_1_size);
61  #endif
62}
63
64static BSP_START_TEXT_SECTION void mpc55xx_start_load_nocache_section(void)
65{
66  mpc55xx_start_load_section(
67    bsp_section_nocache_begin,
68    bsp_section_nocache_load_begin,
69    (size_t) bsp_section_nocache_size
70  );
71  rtems_cache_flush_multiple_data_lines(
72    bsp_section_nocache_begin,
73    (size_t) bsp_section_nocache_size
74  );
75}
76
77static BSP_START_TEXT_SECTION void mpc55xx_start_mode_change(void)
78{
79  #ifdef MPC55XX_HAS_MODE_CONTROL
80    uint32_t mctl_key1 = 0x5af0;
81    uint32_t mctl_key2 = 0xa50f;
82    int i = 0;
83
84    /* Clear any pending RGM status */
85    RGM.FES.R = 0xffff;
86    RGM.DES.R = 0xffff;
87
88    /* Make sure XOSC and PLLs are on in RUN0 state */
89    ME.DRUN_MC.R = 0x001f0074;
90    ME.RUN_MC [0].R = 0x001f0074;
91
92    /*
93     * Make sure all peripherals are active in DRUN and RUN0 state.
94     *
95     * FIXME: This might be optimized to reduce power consumtion.
96     */
97    for (i = 0; i < 8; ++i) {
98      ME_RUN_PC_32B_tag run_pc = { .R = ME.RUN_PC [i].R };
99
100      run_pc.B.DRUN = 1;
101      run_pc.B.RUN0 = 1;
102
103      ME.RUN_PC [i].R = run_pc.R;
104    }
105
106    /* Switch to RUN0 state */
107    ME.MCTL.R = 0x40000000 | mctl_key1;
108    ME.MCTL.R = 0x40000000 | mctl_key2;
109
110    while (ME.GS.B.S_MTRANS) {
111      /* Wait for mode switch to be completed */
112    }
113  #endif
114}
115
116static BSP_START_TEXT_SECTION void mpc55xx_start_siu(void)
117{
118  size_t i = 0;
119
120  #ifdef MPC55XX_BOARD_GWLCFM
121    SIU.GPDO[122].B.PDO=1; /* make sure USB reset is kept high */
122    SIU.GPDO[121].B.PDO=1; /* make sure Ethernet reset is kept high */
123    SIU.GPDO[113].B.PDO=1; /* make sure MOST Companion reset is kept high */
124  #endif
125
126  for (i = 0; i < mpc55xx_start_config_siu_pcr_count [0]; ++i) {
127     const mpc55xx_siu_pcr_config *e = &mpc55xx_start_config_siu_pcr [i];
128     int j = e->index;
129     int n = j + e->count;
130     uint16_t pcr = e->pcr.R;
131
132     while (j < n) {
133       SIU.PCR [j].R = pcr;
134       ++j;
135     }
136  }
137}
138
139static BSP_START_TEXT_SECTION void mpc55xx_start_ebi_chip_select(void)
140{
141  #ifdef MPC55XX_HAS_EBI
142    size_t i = 0;
143
144    for (i = 0; i < mpc55xx_start_config_ebi_cs_count [0]; ++i) {
145       EBI.CS [i] = mpc55xx_start_config_ebi_cs [i];
146    }
147
148    for (i = 0; i < mpc55xx_start_config_ebi_cal_cs_count [0]; ++i) {
149       EBI.CAL_CS [i] = mpc55xx_start_config_ebi_cal_cs [i];
150    }
151  #endif
152}
153
154static BSP_START_TEXT_SECTION void mpc55xx_start_ebi(void)
155{
156  #if defined(MPC55XX_BOARD_GWLCFM)
157    /*
158     * init EBI for Muxed AD bus
159     */
160    EBI.MCR.B.DBM = 1;
161    EBI.MCR.B.AD_MUX = 1; /* use multiplexed bus */
162    EBI.MCR.B.D16_31 = 1; /* use lower AD bus    */
163
164    SIU.ECCR.B.EBDF = 3;  /* use CLK/4 as bus clock */
165  #elif defined(MPC55XX_BOARD_MPC5674FEVB)
166    struct EBI_tag ebi = {
167      .MCR = {
168        .B = {
169          .ACGE = 0,
170          .MDIS = 0,
171          .D16_31 = 0,
172          .AD_MUX = 0,
173          .DBM = 0
174        }
175      }
176    };
177
178    EBI.MCR.R = ebi.MCR.R;
179  #endif
180}
181
182BSP_START_TEXT_SECTION void mpc55xx_start_early(void)
183{
184  mpc55xx_start_watchdog();
185  mpc55xx_start_clock();
186  mpc55xx_start_flash();
187  #if defined(BSP_DATA_CACHE_ENABLED) || defined(BSP_INSTRUCTION_CACHE_ENABLED)
188    mpc55xx_start_cache();
189  #endif
190  mpc55xx_start_internal_ram();
191  mpc55xx_start_load_nocache_section();
192  mpc55xx_start_mmu();
193  mpc55xx_start_mode_change();
194  mpc55xx_start_siu();
195  mpc55xx_start_ebi_chip_select();
196  mpc55xx_start_ebi();
197}
Note: See TracBrowser for help on using the repository browser.