blob: 4c220fa8e1353cc485e1f5a48c03d24db17b2647 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Reinhard Arltc2e49f72009-07-25 06:19:12 +02002/*
3 * vme8349.c -- esd VME8349 board support
4 *
5 * Copyright (c) 2008-2009 esd gmbh.
6 *
7 * (C) Copyright 2006
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
10 * Reinhard Arlt <reinhard.arlt@esd-electronics.com>
11 * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
Reinhard Arltc2e49f72009-07-25 06:19:12 +020012 */
13
14#include <common.h>
15#include <ioports.h>
16#include <mpc83xx.h>
17#include <asm/mpc8349_pci.h>
18#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Reinhard Arltc2e49f72009-07-25 06:19:12 +020020#endif
21#include <asm/io.h>
22#include <asm/mmu.h>
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010023#include <spd.h>
24#include <spd_sdram.h>
25#include <i2c.h>
26#include <netdev.h>
Reinhard Arltc2e49f72009-07-25 06:19:12 +020027
Simon Glass088454c2017-03-31 08:40:25 -060028DECLARE_GLOBAL_DATA_PTR;
29
Reinhard Arltc2e49f72009-07-25 06:19:12 +020030void ddr_enable_ecc(unsigned int dram_size);
31
Simon Glassf1683aa2017-04-06 12:47:05 -060032int dram_init(void)
Reinhard Arltc2e49f72009-07-25 06:19:12 +020033{
34 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
35 u32 msize = 0;
36
37 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
Simon Glass088454c2017-03-31 08:40:25 -060038 return -ENXIO;
Reinhard Arltc2e49f72009-07-25 06:19:12 +020039
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010040 /* DDR SDRAM - Main memory */
Mario Six8a81bfd2019-01-21 09:18:15 +010041 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Reinhard Arltc2e49f72009-07-25 06:19:12 +020042
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010043 msize = spd_sdram();
Reinhard Arltc2e49f72009-07-25 06:19:12 +020044
45#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
46 /*
47 * Initialize and enable DDR ECC.
48 */
49 ddr_enable_ecc(msize * 1024 * 1024);
50#endif
51
52 /* Now check memory size (after ECC is initialized) */
53 msize = get_ram_size(0, msize);
54
55 /* return total bus SDRAM size(bytes) -- DDR */
Simon Glass088454c2017-03-31 08:40:25 -060056 gd->ram_size = msize * 1024 * 1024;
57
58 return 0;
Reinhard Arltc2e49f72009-07-25 06:19:12 +020059}
60
61int checkboard(void)
62{
Mario Six904c47f2019-01-21 09:17:38 +010063#ifdef CONFIG_TARGET_CADDY2
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010064 puts("Board: esd VME-CADDY/2\n");
65#else
66 puts("Board: esd VME-CPU/8349\n");
67#endif
Reinhard Arltc2e49f72009-07-25 06:19:12 +020068
69 return 0;
70}
71
Mario Six904c47f2019-01-21 09:17:38 +010072#ifdef CONFIG_TARGET_CADDY2
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010073int board_eth_init(bd_t *bis)
74{
75 return pci_eth_init(bis);
76}
77#endif
78
Reinhard Arltc2e49f72009-07-25 06:19:12 +020079#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -060080int ft_board_setup(void *blob, bd_t *bd)
Reinhard Arltc2e49f72009-07-25 06:19:12 +020081{
82 ft_cpu_setup(blob, bd);
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010083
Reinhard Arltc2e49f72009-07-25 06:19:12 +020084#ifdef CONFIG_PCI
85 ft_pci_setup(blob, bd);
86#endif
Simon Glasse895a4b2014-10-23 18:58:47 -060087
88 return 0;
Reinhard Arltc2e49f72009-07-25 06:19:12 +020089}
90#endif
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010091
92int misc_init_r()
93{
94 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
95
Becky Brucef51cdaf2010-06-17 11:37:20 -050096 clrsetbits_be32(&im->im_lbc.lcrr, LBCR_LDIS, 0);
Reinhard Arlt1dee9be2009-12-08 09:13:08 +010097
98 return 0;
99}
100
101/*
102 * Provide SPD values for spd_sdram(). Both boards (VME-CADDY/2
103 * and VME-CADDY/2) have different SDRAM configurations.
104 */
Mario Six904c47f2019-01-21 09:17:38 +0100105#ifdef CONFIG_TARGET_CADDY2
Reinhard Arlt1dee9be2009-12-08 09:13:08 +0100106#define SMALL_RAM 0xff
107#define LARGE_RAM 0x00
108#else
109#define SMALL_RAM 0x00
110#define LARGE_RAM 0xff
111#endif
112
113#define SPD_VAL(a, b) (((a) & SMALL_RAM) | ((b) & LARGE_RAM))
114
115static spd_eeprom_t default_spd_eeprom = {
116 SPD_VAL(0x80, 0x80), /* 00 use 128 Bytes */
117 SPD_VAL(0x07, 0x07), /* 01 use 128 Bytes */
118 SPD_MEMTYPE_DDR2, /* 02 type is DDR2 */
119 SPD_VAL(0x0d, 0x0d), /* 03 rows: 13 */
120 SPD_VAL(0x09, 0x0a), /* 04 cols: 9 / 10 */
121 SPD_VAL(0x00, 0x00), /* 05 */
122 SPD_VAL(0x40, 0x40), /* 06 */
123 SPD_VAL(0x00, 0x00), /* 07 */
124 SPD_VAL(0x05, 0x05), /* 08 */
125 SPD_VAL(0x30, 0x30), /* 09 */
126 SPD_VAL(0x45, 0x45), /* 10 */
127 SPD_VAL(0x02, 0x02), /* 11 ecc used */
128 SPD_VAL(0x82, 0x82), /* 12 */
129 SPD_VAL(0x10, 0x10), /* 13 */
130 SPD_VAL(0x08, 0x08), /* 14 */
131 SPD_VAL(0x00, 0x00), /* 15 */
132 SPD_VAL(0x0c, 0x0c), /* 16 */
133 SPD_VAL(0x04, 0x08), /* 17 banks: 4 / 8 */
134 SPD_VAL(0x38, 0x38), /* 18 */
135 SPD_VAL(0x00, 0x00), /* 19 */
136 SPD_VAL(0x02, 0x02), /* 20 */
137 SPD_VAL(0x00, 0x00), /* 21 */
138 SPD_VAL(0x03, 0x03), /* 22 */
139 SPD_VAL(0x3d, 0x3d), /* 23 */
140 SPD_VAL(0x45, 0x45), /* 24 */
141 SPD_VAL(0x50, 0x50), /* 25 */
142 SPD_VAL(0x45, 0x45), /* 26 */
143 SPD_VAL(0x3c, 0x3c), /* 27 */
144 SPD_VAL(0x28, 0x28), /* 28 */
145 SPD_VAL(0x3c, 0x3c), /* 29 */
146 SPD_VAL(0x2d, 0x2d), /* 30 */
147 SPD_VAL(0x20, 0x80), /* 31 */
148 SPD_VAL(0x20, 0x20), /* 32 */
149 SPD_VAL(0x27, 0x27), /* 33 */
150 SPD_VAL(0x10, 0x10), /* 34 */
151 SPD_VAL(0x17, 0x17), /* 35 */
152 SPD_VAL(0x3c, 0x3c), /* 36 */
153 SPD_VAL(0x1e, 0x1e), /* 37 */
154 SPD_VAL(0x1e, 0x1e), /* 38 */
155 SPD_VAL(0x00, 0x00), /* 39 */
156 SPD_VAL(0x00, 0x06), /* 40 */
157 SPD_VAL(0x37, 0x37), /* 41 */
158 SPD_VAL(0x4b, 0x7f), /* 42 */
159 SPD_VAL(0x80, 0x80), /* 43 */
160 SPD_VAL(0x18, 0x18), /* 44 */
161 SPD_VAL(0x22, 0x22), /* 45 */
162 SPD_VAL(0x00, 0x00), /* 46 */
163 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
164 SPD_VAL(0x10, 0x10), /* 62 */
165 SPD_VAL(0x7e, 0x1d), /* 63 */
166 { 'e', 's', 'd', '-', 'g', 'm', 'b', 'h' },
167 SPD_VAL(0x00, 0x00), /* 72 */
Mario Six904c47f2019-01-21 09:17:38 +0100168#ifdef CONFIG_TARGET_CADDY2
Reinhard Arlt1dee9be2009-12-08 09:13:08 +0100169 { "vme-caddy/2 ram " }
170#else
171 { "vme-cpu/2 ram " }
172#endif
173};
174
175int vme8349_read_spd(uchar chip, uint addr, int alen, uchar *buffer, int len)
176{
Heiko Schocher00f792e2012-10-24 13:48:22 +0200177 int old_bus = i2c_get_bus_num();
Reinhard Arlt1dee9be2009-12-08 09:13:08 +0100178 unsigned int l, sum;
179 int valid = 0;
180
Heiko Schocher00f792e2012-10-24 13:48:22 +0200181 i2c_set_bus_num(0);
Reinhard Arlt1dee9be2009-12-08 09:13:08 +0100182
183 if (i2c_read(chip, addr, alen, buffer, len) == 0)
184 if (memcmp(&buffer[64], &default_spd_eeprom.mid[0], 8) == 0) {
185 sum = 0;
186 for (l = 0; l < 63; l++)
187 sum = (sum + buffer[l]) & 0xff;
188 if (sum == buffer[63])
189 valid = 1;
190 else
191 printf("Invalid checksum in EEPROM %02x %02x\n",
192 sum, buffer[63]);
193 }
194
195 if (valid == 0) {
196 memcpy(buffer, (void *)&default_spd_eeprom, len);
197 sum = 0;
198 for (l = 0; l < 63; l++)
199 sum = (sum + buffer[l]) & 0xff;
200 if (sum != buffer[63])
201 printf("Invalid checksum in FLASH %02x %02x\n",
202 sum, buffer[63]);
203 buffer[63] = sum;
204 }
205
Heiko Schocher00f792e2012-10-24 13:48:22 +0200206 i2c_set_bus_num(old_bus);
Reinhard Arlt1dee9be2009-12-08 09:13:08 +0100207
208 return 0;
209}