xref: /OK3568_Linux_fs/u-boot/board/freescale/m54455evb/m54455evb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2000-2003
3*4882a593Smuzhiyun  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
6*4882a593Smuzhiyun  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
9*4882a593Smuzhiyun  */
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <common.h>
12*4882a593Smuzhiyun #include <pci.h>
13*4882a593Smuzhiyun #include <asm/immap.h>
14*4882a593Smuzhiyun #include <asm/io.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
17*4882a593Smuzhiyun 
checkboard(void)18*4882a593Smuzhiyun int checkboard(void)
19*4882a593Smuzhiyun {
20*4882a593Smuzhiyun 	puts("Board: ");
21*4882a593Smuzhiyun 	puts("Freescale M54455 EVB\n");
22*4882a593Smuzhiyun 	return 0;
23*4882a593Smuzhiyun };
24*4882a593Smuzhiyun 
dram_init(void)25*4882a593Smuzhiyun int dram_init(void)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun 	u32 dramsize;
28*4882a593Smuzhiyun #ifdef CONFIG_CF_SBF
29*4882a593Smuzhiyun 	/*
30*4882a593Smuzhiyun 	 * Serial Boot: The dram is already initialized in start.S
31*4882a593Smuzhiyun 	 * only require to return DRAM size
32*4882a593Smuzhiyun 	 */
33*4882a593Smuzhiyun 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
34*4882a593Smuzhiyun #else
35*4882a593Smuzhiyun 	sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
36*4882a593Smuzhiyun 	gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
37*4882a593Smuzhiyun 	u32 i;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	for (i = 0x13; i < 0x20; i++) {
42*4882a593Smuzhiyun 		if (dramsize == (1 << i))
43*4882a593Smuzhiyun 			break;
44*4882a593Smuzhiyun 	}
45*4882a593Smuzhiyun 	i--;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 	out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
50*4882a593Smuzhiyun 	out_be32(&sdram->sdcs1, CONFIG_SYS_SDRAM_BASE1 | i);
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
53*4882a593Smuzhiyun 	out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	/* Issue PALL */
56*4882a593Smuzhiyun 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/* Issue LEMR */
59*4882a593Smuzhiyun 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD | 0x408);
60*4882a593Smuzhiyun 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x300);
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	udelay(500);
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	/* Issue PALL */
65*4882a593Smuzhiyun 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	/* Perform two refresh cycles */
68*4882a593Smuzhiyun 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
69*4882a593Smuzhiyun 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x200);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun 	out_be32(&sdram->sdcr,
74*4882a593Smuzhiyun 		(CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	udelay(100);
77*4882a593Smuzhiyun #endif
78*4882a593Smuzhiyun 	gd->ram_size = dramsize << 1;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	return 0;
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun 
testdram(void)83*4882a593Smuzhiyun int testdram(void)
84*4882a593Smuzhiyun {
85*4882a593Smuzhiyun 	/* TODO: XXX XXX XXX */
86*4882a593Smuzhiyun 	printf("DRAM test not implemented!\n");
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 	return (0);
89*4882a593Smuzhiyun }
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #if defined(CONFIG_IDE)
92*4882a593Smuzhiyun #include <ata.h>
93*4882a593Smuzhiyun 
ide_preinit(void)94*4882a593Smuzhiyun int ide_preinit(void)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun 	gpio_t *gpio = (gpio_t *) MMAP_GPIO;
97*4882a593Smuzhiyun 	u32 tmp;
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun 	tmp = (in_8(&gpio->par_fec) & GPIO_PAR_FEC_FEC1_UNMASK) | 0x10;
100*4882a593Smuzhiyun 	setbits_8(&gpio->par_fec, tmp);
101*4882a593Smuzhiyun 	tmp = ((in_be16(&gpio->par_feci2c) & 0xf0ff) |
102*4882a593Smuzhiyun 		(GPIO_PAR_FECI2C_MDC1_ATA_DIOR | GPIO_PAR_FECI2C_MDIO1_ATA_DIOW));
103*4882a593Smuzhiyun 	setbits_be16(&gpio->par_feci2c, tmp);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	setbits_be16(&gpio->par_ata,
106*4882a593Smuzhiyun 		GPIO_PAR_ATA_BUFEN | GPIO_PAR_ATA_CS1 | GPIO_PAR_ATA_CS0 |
107*4882a593Smuzhiyun 		GPIO_PAR_ATA_DA2 | GPIO_PAR_ATA_DA1 | GPIO_PAR_ATA_DA0 |
108*4882a593Smuzhiyun 		GPIO_PAR_ATA_RESET_RESET | GPIO_PAR_ATA_DMARQ_DMARQ |
109*4882a593Smuzhiyun 		GPIO_PAR_ATA_IORDY_IORDY);
110*4882a593Smuzhiyun 	setbits_be16(&gpio->par_pci,
111*4882a593Smuzhiyun 		GPIO_PAR_PCI_GNT3_ATA_DMACK | GPIO_PAR_PCI_REQ3_ATA_INTRQ);
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun 	return (0);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun 
ide_set_reset(int idereset)116*4882a593Smuzhiyun void ide_set_reset(int idereset)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	atac_t *ata = (atac_t *) MMAP_ATA;
119*4882a593Smuzhiyun 	long period;
120*4882a593Smuzhiyun 	/*  t1,  t2,  t3,  t4,  t5,  t6,  t9, tRD,  tA */
121*4882a593Smuzhiyun 	int piotms[5][9] = {
122*4882a593Smuzhiyun 		{70, 165, 60, 30, 50, 5, 20, 0, 35},	/* PIO 0 */
123*4882a593Smuzhiyun 		{50, 125, 45, 20, 35, 5, 15, 0, 35},	/* PIO 1 */
124*4882a593Smuzhiyun 		{30, 100, 30, 15, 20, 5, 10, 0, 35},	/* PIO 2 */
125*4882a593Smuzhiyun 		{30, 80, 30, 10, 20, 5, 10, 0, 35},	/* PIO 3 */
126*4882a593Smuzhiyun 		{25, 70, 20, 10, 20, 5, 10, 0, 35}
127*4882a593Smuzhiyun 	};			/* PIO 4 */
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 	if (idereset) {
130*4882a593Smuzhiyun 		/* control reset */
131*4882a593Smuzhiyun 		out_8(&ata->cr, 0);
132*4882a593Smuzhiyun 		udelay(10000);
133*4882a593Smuzhiyun 	} else {
134*4882a593Smuzhiyun #define CALC_TIMING(t) (t + period - 1) / period
135*4882a593Smuzhiyun 		period = 1000000000 / gd->bus_clk;	/* period in ns */
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 		/*ata->ton = CALC_TIMING (180); */
138*4882a593Smuzhiyun 		out_8(&ata->t1, CALC_TIMING(piotms[2][0]));
139*4882a593Smuzhiyun 		out_8(&ata->t2w, CALC_TIMING(piotms[2][1]));
140*4882a593Smuzhiyun 		out_8(&ata->t2r, CALC_TIMING(piotms[2][1]));
141*4882a593Smuzhiyun 		out_8(&ata->ta, CALC_TIMING(piotms[2][8]));
142*4882a593Smuzhiyun 		out_8(&ata->trd, CALC_TIMING(piotms[2][7]));
143*4882a593Smuzhiyun 		out_8(&ata->t4, CALC_TIMING(piotms[2][3]));
144*4882a593Smuzhiyun 		out_8(&ata->t9, CALC_TIMING(piotms[2][6]));
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun 		/* IORDY enable */
147*4882a593Smuzhiyun 		out_8(&ata->cr, 0x40);
148*4882a593Smuzhiyun 		udelay(200000);
149*4882a593Smuzhiyun 		/* IORDY enable */
150*4882a593Smuzhiyun 		setbits_8(&ata->cr, 0x01);
151*4882a593Smuzhiyun 	}
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun #endif
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun #if defined(CONFIG_PCI)
156*4882a593Smuzhiyun /*
157*4882a593Smuzhiyun  * Initialize PCI devices, report devices found.
158*4882a593Smuzhiyun  */
159*4882a593Smuzhiyun static struct pci_controller hose;
160*4882a593Smuzhiyun extern void pci_mcf5445x_init(struct pci_controller *hose);
161*4882a593Smuzhiyun 
pci_init_board(void)162*4882a593Smuzhiyun void pci_init_board(void)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun 	pci_mcf5445x_init(&hose);
165*4882a593Smuzhiyun }
166*4882a593Smuzhiyun #endif				/* CONFIG_PCI */
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun #if defined(CONFIG_FLASH_CFI_LEGACY)
169*4882a593Smuzhiyun #include <flash.h>
board_flash_get_legacy(ulong base,int banknum,flash_info_t * info)170*4882a593Smuzhiyun ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
171*4882a593Smuzhiyun {
172*4882a593Smuzhiyun 	int sect[] = CONFIG_SYS_ATMEL_SECT;
173*4882a593Smuzhiyun 	int sectsz[] = CONFIG_SYS_ATMEL_SECTSZ;
174*4882a593Smuzhiyun 	int i, j, k;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun 	if (base != CONFIG_SYS_ATMEL_BASE)
177*4882a593Smuzhiyun 		return 0;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	info->flash_id          = 0x01000000;
180*4882a593Smuzhiyun 	info->portwidth         = 1;
181*4882a593Smuzhiyun 	info->chipwidth         = 1;
182*4882a593Smuzhiyun 	info->buffer_size       = 1;
183*4882a593Smuzhiyun 	info->erase_blk_tout    = 16384;
184*4882a593Smuzhiyun 	info->write_tout        = 2;
185*4882a593Smuzhiyun 	info->buffer_write_tout = 5;
186*4882a593Smuzhiyun 	info->vendor            = 0xFFF0; /* CFI_CMDSET_AMD_LEGACY */
187*4882a593Smuzhiyun 	info->cmd_reset         = 0x00F0;
188*4882a593Smuzhiyun 	info->interface         = FLASH_CFI_X8;
189*4882a593Smuzhiyun 	info->legacy_unlock     = 0;
190*4882a593Smuzhiyun 	info->manufacturer_id   = (u16) ATM_MANUFACT;
191*4882a593Smuzhiyun 	info->device_id         = ATM_ID_LV040;
192*4882a593Smuzhiyun 	info->device_id2        = 0;
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun 	info->ext_addr          = 0;
195*4882a593Smuzhiyun 	info->cfi_version       = 0x3133;
196*4882a593Smuzhiyun 	info->cfi_offset        = 0x0000;
197*4882a593Smuzhiyun 	info->addr_unlock1      = 0x00000555;
198*4882a593Smuzhiyun 	info->addr_unlock2      = 0x000002AA;
199*4882a593Smuzhiyun 	info->name              = "CFI conformant";
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	info->size              = 0;
202*4882a593Smuzhiyun 	info->sector_count      = CONFIG_SYS_ATMEL_TOTALSECT;
203*4882a593Smuzhiyun 	info->start[0] = base;
204*4882a593Smuzhiyun 	for (k = 0, i = 0; i < CONFIG_SYS_ATMEL_REGION; i++) {
205*4882a593Smuzhiyun 		info->size += sect[i] * sectsz[i];
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 		for (j = 0; j < sect[i]; j++, k++) {
208*4882a593Smuzhiyun 			info->start[k + 1] = info->start[k] + sectsz[i];
209*4882a593Smuzhiyun 			info->protect[k] = 0;
210*4882a593Smuzhiyun 		}
211*4882a593Smuzhiyun 	}
212*4882a593Smuzhiyun 
213*4882a593Smuzhiyun 	return 1;
214*4882a593Smuzhiyun }
215*4882a593Smuzhiyun #endif				/* CONFIG_SYS_FLASH_CFI */
216