Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 2 | /* |
| 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 Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 10 | #include <env.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 11 | #include <hwconfig.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 12 | #include <init.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 13 | #include <mpc8xx.h> |
| 14 | #include <fdt_support.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 15 | #include <serial.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 17 | #include <asm/io.h> |
Christophe Leroy | 5d5675a | 2018-11-21 08:51:47 +0000 | [diff] [blame] | 18 | #include <dm/uclass.h> |
| 19 | #include <wdt.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 21 | |
| 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Christophe Leroy | c085795 | 2018-03-16 17:20:51 +0100 | [diff] [blame] | 24 | #define SDRAM_MAX_SIZE (32 * 1024 * 1024) |
| 25 | |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 26 | static const uint cs1_dram_table_66[] = { |
| 27 | /* DRAM - single read. (offset 0 in upm RAM) */ |
| 28 | 0x0F3DFC04, 0x0FEFBC04, 0x00BE7804, 0x0FFDF400, |
| 29 | 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 30 | |
| 31 | /* DRAM - burst read. (offset 8 in upm RAM) */ |
| 32 | 0x0F3DFC04, 0x0FEFBC04, 0x00BF7C04, 0x00FFFC00, |
| 33 | 0x00FFFC00, 0x00FEF800, 0x0FFDF400, 0x1FFFFC05, |
| 34 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 35 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 36 | |
| 37 | /* DRAM - single write. (offset 18 in upm RAM) */ |
| 38 | 0x0F3DFC04, 0x0FEFB800, 0x00BF7404, 0x0FFEF804, |
| 39 | 0x0FFDF404, 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, |
| 40 | |
| 41 | /* DRAM - burst write. (offset 20 in upm RAM) */ |
| 42 | 0x0F3DFC04, 0x0FEFB800, 0x00BF7400, 0x00FFFC00, |
| 43 | 0x00FFFC00, 0x00FFFC04, 0x0FFEF804, 0x0FFDF404, |
| 44 | 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 45 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 46 | |
| 47 | /* refresh (offset 30 in upm RAM) */ |
| 48 | 0x0FFDF404, 0x0FFEBC04, 0x0FFD7C84, 0x0FFFFC04, |
| 49 | 0x0FFFFC04, 0x0FFFFC04, 0x1FFFFC85, 0xFFFFFFFF, |
| 50 | |
| 51 | /* init */ |
| 52 | 0x0FEEB874, 0x0FBD7474, 0x1FFFFC45, 0xFFFFFFFF, |
| 53 | |
| 54 | /* exception. (offset 3c in upm RAM) */ |
| 55 | 0xFFFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 56 | }; |
| 57 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 58 | int ft_board_setup(void *blob, struct bd_info *bd) |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 59 | { |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 60 | ft_cpu_setup(blob, bd); |
| 61 | |
| 62 | /* BRG */ |
| 63 | do_fixup_by_path_u32(blob, "/soc/cpm", "brg-frequency", |
| 64 | bd->bi_busfreq, 1); |
| 65 | |
| 66 | /* MAC addr */ |
| 67 | fdt_fixup_ethernet(blob); |
| 68 | |
| 69 | /* Bus Frequency for CPM */ |
| 70 | do_fixup_by_path_u32(blob, "/soc", "bus-frequency", bd->bi_busfreq, 1); |
| 71 | |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | int checkboard(void) |
| 76 | { |
| 77 | serial_puts("BOARD: MCR3000 CSSI\n"); |
| 78 | |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | int dram_init(void) |
| 83 | { |
| 84 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 85 | memctl8xx_t __iomem *memctl = &immap->im_memctl; |
| 86 | |
| 87 | printf("UPMA init for SDRAM (CAS latency 2), "); |
| 88 | printf("init address 0x%08x, size ", (int)dram_init); |
| 89 | /* Configure UPMA for cs1 */ |
| 90 | upmconfig(UPMA, (uint *)cs1_dram_table_66, |
| 91 | sizeof(cs1_dram_table_66) / sizeof(uint)); |
| 92 | udelay(10); |
| 93 | out_be16(&memctl->memc_mptpr, 0x0200); |
| 94 | out_be32(&memctl->memc_mamr, 0x14904000); |
| 95 | udelay(10); |
| 96 | out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM); |
| 97 | out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM); |
| 98 | udelay(10); |
| 99 | out_be32(&memctl->memc_mcr, 0x80002830); |
| 100 | out_be32(&memctl->memc_mar, 0x00000088); |
| 101 | out_be32(&memctl->memc_mcr, 0x80002038); |
| 102 | udelay(200); |
| 103 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 104 | gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE, |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 105 | SDRAM_MAX_SIZE); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | int misc_init_r(void) |
| 111 | { |
| 112 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 113 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 114 | |
| 115 | /* Set port C13 as GPIO (BTN_ACQ_AL) */ |
| 116 | clrbits_be16(&iop->iop_pcpar, 0x4); |
| 117 | clrbits_be16(&iop->iop_pcdir, 0x4); |
| 118 | |
| 119 | /* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */ |
| 120 | if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 121 | env_set("bootdelay", "60"); |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | int board_early_init_f(void) |
| 127 | { |
| 128 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 129 | |
| 130 | /* |
| 131 | * Erase FPGA(s) for reboot |
| 132 | */ |
| 133 | clrbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA down */ |
| 134 | setbits_be32(&immr->im_cpm.cp_pbdir, 0x00020000); /* PROGFPGA output */ |
| 135 | udelay(1); /* Wait more than 300ns */ |
| 136 | setbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA up */ |
| 137 | |
| 138 | return 0; |
| 139 | } |