recognize another memory MCP chip
[pandora-x-loader.git] / board / pandora / pandora.c
1 /*
2  * (C) Copyright 2006
3  * Texas Instruments, <www.ti.com>
4  * Jian Zhang <jzhang@ti.com>
5  * Richard Woodruff <r-woodruff2@ti.com>
6  *
7  * Modified for the Pandora
8  * John Willis <source@distant-earth.com>
9  * GraÅžvydas Ignotas <notasas@gmail.com>
10  *
11  * See file CREDITS for list of people who contributed to this
12  * project.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of
17  * the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27  * MA 02111-1307 USA
28  */
29
30 #include <common.h>
31 #include <command.h>
32 #include <asm/arch/cpu.h>
33 #include <asm/arch/bits.h>
34 #include <asm/arch/mux.h>
35 #include <asm/arch/gpio.h>
36 #include <asm/arch/sys_proto.h>
37 #include <asm/arch/sys_info.h>
38 #include <asm/arch/clocks.h>
39 #include <asm/arch/mem.h>
40 #include <part.h>
41 #include <fat.h>
42 #include <i2c.h>
43
44 #define __raw_readl(a)          (*(volatile unsigned int *)(a))
45 #define __raw_writel(v, a)      (*(volatile unsigned int *)(a) = (v))
46 #define __raw_readw(a)          (*(volatile unsigned short *)(a))
47 #define __raw_writew(v, a)      (*(volatile unsigned short *)(a) = (v))
48
49 /* slight RAM timing differencer,
50  * tCKE differs from beagle's Micron part */
51 #define MICRON_V_ACTIMB_200_2 (((MICRON_V_ACTIMB_200) & ~(7 << 12)) | (1 << 12))
52
53 /*******************************************************
54  * Routine: delay
55  * Description: spinning delay to use before udelay works
56  ******************************************************/
57 static inline void delay(unsigned long loops)
58 {
59         __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
60                           "bne 1b":"=r" (loops):"0"(loops));
61 }
62
63 void udelay (unsigned long usecs) {
64         delay(usecs);
65 }
66
67 /*****************************************
68  * Routine: board_init
69  * Description: Early hardware init.
70  *****************************************/
71 int board_init(void)
72 {
73 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
74         unsigned char byte;
75
76         /* restore GPBR1 for charging to work -
77          * boot ROM or something clears it before us */
78         byte = 0x90;
79         i2c_write(0x49, 0x91, 1, &byte, 1);
80
81         /* disable VSIM to prevent audio noise */
82         byte = 0x00;
83         i2c_write(0x4B, 0x92, 1, &byte, 1);
84
85 #ifdef CFG_PRINTF
86         /* do additional init to prevent trash being output on startup */
87         serial_init();
88
89         /* VAUX3 = 2.8V (AV connector) */
90         byte = 0x20;
91         i2c_write(0x4B, 0x7A, 1, &byte, 1);
92         byte = 0x03;
93         i2c_write(0x4B, 0x7D, 1, &byte, 1);
94 #endif
95 #endif
96
97         return 0;
98 }
99
100 /*************************************************************
101  * Routine: get_mem_type(void) - returns the kind of memory connected
102  * to GPMC that we are trying to boot form. Uses SYS BOOT settings.
103  *************************************************************/
104 u32 get_mem_type(void)
105 {
106         u32 mem_type = get_sysboot_value();
107         switch (mem_type) {
108         case 0:
109         case 2:
110         case 4:
111         case 16:
112         case 22:
113                 return GPMC_ONENAND;
114
115         case 1:
116         case 12:
117         case 15:
118         case 21:
119         case 27:
120                 return GPMC_NAND;
121
122         case 3:
123         case 6:
124                 return MMC_ONENAND;
125
126         case 8:
127         case 11:
128         case 14:
129         case 20:
130         case 26:
131                 return GPMC_MDOC;
132
133         case 17:
134         case 18:
135         case 24:
136                 return MMC_NAND;
137
138         case 7:
139         case 10:
140         case 13:
141         case 19:
142         case 25:
143         default:
144                 return GPMC_NOR;
145         }
146 }
147
148 static void early_nand_init(void)
149 {
150         /* global settings */
151         __raw_writel(0x10, GPMC_SYSCONFIG);     /* smart idle */
152         __raw_writel(0x0, GPMC_IRQENABLE);      /* isr's sources masked */
153         __raw_writel(0, GPMC_TIMEOUT_CONTROL);  /* timeout disable */
154
155         /* Set the GPMC Vals, NAND is mapped at CS0, oneNAND at CS0.
156          *  We configure only GPMC CS0 with required values. Configiring other devices
157          *  at other CS is done in u-boot. So we don't have to bother doing it here.
158          */
159         __raw_writel(0 , GPMC_CONFIG7 + GPMC_CONFIG_CS0);
160         delay(1000);
161
162         __raw_writel(M_NAND_GPMC_CONFIG1, GPMC_CONFIG1 + GPMC_CONFIG_CS0);
163         __raw_writel(M_NAND_GPMC_CONFIG2, GPMC_CONFIG2 + GPMC_CONFIG_CS0);
164         __raw_writel(M_NAND_GPMC_CONFIG3, GPMC_CONFIG3 + GPMC_CONFIG_CS0);
165         __raw_writel(M_NAND_GPMC_CONFIG4, GPMC_CONFIG4 + GPMC_CONFIG_CS0);
166         __raw_writel(M_NAND_GPMC_CONFIG5, GPMC_CONFIG5 + GPMC_CONFIG_CS0);
167         __raw_writel(M_NAND_GPMC_CONFIG6, GPMC_CONFIG6 + GPMC_CONFIG_CS0);
168
169         /* Enable the GPMC Mapping */
170         __raw_writel((((OMAP34XX_GPMC_CS0_SIZE & 0xF)<<8) |
171                                 ((NAND_BASE_ADR>>24) & 0x3F) |
172                                 (1<<6)),  (GPMC_CONFIG7 + GPMC_CONFIG_CS0));
173         delay(2000);
174 }
175
176 #ifdef CFG_3430SDRAM_DDR
177 static int strncmp(const char *s1, const char *s2, int n)
178 {
179         int i;
180         for (i = 0; i < n; i++)
181                 if (s1[i] != s2[i])
182                         return s1[i] - s2[i];
183         return 0;
184 }
185
186 #define MICRON_128MB_166MHZ 0
187 #define MICRON_256MB_200MHZ 1
188
189 /*********************************************************************
190  * config_sdram_ddr() - Init DDR SDRAM
191  *********************************************************************/
192 static void config_sdram_ddr(u32 cpu_family)
193 {
194         unsigned char buf[64];
195         int ram_type = MICRON_128MB_166MHZ;
196         int mfr, id;
197         int ret;
198
199         /* reset sdrc controller */
200         __raw_writel(SOFTRESET, SDRC_SYSCONFIG);
201         wait_on_value(BIT0, BIT0, SDRC_STATUS, 12000000);
202         __raw_writel(0, SDRC_SYSCONFIG);
203
204         /* setup sdrc to ball mux */
205         __raw_writel(SDP_SDRC_SHARING, SDRC_SHARING);
206
207         /* read NAND id to guess what RAM is attached */
208         early_nand_init();
209         ret = nand_readid(&mfr, &id);
210         if (ret == 0 && id == 0xb3) {
211                 ram_type = MICRON_256MB_200MHZ;
212         } else {
213                 /* others share the same id (bc), luckily NAND model differs */
214                 ret = nand_read_param_page(buf, sizeof(buf));
215                 if (ret == 0) {
216                         if (strncmp((char *)buf + 44, "MT29F4G16ABBDA", 14) == 0)
217                                 ram_type = MICRON_256MB_200MHZ;
218                 }
219         }
220
221         if (ram_type == MICRON_256MB_200MHZ) {
222                 __raw_writel(0x2, SDRC_CS_CFG); /* 256MB/bank */
223                 __raw_writel(SDP_SDRC_MDCFG_0_DDR_MICRON_XM, SDRC_MCFG_0);
224                 __raw_writel(SDP_SDRC_MDCFG_0_DDR_MICRON_XM, SDRC_MCFG_1);
225         } else {
226                 __raw_writel(0x1, SDRC_CS_CFG); /* 128MB/bank */
227                 __raw_writel(SDP_SDRC_MDCFG_0_DDR, SDRC_MCFG_0);
228                 __raw_writel(SDP_SDRC_MDCFG_0_DDR, SDRC_MCFG_1);
229         }
230
231         if (cpu_family == CPU_OMAP36XX && ram_type == MICRON_256MB_200MHZ) {
232                 __raw_writel(MICRON_V_ACTIMA_200, SDRC_ACTIM_CTRLA_0);
233                 __raw_writel(MICRON_V_ACTIMB_200_2, SDRC_ACTIM_CTRLB_0);
234                 __raw_writel(MICRON_V_ACTIMA_200, SDRC_ACTIM_CTRLA_1);
235                 __raw_writel(MICRON_V_ACTIMB_200_2, SDRC_ACTIM_CTRLB_1);
236                 __raw_writel(SDP_3430_SDRC_RFR_CTRL_200MHz, SDRC_RFR_CTRL_0);
237                 __raw_writel(SDP_3430_SDRC_RFR_CTRL_200MHz, SDRC_RFR_CTRL_1);
238
239                 /* reprogram CORE DPLL to 400MHz */
240                 sr32(CM_CLKEN_PLL, 0, 3, PLL_FAST_RELOCK_BYPASS);
241                 wait_on_value(BIT0, 0, CM_IDLEST_CKGEN, LDELAY);
242                 sr32(CM_CLKSEL1_PLL, 16, 11, 400);      /* Set M */
243                 sr32(CM_CLKSEL1_PLL, 8, 7, N_13);       /* Set N */
244                 sr32(CM_CLKEN_PLL, 0, 3, PLL_LOCK);     /* lock mode */
245                 wait_on_value(BIT0, 1, CM_IDLEST_CKGEN, LDELAY);
246         } else {
247                 __raw_writel(MICRON_V_ACTIMA_165, SDRC_ACTIM_CTRLA_0);
248                 __raw_writel(MICRON_V_ACTIMB_165, SDRC_ACTIM_CTRLB_0);
249                 __raw_writel(MICRON_V_ACTIMA_165, SDRC_ACTIM_CTRLA_1);
250                 __raw_writel(MICRON_V_ACTIMB_165, SDRC_ACTIM_CTRLB_1);
251                 __raw_writel(SDP_3430_SDRC_RFR_CTRL_165MHz, SDRC_RFR_CTRL_0);
252                 __raw_writel(SDP_3430_SDRC_RFR_CTRL_165MHz, SDRC_RFR_CTRL_1);
253         }
254
255         __raw_writel(SDP_SDRC_POWER_POP, SDRC_POWER);
256
257         /* init sequence for mDDR/mSDR using manual commands (DDR is different) */
258         __raw_writel(CMD_NOP, SDRC_MANUAL_0);
259         __raw_writel(CMD_NOP, SDRC_MANUAL_1);
260
261         delay(5000);
262
263         __raw_writel(CMD_PRECHARGE, SDRC_MANUAL_0);
264         __raw_writel(CMD_PRECHARGE, SDRC_MANUAL_1);
265
266         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0);
267         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_1);
268
269         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0);
270         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_1);
271
272         /* set mr0 */
273         __raw_writel(SDP_SDRC_MR_0_DDR, SDRC_MR_0);
274         __raw_writel(SDP_SDRC_MR_0_DDR, SDRC_MR_1);
275
276         /* set up dll */
277         __raw_writel(SDP_SDRC_DLLAB_CTRL, SDRC_DLLA_CTRL);
278         delay(0x2000);  /* give time to lock */
279 }
280 #endif /* CFG_3430SDRAM_DDR */
281
282 /*************************************************************
283  * get_sys_clk_speed - determine reference oscillator speed
284  *  based on known 32kHz clock and gptimer.
285  *************************************************************/
286 u32 get_osc_clk_speed(void)
287 {
288         u32 start, cstart, cend, cdiff, cdiv, val;
289
290         val = __raw_readl(PRM_CLKSRC_CTRL);
291
292         if (val & SYSCLKDIV_2)
293                 cdiv = 2;
294         else
295                 cdiv = 1;
296
297         /* enable timer2 */
298         val = __raw_readl(CM_CLKSEL_WKUP) | BIT0;
299         __raw_writel(val, CM_CLKSEL_WKUP);      /* select sys_clk for GPT1 */
300
301         /* Enable I and F Clocks for GPT1 */
302         val = __raw_readl(CM_ICLKEN_WKUP) | BIT0 | BIT2;
303         __raw_writel(val, CM_ICLKEN_WKUP);
304         val = __raw_readl(CM_FCLKEN_WKUP) | BIT0;
305         __raw_writel(val, CM_FCLKEN_WKUP);
306
307         __raw_writel(0, OMAP34XX_GPT1 + TLDR);          /* start counting at 0 */
308         __raw_writel(GPT_EN, OMAP34XX_GPT1 + TCLR);     /* enable clock */
309         /* enable 32kHz source */
310         /* enabled out of reset */
311         /* determine sys_clk via gauging */
312
313         start = 20 + __raw_readl(S32K_CR);      /* start time in 20 cycles */
314         while (__raw_readl(S32K_CR) < start) ;  /* dead loop till start time */
315         cstart = __raw_readl(OMAP34XX_GPT1 + TCRR);     /* get start sys_clk count */
316         while (__raw_readl(S32K_CR) < (start + 20)) ;   /* wait for 40 cycles */
317         cend = __raw_readl(OMAP34XX_GPT1 + TCRR);       /* get end sys_clk count */
318         cdiff = cend - cstart;  /* get elapsed ticks */
319         cdiff *= cdiv;
320
321         /* based on number of ticks assign speed */
322         if (cdiff > 19000)
323                 return S38_4M;
324         else if (cdiff > 15200)
325                 return S26M;
326         else if (cdiff > 13000)
327                 return S24M;
328         else if (cdiff > 9000)
329                 return S19_2M;
330         else if (cdiff > 7600)
331                 return S13M;
332         else
333                 return S12M;
334 }
335
336 /******************************************************************************
337  * prcm_init() - inits clocks for PRCM as defined in clocks.h
338  *   -- called from SRAM, or Flash (using temp SRAM stack).
339  *****************************************************************************/
340 void prcm_init_(u32 cpu_family)
341 {
342         u32 osc_clk, sys_clkin_sel;
343         u32 m;
344
345         /* Gauge the input clock speed and find out the sys_clkin_sel
346          * value corresponding to the input clock.
347          */
348         osc_clk = get_osc_clk_speed();
349         get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
350
351         sr32(PRM_CLKSEL, 0, 3, sys_clkin_sel);  /* set input crystal speed */
352
353         /* If the input clock is greater than 19.2M always divide/2 */
354         m = (sys_clkin_sel > 2) ? 2 : 1;
355         sr32(PRM_CLKSRC_CTRL, 6, 2, m); /* input clock divider */
356
357         sr32(PRM_CLKSRC_CTRL, 0, 2, 0);/* Bypass mode: T2 inputs a square clock */
358
359         /* Unlock MPU DPLL (slows things down, and needed later) */
360         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOW_POWER_BYPASS);
361         wait_on_value(BIT0, 0, CM_IDLEST_PLL_MPU, LDELAY);
362
363         /* CORE DPLL */
364         /* sr32(CM_CLKSEL2_EMU) set override to work when asleep */
365         sr32(CM_CLKEN_PLL, 0, 3, PLL_FAST_RELOCK_BYPASS);
366         wait_on_value(BIT0, 0, CM_IDLEST_CKGEN, LDELAY);
367
368         /* *_13 because of 'input clock divider' above */
369         sr32(CM_CLKSEL1_EMU, 16, 5, CORE_M3X2); /* m3x2 */
370         sr32(CM_CLKSEL1_PLL, 27, 2, M2_13);     /* Set M2 */
371         sr32(CM_CLKSEL1_PLL, 16, 11, M_13);     /* Set M */
372         sr32(CM_CLKSEL1_PLL, 8, 7, N_13);       /* Set N */
373         sr32(CM_CLKSEL1_PLL, 6, 1, 0);  /* 96M Src */
374         sr32(CM_CLKSEL_CORE, 8, 4, CORE_SSI_DIV);       /* ssi */
375         sr32(CM_CLKSEL_CORE, 4, 2, CORE_FUSB_DIV);      /* fsusb */
376         sr32(CM_CLKSEL_CORE, 2, 2, CORE_L4_DIV);        /* l4 */
377         sr32(CM_CLKSEL_CORE, 0, 2, CORE_L3_DIV);        /* l3 */
378         sr32(CM_CLKSEL_WKUP, 1, 2, WKUP_RSM);   /* reset mgr */
379         sr32(CM_CLKEN_PLL, 4, 4, FSEL_13);      /* FREQSEL */
380         sr32(CM_CLKEN_PLL, 0, 3, PLL_LOCK);     /* lock mode */
381         wait_on_value(BIT0, 1, CM_IDLEST_CKGEN, LDELAY);
382
383         /* PER DPLL */
384         m = (cpu_family == CPU_OMAP36XX) ? 0x360 : 0x1B0;
385         sr32(CM_CLKEN_PLL, 16, 3, PLL_STOP);
386         wait_on_value(BIT1, 0, CM_IDLEST_CKGEN, LDELAY);
387         sr32(CM_CLKSEL1_EMU, 24, 5, PER_M6X2);  /* set M6 */
388         sr32(CM_CLKSEL_CAM, 0, 5, PER_M5X2);    /* set M5 */
389         sr32(CM_CLKSEL_DSS, 0, 5, PER_M4X2);    /* set M4 */
390         sr32(CM_CLKSEL_DSS, 8, 5, PER_M3X2);    /* set M3 */
391         sr32(CM_CLKSEL3_PLL, 0, 5, 0x09);       /* set M2 */
392         sr32(CM_CLKSEL2_PLL, 8, 11, m);         /* set m */
393         sr32(CM_CLKSEL2_PLL, 0, 7, 0x0C);       /* set n */
394         sr32(CM_CLKEN_PLL, 20, 4, 0x03);        /* FREQSEL */
395         sr32(CM_CLKEN_PLL, 16, 3, PLL_LOCK);    /* lock mode */
396         wait_on_value(BIT1, 2, CM_IDLEST_CKGEN, LDELAY);
397
398         /* MPU DPLL (unlocked already) */
399         m = (cpu_family == CPU_OMAP36XX) ? 600 : 500;
400         sr32(CM_CLKSEL2_PLL_MPU, 0, 5, 0x01);   /* Set M2 */
401         sr32(CM_CLKSEL1_PLL_MPU, 8, 11, m);     /* Set M */
402         sr32(CM_CLKSEL1_PLL_MPU, 0, 7, 0x0C);   /* Set N */
403         sr32(CM_CLKEN_PLL_MPU, 4, 4, 0x03);     /* FREQSEL */
404         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOCK); /* lock mode */
405         wait_on_value(BIT0, 1, CM_IDLEST_PLL_MPU, LDELAY);
406
407         /* Set up GPTimers to sys_clk source only */
408         sr32(CM_CLKSEL_PER, 0, 8, 0xff);
409         sr32(CM_CLKSEL_WKUP, 0, 1, 1);
410
411         delay(5000);
412 }
413
414 /**********************************************************
415  * Routine: s_init
416  * Description: Does early system init of muxing and clocks.
417  * - Called at time when only stack is available.
418  **********************************************************/
419
420 void s_init(void)
421 {
422         u32 cpu_family;
423
424         watchdog_init();
425         try_unlock_memory();
426         set_muxconf_regs();
427         delay(100);
428         per_clocks_enable();
429
430         cpu_family = get_cpu_family();
431         prcm_init_(cpu_family);
432         config_sdram_ddr(cpu_family);
433 }
434
435 /*******************************************************
436  * Routine: misc_init_r
437  ********************************************************/
438 int misc_init_r(void)
439 {
440 #ifdef CFG_PRINTF
441         unsigned char buf[64];
442         char nand_model[20];
443         int i, ret;
444
445         printf("OpenPandora System\n");
446         print_cpuinfo();
447
448         /* log NAND model */
449         ret = nand_read_param_page(buf, sizeof(buf));
450         if (ret == 0) {
451                 for (i = 0; i < sizeof(nand_model) - 1; i++) {
452                         if (buf[i + 44] == ' ')
453                                 break;
454                         nand_model[i] = buf[i + 44];
455                 }
456                 nand_model[i] = 0;
457                 printf("NAND: %s\n", nand_model);
458         }
459 #endif
460
461         return 0;
462 }
463
464 /******************************************************
465  * Routine: wait_for_command_complete
466  * Description: Wait for posting to finish on watchdog
467  ******************************************************/
468 void wait_for_command_complete(unsigned int wd_base)
469 {
470         int pending = 1;
471         do {
472                 pending = __raw_readl(wd_base + WWPS);
473         } while (pending);
474 }
475
476 /****************************************
477  * Routine: watchdog_init
478  * Description: Shut down watch dogs
479  *****************************************/
480 void watchdog_init(void)
481 {
482         /* There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
483          * either taken care of by ROM (HS/EMU) or not accessible (GP).
484          * We need to take care of WD2-MPU or take a PRCM reset.  WD3
485          * should not be running and does not generate a PRCM reset.
486          */
487         sr32(CM_FCLKEN_WKUP, 5, 1, 1);
488         sr32(CM_ICLKEN_WKUP, 5, 1, 1);
489         wait_on_value(BIT5, 0x20, CM_IDLEST_WKUP, 5);   /* some issue here */
490
491         __raw_writel(WD_UNLOCK1, WD2_BASE + WSPR);
492         wait_for_command_complete(WD2_BASE);
493         __raw_writel(WD_UNLOCK2, WD2_BASE + WSPR);
494 }
495
496 /**********************************************
497  * Routine: dram_init
498  * Description: sets uboots idea of sdram size
499  **********************************************/
500 int dram_init(void)
501 {
502         return 0;
503 }
504
505 /*****************************************************************
506  * Routine: peripheral_enable
507  * Description: Enable the clks & power for perifs (GPT2, UART1,...)
508  ******************************************************************/
509 void per_clocks_enable(void)
510 {
511         /* Enable GP2 timer. */
512         sr32(CM_CLKSEL_PER, 0, 1, 0x1); /* GPT2 = sys clk */
513         sr32(CM_ICLKEN_PER, 3, 1, 0x1); /* ICKen GPT2 */
514         sr32(CM_FCLKEN_PER, 3, 1, 0x1); /* FCKen GPT2 */
515
516 #ifdef CFG_NS16550
517         /* UART1 clocks */
518         sr32(CM_FCLKEN1_CORE, 13, 1, 0x1);
519         sr32(CM_ICLKEN1_CORE, 13, 1, 0x1);
520
521         /* UART 3 Clocks */
522         sr32(CM_FCLKEN_PER, 11, 1, 0x1);
523         sr32(CM_ICLKEN_PER, 11, 1, 0x1);
524 #endif
525
526 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
527         /* Turn on all 3 I2C clocks */
528         sr32(CM_FCLKEN1_CORE, 15, 3, 0x7);
529         sr32(CM_ICLKEN1_CORE, 15, 3, 0x7);      /* I2C1,2,3 = on */
530 #endif
531
532         /* Enable the ICLK for 32K Sync Timer as its used in udelay */
533         sr32(CM_ICLKEN_WKUP, 2, 1, 0x1);
534
535         sr32(CM_FCLKEN_IVA2, 0, 32, FCK_IVA2_ON);
536         sr32(CM_FCLKEN1_CORE, 0, 32, FCK_CORE1_ON);
537         sr32(CM_ICLKEN1_CORE, 0, 32, ICK_CORE1_ON);
538         sr32(CM_ICLKEN2_CORE, 0, 32, ICK_CORE2_ON);
539         sr32(CM_FCLKEN_WKUP, 0, 32, FCK_WKUP_ON);
540         sr32(CM_ICLKEN_WKUP, 0, 32, ICK_WKUP_ON);
541         sr32(CM_FCLKEN_DSS, 0, 32, FCK_DSS_ON);
542         sr32(CM_ICLKEN_DSS, 0, 32, ICK_DSS_ON);
543         sr32(CM_FCLKEN_CAM, 0, 32, FCK_CAM_ON);
544         sr32(CM_ICLKEN_CAM, 0, 32, ICK_CAM_ON);
545         sr32(CM_FCLKEN_PER, 0, 32, FCK_PER_ON);
546         sr32(CM_ICLKEN_PER, 0, 32, ICK_PER_ON);
547
548         /* Enable GPIO5 clocks for blinky LEDs */
549         sr32(CM_FCLKEN_PER, 16, 1, 0x1);        /* FCKen GPIO5 */
550         sr32(CM_ICLKEN_PER, 16, 1, 0x1);        /* ICKen GPIO5 */
551
552         delay(1000);
553 }
554
555 /* Set MUX for UART, GPMC, SDRC, GPIO */
556
557 #define         MUX_VAL(OFFSET,VALUE)\
558                 __raw_writew((VALUE), OMAP34XX_CTRL_BASE + (OFFSET));
559
560 #define         CP(x)   (CONTROL_PADCONF_##x)
561 /*
562  * IEN  - Input Enable
563  * IDIS - Input Disable
564  * PTD  - Pull type Down
565  * PTU  - Pull type Up
566  * DIS  - Pull type selection is inactive
567  * EN   - Pull type selection is active
568  * M0   - Mode 0
569  * The commented string gives the final mux configuration for that pin
570  */
571 #define MUX_DEFAULT()\
572         /*SDRC*/\
573         MUX_VAL(CP(SDRC_D0),        (IEN  | PTD | DIS | M0)) /*SDRC_D0*/\
574         MUX_VAL(CP(SDRC_D1),        (IEN  | PTD | DIS | M0)) /*SDRC_D1*/\
575         MUX_VAL(CP(SDRC_D2),        (IEN  | PTD | DIS | M0)) /*SDRC_D2*/\
576         MUX_VAL(CP(SDRC_D3),        (IEN  | PTD | DIS | M0)) /*SDRC_D3*/\
577         MUX_VAL(CP(SDRC_D4),        (IEN  | PTD | DIS | M0)) /*SDRC_D4*/\
578         MUX_VAL(CP(SDRC_D5),        (IEN  | PTD | DIS | M0)) /*SDRC_D5*/\
579         MUX_VAL(CP(SDRC_D6),        (IEN  | PTD | DIS | M0)) /*SDRC_D6*/\
580         MUX_VAL(CP(SDRC_D7),        (IEN  | PTD | DIS | M0)) /*SDRC_D7*/\
581         MUX_VAL(CP(SDRC_D8),        (IEN  | PTD | DIS | M0)) /*SDRC_D8*/\
582         MUX_VAL(CP(SDRC_D9),        (IEN  | PTD | DIS | M0)) /*SDRC_D9*/\
583         MUX_VAL(CP(SDRC_D10),       (IEN  | PTD | DIS | M0)) /*SDRC_D10*/\
584         MUX_VAL(CP(SDRC_D11),       (IEN  | PTD | DIS | M0)) /*SDRC_D11*/\
585         MUX_VAL(CP(SDRC_D12),       (IEN  | PTD | DIS | M0)) /*SDRC_D12*/\
586         MUX_VAL(CP(SDRC_D13),       (IEN  | PTD | DIS | M0)) /*SDRC_D13*/\
587         MUX_VAL(CP(SDRC_D14),       (IEN  | PTD | DIS | M0)) /*SDRC_D14*/\
588         MUX_VAL(CP(SDRC_D15),       (IEN  | PTD | DIS | M0)) /*SDRC_D15*/\
589         MUX_VAL(CP(SDRC_D16),       (IEN  | PTD | DIS | M0)) /*SDRC_D16*/\
590         MUX_VAL(CP(SDRC_D17),       (IEN  | PTD | DIS | M0)) /*SDRC_D17*/\
591         MUX_VAL(CP(SDRC_D18),       (IEN  | PTD | DIS | M0)) /*SDRC_D18*/\
592         MUX_VAL(CP(SDRC_D19),       (IEN  | PTD | DIS | M0)) /*SDRC_D19*/\
593         MUX_VAL(CP(SDRC_D20),       (IEN  | PTD | DIS | M0)) /*SDRC_D20*/\
594         MUX_VAL(CP(SDRC_D21),       (IEN  | PTD | DIS | M0)) /*SDRC_D21*/\
595         MUX_VAL(CP(SDRC_D22),       (IEN  | PTD | DIS | M0)) /*SDRC_D22*/\
596         MUX_VAL(CP(SDRC_D23),       (IEN  | PTD | DIS | M0)) /*SDRC_D23*/\
597         MUX_VAL(CP(SDRC_D24),       (IEN  | PTD | DIS | M0)) /*SDRC_D24*/\
598         MUX_VAL(CP(SDRC_D25),       (IEN  | PTD | DIS | M0)) /*SDRC_D25*/\
599         MUX_VAL(CP(SDRC_D26),       (IEN  | PTD | DIS | M0)) /*SDRC_D26*/\
600         MUX_VAL(CP(SDRC_D27),       (IEN  | PTD | DIS | M0)) /*SDRC_D27*/\
601         MUX_VAL(CP(SDRC_D28),       (IEN  | PTD | DIS | M0)) /*SDRC_D28*/\
602         MUX_VAL(CP(SDRC_D29),       (IEN  | PTD | DIS | M0)) /*SDRC_D29*/\
603         MUX_VAL(CP(SDRC_D30),       (IEN  | PTD | DIS | M0)) /*SDRC_D30*/\
604         MUX_VAL(CP(SDRC_D31),       (IEN  | PTD | DIS | M0)) /*SDRC_D31*/\
605         MUX_VAL(CP(SDRC_CLK),       (IEN  | PTD | DIS | M0)) /*SDRC_CLK*/\
606         MUX_VAL(CP(SDRC_DQS0),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS0*/\
607         MUX_VAL(CP(SDRC_DQS1),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS1*/\
608         MUX_VAL(CP(SDRC_DQS2),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS2*/\
609         MUX_VAL(CP(SDRC_DQS3),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS3*/\
610         /*GPMC*/\
611         MUX_VAL(CP(GPMC_A1),        (IDIS | PTD | DIS | M0)) /*GPMC_A1*/\
612         MUX_VAL(CP(GPMC_A2),        (IDIS | PTD | DIS | M0)) /*GPMC_A2*/\
613         MUX_VAL(CP(GPMC_A3),        (IDIS | PTD | DIS | M0)) /*GPMC_A3*/\
614         MUX_VAL(CP(GPMC_A4),        (IDIS | PTD | DIS | M0)) /*GPMC_A4*/\
615         MUX_VAL(CP(GPMC_A5),        (IDIS | PTD | DIS | M0)) /*GPMC_A5*/\
616         MUX_VAL(CP(GPMC_A6),        (IDIS | PTD | DIS | M0)) /*GPMC_A6*/\
617         MUX_VAL(CP(GPMC_A7),        (IDIS | PTD | DIS | M0)) /*GPMC_A7*/\
618         MUX_VAL(CP(GPMC_A8),        (IDIS | PTD | DIS | M0)) /*GPMC_A8*/\
619         MUX_VAL(CP(GPMC_A9),        (IDIS | PTD | DIS | M0)) /*GPMC_A9*/\
620         MUX_VAL(CP(GPMC_A10),       (IDIS | PTD | DIS | M0)) /*GPMC_A10*/\
621         MUX_VAL(CP(GPMC_D0),        (IEN  | PTD | DIS | M0)) /*GPMC_D0*/\
622         MUX_VAL(CP(GPMC_D1),        (IEN  | PTD | DIS | M0)) /*GPMC_D1*/\
623         MUX_VAL(CP(GPMC_D2),        (IEN  | PTD | DIS | M0)) /*GPMC_D2*/\
624         MUX_VAL(CP(GPMC_D3),        (IEN  | PTD | DIS | M0)) /*GPMC_D3*/\
625         MUX_VAL(CP(GPMC_D4),        (IEN  | PTD | DIS | M0)) /*GPMC_D4*/\
626         MUX_VAL(CP(GPMC_D5),        (IEN  | PTD | DIS | M0)) /*GPMC_D5*/\
627         MUX_VAL(CP(GPMC_D6),        (IEN  | PTD | DIS | M0)) /*GPMC_D6*/\
628         MUX_VAL(CP(GPMC_D7),        (IEN  | PTD | DIS | M0)) /*GPMC_D7*/\
629         MUX_VAL(CP(GPMC_D8),        (IEN  | PTD | DIS | M0)) /*GPMC_D8*/\
630         MUX_VAL(CP(GPMC_D9),        (IEN  | PTD | DIS | M0)) /*GPMC_D9*/\
631         MUX_VAL(CP(GPMC_D10),       (IEN  | PTD | DIS | M0)) /*GPMC_D10*/\
632         MUX_VAL(CP(GPMC_D11),       (IEN  | PTD | DIS | M0)) /*GPMC_D11*/\
633         MUX_VAL(CP(GPMC_D12),       (IEN  | PTD | DIS | M0)) /*GPMC_D12*/\
634         MUX_VAL(CP(GPMC_D13),       (IEN  | PTD | DIS | M0)) /*GPMC_D13*/\
635         MUX_VAL(CP(GPMC_D14),       (IEN  | PTD | DIS | M0)) /*GPMC_D14*/\
636         MUX_VAL(CP(GPMC_D15),       (IEN  | PTD | DIS | M0)) /*GPMC_D15*/\
637         MUX_VAL(CP(GPMC_nCS0),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS0*/\
638         MUX_VAL(CP(GPMC_nCS1),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS1*/\
639         MUX_VAL(CP(GPMC_CLK),       (IDIS | PTD | DIS | M0)) /*GPMC_CLK*/\
640         MUX_VAL(CP(GPMC_nADV_ALE),  (IDIS | PTD | DIS | M0)) /*GPMC_nADV_ALE*/\
641         MUX_VAL(CP(GPMC_nOE),       (IDIS | PTD | DIS | M0)) /*GPMC_nOE*/\
642         MUX_VAL(CP(GPMC_nWE),       (IDIS | PTD | DIS | M0)) /*GPMC_nWE*/\
643         MUX_VAL(CP(GPMC_nBE0_CLE),  (IDIS | PTD | DIS | M0)) /*GPMC_nBE0_CLE*/\
644         MUX_VAL(CP(GPMC_nWP),       (IEN  | PTD | DIS | M0)) /*GPMC_nWP*/\
645         MUX_VAL(CP(GPMC_WAIT0),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT0*/\
646         MUX_VAL(CP(GPMC_WAIT1),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT1*/\
647         /*Serial Interface (Peripheral boot, Linux console)*/\
648         MUX_VAL(CP(UART3_RX_IRRX),  (IEN  | PTU | EN  | M0)) /*UART3_RX*/\
649         MUX_VAL(CP(UART3_TX_IRTX),  (IDIS | PTD | DIS | M0)) /*UART3_TX*/\
650         /*I2C Ports*/\
651         MUX_VAL(CP(I2C1_SCL),       (IEN  | PTU | EN  | M0)) /*I2C1_SCL*/\
652         MUX_VAL(CP(I2C1_SDA),       (IEN  | PTU | EN  | M0)) /*I2C1_SDA*/\
653         /*LEDs (Controlled by OMAP)*/\
654         MUX_VAL(CP(MMC1_DAT6),      (IDIS | PTD | DIS | M4)) /*GPIO_128*/\
655         MUX_VAL(CP(MMC1_DAT7),      (IDIS | PTD | DIS | M4)) /*GPIO_129*/\
656         /*enable pulldowns for peripheral enable until u-boot loads*/\
657         MUX_VAL(CP(ETK_D0_ES2),     (IDIS | PTD | EN  | M4)) /*GPIO_14*/\
658         MUX_VAL(CP(McBSP2_DR),      (IDIS | PTD | EN  | M4)) /*GPIO_118*/\
659         MUX_VAL(CP(McBSP1_FSR),     (IDIS | PTD | EN  | M4)) /*GPIO_157*/\
660
661 /**********************************************************
662  * Routine: set_muxconf_regs
663  * Description: Setting up the configuration Mux registers
664  *              specific to the hardware. Many pins need
665  *              to be moved from protect to primary mode.
666  *********************************************************/
667 void set_muxconf_regs(void)
668 {
669         MUX_DEFAULT();
670 }
671
672 /**********************************************************
673  * Routine: nand+_init
674  * Description: Set up nand for nand and jffs2 commands
675  *********************************************************/
676 int nand_init(void)
677 {
678         /* init already done in early_nand_init */
679
680         if (get_mem_type() != GPMC_NAND && get_mem_type() != MMC_NAND) {
681 #ifdef CFG_PRINTF
682                 printf("Unsupported flash chip!\n");
683 #endif
684                 return 1;
685         }
686
687         if (nand_chip()) {
688 #ifdef CFG_PRINTF
689                 printf("Unsupported NAND Chip!\n");
690 #endif
691                 return 1;
692         }
693
694         return 0;
695 }
696
697 #define DEBUG_LED1                      128     /* gpio - SD Slot 1 */
698 #define DEBUG_LED2                      129     /* gpio - SD Slot 2 */
699
700 static void blinkLEDs(void)
701 {
702         void *p;
703
704         /* Alternately turn the LEDs on and off */
705         p = (unsigned long *)OMAP34XX_GPIO5_BASE;
706         while (1) {
707                 /* turn LED1 on and LED2 off */
708                 *(unsigned long *)(p + 0x94) = 1 << (DEBUG_LED1 % 32);
709                 *(unsigned long *)(p + 0x90) = 1 << (DEBUG_LED2 % 32);
710
711                 /* delay for a while */
712                 delay(1000);
713
714                 /* turn LED1 off and LED2 on */
715                 *(unsigned long *)(p + 0x90) = 1 << (DEBUG_LED1 % 32);
716                 *(unsigned long *)(p + 0x94) = 1 << (DEBUG_LED2 % 32);
717
718                 /* delay for a while */
719                 delay(1000);
720         }
721 }
722
723 /* optionally do something like blinking LED */
724 void board_hang(void)
725 {
726         while (1)
727                 blinkLEDs();
728 }
729
730 /******************************************************************************
731  * Dummy function to handle errors for EABI incompatibility
732  *****************************************************************************/
733 void raise(void)
734 {
735 }
736
737 /******************************************************************************
738  * Dummy function to handle errors for EABI incompatibility
739  *****************************************************************************/
740 void abort(void)
741 {
742 }