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