]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/omap3/board.c
i2c: designware: add an implement i2c protos
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / omap3 / board.c
1 /*
2  *
3  * Common board functions for OMAP3 based boards.
4  *
5  * (C) Copyright 2004-2008
6  * Texas Instruments, <www.ti.com>
7  *
8  * Author :
9  *      Sunil Kumar <sunilsaini05@gmail.com>
10  *      Shashi Ranjan <shashiranjanmca05@gmail.com>
11  *
12  * Derived from Beagle Board and 3430 SDP code by
13  *      Richard Woodruff <r-woodruff2@ti.com>
14  *      Syed Mohammed Khasim <khasim@ti.com>
15  *
16  *
17  * SPDX-License-Identifier:     GPL-2.0+
18  */
19 #include <common.h>
20 #include <mmc.h>
21 #include <spl.h>
22 #include <asm/io.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/arch/mem.h>
25 #include <asm/cache.h>
26 #include <asm/armv7.h>
27 #include <asm/arch/gpio.h>
28 #include <asm/omap_common.h>
29 #include <asm/arch/mmc_host_def.h>
30 #include <i2c.h>
31 #include <linux/compiler.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 /* Declarations */
36 extern omap3_sysinfo sysinfo;
37 static void omap3_setup_aux_cr(void);
38 #ifndef CONFIG_SYS_L2CACHE_OFF
39 static void omap3_invalidate_l2_cache_secure(void);
40 #endif
41
42 static const struct gpio_bank gpio_bank_34xx[6] = {
43         { (void *)OMAP34XX_GPIO1_BASE, METHOD_GPIO_24XX },
44         { (void *)OMAP34XX_GPIO2_BASE, METHOD_GPIO_24XX },
45         { (void *)OMAP34XX_GPIO3_BASE, METHOD_GPIO_24XX },
46         { (void *)OMAP34XX_GPIO4_BASE, METHOD_GPIO_24XX },
47         { (void *)OMAP34XX_GPIO5_BASE, METHOD_GPIO_24XX },
48         { (void *)OMAP34XX_GPIO6_BASE, METHOD_GPIO_24XX },
49 };
50
51 const struct gpio_bank *const omap_gpio_bank = gpio_bank_34xx;
52
53 #ifdef CONFIG_SPL_BUILD
54 /*
55 * We use static variables because global data is not ready yet.
56 * Initialized data is available in SPL right from the beginning.
57 * We would not typically need to save these parameters in regular
58 * U-Boot. This is needed only in SPL at the moment.
59 */
60 u32 omap3_boot_device = BOOT_DEVICE_NAND;
61
62 /* auto boot mode detection is not possible for OMAP3 - hard code */
63 u32 spl_boot_mode(void)
64 {
65         switch (spl_boot_device()) {
66         case BOOT_DEVICE_MMC2:
67                 return MMCSD_MODE_RAW;
68         case BOOT_DEVICE_MMC1:
69                 return MMCSD_MODE_FAT;
70                 break;
71         default:
72                 puts("spl: ERROR:  unknown device - can't select boot mode\n");
73                 hang();
74         }
75 }
76
77 u32 spl_boot_device(void)
78 {
79         return omap3_boot_device;
80 }
81
82 int board_mmc_init(bd_t *bis)
83 {
84         switch (spl_boot_device()) {
85         case BOOT_DEVICE_MMC1:
86                 omap_mmc_init(0, 0, 0, -1, -1);
87                 break;
88         case BOOT_DEVICE_MMC2:
89         case BOOT_DEVICE_MMC2_2:
90                 omap_mmc_init(1, 0, 0, -1, -1);
91                 break;
92         }
93         return 0;
94 }
95
96 void spl_board_init(void)
97 {
98 #if defined(CONFIG_SPL_NAND_SUPPORT) || defined(CONFIG_SPL_ONENAND_SUPPORT)
99         gpmc_init();
100 #endif
101 #ifdef CONFIG_SPL_I2C_SUPPORT
102         i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
103 #endif
104 }
105 #endif /* CONFIG_SPL_BUILD */
106
107
108 /******************************************************************************
109  * Routine: secure_unlock
110  * Description: Setup security registers for access
111  *              (GP Device only)
112  *****************************************************************************/
113 void secure_unlock_mem(void)
114 {
115         struct pm *pm_rt_ape_base = (struct pm *)PM_RT_APE_BASE_ADDR_ARM;
116         struct pm *pm_gpmc_base = (struct pm *)PM_GPMC_BASE_ADDR_ARM;
117         struct pm *pm_ocm_ram_base = (struct pm *)PM_OCM_RAM_BASE_ADDR_ARM;
118         struct pm *pm_iva2_base = (struct pm *)PM_IVA2_BASE_ADDR_ARM;
119         struct sms *sms_base = (struct sms *)OMAP34XX_SMS_BASE;
120
121         /* Protection Module Register Target APE (PM_RT) */
122         writel(UNLOCK_1, &pm_rt_ape_base->req_info_permission_1);
123         writel(UNLOCK_1, &pm_rt_ape_base->read_permission_0);
124         writel(UNLOCK_1, &pm_rt_ape_base->wirte_permission_0);
125         writel(UNLOCK_2, &pm_rt_ape_base->addr_match_1);
126
127         writel(UNLOCK_3, &pm_gpmc_base->req_info_permission_0);
128         writel(UNLOCK_3, &pm_gpmc_base->read_permission_0);
129         writel(UNLOCK_3, &pm_gpmc_base->wirte_permission_0);
130
131         writel(UNLOCK_3, &pm_ocm_ram_base->req_info_permission_0);
132         writel(UNLOCK_3, &pm_ocm_ram_base->read_permission_0);
133         writel(UNLOCK_3, &pm_ocm_ram_base->wirte_permission_0);
134         writel(UNLOCK_2, &pm_ocm_ram_base->addr_match_2);
135
136         /* IVA Changes */
137         writel(UNLOCK_3, &pm_iva2_base->req_info_permission_0);
138         writel(UNLOCK_3, &pm_iva2_base->read_permission_0);
139         writel(UNLOCK_3, &pm_iva2_base->wirte_permission_0);
140
141         /* SDRC region 0 public */
142         writel(UNLOCK_1, &sms_base->rg_att0);
143 }
144
145 /******************************************************************************
146  * Routine: secureworld_exit()
147  * Description: If chip is EMU and boot type is external
148  *              configure secure registers and exit secure world
149  *              general use.
150  *****************************************************************************/
151 void secureworld_exit(void)
152 {
153         unsigned long i;
154
155         /* configure non-secure access control register */
156         __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 2":"=r"(i));
157         /* enabling co-processor CP10 and CP11 accesses in NS world */
158         __asm__ __volatile__("orr %0, %0, #0xC00":"=r"(i));
159         /*
160          * allow allocation of locked TLBs and L2 lines in NS world
161          * allow use of PLE registers in NS world also
162          */
163         __asm__ __volatile__("orr %0, %0, #0x70000":"=r"(i));
164         __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 2":"=r"(i));
165
166         /* Enable ASA in ACR register */
167         __asm__ __volatile__("mrc p15, 0, %0, c1, c0, 1":"=r"(i));
168         __asm__ __volatile__("orr %0, %0, #0x10":"=r"(i));
169         __asm__ __volatile__("mcr p15, 0, %0, c1, c0, 1":"=r"(i));
170
171         /* Exiting secure world */
172         __asm__ __volatile__("mrc p15, 0, %0, c1, c1, 0":"=r"(i));
173         __asm__ __volatile__("orr %0, %0, #0x31":"=r"(i));
174         __asm__ __volatile__("mcr p15, 0, %0, c1, c1, 0":"=r"(i));
175 }
176
177 /******************************************************************************
178  * Routine: try_unlock_sram()
179  * Description: If chip is GP/EMU(special) type, unlock the SRAM for
180  *              general use.
181  *****************************************************************************/
182 void try_unlock_memory(void)
183 {
184         int mode;
185         int in_sdram = is_running_in_sdram();
186
187         /*
188          * if GP device unlock device SRAM for general use
189          * secure code breaks for Secure/Emulation device - HS/E/T
190          */
191         mode = get_device_type();
192         if (mode == GP_DEVICE)
193                 secure_unlock_mem();
194
195         /*
196          * If device is EMU and boot is XIP external booting
197          * Unlock firewalls and disable L2 and put chip
198          * out of secure world
199          *
200          * Assuming memories are unlocked by the demon who put us in SDRAM
201          */
202         if ((mode <= EMU_DEVICE) && (get_boot_type() == 0x1F)
203             && (!in_sdram)) {
204                 secure_unlock_mem();
205                 secureworld_exit();
206         }
207
208         return;
209 }
210
211 /******************************************************************************
212  * Routine: s_init
213  * Description: Does early system init of muxing and clocks.
214  *              - Called path is with SRAM stack.
215  *****************************************************************************/
216 void s_init(void)
217 {
218         int in_sdram = is_running_in_sdram();
219
220         watchdog_init();
221
222         try_unlock_memory();
223
224         /* Errata workarounds */
225         omap3_setup_aux_cr();
226
227 #ifndef CONFIG_SYS_L2CACHE_OFF
228         /* Invalidate L2-cache from secure mode */
229         omap3_invalidate_l2_cache_secure();
230 #endif
231
232         set_muxconf_regs();
233         sdelay(100);
234
235         prcm_init();
236
237         per_clocks_enable();
238
239 #ifdef CONFIG_USB_EHCI_OMAP
240         ehci_clocks_enable();
241 #endif
242
243 #ifdef CONFIG_SPL_BUILD
244         gd = &gdata;
245
246         preloader_console_init();
247
248         timer_init();
249 #endif
250
251         if (!in_sdram)
252                 mem_init();
253 }
254
255 /*
256  * Routine: misc_init_r
257  * Description: A basic misc_init_r that just displays the die ID
258  */
259 int __weak misc_init_r(void)
260 {
261         dieid_num_r();
262
263         return 0;
264 }
265
266 /******************************************************************************
267  * Routine: wait_for_command_complete
268  * Description: Wait for posting to finish on watchdog
269  *****************************************************************************/
270 static void wait_for_command_complete(struct watchdog *wd_base)
271 {
272         int pending = 1;
273         do {
274                 pending = readl(&wd_base->wwps);
275         } while (pending);
276 }
277
278 /******************************************************************************
279  * Routine: watchdog_init
280  * Description: Shut down watch dogs
281  *****************************************************************************/
282 void watchdog_init(void)
283 {
284         struct watchdog *wd2_base = (struct watchdog *)WD2_BASE;
285         struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
286
287         /*
288          * There are 3 watch dogs WD1=Secure, WD2=MPU, WD3=IVA. WD1 is
289          * either taken care of by ROM (HS/EMU) or not accessible (GP).
290          * We need to take care of WD2-MPU or take a PRCM reset. WD3
291          * should not be running and does not generate a PRCM reset.
292          */
293
294         setbits_le32(&prcm_base->fclken_wkup, 0x20);
295         setbits_le32(&prcm_base->iclken_wkup, 0x20);
296         wait_on_value(ST_WDT2, 0x20, &prcm_base->idlest_wkup, 5);
297
298         writel(WD_UNLOCK1, &wd2_base->wspr);
299         wait_for_command_complete(wd2_base);
300         writel(WD_UNLOCK2, &wd2_base->wspr);
301 }
302
303 /******************************************************************************
304  * Dummy function to handle errors for EABI incompatibility
305  *****************************************************************************/
306 void abort(void)
307 {
308 }
309
310 #if defined(CONFIG_NAND_OMAP_GPMC) & !defined(CONFIG_SPL_BUILD)
311 /******************************************************************************
312  * OMAP3 specific command to switch between NAND HW and SW ecc
313  *****************************************************************************/
314 static int do_switch_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
315 {
316         if (argc < 2 || argc > 3)
317                 goto usage;
318
319         if (strncmp(argv[1], "hw", 2) == 0) {
320                 if (argc == 2) {
321                         omap_nand_switch_ecc(1, 1);
322                 } else {
323                         if (strncmp(argv[2], "hamming", 7) == 0)
324                                 omap_nand_switch_ecc(1, 1);
325                         else if (strncmp(argv[2], "bch8", 4) == 0)
326                                 omap_nand_switch_ecc(1, 8);
327                         else
328                                 goto usage;
329                 }
330         } else if (strncmp(argv[1], "sw", 2) == 0) {
331                 omap_nand_switch_ecc(0, 0);
332         } else {
333                 goto usage;
334         }
335
336         return 0;
337
338 usage:
339         printf ("Usage: nandecc %s\n", cmdtp->usage);
340         return 1;
341 }
342
343 U_BOOT_CMD(
344         nandecc, 3, 1,  do_switch_ecc,
345         "switch OMAP3 NAND ECC calculation algorithm",
346         "hw [hamming|bch8] - Switch between NAND hardware 1-bit hamming and"
347         " 8-bit BCH\n"
348         "                           ecc calculation (second parameter may"
349         " be omitted).\n"
350         "nandecc sw               - Switch to NAND software ecc algorithm."
351 );
352
353 #endif /* CONFIG_NAND_OMAP_GPMC & !CONFIG_SPL_BUILD */
354
355 #ifdef CONFIG_DISPLAY_BOARDINFO
356 /**
357  * Print board information
358  */
359 int checkboard (void)
360 {
361         char *mem_s ;
362
363         if (is_mem_sdr())
364                 mem_s = "mSDR";
365         else
366                 mem_s = "LPDDR";
367
368         printf("%s + %s/%s\n", sysinfo.board_string, mem_s,
369                         sysinfo.nand_string);
370
371         return 0;
372 }
373 #endif  /* CONFIG_DISPLAY_BOARDINFO */
374
375 static void omap3_emu_romcode_call(u32 service_id, u32 *parameters)
376 {
377         u32 i, num_params = *parameters;
378         u32 *sram_scratch_space = (u32 *)OMAP3_PUBLIC_SRAM_SCRATCH_AREA;
379
380         /*
381          * copy the parameters to an un-cached area to avoid coherency
382          * issues
383          */
384         for (i = 0; i < num_params; i++) {
385                 __raw_writel(*parameters, sram_scratch_space);
386                 parameters++;
387                 sram_scratch_space++;
388         }
389
390         /* Now make the PPA call */
391         do_omap3_emu_romcode_call(service_id, OMAP3_PUBLIC_SRAM_SCRATCH_AREA);
392 }
393
394 static void omap3_update_aux_cr_secure(u32 set_bits, u32 clear_bits)
395 {
396         u32 acr;
397
398         /* Read ACR */
399         asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
400         acr &= ~clear_bits;
401         acr |= set_bits;
402
403         if (get_device_type() == GP_DEVICE) {
404                 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_WRITE_ACR,
405                                        acr);
406         } else {
407                 struct emu_hal_params emu_romcode_params;
408                 emu_romcode_params.num_params = 1;
409                 emu_romcode_params.param1 = acr;
410                 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_WRITE_ACR,
411                                        (u32 *)&emu_romcode_params);
412         }
413 }
414
415 static void omap3_setup_aux_cr(void)
416 {
417         /* Workaround for Cortex-A8 errata: #454179 #430973
418          *      Set "IBE" bit
419          *      Set "Disable Branch Size Mispredicts" bit
420          * Workaround for erratum #621766
421          *      Enable L1NEON bit
422          * ACR |= (IBE | DBSM | L1NEON) => ACR |= 0xE0
423          */
424         omap3_update_aux_cr_secure(0xE0, 0);
425 }
426
427 #ifndef CONFIG_SYS_L2CACHE_OFF
428 static void omap3_update_aux_cr(u32 set_bits, u32 clear_bits)
429 {
430         u32 acr;
431
432         /* Read ACR */
433         asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
434         acr &= ~clear_bits;
435         acr |= set_bits;
436
437         /* Write ACR - affects non-secure banked bits */
438         asm volatile ("mcr p15, 0, %0, c1, c0, 1" : : "r" (acr));
439 }
440
441 /* Invalidate the entire L2 cache from secure mode */
442 static void omap3_invalidate_l2_cache_secure(void)
443 {
444         if (get_device_type() == GP_DEVICE) {
445                 omap3_gp_romcode_call(OMAP3_GP_ROMCODE_API_L2_INVAL,
446                                       0);
447         } else {
448                 struct emu_hal_params emu_romcode_params;
449                 emu_romcode_params.num_params = 1;
450                 emu_romcode_params.param1 = 0;
451                 omap3_emu_romcode_call(OMAP3_EMU_HAL_API_L2_INVAL,
452                                        (u32 *)&emu_romcode_params);
453         }
454 }
455
456 void v7_outer_cache_enable(void)
457 {
458         /* Set L2EN */
459         omap3_update_aux_cr_secure(0x2, 0);
460
461         /*
462          * On some revisions L2EN bit is banked on some revisions it's not
463          * No harm in setting both banked bits(in fact this is required
464          * by an erratum)
465          */
466         omap3_update_aux_cr(0x2, 0);
467 }
468
469 void omap3_outer_cache_disable(void)
470 {
471         /* Clear L2EN */
472         omap3_update_aux_cr_secure(0, 0x2);
473
474         /*
475          * On some revisions L2EN bit is banked on some revisions it's not
476          * No harm in clearing both banked bits(in fact this is required
477          * by an erratum)
478          */
479         omap3_update_aux_cr(0, 0x2);
480 }
481 #endif /* !CONFIG_SYS_L2CACHE_OFF */