Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 2 | * Copyright (C) 2011-2015 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 5894ca0 | 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 | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 8 | #include <linux/err.h> |
Masahiro Yamada | f6e7f07 | 2015-05-29 17:30:00 +0900 | [diff] [blame] | 9 | #include <linux/io.h> |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 10 | #include <linux/sizes.h> |
Masahiro Yamada | 107b3fb | 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 | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 15 | |
Masahiro Yamada | ee94ee3 | 2015-01-21 15:06:46 +0900 | [diff] [blame] | 16 | static void umc_start_ssif(void __iomem *ssif_base) |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 17 | { |
| 18 | writel(0x00000000, ssif_base + 0x0000b004); |
| 19 | writel(0xffffffff, ssif_base + 0x0000c004); |
| 20 | writel(0x000fffcf, ssif_base + 0x0000c008); |
| 21 | writel(0x00000001, ssif_base + 0x0000b000); |
| 22 | writel(0x00000001, ssif_base + 0x0000c000); |
| 23 | writel(0x03010101, ssif_base + UMC_MDMCHSEL); |
| 24 | writel(0x03010100, ssif_base + UMC_DMDCHSEL); |
| 25 | |
| 26 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_FETCH); |
| 27 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE0); |
| 28 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC0); |
| 29 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC0); |
| 30 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMQUE1); |
| 31 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMWC1); |
| 32 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_COMRC1); |
| 33 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_WC); |
| 34 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_RC); |
| 35 | writel(0x00000000, ssif_base + UMC_CLKEN_SSIF_DST); |
| 36 | |
| 37 | writel(0x00000001, ssif_base + UMC_CPURST); |
| 38 | writel(0x00000001, ssif_base + UMC_IDSRST); |
| 39 | writel(0x00000001, ssif_base + UMC_IXMRST); |
| 40 | writel(0x00000001, ssif_base + UMC_MDMRST); |
| 41 | writel(0x00000001, ssif_base + UMC_MDDRST); |
| 42 | writel(0x00000001, ssif_base + UMC_SIORST); |
| 43 | writel(0x00000001, ssif_base + UMC_VIORST); |
| 44 | writel(0x00000001, ssif_base + UMC_FRCRST); |
| 45 | writel(0x00000001, ssif_base + UMC_RGLRST); |
| 46 | writel(0x00000001, ssif_base + UMC_AIORST); |
| 47 | writel(0x00000001, ssif_base + UMC_DMDRST); |
| 48 | } |
| 49 | |
Masahiro Yamada | ec79c79 | 2015-01-21 15:06:06 +0900 | [diff] [blame] | 50 | static void umc_dramcont_init(void __iomem *dramcont, void __iomem *ca_base, |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 51 | int size, int freq, bool ddr3plus) |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 52 | { |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 53 | writel(ddr3plus ? 0x45990b11 : 0x55990b11, dramcont + UMC_CMDCTLA); |
| 54 | writel(ddr3plus ? 0x16958924 : 0x16958944, dramcont + UMC_CMDCTLB); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 55 | |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 56 | if (size == 1) |
| 57 | writel(0x00240512, dramcont + UMC_SPCCTLA); |
| 58 | else if (size == 2) |
| 59 | writel(0x00350512, dramcont + UMC_SPCCTLA); |
| 60 | |
| 61 | writel(0x00ff0006, dramcont + UMC_SPCCTLB); |
| 62 | writel(0x000a00ac, dramcont + UMC_RDATACTL_D0); |
| 63 | writel(0x04060806, dramcont + UMC_WDATACTL_D0); |
| 64 | writel(0x04a02000, dramcont + UMC_DATASET); |
| 65 | writel(0x00000000, ca_base + 0x2300); |
| 66 | writel(0x00400020, dramcont + UMC_DCCGCTL); |
| 67 | writel(0x00000003, dramcont + 0x7000); |
| 68 | writel(0x0000004f, dramcont + 0x8000); |
| 69 | writel(0x000000c3, dramcont + 0x8004); |
| 70 | writel(0x00000077, dramcont + 0x8008); |
| 71 | writel(0x0000003b, dramcont + UMC_DICGCTLA); |
| 72 | writel(0x020a0808, dramcont + UMC_DICGCTLB); |
| 73 | writel(0x00000004, dramcont + UMC_FLOWCTLG); |
| 74 | writel(0x80000201, ca_base + 0xc20); |
| 75 | writel(0x0801e01e, dramcont + UMC_FLOWCTLA); |
| 76 | writel(0x00200000, dramcont + UMC_FLOWCTLB); |
| 77 | writel(0x00004444, dramcont + UMC_FLOWCTLC); |
| 78 | writel(0x200a0a00, dramcont + UMC_SPCSETB); |
| 79 | writel(0x00000000, dramcont + UMC_SPCSETD); |
| 80 | writel(0x00000520, dramcont + UMC_DFICUPDCTLA); |
| 81 | } |
| 82 | |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 83 | static int umc_init_sub(int freq, int size_ch0, int size_ch1, bool ddr3plus) |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 84 | { |
| 85 | void __iomem *ssif_base = (void __iomem *)UMC_SSIF_BASE; |
| 86 | void __iomem *ca_base0 = (void __iomem *)UMC_CA_BASE(0); |
| 87 | void __iomem *ca_base1 = (void __iomem *)UMC_CA_BASE(1); |
| 88 | void __iomem *dramcont0 = (void __iomem *)UMC_DRAMCONT_BASE(0); |
| 89 | void __iomem *dramcont1 = (void __iomem *)UMC_DRAMCONT_BASE(1); |
Masahiro Yamada | b614e16 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 90 | void __iomem *phy0_0 = (void __iomem *)DDRPHY_BASE(0, 0); |
| 91 | void __iomem *phy1_0 = (void __iomem *)DDRPHY_BASE(1, 0); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 92 | |
| 93 | umc_dram_init_start(dramcont0); |
| 94 | umc_dram_init_start(dramcont1); |
| 95 | umc_dram_init_poll(dramcont0); |
| 96 | umc_dram_init_poll(dramcont1); |
| 97 | |
| 98 | writel(0x00000101, dramcont0 + UMC_DIOCTLA); |
| 99 | |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 100 | ph1_sld8_ddrphy_init(phy0_0, freq, size_ch0, ddr3plus); |
Masahiro Yamada | b614e16 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 101 | |
| 102 | ddrphy_prepare_training(phy0_0, 0); |
| 103 | ddrphy_training(phy0_0); |
| 104 | |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 105 | writel(0x00000101, dramcont1 + UMC_DIOCTLA); |
| 106 | |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 107 | ph1_sld8_ddrphy_init(phy1_0, freq, size_ch1, ddr3plus); |
Masahiro Yamada | b614e16 | 2014-12-19 20:20:52 +0900 | [diff] [blame] | 108 | |
| 109 | ddrphy_prepare_training(phy1_0, 1); |
| 110 | ddrphy_training(phy1_0); |
| 111 | |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 112 | umc_dramcont_init(dramcont0, ca_base0, size_ch0, freq, ddr3plus); |
| 113 | umc_dramcont_init(dramcont1, ca_base1, size_ch1, freq, ddr3plus); |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 114 | |
| 115 | umc_start_ssif(ssif_base); |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 120 | int ph1_sld8_umc_init(const struct uniphier_board_data *bd) |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 121 | { |
Masahiro Yamada | 46abfcc | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 122 | if ((bd->dram_ch[0].size == SZ_128M || bd->dram_ch[0].size == SZ_256M) && |
| 123 | (bd->dram_ch[1].size == SZ_128M || bd->dram_ch[1].size == SZ_256M) && |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 124 | bd->dram_freq == 1333 && |
Masahiro Yamada | 46abfcc | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 125 | bd->dram_ch[0].width == 16 && bd->dram_ch[1].width == 16) { |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 126 | return umc_init_sub(bd->dram_freq, |
Masahiro Yamada | 46abfcc | 2016-02-26 14:21:34 +0900 | [diff] [blame] | 127 | bd->dram_ch[0].size / SZ_128M, |
Masahiro Yamada | 4021b43 | 2016-02-26 14:21:40 +0900 | [diff] [blame^] | 128 | bd->dram_ch[1].size / SZ_128M, |
| 129 | bd->dram_ddr3plus); |
Masahiro Yamada | 323d1f9 | 2015-09-22 00:27:39 +0900 | [diff] [blame] | 130 | } else { |
| 131 | pr_err("Unsupported DDR configuration\n"); |
| 132 | return -EINVAL; |
| 133 | } |
Masahiro Yamada | 5894ca0 | 2014-10-03 19:21:06 +0900 | [diff] [blame] | 134 | } |