1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) Freescale Semiconductor, Inc. 2006.
7 #include <fdt_support.h>
16 #include <asm/mpc8349_pci.h>
19 #include <spd_sdram.h>
21 #if defined(CONFIG_OF_LIBFDT)
22 #include <linux/libfdt.h>
25 #include "../../../arch/powerpc/cpu/mpc83xx/hrcw/hrcw.h"
26 #include "../../../arch/powerpc/cpu/mpc83xx/elbc/elbc.h"
28 DECLARE_GLOBAL_DATA_PTR;
30 #ifndef CONFIG_SPD_EEPROM
31 /*************************************************************************
32 * fixed sdram init -- doesn't use serial presence detect.
33 ************************************************************************/
36 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
37 /* The size of RAM, in bytes */
38 u32 ddr_size = CONFIG_SYS_DDR_SIZE << 20;
39 u32 ddr_size_log2 = __ilog2(ddr_size);
41 im->sysconf.ddrlaw[0].ar =
42 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
43 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
45 #if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
46 #warning Chip select bounds is only configurable in 16MB increments
48 im->ddr.csbnds[0].csbnds =
49 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
50 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
51 CSBNDS_EA_SHIFT) & CSBNDS_EA);
52 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
54 /* Only one CS for DDR */
55 im->ddr.cs_config[1] = 0;
56 im->ddr.cs_config[2] = 0;
57 im->ddr.cs_config[3] = 0;
59 debug("cs0_bnds = 0x%08x\n", im->ddr.csbnds[0].csbnds);
60 debug("cs0_config = 0x%08x\n", im->ddr.cs_config[0]);
62 debug("DDR:bar=0x%08x\n", im->sysconf.ddrlaw[0].bar);
63 debug("DDR:ar=0x%08x\n", im->sysconf.ddrlaw[0].ar);
65 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
66 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
67 im->ddr.sdram_cfg = SDRAM_CFG_SREN | SDRAM_CFG_SDRAM_TYPE_DDR1;
69 (0x0000 << SDRAM_MODE_ESD_SHIFT) | (0x0032 << SDRAM_MODE_SD_SHIFT);
70 im->ddr.sdram_interval =
71 (0x0410 << SDRAM_INTERVAL_REFINT_SHIFT) | (0x0100 <<
72 SDRAM_INTERVAL_BSTOPRE_SHIFT);
73 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
77 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
79 debug("DDR:timing_cfg_1=0x%08x\n", im->ddr.timing_cfg_1);
80 debug("DDR:timing_cfg_2=0x%08x\n", im->ddr.timing_cfg_2);
81 debug("DDR:sdram_mode=0x%08x\n", im->ddr.sdram_mode);
82 debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
83 debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
85 return CONFIG_SYS_DDR_SIZE;
91 * Initialize PCI Devices, report devices found
93 #ifndef CONFIG_PCI_PNP
94 static struct pci_config_table pci_mpc83xxmitx_config_table[] = {
102 pci_cfgfunc_config_device,
106 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
112 volatile static struct pci_controller hose[] = {
114 #ifndef CONFIG_PCI_PNP
115 config_table:pci_mpc83xxmitx_config_table,
119 #ifndef CONFIG_PCI_PNP
120 config_table:pci_mpc83xxmitx_config_table,
124 #endif /* CONFIG_PCI */
128 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
130 #ifdef CONFIG_DDR_ECC
131 volatile ddr83xx_t *ddr = &im->ddr;
134 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
137 /* DDR SDRAM - Main SODIMM */
138 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
139 #ifdef CONFIG_SPD_EEPROM
142 msize = fixed_sdram();
145 #ifdef CONFIG_DDR_ECC
146 if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
147 /* Unlike every other board, on the 83xx spd_sdram() returns
148 megabytes instead of just bytes. That's why we need to
149 multiple by 1MB when calling ddr_enable_ecc(). */
150 ddr_enable_ecc(msize * 1048576);
153 /* return total bus RAM size(bytes) */
154 gd->ram_size = msize * 1024 * 1024;
161 #ifdef CONFIG_TARGET_MPC8349ITX
162 puts("Board: Freescale MPC8349E-mITX\n");
164 puts("Board: Freescale MPC8349E-mITX-GP\n");
171 * Implement a work-around for a hardware problem with compact
174 * Program the UPM if compact flash is enabled.
176 int misc_init_f(void)
178 #ifdef CONFIG_VSC7385_ENET
179 volatile u32 *vsc7385_cpuctrl;
181 /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
182 default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
183 means it is 0 when the IRQ is not active. This makes the wire-AND
184 logic always assert IRQ7 to CPU even if there is no request from the
185 switch. Since the compact flash and the switch share the same IRQ,
186 the Linux kernel will think that the compact flash is requesting irq
187 and get stuck when it tries to clear the IRQ. Thus we need to set
188 the L2_IRQ0 and L2_IRQ1 to active low.
190 The following code sets the L1_IRQ and L2_IRQ polarity to active low.
191 Without this code, compact flash will not work in Linux because
192 unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
193 don't enable compact flash for U-Boot.
196 vsc7385_cpuctrl = (volatile u32 *)(CONFIG_SYS_VSC7385_BASE + 0x1c0c0);
197 *vsc7385_cpuctrl |= 0x0c;
200 #ifdef CONFIG_COMPACT_FLASH
201 /* UPM Table Configuration Code */
202 static uint UPMATable[] = {
203 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
204 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
205 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
206 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
207 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
208 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
209 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
210 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
211 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
212 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
213 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
214 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
215 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
216 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
217 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
218 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
220 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
222 set_lbc_br(3, CONFIG_SYS_BR3_PRELIM);
223 set_lbc_or(3, CONFIG_SYS_OR3_PRELIM);
225 /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
226 GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
228 immap->im_lbc.mamr = 0x08404440;
230 upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
232 puts("UPMA: Configured for compact flash\n");
239 * Miscellaneous late-boot configurations
241 * Make sure the EEPROM has the HRCW correctly programmed.
242 * Make sure the RTC is correctly programmed.
244 * The MPC8349E-mITX can be configured to load the HRCW from
245 * EEPROM instead of flash. This is controlled via jumpers
246 * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
247 * jumpered), but if they're set to 001 or 010, then the HRCW is
248 * read from the "I2C EEPROM".
250 * This function makes sure that the I2C EEPROM is programmed
253 * If a VSC7385 microcode image is present, then upload it.
255 int misc_init_r(void)
259 #if defined(CONFIG_SYS_I2C)
260 unsigned int orig_bus = i2c_get_bus_num();
263 #ifdef CONFIG_SYS_I2C_RTC_ADDR
267 #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
268 static u8 eeprom_data[] = /* HRCW data */
270 0xAA, 0x55, 0xAA, /* Preamble */
271 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
272 0x02, 0x40, /* RCWL ADDR=0x0_0900 */
273 (CONFIG_SYS_HRCW_LOW >> 24) & 0xFF,
274 (CONFIG_SYS_HRCW_LOW >> 16) & 0xFF,
275 (CONFIG_SYS_HRCW_LOW >> 8) & 0xFF,
276 CONFIG_SYS_HRCW_LOW & 0xFF,
277 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
278 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
279 (CONFIG_SYS_HRCW_HIGH >> 24) & 0xFF,
280 (CONFIG_SYS_HRCW_HIGH >> 16) & 0xFF,
281 (CONFIG_SYS_HRCW_HIGH >> 8) & 0xFF,
282 CONFIG_SYS_HRCW_HIGH & 0xFF
285 u8 data[sizeof(eeprom_data)];
288 printf("Board revision: ");
290 if (i2c_read(CONFIG_SYS_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
291 printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
292 else if (i2c_read(CONFIG_SYS_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
293 printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
299 #ifdef CONFIG_SYS_I2C_EEPROM_ADDR
302 if (i2c_read(CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
303 if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
305 (CONFIG_SYS_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
306 sizeof(eeprom_data)) != 0) {
307 puts("Failure writing the HRCW to EEPROM via I2C.\n");
312 puts("Failure reading the HRCW from EEPROM via I2C.\n");
317 #ifdef CONFIG_SYS_I2C_RTC_ADDR
320 if (i2c_read(CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
323 /* Work-around for MPC8349E-mITX bug #13601.
324 If the RTC does not contain valid register values, the DS1339
325 Linux driver will not work.
328 /* Make sure status register bits 6-2 are zero */
329 ds1339_data[0x0f] &= ~0x7c;
331 /* Check for a valid day register value */
332 ds1339_data[0x03] &= ~0xf8;
333 if (ds1339_data[0x03] == 0) {
334 ds1339_data[0x03] = 1;
337 /* Check for a valid date register value */
338 ds1339_data[0x04] &= ~0xc0;
339 if ((ds1339_data[0x04] == 0) ||
340 ((ds1339_data[0x04] & 0x0f) > 9) ||
341 (ds1339_data[0x04] >= 0x32)) {
342 ds1339_data[0x04] = 1;
345 /* Check for a valid month register value */
346 ds1339_data[0x05] &= ~0x60;
348 if ((ds1339_data[0x05] == 0) ||
349 ((ds1339_data[0x05] & 0x0f) > 9) ||
350 ((ds1339_data[0x05] >= 0x13)
351 && (ds1339_data[0x05] <= 0x19))) {
352 ds1339_data[0x05] = 1;
355 /* Enable Oscillator and rate select */
356 ds1339_data[0x0e] = 0x1c;
358 /* Work-around for MPC8349E-mITX bug #13330.
359 Ensure that the RTC control register contains the value 0x1c.
360 This affects SATA performance.
364 (CONFIG_SYS_I2C_RTC_ADDR, 0, 1, ds1339_data,
365 sizeof(ds1339_data))) {
366 puts("Failure writing to the RTC via I2C.\n");
370 puts("Failure reading from the RTC via I2C.\n");
375 i2c_set_bus_num(orig_bus);
378 #ifdef CONFIG_VSC7385_IMAGE
379 if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
380 CONFIG_VSC7385_IMAGE_SIZE)) {
381 puts("Failure uploading VSC7385 microcode.\n");
389 #if defined(CONFIG_OF_BOARD_SETUP)
390 int ft_board_setup(void *blob, bd_t *bd)
392 ft_cpu_setup(blob, bd);
394 ft_pci_setup(blob, bd);