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