Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / arch / powerpc / cpu / mpc83xx / spl_minimal.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2004-2008 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <asm-offsets.h>
8 #include <clock_legacy.h>
9 #include <mpc83xx.h>
10 #include <time.h>
11
12 #include "lblaw/lblaw.h"
13 #include "elbc/elbc.h"
14
15 DECLARE_GLOBAL_DATA_PTR;
16
17 /*
18  * Breathe some life into the CPU...
19  *
20  * Set up the memory map,
21  * initialize a bunch of registers,
22  * initialize the UPM's
23  */
24 void cpu_init_f (volatile immap_t * im)
25 {
26         /* Pointer is writable since we allocated a register for it */
27         gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
28
29         /* global data region was cleared in start.S */
30
31         /* system performance tweaking */
32
33 #ifndef CONFIG_ACR_PIPE_DEP_UNSET
34         /* Arbiter pipeline depth */
35         im->arbiter.acr = (im->arbiter.acr & ~ACR_PIPE_DEP) |
36                           CONFIG_ACR_PIPE_DEP;
37 #endif
38
39 #ifndef CONFIG_ACR_RPTCNT_UNSET
40         /* Arbiter repeat count */
41         im->arbiter.acr = (im->arbiter.acr & ~(ACR_RPTCNT)) |
42                           CONFIG_ACR_RPTCNT;
43 #endif
44
45 #ifdef CONFIG_SYS_SPCR_OPT
46         /* Optimize transactions between CSB and other devices */
47         im->sysconf.spcr = (im->sysconf.spcr & ~SPCR_OPT) |
48                            (CONFIG_SYS_SPCR_OPT << SPCR_OPT_SHIFT);
49 #endif
50
51         /* Enable Time Base & Decrementer (so we will have udelay()) */
52         im->sysconf.spcr |= SPCR_TBEN;
53
54         /* DDR control driver register */
55 #ifdef CONFIG_SYS_DDRCDR
56         im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR;
57 #endif
58         /* Output buffer impedance register */
59 #ifdef CONFIG_SYS_OBIR
60         im->sysconf.obir = CONFIG_SYS_OBIR;
61 #endif
62
63         /*
64          * Memory Controller:
65          */
66
67         /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
68          * addresses - these have to be modified later when FLASH size
69          * has been determined
70          */
71
72 #if defined(CONFIG_SYS_NAND_BR_PRELIM)  \
73         && defined(CONFIG_SYS_NAND_OR_PRELIM) \
74         && defined(CONFIG_SYS_NAND_LBLAWBAR_PRELIM) \
75         && defined(CONFIG_SYS_NAND_LBLAWAR_PRELIM)
76         set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
77         set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
78         im->sysconf.lblaw[0].bar = CONFIG_SYS_NAND_LBLAWBAR_PRELIM;
79         im->sysconf.lblaw[0].ar = CONFIG_SYS_NAND_LBLAWAR_PRELIM;
80 #else
81 #error CONFIG_SYS_NAND_BR_PRELIM, CONFIG_SYS_NAND_OR_PRELIM, CONFIG_SYS_NAND_LBLAWBAR_PRELIM & CONFIG_SYS_NAND_LBLAWAR_PRELIM must be defined
82 #endif
83 }
84
85 /*
86  * Get timebase clock frequency (like cpu_clk in Hz)
87  */
88 unsigned long get_tbclk(void)
89 {
90         return (gd->bus_clk + 3L) / 4L;
91 }
92
93 void puts(const char *str)
94 {
95         while (*str)
96                 putc(*str++);
97 }
98
99 ulong get_bus_freq(ulong dummy)
100 {
101         volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
102         u8 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
103
104         return CONFIG_SYS_CLK_FREQ * spmf;
105 }