2 * Partially derived from board code for digsyMTC,
4 * Grzegorz Bernacki, Semihalf, gjb@semihalf.com
7 * DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
9 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/processor.h>
17 #include <fdt_support.h>
23 DECLARE_GLOBAL_DATA_PTR
;
25 #define SDRAM_MODE 0x00CD0000
26 #define SDRAM_CONTROL 0x504F0000
27 #define SDRAM_CONFIG1 0xD2322800
28 #define SDRAM_CONFIG2 0x8AD70000
30 enum 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 */
38 static enum ifm_sensor_type gt_ifm_sensor_type
;
40 #ifndef CONFIG_SYS_RAMBOOT
41 static void sdram_start(int hi_addr
)
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
;
47 /* unlock mode register */
48 out_be32(&sdram
->ctrl
, control
| 0x80000000);
50 /* precharge all banks */
51 out_be32(&sdram
->ctrl
, control
| 0x80000002);
54 out_be32(&sdram
->ctrl
, control
| 0x80000004);
56 /* set mode register */
57 out_be32(&sdram
->mode
, SDRAM_MODE
);
59 /* normal operation */
60 out_be32(&sdram
->ctrl
, control
);
65 * ATTENTION: Although partially referenced dram_init 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.
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
;
78 if (gt_ifm_sensor_type
== O2DNT2
) {
79 /* activate SDRAM CS1 */
80 setbits_be32((void *)MPC5XXX_GPS_PORT_CONFIG
, 0x80000000);
83 #ifndef CONFIG_SYS_RAMBOOT
86 /* setup SDRAM chip selects */
87 out_be32(&mmap_ctl
->sdram0
, 0x0000001E); /* 2 GB at 0x0 */
88 out_be32(&mmap_ctl
->sdram1
, 0x00000000); /* disabled */
90 /* setup config registers */
91 out_be32(&sdram
->config1
, SDRAM_CONFIG1
);
92 out_be32(&sdram
->config2
, SDRAM_CONFIG2
);
94 /* find RAM size using SDRAM CS0 only */
96 test1
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, 0x08000000);
98 test2
= get_ram_size((long *)CONFIG_SYS_SDRAM_BASE
, 0x08000000);
106 /* memory smaller than 1MB is impossible */
107 if (dramsize
< (1 << 20))
110 /* set SDRAM CS0 size according to the amount of RAM found */
112 out_be32(&mmap_ctl
->sdram0
,
113 (0x13 + __builtin_ffs(dramsize
>> 20) - 1));
115 out_be32(&mmap_ctl
->sdram0
, 0); /* disabled */
118 /* let SDRAM CS1 start right after CS0 */
119 out_be32(&mmap_ctl
->sdram1
, dramsize
+ 0x0000001E); /* 2G */
121 /* find RAM size using SDRAM CS1 only */
125 test2
= test1
= get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE
+ dramsize
),
129 test2
= get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE
+ dramsize
),
140 /* memory smaller than 1MB is impossible */
141 if (dramsize2
< (1 << 20))
144 /* set SDRAM CS1 size according to the amount of RAM found */
146 out_be32(&mmap_ctl
->sdram1
, (dramsize
|
147 (0x13 + __builtin_ffs(dramsize2
>> 20) - 1)));
149 out_be32(&mmap_ctl
->sdram1
, dramsize
); /* disabled */
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;
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;
167 #endif /* CONFIG_SYS_RAMBOOT */
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:
174 * "The SDelay should be written to a value of 0x00000004. It is
175 * required to account for changes caused by normal wafer processing
180 if ((SVR_MJREV(svr
) >= 2) &&
181 (PVR_MAJ(pvr
) == 1) && (PVR_MIN(pvr
) == 4))
182 out_be32(&sdram
->sdelay
, 0x04);
184 gd
->ram_size
= dramsize
+ dramsize2
;
190 #define GPT_GPIO_IN 0x4
194 struct mpc5xxx_gpt
*gpt
= (struct mpc5xxx_gpt
*)MPC5XXX_GPT
;
195 unsigned char board_config
= 0;
198 /* switch gpt0 - gpt7 to input */
199 for (i
= 0; i
< 7; i
++)
200 out_be32(&gpt
[i
].emsr
, GPT_GPIO_IN
);
202 /* get configuration byte on timer-port */
203 for (i
= 0; i
< 7; i
++)
204 board_config
|= (in_be32(&gpt
[i
].sr
) & 0x100) >> (8 - i
);
208 switch (board_config
) {
211 gt_ifm_sensor_type
= O2DNT
;
215 gt_ifm_sensor_type
= O3DNT
;
219 gt_ifm_sensor_type
= O2DNT2
;
222 puts("O3DNT Minerva\n");
223 gt_ifm_sensor_type
= O3DNT_MIN
;
227 gt_ifm_sensor_type
= UNKNOWN
;
234 int board_early_init_r(void)
236 struct mpc5xxx_lpb
*lpb_regs
= (struct mpc5xxx_lpb
*)MPC5XXX_LPB
;
239 * Now, when we are in RAM, enable flash write access for detection
240 * process. Note that CS_BOOT cannot be cleared when executing in flash.
242 clrbits_be32(&lpb_regs
->cs0_cfg
, 1); /* clear RO */
243 /* disable CS_BOOT */
244 clrbits_be32((void *)MPC5XXX_ADDECR
, (1 << 25));
246 setbits_be32((void *)MPC5XXX_ADDECR
, (1 << 16));
251 #define MIIM_LXT971_LED_CFG_REG 0x14
252 #define LXT971_LED_CFG_LINK_STATUS 0x4000
253 #define LXT971_LED_CFG_RX_TX_ACTIVITY 0x0700
254 #define LXT971_LED_CFG_LINK_ACTIVITY 0x00D0
255 #define LXT971_LED_CFG_PULSE_STRETCH 0x0002
257 * Additional PHY intialization after reset in mpc5xxx_fec_init_phy()
262 * Set LED configuration bits.
263 * It can't be done in misc_init_r() since FEC is not
264 * initialized at this time. Therefore we do it here.
266 miiphy_write("FEC", CONFIG_PHY_ADDR
, MIIM_LXT971_LED_CFG_REG
,
267 LXT971_LED_CFG_LINK_STATUS
|
268 LXT971_LED_CFG_RX_TX_ACTIVITY
|
269 LXT971_LED_CFG_LINK_ACTIVITY
|
270 LXT971_LED_CFG_PULSE_STRETCH
);
273 #if defined(CONFIG_POST)
275 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
276 * is left open, no keypress is detected.
278 int post_hotkeys_pressed(void)
280 struct mpc5xxx_gpio
*gpio
= (struct mpc5xxx_gpio
*) MPC5XXX_GPIO
;
283 * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
284 * CODEC or UART mode. Consumer IrDA should still be possible.
286 clrbits_be32(&gpio
->port_config
, 0x07000000);
287 setbits_be32(&gpio
->port_config
, 0x03000000);
289 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
290 setbits_be32(&gpio
->simple_gpioe
, 0x20000000);
292 /* Configure GPIO_IRDA_1 as input */
293 clrbits_be32(&gpio
->simple_ddr
, 0x20000000);
295 return (in_be32(&gpio
->simple_ival
) & 0x20000000) ? 0 : 1;
300 static struct pci_controller hose
;
302 void pci_init_board(void)
304 pci_mpc5xxx_init(&hose
);
308 #ifdef CONFIG_OF_BOARD_SETUP
309 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
310 static void ft_adapt_flash_base(void *blob
)
312 flash_info_t
*dev
= &flash_info
[0];
314 struct fdt_property
*prop
;
318 off
= fdt_node_offset_by_compatible(blob
, -1, "fsl,mpc5200b-lpb");
320 printf("Could not find fsl,mpc5200b-lpb node.\n");
324 /* found compatible property */
325 prop
= fdt_get_property_w(blob
, off
, "ranges", &len
);
327 reg
= reg2
= (u32
*)&prop
->data
[0];
329 reg
[2] = dev
->start
[0];
331 fdt_setprop(blob
, off
, "ranges", reg2
, len
);
333 printf("Could not find ranges\n");
336 extern ulong
flash_get_size(phys_addr_t base
, int banknum
);
338 /* Update the flash baseaddr settings */
339 int update_flash_size(int flash_size
)
341 struct mpc5xxx_mmap_ctl
*mm
=
342 (struct mpc5xxx_mmap_ctl
*) CONFIG_SYS_MBAR
;
346 unsigned long base
= 0x0;
347 u32
*cs_reg
= (u32
*)&mm
->cs0_start
;
349 for (i
= 0; i
< 2; i
++) {
350 dev
= &flash_info
[i
];
353 /* calculate new base addr for this chipselect */
355 out_be32(cs_reg
, START_REG(base
));
357 out_be32(cs_reg
, STOP_REG(base
, dev
->size
));
359 /* recalculate the sectoraddr in the cfi driver */
360 size
+= flash_get_size(base
, i
);
363 flash_protect_default();
364 gd
->bd
->bi_flashstart
= base
;
367 #endif /* defined(CONFIG_SYS_UPDATE_FLASH_SIZE) */
369 int ft_board_setup(void *blob
, bd_t
*bd
)
371 int phy_addr
= CONFIG_PHY_ADDR
;
372 char eth_path
[] = "/soc5200@f0000000/mdio@3000/ethernet-phy@0";
374 ft_cpu_setup(blob
, bd
);
376 #if defined(CONFIG_SYS_UPDATE_FLASH_SIZE)
377 #ifdef CONFIG_FDT_FIXUP_NOR_FLASH_SIZE
378 /* Update reg property in all nor flash nodes too */
379 fdt_fixup_nor_flash_size(blob
);
381 ft_adapt_flash_base(blob
);
383 /* fix up the phy address */
384 do_fixup_by_path(blob
, eth_path
, "reg", &phy_addr
, sizeof(int), 0);
388 #endif /* CONFIG_OF_BOARD_SETUP */