Masahiro Yamada | 1fe65d3 | 2015-09-22 00:27:41 +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 | 1fe65d3 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 14 | |
Masahiro Yamada | 9890569 | 2016-03-30 20:17:02 +0900 | [diff] [blame^] | 15 | int uniphier_pxs2_memconf_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | 1fe65d3 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 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 | |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 24 | switch (bd->dram_ch[2].width) { |
Masahiro Yamada | 1fe65d3 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 25 | case 16: |
| 26 | tmp |= SG_MEMCONF_CH2_NUM_1; |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 27 | size_per_word = bd->dram_ch[2].size; |
Masahiro Yamada | 1fe65d3 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 28 | break; |
| 29 | case 32: |
| 30 | tmp |= SG_MEMCONF_CH2_NUM_2; |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 31 | size_per_word = bd->dram_ch[2].size >> 1; |
Masahiro Yamada | 1fe65d3 | 2015-09-22 00:27:41 +0900 | [diff] [blame] | 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 | 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 | } |