blob: d7bf0d4e5fa2277a115c2e81e484e50dd59b57a9 [file] [log] [blame]
Masahiro Yamada019df872015-09-22 00:27:41 +09001/*
2 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <linux/err.h>
9#include <linux/io.h>
10#include <linux/sizes.h>
11#include <mach/init.h>
12#include <mach/sg-regs.h>
13
14int proxstream2_memconf_init(const struct uniphier_board_data *bd)
15{
16 u32 tmp;
17 unsigned long size_per_word;
18
19 tmp = readl(SG_MEMCONF);
20
21 tmp &= ~(SG_MEMCONF_CH2_SZ_MASK | SG_MEMCONF_CH2_NUM_MASK);
22
23 switch (bd->dram_ch2_width) {
24 case 16:
25 tmp |= SG_MEMCONF_CH2_NUM_1;
26 size_per_word = bd->dram_ch2_size;
27 break;
28 case 32:
29 tmp |= SG_MEMCONF_CH2_NUM_2;
30 size_per_word = bd->dram_ch2_size >> 1;
31 break;
32 default:
33 pr_err("error: unsupported DRAM Ch2 width\n");
34 return -EINVAL;
35 }
36
37 /* Set DDR size */
38 switch (size_per_word) {
39 case SZ_64M:
40 tmp |= SG_MEMCONF_CH2_SZ_64M;
41 break;
42 case SZ_128M:
43 tmp |= SG_MEMCONF_CH2_SZ_128M;
44 break;
45 case SZ_256M:
46 tmp |= SG_MEMCONF_CH2_SZ_256M;
47 break;
48 case SZ_512M:
49 tmp |= SG_MEMCONF_CH2_SZ_512M;
50 break;
51 default:
52 pr_err("error: unsupported DRAM Ch2 size\n");
53 return -EINVAL;
54 }
55
56 if (size_per_word)
57 tmp &= ~SG_MEMCONF_CH2_DISABLE;
58 else
59 tmp |= SG_MEMCONF_CH2_DISABLE;
60
61 writel(tmp, SG_MEMCONF);
62
63 return 0;
64}