Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 SAMSUNG Electronics |
| 4 | * Jaehoon Chung <jh80.chung@samsung.com> |
| 5 | * Rajeshawari Shinde <rajeshwari.s@samsung.com> |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 8 | #include <bouncebuf.h> |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 11 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 13 | #include <malloc.h> |
Simon Glass | 2dd337a | 2015-09-02 17:24:58 -0600 | [diff] [blame] | 14 | #include <memalign.h> |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 15 | #include <mmc.h> |
| 16 | #include <dwmmc.h> |
Ley Foon Tan | b98e892 | 2018-12-20 17:55:41 +0800 | [diff] [blame] | 17 | #include <wait_bit.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <asm/cache.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Urja Rannikko | 9932a01 | 2019-05-13 13:25:27 +0000 | [diff] [blame] | 20 | #include <power/regulator.h> |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 21 | |
| 22 | #define PAGE_SIZE 4096 |
| 23 | |
| 24 | static 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 | |
| 39 | static 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; |
Prabhakar Kushwaha | fdefb90 | 2015-10-25 13:18:25 +0530 | [diff] [blame] | 47 | desc->next_addr = (ulong)desc + sizeof(struct dwmci_idmac); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void dwmci_prepare_data(struct dwmci_host *host, |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 51 | struct mmc_data *data, |
| 52 | struct dwmci_idmac *cur_idmac, |
| 53 | void *bounce_buffer) |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 54 | { |
| 55 | unsigned long ctrl; |
| 56 | unsigned int i = 0, flags, cnt, blk_cnt; |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 57 | ulong data_start, data_end; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 58 | |
| 59 | |
| 60 | blk_cnt = data->blocks; |
| 61 | |
| 62 | dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET); |
| 63 | |
Ley Foon Tan | b98e892 | 2018-12-20 17:55:41 +0800 | [diff] [blame] | 64 | /* Clear IDMAC interrupt */ |
| 65 | dwmci_writel(host, DWMCI_IDSTS, 0xFFFFFFFF); |
| 66 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 67 | data_start = (ulong)cur_idmac; |
Prabhakar Kushwaha | fdefb90 | 2015-10-25 13:18:25 +0530 | [diff] [blame] | 68 | dwmci_writel(host, DWMCI_DBADDR, (ulong)cur_idmac); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 69 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 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, |
Prabhakar Kushwaha | fdefb90 | 2015-10-25 13:18:25 +0530 | [diff] [blame] | 80 | (ulong)bounce_buffer + (i * PAGE_SIZE)); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 81 | |
Marek Vasut | b6da37b | 2019-02-13 20:16:20 +0100 | [diff] [blame] | 82 | cur_idmac++; |
Mischa Jonker | a7a6091 | 2013-07-26 16:18:40 +0200 | [diff] [blame] | 83 | if (blk_cnt <= 8) |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 84 | break; |
| 85 | blk_cnt -= 8; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 86 | i++; |
| 87 | } while(1); |
| 88 | |
| 89 | data_end = (ulong)cur_idmac; |
Marek Vasut | b6da37b | 2019-02-13 20:16:20 +0100 | [diff] [blame] | 90 | flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN)); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 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 | |
Heiko Stuebner | 46b7a4f | 2018-09-21 10:59:45 +0200 | [diff] [blame] | 104 | static 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 | |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 122 | static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size) |
| 123 | { |
| 124 | unsigned int timeout; |
| 125 | |
Kever Yang | 4889d83 | 2019-08-29 15:42:41 +0800 | [diff] [blame] | 126 | timeout = size * 8; /* counting in bits */ |
| 127 | timeout *= 10; /* wait 10 times as long */ |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 128 | timeout /= mmc->clock; |
| 129 | timeout /= mmc->bus_width; |
| 130 | timeout /= mmc->ddr_mode ? 2 : 1; |
Kever Yang | 4889d83 | 2019-08-29 15:42:41 +0800 | [diff] [blame] | 131 | timeout *= 1000; /* counting in msec */ |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 132 | timeout = (timeout < 1000) ? 1000 : timeout; |
| 133 | |
| 134 | return timeout; |
| 135 | } |
| 136 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 137 | static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data) |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 138 | { |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 139 | struct mmc *mmc = host->mmc; |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 140 | int ret = 0; |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 141 | u32 timeout, mask, size, i, len = 0; |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 142 | u32 *buf = NULL; |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 143 | ulong start = get_timer(0); |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 144 | u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >> |
| 145 | RX_WMARK_SHIFT) + 1) * 2; |
| 146 | |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 147 | size = data->blocksize * data->blocks; |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 148 | if (data->flags == MMC_DATA_READ) |
| 149 | buf = (unsigned int *)data->dest; |
| 150 | else |
| 151 | buf = (unsigned int *)data->src; |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 152 | |
Marek Vasut | ffac512 | 2019-03-23 03:32:24 +0100 | [diff] [blame] | 153 | timeout = dwmci_get_timeout(mmc, size); |
| 154 | |
| 155 | size /= 4; |
| 156 | |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 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 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 166 | if (host->fifo_mode && size) { |
Xu Ziyuan | 5b8bf12 | 2016-07-28 10:25:48 +0800 | [diff] [blame] | 167 | len = 0; |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 168 | if (data->flags == MMC_DATA_READ && |
Ley Foon Tan | 1cead23 | 2021-04-26 11:35:05 +0800 | [diff] [blame] | 169 | (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) { |
| 170 | dwmci_writel(host, DWMCI_RINTSTS, |
John Keeping | a6a7157 | 2022-09-15 18:56:56 +0100 | [diff] [blame] | 171 | mask & (DWMCI_INTMSK_RXDR | |
| 172 | DWMCI_INTMSK_DTO)); |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 173 | while (size) { |
Heiko Stuebner | 46b7a4f | 2018-09-21 10:59:45 +0200 | [diff] [blame] | 174 | ret = dwmci_fifo_ready(host, |
| 175 | DWMCI_FIFO_EMPTY, |
| 176 | &len); |
| 177 | if (ret < 0) |
| 178 | break; |
| 179 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 180 | len = (len >> DWMCI_FIFO_SHIFT) & |
| 181 | DWMCI_FIFO_MASK; |
Xu Ziyuan | 6577a2a | 2016-07-28 10:25:47 +0800 | [diff] [blame] | 182 | len = min(size, len); |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 183 | for (i = 0; i < len; i++) |
| 184 | *buf++ = |
| 185 | dwmci_readl(host, DWMCI_DATA); |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 186 | size = size > len ? (size - len) : 0; |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 187 | } |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 188 | } else if (data->flags == MMC_DATA_WRITE && |
| 189 | (mask & DWMCI_INTMSK_TXDR)) { |
| 190 | while (size) { |
Heiko Stuebner | 46b7a4f | 2018-09-21 10:59:45 +0200 | [diff] [blame] | 191 | ret = dwmci_fifo_ready(host, |
| 192 | DWMCI_FIFO_FULL, |
| 193 | &len); |
| 194 | if (ret < 0) |
| 195 | break; |
| 196 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 197 | len = fifo_depth - ((len >> |
| 198 | DWMCI_FIFO_SHIFT) & |
| 199 | DWMCI_FIFO_MASK); |
Xu Ziyuan | 6577a2a | 2016-07-28 10:25:47 +0800 | [diff] [blame] | 200 | len = min(size, len); |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 201 | for (i = 0; i < len; i++) |
| 202 | dwmci_writel(host, DWMCI_DATA, |
| 203 | *buf++); |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 204 | size = size > len ? (size - len) : 0; |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 205 | } |
Jacob Chen | 953d975 | 2016-09-19 10:16:50 +0800 | [diff] [blame] | 206 | dwmci_writel(host, DWMCI_RINTSTS, |
| 207 | DWMCI_INTMSK_TXDR); |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 208 | } |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 209 | } |
| 210 | |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 211 | /* Data arrived correctly. */ |
| 212 | if (mask & DWMCI_INTMSK_DTO) { |
| 213 | ret = 0; |
| 214 | break; |
| 215 | } |
| 216 | |
| 217 | /* Check for timeout. */ |
| 218 | if (get_timer(start) > timeout) { |
| 219 | debug("%s: Timeout waiting for data!\n", |
| 220 | __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 221 | ret = -ETIMEDOUT; |
huang lin | f983676 | 2015-11-17 14:20:21 +0800 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | dwmci_writel(host, DWMCI_RINTSTS, mask); |
| 227 | |
| 228 | return ret; |
| 229 | } |
| 230 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 231 | static int dwmci_set_transfer_mode(struct dwmci_host *host, |
| 232 | struct mmc_data *data) |
| 233 | { |
| 234 | unsigned long mode; |
| 235 | |
| 236 | mode = DWMCI_CMD_DATA_EXP; |
| 237 | if (data->flags & MMC_DATA_WRITE) |
| 238 | mode |= DWMCI_CMD_RW; |
| 239 | |
| 240 | return mode; |
| 241 | } |
| 242 | |
Simon Glass | eba48f9 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 243 | #ifdef CONFIG_DM_MMC |
Jaehoon Chung | ad220ac | 2016-06-28 15:52:21 +0900 | [diff] [blame] | 244 | static int dwmci_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 245 | struct mmc_data *data) |
| 246 | { |
| 247 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 248 | #else |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 249 | static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
| 250 | struct mmc_data *data) |
| 251 | { |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 252 | #endif |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 253 | struct dwmci_host *host = mmc->priv; |
Mischa Jonker | 7423bed | 2013-07-26 14:08:14 +0200 | [diff] [blame] | 254 | ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac, |
Mischa Jonker | a7a6091 | 2013-07-26 16:18:40 +0200 | [diff] [blame] | 255 | data ? DIV_ROUND_UP(data->blocks, 8) : 0); |
Marek Vasut | 81e093f | 2015-07-27 22:39:38 +0200 | [diff] [blame] | 256 | int ret = 0, flags = 0, i; |
Xu Ziyuan | 34a10d3 | 2016-07-19 09:38:22 +0800 | [diff] [blame] | 257 | unsigned int timeout = 500; |
Alexander Graf | 61c2a66 | 2016-03-04 01:09:52 +0100 | [diff] [blame] | 258 | u32 retry = 100000; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 259 | u32 mask, ctrl; |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 260 | ulong start = get_timer(0); |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 261 | struct bounce_buffer bbstate; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 262 | |
| 263 | while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) { |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 264 | if (get_timer(start) > timeout) { |
Yang Xiwen | 84df6a7 | 2024-02-01 22:05:43 +0800 | [diff] [blame] | 265 | debug("%s: Timeout on data busy, continue anyway\n", __func__); |
| 266 | break; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 267 | } |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL); |
| 271 | |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 272 | if (data) { |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 273 | if (host->fifo_mode) { |
| 274 | dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize); |
| 275 | dwmci_writel(host, DWMCI_BYTCNT, |
| 276 | data->blocksize * data->blocks); |
| 277 | dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET); |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 278 | } else { |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 279 | if (data->flags == MMC_DATA_READ) { |
Marek Vasut | 72d37b6 | 2019-03-23 18:45:27 +0100 | [diff] [blame] | 280 | ret = bounce_buffer_start(&bbstate, |
| 281 | (void*)data->dest, |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 282 | data->blocksize * |
| 283 | data->blocks, GEN_BB_WRITE); |
| 284 | } else { |
Marek Vasut | 72d37b6 | 2019-03-23 18:45:27 +0100 | [diff] [blame] | 285 | ret = bounce_buffer_start(&bbstate, |
| 286 | (void*)data->src, |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 287 | data->blocksize * |
| 288 | data->blocks, GEN_BB_READ); |
| 289 | } |
Marek Vasut | 72d37b6 | 2019-03-23 18:45:27 +0100 | [diff] [blame] | 290 | |
| 291 | if (ret) |
| 292 | return ret; |
| 293 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 294 | dwmci_prepare_data(host, data, cur_idmac, |
| 295 | bbstate.bounce_buffer); |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 296 | } |
Alexey Brodkin | 55bab5e | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 297 | } |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 298 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 299 | dwmci_writel(host, DWMCI_CMDARG, cmd->cmdarg); |
| 300 | |
| 301 | if (data) |
| 302 | flags = dwmci_set_transfer_mode(host, data); |
| 303 | |
| 304 | if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY)) |
John Keeping | feb7fa3 | 2021-12-07 16:09:35 +0000 | [diff] [blame] | 305 | return -EBUSY; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 306 | |
| 307 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 308 | flags |= DWMCI_CMD_ABORT_STOP; |
| 309 | else |
| 310 | flags |= DWMCI_CMD_PRV_DAT_WAIT; |
| 311 | |
| 312 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 313 | flags |= DWMCI_CMD_RESP_EXP; |
| 314 | if (cmd->resp_type & MMC_RSP_136) |
| 315 | flags |= DWMCI_CMD_RESP_LENGTH; |
| 316 | } |
| 317 | |
| 318 | if (cmd->resp_type & MMC_RSP_CRC) |
| 319 | flags |= DWMCI_CMD_CHECK_CRC; |
| 320 | |
| 321 | flags |= (cmd->cmdidx | DWMCI_CMD_START | DWMCI_CMD_USE_HOLD_REG); |
| 322 | |
| 323 | debug("Sending CMD%d\n",cmd->cmdidx); |
| 324 | |
| 325 | dwmci_writel(host, DWMCI_CMD, flags); |
| 326 | |
| 327 | for (i = 0; i < retry; i++) { |
| 328 | mask = dwmci_readl(host, DWMCI_RINTSTS); |
| 329 | if (mask & DWMCI_INTMSK_CDONE) { |
| 330 | if (!data) |
| 331 | dwmci_writel(host, DWMCI_RINTSTS, mask); |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 336 | if (i == retry) { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 337 | debug("%s: Timeout.\n", __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 338 | return -ETIMEDOUT; |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 339 | } |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 340 | |
| 341 | if (mask & DWMCI_INTMSK_RTO) { |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 342 | /* |
| 343 | * Timeout here is not necessarily fatal. (e)MMC cards |
| 344 | * will splat here when they receive CMD55 as they do |
| 345 | * not support this command and that is exactly the way |
| 346 | * to tell them apart from SD cards. Thus, this output |
| 347 | * below shall be debug(). eMMC cards also do not favor |
| 348 | * CMD8, please keep that in mind. |
| 349 | */ |
| 350 | debug("%s: Response Timeout.\n", __func__); |
Jaehoon Chung | 7825d20 | 2016-07-19 16:33:36 +0900 | [diff] [blame] | 351 | return -ETIMEDOUT; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 352 | } else if (mask & DWMCI_INTMSK_RE) { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 353 | debug("%s: Response Error.\n", __func__); |
| 354 | return -EIO; |
Marek Vasut | a6d9199 | 2018-11-06 23:42:11 +0100 | [diff] [blame] | 355 | } else if ((cmd->resp_type & MMC_RSP_CRC) && |
| 356 | (mask & DWMCI_INTMSK_RCRC)) { |
| 357 | debug("%s: Response CRC Error.\n", __func__); |
| 358 | return -EIO; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | |
| 362 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 363 | if (cmd->resp_type & MMC_RSP_136) { |
| 364 | cmd->response[0] = dwmci_readl(host, DWMCI_RESP3); |
| 365 | cmd->response[1] = dwmci_readl(host, DWMCI_RESP2); |
| 366 | cmd->response[2] = dwmci_readl(host, DWMCI_RESP1); |
| 367 | cmd->response[3] = dwmci_readl(host, DWMCI_RESP0); |
| 368 | } else { |
| 369 | cmd->response[0] = dwmci_readl(host, DWMCI_RESP0); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | if (data) { |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 374 | ret = dwmci_data_transfer(host, data); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 375 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 376 | /* only dma mode need it */ |
| 377 | if (!host->fifo_mode) { |
Ley Foon Tan | b98e892 | 2018-12-20 17:55:41 +0800 | [diff] [blame] | 378 | if (data->flags == MMC_DATA_READ) |
| 379 | mask = DWMCI_IDINTEN_RI; |
| 380 | else |
| 381 | mask = DWMCI_IDINTEN_TI; |
| 382 | ret = wait_for_bit_le32(host->ioaddr + DWMCI_IDSTS, |
| 383 | mask, true, 1000, false); |
| 384 | if (ret) |
| 385 | debug("%s: DWMCI_IDINTEN mask 0x%x timeout.\n", |
| 386 | __func__, mask); |
| 387 | /* clear interrupts */ |
| 388 | dwmci_writel(host, DWMCI_IDSTS, DWMCI_IDINTEN_MASK); |
| 389 | |
huang lin | 50b7375 | 2015-11-17 14:20:22 +0800 | [diff] [blame] | 390 | ctrl = dwmci_readl(host, DWMCI_CTRL); |
| 391 | ctrl &= ~(DWMCI_DMA_EN); |
| 392 | dwmci_writel(host, DWMCI_CTRL, ctrl); |
| 393 | bounce_buffer_stop(&bbstate); |
| 394 | } |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | udelay(100); |
| 398 | |
Marek Vasut | 81e093f | 2015-07-27 22:39:38 +0200 | [diff] [blame] | 399 | return ret; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) |
| 403 | { |
| 404 | u32 div, status; |
| 405 | int timeout = 10000; |
| 406 | unsigned long sclk; |
| 407 | |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 408 | if ((freq == host->clock) || (freq == 0)) |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 409 | return 0; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 410 | /* |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 411 | * If host->get_mmc_clk isn't defined, |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 412 | * then assume that host->bus_hz is source clock value. |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 413 | * host->bus_hz should be set by user. |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 414 | */ |
Jaehoon Chung | d94735b | 2013-10-06 18:59:31 +0900 | [diff] [blame] | 415 | if (host->get_mmc_clk) |
Simon Glass | eff7668 | 2015-08-30 16:55:15 -0600 | [diff] [blame] | 416 | sclk = host->get_mmc_clk(host, freq); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 417 | else if (host->bus_hz) |
| 418 | sclk = host->bus_hz; |
| 419 | else { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 420 | debug("%s: Didn't get source clock value.\n", __func__); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 421 | return -EINVAL; |
| 422 | } |
| 423 | |
Chin Liang See | 4cfff95 | 2014-06-10 01:26:52 -0500 | [diff] [blame] | 424 | if (sclk == freq) |
| 425 | div = 0; /* bypass mode */ |
| 426 | else |
| 427 | div = DIV_ROUND_UP(sclk, 2 * freq); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 428 | |
| 429 | dwmci_writel(host, DWMCI_CLKENA, 0); |
| 430 | dwmci_writel(host, DWMCI_CLKSRC, 0); |
| 431 | |
| 432 | dwmci_writel(host, DWMCI_CLKDIV, div); |
| 433 | dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | |
| 434 | DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); |
| 435 | |
| 436 | do { |
| 437 | status = dwmci_readl(host, DWMCI_CMD); |
| 438 | if (timeout-- < 0) { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 439 | debug("%s: Timeout!\n", __func__); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 440 | return -ETIMEDOUT; |
| 441 | } |
| 442 | } while (status & DWMCI_CMD_START); |
| 443 | |
| 444 | dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE | |
| 445 | DWMCI_CLKEN_LOW_PWR); |
| 446 | |
| 447 | dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | |
| 448 | DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); |
| 449 | |
| 450 | timeout = 10000; |
| 451 | do { |
| 452 | status = dwmci_readl(host, DWMCI_CMD); |
| 453 | if (timeout-- < 0) { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 454 | debug("%s: Timeout!\n", __func__); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 455 | return -ETIMEDOUT; |
| 456 | } |
| 457 | } while (status & DWMCI_CMD_START); |
| 458 | |
| 459 | host->clock = freq; |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
Simon Glass | eba48f9 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 464 | #ifdef CONFIG_DM_MMC |
Jaehoon Chung | ad220ac | 2016-06-28 15:52:21 +0900 | [diff] [blame] | 465 | static int dwmci_set_ios(struct udevice *dev) |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 466 | { |
| 467 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 468 | #else |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 469 | static int dwmci_set_ios(struct mmc *mmc) |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 470 | { |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 471 | #endif |
Jaehoon Chung | e867294 | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 472 | struct dwmci_host *host = (struct dwmci_host *)mmc->priv; |
| 473 | u32 ctype, regs; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 474 | |
Pavel Machek | a425f5d | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 475 | debug("Buswidth = %d, clock: %d\n", mmc->bus_width, mmc->clock); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 476 | |
| 477 | dwmci_setup_bus(host, mmc->clock); |
| 478 | switch (mmc->bus_width) { |
| 479 | case 8: |
| 480 | ctype = DWMCI_CTYPE_8BIT; |
| 481 | break; |
| 482 | case 4: |
| 483 | ctype = DWMCI_CTYPE_4BIT; |
| 484 | break; |
| 485 | default: |
| 486 | ctype = DWMCI_CTYPE_1BIT; |
| 487 | break; |
| 488 | } |
| 489 | |
| 490 | dwmci_writel(host, DWMCI_CTYPE, ctype); |
| 491 | |
Jaehoon Chung | e867294 | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 492 | regs = dwmci_readl(host, DWMCI_UHS_REG); |
Andrew Gabbasov | 54c0e22 | 2014-12-01 06:59:12 -0600 | [diff] [blame] | 493 | if (mmc->ddr_mode) |
Jaehoon Chung | e867294 | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 494 | regs |= DWMCI_DDR_MODE; |
| 495 | else |
Jaehoon Chung | 401fc50 | 2015-01-14 17:37:53 +0900 | [diff] [blame] | 496 | regs &= ~DWMCI_DDR_MODE; |
Jaehoon Chung | e867294 | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 497 | |
| 498 | dwmci_writel(host, DWMCI_UHS_REG, regs); |
| 499 | |
Siew Chin Lim | c51e7e1 | 2020-12-24 18:21:03 +0800 | [diff] [blame] | 500 | if (host->clksel) { |
| 501 | int ret; |
| 502 | |
| 503 | ret = host->clksel(host); |
| 504 | if (ret) |
| 505 | return ret; |
| 506 | } |
Jaehoon Chung | b6cd1d3 | 2016-12-30 15:30:16 +0900 | [diff] [blame] | 507 | |
Urja Rannikko | 9932a01 | 2019-05-13 13:25:27 +0000 | [diff] [blame] | 508 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
| 509 | if (mmc->vqmmc_supply) { |
| 510 | int ret; |
| 511 | |
Jonas Karlman | a117d61 | 2023-07-19 21:21:00 +0000 | [diff] [blame] | 512 | ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, false); |
| 513 | if (ret) |
| 514 | return ret; |
| 515 | |
Urja Rannikko | 9932a01 | 2019-05-13 13:25:27 +0000 | [diff] [blame] | 516 | if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180) |
| 517 | regulator_set_value(mmc->vqmmc_supply, 1800000); |
| 518 | else |
| 519 | regulator_set_value(mmc->vqmmc_supply, 3300000); |
| 520 | |
| 521 | ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true); |
| 522 | if (ret) |
| 523 | return ret; |
| 524 | } |
| 525 | #endif |
| 526 | |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 527 | return 0; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | static int dwmci_init(struct mmc *mmc) |
| 531 | { |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 532 | struct dwmci_host *host = mmc->priv; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 533 | |
Jaehoon Chung | 42f81a8 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 534 | if (host->board_init) |
| 535 | host->board_init(host); |
Rajeshwari Shinde | 7016309 | 2013-10-29 12:53:13 +0530 | [diff] [blame] | 536 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 537 | dwmci_writel(host, DWMCI_PWREN, 1); |
| 538 | |
| 539 | if (!dwmci_wait_reset(host, DWMCI_RESET_ALL)) { |
Simon Glass | 4c9b948 | 2015-08-06 20:16:27 -0600 | [diff] [blame] | 540 | debug("%s[%d] Fail-reset!!\n", __func__, __LINE__); |
| 541 | return -EIO; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 544 | /* Enumerate at 400KHz */ |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 545 | dwmci_setup_bus(host, mmc->cfg->f_min); |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 546 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 547 | dwmci_writel(host, DWMCI_RINTSTS, 0xFFFFFFFF); |
| 548 | dwmci_writel(host, DWMCI_INTMASK, 0); |
| 549 | |
| 550 | dwmci_writel(host, DWMCI_TMOUT, 0xFFFFFFFF); |
| 551 | |
| 552 | dwmci_writel(host, DWMCI_IDINTEN, 0); |
| 553 | dwmci_writel(host, DWMCI_BMOD, 1); |
| 554 | |
Simon Glass | 6133efa | 2015-08-06 20:16:29 -0600 | [diff] [blame] | 555 | if (!host->fifoth_val) { |
| 556 | uint32_t fifo_size; |
| 557 | |
| 558 | fifo_size = dwmci_readl(host, DWMCI_FIFOTH); |
| 559 | fifo_size = ((fifo_size & RX_WMARK_MASK) >> RX_WMARK_SHIFT) + 1; |
| 560 | host->fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size / 2 - 1) | |
| 561 | TX_WMARK(fifo_size / 2); |
Amar | 902664c | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 562 | } |
Simon Glass | 6133efa | 2015-08-06 20:16:29 -0600 | [diff] [blame] | 563 | dwmci_writel(host, DWMCI_FIFOTH, host->fifoth_val); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 564 | |
| 565 | dwmci_writel(host, DWMCI_CLKENA, 0); |
| 566 | dwmci_writel(host, DWMCI_CLKSRC, 0); |
| 567 | |
Ley Foon Tan | b98e892 | 2018-12-20 17:55:41 +0800 | [diff] [blame] | 568 | if (!host->fifo_mode) |
| 569 | dwmci_writel(host, DWMCI_IDINTEN, DWMCI_IDINTEN_MASK); |
| 570 | |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
Simon Glass | eba48f9 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 574 | #ifdef CONFIG_DM_MMC |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 575 | int dwmci_probe(struct udevice *dev) |
| 576 | { |
| 577 | struct mmc *mmc = mmc_get_mmc_dev(dev); |
| 578 | |
| 579 | return dwmci_init(mmc); |
| 580 | } |
| 581 | |
| 582 | const struct dm_mmc_ops dm_dwmci_ops = { |
| 583 | .send_cmd = dwmci_send_cmd, |
| 584 | .set_ios = dwmci_set_ios, |
| 585 | }; |
| 586 | |
| 587 | #else |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 588 | static const struct mmc_ops dwmci_ops = { |
| 589 | .send_cmd = dwmci_send_cmd, |
| 590 | .set_ios = dwmci_set_ios, |
| 591 | .init = dwmci_init, |
| 592 | }; |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 593 | #endif |
Pantelis Antoniou | c9e7591 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 594 | |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 595 | void dwmci_setup_cfg(struct mmc_config *cfg, struct dwmci_host *host, |
| 596 | u32 max_clk, u32 min_clk) |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 597 | { |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 598 | cfg->name = host->name; |
Simon Glass | eba48f9 | 2017-07-29 11:35:31 -0600 | [diff] [blame] | 599 | #ifndef CONFIG_DM_MMC |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 600 | cfg->ops = &dwmci_ops; |
Simon Glass | ff5c1b7 | 2016-06-12 23:30:23 -0600 | [diff] [blame] | 601 | #endif |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 602 | cfg->f_min = min_clk; |
| 603 | cfg->f_max = max_clk; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 604 | |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 605 | cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 606 | |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 607 | cfg->host_caps = host->caps; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 608 | |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 609 | if (host->buswidth == 8) { |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 610 | cfg->host_caps |= MMC_MODE_8BIT; |
| 611 | cfg->host_caps &= ~MMC_MODE_4BIT; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 612 | } else { |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 613 | cfg->host_caps |= MMC_MODE_4BIT; |
| 614 | cfg->host_caps &= ~MMC_MODE_8BIT; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 615 | } |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 616 | cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz; |
| 617 | |
| 618 | cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
| 619 | } |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 620 | |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 621 | #ifdef CONFIG_BLK |
| 622 | int dwmci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg) |
| 623 | { |
| 624 | return mmc_bind(dev, mmc, cfg); |
| 625 | } |
| 626 | #else |
| 627 | int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk) |
| 628 | { |
Jaehoon Chung | bf819d0 | 2016-09-23 19:13:16 +0900 | [diff] [blame] | 629 | dwmci_setup_cfg(&host->cfg, host, max_clk, min_clk); |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 630 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 631 | host->mmc = mmc_create(&host->cfg, host); |
| 632 | if (host->mmc == NULL) |
| 633 | return -1; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 634 | |
Pantelis Antoniou | 2c85046 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 635 | return 0; |
Jaehoon Chung | 7cf7307 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 636 | } |
Simon Glass | 8268254 | 2016-05-14 14:03:07 -0600 | [diff] [blame] | 637 | #endif |