Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 2 | /* |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 3 | * Mem setup common file for different types of DDR present on Exynos boards. |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2012 Samsung Electronics |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Tom Rini | 525a68e | 2024-04-30 07:35:52 -0600 | [diff] [blame] | 8 | #include <linux/types.h> |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 9 | #include <asm/arch/spl.h> |
| 10 | |
| 11 | #include "clock_init.h" |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 12 | #include "common_setup.h" |
| 13 | #include "exynos5_setup.h" |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 14 | |
| 15 | #define ZQ_INIT_TIMEOUT 10000 |
| 16 | |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 17 | int dmc_config_zq(struct mem_timings *mem, uint32_t *phy0_con16, |
| 18 | uint32_t *phy1_con16, uint32_t *phy0_con17, |
| 19 | uint32_t *phy1_con17) |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 20 | { |
| 21 | unsigned long val = 0; |
| 22 | int i; |
| 23 | |
| 24 | /* |
| 25 | * ZQ Calibration: |
| 26 | * Select Driver Strength, |
| 27 | * long calibration for manual calibration |
| 28 | */ |
| 29 | val = PHY_CON16_RESET_VAL; |
| 30 | val |= mem->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT; |
| 31 | val |= mem->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT; |
| 32 | val |= ZQ_CLK_DIV_EN; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 33 | writel(val, phy0_con16); |
| 34 | writel(val, phy1_con16); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 35 | |
| 36 | /* Disable termination */ |
| 37 | if (mem->zq_mode_noterm) |
| 38 | val |= PHY_CON16_ZQ_MODE_NOTERM_MASK; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 39 | writel(val, phy0_con16); |
| 40 | writel(val, phy1_con16); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 41 | |
| 42 | /* ZQ_MANUAL_START: Enable */ |
| 43 | val |= ZQ_MANUAL_STR; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 44 | writel(val, phy0_con16); |
| 45 | writel(val, phy1_con16); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 46 | |
| 47 | /* ZQ_MANUAL_START: Disable */ |
| 48 | val &= ~ZQ_MANUAL_STR; |
| 49 | |
| 50 | /* |
| 51 | * Since we are manaully calibrating the ZQ values, |
| 52 | * we are looping for the ZQ_init to complete. |
| 53 | */ |
| 54 | i = ZQ_INIT_TIMEOUT; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 55 | while ((readl(phy0_con17) & ZQ_DONE) != ZQ_DONE && i > 0) { |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 56 | sdelay(100); |
| 57 | i--; |
| 58 | } |
| 59 | if (!i) |
| 60 | return -1; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 61 | writel(val, phy0_con16); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 62 | |
| 63 | i = ZQ_INIT_TIMEOUT; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 64 | while ((readl(phy1_con17) & ZQ_DONE) != ZQ_DONE && i > 0) { |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 65 | sdelay(100); |
| 66 | i--; |
| 67 | } |
| 68 | if (!i) |
| 69 | return -1; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 70 | writel(val, phy1_con16); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 75 | void update_reset_dll(uint32_t *phycontrol0, enum ddr_mode mode) |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 76 | { |
| 77 | unsigned long val; |
| 78 | |
| 79 | if (mode == DDR_MODE_DDR3) { |
| 80 | val = MEM_TERM_EN | PHY_TERM_EN | DMC_CTRL_SHGATE; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 81 | writel(val, phycontrol0); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* Update DLL Information: Force DLL Resyncronization */ |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 85 | val = readl(phycontrol0); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 86 | val |= FP_RSYNC; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 87 | writel(val, phycontrol0); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 88 | |
| 89 | /* Reset Force DLL Resyncronization */ |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 90 | val = readl(phycontrol0); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 91 | val &= ~FP_RSYNC; |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 92 | writel(val, phycontrol0); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 95 | void dmc_config_mrs(struct mem_timings *mem, uint32_t *directcmd) |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 96 | { |
| 97 | int channel, chip; |
| 98 | |
| 99 | for (channel = 0; channel < mem->dmc_channels; channel++) { |
| 100 | unsigned long mask; |
| 101 | |
| 102 | mask = channel << DIRECT_CMD_CHANNEL_SHIFT; |
| 103 | for (chip = 0; chip < mem->chips_to_configure; chip++) { |
| 104 | int i; |
| 105 | |
| 106 | mask |= chip << DIRECT_CMD_CHIP_SHIFT; |
| 107 | |
| 108 | /* Sending NOP command */ |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 109 | writel(DIRECT_CMD_NOP | mask, directcmd); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * TODO(alim.akhtar@samsung.com): Do we need these |
| 113 | * delays? This one and the next were not there for |
| 114 | * DDR3. |
| 115 | */ |
| 116 | sdelay(0x10000); |
| 117 | |
| 118 | /* Sending EMRS/MRS commands */ |
| 119 | for (i = 0; i < MEM_TIMINGS_MSR_COUNT; i++) { |
| 120 | writel(mem->direct_cmd_msr[i] | mask, |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 121 | directcmd); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 122 | sdelay(0x10000); |
| 123 | } |
| 124 | |
| 125 | if (mem->send_zq_init) { |
| 126 | /* Sending ZQINIT command */ |
| 127 | writel(DIRECT_CMD_ZQINIT | mask, |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 128 | directcmd); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 129 | |
| 130 | sdelay(10000); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 136 | void dmc_config_prech(struct mem_timings *mem, uint32_t *directcmd) |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 137 | { |
| 138 | int channel, chip; |
| 139 | |
| 140 | for (channel = 0; channel < mem->dmc_channels; channel++) { |
| 141 | unsigned long mask; |
| 142 | |
| 143 | mask = channel << DIRECT_CMD_CHANNEL_SHIFT; |
| 144 | for (chip = 0; chip < mem->chips_per_channel; chip++) { |
| 145 | mask |= chip << DIRECT_CMD_CHIP_SHIFT; |
| 146 | |
| 147 | /* PALL (all banks precharge) CMD */ |
Rajeshwari Birje | 2d7f08c | 2013-12-26 09:44:22 +0530 | [diff] [blame] | 148 | writel(DIRECT_CMD_PALL | mask, directcmd); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 149 | sdelay(0x10000); |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
Rajeshwari Shinde | bed2442 | 2013-07-04 12:29:17 +0530 | [diff] [blame] | 154 | void mem_ctrl_init(int reset) |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 155 | { |
| 156 | struct spl_machine_param *param = spl_get_machine_params(); |
| 157 | struct mem_timings *mem; |
| 158 | int ret; |
| 159 | |
| 160 | mem = clock_get_mem_timings(); |
| 161 | |
| 162 | /* If there are any other memory variant, add their init call below */ |
| 163 | if (param->mem_type == DDR_MODE_DDR3) { |
Akshay Saraswat | 24c3e95 | 2014-05-26 19:17:03 +0530 | [diff] [blame] | 164 | ret = ddr3_mem_ctrl_init(mem, reset); |
Rajeshwari Shinde | 6558d27 | 2012-07-03 20:02:56 +0000 | [diff] [blame] | 165 | if (ret) { |
| 166 | /* will hang if failed to init memory control */ |
| 167 | while (1) |
| 168 | ; |
| 169 | } |
| 170 | } else { |
| 171 | /* will hang if unknow memory type */ |
| 172 | while (1) |
| 173 | ; |
| 174 | } |
| 175 | } |