blob: 63561e19c82bcfbd1b479db0ee75681c98230d27 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasute94cad92018-04-08 15:22:58 +02002/*
3 * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
Marek Vasute94cad92018-04-08 15:22:58 +02004 */
5
6#include <common.h>
7#include <clk.h>
8#include <fdtdec.h>
9#include <mmc.h>
10#include <dm.h>
11#include <linux/compat.h>
12#include <linux/dma-direction.h>
13#include <linux/io.h>
14#include <linux/sizes.h>
15#include <power/regulator.h>
16#include <asm/unaligned.h>
17
Marek Vasutcb0b6b02018-04-13 23:51:33 +020018#include "tmio-common.h"
Marek Vasute94cad92018-04-08 15:22:58 +020019
Marek Vasutf63968b2018-04-08 19:09:17 +020020#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
21
22/* SCC registers */
23#define RENESAS_SDHI_SCC_DTCNTL 0x800
24#define RENESAS_SDHI_SCC_DTCNTL_TAPEN BIT(0)
25#define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT 16
26#define RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK 0xff
27#define RENESAS_SDHI_SCC_TAPSET 0x804
28#define RENESAS_SDHI_SCC_DT2FF 0x808
29#define RENESAS_SDHI_SCC_CKSEL 0x80c
30#define RENESAS_SDHI_SCC_CKSEL_DTSEL BIT(0)
31#define RENESAS_SDHI_SCC_RVSCNTL 0x810
32#define RENESAS_SDHI_SCC_RVSCNTL_RVSEN BIT(0)
33#define RENESAS_SDHI_SCC_RVSREQ 0x814
34#define RENESAS_SDHI_SCC_RVSREQ_RVSERR BIT(2)
35#define RENESAS_SDHI_SCC_SMPCMP 0x818
36#define RENESAS_SDHI_SCC_TMPPORT2 0x81c
Marek Vasutdc1488f2018-06-13 08:02:55 +020037#define RENESAS_SDHI_SCC_TMPPORT2_HS400EN BIT(31)
38#define RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL BIT(4)
Marek Vasutf63968b2018-04-08 19:09:17 +020039
40#define RENESAS_SDHI_MAX_TAP 3
41
Marek Vasutcb0b6b02018-04-13 23:51:33 +020042static unsigned int renesas_sdhi_init_tuning(struct tmio_sd_priv *priv)
Marek Vasutf63968b2018-04-08 19:09:17 +020043{
44 u32 reg;
45
46 /* Initialize SCC */
Marek Vasutcb0b6b02018-04-13 23:51:33 +020047 tmio_sd_writel(priv, 0, TMIO_SD_INFO1);
Marek Vasutf63968b2018-04-08 19:09:17 +020048
Marek Vasutcb0b6b02018-04-13 23:51:33 +020049 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
50 reg &= ~TMIO_SD_CLKCTL_SCLKEN;
51 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020052
53 /* Set sampling clock selection range */
Marek Vasutcb0b6b02018-04-13 23:51:33 +020054 tmio_sd_writel(priv, 0x8 << RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT,
Marek Vasutf63968b2018-04-08 19:09:17 +020055 RENESAS_SDHI_SCC_DTCNTL);
56
Marek Vasutcb0b6b02018-04-13 23:51:33 +020057 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_DTCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020058 reg |= RENESAS_SDHI_SCC_DTCNTL_TAPEN;
Marek Vasutcb0b6b02018-04-13 23:51:33 +020059 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_DTCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020060
Marek Vasutcb0b6b02018-04-13 23:51:33 +020061 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL);
Marek Vasutf63968b2018-04-08 19:09:17 +020062 reg |= RENESAS_SDHI_SCC_CKSEL_DTSEL;
Marek Vasutcb0b6b02018-04-13 23:51:33 +020063 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL);
Marek Vasutf63968b2018-04-08 19:09:17 +020064
Marek Vasutcb0b6b02018-04-13 23:51:33 +020065 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020066 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
Marek Vasutcb0b6b02018-04-13 23:51:33 +020067 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020068
Marek Vasutcb0b6b02018-04-13 23:51:33 +020069 tmio_sd_writel(priv, 0x300 /* scc_tappos */,
Marek Vasutf63968b2018-04-08 19:09:17 +020070 RENESAS_SDHI_SCC_DT2FF);
71
Marek Vasutcb0b6b02018-04-13 23:51:33 +020072 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
73 reg |= TMIO_SD_CLKCTL_SCLKEN;
74 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020075
76 /* Read TAPNUM */
Marek Vasutcb0b6b02018-04-13 23:51:33 +020077 return (tmio_sd_readl(priv, RENESAS_SDHI_SCC_DTCNTL) >>
Marek Vasutf63968b2018-04-08 19:09:17 +020078 RENESAS_SDHI_SCC_DTCNTL_TAPNUM_SHIFT) &
79 RENESAS_SDHI_SCC_DTCNTL_TAPNUM_MASK;
80}
81
Marek Vasutcb0b6b02018-04-13 23:51:33 +020082static void renesas_sdhi_reset_tuning(struct tmio_sd_priv *priv)
Marek Vasutf63968b2018-04-08 19:09:17 +020083{
84 u32 reg;
85
86 /* Reset SCC */
Marek Vasutcb0b6b02018-04-13 23:51:33 +020087 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
88 reg &= ~TMIO_SD_CLKCTL_SCLKEN;
89 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
Marek Vasutf63968b2018-04-08 19:09:17 +020090
Marek Vasutcb0b6b02018-04-13 23:51:33 +020091 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_CKSEL);
Marek Vasutf63968b2018-04-08 19:09:17 +020092 reg &= ~RENESAS_SDHI_SCC_CKSEL_DTSEL;
Marek Vasutcb0b6b02018-04-13 23:51:33 +020093 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_CKSEL);
Marek Vasutf63968b2018-04-08 19:09:17 +020094
Marek Vasutdc1488f2018-06-13 08:02:55 +020095 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_TMPPORT2);
96 reg &= ~(RENESAS_SDHI_SCC_TMPPORT2_HS400EN |
97 RENESAS_SDHI_SCC_TMPPORT2_HS400OSEL);
98 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_TMPPORT2);
99
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200100 reg = tmio_sd_readl(priv, TMIO_SD_CLKCTL);
101 reg |= TMIO_SD_CLKCTL_SCLKEN;
102 tmio_sd_writel(priv, reg, TMIO_SD_CLKCTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200103
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200104 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200105 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200106 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200107
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200108 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200109 reg &= ~RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200110 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200111}
112
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200113static void renesas_sdhi_prepare_tuning(struct tmio_sd_priv *priv,
Marek Vasutf63968b2018-04-08 19:09:17 +0200114 unsigned long tap)
115{
116 /* Set sampling clock position */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200117 tmio_sd_writel(priv, tap, RENESAS_SDHI_SCC_TAPSET);
Marek Vasutf63968b2018-04-08 19:09:17 +0200118}
119
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200120static unsigned int renesas_sdhi_compare_scc_data(struct tmio_sd_priv *priv)
Marek Vasutf63968b2018-04-08 19:09:17 +0200121{
122 /* Get comparison of sampling data */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200123 return tmio_sd_readl(priv, RENESAS_SDHI_SCC_SMPCMP);
Marek Vasutf63968b2018-04-08 19:09:17 +0200124}
125
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200126static int renesas_sdhi_select_tuning(struct tmio_sd_priv *priv,
Marek Vasutf63968b2018-04-08 19:09:17 +0200127 unsigned int tap_num, unsigned int taps,
128 unsigned int smpcmp)
129{
130 unsigned long tap_cnt; /* counter of tuning success */
131 unsigned long tap_set; /* tap position */
132 unsigned long tap_start;/* start position of tuning success */
133 unsigned long tap_end; /* end position of tuning success */
134 unsigned long ntap; /* temporary counter of tuning success */
135 unsigned long match_cnt;/* counter of matching data */
136 unsigned long i;
137 bool select = false;
138 u32 reg;
139
140 /* Clear SCC_RVSREQ */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200141 tmio_sd_writel(priv, 0, RENESAS_SDHI_SCC_RVSREQ);
Marek Vasutf63968b2018-04-08 19:09:17 +0200142
143 /* Merge the results */
144 for (i = 0; i < tap_num * 2; i++) {
145 if (!(taps & BIT(i))) {
146 taps &= ~BIT(i % tap_num);
147 taps &= ~BIT((i % tap_num) + tap_num);
148 }
149 if (!(smpcmp & BIT(i))) {
150 smpcmp &= ~BIT(i % tap_num);
151 smpcmp &= ~BIT((i % tap_num) + tap_num);
152 }
153 }
154
155 /*
156 * Find the longest consecutive run of successful probes. If that
157 * is more than RENESAS_SDHI_MAX_TAP probes long then use the
158 * center index as the tap.
159 */
160 tap_cnt = 0;
161 ntap = 0;
162 tap_start = 0;
163 tap_end = 0;
164 for (i = 0; i < tap_num * 2; i++) {
165 if (taps & BIT(i))
166 ntap++;
167 else {
168 if (ntap > tap_cnt) {
169 tap_start = i - ntap;
170 tap_end = i - 1;
171 tap_cnt = ntap;
172 }
173 ntap = 0;
174 }
175 }
176
177 if (ntap > tap_cnt) {
178 tap_start = i - ntap;
179 tap_end = i - 1;
180 tap_cnt = ntap;
181 }
182
183 /*
184 * If all of the TAP is OK, the sampling clock position is selected by
185 * identifying the change point of data.
186 */
187 if (tap_cnt == tap_num * 2) {
188 match_cnt = 0;
189 ntap = 0;
190 tap_start = 0;
191 tap_end = 0;
192 for (i = 0; i < tap_num * 2; i++) {
193 if (smpcmp & BIT(i))
194 ntap++;
195 else {
196 if (ntap > match_cnt) {
197 tap_start = i - ntap;
198 tap_end = i - 1;
199 match_cnt = ntap;
200 }
201 ntap = 0;
202 }
203 }
204 if (ntap > match_cnt) {
205 tap_start = i - ntap;
206 tap_end = i - 1;
207 match_cnt = ntap;
208 }
209 if (match_cnt)
210 select = true;
211 } else if (tap_cnt >= RENESAS_SDHI_MAX_TAP)
212 select = true;
213
214 if (select)
215 tap_set = ((tap_start + tap_end) / 2) % tap_num;
216 else
217 return -EIO;
218
219 /* Set SCC */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200220 tmio_sd_writel(priv, tap_set, RENESAS_SDHI_SCC_TAPSET);
Marek Vasutf63968b2018-04-08 19:09:17 +0200221
222 /* Enable auto re-tuning */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200223 reg = tmio_sd_readl(priv, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200224 reg |= RENESAS_SDHI_SCC_RVSCNTL_RVSEN;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200225 tmio_sd_writel(priv, reg, RENESAS_SDHI_SCC_RVSCNTL);
Marek Vasutf63968b2018-04-08 19:09:17 +0200226
227 return 0;
228}
229
230int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode)
231{
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200232 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutf63968b2018-04-08 19:09:17 +0200233 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
234 struct mmc *mmc = upriv->mmc;
235 unsigned int tap_num;
236 unsigned int taps = 0, smpcmp = 0;
237 int i, ret = 0;
238 u32 caps;
239
240 /* Only supported on Renesas RCar */
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200241 if (!(priv->caps & TMIO_SD_CAP_RCAR_UHS))
Marek Vasutf63968b2018-04-08 19:09:17 +0200242 return -EINVAL;
243
244 /* clock tuning is not needed for upto 52MHz */
245 if (!((mmc->selected_mode == MMC_HS_200) ||
246 (mmc->selected_mode == UHS_SDR104) ||
247 (mmc->selected_mode == UHS_SDR50)))
248 return 0;
249
250 tap_num = renesas_sdhi_init_tuning(priv);
251 if (!tap_num)
252 /* Tuning is not supported */
253 goto out;
254
255 if (tap_num * 2 >= sizeof(taps) * 8) {
256 dev_err(dev,
257 "Too many taps, skipping tuning. Please consider updating size of taps field of tmio_mmc_host\n");
258 goto out;
259 }
260
261 /* Issue CMD19 twice for each tap */
262 for (i = 0; i < 2 * tap_num; i++) {
263 renesas_sdhi_prepare_tuning(priv, i % tap_num);
264
265 /* Force PIO for the tuning */
266 caps = priv->caps;
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200267 priv->caps &= ~TMIO_SD_CAP_DMA_INTERNAL;
Marek Vasutf63968b2018-04-08 19:09:17 +0200268
269 ret = mmc_send_tuning(mmc, opcode, NULL);
270
271 priv->caps = caps;
272
273 if (ret == 0)
274 taps |= BIT(i);
275
276 ret = renesas_sdhi_compare_scc_data(priv);
277 if (ret == 0)
278 smpcmp |= BIT(i);
279
280 mdelay(1);
281 }
282
283 ret = renesas_sdhi_select_tuning(priv, tap_num, taps, smpcmp);
284
285out:
286 if (ret < 0) {
287 dev_warn(dev, "Tuning procedure failed\n");
288 renesas_sdhi_reset_tuning(priv);
289 }
290
291 return ret;
292}
293#endif
294
295static int renesas_sdhi_set_ios(struct udevice *dev)
296{
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200297 int ret = tmio_sd_set_ios(dev);
Marek Vasutcf39f3f2018-04-09 20:47:31 +0200298
299 mdelay(10);
300
Marek Vasutf63968b2018-04-08 19:09:17 +0200301#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200302 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutf63968b2018-04-08 19:09:17 +0200303
Marek Vasut52e17962018-10-28 15:30:06 +0100304 if (priv->caps & TMIO_SD_CAP_RCAR_UHS)
305 renesas_sdhi_reset_tuning(priv);
Marek Vasutf63968b2018-04-08 19:09:17 +0200306#endif
307
308 return ret;
309}
310
Marek Vasut2fc10752018-10-28 19:28:56 +0100311#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
312static int renesas_sdhi_wait_dat0(struct udevice *dev, int state, int timeout)
313{
314 int ret = -ETIMEDOUT;
315 bool dat0_high;
316 bool target_dat0_high = !!state;
317 struct tmio_sd_priv *priv = dev_get_priv(dev);
318
319 timeout = DIV_ROUND_UP(timeout, 10); /* check every 10 us. */
320 while (timeout--) {
321 dat0_high = !!(tmio_sd_readl(priv, TMIO_SD_INFO2) & TMIO_SD_INFO2_DAT0);
322 if (dat0_high == target_dat0_high) {
323 ret = 0;
324 break;
325 }
326 udelay(10);
327 }
328
329 return ret;
330}
331#endif
332
Marek Vasute94cad92018-04-08 15:22:58 +0200333static const struct dm_mmc_ops renesas_sdhi_ops = {
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200334 .send_cmd = tmio_sd_send_cmd,
Marek Vasutf63968b2018-04-08 19:09:17 +0200335 .set_ios = renesas_sdhi_set_ios,
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200336 .get_cd = tmio_sd_get_cd,
Marek Vasut2fc10752018-10-28 19:28:56 +0100337#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT) || CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
Marek Vasutf63968b2018-04-08 19:09:17 +0200338 .execute_tuning = renesas_sdhi_execute_tuning,
339#endif
Marek Vasut2fc10752018-10-28 19:28:56 +0100340#if CONFIG_IS_ENABLED(MMC_UHS_SUPPORT)
341 .wait_dat0 = renesas_sdhi_wait_dat0,
342#endif
Marek Vasute94cad92018-04-08 15:22:58 +0200343};
344
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200345#define RENESAS_GEN2_QUIRKS TMIO_SD_CAP_RCAR_GEN2
Marek Vasutf98833d2018-04-08 18:49:52 +0200346#define RENESAS_GEN3_QUIRKS \
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200347 TMIO_SD_CAP_64BIT | TMIO_SD_CAP_RCAR_GEN3 | TMIO_SD_CAP_RCAR_UHS
Marek Vasutf98833d2018-04-08 18:49:52 +0200348
Marek Vasute94cad92018-04-08 15:22:58 +0200349static const struct udevice_id renesas_sdhi_match[] = {
Marek Vasutf98833d2018-04-08 18:49:52 +0200350 { .compatible = "renesas,sdhi-r8a7790", .data = RENESAS_GEN2_QUIRKS },
351 { .compatible = "renesas,sdhi-r8a7791", .data = RENESAS_GEN2_QUIRKS },
352 { .compatible = "renesas,sdhi-r8a7792", .data = RENESAS_GEN2_QUIRKS },
353 { .compatible = "renesas,sdhi-r8a7793", .data = RENESAS_GEN2_QUIRKS },
354 { .compatible = "renesas,sdhi-r8a7794", .data = RENESAS_GEN2_QUIRKS },
355 { .compatible = "renesas,sdhi-r8a7795", .data = RENESAS_GEN3_QUIRKS },
356 { .compatible = "renesas,sdhi-r8a7796", .data = RENESAS_GEN3_QUIRKS },
357 { .compatible = "renesas,sdhi-r8a77965", .data = RENESAS_GEN3_QUIRKS },
358 { .compatible = "renesas,sdhi-r8a77970", .data = RENESAS_GEN3_QUIRKS },
Marek Vasutd6291522018-04-26 13:19:29 +0200359 { .compatible = "renesas,sdhi-r8a77990", .data = RENESAS_GEN3_QUIRKS },
Marek Vasutf98833d2018-04-08 18:49:52 +0200360 { .compatible = "renesas,sdhi-r8a77995", .data = RENESAS_GEN3_QUIRKS },
Marek Vasute94cad92018-04-08 15:22:58 +0200361 { /* sentinel */ }
362};
363
Marek Vasutc769e602018-04-08 17:45:23 +0200364static int renesas_sdhi_probe(struct udevice *dev)
365{
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +0900366 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutc769e602018-04-08 17:45:23 +0200367 u32 quirks = dev_get_driver_data(dev);
Marek Vasut7cf7ef82018-04-08 18:14:22 +0200368 struct fdt_resource reg_res;
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +0900369 struct clk clk;
Marek Vasut7cf7ef82018-04-08 18:14:22 +0200370 DECLARE_GLOBAL_DATA_PTR;
371 int ret;
372
Marek Vasutf98833d2018-04-08 18:49:52 +0200373 if (quirks == RENESAS_GEN2_QUIRKS) {
374 ret = fdt_get_resource(gd->fdt_blob, dev_of_offset(dev),
375 "reg", 0, &reg_res);
376 if (ret < 0) {
377 dev_err(dev, "\"reg\" resource not found, ret=%i\n",
378 ret);
379 return ret;
380 }
Marek Vasut7cf7ef82018-04-08 18:14:22 +0200381
Marek Vasutf98833d2018-04-08 18:49:52 +0200382 if (fdt_resource_size(&reg_res) == 0x100)
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200383 quirks |= TMIO_SD_CAP_16BIT;
Marek Vasutf98833d2018-04-08 18:49:52 +0200384 }
Marek Vasutc769e602018-04-08 17:45:23 +0200385
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +0900386 ret = clk_get_by_index(dev, 0, &clk);
387 if (ret < 0) {
388 dev_err(dev, "failed to get host clock\n");
389 return ret;
390 }
391
392 /* set to max rate */
393 priv->mclk = clk_set_rate(&clk, ULONG_MAX);
394 if (IS_ERR_VALUE(priv->mclk)) {
395 dev_err(dev, "failed to set rate for host clock\n");
396 clk_free(&clk);
397 return priv->mclk;
398 }
399
400 ret = clk_enable(&clk);
401 clk_free(&clk);
402 if (ret) {
403 dev_err(dev, "failed to enable host clock\n");
404 return ret;
405 }
406
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200407 ret = tmio_sd_probe(dev, quirks);
Marek Vasutf63968b2018-04-08 19:09:17 +0200408#if CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)
Marek Vasut52e17962018-10-28 15:30:06 +0100409 if (!ret && (priv->caps & TMIO_SD_CAP_RCAR_UHS))
Marek Vasut65186972018-08-30 15:27:26 +0200410 renesas_sdhi_reset_tuning(priv);
Marek Vasutf63968b2018-04-08 19:09:17 +0200411#endif
412 return ret;
Marek Vasutc769e602018-04-08 17:45:23 +0200413}
414
Marek Vasute94cad92018-04-08 15:22:58 +0200415U_BOOT_DRIVER(renesas_sdhi) = {
416 .name = "renesas-sdhi",
417 .id = UCLASS_MMC,
418 .of_match = renesas_sdhi_match,
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200419 .bind = tmio_sd_bind,
Marek Vasutc769e602018-04-08 17:45:23 +0200420 .probe = renesas_sdhi_probe,
Marek Vasutcb0b6b02018-04-13 23:51:33 +0200421 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
422 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
Marek Vasute94cad92018-04-08 15:22:58 +0200423 .ops = &renesas_sdhi_ops,
424};