TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 5 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 6 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <pci.h> |
| 29 | #include <asm/immap.h> |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 30 | #include <asm/io.h> |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | int checkboard(void) |
| 35 | { |
| 36 | puts("Board: "); |
| 37 | puts("Freescale M54455 EVB\n"); |
| 38 | return 0; |
| 39 | }; |
| 40 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 41 | phys_size_t initdram(int board_type) |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 42 | { |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 43 | u32 dramsize; |
| 44 | #ifdef CONFIG_CF_SBF |
| 45 | /* |
| 46 | * Serial Boot: The dram is already initialized in start.S |
| 47 | * only require to return DRAM size |
| 48 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1; |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 50 | #else |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 51 | sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM); |
| 52 | gpio_t *gpio = (gpio_t *)(MMAP_GPIO); |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 53 | u32 i; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 54 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000 >> 1; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 56 | |
| 57 | for (i = 0x13; i < 0x20; i++) { |
| 58 | if (dramsize == (1 << i)) |
| 59 | break; |
| 60 | } |
| 61 | i--; |
| 62 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 63 | out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 64 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 65 | out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i); |
| 66 | out_be32(&sdram->sdcs1, CONFIG_SYS_SDRAM_BASE1 | i); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 67 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 68 | out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1); |
| 69 | out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 70 | |
| 71 | /* Issue PALL */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 72 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 73 | |
| 74 | /* Issue LEMR */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 75 | out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD | 0x408); |
| 76 | out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x300); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 77 | |
| 78 | udelay(500); |
| 79 | |
| 80 | /* Issue PALL */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 81 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 82 | |
| 83 | /* Perform two refresh cycles */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 84 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4); |
| 85 | out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 86 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 87 | out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE | 0x200); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 88 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 89 | out_be32(&sdram->sdcr, |
| 90 | (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 91 | |
| 92 | udelay(100); |
TsiChung Liew | 9f75155 | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 93 | #endif |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 94 | return (dramsize << 1); |
| 95 | }; |
| 96 | |
| 97 | int testdram(void) |
| 98 | { |
| 99 | /* TODO: XXX XXX XXX */ |
| 100 | printf("DRAM test not implemented!\n"); |
| 101 | |
| 102 | return (0); |
| 103 | } |
| 104 | |
| 105 | #if defined(CONFIG_CMD_IDE) |
| 106 | #include <ata.h> |
| 107 | |
| 108 | int ide_preinit(void) |
| 109 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 110 | gpio_t *gpio = (gpio_t *) MMAP_GPIO; |
| 111 | u32 tmp; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 112 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 113 | tmp = (in_8(&gpio->par_fec) & GPIO_PAR_FEC_FEC1_UNMASK) | 0x10; |
| 114 | setbits_8(&gpio->par_fec, tmp); |
| 115 | tmp = ((in_be16(&gpio->par_feci2c) & 0xf0ff) | |
| 116 | (GPIO_PAR_FECI2C_MDC1_ATA_DIOR | GPIO_PAR_FECI2C_MDIO1_ATA_DIOW)); |
| 117 | setbits_be16(&gpio->par_feci2c, tmp); |
| 118 | |
| 119 | setbits_be16(&gpio->par_ata, |
| 120 | GPIO_PAR_ATA_BUFEN | GPIO_PAR_ATA_CS1 | GPIO_PAR_ATA_CS0 | |
| 121 | GPIO_PAR_ATA_DA2 | GPIO_PAR_ATA_DA1 | GPIO_PAR_ATA_DA0 | |
| 122 | GPIO_PAR_ATA_RESET_RESET | GPIO_PAR_ATA_DMARQ_DMARQ | |
| 123 | GPIO_PAR_ATA_IORDY_IORDY); |
| 124 | setbits_be16(&gpio->par_pci, |
| 125 | GPIO_PAR_PCI_GNT3_ATA_DMACK | GPIO_PAR_PCI_REQ3_ATA_INTRQ); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 126 | |
| 127 | return (0); |
| 128 | } |
| 129 | |
| 130 | void ide_set_reset(int idereset) |
| 131 | { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 132 | atac_t *ata = (atac_t *) MMAP_ATA; |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 133 | long period; |
| 134 | /* t1, t2, t3, t4, t5, t6, t9, tRD, tA */ |
| 135 | int piotms[5][9] = { |
| 136 | {70, 165, 60, 30, 50, 5, 20, 0, 35}, /* PIO 0 */ |
| 137 | {50, 125, 45, 20, 35, 5, 15, 0, 35}, /* PIO 1 */ |
| 138 | {30, 100, 30, 15, 20, 5, 10, 0, 35}, /* PIO 2 */ |
| 139 | {30, 80, 30, 10, 20, 5, 10, 0, 35}, /* PIO 3 */ |
| 140 | {25, 70, 20, 10, 20, 5, 10, 0, 35} |
| 141 | }; /* PIO 4 */ |
| 142 | |
| 143 | if (idereset) { |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 144 | /* control reset */ |
| 145 | out_8(&ata->cr, 0); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 146 | udelay(10000); |
| 147 | } else { |
| 148 | #define CALC_TIMING(t) (t + period - 1) / period |
| 149 | period = 1000000000 / gd->bus_clk; /* period in ns */ |
| 150 | |
| 151 | /*ata->ton = CALC_TIMING (180); */ |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 152 | out_8(&ata->t1, CALC_TIMING(piotms[2][0])); |
| 153 | out_8(&ata->t2w, CALC_TIMING(piotms[2][1])); |
| 154 | out_8(&ata->t2r, CALC_TIMING(piotms[2][1])); |
| 155 | out_8(&ata->ta, CALC_TIMING(piotms[2][8])); |
| 156 | out_8(&ata->trd, CALC_TIMING(piotms[2][7])); |
| 157 | out_8(&ata->t4, CALC_TIMING(piotms[2][3])); |
| 158 | out_8(&ata->t9, CALC_TIMING(piotms[2][6])); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 159 | |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 160 | /* IORDY enable */ |
| 161 | out_8(&ata->cr, 0x40); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 162 | udelay(200000); |
Alison Wang | 198cafb | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 163 | /* IORDY enable */ |
| 164 | setbits_8(&ata->cr, 0x01); |
TsiChungLiew | 8ae158c | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | #endif |
| 168 | |
| 169 | #if defined(CONFIG_PCI) |
| 170 | /* |
| 171 | * Initialize PCI devices, report devices found. |
| 172 | */ |
| 173 | static struct pci_controller hose; |
| 174 | extern void pci_mcf5445x_init(struct pci_controller *hose); |
| 175 | |
| 176 | void pci_init_board(void) |
| 177 | { |
| 178 | pci_mcf5445x_init(&hose); |
| 179 | } |
| 180 | #endif /* CONFIG_PCI */ |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 181 | |
TsiChung Liew | f78ced3 | 2008-08-19 00:26:25 +0600 | [diff] [blame] | 182 | #if defined(CONFIG_FLASH_CFI_LEGACY) |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 183 | #include <flash.h> |
| 184 | ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info) |
| 185 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 186 | int sect[] = CONFIG_SYS_ATMEL_SECT; |
| 187 | int sectsz[] = CONFIG_SYS_ATMEL_SECTSZ; |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 188 | int i, j, k; |
| 189 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 190 | if (base != CONFIG_SYS_ATMEL_BASE) |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 191 | return 0; |
| 192 | |
| 193 | info->flash_id = 0x01000000; |
| 194 | info->portwidth = 1; |
| 195 | info->chipwidth = 1; |
TsiChung Liew | 9d3a86a | 2010-03-16 12:39:36 -0500 | [diff] [blame] | 196 | info->buffer_size = 1; |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 197 | info->erase_blk_tout = 16384; |
| 198 | info->write_tout = 2; |
| 199 | info->buffer_write_tout = 5; |
TsiChung Liew | f78ced3 | 2008-08-19 00:26:25 +0600 | [diff] [blame] | 200 | info->vendor = 0xFFF0; /* CFI_CMDSET_AMD_LEGACY */ |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 201 | info->cmd_reset = 0x00F0; |
| 202 | info->interface = FLASH_CFI_X8; |
| 203 | info->legacy_unlock = 0; |
| 204 | info->manufacturer_id = (u16) ATM_MANUFACT; |
| 205 | info->device_id = ATM_ID_LV040; |
| 206 | info->device_id2 = 0; |
| 207 | |
| 208 | info->ext_addr = 0; |
| 209 | info->cfi_version = 0x3133; |
TsiChung Liew | f78ced3 | 2008-08-19 00:26:25 +0600 | [diff] [blame] | 210 | info->cfi_offset = 0x0000; |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 211 | info->addr_unlock1 = 0x00000555; |
| 212 | info->addr_unlock2 = 0x000002AA; |
| 213 | info->name = "CFI conformant"; |
| 214 | |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 215 | info->size = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 216 | info->sector_count = CONFIG_SYS_ATMEL_TOTALSECT; |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 217 | info->start[0] = base; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 218 | for (k = 0, i = 0; i < CONFIG_SYS_ATMEL_REGION; i++) { |
TsiChung Liew | b2d022d | 2008-07-23 17:37:10 -0500 | [diff] [blame] | 219 | info->size += sect[i] * sectsz[i]; |
| 220 | |
| 221 | for (j = 0; j < sect[i]; j++, k++) { |
| 222 | info->start[k + 1] = info->start[k] + sectsz[i]; |
| 223 | info->protect[k] = 0; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | return 1; |
| 228 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 229 | #endif /* CONFIG_SYS_FLASH_CFI */ |