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