1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2012-2015 Panasonic Corporation
* Copyright (C) 2015-2017 Socionext Inc.
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
*/
#include <common.h>
#include <init.h>
#include <linux/errno.h>
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/printk.h>
#include <linux/sizes.h>
#include <asm/global_data.h>
#include "init.h"
#include "sg-regs.h"
#include "soc-info.h"
DECLARE_GLOBAL_DATA_PTR;
struct uniphier_dram_map {
unsigned long base;
unsigned long size;
};
static int uniphier_memconf_decode(struct uniphier_dram_map *dram_map,
unsigned long sparse_ch1_base, bool have_ch2)
{
unsigned long size;
u32 val;
val = readl(sg_base + SG_MEMCONF);
/* set up ch0 */
dram_map[0].base = 0x80000000;
switch (val & SG_MEMCONF_CH0_SZ_MASK) {
case SG_MEMCONF_CH0_SZ_64M:
size = SZ_64M;
break;
case SG_MEMCONF_CH0_SZ_128M:
size = SZ_128M;
break;
case SG_MEMCONF_CH0_SZ_256M:
size = SZ_256M;
break;
case SG_MEMCONF_CH0_SZ_512M:
size = SZ_512M;
break;
case SG_MEMCONF_CH0_SZ_1G:
size = SZ_1G;
break;
default:
pr_err("error: invalid value is set to MEMCONF ch0 size\n");
return -EINVAL;
}
if ((val & SG_MEMCONF_CH0_NUM_MASK) == SG_MEMCONF_CH0_NUM_2)
size *= 2;
dram_map[0].size = size;
/* set up ch1 */
dram_map[1].base = dram_map[0].base + size;
if (val & SG_MEMCONF_SPARSEMEM) {
if (dram_map[1].base > sparse_ch1_base) {
pr_warn("Sparse mem is enabled, but ch0 and ch1 overlap\n");
pr_warn("Only ch0 is available\n");
dram_map[1].base = 0;
return 0;
}
dram_map[1].base = sparse_ch1_base;
}
switch (val & SG_MEMCONF_CH1_SZ_MASK) {
case SG_MEMCONF_CH1_SZ_64M:
size = SZ_64M;
break;
case SG_MEMCONF_CH1_SZ_128M:
size = SZ_128M;
break;
case SG_MEMCONF_CH1_SZ_256M:
size = SZ_256M;
break;
case SG_MEMCONF_CH1_SZ_512M:
size = SZ_512M;
break;
case SG_MEMCONF_CH1_SZ_1G:
size = SZ_1G;
break;
default:
pr_err("error: invalid value is set to MEMCONF ch1 size\n");
return -EINVAL;
}
if ((val & SG_MEMCONF_CH1_NUM_MASK) == SG_MEMCONF_CH1_NUM_2)
size *= 2;
dram_map[1].size = size;
if (!have_ch2 || val & SG_MEMCONF_CH2_DISABLE)
return 0;
/* set up ch2 */
dram_map[2].base = dram_map[1].base + size;
switch (val & SG_MEMCONF_CH2_SZ_MASK) {
case SG_MEMCONF_CH2_SZ_64M:
size = SZ_64M;
break;
case SG_MEMCONF_CH2_SZ_128M:
size = SZ_128M;
break;
case SG_MEMCONF_CH2_SZ_256M:
size = SZ_256M;
break;
case SG_MEMCONF_CH2_SZ_512M:
size = SZ_512M;
break;
case SG_MEMCONF_CH2_SZ_1G:
size = SZ_1G;
break;
default:
pr_err("error: invalid value is set to MEMCONF ch2 size\n");
return -EINVAL;
}
if ((val & SG_MEMCONF_CH2_NUM_MASK) == SG_MEMCONF_CH2_NUM_2)
size *= 2;
dram_map[2].size = size;
return 0;
}
static int uniphier_ld4_dram_map_get(struct uniphier_dram_map dram_map[])
{
return uniphier_memconf_decode(dram_map, 0xc0000000, false);
}
static int uniphier_pro4_dram_map_get(struct uniphier_dram_map dram_map[])
{
return uniphier_memconf_decode(dram_map, 0xa0000000, false);
}
static int uniphier_pxs2_dram_map_get(struct uniphier_dram_map dram_map[])
{
return uniphier_memconf_decode(dram_map, 0xc0000000, true);
}
struct uniphier_dram_init_data {
unsigned int soc_id;
int (*dram_map_get)(struct uniphier_dram_map dram_map[]);
};
static const struct uniphier_dram_init_data uniphier_dram_init_data[] = {
{
.soc_id = UNIPHIER_LD4_ID,
.dram_map_get = uniphier_ld4_dram_map_get,
},
{
.soc_id = UNIPHIER_PRO4_ID,
.dram_map_get = uniphier_pro4_dram_map_get,
},
{
.soc_id = UNIPHIER_SLD8_ID,
.dram_map_get = uniphier_ld4_dram_map_get,
},
{
.soc_id = UNIPHIER_PRO5_ID,
.dram_map_get = uniphier_ld4_dram_map_get,
},
{
.soc_id = UNIPHIER_PXS2_ID,
.dram_map_get = uniphier_pxs2_dram_map_get,
},
{
.soc_id = UNIPHIER_LD6B_ID,
.dram_map_get = uniphier_pxs2_dram_map_get,
},
{
.soc_id = UNIPHIER_LD11_ID,
.dram_map_get = uniphier_ld4_dram_map_get,
},
{
.soc_id = UNIPHIER_LD20_ID,
.dram_map_get = uniphier_pxs2_dram_map_get,
},
{
.soc_id = UNIPHIER_PXS3_ID,
.dram_map_get = uniphier_pxs2_dram_map_get,
},
};
UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_dram_init_data,
uniphier_dram_init_data)
static int uniphier_dram_map_get(struct uniphier_dram_map *dram_map)
{
const struct uniphier_dram_init_data *data;
data = uniphier_get_dram_init_data();
if (!data) {
pr_err("unsupported SoC\n");
return -ENOTSUPP;
}
return data->dram_map_get(dram_map);
}
int dram_init(void)
{
struct uniphier_dram_map dram_map[3] = {};
bool valid_bank_found = false;
unsigned long prev_top;
int ret, i;
gd->ram_size = 0;
ret = uniphier_dram_map_get(dram_map);
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(dram_map); i++) {
unsigned long max_size;
if (!dram_map[i].size)
continue;
/*
* U-Boot relocates itself to the tail of the memory region,
* but it does not expect sparse memory. We use the first
* contiguous chunk here.
*/
if (valid_bank_found && prev_top < dram_map[i].base)
break;
/*
* Do not use memory that exceeds 32bit address range. U-Boot
* relocates itself to the end of the effectively available RAM.
* This could be a problem for DMA engines that do not support
* 64bit address (SDMA of SDHCI, UniPhier AV-ether, etc.)
*/
if (dram_map[i].base >= 1ULL << 32)
break;
max_size = (1ULL << 32) - dram_map[i].base;
gd->ram_size = min(dram_map[i].size, max_size);
if (!valid_bank_found)
gd->ram_base = dram_map[i].base;
prev_top = dram_map[i].base + dram_map[i].size;
valid_bank_found = true;
}
/*
* LD20 uses the last 64 byte for each channel for dynamic
* DDR PHY training
*/
if (uniphier_get_soc_id() == UNIPHIER_LD20_ID)
gd->ram_size -= 64;
return 0;
}
int dram_init_banksize(void)
{
struct uniphier_dram_map dram_map[3] = {};
unsigned long base, top;
bool valid_bank_found = false;
int ret, i;
ret = uniphier_dram_map_get(dram_map);
if (ret)
return ret;
for (i = 0; i < ARRAY_SIZE(dram_map); i++) {
if (i < ARRAY_SIZE(gd->bd->bi_dram)) {
gd->bd->bi_dram[i].start = dram_map[i].base;
gd->bd->bi_dram[i].size = dram_map[i].size;
}
if (!dram_map[i].size)
continue;
if (!valid_bank_found)
base = dram_map[i].base;
top = dram_map[i].base + dram_map[i].size;
valid_bank_found = true;
}
if (!valid_bank_found)
return -EINVAL;
/* map all the DRAM regions */
uniphier_mem_map_init(base, top - base);
return 0;
}
|