blob: 33a8aa51847d4e91b6287889349c11f6f9f5e988 [file] [log] [blame]
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02001/*
Wolfgang Denkb8539952009-05-16 10:47:43 +02002 * (C) Copyright 2007-2009 DENX Software Engineering
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02003 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
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.
11 *
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.
16 *
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,
20 * MA 02111-1307 USA
21 *
22 */
23
24#include <common.h>
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020025#include <asm/bitops.h>
26#include <command.h>
Wolfgang Denkb8539952009-05-16 10:47:43 +020027#include <asm/io.h>
John Rigby0c9b3012008-08-28 13:17:07 -060028#include <asm/processor.h>
Wolfgang Denk1d7cc1e2009-06-14 20:58:47 +020029#include <asm/mpc512x.h>
Wolfgang Denk049430f2008-01-13 00:55:47 +010030#include <fdt_support.h>
Martha Marxfd449ab2008-05-29 14:23:25 -040031#ifdef CONFIG_MISC_INIT_R
32#include <i2c.h>
33#endif
Martha M Stanff8c0df2009-09-21 14:08:00 -040034#include <net.h>
Wolfgang Denk12cec0a2008-07-11 01:16:00 +020035
Stefan Roese406e95a2009-06-09 16:57:47 +020036#include <linux/mtd/mtd.h>
37#include <linux/mtd/nand.h>
38
Ralph Kondziellad074bfe2009-01-26 12:34:36 -070039DECLARE_GLOBAL_DATA_PTR;
40
Stefan Roese406e95a2009-06-09 16:57:47 +020041void __mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip);
42
43/* Active chip number set in board_nand_select_device() (mpc5121_nfc.c) */
44extern int mpc5121_nfc_chip;
45
46/* Control chips select signal on MPC5121ADS board */
47void mpc5121_nfc_select_chip(struct mtd_info *mtd, int chip)
48{
49 unsigned char *csreg = (u8 *)CONFIG_SYS_CPLD_BASE + 0x09;
50 u8 v;
51
52 v = in_8(csreg);
53 v |= 0x0F;
54
55 if (chip >= 0) {
56 __mpc5121_nfc_select_chip(mtd, 0);
57 v &= ~(1 << mpc5121_nfc_chip);
58 } else {
59 __mpc5121_nfc_select_chip(mtd, -1);
60 }
61
62 out_8(csreg, v);
63}
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020064
Wolfgang Denk1d7cc1e2009-06-14 20:58:47 +020065int board_early_init_f(void)
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020066{
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020067 /*
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020068 * Disable Boot NOR FLASH write protect - CPLD Reg 8 NOR FLASH Control
69 *
70 * Without this the flash identification routine fails, as it needs to issue
71 * write commands in order to establish the device ID.
72 */
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020073
mark.vels@team-embedded.nlec281332010-10-05 17:46:19 +020074#ifdef CONFIG_MPC5121ADS_REV2
Wolfgang Denkb8539952009-05-16 10:47:43 +020075 out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
Martha Marxfd449ab2008-05-29 14:23:25 -040076#else
Wolfgang Denkb8539952009-05-16 10:47:43 +020077 if (in_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08)) & 0x04) {
78 out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0xC1);
Martha Marxfd449ab2008-05-29 14:23:25 -040079 } else {
80 /* running from Backup flash */
Wolfgang Denkb8539952009-05-16 10:47:43 +020081 out_8((u8 *)(CONFIG_SYS_CPLD_BASE + 0x08), 0x32);
Martha Marxfd449ab2008-05-29 14:23:25 -040082 }
83#endif
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020084 return 0;
85}
86
Martha M Stanff8c0df2009-09-21 14:08:00 -040087int is_micron(void){
88
89 ushort brd_rev = *(vu_short *)(CONFIG_SYS_CPLD_BASE + 0x00);
90 uchar macaddr[6];
91 u32 brddate, macchk, ismicron;
92
93 /*
94 * MAC address has serial number with date of manufacture
95 * Boards made before Nov-08 #1180 use Micron memory;
96 * 001e59 is the STx vendor #
97 * Default is Elpida since it works for both but is slightly slower
98 */
99 ismicron = 0;
100 if (brd_rev >= 0x0400 && eth_getenv_enetaddr("ethaddr", macaddr)) {
101 brddate = (macaddr[3] << 16) + (macaddr[4] << 8) + macaddr[5];
102 macchk = (macaddr[0] << 16) + (macaddr[1] << 8) + macaddr[2];
103 debug("brddate = %d\n\t", brddate);
104
105 if (macchk == 0x001e59 && brddate <= 8111180)
106 ismicron = 1;
107 } else if (brd_rev < 0x400) {
108 ismicron = 1;
109 }
110 debug("Using %s Memory settings\n\t",
111 ismicron ? "Micron" : "Elpida");
112 return(ismicron);
113}
114
Wolfgang Denk1d7cc1e2009-06-14 20:58:47 +0200115phys_size_t initdram(int board_type)
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200116{
117 u32 msize = 0;
Martha M Stanff8c0df2009-09-21 14:08:00 -0400118 /*
119 * Elpida MDDRC and initialization settings are an alternative
120 * to the Default Micron ones for all but the earliest Rev 4 boards
121 */
Wolfgang Denkce33a012009-10-04 22:56:08 +0200122 ddr512x_config_t elpida_mddrc_config = {
123 .ddr_sys_config = CONFIG_SYS_MDDRC_SYS_CFG_ELPIDA,
124 .ddr_time_config0 = CONFIG_SYS_MDDRC_TIME_CFG0,
125 .ddr_time_config1 = CONFIG_SYS_MDDRC_TIME_CFG1_ELPIDA,
126 .ddr_time_config2 = CONFIG_SYS_MDDRC_TIME_CFG2_ELPIDA,
Martha M Stanff8c0df2009-09-21 14:08:00 -0400127 };
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200128
Martha M Stanff8c0df2009-09-21 14:08:00 -0400129 u32 elpida_init_sequence[] = {
130 CONFIG_SYS_DDRCMD_NOP,
131 CONFIG_SYS_DDRCMD_NOP,
132 CONFIG_SYS_DDRCMD_NOP,
133 CONFIG_SYS_DDRCMD_NOP,
134 CONFIG_SYS_DDRCMD_NOP,
135 CONFIG_SYS_DDRCMD_NOP,
136 CONFIG_SYS_DDRCMD_NOP,
137 CONFIG_SYS_DDRCMD_NOP,
138 CONFIG_SYS_DDRCMD_NOP,
139 CONFIG_SYS_DDRCMD_NOP,
140 CONFIG_SYS_DDRCMD_PCHG_ALL,
141 CONFIG_SYS_DDRCMD_NOP,
142 CONFIG_SYS_DDRCMD_RFSH,
143 CONFIG_SYS_DDRCMD_NOP,
144 CONFIG_SYS_DDRCMD_RFSH,
145 CONFIG_SYS_DDRCMD_NOP,
146 CONFIG_SYS_DDRCMD_EM2,
147 CONFIG_SYS_DDRCMD_EM3,
148 CONFIG_SYS_DDRCMD_EN_DLL,
149 CONFIG_SYS_ELPIDA_RES_DLL,
150 CONFIG_SYS_DDRCMD_PCHG_ALL,
151 CONFIG_SYS_DDRCMD_RFSH,
152 CONFIG_SYS_DDRCMD_RFSH,
153 CONFIG_SYS_DDRCMD_RFSH,
154 CONFIG_SYS_ELPIDA_INIT_DEV_OP,
155 CONFIG_SYS_DDRCMD_NOP,
156 CONFIG_SYS_DDRCMD_NOP,
157 CONFIG_SYS_DDRCMD_NOP,
158 CONFIG_SYS_DDRCMD_NOP,
159 CONFIG_SYS_DDRCMD_NOP,
160 CONFIG_SYS_DDRCMD_NOP,
161 CONFIG_SYS_DDRCMD_NOP,
162 CONFIG_SYS_DDRCMD_NOP,
163 CONFIG_SYS_DDRCMD_NOP,
164 CONFIG_SYS_DDRCMD_NOP,
165 CONFIG_SYS_DDRCMD_OCD_DEFAULT,
166 CONFIG_SYS_ELPIDA_OCD_EXIT,
167 CONFIG_SYS_DDRCMD_NOP,
168 CONFIG_SYS_DDRCMD_NOP,
169 CONFIG_SYS_DDRCMD_NOP,
170 CONFIG_SYS_DDRCMD_NOP,
171 CONFIG_SYS_DDRCMD_NOP,
172 CONFIG_SYS_DDRCMD_NOP,
173 CONFIG_SYS_DDRCMD_NOP,
174 CONFIG_SYS_DDRCMD_NOP,
175 CONFIG_SYS_DDRCMD_NOP,
176 CONFIG_SYS_DDRCMD_NOP
177 };
178
179 if (is_micron()) {
180 msize = fixed_sdram(NULL, NULL, 0);
181 } else {
Wolfgang Denkce33a012009-10-04 22:56:08 +0200182 msize = fixed_sdram(&elpida_mddrc_config,
Martha M Stanff8c0df2009-09-21 14:08:00 -0400183 elpida_init_sequence,
184 sizeof(elpida_init_sequence)/sizeof(u32));
185 }
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200186
187 return msize;
188}
189
York Sunfd7cbfd2008-05-05 10:20:01 -0500190int misc_init_r(void)
191{
192 u8 tmp_val;
193
194 /* Using this for DIU init before the driver in linux takes over
195 * Enable the TFP410 Encoder (I2C address 0x38)
196 */
197
198 i2c_set_bus_num(2);
199 tmp_val = 0xBF;
200 i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
201 /* Verify if enabled */
202 tmp_val = 0;
203 i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
Marek Vasut4a5a6d72011-10-21 14:17:03 +0000204 debug("DVI Encoder Read: 0x%02x\n", tmp_val);
York Sunfd7cbfd2008-05-05 10:20:01 -0500205
206 tmp_val = 0x10;
207 i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
208 /* Verify if enabled */
209 tmp_val = 0;
210 i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
Marek Vasut4a5a6d72011-10-21 14:17:03 +0000211 debug("DVI Encoder Read: 0x%02x\n", tmp_val);
York Sunfd7cbfd2008-05-05 10:20:01 -0500212
York Sunfd7cbfd2008-05-05 10:20:01 -0500213 return 0;
214}
Wolfgang Denkbbcbb322009-05-16 10:47:41 +0200215
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200216static iopin_t ioregs_init[] = {
217 /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
218 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200219 offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200220 IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
221 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
222 },
223 /* Set highest Slew on 9 PATA pins */
224 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200225 offsetof(struct ioctrl512x, io_control_pata_ce1), 9, 1,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200226 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
227 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
228 },
229 /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
230 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200231 offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200232 IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
233 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
234 },
235 /* FUNC1=SPDIF_TXCLK */
236 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200237 offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200238 IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
239 IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
240 },
241 /* FUNC2=SPDIF_TX and sets Next pin to SPDIF_RX */
242 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200243 offsetof(struct ioctrl512x, io_control_i2c1_scl), 2, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200244 IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
245 IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
246 },
247 /* FUNC2=DIU CLK */
248 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200249 offsetof(struct ioctrl512x, io_control_psc6_0), 1, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200250 IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
251 IO_PIN_PUE(0) | IO_PIN_ST(1) | IO_PIN_DS(3)
252 },
253 /* FUNC2=DIU_HSYNC */
254 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200255 offsetof(struct ioctrl512x, io_control_psc6_1), 1, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200256 IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
257 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
258 },
259 /* FUNC2=DIUVSYNC Sets Next 26 to DIU Pads */
260 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200261 offsetof(struct ioctrl512x, io_control_psc6_4), 26, 0,
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200262 IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
263 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
264 }
265};
York Sunfd7cbfd2008-05-05 10:20:01 -0500266
John Rigbyea1dfef2009-01-23 10:33:15 -0700267static iopin_t rev2_silicon_pci_ioregs_init[] = {
268 /* FUNC0=PCI Sets next 54 to PCI pads */
269 {
Wolfgang Denkb8539952009-05-16 10:47:43 +0200270 offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
John Rigbyea1dfef2009-01-23 10:33:15 -0700271 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
272 }
273};
274
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200275int checkboard (void)
276{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200277 ushort brd_rev = *(vu_short *) (CONFIG_SYS_CPLD_BASE + 0x00);
278 uchar cpld_rev = *(vu_char *) (CONFIG_SYS_CPLD_BASE + 0x02);
John Rigbyea1dfef2009-01-23 10:33:15 -0700279 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Wolfgang Denkb8539952009-05-16 10:47:43 +0200280 u32 spridr = in_be32(&im->sysconf.spridr);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200281
mark.vels@team-embedded.nlec281332010-10-05 17:46:19 +0200282 printf ("Board: MPC5121ADS rev. 0x%04x (CPLD rev. 0x%02x)\n",
Wolfgang Denk530181f2007-08-02 21:27:46 +0200283 brd_rev, cpld_rev);
Wolfgang Denkbbcbb322009-05-16 10:47:41 +0200284
Martha Marx44727cb2008-05-29 15:37:21 -0400285 /* initialize function mux & slew rate IO inter alia on IO Pins */
Wolfgang Denkbbcbb322009-05-16 10:47:41 +0200286 iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
Kenneth Johansson8d676e42008-07-15 12:13:38 +0200287
Wolfgang Denkb8539952009-05-16 10:47:43 +0200288 if (SVR_MJREV (spridr) >= 2)
John Rigbyea1dfef2009-01-23 10:33:15 -0700289 iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
John Rigby92d24ac2007-08-24 18:18:43 -0600290
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200291 return 0;
292}
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100293
294#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
295void ft_board_setup(void *blob, bd_t *bd)
296{
297 ft_cpu_setup(blob, bd);
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100298}
299#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */