blob: e83176658364f5c470b10c73d16d4989ac036ee8 [file] [log] [blame]
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09001/*
Masahiro Yamada663a23f2015-05-29 17:30:00 +09002 * Copyright (C) 2011-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada75f16f82015-09-22 00:27:39 +09008#include <linux/err.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09009#include <linux/io.h>
Masahiro Yamada75f16f82015-09-22 00:27:39 +090010#include <linux/sizes.h>
Masahiro Yamadaf734aa92016-02-26 14:21:52 +090011#include <asm/processor.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090012
13#include "../init.h"
14#include "ddrphy-regs.h"
15#include "umc-regs.h"
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090016
Masahiro Yamada938384f2016-02-26 14:21:47 +090017#define DRAM_CH_NR 2
18
Masahiro Yamada547f6f62016-02-26 14:21:45 +090019enum dram_freq {
20 DRAM_FREQ_1333M,
21 DRAM_FREQ_1600M,
22 DRAM_FREQ_NR,
23};
24
Masahiro Yamada7d177592016-02-26 14:21:44 +090025enum dram_size {
26 DRAM_SZ_128M,
27 DRAM_SZ_256M,
Masahiro Yamada547f6f62016-02-26 14:21:45 +090028 DRAM_SZ_512M,
Masahiro Yamada7d177592016-02-26 14:21:44 +090029 DRAM_SZ_NR,
30};
31
Masahiro Yamada547f6f62016-02-26 14:21:45 +090032static u32 umc_cmdctla[DRAM_FREQ_NR] = {0x55990b11, 0x66bb0f17};
33static u32 umc_cmdctla_plus[DRAM_FREQ_NR] = {0x45990b11, 0x46bb0f17};
34static u32 umc_cmdctlb[DRAM_FREQ_NR] = {0x16958944, 0x18c6ab44};
35static u32 umc_cmdctlb_plus[DRAM_FREQ_NR] = {0x16958924, 0x18c6ab24};
36static u32 umc_spcctla[DRAM_FREQ_NR][DRAM_SZ_NR] = {
37 {0x00240512, 0x00350512, 0x00000000}, /* no data for 1333MHz,128MB */
38 {0x002b0617, 0x003f0617, 0x00670617},
39};
40static u32 umc_spcctlb[DRAM_FREQ_NR] = {0x00ff0006, 0x00ff0008};
41static u32 umc_rdatactl[DRAM_FREQ_NR] = {0x000a00ac, 0x000c00ac};
Masahiro Yamada7d177592016-02-26 14:21:44 +090042
Masahiro Yamada938384f2016-02-26 14:21:47 +090043static int umc_get_rank(int ch)
44{
45 return ch; /* ch0: rank0, ch1: rank1 for this SoC */
46}
47
Masahiro Yamada3cf2e412015-01-21 15:06:46 +090048static void umc_start_ssif(void __iomem *ssif_base)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090049{
50 writel(0x00000000, ssif_base + 0x0000b004);
51 writel(0xffffffff, ssif_base + 0x0000c004);
52 writel(0x000fffcf, ssif_base + 0x0000c008);
53 writel(0x00000001, ssif_base + 0x0000b000);
54 writel(0x00000001, ssif_base + 0x0000c000);
55 writel(0x03010101, ssif_base + UMC_MDMCHSEL);
56 writel(0x03010100, ssif_base + UMC_DMDCHSEL);
57
58 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH);
59 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0);
60 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0);
61 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0);
62 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1);
63 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1);
64 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1);
65 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC);
66 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC);
67 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST);
68
69 writel(0x00000001, ssif_base + UMC_CPURST);
70 writel(0x00000001, ssif_base + UMC_IDSRST);
71 writel(0x00000001, ssif_base + UMC_IXMRST);
72 writel(0x00000001, ssif_base + UMC_MDMRST);
73 writel(0x00000001, ssif_base + UMC_MDDRST);
74 writel(0x00000001, ssif_base + UMC_SIORST);
75 writel(0x00000001, ssif_base + UMC_VIORST);
76 writel(0x00000001, ssif_base + UMC_FRCRST);
77 writel(0x00000001, ssif_base + UMC_RGLRST);
78 writel(0x00000001, ssif_base + UMC_AIORST);
79 writel(0x00000001, ssif_base + UMC_DMDRST);
80}
81
Masahiro Yamada392ecb62016-02-26 14:21:53 +090082static int umc_dramcont_init(void __iomem *dc_base, void __iomem *ca_base,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +090083 int freq, unsigned long size, bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090084{
Masahiro Yamada547f6f62016-02-26 14:21:45 +090085 enum dram_freq freq_e;
Masahiro Yamada7d177592016-02-26 14:21:44 +090086 enum dram_size size_e;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090087
Masahiro Yamada547f6f62016-02-26 14:21:45 +090088 switch (freq) {
89 case 1333:
90 freq_e = DRAM_FREQ_1333M;
91 break;
92 case 1600:
93 freq_e = DRAM_FREQ_1600M;
94 break;
95 default:
96 pr_err("unsupported DRAM frequency %d MHz\n", freq);
97 return -EINVAL;
98 }
99
Masahiro Yamada7d177592016-02-26 14:21:44 +0900100 switch (size) {
101 case 0:
102 return 0;
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900103 case SZ_128M:
Masahiro Yamada7d177592016-02-26 14:21:44 +0900104 size_e = DRAM_SZ_128M;
105 break;
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900106 case SZ_256M:
Masahiro Yamada7d177592016-02-26 14:21:44 +0900107 size_e = DRAM_SZ_256M;
108 break;
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900109 case SZ_512M:
Masahiro Yamada547f6f62016-02-26 14:21:45 +0900110 size_e = DRAM_SZ_512M;
111 break;
Masahiro Yamada7d177592016-02-26 14:21:44 +0900112 default:
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900113 pr_err("unsupported DRAM size 0x%08lx\n", size);
Masahiro Yamada7d177592016-02-26 14:21:44 +0900114 return -EINVAL;
115 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900116
Masahiro Yamada547f6f62016-02-26 14:21:45 +0900117 writel((ddr3plus ? umc_cmdctla_plus : umc_cmdctla)[freq_e],
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900118 dc_base + UMC_CMDCTLA);
Masahiro Yamada547f6f62016-02-26 14:21:45 +0900119 writel((ddr3plus ? umc_cmdctlb_plus : umc_cmdctlb)[freq_e],
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900120 dc_base + UMC_CMDCTLB);
121 writel(umc_spcctla[freq_e][size_e], dc_base + UMC_SPCCTLA);
122 writel(umc_spcctlb[freq_e], dc_base + UMC_SPCCTLB);
123 writel(umc_rdatactl[freq_e], dc_base + UMC_RDATACTL_D0);
124 writel(0x04060806, dc_base + UMC_WDATACTL_D0);
125 writel(0x04a02000, dc_base + UMC_DATASET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900126 writel(0x00000000, ca_base + 0x2300);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900127 writel(0x00400020, dc_base + UMC_DCCGCTL);
128 writel(0x00000003, dc_base + 0x7000);
129 writel(0x0000004f, dc_base + 0x8000);
130 writel(0x000000c3, dc_base + 0x8004);
131 writel(0x00000077, dc_base + 0x8008);
132 writel(0x0000003b, dc_base + UMC_DICGCTLA);
133 writel(0x020a0808, dc_base + UMC_DICGCTLB);
134 writel(0x00000004, dc_base + UMC_FLOWCTLG);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900135 writel(0x80000201, ca_base + 0xc20);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900136 writel(0x0801e01e, dc_base + UMC_FLOWCTLA);
137 writel(0x00200000, dc_base + UMC_FLOWCTLB);
138 writel(0x00004444, dc_base + UMC_FLOWCTLC);
139 writel(0x200a0a00, dc_base + UMC_SPCSETB);
140 writel(0x00000000, dc_base + UMC_SPCSETD);
141 writel(0x00000520, dc_base + UMC_DFICUPDCTLA);
Masahiro Yamada7d177592016-02-26 14:21:44 +0900142
143 return 0;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900144}
145
Masahiro Yamada938384f2016-02-26 14:21:47 +0900146static int umc_ch_init(void __iomem *dc_base, void __iomem *ca_base,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900147 int freq, unsigned long size, bool ddr3plus, int ch)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900148{
Masahiro Yamada938384f2016-02-26 14:21:47 +0900149 void __iomem *phy_base = dc_base + 0x00001000;
150 int ret;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900151
Masahiro Yamadaf734aa92016-02-26 14:21:52 +0900152 writel(UMC_INITSET_INIT1EN, dc_base + UMC_INITSET);
153 while (readl(dc_base + UMC_INITSET) & UMC_INITSTAT_INIT1ST)
154 cpu_relax();
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900155
Masahiro Yamada938384f2016-02-26 14:21:47 +0900156 writel(0x00000101, dc_base + UMC_DIOCTLA);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900157
Masahiro Yamada98905692016-03-30 20:17:02 +0900158 ret = uniphier_ld4_ddrphy_init(phy_base, freq, ddr3plus);
Masahiro Yamada938384f2016-02-26 14:21:47 +0900159 if (ret)
160 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900161
Masahiro Yamada938384f2016-02-26 14:21:47 +0900162 ddrphy_prepare_training(phy_base, umc_get_rank(ch));
163 ret = ddrphy_training(phy_base);
164 if (ret)
165 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900166
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900167 return umc_dramcont_init(dc_base, ca_base, freq, size, ddr3plus);
Masahiro Yamada938384f2016-02-26 14:21:47 +0900168}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900169
Masahiro Yamada98905692016-03-30 20:17:02 +0900170int uniphier_sld8_umc_init(const struct uniphier_board_data *bd)
Masahiro Yamada938384f2016-02-26 14:21:47 +0900171{
172 void __iomem *umc_base = (void __iomem *)0x5b800000;
173 void __iomem *ca_base = umc_base + 0x00001000;
174 void __iomem *dc_base = umc_base + 0x00400000;
175 void __iomem *ssif_base = umc_base;
176 int ch, ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900177
Masahiro Yamada938384f2016-02-26 14:21:47 +0900178 for (ch = 0; ch < DRAM_CH_NR; ch++) {
179 ret = umc_ch_init(dc_base, ca_base, bd->dram_freq,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900180 bd->dram_ch[ch].size,
Masahiro Yamada938384f2016-02-26 14:21:47 +0900181 bd->dram_ddr3plus, ch);
182 if (ret) {
183 pr_err("failed to initialize UMC ch%d\n", ch);
184 return ret;
185 }
Masahiro Yamada04191e52014-12-19 20:20:52 +0900186
Masahiro Yamada938384f2016-02-26 14:21:47 +0900187 ca_base += 0x00001000;
188 dc_base += 0x00200000;
189 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900190
191 umc_start_ssif(ssif_base);
192
193 return 0;
194}