]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx27/ads/v2_0/src/board_misc.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / hal / arm / mx27 / ads / v2_0 / src / board_misc.c
1 //==========================================================================
2 //
3 //      board_misc.c
4 //
5 //      HAL misc board support code for the board
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 //
13 // eCos is free software; you can redistribute it and/or modify it under
14 // the terms of the GNU General Public License as published by the Free
15 // Software Foundation; either version 2 or (at your option) any later version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //========================================================================*/
41
42 #include <redboot.h>
43 #include <pkgconf/hal.h>
44 #include <pkgconf/system.h>
45 #include CYGBLD_HAL_PLATFORM_H
46
47 #include <cyg/infra/cyg_type.h>         // base types
48 #include <cyg/infra/cyg_trac.h>         // tracing macros
49 #include <cyg/infra/cyg_ass.h>          // assertion macros
50
51 #include <cyg/hal/hal_io.h>             // IO macros
52 #include <cyg/hal/hal_arch.h>           // Register state info
53 #include <cyg/hal/hal_diag.h>
54 #include <cyg/hal/hal_intr.h>           // Interrupt names
55 #include <cyg/hal/hal_cache.h>
56 #include <cyg/hal/hal_soc.h>            // Hardware definitions
57 #include <cyg/hal/fsl_board.h>          // Platform specifics
58
59 #include <cyg/infra/diag.h>             // diag_printf
60
61 // All the MM table layout is here:
62 #include <cyg/hal/hal_mm.h>
63
64 externC void* memset(void *, int, size_t);
65 #define REG_REGULATOR_MODE_1  33
66
67 void hal_mmu_init(void)
68 {
69     unsigned long ttb_base = RAM_BANK0_BASE + 0x4000;
70     unsigned long i;
71
72     /*
73      * Set the TTB register
74      */
75     asm volatile ("mcr  p15,0,%0,c2,c0,0" : : "r"(ttb_base) /*:*/);
76
77     /*
78      * Set the Domain Access Control Register
79      */
80     i = ARM_ACCESS_DACR_DEFAULT;
81     asm volatile ("mcr  p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
82
83     /*
84      * First clear all TT entries - ie Set them to Faulting
85      */
86     memset((void *)ttb_base, 0, ARM_FIRST_LEVEL_PAGE_TABLE_SIZE);
87
88     /*             Actual    Virtual  Size   Attributes                                                    Function  */
89     /*             Base      Base     MB      cached?           buffered?        access permissions                 */
90     /*             xxx00000  xxx00000                                                                                */
91     X_ARM_MMU_SECTION(0x000, 0xF00,   0x001, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* Boot Rom */
92     X_ARM_MMU_SECTION(0x100, 0x100,   0x001, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* Internal Regsisters */
93     X_ARM_MMU_SECTION(0x800, 0x800,   0x001, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CSI/ATA Regsisters */
94     X_ARM_MMU_SECTION(0xA00, 0x000,   0x080, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
95     X_ARM_MMU_SECTION(0xA00, 0xA00,   0x080, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* SDRAM */
96     X_ARM_MMU_SECTION(0xA00, 0xA80,   0x080, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* SDRAM */
97     X_ARM_MMU_SECTION(0xC00, 0xC00,   0x020, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* Flash */
98     X_ARM_MMU_SECTION(0xD40, 0xD40,   0x020, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* CS4 for External I/O */
99     X_ARM_MMU_SECTION(0xD60, 0xD60,   0x020, ARM_CACHEABLE,   ARM_BUFFERABLE,   ARM_ACCESS_PERM_RW_RW); /* CS5 PSRAM */
100     X_ARM_MMU_SECTION(0xD80, 0xD80,   0x100, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* EMI control/PCMCIA */
101     X_ARM_MMU_SECTION(0xFFF, 0xFFF,   0x001, ARM_UNCACHEABLE, ARM_UNBUFFERABLE, ARM_ACCESS_PERM_RW_RW); /* VRAM */
102 }
103
104 //
105 // Platform specific initialization
106 //
107 static void fec_gpio_init(void)
108 {
109         unsigned long addr , val;
110
111         /* PF23 */
112         addr = SOC_GPIOF_BASE;
113         /* OCR2: AIN=0x00 */
114         HAL_READ_UINT32(addr+GPIO_OCR2, val);
115         val = val & (~(0x00000003<<(13)));
116         HAL_WRITE_UINT32(addr+GPIO_OCR2, val);
117
118         /* DDR: OUTPUT */
119         HAL_READ_UINT32(addr+GPIO_DDIR, val);
120         val = val | (0x00000001<<(23));
121         HAL_WRITE_UINT32(addr+GPIO_DDIR, val);
122
123         /* GIUS: GPIO */
124         HAL_READ_UINT32(addr+GPIO_GIUS, val);
125         val = val | (0x00000001<<23);
126         HAL_WRITE_UINT32(addr+GPIO_GIUS, val);
127
128         /* PD16-0*/
129         addr = SOC_GPIOD_BASE;
130         /* PD16 OCR2: AIN=0x00 */
131         HAL_READ_UINT32(addr+GPIO_OCR2, val);
132         val = val & ~0x00000003;
133         HAL_WRITE_UINT32(addr+GPIO_OCR2, val);
134
135         /* PD9, 3-0  OCR1: AIN=0x00 */
136         HAL_READ_UINT32(addr+GPIO_OCR1, val);
137         val = val & ~(0x000C00FF);
138         HAL_WRITE_UINT32(addr+GPIO_OCR1, val);
139
140         /* PD15~10, P7~4  ICONFIGA1: AOUT=0x00 */
141         HAL_READ_UINT32(addr+GPIO_ICONFA1, val);
142         val = val & ~(0xFFF0FF00);
143         HAL_WRITE_UINT32(addr+GPIO_ICONFA1, val);
144
145         /* PD8  GPR: ALT */
146         HAL_READ_UINT32(addr+GPIO_GPR, val);
147         val = val | 0x00000100;
148         HAL_WRITE_UINT32(addr+GPIO_GPR, val);
149
150         /* DDR: OUTPUT */
151         HAL_READ_UINT32(addr+GPIO_DDIR, val);
152         val = (val & 0xFFFE0000) | 0x0001020F;
153         HAL_WRITE_UINT32(addr+GPIO_DDIR, val);
154
155         /* GIUS: GPIO */
156         HAL_READ_UINT32(addr+GPIO_GIUS, val);
157         val = (val & 0xFFFE0000) | 0x0001FEFF;
158         HAL_WRITE_UINT32(addr+GPIO_GIUS, val);
159
160 }
161
162 void fec_cpld_init(void)
163 {
164         unsigned long addr, val;
165
166         addr = PBC_BASE;
167
168         //Select FEC data through data path
169         val = 0x0020;
170         HAL_WRITE_UINT16(addr+0x10, val);
171
172         //Enable CPLD FEC data path
173         val = 0x0010;
174         HAL_WRITE_UINT16(addr+0x14, val);
175 }
176
177 //
178 // Platform specific initialization
179 //
180
181 unsigned int g_clock_src;
182 unsigned int g_board_type = BOARD_TYPE_UNKNOWN;
183
184 void plf_hardware_init(void)
185 {
186     unsigned long val = readl(SOC_CRM_CSCR);
187
188     if ((val & (1 << 16)) != 0) {
189         if ((readw(PBC_BASE + PBC_VERSION) & CLK_INPUT_27MHZ_SET) == 0) {
190             g_clock_src = FREQ_27MHZ;
191         } else {
192             g_clock_src = FREQ_26MHZ;
193         }
194     } else {
195         g_clock_src = FREQ_32768HZ;
196     }
197
198     if ((BOARD_PBC_VERSION & 0x80) != 0) {
199         g_board_type = BOARD_TYPE_ADS;
200     } else {
201         if ((BOARD_PBC_VERSION & 0x40) != 0) {
202             g_board_type = BOARD_TYPE_EVB_B;
203         } else {
204             g_board_type = BOARD_TYPE_EVB_A;
205         }
206     }
207
208     fec_gpio_init();
209     fec_cpld_init();
210 }
211
212 static void board_raise_voltage(void)
213 {
214     unsigned int val = 0, temp = 0;
215 #if defined (CLOCK_399_133_66)
216     /* Increase core voltage to 1.45 */
217     setCoreVoltage(0x16);
218 #endif
219
220     temp = 0x9240;
221     val = (1 << 31) | (REG_REGULATOR_MODE_1 << 25) | (temp & 0x00FFFFFF);
222     /* Enable VCAM */
223     spi_xchg_single(val, PMIC_SPI_BASE);
224 }
225
226 RedBoot_init(board_raise_voltage, RedBoot_INIT_PRIO(101));
227
228 #include CYGHWR_MEMORY_LAYOUT_H
229
230 typedef void code_fun(void);
231
232 void board_program_new_stack(void *func)
233 {
234     register CYG_ADDRESS stack_ptr asm("sp");
235     register CYG_ADDRESS old_stack asm("r4");
236     register code_fun *new_func asm("r0");
237     old_stack = stack_ptr;
238     stack_ptr = CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE - sizeof(CYG_ADDRESS);
239     new_func = (code_fun*)func;
240     new_func();
241     stack_ptr = old_stack;
242 }
243
244 static void display_clock_src(void)
245 {
246     if (g_clock_src == FREQ_27MHZ) {
247         diag_printf("Clock input: 27 MHz");
248     } else if (g_clock_src == FREQ_26MHZ) {
249         diag_printf("Clock input: 26 MHz");
250     } else if (g_clock_src == FREQ_32768HZ) {
251         diag_printf("Clock input: 32KHz");
252     } else {
253         diag_printf("Unknown clock input source. Something is wrong!");
254     }
255 }
256
257 static void display_board_type(void)
258 {
259     if (g_board_type == BOARD_TYPE_ADS) {
260         diag_printf("\nBoard Type: ADS\n");
261     } else if (g_board_type == BOARD_TYPE_EVB_A) {
262         diag_printf("\nBoard Type: EVB [rev A] (external UART doesn't work)\n");
263     } else if (g_board_type == BOARD_TYPE_EVB_B) {
264         diag_printf("\nBoard Type: EVB [rev AA/B]\n");
265     } else {
266         diag_printf("\nBoard Type: Unknown val %d\n", g_board_type);
267     }
268 }
269
270 static void display_board_info(void)
271 {
272     display_board_type();
273     display_clock_src();
274 }
275
276 RedBoot_init(display_board_info, RedBoot_INIT_LAST);
277 // ------------------------------------------------------------------------