153193a4fSChristophe Leroy /*
253193a4fSChristophe Leroy * Copyright (C) 2010-2017 CS Systemes d'Information
353193a4fSChristophe Leroy * Florent Trinh Thai <florent.trinh-thai@c-s.fr>
453193a4fSChristophe Leroy * Christophe Leroy <christophe.leroy@c-s.fr>
553193a4fSChristophe Leroy *
653193a4fSChristophe Leroy * Board specific routines for the MCR3000 board
753193a4fSChristophe Leroy *
853193a4fSChristophe Leroy * SPDX-License-Identifier: GPL-2.0+
953193a4fSChristophe Leroy */
1053193a4fSChristophe Leroy
1153193a4fSChristophe Leroy #include <common.h>
1253193a4fSChristophe Leroy #include <hwconfig.h>
1353193a4fSChristophe Leroy #include <mpc8xx.h>
1453193a4fSChristophe Leroy #include <fdt_support.h>
1553193a4fSChristophe Leroy #include <asm/io.h>
1653193a4fSChristophe Leroy
1753193a4fSChristophe Leroy DECLARE_GLOBAL_DATA_PTR;
1853193a4fSChristophe Leroy
1953193a4fSChristophe Leroy static const uint cs1_dram_table_66[] = {
2053193a4fSChristophe Leroy /* DRAM - single read. (offset 0 in upm RAM) */
2153193a4fSChristophe Leroy 0x0F3DFC04, 0x0FEFBC04, 0x00BE7804, 0x0FFDF400,
2253193a4fSChristophe Leroy 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2353193a4fSChristophe Leroy
2453193a4fSChristophe Leroy /* DRAM - burst read. (offset 8 in upm RAM) */
2553193a4fSChristophe Leroy 0x0F3DFC04, 0x0FEFBC04, 0x00BF7C04, 0x00FFFC00,
2653193a4fSChristophe Leroy 0x00FFFC00, 0x00FEF800, 0x0FFDF400, 0x1FFFFC05,
2753193a4fSChristophe Leroy 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2853193a4fSChristophe Leroy 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
2953193a4fSChristophe Leroy
3053193a4fSChristophe Leroy /* DRAM - single write. (offset 18 in upm RAM) */
3153193a4fSChristophe Leroy 0x0F3DFC04, 0x0FEFB800, 0x00BF7404, 0x0FFEF804,
3253193a4fSChristophe Leroy 0x0FFDF404, 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF,
3353193a4fSChristophe Leroy
3453193a4fSChristophe Leroy /* DRAM - burst write. (offset 20 in upm RAM) */
3553193a4fSChristophe Leroy 0x0F3DFC04, 0x0FEFB800, 0x00BF7400, 0x00FFFC00,
3653193a4fSChristophe Leroy 0x00FFFC00, 0x00FFFC04, 0x0FFEF804, 0x0FFDF404,
3753193a4fSChristophe Leroy 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3853193a4fSChristophe Leroy 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
3953193a4fSChristophe Leroy
4053193a4fSChristophe Leroy /* refresh (offset 30 in upm RAM) */
4153193a4fSChristophe Leroy 0x0FFDF404, 0x0FFEBC04, 0x0FFD7C84, 0x0FFFFC04,
4253193a4fSChristophe Leroy 0x0FFFFC04, 0x0FFFFC04, 0x1FFFFC85, 0xFFFFFFFF,
4353193a4fSChristophe Leroy
4453193a4fSChristophe Leroy /* init */
4553193a4fSChristophe Leroy 0x0FEEB874, 0x0FBD7474, 0x1FFFFC45, 0xFFFFFFFF,
4653193a4fSChristophe Leroy
4753193a4fSChristophe Leroy /* exception. (offset 3c in upm RAM) */
4853193a4fSChristophe Leroy 0xFFFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
4953193a4fSChristophe Leroy };
5053193a4fSChristophe Leroy
ft_board_setup(void * blob,bd_t * bd)5153193a4fSChristophe Leroy int ft_board_setup(void *blob, bd_t *bd)
5253193a4fSChristophe Leroy {
5353193a4fSChristophe Leroy const char *sync = "receive";
5453193a4fSChristophe Leroy
5553193a4fSChristophe Leroy ft_cpu_setup(blob, bd);
5653193a4fSChristophe Leroy
5753193a4fSChristophe Leroy /* BRG */
5853193a4fSChristophe Leroy do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency",
5953193a4fSChristophe Leroy bd->bi_busfreq, 1);
6053193a4fSChristophe Leroy
6153193a4fSChristophe Leroy /* MAC addr */
6253193a4fSChristophe Leroy fdt_fixup_ethernet(blob);
6353193a4fSChristophe Leroy
6453193a4fSChristophe Leroy /* Bus Frequency for CPM */
6553193a4fSChristophe Leroy do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1);
6653193a4fSChristophe Leroy
6753193a4fSChristophe Leroy /* E1 interface - Set data rate */
6853193a4fSChristophe Leroy do_fixup_by_path_u32(blob, "/localbus/e1-wan", "data-rate", 2, 1);
6953193a4fSChristophe Leroy
7053193a4fSChristophe Leroy /* E1 interface - Set channel phase to 0 */
7153193a4fSChristophe Leroy do_fixup_by_path_u32(blob, "/localbus/e1-wan", "channel-phase", 0, 1);
7253193a4fSChristophe Leroy
7353193a4fSChristophe Leroy /* E1 interface - rising edge sync pulse transmit */
7453193a4fSChristophe Leroy do_fixup_by_path(blob, "/localbus/e1-wan", "rising-edge-sync-pulse",
7553193a4fSChristophe Leroy sync, strlen(sync), 1);
7653193a4fSChristophe Leroy
7753193a4fSChristophe Leroy return 0;
7853193a4fSChristophe Leroy }
7953193a4fSChristophe Leroy
checkboard(void)8053193a4fSChristophe Leroy int checkboard(void)
8153193a4fSChristophe Leroy {
8253193a4fSChristophe Leroy serial_puts("BOARD: MCR3000 CSSI\n");
8353193a4fSChristophe Leroy
8453193a4fSChristophe Leroy return 0;
8553193a4fSChristophe Leroy }
8653193a4fSChristophe Leroy
dram_init(void)8753193a4fSChristophe Leroy int dram_init(void)
8853193a4fSChristophe Leroy {
8953193a4fSChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
9053193a4fSChristophe Leroy memctl8xx_t __iomem *memctl = &immap->im_memctl;
9153193a4fSChristophe Leroy
9253193a4fSChristophe Leroy printf("UPMA init for SDRAM (CAS latency 2), ");
9353193a4fSChristophe Leroy printf("init address 0x%08x, size ", (int)dram_init);
9453193a4fSChristophe Leroy /* Configure UPMA for cs1 */
9553193a4fSChristophe Leroy upmconfig(UPMA, (uint *)cs1_dram_table_66,
9653193a4fSChristophe Leroy sizeof(cs1_dram_table_66) / sizeof(uint));
9753193a4fSChristophe Leroy udelay(10);
9853193a4fSChristophe Leroy out_be16(&memctl->memc_mptpr, 0x0200);
9953193a4fSChristophe Leroy out_be32(&memctl->memc_mamr, 0x14904000);
10053193a4fSChristophe Leroy udelay(10);
10153193a4fSChristophe Leroy out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM);
10253193a4fSChristophe Leroy out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM);
10353193a4fSChristophe Leroy udelay(10);
10453193a4fSChristophe Leroy out_be32(&memctl->memc_mcr, 0x80002830);
10553193a4fSChristophe Leroy out_be32(&memctl->memc_mar, 0x00000088);
10653193a4fSChristophe Leroy out_be32(&memctl->memc_mcr, 0x80002038);
10753193a4fSChristophe Leroy udelay(200);
10853193a4fSChristophe Leroy
10953193a4fSChristophe Leroy gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE,
11053193a4fSChristophe Leroy SDRAM_MAX_SIZE);
11153193a4fSChristophe Leroy
11253193a4fSChristophe Leroy return 0;
11353193a4fSChristophe Leroy }
11453193a4fSChristophe Leroy
misc_init_r(void)11553193a4fSChristophe Leroy int misc_init_r(void)
11653193a4fSChristophe Leroy {
11753193a4fSChristophe Leroy immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
11853193a4fSChristophe Leroy iop8xx_t __iomem *iop = &immr->im_ioport;
11953193a4fSChristophe Leroy
12053193a4fSChristophe Leroy /* Set port C13 as GPIO (BTN_ACQ_AL) */
12153193a4fSChristophe Leroy clrbits_be16(&iop->iop_pcpar, 0x4);
12253193a4fSChristophe Leroy clrbits_be16(&iop->iop_pcdir, 0x4);
12353193a4fSChristophe Leroy
12453193a4fSChristophe Leroy /* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */
12553193a4fSChristophe Leroy if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0)
126*382bee57SSimon Glass env_set("bootdelay", "60");
12753193a4fSChristophe Leroy
12853193a4fSChristophe Leroy return 0;
12953193a4fSChristophe Leroy }
13053193a4fSChristophe Leroy
board_early_init_f(void)13153193a4fSChristophe Leroy int board_early_init_f(void)
13253193a4fSChristophe Leroy {
13353193a4fSChristophe Leroy immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR;
13453193a4fSChristophe Leroy
13553193a4fSChristophe Leroy /*
13653193a4fSChristophe Leroy * Erase FPGA(s) for reboot
13753193a4fSChristophe Leroy */
13853193a4fSChristophe Leroy clrbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA down */
13953193a4fSChristophe Leroy setbits_be32(&immr->im_cpm.cp_pbdir, 0x00020000); /* PROGFPGA output */
14053193a4fSChristophe Leroy udelay(1); /* Wait more than 300ns */
14153193a4fSChristophe Leroy setbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA up */
14253193a4fSChristophe Leroy
14353193a4fSChristophe Leroy return 0;
14453193a4fSChristophe Leroy }
145