blob: 48e82a902d5f4e317863a560004fb09e592efb2e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Christophe Leroy35982952017-07-07 10:16:42 +02002/*
3 * Copyright (C) 2010-2017 CS Systemes d'Information
4 * Florent Trinh Thai <florent.trinh-thai@c-s.fr>
5 * Christophe Leroy <christophe.leroy@c-s.fr>
6 *
7 * Board specific routines for the MCR3000 board
Christophe Leroy35982952017-07-07 10:16:42 +02008 */
9
Simon Glass5e6201b2019-08-01 09:46:51 -060010#include <env.h>
Christophe Leroy35982952017-07-07 10:16:42 +020011#include <hwconfig.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Christophe Leroy35982952017-07-07 10:16:42 +020013#include <mpc8xx.h>
14#include <fdt_support.h>
Simon Glass36736182019-11-14 12:57:24 -070015#include <serial.h>
Christophe Leroy61d94852024-04-14 11:17:13 +020016#include <spi.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Christophe Leroy35982952017-07-07 10:16:42 +020018#include <asm/io.h>
Christophe Leroy5d5675a2018-11-21 08:51:47 +000019#include <dm/uclass.h>
20#include <wdt.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Christophe Leroy35982952017-07-07 10:16:42 +020022
Christophe Leroy61d94852024-04-14 11:17:13 +020023#include "fpga_code.h"
24
Christophe Leroy35982952017-07-07 10:16:42 +020025DECLARE_GLOBAL_DATA_PTR;
26
Christophe Leroyc0857952018-03-16 17:20:51 +010027#define SDRAM_MAX_SIZE (32 * 1024 * 1024)
28
Christophe Leroy35982952017-07-07 10:16:42 +020029static const uint cs1_dram_table_66[] = {
30 /* DRAM - single read. (offset 0 in upm RAM) */
31 0x0F3DFC04, 0x0FEFBC04, 0x00BE7804, 0x0FFDF400,
32 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
33
34 /* DRAM - burst read. (offset 8 in upm RAM) */
35 0x0F3DFC04, 0x0FEFBC04, 0x00BF7C04, 0x00FFFC00,
36 0x00FFFC00, 0x00FEF800, 0x0FFDF400, 0x1FFFFC05,
37 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
38 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
39
40 /* DRAM - single write. (offset 18 in upm RAM) */
41 0x0F3DFC04, 0x0FEFB800, 0x00BF7404, 0x0FFEF804,
42 0x0FFDF404, 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF,
43
44 /* DRAM - burst write. (offset 20 in upm RAM) */
45 0x0F3DFC04, 0x0FEFB800, 0x00BF7400, 0x00FFFC00,
46 0x00FFFC00, 0x00FFFC04, 0x0FFEF804, 0x0FFDF404,
47 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
48 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
49
50 /* refresh (offset 30 in upm RAM) */
51 0x0FFDF404, 0x0FFEBC04, 0x0FFD7C84, 0x0FFFFC04,
52 0x0FFFFC04, 0x0FFFFC04, 0x1FFFFC85, 0xFFFFFFFF,
53
54 /* init */
55 0x0FEEB874, 0x0FBD7474, 0x1FFFFC45, 0xFFFFFFFF,
56
57 /* exception. (offset 3c in upm RAM) */
58 0xFFFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
59};
60
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090061int ft_board_setup(void *blob, struct bd_info *bd)
Christophe Leroy35982952017-07-07 10:16:42 +020062{
Christophe Leroy35982952017-07-07 10:16:42 +020063 ft_cpu_setup(blob, bd);
64
65 /* BRG */
66 do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency",
67 bd->bi_busfreq, 1);
68
69 /* MAC addr */
70 fdt_fixup_ethernet(blob);
71
72 /* Bus Frequency for CPM */
73 do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
74
Christophe Leroy35982952017-07-07 10:16:42 +020075 return 0;
76}
77
78int checkboard(void)
79{
80 serial_puts("BOARD: MCR3000 CSSI\n");
81
82 return 0;
83}
84
85int dram_init(void)
86{
87 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
88 memctl8xx_t __iomem *memctl = &immap->im_memctl;
89
90 printf("UPMA init for SDRAM (CAS latency 2), ");
91 printf("init address 0x%08x, size ", (int)dram_init);
92 /* Configure UPMA for cs1 */
93 upmconfig(UPMA, (uint *)cs1_dram_table_66,
94 sizeof(cs1_dram_table_66) / sizeof(uint));
95 udelay(10);
96 out_be16(&memctl->memc_mptpr, 0x0200);
97 out_be32(&memctl->memc_mamr, 0x14904000);
98 udelay(10);
99 out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
100 out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
101 udelay(10);
102 out_be32(&memctl->memc_mcr, 0x80002830);
103 out_be32(&memctl->memc_mar, 0x00000088);
104 out_be32(&memctl->memc_mcr, 0x80002038);
105 udelay(200);
106
Tom Rinibb4dd962022-11-16 13:10:37 -0500107 gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE,
Christophe Leroy35982952017-07-07 10:16:42 +0200108 SDRAM_MAX_SIZE);
109
110 return 0;
111}
112
Christophe Leroy61d94852024-04-14 11:17:13 +0200113static int load_fpga(void)
114{
115 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
116 struct udevice *master;
117 struct spi_slave *slave;
118 int ret;
119
120 ret = uclass_get_device(UCLASS_SPI, 0, &master);
121 if (ret)
122 return ret;
123
124 ret = _spi_get_bus_and_cs(0, 1, 10000000, 0, "spi_generic_drv",
125 "generic_0:0", &master, &slave);
126 if (ret)
127 return ret;
128
129 ret = spi_claim_bus(slave);
130
131 printf("FPGA Init ... ");
132
133 clrbits_be32(&immr->im_cpm.cp_pbdat, 0x20000);
134 while ((in_be32(&immr->im_cpm.cp_pbdat) & 0x8000))
135 ;
136 setbits_be32(&immr->im_cpm.cp_pbdat, 0x20000);
137 while (!(in_be32(&immr->im_cpm.cp_pbdat) & 0x8000))
138 ;
139
140 printf("Loading ... ");
141
142 ret = spi_xfer(slave, sizeof(fpga_code) * BITS_PER_BYTE, fpga_code, NULL, 0);
143
144 spi_release_bus(slave);
145
146 if ((in_be32(&immr->im_cpm.cp_pbdat) & 0x4000)) {
147 printf("Done\n");
148 } else {
149 printf("FAILED\n");
150 ret = -EINVAL;
151 }
152
153 return ret;
154}
155
Christophe Leroy35982952017-07-07 10:16:42 +0200156int misc_init_r(void)
157{
158 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
159 iop8xx_t __iomem *iop = &immr->im_ioport;
160
161 /* Set port C13 as GPIO (BTN_ACQ_AL) */
162 clrbits_be16(&iop->iop_pcpar, 0x4);
163 clrbits_be16(&iop->iop_pcdir, 0x4);
164
Christophe Leroy0ee1ff82024-04-12 12:01:25 +0200165 /* Activate SPI */
166 clrsetbits_be32(&immr->im_cpm.cp_pbpar, 0x1, 0xe);
167 setbits_be32(&immr->im_cpm.cp_pbdir, 0xf);
168 clrbits_be32(&immr->im_cpm.cp_pbdat, 0x1);
169
Christophe Leroy77254252024-04-14 16:47:06 +0200170 if (!load_fpga()) {
171 u8 addr = in_be16((void *)0x1400009c);
172
173 printf("Board address: 0x%2.2x (System %d Rack %d Slot %d)\n",
174 addr, addr >> 7, (addr >> 4) & 7, addr & 15);
175 }
Christophe Leroy61d94852024-04-14 11:17:13 +0200176
Christophe Leroy35982952017-07-07 10:16:42 +0200177 /* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */
178 if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
Simon Glass6a38e412017-08-03 12:22:09 -0600179 env_set("bootdelay", "60");
Christophe Leroy35982952017-07-07 10:16:42 +0200180
181 return 0;
182}
183
184int board_early_init_f(void)
185{
186 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
187
188 /*
189 * Erase FPGA(s) for reboot
190 */
191 clrbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA down */
192 setbits_be32(&immr->im_cpm.cp_pbdir, 0x00020000); /* PROGFPGA output */
193 udelay(1); /* Wait more than 300ns */
194 setbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA up */
195
196 return 0;
197}