]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/mx51/var/v2_0/src/soc_misc.c
Merge branch 'master' of git+ssh://git.kernelconcepts.de/karo-tx-redboot
[karo-tx-redboot.git] / packages / hal / arm / mx51 / var / v2_0 / src / soc_misc.c
1 //==========================================================================
2 //
3 //      soc_misc.c
4 //
5 //      HAL misc board support code
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_misc.h>                   // Size constants
52 #include <cyg/hal/hal_io.h>                             // IO macros
53 #include <cyg/hal/hal_arch.h>                   // Register state info
54 #include <cyg/hal/hal_diag.h>
55 #include <cyg/hal/hal_intr.h>                   // Interrupt names
56 #include <cyg/hal/hal_cache.h>                  // Cache control
57 #include <cyg/hal/hal_soc.h>                    // Hardware definitions
58 #include <cyg/hal/hal_mm.h>                             // MMap table definitions
59 #include <cyg/infra/diag.h>                             // diag_printf
60 #ifdef MXCFLASH_SELECT_NAND
61 #include <cyg/io/imx_nfc.h>
62 #endif
63
64 // Most initialization has already been done before we get here.
65 // All we do here is set up the interrupt environment.
66 // FIXME: some of the stuff in hal_platform_setup could be moved here.
67
68 int _mxc_fis;
69
70 /*
71  * System_rev will have the following format
72  * 31-12 = part # (0x31, 0x32, 0x27, 0x91131, 0x91321, etc)
73  * 11-8 = unused
74  * 7-4 = major (1.y)
75  * 3-0 = minor (x.0)
76  */
77 unsigned int system_rev = CHIP_REV_1_0;
78 static int find_correct_chip;
79
80 #define SBMR_BT_MEM_CTL_SHIFT           0
81 #define SBMR_BT_MEM_CTL_MASK            (3 << SBMR_BT_MEM_CTL_SHIFT)
82 #define SBMR_BT_MEM_CTL(r)                      (((r) & SBMR_BT_MEM_CTL_MASK) >> SBMR_BT_MEM_CTL_SHIFT)
83 #define SBMR_BT_BUS_WIDTH_SHIFT         2
84 #define SBMR_BT_BUS_WIDTH_MASK          (1 << SBMR_BT_BUS_WIDTH_SHIFT)
85 #define SBMR_BT_BUS_WIDTH(r)            (((r) & SBMR_BT_BUS_WIDTH_MASK) >> SBMR_BT_BUS_WIDTH_SHIFT)
86 #define SBMR_BT_PAGE_SIZE_SHIFT         3
87 #define SBMR_BT_PAGE_SIZE_MASK          (3 << SBMR_BT_PAGE_SIZE_SHIFT)
88 #define SBMR_BT_PAGE_SIZE(r)            (((r) & SBMR_BT_PAGE_SIZE_MASK) >> SBMR_BT_PAGE_SIZE_SHIFT)
89 #define SBMR_BT_SPARE_SIZE_SHIFT        6
90 #define SBMR_BT_SPARE_SIZE_MASK         (1 << SBMR_BT_SPARE_SIZE_SHIFT)
91 #define SBMR_BT_SPARE_SIZE(r)           (((r) & SBMR_BT_SPARE_SIZE_MASK) >> SBMR_BT_SPARE_SIZE_SHIFT)
92 #define SBMR_BT_MEM_TYPE_SHIFT          7
93 #define SBMR_BT_MEM_TYPE_MASK           (3 << SBMR_BT_MEM_TYPE_SHIFT)
94 #define SBMR_BT_MEM_TYPE(r)                     (((r) & SBMR_BT_MEM_TYPE_MASK) >> SBMR_BT_MEM_TYPE_SHIFT)
95 #define SBMR_BT_MLC_SEL_SHIFT           10
96 #define SBMR_BT_MLC_SEL_MASK            (1 << SBMR_BT_MLC_SEL_SHIFT)
97 #define SBMR_BT_MLC_SEL(r)                      (((r) & SBMR_BT_MLC_SEL_MASK) >> SBMR_BT_MLC_SEL_SHIFT)
98 //#define SBMR_BT_USB_SRC_0_SHIFT       11
99 //#define SBMR_BT_USB_SRC_0_MASK        (1 << ) /* reserved in Ref. Manual *SBMR_BT_USB_SRC_0_SHIFT/
100 //#define SBMR_BT_USB_SRC_0(r)          (((r) & SBMR_BT_USB_SRC_0_MASK) >> SBMR_BT_USB_SRC_0_SHIFT)
101 #ifdef UNUSED
102 #define SBMR_BT_EEPROM_CFG_SHIFT        12
103 #define SBMR_BT_EEPROM_CFG_MASK         (1 << SBMR_BT_EEPROM_CFG_SHIFT)
104 #define SBMR_BT_EEPROM_CFG(r)           (((r) & SBMR_BT_EEPROM_CFG_MASK) >> SBMR_BT_EEPROM_CFG_SHIFT)
105 #endif
106 #define SBMR_DIR_BT_DIS_SHIFT           13
107 #define SBMR_DIR_BT_DIS_MASK            (1 << SBMR_DIR_BT_DIS_SHIFT)
108 #define SBMR_DIR_BT_DIS(r)                      (((r) & SBMR_DIR_BT_DIS_MASK) >> SBMR_DIR_BT_DIS_SHIFT)
109 #define SBMR_BMOD_SHIFT                         14
110 #define SBMR_BMOD_MASK                          (3 << SBMR_BMOD_SHIFT)
111 #define SBMR_BMOD(r)                            (((r) & SBMR_BMOD_MASK) >> SBMR_BMOD_SHIFT)
112 #define SBMR_BT_WEIM_MUXED_SHIFT        16
113 #define SBMR_BT_WEIM_MUXED_MASK         (3 << SBMR_BT_WEIM_MUXED_SHIFT)
114 #ifdef UNUSED
115 #define SBMR_BT_WEIM_MUXED(r)           (((r) & SBMR_BT_WEIM_MUXED_MASK) >> SBMR_BT_WEIM_MUXED_SHIFT)
116 #define SBMR_BT_LPB_EN_SHIFT            18
117 #define SBMR_BT_LPB_EN_MASK                     (1 << SBMR_BT_LPB_EN_SHIFT)
118 #define SBMR_BT_LPB_EN(r)                       (((r) & SBMR_BT_LPB_EN_MASK) >> SBMR_BT_LPB_EN_SHIFT)
119 #endif
120 #define SBMR_BT_SDMMC_SRC_SHIFT         19
121 #define SBMR_BT_SDMMC_SRC_MASK          (3 << SBMR_BT_SDMMC_SRC_SHIFT)
122 #define SBMR_BT_SDMMC_SRC(r)            (((r) & SBMR_BT_SDMMC_SRC_MASK) >> SBMR_BT_SDMMC_SRC_SHIFT)
123 #ifdef UNUSED
124 #define SBMR_BT_OSC_FREQ_SEL_SHIFT      21
125 #define SBMR_BT_OSC_FREQ_SEL_MASK       (3 << SBMR_BT_OSC_FREQ_SEL_SHIFT)
126 #define SBMR_BT_OSC_FREQ_SEL(r)         (((r) & SBMR_BT_OSC_FREQ_SEL_MASK) >> SBMR_BT_OSC_FREQ_SEL_SHIFT)
127 #define SBMR_BT_LPB_SHIFT                       23
128 #define SBMR_BT_LPB_MASK                        (3 << SBMR_BT_LPB_SHIFT)
129 #define SBMR_BT_LPB(r)                          (((r) & SBMR_BT_LPB_MASK) >> SBMR_BT_LPB_SHIFT)
130 #define SBMR_BT_UART_SRC_SHIFT          25
131 #define SBMR_BT_UART_SRC_MASK           (3 << SBMR_BT_UART_SRC_SHIFT)
132 #define SBMR_BT_UART_SRC(r)                     (((r) & SBMR_BT_UART_SRC_MASK) >> SBMR_BT_UART_SRC_SHIFT)
133 #define SBMR_BT_USB_SRC_SHIFT           27
134 #define SBMR_BT_USB_SRC_MASK            (3 << SBMR_BT_USB_SRC_SHIFT)
135 #define SBMR_BT_USB_SRC(r)                      (((r) & SBMR_BT_USB_SRC_MASK) >> SBMR_BT_USB_SRC_SHIFT)
136 #define SBMR_BT_HPN_EN_SHIFT            28
137 #define SBMR_BT_HPN_EN_MASK                     (1 << SBMR_BT_HPN_EN_SHIFT)
138 #define SBMR_BT_HPN_EN(r)                       (((r) & SBMR_BT_HPN_EN_MASK) >> SBMR_BT_HPN_EN_SHIFT)
139 #define SBMR_BT_LPB_FREQ_SHIFT          29
140 #define SBMR_BT_LPB_FREQ_MASK           (7 << SBMR_BT_LPB_FREQ_SHIFT)
141 #define SBMR_BT_LPB_FREQ(r)                     (((r) & SBMR_BT_LPB_FREQ_MASK) >> SBMR_BT_LPB_FREQ_SHIFT)
142 #endif
143
144 /*
145  * This functions reads the IIM module and returns the system revision number.
146  * It returns the IIM silicon revision reg value if valid product rev is found.
147  . Otherwise, it returns -1.
148  */
149 static int read_system_rev(void)
150 {
151         int val;
152         int *rom_id_address;
153
154         rom_id_address = (int *)((unsigned long)ROM_BASE_ADDR_VIRT + ROM_SI_REV_OFFSET);
155
156         val = readl(IIM_BASE_ADDR + IIM_PREV_OFF);
157
158         system_rev = 0x51 << PART_NUMBER_OFFSET; /* For MX51 Platform*/
159
160         /* Now try to retrieve the silicon rev from IIM's SREV register */
161         return *rom_id_address;
162 }
163
164 #ifdef MXCFLASH_SELECT_NAND
165 unsigned int mxc_nfc_soc_setup(unsigned int pg_sz, unsigned int io_sz,
166                                                         unsigned int is_mlc, unsigned int num_of_chips);
167 extern nfc_setup_func_t *nfc_setup;
168 #endif
169
170 #ifdef MXCFLASH_SELECT_MMC
171 //extern mxc_mmc_check_sdhc_boot_slot *check_sdhc_slot;
172 #endif
173
174 int mxc_check_sdhc_boot_slot(unsigned int port, unsigned int *sdhc_addr);
175
176 void hal_hardware_init(void)
177 {
178         int ver = read_system_rev();
179         unsigned int i;
180 #ifndef CYGPKG_HAL_ARM_TX51KARO
181         unsigned int sbmr = readl(SRC_BASE_ADDR + 0x4);
182         unsigned int *fis_addr = (unsigned int *)IRAM_BASE_ADDR;
183
184         switch (*fis_addr) {
185         case FROM_MMC_FLASH:
186                 _mxc_fis = FROM_MMC_FLASH;
187                 break;
188         case FROM_NAND_FLASH:
189                 _mxc_fis = FROM_NAND_FLASH;
190                 break;
191         case FROM_SPI_NOR_FLASH:
192                 _mxc_fis = FROM_SPI_NOR_FLASH;
193                 break;
194         default:
195                 if (SBMR_BT_MEM_CTL(sbmr) == 0x3) {
196                         if (SBMR_BT_MEM_TYPE(sbmr) == 0) {
197                                 _mxc_fis = MMC_FLASH_BOOT;
198                                 *fis_addr = FROM_MMC_FLASH;
199                         } else if (SBMR_BT_MEM_TYPE(sbmr) == 3) {
200                                 _mxc_fis = SPI_NOR_FLASH_BOOT;
201                                 *fis_addr = FROM_SPI_NOR_FLASH;
202                         }
203                 } else if (SBMR_BT_MEM_CTL(sbmr) == 1) {
204                         _mxc_fis = NAND_FLASH_BOOT;
205                         *fis_addr = FROM_NAND_FLASH;
206                 }
207         }
208 #else
209         _mxc_fis = FROM_NAND_FLASH;
210 #endif
211
212         find_correct_chip = ver;
213
214         if (ver != CHIP_VERSION_NONE) {
215                 /* Valid product revision found. Check actual silicon rev from the ROM code. */
216                 if (ver == 0x1) {
217                         HAL_PLATFORM_EXTRA[5] = '1';
218                         HAL_PLATFORM_EXTRA[7] = '0';
219                         system_rev |= 1 << MAJOR_NUMBER_OFFSET; /*Major Number*/
220                         system_rev |= 0 << MINOR_NUMBER_OFFSET; /*Minor Number*/
221                 } else if (ver == 0x2) {
222                         HAL_PLATFORM_EXTRA[5] = '1';
223                         HAL_PLATFORM_EXTRA[7] = '1';
224                         system_rev |= 1 << MAJOR_NUMBER_OFFSET; /*Major Number*/
225                         system_rev |= 1 << MINOR_NUMBER_OFFSET; /*Minor Number*/
226                 } else if (ver == 0x10) {
227                         HAL_PLATFORM_EXTRA[5] = '2';
228                         HAL_PLATFORM_EXTRA[7] = '0';
229                         system_rev |= 2 << MAJOR_NUMBER_OFFSET; /*Major Number*/
230                         system_rev |= 0 << MINOR_NUMBER_OFFSET; /*Minor Number*/
231                 } else if (ver == 0x20) {
232                         HAL_PLATFORM_EXTRA[5] = '3';
233                         HAL_PLATFORM_EXTRA[7] = '0';
234                         system_rev |= 3 << MAJOR_NUMBER_OFFSET; /*Major Number*/
235                         system_rev |= 0 << MINOR_NUMBER_OFFSET; /*Minor Number*/
236                 } else {
237                         HAL_PLATFORM_EXTRA[5] = 'x';
238                         HAL_PLATFORM_EXTRA[7] = 'x';
239                         system_rev |= 3 << MAJOR_NUMBER_OFFSET; /*Major Number*/
240                         system_rev |= 0 << MINOR_NUMBER_OFFSET; /*Minor Number*/
241                         find_correct_chip = CHIP_VERSION_UNKNOWN;
242                 }
243
244         }
245         // Enable caches
246 #ifdef CYGSEM_HAL_ENABLE_ICACHE_ON_STARTUP
247         HAL_ICACHE_ENABLE();
248 #endif
249 #ifdef CYGSEM_HAL_ENABLE_DCACHE_ON_STARTUP
250         HAL_DCACHE_ENABLE();
251 #endif
252
253         // enable EPIT and start it with 32KHz input clock
254         writel(0x00010000, EPIT_BASE_ADDR + EPITCR);
255
256         // make sure reset is complete
257         while ((readl(EPIT_BASE_ADDR + EPITCR) & 0x10000) != 0) {
258         }
259
260         writel(0x030E0002, EPIT_BASE_ADDR + EPITCR);
261         writel(0x030E0003, EPIT_BASE_ADDR + EPITCR);
262
263         writel(0, EPIT_BASE_ADDR + EPITCMPR);  // always compare with 0
264
265         if ((readw(WDOG_BASE_ADDR) & 4) != 0) {
266                 // increase the WDOG timeout value to the max
267                 writew(readw(WDOG_BASE_ADDR) | 0xFF00, WDOG_BASE_ADDR);
268         }
269
270         // Perform any platform specific initializations
271         plf_hardware_init();
272
273         // Set up eCos/ROM interfaces
274         hal_if_init();
275
276         // initial NAND setup
277         writel(0xFFFF0000, UNLOCK_BLK_ADD0_REG);
278         writel(0xFFFF0000, UNLOCK_BLK_ADD1_REG);
279         writel(0xFFFF0000, UNLOCK_BLK_ADD2_REG);
280         writel(0xFFFF0000, UNLOCK_BLK_ADD3_REG);
281         writel(0xFFFF0000, UNLOCK_BLK_ADD4_REG);
282         writel(0xFFFF0000, UNLOCK_BLK_ADD5_REG);
283         writel(0xFFFF0000, UNLOCK_BLK_ADD6_REG);
284         writel(0xFFFF0000, UNLOCK_BLK_ADD7_REG);
285
286         // unlock all the CS's
287         for (i = 0; i < 8; i++) {
288                 writel(0x84 | (i << 3), NFC_WR_PROT_REG);
289         }
290         writel(0, NFC_IPC_REG);
291 #ifdef MXCFLASH_SELECT_NAND
292         nfc_setup = mxc_nfc_soc_setup;
293 #endif
294 }
295
296 // -------------------------------------------------------------------------
297 void hal_clock_initialize(cyg_uint32 period)
298 {
299 }
300
301 // This routine is called during a clock interrupt.
302
303 // Define this if you want to ensure that the clock is perfect (i.e. does
304 // not drift).  One reason to leave it turned off is that it costs some
305 // us per system clock interrupt for this maintenance.
306 #undef COMPENSATE_FOR_CLOCK_DRIFT
307
308 void hal_clock_reset(cyg_uint32 vector, cyg_uint32 period)
309 {
310 }
311
312 // Read the current value of the clock, returning the number of hardware
313 // "ticks" that have occurred (i.e. how far away the current value is from
314 // the start)
315
316 // Note: The "contract" for this function is that the value is the number
317 // of hardware clocks that have happened since the last interrupt (i.e.
318 // when it was reset).  This value is used to measure interrupt latencies.
319 // However, since the hardware counter runs freely, this routine computes
320 // the difference between the current clock period and the number of hardware
321 // ticks left before the next timer interrupt.
322 void hal_clock_read(cyg_uint32 *pvalue)
323 {
324 }
325
326 // This is to cope with the test read used by tm_basic with
327 // CYGVAR_KERNEL_COUNTERS_CLOCK_LATENCY defined; we read the count ASAP
328 // in the ISR, *before* resetting the clock.  Which returns 1tick +
329 // latency if we just use plain hal_clock_read().
330 void hal_clock_latency(cyg_uint32 *pvalue)
331 {
332 }
333
334 unsigned int hal_timer_count(void)
335 {
336         return (0xFFFFFFFF - readl(EPIT_BASE_ADDR + EPITCNR));
337 }
338
339 #define WDT_MAGIC_1                             0x5555
340 #define WDT_MAGIC_2                             0xAAAA
341 #define MXC_WDT_WSR                             0x2
342
343 unsigned int i2c_base_addr[] = {
344         I2C_BASE_ADDR,
345         I2C2_BASE_ADDR,
346 };
347 unsigned int i2c_num = 2;
348
349 static unsigned int led_on = 0;
350 //
351 // Delay for some number of micro-seconds
352 //
353 void hal_delay_us(unsigned int usecs)
354 {
355         /*
356          * This causes overflow.
357          * unsigned int delayCount = (usecs * 32768) / 1000000;
358          * So use the following one instead
359          */
360         unsigned int delayCount = (usecs * 512) / 15625;
361
362         // issue the service sequence instructions
363         if ((readw(WDOG_BASE_ADDR) & 4) != 0) {
364                 writew(WDT_MAGIC_1, WDOG_BASE_ADDR + MXC_WDT_WSR);
365                 writew(WDT_MAGIC_2, WDOG_BASE_ADDR + MXC_WDT_WSR);
366         }
367
368         if (delayCount == 0) {
369                 return;
370         }
371
372         writel(0x01, EPIT_BASE_ADDR + EPITSR); // clear the compare status bit
373
374         writel(delayCount, EPIT_BASE_ADDR + EPITLR);
375
376         while ((0x1 & readl(EPIT_BASE_ADDR + EPITSR)) == 0); // wait until compare bit is set
377         if ((++led_on % 3000) == 0)
378                 BOARD_DEBUG_LED(0);
379 }
380
381 // -------------------------------------------------------------------------
382
383 // This routine is called to respond to a hardware interrupt (IRQ).  It
384 // should interrogate the hardware and return the IRQ vector number.
385 int hal_IRQ_handler(void)
386 {
387 #ifdef HAL_EXTENDED_IRQ_HANDLER
388         cyg_uint32 index;
389
390         // Use platform specific IRQ handler, if defined
391         // Note: this macro should do a 'return' with the appropriate
392         // interrupt number if such an extended interrupt exists.  The
393         // assumption is that the line after the macro starts 'normal' processing.
394         HAL_EXTENDED_IRQ_HANDLER(index);
395 #endif
396
397         return CYGNUM_HAL_INTERRUPT_NONE; // This shouldn't happen!
398 }
399
400 //
401 // Interrupt control
402 //
403
404 void hal_interrupt_mask(int vector)
405 {
406 //    diag_printf("6hal_interrupt_mask(vector=%d) \n", vector);
407 #ifdef HAL_EXTENDED_INTERRUPT_MASK
408         // Use platform specific handling, if defined
409         // Note: this macro should do a 'return' for "extended" values of 'vector'
410         // Normal vectors are handled by code subsequent to the macro call.
411         HAL_EXTENDED_INTERRUPT_MASK(vector);
412 #endif
413 }
414
415 void hal_interrupt_unmask(int vector)
416 {
417 //    diag_printf("7hal_interrupt_unmask(vector=%d) \n", vector);
418
419 #ifdef HAL_EXTENDED_INTERRUPT_UNMASK
420         // Use platform specific handling, if defined
421         // Note: this macro should do a 'return' for "extended" values of 'vector'
422         // Normal vectors are handled by code subsequent to the macro call.
423         HAL_EXTENDED_INTERRUPT_UNMASK(vector);
424 #endif
425 }
426
427 void hal_interrupt_acknowledge(int vector)
428 {
429
430 //    diag_printf("8hal_interrupt_acknowledge(vector=%d) \n", vector);
431 #ifdef HAL_EXTENDED_INTERRUPT_UNMASK
432         // Use platform specific handling, if defined
433         // Note: this macro should do a 'return' for "extended" values of 'vector'
434         // Normal vectors are handled by code subsequent to the macro call.
435         HAL_EXTENDED_INTERRUPT_ACKNOWLEDGE(vector);
436 #endif
437 }
438
439 void hal_interrupt_configure(int vector, int level, int up)
440 {
441
442 #ifdef HAL_EXTENDED_INTERRUPT_CONFIGURE
443         // Use platform specific handling, if defined
444         // Note: this macro should do a 'return' for "extended" values of 'vector'
445         // Normal vectors are handled by code subsequent to the macro call.
446         HAL_EXTENDED_INTERRUPT_CONFIGURE(vector, level, up);
447 #endif
448 }
449
450 void hal_interrupt_set_level(int vector, int level)
451 {
452
453 #ifdef HAL_EXTENDED_INTERRUPT_SET_LEVEL
454         // Use platform specific handling, if defined
455         // Note: this macro should do a 'return' for "extended" values of 'vector'
456         // Normal vectors are handled by code subsequent to the macro call.
457         HAL_EXTENDED_INTERRUPT_SET_LEVEL(vector, level);
458 #endif
459
460         // Interrupt priorities are not configurable.
461 }
462
463 #ifdef MXCFLASH_SELECT_NAND
464 unsigned int mxc_nfc_soc_setup(unsigned int pg_sz, unsigned int io_sz,
465                                                         unsigned int is_mlc, unsigned int num_of_chips)
466 {
467         unsigned int src_scr_reg;
468         unsigned int tmp;
469
470         tmp = readl(NFC_FLASH_CONFIG2_REG);
471         /* Set the ST_CMD to be 0x70 for all NAND devices */
472         tmp &= ~(0xFF << 24);
473         tmp |= (0x70 << 24);
474 #ifndef CYGPKG_HAL_ARM_TX51KARO
475         /* Set the Spare size */
476         tmp &= ~(0xFF << 16);
477         //tmp |= (((flash_params->spare_size & 0xFF) / 2) << 16);
478         tmp |= (64 / 2) << 16;
479 #else
480         tmp = (tmp & ~(0xff << 16)) | ((64 / 2) << 16);
481 #endif
482         /* Set the Page Size */
483         tmp &= ~(0x3);
484         switch (pg_sz) {
485         case 512:
486                 tmp |= 0x0;
487                 break;
488         case 2048:
489                 tmp |= 0x1;
490                 break;
491         case 4096:
492         default:
493                 tmp |= 0x2;
494                 break;
495         }
496 #ifndef CYGPKG_HAL_ARM_TX51KARO
497         /* Set ECC mode */
498 #if 0
499         if (flash_params->spare_size >= 218) {
500                 /* Use 8-bit ECC */
501                 tmp |= (0x1 << 6);
502         } else {
503                 tmp &= ~(0x1 << 6);
504         }
505 #else
506         tmp = (tmp & ~(1 << 6)) | (0 << 6);
507 #endif
508 #else
509         tmp = (tmp & ~(1 << 6)) | (0 << 6);
510 #endif
511 #ifndef CYGPKG_HAL_ARM_TX51KARO
512         /* Pages per block */
513         tmp &= ~(0x3 << 7);
514 #if 0
515         switch (flash_params->pages_per_block) {
516         case 32:
517                 tmp |= 0x0;
518                 break;
519         case 64:
520                 tmp |= (0x1 << 7);
521                 break;
522         case 128:
523                 tmp |= (0x2 << 7);
524                 break;
525         case 256:
526         default:
527                 tmp |= (0x3 << 7);
528                 break;
529         }
530 #else
531         tmp = (tmp & ~(3 << 7)) | (1 << 7);
532 #endif
533 #else
534         tmp = (tmp & ~(3 << 7)) | (1 << 7);
535 #endif
536         /* Set the number of phase bits & ECC enable bit to default value */
537         tmp &= ~(0x3 << 12);
538         tmp |= 0x2038;
539         writel(tmp, NFC_FLASH_CONFIG2_REG);
540
541         tmp = readl(NFC_FLASH_CONFIG3_REG);
542         /* Set the No SDMA bit */
543         tmp |= (0x1 << 20);
544         /* Set the Status Busy Bit to 0x6 (default) */
545         tmp &= ~(0x7 << 8);
546         tmp |= (0x6 << 8);
547         /* Set the Flash Width */
548         if (io_sz == MXC_NAND_16_BIT) {
549                 tmp &= ~(1 << 3);
550         } else {
551                 tmp |= 1 << 3;
552         }
553         /* Set the Number of Nand Chips */
554         tmp &= ~(0x7 << 12);
555         tmp |= ((num_of_chips - 1) << 12);
556         if (num_of_chips > 1)
557                 tmp |= 0x1;
558         writel(tmp, NFC_FLASH_CONFIG3_REG);
559
560         if (((system_rev >> MAJOR_NUMBER_OFFSET) & 0xf) <= 0x2) {
561                 unsigned int sbmr = readl(SRC_BASE_ADDR + 0x4);
562
563                 /* This issue is fixed in MX51 TO 3.0 */
564                 /* Workaround to disable WARM RESET when booting from interleaved NAND devices */
565                 if ((num_of_chips > 1) && (SBMR_BT_MEM_CTL(sbmr) == 1)) {
566                         diag_printf("%s: Disabling WARM reset due to boot from interleaved NAND\n", __FUNCTION__);
567                         src_scr_reg = readl(SRC_BASE_ADDR);
568                         src_scr_reg &= ~0x1;
569                         writel(src_scr_reg, SRC_BASE_ADDR);
570                 }
571         }
572
573         return MXC_NFC_V3;
574 }
575 #endif
576
577 static void show_sys_info(void)
578 {
579         cyg_uint32 sbmr = readl(SRC_BASE_ADDR + 0x4);
580         cyg_uint32 srsr = readl(SRC_BASE_ADDR + 0x8);
581         const char *dlm = "";
582
583         if (find_correct_chip == CHIP_VERSION_UNKNOWN) {
584                 diag_printf("Unrecognized chip version: 0x%08x!!!\n", read_system_rev());
585                 diag_printf("Assuming chip version=0x%08x\n", system_rev);
586         } else if (find_correct_chip == CHIP_VERSION_NONE) {
587                 diag_printf("Unrecognized chip: 0x%08x!!!\n", readl(IIM_BASE_ADDR + IIM_PREV_OFF));
588         }
589
590         diag_printf("Reset reason: ");
591
592         if (srsr & (1 << 0)) {
593                 diag_printf("%sPOWER_ON", dlm);
594                 dlm = " | ";
595         }
596         if (srsr & (1 << 2)) {
597                 diag_printf("%sCSU", dlm);
598                 dlm = " | ";
599         }
600         if (srsr & (1 << 3)) {
601                 diag_printf("%sUSER", dlm);
602                 dlm = " | ";
603         }
604         if (srsr & (1 << 4)) {
605                 CYG_WORD16 wrsr;
606
607                 HAL_READ_UINT16(WDOG_BASE_ADDR + 4, wrsr);
608                 if (wrsr & (1 << 0)) {
609                         diag_printf("%sSOFT", dlm);
610                         dlm = " | ";
611                 }
612                 if (wrsr & (1 << 1)) {
613                         diag_printf("%sWATCHDOG", dlm);
614                         dlm = " | ";
615                 }
616         }
617         if (srsr & (1 << 5)) {
618                 diag_printf("%sJTAG_HW", dlm);
619                 dlm = " | ";
620         }
621         if (srsr & (1 << 6)) {
622                 diag_printf("%sJTAG_SW", dlm);
623                 dlm = " | ";
624         }
625         if (srsr & (1 << 16)) {
626                 diag_printf("%sWARM BOOT", dlm);
627                 dlm = " | ";
628         }
629
630         if (*dlm == '\0') {
631                 diag_printf("UNKNOWN: %08x\n", srsr);
632         } else {
633                 diag_printf(" RESET\n");
634         }
635
636         if (_mxc_fis == MMC_FLASH_BOOT) {
637                 diag_printf("fis/fconfig from MMC\n");
638         } else if (_mxc_fis == SPI_NOR_FLASH_BOOT) {
639                 diag_printf("fis/fconfig from SPI-NOR\n");
640         } else if (_mxc_fis == NAND_FLASH_BOOT) {
641                 diag_printf("fis/fconfig from NAND\n");
642         } else {
643                 diag_printf("Use \"factive [MMC|SPI|NAND]\" to choose fis/fconfig storage\n");
644         }
645
646         diag_printf("Boot switch: ");
647         if ((SBMR_BMOD(sbmr)) == 0) {
648                 diag_printf("INTERNAL (GPIO)\n");
649         } else if ((SBMR_BMOD(sbmr)) == 2) {
650                 diag_printf("INTERNAL (FUSE)\n");
651         } else if ((SBMR_BMOD(sbmr)) == 3){
652                 diag_printf("BOOTSTRAP\n");
653         } else if ((SBMR_BMOD(sbmr)) == 0x1 && (SBMR_DIR_BT_DIS(sbmr)) == 0) {
654                 diag_printf("TEST EXEC\n");
655         } else {
656                 diag_printf("UNKNOWN: 0x%x\n", SBMR_BMOD(sbmr));
657         }
658         diag_printf("\t");
659         if ((SBMR_BT_MEM_CTL(sbmr)) == 0) {
660                 diag_printf("WEIM: ");
661                 if ((SBMR_BT_MEM_TYPE(sbmr)) == 0) {
662                         diag_printf("NOR");
663                 } else if ((SBMR_BT_MEM_TYPE(sbmr)) == 2) {
664                         diag_printf("ONE NAND");
665                 } else {
666                         diag_printf("UNKNOWN: 0x%x", SBMR_BT_MEM_TYPE(sbmr));
667                 }
668         } else if ((SBMR_BT_MEM_CTL(sbmr)) == 1) {
669                 diag_printf("NAND: ADDR CYCLES:");
670                 if ((SBMR_BT_MEM_TYPE(sbmr)) == 0) {
671                         diag_printf("3: ");
672                 } else if ((SBMR_BT_MEM_TYPE(sbmr)) == 1) {
673                         diag_printf("4: ");
674                 } else if ((SBMR_BT_MEM_TYPE(sbmr)) == 2) {
675                         diag_printf("5: ");
676                 } else {
677                         diag_printf("UNKNOWN: 0x%x ", SBMR_BT_MEM_TYPE(sbmr));
678                 }
679                 if (SBMR_BT_MLC_SEL(sbmr) == 0) {
680                         diag_printf("SLC: ");
681                 } else {
682                         diag_printf("MLC: ");
683                 }
684                 if ((SBMR_BT_SPARE_SIZE(sbmr)) == 0) {
685                         diag_printf("128B spare (4-bit ECC): ");
686                 } else {
687                         diag_printf("218B spare (8-bit ECC): ");
688                 }
689                 diag_printf("PAGE SIZE: ");
690                 if ((SBMR_BT_PAGE_SIZE(sbmr)) == 0) {
691                         diag_printf("512: ");
692                 } else if ((SBMR_BT_PAGE_SIZE(sbmr)) == 1) {
693                         diag_printf("2K: ");
694                 } else if ((SBMR_BT_PAGE_SIZE(sbmr)) == 2) {
695                         diag_printf("4K: ");
696                 } else {
697                         diag_printf("UNKNOWN: 0x%x", SBMR_BT_PAGE_SIZE(sbmr));
698                 }
699                 diag_printf("BUS WIDTH: ");
700                 if ((SBMR_BT_BUS_WIDTH(sbmr)) == 0) {
701                         diag_printf("8");
702                 } else {
703                         diag_printf("16");
704                 }
705         } else if ((SBMR_BT_MEM_CTL(sbmr)) == 3) {
706                 diag_printf("EXPANSION: ");
707                 if ((SBMR_BT_MEM_TYPE(sbmr)) == 0) {
708                         diag_printf("SD/MMC-%d", (SBMR_BT_SDMMC_SRC(sbmr)));
709                 } else if ((SBMR_BT_MEM_TYPE(sbmr)) == 2) {
710                         diag_printf("I2C-NOR: ");
711                         if ((SBMR_BT_SDMMC_SRC(sbmr)) == 0) {
712                                 diag_printf("I2C-1");
713                         } else if ((SBMR_BT_SDMMC_SRC(sbmr)) == 1) {
714                                 diag_printf("I2C-2");
715                         } else if ((SBMR_BT_SDMMC_SRC(sbmr)) == 2) {
716                                 diag_printf("HS-I2C");
717                         } else {
718                                 diag_printf("UNKNOWN: 0x%x", SBMR_BT_SDMMC_SRC(sbmr));
719                         }
720                 } else if ((SBMR_BT_MEM_TYPE(sbmr)) == 3) {
721                         diag_printf("SPI-NOR: ");
722                         if ((SBMR_BT_SDMMC_SRC(sbmr)) == 0) {
723                                 diag_printf("eCSPI1");
724                         } else if ((SBMR_BT_SDMMC_SRC(sbmr)) == 1) {
725                                 diag_printf("eCSPI2");
726                         } else if ((SBMR_BT_SDMMC_SRC(sbmr)) == 2) {
727                                 diag_printf("CSPI");
728                         } else {
729                                 diag_printf("UNKNOWN: 0x%x", SBMR_BT_SDMMC_SRC(sbmr));
730                         }
731                 } else {
732                         diag_printf("UNKNOWN: 0x%x", SBMR_BT_MEM_TYPE(sbmr));
733                 }
734         } else {
735                 diag_printf("UNKNOWN: 0x%x", SBMR_BT_MEM_CTL(sbmr));
736         }
737         diag_printf("\n");
738 }
739
740 RedBoot_init(show_sys_info, RedBoot_INIT_LAST);