2 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * 20050101: Eran Liberty (liberty@freescale.com)
25 * Initial file creating (porting from 85XX & 8260)
29 * CPU specific code for the MPC83xx family.
31 * Derived from the MPC8260 and MPC85xx.
39 #include <asm/processor.h>
41 DECLARE_GLOBAL_DATA_PTR
;
46 volatile immap_t
*immr
;
47 ulong clock
= gd
->cpu_clk
;
52 immr
= (immap_t
*)CFG_IMMR
;
54 if ((pvr
& 0xFFFF0000) != PVR_83xx
) {
55 puts("Not MPC83xx Family!!!\n");
59 spridr
= immr
->sysconf
.spridr
;
70 case SPR_8347E_REV10_TBGA
:
71 case SPR_8347E_REV11_TBGA
:
72 case SPR_8347E_REV10_PBGA
:
73 case SPR_8347E_REV11_PBGA
:
76 case SPR_8347_REV10_TBGA
:
77 case SPR_8347_REV11_TBGA
:
78 case SPR_8347_REV10_PBGA
:
79 case SPR_8347_REV11_PBGA
:
101 puts("Rev: Unknown\n");
102 return -1; /* Not sure what this is */
105 #if defined(CONFIG_MPC8349)
106 printf("Rev: %02x at %s MHz\n", (spridr
& 0x0000FFFF)>>4 |(spridr
& 0x0000000F), strmhz(buf
, clock
));
108 printf("Rev: %02x at %s MHz\n", spridr
& 0x0000FFFF, strmhz(buf
, clock
));
115 * Program a UPM with the code supplied in the table.
117 * The 'dummy' variable is used to increment the MAD. 'dummy' is
118 * supposed to be a pointer to the memory of the device being
119 * programmed by the UPM. The data in the MDR is written into
120 * memory and the MAD is incremented every time there's a read
121 * from 'dummy'. Unfortunately, the current prototype for this
122 * function doesn't allow for passing the address of this
123 * device, and changing the prototype will break a number lots
124 * of other code, so we need to use a round-about way of finding
125 * the value for 'dummy'.
127 * The value can be extracted from the base address bits of the
128 * Base Register (BR) associated with the specific UPM. To find
129 * that BR, we need to scan all 8 BRs until we find the one that
130 * has its MSEL bits matching the UPM we want. Once we know the
131 * right BR, we can extract the base address bits from it.
133 * The MxMR and the BR and OR of the chosen bank should all be
134 * configured before calling this function.
137 * upm: 0=UPMA, 1=UPMB, 2=UPMC
138 * table: Pointer to an array of values to program
139 * size: Number of elements in the array. Must be 64 or less.
141 void upmconfig (uint upm
, uint
*table
, uint size
)
143 #if defined(CONFIG_MPC834X)
144 volatile immap_t
*immap
= (immap_t
*) CFG_IMMR
;
145 volatile lbus83xx_t
*lbus
= &immap
->lbus
;
146 volatile uchar
*dummy
= NULL
;
147 const u32 msel
= (upm
+ 4) << BR_MSEL_SHIFT
; /* What the MSEL field in BRn should be */
148 volatile u32
*mxmr
= &lbus
->mamr
+ upm
; /* Pointer to mamr, mbmr, or mcmr */
151 /* Scan all the banks to determine the base address of the device */
152 for (i
= 0; i
< 8; i
++) {
153 if ((lbus
->bank
[i
].br
& BR_MSEL
) == msel
) {
154 dummy
= (uchar
*) (lbus
->bank
[i
].br
& BR_BA
);
160 printf("Error: %s() could not find matching BR\n", __FUNCTION__
);
164 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
165 *mxmr
= (*mxmr
& 0xCFFFFFC0) | 0x10000000;
167 for (i
= 0; i
< size
; i
++) {
168 lbus
->mdr
= table
[i
];
169 __asm__
__volatile__ ("sync");
170 *dummy
; /* Write the value to memory and increment MAD */
171 __asm__
__volatile__ ("sync");
174 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
177 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__
);
184 do_reset (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
187 #ifndef MPC83xx_RESET
191 volatile immap_t
*immap
= (immap_t
*) CFG_IMMR
;
194 /* Interrupts and MMU off */
195 __asm__
__volatile__ ("mfmsr %0":"=r" (msr
):);
197 msr
&= ~( MSR_EE
| MSR_IR
| MSR_DR
);
198 __asm__
__volatile__ ("mtmsr %0"::"r" (msr
));
200 /* enable Reset Control Reg */
201 immap
->reset
.rpr
= 0x52535445;
202 __asm__
__volatile__ ("sync");
203 __asm__
__volatile__ ("isync");
205 /* confirm Reset Control Reg is enabled */
206 while(!((immap
->reset
.rcer
) & RCER_CRE
));
208 printf("Resetting the board.");
213 /* perform reset, only one bit */
214 immap
->reset
.rcr
= RCR_SWHR
;
216 #else /* ! MPC83xx_RESET */
218 immap
->reset
.rmr
= RMR_CSRE
; /* Checkstop Reset enable */
220 /* Interrupts and MMU off */
221 __asm__
__volatile__ ("mfmsr %0":"=r" (msr
):);
223 msr
&= ~(MSR_ME
| MSR_EE
| MSR_IR
| MSR_DR
);
224 __asm__
__volatile__ ("mtmsr %0"::"r" (msr
));
227 * Trying to execute the next instruction at a non-existing address
228 * should cause a machine check, resulting in reset
230 addr
= CFG_RESET_ADDRESS
;
232 printf("resetting the board.");
234 ((void (*)(void)) addr
) ();
235 #endif /* MPC83xx_RESET */
242 * Get timebase clock frequency (like cpu_clk in Hz)
245 unsigned long get_tbclk(void)
249 tbclk
= (gd
->bus_clk
+ 3L) / 4L;
255 #if defined(CONFIG_WATCHDOG)
256 void watchdog_reset (void)
258 #ifdef CONFIG_MPC834X
259 int re_enable
= disable_interrupts();
261 /* Reset the 83xx watchdog */
262 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
263 immr
->wdt
.swsrr
= 0x556c;
264 immr
->wdt
.swsrr
= 0xaa39;
267 enable_interrupts ();
274 #if defined(CONFIG_OF_FLAT_TREE)
276 ft_cpu_setup(void *blob
, bd_t
*bd
)
282 clock
= bd
->bi_busfreq
;
283 p
= ft_get_prop(blob
, "/cpus/" OF_CPU
"/bus-frequency", &len
);
285 *p
= cpu_to_be32(clock
);
287 p
= ft_get_prop(blob
, "/" OF_SOC
"/bus-frequency", &len
);
289 *p
= cpu_to_be32(clock
);
291 p
= ft_get_prop(blob
, "/" OF_SOC
"/serial@4500/clock-frequency", &len
);
293 *p
= cpu_to_be32(clock
);
295 p
= ft_get_prop(blob
, "/" OF_SOC
"/serial@4600/clock-frequency", &len
);
297 *p
= cpu_to_be32(clock
);
299 #ifdef CONFIG_MPC83XX_TSEC1
300 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@24000/local-mac-address", &len
);
301 memcpy(p
, bd
->bi_enetaddr
, 6);
304 #ifdef CONFIG_MPC83XX_TSEC2
305 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@25000/local-mac-address", &len
);
306 memcpy(p
, bd
->bi_enet1addr
, 6);
311 #if defined(CONFIG_DDR_ECC)
314 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
315 volatile dma83xx_t
*dma
= &immap
->dma
;
316 volatile u32 status
= swab32(dma
->dmasr0
);
317 volatile u32 dmamr0
= swab32(dma
->dmamr0
);
321 /* initialize DMASARn, DMADAR and DMAABCRn */
322 dma
->dmadar0
= (u32
)0;
323 dma
->dmasar0
= (u32
)0;
326 __asm__
__volatile__ ("sync");
327 __asm__
__volatile__ ("isync");
330 dmamr0
&= ~DMA_CHANNEL_START
;
331 dma
->dmamr0
= swab32(dmamr0
);
332 __asm__
__volatile__ ("sync");
333 __asm__
__volatile__ ("isync");
335 /* while the channel is busy, spin */
336 while(status
& DMA_CHANNEL_BUSY
) {
337 status
= swab32(dma
->dmasr0
);
340 debug("DMA-init end\n");
345 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
346 volatile dma83xx_t
*dma
= &immap
->dma
;
347 volatile u32 status
= swab32(dma
->dmasr0
);
348 volatile u32 byte_count
= swab32(dma
->dmabcr0
);
350 /* while the channel is busy, spin */
351 while (status
& DMA_CHANNEL_BUSY
) {
352 status
= swab32(dma
->dmasr0
);
355 if (status
& DMA_CHANNEL_TRANSFER_ERROR
) {
356 printf ("DMA Error: status = %x @ %d\n", status
, byte_count
);
362 int dma_xfer(void *dest
, u32 count
, void *src
)
364 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
365 volatile dma83xx_t
*dma
= &immap
->dma
;
368 /* initialize DMASARn, DMADAR and DMAABCRn */
369 dma
->dmadar0
= swab32((u32
)dest
);
370 dma
->dmasar0
= swab32((u32
)src
);
371 dma
->dmabcr0
= swab32(count
);
373 __asm__
__volatile__ ("sync");
374 __asm__
__volatile__ ("isync");
376 /* init direct transfer, clear CS bit */
377 dmamr0
= (DMA_CHANNEL_TRANSFER_MODE_DIRECT
|
378 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B
|
379 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN
);
381 dma
->dmamr0
= swab32(dmamr0
);
383 __asm__
__volatile__ ("sync");
384 __asm__
__volatile__ ("isync");
386 /* set CS to start DMA transfer */
387 dmamr0
|= DMA_CHANNEL_START
;
388 dma
->dmamr0
= swab32(dmamr0
);
389 __asm__
__volatile__ ("sync");
390 __asm__
__volatile__ ("isync");
392 return ((int)dma_check());
394 #endif /*CONFIG_DDR_ECC*/