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 | |
| 10 | #include <common.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 12 | #include <hwconfig.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 13 | #include <init.h> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 14 | #include <mpc8xx.h> |
| 15 | #include <fdt_support.h> |
Simon Glass | 3673618 | 2019-11-14 12:57:24 -0700 | [diff] [blame] | 16 | #include <serial.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> |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Christophe Leroy | c085795 | 2018-03-16 17:20:51 +0100 | [diff] [blame] | 23 | #define SDRAM_MAX_SIZE (32 * 1024 * 1024) |
| 24 | |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 25 | static const uint cs1_dram_table_66[] = { |
| 26 | /* DRAM - single read. (offset 0 in upm RAM) */ |
| 27 | 0x0F3DFC04, 0x0FEFBC04, 0x00BE7804, 0x0FFDF400, |
| 28 | 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 29 | |
| 30 | /* DRAM - burst read. (offset 8 in upm RAM) */ |
| 31 | 0x0F3DFC04, 0x0FEFBC04, 0x00BF7C04, 0x00FFFC00, |
| 32 | 0x00FFFC00, 0x00FEF800, 0x0FFDF400, 0x1FFFFC05, |
| 33 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 34 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 35 | |
| 36 | /* DRAM - single write. (offset 18 in upm RAM) */ |
| 37 | 0x0F3DFC04, 0x0FEFB800, 0x00BF7404, 0x0FFEF804, |
| 38 | 0x0FFDF404, 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, |
| 39 | |
| 40 | /* DRAM - burst write. (offset 20 in upm RAM) */ |
| 41 | 0x0F3DFC04, 0x0FEFB800, 0x00BF7400, 0x00FFFC00, |
| 42 | 0x00FFFC00, 0x00FFFC04, 0x0FFEF804, 0x0FFDF404, |
| 43 | 0x1FFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 44 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 45 | |
| 46 | /* refresh (offset 30 in upm RAM) */ |
| 47 | 0x0FFDF404, 0x0FFEBC04, 0x0FFD7C84, 0x0FFFFC04, |
| 48 | 0x0FFFFC04, 0x0FFFFC04, 0x1FFFFC85, 0xFFFFFFFF, |
| 49 | |
| 50 | /* init */ |
| 51 | 0x0FEEB874, 0x0FBD7474, 0x1FFFFC45, 0xFFFFFFFF, |
| 52 | |
| 53 | /* exception. (offset 3c in upm RAM) */ |
| 54 | 0xFFFFFC05, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 55 | }; |
| 56 | |
| 57 | int ft_board_setup(void *blob, bd_t *bd) |
| 58 | { |
| 59 | const char *sync = "receive"; |
| 60 | |
| 61 | 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 | |
| 73 | /* E1 interface - Set data rate */ |
| 74 | do_fixup_by_path_u32(blob, "/localbus/e1-wan", "data-rate", 2, 1); |
| 75 | |
| 76 | /* E1 interface - Set channel phase to 0 */ |
| 77 | do_fixup_by_path_u32(blob, "/localbus/e1-wan", "channel-phase", 0, 1); |
| 78 | |
| 79 | /* E1 interface - rising edge sync pulse transmit */ |
| 80 | do_fixup_by_path(blob, "/localbus/e1-wan", "rising-edge-sync-pulse", |
| 81 | sync, strlen(sync), 1); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | int checkboard(void) |
| 87 | { |
| 88 | serial_puts("BOARD: MCR3000 CSSI\n"); |
| 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int dram_init(void) |
| 94 | { |
| 95 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 96 | memctl8xx_t __iomem *memctl = &immap->im_memctl; |
| 97 | |
| 98 | printf("UPMA init for SDRAM (CAS latency 2), "); |
| 99 | printf("init address 0x%08x, size ", (int)dram_init); |
| 100 | /* Configure UPMA for cs1 */ |
| 101 | upmconfig(UPMA, (uint *)cs1_dram_table_66, |
| 102 | sizeof(cs1_dram_table_66) / sizeof(uint)); |
| 103 | udelay(10); |
| 104 | out_be16(&memctl->memc_mptpr, 0x0200); |
| 105 | out_be32(&memctl->memc_mamr, 0x14904000); |
| 106 | udelay(10); |
| 107 | out_be32(&memctl->memc_or1, CONFIG_SYS_OR1_PRELIM); |
| 108 | out_be32(&memctl->memc_br1, CONFIG_SYS_BR1_PRELIM); |
| 109 | udelay(10); |
| 110 | out_be32(&memctl->memc_mcr, 0x80002830); |
| 111 | out_be32(&memctl->memc_mar, 0x00000088); |
| 112 | out_be32(&memctl->memc_mcr, 0x80002038); |
| 113 | udelay(200); |
| 114 | |
| 115 | gd->ram_size = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, |
| 116 | SDRAM_MAX_SIZE); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | int misc_init_r(void) |
| 122 | { |
| 123 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 124 | iop8xx_t __iomem *iop = &immr->im_ioport; |
| 125 | |
| 126 | /* Set port C13 as GPIO (BTN_ACQ_AL) */ |
| 127 | clrbits_be16(&iop->iop_pcpar, 0x4); |
| 128 | clrbits_be16(&iop->iop_pcdir, 0x4); |
| 129 | |
| 130 | /* if BTN_ACQ_AL is pressed then bootdelay is changed to 60 second */ |
| 131 | if ((in_be16(&iop->iop_pcdat) & 0x0004) == 0) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 132 | env_set("bootdelay", "60"); |
Christophe Leroy | 3598295 | 2017-07-07 10:16:42 +0200 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | int board_early_init_f(void) |
| 138 | { |
| 139 | immap_t __iomem *immr = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 140 | |
| 141 | /* |
| 142 | * Erase FPGA(s) for reboot |
| 143 | */ |
| 144 | clrbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA down */ |
| 145 | setbits_be32(&immr->im_cpm.cp_pbdir, 0x00020000); /* PROGFPGA output */ |
| 146 | udelay(1); /* Wait more than 300ns */ |
| 147 | setbits_be32(&immr->im_cpm.cp_pbdat, 0x00020000); /* PROGFPGA up */ |
| 148 | |
| 149 | return 0; |
| 150 | } |
Christophe Leroy | 5d5675a | 2018-11-21 08:51:47 +0000 | [diff] [blame] | 151 | |
| 152 | int board_early_init_r(void) |
| 153 | { |
| 154 | struct udevice *watchdog_dev = NULL; |
| 155 | |
| 156 | if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) { |
| 157 | puts("Cannot find watchdog!\n"); |
| 158 | } else { |
| 159 | puts("Enabling watchdog.\n"); |
| 160 | wdt_start(watchdog_dev, 0xffff, 0); |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | } |