blob: 7036e3fae0c85ecf5ab8bdfb52826ff4868cd9fd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Scott Woodb71689b2008-06-30 14:13:28 -05002/*
3 * Copyright (C) 2004-2008 Freescale Semiconductor, Inc.
Scott Woodb71689b2008-06-30 14:13:28 -05004 */
5
Tom Rinidec7ea02024-05-20 13:35:03 -06006#include <config.h>
Simon Glass40d9b242020-05-10 11:40:07 -06007#include <asm-offsets.h>
Simon Glass85d65312019-12-28 10:44:58 -07008#include <clock_legacy.h>
Scott Woodb71689b2008-06-30 14:13:28 -05009#include <mpc83xx.h>
Tom Rini4ddbade2022-05-25 12:16:03 -040010#include <system-constants.h>
Simon Glassa9dc0682019-12-28 10:44:59 -070011#include <time.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
Scott Woodb71689b2008-06-30 14:13:28 -050013
Mario Sixb47839c2019-01-21 09:17:58 +010014#include "lblaw/lblaw.h"
Mario Six1faf95d2019-01-21 09:18:03 +010015#include "elbc/elbc.h"
Mario Sixb47839c2019-01-21 09:17:58 +010016
Scott Woodb71689b2008-06-30 14:13:28 -050017DECLARE_GLOBAL_DATA_PTR;
18
19/*
20 * Breathe some life into the CPU...
21 *
22 * Set up the memory map,
23 * initialize a bunch of registers,
24 * initialize the UPM's
25 */
26void cpu_init_f (volatile immap_t * im)
27{
Scott Woodb71689b2008-06-30 14:13:28 -050028 /* Pointer is writable since we allocated a register for it */
Tom Rini4ddbade2022-05-25 12:16:03 -040029 gd = (gd_t *)SYS_INIT_SP_ADDR;
Scott Woodb71689b2008-06-30 14:13:28 -050030
mario.six@gdsys.cc85df7b42017-01-17 08:33:48 +010031 /* global data region was cleared in start.S */
Scott Woodb71689b2008-06-30 14:13:28 -050032
33 /* system performance tweaking */
34
Mario Sixaa502542019-01-21 09:18:12 +010035#ifndef CONFIG_ACR_PIPE_DEP_UNSET
Scott Woodb71689b2008-06-30 14:13:28 -050036 /* Arbiter pipeline depth */
37 im->arbiter.acr = (im->arbiter.acr & ~ACR_PIPE_DEP) |
Mario Sixaa502542019-01-21 09:18:12 +010038 CONFIG_ACR_PIPE_DEP;
Scott Woodb71689b2008-06-30 14:13:28 -050039#endif
40
Mario Sixaa502542019-01-21 09:18:12 +010041#ifndef CONFIG_ACR_RPTCNT_UNSET
Scott Woodb71689b2008-06-30 14:13:28 -050042 /* Arbiter repeat count */
43 im->arbiter.acr = (im->arbiter.acr & ~(ACR_RPTCNT)) |
Mario Sixaa502542019-01-21 09:18:12 +010044 CONFIG_ACR_RPTCNT;
Scott Woodb71689b2008-06-30 14:13:28 -050045#endif
46
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020047#ifdef CONFIG_SYS_SPCR_OPT
Scott Woodb71689b2008-06-30 14:13:28 -050048 /* Optimize transactions between CSB and other devices */
49 im->sysconf.spcr = (im->sysconf.spcr & ~SPCR_OPT) |
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020050 (CONFIG_SYS_SPCR_OPT << SPCR_OPT_SHIFT);
Scott Woodb71689b2008-06-30 14:13:28 -050051#endif
52
Robert P. J. Daycbd618f2015-12-16 12:25:42 -050053 /* Enable Time Base & Decrementer (so we will have udelay()) */
Scott Woodb71689b2008-06-30 14:13:28 -050054 im->sysconf.spcr |= SPCR_TBEN;
55
56 /* DDR control driver register */
Tom Rini6a5dccc2022-11-16 13:10:41 -050057#ifdef CFG_SYS_DDRCDR
58 im->sysconf.ddrcdr = CFG_SYS_DDRCDR;
Scott Woodb71689b2008-06-30 14:13:28 -050059#endif
60 /* Output buffer impedance register */
Tom Rini6a5dccc2022-11-16 13:10:41 -050061#ifdef CFG_SYS_OBIR
62 im->sysconf.obir = CFG_SYS_OBIR;
Scott Woodb71689b2008-06-30 14:13:28 -050063#endif
64
65 /*
66 * Memory Controller:
67 */
68
69 /* Map banks 0 and 1 to the FLASH banks 0 and 1 at preliminary
70 * addresses - these have to be modified later when FLASH size
71 * has been determined
72 */
73
Tom Rinib4213492022-11-12 17:36:51 -050074#if defined(CFG_SYS_NAND_BR_PRELIM) \
75 && defined(CFG_SYS_NAND_OR_PRELIM) \
Tom Rini364d0022023-01-10 11:19:45 -050076 && defined(CFG_SYS_NAND_LBLAWBAR_PRELIM) \
77 && defined(CFG_SYS_NAND_LBLAWAR_PRELIM)
Tom Rinib4213492022-11-12 17:36:51 -050078 set_lbc_br(0, CFG_SYS_NAND_BR_PRELIM);
79 set_lbc_or(0, CFG_SYS_NAND_OR_PRELIM);
Tom Rini364d0022023-01-10 11:19:45 -050080 im->sysconf.lblaw[0].bar = CFG_SYS_NAND_LBLAWBAR_PRELIM;
81 im->sysconf.lblaw[0].ar = CFG_SYS_NAND_LBLAWAR_PRELIM;
Scott Woodb71689b2008-06-30 14:13:28 -050082#else
Tom Rini364d0022023-01-10 11:19:45 -050083#error CFG_SYS_NAND_BR_PRELIM, CFG_SYS_NAND_OR_PRELIM, CFG_SYS_NAND_LBLAWBAR_PRELIM & CFG_SYS_NAND_LBLAWAR_PRELIM must be defined
Scott Woodb71689b2008-06-30 14:13:28 -050084#endif
85}
86
87/*
88 * Get timebase clock frequency (like cpu_clk in Hz)
89 */
90unsigned long get_tbclk(void)
91{
92 return (gd->bus_clk + 3L) / 4L;
93}
94
95void puts(const char *str)
96{
97 while (*str)
98 putc(*str++);
99}
Mario Sixcd677ca2019-01-21 09:17:52 +0100100
101ulong get_bus_freq(ulong dummy)
102{
103 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
104 u8 spmf = (im->clk.spmr & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
105
Tom Rini8c70baa2021-12-14 13:36:40 -0500106 return get_board_sys_clk() * spmf;
Mario Sixcd677ca2019-01-21 09:17:52 +0100107}