Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 |
| 4 | * Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 5 | * |
| 6 | * Based on: |
| 7 | * Copyright (c) 2011 IDS GmbH, Germany |
| 8 | * ids8313.c - ids8313 board support. |
| 9 | * |
| 10 | * Sergej Stepanov <ste@ids.de> |
| 11 | * Based on board/freescale/mpc8313erdb/mpc8313erdb.c |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 15 | #include <fdt_support.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 16 | #include <init.h> |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 17 | #include <mpc83xx.h> |
| 18 | #include <spi.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <asm/bitops.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 21 | #include <linux/libfdt.h> |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | /** CPLD contains the info about: |
| 25 | * - board type: *pCpld & 0xF0 |
| 26 | * - hw-revision: *pCpld & 0x0F |
| 27 | * - cpld-revision: *pCpld+1 |
| 28 | */ |
| 29 | int checkboard(void) |
| 30 | { |
| 31 | char *pcpld = (char *)CONFIG_SYS_CPLD_BASE; |
| 32 | u8 u8Vers = readb(pcpld); |
| 33 | u8 u8Revs = readb(pcpld + 1); |
| 34 | |
| 35 | printf("Board: "); |
| 36 | switch (u8Vers & 0xF0) { |
| 37 | case '\x40': |
| 38 | printf("CU73X"); |
| 39 | break; |
| 40 | case '\x50': |
| 41 | printf("CC73X"); |
| 42 | break; |
| 43 | default: |
| 44 | printf("unknown(0x%02X, 0x%02X)\n", u8Vers, u8Revs); |
| 45 | return 0; |
| 46 | } |
| 47 | printf("\nInfo: HW-Rev: %i, CPLD-Rev: %i\n", |
| 48 | u8Vers & 0x0F, u8Revs & 0xFF); |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * fixed sdram init |
| 54 | */ |
| 55 | int fixed_sdram(unsigned long config) |
| 56 | { |
| 57 | immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
| 58 | u32 msize = CONFIG_SYS_DDR_SIZE << 20; |
| 59 | |
| 60 | #ifndef CONFIG_SYS_RAMBOOT |
| 61 | u32 msize_log2 = __ilog2(msize); |
| 62 | |
| 63 | out_be32(&im->sysconf.ddrlaw[0].bar, |
Mario Six | 133ec60 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 64 | (CONFIG_SYS_SDRAM_BASE & 0xfffff000)); |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 65 | out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1)); |
| 66 | out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE); |
| 67 | sync(); |
| 68 | |
| 69 | /* |
| 70 | * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg], |
| 71 | * or the DDR2 controller may fail to initialize correctly. |
| 72 | */ |
| 73 | udelay(50000); |
| 74 | |
| 75 | out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24); |
| 76 | out_be32(&im->ddr.cs_config[0], config); |
| 77 | |
| 78 | /* currently we use only one CS, so disable the other banks */ |
| 79 | out_be32(&im->ddr.cs_config[1], 0); |
| 80 | out_be32(&im->ddr.cs_config[2], 0); |
| 81 | out_be32(&im->ddr.cs_config[3], 0); |
| 82 | |
| 83 | out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3); |
| 84 | out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1); |
| 85 | out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2); |
| 86 | out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0); |
| 87 | |
| 88 | out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_SDRAM_CFG); |
| 89 | out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_SDRAM_CFG2); |
| 90 | |
| 91 | out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE); |
| 92 | out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE_2); |
| 93 | |
| 94 | out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL); |
| 95 | out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL); |
| 96 | sync(); |
| 97 | udelay(300); |
| 98 | |
| 99 | /* enable DDR controller */ |
| 100 | setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN); |
| 101 | /* now check the real size */ |
| 102 | disable_addr_trans(); |
Mario Six | 8a81bfd | 2019-01-21 09:18:15 +0100 | [diff] [blame] | 103 | msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize); |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 104 | enable_addr_trans(); |
| 105 | #endif |
| 106 | return msize; |
| 107 | } |
| 108 | |
| 109 | static int setup_sdram(void) |
| 110 | { |
| 111 | u32 msize = CONFIG_SYS_DDR_SIZE << 20; |
| 112 | long int size_01, size_02; |
| 113 | |
| 114 | size_01 = fixed_sdram(CONFIG_SYS_DDR_CONFIG); |
| 115 | size_02 = fixed_sdram(CONFIG_SYS_DDR_CONFIG_256); |
| 116 | |
| 117 | if (size_01 > size_02) |
| 118 | msize = fixed_sdram(CONFIG_SYS_DDR_CONFIG); |
| 119 | else |
| 120 | msize = size_02; |
| 121 | |
| 122 | return msize; |
| 123 | } |
| 124 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 125 | int dram_init(void) |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 126 | { |
| 127 | immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
| 128 | fsl_lbc_t *lbc = &im->im_lbc; |
| 129 | u32 msize = 0; |
| 130 | |
| 131 | if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im) |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 132 | return -ENXIO; |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 133 | |
| 134 | msize = setup_sdram(); |
| 135 | |
Mario Six | 42c9a49 | 2019-01-21 09:18:17 +0100 | [diff] [blame] | 136 | out_be32(&lbc->lbcr, (0x00040000 | (0xFF << LBCR_BMT_SHIFT) | 0xF)); |
| 137 | out_be32(&lbc->mrtpr, 0x20000000); |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 138 | sync(); |
| 139 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 140 | gd->ram_size = msize; |
| 141 | |
| 142 | return 0; |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame^] | 146 | int ft_board_setup(void *blob, struct bd_info *bd) |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 147 | { |
| 148 | ft_cpu_setup(blob, bd); |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 149 | |
| 150 | return 0; |
Heiko Schocher | eaf8c98 | 2014-01-25 07:53:48 +0100 | [diff] [blame] | 151 | } |
| 152 | #endif |
| 153 | |
| 154 | /* gpio mask for spi_cs */ |
| 155 | #define IDSCPLD_SPI_CS_MASK 0x00000001 |
| 156 | /* spi_cs multiplexed through cpld */ |
| 157 | #define IDSCPLD_SPI_CS_BASE (CONFIG_SYS_CPLD_BASE + 0xf) |
| 158 | |
| 159 | #if defined(CONFIG_MISC_INIT_R) |
| 160 | /* srp umcr mask for rts */ |
| 161 | #define IDSUMCR_RTS_MASK 0x04 |
| 162 | int misc_init_r(void) |
| 163 | { |
| 164 | /*srp*/ |
| 165 | duart83xx_t *uart1 = &((immap_t *)CONFIG_SYS_IMMR)->duart[0]; |
| 166 | duart83xx_t *uart2 = &((immap_t *)CONFIG_SYS_IMMR)->duart[1]; |
| 167 | |
| 168 | gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0]; |
| 169 | u8 *spi_base = (u8 *)IDSCPLD_SPI_CS_BASE; |
| 170 | |
| 171 | /* deactivate spi_cs channels */ |
| 172 | out_8(spi_base, 0); |
| 173 | /* deactivate the spi_cs */ |
| 174 | setbits_be32(&iopd->dir, IDSCPLD_SPI_CS_MASK); |
| 175 | /*srp - deactivate rts*/ |
| 176 | out_8(&uart1->umcr, IDSUMCR_RTS_MASK); |
| 177 | out_8(&uart2->umcr, IDSUMCR_RTS_MASK); |
| 178 | |
| 179 | |
| 180 | gd->fdt_blob = (void *)CONFIG_SYS_FLASH_BASE; |
| 181 | return 0; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | #ifdef CONFIG_MPC8XXX_SPI |
| 186 | /* |
| 187 | * The following are used to control the SPI chip selects |
| 188 | */ |
| 189 | int spi_cs_is_valid(unsigned int bus, unsigned int cs) |
| 190 | { |
| 191 | return bus == 0 && ((cs >= 0) && (cs <= 2)); |
| 192 | } |
| 193 | |
| 194 | void spi_cs_activate(struct spi_slave *slave) |
| 195 | { |
| 196 | gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0]; |
| 197 | u8 *spi_base = (u8 *)IDSCPLD_SPI_CS_BASE; |
| 198 | |
| 199 | /* select the spi_cs channel */ |
| 200 | out_8(spi_base, 1 << slave->cs); |
| 201 | /* activate the spi_cs */ |
| 202 | clrbits_be32(&iopd->dat, IDSCPLD_SPI_CS_MASK); |
| 203 | } |
| 204 | |
| 205 | void spi_cs_deactivate(struct spi_slave *slave) |
| 206 | { |
| 207 | gpio83xx_t *iopd = &((immap_t *)CONFIG_SYS_IMMR)->gpio[0]; |
| 208 | u8 *spi_base = (u8 *)IDSCPLD_SPI_CS_BASE; |
| 209 | |
| 210 | /* select the spi_cs channel */ |
| 211 | out_8(spi_base, 1 << slave->cs); |
| 212 | /* deactivate the spi_cs */ |
| 213 | setbits_be32(&iopd->dat, IDSCPLD_SPI_CS_MASK); |
| 214 | } |
Jagan Teki | 35f9d9b | 2018-11-24 14:31:12 +0530 | [diff] [blame] | 215 | #endif |