blob: d0d34012d74fd4b12e4b5dcef008721650a3191e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schochereaf8c982014-01-25 07:53:48 +01002/*
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 Schochereaf8c982014-01-25 07:53:48 +010012 */
13
14#include <common.h>
Simon Glass807765b2019-12-28 10:44:54 -070015#include <fdt_support.h>
Simon Glass9b4a2052019-12-28 10:45:05 -070016#include <init.h>
Heiko Schochereaf8c982014-01-25 07:53:48 +010017#include <mpc83xx.h>
18#include <spi.h>
Simon Glasscd93d622020-05-10 11:40:13 -060019#include <asm/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060020#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090021#include <linux/libfdt.h>
Heiko Schochereaf8c982014-01-25 07:53:48 +010022
23DECLARE_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 */
29int 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 */
55int 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 Six133ec602019-01-21 09:18:16 +010064 (CONFIG_SYS_SDRAM_BASE & 0xfffff000));
Heiko Schochereaf8c982014-01-25 07:53:48 +010065 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 Six8a81bfd2019-01-21 09:18:15 +0100103 msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Heiko Schochereaf8c982014-01-25 07:53:48 +0100104 enable_addr_trans();
105#endif
106 return msize;
107}
108
109static 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 Glassf1683aa2017-04-06 12:47:05 -0600125int dram_init(void)
Heiko Schochereaf8c982014-01-25 07:53:48 +0100126{
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 Glass088454c2017-03-31 08:40:25 -0600132 return -ENXIO;
Heiko Schochereaf8c982014-01-25 07:53:48 +0100133
134 msize = setup_sdram();
135
Mario Six42c9a492019-01-21 09:18:17 +0100136 out_be32(&lbc->lbcr, (0x00040000 | (0xFF << LBCR_BMT_SHIFT) | 0xF));
137 out_be32(&lbc->mrtpr, 0x20000000);
Heiko Schochereaf8c982014-01-25 07:53:48 +0100138 sync();
139
Simon Glass088454c2017-03-31 08:40:25 -0600140 gd->ram_size = msize;
141
142 return 0;
Heiko Schochereaf8c982014-01-25 07:53:48 +0100143}
144
145#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600146int ft_board_setup(void *blob, bd_t *bd)
Heiko Schochereaf8c982014-01-25 07:53:48 +0100147{
148 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600149
150 return 0;
Heiko Schochereaf8c982014-01-25 07:53:48 +0100151}
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
162int 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 */
189int spi_cs_is_valid(unsigned int bus, unsigned int cs)
190{
191 return bus == 0 && ((cs >= 0) && (cs <= 2));
192}
193
194void 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
205void 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 Teki35f9d9b2018-11-24 14:31:12 +0530215#endif