2 * Copyright (C) 2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/sizes.h>
13 #include "../sg-regs.h"
15 int uniphier_pxs2_memconf_init(const struct uniphier_board_data *bd)
18 unsigned long size_per_word;
20 tmp = readl(SG_MEMCONF);
22 tmp &= ~(SG_MEMCONF_CH2_SZ_MASK | SG_MEMCONF_CH2_NUM_MASK);
24 switch (bd->dram_ch[2].width) {
26 tmp |= SG_MEMCONF_CH2_NUM_1;
27 size_per_word = bd->dram_ch[2].size;
30 tmp |= SG_MEMCONF_CH2_NUM_2;
31 size_per_word = bd->dram_ch[2].size >> 1;
34 pr_err("error: unsupported DRAM Ch2 width\n");
39 switch (size_per_word) {
41 tmp |= SG_MEMCONF_CH2_SZ_64M;
44 tmp |= SG_MEMCONF_CH2_SZ_128M;
47 tmp |= SG_MEMCONF_CH2_SZ_256M;
50 tmp |= SG_MEMCONF_CH2_SZ_512M;
53 tmp |= SG_MEMCONF_CH2_SZ_1G;
56 pr_err("error: unsupported DRAM Ch2 size\n");
61 tmp &= ~SG_MEMCONF_CH2_DISABLE;
63 tmp |= SG_MEMCONF_CH2_DISABLE;
65 writel(tmp, SG_MEMCONF);