source: rtems/c/src/lib/libbsp/m68k/genmcf548x/startup/init548x.c @ 6229b2a7

4.104.115
Last change on this file since 6229b2a7 was 939439d3, checked in by Joel Sherrill <joel.sherrill@…>, on 09/16/08 at 22:16:01

2008-09-16 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, startup/bspstart.c, startup/init548x.c, startup/linkcmds, startup/linkcmds.m5484FireEngine.flash: Use top level shared bsp_get_work_area() implementation.
  • Property mode set to 100644
File size: 10.0 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#define SYSTEM_PERIOD                   10      /* system bus period in ns */
50
51/* SDRAM Timing Parameters */
52#define SDRAM_TWR                       2               /* in clocks */
53#define SDRAM_CASL                      2.5     /* in clocks */
54#define SDRAM_TRCD                      20              /* in ns */
55#define SDRAM_TRP                       20              /* in ns */
56#define SDRAM_TRFC                      75              /* in ns */
57#define SDRAM_TREFI                     7800    /* in ns */
58
59extern uint8_t _DataRom[];
60extern uint8_t _DataRam[];
61extern uint8_t _DataEnd[];
62extern uint8_t _BssStart[];
63extern uint8_t _BssEnd[];
64extern uint8_t _BootFlashBase[];
65extern uint8_t _CodeFlashBase[];
66extern uint8_t RamBase[];
67extern uint32_t InterruptVectorTable[];
68extern uint32_t _VectorRam[];
69
70void gpio_init(void);
71void fbcs_init(void);
72void sdramc_init(void);
73void mcf548x_init(void);
74
75
76void mcf548x_init(void)
77    {
78    uint32_t n;
79    uint8_t *dp, *sp;
80
81    /* set XLB arbiter timeouts */
82#ifdef M5484FIREENGINE
83    /* set XLB arbiter timeouts */
84    MCF548X_XLB_ADRTO = 0x00000100;
85    MCF548X_XLB_DATTO = 0x00000100;
86    MCF548X_XLB_BUSTO = 0x00000100;
87#endif
88
89    gpio_init();
90    fbcs_init();
91    sdramc_init();
92
93    /* Copy the vector table to RAM */
94    if (_VectorRam != InterruptVectorTable)
95    {
96        for( n = 0; n < 256; n++)
97          {
98      _VectorRam[n] = InterruptVectorTable[n];
99          }
100    }
101
102    m68k_set_vbr((uint32_t)_VectorRam);
103
104    /* Move initialized data from ROM to RAM. */
105    if (_DataRom != _DataRam)
106    {
107                n = _DataEnd - _DataRam;
108        sp = (uint8_t *)_DataRom;
109        dp = (uint8_t *)_DataRam;
110                while(n--)
111           *dp++ = *sp++;
112     }
113
114    /* Zero uninitialized data */
115    if (_BssStart != _BssEnd)
116    {
117                n = _BssEnd - _BssStart;
118        sp = (uint8_t *)_BssStart;
119        while (n--)
120            *sp++ = 0;
121    }
122
123}
124/********************************************************************/
125void
126fbcs_init (void)
127{
128#ifdef M5484FIREENGINE
129
130volatile uint32_t cscr, clk_ratio, fb_period, ws;
131
132/* boot flash already valid ? */
133if(!(MCF548X_FBCS_CSMR0 & MCF548X_FBCS_CSMR_V))
134  {
135
136    /*
137     * Boot Flash
138     */
139    MCF548X_FBCS_CSAR0 = MCF548X_FBCS_CSAR_BA((uint32_t)(_BootFlashBase));
140
141    cscr = (0
142            | MCF548X_FBCS_CSCR_ASET(1)
143            | MCF548X_FBCS_CSCR_WRAH(0)
144            | MCF548X_FBCS_CSCR_RDAH(0)
145            | MCF548X_FBCS_CSCR_AA
146            | MCF548X_FBCS_CSCR_PS_16);
147
148    /*
149     * Determine the necessary wait states based on the defined system
150     * period (XLB clock period) and the CLKIN to XLB ratio.
151     * The boot flash has a max access time of 110ns.
152     */
153    clk_ratio = (MCF548X_PCI_PCIGSCR >> 24) & 0x7;
154    fb_period = SYSTEM_PERIOD * clk_ratio;
155    ws = 110 / fb_period;
156
157    MCF548X_FBCS_CSCR0 = cscr | MCF548X_FBCS_CSCR_WS(ws);
158    MCF548X_FBCS_CSMR0 = (0
159                          | MCF548X_FBCS_CSMR_BAM_2M
160                          | MCF548X_FBCS_CSMR_V);
161
162  }
163
164/* code flash already valid ? */
165if(!(MCF548X_FBCS_CSMR1 & MCF548X_FBCS_CSMR_V))
166  {
167
168    /*
169     * Code Flash
170     */
171    MCF548X_FBCS_CSAR1 = MCF548X_FBCS_CSAR_BA((uint32_t)(_CodeFlashBase));
172
173    /*
174     * Determine the necessary wait states based on the defined system
175     * period (XLB clock period) and the CLKIN to XLB ratio.
176     * The user/code flash has a max access time of 120ns.
177     */
178    ws = 120 / fb_period;
179    MCF548X_FBCS_CSCR1 = cscr | MCF548X_FBCS_CSCR_WS(ws);
180    MCF548X_FBCS_CSMR1 = (0
181                          | MCF548X_FBCS_CSMR_BAM_16M
182                          | MCF548X_FBCS_CSMR_V);
183    }
184
185#endif
186}
187
188/********************************************************************/
189void
190sdramc_init (void)
191{
192
193        /*
194         * Check to see if the SDRAM has already been initialized
195         * by a run control tool
196         */
197        if (!(MCF548X_SDRAMC_SDCR & MCF548X_SDRAMC_SDCR_REF))
198        {
199                /*
200         * Basic configuration and initialization
201         */
202                MCF548X_SDRAMC_SDRAMDS = (0
203                        | MCF548X_SDRAMC_SDRAMDS_SB_E(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
204                        | MCF548X_SDRAMC_SDRAMDS_SB_C(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
205                        | MCF548X_SDRAMC_SDRAMDS_SB_A(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
206                        | MCF548X_SDRAMC_SDRAMDS_SB_S(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
207                        | MCF548X_SDRAMC_SDRAMDS_SB_D(MCF548X_SDRAMC_SDRAMDS_DRIVE_8MA)
208            );
209        MCF548X_SDRAMC_CS0CFG = (0
210            | MCF548X_SDRAMC_CSnCFG_CSBA((uint32_t)(RamBase))
211            | MCF548X_SDRAMC_CSnCFG_CSSZ(MCF548X_SDRAMC_CSnCFG_CSSZ_64MBYTE)
212            );
213        MCF548X_SDRAMC_SDCFG1 = (0
214                        | MCF548X_SDRAMC_SDCFG1_SRD2RW(7)
215                        | MCF548X_SDRAMC_SDCFG1_SWT2RD(SDRAM_TWR + 1)
216                        | MCF548X_SDRAMC_SDCFG1_RDLAT((int)((SDRAM_CASL*2) + 2))
217                        | MCF548X_SDRAMC_SDCFG1_ACT2RW((int)(((SDRAM_TRCD/SYSTEM_PERIOD) - 1) + 0.5))
218                        | MCF548X_SDRAMC_SDCFG1_PRE2ACT((int)(((SDRAM_TRP/SYSTEM_PERIOD) - 1) + 0.5))
219                        | MCF548X_SDRAMC_SDCFG1_REF2ACT((int)(((SDRAM_TRFC/SYSTEM_PERIOD) - 1) + 0.5))
220                        | MCF548X_SDRAMC_SDCFG1_WTLAT(3)
221            );
222                MCF548X_SDRAMC_SDCFG2 = (0
223                        | MCF548X_SDRAMC_SDCFG2_BRD2PRE(4)
224                        | MCF548X_SDRAMC_SDCFG2_BWT2RW(6)
225                        | MCF548X_SDRAMC_SDCFG2_BRD2WT(7)
226                        | MCF548X_SDRAMC_SDCFG2_BL(7)
227            );
228
229                /*
230         * Precharge and enable write to SDMR
231         */
232        MCF548X_SDRAMC_SDCR = (0
233                        | MCF548X_SDRAMC_SDCR_MODE_EN
234                        | MCF548X_SDRAMC_SDCR_CKE
235                        | MCF548X_SDRAMC_SDCR_DDR
236                        | MCF548X_SDRAMC_SDCR_MUX(1)
237                        | MCF548X_SDRAMC_SDCR_RCNT((int)(((SDRAM_TREFI/(SYSTEM_PERIOD*64)) - 1) + 0.5))
238                        | MCF548X_SDRAMC_SDCR_IPALL
239            );
240
241                /*
242         * Write extended mode register
243         */
244                MCF548X_SDRAMC_SDMR = (0
245                        | MCF548X_SDRAMC_SDMR_BNKAD_LEMR
246                        | MCF548X_SDRAMC_SDMR_AD(0x0)
247                        | MCF548X_SDRAMC_SDMR_CMD
248            );
249
250                /*
251         * Write mode register and reset DLL
252         */
253                MCF548X_SDRAMC_SDMR = (0
254                        | MCF548X_SDRAMC_SDMR_BNKAD_LMR
255                        | MCF548X_SDRAMC_SDMR_AD(0x163)
256                        | MCF548X_SDRAMC_SDMR_CMD
257            );
258
259                /*
260         * Execute a PALL command
261         */
262                MCF548X_SDRAMC_SDCR |=MCF548X_SDRAMC_SDCR_IPALL;
263
264                /*
265         * Perform two REF cycles
266         */
267                MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF;
268                MCF548X_SDRAMC_SDCR |= MCF548X_SDRAMC_SDCR_IREF;
269
270                /*
271         * Write mode register and clear reset DLL
272         */
273                MCF548X_SDRAMC_SDMR = (0
274                        | MCF548X_SDRAMC_SDMR_BNKAD_LMR
275                        | MCF548X_SDRAMC_SDMR_AD(0x063)
276                        | MCF548X_SDRAMC_SDMR_CMD
277            );
278
279                /*
280         * Enable auto refresh and lock SDMR
281         */
282                MCF548X_SDRAMC_SDCR &= ~MCF548X_SDRAMC_SDCR_MODE_EN;
283        MCF548X_SDRAMC_SDCR |= (0
284                        | MCF548X_SDRAMC_SDCR_REF
285                        | MCF548X_SDRAMC_SDCR_DQS_OE(0xF)
286            );
287    }
288
289}
290
291/********************************************************************/
292void
293gpio_init(void)
294{
295
296#ifdef M5484FIREENGINE
297
298    /*
299     * Enable Ethernet signals so that, if a cable is plugged into
300     * the ports, the lines won't be floating and potentially cause
301     * erroneous transmissions
302     */
303    MCF548X_GPIO_PAR_FECI2CIRQ = (0
304        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDC_EMDC
305        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MDIO_EMDIO
306        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E1MII
307        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E17
308        );
309    MCF548X_GPIO_PAR_FECI2CIRQ = (0
310        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDC
311        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MDIO
312        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E0MII
313        | MCF548X_GPIO_PAR_FECI2CIRQ_PAR_E07
314        );
315
316#endif
317}
Note: See TracBrowser for help on using the repository browser.