xref: /rk3399_rockchip-uboot/board/freescale/m54455evb/m54455evb.c (revision fc843a02acad62e231a3e779cebd1712688146fc)
18ae158cdSTsiChungLiew /*
28ae158cdSTsiChungLiew  * (C) Copyright 2000-2003
38ae158cdSTsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
48ae158cdSTsiChungLiew  *
5198cafbfSAlison Wang  * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
68ae158cdSTsiChungLiew  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
78ae158cdSTsiChungLiew  *
81a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
98ae158cdSTsiChungLiew  */
108ae158cdSTsiChungLiew 
118ae158cdSTsiChungLiew #include <common.h>
128ae158cdSTsiChungLiew #include <pci.h>
138ae158cdSTsiChungLiew #include <asm/immap.h>
14198cafbfSAlison Wang #include <asm/io.h>
158ae158cdSTsiChungLiew 
168ae158cdSTsiChungLiew DECLARE_GLOBAL_DATA_PTR;
178ae158cdSTsiChungLiew 
checkboard(void)188ae158cdSTsiChungLiew int checkboard(void)
198ae158cdSTsiChungLiew {
208ae158cdSTsiChungLiew 	puts("Board: ");
218ae158cdSTsiChungLiew 	puts("Freescale M54455 EVB\n");
228ae158cdSTsiChungLiew 	return 0;
238ae158cdSTsiChungLiew };
248ae158cdSTsiChungLiew 
dram_init(void)25f1683aa7SSimon Glass int dram_init(void)
268ae158cdSTsiChungLiew {
279f751551STsiChung Liew 	u32 dramsize;
289f751551STsiChung Liew #ifdef CONFIG_CF_SBF
299f751551STsiChung Liew 	/*
309f751551STsiChung Liew 	 * Serial Boot: The dram is already initialized in start.S
319f751551STsiChung Liew 	 * only require to return DRAM size
329f751551STsiChung Liew 	 */
336d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
349f751551STsiChung Liew #else
35198cafbfSAlison Wang 	sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
36198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
379f751551STsiChung Liew 	u32 i;
388ae158cdSTsiChungLiew 
396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
408ae158cdSTsiChungLiew 
418ae158cdSTsiChungLiew 	for (i = 0x13; i < 0x20; i++) {
428ae158cdSTsiChungLiew 		if (dramsize == (1 << i))
438ae158cdSTsiChungLiew 			break;
448ae158cdSTsiChungLiew 	}
458ae158cdSTsiChungLiew 	i--;
468ae158cdSTsiChungLiew 
47198cafbfSAlison Wang 	out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
488ae158cdSTsiChungLiew 
49198cafbfSAlison Wang 	out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
50198cafbfSAlison Wang 	out_be32(&sdram->sdcs1, CONFIG_SYS_SDRAM_BASE1 | i);
518ae158cdSTsiChungLiew 
52198cafbfSAlison Wang 	out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
53198cafbfSAlison Wang 	out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
548ae158cdSTsiChungLiew 
558ae158cdSTsiChungLiew 	/* Issue PALL */
56198cafbfSAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
578ae158cdSTsiChungLiew 
588ae158cdSTsiChungLiew 	/* Issue LEMR */
59198cafbfSAlison Wang 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD | 0x408);
60198cafbfSAlison Wang 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x300);
618ae158cdSTsiChungLiew 
628ae158cdSTsiChungLiew 	udelay(500);
638ae158cdSTsiChungLiew 
648ae158cdSTsiChungLiew 	/* Issue PALL */
65198cafbfSAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
668ae158cdSTsiChungLiew 
678ae158cdSTsiChungLiew 	/* Perform two refresh cycles */
68198cafbfSAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
69198cafbfSAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
708ae158cdSTsiChungLiew 
71198cafbfSAlison Wang 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x200);
728ae158cdSTsiChungLiew 
73198cafbfSAlison Wang 	out_be32(&sdram->sdcr,
74198cafbfSAlison Wang 		(CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00);
758ae158cdSTsiChungLiew 
768ae158cdSTsiChungLiew 	udelay(100);
779f751551STsiChung Liew #endif
78088454cdSSimon Glass 	gd->ram_size = dramsize << 1;
79088454cdSSimon Glass 
80088454cdSSimon Glass 	return 0;
818ae158cdSTsiChungLiew };
828ae158cdSTsiChungLiew 
testdram(void)838ae158cdSTsiChungLiew int testdram(void)
848ae158cdSTsiChungLiew {
858ae158cdSTsiChungLiew 	/* TODO: XXX XXX XXX */
868ae158cdSTsiChungLiew 	printf("DRAM test not implemented!\n");
878ae158cdSTsiChungLiew 
888ae158cdSTsiChungLiew 	return (0);
898ae158cdSTsiChungLiew }
908ae158cdSTsiChungLiew 
91*fc843a02SSimon Glass #if defined(CONFIG_IDE)
928ae158cdSTsiChungLiew #include <ata.h>
938ae158cdSTsiChungLiew 
ide_preinit(void)948ae158cdSTsiChungLiew int ide_preinit(void)
958ae158cdSTsiChungLiew {
96198cafbfSAlison Wang 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
97198cafbfSAlison Wang 	u32 tmp;
988ae158cdSTsiChungLiew 
99198cafbfSAlison Wang 	tmp = (in_8(&gpio->par_fec) & GPIO_PAR_FEC_FEC1_UNMASK) | 0x10;
100198cafbfSAlison Wang 	setbits_8(&gpio->par_fec, tmp);
101198cafbfSAlison Wang 	tmp = ((in_be16(&gpio->par_feci2c) & 0xf0ff) |
102198cafbfSAlison Wang 		(GPIO_PAR_FECI2C_MDC1_ATA_DIOR | GPIO_PAR_FECI2C_MDIO1_ATA_DIOW));
103198cafbfSAlison Wang 	setbits_be16(&gpio->par_feci2c, tmp);
104198cafbfSAlison Wang 
105198cafbfSAlison Wang 	setbits_be16(&gpio->par_ata,
106198cafbfSAlison Wang 		GPIO_PAR_ATA_BUFEN | GPIO_PAR_ATA_CS1 | GPIO_PAR_ATA_CS0 |
107198cafbfSAlison Wang 		GPIO_PAR_ATA_DA2 | GPIO_PAR_ATA_DA1 | GPIO_PAR_ATA_DA0 |
108198cafbfSAlison Wang 		GPIO_PAR_ATA_RESET_RESET | GPIO_PAR_ATA_DMARQ_DMARQ |
1098ae158cdSTsiChungLiew 		GPIO_PAR_ATA_IORDY_IORDY);
110198cafbfSAlison Wang 	setbits_be16(&gpio->par_pci,
111198cafbfSAlison Wang 		GPIO_PAR_PCI_GNT3_ATA_DMACK | GPIO_PAR_PCI_REQ3_ATA_INTRQ);
1128ae158cdSTsiChungLiew 
1138ae158cdSTsiChungLiew 	return (0);
1148ae158cdSTsiChungLiew }
1158ae158cdSTsiChungLiew 
ide_set_reset(int idereset)1168ae158cdSTsiChungLiew void ide_set_reset(int idereset)
1178ae158cdSTsiChungLiew {
118198cafbfSAlison Wang 	atac_t *ata = (atac_t *) MMAP_ATA;
1198ae158cdSTsiChungLiew 	long period;
1208ae158cdSTsiChungLiew 	/*  t1,  t2,  t3,  t4,  t5,  t6,  t9, tRD,  tA */
1218ae158cdSTsiChungLiew 	int piotms[5][9] = {
1228ae158cdSTsiChungLiew 		{70, 165, 60, 30, 50, 5, 20, 0, 35},	/* PIO 0 */
1238ae158cdSTsiChungLiew 		{50, 125, 45, 20, 35, 5, 15, 0, 35},	/* PIO 1 */
1248ae158cdSTsiChungLiew 		{30, 100, 30, 15, 20, 5, 10, 0, 35},	/* PIO 2 */
1258ae158cdSTsiChungLiew 		{30, 80, 30, 10, 20, 5, 10, 0, 35},	/* PIO 3 */
1268ae158cdSTsiChungLiew 		{25, 70, 20, 10, 20, 5, 10, 0, 35}
1278ae158cdSTsiChungLiew 	};			/* PIO 4 */
1288ae158cdSTsiChungLiew 
1298ae158cdSTsiChungLiew 	if (idereset) {
130198cafbfSAlison Wang 		/* control reset */
131198cafbfSAlison Wang 		out_8(&ata->cr, 0);
1328ae158cdSTsiChungLiew 		udelay(10000);
1338ae158cdSTsiChungLiew 	} else {
1348ae158cdSTsiChungLiew #define CALC_TIMING(t) (t + period - 1) / period
1358ae158cdSTsiChungLiew 		period = 1000000000 / gd->bus_clk;	/* period in ns */
1368ae158cdSTsiChungLiew 
1378ae158cdSTsiChungLiew 		/*ata->ton = CALC_TIMING (180); */
138198cafbfSAlison Wang 		out_8(&ata->t1, CALC_TIMING(piotms[2][0]));
139198cafbfSAlison Wang 		out_8(&ata->t2w, CALC_TIMING(piotms[2][1]));
140198cafbfSAlison Wang 		out_8(&ata->t2r, CALC_TIMING(piotms[2][1]));
141198cafbfSAlison Wang 		out_8(&ata->ta, CALC_TIMING(piotms[2][8]));
142198cafbfSAlison Wang 		out_8(&ata->trd, CALC_TIMING(piotms[2][7]));
143198cafbfSAlison Wang 		out_8(&ata->t4, CALC_TIMING(piotms[2][3]));
144198cafbfSAlison Wang 		out_8(&ata->t9, CALC_TIMING(piotms[2][6]));
1458ae158cdSTsiChungLiew 
146198cafbfSAlison Wang 		/* IORDY enable */
147198cafbfSAlison Wang 		out_8(&ata->cr, 0x40);
1488ae158cdSTsiChungLiew 		udelay(200000);
149198cafbfSAlison Wang 		/* IORDY enable */
150198cafbfSAlison Wang 		setbits_8(&ata->cr, 0x01);
1518ae158cdSTsiChungLiew 	}
1528ae158cdSTsiChungLiew }
1538ae158cdSTsiChungLiew #endif
1548ae158cdSTsiChungLiew 
1558ae158cdSTsiChungLiew #if defined(CONFIG_PCI)
1568ae158cdSTsiChungLiew /*
1578ae158cdSTsiChungLiew  * Initialize PCI devices, report devices found.
1588ae158cdSTsiChungLiew  */
1598ae158cdSTsiChungLiew static struct pci_controller hose;
1608ae158cdSTsiChungLiew extern void pci_mcf5445x_init(struct pci_controller *hose);
1618ae158cdSTsiChungLiew 
pci_init_board(void)1628ae158cdSTsiChungLiew void pci_init_board(void)
1638ae158cdSTsiChungLiew {
1648ae158cdSTsiChungLiew 	pci_mcf5445x_init(&hose);
1658ae158cdSTsiChungLiew }
1668ae158cdSTsiChungLiew #endif				/* CONFIG_PCI */
167b2d022d1STsiChung Liew 
168f78ced30STsiChung Liew #if defined(CONFIG_FLASH_CFI_LEGACY)
169b2d022d1STsiChung Liew #include <flash.h>
board_flash_get_legacy(ulong base,int banknum,flash_info_t * info)170b2d022d1STsiChung Liew ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
171b2d022d1STsiChung Liew {
1726d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	int sect[] = CONFIG_SYS_ATMEL_SECT;
1736d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	int sectsz[] = CONFIG_SYS_ATMEL_SECTSZ;
174b2d022d1STsiChung Liew 	int i, j, k;
175b2d022d1STsiChung Liew 
1766d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	if (base != CONFIG_SYS_ATMEL_BASE)
177b2d022d1STsiChung Liew 		return 0;
178b2d022d1STsiChung Liew 
179b2d022d1STsiChung Liew 	info->flash_id          = 0x01000000;
180b2d022d1STsiChung Liew 	info->portwidth         = 1;
181b2d022d1STsiChung Liew 	info->chipwidth         = 1;
1829d3a86aeSTsiChung Liew 	info->buffer_size       = 1;
183b2d022d1STsiChung Liew 	info->erase_blk_tout    = 16384;
184b2d022d1STsiChung Liew 	info->write_tout        = 2;
185b2d022d1STsiChung Liew 	info->buffer_write_tout = 5;
186f78ced30STsiChung Liew 	info->vendor            = 0xFFF0; /* CFI_CMDSET_AMD_LEGACY */
187b2d022d1STsiChung Liew 	info->cmd_reset         = 0x00F0;
188b2d022d1STsiChung Liew 	info->interface         = FLASH_CFI_X8;
189b2d022d1STsiChung Liew 	info->legacy_unlock     = 0;
190b2d022d1STsiChung Liew 	info->manufacturer_id   = (u16) ATM_MANUFACT;
191b2d022d1STsiChung Liew 	info->device_id         = ATM_ID_LV040;
192b2d022d1STsiChung Liew 	info->device_id2        = 0;
193b2d022d1STsiChung Liew 
194b2d022d1STsiChung Liew 	info->ext_addr          = 0;
195b2d022d1STsiChung Liew 	info->cfi_version       = 0x3133;
196f78ced30STsiChung Liew 	info->cfi_offset        = 0x0000;
197b2d022d1STsiChung Liew 	info->addr_unlock1      = 0x00000555;
198b2d022d1STsiChung Liew 	info->addr_unlock2      = 0x000002AA;
199b2d022d1STsiChung Liew 	info->name              = "CFI conformant";
200b2d022d1STsiChung Liew 
201b2d022d1STsiChung Liew 	info->size              = 0;
2026d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	info->sector_count      = CONFIG_SYS_ATMEL_TOTALSECT;
203b2d022d1STsiChung Liew 	info->start[0] = base;
2046d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	for (k = 0, i = 0; i < CONFIG_SYS_ATMEL_REGION; i++) {
205b2d022d1STsiChung Liew 		info->size += sect[i] * sectsz[i];
206b2d022d1STsiChung Liew 
207b2d022d1STsiChung Liew 		for (j = 0; j < sect[i]; j++, k++) {
208b2d022d1STsiChung Liew 			info->start[k + 1] = info->start[k] + sectsz[i];
209b2d022d1STsiChung Liew 			info->protect[k] = 0;
210b2d022d1STsiChung Liew 		}
211b2d022d1STsiChung Liew 	}
212b2d022d1STsiChung Liew 
213b2d022d1STsiChung Liew 	return 1;
214b2d022d1STsiChung Liew }
2156d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #endif				/* CONFIG_SYS_FLASH_CFI */
216