Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2011-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 8 | #include <linux/err.h> |
Masahiro Yamada | 663a23f | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 10 | #include <linux/sizes.h> |
Masahiro Yamada | efdf340 | 2016-01-09 01:51:13 +0900 | [diff] [blame] | 11 | |
| 12 | #include "../init.h" |
| 13 | #include "ddrphy-regs.h" |
| 14 | #include "umc-regs.h" |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 15 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 16 | enum dram_size { |
| 17 | DRAM_SZ_128M, |
| 18 | DRAM_SZ_256M, |
| 19 | DRAM_SZ_NR, |
| 20 | }; |
| 21 | |
| 22 | static u32 umc_spcctla[DRAM_SZ_NR] = {0x00240512, 0x00350512}; |
| 23 | |
Masahiro Yamada | 3cf2e41 | 2015-01-21 15:06:46 +0900 | [diff] [blame] | 24 | static void umc_start_ssif(void __iomem *ssif_base) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 25 | { |
| 26 | writel(0x00000000, ssif_base + 0x0000b004); |
| 27 | writel(0xffffffff, ssif_base + 0x0000c004); |
| 28 | writel(0x000fffcf, ssif_base + 0x0000c008); |
| 29 | writel(0x00000001, ssif_base + 0x0000b000); |
| 30 | writel(0x00000001, ssif_base + 0x0000c000); |
| 31 | writel(0x03010101, ssif_base + UMC_MDMCHSEL); |
| 32 | writel(0x03010100, ssif_base + UMC_DMDCHSEL); |
| 33 | |
| 34 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH); |
| 35 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0); |
| 36 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0); |
| 37 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0); |
| 38 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1); |
| 39 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1); |
| 40 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1); |
| 41 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC); |
| 42 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC); |
| 43 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST); |
| 44 | |
| 45 | writel(0x00000001, ssif_base + UMC_CPURST); |
| 46 | writel(0x00000001, ssif_base + UMC_IDSRST); |
| 47 | writel(0x00000001, ssif_base + UMC_IXMRST); |
| 48 | writel(0x00000001, ssif_base + UMC_MDMRST); |
| 49 | writel(0x00000001, ssif_base + UMC_MDDRST); |
| 50 | writel(0x00000001, ssif_base + UMC_SIORST); |
| 51 | writel(0x00000001, ssif_base + UMC_VIORST); |
| 52 | writel(0x00000001, ssif_base + UMC_FRCRST); |
| 53 | writel(0x00000001, ssif_base + UMC_RGLRST); |
| 54 | writel(0x00000001, ssif_base + UMC_AIORST); |
| 55 | writel(0x00000001, ssif_base + UMC_DMDRST); |
| 56 | } |
| 57 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 58 | static int umc_dramcont_init(void __iomem *dramcont, void __iomem *ca_base, |
| 59 | int size, int freq, bool ddr3plus) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 60 | { |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 61 | enum dram_size size_e; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 62 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 63 | switch (size) { |
| 64 | case 0: |
| 65 | return 0; |
| 66 | case 1: |
| 67 | size_e = DRAM_SZ_128M; |
| 68 | break; |
| 69 | case 2: |
| 70 | size_e = DRAM_SZ_256M; |
| 71 | break; |
| 72 | default: |
| 73 | pr_err("unsupported DRAM size\n"); |
| 74 | return -EINVAL; |
| 75 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 76 | |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 77 | writel(ddr3plus ? 0x45990b11 : 0x55990b11, dramcont + UMC_CMDCTLA); |
| 78 | writel(ddr3plus ? 0x16958924 : 0x16958944, dramcont + UMC_CMDCTLB); |
| 79 | writel(umc_spcctla[size_e], dramcont + UMC_SPCCTLA); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 80 | writel(0x00ff0006, dramcont + UMC_SPCCTLB); |
| 81 | writel(0x000a00ac, dramcont + UMC_RDATACTL_D0); |
| 82 | writel(0x04060806, dramcont + UMC_WDATACTL_D0); |
| 83 | writel(0x04a02000, dramcont + UMC_DATASET); |
| 84 | writel(0x00000000, ca_base + 0x2300); |
| 85 | writel(0x00400020, dramcont + UMC_DCCGCTL); |
| 86 | writel(0x00000003, dramcont + 0x7000); |
| 87 | writel(0x0000004f, dramcont + 0x8000); |
| 88 | writel(0x000000c3, dramcont + 0x8004); |
| 89 | writel(0x00000077, dramcont + 0x8008); |
| 90 | writel(0x0000003b, dramcont + UMC_DICGCTLA); |
| 91 | writel(0x020a0808, dramcont + UMC_DICGCTLB); |
| 92 | writel(0x00000004, dramcont + UMC_FLOWCTLG); |
| 93 | writel(0x80000201, ca_base + 0xc20); |
| 94 | writel(0x0801e01e, dramcont + UMC_FLOWCTLA); |
| 95 | writel(0x00200000, dramcont + UMC_FLOWCTLB); |
| 96 | writel(0x00004444, dramcont + UMC_FLOWCTLC); |
| 97 | writel(0x200a0a00, dramcont + UMC_SPCSETB); |
| 98 | writel(0x00000000, dramcont + UMC_SPCSETD); |
| 99 | writel(0x00000520, dramcont + UMC_DFICUPDCTLA); |
Masahiro Yamada | 7d17759 | 2016-02-26 14:21:44 +0900 | [diff] [blame^] | 100 | |
| 101 | return 0; |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 102 | } |
| 103 | |
Masahiro Yamada | a573188 | 2016-02-26 14:21:40 +0900 | [diff] [blame] | 104 | static int umc_init_sub(int freq, int size_ch0, int size_ch1, bool ddr3plus) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 105 | { |
| 106 | void __iomem *ssif_base = (void __iomem *)UMC_SSIF_BASE; |
| 107 | void __iomem *ca_base0 = (void __iomem *)UMC_CA_BASE(0); |
| 108 | void __iomem *ca_base1 = (void __iomem *)UMC_CA_BASE(1); |
| 109 | void __iomem *dramcont0 = (void __iomem *)UMC_DRAMCONT_BASE(0); |
| 110 | void __iomem *dramcont1 = (void __iomem *)UMC_DRAMCONT_BASE(1); |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 111 | void __iomem *phy0_0 = (void __iomem *)DDRPHY_BASE(0, 0); |
| 112 | void __iomem *phy1_0 = (void __iomem *)DDRPHY_BASE(1, 0); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 113 | |
| 114 | umc_dram_init_start(dramcont0); |
| 115 | umc_dram_init_start(dramcont1); |
| 116 | umc_dram_init_poll(dramcont0); |
| 117 | umc_dram_init_poll(dramcont1); |
| 118 | |
| 119 | writel(0x00000101, dramcont0 + UMC_DIOCTLA); |
| 120 | |
Masahiro Yamada | 3bee85d | 2016-02-26 14:21:42 +0900 | [diff] [blame] | 121 | ph1_ld4_ddrphy_init(phy0_0, freq, ddr3plus); |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 122 | |
| 123 | ddrphy_prepare_training(phy0_0, 0); |
| 124 | ddrphy_training(phy0_0); |
| 125 | |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 126 | writel(0x00000101, dramcont1 + UMC_DIOCTLA); |
| 127 | |
Masahiro Yamada | 3bee85d | 2016-02-26 14:21:42 +0900 | [diff] [blame] | 128 | ph1_ld4_ddrphy_init(phy1_0, freq, ddr3plus); |
Masahiro Yamada | 04191e5 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 129 | |
| 130 | ddrphy_prepare_training(phy1_0, 1); |
| 131 | ddrphy_training(phy1_0); |
| 132 | |
Masahiro Yamada | a573188 | 2016-02-26 14:21:40 +0900 | [diff] [blame] | 133 | umc_dramcont_init(dramcont0, ca_base0, size_ch0, freq, ddr3plus); |
| 134 | umc_dramcont_init(dramcont1, ca_base1, size_ch1, freq, ddr3plus); |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 135 | |
| 136 | umc_start_ssif(ssif_base); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 141 | int ph1_sld8_umc_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 142 | { |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 143 | if ((bd->dram_ch[0].size == SZ_128M || bd->dram_ch[0].size == SZ_256M) && |
| 144 | (bd->dram_ch[1].size == SZ_128M || bd->dram_ch[1].size == SZ_256M) && |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 145 | bd->dram_freq == 1333 && |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 146 | bd->dram_ch[0].width == 16 && bd->dram_ch[1].width == 16) { |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 147 | return umc_init_sub(bd->dram_freq, |
Masahiro Yamada | 799e6f2 | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 148 | bd->dram_ch[0].size / SZ_128M, |
Masahiro Yamada | a573188 | 2016-02-26 14:21:40 +0900 | [diff] [blame] | 149 | bd->dram_ch[1].size / SZ_128M, |
| 150 | bd->dram_ddr3plus); |
Masahiro Yamada | 75f16f8 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 151 | } else { |
| 152 | pr_err("Unsupported DDR configuration\n"); |
| 153 | return -EINVAL; |
| 154 | } |
Masahiro Yamada | bb2ff9d | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 155 | } |