source: rtems/bsps/powerpc/mpc55xxevb/start/start-early.c

Last change on this file was bcef89f2, checked in by Sebastian Huber <sebastian.huber@…>, on 05/19/23 at 06:18:25

Update company name

The embedded brains GmbH & Co. KG is the legal successor of embedded
brains GmbH.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSBSPsPowerPCMPC55XX
7 *
8 * @brief Early initialization code.
9 */
10
11/*
12 * Copyright (C) 2008, 2012 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 *    notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#include <bsp/mpc55xx-config.h>
37#include <bsp/linker-symbols.h>
38
39/* This function is defined in start.S */
40BSP_START_TEXT_SECTION void mpc55xx_start_load_section(
41  void *dst,
42  const void *src,
43  size_t n
44);
45
46static BSP_START_TEXT_SECTION void mpc55xx_start_mmu(void)
47{
48  #ifdef MPC55XX_BOOTFLAGS
49    /* If the low bit of bootflag 0 is clear don't change the MMU.  */
50    bool do_mmu_config = (mpc55xx_bootflag_0 [0] & 1) != 0;
51  #else
52    bool do_mmu_config = true;
53  #endif
54
55  if (do_mmu_config) {
56    mpc55xx_start_mmu_apply_config(
57      &mpc55xx_start_config_mmu [0],
58      mpc55xx_start_config_mmu_count [0]
59    );
60  }
61}
62
63static BSP_START_TEXT_SECTION void mpc55xx_start_internal_ram(void)
64{
65  #ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
66    /* Initialize internal SRAM to zero (ECC) */
67    bsp_start_zero(
68      (char *) bsp_ram_start + MPC55XX_EARLY_STACK_SIZE,
69      (size_t) bsp_ram_size - MPC55XX_EARLY_STACK_SIZE
70    );
71    #ifdef MPC55XX_HAS_SECOND_INTERNAL_RAM_AREA
72      bsp_start_zero(&bsp_ram_1_start [0], (size_t) bsp_ram_1_size);
73    #endif
74  #else
75    bsp_start_zero(
76      bsp_section_sbss_begin,
77      (size_t) bsp_section_sbss_size
78    );
79    bsp_start_zero(
80      bsp_section_bss_begin,
81      (size_t) bsp_section_bss_size
82    );
83  #endif
84}
85
86static BSP_START_TEXT_SECTION void mpc55xx_start_load_nocache_section(void)
87{
88  mpc55xx_start_load_section(
89    bsp_section_nocache_begin,
90    bsp_section_nocache_load_begin,
91    (size_t) bsp_section_nocache_size
92  );
93  rtems_cache_flush_multiple_data_lines(
94    bsp_section_nocache_begin,
95    (size_t) bsp_section_nocache_size
96  );
97}
98
99static BSP_START_TEXT_SECTION void mpc55xx_start_mode_change(void)
100{
101  #ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
102    #ifdef MPC55XX_HAS_MODE_CONTROL
103      uint32_t mctl_key1 = 0x5af0;
104      uint32_t mctl_key2 = 0xa50f;
105      int i = 0;
106
107      /* Clear any pending RGM status */
108      RGM.FES.R = 0xffff;
109      RGM.DES.R = 0xffff;
110
111      /* Make sure XOSC and PLLs are on in RUN0 state */
112      ME.DRUN_MC.R = 0x001f0074;
113      ME.RUN_MC [0].R = 0x001f0074;
114
115      /*
116       * Make sure all peripherals are active in DRUN and RUN0 state.
117       *
118       * FIXME: This might be optimized to reduce power consumtion.
119       */
120      for (i = 0; i < 8; ++i) {
121        ME_RUN_PC_32B_tag run_pc = { .R = ME.RUN_PC [i].R };
122
123        run_pc.B.DRUN = 1;
124        run_pc.B.RUN0 = 1;
125
126        ME.RUN_PC [i].R = run_pc.R;
127      }
128
129      /* Switch to RUN0 state */
130      ME.MCTL.R = 0x40000000 | mctl_key1;
131      ME.MCTL.R = 0x40000000 | mctl_key2;
132
133      while (ME.GS.B.S_MTRANS) {
134        /* Wait for mode switch to be completed */
135      }
136    #endif
137  #endif
138}
139
140static BSP_START_TEXT_SECTION void mpc55xx_start_siu(void)
141{
142  size_t i = 0;
143
144  for (i = 0; i < mpc55xx_start_config_siu_pcr_count [0]; ++i) {
145     const mpc55xx_siu_pcr_config *e = &mpc55xx_start_config_siu_pcr [i];
146     int j = e->index;
147     int n = j + e->count;
148     uint8_t gpdo = e->output;
149     uint16_t pcr = e->pcr.R;
150
151     while (j < n) {
152       SIU.GPDO [j].R = gpdo;
153       SIU.PCR [j].R = pcr;
154       ++j;
155     }
156  }
157}
158
159static BSP_START_TEXT_SECTION void mpc55xx_start_ebi_chip_select(void)
160{
161  #ifdef MPC55XX_HAS_EBI
162    size_t i = 0;
163
164    for (i = 0; i < mpc55xx_start_config_ebi_cs_count [0]; ++i) {
165      EBI.CS [i] = mpc55xx_start_config_ebi_cs [i];
166    }
167
168    for (i = 0; i < mpc55xx_start_config_ebi_cal_cs_count [0]; ++i) {
169      EBI.CAL_CS [i] = mpc55xx_start_config_ebi_cal_cs [i];
170    }
171  #endif
172}
173
174static BSP_START_TEXT_SECTION void mpc55xx_start_ebi(void)
175{
176  #ifdef MPC55XX_HAS_EBI
177    size_t i = 0;
178
179    for (i = 0; i < mpc55xx_start_config_ebi_count [0]; ++i) {
180      SIU.ECCR.B.EBDF = mpc55xx_start_config_ebi [i].siu_eccr_ebdf;
181      EBI.MCR.R = mpc55xx_start_config_ebi [i].ebi_mcr.R;
182    }
183  #endif
184}
185
186#ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
187static BSP_START_TEXT_SECTION bool
188mpc55xx_start_is_in_internal_ram(const void *addr)
189{
190  return (size_t) addr - (size_t) bsp_ram_start < (size_t) bsp_ram_size;
191}
192#endif
193
194static BSP_START_TEXT_SECTION void mpc55xx_start_clear_bss(void)
195{
196  #ifdef MPC55XX_NEEDS_LOW_LEVEL_INIT
197    if (!mpc55xx_start_is_in_internal_ram(bsp_section_sbss_begin)) {
198      bsp_start_zero(
199        bsp_section_sbss_begin,
200        (size_t) bsp_section_sbss_size
201      );
202    }
203
204    if (!mpc55xx_start_is_in_internal_ram(bsp_section_bss_begin)) {
205      bsp_start_zero(
206        bsp_section_bss_begin,
207        (size_t) bsp_section_bss_size
208      );
209    }
210  #endif
211}
212
213BSP_START_TEXT_SECTION void mpc55xx_start_early(void)
214{
215  mpc55xx_start_watchdog();
216  mpc55xx_start_clock();
217  mpc55xx_start_flash();
218  #if defined(BSP_DATA_CACHE_ENABLED) || defined(BSP_INSTRUCTION_CACHE_ENABLED)
219    mpc55xx_start_cache();
220  #endif
221  mpc55xx_start_internal_ram();
222  mpc55xx_start_load_nocache_section();
223  mpc55xx_start_mmu();
224  mpc55xx_start_mode_change();
225  mpc55xx_start_siu();
226  mpc55xx_start_ebi_chip_select();
227  mpc55xx_start_ebi();
228  mpc55xx_start_clear_bss();
229}
Note: See TracBrowser for help on using the repository browser.