OMAP3: Move sr32() function to not duplicate code
[pandora-x-loader.git] / board / igep00x0 / igep00x0.c
1 /*
2  * (C) Copyright 2010
3  * ISEE 2007 SL <www.iseebcn.com>
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <command.h>
26 #include <part.h>
27 #include <fat.h>
28 #include <asm/arch/cpu.h>
29 #include <asm/arch/bits.h>
30 #include <asm/arch/mux.h>
31 #include <asm/arch/sys_proto.h>
32 #include <asm/arch/sys_info.h>
33 #include <asm/arch/clocks.h>
34 #include <asm/arch/mem.h>
35 #include <asm/arch/gpio.h>
36
37 /* params for 37XX */
38 #define CORE_DPLL_PARAM_M2      0x09
39 #define CORE_DPLL_PARAM_M       0x360
40 #define CORE_DPLL_PARAM_N       0xC
41
42 /* Used to index into DPLL parameter tables */
43 struct dpll_param {
44         unsigned int m;
45         unsigned int n;
46         unsigned int fsel;
47         unsigned int m2;
48 };
49
50 typedef struct dpll_param dpll_param;
51
52 /* Following functions are exported from lowlevel_init.S */
53 extern dpll_param *get_mpu_dpll_param(void);
54 extern dpll_param *get_iva_dpll_param(void);
55 extern dpll_param *get_core_dpll_param(void);
56 extern dpll_param *get_per_dpll_param(void);
57
58 #define __raw_readl(a)          (*(volatile unsigned int *)(a))
59 #define __raw_writel(v, a)      (*(volatile unsigned int *)(a) = (v))
60 #define __raw_readw(a)          (*(volatile unsigned short *)(a))
61 #define __raw_writew(v, a)      (*(volatile unsigned short *)(a) = (v))
62
63 /*******************************************************
64  * Routine: delay
65  * Description: spinning delay to use before udelay works
66  ******************************************************/
67 static inline void delay(unsigned long loops)
68 {
69         __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
70                           "bne 1b":"=r" (loops):"0"(loops));
71 }
72
73 void udelay (unsigned long usecs) {
74         delay(usecs);
75 }
76
77 /*************************************************************
78  * Routine: get_mem_type(void) - returns the kind of memory connected
79  * to GPMC that we are trying to boot form. Uses SYS BOOT settings.
80  *************************************************************/
81 u32 get_mem_type(void)
82 {
83         return GPMC_ONENAND;
84 }
85
86 /*********************************************************************
87  * wait_on_value() - common routine to allow waiting for changes in
88  *   volatile regs.
89  *********************************************************************/
90 u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
91 {
92         u32 i = 0, val;
93         do {
94                 ++i;
95                 val = __raw_readl(read_addr) & read_bit_mask;
96                 if (val == match_value)
97                         return 1;
98                 if (i == bound)
99                         return 0;
100         } while (1);
101 }
102
103 /*************************************************************
104  * get_sys_clk_speed - determine reference oscillator speed
105  *  based on known 32kHz clock and gptimer.
106  *************************************************************/
107 u32 get_osc_clk_speed(void)
108 {
109         u32 start, cstart, cend, cdiff, val;
110
111         val = __raw_readl(PRM_CLKSRC_CTRL);
112         /* If SYS_CLK is being divided by 2, remove for now */
113         val = (val & (~BIT7)) | BIT6;
114         __raw_writel(val, PRM_CLKSRC_CTRL);
115
116         /* enable timer2 */
117         val = __raw_readl(CM_CLKSEL_WKUP) | BIT0;
118         __raw_writel(val, CM_CLKSEL_WKUP);      /* select sys_clk for GPT1 */
119
120         /* Enable I and F Clocks for GPT1 */
121         val = __raw_readl(CM_ICLKEN_WKUP) | BIT0 | BIT2;
122         __raw_writel(val, CM_ICLKEN_WKUP);
123         val = __raw_readl(CM_FCLKEN_WKUP) | BIT0;
124         __raw_writel(val, CM_FCLKEN_WKUP);
125
126         __raw_writel(0, OMAP34XX_GPT1 + TLDR);          /* start counting at 0 */
127         __raw_writel(GPT_EN, OMAP34XX_GPT1 + TCLR);     /* enable clock */
128         /* enable 32kHz source */
129         /* enabled out of reset */
130         /* determine sys_clk via gauging */
131
132         start = 20 + __raw_readl(S32K_CR);      /* start time in 20 cycles */
133         while (__raw_readl(S32K_CR) < start) ;  /* dead loop till start time */
134         cstart = __raw_readl(OMAP34XX_GPT1 + TCRR);     /* get start sys_clk count */
135         while (__raw_readl(S32K_CR) < (start + 20)) ;   /* wait for 40 cycles */
136         cend = __raw_readl(OMAP34XX_GPT1 + TCRR);       /* get end sys_clk count */
137         cdiff = cend - cstart;  /* get elapsed ticks */
138
139         /* based on number of ticks assign speed */
140         if (cdiff > 19000)
141                 return S38_4M;
142         else if (cdiff > 15200)
143                 return S26M;
144         else if (cdiff > 13000)
145                 return S24M;
146         else if (cdiff > 9000)
147                 return S19_2M;
148         else if (cdiff > 7600)
149                 return S13M;
150         else
151                 return S12M;
152 }
153
154 /******************************************************************************
155  * get_sys_clkin_sel() - returns the sys_clkin_sel field value based on
156  *   -- input oscillator clock frequency.
157  *
158  *****************************************************************************/
159 void get_sys_clkin_sel(u32 osc_clk, u32 *sys_clkin_sel)
160 {
161         if (osc_clk == S38_4M)
162                 *sys_clkin_sel = 4;
163         else if (osc_clk == S26M)
164                 *sys_clkin_sel = 3;
165         else if (osc_clk == S19_2M)
166                 *sys_clkin_sel = 2;
167         else if (osc_clk == S13M)
168                 *sys_clkin_sel = 1;
169         else if (osc_clk == S12M)
170                 *sys_clkin_sel = 0;
171 }
172
173 /******************************************************************************
174  * prcm_init() - inits clocks for PRCM as defined in clocks.h
175  *   -- called from SRAM, or Flash (using temp SRAM stack).
176  *****************************************************************************/
177 void prcm_init(void)
178 {
179         u32 osc_clk = 0, sys_clkin_sel;
180         dpll_param *dpll_param_p;
181         u32 clk_index, sil_index;
182
183         /* Gauge the input clock speed and find out the sys_clkin_sel
184          * value corresponding to the input clock.
185          */
186         osc_clk = get_osc_clk_speed();
187         get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
188
189         sr32(PRM_CLKSEL, 0, 3, sys_clkin_sel);  /* set input crystal speed */
190
191         /* If the input clock is greater than 19.2M always divide/2 */
192         if (sys_clkin_sel > 2) {
193                 sr32(PRM_CLKSRC_CTRL, 6, 2, 2); /* input clock divider */
194                 clk_index = sys_clkin_sel / 2;
195         } else {
196                 sr32(PRM_CLKSRC_CTRL, 6, 2, 1); /* input clock divider */
197                 clk_index = sys_clkin_sel;
198         }
199
200         sr32(PRM_CLKSRC_CTRL, 0, 2, 0);/* Bypass mode: T2 inputs a square clock */
201
202         /* The DPLL tables are defined according to sysclk value and
203          * silicon revision. The clk_index value will be used to get
204          * the values for that input sysclk from the DPLL param table
205          * and sil_index will get the values for that SysClk for the
206          * appropriate silicon rev.
207          */
208         sil_index = get_cpu_rev() - 1;
209
210         /* Unlock MPU DPLL (slows things down, and needed later) */
211         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOW_POWER_BYPASS);
212         wait_on_value(BIT0, 0, CM_IDLEST_PLL_MPU, LDELAY);
213
214         /* Getting the base address of Core DPLL param table */
215         dpll_param_p = (dpll_param *) get_core_dpll_param();
216         /* Moving it to the right sysclk and ES rev base */
217         dpll_param_p = dpll_param_p + 3 * clk_index + sil_index;
218         /* CORE DPLL */
219         /* sr32(CM_CLKSEL2_EMU) set override to work when asleep */
220         sr32(CM_CLKEN_PLL, 0, 3, PLL_FAST_RELOCK_BYPASS);
221         wait_on_value(BIT0, 0, CM_IDLEST_CKGEN, LDELAY);
222
223          /* For 3430 ES1.0 Errata 1.50, default value directly doesnt
224         work. write another value and then default value. */
225         sr32(CM_CLKSEL1_EMU, 16, 5, CORE_M3X2 + 1);     /* m3x2 */
226         sr32(CM_CLKSEL1_EMU, 16, 5, CORE_M3X2); /* m3x2 */
227         sr32(CM_CLKSEL1_PLL, 27, 2, dpll_param_p->m2);  /* Set M2 */
228         sr32(CM_CLKSEL1_PLL, 16, 11, dpll_param_p->m);  /* Set M */
229         sr32(CM_CLKSEL1_PLL, 8, 7, dpll_param_p->n);    /* Set N */
230         sr32(CM_CLKSEL1_PLL, 6, 1, 0);  /* 96M Src */
231         sr32(CM_CLKSEL_CORE, 8, 4, CORE_SSI_DIV);       /* ssi */
232         sr32(CM_CLKSEL_CORE, 4, 2, CORE_FUSB_DIV);      /* fsusb */
233         sr32(CM_CLKSEL_CORE, 2, 2, CORE_L4_DIV);        /* l4 */
234         sr32(CM_CLKSEL_CORE, 0, 2, CORE_L3_DIV);        /* l3 */
235         sr32(CM_CLKSEL_GFX, 0, 3, GFX_DIV);     /* gfx */
236         sr32(CM_CLKSEL_WKUP, 1, 2, WKUP_RSM);   /* reset mgr */
237         sr32(CM_CLKEN_PLL, 4, 4, dpll_param_p->fsel);   /* FREQSEL */
238         sr32(CM_CLKEN_PLL, 0, 3, PLL_LOCK);     /* lock mode */
239         wait_on_value(BIT0, 1, CM_IDLEST_CKGEN, LDELAY);
240
241         /* Getting the base address to PER  DPLL param table */
242         dpll_param_p = (dpll_param *) get_per_dpll_param();
243         /* Moving it to the right sysclk base */
244         dpll_param_p = dpll_param_p + clk_index;
245         /* PER DPLL */
246         sr32(CM_CLKEN_PLL, 16, 3, PLL_STOP);
247         wait_on_value(BIT1, 0, CM_IDLEST_CKGEN, LDELAY);
248         sr32(CM_CLKSEL1_EMU, 24, 5, PER_M6X2);  /* set M6 */
249         sr32(CM_CLKSEL_CAM, 0, 5, PER_M5X2);    /* set M5 */
250         sr32(CM_CLKSEL_DSS, 0, 5, PER_M4X2);    /* set M4 */
251         sr32(CM_CLKSEL_DSS, 8, 5, PER_M3X2);    /* set M3 */
252
253         if (get_cpu_family() == CPU_OMAP36XX) {
254                 sr32(CM_CLKSEL3_PLL, 0, 5, CORE_DPLL_PARAM_M2); /* set M2 */
255                 sr32(CM_CLKSEL2_PLL, 8, 11, CORE_DPLL_PARAM_M); /* set m */
256                 sr32(CM_CLKSEL2_PLL, 0, 7, CORE_DPLL_PARAM_N);  /* set n */
257         } else {
258                 sr32(CM_CLKSEL3_PLL, 0, 5, dpll_param_p->m2);   /* set M2 */
259                 sr32(CM_CLKSEL2_PLL, 8, 11, dpll_param_p->m);   /* set m */
260                 sr32(CM_CLKSEL2_PLL, 0, 7, dpll_param_p->n);    /* set n */
261         }
262
263         sr32(CM_CLKEN_PLL, 20, 4, dpll_param_p->fsel);  /* FREQSEL */
264         sr32(CM_CLKEN_PLL, 16, 3, PLL_LOCK);    /* lock mode */
265         wait_on_value(BIT1, 2, CM_IDLEST_CKGEN, LDELAY);
266
267         /* Getting the base address to MPU DPLL param table */
268         dpll_param_p = (dpll_param *) get_mpu_dpll_param();
269
270         /* Moving it to the right sysclk and ES rev base */
271         dpll_param_p = dpll_param_p + 3 * clk_index + sil_index;
272
273         /* MPU DPLL (unlocked already) */
274         sr32(CM_CLKSEL2_PLL_MPU, 0, 5, dpll_param_p->m2);       /* Set M2 */
275         sr32(CM_CLKSEL1_PLL_MPU, 8, 11, dpll_param_p->m);       /* Set M */
276         sr32(CM_CLKSEL1_PLL_MPU, 0, 7, dpll_param_p->n);        /* Set N */
277         sr32(CM_CLKEN_PLL_MPU, 4, 4, dpll_param_p->fsel);       /* FREQSEL */
278         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOCK); /* lock mode */
279         wait_on_value(BIT0, 1, CM_IDLEST_PLL_MPU, LDELAY);
280
281         /* Getting the base address to IVA DPLL param table */
282         dpll_param_p = (dpll_param *) get_iva_dpll_param();
283         /* Moving it to the right sysclk and ES rev base */
284         dpll_param_p = dpll_param_p + 3 * clk_index + sil_index;
285         /* IVA DPLL (set to 12*20=240MHz) */
286         sr32(CM_CLKEN_PLL_IVA2, 0, 3, PLL_STOP);
287         wait_on_value(BIT0, 0, CM_IDLEST_PLL_IVA2, LDELAY);
288         sr32(CM_CLKSEL2_PLL_IVA2, 0, 5, dpll_param_p->m2);      /* set M2 */
289         sr32(CM_CLKSEL1_PLL_IVA2, 8, 11, dpll_param_p->m);      /* set M */
290         sr32(CM_CLKSEL1_PLL_IVA2, 0, 7, dpll_param_p->n);       /* set N */
291         sr32(CM_CLKEN_PLL_IVA2, 4, 4, dpll_param_p->fsel);      /* FREQSEL */
292         sr32(CM_CLKEN_PLL_IVA2, 0, 3, PLL_LOCK);        /* lock mode */
293         wait_on_value(BIT0, 1, CM_IDLEST_PLL_IVA2, LDELAY);
294
295         /* Set up GPTimers to sys_clk source only */
296         sr32(CM_CLKSEL_PER, 0, 8, 0xff);
297         sr32(CM_CLKSEL_WKUP, 0, 1, 1);
298
299         delay(5000);
300 }
301
302 /*****************************************
303  * Routine: secure_unlock
304  * Description: Setup security registers for access
305  * (GP Device only)
306  *****************************************/
307 void secure_unlock(void)
308 {
309         /* Permission values for registers -Full fledged permissions to all */
310 #define UNLOCK_1 0xFFFFFFFF
311 #define UNLOCK_2 0x00000000
312 #define UNLOCK_3 0x0000FFFF
313         /* Protection Module Register Target APE (PM_RT) */
314         __raw_writel(UNLOCK_1, RT_REQ_INFO_PERMISSION_1);
315         __raw_writel(UNLOCK_1, RT_READ_PERMISSION_0);
316         __raw_writel(UNLOCK_1, RT_WRITE_PERMISSION_0);
317         __raw_writel(UNLOCK_2, RT_ADDR_MATCH_1);
318
319         __raw_writel(UNLOCK_3, GPMC_REQ_INFO_PERMISSION_0);
320         __raw_writel(UNLOCK_3, GPMC_READ_PERMISSION_0);
321         __raw_writel(UNLOCK_3, GPMC_WRITE_PERMISSION_0);
322
323         __raw_writel(UNLOCK_3, OCM_REQ_INFO_PERMISSION_0);
324         __raw_writel(UNLOCK_3, OCM_READ_PERMISSION_0);
325         __raw_writel(UNLOCK_3, OCM_WRITE_PERMISSION_0);
326         __raw_writel(UNLOCK_2, OCM_ADDR_MATCH_2);
327
328         /* IVA Changes */
329         __raw_writel(UNLOCK_3, IVA2_REQ_INFO_PERMISSION_0);
330         __raw_writel(UNLOCK_3, IVA2_READ_PERMISSION_0);
331         __raw_writel(UNLOCK_3, IVA2_WRITE_PERMISSION_0);
332
333         __raw_writel(UNLOCK_1, SMS_RG_ATT0);    /* SDRC region 0 public */
334 }
335
336 /**********************************************************
337  * Routine: try_unlock_sram()
338  * Description: If chip is GP type, unlock the SRAM for
339  *  general use.
340  ***********************************************************/
341 void try_unlock_memory(void)
342 {
343         int mode;
344
345         /* if GP device unlock device SRAM for general use */
346         /* secure code breaks for Secure/Emulation device - HS/E/T */
347         mode = get_device_type();
348         if (mode == GP_DEVICE)
349                 secure_unlock();
350         return;
351 }
352
353 /*********************************************************************
354  * config_sdram_m65kx002am() - 2 dice of 2Gb, DDR x32 I/O, 4KB page
355  *********************************************************************/
356 void config_sdram_m65kx002am(void)
357 {
358         /* M65KX002AM - 2 dice of 2Gb */
359         /* reset sdrc controller */
360         __raw_writel(SOFTRESET, SDRC_SYSCONFIG);
361         wait_on_value(BIT0, BIT0, SDRC_STATUS, 12000000);
362         __raw_writel(0, SDRC_SYSCONFIG);
363
364         /* setup sdrc to ball mux */
365         __raw_writel(SDP_SDRC_SHARING, SDRC_SHARING);
366         __raw_writel(0x2, SDRC_CS_CFG); /* 256 MB/bank */
367
368         /* CS0 SDRC Mode Register */
369         __raw_writel(MK65KX002AM_SDRC_MCDCFG, SDRC_MCFG_0);
370
371         /* CS1 SDRC Mode Register */
372         __raw_writel(MK65KX002AM_SDRC_MCDCFG, SDRC_MCFG_1);
373
374         /* Set timings */
375         __raw_writel(NUMONYX_SDRC_ACTIM_CTRLA_0, SDRC_ACTIM_CTRLA_0);
376         __raw_writel(NUMONYX_SDRC_ACTIM_CTRLB_0, SDRC_ACTIM_CTRLB_0);
377         __raw_writel(NUMONYX_SDRC_ACTIM_CTRLA_0, SDRC_ACTIM_CTRLA_1);
378         __raw_writel(NUMONYX_SDRC_ACTIM_CTRLB_0, SDRC_ACTIM_CTRLB_1);
379
380         __raw_writel(SDP_SDRC_RFR_CTRL, SDRC_RFR_CTRL_0);
381         __raw_writel(SDP_SDRC_RFR_CTRL, SDRC_RFR_CTRL_1);
382
383         __raw_writel(SDP_SDRC_POWER_POP, SDRC_POWER);
384
385         /* init sequence for mDDR/mSDR using manual commands (DDR is different) */
386         __raw_writel(CMD_NOP, SDRC_MANUAL_0);
387         __raw_writel(CMD_NOP, SDRC_MANUAL_1);
388
389         delay(5000);
390
391         __raw_writel(CMD_PRECHARGE, SDRC_MANUAL_0);
392         __raw_writel(CMD_PRECHARGE, SDRC_MANUAL_1);
393
394         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0);
395         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_1);
396
397         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_0);
398         __raw_writel(CMD_AUTOREFRESH, SDRC_MANUAL_1);
399
400         /* set mr0 */
401         __raw_writel(SDP_SDRC_MR_0_DDR, SDRC_MR_0);
402         __raw_writel(SDP_SDRC_MR_0_DDR, SDRC_MR_1);
403
404         /* set up dll */
405         __raw_writel(SDP_SDRC_DLLAB_CTRL, SDRC_DLLA_CTRL);
406         delay(0x2000);  /* give time to lock */
407 }
408
409 /*********************************************************************
410  * config_onenand_nand0xgr4wxa() - 4-Gbit DDP or 2-Gbit OneNAND Flash
411  *********************************************************************/
412 void config_onenand_nand0xgr4wxa(void)
413 {
414         /* global settings */
415         __raw_writel(0x10, GPMC_SYSCONFIG);     /* smart idle */
416         __raw_writel(0x0, GPMC_IRQENABLE);      /* isr's sources masked */
417         __raw_writel(0, GPMC_TIMEOUT_CONTROL);/* timeout disable */
418
419         /* Set the GPMC Vals, NAND is mapped at CS0, oneNAND at CS0.
420          *  We configure only GPMC CS0 with required values. Configuring other devices
421          *  at other CS is done in u-boot. So we don't have to bother doing it here.
422          */
423         __raw_writel(0 , GPMC_CONFIG7 + GPMC_CONFIG_CS0);
424         delay(1000);
425
426         __raw_writel(ONENAND_GPMC_CONFIG1, GPMC_CONFIG1 + GPMC_CONFIG_CS0);
427         __raw_writel(ONENAND_GPMC_CONFIG2, GPMC_CONFIG2 + GPMC_CONFIG_CS0);
428         __raw_writel(ONENAND_GPMC_CONFIG3, GPMC_CONFIG3 + GPMC_CONFIG_CS0);
429         __raw_writel(ONENAND_GPMC_CONFIG4, GPMC_CONFIG4 + GPMC_CONFIG_CS0);
430         __raw_writel(ONENAND_GPMC_CONFIG5, GPMC_CONFIG5 + GPMC_CONFIG_CS0);
431         __raw_writel(ONENAND_GPMC_CONFIG6, GPMC_CONFIG6 + GPMC_CONFIG_CS0);
432
433         /* Enable the GPMC Mapping */
434         __raw_writel((((OMAP34XX_GPMC_CS0_SIZE & 0xF)<<8) |
435                      ((ONENAND_BASE>>24) & 0x3F) |
436                      (1<<6)),  (GPMC_CONFIG7 + GPMC_CONFIG_CS0));
437         delay(2000);
438 }
439
440 /**********************************************************
441  * Routine: s_init
442  * Description: Does early system init of muxing and clocks.
443  * - Called at time when only stack is available.
444  **********************************************************/
445 void s_init(void)
446 {
447         watchdog_init();
448
449         try_unlock_memory();
450         set_muxconf_regs();
451         delay(100);
452         prcm_init();
453         per_clocks_enable();
454         config_sdram_m65kx002am();
455 }
456
457 /*****************************************
458  * Routine: board_init
459  * Description: Early hardware init.
460  *****************************************/
461 int board_init(void)
462 {
463         return 0;
464 }
465
466 /*******************************************************
467  * Routine: misc_init_r
468  * Description: Init ethernet (done here so udelay works)
469  ********************************************************/
470 int misc_init_r(void)
471 {
472         omap_request_gpio(27);
473         omap_set_gpio_direction(27, 0);
474         omap_set_gpio_dataout(27, 1);
475
476         return 0;
477 }
478
479 /******************************************************
480  * Routine: wait_for_command_complete
481  * Description: Wait for posting to finish on watchdog
482  ******************************************************/
483 void wait_for_command_complete(unsigned int wd_base)
484 {
485         int pending = 1;
486         do {
487                 pending = __raw_readl(wd_base + WWPS);
488         } while (pending);
489 }
490
491 /****************************************
492  * Routine: watchdog_init
493  * Description: Shut down watch dogs
494  *****************************************/
495 void watchdog_init(void)
496 {
497         /* There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
498          * either taken care of by ROM (HS/EMU) or not accessible (GP).
499          * We need to take care of WD2-MPU or take a PRCM reset.  WD3
500          * should not be running and does not generate a PRCM reset.
501          */
502         sr32(CM_FCLKEN_WKUP, 5, 1, 1);
503         sr32(CM_ICLKEN_WKUP, 5, 1, 1);
504         wait_on_value(BIT5, 0x20, CM_IDLEST_WKUP, 5);   /* some issue here */
505
506 #ifdef CONFIG_WATCHDOG
507         /* Enable WD2 watchdog */
508         __raw_writel(WD_UNLOCK3, WD2_BASE + WSPR);
509         wait_for_command_complete(WD2_BASE);
510         __raw_writel(WD_UNLOCK4, WD2_BASE + WSPR);
511 #else
512         /* Disable WD2 watchdog */
513         __raw_writel(WD_UNLOCK1, WD2_BASE + WSPR);
514         wait_for_command_complete(WD2_BASE);
515         __raw_writel(WD_UNLOCK2, WD2_BASE + WSPR);
516 #endif
517 }
518
519 /**********************************************
520  * Routine: dram_init
521  * Description: sets uboots idea of sdram size
522  **********************************************/
523 int dram_init(void)
524 {
525         return 0;
526 }
527
528 /*****************************************************************
529  * Routine: peripheral_enable
530  * Description: Enable the clks & power for perifs (GPT2, UART1,...)
531  ******************************************************************/
532 void per_clocks_enable(void)
533 {
534         /* Enable GP2 timer. */
535         sr32(CM_CLKSEL_PER, 0, 1, 0x1); /* GPT2 = sys clk */
536         sr32(CM_ICLKEN_PER, 3, 1, 0x1); /* ICKen GPT2 */
537         sr32(CM_FCLKEN_PER, 3, 1, 0x1); /* FCKen GPT2 */
538
539 #ifdef CFG_NS16550
540         /* UART1 clocks */
541         sr32(CM_FCLKEN1_CORE, 13, 1, 0x1);
542         sr32(CM_ICLKEN1_CORE, 13, 1, 0x1);
543
544         /* UART 3 Clocks */
545         sr32(CM_FCLKEN_PER, 11, 1, 0x1);
546         sr32(CM_ICLKEN_PER, 11, 1, 0x1);
547
548 #endif
549
550 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
551         /* Turn on all 3 I2C clocks */
552         sr32(CM_FCLKEN1_CORE, 15, 3, 0x7);
553         sr32(CM_ICLKEN1_CORE, 15, 3, 0x7);      /* I2C1,2,3 = on */
554 #endif
555
556         /* Enable the ICLK for 32K Sync Timer as its used in udelay */
557         sr32(CM_ICLKEN_WKUP, 2, 1, 0x1);
558
559         sr32(CM_FCLKEN_IVA2, 0, 32, FCK_IVA2_ON);
560         sr32(CM_FCLKEN1_CORE, 0, 32, FCK_CORE1_ON);
561         sr32(CM_ICLKEN1_CORE, 0, 32, ICK_CORE1_ON);
562         sr32(CM_ICLKEN2_CORE, 0, 32, ICK_CORE2_ON);
563         sr32(CM_FCLKEN_WKUP, 0, 32, FCK_WKUP_ON);
564         sr32(CM_ICLKEN_WKUP, 0, 32, ICK_WKUP_ON);
565         sr32(CM_FCLKEN_DSS, 0, 32, FCK_DSS_ON);
566         sr32(CM_ICLKEN_DSS, 0, 32, ICK_DSS_ON);
567         sr32(CM_FCLKEN_CAM, 0, 32, FCK_CAM_ON);
568         sr32(CM_ICLKEN_CAM, 0, 32, ICK_CAM_ON);
569         sr32(CM_FCLKEN_PER, 0, 32, FCK_PER_ON);
570         sr32(CM_ICLKEN_PER, 0, 32, ICK_PER_ON);
571
572         delay(1000);
573 }
574
575 /* Set MUX for UART, GPMC, SDRC, GPIO */
576
577 #define         MUX_VAL(OFFSET,VALUE)\
578                 __raw_writew((VALUE), OMAP34XX_CTRL_BASE + (OFFSET));
579
580 #define         CP(x)   (CONTROL_PADCONF_##x)
581 /*
582  * IEN  - Input Enable
583  * IDIS - Input Disable
584  * PTD  - Pull type Down
585  * PTU  - Pull type Up
586  * DIS  - Pull type selection is inactive
587  * EN   - Pull type selection is active
588  * M0   - Mode 0
589  * The commented string gives the final mux configuration for that pin
590  */
591 #define MUX_DEFAULT()\
592         MUX_VAL(CP(SDRC_D0),        (IEN  | PTD | DIS | M0)) /*SDRC_D0*/\
593         MUX_VAL(CP(SDRC_D1),        (IEN  | PTD | DIS | M0)) /*SDRC_D1*/\
594         MUX_VAL(CP(SDRC_D2),        (IEN  | PTD | DIS | M0)) /*SDRC_D2*/\
595         MUX_VAL(CP(SDRC_D3),        (IEN  | PTD | DIS | M0)) /*SDRC_D3*/\
596         MUX_VAL(CP(SDRC_D4),        (IEN  | PTD | DIS | M0)) /*SDRC_D4*/\
597         MUX_VAL(CP(SDRC_D5),        (IEN  | PTD | DIS | M0)) /*SDRC_D5*/\
598         MUX_VAL(CP(SDRC_D6),        (IEN  | PTD | DIS | M0)) /*SDRC_D6*/\
599         MUX_VAL(CP(SDRC_D7),        (IEN  | PTD | DIS | M0)) /*SDRC_D7*/\
600         MUX_VAL(CP(SDRC_D8),        (IEN  | PTD | DIS | M0)) /*SDRC_D8*/\
601         MUX_VAL(CP(SDRC_D9),        (IEN  | PTD | DIS | M0)) /*SDRC_D9*/\
602         MUX_VAL(CP(SDRC_D10),       (IEN  | PTD | DIS | M0)) /*SDRC_D10*/\
603         MUX_VAL(CP(SDRC_D11),       (IEN  | PTD | DIS | M0)) /*SDRC_D11*/\
604         MUX_VAL(CP(SDRC_D12),       (IEN  | PTD | DIS | M0)) /*SDRC_D12*/\
605         MUX_VAL(CP(SDRC_D13),       (IEN  | PTD | DIS | M0)) /*SDRC_D13*/\
606         MUX_VAL(CP(SDRC_D14),       (IEN  | PTD | DIS | M0)) /*SDRC_D14*/\
607         MUX_VAL(CP(SDRC_D15),       (IEN  | PTD | DIS | M0)) /*SDRC_D15*/\
608         MUX_VAL(CP(SDRC_D16),       (IEN  | PTD | DIS | M0)) /*SDRC_D16*/\
609         MUX_VAL(CP(SDRC_D17),       (IEN  | PTD | DIS | M0)) /*SDRC_D17*/\
610         MUX_VAL(CP(SDRC_D18),       (IEN  | PTD | DIS | M0)) /*SDRC_D18*/\
611         MUX_VAL(CP(SDRC_D19),       (IEN  | PTD | DIS | M0)) /*SDRC_D19*/\
612         MUX_VAL(CP(SDRC_D20),       (IEN  | PTD | DIS | M0)) /*SDRC_D20*/\
613         MUX_VAL(CP(SDRC_D21),       (IEN  | PTD | DIS | M0)) /*SDRC_D21*/\
614         MUX_VAL(CP(SDRC_D22),       (IEN  | PTD | DIS | M0)) /*SDRC_D22*/\
615         MUX_VAL(CP(SDRC_D23),       (IEN  | PTD | DIS | M0)) /*SDRC_D23*/\
616         MUX_VAL(CP(SDRC_D24),       (IEN  | PTD | DIS | M0)) /*SDRC_D24*/\
617         MUX_VAL(CP(SDRC_D25),       (IEN  | PTD | DIS | M0)) /*SDRC_D25*/\
618         MUX_VAL(CP(SDRC_D26),       (IEN  | PTD | DIS | M0)) /*SDRC_D26*/\
619         MUX_VAL(CP(SDRC_D27),       (IEN  | PTD | DIS | M0)) /*SDRC_D27*/\
620         MUX_VAL(CP(SDRC_D28),       (IEN  | PTD | DIS | M0)) /*SDRC_D28*/\
621         MUX_VAL(CP(SDRC_D29),       (IEN  | PTD | DIS | M0)) /*SDRC_D29*/\
622         MUX_VAL(CP(SDRC_D30),       (IEN  | PTD | DIS | M0)) /*SDRC_D30*/\
623         MUX_VAL(CP(SDRC_D31),       (IEN  | PTD | DIS | M0)) /*SDRC_D31*/\
624         MUX_VAL(CP(SDRC_CLK),       (IEN  | PTD | DIS | M0)) /*SDRC_CLK*/\
625         MUX_VAL(CP(SDRC_DQS0),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS0*/\
626         MUX_VAL(CP(SDRC_DQS1),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS1*/\
627         MUX_VAL(CP(SDRC_DQS2),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS2*/\
628         MUX_VAL(CP(SDRC_DQS3),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS3*/\
629         MUX_VAL(CP(GPMC_A1),        (IDIS | PTD | DIS | M0)) /*GPMC_A1*/\
630         MUX_VAL(CP(GPMC_A2),        (IDIS | PTD | DIS | M0)) /*GPMC_A2*/\
631         MUX_VAL(CP(GPMC_A3),        (IDIS | PTD | DIS | M0)) /*GPMC_A3*/\
632         MUX_VAL(CP(GPMC_A4),        (IDIS | PTD | DIS | M0)) /*GPMC_A4*/\
633         MUX_VAL(CP(GPMC_A5),        (IDIS | PTD | DIS | M0)) /*GPMC_A5*/\
634         MUX_VAL(CP(GPMC_A6),        (IDIS | PTD | DIS | M0)) /*GPMC_A6*/\
635         MUX_VAL(CP(GPMC_A7),        (IDIS | PTD | DIS | M0)) /*GPMC_A7*/\
636         MUX_VAL(CP(GPMC_A8),        (IDIS | PTD | DIS | M0)) /*GPMC_A8*/\
637         MUX_VAL(CP(GPMC_A9),        (IDIS | PTD | DIS | M0)) /*GPMC_A9*/\
638         MUX_VAL(CP(GPMC_A10),       (IDIS | PTD | DIS | M0)) /*GPMC_A10*/\
639         MUX_VAL(CP(GPMC_D0),        (IEN  | PTD | DIS | M0)) /*GPMC_D0*/\
640         MUX_VAL(CP(GPMC_D1),        (IEN  | PTD | DIS | M0)) /*GPMC_D1*/\
641         MUX_VAL(CP(GPMC_D2),        (IEN  | PTD | DIS | M0)) /*GPMC_D2*/\
642         MUX_VAL(CP(GPMC_D3),        (IEN  | PTD | DIS | M0)) /*GPMC_D3*/\
643         MUX_VAL(CP(GPMC_D4),        (IEN  | PTD | DIS | M0)) /*GPMC_D4*/\
644         MUX_VAL(CP(GPMC_D5),        (IEN  | PTD | DIS | M0)) /*GPMC_D5*/\
645         MUX_VAL(CP(GPMC_D6),        (IEN  | PTD | DIS | M0)) /*GPMC_D6*/\
646         MUX_VAL(CP(GPMC_D7),        (IEN  | PTD | DIS | M0)) /*GPMC_D7*/\
647         MUX_VAL(CP(GPMC_D8),        (IEN  | PTD | DIS | M0)) /*GPMC_D8*/\
648         MUX_VAL(CP(GPMC_D9),        (IEN  | PTD | DIS | M0)) /*GPMC_D9*/\
649         MUX_VAL(CP(GPMC_D10),       (IEN  | PTD | DIS | M0)) /*GPMC_D10*/\
650         MUX_VAL(CP(GPMC_D11),       (IEN  | PTD | DIS | M0)) /*GPMC_D11*/\
651         MUX_VAL(CP(GPMC_D12),       (IEN  | PTD | DIS | M0)) /*GPMC_D12*/\
652         MUX_VAL(CP(GPMC_D13),       (IEN  | PTD | DIS | M0)) /*GPMC_D13*/\
653         MUX_VAL(CP(GPMC_D14),       (IEN  | PTD | DIS | M0)) /*GPMC_D14*/\
654         MUX_VAL(CP(GPMC_D15),       (IEN  | PTD | DIS | M0)) /*GPMC_D15*/\
655         MUX_VAL(CP(GPMC_nCS0),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS0*/\
656         MUX_VAL(CP(GPMC_nCS1),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS1*/\
657         MUX_VAL(CP(GPMC_nCS2),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS2*/\
658         MUX_VAL(CP(GPMC_nCS3),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS3*/\
659         MUX_VAL(CP(GPMC_nCS4),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS4*/\
660         MUX_VAL(CP(GPMC_nCS5),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS5*/\
661         MUX_VAL(CP(GPMC_nCS6),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS6*/\
662         MUX_VAL(CP(GPMC_nCS7),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS7*/\
663         MUX_VAL(CP(GPMC_CLK),       (IDIS | PTD | DIS | M0)) /*GPMC_CLK*/\
664         MUX_VAL(CP(GPMC_nADV_ALE),  (IDIS | PTD | DIS | M0)) /*GPMC_nADV_ALE*/\
665         MUX_VAL(CP(GPMC_nOE),       (IDIS | PTD | DIS | M0)) /*GPMC_nOE*/\
666         MUX_VAL(CP(GPMC_nWE),       (IDIS | PTD | DIS | M0)) /*GPMC_nWE*/\
667         MUX_VAL(CP(GPMC_nBE0_CLE),  (IDIS | PTD | DIS | M0)) /*GPMC_nBE0_CLE*/\
668         MUX_VAL(CP(GPMC_nBE1),      (IEN  | PTD | DIS | M0)) /*GPIO_61*/\
669         MUX_VAL(CP(GPMC_nWP),       (IEN  | PTD | DIS | M0)) /*GPMC_nWP*/\
670         MUX_VAL(CP(GPMC_WAIT0),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT0*/\
671         MUX_VAL(CP(GPMC_WAIT1),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT1*/\
672         MUX_VAL(CP(GPMC_WAIT2),     (IEN  | PTU | EN  | M4)) /*GPIO_64*/\
673         MUX_VAL(CP(GPMC_WAIT3),     (IEN  | PTU | EN  | M4)) /*GPIO_65*/\
674         MUX_VAL(CP(DSS_DATA18),     (IEN  | PTD | DIS | M4)) /*GPIO_88*/\
675         MUX_VAL(CP(DSS_DATA19),     (IEN  | PTD | DIS | M4)) /*GPIO_89*/\
676         MUX_VAL(CP(DSS_DATA20),     (IEN  | PTD | DIS | M4)) /*GPIO_90*/\
677         MUX_VAL(CP(DSS_DATA21),     (IEN  | PTD | DIS | M4)) /*GPIO_91*/\
678         MUX_VAL(CP(CAM_WEN),        (IEN  | PTD | DIS | M4)) /*GPIO_167*/\
679         MUX_VAL(CP(MMC1_CLK),       (IDIS | PTU | EN  | M0)) /*MMC1_CLK*/\
680         MUX_VAL(CP(MMC1_CMD),       (IEN  | PTU | EN  | M0)) /*MMC1_CMD*/\
681         MUX_VAL(CP(MMC1_DAT0),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT0*/\
682         MUX_VAL(CP(MMC1_DAT1),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT1*/\
683         MUX_VAL(CP(MMC1_DAT2),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT2*/\
684         MUX_VAL(CP(MMC1_DAT3),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT3*/\
685         MUX_VAL(CP(MMC1_DAT4),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT4*/\
686         MUX_VAL(CP(MMC1_DAT5),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT5*/\
687         MUX_VAL(CP(MMC1_DAT6),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT6*/\
688         MUX_VAL(CP(MMC1_DAT7),      (IEN  | PTU | EN  | M0)) /*MMC1_DAT7*/\
689         MUX_VAL(CP(UART1_TX),       (IDIS | PTD | DIS | M0)) /*UART1_TX*/\
690         MUX_VAL(CP(UART1_RTS),      (IDIS | PTD | DIS | M0)) /*UART1_RTS*/\
691         MUX_VAL(CP(UART1_CTS),      (IEN | PTU | DIS | M0)) /*UART1_CTS*/\
692         MUX_VAL(CP(UART1_RX),       (IEN  | PTD | DIS | M0)) /*UART1_RX*/\
693         MUX_VAL(CP(UART3_CTS_RCTX), (IEN  | PTD | EN  | M0)) /*UART3_CTS_RCTX */\
694         MUX_VAL(CP(UART3_RTS_SD),   (IDIS | PTD | DIS | M0)) /*UART3_RTS_SD */\
695         MUX_VAL(CP(UART3_RX_IRRX),  (IEN  | PTD | DIS | M0)) /*UART3_RX_IRRX*/\
696         MUX_VAL(CP(UART3_TX_IRTX),  (IDIS | PTD | DIS | M0)) /*UART3_TX_IRTX*/\
697         MUX_VAL(CP(I2C1_SCL),       (IEN  | PTU | EN  | M0)) /*I2C1_SCL*/\
698         MUX_VAL(CP(I2C1_SDA),       (IEN  | PTU | EN  | M0)) /*I2C1_SDA*/\
699         MUX_VAL(CP(I2C2_SCL),       (IEN  | PTU | EN  | M0)) /*I2C2_SCL*/\
700         MUX_VAL(CP(I2C2_SDA),       (IEN  | PTU | EN  | M0)) /*I2C2_SDA*/\
701         MUX_VAL(CP(I2C3_SCL),       (IEN  | PTU | EN  | M0)) /*I2C3_SCL*/\
702         MUX_VAL(CP(I2C3_SDA),       (IEN  | PTU | EN  | M0)) /*I2C3_SDA*/\
703         MUX_VAL(CP(I2C4_SCL),       (IEN  | PTU | EN  | M0)) /*I2C4_SCL*/\
704         MUX_VAL(CP(I2C4_SDA),       (IEN  | PTU | EN  | M0)) /*I2C4_SDA*/\
705         MUX_VAL(CP(McBSP1_DX),      (IEN  | PTD | DIS | M4)) /*GPIO_158*/\
706         MUX_VAL(CP(SYS_32K),        (IEN  | PTD | DIS | M0)) /*SYS_32K*/\
707         MUX_VAL(CP(SYS_BOOT0),      (IEN  | PTD | DIS | M4)) /*GPIO_2 */\
708         MUX_VAL(CP(SYS_BOOT1),      (IEN  | PTD | DIS | M4)) /*GPIO_3 */\
709         MUX_VAL(CP(SYS_BOOT2),      (IEN  | PTD | DIS | M4)) /*GPIO_4 */\
710         MUX_VAL(CP(SYS_BOOT3),      (IEN  | PTD | DIS | M4)) /*GPIO_5 */\
711         MUX_VAL(CP(SYS_BOOT4),      (IEN  | PTD | DIS | M4)) /*GPIO_6 */\
712         MUX_VAL(CP(SYS_BOOT5),      (IEN  | PTD | DIS | M4)) /*GPIO_7 */\
713         MUX_VAL(CP(SYS_BOOT6),      (IEN  | PTD | DIS | M4)) /*GPIO_8 */\
714         MUX_VAL(CP(SYS_CLKOUT2),    (IEN  | PTU | EN  | M4)) /*GPIO_186*/\
715         MUX_VAL(CP(JTAG_nTRST),     (IEN  | PTD | DIS | M0)) /*JTAG_nTRST*/\
716         MUX_VAL(CP(JTAG_TCK),       (IEN  | PTD | DIS | M0)) /*JTAG_TCK*/\
717         MUX_VAL(CP(JTAG_TMS),       (IEN  | PTD | DIS | M0)) /*JTAG_TMS*/\
718         MUX_VAL(CP(JTAG_TDI),       (IEN  | PTD | DIS | M0)) /*JTAG_TDI*/\
719         MUX_VAL(CP(JTAG_EMU0),      (IEN  | PTD | DIS | M0)) /*JTAG_EMU0*/\
720         MUX_VAL(CP(JTAG_EMU1),      (IEN  | PTD | DIS | M0)) /*JTAG_EMU1*/\
721         MUX_VAL(CP(ETK_CLK),        (IEN  | PTD | DIS | M4)) /*GPIO_12*/\
722         MUX_VAL(CP(ETK_CTL),        (IEN  | PTD | DIS | M4)) /*GPIO_13*/\
723         MUX_VAL(CP(ETK_D0),         (IEN  | PTD | DIS | M4)) /*GPIO_14*/\
724         MUX_VAL(CP(ETK_D1),         (IEN  | PTD | DIS | M4)) /*GPIO_15*/\
725         MUX_VAL(CP(ETK_D2),         (IEN  | PTD | DIS | M4)) /*GPIO_16*/\
726         MUX_VAL(CP(ETK_D11),        (IEN  | PTD | DIS  | M4)) /*GPIO_25*/\
727         MUX_VAL(CP(ETK_D12),        (IDIS  | PTD | DIS | M4)) /*GPIO_26*/\
728         MUX_VAL(CP(ETK_D13),        (IDIS  | PTD | DIS | M4)) /*GPIO_27*/\
729         MUX_VAL(CP(ETK_D14),        (IEN  | PTD | DIS | M4)) /*GPIO_28*/\
730         MUX_VAL(CP(ETK_D15),        (IEN  | PTD | DIS | M4)) /*GPIO_29 */\
731         MUX_VAL(CP(sdrc_cke0),      (IDIS | PTU | EN  | M0)) /*sdrc_cke0 */\
732         MUX_VAL(CP(sdrc_cke1),      (IDIS | PTD | DIS | M7)) /*sdrc_cke1 not used*/
733
734 /**********************************************************
735  * Routine: set_muxconf_regs
736  * Description: Setting up the configuration Mux registers
737  *              specific to the hardware. Many pins need
738  *              to be moved from protect to primary mode.
739  *********************************************************/
740 void set_muxconf_regs(void)
741 {
742         MUX_DEFAULT();
743 }
744
745 /**********************************************************
746  * Routine: nand_init
747  * Description: Set up flash, NAND and OneNAND
748  *********************************************************/
749 int nand_init(void)
750 {
751 #ifdef CFG_ONENAND
752         config_onenand_nand0xgr4wxa();
753         if (onenand_chip()) {
754 #ifdef CFG_PRINTF
755                 printf("OneNAND Unsupported !\n");
756 #endif
757                 return 1;
758         }
759 #endif
760
761         return 0;
762 }
763
764 /* optionally do something */
765 void board_hang(void)
766 {
767 }
768
769 /******************************************************************************
770  * Dummy function to handle errors for EABI incompatibility
771  *****************************************************************************/
772 void raise(void)
773 {
774 }
775