blob: ca09767d287b6b366033c39d5d3d13862ea4405f [file] [log] [blame]
Anatolij Gustschin4387cf12012-08-31 01:29:57 +00001/*
2 * Partially derived from board code for digsyMTC,
3 * (C) Copyright 2009
4 * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
5 *
6 * (C) Copyright 2012
7 * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Anatolij Gustschin4387cf12012-08-31 01:29:57 +000010 */
11
12#include <common.h>
13#include <mpc5xxx.h>
14#include <asm/processor.h>
15#include <asm/io.h>
16#include <libfdt.h>
17#include <fdt_support.h>
18#include <i2c.h>
19#include <miiphy.h>
20#include <net.h>
21#include <pci.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define SDRAM_MODE 0x00CD0000
26#define SDRAM_CONTROL 0x504F0000
27#define SDRAM_CONFIG1 0xD2322800
28#define SDRAM_CONFIG2 0x8AD70000
29
30enum ifm_sensor_type {
31 O2DNT = 0x00, /* !< O2DNT 32MB */
32 O2DNT2 = 0x01, /* !< O2DNT2 64MB */
33 O3DNT = 0x02, /* !< O3DNT 32MB */
34 O3DNT_MIN = 0x40, /* !< O3DNT Minerva 32MB */
35 UNKNOWN = 0xff, /* !< Unknow sensor */
36};
37
38static enum ifm_sensor_type gt_ifm_sensor_type;
39
40#ifndef CONFIG_SYS_RAMBOOT
41static void sdram_start(int hi_addr)
42{
43 struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
44 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
45 long control = SDRAM_CONTROL | hi_addr_bit;
46
47 /* unlock mode register */
48 out_be32(&sdram->ctrl, control | 0x80000000);
49
50 /* precharge all banks */
51 out_be32(&sdram->ctrl, control | 0x80000002);
52
53 /* auto refresh */
54 out_be32(&sdram->ctrl, control | 0x80000004);
55
56 /* set mode register */
57 out_be32(&sdram->mode, SDRAM_MODE);
58
59 /* normal operation */
60 out_be32(&sdram->ctrl, control);
61}
62#endif
63
64/*
65 * ATTENTION: Although partially referenced initdram does NOT make real use
66 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if
67 * CONFIG_SYS_SDRAM_BASE is something else than 0x00000000.
68 */
69phys_size_t initdram(int board_type)
70{
71 struct mpc5xxx_mmap_ctl *mmap_ctl =
72 (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
73 struct mpc5xxx_sdram *sdram = (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
74 ulong dramsize = 0;
75 ulong dramsize2 = 0;
76 uint svr, pvr;
77
78 if (gt_ifm_sensor_type == O2DNT2) {
79 /* activate SDRAM CS1 */
80 setbits_be32((void *)MPC5XXX_GPS_PORT_CONFIG, 0x80000000);
81 }
82
83#ifndef CONFIG_SYS_RAMBOOT
84 ulong test1, test2;
85
86 /* setup SDRAM chip selects */
87 out_be32(&mmap_ctl->sdram0, 0x0000001E); /* 2 GB at 0x0 */
88 out_be32(&mmap_ctl->sdram1, 0x00000000); /* disabled */
89
90 /* setup config registers */
91 out_be32(&sdram->config1, SDRAM_CONFIG1);
92 out_be32(&sdram->config2, SDRAM_CONFIG2);
93
94 /* find RAM size using SDRAM CS0 only */
95 sdram_start(0);
96 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
97 sdram_start(1);
98 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x08000000);
99 if (test1 > test2) {
100 sdram_start(0);
101 dramsize = test1;
102 } else {
103 dramsize = test2;
104 }
105
106 /* memory smaller than 1MB is impossible */
107 if (dramsize < (1 << 20))
108 dramsize = 0;
109
110 /* set SDRAM CS0 size according to the amount of RAM found */
111 if (dramsize > 0) {
112 out_be32(&mmap_ctl->sdram0,
113 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
114 } else {
115 out_be32(&mmap_ctl->sdram0, 0); /* disabled */
116 }
117
118 /* let SDRAM CS1 start right after CS0 */
119 out_be32(&mmap_ctl->sdram1, dramsize + 0x0000001E); /* 2G */
120
121 /* find RAM size using SDRAM CS1 only */
122 if (!dramsize)
123 sdram_start(0);
124
125 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
126 0x80000000);
127 if (!dramsize) {
128 sdram_start(1);
129 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize),
130 0x80000000);
131 }
132
133 if (test1 > test2) {
134 sdram_start(0);
135 dramsize2 = test1;
136 } else {
137 dramsize2 = test2;
138 }
139
140 /* memory smaller than 1MB is impossible */
141 if (dramsize2 < (1 << 20))
142 dramsize2 = 0;
143
144 /* set SDRAM CS1 size according to the amount of RAM found */
145 if (dramsize2 > 0) {
146 out_be32(&mmap_ctl->sdram1, (dramsize |
147 (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
148 } else {
149 out_be32(&mmap_ctl->sdram1, dramsize); /* disabled */
150 }
151
152#else /* CONFIG_SYS_RAMBOOT */
153 /* retrieve size of memory connected to SDRAM CS0 */
154 dramsize = in_be32(&mmap_ctl->sdram0) & 0xFF;
155 if (dramsize >= 0x13)
156 dramsize = (1 << (dramsize - 0x13)) << 20;
157 else
158 dramsize = 0;
159
160 /* retrieve size of memory connected to SDRAM CS1 */
161 dramsize2 = in_be32(&mmap_ctl->sdram1) & 0xFF;
162 if (dramsize2 >= 0x13)
163 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
164 else
165 dramsize2 = 0;
166
167#endif /* CONFIG_SYS_RAMBOOT */
168
169 /*
170 * On MPC5200B we need to set the special configuration delay in the
171 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
172 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
173 *
174 * "The SDelay should be written to a value of 0x00000004. It is
175 * required to account for changes caused by normal wafer processing
176 * parameters."
177 */
178 svr = get_svr();
179 pvr = get_pvr();
180 if ((SVR_MJREV(svr) >= 2) &&
181 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4))
182 out_be32(&sdram->sdelay, 0x04);
183
184 return dramsize + dramsize2;
185}
186
187
188#define GPT_GPIO_IN 0x4
189
190int checkboard(void)
191{
192 struct mpc5xxx_gpt *gpt = (struct mpc5xxx_gpt *)MPC5XXX_GPT;
193 unsigned char board_config = 0;
194 int i;
195
196 /* switch gpt0 - gpt7 to input */
197 for (i = 0; i < 7; i++)
198 out_be32(&gpt[i].emsr, GPT_GPIO_IN);
199
200 /* get configuration byte on timer-port */
201 for (i = 0; i < 7; i++)
202 board_config |= (in_be32(&gpt[i].sr) & 0x100) >> (8 - i);
203
204 puts("Board: ");
205
206 switch (board_config) {
207 case 0:
208 puts("O2DNT\n");
209 gt_ifm_sensor_type = O2DNT;
210 break;
211 case 1:
212 puts("O3DNT\n");
213 gt_ifm_sensor_type = O3DNT;
214 break;
215 case 2:
216 puts("O2DNT2\n");
217 gt_ifm_sensor_type = O2DNT2;
218 break;
219 case 64:
220 puts("O3DNT Minerva\n");
221 gt_ifm_sensor_type = O3DNT_MIN;
222 break;
223 default:
224 puts("Unknown\n");
225 gt_ifm_sensor_type = UNKNOWN;
226 break;
227 }
228
229 return 0;
230}
231
232int board_early_init_r(void)
233{
234 struct mpc5xxx_lpb *lpb_regs = (struct mpc5xxx_lpb *)MPC5XXX_LPB;
235
236 /*
237 * Now, when we are in RAM, enable flash write access for detection
238 * process. Note that CS_BOOT cannot be cleared when executing in flash.
239 */
240 clrbits_be32(&lpb_regs->cs0_cfg, 1); /* clear RO */
241 /* disable CS_BOOT */
242 clrbits_be32((void *)MPC5XXX_ADDECR, (1 << 25));
243 /* enable CS0 */
244 setbits_be32((void *)MPC5XXX_ADDECR, (1 << 16));
245
246 return 0;
247}
248
249#define MIIM_LXT971_LED_CFG_REG 0x14
250#define LXT971_LED_CFG_LINK_STATUS 0x4000
251#define LXT971_LED_CFG_RX_TX_ACTIVITY 0x0700
252#define LXT971_LED_CFG_LINK_ACTIVITY 0x00D0
253#define LXT971_LED_CFG_PULSE_STRETCH 0x0002
254/*
255 * Additional PHY intialization after reset in mpc5xxx_fec_init_phy()
256 */
257void reset_phy(void)
258{
259 /*
260 * Set LED configuration bits.
261 * It can't be done in misc_init_r() since FEC is not
262 * initialized at this time. Therefore we do it here.
263 */
264 miiphy_write("FEC", CONFIG_PHY_ADDR, MIIM_LXT971_LED_CFG_REG,
265 LXT971_LED_CFG_LINK_STATUS |
266 LXT971_LED_CFG_RX_TX_ACTIVITY |
267 LXT971_LED_CFG_LINK_ACTIVITY |
268 LXT971_LED_CFG_PULSE_STRETCH);
269}
270
271#if defined(CONFIG_POST)
272/*
273 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
274 * is left open, no keypress is detected.
275 */
276int post_hotkeys_pressed(void)
277{
278 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
279
280 /*
281 * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
282 * CODEC or UART mode. Consumer IrDA should still be possible.
283 */
284 clrbits_be32(&gpio->port_config, 0x07000000);
285 setbits_be32(&gpio->port_config, 0x03000000);
286
287 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
288 setbits_be32(&gpio->simple_gpioe, 0x20000000);
289
290 /* Configure GPIO_IRDA_1 as input */
291 clrbits_be32(&gpio->simple_ddr, 0x20000000);
292
293 return (in_be32(&gpio->simple_ival) & 0x20000000) ? 0 : 1;
294}
295#endif
296
297#ifdef CONFIG_PCI
298static struct pci_controller hose;
299
300void pci_init_board(void)
301{
302 pci_mpc5xxx_init(&hose);
303}
304#endif
305
306#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
307#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
308static void ft_adapt_flash_base(void *blob)
309{
310 flash_info_t *dev = &flash_info[0];
311 int off;
312 struct fdt_property *prop;
313 int len;
314 u32 *reg, *reg2;
315
316 off = fdt_node_offset_by_compatible(blob, -1, "fsl,mpc5200b-lpb");
317 if (off < 0) {
318 printf("Could not find fsl,mpc5200b-lpb node.\n");
319 return;
320 }
321
322 /* found compatible property */
323 prop = fdt_get_property_w(blob, off, "ranges", &len);
324 if (prop) {
325 reg = reg2 = (u32 *)&prop->data[0];
326
327 reg[2] = dev->start[0];
328 reg[3] = dev->size;
329 fdt_setprop(blob, off, "ranges", reg2, len);
330 } else
331 printf("Could not find ranges\n");
332}
333
334extern ulong flash_get_size(phys_addr_t base, int banknum);
335
336/* Update the flash baseaddr settings */
337int update_flash_size(int flash_size)
338{
339 struct mpc5xxx_mmap_ctl *mm =
340 (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
341 flash_info_t *dev;
342 int i;
343 int size = 0;
344 unsigned long base = 0x0;
345 u32 *cs_reg = (u32 *)&mm->cs0_start;
346
347 for (i = 0; i < 2; i++) {
348 dev = &flash_info[i];
349
350 if (dev->size) {
351 /* calculate new base addr for this chipselect */
352 base -= dev->size;
353 out_be32(cs_reg, START_REG(base));
354 cs_reg++;
355 out_be32(cs_reg, STOP_REG(base, dev->size));
356 cs_reg++;
357 /* recalculate the sectoraddr in the cfi driver */
358 size += flash_get_size(base, i);
359 }
360 }
361 flash_protect_default();
362 gd->bd->bi_flashstart = base;
363 return 0;
364}
365#endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
366
Simon Glasse895a4b2014-10-23 18:58:47 -0600367int ft_board_setup(void *blob, bd_t *bd)
Anatolij Gustschin4387cf12012-08-31 01:29:57 +0000368{
369 int phy_addr = CONFIG_PHY_ADDR;
370 char eth_path[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
371
372 ft_cpu_setup(blob, bd);
373
374#if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
375#ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
376 /* Update reg property in all nor flash nodes too */
377 fdt_fixup_nor_flash_size(blob);
378#endif
379 ft_adapt_flash_base(blob);
380#endif
381 /* fix up the phy address */
382 do_fixup_by_path(blob, eth_path, "reg", &phy_addr, sizeof(int), 0);
Simon Glasse895a4b2014-10-23 18:58:47 -0600383
384 return 0;
Anatolij Gustschin4387cf12012-08-31 01:29:57 +0000385}
386#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */