Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | fcdbbec | 2016-07-22 13:38:32 +0900 | [diff] [blame] | 3 | * Copyright (C) 2011-2014 Panasonic Corporation |
| 4 | * Copyright (C) 2015-2016 Socionext Inc. |
| 5 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Masahiro Yamada | e4e789d | 2017-01-21 18:05:24 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 10 | #include <linux/io.h> |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 11 | #include <linux/sizes.h> |
Masahiro Yamada | f734aa9 | 2016-02-26 14:21:52 +0900 | [diff] [blame] | 12 | #include <asm/processor.h> |
Masahiro Yamada | efdf340 | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 13 | |
| 14 | #include "../init.h" |
Masahiro Yamada | b464ff9 | 2016-10-27 23:47:07 +0900 | [diff] [blame] | 15 | #include "ddrphy-init.h" |
Masahiro Yamada | efdf340 | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 16 | #include "umc-regs.h" |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 17 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 18 | #define DRAM_CH_NR 2 |
| 19 | |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 20 | enum dram_freq { |
| 21 | DRAM_FREQ_1333M, |
| 22 | DRAM_FREQ_1600M, |
| 23 | DRAM_FREQ_NR, |
| 24 | }; |
| 25 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 26 | enum dram_size { |
| 27 | DRAM_SZ_128M, |
| 28 | DRAM_SZ_256M, |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 29 | DRAM_SZ_512M, |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 30 | DRAM_SZ_NR, |
| 31 | }; |
| 32 | |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 33 | static u32 umc_cmdctla[DRAM_FREQ_NR] = {0x55990b11, 0x66bb0f17}; |
| 34 | static u32 umc_cmdctla_plus[DRAM_FREQ_NR] = {0x45990b11, 0x46bb0f17}; |
| 35 | static u32 umc_cmdctlb[DRAM_FREQ_NR] = {0x16958944, 0x18c6ab44}; |
| 36 | static u32 umc_cmdctlb_plus[DRAM_FREQ_NR] = {0x16958924, 0x18c6ab24}; |
| 37 | static u32 umc_spcctla[DRAM_FREQ_NR][DRAM_SZ_NR] = { |
| 38 | {0x00240512, 0x00350512, 0x00000000}, /* no data for 1333MHz,128MB */ |
| 39 | {0x002b0617, 0x003f0617, 0x00670617}, |
| 40 | }; |
| 41 | static u32 umc_spcctlb[DRAM_FREQ_NR] = {0x00ff0006, 0x00ff0008}; |
| 42 | static u32 umc_rdatactl[DRAM_FREQ_NR] = {0x000a00ac, 0x000c00ac}; |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 43 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 44 | static int umc_get_rank(int ch) |
| 45 | { |
| 46 | return ch; /* ch0: rank0, ch1: rank1 for this SoC */ |
| 47 | } |
| 48 | |
Masahiro Yamada | 3cf2e41 | 2015-01-21 15:06:46 +0900 | [diff] [blame] | 49 | static void umc_start_ssif(void __iomem *ssif_base) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 50 | { |
| 51 | writel(0x00000000, ssif_base + 0x0000b004); |
| 52 | writel(0xffffffff, ssif_base + 0x0000c004); |
| 53 | writel(0x000fffcf, ssif_base + 0x0000c008); |
| 54 | writel(0x00000001, ssif_base + 0x0000b000); |
| 55 | writel(0x00000001, ssif_base + 0x0000c000); |
| 56 | writel(0x03010101, ssif_base + UMC_MDMCHSEL); |
| 57 | writel(0x03010100, ssif_base + UMC_DMDCHSEL); |
| 58 | |
| 59 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH); |
| 60 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0); |
| 61 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0); |
| 62 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0); |
| 63 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1); |
| 64 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1); |
| 65 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1); |
| 66 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC); |
| 67 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC); |
| 68 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST); |
| 69 | |
| 70 | writel(0x00000001, ssif_base + UMC_CPURST); |
| 71 | writel(0x00000001, ssif_base + UMC_IDSRST); |
| 72 | writel(0x00000001, ssif_base + UMC_IXMRST); |
| 73 | writel(0x00000001, ssif_base + UMC_MDMRST); |
| 74 | writel(0x00000001, ssif_base + UMC_MDDRST); |
| 75 | writel(0x00000001, ssif_base + UMC_SIORST); |
| 76 | writel(0x00000001, ssif_base + UMC_VIORST); |
| 77 | writel(0x00000001, ssif_base + UMC_FRCRST); |
| 78 | writel(0x00000001, ssif_base + UMC_RGLRST); |
| 79 | writel(0x00000001, ssif_base + UMC_AIORST); |
| 80 | writel(0x00000001, ssif_base + UMC_DMDRST); |
| 81 | } |
| 82 | |
Masahiro Yamada | 392ecb6 | 2016-02-26 14:21:53 +0900 | [diff] [blame] | 83 | static int umc_dramcont_init(void __iomem *dc_base, void __iomem *ca_base, |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 84 | int freq, unsigned long size, bool ddr3plus) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 85 | { |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 86 | enum dram_freq freq_e; |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 87 | enum dram_size size_e; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 88 | |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 89 | switch (freq) { |
| 90 | case 1333: |
| 91 | freq_e = DRAM_FREQ_1333M; |
| 92 | break; |
| 93 | case 1600: |
| 94 | freq_e = DRAM_FREQ_1600M; |
| 95 | break; |
| 96 | default: |
| 97 | pr_err("unsupported DRAM frequency %d MHz\n", freq); |
| 98 | return -EINVAL; |
| 99 | } |
| 100 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 101 | switch (size) { |
| 102 | case 0: |
| 103 | return 0; |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 104 | case SZ_128M: |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 105 | size_e = DRAM_SZ_128M; |
| 106 | break; |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 107 | case SZ_256M: |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 108 | size_e = DRAM_SZ_256M; |
| 109 | break; |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 110 | case SZ_512M: |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 111 | size_e = DRAM_SZ_512M; |
| 112 | break; |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 113 | default: |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 114 | pr_err("unsupported DRAM size 0x%08lx\n", size); |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 115 | return -EINVAL; |
| 116 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 117 | |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 118 | writel((ddr3plus ? umc_cmdctla_plus : umc_cmdctla)[freq_e], |
Masahiro Yamada | 392ecb6 | 2016-02-26 14:21:53 +0900 | [diff] [blame] | 119 | dc_base + UMC_CMDCTLA); |
Masahiro Yamada | 547f6f6 | 2016-02-26 14:21:45 +0900 | [diff] [blame] | 120 | writel((ddr3plus ? umc_cmdctlb_plus : umc_cmdctlb)[freq_e], |
Masahiro Yamada | 392ecb6 | 2016-02-26 14:21:53 +0900 | [diff] [blame] | 121 | dc_base + UMC_CMDCTLB); |
| 122 | writel(umc_spcctla[freq_e][size_e], dc_base + UMC_SPCCTLA); |
| 123 | writel(umc_spcctlb[freq_e], dc_base + UMC_SPCCTLB); |
| 124 | writel(umc_rdatactl[freq_e], dc_base + UMC_RDATACTL_D0); |
| 125 | writel(0x04060806, dc_base + UMC_WDATACTL_D0); |
| 126 | writel(0x04a02000, dc_base + UMC_DATASET); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 127 | writel(0x00000000, ca_base + 0x2300); |
Masahiro Yamada | 392ecb6 | 2016-02-26 14:21:53 +0900 | [diff] [blame] | 128 | writel(0x00400020, dc_base + UMC_DCCGCTL); |
| 129 | writel(0x00000003, dc_base + 0x7000); |
| 130 | writel(0x0000004f, dc_base + 0x8000); |
| 131 | writel(0x000000c3, dc_base + 0x8004); |
| 132 | writel(0x00000077, dc_base + 0x8008); |
| 133 | writel(0x0000003b, dc_base + UMC_DICGCTLA); |
| 134 | writel(0x020a0808, dc_base + UMC_DICGCTLB); |
| 135 | writel(0x00000004, dc_base + UMC_FLOWCTLG); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 136 | writel(0x80000201, ca_base + 0xc20); |
Masahiro Yamada | 392ecb6 | 2016-02-26 14:21:53 +0900 | [diff] [blame] | 137 | writel(0x0801e01e, dc_base + UMC_FLOWCTLA); |
| 138 | writel(0x00200000, dc_base + UMC_FLOWCTLB); |
| 139 | writel(0x00004444, dc_base + UMC_FLOWCTLC); |
| 140 | writel(0x200a0a00, dc_base + UMC_SPCSETB); |
| 141 | writel(0x00000000, dc_base + UMC_SPCSETD); |
| 142 | writel(0x00000520, dc_base + UMC_DFICUPDCTLA); |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame] | 143 | |
| 144 | return 0; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 147 | static int umc_ch_init(void __iomem *dc_base, void __iomem *ca_base, |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 148 | int freq, unsigned long size, bool ddr3plus, int ch) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 149 | { |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 150 | void __iomem *phy_base = dc_base + 0x00001000; |
| 151 | int ret; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 152 | |
Masahiro Yamada | f734aa9 | 2016-02-26 14:21:52 +0900 | [diff] [blame] | 153 | writel(UMC_INITSET_INIT1EN, dc_base + UMC_INITSET); |
Masahiro Yamada | b018e26 | 2016-10-27 23:47:04 +0900 | [diff] [blame] | 154 | while (readl(dc_base + UMC_INITSTAT) & UMC_INITSTAT_INIT1ST) |
Masahiro Yamada | f734aa9 | 2016-02-26 14:21:52 +0900 | [diff] [blame] | 155 | cpu_relax(); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 156 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 157 | writel(0x00000101, dc_base + UMC_DIOCTLA); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 158 | |
Masahiro Yamada | 9890569 | 2016-03-30 20:17:02 +0900 | [diff] [blame] | 159 | ret = uniphier_ld4_ddrphy_init(phy_base, freq, ddr3plus); |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 160 | if (ret) |
| 161 | return ret; |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 162 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 163 | ddrphy_prepare_training(phy_base, umc_get_rank(ch)); |
| 164 | ret = ddrphy_training(phy_base); |
| 165 | if (ret) |
| 166 | return ret; |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 167 | |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 168 | return umc_dramcont_init(dc_base, ca_base, freq, size, ddr3plus); |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 169 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 170 | |
Masahiro Yamada | 9890569 | 2016-03-30 20:17:02 +0900 | [diff] [blame] | 171 | int uniphier_sld8_umc_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 172 | { |
| 173 | void __iomem *umc_base = (void __iomem *)0x5b800000; |
| 174 | void __iomem *ca_base = umc_base + 0x00001000; |
| 175 | void __iomem *dc_base = umc_base + 0x00400000; |
| 176 | void __iomem *ssif_base = umc_base; |
| 177 | int ch, ret; |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 178 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 179 | for (ch = 0; ch < DRAM_CH_NR; ch++) { |
| 180 | ret = umc_ch_init(dc_base, ca_base, bd->dram_freq, |
Masahiro Yamada | cf3e417 | 2016-02-26 14:21:50 +0900 | [diff] [blame] | 181 | bd->dram_ch[ch].size, |
Masahiro Yamada | fcdbbec | 2016-07-22 13:38:32 +0900 | [diff] [blame] | 182 | !!(bd->flags & UNIPHIER_BD_DDR3PLUS), ch); |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 183 | if (ret) { |
| 184 | pr_err("failed to initialize UMC ch%d\n", ch); |
| 185 | return ret; |
| 186 | } |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 187 | |
Masahiro Yamada | 938384f | 2016-02-26 14:21:47 +0900 | [diff] [blame] | 188 | ca_base += 0x00001000; |
| 189 | dc_base += 0x00200000; |
| 190 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 191 | |
| 192 | umc_start_ssif(ssif_base); |
| 193 | |
| 194 | return 0; |
| 195 | } |