Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2004-2008 Freescale Semiconductor, Inc. |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Simon Glass | 40d9b24 | 2020-05-10 11:40:07 -0600 | [diff] [blame] | 7 | #include <asm-offsets.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 8 | #include <clock_legacy.h> |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 9 | #include <mpc83xx.h> |
Tom Rini | 4ddbade | 2022-05-25 12:16:03 -0400 | [diff] [blame] | 10 | #include <system-constants.h> |
Simon Glass | a9dc068 | 2019-12-28 10:44:59 -0700 | [diff] [blame] | 11 | #include <time.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 12 | #include <asm/global_data.h> |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 13 | |
Mario Six | b47839c | 2019-01-21 09:17:58 +0100 | [diff] [blame] | 14 | #include "lblaw/lblaw.h" |
Mario Six | 1faf95d | 2019-01-21 09:18:03 +0100 | [diff] [blame] | 15 | #include "elbc/elbc.h" |
Mario Six | b47839c | 2019-01-21 09:17:58 +0100 | [diff] [blame] | 16 | |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 17 | DECLARE_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 | */ |
| 26 | void cpu_init_f (volatile immap_t * im) |
| 27 | { |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 28 | /* Pointer is writable since we allocated a register for it */ |
Tom Rini | 4ddbade | 2022-05-25 12:16:03 -0400 | [diff] [blame] | 29 | gd = (gd_t *)SYS_INIT_SP_ADDR; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 30 | |
mario.six@gdsys.cc | 85df7b4 | 2017-01-17 08:33:48 +0100 | [diff] [blame] | 31 | /* global data region was cleared in start.S */ |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 32 | |
| 33 | /* system performance tweaking */ |
| 34 | |
Mario Six | aa50254 | 2019-01-21 09:18:12 +0100 | [diff] [blame] | 35 | #ifndef CONFIG_ACR_PIPE_DEP_UNSET |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 36 | /* Arbiter pipeline depth */ |
| 37 | im->arbiter.acr = (im->arbiter.acr & ~ACR_PIPE_DEP) | |
Mario Six | aa50254 | 2019-01-21 09:18:12 +0100 | [diff] [blame] | 38 | CONFIG_ACR_PIPE_DEP; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 39 | #endif |
| 40 | |
Mario Six | aa50254 | 2019-01-21 09:18:12 +0100 | [diff] [blame] | 41 | #ifndef CONFIG_ACR_RPTCNT_UNSET |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 42 | /* Arbiter repeat count */ |
| 43 | im->arbiter.acr = (im->arbiter.acr & ~(ACR_RPTCNT)) | |
Mario Six | aa50254 | 2019-01-21 09:18:12 +0100 | [diff] [blame] | 44 | CONFIG_ACR_RPTCNT; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 45 | #endif |
| 46 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 47 | #ifdef CONFIG_SYS_SPCR_OPT |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 48 | /* Optimize transactions between CSB and other devices */ |
| 49 | im->sysconf.spcr = (im->sysconf.spcr & ~SPCR_OPT) | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | (CONFIG_SYS_SPCR_OPT << SPCR_OPT_SHIFT); |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 51 | #endif |
| 52 | |
Robert P. J. Day | cbd618f | 2015-12-16 12:25:42 -0500 | [diff] [blame] | 53 | /* Enable Time Base & Decrementer (so we will have udelay()) */ |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 54 | im->sysconf.spcr |= SPCR_TBEN; |
| 55 | |
| 56 | /* DDR control driver register */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 57 | #ifdef CFG_SYS_DDRCDR |
| 58 | im->sysconf.ddrcdr = CFG_SYS_DDRCDR; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 59 | #endif |
| 60 | /* Output buffer impedance register */ |
Tom Rini | 6a5dccc | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 61 | #ifdef CFG_SYS_OBIR |
| 62 | im->sysconf.obir = CFG_SYS_OBIR; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 63 | #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 Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 74 | #if defined(CFG_SYS_NAND_BR_PRELIM) \ |
| 75 | && defined(CFG_SYS_NAND_OR_PRELIM) \ |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 76 | && defined(CFG_SYS_NAND_LBLAWBAR_PRELIM) \ |
| 77 | && defined(CFG_SYS_NAND_LBLAWAR_PRELIM) |
Tom Rini | b421349 | 2022-11-12 17:36:51 -0500 | [diff] [blame] | 78 | set_lbc_br(0, CFG_SYS_NAND_BR_PRELIM); |
| 79 | set_lbc_or(0, CFG_SYS_NAND_OR_PRELIM); |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 80 | im->sysconf.lblaw[0].bar = CFG_SYS_NAND_LBLAWBAR_PRELIM; |
| 81 | im->sysconf.lblaw[0].ar = CFG_SYS_NAND_LBLAWAR_PRELIM; |
Scott Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 82 | #else |
Tom Rini | 364d002 | 2023-01-10 11:19:45 -0500 | [diff] [blame] | 83 | #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 Wood | b71689b | 2008-06-30 14:13:28 -0500 | [diff] [blame] | 84 | #endif |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 89 | */ |
| 90 | unsigned long get_tbclk(void) |
| 91 | { |
| 92 | return (gd->bus_clk + 3L) / 4L; |
| 93 | } |
| 94 | |
| 95 | void puts(const char *str) |
| 96 | { |
| 97 | while (*str) |
| 98 | putc(*str++); |
| 99 | } |
Mario Six | cd677ca | 2019-01-21 09:17:52 +0100 | [diff] [blame] | 100 | |
| 101 | ulong 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 Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 106 | return get_board_sys_clk() * spmf; |
Mario Six | cd677ca | 2019-01-21 09:17:52 +0100 | [diff] [blame] | 107 | } |