blob: 33d00b06c77728ce4117d9aac349a43dda915b90 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Michal Simek0dd222b2013-04-22 14:56:49 +02002/*
Michal Simek9ecd2682015-11-30 16:13:03 +01003 * (C) Copyright 2013 - 2015 Xilinx, Inc.
Michal Simek0dd222b2013-04-22 14:56:49 +02004 *
5 * Xilinx Zynq SD Host Controller Interface
Michal Simek0dd222b2013-04-22 14:56:49 +02006 */
7
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +01008#include <clk.h>
Michal Simek0dd222b2013-04-22 14:56:49 +02009#include <common.h>
Michal Simek9ecd2682015-11-30 16:13:03 +010010#include <dm.h>
Michal Simekc57ba042014-02-24 11:16:31 +010011#include <fdtdec.h>
Simon Glassdbd79542020-05-10 11:40:11 -060012#include <linux/delay.h>
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053013#include "mmc_private.h"
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070015#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070016#include <linux/err.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090017#include <linux/libfdt.h>
Ashok Reddy Soma7a5f8102021-08-02 23:20:44 -060018#include <asm/cache.h>
Michal Simek0dd222b2013-04-22 14:56:49 +020019#include <malloc.h>
20#include <sdhci.h>
Ashok Reddy Soma467d0782021-08-02 23:20:43 -060021#include <zynqmp_firmware.h>
Michal Simek0dd222b2013-04-22 14:56:49 +020022
Ashok Reddy Soma24a51072021-07-09 05:53:41 -060023#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 Soma568edfd2020-10-23 04:59:02 -060030
Michal Simek5b5101e2020-10-23 04:58:59 -060031#define SDHCI_TUNING_LOOP_COUNT 40
Michal Simek33a6b772020-10-23 04:59:00 -060032#define MMC_BANK2 0x2
33
Ashok Reddy Soma7a5f8102021-08-02 23:20:44 -060034#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 Simek33a6b772020-10-23 04:59:00 -060048struct 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 Simek5b5101e2020-10-23 04:58:59 -060052
Simon Glass4cc87fb2016-07-05 17:10:15 -060053struct arasan_sdhci_plat {
54 struct mmc_config cfg;
55 struct mmc mmc;
56};
57
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053058struct arasan_sdhci_priv {
59 struct sdhci_host *host;
Michal Simek33a6b772020-10-23 04:59:00 -060060 struct arasan_sdhci_clk_data clk_data;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053061 u8 deviceid;
62 u8 bank;
Ashok Reddy Soma61e0df92020-10-23 04:58:57 -060063 u8 no_1p8;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053064};
65
Ashok Reddy Soma7a5f8102021-08-02 23:20:44 -060066/* 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
T Karthik Reddyd0618272021-10-01 16:38:38 +053072__weak int xilinx_pm_request(u32 api_id, u32 arg0, u32 arg1, u32 arg2,
73 u32 arg3, u32 *ret_payload)
74{
75 return 0;
76}
77
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -060078#if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL)
Michal Simek33a6b772020-10-23 04:59:00 -060079/* Default settings for ZynqMP Clock Phases */
Michal Simek635cf4a2021-07-09 05:53:44 -060080static const u32 zynqmp_iclk_phases[] = {0, 63, 63, 0, 63, 0,
81 0, 183, 54, 0, 0};
82static const u32 zynqmp_oclk_phases[] = {0, 72, 60, 0, 60, 72,
83 135, 48, 72, 135, 0};
Michal Simek33a6b772020-10-23 04:59:00 -060084
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -060085/* Default settings for Versal Clock Phases */
Michal Simek635cf4a2021-07-09 05:53:44 -060086static const u32 versal_iclk_phases[] = {0, 132, 132, 0, 132,
87 0, 0, 162, 90, 0, 0};
88static const u32 versal_oclk_phases[] = {0, 60, 48, 0, 48, 72,
89 90, 36, 60, 90, 0};
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -060090
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +053091static const u8 mode2timing[] = {
Ashok Reddy Soma0afdfe32020-10-23 04:58:58 -060092 [MMC_LEGACY] = MMC_TIMING_LEGACY,
93 [MMC_HS] = MMC_TIMING_MMC_HS,
94 [SD_HS] = MMC_TIMING_SD_HS,
95 [MMC_HS_52] = MMC_TIMING_UHS_SDR50,
96 [MMC_DDR_52] = MMC_TIMING_UHS_DDR50,
97 [UHS_SDR12] = MMC_TIMING_UHS_SDR12,
98 [UHS_SDR25] = MMC_TIMING_UHS_SDR25,
99 [UHS_SDR50] = MMC_TIMING_UHS_SDR50,
100 [UHS_DDR50] = MMC_TIMING_UHS_DDR50,
101 [UHS_SDR104] = MMC_TIMING_UHS_SDR104,
102 [MMC_HS_200] = MMC_TIMING_MMC_HS200,
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530103};
104
Ashok Reddy Soma7a5f8102021-08-02 23:20:44 -0600105static inline int arasan_zynqmp_set_in_tapdelay(u8 node_id, u32 itap_delay)
106{
107 int ret;
108
109 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
110 if (node_id == NODE_SD_0) {
111 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN,
112 SD0_ITAPCHGWIN);
113 if (ret)
114 return ret;
115
116 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYENA,
117 SD0_ITAPDLYENA);
118 if (ret)
119 return ret;
120
121 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPDLYSEL_MASK,
122 itap_delay);
123 if (ret)
124 return ret;
125
126 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD0_ITAPCHGWIN, 0);
127 if (ret)
128 return ret;
129 }
130 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN,
131 SD1_ITAPCHGWIN);
132 if (ret)
133 return ret;
134
135 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYENA,
136 SD1_ITAPDLYENA);
137 if (ret)
138 return ret;
139
140 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPDLYSEL_MASK,
141 (itap_delay << 16));
142 if (ret)
143 return ret;
144
145 ret = zynqmp_mmio_write(SD_ITAP_DLY, SD1_ITAPCHGWIN, 0);
146 if (ret)
147 return ret;
148 } else {
149 return xilinx_pm_request(PM_IOCTL, (u32)node_id,
150 IOCTL_SET_SD_TAPDELAY,
151 PM_TAPDELAY_INPUT, itap_delay, NULL);
152 }
153
154 return 0;
155}
156
157static inline int arasan_zynqmp_set_out_tapdelay(u8 node_id, u32 otap_delay)
158{
159 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
160 if (node_id == NODE_SD_0)
161 return zynqmp_mmio_write(SD_OTAP_DLY,
162 SD0_OTAPDLYSEL_MASK,
163 otap_delay);
164
165 return zynqmp_mmio_write(SD_OTAP_DLY, SD1_OTAPDLYSEL_MASK,
166 (otap_delay << 16));
167 } else {
168 return xilinx_pm_request(PM_IOCTL, (u32)node_id,
169 IOCTL_SET_SD_TAPDELAY,
170 PM_TAPDELAY_OUTPUT, otap_delay, NULL);
171 }
172}
173
174static inline int zynqmp_dll_reset(u8 node_id, u32 type)
175{
176 if (IS_ENABLED(CONFIG_SPL_BUILD) || current_el() == 3) {
177 if (node_id == NODE_SD_0)
178 return zynqmp_mmio_write(SD_DLL_CTRL, SD0_DLL_RST,
179 type == PM_DLL_RESET_ASSERT ?
180 SD0_DLL_RST : 0);
181
182 return zynqmp_mmio_write(SD_DLL_CTRL, SD1_DLL_RST,
183 type == PM_DLL_RESET_ASSERT ?
184 SD1_DLL_RST : 0);
185 } else {
186 return xilinx_pm_request(PM_IOCTL, (u32)node_id,
187 IOCTL_SD_DLL_RESET, type, 0, NULL);
188 }
189}
190
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600191static int arasan_zynqmp_dll_reset(struct sdhci_host *host, u8 node_id)
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530192{
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600193 struct mmc *mmc = (struct mmc *)host->mmc;
194 struct udevice *dev = mmc->dev;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530195 unsigned long timeout;
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600196 int ret;
197 u16 clk;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530198
199 clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL);
200 clk &= ~(SDHCI_CLOCK_CARD_EN);
201 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
202
203 /* Issue DLL Reset */
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600204 ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_ASSERT);
205 if (ret) {
206 dev_err(dev, "dll_reset assert failed with err: %d\n", ret);
207 return ret;
208 }
209
210 /* Allow atleast 1ms delay for proper DLL reset */
211 mdelay(1);
212 ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_RELEASE);
213 if (ret) {
214 dev_err(dev, "dll_reset release failed with err: %d\n", ret);
215 return ret;
216 }
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530217
218 /* Wait max 20 ms */
219 timeout = 100;
220 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
221 & SDHCI_CLOCK_INT_STABLE)) {
222 if (timeout == 0) {
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600223 dev_err(dev, ": Internal clock never stabilised.\n");
224 return -EBUSY;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530225 }
226 timeout--;
227 udelay(1000);
228 }
229
230 clk |= SDHCI_CLOCK_CARD_EN;
231 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600232
233 return 0;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530234}
235
236static int arasan_sdhci_execute_tuning(struct mmc *mmc, u8 opcode)
237{
238 struct mmc_cmd cmd;
239 struct mmc_data data;
240 u32 ctrl;
241 struct sdhci_host *host;
242 struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev);
Michal Simek91e95ff2018-06-13 09:12:29 +0200243 char tuning_loop_counter = SDHCI_TUNING_LOOP_COUNT;
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600244 u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530245
246 debug("%s\n", __func__);
247
248 host = priv->host;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530249
Faiz Abbas2eddc002019-06-11 00:43:40 +0530250 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530251 ctrl |= SDHCI_CTRL_EXEC_TUNING;
Faiz Abbas2eddc002019-06-11 00:43:40 +0530252 sdhci_writew(host, ctrl, SDHCI_HOST_CONTROL2);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530253
254 mdelay(1);
255
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600256 arasan_zynqmp_dll_reset(host, node_id);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530257
258 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_INT_ENABLE);
259 sdhci_writel(host, SDHCI_INT_DATA_AVAIL, SDHCI_SIGNAL_ENABLE);
260
261 do {
262 cmd.cmdidx = opcode;
263 cmd.resp_type = MMC_RSP_R1;
264 cmd.cmdarg = 0;
265
266 data.blocksize = 64;
267 data.blocks = 1;
268 data.flags = MMC_DATA_READ;
269
270 if (tuning_loop_counter-- == 0)
271 break;
272
273 if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200 &&
274 mmc->bus_width == 8)
275 data.blocksize = 128;
276
277 sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
278 data.blocksize),
279 SDHCI_BLOCK_SIZE);
280 sdhci_writew(host, data.blocks, SDHCI_BLOCK_COUNT);
281 sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE);
282
283 mmc_send_cmd(mmc, &cmd, NULL);
Faiz Abbas2eddc002019-06-11 00:43:40 +0530284 ctrl = sdhci_readw(host, SDHCI_HOST_CONTROL2);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530285
286 if (cmd.cmdidx == MMC_CMD_SEND_TUNING_BLOCK)
287 udelay(1);
288
289 } while (ctrl & SDHCI_CTRL_EXEC_TUNING);
290
291 if (tuning_loop_counter < 0) {
292 ctrl &= ~SDHCI_CTRL_TUNED_CLK;
Faiz Abbas2eddc002019-06-11 00:43:40 +0530293 sdhci_writel(host, ctrl, SDHCI_HOST_CONTROL2);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530294 }
295
296 if (!(ctrl & SDHCI_CTRL_TUNED_CLK)) {
297 printf("%s:Tuning failed\n", __func__);
298 return -1;
299 }
300
301 udelay(1);
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600302 arasan_zynqmp_dll_reset(host, node_id);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530303
304 /* Enable only interrupts served by the SD controller */
305 sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK,
306 SDHCI_INT_ENABLE);
307 /* Mask all sdhci interrupt sources */
308 sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE);
309
310 return 0;
311}
312
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600313/**
314 * sdhci_zynqmp_sdcardclk_set_phase - Set the SD Output Clock Tap Delays
315 *
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600316 * @host: Pointer to the sdhci_host structure.
317 * @degrees: The clock phase shift between 0 - 359.
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600318 * Return: 0
Michal Simek2a43ab82021-07-09 05:53:43 -0600319 *
320 * Set the SD Output Clock Tap Delays for Output path
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600321 */
322static int sdhci_zynqmp_sdcardclk_set_phase(struct sdhci_host *host,
323 int degrees)
324{
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600325 struct mmc *mmc = (struct mmc *)host->mmc;
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600326 struct udevice *dev = mmc->dev;
327 struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev);
328 u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600329 u8 tap_delay, tap_max = 0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600330 int timing = mode2timing[mmc->selected_mode];
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600331 int ret;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600332
333 /*
334 * This is applicable for SDHCI_SPEC_300 and above
335 * ZynqMP does not set phase for <=25MHz clock.
336 * If degrees is zero, no need to do anything.
337 */
Ashok Reddy Soma6f645382021-07-09 05:53:40 -0600338 if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300)
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600339 return 0;
340
341 switch (timing) {
342 case MMC_TIMING_MMC_HS:
343 case MMC_TIMING_SD_HS:
344 case MMC_TIMING_UHS_SDR25:
345 case MMC_TIMING_UHS_DDR50:
346 case MMC_TIMING_MMC_DDR52:
347 /* For 50MHz clock, 30 Taps are available */
348 tap_max = 30;
349 break;
350 case MMC_TIMING_UHS_SDR50:
351 /* For 100MHz clock, 15 Taps are available */
352 tap_max = 15;
353 break;
354 case MMC_TIMING_UHS_SDR104:
355 case MMC_TIMING_MMC_HS200:
356 /* For 200MHz clock, 8 Taps are available */
357 tap_max = 8;
358 default:
359 break;
360 }
361
362 tap_delay = (degrees * tap_max) / 360;
363
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -0600364 /* Limit output tap_delay value to 6 bits */
365 tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK;
366
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600367 /* Set the Clock Phase */
368 ret = arasan_zynqmp_set_out_tapdelay(node_id, tap_delay);
369 if (ret) {
370 dev_err(dev, "Error setting output Tap Delay\n");
371 return ret;
372 }
373
374 /* Release DLL Reset */
375 ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_RELEASE);
376 if (ret) {
377 dev_err(dev, "dll_reset release failed with err: %d\n", ret);
378 return ret;
379 }
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600380
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600381 return 0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600382}
383
384/**
385 * sdhci_zynqmp_sampleclk_set_phase - Set the SD Input Clock Tap Delays
386 *
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600387 * @host: Pointer to the sdhci_host structure.
388 * @degrees: The clock phase shift between 0 - 359.
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600389 * Return: 0
Michal Simek2a43ab82021-07-09 05:53:43 -0600390 *
391 * Set the SD Input Clock Tap Delays for Input path
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600392 */
393static int sdhci_zynqmp_sampleclk_set_phase(struct sdhci_host *host,
394 int degrees)
395{
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600396 struct mmc *mmc = (struct mmc *)host->mmc;
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600397 struct udevice *dev = mmc->dev;
398 struct arasan_sdhci_priv *priv = dev_get_priv(mmc->dev);
399 u8 node_id = priv->deviceid ? NODE_SD_1 : NODE_SD_0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600400 u8 tap_delay, tap_max = 0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600401 int timing = mode2timing[mmc->selected_mode];
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600402 int ret;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600403
404 /*
405 * This is applicable for SDHCI_SPEC_300 and above
406 * ZynqMP does not set phase for <=25MHz clock.
407 * If degrees is zero, no need to do anything.
408 */
Ashok Reddy Soma6f645382021-07-09 05:53:40 -0600409 if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300)
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600410 return 0;
411
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600412 /* Assert DLL Reset */
413 ret = zynqmp_dll_reset(node_id, PM_DLL_RESET_ASSERT);
414 if (ret) {
415 dev_err(dev, "dll_reset assert failed with err: %d\n", ret);
416 return ret;
417 }
418
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600419 switch (timing) {
420 case MMC_TIMING_MMC_HS:
421 case MMC_TIMING_SD_HS:
422 case MMC_TIMING_UHS_SDR25:
423 case MMC_TIMING_UHS_DDR50:
424 case MMC_TIMING_MMC_DDR52:
425 /* For 50MHz clock, 120 Taps are available */
426 tap_max = 120;
427 break;
428 case MMC_TIMING_UHS_SDR50:
429 /* For 100MHz clock, 60 Taps are available */
430 tap_max = 60;
431 break;
432 case MMC_TIMING_UHS_SDR104:
433 case MMC_TIMING_MMC_HS200:
434 /* For 200MHz clock, 30 Taps are available */
435 tap_max = 30;
436 default:
437 break;
438 }
439
440 tap_delay = (degrees * tap_max) / 360;
441
Ashok Reddy Soma39a177a2021-07-09 05:53:42 -0600442 /* Limit input tap_delay value to 8 bits */
443 tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK;
444
Ashok Reddy Soma467d0782021-08-02 23:20:43 -0600445 ret = arasan_zynqmp_set_in_tapdelay(node_id, tap_delay);
446 if (ret) {
447 dev_err(dev, "Error setting Input Tap Delay\n");
448 return ret;
449 }
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600450
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600451 return 0;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600452}
453
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600454/**
455 * sdhci_versal_sdcardclk_set_phase - Set the SD Output Clock Tap Delays
456 *
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600457 * @host: Pointer to the sdhci_host structure.
Michal Simek2a43ab82021-07-09 05:53:43 -0600458 * @degrees: The clock phase shift between 0 - 359.
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600459 * Return: 0
Michal Simek2a43ab82021-07-09 05:53:43 -0600460 *
461 * Set the SD Output Clock Tap Delays for Output path
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600462 */
463static int sdhci_versal_sdcardclk_set_phase(struct sdhci_host *host,
464 int degrees)
465{
466 struct mmc *mmc = (struct mmc *)host->mmc;
467 u8 tap_delay, tap_max = 0;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600468 int timing = mode2timing[mmc->selected_mode];
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600469 u32 regval;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600470
471 /*
472 * This is applicable for SDHCI_SPEC_300 and above
473 * Versal does not set phase for <=25MHz clock.
474 * If degrees is zero, no need to do anything.
475 */
Ashok Reddy Soma6f645382021-07-09 05:53:40 -0600476 if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300)
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600477 return 0;
478
479 switch (timing) {
480 case MMC_TIMING_MMC_HS:
481 case MMC_TIMING_SD_HS:
482 case MMC_TIMING_UHS_SDR25:
483 case MMC_TIMING_UHS_DDR50:
484 case MMC_TIMING_MMC_DDR52:
485 /* For 50MHz clock, 30 Taps are available */
486 tap_max = 30;
487 break;
488 case MMC_TIMING_UHS_SDR50:
489 /* For 100MHz clock, 15 Taps are available */
490 tap_max = 15;
491 break;
492 case MMC_TIMING_UHS_SDR104:
493 case MMC_TIMING_MMC_HS200:
494 /* For 200MHz clock, 8 Taps are available */
495 tap_max = 8;
496 default:
497 break;
498 }
499
500 tap_delay = (degrees * tap_max) / 360;
501
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600502 /* Limit output tap_delay value to 6 bits */
503 tap_delay &= SDHCI_ARASAN_OTAPDLY_SEL_MASK;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600504
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600505 /* Set the Clock Phase */
506 regval = sdhci_readl(host, SDHCI_ARASAN_OTAPDLY_REGISTER);
507 regval |= SDHCI_OTAPDLY_ENABLE;
508 sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
509 regval &= ~SDHCI_ARASAN_OTAPDLY_SEL_MASK;
510 regval |= tap_delay;
511 sdhci_writel(host, regval, SDHCI_ARASAN_OTAPDLY_REGISTER);
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600512
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600513 return 0;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600514}
515
516/**
517 * sdhci_versal_sampleclk_set_phase - Set the SD Input Clock Tap Delays
518 *
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600519 * @host: Pointer to the sdhci_host structure.
Michal Simek2a43ab82021-07-09 05:53:43 -0600520 * @degrees: The clock phase shift between 0 - 359.
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600521 * Return: 0
Michal Simek2a43ab82021-07-09 05:53:43 -0600522 *
523 * Set the SD Input Clock Tap Delays for Input path
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600524 */
525static int sdhci_versal_sampleclk_set_phase(struct sdhci_host *host,
526 int degrees)
527{
528 struct mmc *mmc = (struct mmc *)host->mmc;
529 u8 tap_delay, tap_max = 0;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600530 int timing = mode2timing[mmc->selected_mode];
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600531 u32 regval;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600532
533 /*
534 * This is applicable for SDHCI_SPEC_300 and above
535 * Versal does not set phase for <=25MHz clock.
536 * If degrees is zero, no need to do anything.
537 */
Ashok Reddy Soma6f645382021-07-09 05:53:40 -0600538 if (SDHCI_GET_VERSION(host) < SDHCI_SPEC_300)
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600539 return 0;
540
541 switch (timing) {
542 case MMC_TIMING_MMC_HS:
543 case MMC_TIMING_SD_HS:
544 case MMC_TIMING_UHS_SDR25:
545 case MMC_TIMING_UHS_DDR50:
546 case MMC_TIMING_MMC_DDR52:
547 /* For 50MHz clock, 120 Taps are available */
548 tap_max = 120;
549 break;
550 case MMC_TIMING_UHS_SDR50:
551 /* For 100MHz clock, 60 Taps are available */
552 tap_max = 60;
553 break;
554 case MMC_TIMING_UHS_SDR104:
555 case MMC_TIMING_MMC_HS200:
556 /* For 200MHz clock, 30 Taps are available */
557 tap_max = 30;
558 default:
559 break;
560 }
561
562 tap_delay = (degrees * tap_max) / 360;
563
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600564 /* Limit input tap_delay value to 8 bits */
565 tap_delay &= SDHCI_ARASAN_ITAPDLY_SEL_MASK;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600566
Ashok Reddy Soma24a51072021-07-09 05:53:41 -0600567 /* Set the Clock Phase */
568 regval = sdhci_readl(host, SDHCI_ARASAN_ITAPDLY_REGISTER);
569 regval |= SDHCI_ITAPDLY_CHGWIN;
570 sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
571 regval |= SDHCI_ITAPDLY_ENABLE;
572 sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
573 regval &= ~SDHCI_ARASAN_ITAPDLY_SEL_MASK;
574 regval |= tap_delay;
575 sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
576 regval &= ~SDHCI_ITAPDLY_CHGWIN;
577 sdhci_writel(host, regval, SDHCI_ARASAN_ITAPDLY_REGISTER);
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600578
Ashok Reddy Soma94a755d2021-07-09 05:53:39 -0600579 return 0;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600580}
581
Ashok Reddy Soma21fd7632021-08-02 23:20:40 -0600582static int arasan_sdhci_set_tapdelay(struct sdhci_host *host)
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530583{
584 struct arasan_sdhci_priv *priv = dev_get_priv(host->mmc->dev);
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600585 struct arasan_sdhci_clk_data *clk_data = &priv->clk_data;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530586 struct mmc *mmc = (struct mmc *)host->mmc;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600587 struct udevice *dev = mmc->dev;
588 u8 timing = mode2timing[mmc->selected_mode];
589 u32 iclk_phase = clk_data->clk_phase_in[timing];
590 u32 oclk_phase = clk_data->clk_phase_out[timing];
Ashok Reddy Soma21fd7632021-08-02 23:20:40 -0600591 int ret;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530592
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600593 dev_dbg(dev, "%s, host:%s, mode:%d\n", __func__, host->name, timing);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530594
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600595 if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) &&
596 device_is_compatible(dev, "xlnx,zynqmp-8.9a")) {
Ashok Reddy Soma21fd7632021-08-02 23:20:40 -0600597 ret = sdhci_zynqmp_sampleclk_set_phase(host, iclk_phase);
598 if (ret)
599 return ret;
600
601 ret = sdhci_zynqmp_sdcardclk_set_phase(host, oclk_phase);
602 if (ret)
603 return ret;
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600604 } else if (IS_ENABLED(CONFIG_ARCH_VERSAL) &&
605 device_is_compatible(dev, "xlnx,versal-8.9a")) {
Ashok Reddy Soma21fd7632021-08-02 23:20:40 -0600606 ret = sdhci_versal_sampleclk_set_phase(host, iclk_phase);
607 if (ret)
608 return ret;
609
610 ret = sdhci_versal_sdcardclk_set_phase(host, oclk_phase);
611 if (ret)
612 return ret;
Ashok Reddy Soma8f629862020-10-23 04:59:01 -0600613 }
Ashok Reddy Soma21fd7632021-08-02 23:20:40 -0600614
615 return 0;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530616}
617
Michal Simek33a6b772020-10-23 04:59:00 -0600618static void arasan_dt_read_clk_phase(struct udevice *dev, unsigned char timing,
619 const char *prop)
620{
621 struct arasan_sdhci_priv *priv = dev_get_priv(dev);
622 struct arasan_sdhci_clk_data *clk_data = &priv->clk_data;
623 u32 clk_phase[2] = {0};
624
625 /*
626 * Read Tap Delay values from DT, if the DT does not contain the
627 * Tap Values then use the pre-defined values
628 */
629 if (dev_read_u32_array(dev, prop, &clk_phase[0], 2)) {
630 dev_dbg(dev, "Using predefined clock phase for %s = %d %d\n",
631 prop, clk_data->clk_phase_in[timing],
632 clk_data->clk_phase_out[timing]);
633 return;
634 }
635
636 /* The values read are Input and Output Clock Delays in order */
637 clk_data->clk_phase_in[timing] = clk_phase[0];
638 clk_data->clk_phase_out[timing] = clk_phase[1];
639}
640
641/**
642 * arasan_dt_parse_clk_phases - Read Tap Delay values from DT
643 *
Michal Simek33a6b772020-10-23 04:59:00 -0600644 * @dev: Pointer to our struct udevice.
Michal Simek2a43ab82021-07-09 05:53:43 -0600645 *
646 * Called at initialization to parse the values of Tap Delays.
Michal Simek33a6b772020-10-23 04:59:00 -0600647 */
648static void arasan_dt_parse_clk_phases(struct udevice *dev)
649{
650 struct arasan_sdhci_priv *priv = dev_get_priv(dev);
651 struct arasan_sdhci_clk_data *clk_data = &priv->clk_data;
652 int i;
653
654 if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) &&
655 device_is_compatible(dev, "xlnx,zynqmp-8.9a")) {
656 for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) {
657 clk_data->clk_phase_in[i] = zynqmp_iclk_phases[i];
658 clk_data->clk_phase_out[i] = zynqmp_oclk_phases[i];
659 }
660
661 if (priv->bank == MMC_BANK2) {
662 clk_data->clk_phase_out[MMC_TIMING_UHS_SDR104] = 90;
663 clk_data->clk_phase_out[MMC_TIMING_MMC_HS200] = 90;
664 }
665 }
666
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600667 if (IS_ENABLED(CONFIG_ARCH_VERSAL) &&
668 device_is_compatible(dev, "xlnx,versal-8.9a")) {
669 for (i = 0; i <= MMC_TIMING_MMC_HS400; i++) {
670 clk_data->clk_phase_in[i] = versal_iclk_phases[i];
671 clk_data->clk_phase_out[i] = versal_oclk_phases[i];
672 }
673 }
674
Michal Simek33a6b772020-10-23 04:59:00 -0600675 arasan_dt_read_clk_phase(dev, MMC_TIMING_LEGACY,
676 "clk-phase-legacy");
677 arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS,
678 "clk-phase-mmc-hs");
679 arasan_dt_read_clk_phase(dev, MMC_TIMING_SD_HS,
680 "clk-phase-sd-hs");
681 arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR12,
682 "clk-phase-uhs-sdr12");
683 arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR25,
684 "clk-phase-uhs-sdr25");
685 arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR50,
686 "clk-phase-uhs-sdr50");
687 arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_SDR104,
688 "clk-phase-uhs-sdr104");
689 arasan_dt_read_clk_phase(dev, MMC_TIMING_UHS_DDR50,
690 "clk-phase-uhs-ddr50");
691 arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_DDR52,
692 "clk-phase-mmc-ddr52");
693 arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS200,
694 "clk-phase-mmc-hs200");
695 arasan_dt_read_clk_phase(dev, MMC_TIMING_MMC_HS400,
696 "clk-phase-mmc-hs400");
697}
698
Michal Simek635cf4a2021-07-09 05:53:44 -0600699static const struct sdhci_ops arasan_ops = {
700 .platform_execute_tuning = &arasan_sdhci_execute_tuning,
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530701 .set_delay = &arasan_sdhci_set_tapdelay,
Ashok Reddy Soma8ee49f02021-08-02 23:20:46 -0600702 .set_control_reg = &sdhci_set_control_reg,
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530703};
704#endif
705
Michal Simek9ecd2682015-11-30 16:13:03 +0100706static int arasan_sdhci_probe(struct udevice *dev)
Michal Simek0dd222b2013-04-22 14:56:49 +0200707{
Simon Glassfa20e932020-12-03 16:55:20 -0700708 struct arasan_sdhci_plat *plat = dev_get_plat(dev);
Michal Simek9ecd2682015-11-30 16:13:03 +0100709 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530710 struct arasan_sdhci_priv *priv = dev_get_priv(dev);
711 struct sdhci_host *host;
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +0100712 struct clk clk;
713 unsigned long clock;
Simon Glass4cc87fb2016-07-05 17:10:15 -0600714 int ret;
Michal Simek0dd222b2013-04-22 14:56:49 +0200715
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530716 host = priv->host;
717
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +0100718 ret = clk_get_by_index(dev, 0, &clk);
719 if (ret < 0) {
720 dev_err(dev, "failed to get clock\n");
721 return ret;
722 }
723
724 clock = clk_get_rate(&clk);
725 if (IS_ERR_VALUE(clock)) {
726 dev_err(dev, "failed to get rate\n");
727 return clock;
728 }
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530729
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +0100730 debug("%s: CLK %ld\n", __func__, clock);
731
732 ret = clk_enable(&clk);
Michal Simek41710952021-02-09 15:28:15 +0100733 if (ret) {
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +0100734 dev_err(dev, "failed to enable clock\n");
735 return ret;
736 }
737
Siva Durga Prasad Paladugu049e0032014-07-08 15:31:04 +0530738 host->quirks = SDHCI_QUIRK_WAIT_SEND_CMD |
Siva Durga Prasad Paladugu0d6891b2014-01-22 09:17:09 +0100739 SDHCI_QUIRK_BROKEN_R1B;
Siva Durga Prasad Paladugua1619fe2016-01-12 15:12:16 +0530740
741#ifdef CONFIG_ZYNQ_HISPD_BROKEN
Hannes Schmelzer94a5bbc2018-03-07 08:00:57 +0100742 host->quirks |= SDHCI_QUIRK_BROKEN_HISPD_MODE;
Siva Durga Prasad Paladugua1619fe2016-01-12 15:12:16 +0530743#endif
744
Ashok Reddy Soma61e0df92020-10-23 04:58:57 -0600745 if (priv->no_1p8)
746 host->quirks |= SDHCI_QUIRK_NO_1_8_V;
747
Benedikt Grassl529e6f02020-04-14 07:32:12 +0200748 plat->cfg.f_max = CONFIG_ZYNQ_SDHCI_MAX_FREQ;
749
750 ret = mmc_of_parse(dev, &plat->cfg);
751 if (ret)
752 return ret;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530753
Stefan Herbrechtsmeier739ae402017-01-17 16:27:32 +0100754 host->max_clk = clock;
Stefan Herbrechtsmeierbc47e0e2017-01-17 15:58:48 +0100755
Matwey V. Kornilov194b8602019-08-01 18:00:05 +0300756 host->mmc = &plat->mmc;
757 host->mmc->dev = dev;
758 host->mmc->priv = host;
759
Benedikt Grassl529e6f02020-04-14 07:32:12 +0200760 ret = sdhci_setup_cfg(&plat->cfg, host, plat->cfg.f_max,
Jaehoon Chung8a5ffbb2016-07-26 19:06:24 +0900761 CONFIG_ZYNQ_SDHCI_MIN_FREQ);
Simon Glass4cc87fb2016-07-05 17:10:15 -0600762 if (ret)
763 return ret;
Simon Glass4cc87fb2016-07-05 17:10:15 -0600764 upriv->mmc = host->mmc;
Michal Simek9ecd2682015-11-30 16:13:03 +0100765
T Karthik Reddyab0a7492021-08-02 23:20:45 -0600766 /*
767 * WORKAROUND: Versal platforms have an issue with card detect state.
768 * Due to this, host controller is switching off voltage to sd card
769 * causing sd card timeout error. Workaround this by adding a wait for
770 * 1000msec till the card detect state gets stable.
771 */
Ashok Reddy Soma6556bff2022-02-23 15:13:32 +0100772 if (IS_ENABLED(CONFIG_ARCH_ZYNQMP) || IS_ENABLED(CONFIG_ARCH_VERSAL)) {
Ashok Reddy Somadd745772022-02-23 15:13:31 +0100773 u32 timeout = 1000000;
T Karthik Reddyab0a7492021-08-02 23:20:45 -0600774
775 while (((sdhci_readl(host, SDHCI_PRESENT_STATE) &
Ashok Reddy Soma09f38902022-02-23 15:13:30 +0100776 SDHCI_CARD_STATE_STABLE) == 0) && timeout) {
Ashok Reddy Somadd745772022-02-23 15:13:31 +0100777 udelay(1);
Ashok Reddy Soma09f38902022-02-23 15:13:30 +0100778 timeout--;
T Karthik Reddyab0a7492021-08-02 23:20:45 -0600779 }
780 if (!timeout) {
781 dev_err(dev, "Sdhci card detect state not stable\n");
782 return -ETIMEDOUT;
783 }
784 }
785
Simon Glass4cc87fb2016-07-05 17:10:15 -0600786 return sdhci_probe(dev);
Michal Simek0dd222b2013-04-22 14:56:49 +0200787}
Michal Simek9ecd2682015-11-30 16:13:03 +0100788
Simon Glassaad29ae2020-12-03 16:55:21 -0700789static int arasan_sdhci_of_to_plat(struct udevice *dev)
Michal Simek9ecd2682015-11-30 16:13:03 +0100790{
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530791 struct arasan_sdhci_priv *priv = dev_get_priv(dev);
Michal Simek9ecd2682015-11-30 16:13:03 +0100792
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530793 priv->host = calloc(1, sizeof(struct sdhci_host));
794 if (!priv->host)
795 return -1;
796
797 priv->host->name = dev->name;
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530798
Ashok Reddy Soma568edfd2020-10-23 04:59:02 -0600799#if defined(CONFIG_ARCH_ZYNQMP) || defined(CONFIG_ARCH_VERSAL)
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530800 priv->host->ops = &arasan_ops;
Michal Simek33a6b772020-10-23 04:59:00 -0600801 arasan_dt_parse_clk_phases(dev);
Siva Durga Prasad Paladugucad14a82018-04-19 12:37:09 +0530802#endif
Michal Simek9ecd2682015-11-30 16:13:03 +0100803
Michal Simek921a8de2018-05-16 10:57:07 +0200804 priv->host->ioaddr = (void *)dev_read_addr(dev);
805 if (IS_ERR(priv->host->ioaddr))
806 return PTR_ERR(priv->host->ioaddr);
807
808 priv->deviceid = dev_read_u32_default(dev, "xlnx,device_id", -1);
Michal Simeke40ae572020-07-22 17:46:31 +0200809 priv->bank = dev_read_u32_default(dev, "xlnx,mio-bank", 0);
Ashok Reddy Soma61e0df92020-10-23 04:58:57 -0600810 priv->no_1p8 = dev_read_bool(dev, "no-1-8-v");
Stefan Herbrechtsmeier5567b422017-01-17 16:27:33 +0100811
Michal Simek9ecd2682015-11-30 16:13:03 +0100812 return 0;
813}
814
Simon Glass4cc87fb2016-07-05 17:10:15 -0600815static int arasan_sdhci_bind(struct udevice *dev)
816{
Simon Glassfa20e932020-12-03 16:55:20 -0700817 struct arasan_sdhci_plat *plat = dev_get_plat(dev);
Simon Glass4cc87fb2016-07-05 17:10:15 -0600818
Masahiro Yamadacdb67f32016-09-06 22:17:32 +0900819 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
Simon Glass4cc87fb2016-07-05 17:10:15 -0600820}
821
Michal Simek9ecd2682015-11-30 16:13:03 +0100822static const struct udevice_id arasan_sdhci_ids[] = {
823 { .compatible = "arasan,sdhci-8.9a" },
824 { }
825};
826
827U_BOOT_DRIVER(arasan_sdhci_drv) = {
828 .name = "arasan_sdhci",
829 .id = UCLASS_MMC,
830 .of_match = arasan_sdhci_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700831 .of_to_plat = arasan_sdhci_of_to_plat,
Simon Glass4cc87fb2016-07-05 17:10:15 -0600832 .ops = &sdhci_ops,
833 .bind = arasan_sdhci_bind,
Michal Simek9ecd2682015-11-30 16:13:03 +0100834 .probe = arasan_sdhci_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700835 .priv_auto = sizeof(struct arasan_sdhci_priv),
Simon Glass71fa5b42020-12-03 16:55:18 -0700836 .plat_auto = sizeof(struct arasan_sdhci_plat),
Michal Simek9ecd2682015-11-30 16:13:03 +0100837};