blob: c749ee407e770034f7a621a314197118d3b98eb9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiew8ae158c2007-08-16 15:05:11 -05002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang198cafb2012-03-26 21:49:08 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew8ae158c2007-08-16 15:05:11 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiew8ae158c2007-08-16 15:05:11 -05008 */
9
10#include <common.h>
Simon Glass2cf431c2019-11-14 12:57:47 -070011#include <init.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050012#include <pci.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050014#include <asm/immap.h>
Alison Wang198cafb2012-03-26 21:49:08 +000015#include <asm/io.h>
Simon Glassc05ed002020-05-10 11:40:11 -060016#include <linux/delay.h>
TsiChungLiew8ae158c2007-08-16 15:05:11 -050017
18DECLARE_GLOBAL_DATA_PTR;
19
20int checkboard(void)
21{
22 puts("Board: ");
23 puts("Freescale M54455 EVB\n");
24 return 0;
25};
26
Simon Glassf1683aa2017-04-06 12:47:05 -060027int dram_init(void)
TsiChungLiew8ae158c2007-08-16 15:05:11 -050028{
TsiChung Liew9f751552008-07-23 20:38:53 -050029 u32 dramsize;
30#ifdef CONFIG_CF_SBF
31 /*
32 * Serial Boot: The dram is already initialized in start.S
33 * only require to return DRAM size
34 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
TsiChung Liew9f751552008-07-23 20:38:53 -050036#else
Alison Wang198cafb2012-03-26 21:49:08 +000037 sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
38 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChung Liew9f751552008-07-23 20:38:53 -050039 u32 i;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050040
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050042
43 for (i = 0x13; i < 0x20; i++) {
44 if (dramsize == (1 << i))
45 break;
46 }
47 i--;
48
Alison Wang198cafb2012-03-26 21:49:08 +000049 out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050050
Alison Wang198cafb2012-03-26 21:49:08 +000051 out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
52 out_be32(&sdram->sdcs1, CONFIG_SYS_SDRAM_BASE1 | i);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050053
Alison Wang198cafb2012-03-26 21:49:08 +000054 out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
55 out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050056
57 /* Issue PALL */
Alison Wang198cafb2012-03-26 21:49:08 +000058 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050059
60 /* Issue LEMR */
Alison Wang198cafb2012-03-26 21:49:08 +000061 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD | 0x408);
62 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x300);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050063
64 udelay(500);
65
66 /* Issue PALL */
Alison Wang198cafb2012-03-26 21:49:08 +000067 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050068
69 /* Perform two refresh cycles */
Alison Wang198cafb2012-03-26 21:49:08 +000070 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
71 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050072
Alison Wang198cafb2012-03-26 21:49:08 +000073 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x200);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050074
Alison Wang198cafb2012-03-26 21:49:08 +000075 out_be32(&sdram->sdcr,
76 (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00);
TsiChungLiew8ae158c2007-08-16 15:05:11 -050077
78 udelay(100);
TsiChung Liew9f751552008-07-23 20:38:53 -050079#endif
Simon Glass088454c2017-03-31 08:40:25 -060080 gd->ram_size = dramsize << 1;
81
82 return 0;
TsiChungLiew8ae158c2007-08-16 15:05:11 -050083};
84
85int testdram(void)
86{
87 /* TODO: XXX XXX XXX */
88 printf("DRAM test not implemented!\n");
89
90 return (0);
91}
92
Simon Glassfc843a02017-05-17 03:25:30 -060093#if defined(CONFIG_IDE)
TsiChungLiew8ae158c2007-08-16 15:05:11 -050094#include <ata.h>
95
96int ide_preinit(void)
97{
Alison Wang198cafb2012-03-26 21:49:08 +000098 gpio_t *gpio = (gpio_t *) MMAP_GPIO;
99 u32 tmp;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500100
Alison Wang198cafb2012-03-26 21:49:08 +0000101 tmp = (in_8(&gpio->par_fec) & GPIO_PAR_FEC_FEC1_UNMASK) | 0x10;
102 setbits_8(&gpio->par_fec, tmp);
103 tmp = ((in_be16(&gpio->par_feci2c) & 0xf0ff) |
104 (GPIO_PAR_FECI2C_MDC1_ATA_DIOR | GPIO_PAR_FECI2C_MDIO1_ATA_DIOW));
105 setbits_be16(&gpio->par_feci2c, tmp);
106
107 setbits_be16(&gpio->par_ata,
108 GPIO_PAR_ATA_BUFEN | GPIO_PAR_ATA_CS1 | GPIO_PAR_ATA_CS0 |
109 GPIO_PAR_ATA_DA2 | GPIO_PAR_ATA_DA1 | GPIO_PAR_ATA_DA0 |
110 GPIO_PAR_ATA_RESET_RESET | GPIO_PAR_ATA_DMARQ_DMARQ |
111 GPIO_PAR_ATA_IORDY_IORDY);
112 setbits_be16(&gpio->par_pci,
113 GPIO_PAR_PCI_GNT3_ATA_DMACK | GPIO_PAR_PCI_REQ3_ATA_INTRQ);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500114
115 return (0);
116}
117
118void ide_set_reset(int idereset)
119{
Alison Wang198cafb2012-03-26 21:49:08 +0000120 atac_t *ata = (atac_t *) MMAP_ATA;
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500121 long period;
122 /* t1, t2, t3, t4, t5, t6, t9, tRD, tA */
123 int piotms[5][9] = {
124 {70, 165, 60, 30, 50, 5, 20, 0, 35}, /* PIO 0 */
125 {50, 125, 45, 20, 35, 5, 15, 0, 35}, /* PIO 1 */
126 {30, 100, 30, 15, 20, 5, 10, 0, 35}, /* PIO 2 */
127 {30, 80, 30, 10, 20, 5, 10, 0, 35}, /* PIO 3 */
128 {25, 70, 20, 10, 20, 5, 10, 0, 35}
129 }; /* PIO 4 */
130
131 if (idereset) {
Alison Wang198cafb2012-03-26 21:49:08 +0000132 /* control reset */
133 out_8(&ata->cr, 0);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500134 udelay(10000);
135 } else {
136#define CALC_TIMING(t) (t + period - 1) / period
137 period = 1000000000 / gd->bus_clk; /* period in ns */
138
139 /*ata->ton = CALC_TIMING (180); */
Alison Wang198cafb2012-03-26 21:49:08 +0000140 out_8(&ata->t1, CALC_TIMING(piotms[2][0]));
141 out_8(&ata->t2w, CALC_TIMING(piotms[2][1]));
142 out_8(&ata->t2r, CALC_TIMING(piotms[2][1]));
143 out_8(&ata->ta, CALC_TIMING(piotms[2][8]));
144 out_8(&ata->trd, CALC_TIMING(piotms[2][7]));
145 out_8(&ata->t4, CALC_TIMING(piotms[2][3]));
146 out_8(&ata->t9, CALC_TIMING(piotms[2][6]));
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500147
Alison Wang198cafb2012-03-26 21:49:08 +0000148 /* IORDY enable */
149 out_8(&ata->cr, 0x40);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500150 udelay(200000);
Alison Wang198cafb2012-03-26 21:49:08 +0000151 /* IORDY enable */
152 setbits_8(&ata->cr, 0x01);
TsiChungLiew8ae158c2007-08-16 15:05:11 -0500153 }
154}
155#endif
156
157#if defined(CONFIG_PCI)
158/*
159 * Initialize PCI devices, report devices found.
160 */
161static struct pci_controller hose;
162extern void pci_mcf5445x_init(struct pci_controller *hose);
163
164void pci_init_board(void)
165{
166 pci_mcf5445x_init(&hose);
167}
168#endif /* CONFIG_PCI */
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500169
TsiChung Liewf78ced32008-08-19 00:26:25 +0600170#if defined(CONFIG_FLASH_CFI_LEGACY)
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500171#include <flash.h>
172ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info)
173{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200174 int sect[] = CONFIG_SYS_ATMEL_SECT;
175 int sectsz[] = CONFIG_SYS_ATMEL_SECTSZ;
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500176 int i, j, k;
177
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200178 if (base != CONFIG_SYS_ATMEL_BASE)
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500179 return 0;
180
181 info->flash_id = 0x01000000;
182 info->portwidth = 1;
183 info->chipwidth = 1;
TsiChung Liew9d3a86a2010-03-16 12:39:36 -0500184 info->buffer_size = 1;
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500185 info->erase_blk_tout = 16384;
186 info->write_tout = 2;
187 info->buffer_write_tout = 5;
TsiChung Liewf78ced32008-08-19 00:26:25 +0600188 info->vendor = 0xFFF0; /* CFI_CMDSET_AMD_LEGACY */
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500189 info->cmd_reset = 0x00F0;
190 info->interface = FLASH_CFI_X8;
191 info->legacy_unlock = 0;
192 info->manufacturer_id = (u16) ATM_MANUFACT;
193 info->device_id = ATM_ID_LV040;
194 info->device_id2 = 0;
195
196 info->ext_addr = 0;
197 info->cfi_version = 0x3133;
TsiChung Liewf78ced32008-08-19 00:26:25 +0600198 info->cfi_offset = 0x0000;
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500199 info->addr_unlock1 = 0x00000555;
200 info->addr_unlock2 = 0x000002AA;
201 info->name = "CFI conformant";
202
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500203 info->size = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200204 info->sector_count = CONFIG_SYS_ATMEL_TOTALSECT;
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500205 info->start[0] = base;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200206 for (k = 0, i = 0; i < CONFIG_SYS_ATMEL_REGION; i++) {
TsiChung Liewb2d022d2008-07-23 17:37:10 -0500207 info->size += sect[i] * sectsz[i];
208
209 for (j = 0; j < sect[i]; j++, k++) {
210 info->start[k + 1] = info->start[k] + sectsz[i];
211 info->protect[k] = 0;
212 }
213 }
214
215 return 1;
216}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200217#endif /* CONFIG_SYS_FLASH_CFI */