xref: /rk3399_rockchip-uboot/board/sysam/amcore/amcore.c (revision f1683aa73c31db0a025e0254e6ce1ee7e56aad3e)
106fd66a4Sangelo@sysam.it /*
206fd66a4Sangelo@sysam.it  * Board functions for Sysam AMCORE (MCF5307 based) board
306fd66a4Sangelo@sysam.it  *
418c9b10cSAngelo Dureghello  * (C) Copyright 2016  Angelo Dureghello <angelo@sysam.it>
506fd66a4Sangelo@sysam.it  *
606fd66a4Sangelo@sysam.it  * SPDX-License-Identifier:     GPL-2.0+
706fd66a4Sangelo@sysam.it  *
806fd66a4Sangelo@sysam.it  * This file copies memory testdram() from sandburst/common/sb_common.c
906fd66a4Sangelo@sysam.it  */
1006fd66a4Sangelo@sysam.it 
1106fd66a4Sangelo@sysam.it #include <common.h>
1206fd66a4Sangelo@sysam.it #include <asm/immap.h>
1306fd66a4Sangelo@sysam.it #include <asm/io.h>
1418c9b10cSAngelo Dureghello #include <dm.h>
1518c9b10cSAngelo Dureghello #include <dm/platform_data/serial_coldfire.h>
1606fd66a4Sangelo@sysam.it 
17088454cdSSimon Glass DECLARE_GLOBAL_DATA_PTR;
18088454cdSSimon Glass 
init_lcd(void)1906fd66a4Sangelo@sysam.it void init_lcd(void)
2006fd66a4Sangelo@sysam.it {
2106fd66a4Sangelo@sysam.it 	/* setup for possible K0108 lcd connected on the parallel port */
2206fd66a4Sangelo@sysam.it 	sim_t *sim = (sim_t *)(MMAP_SIM);
2306fd66a4Sangelo@sysam.it 
2406fd66a4Sangelo@sysam.it 	out_be16(&sim->par, 0x300);
2506fd66a4Sangelo@sysam.it 
2606fd66a4Sangelo@sysam.it 	gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
2706fd66a4Sangelo@sysam.it 
2806fd66a4Sangelo@sysam.it 	out_be16(&gpio->paddr, 0xfcff);
2906fd66a4Sangelo@sysam.it 	out_be16(&gpio->padat, 0x0c00);
3006fd66a4Sangelo@sysam.it }
3106fd66a4Sangelo@sysam.it 
checkboard(void)3206fd66a4Sangelo@sysam.it int checkboard(void)
3306fd66a4Sangelo@sysam.it {
3406fd66a4Sangelo@sysam.it 	puts("Board: ");
3506fd66a4Sangelo@sysam.it 	puts("AMCORE v.001(alpha)\n");
3606fd66a4Sangelo@sysam.it 
3706fd66a4Sangelo@sysam.it 	init_lcd();
3806fd66a4Sangelo@sysam.it 
3906fd66a4Sangelo@sysam.it 	return 0;
4006fd66a4Sangelo@sysam.it }
4106fd66a4Sangelo@sysam.it 
4206fd66a4Sangelo@sysam.it /*
43*f1683aa7SSimon Glass  * in dram_init we are here executing from flash
4406fd66a4Sangelo@sysam.it  * case 1:
4506fd66a4Sangelo@sysam.it  * is with no ACR/flash cache enabled
4606fd66a4Sangelo@sysam.it  * nop = 40ns (scope measured)
4706fd66a4Sangelo@sysam.it  */
fudelay(int usec)4806fd66a4Sangelo@sysam.it void fudelay(int usec)
4906fd66a4Sangelo@sysam.it {
5006fd66a4Sangelo@sysam.it 	while (usec--)
5106fd66a4Sangelo@sysam.it 		asm volatile ("nop");
5206fd66a4Sangelo@sysam.it }
5306fd66a4Sangelo@sysam.it 
dram_init(void)54*f1683aa7SSimon Glass int dram_init(void)
5506fd66a4Sangelo@sysam.it {
5606fd66a4Sangelo@sysam.it 	u32 dramsize, RC;
5706fd66a4Sangelo@sysam.it 
5806fd66a4Sangelo@sysam.it 	sdramctrl_t *dc = (sdramctrl_t *)(MMAP_DRAMC);
5906fd66a4Sangelo@sysam.it 
6006fd66a4Sangelo@sysam.it 	/*
6106fd66a4Sangelo@sysam.it 	 * SDRAM  MT48LC4M32B2 details
6206fd66a4Sangelo@sysam.it 	 * Memory block 0: 16 MB of SDRAM at address $00000000
6306fd66a4Sangelo@sysam.it 	 * Port size: 32-bit port
6406fd66a4Sangelo@sysam.it 	 *
6506fd66a4Sangelo@sysam.it 	 * Memory block 0 wired as follows:
6606fd66a4Sangelo@sysam.it 	 * CPU   : A15 A14 A13 A12 A11 A10 A9 A17 A18 A19 A20 A21 A22 A23
6706fd66a4Sangelo@sysam.it 	 * SDRAM :  A0  A1  A2  A3  A4  A5  A6 A7  A8  A9 A10 A11 BA0 BA1
6806fd66a4Sangelo@sysam.it 	 *
6906fd66a4Sangelo@sysam.it 	 * Ensure that there is a delay of at least 100 microseconds from
7006fd66a4Sangelo@sysam.it 	 * processor reset to the following code so that the SDRAM is ready
7106fd66a4Sangelo@sysam.it 	 * for commands.
7206fd66a4Sangelo@sysam.it 	 */
7306fd66a4Sangelo@sysam.it 	fudelay(100);
7406fd66a4Sangelo@sysam.it 
7506fd66a4Sangelo@sysam.it 	/*
7606fd66a4Sangelo@sysam.it 	 * DCR
7706fd66a4Sangelo@sysam.it 	 * set proper  RC as per specification
7806fd66a4Sangelo@sysam.it 	 */
7906fd66a4Sangelo@sysam.it 	RC = (CONFIG_SYS_CPU_CLK / 1000000) >> 1;
8006fd66a4Sangelo@sysam.it 	RC = (RC * 15) >> 4;
8106fd66a4Sangelo@sysam.it 
8206fd66a4Sangelo@sysam.it 	/* 0x8000 is the faster option */
8306fd66a4Sangelo@sysam.it 	out_be16(&dc->dcr, 0x8200 | RC);
8406fd66a4Sangelo@sysam.it 
8506fd66a4Sangelo@sysam.it 	/*
8606fd66a4Sangelo@sysam.it 	 * DACR0, page mode continuous, CMD on A20 0x0300
8706fd66a4Sangelo@sysam.it 	 */
8806fd66a4Sangelo@sysam.it 	out_be32(&dc->dacr0, 0x00003304);
8906fd66a4Sangelo@sysam.it 
9006fd66a4Sangelo@sysam.it 	dramsize = ((CONFIG_SYS_SDRAM_SIZE)-1) & 0xfffc0000;
9106fd66a4Sangelo@sysam.it 	out_be32(&dc->dmr0,  dramsize|1);
9206fd66a4Sangelo@sysam.it 
9306fd66a4Sangelo@sysam.it 	/* issue a PRECHARGE ALL */
9406fd66a4Sangelo@sysam.it 	out_be32(&dc->dacr0, 0x0000330c);
9506fd66a4Sangelo@sysam.it 	out_be32((u32 *)0x00000004, 0xbeaddeed);
9606fd66a4Sangelo@sysam.it 	/* issue AUTOREFRESH */
9706fd66a4Sangelo@sysam.it 	out_be32(&dc->dacr0, 0x0000b304);
9882bd2f29SVagrant Cascadian 	/* let refresh occur */
9906fd66a4Sangelo@sysam.it 	fudelay(1);
10006fd66a4Sangelo@sysam.it 
10106fd66a4Sangelo@sysam.it 	out_be32(&dc->dacr0, 0x0000b344);
10206fd66a4Sangelo@sysam.it 	out_be32((u32 *)0x00000c00, 0xbeaddeed);
10306fd66a4Sangelo@sysam.it 
104088454cdSSimon Glass 	gd->ram_size = get_ram_size(CONFIG_SYS_SDRAM_BASE,
105088454cdSSimon Glass 				    CONFIG_SYS_SDRAM_SIZE);
106088454cdSSimon Glass 
107088454cdSSimon Glass 	return 0;
10806fd66a4Sangelo@sysam.it }
10918c9b10cSAngelo Dureghello 
11018c9b10cSAngelo Dureghello static struct coldfire_serial_platdata mcf5307_serial_plat = {
11118c9b10cSAngelo Dureghello 	.base = CONFIG_SYS_UART_BASE,
11218c9b10cSAngelo Dureghello 	.port = 0,
11318c9b10cSAngelo Dureghello 	.baudrate = CONFIG_BAUDRATE,
11418c9b10cSAngelo Dureghello };
11518c9b10cSAngelo Dureghello 
11618c9b10cSAngelo Dureghello U_BOOT_DEVICE(coldfire_serial) = {
11718c9b10cSAngelo Dureghello 	.name = "serial_coldfire",
11818c9b10cSAngelo Dureghello 	.platdata = &mcf5307_serial_plat,
11918c9b10cSAngelo Dureghello };
120