2 * Copyright (C) 2004-2007 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 * CPU specific code for the MPC83xx family.
26 * Derived from the MPC8260 and MPC85xx.
33 #include <asm/processor.h>
34 #if defined(CONFIG_OF_FLAT_TREE)
36 #elif defined(CONFIG_OF_LIBFDT)
38 #include <fdt_support.h>
41 DECLARE_GLOBAL_DATA_PTR
;
45 volatile immap_t
*immr
;
46 ulong clock
= gd
->cpu_clk
;
51 immr
= (immap_t
*)CFG_IMMR
;
55 switch (pvr
& 0xffff0000) {
73 printf("Unknown core, ");
76 spridr
= immr
->sysconf
.spridr
;
88 case SPR_8347E_REV10_TBGA
:
89 case SPR_8347E_REV11_TBGA
:
90 case SPR_8347E_REV31_TBGA
:
91 case SPR_8347E_REV10_PBGA
:
92 case SPR_8347E_REV11_PBGA
:
93 case SPR_8347E_REV31_PBGA
:
96 case SPR_8347_REV10_TBGA
:
97 case SPR_8347_REV11_TBGA
:
98 case SPR_8347_REV31_TBGA
:
99 case SPR_8347_REV10_PBGA
:
100 case SPR_8347_REV11_PBGA
:
101 case SPR_8347_REV31_PBGA
:
104 case SPR_8343E_REV10
:
105 case SPR_8343E_REV11
:
106 case SPR_8343E_REV31
:
114 case SPR_8360E_REV10
:
115 case SPR_8360E_REV11
:
116 case SPR_8360E_REV12
:
117 case SPR_8360E_REV20
:
118 case SPR_8360E_REV21
:
128 case SPR_8323E_REV10
:
129 case SPR_8323E_REV11
:
136 case SPR_8321E_REV10
:
137 case SPR_8321E_REV11
:
147 case SPR_8311E_REV10
:
153 case SPR_8313E_REV10
:
156 case SPR_8315E_REV10
:
162 case SPR_8314E_REV10
:
168 case SPR_8379E_REV10
:
174 case SPR_8378E_REV10
:
180 case SPR_8377E_REV10
:
187 printf("Rev: Unknown revision number:%08x\n"
188 "Warning: Unsupported cpu revision!\n",spridr
);
192 #if defined(CONFIG_MPC834X)
193 /* Multiple revisons of 834x processors may have the same SPRIDR value.
194 * So use PVR to identify the revision number.
196 printf("Rev: %02x at %s MHz", PVR_MAJ(pvr
)<<4 | PVR_MIN(pvr
), strmhz(buf
, clock
));
198 printf("Rev: %02x at %s MHz", spridr
& 0x0000FFFF, strmhz(buf
, clock
));
200 printf(", CSB: %4d MHz\n", gd
->csb_clk
/ 1000000);
207 * Program a UPM with the code supplied in the table.
209 * The 'dummy' variable is used to increment the MAD. 'dummy' is
210 * supposed to be a pointer to the memory of the device being
211 * programmed by the UPM. The data in the MDR is written into
212 * memory and the MAD is incremented every time there's a read
213 * from 'dummy'. Unfortunately, the current prototype for this
214 * function doesn't allow for passing the address of this
215 * device, and changing the prototype will break a number lots
216 * of other code, so we need to use a round-about way of finding
217 * the value for 'dummy'.
219 * The value can be extracted from the base address bits of the
220 * Base Register (BR) associated with the specific UPM. To find
221 * that BR, we need to scan all 8 BRs until we find the one that
222 * has its MSEL bits matching the UPM we want. Once we know the
223 * right BR, we can extract the base address bits from it.
225 * The MxMR and the BR and OR of the chosen bank should all be
226 * configured before calling this function.
229 * upm: 0=UPMA, 1=UPMB, 2=UPMC
230 * table: Pointer to an array of values to program
231 * size: Number of elements in the array. Must be 64 or less.
233 void upmconfig (uint upm
, uint
*table
, uint size
)
235 #if defined(CONFIG_MPC834X)
236 volatile immap_t
*immap
= (immap_t
*) CFG_IMMR
;
237 volatile lbus83xx_t
*lbus
= &immap
->lbus
;
238 volatile uchar
*dummy
= NULL
;
239 const u32 msel
= (upm
+ 4) << BR_MSEL_SHIFT
; /* What the MSEL field in BRn should be */
240 volatile u32
*mxmr
= &lbus
->mamr
+ upm
; /* Pointer to mamr, mbmr, or mcmr */
243 /* Scan all the banks to determine the base address of the device */
244 for (i
= 0; i
< 8; i
++) {
245 if ((lbus
->bank
[i
].br
& BR_MSEL
) == msel
) {
246 dummy
= (uchar
*) (lbus
->bank
[i
].br
& BR_BA
);
252 printf("Error: %s() could not find matching BR\n", __FUNCTION__
);
256 /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
257 *mxmr
= (*mxmr
& 0xCFFFFFC0) | 0x10000000;
259 for (i
= 0; i
< size
; i
++) {
260 lbus
->mdr
= table
[i
];
261 __asm__
__volatile__ ("sync");
262 *dummy
; /* Write the value to memory and increment MAD */
263 __asm__
__volatile__ ("sync");
266 /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
269 printf("Error: %s() not defined for this configuration.\n", __FUNCTION__
);
276 do_reset (cmd_tbl_t
* cmdtp
, int flag
, int argc
, char *argv
[])
279 #ifndef MPC83xx_RESET
283 volatile immap_t
*immap
= (immap_t
*) CFG_IMMR
;
286 /* Interrupts and MMU off */
287 __asm__
__volatile__ ("mfmsr %0":"=r" (msr
):);
289 msr
&= ~( MSR_EE
| MSR_IR
| MSR_DR
);
290 __asm__
__volatile__ ("mtmsr %0"::"r" (msr
));
292 /* enable Reset Control Reg */
293 immap
->reset
.rpr
= 0x52535445;
294 __asm__
__volatile__ ("sync");
295 __asm__
__volatile__ ("isync");
297 /* confirm Reset Control Reg is enabled */
298 while(!((immap
->reset
.rcer
) & RCER_CRE
));
300 printf("Resetting the board.");
305 /* perform reset, only one bit */
306 immap
->reset
.rcr
= RCR_SWHR
;
308 #else /* ! MPC83xx_RESET */
310 immap
->reset
.rmr
= RMR_CSRE
; /* Checkstop Reset enable */
312 /* Interrupts and MMU off */
313 __asm__
__volatile__ ("mfmsr %0":"=r" (msr
):);
315 msr
&= ~(MSR_ME
| MSR_EE
| MSR_IR
| MSR_DR
);
316 __asm__
__volatile__ ("mtmsr %0"::"r" (msr
));
319 * Trying to execute the next instruction at a non-existing address
320 * should cause a machine check, resulting in reset
322 addr
= CFG_RESET_ADDRESS
;
324 printf("resetting the board.");
326 ((void (*)(void)) addr
) ();
327 #endif /* MPC83xx_RESET */
334 * Get timebase clock frequency (like cpu_clk in Hz)
337 unsigned long get_tbclk(void)
341 tbclk
= (gd
->bus_clk
+ 3L) / 4L;
347 #if defined(CONFIG_WATCHDOG)
348 void watchdog_reset (void)
350 int re_enable
= disable_interrupts();
352 /* Reset the 83xx watchdog */
353 volatile immap_t
*immr
= (immap_t
*) CFG_IMMR
;
354 immr
->wdt
.swsrr
= 0x556c;
355 immr
->wdt
.swsrr
= 0xaa39;
358 enable_interrupts ();
362 #if defined(CONFIG_OF_LIBFDT)
365 * "Setter" functions used to add/modify FDT entries.
367 static int fdt_set_eth0(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
369 /* Fix it up if it exists, don't create it if it doesn't exist */
370 if (fdt_get_property(blob
, nodeoffset
, name
, 0)) {
371 return fdt_setprop(blob
, nodeoffset
, name
, bd
->bi_enetaddr
, 6);
375 #ifdef CONFIG_HAS_ETH1
376 /* second onboard ethernet port */
377 static int fdt_set_eth1(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
379 /* Fix it up if it exists, don't create it if it doesn't exist */
380 if (fdt_get_property(blob
, nodeoffset
, name
, 0)) {
381 return fdt_setprop(blob
, nodeoffset
, name
, bd
->bi_enet1addr
, 6);
386 #ifdef CONFIG_HAS_ETH2
387 /* third onboard ethernet port */
388 static int fdt_set_eth2(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
390 /* Fix it up if it exists, don't create it if it doesn't exist */
391 if (fdt_get_property(blob
, nodeoffset
, name
, 0)) {
392 return fdt_setprop(blob
, nodeoffset
, name
, bd
->bi_enet2addr
, 6);
397 #ifdef CONFIG_HAS_ETH3
398 /* fourth onboard ethernet port */
399 static int fdt_set_eth3(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
401 /* Fix it up if it exists, don't create it if it doesn't exist */
402 if (fdt_get_property(blob
, nodeoffset
, name
, 0)) {
403 return fdt_setprop(blob
, nodeoffset
, name
, bd
->bi_enet3addr
, 6);
409 static int fdt_set_busfreq(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
412 /* Create or update the property */
413 tmp
= cpu_to_be32(bd
->bi_busfreq
);
414 return fdt_setprop(blob
, nodeoffset
, name
, &tmp
, sizeof(tmp
));
417 static int fdt_set_tbfreq(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
420 /* Create or update the property */
421 tmp
= cpu_to_be32(OF_TBCLK
);
422 return fdt_setprop(blob
, nodeoffset
, name
, &tmp
, sizeof(tmp
));
426 static int fdt_set_clockfreq(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
429 /* Create or update the property */
430 tmp
= cpu_to_be32(gd
->core_clk
);
431 return fdt_setprop(blob
, nodeoffset
, name
, &tmp
, sizeof(tmp
));
435 static int fdt_set_qe_busfreq(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
438 /* Create or update the property */
439 tmp
= cpu_to_be32(gd
->qe_clk
);
440 return fdt_setprop(blob
, nodeoffset
, name
, &tmp
, sizeof(tmp
));
443 static int fdt_set_qe_brgfreq(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
)
446 /* Create or update the property */
447 tmp
= cpu_to_be32(gd
->brg_clk
);
448 return fdt_setprop(blob
, nodeoffset
, name
, &tmp
, sizeof(tmp
));
455 static const struct {
458 int (*set_fn
)(void *blob
, int nodeoffset
, const char *name
, bd_t
*bd
);
461 "timebase-frequency",
476 { "/" OF_SOC
"/serial@4500",
480 { "/" OF_SOC
"/serial@4600",
485 { "/" OF_SOC
"/ethernet@24000",
489 { "/" OF_SOC
"/ethernet@24000",
495 { "/" OF_SOC
"/ethernet@25000",
499 { "/" OF_SOC
"/ethernet@25000",
513 #ifdef CONFIG_UEC_ETH1
514 #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
515 { "/" OF_QE
"/ucc@2000",
519 { "/" OF_QE
"/ucc@2000",
523 #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
524 { "/" OF_QE
"/ucc@2200",
528 { "/" OF_QE
"/ucc@2200",
533 #endif /* CONFIG_UEC_ETH1 */
534 #ifdef CONFIG_UEC_ETH2
535 #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
536 { "/" OF_QE
"/ucc@3000",
540 { "/" OF_QE
"/ucc@3000",
544 #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
545 { "/" OF_QE
"/ucc@3200",
549 { "/" OF_QE
"/ucc@3200",
554 #endif /* CONFIG_UEC_ETH2 */
555 #endif /* CONFIG_QE */
559 ft_cpu_setup(void *blob
, bd_t
*bd
)
565 for (j
= 0; j
< (sizeof(fixup_props
) / sizeof(fixup_props
[0])); j
++) {
566 nodeoffset
= fdt_path_offset(blob
, fixup_props
[j
].node
);
567 if (nodeoffset
>= 0) {
568 err
= fixup_props
[j
].set_fn(blob
, nodeoffset
,
569 fixup_props
[j
].prop
, bd
);
571 debug("Problem setting %s = %s: %s\n",
572 fixup_props
[j
].node
, fixup_props
[j
].prop
,
575 debug("Couldn't find %s: %s\n",
576 fixup_props
[j
].node
, fdt_strerror(nodeoffset
));
580 fdt_fixup_memory(blob
, (u64
)bd
->bi_memstart
, (u64
)bd
->bi_memsize
);
582 #elif defined(CONFIG_OF_FLAT_TREE)
584 ft_cpu_setup(void *blob
, bd_t
*bd
)
590 clock
= bd
->bi_busfreq
;
591 p
= ft_get_prop(blob
, "/cpus/" OF_CPU
"/bus-frequency", &len
);
593 *p
= cpu_to_be32(clock
);
595 p
= ft_get_prop(blob
, "/" OF_SOC
"/bus-frequency", &len
);
597 *p
= cpu_to_be32(clock
);
599 p
= ft_get_prop(blob
, "/" OF_SOC
"/serial@4500/clock-frequency", &len
);
601 *p
= cpu_to_be32(clock
);
603 p
= ft_get_prop(blob
, "/" OF_SOC
"/serial@4600/clock-frequency", &len
);
605 *p
= cpu_to_be32(clock
);
608 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@24000/mac-address", &len
);
610 memcpy(p
, bd
->bi_enetaddr
, 6);
612 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@24000/local-mac-address", &len
);
614 memcpy(p
, bd
->bi_enetaddr
, 6);
618 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@25000/mac-address", &len
);
620 memcpy(p
, bd
->bi_enet1addr
, 6);
622 p
= ft_get_prop(blob
, "/" OF_SOC
"/ethernet@25000/local-mac-address", &len
);
624 memcpy(p
, bd
->bi_enet1addr
, 6);
627 #ifdef CONFIG_UEC_ETH1
628 #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
629 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@2000/mac-address", &len
);
631 memcpy(p
, bd
->bi_enetaddr
, 6);
633 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@2000/local-mac-address", &len
);
635 memcpy(p
, bd
->bi_enetaddr
, 6);
636 #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
637 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@2200/mac-address", &len
);
639 memcpy(p
, bd
->bi_enetaddr
, 6);
641 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@2200/local-mac-address", &len
);
643 memcpy(p
, bd
->bi_enetaddr
, 6);
647 #ifdef CONFIG_UEC_ETH2
648 #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
649 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@3000/mac-address", &len
);
651 memcpy(p
, bd
->bi_enet1addr
, 6);
653 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@3000/local-mac-address", &len
);
655 memcpy(p
, bd
->bi_enet1addr
, 6);
656 #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
657 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@3200/mac-address", &len
);
659 memcpy(p
, bd
->bi_enet1addr
, 6);
661 p
= ft_get_prop(blob
, "/" OF_QE
"/ucc@3200/local-mac-address", &len
);
663 memcpy(p
, bd
->bi_enet1addr
, 6);
669 #if defined(CONFIG_DDR_ECC)
672 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
673 volatile dma83xx_t
*dma
= &immap
->dma
;
674 volatile u32 status
= swab32(dma
->dmasr0
);
675 volatile u32 dmamr0
= swab32(dma
->dmamr0
);
679 /* initialize DMASARn, DMADAR and DMAABCRn */
680 dma
->dmadar0
= (u32
)0;
681 dma
->dmasar0
= (u32
)0;
684 __asm__
__volatile__ ("sync");
685 __asm__
__volatile__ ("isync");
688 dmamr0
&= ~DMA_CHANNEL_START
;
689 dma
->dmamr0
= swab32(dmamr0
);
690 __asm__
__volatile__ ("sync");
691 __asm__
__volatile__ ("isync");
693 /* while the channel is busy, spin */
694 while(status
& DMA_CHANNEL_BUSY
) {
695 status
= swab32(dma
->dmasr0
);
698 debug("DMA-init end\n");
703 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
704 volatile dma83xx_t
*dma
= &immap
->dma
;
705 volatile u32 status
= swab32(dma
->dmasr0
);
706 volatile u32 byte_count
= swab32(dma
->dmabcr0
);
708 /* while the channel is busy, spin */
709 while (status
& DMA_CHANNEL_BUSY
) {
710 status
= swab32(dma
->dmasr0
);
713 if (status
& DMA_CHANNEL_TRANSFER_ERROR
) {
714 printf ("DMA Error: status = %x @ %d\n", status
, byte_count
);
720 int dma_xfer(void *dest
, u32 count
, void *src
)
722 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
723 volatile dma83xx_t
*dma
= &immap
->dma
;
726 /* initialize DMASARn, DMADAR and DMAABCRn */
727 dma
->dmadar0
= swab32((u32
)dest
);
728 dma
->dmasar0
= swab32((u32
)src
);
729 dma
->dmabcr0
= swab32(count
);
731 __asm__
__volatile__ ("sync");
732 __asm__
__volatile__ ("isync");
734 /* init direct transfer, clear CS bit */
735 dmamr0
= (DMA_CHANNEL_TRANSFER_MODE_DIRECT
|
736 DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B
|
737 DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN
);
739 dma
->dmamr0
= swab32(dmamr0
);
741 __asm__
__volatile__ ("sync");
742 __asm__
__volatile__ ("isync");
744 /* set CS to start DMA transfer */
745 dmamr0
|= DMA_CHANNEL_START
;
746 dma
->dmamr0
= swab32(dmamr0
);
747 __asm__
__volatile__ ("sync");
748 __asm__
__volatile__ ("isync");
750 return ((int)dma_check());
752 #endif /*CONFIG_DDR_ECC*/