blob: 0e51bd1c891246fef70cded4900441a1bec66472 [file] [log] [blame]
wdenk0608e042004-03-25 19:29:38 +00001/*
2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * Klaus Heydeck, Kieback & Peter GmbH & Co KG, heydeck@kieback-peter.de
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenk0608e042004-03-25 19:29:38 +00007 */
8
9#include <common.h>
10#include <mpc8xx.h>
wdenk02b11f82004-05-12 22:54:36 +000011#include <post.h>
wdenk0608e042004-03-25 19:29:38 +000012#include "../common/kup.h"
Heiko Schochere604e402010-07-19 23:46:48 +020013#include <asm/io.h>
wdenk0608e042004-03-25 19:29:38 +000014
wdenk0608e042004-03-25 19:29:38 +000015
16#define _NOT_USED_ 0xFFFFFFFF
17
18const uint sdram_table[] = {
19 /*
20 * Single Read. (Offset 0 in UPMA RAM)
21 */
22 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
23 0x1FF77C47, /* last */
24
25 /*
26 * SDRAM Initialization (offset 5 in UPMA RAM)
27 *
28 * This is no UPM entry point. The following definition uses
29 * the remaining space to establish an initialization
30 * sequence, which is executed by a RUN command.
31 *
32 */
33 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
34
35 /*
36 * Burst Read. (Offset 8 in UPMA RAM)
37 */
38 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
39 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
40 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
41 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
42
43 /*
44 * Single Write. (Offset 18 in UPMA RAM)
45 */
46 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
47 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
48
49 /*
50 * Burst Write. (Offset 20 in UPMA RAM)
51 */
52 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
53 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
54 _NOT_USED_,
55 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
56 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
57
58 /*
59 * Refresh (Offset 30 in UPMA RAM)
60 */
61 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
62 0xFFFFFC84, 0xFFFFFC07, /* last */
63 _NOT_USED_, _NOT_USED_,
64 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
65
66 /*
67 * Exception. (Offset 3c in UPMA RAM)
68 */
69 0x7FFFFC07, /* last */
70 _NOT_USED_, _NOT_USED_, _NOT_USED_,
71};
72
wdenk0608e042004-03-25 19:29:38 +000073
74/*
75 * Check Board Identity:
76 */
77
Heiko Schochere604e402010-07-19 23:46:48 +020078int checkboard(void)
wdenk0608e042004-03-25 19:29:38 +000079{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk0608e042004-03-25 19:29:38 +000081 volatile memctl8xx_t *memctl = &immap->im_memctl;
Heiko Schochere604e402010-07-19 23:46:48 +020082 uchar latch, rev, mod;
wdenk0608e042004-03-25 19:29:38 +000083
84 /*
85 * Init ChipSelect #4 (CAN + HW-Latch)
86 */
Heiko Schochere604e402010-07-19 23:46:48 +020087 out_be32(&memctl->memc_or4, 0xFFFF8926);
88 out_be32(&memctl->memc_br4, 0x90000401);
89
90 latch = in_8( (unsigned char *) LATCH_ADDR);
91 rev = (latch & 0xF8) >> 3;
92 mod = (latch & 0x03);
93
94 printf("Board: KUP4X Rev %d.%d\n", rev, mod);
95
96 return 0;
wdenk0608e042004-03-25 19:29:38 +000097}
98
wdenk0608e042004-03-25 19:29:38 +000099
Heiko Schochere604e402010-07-19 23:46:48 +0200100phys_size_t initdram(int board_type)
wdenk0608e042004-03-25 19:29:38 +0000101{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk0608e042004-03-25 19:29:38 +0000103 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk0608e042004-03-25 19:29:38 +0000104
Heiko Schochere604e402010-07-19 23:46:48 +0200105 upmconfig(UPMA, (uint *) sdram_table,
wdenk0608e042004-03-25 19:29:38 +0000106 sizeof (sdram_table) / sizeof (uint));
wdenk0608e042004-03-25 19:29:38 +0000107
Heiko Schochere604e402010-07-19 23:46:48 +0200108 out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
wdenk0608e042004-03-25 19:29:38 +0000109
Heiko Schochere604e402010-07-19 23:46:48 +0200110 out_be32(&memctl->memc_mar, 0x00000088);
wdenk0608e042004-03-25 19:29:38 +0000111
Heiko Schochere604e402010-07-19 23:46:48 +0200112 out_be32(&memctl->memc_mamr,
113 CONFIG_SYS_MAMR & (~(MAMR_PTAE))); /* no refresh yet */
wdenk0608e042004-03-25 19:29:38 +0000114
Heiko Schochere604e402010-07-19 23:46:48 +0200115 udelay(200);
wdenk0608e042004-03-25 19:29:38 +0000116
117 /* perform SDRAM initializsation sequence */
118
Heiko Schochere604e402010-07-19 23:46:48 +0200119 /* SDRAM bank 0 */
120 out_be32(&memctl->memc_mcr, 0x80002105);
121 udelay(1);
122 out_be32(&memctl->memc_mcr, 0x80002830); /* execute twice */
123 udelay(1);
124 out_be32(&memctl->memc_mcr, 0x80002106); /* RUN MRS Pattern from loc 6 */
125 udelay(1);
wdenk0608e042004-03-25 19:29:38 +0000126
Heiko Schochere604e402010-07-19 23:46:48 +0200127 /* SDRAM bank 1 */
128 out_be32(&memctl->memc_mcr, 0x80004105);
129 udelay(1);
130 out_be32(&memctl->memc_mcr, 0x80004830); /* execute twice */
131 udelay(1);
132 out_be32(&memctl->memc_mcr, 0x80004106); /* RUN MRS Pattern from loc 6 */
133 udelay(1);
wdenk0608e042004-03-25 19:29:38 +0000134
Heiko Schochere604e402010-07-19 23:46:48 +0200135 /* SDRAM bank 2 */
136 out_be32(&memctl->memc_mcr, 0x80006105);
137 udelay(1);
138 out_be32(&memctl->memc_mcr, 0x80006830); /* execute twice */
139 udelay(1);
140 out_be32(&memctl->memc_mcr, 0x80006106); /* RUN MRS Pattern from loc 6 */
141 udelay(1);
wdenk0608e042004-03-25 19:29:38 +0000142
Heiko Schochere604e402010-07-19 23:46:48 +0200143 /* SDRAM bank 3 */
144 out_be32(&memctl->memc_mcr, 0x8000C105);
145 udelay(1);
146 out_be32(&memctl->memc_mcr, 0x8000C830); /* execute twice */
147 udelay(1);
148 out_be32(&memctl->memc_mcr, 0x8000C106); /* RUN MRS Pattern from loc 6 */
149 udelay(1);
wdenk0608e042004-03-25 19:29:38 +0000150
Heiko Schochere604e402010-07-19 23:46:48 +0200151 setbits_be32(&memctl->memc_mamr, MAMR_PTAE); /* enable refresh */
wdenk0608e042004-03-25 19:29:38 +0000152
Heiko Schochere604e402010-07-19 23:46:48 +0200153 udelay(1000);
154 /* 4 x 16 MB */
155 out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR);
156 udelay(1000);
157 out_be32(&memctl->memc_or1, 0xFF000A00);
158 out_be32(&memctl->memc_br1, 0x00000081);
159 out_be32(&memctl->memc_or2, 0xFE000A00);
160 out_be32(&memctl->memc_br2, 0x01000081);
161 out_be32(&memctl->memc_or3, 0xFD000A00);
162 out_be32(&memctl->memc_br3, 0x02000081);
163 out_be32(&memctl->memc_or6, 0xFC000A00);
164 out_be32(&memctl->memc_br6, 0x03000081);
165 udelay(10000);
166
167 return (4 * 16 * 1024 * 1024);
wdenk0608e042004-03-25 19:29:38 +0000168}
169
Heiko Schochere604e402010-07-19 23:46:48 +0200170int misc_init_r(void)
wdenk0608e042004-03-25 19:29:38 +0000171{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200172 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk0608e042004-03-25 19:29:38 +0000173
wdenk0608e042004-03-25 19:29:38 +0000174#ifdef CONFIG_IDE_LED
175 /* Configure PA8 as output port */
Heiko Schochere604e402010-07-19 23:46:48 +0200176 setbits_be16(&immap->im_ioport.iop_padir, PA_8);
177 setbits_be16(&immap->im_ioport.iop_paodr, PA_8);
178 clrbits_be16(&immap->im_ioport.iop_papar, PA_8);
179 setbits_be16(&immap->im_ioport.iop_padat, PA_8); /* turn it off */
wdenk0608e042004-03-25 19:29:38 +0000180#endif
Mike Frysinger9c150102009-02-11 20:09:52 -0500181 load_sernum_ethaddr();
Heiko Schochere604e402010-07-19 23:46:48 +0200182 setenv("hw", "4x");
183 poweron_key();
184 return 0;
wdenk0608e042004-03-25 19:29:38 +0000185}