blob: afcb75ba17a0aafb265d6f67d869d6de85109b23 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Becky Bruce0d4cee12010-06-17 11:37:20 -05002/*
Kumar Gala77b37af2011-01-13 02:58:23 -06003 * Copyright 2010-2011 Freescale Semiconductor, Inc.
Becky Bruce0d4cee12010-06-17 11:37:20 -05004 */
5
6#include <common.h>
Simon Glassf11478f2019-12-28 10:45:07 -07007#include <hang.h>
Becky Bruce0d4cee12010-06-17 11:37:20 -05008#include <asm/fsl_lbc.h>
9
Mario Six1faf95d2019-01-21 09:18:03 +010010#ifdef CONFIG_MPC83xx
11#include "../mpc83xx/elbc/elbc.h"
12#endif
13
Becky Bruce5e35d8a2010-12-17 17:17:56 -060014#ifdef CONFIG_MPC85xx
15/* Boards should provide their own version of this if they use lbc sdram */
Kim Phillips82f576f2012-10-29 13:34:37 +000016static void __lbc_sdram_init(void)
Becky Bruce5e35d8a2010-12-17 17:17:56 -060017{
18 /* Do nothing */
19}
Becky Bruceb88d3d02010-12-17 17:17:57 -060020void lbc_sdram_init(void) __attribute__((weak, alias("__lbc_sdram_init")));
Becky Bruce5e35d8a2010-12-17 17:17:56 -060021#endif
22
23
Becky Bruce0d4cee12010-06-17 11:37:20 -050024void print_lbc_regs(void)
25{
26 int i;
27
28 printf("\nLocal Bus Controller Registers\n");
29 for (i = 0; i < 8; i++) {
30 printf("BR%d\t0x%08X\tOR%d\t0x%08X\n",
31 i, get_lbc_br(i), i, get_lbc_or(i));
32 }
Paul Gortmakerc7ec3c22011-12-15 10:22:07 -050033 printf("LBCR\t0x%08X\tLCRR\t0x%08X\n",
34 get_lbc_lbcr(), get_lbc_lcrr());
Becky Bruce0d4cee12010-06-17 11:37:20 -050035}
36
37void init_early_memctl_regs(void)
38{
39 uint init_br1 = 1;
40
Kumar Gala77b37af2011-01-13 02:58:23 -060041#ifdef CONFIG_SYS_FSL_ERRATUM_ELBC_A001
42 /* Set the local bus monitor timeout value to the maximum */
43 clrsetbits_be32(&(LBC_BASE_ADDR)->lbcr, LBCR_BMT|LBCR_BMTPS, 0xf);
44#endif
45
Becky Bruce0d4cee12010-06-17 11:37:20 -050046#ifdef CONFIG_MPC85xx
47 /* if cs1 is already set via debugger, leave cs0/cs1 alone */
48 if (get_lbc_br(1) & BR_V)
49 init_br1 = 0;
50#endif
51
52 /*
53 * Map banks 0 (and maybe 1) to the FLASH banks 0 (and 1) at
54 * preliminary addresses - these have to be modified later
55 * when FLASH size has been determined
56 */
57#if defined(CONFIG_SYS_OR0_REMAP)
58 set_lbc_or(0, CONFIG_SYS_OR0_REMAP);
59#endif
60#if defined(CONFIG_SYS_OR1_REMAP)
61 set_lbc_or(1, CONFIG_SYS_OR1_REMAP);
62#endif
63 /* now restrict to preliminary range */
64 if (init_br1) {
Kumar Galaf9865b82011-05-20 00:54:39 -050065#if defined(CONFIG_SYS_BR0_PRELIM) && defined(CONFIG_SYS_OR0_PRELIM)
Becky Bruce0d4cee12010-06-17 11:37:20 -050066 set_lbc_br(0, CONFIG_SYS_BR0_PRELIM);
67 set_lbc_or(0, CONFIG_SYS_OR0_PRELIM);
Kumar Galaf9865b82011-05-20 00:54:39 -050068#endif
Becky Bruce0d4cee12010-06-17 11:37:20 -050069
70#if defined(CONFIG_SYS_BR1_PRELIM) && defined(CONFIG_SYS_OR1_PRELIM)
71 set_lbc_or(1, CONFIG_SYS_OR1_PRELIM);
72 set_lbc_br(1, CONFIG_SYS_BR1_PRELIM);
73#endif
74 }
75
76#if defined(CONFIG_SYS_BR2_PRELIM) && defined(CONFIG_SYS_OR2_PRELIM)
77 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
78 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
79#endif
80
81#if defined(CONFIG_SYS_BR3_PRELIM) && defined(CONFIG_SYS_OR3_PRELIM)
82 set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
83 set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
84#endif
85
86#if defined(CONFIG_SYS_BR4_PRELIM) && defined(CONFIG_SYS_OR4_PRELIM)
87 set_lbc_or(4, CONFIG_SYS_OR4_PRELIM);
88 set_lbc_br(4, CONFIG_SYS_BR4_PRELIM);
89#endif
90
91#if defined(CONFIG_SYS_BR5_PRELIM) && defined(CONFIG_SYS_OR5_PRELIM)
92 set_lbc_or(5, CONFIG_SYS_OR5_PRELIM);
93 set_lbc_br(5, CONFIG_SYS_BR5_PRELIM);
94#endif
95
96#if defined(CONFIG_SYS_BR6_PRELIM) && defined(CONFIG_SYS_OR6_PRELIM)
97 set_lbc_or(6, CONFIG_SYS_OR6_PRELIM);
98 set_lbc_br(6, CONFIG_SYS_BR6_PRELIM);
99#endif
100
101#if defined(CONFIG_SYS_BR7_PRELIM) && defined(CONFIG_SYS_OR7_PRELIM)
102 set_lbc_or(7, CONFIG_SYS_OR7_PRELIM);
103 set_lbc_br(7, CONFIG_SYS_BR7_PRELIM);
104#endif
105}
Becky Brucea08b71c2010-06-17 11:37:26 -0500106
107/*
108 * Configures a UPM. The function requires the respective MxMR to be set
109 * before calling this function. "size" is the number or entries, not a sizeof.
110 */
111void upmconfig(uint upm, uint *table, uint size)
112{
113 fsl_lbc_t *lbc = LBC_BASE_ADDR;
Kumar Galaacb70002011-11-09 10:00:23 -0600114 int i, mad, old_mad = 0;
Becky Brucea08b71c2010-06-17 11:37:26 -0500115 u32 mask = (~MxMR_OP_MSK & ~MxMR_MAD_MSK);
116 u32 msel = BR_UPMx_TO_MSEL(upm);
117 u32 *mxmr = &lbc->mamr + upm;
118 volatile u8 *dummy = NULL;
119
120 if (upm < UPMA || upm > UPMC) {
121 printf("Error: %s() Bad UPM index %d\n", __func__, upm);
122 hang();
123 }
124
125 /*
126 * Find the address for the dummy write - scan all of the BRs until we
127 * find one matching the UPM and extract the base address bits from it.
128 */
129 for (i = 0; i < 8; i++) {
130 if ((get_lbc_br(i) & (BR_V | BR_MSEL)) == (BR_V | msel)) {
131 dummy = (volatile u8 *)(get_lbc_br(i) & BR_BA);
132 break;
133 }
134 }
135
136 if (!dummy) {
137 printf("Error: %s() No matching BR\n", __func__);
138 hang();
139 }
140
141 /* Program UPM using steps outlined by the reference manual */
142 for (i = 0; i < size; i++) {
143 out_be32(mxmr, (in_be32(mxmr) & mask) | MxMR_OP_WARR | i);
144 out_be32(&lbc->mdr, table[i]);
Kumar Galaacb70002011-11-09 10:00:23 -0600145 (void)in_be32(&lbc->mdr);
Becky Brucea08b71c2010-06-17 11:37:26 -0500146 *dummy = 0;
147 do {
148 mad = in_be32(mxmr) & MxMR_MAD_MSK;
149 } while (mad <= old_mad && !(!mad && i == (size-1)));
150 old_mad = mad;
151 }
152
153 /* Return to normal operation */
154 out_be32(mxmr, (in_be32(mxmr) & mask) | MxMR_OP_NORM);
155}