wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 1 | /* |
| 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 Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <mpc8xx.h> |
wdenk | 02b11f8 | 2004-05-12 22:54:36 +0000 | [diff] [blame] | 11 | #include <post.h> |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 12 | #include "../common/kup.h" |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 13 | #include <asm/io.h> |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 14 | |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 15 | |
| 16 | #define _NOT_USED_ 0xFFFFFFFF |
| 17 | |
| 18 | const 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 | |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Check Board Identity: |
| 76 | */ |
| 77 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 78 | int checkboard(void) |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 79 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 81 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 82 | uchar latch, rev, mod; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Init ChipSelect #4 (CAN + HW-Latch) |
| 86 | */ |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 87 | 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; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 97 | } |
| 98 | |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 99 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 100 | phys_size_t initdram(int board_type) |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 101 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 102 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 103 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 104 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 105 | upmconfig(UPMA, (uint *) sdram_table, |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 106 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 107 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 108 | out_be16(&memctl->memc_mptpr, CONFIG_SYS_MPTPR); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 109 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 110 | out_be32(&memctl->memc_mar, 0x00000088); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 111 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 112 | out_be32(&memctl->memc_mamr, |
| 113 | CONFIG_SYS_MAMR & (~(MAMR_PTAE))); /* no refresh yet */ |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 114 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 115 | udelay(200); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 116 | |
| 117 | /* perform SDRAM initializsation sequence */ |
| 118 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 119 | /* 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); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 126 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 127 | /* 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); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 134 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 135 | /* 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); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 142 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 143 | /* 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); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 150 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 151 | setbits_be32(&memctl->memc_mamr, MAMR_PTAE); /* enable refresh */ |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 152 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 153 | 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); |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 170 | int misc_init_r(void) |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 171 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 173 | |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 174 | #ifdef CONFIG_IDE_LED |
| 175 | /* Configure PA8 as output port */ |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 176 | 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 */ |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 180 | #endif |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 181 | load_sernum_ethaddr(); |
Heiko Schocher | e604e40 | 2010-07-19 23:46:48 +0200 | [diff] [blame] | 182 | setenv("hw", "4x"); |
| 183 | poweron_key(); |
| 184 | return 0; |
wdenk | 0608e04 | 2004-03-25 19:29:38 +0000 | [diff] [blame] | 185 | } |