fd7af92a31459bcd7a22df19b22c707ae2c4057e
[pandora-x-loader.git] / board / pandora / pandora.c
1 /*
2  * (C) Copyright 2006
3  * Texas Instruments, <www.ti.com>
4  * Jian Zhang <jzhang@ti.com>
5  * Richard Woodruff <r-woodruff2@ti.com>
6  *
7  * Modified for the Pandora
8  * John Willis <source@distant-earth.com>
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28
29 #include <common.h>
30 #include <command.h>
31 #include <part.h>
32 #include <fat.h>
33 #include <asm/arch/cpu.h>
34 #include <asm/arch/bits.h>
35 #include <asm/arch/mux.h>
36 #include <asm/arch/sys_proto.h>
37 #include <asm/arch/sys_info.h>
38 #include <asm/arch/clocks.h>
39 #include <asm/arch/mem.h>
40
41 /* Used to index into DPLL parameter tables */
42 struct dpll_param {
43         unsigned int m;
44         unsigned int n;
45         unsigned int fsel;
46         unsigned int m2;
47 };
48
49 typedef struct dpll_param dpll_param;
50
51 /* Following functions are exported from lowlevel_init.S */
52 extern dpll_param *get_mpu_dpll_param();
53 extern dpll_param *get_iva_dpll_param();
54 extern dpll_param *get_core_dpll_param();
55 extern dpll_param *get_per_dpll_param();
56
57 #define __raw_readl(a)          (*(volatile unsigned int *)(a))
58 #define __raw_writel(v, a)      (*(volatile unsigned int *)(a) = (v))
59 #define __raw_readw(a)          (*(volatile unsigned short *)(a))
60 #define __raw_writew(v, a)      (*(volatile unsigned short *)(a) = (v))
61
62 /*******************************************************
63  * Routine: delay
64  * Description: spinning delay to use before udelay works
65  ******************************************************/
66 static inline void delay(unsigned long loops)
67 {
68         __asm__ volatile ("1:\n" "subs %0, %1, #1\n"
69                           "bne 1b":"=r" (loops):"0"(loops));
70 }
71
72 void udelay (unsigned long usecs) {
73         delay(usecs);
74 }
75
76 /*****************************************
77  * Routine: board_init
78  * Description: Early hardware init.
79  *****************************************/
80 int board_init(void)
81 {
82 #if defined(CFG_PRINTF) && defined(CONFIG_DRIVER_OMAP34XX_I2C)
83         unsigned char byte;
84
85         /* do additional init to prevent trash being output on startup */
86         serial_init();
87
88 #ifdef CONFIG_PANDORA_FINAL
89         /*VAUX3 = 2.8V    (AV connector)*/
90         byte = 0x20;
91         i2c_write(0x4B, 0x7A, 1, &byte, 1);
92         byte = 0x03;
93         i2c_write(0x4B, 0x7D, 1, &byte, 1);
94 #else
95         /*VAUX4 = 2.8V    (TOUCH,NUBS,RS-232 TRANSCEIVER)*/
96         byte = 0x20;
97         i2c_write(0x4B, 0x7E, 1, &byte, 1);
98         byte = 0x0A;
99         i2c_write(0x4B, 0x81, 1, &byte, 1);
100 #endif
101
102         delay(10000);  /* give time to power up */
103 #endif
104
105         return 0;
106 }
107
108 /*************************************************************
109  *  get_device_type(): tell if GP/HS/EMU/TST
110  *************************************************************/
111 u32 get_device_type(void)
112 {
113         int mode;
114         mode = __raw_readl(CONTROL_STATUS) & (DEVICE_MASK);
115         return (mode >>= 8);
116 }
117
118 /************************************************
119  * get_sysboot_value(void) - return SYS_BOOT[4:0]
120  ************************************************/
121 u32 get_sysboot_value(void)
122 {
123         int mode;
124         mode = __raw_readl(CONTROL_STATUS) & (SYSBOOT_MASK);
125         return mode;
126 }
127
128 /*************************************************************
129  * Routine: get_mem_type(void) - returns the kind of memory connected
130  * to GPMC that we are trying to boot form. Uses SYS BOOT settings.
131  *************************************************************/
132 u32 get_mem_type(void)
133 {
134         u32   mem_type = get_sysboot_value();
135         switch (mem_type) {
136         case 0:
137         case 2:
138         case 4:
139         case 16:
140         case 22:
141                 return GPMC_ONENAND;
142
143         case 1:
144         case 12:
145         case 15:
146         case 21:
147         case 27:
148                 return GPMC_NAND;
149
150         case 3:
151         case 6:
152                 return MMC_ONENAND;
153
154         case 8:
155         case 11:
156         case 14:
157         case 20:
158         case 26:
159                 return GPMC_MDOC;
160
161         case 17:
162         case 18:
163         case 24:
164                 return MMC_NAND;
165
166         case 7:
167         case 10:
168         case 13:
169         case 19:
170         case 25:
171         default:
172                 return GPMC_NOR;
173         }
174 }
175
176 /******************************************
177  * get_cpu_rev(void) - extract version info
178  ******************************************/
179 u32 get_cpu_rev(void)
180 {
181         u32 cpuid = 0;
182         /* On ES1.0 the IDCODE register is not exposed on L4
183          * so using CPU ID to differentiate
184          * between ES2.0 and ES1.0.
185          */
186         __asm__ __volatile__("mrc p15, 0, %0, c0, c0, 0":"=r"(cpuid));
187         if ((cpuid & 0xf) == 0x0)
188                 return CPU_3430_ES1;
189         else
190                 return CPU_3430_ES2;
191
192 }
193
194 /******************************************
195  * cpu_is_3410(void) - returns true for 3410
196  ******************************************/
197 u32 cpu_is_3410(void)
198 {
199         int status;
200         if (get_cpu_rev() < CPU_3430_ES2) {
201                 return 0;
202         } else {
203                 /* read scalability status and return 1 for 3410*/
204                 status = __raw_readl(CONTROL_SCALABLE_OMAP_STATUS);
205                 /* Check whether MPU frequency is set to 266 MHz which
206                  * is nominal for 3410. If yes return true else false
207                  */
208                 if (((status >> 8) & 0x3) == 0x2)
209                         return 1;
210                 else
211                         return 0;
212         }
213 }
214
215 /*****************************************************************
216  * sr32 - clear & set a value in a bit range for a 32 bit address
217  *****************************************************************/
218 void sr32(u32 addr, u32 start_bit, u32 num_bits, u32 value)
219 {
220         u32 tmp, msk = 0;
221         msk = 1 << num_bits;
222         --msk;
223         tmp = __raw_readl(addr) & ~(msk << start_bit);
224         tmp |= value << start_bit;
225         __raw_writel(tmp, addr);
226 }
227
228 /*********************************************************************
229  * wait_on_value() - common routine to allow waiting for changes in
230  *   volatile regs.
231  *********************************************************************/
232 u32 wait_on_value(u32 read_bit_mask, u32 match_value, u32 read_addr, u32 bound)
233 {
234         u32 i = 0, val;
235         do {
236                 ++i;
237                 val = __raw_readl(read_addr) & read_bit_mask;
238                 if (val == match_value)
239                         return (1);
240                 if (i == bound)
241                         return (0);
242         } while (1);
243 }
244
245 #ifdef CFG_3430SDRAM_DDR
246 /*********************************************************************
247  * config_3430sdram_ddr() - Init DDR on 3430SDP dev board.
248  *********************************************************************/
249 void config_3430sdram_ddr(void)
250 {
251         /* reset sdrc controller */
252         __raw_writel(SOFTRESET, SDRC_SYSCONFIG);
253         wait_on_value(BIT0, BIT0, SDRC_STATUS, 12000000);
254         __raw_writel(0, SDRC_SYSCONFIG);
255
256         /* setup sdrc to ball mux */
257         __raw_writel(SDP_SDRC_SHARING, SDRC_SHARING);
258
259         /* SDRC put in weak */
260 //        (*(unsigned int*)0x6D00008C) = 0x00000020;
261
262         /* SDRC_MCFG0 register */
263         (*(unsigned int*)0x6D000080) = 0x02584099;//from Micron
264
265         /* SDRC_ACTIM_CTRLA0 register */
266 //our value        (*(unsigned int*)0x6D00009c) = 0xa29db4c6;// for 166M
267         (*(unsigned int*)0x6D00009c) = 0xaa9db4c6;// for 166M from rkw
268
269         /* SDRC_ACTIM_CTRLB0 register */
270 //from micron   (*(unsigned int*)0x6D0000a0) = 0x12214;// for 166M
271
272 //        (*(unsigned int*)0x6D0000a0) = 0x00011417; our value
273         (*(unsigned int*)0x6D0000a0) = 0x00011517;
274
275         /* SDRC_RFR_CTRL0 register */
276 //from micron   (*(unsigned int*)0x6D0000a4) =0x54601; // for 166M
277
278         (*(unsigned int*)0x6D0000a4) =0x0004DC01;
279
280         /* Disble Power Down of CKE cuz of 1 CKE on combo part */
281         (*(unsigned int*)0x6D000070) = 0x00000081;
282
283         /* SDRC_Manual command register */
284         (*(unsigned int*)0x6D0000a8) = 0x00000000; // NOP command
285         delay(5000);
286         (*(unsigned int*)0x6D0000a8) = 0x00000001; // Precharge command
287         (*(unsigned int*)0x6D0000a8) = 0x00000002; // Auto-refresh command
288         (*(unsigned int*)0x6D0000a8) = 0x00000002; // Auto-refresh command
289
290         /* SDRC MR0 register */
291         (*(int*)0x6D000084) = 0x00000032; // Burst length =4
292         // CAS latency = 3
293         // Write Burst = Read Burst
294         // Serial Mode
295
296         /* SDRC DLLA control register */
297         (*(unsigned int*)0x6D000060) = 0x0000A;
298         delay(0x20000); // some delay
299
300 }
301 #endif /* CFG_3430SDRAM_DDR */
302
303 /*************************************************************
304  * get_sys_clk_speed - determine reference oscillator speed
305  *  based on known 32kHz clock and gptimer.
306  *************************************************************/
307 u32 get_osc_clk_speed(void)
308 {
309         u32 start, cstart, cend, cdiff, val;
310
311         val = __raw_readl(PRM_CLKSRC_CTRL);
312         /* If SYS_CLK is being divided by 2, remove for now */
313         val = (val & (~BIT7)) | BIT6;
314         __raw_writel(val, PRM_CLKSRC_CTRL);
315
316         /* enable timer2 */
317         val = __raw_readl(CM_CLKSEL_WKUP) | BIT0;
318         __raw_writel(val, CM_CLKSEL_WKUP);      /* select sys_clk for GPT1 */
319
320         /* Enable I and F Clocks for GPT1 */
321         val = __raw_readl(CM_ICLKEN_WKUP) | BIT0 | BIT2;
322         __raw_writel(val, CM_ICLKEN_WKUP);
323         val = __raw_readl(CM_FCLKEN_WKUP) | BIT0;
324         __raw_writel(val, CM_FCLKEN_WKUP);
325
326         __raw_writel(0, OMAP34XX_GPT1 + TLDR);  /* start counting at 0 */
327         __raw_writel(GPT_EN, OMAP34XX_GPT1 + TCLR);     /* enable clock */
328         /* enable 32kHz source */
329         /* enabled out of reset */
330         /* determine sys_clk via gauging */
331
332         start = 20 + __raw_readl(S32K_CR);      /* start time in 20 cycles */
333         while (__raw_readl(S32K_CR) < start) ;  /* dead loop till start time */
334         cstart = __raw_readl(OMAP34XX_GPT1 + TCRR);     /* get start sys_clk count */
335         while (__raw_readl(S32K_CR) < (start + 20)) ;   /* wait for 40 cycles */
336         cend = __raw_readl(OMAP34XX_GPT1 + TCRR);       /* get end sys_clk count */
337         cdiff = cend - cstart;  /* get elapsed ticks */
338
339         /* based on number of ticks assign speed */
340         if (cdiff > 19000)
341                 return (S38_4M);
342         else if (cdiff > 15200)
343                 return (S26M);
344         else if (cdiff > 13000)
345                 return (S24M);
346         else if (cdiff > 9000)
347                 return (S19_2M);
348         else if (cdiff > 7600)
349                 return (S13M);
350         else
351                 return (S12M);
352 }
353
354 /******************************************************************************
355  * get_sys_clkin_sel() - returns the sys_clkin_sel field value based on
356  *   -- input oscillator clock frequency.
357  *
358  *****************************************************************************/
359 void get_sys_clkin_sel(u32 osc_clk, u32 * sys_clkin_sel)
360 {
361         if (osc_clk == S38_4M)
362                 *sys_clkin_sel = 4;
363         else if (osc_clk == S26M)
364                 *sys_clkin_sel = 3;
365         else if (osc_clk == S19_2M)
366                 *sys_clkin_sel = 2;
367         else if (osc_clk == S13M)
368                 *sys_clkin_sel = 1;
369         else if (osc_clk == S12M)
370                 *sys_clkin_sel = 0;
371 }
372
373 /******************************************************************************
374  * prcm_init() - inits clocks for PRCM as defined in clocks.h
375  *   -- called from SRAM, or Flash (using temp SRAM stack).
376  *****************************************************************************/
377 void prcm_init(void)
378 {
379         u32 osc_clk = 0, sys_clkin_sel;
380         dpll_param *dpll_param_p;
381         u32 clk_index, sil_index;
382
383         /* Gauge the input clock speed and find out the sys_clkin_sel
384          * value corresponding to the input clock.
385          */
386         osc_clk = get_osc_clk_speed();
387         get_sys_clkin_sel(osc_clk, &sys_clkin_sel);
388
389         sr32(PRM_CLKSEL, 0, 3, sys_clkin_sel);  /* set input crystal speed */
390
391         /* If the input clock is greater than 19.2M always divide/2 */
392         if (sys_clkin_sel > 2) {
393                 sr32(PRM_CLKSRC_CTRL, 6, 2, 2); /* input clock divider */
394                 clk_index = sys_clkin_sel / 2;
395         } else {
396                 sr32(PRM_CLKSRC_CTRL, 6, 2, 1); /* input clock divider */
397                 clk_index = sys_clkin_sel;
398         }
399
400         sr32(PRM_CLKSRC_CTRL, 0, 2, 0);/* Bypass mode: T2 inputs a square clock */
401
402         /* The DPLL tables are defined according to sysclk value and
403          * silicon revision. The clk_index value will be used to get
404          * the values for that input sysclk from the DPLL param table
405          * and sil_index will get the values for that SysClk for the
406          * appropriate silicon rev.
407          */
408         sil_index = get_cpu_rev() - 1;
409
410         /* Unlock MPU DPLL (slows things down, and needed later) */
411         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOW_POWER_BYPASS);
412         wait_on_value(BIT0, 0, CM_IDLEST_PLL_MPU, LDELAY);
413
414         /* Getting the base address of Core DPLL param table */
415         dpll_param_p = (dpll_param *) get_core_dpll_param();
416         /* Moving it to the right sysclk and ES rev base */
417         dpll_param_p = dpll_param_p + 2*clk_index + sil_index;
418         /* CORE DPLL */
419         /* sr32(CM_CLKSEL2_EMU) set override to work when asleep */
420         sr32(CM_CLKEN_PLL, 0, 3, PLL_FAST_RELOCK_BYPASS);
421         wait_on_value(BIT0, 0, CM_IDLEST_CKGEN, LDELAY);
422         sr32(CM_CLKSEL1_EMU, 16, 5, CORE_M3X2); /* m3x2 */
423         sr32(CM_CLKSEL1_PLL, 27, 2, dpll_param_p->m2);  /* Set M2 */
424         sr32(CM_CLKSEL1_PLL, 16, 11, dpll_param_p->m);  /* Set M */
425         sr32(CM_CLKSEL1_PLL, 8, 7, dpll_param_p->n);    /* Set N */
426         sr32(CM_CLKSEL1_PLL, 6, 1, 0);  /* 96M Src */
427         sr32(CM_CLKSEL_CORE, 8, 4, CORE_SSI_DIV);       /* ssi */
428         sr32(CM_CLKSEL_CORE, 4, 2, CORE_FUSB_DIV);      /* fsusb */
429         sr32(CM_CLKSEL_CORE, 2, 2, CORE_L4_DIV);        /* l4 */
430         sr32(CM_CLKSEL_CORE, 0, 2, CORE_L3_DIV);        /* l3 */
431         sr32(CM_CLKSEL_GFX, 0, 3, GFX_DIV);     /* gfx */
432         sr32(CM_CLKSEL_WKUP, 1, 2, WKUP_RSM);   /* reset mgr */
433         sr32(CM_CLKEN_PLL, 4, 4, dpll_param_p->fsel);   /* FREQSEL */
434         sr32(CM_CLKEN_PLL, 0, 3, PLL_LOCK);     /* lock mode */
435         wait_on_value(BIT0, 1, CM_IDLEST_CKGEN, LDELAY);
436
437         /* Getting the base address to PER  DPLL param table */
438         dpll_param_p = (dpll_param *) get_per_dpll_param();
439         /* Moving it to the right sysclk base */
440         dpll_param_p = dpll_param_p + clk_index;
441         /* PER DPLL */
442         sr32(CM_CLKEN_PLL, 16, 3, PLL_STOP);
443         wait_on_value(BIT1, 0, CM_IDLEST_CKGEN, LDELAY);
444         sr32(CM_CLKSEL1_EMU, 24, 5, PER_M6X2);  /* set M6 */
445         sr32(CM_CLKSEL_CAM, 0, 5, PER_M5X2);    /* set M5 */
446         sr32(CM_CLKSEL_DSS, 0, 5, PER_M4X2);    /* set M4 */
447         sr32(CM_CLKSEL_DSS, 8, 5, PER_M3X2);    /* set M3 */
448         sr32(CM_CLKSEL3_PLL, 0, 5, dpll_param_p->m2);   /* set M2 */
449         sr32(CM_CLKSEL2_PLL, 8, 11, dpll_param_p->m);   /* set m */
450         sr32(CM_CLKSEL2_PLL, 0, 7, dpll_param_p->n);    /* set n */
451         sr32(CM_CLKEN_PLL, 20, 4, dpll_param_p->fsel);  /* FREQSEL */
452         sr32(CM_CLKEN_PLL, 16, 3, PLL_LOCK);    /* lock mode */
453         wait_on_value(BIT1, 2, CM_IDLEST_CKGEN, LDELAY);
454
455         /* Getting the base address to MPU DPLL param table */
456         dpll_param_p = (dpll_param *) get_mpu_dpll_param();
457         /* Moving it to the right sysclk and ES rev base */
458         dpll_param_p = dpll_param_p + 2*clk_index + sil_index;
459         /* MPU DPLL (unlocked already) */
460         sr32(CM_CLKSEL2_PLL_MPU, 0, 5, dpll_param_p->m2);       /* Set M2 */
461         sr32(CM_CLKSEL1_PLL_MPU, 8, 11, dpll_param_p->m);       /* Set M */
462         sr32(CM_CLKSEL1_PLL_MPU, 0, 7, dpll_param_p->n);        /* Set N */
463         sr32(CM_CLKEN_PLL_MPU, 4, 4, dpll_param_p->fsel);       /* FREQSEL */
464         sr32(CM_CLKEN_PLL_MPU, 0, 3, PLL_LOCK); /* lock mode */
465         wait_on_value(BIT0, 1, CM_IDLEST_PLL_MPU, LDELAY);
466
467         /* Getting the base address to IVA DPLL param table */
468         dpll_param_p = (dpll_param *) get_iva_dpll_param();
469         /* Moving it to the right sysclk and ES rev base */
470         dpll_param_p = dpll_param_p + 2*clk_index + sil_index;
471         /* IVA DPLL (set to 12*20=240MHz) */
472         sr32(CM_CLKEN_PLL_IVA2, 0, 3, PLL_STOP);
473         wait_on_value(BIT0, 0, CM_IDLEST_PLL_IVA2, LDELAY);
474         sr32(CM_CLKSEL2_PLL_IVA2, 0, 5, dpll_param_p->m2);      /* set M2 */
475         sr32(CM_CLKSEL1_PLL_IVA2, 8, 11, dpll_param_p->m);      /* set M */
476         sr32(CM_CLKSEL1_PLL_IVA2, 0, 7, dpll_param_p->n);       /* set N */
477         sr32(CM_CLKEN_PLL_IVA2, 4, 4, dpll_param_p->fsel);      /* FREQSEL */
478         sr32(CM_CLKEN_PLL_IVA2, 0, 3, PLL_LOCK);        /* lock mode */
479         wait_on_value(BIT0, 1, CM_IDLEST_PLL_IVA2, LDELAY);
480
481         /* Set up GPTimers to sys_clk source only */
482         sr32(CM_CLKSEL_PER, 0, 8, 0xff);
483         sr32(CM_CLKSEL_WKUP, 0, 1, 1);
484
485         delay(5000);
486 }
487
488 /*****************************************
489  * Routine: secure_unlock
490  * Description: Setup security registers for access
491  * (GP Device only)
492  *****************************************/
493 void secure_unlock(void)
494 {
495         /* Permission values for registers -Full fledged permissions to all */
496 #define UNLOCK_1 0xFFFFFFFF
497 #define UNLOCK_2 0x00000000
498 #define UNLOCK_3 0x0000FFFF
499         /* Protection Module Register Target APE (PM_RT) */
500         __raw_writel(UNLOCK_1, RT_REQ_INFO_PERMISSION_1);
501         __raw_writel(UNLOCK_1, RT_READ_PERMISSION_0);
502         __raw_writel(UNLOCK_1, RT_WRITE_PERMISSION_0);
503         __raw_writel(UNLOCK_2, RT_ADDR_MATCH_1);
504
505         __raw_writel(UNLOCK_3, GPMC_REQ_INFO_PERMISSION_0);
506         __raw_writel(UNLOCK_3, GPMC_READ_PERMISSION_0);
507         __raw_writel(UNLOCK_3, GPMC_WRITE_PERMISSION_0);
508
509         __raw_writel(UNLOCK_3, OCM_REQ_INFO_PERMISSION_0);
510         __raw_writel(UNLOCK_3, OCM_READ_PERMISSION_0);
511         __raw_writel(UNLOCK_3, OCM_WRITE_PERMISSION_0);
512         __raw_writel(UNLOCK_2, OCM_ADDR_MATCH_2);
513
514         /* IVA Changes */
515         __raw_writel(UNLOCK_3, IVA2_REQ_INFO_PERMISSION_0);
516         __raw_writel(UNLOCK_3, IVA2_READ_PERMISSION_0);
517         __raw_writel(UNLOCK_3, IVA2_WRITE_PERMISSION_0);
518
519         __raw_writel(UNLOCK_1, SMS_RG_ATT0);    /* SDRC region 0 public */
520 }
521
522 /**********************************************************
523  * Routine: try_unlock_sram()
524  * Description: If chip is GP type, unlock the SRAM for
525  *  general use.
526  ***********************************************************/
527 void try_unlock_memory(void)
528 {
529         int mode;
530
531         /* if GP device unlock device SRAM for general use */
532         /* secure code breaks for Secure/Emulation device - HS/E/T */
533         mode = get_device_type();
534         if (mode == GP_DEVICE) {
535                 secure_unlock();
536         }
537         return;
538 }
539
540 /**********************************************************
541  * Routine: s_init
542  * Description: Does early system init of muxing and clocks.
543  * - Called at time when only stack is available.
544  **********************************************************/
545
546 void s_init(void)
547 {
548         watchdog_init();
549 #ifdef CONFIG_3430_AS_3410
550         /* setup the scalability control register for
551          * 3430 to work in 3410 mode
552          */
553         __raw_writel(0x5ABF, CONTROL_SCALABLE_OMAP_OCP);
554 #endif
555         try_unlock_memory();
556         set_muxconf_regs();
557         delay(100);
558         prcm_init();
559         per_clocks_enable();
560         config_3430sdram_ddr();
561 }
562
563 /*******************************************************
564  * Routine: misc_init_r
565  * Description: Init
566  ********************************************************/
567 int misc_init_r(void)
568 {
569 #ifdef CFG_PRINTF
570         printf("Pandora edition\n");
571 #endif
572
573         return (0);
574 }
575
576 /******************************************************
577  * Routine: wait_for_command_complete
578  * Description: Wait for posting to finish on watchdog
579  ******************************************************/
580 void wait_for_command_complete(unsigned int wd_base)
581 {
582         int pending = 1;
583         do {
584                 pending = __raw_readl(wd_base + WWPS);
585         } while (pending);
586 }
587
588 /****************************************
589  * Routine: watchdog_init
590  * Description: Shut down watch dogs
591  *****************************************/
592 void watchdog_init(void)
593 {
594         /* There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
595          * either taken care of by ROM (HS/EMU) or not accessible (GP).
596          * We need to take care of WD2-MPU or take a PRCM reset.  WD3
597          * should not be running and does not generate a PRCM reset.
598          */
599         sr32(CM_FCLKEN_WKUP, 5, 1, 1);
600         sr32(CM_ICLKEN_WKUP, 5, 1, 1);
601         wait_on_value(BIT5, 0x20, CM_IDLEST_WKUP, 5);   /* some issue here */
602
603         __raw_writel(WD_UNLOCK1, WD2_BASE + WSPR);
604         wait_for_command_complete(WD2_BASE);
605         __raw_writel(WD_UNLOCK2, WD2_BASE + WSPR);
606 }
607
608 /**********************************************
609  * Routine: dram_init
610  * Description: sets uboots idea of sdram size
611  **********************************************/
612 int dram_init(void)
613 {
614         return 0;
615 }
616
617 /*****************************************************************
618  * Routine: peripheral_enable
619  * Description: Enable the clks & power for perifs (GPT2, UART1,...)
620  ******************************************************************/
621 void per_clocks_enable(void)
622 {
623         /* Enable GP2 timer. */
624         sr32(CM_CLKSEL_PER, 0, 1, 0x1); /* GPT2 = sys clk */
625         sr32(CM_ICLKEN_PER, 3, 1, 0x1); /* ICKen GPT2 */
626         sr32(CM_FCLKEN_PER, 3, 1, 0x1); /* FCKen GPT2 */
627
628 #ifdef CFG_NS16550
629         /* Enable UART1 clocks */
630         sr32(CM_FCLKEN1_CORE, 13, 1, 0x1);
631         sr32(CM_ICLKEN1_CORE, 13, 1, 0x1);
632
633         /* UART 3 Clocks */
634         sr32(CM_FCLKEN_PER, 11, 1, 0x1);
635         sr32(CM_ICLKEN_PER, 11, 1, 0x1);
636
637 #endif
638
639 #ifdef CONFIG_DRIVER_OMAP34XX_I2C
640         /* Turn on all 3 I2C clocks */
641         sr32(CM_FCLKEN1_CORE, 15, 3, 0x7);
642         sr32(CM_ICLKEN1_CORE, 15, 3, 0x7);      /* I2C1,2,3 = on */
643 #endif
644
645         /* Enable the ICLK for 32K Sync Timer as its used in udelay */
646         sr32(CM_ICLKEN_WKUP, 2, 1, 0x1);
647
648         sr32(CM_FCLKEN_IVA2, 0, 32, FCK_IVA2_ON);
649         sr32(CM_FCLKEN1_CORE, 0, 32, FCK_CORE1_ON);
650         sr32(CM_ICLKEN1_CORE, 0, 32, ICK_CORE1_ON);
651         sr32(CM_ICLKEN2_CORE, 0, 32, ICK_CORE2_ON);
652         sr32(CM_FCLKEN_WKUP, 0, 32, FCK_WKUP_ON);
653         sr32(CM_ICLKEN_WKUP, 0, 32, ICK_WKUP_ON);
654         sr32(CM_FCLKEN_DSS, 0, 32, FCK_DSS_ON);
655         sr32(CM_ICLKEN_DSS, 0, 32, ICK_DSS_ON);
656         sr32(CM_FCLKEN_CAM, 0, 32, FCK_CAM_ON);
657         sr32(CM_ICLKEN_CAM, 0, 32, ICK_CAM_ON);
658         sr32(CM_FCLKEN_PER, 0, 32, FCK_PER_ON);
659         sr32(CM_ICLKEN_PER, 0, 32, ICK_PER_ON);
660
661         /* Enable GPIO5 clocks for blinky LEDs */
662         sr32(CM_FCLKEN_PER, 16, 1, 0x1);        /* FCKen GPIO5 */
663         sr32(CM_ICLKEN_PER, 16, 1, 0x1);        /* ICKen GPIO5 */
664
665         delay(1000);
666 }
667
668 /* Set MUX for UART, GPMC, SDRC, GPIO */
669
670 #define         MUX_VAL(OFFSET,VALUE)\
671                 __raw_writew((VALUE), OMAP34XX_CTRL_BASE + (OFFSET));
672
673 #define         CP(x)   (CONTROL_PADCONF_##x)
674 /*
675  * IEN  - Input Enable
676  * IDIS - Input Disable
677  * PTD  - Pull type Down
678  * PTU  - Pull type Up
679  * DIS  - Pull type selection is inactive
680  * EN   - Pull type selection is active
681  * M0   - Mode 0
682  * The commented string gives the final mux configuration for that pin
683  */
684 #define MUX_DEFAULT()\
685         /*SDRC*/\
686         MUX_VAL(CP(SDRC_D0),        (IEN  | PTD | DIS | M0)) /*SDRC_D0*/\
687         MUX_VAL(CP(SDRC_D1),        (IEN  | PTD | DIS | M0)) /*SDRC_D1*/\
688         MUX_VAL(CP(SDRC_D2),        (IEN  | PTD | DIS | M0)) /*SDRC_D2*/\
689         MUX_VAL(CP(SDRC_D3),        (IEN  | PTD | DIS | M0)) /*SDRC_D3*/\
690         MUX_VAL(CP(SDRC_D4),        (IEN  | PTD | DIS | M0)) /*SDRC_D4*/\
691         MUX_VAL(CP(SDRC_D5),        (IEN  | PTD | DIS | M0)) /*SDRC_D5*/\
692         MUX_VAL(CP(SDRC_D6),        (IEN  | PTD | DIS | M0)) /*SDRC_D6*/\
693         MUX_VAL(CP(SDRC_D7),        (IEN  | PTD | DIS | M0)) /*SDRC_D7*/\
694         MUX_VAL(CP(SDRC_D8),        (IEN  | PTD | DIS | M0)) /*SDRC_D8*/\
695         MUX_VAL(CP(SDRC_D9),        (IEN  | PTD | DIS | M0)) /*SDRC_D9*/\
696         MUX_VAL(CP(SDRC_D10),       (IEN  | PTD | DIS | M0)) /*SDRC_D10*/\
697         MUX_VAL(CP(SDRC_D11),       (IEN  | PTD | DIS | M0)) /*SDRC_D11*/\
698         MUX_VAL(CP(SDRC_D12),       (IEN  | PTD | DIS | M0)) /*SDRC_D12*/\
699         MUX_VAL(CP(SDRC_D13),       (IEN  | PTD | DIS | M0)) /*SDRC_D13*/\
700         MUX_VAL(CP(SDRC_D14),       (IEN  | PTD | DIS | M0)) /*SDRC_D14*/\
701         MUX_VAL(CP(SDRC_D15),       (IEN  | PTD | DIS | M0)) /*SDRC_D15*/\
702         MUX_VAL(CP(SDRC_D16),       (IEN  | PTD | DIS | M0)) /*SDRC_D16*/\
703         MUX_VAL(CP(SDRC_D17),       (IEN  | PTD | DIS | M0)) /*SDRC_D17*/\
704         MUX_VAL(CP(SDRC_D18),       (IEN  | PTD | DIS | M0)) /*SDRC_D18*/\
705         MUX_VAL(CP(SDRC_D19),       (IEN  | PTD | DIS | M0)) /*SDRC_D19*/\
706         MUX_VAL(CP(SDRC_D20),       (IEN  | PTD | DIS | M0)) /*SDRC_D20*/\
707         MUX_VAL(CP(SDRC_D21),       (IEN  | PTD | DIS | M0)) /*SDRC_D21*/\
708         MUX_VAL(CP(SDRC_D22),       (IEN  | PTD | DIS | M0)) /*SDRC_D22*/\
709         MUX_VAL(CP(SDRC_D23),       (IEN  | PTD | DIS | M0)) /*SDRC_D23*/\
710         MUX_VAL(CP(SDRC_D24),       (IEN  | PTD | DIS | M0)) /*SDRC_D24*/\
711         MUX_VAL(CP(SDRC_D25),       (IEN  | PTD | DIS | M0)) /*SDRC_D25*/\
712         MUX_VAL(CP(SDRC_D26),       (IEN  | PTD | DIS | M0)) /*SDRC_D26*/\
713         MUX_VAL(CP(SDRC_D27),       (IEN  | PTD | DIS | M0)) /*SDRC_D27*/\
714         MUX_VAL(CP(SDRC_D28),       (IEN  | PTD | DIS | M0)) /*SDRC_D28*/\
715         MUX_VAL(CP(SDRC_D29),       (IEN  | PTD | DIS | M0)) /*SDRC_D29*/\
716         MUX_VAL(CP(SDRC_D30),       (IEN  | PTD | DIS | M0)) /*SDRC_D30*/\
717         MUX_VAL(CP(SDRC_D31),       (IEN  | PTD | DIS | M0)) /*SDRC_D31*/\
718         MUX_VAL(CP(SDRC_CLK),       (IEN  | PTD | DIS | M0)) /*SDRC_CLK*/\
719         MUX_VAL(CP(SDRC_DQS0),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS0*/\
720         MUX_VAL(CP(SDRC_DQS1),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS1*/\
721         MUX_VAL(CP(SDRC_DQS2),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS2*/\
722         MUX_VAL(CP(SDRC_DQS3),      (IEN  | PTD | DIS | M0)) /*SDRC_DQS3*/\
723         /*GPMC*/\
724         MUX_VAL(CP(GPMC_A1),        (IDIS | PTD | DIS | M0)) /*GPMC_A1*/\
725         MUX_VAL(CP(GPMC_A2),        (IDIS | PTD | DIS | M0)) /*GPMC_A2*/\
726         MUX_VAL(CP(GPMC_A3),        (IDIS | PTD | DIS | M0)) /*GPMC_A3*/\
727         MUX_VAL(CP(GPMC_A4),        (IDIS | PTD | DIS | M0)) /*GPMC_A4*/\
728         MUX_VAL(CP(GPMC_A5),        (IDIS | PTD | DIS | M0)) /*GPMC_A5*/\
729         MUX_VAL(CP(GPMC_A6),        (IDIS | PTD | DIS | M0)) /*GPMC_A6*/\
730         MUX_VAL(CP(GPMC_A7),        (IDIS | PTD | DIS | M0)) /*GPMC_A7*/\
731         MUX_VAL(CP(GPMC_A8),        (IDIS | PTD | DIS | M0)) /*GPMC_A8*/\
732         MUX_VAL(CP(GPMC_A9),        (IDIS | PTD | DIS | M0)) /*GPMC_A9*/\
733         MUX_VAL(CP(GPMC_A10),       (IDIS | PTD | DIS | M0)) /*GPMC_A10*/\
734         MUX_VAL(CP(GPMC_D0),        (IEN  | PTD | DIS | M0)) /*GPMC_D0*/\
735         MUX_VAL(CP(GPMC_D1),        (IEN  | PTD | DIS | M0)) /*GPMC_D1*/\
736         MUX_VAL(CP(GPMC_D2),        (IEN  | PTD | DIS | M0)) /*GPMC_D2*/\
737         MUX_VAL(CP(GPMC_D3),        (IEN  | PTD | DIS | M0)) /*GPMC_D3*/\
738         MUX_VAL(CP(GPMC_D4),        (IEN  | PTD | DIS | M0)) /*GPMC_D4*/\
739         MUX_VAL(CP(GPMC_D5),        (IEN  | PTD | DIS | M0)) /*GPMC_D5*/\
740         MUX_VAL(CP(GPMC_D6),        (IEN  | PTD | DIS | M0)) /*GPMC_D6*/\
741         MUX_VAL(CP(GPMC_D7),        (IEN  | PTD | DIS | M0)) /*GPMC_D7*/\
742         MUX_VAL(CP(GPMC_D8),        (IEN  | PTD | DIS | M0)) /*GPMC_D8*/\
743         MUX_VAL(CP(GPMC_D9),        (IEN  | PTD | DIS | M0)) /*GPMC_D9*/\
744         MUX_VAL(CP(GPMC_D10),       (IEN  | PTD | DIS | M0)) /*GPMC_D10*/\
745         MUX_VAL(CP(GPMC_D11),       (IEN  | PTD | DIS | M0)) /*GPMC_D11*/\
746         MUX_VAL(CP(GPMC_D12),       (IEN  | PTD | DIS | M0)) /*GPMC_D12*/\
747         MUX_VAL(CP(GPMC_D13),       (IEN  | PTD | DIS | M0)) /*GPMC_D13*/\
748         MUX_VAL(CP(GPMC_D14),       (IEN  | PTD | DIS | M0)) /*GPMC_D14*/\
749         MUX_VAL(CP(GPMC_D15),       (IEN  | PTD | DIS | M0)) /*GPMC_D15*/\
750         MUX_VAL(CP(GPMC_nCS0),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS0*/\
751         MUX_VAL(CP(GPMC_nCS1),      (IDIS | PTU | EN  | M0)) /*GPMC_nCS1*/\
752         MUX_VAL(CP(GPMC_CLK),       (IDIS | PTD | DIS | M0)) /*GPMC_CLK*/\
753         MUX_VAL(CP(GPMC_nADV_ALE),  (IDIS | PTD | DIS | M0)) /*GPMC_nADV_ALE*/\
754         MUX_VAL(CP(GPMC_nOE),       (IDIS | PTD | DIS | M0)) /*GPMC_nOE*/\
755         MUX_VAL(CP(GPMC_nWE),       (IDIS | PTD | DIS | M0)) /*GPMC_nWE*/\
756         MUX_VAL(CP(GPMC_nBE0_CLE),  (IDIS | PTD | DIS | M0)) /*GPMC_nBE0_CLE*/\
757         MUX_VAL(CP(GPMC_nWP),       (IEN  | PTD | DIS | M0)) /*GPMC_nWP*/\
758         MUX_VAL(CP(GPMC_WAIT0),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT0*/\
759         MUX_VAL(CP(GPMC_WAIT1),     (IEN  | PTU | EN  | M0)) /*GPMC_WAIT1*/\
760         /*Serial Interface (Peripheral boot, Linux console)*/\
761         MUX_VAL(CP(UART3_RX_IRRX ), (IEN  | PTD | DIS | M0)) /*UART3_RX*/\
762         MUX_VAL(CP(UART3_TX_IRTX ), (IDIS | PTD | DIS | M0)) /*UART3_TX*/\
763         /*I2C Ports*/\
764         MUX_VAL(CP(I2C1_SCL),       (IEN  | PTU | EN  | M0)) /*I2C1_SCL*/\
765         MUX_VAL(CP(I2C1_SDA),       (IEN  | PTU | EN  | M0)) /*I2C1_SDA*/\
766         /*LEDs (Controlled by OMAP)*/\
767         MUX_VAL(CP(MMC1_DAT6),      (IDIS | PTD | DIS | M4)) /*GPIO_128*/\
768         MUX_VAL(CP(MMC1_DAT7),      (IDIS | PTD | DIS | M4)) /*GPIO_129*/\
769
770 /**********************************************************
771  * Routine: set_muxconf_regs
772  * Description: Setting up the configuration Mux registers
773  *              specific to the hardware. Many pins need
774  *              to be moved from protect to primary mode.
775  *********************************************************/
776 void set_muxconf_regs(void)
777 {
778         MUX_DEFAULT();
779 }
780
781 /**********************************************************
782  * Routine: nand+_init
783  * Description: Set up nand for nand and jffs2 commands
784  *********************************************************/
785 int nand_init(void)
786 {
787         /* global settings */
788         __raw_writel(0x10, GPMC_SYSCONFIG);     /* smart idle */
789         __raw_writel(0x0, GPMC_IRQENABLE);      /* isr's sources masked */
790         __raw_writel(0, GPMC_TIMEOUT_CONTROL);  /* timeout disable */
791 #ifdef CFG_NAND
792         __raw_writel(0x001, GPMC_CONFIG);       /* set nWP, disable limited addr */
793 #endif
794
795         /* Set the GPMC Vals, NAND is mapped at CS0
796          *  We configure only GPMC CS0 with required values. Configuring other devices
797          *  at other CS is done in u-boot. So we don't have to bother doing it here.
798          */
799         __raw_writel(0, GPMC_CONFIG7 + GPMC_CONFIG_CS0);
800         delay(1000);
801
802         if ((get_mem_type() == GPMC_NAND) || (get_mem_type() == MMC_NAND)) {
803                 __raw_writel(M_NAND_GPMC_CONFIG1, GPMC_CONFIG1 + GPMC_CONFIG_CS0);
804                 __raw_writel(M_NAND_GPMC_CONFIG2, GPMC_CONFIG2 + GPMC_CONFIG_CS0);
805                 __raw_writel(M_NAND_GPMC_CONFIG3, GPMC_CONFIG3 + GPMC_CONFIG_CS0);
806                 __raw_writel(M_NAND_GPMC_CONFIG4, GPMC_CONFIG4 + GPMC_CONFIG_CS0);
807                 __raw_writel(M_NAND_GPMC_CONFIG5, GPMC_CONFIG5 + GPMC_CONFIG_CS0);
808                 __raw_writel(M_NAND_GPMC_CONFIG6, GPMC_CONFIG6 + GPMC_CONFIG_CS0);
809
810                 /* Enable the GPMC Mapping */
811                 __raw_writel((((OMAP34XX_GPMC_CS0_SIZE & 0xF)<<8) |
812                              ((NAND_BASE_ADR>>24) & 0x3F) |
813                              (1<<6)),  (GPMC_CONFIG7 + GPMC_CONFIG_CS0));
814                 delay(2000);
815
816                 if (nand_chip()) {
817 #ifdef CFG_PRINTF
818                         printf("Unsupported Chip!\n");
819 #endif
820                         return 1;
821                 }
822
823         }
824
825         if ((get_mem_type() == GPMC_ONENAND) || (get_mem_type() == MMC_ONENAND)) {
826                 __raw_writel(ONENAND_GPMC_CONFIG1, GPMC_CONFIG1 + GPMC_CONFIG_CS0);
827                 __raw_writel(ONENAND_GPMC_CONFIG2, GPMC_CONFIG2 + GPMC_CONFIG_CS0);
828                 __raw_writel(ONENAND_GPMC_CONFIG3, GPMC_CONFIG3 + GPMC_CONFIG_CS0);
829                 __raw_writel(ONENAND_GPMC_CONFIG4, GPMC_CONFIG4 + GPMC_CONFIG_CS0);
830                 __raw_writel(ONENAND_GPMC_CONFIG5, GPMC_CONFIG5 + GPMC_CONFIG_CS0);
831                 __raw_writel(ONENAND_GPMC_CONFIG6, GPMC_CONFIG6 + GPMC_CONFIG_CS0);
832
833                 /* Enable the GPMC Mapping */
834                 __raw_writel((((OMAP34XX_GPMC_CS0_SIZE & 0xF)<<8) |
835                              ((ONENAND_BASE>>24) & 0x3F) |
836                              (1<<6)),  (GPMC_CONFIG7 + GPMC_CONFIG_CS0));
837                 delay(2000);
838
839                 if (onenand_chip()) {
840 #ifdef CFG_PRINTF
841                         printf("OneNAND Unsupported !\n");
842 #endif
843                         return 1;
844                 }
845         }
846         return 0;
847 }
848
849 #define DEBUG_SD1_LED                   128     /* gpio - SD Slot 1 */
850 #define DEBUG_SD2_LED                   129     /* gpio - SD Slot 2 */
851
852 void blinkLEDs()
853 {
854         void *p;
855
856         /* Alternately turn the LEDs on and off */
857         p = (unsigned long *)OMAP34XX_GPIO5_BASE;
858         while (1) {
859                 /* turn LED1 on and LED2 off */
860                 *(unsigned long *)(p + 0x94) = 1 << (DEBUG_SD1_LED % 32);
861                 *(unsigned long *)(p + 0x90) = 1 << (DEBUG_SD2_LED % 32);
862
863                 /* delay for a while */
864                 delay(1000);
865
866                 /* turn LED1 off and LED2 on */
867                 *(unsigned long *)(p + 0x90) = 1 << (DEBUG_SD1_LED % 32);
868                 *(unsigned long *)(p + 0x94) = 1 << (DEBUG_SD2_LED % 32);
869
870                 /* delay for a while */
871                 delay(1000);
872         }
873 }
874
875 /* optionally do something like blinking LED */
876 void board_hang(void)
877 {
878         while (1)
879                 blinkLEDs();
880 }
881
882 /******************************************************************************
883  * Dummy function to handle errors for EABI incompatibility
884  *****************************************************************************/
885 void raise(void)
886 {
887 }
888
889 /******************************************************************************
890  * Dummy function to handle errors for EABI incompatibility
891  *****************************************************************************/
892 void abort(void)
893 {
894 }