source: rtems/c/src/lib/libbsp/m68k/genmcf548x/startup/init548x.c @ 16393b2f

4.104.115
Last change on this file since 16393b2f was 16393b2f, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/03/09 at 13:08:28

2009-11-03 Ralf Corsépius <ralf.corsepius@…>

  • startup/init548x.c: Comment out junk from end of #endif.
  • Property mode set to 100644
File size: 10.2 KB
Line 
1/*===============================================================*\
2| Project: RTEMS generic mcf548x BSP                              |
3+-----------------------------------------------------------------+
4| File: init548x.c                                                |
5+-----------------------------------------------------------------+
6| The file contains the c part of MCF548x init code               |
7+-----------------------------------------------------------------+
8|                    Copyright (c) 2007                           |
9|                    Embedded Brains GmbH                         |
10|                    Obere Lagerstr. 30                           |
11|                    D-82178 Puchheim                             |
12|                    Germany                                      |
13|                    rtems@embedded-brains.de                     |
14+-----------------------------------------------------------------+
15|                                                                 |
16| Parts of the code has been derived from the "dBUG source code"  |
17| package Freescale is providing for M548X EVBs. The usage of     |
18| the modified or unmodified code and it's integration into the   |
19| generic mcf548x BSP has been done according to the Freescale    |
20| license terms.                                                  |
21|                                                                 |
22| The Freescale license terms can be reviewed in the file         |
23|                                                                 |
24|    Freescale_license.txt                                        |
25|                                                                 |
26+-----------------------------------------------------------------+
27|                                                                 |
28| The generic mcf548x BSP has been developed on the basic         |
29| structures and modules of the av5282 BSP.                       |
30|                                                                 |
31+-----------------------------------------------------------------+
32|                                                                 |
33| The license and distribution terms for this file may be         |
34| found in the file LICENSE in this distribution or at            |
35|                                                                 |
36| http://www.rtems.com/license/LICENSE.                           |
37|                                                                 |
38+-----------------------------------------------------------------+
39|                                                                 |
40|   date                      history                        ID   |
41| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
42| 12.11.07                    1.0                            ras  |
43|                                                                 |
44\*===============================================================*/
45
46#include <rtems.h>
47#include <bsp.h>
48
49#if defined(HAS_LOW_LEVEL_INIT)
50#define SYSTEM_PERIOD                   10      /* system bus period in ns */
51
52/* SDRAM Timing Parameters */
53#define SDRAM_TWR                       2               /* in clocks */
54#define SDRAM_CASL                      2.5     /* in clocks */
55#define SDRAM_TRCD                      20              /* in ns */
56#define SDRAM_TRP                       20              /* in ns */
57#define SDRAM_TRFC                      75              /* in ns */
58#define SDRAM_TREFI                     7800    /* in ns */
59#endif /* defined(HAS_LOW_LEVEL_INIT) */
60
61extern uint8_t _DataRom[];
62extern uint8_t _DataRam[];
63extern uint8_t _DataEnd[];
64extern uint8_t _BssStart[];
65extern uint8_t _BssEnd[];
66extern uint8_t _BootFlashBase[];
67extern uint8_t _CodeFlashBase[];
68extern uint8_t RamBase[];
69extern uint32_t InterruptVectorTable[];
70extern uint32_t _VectorRam[];
71
72void gpio_init(void);
73void fbcs_init(void);
74void sdramc_init(void);
75void mcf548x_init(void);
76
77
78void mcf548x_init(void)
79    {
80    uint32_t n;
81    uint8_t *dp, *sp;
82
83#if defined(HAS_LOW_LEVEL_INIT)
84    /* set XLB arbiter timeouts */
85    MCF548X_XLB_ADRTO = 0x00000100;
86    MCF548X_XLB_DATTO = 0x00000100;
87    MCF548X_XLB_BUSTO = 0x00000100;
88#endif
89
90    gpio_init();
91#if defined(HAS_LOW_LEVEL_INIT)
92    fbcs_init();
93    sdramc_init();
94#endif /* defined(HAS_LOW_LEVEL_INIT) */
95
96    /* Copy the vector table to RAM */
97    if (_VectorRam != InterruptVectorTable)
98    {
99        for( n = 0; n < 256; n++)
100          {
101      _VectorRam[n] = InterruptVectorTable[n];
102          }
103    }
104
105    m68k_set_vbr((uint32_t)_VectorRam);
106
107    /* Move initialized data from ROM to RAM. */
108    if (_DataRom != _DataRam)
109    {
110                n = _DataEnd - _DataRam;
111        sp = (uint8_t *)_DataRom;
112        dp = (uint8_t *)_DataRam;
113                while(n--)
114           *dp++ = *sp++;
115     }
116
117    /* Zero uninitialized data */
118    if (_BssStart != _BssEnd)
119    {
120                n = _BssEnd - _BssStart;
121        sp = (uint8_t *)_BssStart;
122        while (n--)
123            *sp++ = 0;
124    }
125
126}
127/********************************************************************/
128#if defined(HAS_LOW_LEVEL_INIT)
129void
130fbcs_init (void)
131{
132#ifdef M5484FIREENGINE
133
134volatile uint32_t cscr, clk_ratio, fb_period, ws;
135
136/* boot flash already valid ? */
137if(!(MCF548X_FBCS_CSMR0 & MCF548X_FBCS_CSMR_V))
138  {
139
140    /*
141     * Boot Flash
142     */
143    MCF548X_FBCS_CSAR0 = MCF548X_FBCS_CSAR_BA((uint32_t)(_BootFlashBase));
144
145    cscr = (0
146            | MCF548X_FBCS_CSCR_ASET(1)
147            | MCF548X_FBCS_CSCR_WRAH(0)
148            | MCF548X_FBCS_CSCR_RDAH(0)
149            | MCF548X_FBCS_CSCR_AA
150            | MCF548X_FBCS_CSCR_PS_16);
151
152    /*
153     * Determine the necessary wait states based on the defined system
154     * period (XLB clock period) and the CLKIN to XLB ratio.
155     * The boot flash has a max access time of 110ns.
156     */
157    clk_ratio = (MCF548X_PCI_PCIGSCR >> 24) & 0x7;
158    fb_period = SYSTEM_PERIOD * clk_ratio;
159    ws = 110 / fb_period;
160
161    MCF548X_FBCS_CSCR0 = cscr | MCF548X_FBCS_CSCR_WS(ws);
162    MCF548X_FBCS_CSMR0 = (0
163                          | MCF548X_FBCS_CSMR_BAM_2M
164                          | MCF548X_FBCS_CSMR_V);
165
166  }
167
168/* code flash already valid ? */
169if(!(MCF548X_FBCS_CSMR1 & MCF548X_FBCS_CSMR_V))
170  {
171
172    /*
173     * Code Flash
174     */
175    MCF548X_FBCS_CSAR1 = MCF548X_FBCS_CSAR_BA((uint32_t)(_CodeFlashBase));
176
177    /*
178     * Determine the necessary wait states based on the defined system
179     * period (XLB clock period) and the CLKIN to XLB ratio.
180     * The user/code flash has a max access time of 120ns.
181     */
182    ws = 120 / fb_period;
183    MCF548X_FBCS_CSCR1 = cscr | MCF548X_FBCS_CSCR_WS(ws);
184    MCF548X_FBCS_CSMR1 = (0
185                          | MCF548X_FBCS_CSMR_BAM_16M
186                          | MCF548X_FBCS_CSMR_V);
187    }
188
189#endif
190}
191#endif /* defined(HAS_LOW_LEVEL_INIT) */
192
193/********************************************************************/
194#if defined(HAS_LOW_LEVEL_INIT)
195void
196sdramc_init (void)
197{
198
199        /*
200         * Check to see if the SDRAM has already been initialized
201         * by a run control tool
202         */
203        if (!(MCF548X_SDRAMC_SDCR & MCF548X_SDRAMC_SDCR_REF))
204        {
205                /*
206         * Basic configuration and initialization
207         */
208                MCF548X_SDRAMC_SDRAMDS = (0
209                        | MCF548X_SDRAMC_SDRAMDS_SB_E(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
210                        | MCF548X_SDRAMC_SDRAMDS_SB_C(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
211                        | MCF548X_SDRAMC_SDRAMDS_SB_A(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
212                        | MCF548X_SDRAMC_SDRAMDS_SB_S(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
213                        | MCF548X_SDRAMC_SDRAMDS_SB_D(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
214            );
215        MCF548X_SDRAMC_CS0CFG = (0
216            | MCF548X_SDRAMC_CSnCFG_CSBA((uint32_t)(RamBase))
217            | MCF548X_SDRAMC_CSnCFG_CSSZ(MCF548X_SDRAMC_CSnCFG_CSSZ_64MBYTE)
218            );
219        MCF548X_SDRAMC_SDCFG1 = (0
220                        | MCF548X_SDRAMC_SDCFG1_SRD2RW(7)
221                        | MCF548X_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1)
222                        | MCF548X_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL*2) + 2))
223                        | MCF548X_SDRAMC_SDCFG1_ACT2RW((int)(((SDRAM_TRCD/SYSTEM_PERIOD) - 1) + 0.5))
224                        | MCF548X_SDRAMC_SDCFG1_PRE2ACT((int)(((SDRAM_TRP/SYSTEM_PERIOD) - 1) + 0.5))
225                        | MCF548X_SDRAMC_SDCFG1_REF2ACT((int)(((SDRAM_TRFC/SYSTEM_PERIOD) - 1) + 0.5))
226                        | MCF548X_SDRAMC_SDCFG1_WTLAT(3)
227            );
228                MCF548X_SDRAMC_SDCFG2 = (0
229                        | MCF548X_SDRAMC_SDCFG2_BRD2PRE(4)
230                        | MCF548X_SDRAMC_SDCFG2_BWT2RW(6)
231                        | MCF548X_SDRAMC_SDCFG2_BRD2WT(7)
232                        | MCF548X_SDRAMC_SDCFG2_BL(7)
233            );
234
235                /*
236         * Precharge and enable write to SDMR
237         */
238        MCF548X_SDRAMC_SDCR = (0
239                        | MCF548X_SDRAMC_SDCR_MODE_EN
240                        | MCF548X_SDRAMC_SDCR_CKE
241                        | MCF548X_SDRAMC_SDCR_DDR
242                        | MCF548X_SDRAMC_SDCR_MUX(1)
243                        | MCF548X_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI/(SYSTEM_PERIOD*64)) - 1) + 0.5))
244                        | MCF548X_SDRAMC_SDCR_IPALL
245            );
246
247                /*
248         * Write extended mode register
249         */
250                MCF548X_SDRAMC_SDMR = (0
251                        | MCF548X_SDRAMC_SDMR_BNKAD_LEMR
252                        | MCF548X_SDRAMC_SDMR_AD(0x0)
253                        | MCF548X_SDRAMC_SDMR_CMD
254            );
255
256                /*
257         * Write mode register and reset DLL
258         */
259                MCF548X_SDRAMC_SDMR = (0
260                        | MCF548X_SDRAMC_SDMR_BNKAD_LMR
261                        | MCF548X_SDRAMC_SDMR_AD(0x163)
262                        | MCF548X_SDRAMC_SDMR_CMD
263            );
264
265                /*
266         * Execute a PALL command
267         */
268                MCF548X_SDRAMC_SDCR |=MCF548X_SDRAMC_SDCR_IPALL;
269
270                /*
271         * Perform two REF cycles
272         */
273                MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF;
274                MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF;
275
276                /*
277         * Write mode register and clear reset DLL
278         */
279                MCF548X_SDRAMC_SDMR = (0
280                        | MCF548X_SDRAMC_SDMR_BNKAD_LMR
281                        | MCF548X_SDRAMC_SDMR_AD(0x063)
282                        | MCF548X_SDRAMC_SDMR_CMD
283            );
284
285                /*
286         * Enable auto refresh and lock SDMR
287         */
288                MCF548X_SDRAMC_SDCR &= ~MCF548X_SDRAMC_SDCR_MODE_EN;
289        MCF548X_SDRAMC_SDCR |= (0
290                        | MCF548X_SDRAMC_SDCR_REF
291                        | MCF548X_SDRAMC_SDCR_DQS_OE(0xF)
292            );
293    }
294
295}
296#endif /* defined(HAS_LOW_LEVEL_INIT) */
297
298/********************************************************************/
299void
300gpio_init(void)
301{
302
303#ifdef M5484FIREENGINE
304
305    /*
306     * Enable Ethernet signals so that, if a cable is plugged into
307     * the ports, the lines won't be floating and potentially cause
308     * erroneous transmissions
309     */
310    MCF548X_GPIO_PAR_FECI2CIRQ = (0
311
312        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDC_EMDC
313        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDIO_EMDIO
314        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MII
315        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E17
316
317        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDC
318        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDIO
319        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MII
320        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E07
321        );
322
323#endif
324}
Note: See TracBrowser for help on using the repository browser.