blob: 3514f6749014ab0bb004403df31080110bcb2759 [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
10#include <common.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Christophe Leroy35982952017-07-07 10:16:42 +020012#include <hwconfig.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Christophe Leroy35982952017-07-07 10:16:42 +020014#include <mpc8xx.h>
15#include <fdt_support.h>
Simon Glass36736182019-11-14 12:57:24 -070016#include <serial.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
23DECLARE_GLOBAL_DATA_PTR;
24
Christophe Leroyc0857952018-03-16 17:20:51 +010025#define SDRAM_MAX_SIZE (32 * 1024 * 1024)
26
Christophe Leroy35982952017-07-07 10:16:42 +020027static const uint cs1_dram_table_66[] = {
28 /* DRAM - single read. (offset 0 in upm RAM) */
29 0x0F3DFC04, 0x0FEFBC04, 0x00BE7804, 0x0FFDF400,
30 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
31
32 /* DRAM - burst read. (offset 8 in upm RAM) */
33 0x0F3DFC04, 0x0FEFBC04, 0x00BF7C04, 0x00FFFC00,
34 0x00FFFC00, 0x00FEF800, 0x0FFDF400, 0x1FFFFC05,
35 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
36 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
37
38 /* DRAM - single write. (offset 18 in upm RAM) */
39 0x0F3DFC04, 0x0FEFB800, 0x00BF7404, 0x0FFEF804,
40 0x0FFDF404, 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF,
41
42 /* DRAM - burst write. (offset 20 in upm RAM) */
43 0x0F3DFC04, 0x0FEFB800, 0x00BF7400, 0x00FFFC00,
44 0x00FFFC00, 0x00FFFC04, 0x0FFEF804, 0x0FFDF404,
45 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
46 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
47
48 /* refresh (offset 30 in upm RAM) */
49 0x0FFDF404, 0x0FFEBC04, 0x0FFD7C84, 0x0FFFFC04,
50 0x0FFFFC04, 0x0FFFFC04, 0x1FFFFC85, 0xFFFFFFFF,
51
52 /* init */
53 0x0FEEB874, 0x0FBD7474, 0x1FFFFC45, 0xFFFFFFFF,
54
55 /* exception. (offset 3c in upm RAM) */
56 0xFFFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
57};
58
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090059int ft_board_setup(void *blob, struct bd_info *bd)
Christophe Leroy35982952017-07-07 10:16:42 +020060{
Christophe Leroy35982952017-07-07 10:16:42 +020061 ft_cpu_setup(blob, bd);
62
63 /* BRG */
64 do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency",
65 bd->bi_busfreq, 1);
66
67 /* MAC addr */
68 fdt_fixup_ethernet(blob);
69
70 /* Bus Frequency for CPM */
71 do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
72
Christophe Leroy35982952017-07-07 10:16:42 +020073 return 0;
74}
75
76int checkboard(void)
77{
78 serial_puts("BOARD: MCR3000 CSSI\n");
79
80 return 0;
81}
82
83int dram_init(void)
84{
85 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
86 memctl8xx_t __iomem *memctl = &immap->im_memctl;
87
88 printf("UPMA init for SDRAM (CAS latency 2), ");
89 printf("init address 0x%08x, size ", (int)dram_init);
90 /* Configure UPMA for cs1 */
91 upmconfig(UPMA, (uint *)cs1_dram_table_66,
92 sizeof(cs1_dram_table_66) / sizeof(uint));
93 udelay(10);
94 out_be16(&memctl->memc_mptpr, 0x0200);
95 out_be32(&memctl->memc_mamr, 0x14904000);
96 udelay(10);
97 out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
98 out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
99 udelay(10);
100 out_be32(&memctl->memc_mcr, 0x80002830);
101 out_be32(&memctl->memc_mar, 0x00000088);
102 out_be32(&memctl->memc_mcr, 0x80002038);
103 udelay(200);
104
Tom Rinibb4dd962022-11-16 13:10:37 -0500105 gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE,
Christophe Leroy35982952017-07-07 10:16:42 +0200106 SDRAM_MAX_SIZE);
107
108 return 0;
109}
110
111int misc_init_r(void)
112{
113 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
114 iop8xx_t __iomem *iop = &immr->im_ioport;
115
116 /* Set port C13 as GPIO (BTN_ACQ_AL) */
117 clrbits_be16(&iop->iop_pcpar, 0x4);
118 clrbits_be16(&iop->iop_pcdir, 0x4);
119
120 /* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */
121 if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
Simon Glass6a38e412017-08-03 12:22:09 -0600122 env_set("bootdelay", "60");
Christophe Leroy35982952017-07-07 10:16:42 +0200123
124 return 0;
125}
126
127int board_early_init_f(void)
128{
129 immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
130
131 /*
132 * Erase FPGA(s) for reboot
133 */
134 clrbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA down */
135 setbits_be32(&immr->im_cpm.cp_pbdir, 0x00020000); /* PROGFPGA output */
136 udelay(1); /* Wait more than 300ns */
137 setbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA up */
138
139 return 0;
140}