162ddcf05SHeiko Schocher /* 262ddcf05SHeiko Schocher * Copyright (C) 2006 Freescale Semiconductor, Inc. 362ddcf05SHeiko Schocher * Dave Liu <daveliu@freescale.com> 462ddcf05SHeiko Schocher * 562ddcf05SHeiko Schocher * Copyright (C) 2007 Logic Product Development, Inc. 662ddcf05SHeiko Schocher * Peter Barada <peterb@logicpd.com> 762ddcf05SHeiko Schocher * 862ddcf05SHeiko Schocher * Copyright (C) 2007 MontaVista Software, Inc. 962ddcf05SHeiko Schocher * Anton Vorontsov <avorontsov@ru.mvista.com> 1062ddcf05SHeiko Schocher * 1162ddcf05SHeiko Schocher * (C) Copyright 2008 - 2010 1262ddcf05SHeiko Schocher * Heiko Schocher, DENX Software Engineering, hs@denx.de. 1362ddcf05SHeiko Schocher * 1462ddcf05SHeiko Schocher * This program is free software; you can redistribute it and/or 1562ddcf05SHeiko Schocher * modify it under the terms of the GNU General Public License as 1662ddcf05SHeiko Schocher * published by the Free Software Foundation; either version 2 of 1762ddcf05SHeiko Schocher * the License, or (at your option) any later version. 1862ddcf05SHeiko Schocher */ 1962ddcf05SHeiko Schocher 2062ddcf05SHeiko Schocher #include <common.h> 2162ddcf05SHeiko Schocher #include <ioports.h> 2262ddcf05SHeiko Schocher #include <mpc83xx.h> 2362ddcf05SHeiko Schocher #include <i2c.h> 2462ddcf05SHeiko Schocher #include <miiphy.h> 2562ddcf05SHeiko Schocher #include <asm/io.h> 2662ddcf05SHeiko Schocher #include <asm/mmu.h> 2762ddcf05SHeiko Schocher #include <asm/processor.h> 2862ddcf05SHeiko Schocher #include <pci.h> 2962ddcf05SHeiko Schocher #include <libfdt.h> 3062ddcf05SHeiko Schocher 3162ddcf05SHeiko Schocher #include "../common/common.h" 3262ddcf05SHeiko Schocher 3362ddcf05SHeiko Schocher const qe_iop_conf_t qe_iop_conf_tab[] = { 3462ddcf05SHeiko Schocher /* port pin dir open_drain assign */ 3562ddcf05SHeiko Schocher #if defined(CONFIG_KMETER1) 3662ddcf05SHeiko Schocher /* MDIO */ 3762ddcf05SHeiko Schocher {0, 1, 3, 0, 2}, /* MDIO */ 3862ddcf05SHeiko Schocher {0, 2, 1, 0, 1}, /* MDC */ 3962ddcf05SHeiko Schocher 4062ddcf05SHeiko Schocher /* UCC4 - UEC */ 4162ddcf05SHeiko Schocher {1, 14, 1, 0, 1}, /* TxD0 */ 4262ddcf05SHeiko Schocher {1, 15, 1, 0, 1}, /* TxD1 */ 4362ddcf05SHeiko Schocher {1, 20, 2, 0, 1}, /* RxD0 */ 4462ddcf05SHeiko Schocher {1, 21, 2, 0, 1}, /* RxD1 */ 4562ddcf05SHeiko Schocher {1, 18, 1, 0, 1}, /* TX_EN */ 4662ddcf05SHeiko Schocher {1, 26, 2, 0, 1}, /* RX_DV */ 4762ddcf05SHeiko Schocher {1, 27, 2, 0, 1}, /* RX_ER */ 4862ddcf05SHeiko Schocher {1, 24, 2, 0, 1}, /* COL */ 4962ddcf05SHeiko Schocher {1, 25, 2, 0, 1}, /* CRS */ 5062ddcf05SHeiko Schocher {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */ 5162ddcf05SHeiko Schocher {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */ 5262ddcf05SHeiko Schocher 5362ddcf05SHeiko Schocher /* DUART - UART2 */ 5462ddcf05SHeiko Schocher {5, 0, 1, 0, 2}, /* UART2_SOUT */ 5562ddcf05SHeiko Schocher {5, 2, 1, 0, 1}, /* UART2_RTS */ 5662ddcf05SHeiko Schocher {5, 3, 2, 0, 2}, /* UART2_SIN */ 5762ddcf05SHeiko Schocher {5, 1, 2, 0, 3}, /* UART2_CTS */ 5862ddcf05SHeiko Schocher #else 5962ddcf05SHeiko Schocher /* Local Bus */ 6062ddcf05SHeiko Schocher {0, 16, 1, 0, 3}, /* LA00 */ 6162ddcf05SHeiko Schocher {0, 17, 1, 0, 3}, /* LA01 */ 6262ddcf05SHeiko Schocher {0, 18, 1, 0, 3}, /* LA02 */ 6362ddcf05SHeiko Schocher {0, 19, 1, 0, 3}, /* LA03 */ 6462ddcf05SHeiko Schocher {0, 20, 1, 0, 3}, /* LA04 */ 6562ddcf05SHeiko Schocher {0, 21, 1, 0, 3}, /* LA05 */ 6662ddcf05SHeiko Schocher {0, 22, 1, 0, 3}, /* LA06 */ 6762ddcf05SHeiko Schocher {0, 23, 1, 0, 3}, /* LA07 */ 6862ddcf05SHeiko Schocher {0, 24, 1, 0, 3}, /* LA08 */ 6962ddcf05SHeiko Schocher {0, 25, 1, 0, 3}, /* LA09 */ 7062ddcf05SHeiko Schocher {0, 26, 1, 0, 3}, /* LA10 */ 7162ddcf05SHeiko Schocher {0, 27, 1, 0, 3}, /* LA11 */ 7262ddcf05SHeiko Schocher {0, 28, 1, 0, 3}, /* LA12 */ 7362ddcf05SHeiko Schocher {0, 29, 1, 0, 3}, /* LA13 */ 7462ddcf05SHeiko Schocher {0, 30, 1, 0, 3}, /* LA14 */ 7562ddcf05SHeiko Schocher {0, 31, 1, 0, 3}, /* LA15 */ 7662ddcf05SHeiko Schocher 7762ddcf05SHeiko Schocher /* MDIO */ 7862ddcf05SHeiko Schocher {3, 4, 3, 0, 2}, /* MDIO */ 7962ddcf05SHeiko Schocher {3, 5, 1, 0, 2}, /* MDC */ 8062ddcf05SHeiko Schocher 8162ddcf05SHeiko Schocher /* UCC4 - UEC */ 8262ddcf05SHeiko Schocher {1, 18, 1, 0, 1}, /* TxD0 */ 8362ddcf05SHeiko Schocher {1, 19, 1, 0, 1}, /* TxD1 */ 8462ddcf05SHeiko Schocher {1, 22, 2, 0, 1}, /* RxD0 */ 8562ddcf05SHeiko Schocher {1, 23, 2, 0, 1}, /* RxD1 */ 8662ddcf05SHeiko Schocher {1, 26, 2, 0, 1}, /* RxER */ 8762ddcf05SHeiko Schocher {1, 28, 2, 0, 1}, /* Rx_DV */ 8862ddcf05SHeiko Schocher {1, 30, 1, 0, 1}, /* TxEN */ 8962ddcf05SHeiko Schocher {1, 31, 2, 0, 1}, /* CRS */ 9062ddcf05SHeiko Schocher {3, 10, 2, 0, 3}, /* TxCLK->CLK17 */ 9162ddcf05SHeiko Schocher #endif 9262ddcf05SHeiko Schocher 9362ddcf05SHeiko Schocher /* END of table */ 9462ddcf05SHeiko Schocher {0, 0, 0, 0, QE_IOP_TAB_END}, 9562ddcf05SHeiko Schocher }; 9662ddcf05SHeiko Schocher 9762ddcf05SHeiko Schocher static int board_init_i2c_busses(void) 9862ddcf05SHeiko Schocher { 9962ddcf05SHeiko Schocher I2C_MUX_DEVICE *dev = NULL; 10062ddcf05SHeiko Schocher uchar *buf; 10162ddcf05SHeiko Schocher 10262ddcf05SHeiko Schocher /* Set up the Bus for the DTTs */ 10362ddcf05SHeiko Schocher buf = (unsigned char *) getenv("dtt_bus"); 10462ddcf05SHeiko Schocher if (buf != NULL) 10562ddcf05SHeiko Schocher dev = i2c_mux_ident_muxstring(buf); 10662ddcf05SHeiko Schocher if (dev == NULL) { 10762ddcf05SHeiko Schocher printf("Error couldn't add Bus for DTT\n"); 10862ddcf05SHeiko Schocher printf("please setup dtt_bus to where your\n"); 10962ddcf05SHeiko Schocher printf("DTT is found.\n"); 11062ddcf05SHeiko Schocher } 11162ddcf05SHeiko Schocher return 0; 11262ddcf05SHeiko Schocher } 11362ddcf05SHeiko Schocher 11462ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3) 11562ddcf05SHeiko Schocher const uint upma_table[] = { 11662ddcf05SHeiko Schocher 0x1ffedc00, 0x0ffcdc80, 0x0ffcdc80, 0x0ffcdc04, /* Words 0 to 3 */ 11762ddcf05SHeiko Schocher 0x0ffcdc00, 0xffffcc00, 0xffffcc01, 0xfffffc01, /* Words 4 to 7 */ 11862ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 8 to 11 */ 11962ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 12 to 15 */ 12062ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 16 to 19 */ 12162ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 20 to 23 */ 12262ddcf05SHeiko Schocher 0x9cfffc00, 0x00fffc80, 0x00fffc80, 0x00fffc00, /* Words 24 to 27 */ 12362ddcf05SHeiko Schocher 0xffffec04, 0xffffec01, 0xfffffc01, 0xfffffc01, /* Words 28 to 31 */ 12462ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 32 to 35 */ 12562ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 36 to 39 */ 12662ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 40 to 43 */ 12762ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 44 to 47 */ 12862ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 48 to 51 */ 12962ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 52 to 55 */ 13062ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 56 to 59 */ 13162ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01 /* Words 60 to 63 */ 13262ddcf05SHeiko Schocher }; 13362ddcf05SHeiko Schocher #endif 13462ddcf05SHeiko Schocher 13562ddcf05SHeiko Schocher int board_early_init_r(void) 13662ddcf05SHeiko Schocher { 1378ed74341SHeiko Schocher struct km_bec_fpga *base = 1388ed74341SHeiko Schocher (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE; 13962ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3) 14062ddcf05SHeiko Schocher immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; 14162ddcf05SHeiko Schocher fsl_lbc_t *lbc = &immap->im_lbc; 14262ddcf05SHeiko Schocher u32 *mxmr = &lbc->mamr; 14362ddcf05SHeiko Schocher #endif 14462ddcf05SHeiko Schocher 14562ddcf05SHeiko Schocher #if defined(CONFIG_MPC8360) 14662ddcf05SHeiko Schocher unsigned short svid; 14762ddcf05SHeiko Schocher /* 14862ddcf05SHeiko Schocher * Because of errata in the UCCs, we have to write to the reserved 14962ddcf05SHeiko Schocher * registers to slow the clocks down. 15062ddcf05SHeiko Schocher */ 15162ddcf05SHeiko Schocher svid = SVR_REV(mfspr(SVR)); 15262ddcf05SHeiko Schocher switch (svid) { 15362ddcf05SHeiko Schocher case 0x0020: 15462ddcf05SHeiko Schocher /* 15562ddcf05SHeiko Schocher * MPC8360ECE.pdf QE_ENET10 table 4: 15662ddcf05SHeiko Schocher * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2) 15762ddcf05SHeiko Schocher * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1) 15862ddcf05SHeiko Schocher */ 15962ddcf05SHeiko Schocher setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000); 16062ddcf05SHeiko Schocher break; 16162ddcf05SHeiko Schocher case 0x0021: 16262ddcf05SHeiko Schocher /* 16362ddcf05SHeiko Schocher * MPC8360ECE.pdf QE_ENET10 table 4: 16462ddcf05SHeiko Schocher * IMMR + 0x14AC[24:27] = 1010 16562ddcf05SHeiko Schocher */ 16662ddcf05SHeiko Schocher clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac), 16762ddcf05SHeiko Schocher 0x00000050, 0x000000a0); 16862ddcf05SHeiko Schocher break; 16962ddcf05SHeiko Schocher } 17062ddcf05SHeiko Schocher #endif 17162ddcf05SHeiko Schocher 17262ddcf05SHeiko Schocher /* enable the PHY on the PIGGY */ 17362ddcf05SHeiko Schocher setbits_8(&base->pgy_eth, 0x01); 17462ddcf05SHeiko Schocher /* enable the Unit LED (green) */ 17562ddcf05SHeiko Schocher setbits_8(&base->oprth, WRL_BOOT); 17662ddcf05SHeiko Schocher 17762ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3) 17862ddcf05SHeiko Schocher /* configure UPMA for APP1 */ 17962ddcf05SHeiko Schocher upmconfig(UPMA, (uint *) upma_table, 18062ddcf05SHeiko Schocher sizeof(upma_table) / sizeof(uint)); 18162ddcf05SHeiko Schocher out_be32(mxmr, CONFIG_SYS_MAMR); 18262ddcf05SHeiko Schocher #endif 18362ddcf05SHeiko Schocher return 0; 18462ddcf05SHeiko Schocher } 18562ddcf05SHeiko Schocher 18662ddcf05SHeiko Schocher int misc_init_r(void) 18762ddcf05SHeiko Schocher { 18862ddcf05SHeiko Schocher /* add board specific i2c busses */ 18962ddcf05SHeiko Schocher board_init_i2c_busses(); 19062ddcf05SHeiko Schocher return 0; 19162ddcf05SHeiko Schocher } 19262ddcf05SHeiko Schocher 193*f1fef1d8SHeiko Schocher int last_stage_init(void) 194*f1fef1d8SHeiko Schocher { 195*f1fef1d8SHeiko Schocher set_km_env(); 196*f1fef1d8SHeiko Schocher return 0; 197*f1fef1d8SHeiko Schocher } 198*f1fef1d8SHeiko Schocher 19962ddcf05SHeiko Schocher int fixed_sdram(void) 20062ddcf05SHeiko Schocher { 20162ddcf05SHeiko Schocher immap_t *im = (immap_t *)CONFIG_SYS_IMMR; 20262ddcf05SHeiko Schocher u32 msize = 0; 20362ddcf05SHeiko Schocher u32 ddr_size; 20462ddcf05SHeiko Schocher u32 ddr_size_log2; 20562ddcf05SHeiko Schocher 20662ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].ar, (LAWAR_EN | 0x1e)); 20762ddcf05SHeiko Schocher out_be32(&im->ddr.csbnds[0].csbnds, CONFIG_SYS_DDR_CS0_BNDS); 20862ddcf05SHeiko Schocher out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG); 20962ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0); 21062ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1); 21162ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2); 21262ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3); 21362ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG); 21462ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2); 21562ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE); 21662ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2); 21762ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL); 21862ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL); 21962ddcf05SHeiko Schocher udelay(200); 22062ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN); 22162ddcf05SHeiko Schocher 22262ddcf05SHeiko Schocher msize = CONFIG_SYS_DDR_SIZE << 20; 22362ddcf05SHeiko Schocher disable_addr_trans(); 22462ddcf05SHeiko Schocher msize = get_ram_size(CONFIG_SYS_DDR_BASE, msize); 22562ddcf05SHeiko Schocher enable_addr_trans(); 22662ddcf05SHeiko Schocher msize /= (1024 * 1024); 22762ddcf05SHeiko Schocher if (CONFIG_SYS_DDR_SIZE != msize) { 22862ddcf05SHeiko Schocher for (ddr_size = msize << 20, ddr_size_log2 = 0; 22962ddcf05SHeiko Schocher (ddr_size > 1); 23062ddcf05SHeiko Schocher ddr_size = ddr_size >> 1, ddr_size_log2++) 23162ddcf05SHeiko Schocher if (ddr_size & 1) 23262ddcf05SHeiko Schocher return -1; 23362ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].ar, 23462ddcf05SHeiko Schocher (LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE))); 23562ddcf05SHeiko Schocher out_be32(&im->ddr.csbnds[0].csbnds, 23662ddcf05SHeiko Schocher (((msize / 16) - 1) & 0xff)); 23762ddcf05SHeiko Schocher } 23862ddcf05SHeiko Schocher 23962ddcf05SHeiko Schocher return msize; 24062ddcf05SHeiko Schocher } 24162ddcf05SHeiko Schocher 24262ddcf05SHeiko Schocher phys_size_t initdram(int board_type) 24362ddcf05SHeiko Schocher { 24462ddcf05SHeiko Schocher immap_t *im = (immap_t *)CONFIG_SYS_IMMR; 24562ddcf05SHeiko Schocher u32 msize = 0; 24662ddcf05SHeiko Schocher 24762ddcf05SHeiko Schocher if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im) 24862ddcf05SHeiko Schocher return -1; 24962ddcf05SHeiko Schocher 25062ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].bar, 25162ddcf05SHeiko Schocher CONFIG_SYS_DDR_BASE & LAWBAR_BAR); 25262ddcf05SHeiko Schocher msize = fixed_sdram(); 25362ddcf05SHeiko Schocher 25462ddcf05SHeiko Schocher #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) 25562ddcf05SHeiko Schocher /* 25662ddcf05SHeiko Schocher * Initialize DDR ECC byte 25762ddcf05SHeiko Schocher */ 25862ddcf05SHeiko Schocher ddr_enable_ecc(msize * 1024 * 1024); 25962ddcf05SHeiko Schocher #endif 26062ddcf05SHeiko Schocher 26162ddcf05SHeiko Schocher /* return total bus SDRAM size(bytes) -- DDR */ 26262ddcf05SHeiko Schocher return msize * 1024 * 1024; 26362ddcf05SHeiko Schocher } 26462ddcf05SHeiko Schocher 26562ddcf05SHeiko Schocher int checkboard(void) 26662ddcf05SHeiko Schocher { 26762ddcf05SHeiko Schocher puts("Board: Keymile " CONFIG_KM_BOARD_NAME); 26862ddcf05SHeiko Schocher 26962ddcf05SHeiko Schocher if (ethernet_present()) 27062ddcf05SHeiko Schocher puts(" with PIGGY."); 27162ddcf05SHeiko Schocher puts("\n"); 27262ddcf05SHeiko Schocher return 0; 27362ddcf05SHeiko Schocher } 27462ddcf05SHeiko Schocher 27562ddcf05SHeiko Schocher #if defined(CONFIG_OF_BOARD_SETUP) 27662ddcf05SHeiko Schocher void ft_board_setup(void *blob, bd_t *bd) 27762ddcf05SHeiko Schocher { 27862ddcf05SHeiko Schocher ft_cpu_setup(blob, bd); 27962ddcf05SHeiko Schocher } 28062ddcf05SHeiko Schocher #endif 28162ddcf05SHeiko Schocher 28262ddcf05SHeiko Schocher #if defined(CONFIG_HUSH_INIT_VAR) 28362ddcf05SHeiko Schocher int hush_init_var(void) 28462ddcf05SHeiko Schocher { 28562ddcf05SHeiko Schocher ivm_read_eeprom(); 28662ddcf05SHeiko Schocher return 0; 28762ddcf05SHeiko Schocher } 28862ddcf05SHeiko Schocher #endif 289