]> Git Repo - u-boot.git/blame - drivers/mmc/dw_mmc.c
spi: stm32_qspi: Remove SR_BUSY bit check before sending command
[u-boot.git] / drivers / mmc / dw_mmc.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
757bff49
JC
2/*
3 * (C) Copyright 2012 SAMSUNG Electronics
4 * Jaehoon Chung <[email protected]>
5 * Rajeshawari Shinde <[email protected]>
757bff49
JC
6 */
7
2a7a210e 8#include <bouncebuf.h>
757bff49 9#include <common.h>
1eb69ae4 10#include <cpu_func.h>
1c87ffe8 11#include <errno.h>
f7ae49fc 12#include <log.h>
757bff49 13#include <malloc.h>
cf92e05c 14#include <memalign.h>
757bff49
JC
15#include <mmc.h>
16#include <dwmmc.h>
7997599e 17#include <wait_bit.h>
90526e9f 18#include <asm/cache.h>
c05ed00a 19#include <linux/delay.h>
2b157019 20#include <power/regulator.h>
757bff49
JC
21
22#define PAGE_SIZE 4096
23
24static int dwmci_wait_reset(struct dwmci_host *host, u32 value)
25{
26 unsigned long timeout = 1000;
27 u32 ctrl;
28
29 dwmci_writel(host, DWMCI_CTRL, value);
30
31 while (timeout--) {
32 ctrl = dwmci_readl(host, DWMCI_CTRL);
33 if (!(ctrl & DWMCI_RESET_ALL))
34 return 1;
35 }
36 return 0;
37}
38
39static void dwmci_set_idma_desc(struct dwmci_idmac *idmac,
40 u32 desc0, u32 desc1, u32 desc2)
41{
42 struct dwmci_idmac *desc = idmac;
43
44 desc->flags = desc0;
45 desc->cnt = desc1;
46 desc->addr = desc2;
41f7be3c 47 desc->next_addr = (ulong)desc + sizeof(struct dwmci_idmac);
757bff49
JC
48}
49
50static void dwmci_prepare_data(struct dwmci_host *host,
2a7a210e
AB
51 struct mmc_data *data,
52 struct dwmci_idmac *cur_idmac,
53 void *bounce_buffer)
757bff49
JC
54{
55 unsigned long ctrl;
56 unsigned int i = 0, flags, cnt, blk_cnt;
2a7a210e 57 ulong data_start, data_end;
757bff49
JC
58
59
60 blk_cnt = data->blocks;
61
62 dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET);
63
7997599e
LFT
64 /* Clear IDMAC interrupt */
65 dwmci_writel(host, DWMCI_IDSTS, 0xFFFFFFFF);
66
757bff49 67 data_start = (ulong)cur_idmac;
41f7be3c 68 dwmci_writel(host, DWMCI_DBADDR, (ulong)cur_idmac);
757bff49 69
757bff49
JC
70 do {
71 flags = DWMCI_IDMAC_OWN | DWMCI_IDMAC_CH ;
72 flags |= (i == 0) ? DWMCI_IDMAC_FS : 0;
73 if (blk_cnt <= 8) {
74 flags |= DWMCI_IDMAC_LD;
75 cnt = data->blocksize * blk_cnt;
76 } else
77 cnt = data->blocksize * 8;
78
79 dwmci_set_idma_desc(cur_idmac, flags, cnt,
41f7be3c 80 (ulong)bounce_buffer + (i * PAGE_SIZE));
757bff49 81
bdb5df1a 82 cur_idmac++;
21bd5761 83 if (blk_cnt <= 8)
757bff49
JC
84 break;
85 blk_cnt -= 8;
757bff49
JC
86 i++;
87 } while(1);
88
89 data_end = (ulong)cur_idmac;
bdb5df1a 90 flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN));
757bff49
JC
91
92 ctrl = dwmci_readl(host, DWMCI_CTRL);
93 ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
94 dwmci_writel(host, DWMCI_CTRL, ctrl);
95
96 ctrl = dwmci_readl(host, DWMCI_BMOD);
97 ctrl |= DWMCI_BMOD_IDMAC_FB | DWMCI_BMOD_IDMAC_EN;
98 dwmci_writel(host, DWMCI_BMOD, ctrl);
99
100 dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize);
101 dwmci_writel(host, DWMCI_BYTCNT, data->blocksize * data->blocks);
102}
103
05fa06b9
HS
104static int dwmci_fifo_ready(struct dwmci_host *host, u32 bit, u32 *len)
105{
106 u32 timeout = 20000;
107
108 *len = dwmci_readl(host, DWMCI_STATUS);
109 while (--timeout && (*len & bit)) {
110 udelay(200);
111 *len = dwmci_readl(host, DWMCI_STATUS);
112 }
113
114 if (!timeout) {
115 debug("%s: FIFO underflow timeout\n", __func__);
116 return -ETIMEDOUT;
117 }
118
119 return 0;
120}
121
4e16f0a6
MV
122static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size)
123{
124 unsigned int timeout;
125
c077c057
KY
126 timeout = size * 8; /* counting in bits */
127 timeout *= 10; /* wait 10 times as long */
4e16f0a6
MV
128 timeout /= mmc->clock;
129 timeout /= mmc->bus_width;
130 timeout /= mmc->ddr_mode ? 2 : 1;
c077c057 131 timeout *= 1000; /* counting in msec */
4e16f0a6
MV
132 timeout = (timeout < 1000) ? 1000 : timeout;
133
134 return timeout;
135}
136
a65f51b9 137static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
f382eb83 138{
4e16f0a6 139 struct mmc *mmc = host->mmc;
f382eb83 140 int ret = 0;
4e16f0a6 141 u32 timeout, mask, size, i, len = 0;
a65f51b9 142 u32 *buf = NULL;
f382eb83 143 ulong start = get_timer(0);
a65f51b9 144 u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
145 RX_WMARK_SHIFT) + 1) * 2;
146
4e16f0a6 147 size = data->blocksize * data->blocks;
a65f51b9 148 if (data->flags == MMC_DATA_READ)
149 buf = (unsigned int *)data->dest;
150 else
151 buf = (unsigned int *)data->src;
f382eb83 152
4e16f0a6
MV
153 timeout = dwmci_get_timeout(mmc, size);
154
155 size /= 4;
156
f382eb83 157 for (;;) {
158 mask = dwmci_readl(host, DWMCI_RINTSTS);
159 /* Error during data transfer. */
160 if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
161 debug("%s: DATA ERROR!\n", __func__);
162 ret = -EINVAL;
163 break;
164 }
165
a65f51b9 166 if (host->fifo_mode && size) {
720724d0 167 len = 0;
2b429033 168 if (data->flags == MMC_DATA_READ &&
8cb9d3ed
LFT
169 (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) {
170 dwmci_writel(host, DWMCI_RINTSTS,
171 DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO);
2b429033 172 while (size) {
05fa06b9
HS
173 ret = dwmci_fifo_ready(host,
174 DWMCI_FIFO_EMPTY,
175 &len);
176 if (ret < 0)
177 break;
178
a65f51b9 179 len = (len >> DWMCI_FIFO_SHIFT) &
180 DWMCI_FIFO_MASK;
2990e07a 181 len = min(size, len);
a65f51b9 182 for (i = 0; i < len; i++)
183 *buf++ =
184 dwmci_readl(host, DWMCI_DATA);
2b429033 185 size = size > len ? (size - len) : 0;
a65f51b9 186 }
2b429033
JC
187 } else if (data->flags == MMC_DATA_WRITE &&
188 (mask & DWMCI_INTMSK_TXDR)) {
189 while (size) {
05fa06b9
HS
190 ret = dwmci_fifo_ready(host,
191 DWMCI_FIFO_FULL,
192 &len);
193 if (ret < 0)
194 break;
195
a65f51b9 196 len = fifo_depth - ((len >>
197 DWMCI_FIFO_SHIFT) &
198 DWMCI_FIFO_MASK);
2990e07a 199 len = min(size, len);
a65f51b9 200 for (i = 0; i < len; i++)
201 dwmci_writel(host, DWMCI_DATA,
202 *buf++);
2b429033 203 size = size > len ? (size - len) : 0;
a65f51b9 204 }
2b429033
JC
205 dwmci_writel(host, DWMCI_RINTSTS,
206 DWMCI_INTMSK_TXDR);
a65f51b9 207 }
a65f51b9 208 }
209
f382eb83 210 /* Data arrived correctly. */
211 if (mask & DWMCI_INTMSK_DTO) {
212 ret = 0;
213 break;
214 }
215
216 /* Check for timeout. */
217 if (get_timer(start) > timeout) {
218 debug("%s: Timeout waiting for data!\n",
219 __func__);
915ffa52 220 ret = -ETIMEDOUT;
f382eb83 221 break;
222 }
223 }
224
225 dwmci_writel(host, DWMCI_RINTSTS, mask);
226
227 return ret;
228}
229
757bff49
JC
230static int dwmci_set_transfer_mode(struct dwmci_host *host,
231 struct mmc_data *data)
232{
233 unsigned long mode;
234
235 mode = DWMCI_CMD_DATA_EXP;
236 if (data->flags & MMC_DATA_WRITE)
237 mode |= DWMCI_CMD_RW;
238
239 return mode;
240}
241
e7881d85 242#ifdef CONFIG_DM_MMC
5628347f 243static int dwmci_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
691272fe
SG
244 struct mmc_data *data)
245{
246 struct mmc *mmc = mmc_get_mmc_dev(dev);
247#else
757bff49
JC
248static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
249 struct mmc_data *data)
250{
691272fe 251#endif
93bfd616 252 struct dwmci_host *host = mmc->priv;
2136d226 253 ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac,
21bd5761 254 data ? DIV_ROUND_UP(data->blocks, 8) : 0);
9042d974 255 int ret = 0, flags = 0, i;
02ebd42c 256 unsigned int timeout = 500;
9b5b8b6e 257 u32 retry = 100000;
757bff49 258 u32 mask, ctrl;
9c50e35f 259 ulong start = get_timer(0);
2a7a210e 260 struct bounce_buffer bbstate;
757bff49
JC
261
262 while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) {
9c50e35f 263 if (get_timer(start) > timeout) {
1c87ffe8 264 debug("%s: Timeout on data busy\n", __func__);
915ffa52 265 return -ETIMEDOUT;
757bff49 266 }
757bff49
JC
267 }
268
269 dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL);
270
2a7a210e 271 if (data) {
a65f51b9 272 if (host->fifo_mode) {
273 dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize);
274 dwmci_writel(host, DWMCI_BYTCNT,
275 data->blocksize * data->blocks);
276 dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET);
2a7a210e 277 } else {
a65f51b9 278 if (data->flags == MMC_DATA_READ) {
6ad5aec4
MV
279 ret = bounce_buffer_start(&bbstate,
280 (void*)data->dest,
a65f51b9 281 data->blocksize *
282 data->blocks, GEN_BB_WRITE);
283 } else {
6ad5aec4
MV
284 ret = bounce_buffer_start(&bbstate,
285 (void*)data->src,
a65f51b9 286 data->blocksize *
287 data->blocks, GEN_BB_READ);
288 }
6ad5aec4
MV
289
290 if (ret)
291 return ret;
292
a65f51b9 293 dwmci_prepare_data(host, data, cur_idmac,
294 bbstate.bounce_buffer);
2a7a210e 295 }
2a7a210e 296 }
757bff49 297
757bff49
JC
298 dwmci_writel(host, DWMCI_CMDARG, cmd->cmdarg);
299
300 if (data)
301 flags = dwmci_set_transfer_mode(host, data);
302
303 if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY))
66d0b7e1 304 return -EBUSY;
757bff49
JC
305
306 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
307 flags |= DWMCI_CMD_ABORT_STOP;
308 else
309 flags |= DWMCI_CMD_PRV_DAT_WAIT;
310
311 if (cmd->resp_type & MMC_RSP_PRESENT) {
312 flags |= DWMCI_CMD_RESP_EXP;
313 if (cmd->resp_type & MMC_RSP_136)
314 flags |= DWMCI_CMD_RESP_LENGTH;
315 }
316
317 if (cmd->resp_type & MMC_RSP_CRC)
318 flags |= DWMCI_CMD_CHECK_CRC;
319
320 flags |= (cmd->cmdidx | DWMCI_CMD_START | DWMCI_CMD_USE_HOLD_REG);
321
322 debug("Sending CMD%d\n",cmd->cmdidx);
323
324 dwmci_writel(host, DWMCI_CMD, flags);
325
326 for (i = 0; i < retry; i++) {
327 mask = dwmci_readl(host, DWMCI_RINTSTS);
328 if (mask & DWMCI_INTMSK_CDONE) {
329 if (!data)
330 dwmci_writel(host, DWMCI_RINTSTS, mask);
331 break;
332 }
333 }
334
f33c9305 335 if (i == retry) {
1c87ffe8 336 debug("%s: Timeout.\n", __func__);
915ffa52 337 return -ETIMEDOUT;
f33c9305 338 }
757bff49
JC
339
340 if (mask & DWMCI_INTMSK_RTO) {
f33c9305
PM
341 /*
342 * Timeout here is not necessarily fatal. (e)MMC cards
343 * will splat here when they receive CMD55 as they do
344 * not support this command and that is exactly the way
345 * to tell them apart from SD cards. Thus, this output
346 * below shall be debug(). eMMC cards also do not favor
347 * CMD8, please keep that in mind.
348 */
349 debug("%s: Response Timeout.\n", __func__);
915ffa52 350 return -ETIMEDOUT;
757bff49 351 } else if (mask & DWMCI_INTMSK_RE) {
1c87ffe8
SG
352 debug("%s: Response Error.\n", __func__);
353 return -EIO;
26cc40d8
MV
354 } else if ((cmd->resp_type & MMC_RSP_CRC) &&
355 (mask & DWMCI_INTMSK_RCRC)) {
356 debug("%s: Response CRC Error.\n", __func__);
357 return -EIO;
757bff49
JC
358 }
359
360
361 if (cmd->resp_type & MMC_RSP_PRESENT) {
362 if (cmd->resp_type & MMC_RSP_136) {
363 cmd->response[0] = dwmci_readl(host, DWMCI_RESP3);
364 cmd->response[1] = dwmci_readl(host, DWMCI_RESP2);
365 cmd->response[2] = dwmci_readl(host, DWMCI_RESP1);
366 cmd->response[3] = dwmci_readl(host, DWMCI_RESP0);
367 } else {
368 cmd->response[0] = dwmci_readl(host, DWMCI_RESP0);
369 }
370 }
371
372 if (data) {
a65f51b9 373 ret = dwmci_data_transfer(host, data);
374
375 /* only dma mode need it */
376 if (!host->fifo_mode) {
7997599e
LFT
377 if (data->flags == MMC_DATA_READ)
378 mask = DWMCI_IDINTEN_RI;
379 else
380 mask = DWMCI_IDINTEN_TI;
381 ret = wait_for_bit_le32(host->ioaddr + DWMCI_IDSTS,
382 mask, true, 1000, false);
383 if (ret)
384 debug("%s: DWMCI_IDINTEN mask 0x%x timeout.\n",
385 __func__, mask);
386 /* clear interrupts */
387 dwmci_writel(host, DWMCI_IDSTS, DWMCI_IDINTEN_MASK);
388
a65f51b9 389 ctrl = dwmci_readl(host, DWMCI_CTRL);
390 ctrl &= ~(DWMCI_DMA_EN);
391 dwmci_writel(host, DWMCI_CTRL, ctrl);
392 bounce_buffer_stop(&bbstate);
393 }
757bff49
JC
394 }
395
396 udelay(100);
397
9042d974 398 return ret;
757bff49
JC
399}
400
401static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)
402{
403 u32 div, status;
404 int timeout = 10000;
405 unsigned long sclk;
406
9c50e35f 407 if ((freq == host->clock) || (freq == 0))
757bff49 408 return 0;
757bff49 409 /*
f33c9305 410 * If host->get_mmc_clk isn't defined,
757bff49 411 * then assume that host->bus_hz is source clock value.
f33c9305 412 * host->bus_hz should be set by user.
757bff49 413 */
b44fe83a 414 if (host->get_mmc_clk)
e3563f2e 415 sclk = host->get_mmc_clk(host, freq);
757bff49
JC
416 else if (host->bus_hz)
417 sclk = host->bus_hz;
418 else {
1c87ffe8 419 debug("%s: Didn't get source clock value.\n", __func__);
757bff49
JC
420 return -EINVAL;
421 }
422
6ace153d
CLS
423 if (sclk == freq)
424 div = 0; /* bypass mode */
425 else
426 div = DIV_ROUND_UP(sclk, 2 * freq);
757bff49
JC
427
428 dwmci_writel(host, DWMCI_CLKENA, 0);
429 dwmci_writel(host, DWMCI_CLKSRC, 0);
430
431 dwmci_writel(host, DWMCI_CLKDIV, div);
432 dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT |
433 DWMCI_CMD_UPD_CLK | DWMCI_CMD_START);
434
435 do {
436 status = dwmci_readl(host, DWMCI_CMD);
437 if (timeout-- < 0) {
1c87ffe8 438 debug("%s: Timeout!\n", __func__);
757bff49
JC
439 return -ETIMEDOUT;
440 }
441 } while (status & DWMCI_CMD_START);
442
443 dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE |
444 DWMCI_CLKEN_LOW_PWR);
445
446 dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT |
447 DWMCI_CMD_UPD_CLK | DWMCI_CMD_START);
448
449 timeout = 10000;
450 do {
451 status = dwmci_readl(host, DWMCI_CMD);
452 if (timeout-- < 0) {
1c87ffe8 453 debug("%s: Timeout!\n", __func__);
757bff49
JC
454 return -ETIMEDOUT;
455 }
456 } while (status & DWMCI_CMD_START);
457
458 host->clock = freq;
459
460 return 0;
461}
462
e7881d85 463#ifdef CONFIG_DM_MMC
5628347f 464static int dwmci_set_ios(struct udevice *dev)
691272fe
SG
465{
466 struct mmc *mmc = mmc_get_mmc_dev(dev);
467#else
07b0b9c0 468static int dwmci_set_ios(struct mmc *mmc)
757bff49 469{
691272fe 470#endif
045bdcd0
JC
471 struct dwmci_host *host = (struct dwmci_host *)mmc->priv;
472 u32 ctype, regs;
757bff49 473
f33c9305 474 debug("Buswidth = %d, clock: %d\n", mmc->bus_width, mmc->clock);
757bff49
JC
475
476 dwmci_setup_bus(host, mmc->clock);
477 switch (mmc->bus_width) {
478 case 8:
479 ctype = DWMCI_CTYPE_8BIT;
480 break;
481 case 4:
482 ctype = DWMCI_CTYPE_4BIT;
483 break;
484 default:
485 ctype = DWMCI_CTYPE_1BIT;
486 break;
487 }
488
489 dwmci_writel(host, DWMCI_CTYPE, ctype);
490
045bdcd0 491 regs = dwmci_readl(host, DWMCI_UHS_REG);
2b8a9692 492 if (mmc->ddr_mode)
045bdcd0
JC
493 regs |= DWMCI_DDR_MODE;
494 else
afc9e2b5 495 regs &= ~DWMCI_DDR_MODE;
045bdcd0
JC
496
497 dwmci_writel(host, DWMCI_UHS_REG, regs);
498
d456dfba
SCL
499 if (host->clksel) {
500 int ret;
501
502 ret = host->clksel(host);
503 if (ret)
504 return ret;
505 }
07b0b9c0 506
2b157019
UR
507#if CONFIG_IS_ENABLED(DM_REGULATOR)
508 if (mmc->vqmmc_supply) {
509 int ret;
510
511 if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
512 regulator_set_value(mmc->vqmmc_supply, 1800000);
513 else
514 regulator_set_value(mmc->vqmmc_supply, 3300000);
515
516 ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
517 if (ret)
518 return ret;
519 }
520#endif
521
691272fe 522 return 0;
757bff49
JC
523}
524
525static int dwmci_init(struct mmc *mmc)
526{
93bfd616 527 struct dwmci_host *host = mmc->priv;
757bff49 528
18ab6755
JC
529 if (host->board_init)
530 host->board_init(host);
6f0b7caa 531
757bff49
JC
532 dwmci_writel(host, DWMCI_PWREN, 1);
533
534 if (!dwmci_wait_reset(host, DWMCI_RESET_ALL)) {
1c87ffe8
SG
535 debug("%s[%d] Fail-reset!!\n", __func__, __LINE__);
536 return -EIO;
757bff49
JC
537 }
538
9c50e35f 539 /* Enumerate at 400KHz */
93bfd616 540 dwmci_setup_bus(host, mmc->cfg->f_min);
9c50e35f 541
757bff49
JC
542 dwmci_writel(host, DWMCI_RINTSTS, 0xFFFFFFFF);
543 dwmci_writel(host, DWMCI_INTMASK, 0);
544
545 dwmci_writel(host, DWMCI_TMOUT, 0xFFFFFFFF);
546
547 dwmci_writel(host, DWMCI_IDINTEN, 0);
548 dwmci_writel(host, DWMCI_BMOD, 1);
549
760177df
SG
550 if (!host->fifoth_val) {
551 uint32_t fifo_size;
552
553 fifo_size = dwmci_readl(host, DWMCI_FIFOTH);
554 fifo_size = ((fifo_size & RX_WMARK_MASK) >> RX_WMARK_SHIFT) + 1;
555 host->fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size / 2 - 1) |
556 TX_WMARK(fifo_size / 2);
9c50e35f 557 }
760177df 558 dwmci_writel(host, DWMCI_FIFOTH, host->fifoth_val);
757bff49
JC
559
560 dwmci_writel(host, DWMCI_CLKENA, 0);
561 dwmci_writel(host, DWMCI_CLKSRC, 0);
562
7997599e
LFT
563 if (!host->fifo_mode)
564 dwmci_writel(host, DWMCI_IDINTEN, DWMCI_IDINTEN_MASK);
565
757bff49
JC
566 return 0;
567}
568
e7881d85 569#ifdef CONFIG_DM_MMC
691272fe
SG
570int dwmci_probe(struct udevice *dev)
571{
572 struct mmc *mmc = mmc_get_mmc_dev(dev);
573
574 return dwmci_init(mmc);
575}
576
577const struct dm_mmc_ops dm_dwmci_ops = {
578 .send_cmd = dwmci_send_cmd,
579 .set_ios = dwmci_set_ios,
580};
581
582#else
ab769f22
PA
583static const struct mmc_ops dwmci_ops = {
584 .send_cmd = dwmci_send_cmd,
585 .set_ios = dwmci_set_ios,
586 .init = dwmci_init,
587};
691272fe 588#endif
ab769f22 589
e5113c33
JC
590void dwmci_setup_cfg(struct mmc_config *cfg, struct dwmci_host *host,
591 u32 max_clk, u32 min_clk)
757bff49 592{
e5113c33 593 cfg->name = host->name;
e7881d85 594#ifndef CONFIG_DM_MMC
5e6ff810 595 cfg->ops = &dwmci_ops;
691272fe 596#endif
5e6ff810
SG
597 cfg->f_min = min_clk;
598 cfg->f_max = max_clk;
757bff49 599
5e6ff810 600 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
757bff49 601
e5113c33 602 cfg->host_caps = host->caps;
757bff49 603
e5113c33 604 if (host->buswidth == 8) {
5e6ff810
SG
605 cfg->host_caps |= MMC_MODE_8BIT;
606 cfg->host_caps &= ~MMC_MODE_4BIT;
757bff49 607 } else {
5e6ff810
SG
608 cfg->host_caps |= MMC_MODE_4BIT;
609 cfg->host_caps &= ~MMC_MODE_8BIT;
757bff49 610 }
5e6ff810
SG
611 cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz;
612
613 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
614}
93bfd616 615
5e6ff810
SG
616#ifdef CONFIG_BLK
617int dwmci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg)
618{
619 return mmc_bind(dev, mmc, cfg);
620}
621#else
622int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
623{
e5113c33 624 dwmci_setup_cfg(&host->cfg, host, max_clk, min_clk);
757bff49 625
93bfd616
PA
626 host->mmc = mmc_create(&host->cfg, host);
627 if (host->mmc == NULL)
628 return -1;
757bff49 629
93bfd616 630 return 0;
757bff49 631}
5e6ff810 632#endif
This page took 0.383285 seconds and 4 git commands to generate.