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