1 // SPDX-License-Identifier: GPL-2.0+
2 /*
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.)
12 */
13
14 #include <common.h>
15 #include <fdt_support.h>
16 #include <init.h>
17 #include <ioports.h>
18 #include <mpc83xx.h>
19 #include <net.h>
20 #include <asm/global_data.h>
21 #include <asm/mpc8349_pci.h>
22 #if defined(CONFIG_OF_LIBFDT)
23 #include <linux/libfdt.h>
24 #endif
25 #include <asm/io.h>
26 #include <asm/mmu.h>
27 #include <spd.h>
28 #include <spd_sdram.h>
29 #include <i2c.h>
30 #include <netdev.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 void ddr_enable_ecc(unsigned int dram_size);
35
dram_init(void)36 int dram_init(void)
37 {
38 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
39 u32 msize = 0;
40
41 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
42 return -ENXIO;
43
44 /* DDR SDRAM - Main memory */
45 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
46
47 msize = spd_sdram();
48
49 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
50 /*
51 * Initialize and enable DDR ECC.
52 */
53 ddr_enable_ecc(msize * 1024 * 1024);
54 #endif
55
56 /* Now check memory size (after ECC is initialized) */
57 msize = get_ram_size(0, msize);
58
59 /* return total bus SDRAM size(bytes) -- DDR */
60 gd->ram_size = msize * 1024 * 1024;
61
62 return 0;
63 }
64
checkboard(void)65 int checkboard(void)
66 {
67 #ifdef CONFIG_TARGET_CADDY2
68 puts("Board: esd VME-CADDY/2\n");
69 #else
70 puts("Board: esd VME-CPU/8349\n");
71 #endif
72
73 return 0;
74 }
75
76 #ifdef CONFIG_TARGET_CADDY2
board_eth_init(struct bd_info * bis)77 int board_eth_init(struct bd_info *bis)
78 {
79 return pci_eth_init(bis);
80 }
81 #endif
82
83 #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,struct bd_info * bd)84 int ft_board_setup(void *blob, struct bd_info *bd)
85 {
86 ft_cpu_setup(blob, bd);
87
88 #ifdef CONFIG_PCI
89 ft_pci_setup(blob, bd);
90 #endif
91
92 return 0;
93 }
94 #endif
95
misc_init_r()96 int misc_init_r()
97 {
98 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
99
100 clrsetbits_be32(&im->im_lbc.lcrr, LBCR_LDIS, 0);
101
102 return 0;
103 }
104
105 /*
106 * Provide SPD values for spd_sdram(). Both boards (VME-CADDY/2
107 * and VME-CADDY/2) have different SDRAM configurations.
108 */
109 #ifdef CONFIG_TARGET_CADDY2
110 #define SMALL_RAM 0xff
111 #define LARGE_RAM 0x00
112 #else
113 #define SMALL_RAM 0x00
114 #define LARGE_RAM 0xff
115 #endif
116
117 #define SPD_VAL(a, b) (((a) & SMALL_RAM) | ((b) & LARGE_RAM))
118
119 static spd_eeprom_t default_spd_eeprom = {
120 SPD_VAL(0x80, 0x80), /* 00 use 128 Bytes */
121 SPD_VAL(0x07, 0x07), /* 01 use 128 Bytes */
122 SPD_MEMTYPE_DDR2, /* 02 type is DDR2 */
123 SPD_VAL(0x0d, 0x0d), /* 03 rows: 13 */
124 SPD_VAL(0x09, 0x0a), /* 04 cols: 9 / 10 */
125 SPD_VAL(0x00, 0x00), /* 05 */
126 SPD_VAL(0x40, 0x40), /* 06 */
127 SPD_VAL(0x00, 0x00), /* 07 */
128 SPD_VAL(0x05, 0x05), /* 08 */
129 SPD_VAL(0x30, 0x30), /* 09 */
130 SPD_VAL(0x45, 0x45), /* 10 */
131 SPD_VAL(0x02, 0x02), /* 11 ecc used */
132 SPD_VAL(0x82, 0x82), /* 12 */
133 SPD_VAL(0x10, 0x10), /* 13 */
134 SPD_VAL(0x08, 0x08), /* 14 */
135 SPD_VAL(0x00, 0x00), /* 15 */
136 SPD_VAL(0x0c, 0x0c), /* 16 */
137 SPD_VAL(0x04, 0x08), /* 17 banks: 4 / 8 */
138 SPD_VAL(0x38, 0x38), /* 18 */
139 SPD_VAL(0x00, 0x00), /* 19 */
140 SPD_VAL(0x02, 0x02), /* 20 */
141 SPD_VAL(0x00, 0x00), /* 21 */
142 SPD_VAL(0x03, 0x03), /* 22 */
143 SPD_VAL(0x3d, 0x3d), /* 23 */
144 SPD_VAL(0x45, 0x45), /* 24 */
145 SPD_VAL(0x50, 0x50), /* 25 */
146 SPD_VAL(0x45, 0x45), /* 26 */
147 SPD_VAL(0x3c, 0x3c), /* 27 */
148 SPD_VAL(0x28, 0x28), /* 28 */
149 SPD_VAL(0x3c, 0x3c), /* 29 */
150 SPD_VAL(0x2d, 0x2d), /* 30 */
151 SPD_VAL(0x20, 0x80), /* 31 */
152 SPD_VAL(0x20, 0x20), /* 32 */
153 SPD_VAL(0x27, 0x27), /* 33 */
154 SPD_VAL(0x10, 0x10), /* 34 */
155 SPD_VAL(0x17, 0x17), /* 35 */
156 SPD_VAL(0x3c, 0x3c), /* 36 */
157 SPD_VAL(0x1e, 0x1e), /* 37 */
158 SPD_VAL(0x1e, 0x1e), /* 38 */
159 SPD_VAL(0x00, 0x00), /* 39 */
160 SPD_VAL(0x00, 0x06), /* 40 */
161 SPD_VAL(0x37, 0x37), /* 41 */
162 SPD_VAL(0x4b, 0x7f), /* 42 */
163 SPD_VAL(0x80, 0x80), /* 43 */
164 SPD_VAL(0x18, 0x18), /* 44 */
165 SPD_VAL(0x22, 0x22), /* 45 */
166 SPD_VAL(0x00, 0x00), /* 46 */
167 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
168 SPD_VAL(0x10, 0x10), /* 62 */
169 SPD_VAL(0x7e, 0x1d), /* 63 */
170 { 'e', 's', 'd', '-', 'g', 'm', 'b', 'h' },
171 SPD_VAL(0x00, 0x00), /* 72 */
172 #ifdef CONFIG_TARGET_CADDY2
173 { "vme-caddy/2 ram " }
174 #else
175 { "vme-cpu/2 ram " }
176 #endif
177 };
178
vme8349_read_spd(uchar chip,uint addr,int alen,uchar * buffer,int len)179 int vme8349_read_spd(uchar chip, uint addr, int alen, uchar *buffer, int len)
180 {
181 int old_bus = i2c_get_bus_num();
182 unsigned int l, sum;
183 int valid = 0;
184
185 i2c_set_bus_num(0);
186
187 if (i2c_read(chip, addr, alen, buffer, len) == 0)
188 if (memcmp(&buffer[64], &default_spd_eeprom.mid[0], 8) == 0) {
189 sum = 0;
190 for (l = 0; l < 63; l++)
191 sum = (sum + buffer[l]) & 0xff;
192 if (sum == buffer[63])
193 valid = 1;
194 else
195 printf("Invalid checksum in EEPROM %02x %02x\n",
196 sum, buffer[63]);
197 }
198
199 if (valid == 0) {
200 memcpy(buffer, (void *)&default_spd_eeprom, len);
201 sum = 0;
202 for (l = 0; l < 63; l++)
203 sum = (sum + buffer[l]) & 0xff;
204 if (sum != buffer[63])
205 printf("Invalid checksum in FLASH %02x %02x\n",
206 sum, buffer[63]);
207 buffer[63] = sum;
208 }
209
210 i2c_set_bus_num(old_bus);
211
212 return 0;
213 }
214