blob: 5e333e0c96dbed238146d931bb736eacc4c74bdf [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 Yamadaefdf3402016-01-09 01:51:13 +090011
12#include "../init.h"
13#include "ddrphy-regs.h"
14#include "umc-regs.h"
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090015
Masahiro Yamada7d177592016-02-26 14:21:44 +090016enum dram_size {
17 DRAM_SZ_128M,
18 DRAM_SZ_256M,
19 DRAM_SZ_NR,
20};
21
22static u32 umc_spcctla[DRAM_SZ_NR] = {0x00240512, 0x00350512};
23
Masahiro Yamada3cf2e412015-01-21 15:06:46 +090024static void umc_start_ssif(void __iomem *ssif_base)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090025{
26 writel(0x00000000, ssif_base + 0x0000b004);
27 writel(0xffffffff, ssif_base + 0x0000c004);
28 writel(0x000fffcf, ssif_base + 0x0000c008);
29 writel(0x00000001, ssif_base + 0x0000b000);
30 writel(0x00000001, ssif_base + 0x0000c000);
31 writel(0x03010101, ssif_base + UMC_MDMCHSEL);
32 writel(0x03010100, ssif_base + UMC_DMDCHSEL);
33
34 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH);
35 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0);
36 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0);
37 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0);
38 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1);
39 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1);
40 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1);
41 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC);
42 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC);
43 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST);
44
45 writel(0x00000001, ssif_base + UMC_CPURST);
46 writel(0x00000001, ssif_base + UMC_IDSRST);
47 writel(0x00000001, ssif_base + UMC_IXMRST);
48 writel(0x00000001, ssif_base + UMC_MDMRST);
49 writel(0x00000001, ssif_base + UMC_MDDRST);
50 writel(0x00000001, ssif_base + UMC_SIORST);
51 writel(0x00000001, ssif_base + UMC_VIORST);
52 writel(0x00000001, ssif_base + UMC_FRCRST);
53 writel(0x00000001, ssif_base + UMC_RGLRST);
54 writel(0x00000001, ssif_base + UMC_AIORST);
55 writel(0x00000001, ssif_base + UMC_DMDRST);
56}
57
Masahiro Yamada7d177592016-02-26 14:21:44 +090058static int umc_dramcont_init(void __iomem *dramcont, void __iomem *ca_base,
59 int size, int freq, bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090060{
Masahiro Yamada7d177592016-02-26 14:21:44 +090061 enum dram_size size_e;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090062
Masahiro Yamada7d177592016-02-26 14:21:44 +090063 switch (size) {
64 case 0:
65 return 0;
66 case 1:
67 size_e = DRAM_SZ_128M;
68 break;
69 case 2:
70 size_e = DRAM_SZ_256M;
71 break;
72 default:
73 pr_err("unsupported DRAM size\n");
74 return -EINVAL;
75 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090076
Masahiro Yamada7d177592016-02-26 14:21:44 +090077 writel(ddr3plus ? 0x45990b11 : 0x55990b11, dramcont + UMC_CMDCTLA);
78 writel(ddr3plus ? 0x16958924 : 0x16958944, dramcont + UMC_CMDCTLB);
79 writel(umc_spcctla[size_e], dramcont + UMC_SPCCTLA);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090080 writel(0x00ff0006, dramcont + UMC_SPCCTLB);
81 writel(0x000a00ac, dramcont + UMC_RDATACTL_D0);
82 writel(0x04060806, dramcont + UMC_WDATACTL_D0);
83 writel(0x04a02000, dramcont + UMC_DATASET);
84 writel(0x00000000, ca_base + 0x2300);
85 writel(0x00400020, dramcont + UMC_DCCGCTL);
86 writel(0x00000003, dramcont + 0x7000);
87 writel(0x0000004f, dramcont + 0x8000);
88 writel(0x000000c3, dramcont + 0x8004);
89 writel(0x00000077, dramcont + 0x8008);
90 writel(0x0000003b, dramcont + UMC_DICGCTLA);
91 writel(0x020a0808, dramcont + UMC_DICGCTLB);
92 writel(0x00000004, dramcont + UMC_FLOWCTLG);
93 writel(0x80000201, ca_base + 0xc20);
94 writel(0x0801e01e, dramcont + UMC_FLOWCTLA);
95 writel(0x00200000, dramcont + UMC_FLOWCTLB);
96 writel(0x00004444, dramcont + UMC_FLOWCTLC);
97 writel(0x200a0a00, dramcont + UMC_SPCSETB);
98 writel(0x00000000, dramcont + UMC_SPCSETD);
99 writel(0x00000520, dramcont + UMC_DFICUPDCTLA);
Masahiro Yamada7d177592016-02-26 14:21:44 +0900100
101 return 0;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900102}
103
Masahiro Yamadaa5731882016-02-26 14:21:40 +0900104static int umc_init_sub(int freq, int size_ch0, int size_ch1, bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900105{
106 void __iomem *ssif_base = (void __iomem *)UMC_SSIF_BASE;
107 void __iomem *ca_base0 = (void __iomem *)UMC_CA_BASE(0);
108 void __iomem *ca_base1 = (void __iomem *)UMC_CA_BASE(1);
109 void __iomem *dramcont0 = (void __iomem *)UMC_DRAMCONT_BASE(0);
110 void __iomem *dramcont1 = (void __iomem *)UMC_DRAMCONT_BASE(1);
Masahiro Yamada04191e52014-12-19 20:20:52 +0900111 void __iomem *phy0_0 = (void __iomem *)DDRPHY_BASE(0, 0);
112 void __iomem *phy1_0 = (void __iomem *)DDRPHY_BASE(1, 0);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900113
114 umc_dram_init_start(dramcont0);
115 umc_dram_init_start(dramcont1);
116 umc_dram_init_poll(dramcont0);
117 umc_dram_init_poll(dramcont1);
118
119 writel(0x00000101, dramcont0 + UMC_DIOCTLA);
120
Masahiro Yamada3bee85d2016-02-26 14:21:42 +0900121 ph1_ld4_ddrphy_init(phy0_0, freq, ddr3plus);
Masahiro Yamada04191e52014-12-19 20:20:52 +0900122
123 ddrphy_prepare_training(phy0_0, 0);
124 ddrphy_training(phy0_0);
125
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900126 writel(0x00000101, dramcont1 + UMC_DIOCTLA);
127
Masahiro Yamada3bee85d2016-02-26 14:21:42 +0900128 ph1_ld4_ddrphy_init(phy1_0, freq, ddr3plus);
Masahiro Yamada04191e52014-12-19 20:20:52 +0900129
130 ddrphy_prepare_training(phy1_0, 1);
131 ddrphy_training(phy1_0);
132
Masahiro Yamadaa5731882016-02-26 14:21:40 +0900133 umc_dramcont_init(dramcont0, ca_base0, size_ch0, freq, ddr3plus);
134 umc_dramcont_init(dramcont1, ca_base1, size_ch1, freq, ddr3plus);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900135
136 umc_start_ssif(ssif_base);
137
138 return 0;
139}
140
Masahiro Yamada75f16f82015-09-22 00:27:39 +0900141int ph1_sld8_umc_init(const struct uniphier_board_data *bd)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900142{
Masahiro Yamada799e6f22016-02-26 14:21:34 +0900143 if ((bd->dram_ch[0].size == SZ_128M || bd->dram_ch[0].size == SZ_256M) &&
144 (bd->dram_ch[1].size == SZ_128M || bd->dram_ch[1].size == SZ_256M) &&
Masahiro Yamada75f16f82015-09-22 00:27:39 +0900145 bd->dram_freq == 1333 &&
Masahiro Yamada799e6f22016-02-26 14:21:34 +0900146 bd->dram_ch[0].width == 16 && bd->dram_ch[1].width == 16) {
Masahiro Yamada75f16f82015-09-22 00:27:39 +0900147 return umc_init_sub(bd->dram_freq,
Masahiro Yamada799e6f22016-02-26 14:21:34 +0900148 bd->dram_ch[0].size / SZ_128M,
Masahiro Yamadaa5731882016-02-26 14:21:40 +0900149 bd->dram_ch[1].size / SZ_128M,
150 bd->dram_ddr3plus);
Masahiro Yamada75f16f82015-09-22 00:27:39 +0900151 } else {
152 pr_err("Unsupported DDR configuration\n");
153 return -EINVAL;
154 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900155}