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