2 * Copyright (C) 2007 Freescale Semiconductor, Inc.
4 * Copyright (C) 2011 Matrix Vision GmbH
5 * Andre Schwarz <andre.schwarz@matrix-vision.de>
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
21 #include <asm/fsl_mpc83xx_serdes.h>
22 #include <fdt_support.h>
23 #include <spd_sdram.h>
24 #include "mergerbox.h"
26 #include "../common/mv_common.h"
28 static void setup_serdes(void)
30 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
31 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
32 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
33 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
36 #if defined(CONFIG_SYS_DRAM_TEST)
39 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
40 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
43 printf("Testing DRAM from 0x%08x to 0x%08x\n",
44 CONFIG_SYS_MEMTEST_START, CONFIG_SYS_MEMTEST_END);
46 printf("DRAM test phase 1:\n");
47 for (p = pstart; p < pend; p++)
50 for (p = pstart; p < pend; p++) {
51 if (*p != 0xaaaaaaaa) {
52 printf("DRAM test fails at: %08x\n", (uint) p);
57 printf("DRAM test phase 2:\n");
58 for (p = pstart; p < pend; p++)
61 for (p = pstart; p < pend; p++) {
62 if (*p != 0x55555555) {
63 printf("DRAM test fails at: %08x\n", (uint) p);
68 printf("DRAM test passed.\n");
73 phys_size_t initdram(int board_type)
77 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
78 volatile clk83xx_t *clk = (clk83xx_t *)&immr->clk;
80 /* Enable PCI_CLK[0:1] */
81 clk->occr |= 0xc0000000;
84 #if defined(CONFIG_SPD_EEPROM)
87 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
90 msize = CONFIG_SYS_DDR_SIZE;
91 msize_log2 = __ilog2(msize);
93 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
94 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
96 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
99 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
102 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
103 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
106 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
107 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
108 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
109 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
110 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
111 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
112 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
113 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
114 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
115 __asm__ __volatile__("sync");
118 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
128 puts("Board: Matrix Vision MergerBox\n");
133 int misc_init_r(void)
137 volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
138 volatile gpio83xx_t *gpio = (gpio83xx_t *)&immr->gpio[1];
139 unsigned char mac[6], mac_verify[6];
140 char *s = getenv("reset_env");
142 for (dim = 10; dim < 180; dim += 5) {
143 mergerbox_tft_dim(dim);
148 mv_reset_environment();
150 i2c_read(SPD_EEPROM_ADDRESS, 0x80, 2, mac, sizeof(mac));
152 /* check if Matrix Vision prefix present and export to env */
153 if (mac[0] == 0x00 && mac[1] == 0x0c && mac[2] == 0x8d) {
154 printf("valid MAC found in eeprom: %pM\n", mac);
155 eth_setenv_enetaddr("ethaddr", mac);
157 printf("no valid MAC found in eeprom.\n");
159 /* no: check the env */
160 if (!eth_getenv_enetaddr("ethaddr", mac)) {
161 printf("no valid MAC found in env either.\n");
162 /* TODO: ask for valid MAC */
164 printf("valid MAC found in env: %pM\n", mac);
165 printf("updating MAC in eeprom.\n");
168 result = test_and_clear_bit(20, &gpio->dat);
170 printf("unprotect EEPROM failed !\n");
174 i2c_write(SPD_EEPROM_ADDRESS, 0x80, 2, mac, 6);
178 result = test_and_set_bit(20, &gpio->dat);
180 printf("protect EEPROM failed !\n");
184 printf("verify MAC %pM ... ", mac);
185 i2c_read(SPD_EEPROM_ADDRESS, 0x80, 2, mac_verify, 6);
187 if (!strncmp((char *)mac, (char *)mac_verify, 6))
190 /* TODO: retry or do something useful */
191 printf("FAILED (got %pM) !\n", mac_verify);
198 int spi_cs_is_valid(unsigned int bus, unsigned int cs)
200 return bus == 0 && cs == 0;
203 void spi_cs_activate(struct spi_slave *slave)
205 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
207 iopd->dat &= ~TFT_SPI_CPLD_CS;
210 void spi_cs_deactivate(struct spi_slave *slave)
212 volatile gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0];
214 iopd->dat |= TFT_SPI_CPLD_CS;
217 /* control backlight pwm (display brightness).
218 * allow values 0-250 with 0 = turn off and 250 = max brightness
220 void mergerbox_tft_dim(u16 value)
222 struct spi_slave *slave;
226 if (value > 0 && value < 250)
227 dout = 0x4000 | value;
229 slave = spi_setup_slave(0, 0, 1000000, SPI_MODE_0 | SPI_CS_HIGH);
230 spi_claim_bus(slave);
231 spi_xfer(slave, 16, &dout, &din, SPI_XFER_BEGIN | SPI_XFER_END);
232 spi_release_bus(slave);
233 spi_free_slave(slave);
236 void ft_board_setup(void *blob, bd_t *bd)
238 ft_cpu_setup(blob, bd);
239 fdt_fixup_dr_usb(blob, bd);
240 ft_pci_setup(blob, bd);