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