Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Dave Liu <daveliu@freescale.com> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 9 | #include <fdt_support.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 11 | #include <ioports.h> |
| 12 | #include <mpc83xx.h> |
| 13 | #include <i2c.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 14 | #include <miiphy.h> |
| 15 | #include <command.h> |
| 16 | #if defined(CONFIG_PCI) |
| 17 | #include <pci.h> |
| 18 | #endif |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 20 | #include <asm/mmu.h> |
Kim Phillips | 3204c7c | 2007-12-20 15:57:28 -0600 | [diff] [blame] | 21 | #if defined(CONFIG_OF_LIBFDT) |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 22 | #include <linux/libfdt.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 23 | #endif |
Tony Li | c8b57f1 | 2007-08-17 10:35:59 +0800 | [diff] [blame] | 24 | #if defined(CONFIG_PQ_MDS_PIB) |
Kim Phillips | d8ded96 | 2007-08-16 22:53:09 -0500 | [diff] [blame] | 25 | #include "../common/pq-mds-pib.h" |
Tony Li | c8b57f1 | 2007-08-17 10:35:59 +0800 | [diff] [blame] | 26 | #endif |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 27 | #include <linux/delay.h> |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 28 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 31 | const qe_iop_conf_t qe_iop_conf_tab[] = { |
| 32 | /* ETH3 */ |
| 33 | {1, 0, 1, 0, 1}, /* TxD0 */ |
| 34 | {1, 1, 1, 0, 1}, /* TxD1 */ |
| 35 | {1, 2, 1, 0, 1}, /* TxD2 */ |
| 36 | {1, 3, 1, 0, 1}, /* TxD3 */ |
| 37 | {1, 9, 1, 0, 1}, /* TxER */ |
| 38 | {1, 12, 1, 0, 1}, /* TxEN */ |
| 39 | {3, 24, 2, 0, 1}, /* TxCLK->CLK10 */ |
| 40 | |
| 41 | {1, 4, 2, 0, 1}, /* RxD0 */ |
| 42 | {1, 5, 2, 0, 1}, /* RxD1 */ |
| 43 | {1, 6, 2, 0, 1}, /* RxD2 */ |
| 44 | {1, 7, 2, 0, 1}, /* RxD3 */ |
| 45 | {1, 8, 2, 0, 1}, /* RxER */ |
| 46 | {1, 10, 2, 0, 1}, /* RxDV */ |
| 47 | {0, 13, 2, 0, 1}, /* RxCLK->CLK9 */ |
| 48 | {1, 11, 2, 0, 1}, /* COL */ |
| 49 | {1, 13, 2, 0, 1}, /* CRS */ |
| 50 | |
| 51 | /* ETH4 */ |
| 52 | {1, 18, 1, 0, 1}, /* TxD0 */ |
| 53 | {1, 19, 1, 0, 1}, /* TxD1 */ |
| 54 | {1, 20, 1, 0, 1}, /* TxD2 */ |
| 55 | {1, 21, 1, 0, 1}, /* TxD3 */ |
| 56 | {1, 27, 1, 0, 1}, /* TxER */ |
| 57 | {1, 30, 1, 0, 1}, /* TxEN */ |
| 58 | {3, 6, 2, 0, 1}, /* TxCLK->CLK8 */ |
| 59 | |
| 60 | {1, 22, 2, 0, 1}, /* RxD0 */ |
| 61 | {1, 23, 2, 0, 1}, /* RxD1 */ |
| 62 | {1, 24, 2, 0, 1}, /* RxD2 */ |
| 63 | {1, 25, 2, 0, 1}, /* RxD3 */ |
| 64 | {1, 26, 1, 0, 1}, /* RxER */ |
| 65 | {1, 28, 2, 0, 1}, /* Rx_DV */ |
| 66 | {3, 31, 2, 0, 1}, /* RxCLK->CLK7 */ |
| 67 | {1, 29, 2, 0, 1}, /* COL */ |
| 68 | {1, 31, 2, 0, 1}, /* CRS */ |
| 69 | |
| 70 | {3, 4, 3, 0, 2}, /* MDIO */ |
| 71 | {3, 5, 1, 0, 2}, /* MDC */ |
| 72 | |
| 73 | {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */ |
| 74 | }; |
| 75 | |
| 76 | int board_early_init_f(void) |
| 77 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 78 | volatile u8 *bcsr = (volatile u8 *)CONFIG_SYS_BCSR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 79 | |
| 80 | /* Enable flash write */ |
| 81 | bcsr[9] &= ~0x08; |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Tony Li | c8b57f1 | 2007-08-17 10:35:59 +0800 | [diff] [blame] | 86 | int board_early_init_r(void) |
| 87 | { |
| 88 | #ifdef CONFIG_PQ_MDS_PIB |
| 89 | pib_init(); |
| 90 | #endif |
| 91 | return 0; |
| 92 | } |
| 93 | |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 94 | int fixed_sdram(void); |
| 95 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 96 | int dram_init(void) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 97 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 99 | u32 msize = 0; |
| 100 | |
| 101 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 102 | return -ENXIO; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 103 | |
| 104 | /* DDR SDRAM - Main SODIMM */ |
Mario Six | c9f9277 | 2019-01-21 09:18:15 +0100 | [diff] [blame] | 105 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 106 | |
| 107 | msize = fixed_sdram(); |
| 108 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 109 | /* set total bus SDRAM size(bytes) -- DDR */ |
| 110 | gd->ram_size = msize * 1024 * 1024; |
| 111 | |
| 112 | return 0; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /************************************************************************* |
| 116 | * fixed sdram init -- doesn't use serial presence detect. |
| 117 | ************************************************************************/ |
| 118 | int fixed_sdram(void) |
| 119 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 120 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 121 | u32 msize = 0; |
| 122 | u32 ddr_size; |
| 123 | u32 ddr_size_log2; |
| 124 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 125 | msize = CONFIG_SYS_DDR_SIZE; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 126 | for (ddr_size = msize << 20, ddr_size_log2 = 0; |
| 127 | (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) { |
| 128 | if (ddr_size & 1) { |
| 129 | return -1; |
| 130 | } |
| 131 | } |
| 132 | im->sysconf.ddrlaw[0].ar = |
| 133 | LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | #if (CONFIG_SYS_DDR_SIZE != 128) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 135 | #warning Currenly any ddr size other than 128 is not supported |
| 136 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 137 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL; |
| 138 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 139 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
| 140 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 141 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 142 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 143 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 144 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 145 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 146 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 147 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
| 148 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 149 | __asm__ __volatile__ ("sync"); |
| 150 | udelay(200); |
| 151 | |
| 152 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 153 | __asm__ __volatile__ ("sync"); |
| 154 | return msize; |
| 155 | } |
| 156 | |
| 157 | int checkboard(void) |
| 158 | { |
| 159 | puts("Board: Freescale MPC832XEMDS\n"); |
| 160 | return 0; |
| 161 | } |
| 162 | |
Kim Phillips | 2141681 | 2007-08-15 22:30:33 -0500 | [diff] [blame] | 163 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 164 | int ft_board_setup(void *blob, struct bd_info *bd) |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 165 | { |
Kim Phillips | 2141681 | 2007-08-15 22:30:33 -0500 | [diff] [blame] | 166 | ft_cpu_setup(blob, bd); |
| 167 | #ifdef CONFIG_PCI |
| 168 | ft_pci_setup(blob, bd); |
| 169 | #endif |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 170 | |
| 171 | return 0; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 172 | } |
| 173 | #endif |