Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 2 | /* |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 3 | * (C) Copyright 2013 - 2015 Xilinx, Inc. |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 4 | * |
| 5 | * Xilinx Zynq SD Host Controller Interface |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 8 | #include <clk.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 9 | #include <common.h> |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 10 | #include <dm.h> |
Michal Simek | c57ba04 | 2014-02-24 11:16:31 +0100 | [diff] [blame] | 11 | #include <fdtdec.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 12 | #include <linux/delay.h> |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 13 | #include "mmc_private.h" |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 15 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 16 | #include <linux/err.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 17 | #include <linux/libfdt.h> |
Ashok Reddy Soma | 7a5f810 | 2021-08-02 23:20:44 -0600 | [diff] [blame^] | 18 | #include <asm/cache.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 19 | #include <malloc.h> |
| 20 | #include <sdhci.h> |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 21 | #include <zynqmp_firmware.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 22 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 23 | #define SDHCI_ARASAN_ITAPDLY_REGISTER 0xF0F8 |
| 24 | #define SDHCI_ARASAN_ITAPDLY_SEL_MASK GENMASK(7, 0) |
| 25 | #define SDHCI_ARASAN_OTAPDLY_REGISTER 0xF0FC |
| 26 | #define SDHCI_ARASAN_OTAPDLY_SEL_MASK GENMASK(5, 0) |
| 27 | #define SDHCI_ITAPDLY_CHGWIN BIT(9) |
| 28 | #define SDHCI_ITAPDLY_ENABLE BIT(8) |
| 29 | #define SDHCI_OTAPDLY_ENABLE BIT(6) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 30 | |
Michal Simek | 5b5101e | 2020-10-23 04:58:59 -0600 | [diff] [blame] | 31 | #define SDHCI_TUNING_LOOP_COUNT 40 |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 32 | #define MMC_BANK2 0x2 |
| 33 | |
Ashok Reddy Soma | 7a5f810 | 2021-08-02 23:20:44 -0600 | [diff] [blame^] | 34 | #define SD_DLL_CTRL 0xFF180358 |
| 35 | #define SD_ITAP_DLY 0xFF180314 |
| 36 | #define SD_OTAP_DLY 0xFF180318 |
| 37 | #define SD0_DLL_RST BIT(2) |
| 38 | #define SD1_DLL_RST BIT(18) |
| 39 | #define SD0_ITAPCHGWIN BIT(9) |
| 40 | #define SD1_ITAPCHGWIN BIT(25) |
| 41 | #define SD0_ITAPDLYENA BIT(8) |
| 42 | #define SD1_ITAPDLYENA BIT(24) |
| 43 | #define SD0_ITAPDLYSEL_MASK GENMASK(7, 0) |
| 44 | #define SD1_ITAPDLYSEL_MASK GENMASK(23, 16) |
| 45 | #define SD0_OTAPDLYSEL_MASK GENMASK(5, 0) |
| 46 | #define SD1_OTAPDLYSEL_MASK GENMASK(21, 16) |
| 47 | |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 48 | struct arasan_sdhci_clk_data { |
| 49 | int clk_phase_in[MMC_TIMING_MMC_HS400 + 1]; |
| 50 | int clk_phase_out[MMC_TIMING_MMC_HS400 + 1]; |
| 51 | }; |
Michal Simek | 5b5101e | 2020-10-23 04:58:59 -0600 | [diff] [blame] | 52 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 53 | struct arasan_sdhci_plat { |
| 54 | struct mmc_config cfg; |
| 55 | struct mmc mmc; |
| 56 | }; |
| 57 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 58 | struct arasan_sdhci_priv { |
| 59 | struct sdhci_host *host; |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 60 | struct arasan_sdhci_clk_data clk_data; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 61 | u8 deviceid; |
| 62 | u8 bank; |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 63 | u8 no_1p8; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 64 | }; |
| 65 | |
Ashok Reddy Soma | 7a5f810 | 2021-08-02 23:20:44 -0600 | [diff] [blame^] | 66 | /* For Versal platforms zynqmp_mmio_write() won't be available */ |
| 67 | __weak int zynqmp_mmio_write(const u32 address, const u32 mask, const u32 value) |
| 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 72 | #if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL) |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 73 | /* Default settings for ZynqMP Clock Phases */ |
Michal Simek | 635cf4a | 2021-07-09 05:53:44 -0600 | [diff] [blame] | 74 | static const u32 zynqmp_iclk_phases[] = {0, 63, 63, 0, 63, 0, |
| 75 | 0, 183, 54, 0, 0}; |
| 76 | static const u32 zynqmp_oclk_phases[] = {0, 72, 60, 0, 60, 72, |
| 77 | 135, 48, 72, 135, 0}; |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 78 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 79 | /* Default settings for Versal Clock Phases */ |
Michal Simek | 635cf4a | 2021-07-09 05:53:44 -0600 | [diff] [blame] | 80 | static const u32 versal_iclk_phases[] = {0, 132, 132, 0, 132, |
| 81 | 0, 0, 162, 90, 0, 0}; |
| 82 | static const u32 versal_oclk_phases[] = {0, 60, 48, 0, 48, 72, |
| 83 | 90, 36, 60, 90, 0}; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 84 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 85 | static const u8 mode2timing[] = { |
Ashok Reddy Soma | 0afdfe3 | 2020-10-23 04:58:58 -0600 | [diff] [blame] | 86 | [MMC_LEGACY] = MMC_TIMING_LEGACY, |
| 87 | [MMC_HS] = MMC_TIMING_MMC_HS, |
| 88 | [SD_HS] = MMC_TIMING_SD_HS, |
| 89 | [MMC_HS_52] = MMC_TIMING_UHS_SDR50, |
| 90 | [MMC_DDR_52] = MMC_TIMING_UHS_DDR50, |
| 91 | [UHS_SDR12] = MMC_TIMING_UHS_SDR12, |
| 92 | [UHS_SDR25] = MMC_TIMING_UHS_SDR25, |
| 93 | [UHS_SDR50] = MMC_TIMING_UHS_SDR50, |
| 94 | [UHS_DDR50] = MMC_TIMING_UHS_DDR50, |
| 95 | [UHS_SDR104] = MMC_TIMING_UHS_SDR104, |
| 96 | [MMC_HS_200] = MMC_TIMING_MMC_HS200, |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 97 | }; |
| 98 | |
Ashok Reddy Soma | 7a5f810 | 2021-08-02 23:20:44 -0600 | [diff] [blame^] | 99 | static inline int arasan_zynqmp_set_in_tapdelay(u8 node_id, u32 itap_delay) |
| 100 | { |
| 101 | int ret; |
| 102 | |
| 103 | if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) { |
| 104 | if (node_id == NODE_SD_0) { |
| 105 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN, |
| 106 | SD0_ITAPCHGWIN); |
| 107 | if (ret) |
| 108 | return ret; |
| 109 | |
| 110 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYENA, |
| 111 | SD0_ITAPDLYENA); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | |
| 115 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYSEL_MASK, |
| 116 | itap_delay); |
| 117 | if (ret) |
| 118 | return ret; |
| 119 | |
| 120 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN, 0); |
| 121 | if (ret) |
| 122 | return ret; |
| 123 | } |
| 124 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN, |
| 125 | SD1_ITAPCHGWIN); |
| 126 | if (ret) |
| 127 | return ret; |
| 128 | |
| 129 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYENA, |
| 130 | SD1_ITAPDLYENA); |
| 131 | if (ret) |
| 132 | return ret; |
| 133 | |
| 134 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYSEL_MASK, |
| 135 | (itap_delay << 16)); |
| 136 | if (ret) |
| 137 | return ret; |
| 138 | |
| 139 | ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN, 0); |
| 140 | if (ret) |
| 141 | return ret; |
| 142 | } else { |
| 143 | return xilinx_pm_request(PM_IOCTL, (u32)node_id, |
| 144 | IOCTL_SET_SD_TAPDELAY, |
| 145 | PM_TAPDELAY_INPUT, itap_delay, NULL); |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static inline int arasan_zynqmp_set_out_tapdelay(u8 node_id, u32 otap_delay) |
| 152 | { |
| 153 | if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) { |
| 154 | if (node_id == NODE_SD_0) |
| 155 | return zynqmp_mmio_write(SD_OTAP_DLY, |
| 156 | SD0_OTAPDLYSEL_MASK, |
| 157 | otap_delay); |
| 158 | |
| 159 | return zynqmp_mmio_write(SD_OTAP_DLY, SD1_OTAPDLYSEL_MASK, |
| 160 | (otap_delay << 16)); |
| 161 | } else { |
| 162 | return xilinx_pm_request(PM_IOCTL, (u32)node_id, |
| 163 | IOCTL_SET_SD_TAPDELAY, |
| 164 | PM_TAPDELAY_OUTPUT, otap_delay, NULL); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | static inline int zynqmp_dll_reset(u8 node_id, u32 type) |
| 169 | { |
| 170 | if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) { |
| 171 | if (node_id == NODE_SD_0) |
| 172 | return zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST, |
| 173 | type == PM_DLL_RESET_ASSERT ? |
| 174 | SD0_DLL_RST : 0); |
| 175 | |
| 176 | return zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST, |
| 177 | type == PM_DLL_RESET_ASSERT ? |
| 178 | SD1_DLL_RST : 0); |
| 179 | } else { |
| 180 | return xilinx_pm_request(PM_IOCTL, (u32)node_id, |
| 181 | IOCTL_SD_DLL_RESET, type, 0, NULL); |
| 182 | } |
| 183 | } |
| 184 | |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 185 | static int arasan_zynqmp_dll_reset(struct sdhci_host *host, u8 node_id) |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 186 | { |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 187 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 188 | struct udevice *dev = mmc->dev; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 189 | unsigned long timeout; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 190 | int ret; |
| 191 | u16 clk; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 192 | |
| 193 | clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 194 | clk &= ~(SDHCI_CLOCK_CARD_EN); |
| 195 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 196 | |
| 197 | /* Issue DLL Reset */ |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 198 | ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_ASSERT); |
| 199 | if (ret) { |
| 200 | dev_err(dev, "dll_reset assert failed with err: %d\n", ret); |
| 201 | return ret; |
| 202 | } |
| 203 | |
| 204 | /* Allow atleast 1ms delay for proper DLL reset */ |
| 205 | mdelay(1); |
| 206 | ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_RELEASE); |
| 207 | if (ret) { |
| 208 | dev_err(dev, "dll_reset release failed with err: %d\n", ret); |
| 209 | return ret; |
| 210 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 211 | |
| 212 | /* Wait max 20 ms */ |
| 213 | timeout = 100; |
| 214 | while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) |
| 215 | & SDHCI_CLOCK_INT_STABLE)) { |
| 216 | if (timeout == 0) { |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 217 | dev_err(dev, ": Internal clock never stabilised.\n"); |
| 218 | return -EBUSY; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 219 | } |
| 220 | timeout--; |
| 221 | udelay(1000); |
| 222 | } |
| 223 | |
| 224 | clk |= SDHCI_CLOCK_CARD_EN; |
| 225 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 226 | |
| 227 | return 0; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int arasan_sdhci_execute_tuning(struct mmc *mmc, u8 opcode) |
| 231 | { |
| 232 | struct mmc_cmd cmd; |
| 233 | struct mmc_data data; |
| 234 | u32 ctrl; |
| 235 | struct sdhci_host *host; |
| 236 | struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev); |
Michal Simek | 91e95ff | 2018-06-13 09:12:29 +0200 | [diff] [blame] | 237 | char tuning_loop_counter = SDHCI_TUNING_LOOP_COUNT; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 238 | u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 239 | |
| 240 | debug("%s\n", __func__); |
| 241 | |
| 242 | host = priv->host; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 243 | |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 244 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 245 | ctrl |= SDHCI_CTRL_EXEC_TUNING; |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 246 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 247 | |
| 248 | mdelay(1); |
| 249 | |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 250 | arasan_zynqmp_dll_reset(host, node_id); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 251 | |
| 252 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); |
| 253 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); |
| 254 | |
| 255 | do { |
| 256 | cmd.cmdidx = opcode; |
| 257 | cmd.resp_type = MMC_RSP_R1; |
| 258 | cmd.cmdarg = 0; |
| 259 | |
| 260 | data.blocksize = 64; |
| 261 | data.blocks = 1; |
| 262 | data.flags = MMC_DATA_READ; |
| 263 | |
| 264 | if (tuning_loop_counter-- == 0) |
| 265 | break; |
| 266 | |
| 267 | if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200 && |
| 268 | mmc->bus_width == 8) |
| 269 | data.blocksize = 128; |
| 270 | |
| 271 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG, |
| 272 | data.blocksize), |
| 273 | SDHCI_BLOCK_SIZE); |
| 274 | sdhci_writew(host, data.blocks, SDHCI_BLOCK_COUNT); |
| 275 | sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); |
| 276 | |
| 277 | mmc_send_cmd(mmc, &cmd, NULL); |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 278 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 279 | |
| 280 | if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK) |
| 281 | udelay(1); |
| 282 | |
| 283 | } while (ctrl & SDHCI_CTRL_EXEC_TUNING); |
| 284 | |
| 285 | if (tuning_loop_counter < 0) { |
| 286 | ctrl &= ~SDHCI_CTRL_TUNED_CLK; |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 287 | sdhci_writel(host, ctrl, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) { |
| 291 | printf("%s:Tuning failed\n", __func__); |
| 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | udelay(1); |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 296 | arasan_zynqmp_dll_reset(host, node_id); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 297 | |
| 298 | /* Enable only interrupts served by the SD controller */ |
| 299 | sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK, |
| 300 | SDHCI_INT_ENABLE); |
| 301 | /* Mask all sdhci interrupt sources */ |
| 302 | sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE); |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 307 | /** |
| 308 | * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays |
| 309 | * |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 310 | * @host: Pointer to the sdhci_host structure. |
| 311 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 312 | * Return: 0 |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 313 | * |
| 314 | * Set the SD Output Clock Tap Delays for Output path |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 315 | */ |
| 316 | static int sdhci_zynqmp_sdcardclk_set_phase(struct sdhci_host *host, |
| 317 | int degrees) |
| 318 | { |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 319 | struct mmc *mmc = (struct mmc *)host->mmc; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 320 | struct udevice *dev = mmc->dev; |
| 321 | struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev); |
| 322 | u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 323 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 324 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 325 | int ret; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 326 | |
| 327 | /* |
| 328 | * This is applicable for SDHCI_SPEC_300 and above |
| 329 | * ZynqMP does not set phase for <=25MHz clock. |
| 330 | * If degrees is zero, no need to do anything. |
| 331 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 332 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 333 | return 0; |
| 334 | |
| 335 | switch (timing) { |
| 336 | case MMC_TIMING_MMC_HS: |
| 337 | case MMC_TIMING_SD_HS: |
| 338 | case MMC_TIMING_UHS_SDR25: |
| 339 | case MMC_TIMING_UHS_DDR50: |
| 340 | case MMC_TIMING_MMC_DDR52: |
| 341 | /* For 50MHz clock, 30 Taps are available */ |
| 342 | tap_max = 30; |
| 343 | break; |
| 344 | case MMC_TIMING_UHS_SDR50: |
| 345 | /* For 100MHz clock, 15 Taps are available */ |
| 346 | tap_max = 15; |
| 347 | break; |
| 348 | case MMC_TIMING_UHS_SDR104: |
| 349 | case MMC_TIMING_MMC_HS200: |
| 350 | /* For 200MHz clock, 8 Taps are available */ |
| 351 | tap_max = 8; |
| 352 | default: |
| 353 | break; |
| 354 | } |
| 355 | |
| 356 | tap_delay = (degrees * tap_max) / 360; |
| 357 | |
Ashok Reddy Soma | 39a177a | 2021-07-09 05:53:42 -0600 | [diff] [blame] | 358 | /* Limit output tap_delay value to 6 bits */ |
| 359 | tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK; |
| 360 | |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 361 | /* Set the Clock Phase */ |
| 362 | ret = arasan_zynqmp_set_out_tapdelay(node_id, tap_delay); |
| 363 | if (ret) { |
| 364 | dev_err(dev, "Error setting output Tap Delay\n"); |
| 365 | return ret; |
| 366 | } |
| 367 | |
| 368 | /* Release DLL Reset */ |
| 369 | ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_RELEASE); |
| 370 | if (ret) { |
| 371 | dev_err(dev, "dll_reset release failed with err: %d\n", ret); |
| 372 | return ret; |
| 373 | } |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 374 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 375 | return 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
| 379 | * sdhci_zynqmp_sampleclk_set_phase - Set the SD Input Clock Tap Delays |
| 380 | * |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 381 | * @host: Pointer to the sdhci_host structure. |
| 382 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 383 | * Return: 0 |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 384 | * |
| 385 | * Set the SD Input Clock Tap Delays for Input path |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 386 | */ |
| 387 | static int sdhci_zynqmp_sampleclk_set_phase(struct sdhci_host *host, |
| 388 | int degrees) |
| 389 | { |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 390 | struct mmc *mmc = (struct mmc *)host->mmc; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 391 | struct udevice *dev = mmc->dev; |
| 392 | struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev); |
| 393 | u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 394 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 395 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 396 | int ret; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 397 | |
| 398 | /* |
| 399 | * This is applicable for SDHCI_SPEC_300 and above |
| 400 | * ZynqMP does not set phase for <=25MHz clock. |
| 401 | * If degrees is zero, no need to do anything. |
| 402 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 403 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 404 | return 0; |
| 405 | |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 406 | /* Assert DLL Reset */ |
| 407 | ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_ASSERT); |
| 408 | if (ret) { |
| 409 | dev_err(dev, "dll_reset assert failed with err: %d\n", ret); |
| 410 | return ret; |
| 411 | } |
| 412 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 413 | switch (timing) { |
| 414 | case MMC_TIMING_MMC_HS: |
| 415 | case MMC_TIMING_SD_HS: |
| 416 | case MMC_TIMING_UHS_SDR25: |
| 417 | case MMC_TIMING_UHS_DDR50: |
| 418 | case MMC_TIMING_MMC_DDR52: |
| 419 | /* For 50MHz clock, 120 Taps are available */ |
| 420 | tap_max = 120; |
| 421 | break; |
| 422 | case MMC_TIMING_UHS_SDR50: |
| 423 | /* For 100MHz clock, 60 Taps are available */ |
| 424 | tap_max = 60; |
| 425 | break; |
| 426 | case MMC_TIMING_UHS_SDR104: |
| 427 | case MMC_TIMING_MMC_HS200: |
| 428 | /* For 200MHz clock, 30 Taps are available */ |
| 429 | tap_max = 30; |
| 430 | default: |
| 431 | break; |
| 432 | } |
| 433 | |
| 434 | tap_delay = (degrees * tap_max) / 360; |
| 435 | |
Ashok Reddy Soma | 39a177a | 2021-07-09 05:53:42 -0600 | [diff] [blame] | 436 | /* Limit input tap_delay value to 8 bits */ |
| 437 | tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK; |
| 438 | |
Ashok Reddy Soma | 467d078 | 2021-08-02 23:20:43 -0600 | [diff] [blame] | 439 | ret = arasan_zynqmp_set_in_tapdelay(node_id, tap_delay); |
| 440 | if (ret) { |
| 441 | dev_err(dev, "Error setting Input Tap Delay\n"); |
| 442 | return ret; |
| 443 | } |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 444 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 445 | return 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 446 | } |
| 447 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 448 | /** |
| 449 | * sdhci_versal_sdcardclk_set_phase - Set the SD Output Clock Tap Delays |
| 450 | * |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 451 | * @host: Pointer to the sdhci_host structure. |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 452 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 453 | * Return: 0 |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 454 | * |
| 455 | * Set the SD Output Clock Tap Delays for Output path |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 456 | */ |
| 457 | static int sdhci_versal_sdcardclk_set_phase(struct sdhci_host *host, |
| 458 | int degrees) |
| 459 | { |
| 460 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 461 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 462 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 463 | u32 regval; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 464 | |
| 465 | /* |
| 466 | * This is applicable for SDHCI_SPEC_300 and above |
| 467 | * Versal does not set phase for <=25MHz clock. |
| 468 | * If degrees is zero, no need to do anything. |
| 469 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 470 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 471 | return 0; |
| 472 | |
| 473 | switch (timing) { |
| 474 | case MMC_TIMING_MMC_HS: |
| 475 | case MMC_TIMING_SD_HS: |
| 476 | case MMC_TIMING_UHS_SDR25: |
| 477 | case MMC_TIMING_UHS_DDR50: |
| 478 | case MMC_TIMING_MMC_DDR52: |
| 479 | /* For 50MHz clock, 30 Taps are available */ |
| 480 | tap_max = 30; |
| 481 | break; |
| 482 | case MMC_TIMING_UHS_SDR50: |
| 483 | /* For 100MHz clock, 15 Taps are available */ |
| 484 | tap_max = 15; |
| 485 | break; |
| 486 | case MMC_TIMING_UHS_SDR104: |
| 487 | case MMC_TIMING_MMC_HS200: |
| 488 | /* For 200MHz clock, 8 Taps are available */ |
| 489 | tap_max = 8; |
| 490 | default: |
| 491 | break; |
| 492 | } |
| 493 | |
| 494 | tap_delay = (degrees * tap_max) / 360; |
| 495 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 496 | /* Limit output tap_delay value to 6 bits */ |
| 497 | tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 498 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 499 | /* Set the Clock Phase */ |
| 500 | regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER); |
| 501 | regval |= SDHCI_OTAPDLY_ENABLE; |
| 502 | sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER); |
| 503 | regval &= ~SDHCI_ARASAN_OTAPDLY_SEL_MASK; |
| 504 | regval |= tap_delay; |
| 505 | sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER); |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 506 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 507 | return 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | /** |
| 511 | * sdhci_versal_sampleclk_set_phase - Set the SD Input Clock Tap Delays |
| 512 | * |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 513 | * @host: Pointer to the sdhci_host structure. |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 514 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 515 | * Return: 0 |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 516 | * |
| 517 | * Set the SD Input Clock Tap Delays for Input path |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 518 | */ |
| 519 | static int sdhci_versal_sampleclk_set_phase(struct sdhci_host *host, |
| 520 | int degrees) |
| 521 | { |
| 522 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 523 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 524 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 525 | u32 regval; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 526 | |
| 527 | /* |
| 528 | * This is applicable for SDHCI_SPEC_300 and above |
| 529 | * Versal does not set phase for <=25MHz clock. |
| 530 | * If degrees is zero, no need to do anything. |
| 531 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 532 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 533 | return 0; |
| 534 | |
| 535 | switch (timing) { |
| 536 | case MMC_TIMING_MMC_HS: |
| 537 | case MMC_TIMING_SD_HS: |
| 538 | case MMC_TIMING_UHS_SDR25: |
| 539 | case MMC_TIMING_UHS_DDR50: |
| 540 | case MMC_TIMING_MMC_DDR52: |
| 541 | /* For 50MHz clock, 120 Taps are available */ |
| 542 | tap_max = 120; |
| 543 | break; |
| 544 | case MMC_TIMING_UHS_SDR50: |
| 545 | /* For 100MHz clock, 60 Taps are available */ |
| 546 | tap_max = 60; |
| 547 | break; |
| 548 | case MMC_TIMING_UHS_SDR104: |
| 549 | case MMC_TIMING_MMC_HS200: |
| 550 | /* For 200MHz clock, 30 Taps are available */ |
| 551 | tap_max = 30; |
| 552 | default: |
| 553 | break; |
| 554 | } |
| 555 | |
| 556 | tap_delay = (degrees * tap_max) / 360; |
| 557 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 558 | /* Limit input tap_delay value to 8 bits */ |
| 559 | tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 560 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame] | 561 | /* Set the Clock Phase */ |
| 562 | regval = sdhci_readl(host, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 563 | regval |= SDHCI_ITAPDLY_CHGWIN; |
| 564 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 565 | regval |= SDHCI_ITAPDLY_ENABLE; |
| 566 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 567 | regval &= ~SDHCI_ARASAN_ITAPDLY_SEL_MASK; |
| 568 | regval |= tap_delay; |
| 569 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 570 | regval &= ~SDHCI_ITAPDLY_CHGWIN; |
| 571 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 572 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 573 | return 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 574 | } |
| 575 | |
Ashok Reddy Soma | 21fd763 | 2021-08-02 23:20:40 -0600 | [diff] [blame] | 576 | static int arasan_sdhci_set_tapdelay(struct sdhci_host *host) |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 577 | { |
| 578 | struct arasan_sdhci_priv *priv = dev_get_priv(host->mmc->dev); |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 579 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 580 | struct mmc *mmc = (struct mmc *)host->mmc; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 581 | struct udevice *dev = mmc->dev; |
| 582 | u8 timing = mode2timing[mmc->selected_mode]; |
| 583 | u32 iclk_phase = clk_data->clk_phase_in[timing]; |
| 584 | u32 oclk_phase = clk_data->clk_phase_out[timing]; |
Ashok Reddy Soma | 21fd763 | 2021-08-02 23:20:40 -0600 | [diff] [blame] | 585 | int ret; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 586 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 587 | dev_dbg(dev, "%s, host:%s, mode:%d\n", __func__, host->name, timing); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 588 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 589 | if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) && |
| 590 | device_is_compatible(dev, "xlnx,zynqmp-8.9a")) { |
Ashok Reddy Soma | 21fd763 | 2021-08-02 23:20:40 -0600 | [diff] [blame] | 591 | ret = sdhci_zynqmp_sampleclk_set_phase(host, iclk_phase); |
| 592 | if (ret) |
| 593 | return ret; |
| 594 | |
| 595 | ret = sdhci_zynqmp_sdcardclk_set_phase(host, oclk_phase); |
| 596 | if (ret) |
| 597 | return ret; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 598 | } else if (IS_ENABLED(CONFIG_ARCH_VERSAL) && |
| 599 | device_is_compatible(dev, "xlnx,versal-8.9a")) { |
Ashok Reddy Soma | 21fd763 | 2021-08-02 23:20:40 -0600 | [diff] [blame] | 600 | ret = sdhci_versal_sampleclk_set_phase(host, iclk_phase); |
| 601 | if (ret) |
| 602 | return ret; |
| 603 | |
| 604 | ret = sdhci_versal_sdcardclk_set_phase(host, oclk_phase); |
| 605 | if (ret) |
| 606 | return ret; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 607 | } |
Ashok Reddy Soma | 21fd763 | 2021-08-02 23:20:40 -0600 | [diff] [blame] | 608 | |
| 609 | return 0; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 610 | } |
| 611 | |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 612 | static void arasan_dt_read_clk_phase(struct udevice *dev, unsigned char timing, |
| 613 | const char *prop) |
| 614 | { |
| 615 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 616 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
| 617 | u32 clk_phase[2] = {0}; |
| 618 | |
| 619 | /* |
| 620 | * Read Tap Delay values from DT, if the DT does not contain the |
| 621 | * Tap Values then use the pre-defined values |
| 622 | */ |
| 623 | if (dev_read_u32_array(dev, prop, &clk_phase[0], 2)) { |
| 624 | dev_dbg(dev, "Using predefined clock phase for %s = %d %d\n", |
| 625 | prop, clk_data->clk_phase_in[timing], |
| 626 | clk_data->clk_phase_out[timing]); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | /* The values read are Input and Output Clock Delays in order */ |
| 631 | clk_data->clk_phase_in[timing] = clk_phase[0]; |
| 632 | clk_data->clk_phase_out[timing] = clk_phase[1]; |
| 633 | } |
| 634 | |
| 635 | /** |
| 636 | * arasan_dt_parse_clk_phases - Read Tap Delay values from DT |
| 637 | * |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 638 | * @dev: Pointer to our struct udevice. |
Michal Simek | 2a43ab8 | 2021-07-09 05:53:43 -0600 | [diff] [blame] | 639 | * |
| 640 | * Called at initialization to parse the values of Tap Delays. |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 641 | */ |
| 642 | static void arasan_dt_parse_clk_phases(struct udevice *dev) |
| 643 | { |
| 644 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 645 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
| 646 | int i; |
| 647 | |
| 648 | if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) && |
| 649 | device_is_compatible(dev, "xlnx,zynqmp-8.9a")) { |
| 650 | for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) { |
| 651 | clk_data->clk_phase_in[i] = zynqmp_iclk_phases[i]; |
| 652 | clk_data->clk_phase_out[i] = zynqmp_oclk_phases[i]; |
| 653 | } |
| 654 | |
| 655 | if (priv->bank == MMC_BANK2) { |
| 656 | clk_data->clk_phase_out[MMC_TIMING_UHS_SDR104] = 90; |
| 657 | clk_data->clk_phase_out[MMC_TIMING_MMC_HS200] = 90; |
| 658 | } |
| 659 | } |
| 660 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 661 | if (IS_ENABLED(CONFIG_ARCH_VERSAL) && |
| 662 | device_is_compatible(dev, "xlnx,versal-8.9a")) { |
| 663 | for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) { |
| 664 | clk_data->clk_phase_in[i] = versal_iclk_phases[i]; |
| 665 | clk_data->clk_phase_out[i] = versal_oclk_phases[i]; |
| 666 | } |
| 667 | } |
| 668 | |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 669 | arasan_dt_read_clk_phase(dev, MMC_TIMING_LEGACY, |
| 670 | "clk-phase-legacy"); |
| 671 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS, |
| 672 | "clk-phase-mmc-hs"); |
| 673 | arasan_dt_read_clk_phase(dev, MMC_TIMING_SD_HS, |
| 674 | "clk-phase-sd-hs"); |
| 675 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR12, |
| 676 | "clk-phase-uhs-sdr12"); |
| 677 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR25, |
| 678 | "clk-phase-uhs-sdr25"); |
| 679 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR50, |
| 680 | "clk-phase-uhs-sdr50"); |
| 681 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR104, |
| 682 | "clk-phase-uhs-sdr104"); |
| 683 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_DDR50, |
| 684 | "clk-phase-uhs-ddr50"); |
| 685 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_DDR52, |
| 686 | "clk-phase-mmc-ddr52"); |
| 687 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS200, |
| 688 | "clk-phase-mmc-hs200"); |
| 689 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS400, |
| 690 | "clk-phase-mmc-hs400"); |
| 691 | } |
| 692 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 693 | static void arasan_sdhci_set_control_reg(struct sdhci_host *host) |
| 694 | { |
| 695 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 696 | u32 reg; |
| 697 | |
Siva Durga Prasad Paladugu | ed9c012 | 2018-05-29 20:03:11 +0530 | [diff] [blame] | 698 | if (!IS_SD(mmc)) |
| 699 | return; |
| 700 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 701 | if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180) { |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 702 | reg = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 703 | reg |= SDHCI_CTRL_VDD_180; |
| 704 | sdhci_writew(host, reg, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | if (mmc->selected_mode > SD_HS && |
Ashok Reddy Soma | 4179ee8 | 2020-10-23 04:59:03 -0600 | [diff] [blame] | 708 | mmc->selected_mode <= MMC_HS_200) |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 709 | sdhci_set_uhs_timing(host); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 710 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 711 | |
Michal Simek | 635cf4a | 2021-07-09 05:53:44 -0600 | [diff] [blame] | 712 | static const struct sdhci_ops arasan_ops = { |
| 713 | .platform_execute_tuning = &arasan_sdhci_execute_tuning, |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 714 | .set_delay = &arasan_sdhci_set_tapdelay, |
| 715 | .set_control_reg = &arasan_sdhci_set_control_reg, |
| 716 | }; |
| 717 | #endif |
| 718 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 719 | static int arasan_sdhci_probe(struct udevice *dev) |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 720 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 721 | struct arasan_sdhci_plat *plat = dev_get_plat(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 722 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 723 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 724 | struct sdhci_host *host; |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 725 | struct clk clk; |
| 726 | unsigned long clock; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 727 | int ret; |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 728 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 729 | host = priv->host; |
| 730 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 731 | ret = clk_get_by_index(dev, 0, &clk); |
| 732 | if (ret < 0) { |
| 733 | dev_err(dev, "failed to get clock\n"); |
| 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | clock = clk_get_rate(&clk); |
| 738 | if (IS_ERR_VALUE(clock)) { |
| 739 | dev_err(dev, "failed to get rate\n"); |
| 740 | return clock; |
| 741 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 742 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 743 | debug("%s: CLK %ld\n", __func__, clock); |
| 744 | |
| 745 | ret = clk_enable(&clk); |
Michal Simek | 4171095 | 2021-02-09 15:28:15 +0100 | [diff] [blame] | 746 | if (ret) { |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 747 | dev_err(dev, "failed to enable clock\n"); |
| 748 | return ret; |
| 749 | } |
| 750 | |
Siva Durga Prasad Paladugu | 049e003 | 2014-07-08 15:31:04 +0530 | [diff] [blame] | 751 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
Siva Durga Prasad Paladugu | 0d6891b | 2014-01-22 09:17:09 +0100 | [diff] [blame] | 752 | SDHCI_QUIRK_BROKEN_R1B; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 753 | |
| 754 | #ifdef CONFIG_ZYNQ_HISPD_BROKEN |
Hannes Schmelzer | 94a5bbc | 2018-03-07 08:00:57 +0100 | [diff] [blame] | 755 | host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 756 | #endif |
| 757 | |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 758 | if (priv->no_1p8) |
| 759 | host->quirks |= SDHCI_QUIRK_NO_1_8_V; |
| 760 | |
Benedikt Grassl | 529e6f0 | 2020-04-14 07:32:12 +0200 | [diff] [blame] | 761 | plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ; |
| 762 | |
| 763 | ret = mmc_of_parse(dev, &plat->cfg); |
| 764 | if (ret) |
| 765 | return ret; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 766 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 767 | host->max_clk = clock; |
Stefan Herbrechtsmeier | bc47e0e | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 768 | |
Matwey V. Kornilov | 194b860 | 2019-08-01 18:00:05 +0300 | [diff] [blame] | 769 | host->mmc = &plat->mmc; |
| 770 | host->mmc->dev = dev; |
| 771 | host->mmc->priv = host; |
| 772 | |
Benedikt Grassl | 529e6f0 | 2020-04-14 07:32:12 +0200 | [diff] [blame] | 773 | ret = sdhci_setup_cfg(&plat->cfg, host, plat->cfg.f_max, |
Jaehoon Chung | 8a5ffbb | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 774 | CONFIG_ZYNQ_SDHCI_MIN_FREQ); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 775 | if (ret) |
| 776 | return ret; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 777 | upriv->mmc = host->mmc; |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 778 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 779 | return sdhci_probe(dev); |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 780 | } |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 781 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 782 | static int arasan_sdhci_of_to_plat(struct udevice *dev) |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 783 | { |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 784 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 785 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 786 | priv->host = calloc(1, sizeof(struct sdhci_host)); |
| 787 | if (!priv->host) |
| 788 | return -1; |
| 789 | |
| 790 | priv->host->name = dev->name; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 791 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 792 | #if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL) |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 793 | priv->host->ops = &arasan_ops; |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 794 | arasan_dt_parse_clk_phases(dev); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 795 | #endif |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 796 | |
Michal Simek | 921a8de | 2018-05-16 10:57:07 +0200 | [diff] [blame] | 797 | priv->host->ioaddr = (void *)dev_read_addr(dev); |
| 798 | if (IS_ERR(priv->host->ioaddr)) |
| 799 | return PTR_ERR(priv->host->ioaddr); |
| 800 | |
| 801 | priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1); |
Michal Simek | e40ae57 | 2020-07-22 17:46:31 +0200 | [diff] [blame] | 802 | priv->bank = dev_read_u32_default(dev, "xlnx,mio-bank", 0); |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 803 | priv->no_1p8 = dev_read_bool(dev, "no-1-8-v"); |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 804 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 805 | return 0; |
| 806 | } |
| 807 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 808 | static int arasan_sdhci_bind(struct udevice *dev) |
| 809 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 810 | struct arasan_sdhci_plat *plat = dev_get_plat(dev); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 811 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 812 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 813 | } |
| 814 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 815 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 816 | { .compatible = "arasan,sdhci-8.9a" }, |
| 817 | { } |
| 818 | }; |
| 819 | |
| 820 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 821 | .name = "arasan_sdhci", |
| 822 | .id = UCLASS_MMC, |
| 823 | .of_match = arasan_sdhci_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 824 | .of_to_plat = arasan_sdhci_of_to_plat, |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 825 | .ops = &sdhci_ops, |
| 826 | .bind = arasan_sdhci_bind, |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 827 | .probe = arasan_sdhci_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 828 | .priv_auto = sizeof(struct arasan_sdhci_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 829 | .plat_auto = sizeof(struct arasan_sdhci_plat), |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 830 | }; |