blob: 1eb15b611fd3af92ea4b79216bc7f8811beac3a6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09002/*
Masahiro Yamadafcdbbec2016-07-22 13:38:32 +09003 * Copyright (C) 2011-2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +09006 */
7
Masahiro Yamadae4e789d2017-01-21 18:05:24 +09008#include <linux/errno.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +09009#include <linux/io.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060010#include <linux/printk.h>
Masahiro Yamada75f16f82015-09-22 00:27:39 +090011#include <linux/sizes.h>
Masahiro Yamadaf734aa92016-02-26 14:21:52 +090012#include <asm/processor.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090013
14#include "../init.h"
Masahiro Yamadab464ff92016-10-27 23:47:07 +090015#include "ddrphy-init.h"
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090016#include "umc-regs.h"
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090017
Masahiro Yamada8596e782016-02-26 14:21:48 +090018#define DRAM_CH_NR 2
19
Masahiro Yamadae84036a2016-02-26 14:21:46 +090020enum dram_freq {
21 DRAM_FREQ_1333M,
22 DRAM_FREQ_1600M,
23 DRAM_FREQ_NR,
24};
25
26enum dram_size {
27 DRAM_SZ_128M,
28 DRAM_SZ_256M,
29 DRAM_SZ_NR,
30};
31
32static u32 umc_cmdctla_plus[DRAM_FREQ_NR] = {0x45990b11, 0x36bb0f17};
33static u32 umc_cmdctlb_plus[DRAM_FREQ_NR] = {0x16958924, 0x18c6aa24};
34static u32 umc_spcctla[DRAM_FREQ_NR][DRAM_SZ_NR] = {
35 {0x00240512, 0x00350512},
36 {0x002b0617, 0x003f0617},
37};
38static u32 umc_spcctlb[DRAM_FREQ_NR] = {0x00ff0006, 0x00ff0008};
39static u32 umc_rdatactl[DRAM_FREQ_NR] = {0x000a00ac, 0x000c00ae};
40
Masahiro Yamada8596e782016-02-26 14:21:48 +090041static int umc_get_rank(int ch)
42{
43 return ch; /* ch0: rank0, ch1: rank1 for this SoC */
44}
45
Masahiro Yamada3cf2e412015-01-21 15:06:46 +090046static void umc_start_ssif(void __iomem *ssif_base)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090047{
48 writel(0x00000000, ssif_base + 0x0000b004);
49 writel(0xffffffff, ssif_base + 0x0000c004);
50 writel(0x000fffcf, ssif_base + 0x0000c008);
51 writel(0x00000001, ssif_base + 0x0000b000);
52 writel(0x00000001, ssif_base + 0x0000c000);
53 writel(0x03010101, ssif_base + UMC_MDMCHSEL);
54 writel(0x03010100, ssif_base + UMC_DMDCHSEL);
55
56 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH);
57 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0);
58 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0);
59 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0);
60 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1);
61 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1);
62 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1);
63 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC);
64 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC);
65 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST);
66
67 writel(0x00000001, ssif_base + UMC_CPURST);
68 writel(0x00000001, ssif_base + UMC_IDSRST);
69 writel(0x00000001, ssif_base + UMC_IXMRST);
70 writel(0x00000001, ssif_base + UMC_MDMRST);
71 writel(0x00000001, ssif_base + UMC_MDDRST);
72 writel(0x00000001, ssif_base + UMC_SIORST);
73 writel(0x00000001, ssif_base + UMC_VIORST);
74 writel(0x00000001, ssif_base + UMC_FRCRST);
75 writel(0x00000001, ssif_base + UMC_RGLRST);
76 writel(0x00000001, ssif_base + UMC_AIORST);
77 writel(0x00000001, ssif_base + UMC_DMDRST);
78}
79
Masahiro Yamada392ecb62016-02-26 14:21:53 +090080static int umc_dramcont_init(void __iomem *dc_base, void __iomem *ca_base,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +090081 int freq, unsigned long size, bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090082{
Masahiro Yamadae84036a2016-02-26 14:21:46 +090083 enum dram_freq freq_e;
84 enum dram_size size_e;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090085
Masahiro Yamada8596e782016-02-26 14:21:48 +090086 if (!ddr3plus) {
87 pr_err("DDR3 standard is not supported\n");
88 return -EINVAL;
89 }
90
Masahiro Yamadae84036a2016-02-26 14:21:46 +090091 switch (freq) {
92 case 1333:
93 freq_e = DRAM_FREQ_1333M;
94 break;
95 case 1600:
96 freq_e = DRAM_FREQ_1600M;
97 break;
98 default:
99 pr_err("unsupported DRAM frequency %d MHz\n", freq);
100 return -EINVAL;
101 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900102
Masahiro Yamadae84036a2016-02-26 14:21:46 +0900103 switch (size) {
104 case 0:
105 return 0;
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900106 case SZ_128M:
Masahiro Yamadae84036a2016-02-26 14:21:46 +0900107 size_e = DRAM_SZ_128M;
108 break;
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900109 case SZ_256M:
Masahiro Yamadae84036a2016-02-26 14:21:46 +0900110 size_e = DRAM_SZ_256M;
111 break;
112 default:
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900113 pr_err("unsupported DRAM size 0x%08lx\n", size);
Masahiro Yamadae84036a2016-02-26 14:21:46 +0900114 return -EINVAL;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900115 }
116
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900117 writel(umc_cmdctla_plus[freq_e], dc_base + UMC_CMDCTLA);
118 writel(umc_cmdctlb_plus[freq_e], dc_base + UMC_CMDCTLB);
119 writel(umc_spcctla[freq_e][size_e], dc_base + UMC_SPCCTLA);
120 writel(umc_spcctlb[freq_e], dc_base + UMC_SPCCTLB);
121 writel(umc_rdatactl[freq_e], dc_base + UMC_RDATACTL_D0);
122 writel(0x04060806, dc_base + UMC_WDATACTL_D0);
123 writel(0x04a02000, dc_base + UMC_DATASET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900124 writel(0x00000000, ca_base + 0x2300);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900125 writel(0x00400020, dc_base + UMC_DCCGCTL);
126 writel(0x00000003, dc_base + 0x7000);
127 writel(0x0000000f, dc_base + 0x8000);
128 writel(0x000000c3, dc_base + 0x8004);
129 writel(0x00000071, dc_base + 0x8008);
130 writel(0x0000003b, dc_base + UMC_DICGCTLA);
131 writel(0x020a0808, dc_base + UMC_DICGCTLB);
132 writel(0x00000004, dc_base + UMC_FLOWCTLG);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900133 writel(0x80000201, ca_base + 0xc20);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900134 writel(0x0801e01e, dc_base + UMC_FLOWCTLA);
135 writel(0x00200000, dc_base + UMC_FLOWCTLB);
136 writel(0x00004444, dc_base + UMC_FLOWCTLC);
137 writel(0x200a0a00, dc_base + UMC_SPCSETB);
138 writel(0x00000000, dc_base + UMC_SPCSETD);
139 writel(0x00000520, dc_base + UMC_DFICUPDCTLA);
Masahiro Yamadae84036a2016-02-26 14:21:46 +0900140
141 return 0;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900142}
143
Masahiro Yamada8596e782016-02-26 14:21:48 +0900144static int umc_ch_init(void __iomem *dc_base, void __iomem *ca_base,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900145 int freq, unsigned long size, bool ddr3plus, int ch)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900146{
Masahiro Yamada8596e782016-02-26 14:21:48 +0900147 void __iomem *phy_base = dc_base + 0x00001000;
148 int ret;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900149
Masahiro Yamadaf734aa92016-02-26 14:21:52 +0900150 writel(UMC_INITSET_INIT1EN, dc_base + UMC_INITSET);
Masahiro Yamadab018e262016-10-27 23:47:04 +0900151 while (readl(dc_base + UMC_INITSTAT) & UMC_INITSTAT_INIT1ST)
Masahiro Yamadaf734aa92016-02-26 14:21:52 +0900152 cpu_relax();
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900153
Masahiro Yamada8596e782016-02-26 14:21:48 +0900154 writel(0x00000101, dc_base + UMC_DIOCTLA);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900155
Masahiro Yamada98905692016-03-30 20:17:02 +0900156 ret = uniphier_ld4_ddrphy_init(phy_base, freq, ddr3plus);
Masahiro Yamada8596e782016-02-26 14:21:48 +0900157 if (ret)
158 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900159
Masahiro Yamada8596e782016-02-26 14:21:48 +0900160 ddrphy_prepare_training(phy_base, umc_get_rank(ch));
161 ret = ddrphy_training(phy_base);
162 if (ret)
163 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900164
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900165 return umc_dramcont_init(dc_base, ca_base, freq, size, ddr3plus);
Masahiro Yamada8596e782016-02-26 14:21:48 +0900166}
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900167
Masahiro Yamada98905692016-03-30 20:17:02 +0900168int uniphier_ld4_umc_init(const struct uniphier_board_data *bd)
Masahiro Yamada8596e782016-02-26 14:21:48 +0900169{
170 void __iomem *umc_base = (void __iomem *)0x5b800000;
171 void __iomem *ca_base = umc_base + 0x00001000;
172 void __iomem *dc_base = umc_base + 0x00400000;
173 void __iomem *ssif_base = umc_base;
174 int ch, ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900175
Masahiro Yamada8596e782016-02-26 14:21:48 +0900176 for (ch = 0; ch < DRAM_CH_NR; ch++) {
177 ret = umc_ch_init(dc_base, ca_base, bd->dram_freq,
Masahiro Yamadacf3e4172016-02-26 14:21:50 +0900178 bd->dram_ch[ch].size,
Masahiro Yamadafcdbbec2016-07-22 13:38:32 +0900179 !!(bd->flags & UNIPHIER_BD_DDR3PLUS), ch);
Masahiro Yamada8596e782016-02-26 14:21:48 +0900180 if (ret) {
181 pr_err("failed to initialize UMC ch%d\n", ch);
182 return ret;
183 }
Masahiro Yamada04191e52014-12-19 20:20:52 +0900184
Masahiro Yamada8596e782016-02-26 14:21:48 +0900185 ca_base += 0x00001000;
186 dc_base += 0x00200000;
187 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900188
189 umc_start_ssif(ssif_base);
190
191 return 0;
192}