Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2012 SAMSUNG Electronics |
| 3 | * Jaehoon Chung <jh80.chung@samsung.com> |
| 4 | * Rajeshawari Shinde <rajeshwari.s@samsung.com> |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 9 | #include <bouncebuf.h> |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 10 | #include <common.h> |
| 11 | #include <malloc.h> |
| 12 | #include <mmc.h> |
| 13 | #include <dwmmc.h> |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 14 | #include <asm-generic/errno.h> |
| 15 | |
| 16 | #define PAGE_SIZE 4096 |
| 17 | |
| 18 | static int dwmci_wait_reset(struct dwmci_host *host, u32 value) |
| 19 | { |
| 20 | unsigned long timeout = 1000; |
| 21 | u32 ctrl; |
| 22 | |
| 23 | dwmci_writel(host, DWMCI_CTRL, value); |
| 24 | |
| 25 | while (timeout--) { |
| 26 | ctrl = dwmci_readl(host, DWMCI_CTRL); |
| 27 | if (!(ctrl & DWMCI_RESET_ALL)) |
| 28 | return 1; |
| 29 | } |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static void dwmci_set_idma_desc(struct dwmci_idmac *idmac, |
| 34 | u32 desc0, u32 desc1, u32 desc2) |
| 35 | { |
| 36 | struct dwmci_idmac *desc = idmac; |
| 37 | |
| 38 | desc->flags = desc0; |
| 39 | desc->cnt = desc1; |
| 40 | desc->addr = desc2; |
| 41 | desc->next_addr = (unsigned int)desc + sizeof(struct dwmci_idmac); |
| 42 | } |
| 43 | |
| 44 | static void dwmci_prepare_data(struct dwmci_host *host, |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 45 | struct mmc_data *data, |
| 46 | struct dwmci_idmac *cur_idmac, |
| 47 | void *bounce_buffer) |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 48 | { |
| 49 | unsigned long ctrl; |
| 50 | unsigned int i = 0, flags, cnt, blk_cnt; |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 51 | ulong data_start, data_end; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 52 | |
| 53 | |
| 54 | blk_cnt = data->blocks; |
| 55 | |
| 56 | dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET); |
| 57 | |
| 58 | data_start = (ulong)cur_idmac; |
| 59 | dwmci_writel(host, DWMCI_DBADDR, (unsigned int)cur_idmac); |
| 60 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 61 | do { |
| 62 | flags = DWMCI_IDMAC_OWN | DWMCI_IDMAC_CH ; |
| 63 | flags |= (i == 0) ? DWMCI_IDMAC_FS : 0; |
| 64 | if (blk_cnt <= 8) { |
| 65 | flags |= DWMCI_IDMAC_LD; |
| 66 | cnt = data->blocksize * blk_cnt; |
| 67 | } else |
| 68 | cnt = data->blocksize * 8; |
| 69 | |
| 70 | dwmci_set_idma_desc(cur_idmac, flags, cnt, |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 71 | (u32)bounce_buffer + (i * PAGE_SIZE)); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 72 | |
Mischa Jonker | 21bd576 | 2013-07-26 16:18:40 +0200 | [diff] [blame] | 73 | if (blk_cnt <= 8) |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 74 | break; |
| 75 | blk_cnt -= 8; |
| 76 | cur_idmac++; |
| 77 | i++; |
| 78 | } while(1); |
| 79 | |
| 80 | data_end = (ulong)cur_idmac; |
| 81 | flush_dcache_range(data_start, data_end + ARCH_DMA_MINALIGN); |
| 82 | |
| 83 | ctrl = dwmci_readl(host, DWMCI_CTRL); |
| 84 | ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN; |
| 85 | dwmci_writel(host, DWMCI_CTRL, ctrl); |
| 86 | |
| 87 | ctrl = dwmci_readl(host, DWMCI_BMOD); |
| 88 | ctrl |= DWMCI_BMOD_IDMAC_FB | DWMCI_BMOD_IDMAC_EN; |
| 89 | dwmci_writel(host, DWMCI_BMOD, ctrl); |
| 90 | |
| 91 | dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize); |
| 92 | dwmci_writel(host, DWMCI_BYTCNT, data->blocksize * data->blocks); |
| 93 | } |
| 94 | |
| 95 | static int dwmci_set_transfer_mode(struct dwmci_host *host, |
| 96 | struct mmc_data *data) |
| 97 | { |
| 98 | unsigned long mode; |
| 99 | |
| 100 | mode = DWMCI_CMD_DATA_EXP; |
| 101 | if (data->flags & MMC_DATA_WRITE) |
| 102 | mode |= DWMCI_CMD_RW; |
| 103 | |
| 104 | return mode; |
| 105 | } |
| 106 | |
| 107 | static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, |
| 108 | struct mmc_data *data) |
| 109 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 110 | struct dwmci_host *host = mmc->priv; |
Mischa Jonker | 2136d22 | 2013-07-26 14:08:14 +0200 | [diff] [blame] | 111 | ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac, |
Mischa Jonker | 21bd576 | 2013-07-26 16:18:40 +0200 | [diff] [blame] | 112 | data ? DIV_ROUND_UP(data->blocks, 8) : 0); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 113 | int flags = 0, i; |
| 114 | unsigned int timeout = 100000; |
| 115 | u32 retry = 10000; |
| 116 | u32 mask, ctrl; |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 117 | ulong start = get_timer(0); |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 118 | struct bounce_buffer bbstate; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 119 | |
| 120 | while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) { |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 121 | if (get_timer(start) > timeout) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 122 | printf("%s: Timeout on data busy\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 123 | return TIMEOUT; |
| 124 | } |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL); |
| 128 | |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 129 | if (data) { |
| 130 | if (data->flags == MMC_DATA_READ) { |
| 131 | bounce_buffer_start(&bbstate, (void*)data->dest, |
| 132 | data->blocksize * |
| 133 | data->blocks, GEN_BB_WRITE); |
| 134 | } else { |
| 135 | bounce_buffer_start(&bbstate, (void*)data->src, |
| 136 | data->blocksize * |
| 137 | data->blocks, GEN_BB_READ); |
| 138 | } |
| 139 | dwmci_prepare_data(host, data, cur_idmac, |
| 140 | bbstate.bounce_buffer); |
| 141 | } |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 142 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 143 | dwmci_writel(host, DWMCI_CMDARG, cmd->cmdarg); |
| 144 | |
| 145 | if (data) |
| 146 | flags = dwmci_set_transfer_mode(host, data); |
| 147 | |
| 148 | if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY)) |
| 149 | return -1; |
| 150 | |
| 151 | if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION) |
| 152 | flags |= DWMCI_CMD_ABORT_STOP; |
| 153 | else |
| 154 | flags |= DWMCI_CMD_PRV_DAT_WAIT; |
| 155 | |
| 156 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 157 | flags |= DWMCI_CMD_RESP_EXP; |
| 158 | if (cmd->resp_type & MMC_RSP_136) |
| 159 | flags |= DWMCI_CMD_RESP_LENGTH; |
| 160 | } |
| 161 | |
| 162 | if (cmd->resp_type & MMC_RSP_CRC) |
| 163 | flags |= DWMCI_CMD_CHECK_CRC; |
| 164 | |
| 165 | flags |= (cmd->cmdidx | DWMCI_CMD_START | DWMCI_CMD_USE_HOLD_REG); |
| 166 | |
| 167 | debug("Sending CMD%d\n",cmd->cmdidx); |
| 168 | |
| 169 | dwmci_writel(host, DWMCI_CMD, flags); |
| 170 | |
| 171 | for (i = 0; i < retry; i++) { |
| 172 | mask = dwmci_readl(host, DWMCI_RINTSTS); |
| 173 | if (mask & DWMCI_INTMSK_CDONE) { |
| 174 | if (!data) |
| 175 | dwmci_writel(host, DWMCI_RINTSTS, mask); |
| 176 | break; |
| 177 | } |
| 178 | } |
| 179 | |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 180 | if (i == retry) { |
| 181 | printf("%s: Timeout.\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 182 | return TIMEOUT; |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 183 | } |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 184 | |
| 185 | if (mask & DWMCI_INTMSK_RTO) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 186 | /* |
| 187 | * Timeout here is not necessarily fatal. (e)MMC cards |
| 188 | * will splat here when they receive CMD55 as they do |
| 189 | * not support this command and that is exactly the way |
| 190 | * to tell them apart from SD cards. Thus, this output |
| 191 | * below shall be debug(). eMMC cards also do not favor |
| 192 | * CMD8, please keep that in mind. |
| 193 | */ |
| 194 | debug("%s: Response Timeout.\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 195 | return TIMEOUT; |
| 196 | } else if (mask & DWMCI_INTMSK_RE) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 197 | printf("%s: Response Error.\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | |
| 202 | if (cmd->resp_type & MMC_RSP_PRESENT) { |
| 203 | if (cmd->resp_type & MMC_RSP_136) { |
| 204 | cmd->response[0] = dwmci_readl(host, DWMCI_RESP3); |
| 205 | cmd->response[1] = dwmci_readl(host, DWMCI_RESP2); |
| 206 | cmd->response[2] = dwmci_readl(host, DWMCI_RESP1); |
| 207 | cmd->response[3] = dwmci_readl(host, DWMCI_RESP0); |
| 208 | } else { |
| 209 | cmd->response[0] = dwmci_readl(host, DWMCI_RESP0); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | if (data) { |
Marek Vasut | d9dbb97 | 2015-07-27 22:39:37 +0200 | [diff] [blame^] | 214 | start = get_timer(0); |
| 215 | timeout = 1000; |
| 216 | for (;;) { |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 217 | mask = dwmci_readl(host, DWMCI_RINTSTS); |
Marek Vasut | d9dbb97 | 2015-07-27 22:39:37 +0200 | [diff] [blame^] | 218 | /* Error during data transfer. */ |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 219 | if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 220 | printf("%s: DATA ERROR!\n", __func__); |
Marek Vasut | 603b2f3 | 2015-07-27 22:39:36 +0200 | [diff] [blame] | 221 | bounce_buffer_stop(&bbstate); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 222 | return -1; |
| 223 | } |
Marek Vasut | d9dbb97 | 2015-07-27 22:39:37 +0200 | [diff] [blame^] | 224 | |
| 225 | /* Data arrived correctly. */ |
| 226 | if (mask & DWMCI_INTMSK_DTO) |
| 227 | break; |
| 228 | |
| 229 | /* Check for timeout. */ |
| 230 | if (get_timer(start) > timeout) { |
| 231 | printf("%s: Timeout waiting for data!\n", |
| 232 | __func__); |
| 233 | bounce_buffer_stop(&bbstate); |
| 234 | return TIMEOUT; |
| 235 | } |
| 236 | } |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 237 | |
| 238 | dwmci_writel(host, DWMCI_RINTSTS, mask); |
| 239 | |
| 240 | ctrl = dwmci_readl(host, DWMCI_CTRL); |
| 241 | ctrl &= ~(DWMCI_DMA_EN); |
| 242 | dwmci_writel(host, DWMCI_CTRL, ctrl); |
Alexey Brodkin | 2a7a210 | 2013-12-26 15:29:07 +0400 | [diff] [blame] | 243 | |
| 244 | bounce_buffer_stop(&bbstate); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | udelay(100); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static int dwmci_setup_bus(struct dwmci_host *host, u32 freq) |
| 253 | { |
| 254 | u32 div, status; |
| 255 | int timeout = 10000; |
| 256 | unsigned long sclk; |
| 257 | |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 258 | if ((freq == host->clock) || (freq == 0)) |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 259 | return 0; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 260 | /* |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 261 | * If host->get_mmc_clk isn't defined, |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 262 | * then assume that host->bus_hz is source clock value. |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 263 | * host->bus_hz should be set by user. |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 264 | */ |
Jaehoon Chung | b44fe83 | 2013-10-06 18:59:31 +0900 | [diff] [blame] | 265 | if (host->get_mmc_clk) |
Rajeshwari S Shinde | d3e016c | 2014-02-05 10:48:15 +0530 | [diff] [blame] | 266 | sclk = host->get_mmc_clk(host); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 267 | else if (host->bus_hz) |
| 268 | sclk = host->bus_hz; |
| 269 | else { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 270 | printf("%s: Didn't get source clock value.\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | } |
| 273 | |
Chin Liang See | 6ace153 | 2014-06-10 01:26:52 -0500 | [diff] [blame] | 274 | if (sclk == freq) |
| 275 | div = 0; /* bypass mode */ |
| 276 | else |
| 277 | div = DIV_ROUND_UP(sclk, 2 * freq); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 278 | |
| 279 | dwmci_writel(host, DWMCI_CLKENA, 0); |
| 280 | dwmci_writel(host, DWMCI_CLKSRC, 0); |
| 281 | |
| 282 | dwmci_writel(host, DWMCI_CLKDIV, div); |
| 283 | dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | |
| 284 | DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); |
| 285 | |
| 286 | do { |
| 287 | status = dwmci_readl(host, DWMCI_CMD); |
| 288 | if (timeout-- < 0) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 289 | printf("%s: Timeout!\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 290 | return -ETIMEDOUT; |
| 291 | } |
| 292 | } while (status & DWMCI_CMD_START); |
| 293 | |
| 294 | dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE | |
| 295 | DWMCI_CLKEN_LOW_PWR); |
| 296 | |
| 297 | dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT | |
| 298 | DWMCI_CMD_UPD_CLK | DWMCI_CMD_START); |
| 299 | |
| 300 | timeout = 10000; |
| 301 | do { |
| 302 | status = dwmci_readl(host, DWMCI_CMD); |
| 303 | if (timeout-- < 0) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 304 | printf("%s: Timeout!\n", __func__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 305 | return -ETIMEDOUT; |
| 306 | } |
| 307 | } while (status & DWMCI_CMD_START); |
| 308 | |
| 309 | host->clock = freq; |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static void dwmci_set_ios(struct mmc *mmc) |
| 315 | { |
Jaehoon Chung | 045bdcd | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 316 | struct dwmci_host *host = (struct dwmci_host *)mmc->priv; |
| 317 | u32 ctype, regs; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 318 | |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 319 | debug("Buswidth = %d, clock: %d\n", mmc->bus_width, mmc->clock); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 320 | |
| 321 | dwmci_setup_bus(host, mmc->clock); |
| 322 | switch (mmc->bus_width) { |
| 323 | case 8: |
| 324 | ctype = DWMCI_CTYPE_8BIT; |
| 325 | break; |
| 326 | case 4: |
| 327 | ctype = DWMCI_CTYPE_4BIT; |
| 328 | break; |
| 329 | default: |
| 330 | ctype = DWMCI_CTYPE_1BIT; |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | dwmci_writel(host, DWMCI_CTYPE, ctype); |
| 335 | |
Jaehoon Chung | 045bdcd | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 336 | regs = dwmci_readl(host, DWMCI_UHS_REG); |
Andrew Gabbasov | 2b8a969 | 2014-12-01 06:59:12 -0600 | [diff] [blame] | 337 | if (mmc->ddr_mode) |
Jaehoon Chung | 045bdcd | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 338 | regs |= DWMCI_DDR_MODE; |
| 339 | else |
Jaehoon Chung | afc9e2b | 2015-01-14 17:37:53 +0900 | [diff] [blame] | 340 | regs &= ~DWMCI_DDR_MODE; |
Jaehoon Chung | 045bdcd | 2014-05-16 13:59:55 +0900 | [diff] [blame] | 341 | |
| 342 | dwmci_writel(host, DWMCI_UHS_REG, regs); |
| 343 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 344 | if (host->clksel) |
| 345 | host->clksel(host); |
| 346 | } |
| 347 | |
| 348 | static int dwmci_init(struct mmc *mmc) |
| 349 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 350 | struct dwmci_host *host = mmc->priv; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 351 | |
Jaehoon Chung | 18ab675 | 2013-11-29 20:08:57 +0900 | [diff] [blame] | 352 | if (host->board_init) |
| 353 | host->board_init(host); |
Rajeshwari Shinde | 6f0b7ca | 2013-10-29 12:53:13 +0530 | [diff] [blame] | 354 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 355 | dwmci_writel(host, DWMCI_PWREN, 1); |
| 356 | |
| 357 | if (!dwmci_wait_reset(host, DWMCI_RESET_ALL)) { |
Pavel Machek | f33c930 | 2014-09-05 12:49:48 +0200 | [diff] [blame] | 358 | printf("%s[%d] Fail-reset!!\n", __func__, __LINE__); |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 359 | return -1; |
| 360 | } |
| 361 | |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 362 | /* Enumerate at 400KHz */ |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 363 | dwmci_setup_bus(host, mmc->cfg->f_min); |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 364 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 365 | dwmci_writel(host, DWMCI_RINTSTS, 0xFFFFFFFF); |
| 366 | dwmci_writel(host, DWMCI_INTMASK, 0); |
| 367 | |
| 368 | dwmci_writel(host, DWMCI_TMOUT, 0xFFFFFFFF); |
| 369 | |
| 370 | dwmci_writel(host, DWMCI_IDINTEN, 0); |
| 371 | dwmci_writel(host, DWMCI_BMOD, 1); |
| 372 | |
Alexey Brodkin | 9108b31 | 2013-11-27 17:00:52 +0400 | [diff] [blame] | 373 | if (host->fifoth_val) { |
| 374 | dwmci_writel(host, DWMCI_FIFOTH, host->fifoth_val); |
Amar | 9c50e35 | 2013-04-27 11:42:54 +0530 | [diff] [blame] | 375 | } |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 376 | |
| 377 | dwmci_writel(host, DWMCI_CLKENA, 0); |
| 378 | dwmci_writel(host, DWMCI_CLKSRC, 0); |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
Pantelis Antoniou | ab769f2 | 2014-02-26 19:28:45 +0200 | [diff] [blame] | 383 | static const struct mmc_ops dwmci_ops = { |
| 384 | .send_cmd = dwmci_send_cmd, |
| 385 | .set_ios = dwmci_set_ios, |
| 386 | .init = dwmci_init, |
| 387 | }; |
| 388 | |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 389 | int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk) |
| 390 | { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 391 | host->cfg.name = host->name; |
| 392 | host->cfg.ops = &dwmci_ops; |
| 393 | host->cfg.f_min = min_clk; |
| 394 | host->cfg.f_max = max_clk; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 395 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 396 | host->cfg.voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 397 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 398 | host->cfg.host_caps = host->caps; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 399 | |
| 400 | if (host->buswidth == 8) { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 401 | host->cfg.host_caps |= MMC_MODE_8BIT; |
| 402 | host->cfg.host_caps &= ~MMC_MODE_4BIT; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 403 | } else { |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 404 | host->cfg.host_caps |= MMC_MODE_4BIT; |
| 405 | host->cfg.host_caps &= ~MMC_MODE_8BIT; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 406 | } |
Rob Herring | 5a20397 | 2015-03-23 17:56:59 -0500 | [diff] [blame] | 407 | host->cfg.host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 408 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 409 | host->cfg.b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 410 | |
Pantelis Antoniou | 93bfd61 | 2014-03-11 19:34:20 +0200 | [diff] [blame] | 411 | host->mmc = mmc_create(&host->cfg, host); |
| 412 | if (host->mmc == NULL) |
| 413 | return -1; |
| 414 | |
| 415 | return 0; |
Jaehoon Chung | 757bff4 | 2012-10-15 19:10:29 +0000 | [diff] [blame] | 416 | } |