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