blob: 0114df782b4ff1c6bb37511c8c19ecb4bbdc031e [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 Yamadac9b5edf2016-02-26 14:21:49 +090018#define DRAM_CH_NR 2
19
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090020enum dram_size {
21 DRAM_SZ_128M,
22 DRAM_SZ_256M,
23 DRAM_SZ_512M,
24 DRAM_SZ_NR,
25};
26
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090027static u32 umc_spcctla[DRAM_SZ_NR] = {0x002b0617, 0x003f0617, 0x00770617};
28
Masahiro Yamada3cf2e412015-01-21 15:06:46 +090029static void umc_start_ssif(void __iomem *ssif_base)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090030{
Masahiro Yamada11cc7b62016-02-26 14:21:39 +090031 writel(0x00000000, ssif_base + 0x0000b004);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090032 writel(0xffffffff, ssif_base + 0x0000c004);
Masahiro Yamada11cc7b62016-02-26 14:21:39 +090033 writel(0x000fffcf, ssif_base + 0x0000c008);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090034 writel(0x00000001, ssif_base + 0x0000b000);
35 writel(0x00000001, ssif_base + 0x0000c000);
36
37 writel(0x03010100, ssif_base + UMC_HDMCHSEL);
38 writel(0x03010101, ssif_base + UMC_MDMCHSEL);
39 writel(0x03010100, ssif_base + UMC_DVCCHSEL);
40 writel(0x03010100, ssif_base + UMC_DMDCHSEL);
41
42 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH);
43 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0);
44 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0);
45 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0);
46 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1);
47 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1);
48 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1);
49 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC);
50 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC);
51 writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST);
52 writel(0x00000000, ssif_base + 0x0000c044); /* DCGIV_SSIF_REG */
53
54 writel(0x00000001, ssif_base + UMC_CPURST);
55 writel(0x00000001, ssif_base + UMC_IDSRST);
56 writel(0x00000001, ssif_base + UMC_IXMRST);
57 writel(0x00000001, ssif_base + UMC_HDMRST);
58 writel(0x00000001, ssif_base + UMC_MDMRST);
59 writel(0x00000001, ssif_base + UMC_HDDRST);
60 writel(0x00000001, ssif_base + UMC_MDDRST);
61 writel(0x00000001, ssif_base + UMC_SIORST);
62 writel(0x00000001, ssif_base + UMC_GIORST);
63 writel(0x00000001, ssif_base + UMC_HD2RST);
64 writel(0x00000001, ssif_base + UMC_VIORST);
65 writel(0x00000001, ssif_base + UMC_DVCRST);
66 writel(0x00000001, ssif_base + UMC_RGLRST);
67 writel(0x00000001, ssif_base + UMC_VPERST);
68 writel(0x00000001, ssif_base + UMC_AIORST);
69 writel(0x00000001, ssif_base + UMC_DMDRST);
70}
71
Masahiro Yamada392ecb62016-02-26 14:21:53 +090072static int umc_dramcont_init(void __iomem *dc_base, void __iomem *ca_base,
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +090073 int freq, unsigned long size, bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +090074{
Masahiro Yamada392ecb62016-02-26 14:21:53 +090075 enum dram_size size_e;
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090076
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +090077 if (freq != 1600) {
78 pr_err("Unsupported DDR frequency %d MHz\n", freq);
79 return -EINVAL;
80 }
81
82 if (ddr3plus) {
83 pr_err("DDR3+ is not supported\n");
84 return -EINVAL;
85 }
86
87 switch (size) {
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090088 case SZ_128M:
Masahiro Yamada392ecb62016-02-26 14:21:53 +090089 size_e = DRAM_SZ_128M;
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090090 break;
91 case SZ_256M:
Masahiro Yamada392ecb62016-02-26 14:21:53 +090092 size_e = DRAM_SZ_256M;
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090093 break;
94 case SZ_512M:
Masahiro Yamada392ecb62016-02-26 14:21:53 +090095 size_e = DRAM_SZ_512M;
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090096 break;
97 default:
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +090098 pr_err("unsupported DRAM size 0x%08lx (per 16bit)\n", size);
Masahiro Yamadae55dfd12016-01-21 14:57:30 +090099 return -EINVAL;
100 }
101
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900102 writel(0x66bb0f17, dc_base + UMC_CMDCTLA);
103 writel(0x18c6aa44, dc_base + UMC_CMDCTLB);
104 writel(umc_spcctla[size_e], dc_base + UMC_SPCCTLA);
105 writel(0x00ff0008, dc_base + UMC_SPCCTLB);
106 writel(0x000c00ae, dc_base + UMC_RDATACTL_D0);
107 writel(0x000c00ae, dc_base + UMC_RDATACTL_D1);
108 writel(0x04060802, dc_base + UMC_WDATACTL_D0);
109 writel(0x04060802, dc_base + UMC_WDATACTL_D1);
110 writel(0x04a02000, dc_base + UMC_DATASET);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900111 writel(0x00000000, ca_base + 0x2300);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900112 writel(0x00400020, dc_base + UMC_DCCGCTL);
113 writel(0x0000000f, dc_base + 0x7000);
114 writel(0x0000000f, dc_base + 0x8000);
115 writel(0x000000c3, dc_base + 0x8004);
116 writel(0x00000071, dc_base + 0x8008);
117 writel(0x00000004, dc_base + UMC_FLOWCTLG);
118 writel(0x00000000, dc_base + 0x0060);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900119 writel(0x80000201, ca_base + 0xc20);
Masahiro Yamada392ecb62016-02-26 14:21:53 +0900120 writel(0x0801e01e, dc_base + UMC_FLOWCTLA);
121 writel(0x00200000, dc_base + UMC_FLOWCTLB);
122 writel(0x00004444, dc_base + UMC_FLOWCTLC);
123 writel(0x200a0a00, dc_base + UMC_SPCSETB);
124 writel(0x00010000, dc_base + UMC_SPCSETD);
125 writel(0x80000020, dc_base + UMC_DFICUPDCTLA);
Masahiro Yamadae55dfd12016-01-21 14:57:30 +0900126
127 return 0;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900128}
129
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900130static int umc_ch_init(void __iomem *dc_base, void __iomem *ca_base,
131 int freq, unsigned long size, unsigned int width,
132 bool ddr3plus)
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900133{
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900134 void __iomem *phy_base = dc_base + 0x00001000;
135 int nr_phy = width / 16;
136 int phy, ret;
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900137
Masahiro Yamadaf734aa92016-02-26 14:21:52 +0900138 writel(UMC_INITSET_INIT1EN, dc_base + UMC_INITSET);
Masahiro Yamadab018e262016-10-27 23:47:04 +0900139 while (readl(dc_base + UMC_INITSTAT) & UMC_INITSTAT_INIT1ST)
Masahiro Yamadaf734aa92016-02-26 14:21:52 +0900140 cpu_relax();
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900141
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900142 for (phy = 0; phy < nr_phy; phy++) {
143 writel(0x00000100 | ((1 << (phy + 1)) - 1),
144 dc_base + UMC_DIOCTLA);
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900145
Masahiro Yamada98905692016-03-30 20:17:02 +0900146 ret = uniphier_ld4_ddrphy_init(phy_base, freq, ddr3plus);
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900147 if (ret)
148 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900149
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900150 ddrphy_prepare_training(phy_base, phy);
151 ret = ddrphy_training(phy_base);
152 if (ret)
153 return ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900154
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900155 phy_base += 0x00001000;
156 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900157
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900158 return umc_dramcont_init(dc_base, ca_base, freq, size / (width / 16),
159 ddr3plus);
160}
Masahiro Yamada04191e52014-12-19 20:20:52 +0900161
Masahiro Yamada98905692016-03-30 20:17:02 +0900162int uniphier_pro4_umc_init(const struct uniphier_board_data *bd)
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900163{
164 void __iomem *umc_base = (void __iomem *)0x5b800000;
165 void __iomem *ca_base = umc_base + 0x00001000;
166 void __iomem *dc_base = umc_base + 0x00400000;
167 void __iomem *ssif_base = umc_base;
168 int ch, ret;
Masahiro Yamada04191e52014-12-19 20:20:52 +0900169
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900170 for (ch = 0; ch < DRAM_CH_NR; ch++) {
171 ret = umc_ch_init(dc_base, ca_base, bd->dram_freq,
172 bd->dram_ch[ch].size,
173 bd->dram_ch[ch].width,
Masahiro Yamadafcdbbec2016-07-22 13:38:32 +0900174 !!(bd->flags & UNIPHIER_BD_DDR3PLUS));
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900175 if (ret) {
176 pr_err("failed to initialize UMC ch%d\n", ch);
177 return ret;
178 }
Masahiro Yamadae55dfd12016-01-21 14:57:30 +0900179
Masahiro Yamadac9b5edf2016-02-26 14:21:49 +0900180 ca_base += 0x00001000;
181 dc_base += 0x00200000;
182 }
Masahiro Yamadabb2ff9d2014-10-03 19:21:06 +0900183
184 umc_start_ssif(ssif_base);
185
186 return 0;
187}