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> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 18 | #include <malloc.h> |
| 19 | #include <sdhci.h> |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 20 | #include <zynqmp_tap_delay.h> |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 21 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 22 | #define SDHCI_ARASAN_ITAPDLY_REGISTER 0xF0F8 |
| 23 | #define SDHCI_ARASAN_ITAPDLY_SEL_MASK GENMASK(7, 0) |
| 24 | #define SDHCI_ARASAN_OTAPDLY_REGISTER 0xF0FC |
| 25 | #define SDHCI_ARASAN_OTAPDLY_SEL_MASK GENMASK(5, 0) |
| 26 | #define SDHCI_ITAPDLY_CHGWIN BIT(9) |
| 27 | #define SDHCI_ITAPDLY_ENABLE BIT(8) |
| 28 | #define SDHCI_OTAPDLY_ENABLE BIT(6) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 29 | |
Michal Simek | 5b5101e | 2020-10-23 04:58:59 -0600 | [diff] [blame] | 30 | #define SDHCI_TUNING_LOOP_COUNT 40 |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 31 | #define MMC_BANK2 0x2 |
| 32 | |
| 33 | struct arasan_sdhci_clk_data { |
| 34 | int clk_phase_in[MMC_TIMING_MMC_HS400 + 1]; |
| 35 | int clk_phase_out[MMC_TIMING_MMC_HS400 + 1]; |
| 36 | }; |
Michal Simek | 5b5101e | 2020-10-23 04:58:59 -0600 | [diff] [blame] | 37 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 38 | struct arasan_sdhci_plat { |
| 39 | struct mmc_config cfg; |
| 40 | struct mmc mmc; |
| 41 | }; |
| 42 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 43 | struct arasan_sdhci_priv { |
| 44 | struct sdhci_host *host; |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 45 | struct arasan_sdhci_clk_data clk_data; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 46 | u8 deviceid; |
| 47 | u8 bank; |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 48 | u8 no_1p8; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 49 | }; |
| 50 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 51 | #if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL) |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 52 | /* Default settings for ZynqMP Clock Phases */ |
| 53 | const u32 zynqmp_iclk_phases[] = {0, 63, 63, 0, 63, 0, 0, 183, 54, 0, 0}; |
| 54 | const u32 zynqmp_oclk_phases[] = {0, 72, 60, 0, 60, 72, 135, 48, 72, 135, 0}; |
| 55 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 56 | /* Default settings for Versal Clock Phases */ |
| 57 | const u32 versal_iclk_phases[] = {0, 132, 132, 0, 132, 0, 0, 162, 90, 0, 0}; |
| 58 | const u32 versal_oclk_phases[] = {0, 60, 48, 0, 48, 72, 90, 36, 60, 90, 0}; |
| 59 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 60 | static const u8 mode2timing[] = { |
Ashok Reddy Soma | 0afdfe3 | 2020-10-23 04:58:58 -0600 | [diff] [blame] | 61 | [MMC_LEGACY] = MMC_TIMING_LEGACY, |
| 62 | [MMC_HS] = MMC_TIMING_MMC_HS, |
| 63 | [SD_HS] = MMC_TIMING_SD_HS, |
| 64 | [MMC_HS_52] = MMC_TIMING_UHS_SDR50, |
| 65 | [MMC_DDR_52] = MMC_TIMING_UHS_DDR50, |
| 66 | [UHS_SDR12] = MMC_TIMING_UHS_SDR12, |
| 67 | [UHS_SDR25] = MMC_TIMING_UHS_SDR25, |
| 68 | [UHS_SDR50] = MMC_TIMING_UHS_SDR50, |
| 69 | [UHS_DDR50] = MMC_TIMING_UHS_DDR50, |
| 70 | [UHS_SDR104] = MMC_TIMING_UHS_SDR104, |
| 71 | [MMC_HS_200] = MMC_TIMING_MMC_HS200, |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 72 | }; |
| 73 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 74 | static void arasan_zynqmp_dll_reset(struct sdhci_host *host, u8 deviceid) |
| 75 | { |
| 76 | u16 clk; |
| 77 | unsigned long timeout; |
| 78 | |
| 79 | clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); |
| 80 | clk &= ~(SDHCI_CLOCK_CARD_EN); |
| 81 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 82 | |
| 83 | /* Issue DLL Reset */ |
| 84 | zynqmp_dll_reset(deviceid); |
| 85 | |
| 86 | /* Wait max 20 ms */ |
| 87 | timeout = 100; |
| 88 | while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL)) |
| 89 | & SDHCI_CLOCK_INT_STABLE)) { |
| 90 | if (timeout == 0) { |
| 91 | dev_err(mmc_dev(host->mmc), |
| 92 | ": Internal clock never stabilised.\n"); |
| 93 | return; |
| 94 | } |
| 95 | timeout--; |
| 96 | udelay(1000); |
| 97 | } |
| 98 | |
| 99 | clk |= SDHCI_CLOCK_CARD_EN; |
| 100 | sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); |
| 101 | } |
| 102 | |
| 103 | static int arasan_sdhci_execute_tuning(struct mmc *mmc, u8 opcode) |
| 104 | { |
| 105 | struct mmc_cmd cmd; |
| 106 | struct mmc_data data; |
| 107 | u32 ctrl; |
| 108 | struct sdhci_host *host; |
| 109 | struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev); |
Michal Simek | 91e95ff | 2018-06-13 09:12:29 +0200 | [diff] [blame] | 110 | char tuning_loop_counter = SDHCI_TUNING_LOOP_COUNT; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 111 | u8 deviceid; |
| 112 | |
| 113 | debug("%s\n", __func__); |
| 114 | |
| 115 | host = priv->host; |
| 116 | deviceid = priv->deviceid; |
| 117 | |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 118 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 119 | ctrl |= SDHCI_CTRL_EXEC_TUNING; |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 120 | sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 121 | |
| 122 | mdelay(1); |
| 123 | |
| 124 | arasan_zynqmp_dll_reset(host, deviceid); |
| 125 | |
| 126 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE); |
| 127 | sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE); |
| 128 | |
| 129 | do { |
| 130 | cmd.cmdidx = opcode; |
| 131 | cmd.resp_type = MMC_RSP_R1; |
| 132 | cmd.cmdarg = 0; |
| 133 | |
| 134 | data.blocksize = 64; |
| 135 | data.blocks = 1; |
| 136 | data.flags = MMC_DATA_READ; |
| 137 | |
| 138 | if (tuning_loop_counter-- == 0) |
| 139 | break; |
| 140 | |
| 141 | if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200 && |
| 142 | mmc->bus_width == 8) |
| 143 | data.blocksize = 128; |
| 144 | |
| 145 | sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG, |
| 146 | data.blocksize), |
| 147 | SDHCI_BLOCK_SIZE); |
| 148 | sdhci_writew(host, data.blocks, SDHCI_BLOCK_COUNT); |
| 149 | sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); |
| 150 | |
| 151 | mmc_send_cmd(mmc, &cmd, NULL); |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 152 | ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 153 | |
| 154 | if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK) |
| 155 | udelay(1); |
| 156 | |
| 157 | } while (ctrl & SDHCI_CTRL_EXEC_TUNING); |
| 158 | |
| 159 | if (tuning_loop_counter < 0) { |
| 160 | ctrl &= ~SDHCI_CTRL_TUNED_CLK; |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 161 | sdhci_writel(host, ctrl, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) { |
| 165 | printf("%s:Tuning failed\n", __func__); |
| 166 | return -1; |
| 167 | } |
| 168 | |
| 169 | udelay(1); |
| 170 | arasan_zynqmp_dll_reset(host, deviceid); |
| 171 | |
| 172 | /* Enable only interrupts served by the SD controller */ |
| 173 | sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK, |
| 174 | SDHCI_INT_ENABLE); |
| 175 | /* Mask all sdhci interrupt sources */ |
| 176 | sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 181 | /** |
| 182 | * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays |
| 183 | * |
| 184 | * Set the SD Output Clock Tap Delays for Output path |
| 185 | * |
| 186 | * @host: Pointer to the sdhci_host structure. |
| 187 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 188 | * Return: 0 |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 189 | */ |
| 190 | static int sdhci_zynqmp_sdcardclk_set_phase(struct sdhci_host *host, |
| 191 | int degrees) |
| 192 | { |
| 193 | struct arasan_sdhci_priv *priv = dev_get_priv(host->mmc->dev); |
| 194 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 195 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 196 | int timing = mode2timing[mmc->selected_mode]; |
| 197 | |
| 198 | /* |
| 199 | * This is applicable for SDHCI_SPEC_300 and above |
| 200 | * ZynqMP does not set phase for <=25MHz clock. |
| 201 | * If degrees is zero, no need to do anything. |
| 202 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 203 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 204 | return 0; |
| 205 | |
| 206 | switch (timing) { |
| 207 | case MMC_TIMING_MMC_HS: |
| 208 | case MMC_TIMING_SD_HS: |
| 209 | case MMC_TIMING_UHS_SDR25: |
| 210 | case MMC_TIMING_UHS_DDR50: |
| 211 | case MMC_TIMING_MMC_DDR52: |
| 212 | /* For 50MHz clock, 30 Taps are available */ |
| 213 | tap_max = 30; |
| 214 | break; |
| 215 | case MMC_TIMING_UHS_SDR50: |
| 216 | /* For 100MHz clock, 15 Taps are available */ |
| 217 | tap_max = 15; |
| 218 | break; |
| 219 | case MMC_TIMING_UHS_SDR104: |
| 220 | case MMC_TIMING_MMC_HS200: |
| 221 | /* For 200MHz clock, 8 Taps are available */ |
| 222 | tap_max = 8; |
| 223 | default: |
| 224 | break; |
| 225 | } |
| 226 | |
| 227 | tap_delay = (degrees * tap_max) / 360; |
| 228 | |
| 229 | arasan_zynqmp_set_tapdelay(priv->deviceid, 0, tap_delay); |
| 230 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 231 | return 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
| 235 | * sdhci_zynqmp_sampleclk_set_phase - Set the SD Input Clock Tap Delays |
| 236 | * |
| 237 | * Set the SD Input Clock Tap Delays for Input path |
| 238 | * |
| 239 | * @host: Pointer to the sdhci_host structure. |
| 240 | * @degrees: The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 241 | * Return: 0 |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 242 | */ |
| 243 | static int sdhci_zynqmp_sampleclk_set_phase(struct sdhci_host *host, |
| 244 | int degrees) |
| 245 | { |
| 246 | struct arasan_sdhci_priv *priv = dev_get_priv(host->mmc->dev); |
| 247 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 248 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 249 | int timing = mode2timing[mmc->selected_mode]; |
| 250 | |
| 251 | /* |
| 252 | * This is applicable for SDHCI_SPEC_300 and above |
| 253 | * ZynqMP does not set phase for <=25MHz clock. |
| 254 | * If degrees is zero, no need to do anything. |
| 255 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 256 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 257 | return 0; |
| 258 | |
| 259 | switch (timing) { |
| 260 | case MMC_TIMING_MMC_HS: |
| 261 | case MMC_TIMING_SD_HS: |
| 262 | case MMC_TIMING_UHS_SDR25: |
| 263 | case MMC_TIMING_UHS_DDR50: |
| 264 | case MMC_TIMING_MMC_DDR52: |
| 265 | /* For 50MHz clock, 120 Taps are available */ |
| 266 | tap_max = 120; |
| 267 | break; |
| 268 | case MMC_TIMING_UHS_SDR50: |
| 269 | /* For 100MHz clock, 60 Taps are available */ |
| 270 | tap_max = 60; |
| 271 | break; |
| 272 | case MMC_TIMING_UHS_SDR104: |
| 273 | case MMC_TIMING_MMC_HS200: |
| 274 | /* For 200MHz clock, 30 Taps are available */ |
| 275 | tap_max = 30; |
| 276 | default: |
| 277 | break; |
| 278 | } |
| 279 | |
| 280 | tap_delay = (degrees * tap_max) / 360; |
| 281 | |
| 282 | arasan_zynqmp_set_tapdelay(priv->deviceid, tap_delay, 0); |
| 283 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 284 | return 0; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 285 | } |
| 286 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 287 | /** |
| 288 | * sdhci_versal_sdcardclk_set_phase - Set the SD Output Clock Tap Delays |
| 289 | * |
| 290 | * Set the SD Output Clock Tap Delays for Output path |
| 291 | * |
| 292 | * @host: Pointer to the sdhci_host structure. |
| 293 | * @degrees The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 294 | * Return: 0 |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 295 | */ |
| 296 | static int sdhci_versal_sdcardclk_set_phase(struct sdhci_host *host, |
| 297 | int degrees) |
| 298 | { |
| 299 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 300 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 301 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 302 | u32 regval; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 303 | |
| 304 | /* |
| 305 | * This is applicable for SDHCI_SPEC_300 and above |
| 306 | * Versal does not set phase for <=25MHz clock. |
| 307 | * If degrees is zero, no need to do anything. |
| 308 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 309 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 310 | return 0; |
| 311 | |
| 312 | switch (timing) { |
| 313 | case MMC_TIMING_MMC_HS: |
| 314 | case MMC_TIMING_SD_HS: |
| 315 | case MMC_TIMING_UHS_SDR25: |
| 316 | case MMC_TIMING_UHS_DDR50: |
| 317 | case MMC_TIMING_MMC_DDR52: |
| 318 | /* For 50MHz clock, 30 Taps are available */ |
| 319 | tap_max = 30; |
| 320 | break; |
| 321 | case MMC_TIMING_UHS_SDR50: |
| 322 | /* For 100MHz clock, 15 Taps are available */ |
| 323 | tap_max = 15; |
| 324 | break; |
| 325 | case MMC_TIMING_UHS_SDR104: |
| 326 | case MMC_TIMING_MMC_HS200: |
| 327 | /* For 200MHz clock, 8 Taps are available */ |
| 328 | tap_max = 8; |
| 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | tap_delay = (degrees * tap_max) / 360; |
| 334 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 335 | /* Limit output tap_delay value to 6 bits */ |
| 336 | tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 337 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 338 | /* Set the Clock Phase */ |
| 339 | regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER); |
| 340 | regval |= SDHCI_OTAPDLY_ENABLE; |
| 341 | sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER); |
| 342 | regval &= ~SDHCI_ARASAN_OTAPDLY_SEL_MASK; |
| 343 | regval |= tap_delay; |
| 344 | sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER); |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 345 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 346 | return 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /** |
| 350 | * sdhci_versal_sampleclk_set_phase - Set the SD Input Clock Tap Delays |
| 351 | * |
| 352 | * Set the SD Input Clock Tap Delays for Input path |
| 353 | * |
| 354 | * @host: Pointer to the sdhci_host structure. |
| 355 | * @degrees The clock phase shift between 0 - 359. |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 356 | * Return: 0 |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 357 | */ |
| 358 | static int sdhci_versal_sampleclk_set_phase(struct sdhci_host *host, |
| 359 | int degrees) |
| 360 | { |
| 361 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 362 | u8 tap_delay, tap_max = 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 363 | int timing = mode2timing[mmc->selected_mode]; |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 364 | u32 regval; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 365 | |
| 366 | /* |
| 367 | * This is applicable for SDHCI_SPEC_300 and above |
| 368 | * Versal does not set phase for <=25MHz clock. |
| 369 | * If degrees is zero, no need to do anything. |
| 370 | */ |
Ashok Reddy Soma | 6f64538 | 2021-07-09 05:53:40 -0600 | [diff] [blame] | 371 | if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300) |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 372 | return 0; |
| 373 | |
| 374 | switch (timing) { |
| 375 | case MMC_TIMING_MMC_HS: |
| 376 | case MMC_TIMING_SD_HS: |
| 377 | case MMC_TIMING_UHS_SDR25: |
| 378 | case MMC_TIMING_UHS_DDR50: |
| 379 | case MMC_TIMING_MMC_DDR52: |
| 380 | /* For 50MHz clock, 120 Taps are available */ |
| 381 | tap_max = 120; |
| 382 | break; |
| 383 | case MMC_TIMING_UHS_SDR50: |
| 384 | /* For 100MHz clock, 60 Taps are available */ |
| 385 | tap_max = 60; |
| 386 | break; |
| 387 | case MMC_TIMING_UHS_SDR104: |
| 388 | case MMC_TIMING_MMC_HS200: |
| 389 | /* For 200MHz clock, 30 Taps are available */ |
| 390 | tap_max = 30; |
| 391 | default: |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | tap_delay = (degrees * tap_max) / 360; |
| 396 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 397 | /* Limit input tap_delay value to 8 bits */ |
| 398 | tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 399 | |
Ashok Reddy Soma | 24a5107 | 2021-07-09 05:53:41 -0600 | [diff] [blame^] | 400 | /* Set the Clock Phase */ |
| 401 | regval = sdhci_readl(host, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 402 | regval |= SDHCI_ITAPDLY_CHGWIN; |
| 403 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 404 | regval |= SDHCI_ITAPDLY_ENABLE; |
| 405 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 406 | regval &= ~SDHCI_ARASAN_ITAPDLY_SEL_MASK; |
| 407 | regval |= tap_delay; |
| 408 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
| 409 | regval &= ~SDHCI_ITAPDLY_CHGWIN; |
| 410 | sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER); |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 411 | |
Ashok Reddy Soma | 94a755d | 2021-07-09 05:53:39 -0600 | [diff] [blame] | 412 | return 0; |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 413 | } |
| 414 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 415 | static void arasan_sdhci_set_tapdelay(struct sdhci_host *host) |
| 416 | { |
| 417 | struct arasan_sdhci_priv *priv = dev_get_priv(host->mmc->dev); |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 418 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 419 | struct mmc *mmc = (struct mmc *)host->mmc; |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 420 | struct udevice *dev = mmc->dev; |
| 421 | u8 timing = mode2timing[mmc->selected_mode]; |
| 422 | u32 iclk_phase = clk_data->clk_phase_in[timing]; |
| 423 | u32 oclk_phase = clk_data->clk_phase_out[timing]; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 424 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 425 | 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] | 426 | |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 427 | if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) && |
| 428 | device_is_compatible(dev, "xlnx,zynqmp-8.9a")) { |
| 429 | sdhci_zynqmp_sampleclk_set_phase(host, iclk_phase); |
| 430 | sdhci_zynqmp_sdcardclk_set_phase(host, oclk_phase); |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 431 | } else if (IS_ENABLED(CONFIG_ARCH_VERSAL) && |
| 432 | device_is_compatible(dev, "xlnx,versal-8.9a")) { |
| 433 | sdhci_versal_sampleclk_set_phase(host, iclk_phase); |
| 434 | sdhci_versal_sdcardclk_set_phase(host, oclk_phase); |
Ashok Reddy Soma | 8f62986 | 2020-10-23 04:59:01 -0600 | [diff] [blame] | 435 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 438 | static void arasan_dt_read_clk_phase(struct udevice *dev, unsigned char timing, |
| 439 | const char *prop) |
| 440 | { |
| 441 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 442 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
| 443 | u32 clk_phase[2] = {0}; |
| 444 | |
| 445 | /* |
| 446 | * Read Tap Delay values from DT, if the DT does not contain the |
| 447 | * Tap Values then use the pre-defined values |
| 448 | */ |
| 449 | if (dev_read_u32_array(dev, prop, &clk_phase[0], 2)) { |
| 450 | dev_dbg(dev, "Using predefined clock phase for %s = %d %d\n", |
| 451 | prop, clk_data->clk_phase_in[timing], |
| 452 | clk_data->clk_phase_out[timing]); |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | /* The values read are Input and Output Clock Delays in order */ |
| 457 | clk_data->clk_phase_in[timing] = clk_phase[0]; |
| 458 | clk_data->clk_phase_out[timing] = clk_phase[1]; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * arasan_dt_parse_clk_phases - Read Tap Delay values from DT |
| 463 | * |
| 464 | * Called at initialization to parse the values of Tap Delays. |
| 465 | * |
| 466 | * @dev: Pointer to our struct udevice. |
| 467 | */ |
| 468 | static void arasan_dt_parse_clk_phases(struct udevice *dev) |
| 469 | { |
| 470 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 471 | struct arasan_sdhci_clk_data *clk_data = &priv->clk_data; |
| 472 | int i; |
| 473 | |
| 474 | if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) && |
| 475 | device_is_compatible(dev, "xlnx,zynqmp-8.9a")) { |
| 476 | for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) { |
| 477 | clk_data->clk_phase_in[i] = zynqmp_iclk_phases[i]; |
| 478 | clk_data->clk_phase_out[i] = zynqmp_oclk_phases[i]; |
| 479 | } |
| 480 | |
| 481 | if (priv->bank == MMC_BANK2) { |
| 482 | clk_data->clk_phase_out[MMC_TIMING_UHS_SDR104] = 90; |
| 483 | clk_data->clk_phase_out[MMC_TIMING_MMC_HS200] = 90; |
| 484 | } |
| 485 | } |
| 486 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 487 | if (IS_ENABLED(CONFIG_ARCH_VERSAL) && |
| 488 | device_is_compatible(dev, "xlnx,versal-8.9a")) { |
| 489 | for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) { |
| 490 | clk_data->clk_phase_in[i] = versal_iclk_phases[i]; |
| 491 | clk_data->clk_phase_out[i] = versal_oclk_phases[i]; |
| 492 | } |
| 493 | } |
| 494 | |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 495 | arasan_dt_read_clk_phase(dev, MMC_TIMING_LEGACY, |
| 496 | "clk-phase-legacy"); |
| 497 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS, |
| 498 | "clk-phase-mmc-hs"); |
| 499 | arasan_dt_read_clk_phase(dev, MMC_TIMING_SD_HS, |
| 500 | "clk-phase-sd-hs"); |
| 501 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR12, |
| 502 | "clk-phase-uhs-sdr12"); |
| 503 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR25, |
| 504 | "clk-phase-uhs-sdr25"); |
| 505 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR50, |
| 506 | "clk-phase-uhs-sdr50"); |
| 507 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR104, |
| 508 | "clk-phase-uhs-sdr104"); |
| 509 | arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_DDR50, |
| 510 | "clk-phase-uhs-ddr50"); |
| 511 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_DDR52, |
| 512 | "clk-phase-mmc-ddr52"); |
| 513 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS200, |
| 514 | "clk-phase-mmc-hs200"); |
| 515 | arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS400, |
| 516 | "clk-phase-mmc-hs400"); |
| 517 | } |
| 518 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 519 | static void arasan_sdhci_set_control_reg(struct sdhci_host *host) |
| 520 | { |
| 521 | struct mmc *mmc = (struct mmc *)host->mmc; |
| 522 | u32 reg; |
| 523 | |
Siva Durga Prasad Paladugu | ed9c012 | 2018-05-29 20:03:11 +0530 | [diff] [blame] | 524 | if (!IS_SD(mmc)) |
| 525 | return; |
| 526 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 527 | if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180) { |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 528 | reg = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 529 | reg |= SDHCI_CTRL_VDD_180; |
| 530 | sdhci_writew(host, reg, SDHCI_HOST_CONTROL2); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (mmc->selected_mode > SD_HS && |
Ashok Reddy Soma | 4179ee8 | 2020-10-23 04:59:03 -0600 | [diff] [blame] | 534 | mmc->selected_mode <= MMC_HS_200) |
Faiz Abbas | 2eddc00 | 2019-06-11 00:43:40 +0530 | [diff] [blame] | 535 | sdhci_set_uhs_timing(host); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 536 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 537 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 538 | const struct sdhci_ops arasan_ops = { |
Michal Simek | e232bd7 | 2020-09-14 13:00:40 +0200 | [diff] [blame] | 539 | .platform_execute_tuning = &arasan_sdhci_execute_tuning, |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 540 | .set_delay = &arasan_sdhci_set_tapdelay, |
| 541 | .set_control_reg = &arasan_sdhci_set_control_reg, |
| 542 | }; |
| 543 | #endif |
| 544 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 545 | static int arasan_sdhci_probe(struct udevice *dev) |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 546 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 547 | struct arasan_sdhci_plat *plat = dev_get_plat(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 548 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 549 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
| 550 | struct sdhci_host *host; |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 551 | struct clk clk; |
| 552 | unsigned long clock; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 553 | int ret; |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 554 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 555 | host = priv->host; |
| 556 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 557 | ret = clk_get_by_index(dev, 0, &clk); |
| 558 | if (ret < 0) { |
| 559 | dev_err(dev, "failed to get clock\n"); |
| 560 | return ret; |
| 561 | } |
| 562 | |
| 563 | clock = clk_get_rate(&clk); |
| 564 | if (IS_ERR_VALUE(clock)) { |
| 565 | dev_err(dev, "failed to get rate\n"); |
| 566 | return clock; |
| 567 | } |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 568 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 569 | debug("%s: CLK %ld\n", __func__, clock); |
| 570 | |
| 571 | ret = clk_enable(&clk); |
Michal Simek | 4171095 | 2021-02-09 15:28:15 +0100 | [diff] [blame] | 572 | if (ret) { |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 573 | dev_err(dev, "failed to enable clock\n"); |
| 574 | return ret; |
| 575 | } |
| 576 | |
Siva Durga Prasad Paladugu | 049e003 | 2014-07-08 15:31:04 +0530 | [diff] [blame] | 577 | host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD | |
Siva Durga Prasad Paladugu | 0d6891b | 2014-01-22 09:17:09 +0100 | [diff] [blame] | 578 | SDHCI_QUIRK_BROKEN_R1B; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 579 | |
| 580 | #ifdef CONFIG_ZYNQ_HISPD_BROKEN |
Hannes Schmelzer | 94a5bbc | 2018-03-07 08:00:57 +0100 | [diff] [blame] | 581 | host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE; |
Siva Durga Prasad Paladugu | a1619fe | 2016-01-12 15:12:16 +0530 | [diff] [blame] | 582 | #endif |
| 583 | |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 584 | if (priv->no_1p8) |
| 585 | host->quirks |= SDHCI_QUIRK_NO_1_8_V; |
| 586 | |
Benedikt Grassl | 529e6f0 | 2020-04-14 07:32:12 +0200 | [diff] [blame] | 587 | plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ; |
| 588 | |
| 589 | ret = mmc_of_parse(dev, &plat->cfg); |
| 590 | if (ret) |
| 591 | return ret; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 592 | |
Stefan Herbrechtsmeier | 739ae40 | 2017-01-17 16:27:32 +0100 | [diff] [blame] | 593 | host->max_clk = clock; |
Stefan Herbrechtsmeier | bc47e0e | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 594 | |
Matwey V. Kornilov | 194b860 | 2019-08-01 18:00:05 +0300 | [diff] [blame] | 595 | host->mmc = &plat->mmc; |
| 596 | host->mmc->dev = dev; |
| 597 | host->mmc->priv = host; |
| 598 | |
Benedikt Grassl | 529e6f0 | 2020-04-14 07:32:12 +0200 | [diff] [blame] | 599 | ret = sdhci_setup_cfg(&plat->cfg, host, plat->cfg.f_max, |
Jaehoon Chung | 8a5ffbb | 2016-07-26 19:06:24 +0900 | [diff] [blame] | 600 | CONFIG_ZYNQ_SDHCI_MIN_FREQ); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 601 | if (ret) |
| 602 | return ret; |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 603 | upriv->mmc = host->mmc; |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 604 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 605 | return sdhci_probe(dev); |
Michal Simek | 0dd222b | 2013-04-22 14:56:49 +0200 | [diff] [blame] | 606 | } |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 607 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 608 | static int arasan_sdhci_of_to_plat(struct udevice *dev) |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 609 | { |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 610 | struct arasan_sdhci_priv *priv = dev_get_priv(dev); |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 611 | |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 612 | priv->host = calloc(1, sizeof(struct sdhci_host)); |
| 613 | if (!priv->host) |
| 614 | return -1; |
| 615 | |
| 616 | priv->host->name = dev->name; |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 617 | |
Ashok Reddy Soma | 568edfd | 2020-10-23 04:59:02 -0600 | [diff] [blame] | 618 | #if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL) |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 619 | priv->host->ops = &arasan_ops; |
Michal Simek | 33a6b77 | 2020-10-23 04:59:00 -0600 | [diff] [blame] | 620 | arasan_dt_parse_clk_phases(dev); |
Siva Durga Prasad Paladugu | cad14a8 | 2018-04-19 12:37:09 +0530 | [diff] [blame] | 621 | #endif |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 622 | |
Michal Simek | 921a8de | 2018-05-16 10:57:07 +0200 | [diff] [blame] | 623 | priv->host->ioaddr = (void *)dev_read_addr(dev); |
| 624 | if (IS_ERR(priv->host->ioaddr)) |
| 625 | return PTR_ERR(priv->host->ioaddr); |
| 626 | |
| 627 | priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1); |
Michal Simek | e40ae57 | 2020-07-22 17:46:31 +0200 | [diff] [blame] | 628 | priv->bank = dev_read_u32_default(dev, "xlnx,mio-bank", 0); |
Ashok Reddy Soma | 61e0df9 | 2020-10-23 04:58:57 -0600 | [diff] [blame] | 629 | priv->no_1p8 = dev_read_bool(dev, "no-1-8-v"); |
Stefan Herbrechtsmeier | 5567b42 | 2017-01-17 16:27:33 +0100 | [diff] [blame] | 630 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 631 | return 0; |
| 632 | } |
| 633 | |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 634 | static int arasan_sdhci_bind(struct udevice *dev) |
| 635 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 636 | struct arasan_sdhci_plat *plat = dev_get_plat(dev); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 637 | |
Masahiro Yamada | cdb67f3 | 2016-09-06 22:17:32 +0900 | [diff] [blame] | 638 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 639 | } |
| 640 | |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 641 | static const struct udevice_id arasan_sdhci_ids[] = { |
| 642 | { .compatible = "arasan,sdhci-8.9a" }, |
| 643 | { } |
| 644 | }; |
| 645 | |
| 646 | U_BOOT_DRIVER(arasan_sdhci_drv) = { |
| 647 | .name = "arasan_sdhci", |
| 648 | .id = UCLASS_MMC, |
| 649 | .of_match = arasan_sdhci_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 650 | .of_to_plat = arasan_sdhci_of_to_plat, |
Simon Glass | 4cc87fb | 2016-07-05 17:10:15 -0600 | [diff] [blame] | 651 | .ops = &sdhci_ops, |
| 652 | .bind = arasan_sdhci_bind, |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 653 | .probe = arasan_sdhci_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 654 | .priv_auto = sizeof(struct arasan_sdhci_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 655 | .plat_auto = sizeof(struct arasan_sdhci_plat), |
Michal Simek | 9ecd268 | 2015-11-30 16:13:03 +0100 | [diff] [blame] | 656 | }; |