blob: bf14d0d283fa58f7f4dbb9db14619c8417f7de3d [file] [log] [blame]
Masahiro Yamada1fe65d32015-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>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090011
12#include "../init.h"
13#include "../sg-regs.h"
Masahiro Yamada1fe65d32015-09-22 00:27:41 +090014
Masahiro Yamada98905692016-03-30 20:17:02 +090015int uniphier_pxs2_memconf_init(const struct uniphier_board_data *bd)
Masahiro Yamada1fe65d32015-09-22 00:27:41 +090016{
17 u32 tmp;
18 unsigned long size_per_word;
19
20 tmp = readl(SG_MEMCONF);
21
22 tmp &= ~(SG_MEMCONF_CH2_SZ_MASK | SG_MEMCONF_CH2_NUM_MASK);
23
Masahiro Yamada799e6f22016-02-26 14:21:34 +090024 switch (bd->dram_ch[2].width) {
Masahiro Yamada1fe65d32015-09-22 00:27:41 +090025 case 16:
26 tmp |= SG_MEMCONF_CH2_NUM_1;
Masahiro Yamada799e6f22016-02-26 14:21:34 +090027 size_per_word = bd->dram_ch[2].size;
Masahiro Yamada1fe65d32015-09-22 00:27:41 +090028 break;
29 case 32:
30 tmp |= SG_MEMCONF_CH2_NUM_2;
Masahiro Yamada799e6f22016-02-26 14:21:34 +090031 size_per_word = bd->dram_ch[2].size >> 1;
Masahiro Yamada1fe65d32015-09-22 00:27:41 +090032 break;
33 default:
34 pr_err("error: unsupported DRAM Ch2 width\n");
35 return -EINVAL;
36 }
37
38 /* Set DDR size */
39 switch (size_per_word) {
40 case SZ_64M:
41 tmp |= SG_MEMCONF_CH2_SZ_64M;
42 break;
43 case SZ_128M:
44 tmp |= SG_MEMCONF_CH2_SZ_128M;
45 break;
46 case SZ_256M:
47 tmp |= SG_MEMCONF_CH2_SZ_256M;
48 break;
49 case SZ_512M:
50 tmp |= SG_MEMCONF_CH2_SZ_512M;
51 break;
52 default:
53 pr_err("error: unsupported DRAM Ch2 size\n");
54 return -EINVAL;
55 }
56
57 if (size_per_word)
58 tmp &= ~SG_MEMCONF_CH2_DISABLE;
59 else
60 tmp |= SG_MEMCONF_CH2_DISABLE;
61
62 writel(tmp, SG_MEMCONF);
63
64 return 0;
65}