Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 1 | /* |
| 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 Yamada | efdf340 | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 11 | |
| 12 | #include "../init.h" |
| 13 | #include "../sg-regs.h" |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 14 | |
| 15 | int ph1_sld3_memconf_init(const struct uniphier_board_data *bd) |
| 16 | { |
| 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 | |
| 24 | switch (bd->dram_ch2_width) { |
| 25 | case 16: |
| 26 | tmp |= SG_MEMCONF_CH2_NUM_1; |
| 27 | size_per_word = bd->dram_ch2_size; |
| 28 | break; |
| 29 | case 32: |
| 30 | tmp |= SG_MEMCONF_CH2_NUM_2; |
| 31 | size_per_word = bd->dram_ch2_size >> 1; |
| 32 | 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 | writel(tmp, SG_MEMCONF); |
| 58 | |
| 59 | return 0; |
| 60 | } |